2
0

pdf.worker.js 1.3 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270
  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.85';
  30. var pdfjsBuild = 'ebe6fb2';
  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. var NetworkManager = (function NetworkManagerClosure() {
  1531. var OK_RESPONSE = 200;
  1532. var PARTIAL_CONTENT_RESPONSE = 206;
  1533. function NetworkManager(url, args) {
  1534. this.url = url;
  1535. args = args || {};
  1536. this.isHttp = /^https?:/i.test(url);
  1537. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1538. this.withCredentials = args.withCredentials || false;
  1539. this.getXhr = args.getXhr ||
  1540. function NetworkManager_getXhr() {
  1541. return new XMLHttpRequest();
  1542. };
  1543. this.currXhrId = 0;
  1544. this.pendingRequests = Object.create(null);
  1545. this.loadedRequests = Object.create(null);
  1546. }
  1547. function getArrayBuffer(xhr) {
  1548. var data = xhr.response;
  1549. if (typeof data !== 'string') {
  1550. return data;
  1551. }
  1552. var length = data.length;
  1553. var array = new Uint8Array(length);
  1554. for (var i = 0; i < length; i++) {
  1555. array[i] = data.charCodeAt(i) & 0xFF;
  1556. }
  1557. return array.buffer;
  1558. }
  1559. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1560. try {
  1561. var x = new XMLHttpRequest();
  1562. // Firefox 37- required .open() to be called before setting responseType.
  1563. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1564. // Even though the URL is not visited, .open() could fail if the URL is
  1565. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1566. // When this error occurs, this feature detection method will mistakenly
  1567. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1568. x.open('GET', 'https://example.com');
  1569. x.responseType = 'moz-chunked-arraybuffer';
  1570. return x.responseType === 'moz-chunked-arraybuffer';
  1571. } catch (e) {
  1572. return false;
  1573. }
  1574. })();
  1575. NetworkManager.prototype = {
  1576. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1577. var args = {
  1578. begin: begin,
  1579. end: end
  1580. };
  1581. for (var prop in listeners) {
  1582. args[prop] = listeners[prop];
  1583. }
  1584. return this.request(args);
  1585. },
  1586. requestFull: function NetworkManager_requestFull(listeners) {
  1587. return this.request(listeners);
  1588. },
  1589. request: function NetworkManager_request(args) {
  1590. var xhr = this.getXhr();
  1591. var xhrId = this.currXhrId++;
  1592. var pendingRequest = this.pendingRequests[xhrId] = {
  1593. xhr: xhr
  1594. };
  1595. xhr.open('GET', this.url);
  1596. xhr.withCredentials = this.withCredentials;
  1597. for (var property in this.httpHeaders) {
  1598. var value = this.httpHeaders[property];
  1599. if (typeof value === 'undefined') {
  1600. continue;
  1601. }
  1602. xhr.setRequestHeader(property, value);
  1603. }
  1604. if (this.isHttp && 'begin' in args && 'end' in args) {
  1605. var rangeStr = args.begin + '-' + (args.end - 1);
  1606. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1607. pendingRequest.expectedStatus = 206;
  1608. } else {
  1609. pendingRequest.expectedStatus = 200;
  1610. }
  1611. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1612. if (useMozChunkedLoading) {
  1613. xhr.responseType = 'moz-chunked-arraybuffer';
  1614. pendingRequest.onProgressiveData = args.onProgressiveData;
  1615. pendingRequest.mozChunked = true;
  1616. } else {
  1617. xhr.responseType = 'arraybuffer';
  1618. }
  1619. if (args.onError) {
  1620. xhr.onerror = function(evt) {
  1621. args.onError(xhr.status);
  1622. };
  1623. }
  1624. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1625. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1626. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1627. pendingRequest.onDone = args.onDone;
  1628. pendingRequest.onError = args.onError;
  1629. pendingRequest.onProgress = args.onProgress;
  1630. xhr.send(null);
  1631. return xhrId;
  1632. },
  1633. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1634. var pendingRequest = this.pendingRequests[xhrId];
  1635. if (!pendingRequest) {
  1636. // Maybe abortRequest was called...
  1637. return;
  1638. }
  1639. if (pendingRequest.mozChunked) {
  1640. var chunk = getArrayBuffer(pendingRequest.xhr);
  1641. pendingRequest.onProgressiveData(chunk);
  1642. }
  1643. var onProgress = pendingRequest.onProgress;
  1644. if (onProgress) {
  1645. onProgress(evt);
  1646. }
  1647. },
  1648. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1649. var pendingRequest = this.pendingRequests[xhrId];
  1650. if (!pendingRequest) {
  1651. // Maybe abortRequest was called...
  1652. return;
  1653. }
  1654. var xhr = pendingRequest.xhr;
  1655. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1656. pendingRequest.onHeadersReceived();
  1657. delete pendingRequest.onHeadersReceived;
  1658. }
  1659. if (xhr.readyState !== 4) {
  1660. return;
  1661. }
  1662. if (!(xhrId in this.pendingRequests)) {
  1663. // The XHR request might have been aborted in onHeadersReceived()
  1664. // callback, in which case we should abort request
  1665. return;
  1666. }
  1667. delete this.pendingRequests[xhrId];
  1668. // success status == 0 can be on ftp, file and other protocols
  1669. if (xhr.status === 0 && this.isHttp) {
  1670. if (pendingRequest.onError) {
  1671. pendingRequest.onError(xhr.status);
  1672. }
  1673. return;
  1674. }
  1675. var xhrStatus = xhr.status || OK_RESPONSE;
  1676. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1677. // "A server MAY ignore the Range header". This means it's possible to
  1678. // get a 200 rather than a 206 response from a range request.
  1679. var ok_response_on_range_request =
  1680. xhrStatus === OK_RESPONSE &&
  1681. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1682. if (!ok_response_on_range_request &&
  1683. xhrStatus !== pendingRequest.expectedStatus) {
  1684. if (pendingRequest.onError) {
  1685. pendingRequest.onError(xhr.status);
  1686. }
  1687. return;
  1688. }
  1689. this.loadedRequests[xhrId] = true;
  1690. var chunk = getArrayBuffer(xhr);
  1691. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1692. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1693. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1694. var begin = parseInt(matches[1], 10);
  1695. pendingRequest.onDone({
  1696. begin: begin,
  1697. chunk: chunk
  1698. });
  1699. } else if (pendingRequest.onProgressiveData) {
  1700. pendingRequest.onDone(null);
  1701. } else if (chunk) {
  1702. pendingRequest.onDone({
  1703. begin: 0,
  1704. chunk: chunk
  1705. });
  1706. } else if (pendingRequest.onError) {
  1707. pendingRequest.onError(xhr.status);
  1708. }
  1709. },
  1710. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1711. for (var xhrId in this.pendingRequests) {
  1712. return true;
  1713. }
  1714. return false;
  1715. },
  1716. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1717. return this.pendingRequests[xhrId].xhr;
  1718. },
  1719. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1720. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1721. },
  1722. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1723. return xhrId in this.pendingRequests;
  1724. },
  1725. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1726. return xhrId in this.loadedRequests;
  1727. },
  1728. abortAllRequests: function NetworkManager_abortAllRequests() {
  1729. for (var xhrId in this.pendingRequests) {
  1730. this.abortRequest(xhrId | 0);
  1731. }
  1732. },
  1733. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1734. var xhr = this.pendingRequests[xhrId].xhr;
  1735. delete this.pendingRequests[xhrId];
  1736. xhr.abort();
  1737. }
  1738. };
  1739. return NetworkManager;
  1740. })();
  1741. (function (root, factory) {
  1742. {
  1743. factory((root.pdfjsCoreNetwork = {}));
  1744. }
  1745. }(this, function (exports) {
  1746. exports.NetworkManager = NetworkManager;
  1747. }));
  1748. (function (root, factory) {
  1749. {
  1750. factory((root.pdfjsSharedGlobal = {}));
  1751. }
  1752. }(this, function (exports) {
  1753. var globalScope = (typeof window !== 'undefined') ? window :
  1754. (typeof global !== 'undefined') ? global :
  1755. (typeof self !== 'undefined') ? self : this;
  1756. var isWorker = (typeof window === 'undefined');
  1757. // The global PDFJS object exposes the API
  1758. // In production, it will be declared outside a global wrapper
  1759. // In development, it will be declared here
  1760. if (!globalScope.PDFJS) {
  1761. globalScope.PDFJS = {};
  1762. }
  1763. if (typeof pdfjsVersion !== 'undefined') {
  1764. globalScope.PDFJS.version = pdfjsVersion;
  1765. }
  1766. if (typeof pdfjsVersion !== 'undefined') {
  1767. globalScope.PDFJS.build = pdfjsBuild;
  1768. }
  1769. globalScope.PDFJS.pdfBug = false;
  1770. exports.globalScope = globalScope;
  1771. exports.isWorker = isWorker;
  1772. exports.PDFJS = globalScope.PDFJS;
  1773. }));
  1774. (function (root, factory) {
  1775. {
  1776. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  1777. }
  1778. }(this, function (exports, sharedGlobal) {
  1779. var PDFJS = sharedGlobal.PDFJS;
  1780. var bidi = PDFJS.bidi = (function bidiClosure() {
  1781. // Character types for symbols from 0000 to 00FF.
  1782. var baseTypes = [
  1783. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  1784. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1785. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  1786. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  1787. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  1788. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1789. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  1790. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1791. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1792. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  1793. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1794. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1795. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  1796. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  1797. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1798. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1799. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1800. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1801. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  1802. ];
  1803. // Character types for symbols from 0600 to 06FF
  1804. var arabicTypes = [
  1805. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1806. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  1807. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1808. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1809. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1810. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1811. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1812. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1813. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  1814. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1815. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1816. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1817. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1818. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1819. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1820. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1821. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1822. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1823. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1824. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  1825. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1826. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  1827. ];
  1828. function isOdd(i) {
  1829. return (i & 1) !== 0;
  1830. }
  1831. function isEven(i) {
  1832. return (i & 1) === 0;
  1833. }
  1834. function findUnequal(arr, start, value) {
  1835. for (var j = start, jj = arr.length; j < jj; ++j) {
  1836. if (arr[j] !== value) {
  1837. return j;
  1838. }
  1839. }
  1840. return j;
  1841. }
  1842. function setValues(arr, start, end, value) {
  1843. for (var j = start; j < end; ++j) {
  1844. arr[j] = value;
  1845. }
  1846. }
  1847. function reverseValues(arr, start, end) {
  1848. for (var i = start, j = end - 1; i < j; ++i, --j) {
  1849. var temp = arr[i];
  1850. arr[i] = arr[j];
  1851. arr[j] = temp;
  1852. }
  1853. }
  1854. function createBidiText(str, isLTR, vertical) {
  1855. return {
  1856. str: str,
  1857. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  1858. };
  1859. }
  1860. // These are used in bidi(), which is called frequently. We re-use them on
  1861. // each call to avoid unnecessary allocations.
  1862. var chars = [];
  1863. var types = [];
  1864. function bidi(str, startLevel, vertical) {
  1865. var isLTR = true;
  1866. var strLength = str.length;
  1867. if (strLength === 0 || vertical) {
  1868. return createBidiText(str, isLTR, vertical);
  1869. }
  1870. // Get types and fill arrays
  1871. chars.length = strLength;
  1872. types.length = strLength;
  1873. var numBidi = 0;
  1874. var i, ii;
  1875. for (i = 0; i < strLength; ++i) {
  1876. chars[i] = str.charAt(i);
  1877. var charCode = str.charCodeAt(i);
  1878. var charType = 'L';
  1879. if (charCode <= 0x00ff) {
  1880. charType = baseTypes[charCode];
  1881. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1882. charType = 'R';
  1883. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1884. charType = arabicTypes[charCode & 0xff];
  1885. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1886. charType = 'AL';
  1887. }
  1888. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1889. numBidi++;
  1890. }
  1891. types[i] = charType;
  1892. }
  1893. // Detect the bidi method
  1894. // - If there are no rtl characters then no bidi needed
  1895. // - If less than 30% chars are rtl then string is primarily ltr
  1896. // - If more than 30% chars are rtl then string is primarily rtl
  1897. if (numBidi === 0) {
  1898. isLTR = true;
  1899. return createBidiText(str, isLTR);
  1900. }
  1901. if (startLevel === -1) {
  1902. if ((strLength / numBidi) < 0.3) {
  1903. isLTR = true;
  1904. startLevel = 0;
  1905. } else {
  1906. isLTR = false;
  1907. startLevel = 1;
  1908. }
  1909. }
  1910. var levels = [];
  1911. for (i = 0; i < strLength; ++i) {
  1912. levels[i] = startLevel;
  1913. }
  1914. /*
  1915. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1916. */
  1917. var e = (isOdd(startLevel) ? 'R' : 'L');
  1918. var sor = e;
  1919. var eor = sor;
  1920. /*
  1921. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1922. type of the NSM to the type of the previous character. If the NSM is at the
  1923. start of the level run, it will get the type of sor.
  1924. */
  1925. var lastType = sor;
  1926. for (i = 0; i < strLength; ++i) {
  1927. if (types[i] === 'NSM') {
  1928. types[i] = lastType;
  1929. } else {
  1930. lastType = types[i];
  1931. }
  1932. }
  1933. /*
  1934. W2. Search backwards from each instance of a European number until the
  1935. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1936. the type of the European number to Arabic number.
  1937. */
  1938. lastType = sor;
  1939. var t;
  1940. for (i = 0; i < strLength; ++i) {
  1941. t = types[i];
  1942. if (t === 'EN') {
  1943. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  1944. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1945. lastType = t;
  1946. }
  1947. }
  1948. /*
  1949. W3. Change all ALs to R.
  1950. */
  1951. for (i = 0; i < strLength; ++i) {
  1952. t = types[i];
  1953. if (t === 'AL') {
  1954. types[i] = 'R';
  1955. }
  1956. }
  1957. /*
  1958. W4. A single European separator between two European numbers changes to a
  1959. European number. A single common separator between two numbers of the same
  1960. type changes to that type:
  1961. */
  1962. for (i = 1; i < strLength - 1; ++i) {
  1963. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1964. types[i] = 'EN';
  1965. }
  1966. if (types[i] === 'CS' &&
  1967. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  1968. types[i + 1] === types[i - 1]) {
  1969. types[i] = types[i - 1];
  1970. }
  1971. }
  1972. /*
  1973. W5. A sequence of European terminators adjacent to European numbers changes
  1974. to all European numbers:
  1975. */
  1976. for (i = 0; i < strLength; ++i) {
  1977. if (types[i] === 'EN') {
  1978. // do before
  1979. var j;
  1980. for (j = i - 1; j >= 0; --j) {
  1981. if (types[j] !== 'ET') {
  1982. break;
  1983. }
  1984. types[j] = 'EN';
  1985. }
  1986. // do after
  1987. for (j = i + 1; j < strLength; --j) {
  1988. if (types[j] !== 'ET') {
  1989. break;
  1990. }
  1991. types[j] = 'EN';
  1992. }
  1993. }
  1994. }
  1995. /*
  1996. W6. Otherwise, separators and terminators change to Other Neutral:
  1997. */
  1998. for (i = 0; i < strLength; ++i) {
  1999. t = types[i];
  2000. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  2001. types[i] = 'ON';
  2002. }
  2003. }
  2004. /*
  2005. W7. Search backwards from each instance of a European number until the
  2006. first strong type (R, L, or sor) is found. If an L is found, then change
  2007. the type of the European number to L.
  2008. */
  2009. lastType = sor;
  2010. for (i = 0; i < strLength; ++i) {
  2011. t = types[i];
  2012. if (t === 'EN') {
  2013. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  2014. } else if (t === 'R' || t === 'L') {
  2015. lastType = t;
  2016. }
  2017. }
  2018. /*
  2019. N1. A sequence of neutrals takes the direction of the surrounding strong
  2020. text if the text on both sides has the same direction. European and Arabic
  2021. numbers are treated as though they were R. Start-of-level-run (sor) and
  2022. end-of-level-run (eor) are used at level run boundaries.
  2023. */
  2024. for (i = 0; i < strLength; ++i) {
  2025. if (types[i] === 'ON') {
  2026. var end = findUnequal(types, i + 1, 'ON');
  2027. var before = sor;
  2028. if (i > 0) {
  2029. before = types[i - 1];
  2030. }
  2031. var after = eor;
  2032. if (end + 1 < strLength) {
  2033. after = types[end + 1];
  2034. }
  2035. if (before !== 'L') {
  2036. before = 'R';
  2037. }
  2038. if (after !== 'L') {
  2039. after = 'R';
  2040. }
  2041. if (before === after) {
  2042. setValues(types, i, end, before);
  2043. }
  2044. i = end - 1; // reset to end (-1 so next iteration is ok)
  2045. }
  2046. }
  2047. /*
  2048. N2. Any remaining neutrals take the embedding direction.
  2049. */
  2050. for (i = 0; i < strLength; ++i) {
  2051. if (types[i] === 'ON') {
  2052. types[i] = e;
  2053. }
  2054. }
  2055. /*
  2056. I1. For all characters with an even (left-to-right) embedding direction,
  2057. those of type R go up one level and those of type AN or EN go up two
  2058. levels.
  2059. I2. For all characters with an odd (right-to-left) embedding direction,
  2060. those of type L, EN or AN go up one level.
  2061. */
  2062. for (i = 0; i < strLength; ++i) {
  2063. t = types[i];
  2064. if (isEven(levels[i])) {
  2065. if (t === 'R') {
  2066. levels[i] += 1;
  2067. } else if (t === 'AN' || t === 'EN') {
  2068. levels[i] += 2;
  2069. }
  2070. } else { // isOdd
  2071. if (t === 'L' || t === 'AN' || t === 'EN') {
  2072. levels[i] += 1;
  2073. }
  2074. }
  2075. }
  2076. /*
  2077. L1. On each line, reset the embedding level of the following characters to
  2078. the paragraph embedding level:
  2079. segment separators,
  2080. paragraph separators,
  2081. any sequence of whitespace characters preceding a segment separator or
  2082. paragraph separator, and any sequence of white space characters at the end
  2083. of the line.
  2084. */
  2085. // don't bother as text is only single line
  2086. /*
  2087. L2. From the highest level found in the text to the lowest odd level on
  2088. each line, reverse any contiguous sequence of characters that are at that
  2089. level or higher.
  2090. */
  2091. // find highest level & lowest odd level
  2092. var highestLevel = -1;
  2093. var lowestOddLevel = 99;
  2094. var level;
  2095. for (i = 0, ii = levels.length; i < ii; ++i) {
  2096. level = levels[i];
  2097. if (highestLevel < level) {
  2098. highestLevel = level;
  2099. }
  2100. if (lowestOddLevel > level && isOdd(level)) {
  2101. lowestOddLevel = level;
  2102. }
  2103. }
  2104. // now reverse between those limits
  2105. for (level = highestLevel; level >= lowestOddLevel; --level) {
  2106. // find segments to reverse
  2107. var start = -1;
  2108. for (i = 0, ii = levels.length; i < ii; ++i) {
  2109. if (levels[i] < level) {
  2110. if (start >= 0) {
  2111. reverseValues(chars, start, i);
  2112. start = -1;
  2113. }
  2114. } else if (start < 0) {
  2115. start = i;
  2116. }
  2117. }
  2118. if (start >= 0) {
  2119. reverseValues(chars, start, levels.length);
  2120. }
  2121. }
  2122. /*
  2123. L3. Combining marks applied to a right-to-left base character will at this
  2124. point precede their base character. If the rendering engine expects them to
  2125. follow the base characters in the final display process, then the ordering
  2126. of the marks and the base character must be reversed.
  2127. */
  2128. // don't bother for now
  2129. /*
  2130. L4. A character that possesses the mirrored property as specified by
  2131. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  2132. directionality of that character is R.
  2133. */
  2134. // don't mirror as characters are already mirrored in the pdf
  2135. // Finally, return string
  2136. for (i = 0, ii = chars.length; i < ii; ++i) {
  2137. var ch = chars[i];
  2138. if (ch === '<' || ch === '>') {
  2139. chars[i] = '';
  2140. }
  2141. }
  2142. return createBidiText(chars.join(''), isLTR);
  2143. }
  2144. return bidi;
  2145. })();
  2146. exports.bidi = bidi;
  2147. }));
  2148. (function (root, factory) {
  2149. {
  2150. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  2151. }
  2152. }(this, function (exports, sharedGlobal) {
  2153. var PDFJS = sharedGlobal.PDFJS;
  2154. var globalScope = sharedGlobal.globalScope;
  2155. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  2156. var TextRenderingMode = {
  2157. FILL: 0,
  2158. STROKE: 1,
  2159. FILL_STROKE: 2,
  2160. INVISIBLE: 3,
  2161. FILL_ADD_TO_PATH: 4,
  2162. STROKE_ADD_TO_PATH: 5,
  2163. FILL_STROKE_ADD_TO_PATH: 6,
  2164. ADD_TO_PATH: 7,
  2165. FILL_STROKE_MASK: 3,
  2166. ADD_TO_PATH_FLAG: 4
  2167. };
  2168. var ImageKind = {
  2169. GRAYSCALE_1BPP: 1,
  2170. RGB_24BPP: 2,
  2171. RGBA_32BPP: 3
  2172. };
  2173. var AnnotationType = {
  2174. TEXT: 1,
  2175. LINK: 2,
  2176. FREETEXT: 3,
  2177. LINE: 4,
  2178. SQUARE: 5,
  2179. CIRCLE: 6,
  2180. POLYGON: 7,
  2181. POLYLINE: 8,
  2182. HIGHLIGHT: 9,
  2183. UNDERLINE: 10,
  2184. SQUIGGLY: 11,
  2185. STRIKEOUT: 12,
  2186. STAMP: 13,
  2187. CARET: 14,
  2188. INK: 15,
  2189. POPUP: 16,
  2190. FILEATTACHMENT: 17,
  2191. SOUND: 18,
  2192. MOVIE: 19,
  2193. WIDGET: 20,
  2194. SCREEN: 21,
  2195. PRINTERMARK: 22,
  2196. TRAPNET: 23,
  2197. WATERMARK: 24,
  2198. THREED: 25,
  2199. REDACT: 26
  2200. };
  2201. var AnnotationFlag = {
  2202. INVISIBLE: 0x01,
  2203. HIDDEN: 0x02,
  2204. PRINT: 0x04,
  2205. NOZOOM: 0x08,
  2206. NOROTATE: 0x10,
  2207. NOVIEW: 0x20,
  2208. READONLY: 0x40,
  2209. LOCKED: 0x80,
  2210. TOGGLENOVIEW: 0x100,
  2211. LOCKEDCONTENTS: 0x200
  2212. };
  2213. var AnnotationBorderStyleType = {
  2214. SOLID: 1,
  2215. DASHED: 2,
  2216. BEVELED: 3,
  2217. INSET: 4,
  2218. UNDERLINE: 5
  2219. };
  2220. var StreamType = {
  2221. UNKNOWN: 0,
  2222. FLATE: 1,
  2223. LZW: 2,
  2224. DCT: 3,
  2225. JPX: 4,
  2226. JBIG: 5,
  2227. A85: 6,
  2228. AHX: 7,
  2229. CCF: 8,
  2230. RL: 9
  2231. };
  2232. var FontType = {
  2233. UNKNOWN: 0,
  2234. TYPE1: 1,
  2235. TYPE1C: 2,
  2236. CIDFONTTYPE0: 3,
  2237. CIDFONTTYPE0C: 4,
  2238. TRUETYPE: 5,
  2239. CIDFONTTYPE2: 6,
  2240. TYPE3: 7,
  2241. OPENTYPE: 8,
  2242. TYPE0: 9,
  2243. MMTYPE1: 10
  2244. };
  2245. PDFJS.VERBOSITY_LEVELS = {
  2246. errors: 0,
  2247. warnings: 1,
  2248. infos: 5
  2249. };
  2250. // All the possible operations for an operator list.
  2251. var OPS = PDFJS.OPS = {
  2252. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2253. // 0's.
  2254. dependency: 1,
  2255. setLineWidth: 2,
  2256. setLineCap: 3,
  2257. setLineJoin: 4,
  2258. setMiterLimit: 5,
  2259. setDash: 6,
  2260. setRenderingIntent: 7,
  2261. setFlatness: 8,
  2262. setGState: 9,
  2263. save: 10,
  2264. restore: 11,
  2265. transform: 12,
  2266. moveTo: 13,
  2267. lineTo: 14,
  2268. curveTo: 15,
  2269. curveTo2: 16,
  2270. curveTo3: 17,
  2271. closePath: 18,
  2272. rectangle: 19,
  2273. stroke: 20,
  2274. closeStroke: 21,
  2275. fill: 22,
  2276. eoFill: 23,
  2277. fillStroke: 24,
  2278. eoFillStroke: 25,
  2279. closeFillStroke: 26,
  2280. closeEOFillStroke: 27,
  2281. endPath: 28,
  2282. clip: 29,
  2283. eoClip: 30,
  2284. beginText: 31,
  2285. endText: 32,
  2286. setCharSpacing: 33,
  2287. setWordSpacing: 34,
  2288. setHScale: 35,
  2289. setLeading: 36,
  2290. setFont: 37,
  2291. setTextRenderingMode: 38,
  2292. setTextRise: 39,
  2293. moveText: 40,
  2294. setLeadingMoveText: 41,
  2295. setTextMatrix: 42,
  2296. nextLine: 43,
  2297. showText: 44,
  2298. showSpacedText: 45,
  2299. nextLineShowText: 46,
  2300. nextLineSetSpacingShowText: 47,
  2301. setCharWidth: 48,
  2302. setCharWidthAndBounds: 49,
  2303. setStrokeColorSpace: 50,
  2304. setFillColorSpace: 51,
  2305. setStrokeColor: 52,
  2306. setStrokeColorN: 53,
  2307. setFillColor: 54,
  2308. setFillColorN: 55,
  2309. setStrokeGray: 56,
  2310. setFillGray: 57,
  2311. setStrokeRGBColor: 58,
  2312. setFillRGBColor: 59,
  2313. setStrokeCMYKColor: 60,
  2314. setFillCMYKColor: 61,
  2315. shadingFill: 62,
  2316. beginInlineImage: 63,
  2317. beginImageData: 64,
  2318. endInlineImage: 65,
  2319. paintXObject: 66,
  2320. markPoint: 67,
  2321. markPointProps: 68,
  2322. beginMarkedContent: 69,
  2323. beginMarkedContentProps: 70,
  2324. endMarkedContent: 71,
  2325. beginCompat: 72,
  2326. endCompat: 73,
  2327. paintFormXObjectBegin: 74,
  2328. paintFormXObjectEnd: 75,
  2329. beginGroup: 76,
  2330. endGroup: 77,
  2331. beginAnnotations: 78,
  2332. endAnnotations: 79,
  2333. beginAnnotation: 80,
  2334. endAnnotation: 81,
  2335. paintJpegXObject: 82,
  2336. paintImageMaskXObject: 83,
  2337. paintImageMaskXObjectGroup: 84,
  2338. paintImageXObject: 85,
  2339. paintInlineImageXObject: 86,
  2340. paintInlineImageXObjectGroup: 87,
  2341. paintImageXObjectRepeat: 88,
  2342. paintImageMaskXObjectRepeat: 89,
  2343. paintSolidColorImageMask: 90,
  2344. constructPath: 91
  2345. };
  2346. // A notice for devs. These are good for things that are helpful to devs, such
  2347. // as warning that Workers were disabled, which is important to devs but not
  2348. // end users.
  2349. function info(msg) {
  2350. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  2351. console.log('Info: ' + msg);
  2352. }
  2353. }
  2354. // Non-fatal warnings.
  2355. function warn(msg) {
  2356. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  2357. console.log('Warning: ' + msg);
  2358. }
  2359. }
  2360. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2361. function deprecated(details) {
  2362. console.log('Deprecated API usage: ' + details);
  2363. }
  2364. // Fatal errors that should trigger the fallback UI and halt execution by
  2365. // throwing an exception.
  2366. function error(msg) {
  2367. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  2368. console.log('Error: ' + msg);
  2369. console.log(backtrace());
  2370. }
  2371. throw new Error(msg);
  2372. }
  2373. function backtrace() {
  2374. try {
  2375. throw new Error();
  2376. } catch (e) {
  2377. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2378. }
  2379. }
  2380. function assert(cond, msg) {
  2381. if (!cond) {
  2382. error(msg);
  2383. }
  2384. }
  2385. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  2386. unknown: 'unknown',
  2387. forms: 'forms',
  2388. javaScript: 'javaScript',
  2389. smask: 'smask',
  2390. shadingPattern: 'shadingPattern',
  2391. font: 'font'
  2392. };
  2393. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  2394. // absolute URL, it will be returned as is.
  2395. function combineUrl(baseUrl, url) {
  2396. if (!url) {
  2397. return baseUrl;
  2398. }
  2399. return new URL(url, baseUrl).href;
  2400. }
  2401. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2402. function isSameOrigin(baseUrl, otherUrl) {
  2403. try {
  2404. var base = new URL(baseUrl);
  2405. if (!base.origin || base.origin === 'null') {
  2406. return false; // non-HTTP url
  2407. }
  2408. } catch (e) {
  2409. return false;
  2410. }
  2411. var other = new URL(otherUrl, base);
  2412. return base.origin === other.origin;
  2413. }
  2414. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2415. function isValidUrl(url, allowRelative) {
  2416. if (!url) {
  2417. return false;
  2418. }
  2419. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2420. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2421. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2422. if (!protocol) {
  2423. return allowRelative;
  2424. }
  2425. protocol = protocol[0].toLowerCase();
  2426. switch (protocol) {
  2427. case 'http':
  2428. case 'https':
  2429. case 'ftp':
  2430. case 'mailto':
  2431. case 'tel':
  2432. return true;
  2433. default:
  2434. return false;
  2435. }
  2436. }
  2437. PDFJS.isValidUrl = isValidUrl;
  2438. /**
  2439. * Adds various attributes (href, title, target, rel) to hyperlinks.
  2440. * @param {HTMLLinkElement} link - The link element.
  2441. * @param {Object} params - An object with the properties:
  2442. * @param {string} params.url - An absolute URL.
  2443. */
  2444. function addLinkAttributes(link, params) {
  2445. var url = params && params.url;
  2446. link.href = link.title = (url ? removeNullCharacters(url) : '');
  2447. if (url) {
  2448. if (isExternalLinkTargetSet()) {
  2449. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  2450. }
  2451. // Strip referrer from the URL.
  2452. link.rel = PDFJS.externalLinkRel;
  2453. }
  2454. }
  2455. PDFJS.addLinkAttributes = addLinkAttributes;
  2456. function shadow(obj, prop, value) {
  2457. Object.defineProperty(obj, prop, { value: value,
  2458. enumerable: true,
  2459. configurable: true,
  2460. writable: false });
  2461. return value;
  2462. }
  2463. PDFJS.shadow = shadow;
  2464. function getLookupTableFactory(initializer) {
  2465. var lookup;
  2466. return function () {
  2467. if (initializer) {
  2468. lookup = Object.create(null);
  2469. initializer(lookup);
  2470. initializer = null;
  2471. }
  2472. return lookup;
  2473. };
  2474. }
  2475. var LinkTarget = PDFJS.LinkTarget = {
  2476. NONE: 0, // Default value.
  2477. SELF: 1,
  2478. BLANK: 2,
  2479. PARENT: 3,
  2480. TOP: 4,
  2481. };
  2482. var LinkTargetStringMap = [
  2483. '',
  2484. '_self',
  2485. '_blank',
  2486. '_parent',
  2487. '_top'
  2488. ];
  2489. function isExternalLinkTargetSet() {
  2490. if (PDFJS.openExternalLinksInNewWindow) {
  2491. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  2492. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  2493. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  2494. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  2495. }
  2496. // Reset the deprecated parameter, to suppress further warnings.
  2497. PDFJS.openExternalLinksInNewWindow = false;
  2498. }
  2499. switch (PDFJS.externalLinkTarget) {
  2500. case LinkTarget.NONE:
  2501. return false;
  2502. case LinkTarget.SELF:
  2503. case LinkTarget.BLANK:
  2504. case LinkTarget.PARENT:
  2505. case LinkTarget.TOP:
  2506. return true;
  2507. }
  2508. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  2509. // Reset the external link target, to suppress further warnings.
  2510. PDFJS.externalLinkTarget = LinkTarget.NONE;
  2511. return false;
  2512. }
  2513. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  2514. var PasswordResponses = PDFJS.PasswordResponses = {
  2515. NEED_PASSWORD: 1,
  2516. INCORRECT_PASSWORD: 2
  2517. };
  2518. var PasswordException = (function PasswordExceptionClosure() {
  2519. function PasswordException(msg, code) {
  2520. this.name = 'PasswordException';
  2521. this.message = msg;
  2522. this.code = code;
  2523. }
  2524. PasswordException.prototype = new Error();
  2525. PasswordException.constructor = PasswordException;
  2526. return PasswordException;
  2527. })();
  2528. PDFJS.PasswordException = PasswordException;
  2529. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2530. function UnknownErrorException(msg, details) {
  2531. this.name = 'UnknownErrorException';
  2532. this.message = msg;
  2533. this.details = details;
  2534. }
  2535. UnknownErrorException.prototype = new Error();
  2536. UnknownErrorException.constructor = UnknownErrorException;
  2537. return UnknownErrorException;
  2538. })();
  2539. PDFJS.UnknownErrorException = UnknownErrorException;
  2540. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2541. function InvalidPDFException(msg) {
  2542. this.name = 'InvalidPDFException';
  2543. this.message = msg;
  2544. }
  2545. InvalidPDFException.prototype = new Error();
  2546. InvalidPDFException.constructor = InvalidPDFException;
  2547. return InvalidPDFException;
  2548. })();
  2549. PDFJS.InvalidPDFException = InvalidPDFException;
  2550. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2551. function MissingPDFException(msg) {
  2552. this.name = 'MissingPDFException';
  2553. this.message = msg;
  2554. }
  2555. MissingPDFException.prototype = new Error();
  2556. MissingPDFException.constructor = MissingPDFException;
  2557. return MissingPDFException;
  2558. })();
  2559. PDFJS.MissingPDFException = MissingPDFException;
  2560. var UnexpectedResponseException =
  2561. (function UnexpectedResponseExceptionClosure() {
  2562. function UnexpectedResponseException(msg, status) {
  2563. this.name = 'UnexpectedResponseException';
  2564. this.message = msg;
  2565. this.status = status;
  2566. }
  2567. UnexpectedResponseException.prototype = new Error();
  2568. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2569. return UnexpectedResponseException;
  2570. })();
  2571. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  2572. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2573. function NotImplementedException(msg) {
  2574. this.message = msg;
  2575. }
  2576. NotImplementedException.prototype = new Error();
  2577. NotImplementedException.prototype.name = 'NotImplementedException';
  2578. NotImplementedException.constructor = NotImplementedException;
  2579. return NotImplementedException;
  2580. })();
  2581. var MissingDataException = (function MissingDataExceptionClosure() {
  2582. function MissingDataException(begin, end) {
  2583. this.begin = begin;
  2584. this.end = end;
  2585. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2586. }
  2587. MissingDataException.prototype = new Error();
  2588. MissingDataException.prototype.name = 'MissingDataException';
  2589. MissingDataException.constructor = MissingDataException;
  2590. return MissingDataException;
  2591. })();
  2592. var XRefParseException = (function XRefParseExceptionClosure() {
  2593. function XRefParseException(msg) {
  2594. this.message = msg;
  2595. }
  2596. XRefParseException.prototype = new Error();
  2597. XRefParseException.prototype.name = 'XRefParseException';
  2598. XRefParseException.constructor = XRefParseException;
  2599. return XRefParseException;
  2600. })();
  2601. var NullCharactersRegExp = /\x00/g;
  2602. function removeNullCharacters(str) {
  2603. if (typeof str !== 'string') {
  2604. warn('The argument for removeNullCharacters must be a string.');
  2605. return str;
  2606. }
  2607. return str.replace(NullCharactersRegExp, '');
  2608. }
  2609. PDFJS.removeNullCharacters = removeNullCharacters;
  2610. function bytesToString(bytes) {
  2611. assert(bytes !== null && typeof bytes === 'object' &&
  2612. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2613. var length = bytes.length;
  2614. var MAX_ARGUMENT_COUNT = 8192;
  2615. if (length < MAX_ARGUMENT_COUNT) {
  2616. return String.fromCharCode.apply(null, bytes);
  2617. }
  2618. var strBuf = [];
  2619. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2620. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2621. var chunk = bytes.subarray(i, chunkEnd);
  2622. strBuf.push(String.fromCharCode.apply(null, chunk));
  2623. }
  2624. return strBuf.join('');
  2625. }
  2626. function stringToBytes(str) {
  2627. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2628. var length = str.length;
  2629. var bytes = new Uint8Array(length);
  2630. for (var i = 0; i < length; ++i) {
  2631. bytes[i] = str.charCodeAt(i) & 0xFF;
  2632. }
  2633. return bytes;
  2634. }
  2635. function string32(value) {
  2636. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2637. (value >> 8) & 0xff, value & 0xff);
  2638. }
  2639. function log2(x) {
  2640. var n = 1, i = 0;
  2641. while (x > n) {
  2642. n <<= 1;
  2643. i++;
  2644. }
  2645. return i;
  2646. }
  2647. function readInt8(data, start) {
  2648. return (data[start] << 24) >> 24;
  2649. }
  2650. function readUint16(data, offset) {
  2651. return (data[offset] << 8) | data[offset + 1];
  2652. }
  2653. function readUint32(data, offset) {
  2654. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2655. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2656. }
  2657. // Lazy test the endianness of the platform
  2658. // NOTE: This will be 'true' for simulated TypedArrays
  2659. function isLittleEndian() {
  2660. var buffer8 = new Uint8Array(2);
  2661. buffer8[0] = 1;
  2662. var buffer16 = new Uint16Array(buffer8.buffer);
  2663. return (buffer16[0] === 1);
  2664. }
  2665. Object.defineProperty(PDFJS, 'isLittleEndian', {
  2666. configurable: true,
  2667. get: function PDFJS_isLittleEndian() {
  2668. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  2669. }
  2670. });
  2671. // Lazy test if the userAgent support CanvasTypedArrays
  2672. function hasCanvasTypedArrays() {
  2673. var canvas = document.createElement('canvas');
  2674. canvas.width = canvas.height = 1;
  2675. var ctx = canvas.getContext('2d');
  2676. var imageData = ctx.createImageData(1, 1);
  2677. return (typeof imageData.data.buffer !== 'undefined');
  2678. }
  2679. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  2680. configurable: true,
  2681. get: function PDFJS_hasCanvasTypedArrays() {
  2682. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  2683. }
  2684. });
  2685. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2686. function Uint32ArrayView(buffer, length) {
  2687. this.buffer = buffer;
  2688. this.byteLength = buffer.length;
  2689. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2690. ensureUint32ArrayViewProps(this.length);
  2691. }
  2692. Uint32ArrayView.prototype = Object.create(null);
  2693. var uint32ArrayViewSetters = 0;
  2694. function createUint32ArrayProp(index) {
  2695. return {
  2696. get: function () {
  2697. var buffer = this.buffer, offset = index << 2;
  2698. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2699. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2700. },
  2701. set: function (value) {
  2702. var buffer = this.buffer, offset = index << 2;
  2703. buffer[offset] = value & 255;
  2704. buffer[offset + 1] = (value >> 8) & 255;
  2705. buffer[offset + 2] = (value >> 16) & 255;
  2706. buffer[offset + 3] = (value >>> 24) & 255;
  2707. }
  2708. };
  2709. }
  2710. function ensureUint32ArrayViewProps(length) {
  2711. while (uint32ArrayViewSetters < length) {
  2712. Object.defineProperty(Uint32ArrayView.prototype,
  2713. uint32ArrayViewSetters,
  2714. createUint32ArrayProp(uint32ArrayViewSetters));
  2715. uint32ArrayViewSetters++;
  2716. }
  2717. }
  2718. return Uint32ArrayView;
  2719. })();
  2720. exports.Uint32ArrayView = Uint32ArrayView;
  2721. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2722. var Util = PDFJS.Util = (function UtilClosure() {
  2723. function Util() {}
  2724. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2725. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2726. // creating many intermediate strings.
  2727. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2728. rgbBuf[1] = r;
  2729. rgbBuf[3] = g;
  2730. rgbBuf[5] = b;
  2731. return rgbBuf.join('');
  2732. };
  2733. // Concatenates two transformation matrices together and returns the result.
  2734. Util.transform = function Util_transform(m1, m2) {
  2735. return [
  2736. m1[0] * m2[0] + m1[2] * m2[1],
  2737. m1[1] * m2[0] + m1[3] * m2[1],
  2738. m1[0] * m2[2] + m1[2] * m2[3],
  2739. m1[1] * m2[2] + m1[3] * m2[3],
  2740. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2741. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2742. ];
  2743. };
  2744. // For 2d affine transforms
  2745. Util.applyTransform = function Util_applyTransform(p, m) {
  2746. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2747. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2748. return [xt, yt];
  2749. };
  2750. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2751. var d = m[0] * m[3] - m[1] * m[2];
  2752. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2753. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2754. return [xt, yt];
  2755. };
  2756. // Applies the transform to the rectangle and finds the minimum axially
  2757. // aligned bounding box.
  2758. Util.getAxialAlignedBoundingBox =
  2759. function Util_getAxialAlignedBoundingBox(r, m) {
  2760. var p1 = Util.applyTransform(r, m);
  2761. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2762. var p3 = Util.applyTransform([r[0], r[3]], m);
  2763. var p4 = Util.applyTransform([r[2], r[1]], m);
  2764. return [
  2765. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2766. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2767. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2768. Math.max(p1[1], p2[1], p3[1], p4[1])
  2769. ];
  2770. };
  2771. Util.inverseTransform = function Util_inverseTransform(m) {
  2772. var d = m[0] * m[3] - m[1] * m[2];
  2773. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2774. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2775. };
  2776. // Apply a generic 3d matrix M on a 3-vector v:
  2777. // | a b c | | X |
  2778. // | d e f | x | Y |
  2779. // | g h i | | Z |
  2780. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2781. // with v as [X,Y,Z]
  2782. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2783. return [
  2784. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2785. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2786. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2787. ];
  2788. };
  2789. // This calculation uses Singular Value Decomposition.
  2790. // The SVD can be represented with formula A = USV. We are interested in the
  2791. // matrix S here because it represents the scale values.
  2792. Util.singularValueDecompose2dScale =
  2793. function Util_singularValueDecompose2dScale(m) {
  2794. var transpose = [m[0], m[2], m[1], m[3]];
  2795. // Multiply matrix m with its transpose.
  2796. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2797. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2798. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2799. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2800. // Solve the second degree polynomial to get roots.
  2801. var first = (a + d) / 2;
  2802. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2803. var sx = first + second || 1;
  2804. var sy = first - second || 1;
  2805. // Scale values are the square roots of the eigenvalues.
  2806. return [Math.sqrt(sx), Math.sqrt(sy)];
  2807. };
  2808. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2809. // For coordinate systems whose origin lies in the bottom-left, this
  2810. // means normalization to (BL,TR) ordering. For systems with origin in the
  2811. // top-left, this means (TL,BR) ordering.
  2812. Util.normalizeRect = function Util_normalizeRect(rect) {
  2813. var r = rect.slice(0); // clone rect
  2814. if (rect[0] > rect[2]) {
  2815. r[0] = rect[2];
  2816. r[2] = rect[0];
  2817. }
  2818. if (rect[1] > rect[3]) {
  2819. r[1] = rect[3];
  2820. r[3] = rect[1];
  2821. }
  2822. return r;
  2823. };
  2824. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2825. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2826. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2827. Util.intersect = function Util_intersect(rect1, rect2) {
  2828. function compare(a, b) {
  2829. return a - b;
  2830. }
  2831. // Order points along the axes
  2832. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2833. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2834. result = [];
  2835. rect1 = Util.normalizeRect(rect1);
  2836. rect2 = Util.normalizeRect(rect2);
  2837. // X: first and second points belong to different rectangles?
  2838. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2839. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2840. // Intersection must be between second and third points
  2841. result[0] = orderedX[1];
  2842. result[2] = orderedX[2];
  2843. } else {
  2844. return false;
  2845. }
  2846. // Y: first and second points belong to different rectangles?
  2847. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2848. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2849. // Intersection must be between second and third points
  2850. result[1] = orderedY[1];
  2851. result[3] = orderedY[2];
  2852. } else {
  2853. return false;
  2854. }
  2855. return result;
  2856. };
  2857. Util.sign = function Util_sign(num) {
  2858. return num < 0 ? -1 : 1;
  2859. };
  2860. var ROMAN_NUMBER_MAP = [
  2861. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2862. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2863. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2864. ];
  2865. /**
  2866. * Converts positive integers to (upper case) Roman numerals.
  2867. * @param {integer} number - The number that should be converted.
  2868. * @param {boolean} lowerCase - Indicates if the result should be converted
  2869. * to lower case letters. The default is false.
  2870. * @return {string} The resulting Roman number.
  2871. */
  2872. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2873. assert(isInt(number) && number > 0,
  2874. 'The number should be a positive integer.');
  2875. var pos, romanBuf = [];
  2876. // Thousands
  2877. while (number >= 1000) {
  2878. number -= 1000;
  2879. romanBuf.push('M');
  2880. }
  2881. // Hundreds
  2882. pos = (number / 100) | 0;
  2883. number %= 100;
  2884. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2885. // Tens
  2886. pos = (number / 10) | 0;
  2887. number %= 10;
  2888. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2889. // Ones
  2890. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2891. var romanStr = romanBuf.join('');
  2892. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2893. };
  2894. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2895. Array.prototype.push.apply(arr1, arr2);
  2896. };
  2897. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2898. Array.prototype.unshift.apply(arr1, arr2);
  2899. };
  2900. Util.extendObj = function extendObj(obj1, obj2) {
  2901. for (var key in obj2) {
  2902. obj1[key] = obj2[key];
  2903. }
  2904. };
  2905. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2906. name) {
  2907. while (dict && !dict.has(name)) {
  2908. dict = dict.get('Parent');
  2909. }
  2910. if (!dict) {
  2911. return null;
  2912. }
  2913. return dict.get(name);
  2914. };
  2915. Util.inherit = function Util_inherit(sub, base, prototype) {
  2916. sub.prototype = Object.create(base.prototype);
  2917. sub.prototype.constructor = sub;
  2918. for (var prop in prototype) {
  2919. sub.prototype[prop] = prototype[prop];
  2920. }
  2921. };
  2922. Util.loadScript = function Util_loadScript(src, callback) {
  2923. var script = document.createElement('script');
  2924. var loaded = false;
  2925. script.setAttribute('src', src);
  2926. if (callback) {
  2927. script.onload = function() {
  2928. if (!loaded) {
  2929. callback();
  2930. }
  2931. loaded = true;
  2932. };
  2933. }
  2934. document.getElementsByTagName('head')[0].appendChild(script);
  2935. };
  2936. return Util;
  2937. })();
  2938. /**
  2939. * PDF page viewport created based on scale, rotation and offset.
  2940. * @class
  2941. * @alias PDFJS.PageViewport
  2942. */
  2943. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  2944. /**
  2945. * @constructor
  2946. * @private
  2947. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  2948. * @param scale {number} scale of the viewport.
  2949. * @param rotation {number} rotations of the viewport in degrees.
  2950. * @param offsetX {number} offset X
  2951. * @param offsetY {number} offset Y
  2952. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  2953. */
  2954. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  2955. this.viewBox = viewBox;
  2956. this.scale = scale;
  2957. this.rotation = rotation;
  2958. this.offsetX = offsetX;
  2959. this.offsetY = offsetY;
  2960. // creating transform to convert pdf coordinate system to the normal
  2961. // canvas like coordinates taking in account scale and rotation
  2962. var centerX = (viewBox[2] + viewBox[0]) / 2;
  2963. var centerY = (viewBox[3] + viewBox[1]) / 2;
  2964. var rotateA, rotateB, rotateC, rotateD;
  2965. rotation = rotation % 360;
  2966. rotation = rotation < 0 ? rotation + 360 : rotation;
  2967. switch (rotation) {
  2968. case 180:
  2969. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  2970. break;
  2971. case 90:
  2972. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  2973. break;
  2974. case 270:
  2975. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  2976. break;
  2977. //case 0:
  2978. default:
  2979. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  2980. break;
  2981. }
  2982. if (dontFlip) {
  2983. rotateC = -rotateC; rotateD = -rotateD;
  2984. }
  2985. var offsetCanvasX, offsetCanvasY;
  2986. var width, height;
  2987. if (rotateA === 0) {
  2988. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2989. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2990. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2991. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2992. } else {
  2993. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2994. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2995. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2996. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2997. }
  2998. // creating transform for the following operations:
  2999. // translate(-centerX, -centerY), rotate and flip vertically,
  3000. // scale, and translate(offsetCanvasX, offsetCanvasY)
  3001. this.transform = [
  3002. rotateA * scale,
  3003. rotateB * scale,
  3004. rotateC * scale,
  3005. rotateD * scale,
  3006. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  3007. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  3008. ];
  3009. this.width = width;
  3010. this.height = height;
  3011. this.fontScale = scale;
  3012. }
  3013. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  3014. /**
  3015. * Clones viewport with additional properties.
  3016. * @param args {Object} (optional) If specified, may contain the 'scale' or
  3017. * 'rotation' properties to override the corresponding properties in
  3018. * the cloned viewport.
  3019. * @returns {PDFJS.PageViewport} Cloned viewport.
  3020. */
  3021. clone: function PageViewPort_clone(args) {
  3022. args = args || {};
  3023. var scale = 'scale' in args ? args.scale : this.scale;
  3024. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  3025. return new PageViewport(this.viewBox.slice(), scale, rotation,
  3026. this.offsetX, this.offsetY, args.dontFlip);
  3027. },
  3028. /**
  3029. * Converts PDF point to the viewport coordinates. For examples, useful for
  3030. * converting PDF location into canvas pixel coordinates.
  3031. * @param x {number} X coordinate.
  3032. * @param y {number} Y coordinate.
  3033. * @returns {Object} Object that contains 'x' and 'y' properties of the
  3034. * point in the viewport coordinate space.
  3035. * @see {@link convertToPdfPoint}
  3036. * @see {@link convertToViewportRectangle}
  3037. */
  3038. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  3039. return Util.applyTransform([x, y], this.transform);
  3040. },
  3041. /**
  3042. * Converts PDF rectangle to the viewport coordinates.
  3043. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  3044. * @returns {Array} Contains corresponding coordinates of the rectangle
  3045. * in the viewport coordinate space.
  3046. * @see {@link convertToViewportPoint}
  3047. */
  3048. convertToViewportRectangle:
  3049. function PageViewport_convertToViewportRectangle(rect) {
  3050. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  3051. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  3052. return [tl[0], tl[1], br[0], br[1]];
  3053. },
  3054. /**
  3055. * Converts viewport coordinates to the PDF location. For examples, useful
  3056. * for converting canvas pixel location into PDF one.
  3057. * @param x {number} X coordinate.
  3058. * @param y {number} Y coordinate.
  3059. * @returns {Object} Object that contains 'x' and 'y' properties of the
  3060. * point in the PDF coordinate space.
  3061. * @see {@link convertToViewportPoint}
  3062. */
  3063. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  3064. return Util.applyInverseTransform([x, y], this.transform);
  3065. }
  3066. };
  3067. return PageViewport;
  3068. })();
  3069. var PDFStringTranslateTable = [
  3070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3071. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  3072. 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,
  3073. 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,
  3074. 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,
  3075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  3076. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  3077. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  3078. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  3079. ];
  3080. function stringToPDFString(str) {
  3081. var i, n = str.length, strBuf = [];
  3082. if (str[0] === '\xFE' && str[1] === '\xFF') {
  3083. // UTF16BE BOM
  3084. for (i = 2; i < n; i += 2) {
  3085. strBuf.push(String.fromCharCode(
  3086. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  3087. }
  3088. } else {
  3089. for (i = 0; i < n; ++i) {
  3090. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  3091. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  3092. }
  3093. }
  3094. return strBuf.join('');
  3095. }
  3096. function stringToUTF8String(str) {
  3097. return decodeURIComponent(escape(str));
  3098. }
  3099. function utf8StringToString(str) {
  3100. return unescape(encodeURIComponent(str));
  3101. }
  3102. function isEmptyObj(obj) {
  3103. for (var key in obj) {
  3104. return false;
  3105. }
  3106. return true;
  3107. }
  3108. function isBool(v) {
  3109. return typeof v === 'boolean';
  3110. }
  3111. function isInt(v) {
  3112. return typeof v === 'number' && ((v | 0) === v);
  3113. }
  3114. function isNum(v) {
  3115. return typeof v === 'number';
  3116. }
  3117. function isString(v) {
  3118. return typeof v === 'string';
  3119. }
  3120. function isArray(v) {
  3121. return v instanceof Array;
  3122. }
  3123. function isArrayBuffer(v) {
  3124. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  3125. }
  3126. /**
  3127. * Promise Capability object.
  3128. *
  3129. * @typedef {Object} PromiseCapability
  3130. * @property {Promise} promise - A promise object.
  3131. * @property {function} resolve - Fullfills the promise.
  3132. * @property {function} reject - Rejects the promise.
  3133. */
  3134. /**
  3135. * Creates a promise capability object.
  3136. * @alias PDFJS.createPromiseCapability
  3137. *
  3138. * @return {PromiseCapability} A capability object contains:
  3139. * - a Promise, resolve and reject methods.
  3140. */
  3141. function createPromiseCapability() {
  3142. var capability = {};
  3143. capability.promise = new Promise(function (resolve, reject) {
  3144. capability.resolve = resolve;
  3145. capability.reject = reject;
  3146. });
  3147. return capability;
  3148. }
  3149. PDFJS.createPromiseCapability = createPromiseCapability;
  3150. /**
  3151. * Polyfill for Promises:
  3152. * The following promise implementation tries to generally implement the
  3153. * Promise/A+ spec. Some notable differences from other promise libaries are:
  3154. * - There currently isn't a seperate deferred and promise object.
  3155. * - Unhandled rejections eventually show an error if they aren't handled.
  3156. *
  3157. * Based off of the work in:
  3158. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  3159. */
  3160. (function PromiseClosure() {
  3161. if (globalScope.Promise) {
  3162. // Promises existing in the DOM/Worker, checking presence of all/resolve
  3163. if (typeof globalScope.Promise.all !== 'function') {
  3164. globalScope.Promise.all = function (iterable) {
  3165. var count = 0, results = [], resolve, reject;
  3166. var promise = new globalScope.Promise(function (resolve_, reject_) {
  3167. resolve = resolve_;
  3168. reject = reject_;
  3169. });
  3170. iterable.forEach(function (p, i) {
  3171. count++;
  3172. p.then(function (result) {
  3173. results[i] = result;
  3174. count--;
  3175. if (count === 0) {
  3176. resolve(results);
  3177. }
  3178. }, reject);
  3179. });
  3180. if (count === 0) {
  3181. resolve(results);
  3182. }
  3183. return promise;
  3184. };
  3185. }
  3186. if (typeof globalScope.Promise.resolve !== 'function') {
  3187. globalScope.Promise.resolve = function (value) {
  3188. return new globalScope.Promise(function (resolve) { resolve(value); });
  3189. };
  3190. }
  3191. if (typeof globalScope.Promise.reject !== 'function') {
  3192. globalScope.Promise.reject = function (reason) {
  3193. return new globalScope.Promise(function (resolve, reject) {
  3194. reject(reason);
  3195. });
  3196. };
  3197. }
  3198. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  3199. globalScope.Promise.prototype.catch = function (onReject) {
  3200. return globalScope.Promise.prototype.then(undefined, onReject);
  3201. };
  3202. }
  3203. return;
  3204. }
  3205. var STATUS_PENDING = 0;
  3206. var STATUS_RESOLVED = 1;
  3207. var STATUS_REJECTED = 2;
  3208. // In an attempt to avoid silent exceptions, unhandled rejections are
  3209. // tracked and if they aren't handled in a certain amount of time an
  3210. // error is logged.
  3211. var REJECTION_TIMEOUT = 500;
  3212. var HandlerManager = {
  3213. handlers: [],
  3214. running: false,
  3215. unhandledRejections: [],
  3216. pendingRejectionCheck: false,
  3217. scheduleHandlers: function scheduleHandlers(promise) {
  3218. if (promise._status === STATUS_PENDING) {
  3219. return;
  3220. }
  3221. this.handlers = this.handlers.concat(promise._handlers);
  3222. promise._handlers = [];
  3223. if (this.running) {
  3224. return;
  3225. }
  3226. this.running = true;
  3227. setTimeout(this.runHandlers.bind(this), 0);
  3228. },
  3229. runHandlers: function runHandlers() {
  3230. var RUN_TIMEOUT = 1; // ms
  3231. var timeoutAt = Date.now() + RUN_TIMEOUT;
  3232. while (this.handlers.length > 0) {
  3233. var handler = this.handlers.shift();
  3234. var nextStatus = handler.thisPromise._status;
  3235. var nextValue = handler.thisPromise._value;
  3236. try {
  3237. if (nextStatus === STATUS_RESOLVED) {
  3238. if (typeof handler.onResolve === 'function') {
  3239. nextValue = handler.onResolve(nextValue);
  3240. }
  3241. } else if (typeof handler.onReject === 'function') {
  3242. nextValue = handler.onReject(nextValue);
  3243. nextStatus = STATUS_RESOLVED;
  3244. if (handler.thisPromise._unhandledRejection) {
  3245. this.removeUnhandeledRejection(handler.thisPromise);
  3246. }
  3247. }
  3248. } catch (ex) {
  3249. nextStatus = STATUS_REJECTED;
  3250. nextValue = ex;
  3251. }
  3252. handler.nextPromise._updateStatus(nextStatus, nextValue);
  3253. if (Date.now() >= timeoutAt) {
  3254. break;
  3255. }
  3256. }
  3257. if (this.handlers.length > 0) {
  3258. setTimeout(this.runHandlers.bind(this), 0);
  3259. return;
  3260. }
  3261. this.running = false;
  3262. },
  3263. addUnhandledRejection: function addUnhandledRejection(promise) {
  3264. this.unhandledRejections.push({
  3265. promise: promise,
  3266. time: Date.now()
  3267. });
  3268. this.scheduleRejectionCheck();
  3269. },
  3270. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  3271. promise._unhandledRejection = false;
  3272. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3273. if (this.unhandledRejections[i].promise === promise) {
  3274. this.unhandledRejections.splice(i);
  3275. i--;
  3276. }
  3277. }
  3278. },
  3279. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3280. if (this.pendingRejectionCheck) {
  3281. return;
  3282. }
  3283. this.pendingRejectionCheck = true;
  3284. setTimeout(function rejectionCheck() {
  3285. this.pendingRejectionCheck = false;
  3286. var now = Date.now();
  3287. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3288. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3289. var unhandled = this.unhandledRejections[i].promise._value;
  3290. var msg = 'Unhandled rejection: ' + unhandled;
  3291. if (unhandled.stack) {
  3292. msg += '\n' + unhandled.stack;
  3293. }
  3294. warn(msg);
  3295. this.unhandledRejections.splice(i);
  3296. i--;
  3297. }
  3298. }
  3299. if (this.unhandledRejections.length) {
  3300. this.scheduleRejectionCheck();
  3301. }
  3302. }.bind(this), REJECTION_TIMEOUT);
  3303. }
  3304. };
  3305. function Promise(resolver) {
  3306. this._status = STATUS_PENDING;
  3307. this._handlers = [];
  3308. try {
  3309. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3310. } catch (e) {
  3311. this._reject(e);
  3312. }
  3313. }
  3314. /**
  3315. * Builds a promise that is resolved when all the passed in promises are
  3316. * resolved.
  3317. * @param {array} array of data and/or promises to wait for.
  3318. * @return {Promise} New dependant promise.
  3319. */
  3320. Promise.all = function Promise_all(promises) {
  3321. var resolveAll, rejectAll;
  3322. var deferred = new Promise(function (resolve, reject) {
  3323. resolveAll = resolve;
  3324. rejectAll = reject;
  3325. });
  3326. var unresolved = promises.length;
  3327. var results = [];
  3328. if (unresolved === 0) {
  3329. resolveAll(results);
  3330. return deferred;
  3331. }
  3332. function reject(reason) {
  3333. if (deferred._status === STATUS_REJECTED) {
  3334. return;
  3335. }
  3336. results = [];
  3337. rejectAll(reason);
  3338. }
  3339. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3340. var promise = promises[i];
  3341. var resolve = (function(i) {
  3342. return function(value) {
  3343. if (deferred._status === STATUS_REJECTED) {
  3344. return;
  3345. }
  3346. results[i] = value;
  3347. unresolved--;
  3348. if (unresolved === 0) {
  3349. resolveAll(results);
  3350. }
  3351. };
  3352. })(i);
  3353. if (Promise.isPromise(promise)) {
  3354. promise.then(resolve, reject);
  3355. } else {
  3356. resolve(promise);
  3357. }
  3358. }
  3359. return deferred;
  3360. };
  3361. /**
  3362. * Checks if the value is likely a promise (has a 'then' function).
  3363. * @return {boolean} true if value is thenable
  3364. */
  3365. Promise.isPromise = function Promise_isPromise(value) {
  3366. return value && typeof value.then === 'function';
  3367. };
  3368. /**
  3369. * Creates resolved promise
  3370. * @param value resolve value
  3371. * @returns {Promise}
  3372. */
  3373. Promise.resolve = function Promise_resolve(value) {
  3374. return new Promise(function (resolve) { resolve(value); });
  3375. };
  3376. /**
  3377. * Creates rejected promise
  3378. * @param reason rejection value
  3379. * @returns {Promise}
  3380. */
  3381. Promise.reject = function Promise_reject(reason) {
  3382. return new Promise(function (resolve, reject) { reject(reason); });
  3383. };
  3384. Promise.prototype = {
  3385. _status: null,
  3386. _value: null,
  3387. _handlers: null,
  3388. _unhandledRejection: null,
  3389. _updateStatus: function Promise__updateStatus(status, value) {
  3390. if (this._status === STATUS_RESOLVED ||
  3391. this._status === STATUS_REJECTED) {
  3392. return;
  3393. }
  3394. if (status === STATUS_RESOLVED &&
  3395. Promise.isPromise(value)) {
  3396. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3397. this._updateStatus.bind(this, STATUS_REJECTED));
  3398. return;
  3399. }
  3400. this._status = status;
  3401. this._value = value;
  3402. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3403. this._unhandledRejection = true;
  3404. HandlerManager.addUnhandledRejection(this);
  3405. }
  3406. HandlerManager.scheduleHandlers(this);
  3407. },
  3408. _resolve: function Promise_resolve(value) {
  3409. this._updateStatus(STATUS_RESOLVED, value);
  3410. },
  3411. _reject: function Promise_reject(reason) {
  3412. this._updateStatus(STATUS_REJECTED, reason);
  3413. },
  3414. then: function Promise_then(onResolve, onReject) {
  3415. var nextPromise = new Promise(function (resolve, reject) {
  3416. this.resolve = resolve;
  3417. this.reject = reject;
  3418. });
  3419. this._handlers.push({
  3420. thisPromise: this,
  3421. onResolve: onResolve,
  3422. onReject: onReject,
  3423. nextPromise: nextPromise
  3424. });
  3425. HandlerManager.scheduleHandlers(this);
  3426. return nextPromise;
  3427. },
  3428. catch: function Promise_catch(onReject) {
  3429. return this.then(undefined, onReject);
  3430. }
  3431. };
  3432. globalScope.Promise = Promise;
  3433. })();
  3434. var StatTimer = (function StatTimerClosure() {
  3435. function rpad(str, pad, length) {
  3436. while (str.length < length) {
  3437. str += pad;
  3438. }
  3439. return str;
  3440. }
  3441. function StatTimer() {
  3442. this.started = Object.create(null);
  3443. this.times = [];
  3444. this.enabled = true;
  3445. }
  3446. StatTimer.prototype = {
  3447. time: function StatTimer_time(name) {
  3448. if (!this.enabled) {
  3449. return;
  3450. }
  3451. if (name in this.started) {
  3452. warn('Timer is already running for ' + name);
  3453. }
  3454. this.started[name] = Date.now();
  3455. },
  3456. timeEnd: function StatTimer_timeEnd(name) {
  3457. if (!this.enabled) {
  3458. return;
  3459. }
  3460. if (!(name in this.started)) {
  3461. warn('Timer has not been started for ' + name);
  3462. }
  3463. this.times.push({
  3464. 'name': name,
  3465. 'start': this.started[name],
  3466. 'end': Date.now()
  3467. });
  3468. // Remove timer from started so it can be called again.
  3469. delete this.started[name];
  3470. },
  3471. toString: function StatTimer_toString() {
  3472. var i, ii;
  3473. var times = this.times;
  3474. var out = '';
  3475. // Find the longest name for padding purposes.
  3476. var longest = 0;
  3477. for (i = 0, ii = times.length; i < ii; ++i) {
  3478. var name = times[i]['name'];
  3479. if (name.length > longest) {
  3480. longest = name.length;
  3481. }
  3482. }
  3483. for (i = 0, ii = times.length; i < ii; ++i) {
  3484. var span = times[i];
  3485. var duration = span.end - span.start;
  3486. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3487. }
  3488. return out;
  3489. }
  3490. };
  3491. return StatTimer;
  3492. })();
  3493. PDFJS.createBlob = function createBlob(data, contentType) {
  3494. if (typeof Blob !== 'undefined') {
  3495. return new Blob([data], { type: contentType });
  3496. }
  3497. // Blob builder is deprecated in FF14 and removed in FF18.
  3498. var bb = new MozBlobBuilder();
  3499. bb.append(data);
  3500. return bb.getBlob(contentType);
  3501. };
  3502. PDFJS.createObjectURL = (function createObjectURLClosure() {
  3503. // Blob/createObjectURL is not available, falling back to data schema.
  3504. var digits =
  3505. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3506. return function createObjectURL(data, contentType) {
  3507. if (!PDFJS.disableCreateObjectURL &&
  3508. typeof URL !== 'undefined' && URL.createObjectURL) {
  3509. var blob = PDFJS.createBlob(data, contentType);
  3510. return URL.createObjectURL(blob);
  3511. }
  3512. var buffer = 'data:' + contentType + ';base64,';
  3513. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3514. var b1 = data[i] & 0xFF;
  3515. var b2 = data[i + 1] & 0xFF;
  3516. var b3 = data[i + 2] & 0xFF;
  3517. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3518. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3519. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3520. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3521. }
  3522. return buffer;
  3523. };
  3524. })();
  3525. function MessageHandler(sourceName, targetName, comObj) {
  3526. this.sourceName = sourceName;
  3527. this.targetName = targetName;
  3528. this.comObj = comObj;
  3529. this.callbackIndex = 1;
  3530. this.postMessageTransfers = true;
  3531. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3532. var ah = this.actionHandler = Object.create(null);
  3533. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3534. var data = event.data;
  3535. if (data.targetName !== this.sourceName) {
  3536. return;
  3537. }
  3538. if (data.isReply) {
  3539. var callbackId = data.callbackId;
  3540. if (data.callbackId in callbacksCapabilities) {
  3541. var callback = callbacksCapabilities[callbackId];
  3542. delete callbacksCapabilities[callbackId];
  3543. if ('error' in data) {
  3544. callback.reject(data.error);
  3545. } else {
  3546. callback.resolve(data.data);
  3547. }
  3548. } else {
  3549. error('Cannot resolve callback ' + callbackId);
  3550. }
  3551. } else if (data.action in ah) {
  3552. var action = ah[data.action];
  3553. if (data.callbackId) {
  3554. var sourceName = this.sourceName;
  3555. var targetName = data.sourceName;
  3556. Promise.resolve().then(function () {
  3557. return action[0].call(action[1], data.data);
  3558. }).then(function (result) {
  3559. comObj.postMessage({
  3560. sourceName: sourceName,
  3561. targetName: targetName,
  3562. isReply: true,
  3563. callbackId: data.callbackId,
  3564. data: result
  3565. });
  3566. }, function (reason) {
  3567. if (reason instanceof Error) {
  3568. // Serialize error to avoid "DataCloneError"
  3569. reason = reason + '';
  3570. }
  3571. comObj.postMessage({
  3572. sourceName: sourceName,
  3573. targetName: targetName,
  3574. isReply: true,
  3575. callbackId: data.callbackId,
  3576. error: reason
  3577. });
  3578. });
  3579. } else {
  3580. action[0].call(action[1], data.data);
  3581. }
  3582. } else {
  3583. error('Unknown action from worker: ' + data.action);
  3584. }
  3585. }.bind(this);
  3586. comObj.addEventListener('message', this._onComObjOnMessage);
  3587. }
  3588. MessageHandler.prototype = {
  3589. on: function messageHandlerOn(actionName, handler, scope) {
  3590. var ah = this.actionHandler;
  3591. if (ah[actionName]) {
  3592. error('There is already an actionName called "' + actionName + '"');
  3593. }
  3594. ah[actionName] = [handler, scope];
  3595. },
  3596. /**
  3597. * Sends a message to the comObj to invoke the action with the supplied data.
  3598. * @param {String} actionName Action to call.
  3599. * @param {JSON} data JSON data to send.
  3600. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3601. */
  3602. send: function messageHandlerSend(actionName, data, transfers) {
  3603. var message = {
  3604. sourceName: this.sourceName,
  3605. targetName: this.targetName,
  3606. action: actionName,
  3607. data: data
  3608. };
  3609. this.postMessage(message, transfers);
  3610. },
  3611. /**
  3612. * Sends a message to the comObj to invoke the action with the supplied data.
  3613. * Expects that other side will callback with the response.
  3614. * @param {String} actionName Action to call.
  3615. * @param {JSON} data JSON data to send.
  3616. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3617. * @returns {Promise} Promise to be resolved with response data.
  3618. */
  3619. sendWithPromise:
  3620. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3621. var callbackId = this.callbackIndex++;
  3622. var message = {
  3623. sourceName: this.sourceName,
  3624. targetName: this.targetName,
  3625. action: actionName,
  3626. data: data,
  3627. callbackId: callbackId
  3628. };
  3629. var capability = createPromiseCapability();
  3630. this.callbacksCapabilities[callbackId] = capability;
  3631. try {
  3632. this.postMessage(message, transfers);
  3633. } catch (e) {
  3634. capability.reject(e);
  3635. }
  3636. return capability.promise;
  3637. },
  3638. /**
  3639. * Sends raw message to the comObj.
  3640. * @private
  3641. * @param message {Object} Raw message.
  3642. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3643. */
  3644. postMessage: function (message, transfers) {
  3645. if (transfers && this.postMessageTransfers) {
  3646. this.comObj.postMessage(message, transfers);
  3647. } else {
  3648. this.comObj.postMessage(message);
  3649. }
  3650. },
  3651. destroy: function () {
  3652. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3653. }
  3654. };
  3655. function loadJpegStream(id, imageUrl, objs) {
  3656. var img = new Image();
  3657. img.onload = (function loadJpegStream_onloadClosure() {
  3658. objs.resolve(id, img);
  3659. });
  3660. img.onerror = (function loadJpegStream_onerrorClosure() {
  3661. objs.resolve(id, null);
  3662. warn('Error during JPEG image loading');
  3663. });
  3664. img.src = imageUrl;
  3665. }
  3666. // Polyfill from https://github.com/Polymer/URL
  3667. /* Any copyright is dedicated to the Public Domain.
  3668. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3669. (function checkURLConstructor(scope) {
  3670. /* jshint ignore:start */
  3671. // feature detect for URL constructor
  3672. var hasWorkingUrl = false;
  3673. try {
  3674. if (typeof URL === 'function' &&
  3675. typeof URL.prototype === 'object' &&
  3676. ('origin' in URL.prototype)) {
  3677. var u = new URL('b', 'http://a');
  3678. u.pathname = 'c%20d';
  3679. hasWorkingUrl = u.href === 'http://a/c%20d';
  3680. }
  3681. } catch(e) { }
  3682. if (hasWorkingUrl)
  3683. return;
  3684. var relative = Object.create(null);
  3685. relative['ftp'] = 21;
  3686. relative['file'] = 0;
  3687. relative['gopher'] = 70;
  3688. relative['http'] = 80;
  3689. relative['https'] = 443;
  3690. relative['ws'] = 80;
  3691. relative['wss'] = 443;
  3692. var relativePathDotMapping = Object.create(null);
  3693. relativePathDotMapping['%2e'] = '.';
  3694. relativePathDotMapping['.%2e'] = '..';
  3695. relativePathDotMapping['%2e.'] = '..';
  3696. relativePathDotMapping['%2e%2e'] = '..';
  3697. function isRelativeScheme(scheme) {
  3698. return relative[scheme] !== undefined;
  3699. }
  3700. function invalid() {
  3701. clear.call(this);
  3702. this._isInvalid = true;
  3703. }
  3704. function IDNAToASCII(h) {
  3705. if ('' == h) {
  3706. invalid.call(this)
  3707. }
  3708. // XXX
  3709. return h.toLowerCase()
  3710. }
  3711. function percentEscape(c) {
  3712. var unicode = c.charCodeAt(0);
  3713. if (unicode > 0x20 &&
  3714. unicode < 0x7F &&
  3715. // " # < > ? `
  3716. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3717. ) {
  3718. return c;
  3719. }
  3720. return encodeURIComponent(c);
  3721. }
  3722. function percentEscapeQuery(c) {
  3723. // XXX This actually needs to encode c using encoding and then
  3724. // convert the bytes one-by-one.
  3725. var unicode = c.charCodeAt(0);
  3726. if (unicode > 0x20 &&
  3727. unicode < 0x7F &&
  3728. // " # < > ` (do not escape '?')
  3729. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3730. ) {
  3731. return c;
  3732. }
  3733. return encodeURIComponent(c);
  3734. }
  3735. var EOF = undefined,
  3736. ALPHA = /[a-zA-Z]/,
  3737. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3738. function parse(input, stateOverride, base) {
  3739. function err(message) {
  3740. errors.push(message)
  3741. }
  3742. var state = stateOverride || 'scheme start',
  3743. cursor = 0,
  3744. buffer = '',
  3745. seenAt = false,
  3746. seenBracket = false,
  3747. errors = [];
  3748. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3749. var c = input[cursor];
  3750. switch (state) {
  3751. case 'scheme start':
  3752. if (c && ALPHA.test(c)) {
  3753. buffer += c.toLowerCase(); // ASCII-safe
  3754. state = 'scheme';
  3755. } else if (!stateOverride) {
  3756. buffer = '';
  3757. state = 'no scheme';
  3758. continue;
  3759. } else {
  3760. err('Invalid scheme.');
  3761. break loop;
  3762. }
  3763. break;
  3764. case 'scheme':
  3765. if (c && ALPHANUMERIC.test(c)) {
  3766. buffer += c.toLowerCase(); // ASCII-safe
  3767. } else if (':' == c) {
  3768. this._scheme = buffer;
  3769. buffer = '';
  3770. if (stateOverride) {
  3771. break loop;
  3772. }
  3773. if (isRelativeScheme(this._scheme)) {
  3774. this._isRelative = true;
  3775. }
  3776. if ('file' == this._scheme) {
  3777. state = 'relative';
  3778. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3779. state = 'relative or authority';
  3780. } else if (this._isRelative) {
  3781. state = 'authority first slash';
  3782. } else {
  3783. state = 'scheme data';
  3784. }
  3785. } else if (!stateOverride) {
  3786. buffer = '';
  3787. cursor = 0;
  3788. state = 'no scheme';
  3789. continue;
  3790. } else if (EOF == c) {
  3791. break loop;
  3792. } else {
  3793. err('Code point not allowed in scheme: ' + c)
  3794. break loop;
  3795. }
  3796. break;
  3797. case 'scheme data':
  3798. if ('?' == c) {
  3799. this._query = '?';
  3800. state = 'query';
  3801. } else if ('#' == c) {
  3802. this._fragment = '#';
  3803. state = 'fragment';
  3804. } else {
  3805. // XXX error handling
  3806. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3807. this._schemeData += percentEscape(c);
  3808. }
  3809. }
  3810. break;
  3811. case 'no scheme':
  3812. if (!base || !(isRelativeScheme(base._scheme))) {
  3813. err('Missing scheme.');
  3814. invalid.call(this);
  3815. } else {
  3816. state = 'relative';
  3817. continue;
  3818. }
  3819. break;
  3820. case 'relative or authority':
  3821. if ('/' == c && '/' == input[cursor+1]) {
  3822. state = 'authority ignore slashes';
  3823. } else {
  3824. err('Expected /, got: ' + c);
  3825. state = 'relative';
  3826. continue
  3827. }
  3828. break;
  3829. case 'relative':
  3830. this._isRelative = true;
  3831. if ('file' != this._scheme)
  3832. this._scheme = base._scheme;
  3833. if (EOF == c) {
  3834. this._host = base._host;
  3835. this._port = base._port;
  3836. this._path = base._path.slice();
  3837. this._query = base._query;
  3838. this._username = base._username;
  3839. this._password = base._password;
  3840. break loop;
  3841. } else if ('/' == c || '\\' == c) {
  3842. if ('\\' == c)
  3843. err('\\ is an invalid code point.');
  3844. state = 'relative slash';
  3845. } else if ('?' == c) {
  3846. this._host = base._host;
  3847. this._port = base._port;
  3848. this._path = base._path.slice();
  3849. this._query = '?';
  3850. this._username = base._username;
  3851. this._password = base._password;
  3852. state = 'query';
  3853. } else if ('#' == c) {
  3854. this._host = base._host;
  3855. this._port = base._port;
  3856. this._path = base._path.slice();
  3857. this._query = base._query;
  3858. this._fragment = '#';
  3859. this._username = base._username;
  3860. this._password = base._password;
  3861. state = 'fragment';
  3862. } else {
  3863. var nextC = input[cursor+1]
  3864. var nextNextC = input[cursor+2]
  3865. if (
  3866. 'file' != this._scheme || !ALPHA.test(c) ||
  3867. (nextC != ':' && nextC != '|') ||
  3868. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3869. this._host = base._host;
  3870. this._port = base._port;
  3871. this._username = base._username;
  3872. this._password = base._password;
  3873. this._path = base._path.slice();
  3874. this._path.pop();
  3875. }
  3876. state = 'relative path';
  3877. continue;
  3878. }
  3879. break;
  3880. case 'relative slash':
  3881. if ('/' == c || '\\' == c) {
  3882. if ('\\' == c) {
  3883. err('\\ is an invalid code point.');
  3884. }
  3885. if ('file' == this._scheme) {
  3886. state = 'file host';
  3887. } else {
  3888. state = 'authority ignore slashes';
  3889. }
  3890. } else {
  3891. if ('file' != this._scheme) {
  3892. this._host = base._host;
  3893. this._port = base._port;
  3894. this._username = base._username;
  3895. this._password = base._password;
  3896. }
  3897. state = 'relative path';
  3898. continue;
  3899. }
  3900. break;
  3901. case 'authority first slash':
  3902. if ('/' == c) {
  3903. state = 'authority second slash';
  3904. } else {
  3905. err("Expected '/', got: " + c);
  3906. state = 'authority ignore slashes';
  3907. continue;
  3908. }
  3909. break;
  3910. case 'authority second slash':
  3911. state = 'authority ignore slashes';
  3912. if ('/' != c) {
  3913. err("Expected '/', got: " + c);
  3914. continue;
  3915. }
  3916. break;
  3917. case 'authority ignore slashes':
  3918. if ('/' != c && '\\' != c) {
  3919. state = 'authority';
  3920. continue;
  3921. } else {
  3922. err('Expected authority, got: ' + c);
  3923. }
  3924. break;
  3925. case 'authority':
  3926. if ('@' == c) {
  3927. if (seenAt) {
  3928. err('@ already seen.');
  3929. buffer += '%40';
  3930. }
  3931. seenAt = true;
  3932. for (var i = 0; i < buffer.length; i++) {
  3933. var cp = buffer[i];
  3934. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3935. err('Invalid whitespace in authority.');
  3936. continue;
  3937. }
  3938. // XXX check URL code points
  3939. if (':' == cp && null === this._password) {
  3940. this._password = '';
  3941. continue;
  3942. }
  3943. var tempC = percentEscape(cp);
  3944. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3945. }
  3946. buffer = '';
  3947. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3948. cursor -= buffer.length;
  3949. buffer = '';
  3950. state = 'host';
  3951. continue;
  3952. } else {
  3953. buffer += c;
  3954. }
  3955. break;
  3956. case 'file host':
  3957. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3958. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  3959. state = 'relative path';
  3960. } else if (buffer.length == 0) {
  3961. state = 'relative path start';
  3962. } else {
  3963. this._host = IDNAToASCII.call(this, buffer);
  3964. buffer = '';
  3965. state = 'relative path start';
  3966. }
  3967. continue;
  3968. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3969. err('Invalid whitespace in file host.');
  3970. } else {
  3971. buffer += c;
  3972. }
  3973. break;
  3974. case 'host':
  3975. case 'hostname':
  3976. if (':' == c && !seenBracket) {
  3977. // XXX host parsing
  3978. this._host = IDNAToASCII.call(this, buffer);
  3979. buffer = '';
  3980. state = 'port';
  3981. if ('hostname' == stateOverride) {
  3982. break loop;
  3983. }
  3984. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3985. this._host = IDNAToASCII.call(this, buffer);
  3986. buffer = '';
  3987. state = 'relative path start';
  3988. if (stateOverride) {
  3989. break loop;
  3990. }
  3991. continue;
  3992. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3993. if ('[' == c) {
  3994. seenBracket = true;
  3995. } else if (']' == c) {
  3996. seenBracket = false;
  3997. }
  3998. buffer += c;
  3999. } else {
  4000. err('Invalid code point in host/hostname: ' + c);
  4001. }
  4002. break;
  4003. case 'port':
  4004. if (/[0-9]/.test(c)) {
  4005. buffer += c;
  4006. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  4007. if ('' != buffer) {
  4008. var temp = parseInt(buffer, 10);
  4009. if (temp != relative[this._scheme]) {
  4010. this._port = temp + '';
  4011. }
  4012. buffer = '';
  4013. }
  4014. if (stateOverride) {
  4015. break loop;
  4016. }
  4017. state = 'relative path start';
  4018. continue;
  4019. } else if ('\t' == c || '\n' == c || '\r' == c) {
  4020. err('Invalid code point in port: ' + c);
  4021. } else {
  4022. invalid.call(this);
  4023. }
  4024. break;
  4025. case 'relative path start':
  4026. if ('\\' == c)
  4027. err("'\\' not allowed in path.");
  4028. state = 'relative path';
  4029. if ('/' != c && '\\' != c) {
  4030. continue;
  4031. }
  4032. break;
  4033. case 'relative path':
  4034. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  4035. if ('\\' == c) {
  4036. err('\\ not allowed in relative path.');
  4037. }
  4038. var tmp;
  4039. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  4040. buffer = tmp;
  4041. }
  4042. if ('..' == buffer) {
  4043. this._path.pop();
  4044. if ('/' != c && '\\' != c) {
  4045. this._path.push('');
  4046. }
  4047. } else if ('.' == buffer && '/' != c && '\\' != c) {
  4048. this._path.push('');
  4049. } else if ('.' != buffer) {
  4050. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  4051. buffer = buffer[0] + ':';
  4052. }
  4053. this._path.push(buffer);
  4054. }
  4055. buffer = '';
  4056. if ('?' == c) {
  4057. this._query = '?';
  4058. state = 'query';
  4059. } else if ('#' == c) {
  4060. this._fragment = '#';
  4061. state = 'fragment';
  4062. }
  4063. } else if ('\t' != c && '\n' != c && '\r' != c) {
  4064. buffer += percentEscape(c);
  4065. }
  4066. break;
  4067. case 'query':
  4068. if (!stateOverride && '#' == c) {
  4069. this._fragment = '#';
  4070. state = 'fragment';
  4071. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  4072. this._query += percentEscapeQuery(c);
  4073. }
  4074. break;
  4075. case 'fragment':
  4076. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  4077. this._fragment += c;
  4078. }
  4079. break;
  4080. }
  4081. cursor++;
  4082. }
  4083. }
  4084. function clear() {
  4085. this._scheme = '';
  4086. this._schemeData = '';
  4087. this._username = '';
  4088. this._password = null;
  4089. this._host = '';
  4090. this._port = '';
  4091. this._path = [];
  4092. this._query = '';
  4093. this._fragment = '';
  4094. this._isInvalid = false;
  4095. this._isRelative = false;
  4096. }
  4097. // Does not process domain names or IP addresses.
  4098. // Does not handle encoding for the query parameter.
  4099. function jURL(url, base /* , encoding */) {
  4100. if (base !== undefined && !(base instanceof jURL))
  4101. base = new jURL(String(base));
  4102. this._url = url;
  4103. clear.call(this);
  4104. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  4105. // encoding = encoding || 'utf-8'
  4106. parse.call(this, input, null, base);
  4107. }
  4108. jURL.prototype = {
  4109. toString: function() {
  4110. return this.href;
  4111. },
  4112. get href() {
  4113. if (this._isInvalid)
  4114. return this._url;
  4115. var authority = '';
  4116. if ('' != this._username || null != this._password) {
  4117. authority = this._username +
  4118. (null != this._password ? ':' + this._password : '') + '@';
  4119. }
  4120. return this.protocol +
  4121. (this._isRelative ? '//' + authority + this.host : '') +
  4122. this.pathname + this._query + this._fragment;
  4123. },
  4124. set href(href) {
  4125. clear.call(this);
  4126. parse.call(this, href);
  4127. },
  4128. get protocol() {
  4129. return this._scheme + ':';
  4130. },
  4131. set protocol(protocol) {
  4132. if (this._isInvalid)
  4133. return;
  4134. parse.call(this, protocol + ':', 'scheme start');
  4135. },
  4136. get host() {
  4137. return this._isInvalid ? '' : this._port ?
  4138. this._host + ':' + this._port : this._host;
  4139. },
  4140. set host(host) {
  4141. if (this._isInvalid || !this._isRelative)
  4142. return;
  4143. parse.call(this, host, 'host');
  4144. },
  4145. get hostname() {
  4146. return this._host;
  4147. },
  4148. set hostname(hostname) {
  4149. if (this._isInvalid || !this._isRelative)
  4150. return;
  4151. parse.call(this, hostname, 'hostname');
  4152. },
  4153. get port() {
  4154. return this._port;
  4155. },
  4156. set port(port) {
  4157. if (this._isInvalid || !this._isRelative)
  4158. return;
  4159. parse.call(this, port, 'port');
  4160. },
  4161. get pathname() {
  4162. return this._isInvalid ? '' : this._isRelative ?
  4163. '/' + this._path.join('/') : this._schemeData;
  4164. },
  4165. set pathname(pathname) {
  4166. if (this._isInvalid || !this._isRelative)
  4167. return;
  4168. this._path = [];
  4169. parse.call(this, pathname, 'relative path start');
  4170. },
  4171. get search() {
  4172. return this._isInvalid || !this._query || '?' == this._query ?
  4173. '' : this._query;
  4174. },
  4175. set search(search) {
  4176. if (this._isInvalid || !this._isRelative)
  4177. return;
  4178. this._query = '?';
  4179. if ('?' == search[0])
  4180. search = search.slice(1);
  4181. parse.call(this, search, 'query');
  4182. },
  4183. get hash() {
  4184. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  4185. '' : this._fragment;
  4186. },
  4187. set hash(hash) {
  4188. if (this._isInvalid)
  4189. return;
  4190. this._fragment = '#';
  4191. if ('#' == hash[0])
  4192. hash = hash.slice(1);
  4193. parse.call(this, hash, 'fragment');
  4194. },
  4195. get origin() {
  4196. var host;
  4197. if (this._isInvalid || !this._scheme) {
  4198. return '';
  4199. }
  4200. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  4201. // Gecko throws error for "data://"
  4202. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  4203. // Gecko returns String("") for file: mailto:
  4204. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  4205. switch (this._scheme) {
  4206. case 'data':
  4207. case 'file':
  4208. case 'javascript':
  4209. case 'mailto':
  4210. return 'null';
  4211. }
  4212. host = this.host;
  4213. if (!host) {
  4214. return '';
  4215. }
  4216. return this._scheme + '://' + host;
  4217. }
  4218. };
  4219. // Copy over the static methods
  4220. var OriginalURL = scope.URL;
  4221. if (OriginalURL) {
  4222. jURL.createObjectURL = function(blob) {
  4223. // IE extension allows a second optional options argument.
  4224. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  4225. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  4226. };
  4227. jURL.revokeObjectURL = function(url) {
  4228. OriginalURL.revokeObjectURL(url);
  4229. };
  4230. }
  4231. scope.URL = jURL;
  4232. /* jshint ignore:end */
  4233. })(globalScope);
  4234. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  4235. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  4236. exports.OPS = OPS;
  4237. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  4238. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  4239. exports.AnnotationFlag = AnnotationFlag;
  4240. exports.AnnotationType = AnnotationType;
  4241. exports.FontType = FontType;
  4242. exports.ImageKind = ImageKind;
  4243. exports.InvalidPDFException = InvalidPDFException;
  4244. exports.LinkTarget = LinkTarget;
  4245. exports.LinkTargetStringMap = LinkTargetStringMap;
  4246. exports.MessageHandler = MessageHandler;
  4247. exports.MissingDataException = MissingDataException;
  4248. exports.MissingPDFException = MissingPDFException;
  4249. exports.NotImplementedException = NotImplementedException;
  4250. exports.PasswordException = PasswordException;
  4251. exports.PasswordResponses = PasswordResponses;
  4252. exports.StatTimer = StatTimer;
  4253. exports.StreamType = StreamType;
  4254. exports.TextRenderingMode = TextRenderingMode;
  4255. exports.UnexpectedResponseException = UnexpectedResponseException;
  4256. exports.UnknownErrorException = UnknownErrorException;
  4257. exports.Util = Util;
  4258. exports.XRefParseException = XRefParseException;
  4259. exports.assert = assert;
  4260. exports.bytesToString = bytesToString;
  4261. exports.combineUrl = combineUrl;
  4262. exports.createPromiseCapability = createPromiseCapability;
  4263. exports.deprecated = deprecated;
  4264. exports.error = error;
  4265. exports.getLookupTableFactory = getLookupTableFactory;
  4266. exports.info = info;
  4267. exports.isArray = isArray;
  4268. exports.isArrayBuffer = isArrayBuffer;
  4269. exports.isBool = isBool;
  4270. exports.isEmptyObj = isEmptyObj;
  4271. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  4272. exports.isInt = isInt;
  4273. exports.isNum = isNum;
  4274. exports.isString = isString;
  4275. exports.isSameOrigin = isSameOrigin;
  4276. exports.isValidUrl = isValidUrl;
  4277. exports.addLinkAttributes = addLinkAttributes;
  4278. exports.loadJpegStream = loadJpegStream;
  4279. exports.log2 = log2;
  4280. exports.readInt8 = readInt8;
  4281. exports.readUint16 = readUint16;
  4282. exports.readUint32 = readUint32;
  4283. exports.removeNullCharacters = removeNullCharacters;
  4284. exports.shadow = shadow;
  4285. exports.string32 = string32;
  4286. exports.stringToBytes = stringToBytes;
  4287. exports.stringToPDFString = stringToPDFString;
  4288. exports.stringToUTF8String = stringToUTF8String;
  4289. exports.utf8StringToString = utf8StringToString;
  4290. exports.warn = warn;
  4291. }));
  4292. (function (root, factory) {
  4293. {
  4294. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4295. }
  4296. }(this, function (exports, sharedUtil) {
  4297. var MissingDataException = sharedUtil.MissingDataException;
  4298. var assert = sharedUtil.assert;
  4299. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4300. var isInt = sharedUtil.isInt;
  4301. var isEmptyObj = sharedUtil.isEmptyObj;
  4302. var ChunkedStream = (function ChunkedStreamClosure() {
  4303. function ChunkedStream(length, chunkSize, manager) {
  4304. this.bytes = new Uint8Array(length);
  4305. this.start = 0;
  4306. this.pos = 0;
  4307. this.end = length;
  4308. this.chunkSize = chunkSize;
  4309. this.loadedChunks = [];
  4310. this.numChunksLoaded = 0;
  4311. this.numChunks = Math.ceil(length / chunkSize);
  4312. this.manager = manager;
  4313. this.progressiveDataLength = 0;
  4314. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4315. }
  4316. // required methods for a stream. if a particular stream does not
  4317. // implement these, an error should be thrown
  4318. ChunkedStream.prototype = {
  4319. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4320. var chunks = [];
  4321. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4322. if (!this.loadedChunks[chunk]) {
  4323. chunks.push(chunk);
  4324. }
  4325. }
  4326. return chunks;
  4327. },
  4328. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4329. return [this];
  4330. },
  4331. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4332. return this.numChunksLoaded === this.numChunks;
  4333. },
  4334. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4335. var end = begin + chunk.byteLength;
  4336. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4337. // Using this.length is inaccurate here since this.start can be moved
  4338. // See ChunkedStream.moveStart()
  4339. var length = this.bytes.length;
  4340. assert(end % this.chunkSize === 0 || end === length,
  4341. 'Bad end offset: ' + end);
  4342. this.bytes.set(new Uint8Array(chunk), begin);
  4343. var chunkSize = this.chunkSize;
  4344. var beginChunk = Math.floor(begin / chunkSize);
  4345. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4346. var curChunk;
  4347. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4348. if (!this.loadedChunks[curChunk]) {
  4349. this.loadedChunks[curChunk] = true;
  4350. ++this.numChunksLoaded;
  4351. }
  4352. }
  4353. },
  4354. onReceiveProgressiveData:
  4355. function ChunkedStream_onReceiveProgressiveData(data) {
  4356. var position = this.progressiveDataLength;
  4357. var beginChunk = Math.floor(position / this.chunkSize);
  4358. this.bytes.set(new Uint8Array(data), position);
  4359. position += data.byteLength;
  4360. this.progressiveDataLength = position;
  4361. var endChunk = position >= this.end ? this.numChunks :
  4362. Math.floor(position / this.chunkSize);
  4363. var curChunk;
  4364. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4365. if (!this.loadedChunks[curChunk]) {
  4366. this.loadedChunks[curChunk] = true;
  4367. ++this.numChunksLoaded;
  4368. }
  4369. }
  4370. },
  4371. ensureByte: function ChunkedStream_ensureByte(pos) {
  4372. var chunk = Math.floor(pos / this.chunkSize);
  4373. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4374. return;
  4375. }
  4376. if (!this.loadedChunks[chunk]) {
  4377. throw new MissingDataException(pos, pos + 1);
  4378. }
  4379. this.lastSuccessfulEnsureByteChunk = chunk;
  4380. },
  4381. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4382. if (begin >= end) {
  4383. return;
  4384. }
  4385. if (end <= this.progressiveDataLength) {
  4386. return;
  4387. }
  4388. var chunkSize = this.chunkSize;
  4389. var beginChunk = Math.floor(begin / chunkSize);
  4390. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4391. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4392. if (!this.loadedChunks[chunk]) {
  4393. throw new MissingDataException(begin, end);
  4394. }
  4395. }
  4396. },
  4397. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4398. var chunk, numChunks = this.numChunks;
  4399. for (var i = 0; i < numChunks; ++i) {
  4400. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4401. if (!this.loadedChunks[chunk]) {
  4402. return chunk;
  4403. }
  4404. }
  4405. return null;
  4406. },
  4407. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4408. return !!this.loadedChunks[chunk];
  4409. },
  4410. get length() {
  4411. return this.end - this.start;
  4412. },
  4413. get isEmpty() {
  4414. return this.length === 0;
  4415. },
  4416. getByte: function ChunkedStream_getByte() {
  4417. var pos = this.pos;
  4418. if (pos >= this.end) {
  4419. return -1;
  4420. }
  4421. this.ensureByte(pos);
  4422. return this.bytes[this.pos++];
  4423. },
  4424. getUint16: function ChunkedStream_getUint16() {
  4425. var b0 = this.getByte();
  4426. var b1 = this.getByte();
  4427. if (b0 === -1 || b1 === -1) {
  4428. return -1;
  4429. }
  4430. return (b0 << 8) + b1;
  4431. },
  4432. getInt32: function ChunkedStream_getInt32() {
  4433. var b0 = this.getByte();
  4434. var b1 = this.getByte();
  4435. var b2 = this.getByte();
  4436. var b3 = this.getByte();
  4437. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4438. },
  4439. // returns subarray of original buffer
  4440. // should only be read
  4441. getBytes: function ChunkedStream_getBytes(length) {
  4442. var bytes = this.bytes;
  4443. var pos = this.pos;
  4444. var strEnd = this.end;
  4445. if (!length) {
  4446. this.ensureRange(pos, strEnd);
  4447. return bytes.subarray(pos, strEnd);
  4448. }
  4449. var end = pos + length;
  4450. if (end > strEnd) {
  4451. end = strEnd;
  4452. }
  4453. this.ensureRange(pos, end);
  4454. this.pos = end;
  4455. return bytes.subarray(pos, end);
  4456. },
  4457. peekByte: function ChunkedStream_peekByte() {
  4458. var peekedByte = this.getByte();
  4459. this.pos--;
  4460. return peekedByte;
  4461. },
  4462. peekBytes: function ChunkedStream_peekBytes(length) {
  4463. var bytes = this.getBytes(length);
  4464. this.pos -= bytes.length;
  4465. return bytes;
  4466. },
  4467. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4468. this.ensureRange(begin, end);
  4469. return this.bytes.subarray(begin, end);
  4470. },
  4471. skip: function ChunkedStream_skip(n) {
  4472. if (!n) {
  4473. n = 1;
  4474. }
  4475. this.pos += n;
  4476. },
  4477. reset: function ChunkedStream_reset() {
  4478. this.pos = this.start;
  4479. },
  4480. moveStart: function ChunkedStream_moveStart() {
  4481. this.start = this.pos;
  4482. },
  4483. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4484. this.ensureRange(start, start + length);
  4485. function ChunkedStreamSubstream() {}
  4486. ChunkedStreamSubstream.prototype = Object.create(this);
  4487. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4488. var chunkSize = this.chunkSize;
  4489. var beginChunk = Math.floor(this.start / chunkSize);
  4490. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4491. var missingChunks = [];
  4492. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4493. if (!this.loadedChunks[chunk]) {
  4494. missingChunks.push(chunk);
  4495. }
  4496. }
  4497. return missingChunks;
  4498. };
  4499. var subStream = new ChunkedStreamSubstream();
  4500. subStream.pos = subStream.start = start;
  4501. subStream.end = start + length || this.end;
  4502. subStream.dict = dict;
  4503. return subStream;
  4504. },
  4505. isStream: true
  4506. };
  4507. return ChunkedStream;
  4508. })();
  4509. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4510. function ChunkedStreamManager(length, chunkSize, url, args) {
  4511. this.stream = new ChunkedStream(length, chunkSize, this);
  4512. this.length = length;
  4513. this.chunkSize = chunkSize;
  4514. this.url = url;
  4515. this.disableAutoFetch = args.disableAutoFetch;
  4516. var msgHandler = this.msgHandler = args.msgHandler;
  4517. if (args.chunkedViewerLoading) {
  4518. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  4519. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  4520. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  4521. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  4522. };
  4523. } else {
  4524. var getXhr = function getXhr() {
  4525. return new XMLHttpRequest();
  4526. };
  4527. this.networkManager = new NetworkManager(this.url, {
  4528. getXhr: getXhr,
  4529. httpHeaders: args.httpHeaders,
  4530. withCredentials: args.withCredentials
  4531. });
  4532. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  4533. this.networkManager.requestRange(begin, end, {
  4534. onDone: this.onReceiveData.bind(this),
  4535. onProgress: this.onProgress.bind(this)
  4536. });
  4537. };
  4538. }
  4539. this.currRequestId = 0;
  4540. this.chunksNeededByRequest = Object.create(null);
  4541. this.requestsByChunk = Object.create(null);
  4542. this.promisesByRequest = Object.create(null);
  4543. this.progressiveDataLength = 0;
  4544. this._loadedStreamCapability = createPromiseCapability();
  4545. if (args.initialData) {
  4546. this.onReceiveData({chunk: args.initialData});
  4547. }
  4548. }
  4549. ChunkedStreamManager.prototype = {
  4550. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4551. return this._loadedStreamCapability.promise;
  4552. },
  4553. // Get all the chunks that are not yet loaded and groups them into
  4554. // contiguous ranges to load in as few requests as possible
  4555. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4556. var missingChunks = this.stream.getMissingChunks();
  4557. this._requestChunks(missingChunks);
  4558. return this._loadedStreamCapability.promise;
  4559. },
  4560. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4561. var requestId = this.currRequestId++;
  4562. var i, ii;
  4563. var chunksNeeded = Object.create(null);
  4564. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4565. for (i = 0, ii = chunks.length; i < ii; i++) {
  4566. if (!this.stream.hasChunk(chunks[i])) {
  4567. chunksNeeded[chunks[i]] = true;
  4568. }
  4569. }
  4570. if (isEmptyObj(chunksNeeded)) {
  4571. return Promise.resolve();
  4572. }
  4573. var capability = createPromiseCapability();
  4574. this.promisesByRequest[requestId] = capability;
  4575. var chunksToRequest = [];
  4576. for (var chunk in chunksNeeded) {
  4577. chunk = chunk | 0;
  4578. if (!(chunk in this.requestsByChunk)) {
  4579. this.requestsByChunk[chunk] = [];
  4580. chunksToRequest.push(chunk);
  4581. }
  4582. this.requestsByChunk[chunk].push(requestId);
  4583. }
  4584. if (!chunksToRequest.length) {
  4585. return capability.promise;
  4586. }
  4587. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  4588. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  4589. var groupedChunk = groupedChunksToRequest[i];
  4590. var begin = groupedChunk.beginChunk * this.chunkSize;
  4591. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  4592. this.sendRequest(begin, end);
  4593. }
  4594. return capability.promise;
  4595. },
  4596. getStream: function ChunkedStreamManager_getStream() {
  4597. return this.stream;
  4598. },
  4599. // Loads any chunks in the requested range that are not yet loaded
  4600. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  4601. end = Math.min(end, this.length);
  4602. var beginChunk = this.getBeginChunk(begin);
  4603. var endChunk = this.getEndChunk(end);
  4604. var chunks = [];
  4605. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4606. chunks.push(chunk);
  4607. }
  4608. return this._requestChunks(chunks);
  4609. },
  4610. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  4611. ranges = ranges || [];
  4612. var chunksToRequest = [];
  4613. for (var i = 0; i < ranges.length; i++) {
  4614. var beginChunk = this.getBeginChunk(ranges[i].begin);
  4615. var endChunk = this.getEndChunk(ranges[i].end);
  4616. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4617. if (chunksToRequest.indexOf(chunk) < 0) {
  4618. chunksToRequest.push(chunk);
  4619. }
  4620. }
  4621. }
  4622. chunksToRequest.sort(function(a, b) { return a - b; });
  4623. return this._requestChunks(chunksToRequest);
  4624. },
  4625. // Groups a sorted array of chunks into as few contiguous larger
  4626. // chunks as possible
  4627. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  4628. var groupedChunks = [];
  4629. var beginChunk = -1;
  4630. var prevChunk = -1;
  4631. for (var i = 0; i < chunks.length; ++i) {
  4632. var chunk = chunks[i];
  4633. if (beginChunk < 0) {
  4634. beginChunk = chunk;
  4635. }
  4636. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  4637. groupedChunks.push({ beginChunk: beginChunk,
  4638. endChunk: prevChunk + 1 });
  4639. beginChunk = chunk;
  4640. }
  4641. if (i + 1 === chunks.length) {
  4642. groupedChunks.push({ beginChunk: beginChunk,
  4643. endChunk: chunk + 1 });
  4644. }
  4645. prevChunk = chunk;
  4646. }
  4647. return groupedChunks;
  4648. },
  4649. onProgress: function ChunkedStreamManager_onProgress(args) {
  4650. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  4651. args.loaded);
  4652. this.msgHandler.send('DocProgress', {
  4653. loaded: bytesLoaded,
  4654. total: this.length
  4655. });
  4656. },
  4657. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  4658. var chunk = args.chunk;
  4659. var isProgressive = args.begin === undefined;
  4660. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  4661. var end = begin + chunk.byteLength;
  4662. var beginChunk = Math.floor(begin / this.chunkSize);
  4663. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  4664. Math.ceil(end / this.chunkSize);
  4665. if (isProgressive) {
  4666. this.stream.onReceiveProgressiveData(chunk);
  4667. this.progressiveDataLength = end;
  4668. } else {
  4669. this.stream.onReceiveData(begin, chunk);
  4670. }
  4671. if (this.stream.allChunksLoaded()) {
  4672. this._loadedStreamCapability.resolve(this.stream);
  4673. }
  4674. var loadedRequests = [];
  4675. var i, requestId;
  4676. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  4677. // The server might return more chunks than requested
  4678. var requestIds = this.requestsByChunk[chunk] || [];
  4679. delete this.requestsByChunk[chunk];
  4680. for (i = 0; i < requestIds.length; ++i) {
  4681. requestId = requestIds[i];
  4682. var chunksNeeded = this.chunksNeededByRequest[requestId];
  4683. if (chunk in chunksNeeded) {
  4684. delete chunksNeeded[chunk];
  4685. }
  4686. if (!isEmptyObj(chunksNeeded)) {
  4687. continue;
  4688. }
  4689. loadedRequests.push(requestId);
  4690. }
  4691. }
  4692. // If there are no pending requests, automatically fetch the next
  4693. // unfetched chunk of the PDF
  4694. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  4695. var nextEmptyChunk;
  4696. if (this.stream.numChunksLoaded === 1) {
  4697. // This is a special optimization so that after fetching the first
  4698. // chunk, rather than fetching the second chunk, we fetch the last
  4699. // chunk.
  4700. var lastChunk = this.stream.numChunks - 1;
  4701. if (!this.stream.hasChunk(lastChunk)) {
  4702. nextEmptyChunk = lastChunk;
  4703. }
  4704. } else {
  4705. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  4706. }
  4707. if (isInt(nextEmptyChunk)) {
  4708. this._requestChunks([nextEmptyChunk]);
  4709. }
  4710. }
  4711. for (i = 0; i < loadedRequests.length; ++i) {
  4712. requestId = loadedRequests[i];
  4713. var capability = this.promisesByRequest[requestId];
  4714. delete this.promisesByRequest[requestId];
  4715. capability.resolve();
  4716. }
  4717. this.msgHandler.send('DocProgress', {
  4718. loaded: this.stream.numChunksLoaded * this.chunkSize,
  4719. total: this.length
  4720. });
  4721. },
  4722. onError: function ChunkedStreamManager_onError(err) {
  4723. this._loadedStreamCapability.reject(err);
  4724. },
  4725. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  4726. var chunk = Math.floor(begin / this.chunkSize);
  4727. return chunk;
  4728. },
  4729. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  4730. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  4731. return chunk;
  4732. },
  4733. abort: function ChunkedStreamManager_abort() {
  4734. if (this.networkManager) {
  4735. this.networkManager.abortAllRequests();
  4736. }
  4737. for(var requestId in this.promisesByRequest) {
  4738. var capability = this.promisesByRequest[requestId];
  4739. capability.reject(new Error('Request was aborted'));
  4740. }
  4741. }
  4742. };
  4743. return ChunkedStreamManager;
  4744. })();
  4745. exports.ChunkedStream = ChunkedStream;
  4746. exports.ChunkedStreamManager = ChunkedStreamManager;
  4747. }));
  4748. (function (root, factory) {
  4749. {
  4750. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  4751. }
  4752. }(this, function (exports, sharedUtil) {
  4753. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  4754. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  4755. t['A'] = 0x0041;
  4756. t['AE'] = 0x00C6;
  4757. t['AEacute'] = 0x01FC;
  4758. t['AEmacron'] = 0x01E2;
  4759. t['AEsmall'] = 0xF7E6;
  4760. t['Aacute'] = 0x00C1;
  4761. t['Aacutesmall'] = 0xF7E1;
  4762. t['Abreve'] = 0x0102;
  4763. t['Abreveacute'] = 0x1EAE;
  4764. t['Abrevecyrillic'] = 0x04D0;
  4765. t['Abrevedotbelow'] = 0x1EB6;
  4766. t['Abrevegrave'] = 0x1EB0;
  4767. t['Abrevehookabove'] = 0x1EB2;
  4768. t['Abrevetilde'] = 0x1EB4;
  4769. t['Acaron'] = 0x01CD;
  4770. t['Acircle'] = 0x24B6;
  4771. t['Acircumflex'] = 0x00C2;
  4772. t['Acircumflexacute'] = 0x1EA4;
  4773. t['Acircumflexdotbelow'] = 0x1EAC;
  4774. t['Acircumflexgrave'] = 0x1EA6;
  4775. t['Acircumflexhookabove'] = 0x1EA8;
  4776. t['Acircumflexsmall'] = 0xF7E2;
  4777. t['Acircumflextilde'] = 0x1EAA;
  4778. t['Acute'] = 0xF6C9;
  4779. t['Acutesmall'] = 0xF7B4;
  4780. t['Acyrillic'] = 0x0410;
  4781. t['Adblgrave'] = 0x0200;
  4782. t['Adieresis'] = 0x00C4;
  4783. t['Adieresiscyrillic'] = 0x04D2;
  4784. t['Adieresismacron'] = 0x01DE;
  4785. t['Adieresissmall'] = 0xF7E4;
  4786. t['Adotbelow'] = 0x1EA0;
  4787. t['Adotmacron'] = 0x01E0;
  4788. t['Agrave'] = 0x00C0;
  4789. t['Agravesmall'] = 0xF7E0;
  4790. t['Ahookabove'] = 0x1EA2;
  4791. t['Aiecyrillic'] = 0x04D4;
  4792. t['Ainvertedbreve'] = 0x0202;
  4793. t['Alpha'] = 0x0391;
  4794. t['Alphatonos'] = 0x0386;
  4795. t['Amacron'] = 0x0100;
  4796. t['Amonospace'] = 0xFF21;
  4797. t['Aogonek'] = 0x0104;
  4798. t['Aring'] = 0x00C5;
  4799. t['Aringacute'] = 0x01FA;
  4800. t['Aringbelow'] = 0x1E00;
  4801. t['Aringsmall'] = 0xF7E5;
  4802. t['Asmall'] = 0xF761;
  4803. t['Atilde'] = 0x00C3;
  4804. t['Atildesmall'] = 0xF7E3;
  4805. t['Aybarmenian'] = 0x0531;
  4806. t['B'] = 0x0042;
  4807. t['Bcircle'] = 0x24B7;
  4808. t['Bdotaccent'] = 0x1E02;
  4809. t['Bdotbelow'] = 0x1E04;
  4810. t['Becyrillic'] = 0x0411;
  4811. t['Benarmenian'] = 0x0532;
  4812. t['Beta'] = 0x0392;
  4813. t['Bhook'] = 0x0181;
  4814. t['Blinebelow'] = 0x1E06;
  4815. t['Bmonospace'] = 0xFF22;
  4816. t['Brevesmall'] = 0xF6F4;
  4817. t['Bsmall'] = 0xF762;
  4818. t['Btopbar'] = 0x0182;
  4819. t['C'] = 0x0043;
  4820. t['Caarmenian'] = 0x053E;
  4821. t['Cacute'] = 0x0106;
  4822. t['Caron'] = 0xF6CA;
  4823. t['Caronsmall'] = 0xF6F5;
  4824. t['Ccaron'] = 0x010C;
  4825. t['Ccedilla'] = 0x00C7;
  4826. t['Ccedillaacute'] = 0x1E08;
  4827. t['Ccedillasmall'] = 0xF7E7;
  4828. t['Ccircle'] = 0x24B8;
  4829. t['Ccircumflex'] = 0x0108;
  4830. t['Cdot'] = 0x010A;
  4831. t['Cdotaccent'] = 0x010A;
  4832. t['Cedillasmall'] = 0xF7B8;
  4833. t['Chaarmenian'] = 0x0549;
  4834. t['Cheabkhasiancyrillic'] = 0x04BC;
  4835. t['Checyrillic'] = 0x0427;
  4836. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  4837. t['Chedescendercyrillic'] = 0x04B6;
  4838. t['Chedieresiscyrillic'] = 0x04F4;
  4839. t['Cheharmenian'] = 0x0543;
  4840. t['Chekhakassiancyrillic'] = 0x04CB;
  4841. t['Cheverticalstrokecyrillic'] = 0x04B8;
  4842. t['Chi'] = 0x03A7;
  4843. t['Chook'] = 0x0187;
  4844. t['Circumflexsmall'] = 0xF6F6;
  4845. t['Cmonospace'] = 0xFF23;
  4846. t['Coarmenian'] = 0x0551;
  4847. t['Csmall'] = 0xF763;
  4848. t['D'] = 0x0044;
  4849. t['DZ'] = 0x01F1;
  4850. t['DZcaron'] = 0x01C4;
  4851. t['Daarmenian'] = 0x0534;
  4852. t['Dafrican'] = 0x0189;
  4853. t['Dcaron'] = 0x010E;
  4854. t['Dcedilla'] = 0x1E10;
  4855. t['Dcircle'] = 0x24B9;
  4856. t['Dcircumflexbelow'] = 0x1E12;
  4857. t['Dcroat'] = 0x0110;
  4858. t['Ddotaccent'] = 0x1E0A;
  4859. t['Ddotbelow'] = 0x1E0C;
  4860. t['Decyrillic'] = 0x0414;
  4861. t['Deicoptic'] = 0x03EE;
  4862. t['Delta'] = 0x2206;
  4863. t['Deltagreek'] = 0x0394;
  4864. t['Dhook'] = 0x018A;
  4865. t['Dieresis'] = 0xF6CB;
  4866. t['DieresisAcute'] = 0xF6CC;
  4867. t['DieresisGrave'] = 0xF6CD;
  4868. t['Dieresissmall'] = 0xF7A8;
  4869. t['Digammagreek'] = 0x03DC;
  4870. t['Djecyrillic'] = 0x0402;
  4871. t['Dlinebelow'] = 0x1E0E;
  4872. t['Dmonospace'] = 0xFF24;
  4873. t['Dotaccentsmall'] = 0xF6F7;
  4874. t['Dslash'] = 0x0110;
  4875. t['Dsmall'] = 0xF764;
  4876. t['Dtopbar'] = 0x018B;
  4877. t['Dz'] = 0x01F2;
  4878. t['Dzcaron'] = 0x01C5;
  4879. t['Dzeabkhasiancyrillic'] = 0x04E0;
  4880. t['Dzecyrillic'] = 0x0405;
  4881. t['Dzhecyrillic'] = 0x040F;
  4882. t['E'] = 0x0045;
  4883. t['Eacute'] = 0x00C9;
  4884. t['Eacutesmall'] = 0xF7E9;
  4885. t['Ebreve'] = 0x0114;
  4886. t['Ecaron'] = 0x011A;
  4887. t['Ecedillabreve'] = 0x1E1C;
  4888. t['Echarmenian'] = 0x0535;
  4889. t['Ecircle'] = 0x24BA;
  4890. t['Ecircumflex'] = 0x00CA;
  4891. t['Ecircumflexacute'] = 0x1EBE;
  4892. t['Ecircumflexbelow'] = 0x1E18;
  4893. t['Ecircumflexdotbelow'] = 0x1EC6;
  4894. t['Ecircumflexgrave'] = 0x1EC0;
  4895. t['Ecircumflexhookabove'] = 0x1EC2;
  4896. t['Ecircumflexsmall'] = 0xF7EA;
  4897. t['Ecircumflextilde'] = 0x1EC4;
  4898. t['Ecyrillic'] = 0x0404;
  4899. t['Edblgrave'] = 0x0204;
  4900. t['Edieresis'] = 0x00CB;
  4901. t['Edieresissmall'] = 0xF7EB;
  4902. t['Edot'] = 0x0116;
  4903. t['Edotaccent'] = 0x0116;
  4904. t['Edotbelow'] = 0x1EB8;
  4905. t['Efcyrillic'] = 0x0424;
  4906. t['Egrave'] = 0x00C8;
  4907. t['Egravesmall'] = 0xF7E8;
  4908. t['Eharmenian'] = 0x0537;
  4909. t['Ehookabove'] = 0x1EBA;
  4910. t['Eightroman'] = 0x2167;
  4911. t['Einvertedbreve'] = 0x0206;
  4912. t['Eiotifiedcyrillic'] = 0x0464;
  4913. t['Elcyrillic'] = 0x041B;
  4914. t['Elevenroman'] = 0x216A;
  4915. t['Emacron'] = 0x0112;
  4916. t['Emacronacute'] = 0x1E16;
  4917. t['Emacrongrave'] = 0x1E14;
  4918. t['Emcyrillic'] = 0x041C;
  4919. t['Emonospace'] = 0xFF25;
  4920. t['Encyrillic'] = 0x041D;
  4921. t['Endescendercyrillic'] = 0x04A2;
  4922. t['Eng'] = 0x014A;
  4923. t['Enghecyrillic'] = 0x04A4;
  4924. t['Enhookcyrillic'] = 0x04C7;
  4925. t['Eogonek'] = 0x0118;
  4926. t['Eopen'] = 0x0190;
  4927. t['Epsilon'] = 0x0395;
  4928. t['Epsilontonos'] = 0x0388;
  4929. t['Ercyrillic'] = 0x0420;
  4930. t['Ereversed'] = 0x018E;
  4931. t['Ereversedcyrillic'] = 0x042D;
  4932. t['Escyrillic'] = 0x0421;
  4933. t['Esdescendercyrillic'] = 0x04AA;
  4934. t['Esh'] = 0x01A9;
  4935. t['Esmall'] = 0xF765;
  4936. t['Eta'] = 0x0397;
  4937. t['Etarmenian'] = 0x0538;
  4938. t['Etatonos'] = 0x0389;
  4939. t['Eth'] = 0x00D0;
  4940. t['Ethsmall'] = 0xF7F0;
  4941. t['Etilde'] = 0x1EBC;
  4942. t['Etildebelow'] = 0x1E1A;
  4943. t['Euro'] = 0x20AC;
  4944. t['Ezh'] = 0x01B7;
  4945. t['Ezhcaron'] = 0x01EE;
  4946. t['Ezhreversed'] = 0x01B8;
  4947. t['F'] = 0x0046;
  4948. t['Fcircle'] = 0x24BB;
  4949. t['Fdotaccent'] = 0x1E1E;
  4950. t['Feharmenian'] = 0x0556;
  4951. t['Feicoptic'] = 0x03E4;
  4952. t['Fhook'] = 0x0191;
  4953. t['Fitacyrillic'] = 0x0472;
  4954. t['Fiveroman'] = 0x2164;
  4955. t['Fmonospace'] = 0xFF26;
  4956. t['Fourroman'] = 0x2163;
  4957. t['Fsmall'] = 0xF766;
  4958. t['G'] = 0x0047;
  4959. t['GBsquare'] = 0x3387;
  4960. t['Gacute'] = 0x01F4;
  4961. t['Gamma'] = 0x0393;
  4962. t['Gammaafrican'] = 0x0194;
  4963. t['Gangiacoptic'] = 0x03EA;
  4964. t['Gbreve'] = 0x011E;
  4965. t['Gcaron'] = 0x01E6;
  4966. t['Gcedilla'] = 0x0122;
  4967. t['Gcircle'] = 0x24BC;
  4968. t['Gcircumflex'] = 0x011C;
  4969. t['Gcommaaccent'] = 0x0122;
  4970. t['Gdot'] = 0x0120;
  4971. t['Gdotaccent'] = 0x0120;
  4972. t['Gecyrillic'] = 0x0413;
  4973. t['Ghadarmenian'] = 0x0542;
  4974. t['Ghemiddlehookcyrillic'] = 0x0494;
  4975. t['Ghestrokecyrillic'] = 0x0492;
  4976. t['Gheupturncyrillic'] = 0x0490;
  4977. t['Ghook'] = 0x0193;
  4978. t['Gimarmenian'] = 0x0533;
  4979. t['Gjecyrillic'] = 0x0403;
  4980. t['Gmacron'] = 0x1E20;
  4981. t['Gmonospace'] = 0xFF27;
  4982. t['Grave'] = 0xF6CE;
  4983. t['Gravesmall'] = 0xF760;
  4984. t['Gsmall'] = 0xF767;
  4985. t['Gsmallhook'] = 0x029B;
  4986. t['Gstroke'] = 0x01E4;
  4987. t['H'] = 0x0048;
  4988. t['H18533'] = 0x25CF;
  4989. t['H18543'] = 0x25AA;
  4990. t['H18551'] = 0x25AB;
  4991. t['H22073'] = 0x25A1;
  4992. t['HPsquare'] = 0x33CB;
  4993. t['Haabkhasiancyrillic'] = 0x04A8;
  4994. t['Hadescendercyrillic'] = 0x04B2;
  4995. t['Hardsigncyrillic'] = 0x042A;
  4996. t['Hbar'] = 0x0126;
  4997. t['Hbrevebelow'] = 0x1E2A;
  4998. t['Hcedilla'] = 0x1E28;
  4999. t['Hcircle'] = 0x24BD;
  5000. t['Hcircumflex'] = 0x0124;
  5001. t['Hdieresis'] = 0x1E26;
  5002. t['Hdotaccent'] = 0x1E22;
  5003. t['Hdotbelow'] = 0x1E24;
  5004. t['Hmonospace'] = 0xFF28;
  5005. t['Hoarmenian'] = 0x0540;
  5006. t['Horicoptic'] = 0x03E8;
  5007. t['Hsmall'] = 0xF768;
  5008. t['Hungarumlaut'] = 0xF6CF;
  5009. t['Hungarumlautsmall'] = 0xF6F8;
  5010. t['Hzsquare'] = 0x3390;
  5011. t['I'] = 0x0049;
  5012. t['IAcyrillic'] = 0x042F;
  5013. t['IJ'] = 0x0132;
  5014. t['IUcyrillic'] = 0x042E;
  5015. t['Iacute'] = 0x00CD;
  5016. t['Iacutesmall'] = 0xF7ED;
  5017. t['Ibreve'] = 0x012C;
  5018. t['Icaron'] = 0x01CF;
  5019. t['Icircle'] = 0x24BE;
  5020. t['Icircumflex'] = 0x00CE;
  5021. t['Icircumflexsmall'] = 0xF7EE;
  5022. t['Icyrillic'] = 0x0406;
  5023. t['Idblgrave'] = 0x0208;
  5024. t['Idieresis'] = 0x00CF;
  5025. t['Idieresisacute'] = 0x1E2E;
  5026. t['Idieresiscyrillic'] = 0x04E4;
  5027. t['Idieresissmall'] = 0xF7EF;
  5028. t['Idot'] = 0x0130;
  5029. t['Idotaccent'] = 0x0130;
  5030. t['Idotbelow'] = 0x1ECA;
  5031. t['Iebrevecyrillic'] = 0x04D6;
  5032. t['Iecyrillic'] = 0x0415;
  5033. t['Ifraktur'] = 0x2111;
  5034. t['Igrave'] = 0x00CC;
  5035. t['Igravesmall'] = 0xF7EC;
  5036. t['Ihookabove'] = 0x1EC8;
  5037. t['Iicyrillic'] = 0x0418;
  5038. t['Iinvertedbreve'] = 0x020A;
  5039. t['Iishortcyrillic'] = 0x0419;
  5040. t['Imacron'] = 0x012A;
  5041. t['Imacroncyrillic'] = 0x04E2;
  5042. t['Imonospace'] = 0xFF29;
  5043. t['Iniarmenian'] = 0x053B;
  5044. t['Iocyrillic'] = 0x0401;
  5045. t['Iogonek'] = 0x012E;
  5046. t['Iota'] = 0x0399;
  5047. t['Iotaafrican'] = 0x0196;
  5048. t['Iotadieresis'] = 0x03AA;
  5049. t['Iotatonos'] = 0x038A;
  5050. t['Ismall'] = 0xF769;
  5051. t['Istroke'] = 0x0197;
  5052. t['Itilde'] = 0x0128;
  5053. t['Itildebelow'] = 0x1E2C;
  5054. t['Izhitsacyrillic'] = 0x0474;
  5055. t['Izhitsadblgravecyrillic'] = 0x0476;
  5056. t['J'] = 0x004A;
  5057. t['Jaarmenian'] = 0x0541;
  5058. t['Jcircle'] = 0x24BF;
  5059. t['Jcircumflex'] = 0x0134;
  5060. t['Jecyrillic'] = 0x0408;
  5061. t['Jheharmenian'] = 0x054B;
  5062. t['Jmonospace'] = 0xFF2A;
  5063. t['Jsmall'] = 0xF76A;
  5064. t['K'] = 0x004B;
  5065. t['KBsquare'] = 0x3385;
  5066. t['KKsquare'] = 0x33CD;
  5067. t['Kabashkircyrillic'] = 0x04A0;
  5068. t['Kacute'] = 0x1E30;
  5069. t['Kacyrillic'] = 0x041A;
  5070. t['Kadescendercyrillic'] = 0x049A;
  5071. t['Kahookcyrillic'] = 0x04C3;
  5072. t['Kappa'] = 0x039A;
  5073. t['Kastrokecyrillic'] = 0x049E;
  5074. t['Kaverticalstrokecyrillic'] = 0x049C;
  5075. t['Kcaron'] = 0x01E8;
  5076. t['Kcedilla'] = 0x0136;
  5077. t['Kcircle'] = 0x24C0;
  5078. t['Kcommaaccent'] = 0x0136;
  5079. t['Kdotbelow'] = 0x1E32;
  5080. t['Keharmenian'] = 0x0554;
  5081. t['Kenarmenian'] = 0x053F;
  5082. t['Khacyrillic'] = 0x0425;
  5083. t['Kheicoptic'] = 0x03E6;
  5084. t['Khook'] = 0x0198;
  5085. t['Kjecyrillic'] = 0x040C;
  5086. t['Klinebelow'] = 0x1E34;
  5087. t['Kmonospace'] = 0xFF2B;
  5088. t['Koppacyrillic'] = 0x0480;
  5089. t['Koppagreek'] = 0x03DE;
  5090. t['Ksicyrillic'] = 0x046E;
  5091. t['Ksmall'] = 0xF76B;
  5092. t['L'] = 0x004C;
  5093. t['LJ'] = 0x01C7;
  5094. t['LL'] = 0xF6BF;
  5095. t['Lacute'] = 0x0139;
  5096. t['Lambda'] = 0x039B;
  5097. t['Lcaron'] = 0x013D;
  5098. t['Lcedilla'] = 0x013B;
  5099. t['Lcircle'] = 0x24C1;
  5100. t['Lcircumflexbelow'] = 0x1E3C;
  5101. t['Lcommaaccent'] = 0x013B;
  5102. t['Ldot'] = 0x013F;
  5103. t['Ldotaccent'] = 0x013F;
  5104. t['Ldotbelow'] = 0x1E36;
  5105. t['Ldotbelowmacron'] = 0x1E38;
  5106. t['Liwnarmenian'] = 0x053C;
  5107. t['Lj'] = 0x01C8;
  5108. t['Ljecyrillic'] = 0x0409;
  5109. t['Llinebelow'] = 0x1E3A;
  5110. t['Lmonospace'] = 0xFF2C;
  5111. t['Lslash'] = 0x0141;
  5112. t['Lslashsmall'] = 0xF6F9;
  5113. t['Lsmall'] = 0xF76C;
  5114. t['M'] = 0x004D;
  5115. t['MBsquare'] = 0x3386;
  5116. t['Macron'] = 0xF6D0;
  5117. t['Macronsmall'] = 0xF7AF;
  5118. t['Macute'] = 0x1E3E;
  5119. t['Mcircle'] = 0x24C2;
  5120. t['Mdotaccent'] = 0x1E40;
  5121. t['Mdotbelow'] = 0x1E42;
  5122. t['Menarmenian'] = 0x0544;
  5123. t['Mmonospace'] = 0xFF2D;
  5124. t['Msmall'] = 0xF76D;
  5125. t['Mturned'] = 0x019C;
  5126. t['Mu'] = 0x039C;
  5127. t['N'] = 0x004E;
  5128. t['NJ'] = 0x01CA;
  5129. t['Nacute'] = 0x0143;
  5130. t['Ncaron'] = 0x0147;
  5131. t['Ncedilla'] = 0x0145;
  5132. t['Ncircle'] = 0x24C3;
  5133. t['Ncircumflexbelow'] = 0x1E4A;
  5134. t['Ncommaaccent'] = 0x0145;
  5135. t['Ndotaccent'] = 0x1E44;
  5136. t['Ndotbelow'] = 0x1E46;
  5137. t['Nhookleft'] = 0x019D;
  5138. t['Nineroman'] = 0x2168;
  5139. t['Nj'] = 0x01CB;
  5140. t['Njecyrillic'] = 0x040A;
  5141. t['Nlinebelow'] = 0x1E48;
  5142. t['Nmonospace'] = 0xFF2E;
  5143. t['Nowarmenian'] = 0x0546;
  5144. t['Nsmall'] = 0xF76E;
  5145. t['Ntilde'] = 0x00D1;
  5146. t['Ntildesmall'] = 0xF7F1;
  5147. t['Nu'] = 0x039D;
  5148. t['O'] = 0x004F;
  5149. t['OE'] = 0x0152;
  5150. t['OEsmall'] = 0xF6FA;
  5151. t['Oacute'] = 0x00D3;
  5152. t['Oacutesmall'] = 0xF7F3;
  5153. t['Obarredcyrillic'] = 0x04E8;
  5154. t['Obarreddieresiscyrillic'] = 0x04EA;
  5155. t['Obreve'] = 0x014E;
  5156. t['Ocaron'] = 0x01D1;
  5157. t['Ocenteredtilde'] = 0x019F;
  5158. t['Ocircle'] = 0x24C4;
  5159. t['Ocircumflex'] = 0x00D4;
  5160. t['Ocircumflexacute'] = 0x1ED0;
  5161. t['Ocircumflexdotbelow'] = 0x1ED8;
  5162. t['Ocircumflexgrave'] = 0x1ED2;
  5163. t['Ocircumflexhookabove'] = 0x1ED4;
  5164. t['Ocircumflexsmall'] = 0xF7F4;
  5165. t['Ocircumflextilde'] = 0x1ED6;
  5166. t['Ocyrillic'] = 0x041E;
  5167. t['Odblacute'] = 0x0150;
  5168. t['Odblgrave'] = 0x020C;
  5169. t['Odieresis'] = 0x00D6;
  5170. t['Odieresiscyrillic'] = 0x04E6;
  5171. t['Odieresissmall'] = 0xF7F6;
  5172. t['Odotbelow'] = 0x1ECC;
  5173. t['Ogoneksmall'] = 0xF6FB;
  5174. t['Ograve'] = 0x00D2;
  5175. t['Ogravesmall'] = 0xF7F2;
  5176. t['Oharmenian'] = 0x0555;
  5177. t['Ohm'] = 0x2126;
  5178. t['Ohookabove'] = 0x1ECE;
  5179. t['Ohorn'] = 0x01A0;
  5180. t['Ohornacute'] = 0x1EDA;
  5181. t['Ohorndotbelow'] = 0x1EE2;
  5182. t['Ohorngrave'] = 0x1EDC;
  5183. t['Ohornhookabove'] = 0x1EDE;
  5184. t['Ohorntilde'] = 0x1EE0;
  5185. t['Ohungarumlaut'] = 0x0150;
  5186. t['Oi'] = 0x01A2;
  5187. t['Oinvertedbreve'] = 0x020E;
  5188. t['Omacron'] = 0x014C;
  5189. t['Omacronacute'] = 0x1E52;
  5190. t['Omacrongrave'] = 0x1E50;
  5191. t['Omega'] = 0x2126;
  5192. t['Omegacyrillic'] = 0x0460;
  5193. t['Omegagreek'] = 0x03A9;
  5194. t['Omegaroundcyrillic'] = 0x047A;
  5195. t['Omegatitlocyrillic'] = 0x047C;
  5196. t['Omegatonos'] = 0x038F;
  5197. t['Omicron'] = 0x039F;
  5198. t['Omicrontonos'] = 0x038C;
  5199. t['Omonospace'] = 0xFF2F;
  5200. t['Oneroman'] = 0x2160;
  5201. t['Oogonek'] = 0x01EA;
  5202. t['Oogonekmacron'] = 0x01EC;
  5203. t['Oopen'] = 0x0186;
  5204. t['Oslash'] = 0x00D8;
  5205. t['Oslashacute'] = 0x01FE;
  5206. t['Oslashsmall'] = 0xF7F8;
  5207. t['Osmall'] = 0xF76F;
  5208. t['Ostrokeacute'] = 0x01FE;
  5209. t['Otcyrillic'] = 0x047E;
  5210. t['Otilde'] = 0x00D5;
  5211. t['Otildeacute'] = 0x1E4C;
  5212. t['Otildedieresis'] = 0x1E4E;
  5213. t['Otildesmall'] = 0xF7F5;
  5214. t['P'] = 0x0050;
  5215. t['Pacute'] = 0x1E54;
  5216. t['Pcircle'] = 0x24C5;
  5217. t['Pdotaccent'] = 0x1E56;
  5218. t['Pecyrillic'] = 0x041F;
  5219. t['Peharmenian'] = 0x054A;
  5220. t['Pemiddlehookcyrillic'] = 0x04A6;
  5221. t['Phi'] = 0x03A6;
  5222. t['Phook'] = 0x01A4;
  5223. t['Pi'] = 0x03A0;
  5224. t['Piwrarmenian'] = 0x0553;
  5225. t['Pmonospace'] = 0xFF30;
  5226. t['Psi'] = 0x03A8;
  5227. t['Psicyrillic'] = 0x0470;
  5228. t['Psmall'] = 0xF770;
  5229. t['Q'] = 0x0051;
  5230. t['Qcircle'] = 0x24C6;
  5231. t['Qmonospace'] = 0xFF31;
  5232. t['Qsmall'] = 0xF771;
  5233. t['R'] = 0x0052;
  5234. t['Raarmenian'] = 0x054C;
  5235. t['Racute'] = 0x0154;
  5236. t['Rcaron'] = 0x0158;
  5237. t['Rcedilla'] = 0x0156;
  5238. t['Rcircle'] = 0x24C7;
  5239. t['Rcommaaccent'] = 0x0156;
  5240. t['Rdblgrave'] = 0x0210;
  5241. t['Rdotaccent'] = 0x1E58;
  5242. t['Rdotbelow'] = 0x1E5A;
  5243. t['Rdotbelowmacron'] = 0x1E5C;
  5244. t['Reharmenian'] = 0x0550;
  5245. t['Rfraktur'] = 0x211C;
  5246. t['Rho'] = 0x03A1;
  5247. t['Ringsmall'] = 0xF6FC;
  5248. t['Rinvertedbreve'] = 0x0212;
  5249. t['Rlinebelow'] = 0x1E5E;
  5250. t['Rmonospace'] = 0xFF32;
  5251. t['Rsmall'] = 0xF772;
  5252. t['Rsmallinverted'] = 0x0281;
  5253. t['Rsmallinvertedsuperior'] = 0x02B6;
  5254. t['S'] = 0x0053;
  5255. t['SF010000'] = 0x250C;
  5256. t['SF020000'] = 0x2514;
  5257. t['SF030000'] = 0x2510;
  5258. t['SF040000'] = 0x2518;
  5259. t['SF050000'] = 0x253C;
  5260. t['SF060000'] = 0x252C;
  5261. t['SF070000'] = 0x2534;
  5262. t['SF080000'] = 0x251C;
  5263. t['SF090000'] = 0x2524;
  5264. t['SF100000'] = 0x2500;
  5265. t['SF110000'] = 0x2502;
  5266. t['SF190000'] = 0x2561;
  5267. t['SF200000'] = 0x2562;
  5268. t['SF210000'] = 0x2556;
  5269. t['SF220000'] = 0x2555;
  5270. t['SF230000'] = 0x2563;
  5271. t['SF240000'] = 0x2551;
  5272. t['SF250000'] = 0x2557;
  5273. t['SF260000'] = 0x255D;
  5274. t['SF270000'] = 0x255C;
  5275. t['SF280000'] = 0x255B;
  5276. t['SF360000'] = 0x255E;
  5277. t['SF370000'] = 0x255F;
  5278. t['SF380000'] = 0x255A;
  5279. t['SF390000'] = 0x2554;
  5280. t['SF400000'] = 0x2569;
  5281. t['SF410000'] = 0x2566;
  5282. t['SF420000'] = 0x2560;
  5283. t['SF430000'] = 0x2550;
  5284. t['SF440000'] = 0x256C;
  5285. t['SF450000'] = 0x2567;
  5286. t['SF460000'] = 0x2568;
  5287. t['SF470000'] = 0x2564;
  5288. t['SF480000'] = 0x2565;
  5289. t['SF490000'] = 0x2559;
  5290. t['SF500000'] = 0x2558;
  5291. t['SF510000'] = 0x2552;
  5292. t['SF520000'] = 0x2553;
  5293. t['SF530000'] = 0x256B;
  5294. t['SF540000'] = 0x256A;
  5295. t['Sacute'] = 0x015A;
  5296. t['Sacutedotaccent'] = 0x1E64;
  5297. t['Sampigreek'] = 0x03E0;
  5298. t['Scaron'] = 0x0160;
  5299. t['Scarondotaccent'] = 0x1E66;
  5300. t['Scaronsmall'] = 0xF6FD;
  5301. t['Scedilla'] = 0x015E;
  5302. t['Schwa'] = 0x018F;
  5303. t['Schwacyrillic'] = 0x04D8;
  5304. t['Schwadieresiscyrillic'] = 0x04DA;
  5305. t['Scircle'] = 0x24C8;
  5306. t['Scircumflex'] = 0x015C;
  5307. t['Scommaaccent'] = 0x0218;
  5308. t['Sdotaccent'] = 0x1E60;
  5309. t['Sdotbelow'] = 0x1E62;
  5310. t['Sdotbelowdotaccent'] = 0x1E68;
  5311. t['Seharmenian'] = 0x054D;
  5312. t['Sevenroman'] = 0x2166;
  5313. t['Shaarmenian'] = 0x0547;
  5314. t['Shacyrillic'] = 0x0428;
  5315. t['Shchacyrillic'] = 0x0429;
  5316. t['Sheicoptic'] = 0x03E2;
  5317. t['Shhacyrillic'] = 0x04BA;
  5318. t['Shimacoptic'] = 0x03EC;
  5319. t['Sigma'] = 0x03A3;
  5320. t['Sixroman'] = 0x2165;
  5321. t['Smonospace'] = 0xFF33;
  5322. t['Softsigncyrillic'] = 0x042C;
  5323. t['Ssmall'] = 0xF773;
  5324. t['Stigmagreek'] = 0x03DA;
  5325. t['T'] = 0x0054;
  5326. t['Tau'] = 0x03A4;
  5327. t['Tbar'] = 0x0166;
  5328. t['Tcaron'] = 0x0164;
  5329. t['Tcedilla'] = 0x0162;
  5330. t['Tcircle'] = 0x24C9;
  5331. t['Tcircumflexbelow'] = 0x1E70;
  5332. t['Tcommaaccent'] = 0x0162;
  5333. t['Tdotaccent'] = 0x1E6A;
  5334. t['Tdotbelow'] = 0x1E6C;
  5335. t['Tecyrillic'] = 0x0422;
  5336. t['Tedescendercyrillic'] = 0x04AC;
  5337. t['Tenroman'] = 0x2169;
  5338. t['Tetsecyrillic'] = 0x04B4;
  5339. t['Theta'] = 0x0398;
  5340. t['Thook'] = 0x01AC;
  5341. t['Thorn'] = 0x00DE;
  5342. t['Thornsmall'] = 0xF7FE;
  5343. t['Threeroman'] = 0x2162;
  5344. t['Tildesmall'] = 0xF6FE;
  5345. t['Tiwnarmenian'] = 0x054F;
  5346. t['Tlinebelow'] = 0x1E6E;
  5347. t['Tmonospace'] = 0xFF34;
  5348. t['Toarmenian'] = 0x0539;
  5349. t['Tonefive'] = 0x01BC;
  5350. t['Tonesix'] = 0x0184;
  5351. t['Tonetwo'] = 0x01A7;
  5352. t['Tretroflexhook'] = 0x01AE;
  5353. t['Tsecyrillic'] = 0x0426;
  5354. t['Tshecyrillic'] = 0x040B;
  5355. t['Tsmall'] = 0xF774;
  5356. t['Twelveroman'] = 0x216B;
  5357. t['Tworoman'] = 0x2161;
  5358. t['U'] = 0x0055;
  5359. t['Uacute'] = 0x00DA;
  5360. t['Uacutesmall'] = 0xF7FA;
  5361. t['Ubreve'] = 0x016C;
  5362. t['Ucaron'] = 0x01D3;
  5363. t['Ucircle'] = 0x24CA;
  5364. t['Ucircumflex'] = 0x00DB;
  5365. t['Ucircumflexbelow'] = 0x1E76;
  5366. t['Ucircumflexsmall'] = 0xF7FB;
  5367. t['Ucyrillic'] = 0x0423;
  5368. t['Udblacute'] = 0x0170;
  5369. t['Udblgrave'] = 0x0214;
  5370. t['Udieresis'] = 0x00DC;
  5371. t['Udieresisacute'] = 0x01D7;
  5372. t['Udieresisbelow'] = 0x1E72;
  5373. t['Udieresiscaron'] = 0x01D9;
  5374. t['Udieresiscyrillic'] = 0x04F0;
  5375. t['Udieresisgrave'] = 0x01DB;
  5376. t['Udieresismacron'] = 0x01D5;
  5377. t['Udieresissmall'] = 0xF7FC;
  5378. t['Udotbelow'] = 0x1EE4;
  5379. t['Ugrave'] = 0x00D9;
  5380. t['Ugravesmall'] = 0xF7F9;
  5381. t['Uhookabove'] = 0x1EE6;
  5382. t['Uhorn'] = 0x01AF;
  5383. t['Uhornacute'] = 0x1EE8;
  5384. t['Uhorndotbelow'] = 0x1EF0;
  5385. t['Uhorngrave'] = 0x1EEA;
  5386. t['Uhornhookabove'] = 0x1EEC;
  5387. t['Uhorntilde'] = 0x1EEE;
  5388. t['Uhungarumlaut'] = 0x0170;
  5389. t['Uhungarumlautcyrillic'] = 0x04F2;
  5390. t['Uinvertedbreve'] = 0x0216;
  5391. t['Ukcyrillic'] = 0x0478;
  5392. t['Umacron'] = 0x016A;
  5393. t['Umacroncyrillic'] = 0x04EE;
  5394. t['Umacrondieresis'] = 0x1E7A;
  5395. t['Umonospace'] = 0xFF35;
  5396. t['Uogonek'] = 0x0172;
  5397. t['Upsilon'] = 0x03A5;
  5398. t['Upsilon1'] = 0x03D2;
  5399. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5400. t['Upsilonafrican'] = 0x01B1;
  5401. t['Upsilondieresis'] = 0x03AB;
  5402. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5403. t['Upsilonhooksymbol'] = 0x03D2;
  5404. t['Upsilontonos'] = 0x038E;
  5405. t['Uring'] = 0x016E;
  5406. t['Ushortcyrillic'] = 0x040E;
  5407. t['Usmall'] = 0xF775;
  5408. t['Ustraightcyrillic'] = 0x04AE;
  5409. t['Ustraightstrokecyrillic'] = 0x04B0;
  5410. t['Utilde'] = 0x0168;
  5411. t['Utildeacute'] = 0x1E78;
  5412. t['Utildebelow'] = 0x1E74;
  5413. t['V'] = 0x0056;
  5414. t['Vcircle'] = 0x24CB;
  5415. t['Vdotbelow'] = 0x1E7E;
  5416. t['Vecyrillic'] = 0x0412;
  5417. t['Vewarmenian'] = 0x054E;
  5418. t['Vhook'] = 0x01B2;
  5419. t['Vmonospace'] = 0xFF36;
  5420. t['Voarmenian'] = 0x0548;
  5421. t['Vsmall'] = 0xF776;
  5422. t['Vtilde'] = 0x1E7C;
  5423. t['W'] = 0x0057;
  5424. t['Wacute'] = 0x1E82;
  5425. t['Wcircle'] = 0x24CC;
  5426. t['Wcircumflex'] = 0x0174;
  5427. t['Wdieresis'] = 0x1E84;
  5428. t['Wdotaccent'] = 0x1E86;
  5429. t['Wdotbelow'] = 0x1E88;
  5430. t['Wgrave'] = 0x1E80;
  5431. t['Wmonospace'] = 0xFF37;
  5432. t['Wsmall'] = 0xF777;
  5433. t['X'] = 0x0058;
  5434. t['Xcircle'] = 0x24CD;
  5435. t['Xdieresis'] = 0x1E8C;
  5436. t['Xdotaccent'] = 0x1E8A;
  5437. t['Xeharmenian'] = 0x053D;
  5438. t['Xi'] = 0x039E;
  5439. t['Xmonospace'] = 0xFF38;
  5440. t['Xsmall'] = 0xF778;
  5441. t['Y'] = 0x0059;
  5442. t['Yacute'] = 0x00DD;
  5443. t['Yacutesmall'] = 0xF7FD;
  5444. t['Yatcyrillic'] = 0x0462;
  5445. t['Ycircle'] = 0x24CE;
  5446. t['Ycircumflex'] = 0x0176;
  5447. t['Ydieresis'] = 0x0178;
  5448. t['Ydieresissmall'] = 0xF7FF;
  5449. t['Ydotaccent'] = 0x1E8E;
  5450. t['Ydotbelow'] = 0x1EF4;
  5451. t['Yericyrillic'] = 0x042B;
  5452. t['Yerudieresiscyrillic'] = 0x04F8;
  5453. t['Ygrave'] = 0x1EF2;
  5454. t['Yhook'] = 0x01B3;
  5455. t['Yhookabove'] = 0x1EF6;
  5456. t['Yiarmenian'] = 0x0545;
  5457. t['Yicyrillic'] = 0x0407;
  5458. t['Yiwnarmenian'] = 0x0552;
  5459. t['Ymonospace'] = 0xFF39;
  5460. t['Ysmall'] = 0xF779;
  5461. t['Ytilde'] = 0x1EF8;
  5462. t['Yusbigcyrillic'] = 0x046A;
  5463. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5464. t['Yuslittlecyrillic'] = 0x0466;
  5465. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5466. t['Z'] = 0x005A;
  5467. t['Zaarmenian'] = 0x0536;
  5468. t['Zacute'] = 0x0179;
  5469. t['Zcaron'] = 0x017D;
  5470. t['Zcaronsmall'] = 0xF6FF;
  5471. t['Zcircle'] = 0x24CF;
  5472. t['Zcircumflex'] = 0x1E90;
  5473. t['Zdot'] = 0x017B;
  5474. t['Zdotaccent'] = 0x017B;
  5475. t['Zdotbelow'] = 0x1E92;
  5476. t['Zecyrillic'] = 0x0417;
  5477. t['Zedescendercyrillic'] = 0x0498;
  5478. t['Zedieresiscyrillic'] = 0x04DE;
  5479. t['Zeta'] = 0x0396;
  5480. t['Zhearmenian'] = 0x053A;
  5481. t['Zhebrevecyrillic'] = 0x04C1;
  5482. t['Zhecyrillic'] = 0x0416;
  5483. t['Zhedescendercyrillic'] = 0x0496;
  5484. t['Zhedieresiscyrillic'] = 0x04DC;
  5485. t['Zlinebelow'] = 0x1E94;
  5486. t['Zmonospace'] = 0xFF3A;
  5487. t['Zsmall'] = 0xF77A;
  5488. t['Zstroke'] = 0x01B5;
  5489. t['a'] = 0x0061;
  5490. t['aabengali'] = 0x0986;
  5491. t['aacute'] = 0x00E1;
  5492. t['aadeva'] = 0x0906;
  5493. t['aagujarati'] = 0x0A86;
  5494. t['aagurmukhi'] = 0x0A06;
  5495. t['aamatragurmukhi'] = 0x0A3E;
  5496. t['aarusquare'] = 0x3303;
  5497. t['aavowelsignbengali'] = 0x09BE;
  5498. t['aavowelsigndeva'] = 0x093E;
  5499. t['aavowelsigngujarati'] = 0x0ABE;
  5500. t['abbreviationmarkarmenian'] = 0x055F;
  5501. t['abbreviationsigndeva'] = 0x0970;
  5502. t['abengali'] = 0x0985;
  5503. t['abopomofo'] = 0x311A;
  5504. t['abreve'] = 0x0103;
  5505. t['abreveacute'] = 0x1EAF;
  5506. t['abrevecyrillic'] = 0x04D1;
  5507. t['abrevedotbelow'] = 0x1EB7;
  5508. t['abrevegrave'] = 0x1EB1;
  5509. t['abrevehookabove'] = 0x1EB3;
  5510. t['abrevetilde'] = 0x1EB5;
  5511. t['acaron'] = 0x01CE;
  5512. t['acircle'] = 0x24D0;
  5513. t['acircumflex'] = 0x00E2;
  5514. t['acircumflexacute'] = 0x1EA5;
  5515. t['acircumflexdotbelow'] = 0x1EAD;
  5516. t['acircumflexgrave'] = 0x1EA7;
  5517. t['acircumflexhookabove'] = 0x1EA9;
  5518. t['acircumflextilde'] = 0x1EAB;
  5519. t['acute'] = 0x00B4;
  5520. t['acutebelowcmb'] = 0x0317;
  5521. t['acutecmb'] = 0x0301;
  5522. t['acutecomb'] = 0x0301;
  5523. t['acutedeva'] = 0x0954;
  5524. t['acutelowmod'] = 0x02CF;
  5525. t['acutetonecmb'] = 0x0341;
  5526. t['acyrillic'] = 0x0430;
  5527. t['adblgrave'] = 0x0201;
  5528. t['addakgurmukhi'] = 0x0A71;
  5529. t['adeva'] = 0x0905;
  5530. t['adieresis'] = 0x00E4;
  5531. t['adieresiscyrillic'] = 0x04D3;
  5532. t['adieresismacron'] = 0x01DF;
  5533. t['adotbelow'] = 0x1EA1;
  5534. t['adotmacron'] = 0x01E1;
  5535. t['ae'] = 0x00E6;
  5536. t['aeacute'] = 0x01FD;
  5537. t['aekorean'] = 0x3150;
  5538. t['aemacron'] = 0x01E3;
  5539. t['afii00208'] = 0x2015;
  5540. t['afii08941'] = 0x20A4;
  5541. t['afii10017'] = 0x0410;
  5542. t['afii10018'] = 0x0411;
  5543. t['afii10019'] = 0x0412;
  5544. t['afii10020'] = 0x0413;
  5545. t['afii10021'] = 0x0414;
  5546. t['afii10022'] = 0x0415;
  5547. t['afii10023'] = 0x0401;
  5548. t['afii10024'] = 0x0416;
  5549. t['afii10025'] = 0x0417;
  5550. t['afii10026'] = 0x0418;
  5551. t['afii10027'] = 0x0419;
  5552. t['afii10028'] = 0x041A;
  5553. t['afii10029'] = 0x041B;
  5554. t['afii10030'] = 0x041C;
  5555. t['afii10031'] = 0x041D;
  5556. t['afii10032'] = 0x041E;
  5557. t['afii10033'] = 0x041F;
  5558. t['afii10034'] = 0x0420;
  5559. t['afii10035'] = 0x0421;
  5560. t['afii10036'] = 0x0422;
  5561. t['afii10037'] = 0x0423;
  5562. t['afii10038'] = 0x0424;
  5563. t['afii10039'] = 0x0425;
  5564. t['afii10040'] = 0x0426;
  5565. t['afii10041'] = 0x0427;
  5566. t['afii10042'] = 0x0428;
  5567. t['afii10043'] = 0x0429;
  5568. t['afii10044'] = 0x042A;
  5569. t['afii10045'] = 0x042B;
  5570. t['afii10046'] = 0x042C;
  5571. t['afii10047'] = 0x042D;
  5572. t['afii10048'] = 0x042E;
  5573. t['afii10049'] = 0x042F;
  5574. t['afii10050'] = 0x0490;
  5575. t['afii10051'] = 0x0402;
  5576. t['afii10052'] = 0x0403;
  5577. t['afii10053'] = 0x0404;
  5578. t['afii10054'] = 0x0405;
  5579. t['afii10055'] = 0x0406;
  5580. t['afii10056'] = 0x0407;
  5581. t['afii10057'] = 0x0408;
  5582. t['afii10058'] = 0x0409;
  5583. t['afii10059'] = 0x040A;
  5584. t['afii10060'] = 0x040B;
  5585. t['afii10061'] = 0x040C;
  5586. t['afii10062'] = 0x040E;
  5587. t['afii10063'] = 0xF6C4;
  5588. t['afii10064'] = 0xF6C5;
  5589. t['afii10065'] = 0x0430;
  5590. t['afii10066'] = 0x0431;
  5591. t['afii10067'] = 0x0432;
  5592. t['afii10068'] = 0x0433;
  5593. t['afii10069'] = 0x0434;
  5594. t['afii10070'] = 0x0435;
  5595. t['afii10071'] = 0x0451;
  5596. t['afii10072'] = 0x0436;
  5597. t['afii10073'] = 0x0437;
  5598. t['afii10074'] = 0x0438;
  5599. t['afii10075'] = 0x0439;
  5600. t['afii10076'] = 0x043A;
  5601. t['afii10077'] = 0x043B;
  5602. t['afii10078'] = 0x043C;
  5603. t['afii10079'] = 0x043D;
  5604. t['afii10080'] = 0x043E;
  5605. t['afii10081'] = 0x043F;
  5606. t['afii10082'] = 0x0440;
  5607. t['afii10083'] = 0x0441;
  5608. t['afii10084'] = 0x0442;
  5609. t['afii10085'] = 0x0443;
  5610. t['afii10086'] = 0x0444;
  5611. t['afii10087'] = 0x0445;
  5612. t['afii10088'] = 0x0446;
  5613. t['afii10089'] = 0x0447;
  5614. t['afii10090'] = 0x0448;
  5615. t['afii10091'] = 0x0449;
  5616. t['afii10092'] = 0x044A;
  5617. t['afii10093'] = 0x044B;
  5618. t['afii10094'] = 0x044C;
  5619. t['afii10095'] = 0x044D;
  5620. t['afii10096'] = 0x044E;
  5621. t['afii10097'] = 0x044F;
  5622. t['afii10098'] = 0x0491;
  5623. t['afii10099'] = 0x0452;
  5624. t['afii10100'] = 0x0453;
  5625. t['afii10101'] = 0x0454;
  5626. t['afii10102'] = 0x0455;
  5627. t['afii10103'] = 0x0456;
  5628. t['afii10104'] = 0x0457;
  5629. t['afii10105'] = 0x0458;
  5630. t['afii10106'] = 0x0459;
  5631. t['afii10107'] = 0x045A;
  5632. t['afii10108'] = 0x045B;
  5633. t['afii10109'] = 0x045C;
  5634. t['afii10110'] = 0x045E;
  5635. t['afii10145'] = 0x040F;
  5636. t['afii10146'] = 0x0462;
  5637. t['afii10147'] = 0x0472;
  5638. t['afii10148'] = 0x0474;
  5639. t['afii10192'] = 0xF6C6;
  5640. t['afii10193'] = 0x045F;
  5641. t['afii10194'] = 0x0463;
  5642. t['afii10195'] = 0x0473;
  5643. t['afii10196'] = 0x0475;
  5644. t['afii10831'] = 0xF6C7;
  5645. t['afii10832'] = 0xF6C8;
  5646. t['afii10846'] = 0x04D9;
  5647. t['afii299'] = 0x200E;
  5648. t['afii300'] = 0x200F;
  5649. t['afii301'] = 0x200D;
  5650. t['afii57381'] = 0x066A;
  5651. t['afii57388'] = 0x060C;
  5652. t['afii57392'] = 0x0660;
  5653. t['afii57393'] = 0x0661;
  5654. t['afii57394'] = 0x0662;
  5655. t['afii57395'] = 0x0663;
  5656. t['afii57396'] = 0x0664;
  5657. t['afii57397'] = 0x0665;
  5658. t['afii57398'] = 0x0666;
  5659. t['afii57399'] = 0x0667;
  5660. t['afii57400'] = 0x0668;
  5661. t['afii57401'] = 0x0669;
  5662. t['afii57403'] = 0x061B;
  5663. t['afii57407'] = 0x061F;
  5664. t['afii57409'] = 0x0621;
  5665. t['afii57410'] = 0x0622;
  5666. t['afii57411'] = 0x0623;
  5667. t['afii57412'] = 0x0624;
  5668. t['afii57413'] = 0x0625;
  5669. t['afii57414'] = 0x0626;
  5670. t['afii57415'] = 0x0627;
  5671. t['afii57416'] = 0x0628;
  5672. t['afii57417'] = 0x0629;
  5673. t['afii57418'] = 0x062A;
  5674. t['afii57419'] = 0x062B;
  5675. t['afii57420'] = 0x062C;
  5676. t['afii57421'] = 0x062D;
  5677. t['afii57422'] = 0x062E;
  5678. t['afii57423'] = 0x062F;
  5679. t['afii57424'] = 0x0630;
  5680. t['afii57425'] = 0x0631;
  5681. t['afii57426'] = 0x0632;
  5682. t['afii57427'] = 0x0633;
  5683. t['afii57428'] = 0x0634;
  5684. t['afii57429'] = 0x0635;
  5685. t['afii57430'] = 0x0636;
  5686. t['afii57431'] = 0x0637;
  5687. t['afii57432'] = 0x0638;
  5688. t['afii57433'] = 0x0639;
  5689. t['afii57434'] = 0x063A;
  5690. t['afii57440'] = 0x0640;
  5691. t['afii57441'] = 0x0641;
  5692. t['afii57442'] = 0x0642;
  5693. t['afii57443'] = 0x0643;
  5694. t['afii57444'] = 0x0644;
  5695. t['afii57445'] = 0x0645;
  5696. t['afii57446'] = 0x0646;
  5697. t['afii57448'] = 0x0648;
  5698. t['afii57449'] = 0x0649;
  5699. t['afii57450'] = 0x064A;
  5700. t['afii57451'] = 0x064B;
  5701. t['afii57452'] = 0x064C;
  5702. t['afii57453'] = 0x064D;
  5703. t['afii57454'] = 0x064E;
  5704. t['afii57455'] = 0x064F;
  5705. t['afii57456'] = 0x0650;
  5706. t['afii57457'] = 0x0651;
  5707. t['afii57458'] = 0x0652;
  5708. t['afii57470'] = 0x0647;
  5709. t['afii57505'] = 0x06A4;
  5710. t['afii57506'] = 0x067E;
  5711. t['afii57507'] = 0x0686;
  5712. t['afii57508'] = 0x0698;
  5713. t['afii57509'] = 0x06AF;
  5714. t['afii57511'] = 0x0679;
  5715. t['afii57512'] = 0x0688;
  5716. t['afii57513'] = 0x0691;
  5717. t['afii57514'] = 0x06BA;
  5718. t['afii57519'] = 0x06D2;
  5719. t['afii57534'] = 0x06D5;
  5720. t['afii57636'] = 0x20AA;
  5721. t['afii57645'] = 0x05BE;
  5722. t['afii57658'] = 0x05C3;
  5723. t['afii57664'] = 0x05D0;
  5724. t['afii57665'] = 0x05D1;
  5725. t['afii57666'] = 0x05D2;
  5726. t['afii57667'] = 0x05D3;
  5727. t['afii57668'] = 0x05D4;
  5728. t['afii57669'] = 0x05D5;
  5729. t['afii57670'] = 0x05D6;
  5730. t['afii57671'] = 0x05D7;
  5731. t['afii57672'] = 0x05D8;
  5732. t['afii57673'] = 0x05D9;
  5733. t['afii57674'] = 0x05DA;
  5734. t['afii57675'] = 0x05DB;
  5735. t['afii57676'] = 0x05DC;
  5736. t['afii57677'] = 0x05DD;
  5737. t['afii57678'] = 0x05DE;
  5738. t['afii57679'] = 0x05DF;
  5739. t['afii57680'] = 0x05E0;
  5740. t['afii57681'] = 0x05E1;
  5741. t['afii57682'] = 0x05E2;
  5742. t['afii57683'] = 0x05E3;
  5743. t['afii57684'] = 0x05E4;
  5744. t['afii57685'] = 0x05E5;
  5745. t['afii57686'] = 0x05E6;
  5746. t['afii57687'] = 0x05E7;
  5747. t['afii57688'] = 0x05E8;
  5748. t['afii57689'] = 0x05E9;
  5749. t['afii57690'] = 0x05EA;
  5750. t['afii57694'] = 0xFB2A;
  5751. t['afii57695'] = 0xFB2B;
  5752. t['afii57700'] = 0xFB4B;
  5753. t['afii57705'] = 0xFB1F;
  5754. t['afii57716'] = 0x05F0;
  5755. t['afii57717'] = 0x05F1;
  5756. t['afii57718'] = 0x05F2;
  5757. t['afii57723'] = 0xFB35;
  5758. t['afii57793'] = 0x05B4;
  5759. t['afii57794'] = 0x05B5;
  5760. t['afii57795'] = 0x05B6;
  5761. t['afii57796'] = 0x05BB;
  5762. t['afii57797'] = 0x05B8;
  5763. t['afii57798'] = 0x05B7;
  5764. t['afii57799'] = 0x05B0;
  5765. t['afii57800'] = 0x05B2;
  5766. t['afii57801'] = 0x05B1;
  5767. t['afii57802'] = 0x05B3;
  5768. t['afii57803'] = 0x05C2;
  5769. t['afii57804'] = 0x05C1;
  5770. t['afii57806'] = 0x05B9;
  5771. t['afii57807'] = 0x05BC;
  5772. t['afii57839'] = 0x05BD;
  5773. t['afii57841'] = 0x05BF;
  5774. t['afii57842'] = 0x05C0;
  5775. t['afii57929'] = 0x02BC;
  5776. t['afii61248'] = 0x2105;
  5777. t['afii61289'] = 0x2113;
  5778. t['afii61352'] = 0x2116;
  5779. t['afii61573'] = 0x202C;
  5780. t['afii61574'] = 0x202D;
  5781. t['afii61575'] = 0x202E;
  5782. t['afii61664'] = 0x200C;
  5783. t['afii63167'] = 0x066D;
  5784. t['afii64937'] = 0x02BD;
  5785. t['agrave'] = 0x00E0;
  5786. t['agujarati'] = 0x0A85;
  5787. t['agurmukhi'] = 0x0A05;
  5788. t['ahiragana'] = 0x3042;
  5789. t['ahookabove'] = 0x1EA3;
  5790. t['aibengali'] = 0x0990;
  5791. t['aibopomofo'] = 0x311E;
  5792. t['aideva'] = 0x0910;
  5793. t['aiecyrillic'] = 0x04D5;
  5794. t['aigujarati'] = 0x0A90;
  5795. t['aigurmukhi'] = 0x0A10;
  5796. t['aimatragurmukhi'] = 0x0A48;
  5797. t['ainarabic'] = 0x0639;
  5798. t['ainfinalarabic'] = 0xFECA;
  5799. t['aininitialarabic'] = 0xFECB;
  5800. t['ainmedialarabic'] = 0xFECC;
  5801. t['ainvertedbreve'] = 0x0203;
  5802. t['aivowelsignbengali'] = 0x09C8;
  5803. t['aivowelsigndeva'] = 0x0948;
  5804. t['aivowelsigngujarati'] = 0x0AC8;
  5805. t['akatakana'] = 0x30A2;
  5806. t['akatakanahalfwidth'] = 0xFF71;
  5807. t['akorean'] = 0x314F;
  5808. t['alef'] = 0x05D0;
  5809. t['alefarabic'] = 0x0627;
  5810. t['alefdageshhebrew'] = 0xFB30;
  5811. t['aleffinalarabic'] = 0xFE8E;
  5812. t['alefhamzaabovearabic'] = 0x0623;
  5813. t['alefhamzaabovefinalarabic'] = 0xFE84;
  5814. t['alefhamzabelowarabic'] = 0x0625;
  5815. t['alefhamzabelowfinalarabic'] = 0xFE88;
  5816. t['alefhebrew'] = 0x05D0;
  5817. t['aleflamedhebrew'] = 0xFB4F;
  5818. t['alefmaddaabovearabic'] = 0x0622;
  5819. t['alefmaddaabovefinalarabic'] = 0xFE82;
  5820. t['alefmaksuraarabic'] = 0x0649;
  5821. t['alefmaksurafinalarabic'] = 0xFEF0;
  5822. t['alefmaksurainitialarabic'] = 0xFEF3;
  5823. t['alefmaksuramedialarabic'] = 0xFEF4;
  5824. t['alefpatahhebrew'] = 0xFB2E;
  5825. t['alefqamatshebrew'] = 0xFB2F;
  5826. t['aleph'] = 0x2135;
  5827. t['allequal'] = 0x224C;
  5828. t['alpha'] = 0x03B1;
  5829. t['alphatonos'] = 0x03AC;
  5830. t['amacron'] = 0x0101;
  5831. t['amonospace'] = 0xFF41;
  5832. t['ampersand'] = 0x0026;
  5833. t['ampersandmonospace'] = 0xFF06;
  5834. t['ampersandsmall'] = 0xF726;
  5835. t['amsquare'] = 0x33C2;
  5836. t['anbopomofo'] = 0x3122;
  5837. t['angbopomofo'] = 0x3124;
  5838. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  5839. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  5840. t['angkhankhuthai'] = 0x0E5A;
  5841. t['angle'] = 0x2220;
  5842. t['anglebracketleft'] = 0x3008;
  5843. t['anglebracketleftvertical'] = 0xFE3F;
  5844. t['anglebracketright'] = 0x3009;
  5845. t['anglebracketrightvertical'] = 0xFE40;
  5846. t['angleleft'] = 0x2329;
  5847. t['angleright'] = 0x232A;
  5848. t['angstrom'] = 0x212B;
  5849. t['anoteleia'] = 0x0387;
  5850. t['anudattadeva'] = 0x0952;
  5851. t['anusvarabengali'] = 0x0982;
  5852. t['anusvaradeva'] = 0x0902;
  5853. t['anusvaragujarati'] = 0x0A82;
  5854. t['aogonek'] = 0x0105;
  5855. t['apaatosquare'] = 0x3300;
  5856. t['aparen'] = 0x249C;
  5857. t['apostrophearmenian'] = 0x055A;
  5858. t['apostrophemod'] = 0x02BC;
  5859. t['apple'] = 0xF8FF;
  5860. t['approaches'] = 0x2250;
  5861. t['approxequal'] = 0x2248;
  5862. t['approxequalorimage'] = 0x2252;
  5863. t['approximatelyequal'] = 0x2245;
  5864. t['araeaekorean'] = 0x318E;
  5865. t['araeakorean'] = 0x318D;
  5866. t['arc'] = 0x2312;
  5867. t['arighthalfring'] = 0x1E9A;
  5868. t['aring'] = 0x00E5;
  5869. t['aringacute'] = 0x01FB;
  5870. t['aringbelow'] = 0x1E01;
  5871. t['arrowboth'] = 0x2194;
  5872. t['arrowdashdown'] = 0x21E3;
  5873. t['arrowdashleft'] = 0x21E0;
  5874. t['arrowdashright'] = 0x21E2;
  5875. t['arrowdashup'] = 0x21E1;
  5876. t['arrowdblboth'] = 0x21D4;
  5877. t['arrowdbldown'] = 0x21D3;
  5878. t['arrowdblleft'] = 0x21D0;
  5879. t['arrowdblright'] = 0x21D2;
  5880. t['arrowdblup'] = 0x21D1;
  5881. t['arrowdown'] = 0x2193;
  5882. t['arrowdownleft'] = 0x2199;
  5883. t['arrowdownright'] = 0x2198;
  5884. t['arrowdownwhite'] = 0x21E9;
  5885. t['arrowheaddownmod'] = 0x02C5;
  5886. t['arrowheadleftmod'] = 0x02C2;
  5887. t['arrowheadrightmod'] = 0x02C3;
  5888. t['arrowheadupmod'] = 0x02C4;
  5889. t['arrowhorizex'] = 0xF8E7;
  5890. t['arrowleft'] = 0x2190;
  5891. t['arrowleftdbl'] = 0x21D0;
  5892. t['arrowleftdblstroke'] = 0x21CD;
  5893. t['arrowleftoverright'] = 0x21C6;
  5894. t['arrowleftwhite'] = 0x21E6;
  5895. t['arrowright'] = 0x2192;
  5896. t['arrowrightdblstroke'] = 0x21CF;
  5897. t['arrowrightheavy'] = 0x279E;
  5898. t['arrowrightoverleft'] = 0x21C4;
  5899. t['arrowrightwhite'] = 0x21E8;
  5900. t['arrowtableft'] = 0x21E4;
  5901. t['arrowtabright'] = 0x21E5;
  5902. t['arrowup'] = 0x2191;
  5903. t['arrowupdn'] = 0x2195;
  5904. t['arrowupdnbse'] = 0x21A8;
  5905. t['arrowupdownbase'] = 0x21A8;
  5906. t['arrowupleft'] = 0x2196;
  5907. t['arrowupleftofdown'] = 0x21C5;
  5908. t['arrowupright'] = 0x2197;
  5909. t['arrowupwhite'] = 0x21E7;
  5910. t['arrowvertex'] = 0xF8E6;
  5911. t['asciicircum'] = 0x005E;
  5912. t['asciicircummonospace'] = 0xFF3E;
  5913. t['asciitilde'] = 0x007E;
  5914. t['asciitildemonospace'] = 0xFF5E;
  5915. t['ascript'] = 0x0251;
  5916. t['ascriptturned'] = 0x0252;
  5917. t['asmallhiragana'] = 0x3041;
  5918. t['asmallkatakana'] = 0x30A1;
  5919. t['asmallkatakanahalfwidth'] = 0xFF67;
  5920. t['asterisk'] = 0x002A;
  5921. t['asteriskaltonearabic'] = 0x066D;
  5922. t['asteriskarabic'] = 0x066D;
  5923. t['asteriskmath'] = 0x2217;
  5924. t['asteriskmonospace'] = 0xFF0A;
  5925. t['asterisksmall'] = 0xFE61;
  5926. t['asterism'] = 0x2042;
  5927. t['asuperior'] = 0xF6E9;
  5928. t['asymptoticallyequal'] = 0x2243;
  5929. t['at'] = 0x0040;
  5930. t['atilde'] = 0x00E3;
  5931. t['atmonospace'] = 0xFF20;
  5932. t['atsmall'] = 0xFE6B;
  5933. t['aturned'] = 0x0250;
  5934. t['aubengali'] = 0x0994;
  5935. t['aubopomofo'] = 0x3120;
  5936. t['audeva'] = 0x0914;
  5937. t['augujarati'] = 0x0A94;
  5938. t['augurmukhi'] = 0x0A14;
  5939. t['aulengthmarkbengali'] = 0x09D7;
  5940. t['aumatragurmukhi'] = 0x0A4C;
  5941. t['auvowelsignbengali'] = 0x09CC;
  5942. t['auvowelsigndeva'] = 0x094C;
  5943. t['auvowelsigngujarati'] = 0x0ACC;
  5944. t['avagrahadeva'] = 0x093D;
  5945. t['aybarmenian'] = 0x0561;
  5946. t['ayin'] = 0x05E2;
  5947. t['ayinaltonehebrew'] = 0xFB20;
  5948. t['ayinhebrew'] = 0x05E2;
  5949. t['b'] = 0x0062;
  5950. t['babengali'] = 0x09AC;
  5951. t['backslash'] = 0x005C;
  5952. t['backslashmonospace'] = 0xFF3C;
  5953. t['badeva'] = 0x092C;
  5954. t['bagujarati'] = 0x0AAC;
  5955. t['bagurmukhi'] = 0x0A2C;
  5956. t['bahiragana'] = 0x3070;
  5957. t['bahtthai'] = 0x0E3F;
  5958. t['bakatakana'] = 0x30D0;
  5959. t['bar'] = 0x007C;
  5960. t['barmonospace'] = 0xFF5C;
  5961. t['bbopomofo'] = 0x3105;
  5962. t['bcircle'] = 0x24D1;
  5963. t['bdotaccent'] = 0x1E03;
  5964. t['bdotbelow'] = 0x1E05;
  5965. t['beamedsixteenthnotes'] = 0x266C;
  5966. t['because'] = 0x2235;
  5967. t['becyrillic'] = 0x0431;
  5968. t['beharabic'] = 0x0628;
  5969. t['behfinalarabic'] = 0xFE90;
  5970. t['behinitialarabic'] = 0xFE91;
  5971. t['behiragana'] = 0x3079;
  5972. t['behmedialarabic'] = 0xFE92;
  5973. t['behmeeminitialarabic'] = 0xFC9F;
  5974. t['behmeemisolatedarabic'] = 0xFC08;
  5975. t['behnoonfinalarabic'] = 0xFC6D;
  5976. t['bekatakana'] = 0x30D9;
  5977. t['benarmenian'] = 0x0562;
  5978. t['bet'] = 0x05D1;
  5979. t['beta'] = 0x03B2;
  5980. t['betasymbolgreek'] = 0x03D0;
  5981. t['betdagesh'] = 0xFB31;
  5982. t['betdageshhebrew'] = 0xFB31;
  5983. t['bethebrew'] = 0x05D1;
  5984. t['betrafehebrew'] = 0xFB4C;
  5985. t['bhabengali'] = 0x09AD;
  5986. t['bhadeva'] = 0x092D;
  5987. t['bhagujarati'] = 0x0AAD;
  5988. t['bhagurmukhi'] = 0x0A2D;
  5989. t['bhook'] = 0x0253;
  5990. t['bihiragana'] = 0x3073;
  5991. t['bikatakana'] = 0x30D3;
  5992. t['bilabialclick'] = 0x0298;
  5993. t['bindigurmukhi'] = 0x0A02;
  5994. t['birusquare'] = 0x3331;
  5995. t['blackcircle'] = 0x25CF;
  5996. t['blackdiamond'] = 0x25C6;
  5997. t['blackdownpointingtriangle'] = 0x25BC;
  5998. t['blackleftpointingpointer'] = 0x25C4;
  5999. t['blackleftpointingtriangle'] = 0x25C0;
  6000. t['blacklenticularbracketleft'] = 0x3010;
  6001. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  6002. t['blacklenticularbracketright'] = 0x3011;
  6003. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  6004. t['blacklowerlefttriangle'] = 0x25E3;
  6005. t['blacklowerrighttriangle'] = 0x25E2;
  6006. t['blackrectangle'] = 0x25AC;
  6007. t['blackrightpointingpointer'] = 0x25BA;
  6008. t['blackrightpointingtriangle'] = 0x25B6;
  6009. t['blacksmallsquare'] = 0x25AA;
  6010. t['blacksmilingface'] = 0x263B;
  6011. t['blacksquare'] = 0x25A0;
  6012. t['blackstar'] = 0x2605;
  6013. t['blackupperlefttriangle'] = 0x25E4;
  6014. t['blackupperrighttriangle'] = 0x25E5;
  6015. t['blackuppointingsmalltriangle'] = 0x25B4;
  6016. t['blackuppointingtriangle'] = 0x25B2;
  6017. t['blank'] = 0x2423;
  6018. t['blinebelow'] = 0x1E07;
  6019. t['block'] = 0x2588;
  6020. t['bmonospace'] = 0xFF42;
  6021. t['bobaimaithai'] = 0x0E1A;
  6022. t['bohiragana'] = 0x307C;
  6023. t['bokatakana'] = 0x30DC;
  6024. t['bparen'] = 0x249D;
  6025. t['bqsquare'] = 0x33C3;
  6026. t['braceex'] = 0xF8F4;
  6027. t['braceleft'] = 0x007B;
  6028. t['braceleftbt'] = 0xF8F3;
  6029. t['braceleftmid'] = 0xF8F2;
  6030. t['braceleftmonospace'] = 0xFF5B;
  6031. t['braceleftsmall'] = 0xFE5B;
  6032. t['bracelefttp'] = 0xF8F1;
  6033. t['braceleftvertical'] = 0xFE37;
  6034. t['braceright'] = 0x007D;
  6035. t['bracerightbt'] = 0xF8FE;
  6036. t['bracerightmid'] = 0xF8FD;
  6037. t['bracerightmonospace'] = 0xFF5D;
  6038. t['bracerightsmall'] = 0xFE5C;
  6039. t['bracerighttp'] = 0xF8FC;
  6040. t['bracerightvertical'] = 0xFE38;
  6041. t['bracketleft'] = 0x005B;
  6042. t['bracketleftbt'] = 0xF8F0;
  6043. t['bracketleftex'] = 0xF8EF;
  6044. t['bracketleftmonospace'] = 0xFF3B;
  6045. t['bracketlefttp'] = 0xF8EE;
  6046. t['bracketright'] = 0x005D;
  6047. t['bracketrightbt'] = 0xF8FB;
  6048. t['bracketrightex'] = 0xF8FA;
  6049. t['bracketrightmonospace'] = 0xFF3D;
  6050. t['bracketrighttp'] = 0xF8F9;
  6051. t['breve'] = 0x02D8;
  6052. t['brevebelowcmb'] = 0x032E;
  6053. t['brevecmb'] = 0x0306;
  6054. t['breveinvertedbelowcmb'] = 0x032F;
  6055. t['breveinvertedcmb'] = 0x0311;
  6056. t['breveinverteddoublecmb'] = 0x0361;
  6057. t['bridgebelowcmb'] = 0x032A;
  6058. t['bridgeinvertedbelowcmb'] = 0x033A;
  6059. t['brokenbar'] = 0x00A6;
  6060. t['bstroke'] = 0x0180;
  6061. t['bsuperior'] = 0xF6EA;
  6062. t['btopbar'] = 0x0183;
  6063. t['buhiragana'] = 0x3076;
  6064. t['bukatakana'] = 0x30D6;
  6065. t['bullet'] = 0x2022;
  6066. t['bulletinverse'] = 0x25D8;
  6067. t['bulletoperator'] = 0x2219;
  6068. t['bullseye'] = 0x25CE;
  6069. t['c'] = 0x0063;
  6070. t['caarmenian'] = 0x056E;
  6071. t['cabengali'] = 0x099A;
  6072. t['cacute'] = 0x0107;
  6073. t['cadeva'] = 0x091A;
  6074. t['cagujarati'] = 0x0A9A;
  6075. t['cagurmukhi'] = 0x0A1A;
  6076. t['calsquare'] = 0x3388;
  6077. t['candrabindubengali'] = 0x0981;
  6078. t['candrabinducmb'] = 0x0310;
  6079. t['candrabindudeva'] = 0x0901;
  6080. t['candrabindugujarati'] = 0x0A81;
  6081. t['capslock'] = 0x21EA;
  6082. t['careof'] = 0x2105;
  6083. t['caron'] = 0x02C7;
  6084. t['caronbelowcmb'] = 0x032C;
  6085. t['caroncmb'] = 0x030C;
  6086. t['carriagereturn'] = 0x21B5;
  6087. t['cbopomofo'] = 0x3118;
  6088. t['ccaron'] = 0x010D;
  6089. t['ccedilla'] = 0x00E7;
  6090. t['ccedillaacute'] = 0x1E09;
  6091. t['ccircle'] = 0x24D2;
  6092. t['ccircumflex'] = 0x0109;
  6093. t['ccurl'] = 0x0255;
  6094. t['cdot'] = 0x010B;
  6095. t['cdotaccent'] = 0x010B;
  6096. t['cdsquare'] = 0x33C5;
  6097. t['cedilla'] = 0x00B8;
  6098. t['cedillacmb'] = 0x0327;
  6099. t['cent'] = 0x00A2;
  6100. t['centigrade'] = 0x2103;
  6101. t['centinferior'] = 0xF6DF;
  6102. t['centmonospace'] = 0xFFE0;
  6103. t['centoldstyle'] = 0xF7A2;
  6104. t['centsuperior'] = 0xF6E0;
  6105. t['chaarmenian'] = 0x0579;
  6106. t['chabengali'] = 0x099B;
  6107. t['chadeva'] = 0x091B;
  6108. t['chagujarati'] = 0x0A9B;
  6109. t['chagurmukhi'] = 0x0A1B;
  6110. t['chbopomofo'] = 0x3114;
  6111. t['cheabkhasiancyrillic'] = 0x04BD;
  6112. t['checkmark'] = 0x2713;
  6113. t['checyrillic'] = 0x0447;
  6114. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6115. t['chedescendercyrillic'] = 0x04B7;
  6116. t['chedieresiscyrillic'] = 0x04F5;
  6117. t['cheharmenian'] = 0x0573;
  6118. t['chekhakassiancyrillic'] = 0x04CC;
  6119. t['cheverticalstrokecyrillic'] = 0x04B9;
  6120. t['chi'] = 0x03C7;
  6121. t['chieuchacirclekorean'] = 0x3277;
  6122. t['chieuchaparenkorean'] = 0x3217;
  6123. t['chieuchcirclekorean'] = 0x3269;
  6124. t['chieuchkorean'] = 0x314A;
  6125. t['chieuchparenkorean'] = 0x3209;
  6126. t['chochangthai'] = 0x0E0A;
  6127. t['chochanthai'] = 0x0E08;
  6128. t['chochingthai'] = 0x0E09;
  6129. t['chochoethai'] = 0x0E0C;
  6130. t['chook'] = 0x0188;
  6131. t['cieucacirclekorean'] = 0x3276;
  6132. t['cieucaparenkorean'] = 0x3216;
  6133. t['cieuccirclekorean'] = 0x3268;
  6134. t['cieuckorean'] = 0x3148;
  6135. t['cieucparenkorean'] = 0x3208;
  6136. t['cieucuparenkorean'] = 0x321C;
  6137. t['circle'] = 0x25CB;
  6138. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6139. t['circlemultiply'] = 0x2297;
  6140. t['circleot'] = 0x2299;
  6141. t['circleplus'] = 0x2295;
  6142. t['circlepostalmark'] = 0x3036;
  6143. t['circlewithlefthalfblack'] = 0x25D0;
  6144. t['circlewithrighthalfblack'] = 0x25D1;
  6145. t['circumflex'] = 0x02C6;
  6146. t['circumflexbelowcmb'] = 0x032D;
  6147. t['circumflexcmb'] = 0x0302;
  6148. t['clear'] = 0x2327;
  6149. t['clickalveolar'] = 0x01C2;
  6150. t['clickdental'] = 0x01C0;
  6151. t['clicklateral'] = 0x01C1;
  6152. t['clickretroflex'] = 0x01C3;
  6153. t['club'] = 0x2663;
  6154. t['clubsuitblack'] = 0x2663;
  6155. t['clubsuitwhite'] = 0x2667;
  6156. t['cmcubedsquare'] = 0x33A4;
  6157. t['cmonospace'] = 0xFF43;
  6158. t['cmsquaredsquare'] = 0x33A0;
  6159. t['coarmenian'] = 0x0581;
  6160. t['colon'] = 0x003A;
  6161. t['colonmonetary'] = 0x20A1;
  6162. t['colonmonospace'] = 0xFF1A;
  6163. t['colonsign'] = 0x20A1;
  6164. t['colonsmall'] = 0xFE55;
  6165. t['colontriangularhalfmod'] = 0x02D1;
  6166. t['colontriangularmod'] = 0x02D0;
  6167. t['comma'] = 0x002C;
  6168. t['commaabovecmb'] = 0x0313;
  6169. t['commaaboverightcmb'] = 0x0315;
  6170. t['commaaccent'] = 0xF6C3;
  6171. t['commaarabic'] = 0x060C;
  6172. t['commaarmenian'] = 0x055D;
  6173. t['commainferior'] = 0xF6E1;
  6174. t['commamonospace'] = 0xFF0C;
  6175. t['commareversedabovecmb'] = 0x0314;
  6176. t['commareversedmod'] = 0x02BD;
  6177. t['commasmall'] = 0xFE50;
  6178. t['commasuperior'] = 0xF6E2;
  6179. t['commaturnedabovecmb'] = 0x0312;
  6180. t['commaturnedmod'] = 0x02BB;
  6181. t['compass'] = 0x263C;
  6182. t['congruent'] = 0x2245;
  6183. t['contourintegral'] = 0x222E;
  6184. t['control'] = 0x2303;
  6185. t['controlACK'] = 0x0006;
  6186. t['controlBEL'] = 0x0007;
  6187. t['controlBS'] = 0x0008;
  6188. t['controlCAN'] = 0x0018;
  6189. t['controlCR'] = 0x000D;
  6190. t['controlDC1'] = 0x0011;
  6191. t['controlDC2'] = 0x0012;
  6192. t['controlDC3'] = 0x0013;
  6193. t['controlDC4'] = 0x0014;
  6194. t['controlDEL'] = 0x007F;
  6195. t['controlDLE'] = 0x0010;
  6196. t['controlEM'] = 0x0019;
  6197. t['controlENQ'] = 0x0005;
  6198. t['controlEOT'] = 0x0004;
  6199. t['controlESC'] = 0x001B;
  6200. t['controlETB'] = 0x0017;
  6201. t['controlETX'] = 0x0003;
  6202. t['controlFF'] = 0x000C;
  6203. t['controlFS'] = 0x001C;
  6204. t['controlGS'] = 0x001D;
  6205. t['controlHT'] = 0x0009;
  6206. t['controlLF'] = 0x000A;
  6207. t['controlNAK'] = 0x0015;
  6208. t['controlRS'] = 0x001E;
  6209. t['controlSI'] = 0x000F;
  6210. t['controlSO'] = 0x000E;
  6211. t['controlSOT'] = 0x0002;
  6212. t['controlSTX'] = 0x0001;
  6213. t['controlSUB'] = 0x001A;
  6214. t['controlSYN'] = 0x0016;
  6215. t['controlUS'] = 0x001F;
  6216. t['controlVT'] = 0x000B;
  6217. t['copyright'] = 0x00A9;
  6218. t['copyrightsans'] = 0xF8E9;
  6219. t['copyrightserif'] = 0xF6D9;
  6220. t['cornerbracketleft'] = 0x300C;
  6221. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6222. t['cornerbracketleftvertical'] = 0xFE41;
  6223. t['cornerbracketright'] = 0x300D;
  6224. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6225. t['cornerbracketrightvertical'] = 0xFE42;
  6226. t['corporationsquare'] = 0x337F;
  6227. t['cosquare'] = 0x33C7;
  6228. t['coverkgsquare'] = 0x33C6;
  6229. t['cparen'] = 0x249E;
  6230. t['cruzeiro'] = 0x20A2;
  6231. t['cstretched'] = 0x0297;
  6232. t['curlyand'] = 0x22CF;
  6233. t['curlyor'] = 0x22CE;
  6234. t['currency'] = 0x00A4;
  6235. t['cyrBreve'] = 0xF6D1;
  6236. t['cyrFlex'] = 0xF6D2;
  6237. t['cyrbreve'] = 0xF6D4;
  6238. t['cyrflex'] = 0xF6D5;
  6239. t['d'] = 0x0064;
  6240. t['daarmenian'] = 0x0564;
  6241. t['dabengali'] = 0x09A6;
  6242. t['dadarabic'] = 0x0636;
  6243. t['dadeva'] = 0x0926;
  6244. t['dadfinalarabic'] = 0xFEBE;
  6245. t['dadinitialarabic'] = 0xFEBF;
  6246. t['dadmedialarabic'] = 0xFEC0;
  6247. t['dagesh'] = 0x05BC;
  6248. t['dageshhebrew'] = 0x05BC;
  6249. t['dagger'] = 0x2020;
  6250. t['daggerdbl'] = 0x2021;
  6251. t['dagujarati'] = 0x0AA6;
  6252. t['dagurmukhi'] = 0x0A26;
  6253. t['dahiragana'] = 0x3060;
  6254. t['dakatakana'] = 0x30C0;
  6255. t['dalarabic'] = 0x062F;
  6256. t['dalet'] = 0x05D3;
  6257. t['daletdagesh'] = 0xFB33;
  6258. t['daletdageshhebrew'] = 0xFB33;
  6259. t['dalethebrew'] = 0x05D3;
  6260. t['dalfinalarabic'] = 0xFEAA;
  6261. t['dammaarabic'] = 0x064F;
  6262. t['dammalowarabic'] = 0x064F;
  6263. t['dammatanaltonearabic'] = 0x064C;
  6264. t['dammatanarabic'] = 0x064C;
  6265. t['danda'] = 0x0964;
  6266. t['dargahebrew'] = 0x05A7;
  6267. t['dargalefthebrew'] = 0x05A7;
  6268. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6269. t['dblGrave'] = 0xF6D3;
  6270. t['dblanglebracketleft'] = 0x300A;
  6271. t['dblanglebracketleftvertical'] = 0xFE3D;
  6272. t['dblanglebracketright'] = 0x300B;
  6273. t['dblanglebracketrightvertical'] = 0xFE3E;
  6274. t['dblarchinvertedbelowcmb'] = 0x032B;
  6275. t['dblarrowleft'] = 0x21D4;
  6276. t['dblarrowright'] = 0x21D2;
  6277. t['dbldanda'] = 0x0965;
  6278. t['dblgrave'] = 0xF6D6;
  6279. t['dblgravecmb'] = 0x030F;
  6280. t['dblintegral'] = 0x222C;
  6281. t['dbllowline'] = 0x2017;
  6282. t['dbllowlinecmb'] = 0x0333;
  6283. t['dbloverlinecmb'] = 0x033F;
  6284. t['dblprimemod'] = 0x02BA;
  6285. t['dblverticalbar'] = 0x2016;
  6286. t['dblverticallineabovecmb'] = 0x030E;
  6287. t['dbopomofo'] = 0x3109;
  6288. t['dbsquare'] = 0x33C8;
  6289. t['dcaron'] = 0x010F;
  6290. t['dcedilla'] = 0x1E11;
  6291. t['dcircle'] = 0x24D3;
  6292. t['dcircumflexbelow'] = 0x1E13;
  6293. t['dcroat'] = 0x0111;
  6294. t['ddabengali'] = 0x09A1;
  6295. t['ddadeva'] = 0x0921;
  6296. t['ddagujarati'] = 0x0AA1;
  6297. t['ddagurmukhi'] = 0x0A21;
  6298. t['ddalarabic'] = 0x0688;
  6299. t['ddalfinalarabic'] = 0xFB89;
  6300. t['dddhadeva'] = 0x095C;
  6301. t['ddhabengali'] = 0x09A2;
  6302. t['ddhadeva'] = 0x0922;
  6303. t['ddhagujarati'] = 0x0AA2;
  6304. t['ddhagurmukhi'] = 0x0A22;
  6305. t['ddotaccent'] = 0x1E0B;
  6306. t['ddotbelow'] = 0x1E0D;
  6307. t['decimalseparatorarabic'] = 0x066B;
  6308. t['decimalseparatorpersian'] = 0x066B;
  6309. t['decyrillic'] = 0x0434;
  6310. t['degree'] = 0x00B0;
  6311. t['dehihebrew'] = 0x05AD;
  6312. t['dehiragana'] = 0x3067;
  6313. t['deicoptic'] = 0x03EF;
  6314. t['dekatakana'] = 0x30C7;
  6315. t['deleteleft'] = 0x232B;
  6316. t['deleteright'] = 0x2326;
  6317. t['delta'] = 0x03B4;
  6318. t['deltaturned'] = 0x018D;
  6319. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6320. t['dezh'] = 0x02A4;
  6321. t['dhabengali'] = 0x09A7;
  6322. t['dhadeva'] = 0x0927;
  6323. t['dhagujarati'] = 0x0AA7;
  6324. t['dhagurmukhi'] = 0x0A27;
  6325. t['dhook'] = 0x0257;
  6326. t['dialytikatonos'] = 0x0385;
  6327. t['dialytikatonoscmb'] = 0x0344;
  6328. t['diamond'] = 0x2666;
  6329. t['diamondsuitwhite'] = 0x2662;
  6330. t['dieresis'] = 0x00A8;
  6331. t['dieresisacute'] = 0xF6D7;
  6332. t['dieresisbelowcmb'] = 0x0324;
  6333. t['dieresiscmb'] = 0x0308;
  6334. t['dieresisgrave'] = 0xF6D8;
  6335. t['dieresistonos'] = 0x0385;
  6336. t['dihiragana'] = 0x3062;
  6337. t['dikatakana'] = 0x30C2;
  6338. t['dittomark'] = 0x3003;
  6339. t['divide'] = 0x00F7;
  6340. t['divides'] = 0x2223;
  6341. t['divisionslash'] = 0x2215;
  6342. t['djecyrillic'] = 0x0452;
  6343. t['dkshade'] = 0x2593;
  6344. t['dlinebelow'] = 0x1E0F;
  6345. t['dlsquare'] = 0x3397;
  6346. t['dmacron'] = 0x0111;
  6347. t['dmonospace'] = 0xFF44;
  6348. t['dnblock'] = 0x2584;
  6349. t['dochadathai'] = 0x0E0E;
  6350. t['dodekthai'] = 0x0E14;
  6351. t['dohiragana'] = 0x3069;
  6352. t['dokatakana'] = 0x30C9;
  6353. t['dollar'] = 0x0024;
  6354. t['dollarinferior'] = 0xF6E3;
  6355. t['dollarmonospace'] = 0xFF04;
  6356. t['dollaroldstyle'] = 0xF724;
  6357. t['dollarsmall'] = 0xFE69;
  6358. t['dollarsuperior'] = 0xF6E4;
  6359. t['dong'] = 0x20AB;
  6360. t['dorusquare'] = 0x3326;
  6361. t['dotaccent'] = 0x02D9;
  6362. t['dotaccentcmb'] = 0x0307;
  6363. t['dotbelowcmb'] = 0x0323;
  6364. t['dotbelowcomb'] = 0x0323;
  6365. t['dotkatakana'] = 0x30FB;
  6366. t['dotlessi'] = 0x0131;
  6367. t['dotlessj'] = 0xF6BE;
  6368. t['dotlessjstrokehook'] = 0x0284;
  6369. t['dotmath'] = 0x22C5;
  6370. t['dottedcircle'] = 0x25CC;
  6371. t['doubleyodpatah'] = 0xFB1F;
  6372. t['doubleyodpatahhebrew'] = 0xFB1F;
  6373. t['downtackbelowcmb'] = 0x031E;
  6374. t['downtackmod'] = 0x02D5;
  6375. t['dparen'] = 0x249F;
  6376. t['dsuperior'] = 0xF6EB;
  6377. t['dtail'] = 0x0256;
  6378. t['dtopbar'] = 0x018C;
  6379. t['duhiragana'] = 0x3065;
  6380. t['dukatakana'] = 0x30C5;
  6381. t['dz'] = 0x01F3;
  6382. t['dzaltone'] = 0x02A3;
  6383. t['dzcaron'] = 0x01C6;
  6384. t['dzcurl'] = 0x02A5;
  6385. t['dzeabkhasiancyrillic'] = 0x04E1;
  6386. t['dzecyrillic'] = 0x0455;
  6387. t['dzhecyrillic'] = 0x045F;
  6388. t['e'] = 0x0065;
  6389. t['eacute'] = 0x00E9;
  6390. t['earth'] = 0x2641;
  6391. t['ebengali'] = 0x098F;
  6392. t['ebopomofo'] = 0x311C;
  6393. t['ebreve'] = 0x0115;
  6394. t['ecandradeva'] = 0x090D;
  6395. t['ecandragujarati'] = 0x0A8D;
  6396. t['ecandravowelsigndeva'] = 0x0945;
  6397. t['ecandravowelsigngujarati'] = 0x0AC5;
  6398. t['ecaron'] = 0x011B;
  6399. t['ecedillabreve'] = 0x1E1D;
  6400. t['echarmenian'] = 0x0565;
  6401. t['echyiwnarmenian'] = 0x0587;
  6402. t['ecircle'] = 0x24D4;
  6403. t['ecircumflex'] = 0x00EA;
  6404. t['ecircumflexacute'] = 0x1EBF;
  6405. t['ecircumflexbelow'] = 0x1E19;
  6406. t['ecircumflexdotbelow'] = 0x1EC7;
  6407. t['ecircumflexgrave'] = 0x1EC1;
  6408. t['ecircumflexhookabove'] = 0x1EC3;
  6409. t['ecircumflextilde'] = 0x1EC5;
  6410. t['ecyrillic'] = 0x0454;
  6411. t['edblgrave'] = 0x0205;
  6412. t['edeva'] = 0x090F;
  6413. t['edieresis'] = 0x00EB;
  6414. t['edot'] = 0x0117;
  6415. t['edotaccent'] = 0x0117;
  6416. t['edotbelow'] = 0x1EB9;
  6417. t['eegurmukhi'] = 0x0A0F;
  6418. t['eematragurmukhi'] = 0x0A47;
  6419. t['efcyrillic'] = 0x0444;
  6420. t['egrave'] = 0x00E8;
  6421. t['egujarati'] = 0x0A8F;
  6422. t['eharmenian'] = 0x0567;
  6423. t['ehbopomofo'] = 0x311D;
  6424. t['ehiragana'] = 0x3048;
  6425. t['ehookabove'] = 0x1EBB;
  6426. t['eibopomofo'] = 0x311F;
  6427. t['eight'] = 0x0038;
  6428. t['eightarabic'] = 0x0668;
  6429. t['eightbengali'] = 0x09EE;
  6430. t['eightcircle'] = 0x2467;
  6431. t['eightcircleinversesansserif'] = 0x2791;
  6432. t['eightdeva'] = 0x096E;
  6433. t['eighteencircle'] = 0x2471;
  6434. t['eighteenparen'] = 0x2485;
  6435. t['eighteenperiod'] = 0x2499;
  6436. t['eightgujarati'] = 0x0AEE;
  6437. t['eightgurmukhi'] = 0x0A6E;
  6438. t['eighthackarabic'] = 0x0668;
  6439. t['eighthangzhou'] = 0x3028;
  6440. t['eighthnotebeamed'] = 0x266B;
  6441. t['eightideographicparen'] = 0x3227;
  6442. t['eightinferior'] = 0x2088;
  6443. t['eightmonospace'] = 0xFF18;
  6444. t['eightoldstyle'] = 0xF738;
  6445. t['eightparen'] = 0x247B;
  6446. t['eightperiod'] = 0x248F;
  6447. t['eightpersian'] = 0x06F8;
  6448. t['eightroman'] = 0x2177;
  6449. t['eightsuperior'] = 0x2078;
  6450. t['eightthai'] = 0x0E58;
  6451. t['einvertedbreve'] = 0x0207;
  6452. t['eiotifiedcyrillic'] = 0x0465;
  6453. t['ekatakana'] = 0x30A8;
  6454. t['ekatakanahalfwidth'] = 0xFF74;
  6455. t['ekonkargurmukhi'] = 0x0A74;
  6456. t['ekorean'] = 0x3154;
  6457. t['elcyrillic'] = 0x043B;
  6458. t['element'] = 0x2208;
  6459. t['elevencircle'] = 0x246A;
  6460. t['elevenparen'] = 0x247E;
  6461. t['elevenperiod'] = 0x2492;
  6462. t['elevenroman'] = 0x217A;
  6463. t['ellipsis'] = 0x2026;
  6464. t['ellipsisvertical'] = 0x22EE;
  6465. t['emacron'] = 0x0113;
  6466. t['emacronacute'] = 0x1E17;
  6467. t['emacrongrave'] = 0x1E15;
  6468. t['emcyrillic'] = 0x043C;
  6469. t['emdash'] = 0x2014;
  6470. t['emdashvertical'] = 0xFE31;
  6471. t['emonospace'] = 0xFF45;
  6472. t['emphasismarkarmenian'] = 0x055B;
  6473. t['emptyset'] = 0x2205;
  6474. t['enbopomofo'] = 0x3123;
  6475. t['encyrillic'] = 0x043D;
  6476. t['endash'] = 0x2013;
  6477. t['endashvertical'] = 0xFE32;
  6478. t['endescendercyrillic'] = 0x04A3;
  6479. t['eng'] = 0x014B;
  6480. t['engbopomofo'] = 0x3125;
  6481. t['enghecyrillic'] = 0x04A5;
  6482. t['enhookcyrillic'] = 0x04C8;
  6483. t['enspace'] = 0x2002;
  6484. t['eogonek'] = 0x0119;
  6485. t['eokorean'] = 0x3153;
  6486. t['eopen'] = 0x025B;
  6487. t['eopenclosed'] = 0x029A;
  6488. t['eopenreversed'] = 0x025C;
  6489. t['eopenreversedclosed'] = 0x025E;
  6490. t['eopenreversedhook'] = 0x025D;
  6491. t['eparen'] = 0x24A0;
  6492. t['epsilon'] = 0x03B5;
  6493. t['epsilontonos'] = 0x03AD;
  6494. t['equal'] = 0x003D;
  6495. t['equalmonospace'] = 0xFF1D;
  6496. t['equalsmall'] = 0xFE66;
  6497. t['equalsuperior'] = 0x207C;
  6498. t['equivalence'] = 0x2261;
  6499. t['erbopomofo'] = 0x3126;
  6500. t['ercyrillic'] = 0x0440;
  6501. t['ereversed'] = 0x0258;
  6502. t['ereversedcyrillic'] = 0x044D;
  6503. t['escyrillic'] = 0x0441;
  6504. t['esdescendercyrillic'] = 0x04AB;
  6505. t['esh'] = 0x0283;
  6506. t['eshcurl'] = 0x0286;
  6507. t['eshortdeva'] = 0x090E;
  6508. t['eshortvowelsigndeva'] = 0x0946;
  6509. t['eshreversedloop'] = 0x01AA;
  6510. t['eshsquatreversed'] = 0x0285;
  6511. t['esmallhiragana'] = 0x3047;
  6512. t['esmallkatakana'] = 0x30A7;
  6513. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6514. t['estimated'] = 0x212E;
  6515. t['esuperior'] = 0xF6EC;
  6516. t['eta'] = 0x03B7;
  6517. t['etarmenian'] = 0x0568;
  6518. t['etatonos'] = 0x03AE;
  6519. t['eth'] = 0x00F0;
  6520. t['etilde'] = 0x1EBD;
  6521. t['etildebelow'] = 0x1E1B;
  6522. t['etnahtafoukhhebrew'] = 0x0591;
  6523. t['etnahtafoukhlefthebrew'] = 0x0591;
  6524. t['etnahtahebrew'] = 0x0591;
  6525. t['etnahtalefthebrew'] = 0x0591;
  6526. t['eturned'] = 0x01DD;
  6527. t['eukorean'] = 0x3161;
  6528. t['euro'] = 0x20AC;
  6529. t['evowelsignbengali'] = 0x09C7;
  6530. t['evowelsigndeva'] = 0x0947;
  6531. t['evowelsigngujarati'] = 0x0AC7;
  6532. t['exclam'] = 0x0021;
  6533. t['exclamarmenian'] = 0x055C;
  6534. t['exclamdbl'] = 0x203C;
  6535. t['exclamdown'] = 0x00A1;
  6536. t['exclamdownsmall'] = 0xF7A1;
  6537. t['exclammonospace'] = 0xFF01;
  6538. t['exclamsmall'] = 0xF721;
  6539. t['existential'] = 0x2203;
  6540. t['ezh'] = 0x0292;
  6541. t['ezhcaron'] = 0x01EF;
  6542. t['ezhcurl'] = 0x0293;
  6543. t['ezhreversed'] = 0x01B9;
  6544. t['ezhtail'] = 0x01BA;
  6545. t['f'] = 0x0066;
  6546. t['fadeva'] = 0x095E;
  6547. t['fagurmukhi'] = 0x0A5E;
  6548. t['fahrenheit'] = 0x2109;
  6549. t['fathaarabic'] = 0x064E;
  6550. t['fathalowarabic'] = 0x064E;
  6551. t['fathatanarabic'] = 0x064B;
  6552. t['fbopomofo'] = 0x3108;
  6553. t['fcircle'] = 0x24D5;
  6554. t['fdotaccent'] = 0x1E1F;
  6555. t['feharabic'] = 0x0641;
  6556. t['feharmenian'] = 0x0586;
  6557. t['fehfinalarabic'] = 0xFED2;
  6558. t['fehinitialarabic'] = 0xFED3;
  6559. t['fehmedialarabic'] = 0xFED4;
  6560. t['feicoptic'] = 0x03E5;
  6561. t['female'] = 0x2640;
  6562. t['ff'] = 0xFB00;
  6563. t['ffi'] = 0xFB03;
  6564. t['ffl'] = 0xFB04;
  6565. t['fi'] = 0xFB01;
  6566. t['fifteencircle'] = 0x246E;
  6567. t['fifteenparen'] = 0x2482;
  6568. t['fifteenperiod'] = 0x2496;
  6569. t['figuredash'] = 0x2012;
  6570. t['filledbox'] = 0x25A0;
  6571. t['filledrect'] = 0x25AC;
  6572. t['finalkaf'] = 0x05DA;
  6573. t['finalkafdagesh'] = 0xFB3A;
  6574. t['finalkafdageshhebrew'] = 0xFB3A;
  6575. t['finalkafhebrew'] = 0x05DA;
  6576. t['finalmem'] = 0x05DD;
  6577. t['finalmemhebrew'] = 0x05DD;
  6578. t['finalnun'] = 0x05DF;
  6579. t['finalnunhebrew'] = 0x05DF;
  6580. t['finalpe'] = 0x05E3;
  6581. t['finalpehebrew'] = 0x05E3;
  6582. t['finaltsadi'] = 0x05E5;
  6583. t['finaltsadihebrew'] = 0x05E5;
  6584. t['firsttonechinese'] = 0x02C9;
  6585. t['fisheye'] = 0x25C9;
  6586. t['fitacyrillic'] = 0x0473;
  6587. t['five'] = 0x0035;
  6588. t['fivearabic'] = 0x0665;
  6589. t['fivebengali'] = 0x09EB;
  6590. t['fivecircle'] = 0x2464;
  6591. t['fivecircleinversesansserif'] = 0x278E;
  6592. t['fivedeva'] = 0x096B;
  6593. t['fiveeighths'] = 0x215D;
  6594. t['fivegujarati'] = 0x0AEB;
  6595. t['fivegurmukhi'] = 0x0A6B;
  6596. t['fivehackarabic'] = 0x0665;
  6597. t['fivehangzhou'] = 0x3025;
  6598. t['fiveideographicparen'] = 0x3224;
  6599. t['fiveinferior'] = 0x2085;
  6600. t['fivemonospace'] = 0xFF15;
  6601. t['fiveoldstyle'] = 0xF735;
  6602. t['fiveparen'] = 0x2478;
  6603. t['fiveperiod'] = 0x248C;
  6604. t['fivepersian'] = 0x06F5;
  6605. t['fiveroman'] = 0x2174;
  6606. t['fivesuperior'] = 0x2075;
  6607. t['fivethai'] = 0x0E55;
  6608. t['fl'] = 0xFB02;
  6609. t['florin'] = 0x0192;
  6610. t['fmonospace'] = 0xFF46;
  6611. t['fmsquare'] = 0x3399;
  6612. t['fofanthai'] = 0x0E1F;
  6613. t['fofathai'] = 0x0E1D;
  6614. t['fongmanthai'] = 0x0E4F;
  6615. t['forall'] = 0x2200;
  6616. t['four'] = 0x0034;
  6617. t['fourarabic'] = 0x0664;
  6618. t['fourbengali'] = 0x09EA;
  6619. t['fourcircle'] = 0x2463;
  6620. t['fourcircleinversesansserif'] = 0x278D;
  6621. t['fourdeva'] = 0x096A;
  6622. t['fourgujarati'] = 0x0AEA;
  6623. t['fourgurmukhi'] = 0x0A6A;
  6624. t['fourhackarabic'] = 0x0664;
  6625. t['fourhangzhou'] = 0x3024;
  6626. t['fourideographicparen'] = 0x3223;
  6627. t['fourinferior'] = 0x2084;
  6628. t['fourmonospace'] = 0xFF14;
  6629. t['fournumeratorbengali'] = 0x09F7;
  6630. t['fouroldstyle'] = 0xF734;
  6631. t['fourparen'] = 0x2477;
  6632. t['fourperiod'] = 0x248B;
  6633. t['fourpersian'] = 0x06F4;
  6634. t['fourroman'] = 0x2173;
  6635. t['foursuperior'] = 0x2074;
  6636. t['fourteencircle'] = 0x246D;
  6637. t['fourteenparen'] = 0x2481;
  6638. t['fourteenperiod'] = 0x2495;
  6639. t['fourthai'] = 0x0E54;
  6640. t['fourthtonechinese'] = 0x02CB;
  6641. t['fparen'] = 0x24A1;
  6642. t['fraction'] = 0x2044;
  6643. t['franc'] = 0x20A3;
  6644. t['g'] = 0x0067;
  6645. t['gabengali'] = 0x0997;
  6646. t['gacute'] = 0x01F5;
  6647. t['gadeva'] = 0x0917;
  6648. t['gafarabic'] = 0x06AF;
  6649. t['gaffinalarabic'] = 0xFB93;
  6650. t['gafinitialarabic'] = 0xFB94;
  6651. t['gafmedialarabic'] = 0xFB95;
  6652. t['gagujarati'] = 0x0A97;
  6653. t['gagurmukhi'] = 0x0A17;
  6654. t['gahiragana'] = 0x304C;
  6655. t['gakatakana'] = 0x30AC;
  6656. t['gamma'] = 0x03B3;
  6657. t['gammalatinsmall'] = 0x0263;
  6658. t['gammasuperior'] = 0x02E0;
  6659. t['gangiacoptic'] = 0x03EB;
  6660. t['gbopomofo'] = 0x310D;
  6661. t['gbreve'] = 0x011F;
  6662. t['gcaron'] = 0x01E7;
  6663. t['gcedilla'] = 0x0123;
  6664. t['gcircle'] = 0x24D6;
  6665. t['gcircumflex'] = 0x011D;
  6666. t['gcommaaccent'] = 0x0123;
  6667. t['gdot'] = 0x0121;
  6668. t['gdotaccent'] = 0x0121;
  6669. t['gecyrillic'] = 0x0433;
  6670. t['gehiragana'] = 0x3052;
  6671. t['gekatakana'] = 0x30B2;
  6672. t['geometricallyequal'] = 0x2251;
  6673. t['gereshaccenthebrew'] = 0x059C;
  6674. t['gereshhebrew'] = 0x05F3;
  6675. t['gereshmuqdamhebrew'] = 0x059D;
  6676. t['germandbls'] = 0x00DF;
  6677. t['gershayimaccenthebrew'] = 0x059E;
  6678. t['gershayimhebrew'] = 0x05F4;
  6679. t['getamark'] = 0x3013;
  6680. t['ghabengali'] = 0x0998;
  6681. t['ghadarmenian'] = 0x0572;
  6682. t['ghadeva'] = 0x0918;
  6683. t['ghagujarati'] = 0x0A98;
  6684. t['ghagurmukhi'] = 0x0A18;
  6685. t['ghainarabic'] = 0x063A;
  6686. t['ghainfinalarabic'] = 0xFECE;
  6687. t['ghaininitialarabic'] = 0xFECF;
  6688. t['ghainmedialarabic'] = 0xFED0;
  6689. t['ghemiddlehookcyrillic'] = 0x0495;
  6690. t['ghestrokecyrillic'] = 0x0493;
  6691. t['gheupturncyrillic'] = 0x0491;
  6692. t['ghhadeva'] = 0x095A;
  6693. t['ghhagurmukhi'] = 0x0A5A;
  6694. t['ghook'] = 0x0260;
  6695. t['ghzsquare'] = 0x3393;
  6696. t['gihiragana'] = 0x304E;
  6697. t['gikatakana'] = 0x30AE;
  6698. t['gimarmenian'] = 0x0563;
  6699. t['gimel'] = 0x05D2;
  6700. t['gimeldagesh'] = 0xFB32;
  6701. t['gimeldageshhebrew'] = 0xFB32;
  6702. t['gimelhebrew'] = 0x05D2;
  6703. t['gjecyrillic'] = 0x0453;
  6704. t['glottalinvertedstroke'] = 0x01BE;
  6705. t['glottalstop'] = 0x0294;
  6706. t['glottalstopinverted'] = 0x0296;
  6707. t['glottalstopmod'] = 0x02C0;
  6708. t['glottalstopreversed'] = 0x0295;
  6709. t['glottalstopreversedmod'] = 0x02C1;
  6710. t['glottalstopreversedsuperior'] = 0x02E4;
  6711. t['glottalstopstroke'] = 0x02A1;
  6712. t['glottalstopstrokereversed'] = 0x02A2;
  6713. t['gmacron'] = 0x1E21;
  6714. t['gmonospace'] = 0xFF47;
  6715. t['gohiragana'] = 0x3054;
  6716. t['gokatakana'] = 0x30B4;
  6717. t['gparen'] = 0x24A2;
  6718. t['gpasquare'] = 0x33AC;
  6719. t['gradient'] = 0x2207;
  6720. t['grave'] = 0x0060;
  6721. t['gravebelowcmb'] = 0x0316;
  6722. t['gravecmb'] = 0x0300;
  6723. t['gravecomb'] = 0x0300;
  6724. t['gravedeva'] = 0x0953;
  6725. t['gravelowmod'] = 0x02CE;
  6726. t['gravemonospace'] = 0xFF40;
  6727. t['gravetonecmb'] = 0x0340;
  6728. t['greater'] = 0x003E;
  6729. t['greaterequal'] = 0x2265;
  6730. t['greaterequalorless'] = 0x22DB;
  6731. t['greatermonospace'] = 0xFF1E;
  6732. t['greaterorequivalent'] = 0x2273;
  6733. t['greaterorless'] = 0x2277;
  6734. t['greateroverequal'] = 0x2267;
  6735. t['greatersmall'] = 0xFE65;
  6736. t['gscript'] = 0x0261;
  6737. t['gstroke'] = 0x01E5;
  6738. t['guhiragana'] = 0x3050;
  6739. t['guillemotleft'] = 0x00AB;
  6740. t['guillemotright'] = 0x00BB;
  6741. t['guilsinglleft'] = 0x2039;
  6742. t['guilsinglright'] = 0x203A;
  6743. t['gukatakana'] = 0x30B0;
  6744. t['guramusquare'] = 0x3318;
  6745. t['gysquare'] = 0x33C9;
  6746. t['h'] = 0x0068;
  6747. t['haabkhasiancyrillic'] = 0x04A9;
  6748. t['haaltonearabic'] = 0x06C1;
  6749. t['habengali'] = 0x09B9;
  6750. t['hadescendercyrillic'] = 0x04B3;
  6751. t['hadeva'] = 0x0939;
  6752. t['hagujarati'] = 0x0AB9;
  6753. t['hagurmukhi'] = 0x0A39;
  6754. t['haharabic'] = 0x062D;
  6755. t['hahfinalarabic'] = 0xFEA2;
  6756. t['hahinitialarabic'] = 0xFEA3;
  6757. t['hahiragana'] = 0x306F;
  6758. t['hahmedialarabic'] = 0xFEA4;
  6759. t['haitusquare'] = 0x332A;
  6760. t['hakatakana'] = 0x30CF;
  6761. t['hakatakanahalfwidth'] = 0xFF8A;
  6762. t['halantgurmukhi'] = 0x0A4D;
  6763. t['hamzaarabic'] = 0x0621;
  6764. t['hamzalowarabic'] = 0x0621;
  6765. t['hangulfiller'] = 0x3164;
  6766. t['hardsigncyrillic'] = 0x044A;
  6767. t['harpoonleftbarbup'] = 0x21BC;
  6768. t['harpoonrightbarbup'] = 0x21C0;
  6769. t['hasquare'] = 0x33CA;
  6770. t['hatafpatah'] = 0x05B2;
  6771. t['hatafpatah16'] = 0x05B2;
  6772. t['hatafpatah23'] = 0x05B2;
  6773. t['hatafpatah2f'] = 0x05B2;
  6774. t['hatafpatahhebrew'] = 0x05B2;
  6775. t['hatafpatahnarrowhebrew'] = 0x05B2;
  6776. t['hatafpatahquarterhebrew'] = 0x05B2;
  6777. t['hatafpatahwidehebrew'] = 0x05B2;
  6778. t['hatafqamats'] = 0x05B3;
  6779. t['hatafqamats1b'] = 0x05B3;
  6780. t['hatafqamats28'] = 0x05B3;
  6781. t['hatafqamats34'] = 0x05B3;
  6782. t['hatafqamatshebrew'] = 0x05B3;
  6783. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  6784. t['hatafqamatsquarterhebrew'] = 0x05B3;
  6785. t['hatafqamatswidehebrew'] = 0x05B3;
  6786. t['hatafsegol'] = 0x05B1;
  6787. t['hatafsegol17'] = 0x05B1;
  6788. t['hatafsegol24'] = 0x05B1;
  6789. t['hatafsegol30'] = 0x05B1;
  6790. t['hatafsegolhebrew'] = 0x05B1;
  6791. t['hatafsegolnarrowhebrew'] = 0x05B1;
  6792. t['hatafsegolquarterhebrew'] = 0x05B1;
  6793. t['hatafsegolwidehebrew'] = 0x05B1;
  6794. t['hbar'] = 0x0127;
  6795. t['hbopomofo'] = 0x310F;
  6796. t['hbrevebelow'] = 0x1E2B;
  6797. t['hcedilla'] = 0x1E29;
  6798. t['hcircle'] = 0x24D7;
  6799. t['hcircumflex'] = 0x0125;
  6800. t['hdieresis'] = 0x1E27;
  6801. t['hdotaccent'] = 0x1E23;
  6802. t['hdotbelow'] = 0x1E25;
  6803. t['he'] = 0x05D4;
  6804. t['heart'] = 0x2665;
  6805. t['heartsuitblack'] = 0x2665;
  6806. t['heartsuitwhite'] = 0x2661;
  6807. t['hedagesh'] = 0xFB34;
  6808. t['hedageshhebrew'] = 0xFB34;
  6809. t['hehaltonearabic'] = 0x06C1;
  6810. t['heharabic'] = 0x0647;
  6811. t['hehebrew'] = 0x05D4;
  6812. t['hehfinalaltonearabic'] = 0xFBA7;
  6813. t['hehfinalalttwoarabic'] = 0xFEEA;
  6814. t['hehfinalarabic'] = 0xFEEA;
  6815. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  6816. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  6817. t['hehinitialaltonearabic'] = 0xFBA8;
  6818. t['hehinitialarabic'] = 0xFEEB;
  6819. t['hehiragana'] = 0x3078;
  6820. t['hehmedialaltonearabic'] = 0xFBA9;
  6821. t['hehmedialarabic'] = 0xFEEC;
  6822. t['heiseierasquare'] = 0x337B;
  6823. t['hekatakana'] = 0x30D8;
  6824. t['hekatakanahalfwidth'] = 0xFF8D;
  6825. t['hekutaarusquare'] = 0x3336;
  6826. t['henghook'] = 0x0267;
  6827. t['herutusquare'] = 0x3339;
  6828. t['het'] = 0x05D7;
  6829. t['hethebrew'] = 0x05D7;
  6830. t['hhook'] = 0x0266;
  6831. t['hhooksuperior'] = 0x02B1;
  6832. t['hieuhacirclekorean'] = 0x327B;
  6833. t['hieuhaparenkorean'] = 0x321B;
  6834. t['hieuhcirclekorean'] = 0x326D;
  6835. t['hieuhkorean'] = 0x314E;
  6836. t['hieuhparenkorean'] = 0x320D;
  6837. t['hihiragana'] = 0x3072;
  6838. t['hikatakana'] = 0x30D2;
  6839. t['hikatakanahalfwidth'] = 0xFF8B;
  6840. t['hiriq'] = 0x05B4;
  6841. t['hiriq14'] = 0x05B4;
  6842. t['hiriq21'] = 0x05B4;
  6843. t['hiriq2d'] = 0x05B4;
  6844. t['hiriqhebrew'] = 0x05B4;
  6845. t['hiriqnarrowhebrew'] = 0x05B4;
  6846. t['hiriqquarterhebrew'] = 0x05B4;
  6847. t['hiriqwidehebrew'] = 0x05B4;
  6848. t['hlinebelow'] = 0x1E96;
  6849. t['hmonospace'] = 0xFF48;
  6850. t['hoarmenian'] = 0x0570;
  6851. t['hohipthai'] = 0x0E2B;
  6852. t['hohiragana'] = 0x307B;
  6853. t['hokatakana'] = 0x30DB;
  6854. t['hokatakanahalfwidth'] = 0xFF8E;
  6855. t['holam'] = 0x05B9;
  6856. t['holam19'] = 0x05B9;
  6857. t['holam26'] = 0x05B9;
  6858. t['holam32'] = 0x05B9;
  6859. t['holamhebrew'] = 0x05B9;
  6860. t['holamnarrowhebrew'] = 0x05B9;
  6861. t['holamquarterhebrew'] = 0x05B9;
  6862. t['holamwidehebrew'] = 0x05B9;
  6863. t['honokhukthai'] = 0x0E2E;
  6864. t['hookabovecomb'] = 0x0309;
  6865. t['hookcmb'] = 0x0309;
  6866. t['hookpalatalizedbelowcmb'] = 0x0321;
  6867. t['hookretroflexbelowcmb'] = 0x0322;
  6868. t['hoonsquare'] = 0x3342;
  6869. t['horicoptic'] = 0x03E9;
  6870. t['horizontalbar'] = 0x2015;
  6871. t['horncmb'] = 0x031B;
  6872. t['hotsprings'] = 0x2668;
  6873. t['house'] = 0x2302;
  6874. t['hparen'] = 0x24A3;
  6875. t['hsuperior'] = 0x02B0;
  6876. t['hturned'] = 0x0265;
  6877. t['huhiragana'] = 0x3075;
  6878. t['huiitosquare'] = 0x3333;
  6879. t['hukatakana'] = 0x30D5;
  6880. t['hukatakanahalfwidth'] = 0xFF8C;
  6881. t['hungarumlaut'] = 0x02DD;
  6882. t['hungarumlautcmb'] = 0x030B;
  6883. t['hv'] = 0x0195;
  6884. t['hyphen'] = 0x002D;
  6885. t['hypheninferior'] = 0xF6E5;
  6886. t['hyphenmonospace'] = 0xFF0D;
  6887. t['hyphensmall'] = 0xFE63;
  6888. t['hyphensuperior'] = 0xF6E6;
  6889. t['hyphentwo'] = 0x2010;
  6890. t['i'] = 0x0069;
  6891. t['iacute'] = 0x00ED;
  6892. t['iacyrillic'] = 0x044F;
  6893. t['ibengali'] = 0x0987;
  6894. t['ibopomofo'] = 0x3127;
  6895. t['ibreve'] = 0x012D;
  6896. t['icaron'] = 0x01D0;
  6897. t['icircle'] = 0x24D8;
  6898. t['icircumflex'] = 0x00EE;
  6899. t['icyrillic'] = 0x0456;
  6900. t['idblgrave'] = 0x0209;
  6901. t['ideographearthcircle'] = 0x328F;
  6902. t['ideographfirecircle'] = 0x328B;
  6903. t['ideographicallianceparen'] = 0x323F;
  6904. t['ideographiccallparen'] = 0x323A;
  6905. t['ideographiccentrecircle'] = 0x32A5;
  6906. t['ideographicclose'] = 0x3006;
  6907. t['ideographiccomma'] = 0x3001;
  6908. t['ideographiccommaleft'] = 0xFF64;
  6909. t['ideographiccongratulationparen'] = 0x3237;
  6910. t['ideographiccorrectcircle'] = 0x32A3;
  6911. t['ideographicearthparen'] = 0x322F;
  6912. t['ideographicenterpriseparen'] = 0x323D;
  6913. t['ideographicexcellentcircle'] = 0x329D;
  6914. t['ideographicfestivalparen'] = 0x3240;
  6915. t['ideographicfinancialcircle'] = 0x3296;
  6916. t['ideographicfinancialparen'] = 0x3236;
  6917. t['ideographicfireparen'] = 0x322B;
  6918. t['ideographichaveparen'] = 0x3232;
  6919. t['ideographichighcircle'] = 0x32A4;
  6920. t['ideographiciterationmark'] = 0x3005;
  6921. t['ideographiclaborcircle'] = 0x3298;
  6922. t['ideographiclaborparen'] = 0x3238;
  6923. t['ideographicleftcircle'] = 0x32A7;
  6924. t['ideographiclowcircle'] = 0x32A6;
  6925. t['ideographicmedicinecircle'] = 0x32A9;
  6926. t['ideographicmetalparen'] = 0x322E;
  6927. t['ideographicmoonparen'] = 0x322A;
  6928. t['ideographicnameparen'] = 0x3234;
  6929. t['ideographicperiod'] = 0x3002;
  6930. t['ideographicprintcircle'] = 0x329E;
  6931. t['ideographicreachparen'] = 0x3243;
  6932. t['ideographicrepresentparen'] = 0x3239;
  6933. t['ideographicresourceparen'] = 0x323E;
  6934. t['ideographicrightcircle'] = 0x32A8;
  6935. t['ideographicsecretcircle'] = 0x3299;
  6936. t['ideographicselfparen'] = 0x3242;
  6937. t['ideographicsocietyparen'] = 0x3233;
  6938. t['ideographicspace'] = 0x3000;
  6939. t['ideographicspecialparen'] = 0x3235;
  6940. t['ideographicstockparen'] = 0x3231;
  6941. t['ideographicstudyparen'] = 0x323B;
  6942. t['ideographicsunparen'] = 0x3230;
  6943. t['ideographicsuperviseparen'] = 0x323C;
  6944. t['ideographicwaterparen'] = 0x322C;
  6945. t['ideographicwoodparen'] = 0x322D;
  6946. t['ideographiczero'] = 0x3007;
  6947. t['ideographmetalcircle'] = 0x328E;
  6948. t['ideographmooncircle'] = 0x328A;
  6949. t['ideographnamecircle'] = 0x3294;
  6950. t['ideographsuncircle'] = 0x3290;
  6951. t['ideographwatercircle'] = 0x328C;
  6952. t['ideographwoodcircle'] = 0x328D;
  6953. t['ideva'] = 0x0907;
  6954. t['idieresis'] = 0x00EF;
  6955. t['idieresisacute'] = 0x1E2F;
  6956. t['idieresiscyrillic'] = 0x04E5;
  6957. t['idotbelow'] = 0x1ECB;
  6958. t['iebrevecyrillic'] = 0x04D7;
  6959. t['iecyrillic'] = 0x0435;
  6960. t['ieungacirclekorean'] = 0x3275;
  6961. t['ieungaparenkorean'] = 0x3215;
  6962. t['ieungcirclekorean'] = 0x3267;
  6963. t['ieungkorean'] = 0x3147;
  6964. t['ieungparenkorean'] = 0x3207;
  6965. t['igrave'] = 0x00EC;
  6966. t['igujarati'] = 0x0A87;
  6967. t['igurmukhi'] = 0x0A07;
  6968. t['ihiragana'] = 0x3044;
  6969. t['ihookabove'] = 0x1EC9;
  6970. t['iibengali'] = 0x0988;
  6971. t['iicyrillic'] = 0x0438;
  6972. t['iideva'] = 0x0908;
  6973. t['iigujarati'] = 0x0A88;
  6974. t['iigurmukhi'] = 0x0A08;
  6975. t['iimatragurmukhi'] = 0x0A40;
  6976. t['iinvertedbreve'] = 0x020B;
  6977. t['iishortcyrillic'] = 0x0439;
  6978. t['iivowelsignbengali'] = 0x09C0;
  6979. t['iivowelsigndeva'] = 0x0940;
  6980. t['iivowelsigngujarati'] = 0x0AC0;
  6981. t['ij'] = 0x0133;
  6982. t['ikatakana'] = 0x30A4;
  6983. t['ikatakanahalfwidth'] = 0xFF72;
  6984. t['ikorean'] = 0x3163;
  6985. t['ilde'] = 0x02DC;
  6986. t['iluyhebrew'] = 0x05AC;
  6987. t['imacron'] = 0x012B;
  6988. t['imacroncyrillic'] = 0x04E3;
  6989. t['imageorapproximatelyequal'] = 0x2253;
  6990. t['imatragurmukhi'] = 0x0A3F;
  6991. t['imonospace'] = 0xFF49;
  6992. t['increment'] = 0x2206;
  6993. t['infinity'] = 0x221E;
  6994. t['iniarmenian'] = 0x056B;
  6995. t['integral'] = 0x222B;
  6996. t['integralbottom'] = 0x2321;
  6997. t['integralbt'] = 0x2321;
  6998. t['integralex'] = 0xF8F5;
  6999. t['integraltop'] = 0x2320;
  7000. t['integraltp'] = 0x2320;
  7001. t['intersection'] = 0x2229;
  7002. t['intisquare'] = 0x3305;
  7003. t['invbullet'] = 0x25D8;
  7004. t['invcircle'] = 0x25D9;
  7005. t['invsmileface'] = 0x263B;
  7006. t['iocyrillic'] = 0x0451;
  7007. t['iogonek'] = 0x012F;
  7008. t['iota'] = 0x03B9;
  7009. t['iotadieresis'] = 0x03CA;
  7010. t['iotadieresistonos'] = 0x0390;
  7011. t['iotalatin'] = 0x0269;
  7012. t['iotatonos'] = 0x03AF;
  7013. t['iparen'] = 0x24A4;
  7014. t['irigurmukhi'] = 0x0A72;
  7015. t['ismallhiragana'] = 0x3043;
  7016. t['ismallkatakana'] = 0x30A3;
  7017. t['ismallkatakanahalfwidth'] = 0xFF68;
  7018. t['issharbengali'] = 0x09FA;
  7019. t['istroke'] = 0x0268;
  7020. t['isuperior'] = 0xF6ED;
  7021. t['iterationhiragana'] = 0x309D;
  7022. t['iterationkatakana'] = 0x30FD;
  7023. t['itilde'] = 0x0129;
  7024. t['itildebelow'] = 0x1E2D;
  7025. t['iubopomofo'] = 0x3129;
  7026. t['iucyrillic'] = 0x044E;
  7027. t['ivowelsignbengali'] = 0x09BF;
  7028. t['ivowelsigndeva'] = 0x093F;
  7029. t['ivowelsigngujarati'] = 0x0ABF;
  7030. t['izhitsacyrillic'] = 0x0475;
  7031. t['izhitsadblgravecyrillic'] = 0x0477;
  7032. t['j'] = 0x006A;
  7033. t['jaarmenian'] = 0x0571;
  7034. t['jabengali'] = 0x099C;
  7035. t['jadeva'] = 0x091C;
  7036. t['jagujarati'] = 0x0A9C;
  7037. t['jagurmukhi'] = 0x0A1C;
  7038. t['jbopomofo'] = 0x3110;
  7039. t['jcaron'] = 0x01F0;
  7040. t['jcircle'] = 0x24D9;
  7041. t['jcircumflex'] = 0x0135;
  7042. t['jcrossedtail'] = 0x029D;
  7043. t['jdotlessstroke'] = 0x025F;
  7044. t['jecyrillic'] = 0x0458;
  7045. t['jeemarabic'] = 0x062C;
  7046. t['jeemfinalarabic'] = 0xFE9E;
  7047. t['jeeminitialarabic'] = 0xFE9F;
  7048. t['jeemmedialarabic'] = 0xFEA0;
  7049. t['jeharabic'] = 0x0698;
  7050. t['jehfinalarabic'] = 0xFB8B;
  7051. t['jhabengali'] = 0x099D;
  7052. t['jhadeva'] = 0x091D;
  7053. t['jhagujarati'] = 0x0A9D;
  7054. t['jhagurmukhi'] = 0x0A1D;
  7055. t['jheharmenian'] = 0x057B;
  7056. t['jis'] = 0x3004;
  7057. t['jmonospace'] = 0xFF4A;
  7058. t['jparen'] = 0x24A5;
  7059. t['jsuperior'] = 0x02B2;
  7060. t['k'] = 0x006B;
  7061. t['kabashkircyrillic'] = 0x04A1;
  7062. t['kabengali'] = 0x0995;
  7063. t['kacute'] = 0x1E31;
  7064. t['kacyrillic'] = 0x043A;
  7065. t['kadescendercyrillic'] = 0x049B;
  7066. t['kadeva'] = 0x0915;
  7067. t['kaf'] = 0x05DB;
  7068. t['kafarabic'] = 0x0643;
  7069. t['kafdagesh'] = 0xFB3B;
  7070. t['kafdageshhebrew'] = 0xFB3B;
  7071. t['kaffinalarabic'] = 0xFEDA;
  7072. t['kafhebrew'] = 0x05DB;
  7073. t['kafinitialarabic'] = 0xFEDB;
  7074. t['kafmedialarabic'] = 0xFEDC;
  7075. t['kafrafehebrew'] = 0xFB4D;
  7076. t['kagujarati'] = 0x0A95;
  7077. t['kagurmukhi'] = 0x0A15;
  7078. t['kahiragana'] = 0x304B;
  7079. t['kahookcyrillic'] = 0x04C4;
  7080. t['kakatakana'] = 0x30AB;
  7081. t['kakatakanahalfwidth'] = 0xFF76;
  7082. t['kappa'] = 0x03BA;
  7083. t['kappasymbolgreek'] = 0x03F0;
  7084. t['kapyeounmieumkorean'] = 0x3171;
  7085. t['kapyeounphieuphkorean'] = 0x3184;
  7086. t['kapyeounpieupkorean'] = 0x3178;
  7087. t['kapyeounssangpieupkorean'] = 0x3179;
  7088. t['karoriisquare'] = 0x330D;
  7089. t['kashidaautoarabic'] = 0x0640;
  7090. t['kashidaautonosidebearingarabic'] = 0x0640;
  7091. t['kasmallkatakana'] = 0x30F5;
  7092. t['kasquare'] = 0x3384;
  7093. t['kasraarabic'] = 0x0650;
  7094. t['kasratanarabic'] = 0x064D;
  7095. t['kastrokecyrillic'] = 0x049F;
  7096. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7097. t['kaverticalstrokecyrillic'] = 0x049D;
  7098. t['kbopomofo'] = 0x310E;
  7099. t['kcalsquare'] = 0x3389;
  7100. t['kcaron'] = 0x01E9;
  7101. t['kcedilla'] = 0x0137;
  7102. t['kcircle'] = 0x24DA;
  7103. t['kcommaaccent'] = 0x0137;
  7104. t['kdotbelow'] = 0x1E33;
  7105. t['keharmenian'] = 0x0584;
  7106. t['kehiragana'] = 0x3051;
  7107. t['kekatakana'] = 0x30B1;
  7108. t['kekatakanahalfwidth'] = 0xFF79;
  7109. t['kenarmenian'] = 0x056F;
  7110. t['kesmallkatakana'] = 0x30F6;
  7111. t['kgreenlandic'] = 0x0138;
  7112. t['khabengali'] = 0x0996;
  7113. t['khacyrillic'] = 0x0445;
  7114. t['khadeva'] = 0x0916;
  7115. t['khagujarati'] = 0x0A96;
  7116. t['khagurmukhi'] = 0x0A16;
  7117. t['khaharabic'] = 0x062E;
  7118. t['khahfinalarabic'] = 0xFEA6;
  7119. t['khahinitialarabic'] = 0xFEA7;
  7120. t['khahmedialarabic'] = 0xFEA8;
  7121. t['kheicoptic'] = 0x03E7;
  7122. t['khhadeva'] = 0x0959;
  7123. t['khhagurmukhi'] = 0x0A59;
  7124. t['khieukhacirclekorean'] = 0x3278;
  7125. t['khieukhaparenkorean'] = 0x3218;
  7126. t['khieukhcirclekorean'] = 0x326A;
  7127. t['khieukhkorean'] = 0x314B;
  7128. t['khieukhparenkorean'] = 0x320A;
  7129. t['khokhaithai'] = 0x0E02;
  7130. t['khokhonthai'] = 0x0E05;
  7131. t['khokhuatthai'] = 0x0E03;
  7132. t['khokhwaithai'] = 0x0E04;
  7133. t['khomutthai'] = 0x0E5B;
  7134. t['khook'] = 0x0199;
  7135. t['khorakhangthai'] = 0x0E06;
  7136. t['khzsquare'] = 0x3391;
  7137. t['kihiragana'] = 0x304D;
  7138. t['kikatakana'] = 0x30AD;
  7139. t['kikatakanahalfwidth'] = 0xFF77;
  7140. t['kiroguramusquare'] = 0x3315;
  7141. t['kiromeetorusquare'] = 0x3316;
  7142. t['kirosquare'] = 0x3314;
  7143. t['kiyeokacirclekorean'] = 0x326E;
  7144. t['kiyeokaparenkorean'] = 0x320E;
  7145. t['kiyeokcirclekorean'] = 0x3260;
  7146. t['kiyeokkorean'] = 0x3131;
  7147. t['kiyeokparenkorean'] = 0x3200;
  7148. t['kiyeoksioskorean'] = 0x3133;
  7149. t['kjecyrillic'] = 0x045C;
  7150. t['klinebelow'] = 0x1E35;
  7151. t['klsquare'] = 0x3398;
  7152. t['kmcubedsquare'] = 0x33A6;
  7153. t['kmonospace'] = 0xFF4B;
  7154. t['kmsquaredsquare'] = 0x33A2;
  7155. t['kohiragana'] = 0x3053;
  7156. t['kohmsquare'] = 0x33C0;
  7157. t['kokaithai'] = 0x0E01;
  7158. t['kokatakana'] = 0x30B3;
  7159. t['kokatakanahalfwidth'] = 0xFF7A;
  7160. t['kooposquare'] = 0x331E;
  7161. t['koppacyrillic'] = 0x0481;
  7162. t['koreanstandardsymbol'] = 0x327F;
  7163. t['koroniscmb'] = 0x0343;
  7164. t['kparen'] = 0x24A6;
  7165. t['kpasquare'] = 0x33AA;
  7166. t['ksicyrillic'] = 0x046F;
  7167. t['ktsquare'] = 0x33CF;
  7168. t['kturned'] = 0x029E;
  7169. t['kuhiragana'] = 0x304F;
  7170. t['kukatakana'] = 0x30AF;
  7171. t['kukatakanahalfwidth'] = 0xFF78;
  7172. t['kvsquare'] = 0x33B8;
  7173. t['kwsquare'] = 0x33BE;
  7174. t['l'] = 0x006C;
  7175. t['labengali'] = 0x09B2;
  7176. t['lacute'] = 0x013A;
  7177. t['ladeva'] = 0x0932;
  7178. t['lagujarati'] = 0x0AB2;
  7179. t['lagurmukhi'] = 0x0A32;
  7180. t['lakkhangyaothai'] = 0x0E45;
  7181. t['lamaleffinalarabic'] = 0xFEFC;
  7182. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7183. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7184. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7185. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7186. t['lamalefisolatedarabic'] = 0xFEFB;
  7187. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7188. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7189. t['lamarabic'] = 0x0644;
  7190. t['lambda'] = 0x03BB;
  7191. t['lambdastroke'] = 0x019B;
  7192. t['lamed'] = 0x05DC;
  7193. t['lameddagesh'] = 0xFB3C;
  7194. t['lameddageshhebrew'] = 0xFB3C;
  7195. t['lamedhebrew'] = 0x05DC;
  7196. t['lamfinalarabic'] = 0xFEDE;
  7197. t['lamhahinitialarabic'] = 0xFCCA;
  7198. t['laminitialarabic'] = 0xFEDF;
  7199. t['lamjeeminitialarabic'] = 0xFCC9;
  7200. t['lamkhahinitialarabic'] = 0xFCCB;
  7201. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7202. t['lammedialarabic'] = 0xFEE0;
  7203. t['lammeemhahinitialarabic'] = 0xFD88;
  7204. t['lammeeminitialarabic'] = 0xFCCC;
  7205. t['largecircle'] = 0x25EF;
  7206. t['lbar'] = 0x019A;
  7207. t['lbelt'] = 0x026C;
  7208. t['lbopomofo'] = 0x310C;
  7209. t['lcaron'] = 0x013E;
  7210. t['lcedilla'] = 0x013C;
  7211. t['lcircle'] = 0x24DB;
  7212. t['lcircumflexbelow'] = 0x1E3D;
  7213. t['lcommaaccent'] = 0x013C;
  7214. t['ldot'] = 0x0140;
  7215. t['ldotaccent'] = 0x0140;
  7216. t['ldotbelow'] = 0x1E37;
  7217. t['ldotbelowmacron'] = 0x1E39;
  7218. t['leftangleabovecmb'] = 0x031A;
  7219. t['lefttackbelowcmb'] = 0x0318;
  7220. t['less'] = 0x003C;
  7221. t['lessequal'] = 0x2264;
  7222. t['lessequalorgreater'] = 0x22DA;
  7223. t['lessmonospace'] = 0xFF1C;
  7224. t['lessorequivalent'] = 0x2272;
  7225. t['lessorgreater'] = 0x2276;
  7226. t['lessoverequal'] = 0x2266;
  7227. t['lesssmall'] = 0xFE64;
  7228. t['lezh'] = 0x026E;
  7229. t['lfblock'] = 0x258C;
  7230. t['lhookretroflex'] = 0x026D;
  7231. t['lira'] = 0x20A4;
  7232. t['liwnarmenian'] = 0x056C;
  7233. t['lj'] = 0x01C9;
  7234. t['ljecyrillic'] = 0x0459;
  7235. t['ll'] = 0xF6C0;
  7236. t['lladeva'] = 0x0933;
  7237. t['llagujarati'] = 0x0AB3;
  7238. t['llinebelow'] = 0x1E3B;
  7239. t['llladeva'] = 0x0934;
  7240. t['llvocalicbengali'] = 0x09E1;
  7241. t['llvocalicdeva'] = 0x0961;
  7242. t['llvocalicvowelsignbengali'] = 0x09E3;
  7243. t['llvocalicvowelsigndeva'] = 0x0963;
  7244. t['lmiddletilde'] = 0x026B;
  7245. t['lmonospace'] = 0xFF4C;
  7246. t['lmsquare'] = 0x33D0;
  7247. t['lochulathai'] = 0x0E2C;
  7248. t['logicaland'] = 0x2227;
  7249. t['logicalnot'] = 0x00AC;
  7250. t['logicalnotreversed'] = 0x2310;
  7251. t['logicalor'] = 0x2228;
  7252. t['lolingthai'] = 0x0E25;
  7253. t['longs'] = 0x017F;
  7254. t['lowlinecenterline'] = 0xFE4E;
  7255. t['lowlinecmb'] = 0x0332;
  7256. t['lowlinedashed'] = 0xFE4D;
  7257. t['lozenge'] = 0x25CA;
  7258. t['lparen'] = 0x24A7;
  7259. t['lslash'] = 0x0142;
  7260. t['lsquare'] = 0x2113;
  7261. t['lsuperior'] = 0xF6EE;
  7262. t['ltshade'] = 0x2591;
  7263. t['luthai'] = 0x0E26;
  7264. t['lvocalicbengali'] = 0x098C;
  7265. t['lvocalicdeva'] = 0x090C;
  7266. t['lvocalicvowelsignbengali'] = 0x09E2;
  7267. t['lvocalicvowelsigndeva'] = 0x0962;
  7268. t['lxsquare'] = 0x33D3;
  7269. t['m'] = 0x006D;
  7270. t['mabengali'] = 0x09AE;
  7271. t['macron'] = 0x00AF;
  7272. t['macronbelowcmb'] = 0x0331;
  7273. t['macroncmb'] = 0x0304;
  7274. t['macronlowmod'] = 0x02CD;
  7275. t['macronmonospace'] = 0xFFE3;
  7276. t['macute'] = 0x1E3F;
  7277. t['madeva'] = 0x092E;
  7278. t['magujarati'] = 0x0AAE;
  7279. t['magurmukhi'] = 0x0A2E;
  7280. t['mahapakhhebrew'] = 0x05A4;
  7281. t['mahapakhlefthebrew'] = 0x05A4;
  7282. t['mahiragana'] = 0x307E;
  7283. t['maichattawalowleftthai'] = 0xF895;
  7284. t['maichattawalowrightthai'] = 0xF894;
  7285. t['maichattawathai'] = 0x0E4B;
  7286. t['maichattawaupperleftthai'] = 0xF893;
  7287. t['maieklowleftthai'] = 0xF88C;
  7288. t['maieklowrightthai'] = 0xF88B;
  7289. t['maiekthai'] = 0x0E48;
  7290. t['maiekupperleftthai'] = 0xF88A;
  7291. t['maihanakatleftthai'] = 0xF884;
  7292. t['maihanakatthai'] = 0x0E31;
  7293. t['maitaikhuleftthai'] = 0xF889;
  7294. t['maitaikhuthai'] = 0x0E47;
  7295. t['maitholowleftthai'] = 0xF88F;
  7296. t['maitholowrightthai'] = 0xF88E;
  7297. t['maithothai'] = 0x0E49;
  7298. t['maithoupperleftthai'] = 0xF88D;
  7299. t['maitrilowleftthai'] = 0xF892;
  7300. t['maitrilowrightthai'] = 0xF891;
  7301. t['maitrithai'] = 0x0E4A;
  7302. t['maitriupperleftthai'] = 0xF890;
  7303. t['maiyamokthai'] = 0x0E46;
  7304. t['makatakana'] = 0x30DE;
  7305. t['makatakanahalfwidth'] = 0xFF8F;
  7306. t['male'] = 0x2642;
  7307. t['mansyonsquare'] = 0x3347;
  7308. t['maqafhebrew'] = 0x05BE;
  7309. t['mars'] = 0x2642;
  7310. t['masoracirclehebrew'] = 0x05AF;
  7311. t['masquare'] = 0x3383;
  7312. t['mbopomofo'] = 0x3107;
  7313. t['mbsquare'] = 0x33D4;
  7314. t['mcircle'] = 0x24DC;
  7315. t['mcubedsquare'] = 0x33A5;
  7316. t['mdotaccent'] = 0x1E41;
  7317. t['mdotbelow'] = 0x1E43;
  7318. t['meemarabic'] = 0x0645;
  7319. t['meemfinalarabic'] = 0xFEE2;
  7320. t['meeminitialarabic'] = 0xFEE3;
  7321. t['meemmedialarabic'] = 0xFEE4;
  7322. t['meemmeeminitialarabic'] = 0xFCD1;
  7323. t['meemmeemisolatedarabic'] = 0xFC48;
  7324. t['meetorusquare'] = 0x334D;
  7325. t['mehiragana'] = 0x3081;
  7326. t['meizierasquare'] = 0x337E;
  7327. t['mekatakana'] = 0x30E1;
  7328. t['mekatakanahalfwidth'] = 0xFF92;
  7329. t['mem'] = 0x05DE;
  7330. t['memdagesh'] = 0xFB3E;
  7331. t['memdageshhebrew'] = 0xFB3E;
  7332. t['memhebrew'] = 0x05DE;
  7333. t['menarmenian'] = 0x0574;
  7334. t['merkhahebrew'] = 0x05A5;
  7335. t['merkhakefulahebrew'] = 0x05A6;
  7336. t['merkhakefulalefthebrew'] = 0x05A6;
  7337. t['merkhalefthebrew'] = 0x05A5;
  7338. t['mhook'] = 0x0271;
  7339. t['mhzsquare'] = 0x3392;
  7340. t['middledotkatakanahalfwidth'] = 0xFF65;
  7341. t['middot'] = 0x00B7;
  7342. t['mieumacirclekorean'] = 0x3272;
  7343. t['mieumaparenkorean'] = 0x3212;
  7344. t['mieumcirclekorean'] = 0x3264;
  7345. t['mieumkorean'] = 0x3141;
  7346. t['mieumpansioskorean'] = 0x3170;
  7347. t['mieumparenkorean'] = 0x3204;
  7348. t['mieumpieupkorean'] = 0x316E;
  7349. t['mieumsioskorean'] = 0x316F;
  7350. t['mihiragana'] = 0x307F;
  7351. t['mikatakana'] = 0x30DF;
  7352. t['mikatakanahalfwidth'] = 0xFF90;
  7353. t['minus'] = 0x2212;
  7354. t['minusbelowcmb'] = 0x0320;
  7355. t['minuscircle'] = 0x2296;
  7356. t['minusmod'] = 0x02D7;
  7357. t['minusplus'] = 0x2213;
  7358. t['minute'] = 0x2032;
  7359. t['miribaarusquare'] = 0x334A;
  7360. t['mirisquare'] = 0x3349;
  7361. t['mlonglegturned'] = 0x0270;
  7362. t['mlsquare'] = 0x3396;
  7363. t['mmcubedsquare'] = 0x33A3;
  7364. t['mmonospace'] = 0xFF4D;
  7365. t['mmsquaredsquare'] = 0x339F;
  7366. t['mohiragana'] = 0x3082;
  7367. t['mohmsquare'] = 0x33C1;
  7368. t['mokatakana'] = 0x30E2;
  7369. t['mokatakanahalfwidth'] = 0xFF93;
  7370. t['molsquare'] = 0x33D6;
  7371. t['momathai'] = 0x0E21;
  7372. t['moverssquare'] = 0x33A7;
  7373. t['moverssquaredsquare'] = 0x33A8;
  7374. t['mparen'] = 0x24A8;
  7375. t['mpasquare'] = 0x33AB;
  7376. t['mssquare'] = 0x33B3;
  7377. t['msuperior'] = 0xF6EF;
  7378. t['mturned'] = 0x026F;
  7379. t['mu'] = 0x00B5;
  7380. t['mu1'] = 0x00B5;
  7381. t['muasquare'] = 0x3382;
  7382. t['muchgreater'] = 0x226B;
  7383. t['muchless'] = 0x226A;
  7384. t['mufsquare'] = 0x338C;
  7385. t['mugreek'] = 0x03BC;
  7386. t['mugsquare'] = 0x338D;
  7387. t['muhiragana'] = 0x3080;
  7388. t['mukatakana'] = 0x30E0;
  7389. t['mukatakanahalfwidth'] = 0xFF91;
  7390. t['mulsquare'] = 0x3395;
  7391. t['multiply'] = 0x00D7;
  7392. t['mumsquare'] = 0x339B;
  7393. t['munahhebrew'] = 0x05A3;
  7394. t['munahlefthebrew'] = 0x05A3;
  7395. t['musicalnote'] = 0x266A;
  7396. t['musicalnotedbl'] = 0x266B;
  7397. t['musicflatsign'] = 0x266D;
  7398. t['musicsharpsign'] = 0x266F;
  7399. t['mussquare'] = 0x33B2;
  7400. t['muvsquare'] = 0x33B6;
  7401. t['muwsquare'] = 0x33BC;
  7402. t['mvmegasquare'] = 0x33B9;
  7403. t['mvsquare'] = 0x33B7;
  7404. t['mwmegasquare'] = 0x33BF;
  7405. t['mwsquare'] = 0x33BD;
  7406. t['n'] = 0x006E;
  7407. t['nabengali'] = 0x09A8;
  7408. t['nabla'] = 0x2207;
  7409. t['nacute'] = 0x0144;
  7410. t['nadeva'] = 0x0928;
  7411. t['nagujarati'] = 0x0AA8;
  7412. t['nagurmukhi'] = 0x0A28;
  7413. t['nahiragana'] = 0x306A;
  7414. t['nakatakana'] = 0x30CA;
  7415. t['nakatakanahalfwidth'] = 0xFF85;
  7416. t['napostrophe'] = 0x0149;
  7417. t['nasquare'] = 0x3381;
  7418. t['nbopomofo'] = 0x310B;
  7419. t['nbspace'] = 0x00A0;
  7420. t['ncaron'] = 0x0148;
  7421. t['ncedilla'] = 0x0146;
  7422. t['ncircle'] = 0x24DD;
  7423. t['ncircumflexbelow'] = 0x1E4B;
  7424. t['ncommaaccent'] = 0x0146;
  7425. t['ndotaccent'] = 0x1E45;
  7426. t['ndotbelow'] = 0x1E47;
  7427. t['nehiragana'] = 0x306D;
  7428. t['nekatakana'] = 0x30CD;
  7429. t['nekatakanahalfwidth'] = 0xFF88;
  7430. t['newsheqelsign'] = 0x20AA;
  7431. t['nfsquare'] = 0x338B;
  7432. t['ngabengali'] = 0x0999;
  7433. t['ngadeva'] = 0x0919;
  7434. t['ngagujarati'] = 0x0A99;
  7435. t['ngagurmukhi'] = 0x0A19;
  7436. t['ngonguthai'] = 0x0E07;
  7437. t['nhiragana'] = 0x3093;
  7438. t['nhookleft'] = 0x0272;
  7439. t['nhookretroflex'] = 0x0273;
  7440. t['nieunacirclekorean'] = 0x326F;
  7441. t['nieunaparenkorean'] = 0x320F;
  7442. t['nieuncieuckorean'] = 0x3135;
  7443. t['nieuncirclekorean'] = 0x3261;
  7444. t['nieunhieuhkorean'] = 0x3136;
  7445. t['nieunkorean'] = 0x3134;
  7446. t['nieunpansioskorean'] = 0x3168;
  7447. t['nieunparenkorean'] = 0x3201;
  7448. t['nieunsioskorean'] = 0x3167;
  7449. t['nieuntikeutkorean'] = 0x3166;
  7450. t['nihiragana'] = 0x306B;
  7451. t['nikatakana'] = 0x30CB;
  7452. t['nikatakanahalfwidth'] = 0xFF86;
  7453. t['nikhahitleftthai'] = 0xF899;
  7454. t['nikhahitthai'] = 0x0E4D;
  7455. t['nine'] = 0x0039;
  7456. t['ninearabic'] = 0x0669;
  7457. t['ninebengali'] = 0x09EF;
  7458. t['ninecircle'] = 0x2468;
  7459. t['ninecircleinversesansserif'] = 0x2792;
  7460. t['ninedeva'] = 0x096F;
  7461. t['ninegujarati'] = 0x0AEF;
  7462. t['ninegurmukhi'] = 0x0A6F;
  7463. t['ninehackarabic'] = 0x0669;
  7464. t['ninehangzhou'] = 0x3029;
  7465. t['nineideographicparen'] = 0x3228;
  7466. t['nineinferior'] = 0x2089;
  7467. t['ninemonospace'] = 0xFF19;
  7468. t['nineoldstyle'] = 0xF739;
  7469. t['nineparen'] = 0x247C;
  7470. t['nineperiod'] = 0x2490;
  7471. t['ninepersian'] = 0x06F9;
  7472. t['nineroman'] = 0x2178;
  7473. t['ninesuperior'] = 0x2079;
  7474. t['nineteencircle'] = 0x2472;
  7475. t['nineteenparen'] = 0x2486;
  7476. t['nineteenperiod'] = 0x249A;
  7477. t['ninethai'] = 0x0E59;
  7478. t['nj'] = 0x01CC;
  7479. t['njecyrillic'] = 0x045A;
  7480. t['nkatakana'] = 0x30F3;
  7481. t['nkatakanahalfwidth'] = 0xFF9D;
  7482. t['nlegrightlong'] = 0x019E;
  7483. t['nlinebelow'] = 0x1E49;
  7484. t['nmonospace'] = 0xFF4E;
  7485. t['nmsquare'] = 0x339A;
  7486. t['nnabengali'] = 0x09A3;
  7487. t['nnadeva'] = 0x0923;
  7488. t['nnagujarati'] = 0x0AA3;
  7489. t['nnagurmukhi'] = 0x0A23;
  7490. t['nnnadeva'] = 0x0929;
  7491. t['nohiragana'] = 0x306E;
  7492. t['nokatakana'] = 0x30CE;
  7493. t['nokatakanahalfwidth'] = 0xFF89;
  7494. t['nonbreakingspace'] = 0x00A0;
  7495. t['nonenthai'] = 0x0E13;
  7496. t['nonuthai'] = 0x0E19;
  7497. t['noonarabic'] = 0x0646;
  7498. t['noonfinalarabic'] = 0xFEE6;
  7499. t['noonghunnaarabic'] = 0x06BA;
  7500. t['noonghunnafinalarabic'] = 0xFB9F;
  7501. t['nooninitialarabic'] = 0xFEE7;
  7502. t['noonjeeminitialarabic'] = 0xFCD2;
  7503. t['noonjeemisolatedarabic'] = 0xFC4B;
  7504. t['noonmedialarabic'] = 0xFEE8;
  7505. t['noonmeeminitialarabic'] = 0xFCD5;
  7506. t['noonmeemisolatedarabic'] = 0xFC4E;
  7507. t['noonnoonfinalarabic'] = 0xFC8D;
  7508. t['notcontains'] = 0x220C;
  7509. t['notelement'] = 0x2209;
  7510. t['notelementof'] = 0x2209;
  7511. t['notequal'] = 0x2260;
  7512. t['notgreater'] = 0x226F;
  7513. t['notgreaternorequal'] = 0x2271;
  7514. t['notgreaternorless'] = 0x2279;
  7515. t['notidentical'] = 0x2262;
  7516. t['notless'] = 0x226E;
  7517. t['notlessnorequal'] = 0x2270;
  7518. t['notparallel'] = 0x2226;
  7519. t['notprecedes'] = 0x2280;
  7520. t['notsubset'] = 0x2284;
  7521. t['notsucceeds'] = 0x2281;
  7522. t['notsuperset'] = 0x2285;
  7523. t['nowarmenian'] = 0x0576;
  7524. t['nparen'] = 0x24A9;
  7525. t['nssquare'] = 0x33B1;
  7526. t['nsuperior'] = 0x207F;
  7527. t['ntilde'] = 0x00F1;
  7528. t['nu'] = 0x03BD;
  7529. t['nuhiragana'] = 0x306C;
  7530. t['nukatakana'] = 0x30CC;
  7531. t['nukatakanahalfwidth'] = 0xFF87;
  7532. t['nuktabengali'] = 0x09BC;
  7533. t['nuktadeva'] = 0x093C;
  7534. t['nuktagujarati'] = 0x0ABC;
  7535. t['nuktagurmukhi'] = 0x0A3C;
  7536. t['numbersign'] = 0x0023;
  7537. t['numbersignmonospace'] = 0xFF03;
  7538. t['numbersignsmall'] = 0xFE5F;
  7539. t['numeralsigngreek'] = 0x0374;
  7540. t['numeralsignlowergreek'] = 0x0375;
  7541. t['numero'] = 0x2116;
  7542. t['nun'] = 0x05E0;
  7543. t['nundagesh'] = 0xFB40;
  7544. t['nundageshhebrew'] = 0xFB40;
  7545. t['nunhebrew'] = 0x05E0;
  7546. t['nvsquare'] = 0x33B5;
  7547. t['nwsquare'] = 0x33BB;
  7548. t['nyabengali'] = 0x099E;
  7549. t['nyadeva'] = 0x091E;
  7550. t['nyagujarati'] = 0x0A9E;
  7551. t['nyagurmukhi'] = 0x0A1E;
  7552. t['o'] = 0x006F;
  7553. t['oacute'] = 0x00F3;
  7554. t['oangthai'] = 0x0E2D;
  7555. t['obarred'] = 0x0275;
  7556. t['obarredcyrillic'] = 0x04E9;
  7557. t['obarreddieresiscyrillic'] = 0x04EB;
  7558. t['obengali'] = 0x0993;
  7559. t['obopomofo'] = 0x311B;
  7560. t['obreve'] = 0x014F;
  7561. t['ocandradeva'] = 0x0911;
  7562. t['ocandragujarati'] = 0x0A91;
  7563. t['ocandravowelsigndeva'] = 0x0949;
  7564. t['ocandravowelsigngujarati'] = 0x0AC9;
  7565. t['ocaron'] = 0x01D2;
  7566. t['ocircle'] = 0x24DE;
  7567. t['ocircumflex'] = 0x00F4;
  7568. t['ocircumflexacute'] = 0x1ED1;
  7569. t['ocircumflexdotbelow'] = 0x1ED9;
  7570. t['ocircumflexgrave'] = 0x1ED3;
  7571. t['ocircumflexhookabove'] = 0x1ED5;
  7572. t['ocircumflextilde'] = 0x1ED7;
  7573. t['ocyrillic'] = 0x043E;
  7574. t['odblacute'] = 0x0151;
  7575. t['odblgrave'] = 0x020D;
  7576. t['odeva'] = 0x0913;
  7577. t['odieresis'] = 0x00F6;
  7578. t['odieresiscyrillic'] = 0x04E7;
  7579. t['odotbelow'] = 0x1ECD;
  7580. t['oe'] = 0x0153;
  7581. t['oekorean'] = 0x315A;
  7582. t['ogonek'] = 0x02DB;
  7583. t['ogonekcmb'] = 0x0328;
  7584. t['ograve'] = 0x00F2;
  7585. t['ogujarati'] = 0x0A93;
  7586. t['oharmenian'] = 0x0585;
  7587. t['ohiragana'] = 0x304A;
  7588. t['ohookabove'] = 0x1ECF;
  7589. t['ohorn'] = 0x01A1;
  7590. t['ohornacute'] = 0x1EDB;
  7591. t['ohorndotbelow'] = 0x1EE3;
  7592. t['ohorngrave'] = 0x1EDD;
  7593. t['ohornhookabove'] = 0x1EDF;
  7594. t['ohorntilde'] = 0x1EE1;
  7595. t['ohungarumlaut'] = 0x0151;
  7596. t['oi'] = 0x01A3;
  7597. t['oinvertedbreve'] = 0x020F;
  7598. t['okatakana'] = 0x30AA;
  7599. t['okatakanahalfwidth'] = 0xFF75;
  7600. t['okorean'] = 0x3157;
  7601. t['olehebrew'] = 0x05AB;
  7602. t['omacron'] = 0x014D;
  7603. t['omacronacute'] = 0x1E53;
  7604. t['omacrongrave'] = 0x1E51;
  7605. t['omdeva'] = 0x0950;
  7606. t['omega'] = 0x03C9;
  7607. t['omega1'] = 0x03D6;
  7608. t['omegacyrillic'] = 0x0461;
  7609. t['omegalatinclosed'] = 0x0277;
  7610. t['omegaroundcyrillic'] = 0x047B;
  7611. t['omegatitlocyrillic'] = 0x047D;
  7612. t['omegatonos'] = 0x03CE;
  7613. t['omgujarati'] = 0x0AD0;
  7614. t['omicron'] = 0x03BF;
  7615. t['omicrontonos'] = 0x03CC;
  7616. t['omonospace'] = 0xFF4F;
  7617. t['one'] = 0x0031;
  7618. t['onearabic'] = 0x0661;
  7619. t['onebengali'] = 0x09E7;
  7620. t['onecircle'] = 0x2460;
  7621. t['onecircleinversesansserif'] = 0x278A;
  7622. t['onedeva'] = 0x0967;
  7623. t['onedotenleader'] = 0x2024;
  7624. t['oneeighth'] = 0x215B;
  7625. t['onefitted'] = 0xF6DC;
  7626. t['onegujarati'] = 0x0AE7;
  7627. t['onegurmukhi'] = 0x0A67;
  7628. t['onehackarabic'] = 0x0661;
  7629. t['onehalf'] = 0x00BD;
  7630. t['onehangzhou'] = 0x3021;
  7631. t['oneideographicparen'] = 0x3220;
  7632. t['oneinferior'] = 0x2081;
  7633. t['onemonospace'] = 0xFF11;
  7634. t['onenumeratorbengali'] = 0x09F4;
  7635. t['oneoldstyle'] = 0xF731;
  7636. t['oneparen'] = 0x2474;
  7637. t['oneperiod'] = 0x2488;
  7638. t['onepersian'] = 0x06F1;
  7639. t['onequarter'] = 0x00BC;
  7640. t['oneroman'] = 0x2170;
  7641. t['onesuperior'] = 0x00B9;
  7642. t['onethai'] = 0x0E51;
  7643. t['onethird'] = 0x2153;
  7644. t['oogonek'] = 0x01EB;
  7645. t['oogonekmacron'] = 0x01ED;
  7646. t['oogurmukhi'] = 0x0A13;
  7647. t['oomatragurmukhi'] = 0x0A4B;
  7648. t['oopen'] = 0x0254;
  7649. t['oparen'] = 0x24AA;
  7650. t['openbullet'] = 0x25E6;
  7651. t['option'] = 0x2325;
  7652. t['ordfeminine'] = 0x00AA;
  7653. t['ordmasculine'] = 0x00BA;
  7654. t['orthogonal'] = 0x221F;
  7655. t['oshortdeva'] = 0x0912;
  7656. t['oshortvowelsigndeva'] = 0x094A;
  7657. t['oslash'] = 0x00F8;
  7658. t['oslashacute'] = 0x01FF;
  7659. t['osmallhiragana'] = 0x3049;
  7660. t['osmallkatakana'] = 0x30A9;
  7661. t['osmallkatakanahalfwidth'] = 0xFF6B;
  7662. t['ostrokeacute'] = 0x01FF;
  7663. t['osuperior'] = 0xF6F0;
  7664. t['otcyrillic'] = 0x047F;
  7665. t['otilde'] = 0x00F5;
  7666. t['otildeacute'] = 0x1E4D;
  7667. t['otildedieresis'] = 0x1E4F;
  7668. t['oubopomofo'] = 0x3121;
  7669. t['overline'] = 0x203E;
  7670. t['overlinecenterline'] = 0xFE4A;
  7671. t['overlinecmb'] = 0x0305;
  7672. t['overlinedashed'] = 0xFE49;
  7673. t['overlinedblwavy'] = 0xFE4C;
  7674. t['overlinewavy'] = 0xFE4B;
  7675. t['overscore'] = 0x00AF;
  7676. t['ovowelsignbengali'] = 0x09CB;
  7677. t['ovowelsigndeva'] = 0x094B;
  7678. t['ovowelsigngujarati'] = 0x0ACB;
  7679. t['p'] = 0x0070;
  7680. t['paampssquare'] = 0x3380;
  7681. t['paasentosquare'] = 0x332B;
  7682. t['pabengali'] = 0x09AA;
  7683. t['pacute'] = 0x1E55;
  7684. t['padeva'] = 0x092A;
  7685. t['pagedown'] = 0x21DF;
  7686. t['pageup'] = 0x21DE;
  7687. t['pagujarati'] = 0x0AAA;
  7688. t['pagurmukhi'] = 0x0A2A;
  7689. t['pahiragana'] = 0x3071;
  7690. t['paiyannoithai'] = 0x0E2F;
  7691. t['pakatakana'] = 0x30D1;
  7692. t['palatalizationcyrilliccmb'] = 0x0484;
  7693. t['palochkacyrillic'] = 0x04C0;
  7694. t['pansioskorean'] = 0x317F;
  7695. t['paragraph'] = 0x00B6;
  7696. t['parallel'] = 0x2225;
  7697. t['parenleft'] = 0x0028;
  7698. t['parenleftaltonearabic'] = 0xFD3E;
  7699. t['parenleftbt'] = 0xF8ED;
  7700. t['parenleftex'] = 0xF8EC;
  7701. t['parenleftinferior'] = 0x208D;
  7702. t['parenleftmonospace'] = 0xFF08;
  7703. t['parenleftsmall'] = 0xFE59;
  7704. t['parenleftsuperior'] = 0x207D;
  7705. t['parenlefttp'] = 0xF8EB;
  7706. t['parenleftvertical'] = 0xFE35;
  7707. t['parenright'] = 0x0029;
  7708. t['parenrightaltonearabic'] = 0xFD3F;
  7709. t['parenrightbt'] = 0xF8F8;
  7710. t['parenrightex'] = 0xF8F7;
  7711. t['parenrightinferior'] = 0x208E;
  7712. t['parenrightmonospace'] = 0xFF09;
  7713. t['parenrightsmall'] = 0xFE5A;
  7714. t['parenrightsuperior'] = 0x207E;
  7715. t['parenrighttp'] = 0xF8F6;
  7716. t['parenrightvertical'] = 0xFE36;
  7717. t['partialdiff'] = 0x2202;
  7718. t['paseqhebrew'] = 0x05C0;
  7719. t['pashtahebrew'] = 0x0599;
  7720. t['pasquare'] = 0x33A9;
  7721. t['patah'] = 0x05B7;
  7722. t['patah11'] = 0x05B7;
  7723. t['patah1d'] = 0x05B7;
  7724. t['patah2a'] = 0x05B7;
  7725. t['patahhebrew'] = 0x05B7;
  7726. t['patahnarrowhebrew'] = 0x05B7;
  7727. t['patahquarterhebrew'] = 0x05B7;
  7728. t['patahwidehebrew'] = 0x05B7;
  7729. t['pazerhebrew'] = 0x05A1;
  7730. t['pbopomofo'] = 0x3106;
  7731. t['pcircle'] = 0x24DF;
  7732. t['pdotaccent'] = 0x1E57;
  7733. t['pe'] = 0x05E4;
  7734. t['pecyrillic'] = 0x043F;
  7735. t['pedagesh'] = 0xFB44;
  7736. t['pedageshhebrew'] = 0xFB44;
  7737. t['peezisquare'] = 0x333B;
  7738. t['pefinaldageshhebrew'] = 0xFB43;
  7739. t['peharabic'] = 0x067E;
  7740. t['peharmenian'] = 0x057A;
  7741. t['pehebrew'] = 0x05E4;
  7742. t['pehfinalarabic'] = 0xFB57;
  7743. t['pehinitialarabic'] = 0xFB58;
  7744. t['pehiragana'] = 0x307A;
  7745. t['pehmedialarabic'] = 0xFB59;
  7746. t['pekatakana'] = 0x30DA;
  7747. t['pemiddlehookcyrillic'] = 0x04A7;
  7748. t['perafehebrew'] = 0xFB4E;
  7749. t['percent'] = 0x0025;
  7750. t['percentarabic'] = 0x066A;
  7751. t['percentmonospace'] = 0xFF05;
  7752. t['percentsmall'] = 0xFE6A;
  7753. t['period'] = 0x002E;
  7754. t['periodarmenian'] = 0x0589;
  7755. t['periodcentered'] = 0x00B7;
  7756. t['periodhalfwidth'] = 0xFF61;
  7757. t['periodinferior'] = 0xF6E7;
  7758. t['periodmonospace'] = 0xFF0E;
  7759. t['periodsmall'] = 0xFE52;
  7760. t['periodsuperior'] = 0xF6E8;
  7761. t['perispomenigreekcmb'] = 0x0342;
  7762. t['perpendicular'] = 0x22A5;
  7763. t['perthousand'] = 0x2030;
  7764. t['peseta'] = 0x20A7;
  7765. t['pfsquare'] = 0x338A;
  7766. t['phabengali'] = 0x09AB;
  7767. t['phadeva'] = 0x092B;
  7768. t['phagujarati'] = 0x0AAB;
  7769. t['phagurmukhi'] = 0x0A2B;
  7770. t['phi'] = 0x03C6;
  7771. t['phi1'] = 0x03D5;
  7772. t['phieuphacirclekorean'] = 0x327A;
  7773. t['phieuphaparenkorean'] = 0x321A;
  7774. t['phieuphcirclekorean'] = 0x326C;
  7775. t['phieuphkorean'] = 0x314D;
  7776. t['phieuphparenkorean'] = 0x320C;
  7777. t['philatin'] = 0x0278;
  7778. t['phinthuthai'] = 0x0E3A;
  7779. t['phisymbolgreek'] = 0x03D5;
  7780. t['phook'] = 0x01A5;
  7781. t['phophanthai'] = 0x0E1E;
  7782. t['phophungthai'] = 0x0E1C;
  7783. t['phosamphaothai'] = 0x0E20;
  7784. t['pi'] = 0x03C0;
  7785. t['pieupacirclekorean'] = 0x3273;
  7786. t['pieupaparenkorean'] = 0x3213;
  7787. t['pieupcieuckorean'] = 0x3176;
  7788. t['pieupcirclekorean'] = 0x3265;
  7789. t['pieupkiyeokkorean'] = 0x3172;
  7790. t['pieupkorean'] = 0x3142;
  7791. t['pieupparenkorean'] = 0x3205;
  7792. t['pieupsioskiyeokkorean'] = 0x3174;
  7793. t['pieupsioskorean'] = 0x3144;
  7794. t['pieupsiostikeutkorean'] = 0x3175;
  7795. t['pieupthieuthkorean'] = 0x3177;
  7796. t['pieuptikeutkorean'] = 0x3173;
  7797. t['pihiragana'] = 0x3074;
  7798. t['pikatakana'] = 0x30D4;
  7799. t['pisymbolgreek'] = 0x03D6;
  7800. t['piwrarmenian'] = 0x0583;
  7801. t['plus'] = 0x002B;
  7802. t['plusbelowcmb'] = 0x031F;
  7803. t['pluscircle'] = 0x2295;
  7804. t['plusminus'] = 0x00B1;
  7805. t['plusmod'] = 0x02D6;
  7806. t['plusmonospace'] = 0xFF0B;
  7807. t['plussmall'] = 0xFE62;
  7808. t['plussuperior'] = 0x207A;
  7809. t['pmonospace'] = 0xFF50;
  7810. t['pmsquare'] = 0x33D8;
  7811. t['pohiragana'] = 0x307D;
  7812. t['pointingindexdownwhite'] = 0x261F;
  7813. t['pointingindexleftwhite'] = 0x261C;
  7814. t['pointingindexrightwhite'] = 0x261E;
  7815. t['pointingindexupwhite'] = 0x261D;
  7816. t['pokatakana'] = 0x30DD;
  7817. t['poplathai'] = 0x0E1B;
  7818. t['postalmark'] = 0x3012;
  7819. t['postalmarkface'] = 0x3020;
  7820. t['pparen'] = 0x24AB;
  7821. t['precedes'] = 0x227A;
  7822. t['prescription'] = 0x211E;
  7823. t['primemod'] = 0x02B9;
  7824. t['primereversed'] = 0x2035;
  7825. t['product'] = 0x220F;
  7826. t['projective'] = 0x2305;
  7827. t['prolongedkana'] = 0x30FC;
  7828. t['propellor'] = 0x2318;
  7829. t['propersubset'] = 0x2282;
  7830. t['propersuperset'] = 0x2283;
  7831. t['proportion'] = 0x2237;
  7832. t['proportional'] = 0x221D;
  7833. t['psi'] = 0x03C8;
  7834. t['psicyrillic'] = 0x0471;
  7835. t['psilipneumatacyrilliccmb'] = 0x0486;
  7836. t['pssquare'] = 0x33B0;
  7837. t['puhiragana'] = 0x3077;
  7838. t['pukatakana'] = 0x30D7;
  7839. t['pvsquare'] = 0x33B4;
  7840. t['pwsquare'] = 0x33BA;
  7841. t['q'] = 0x0071;
  7842. t['qadeva'] = 0x0958;
  7843. t['qadmahebrew'] = 0x05A8;
  7844. t['qafarabic'] = 0x0642;
  7845. t['qaffinalarabic'] = 0xFED6;
  7846. t['qafinitialarabic'] = 0xFED7;
  7847. t['qafmedialarabic'] = 0xFED8;
  7848. t['qamats'] = 0x05B8;
  7849. t['qamats10'] = 0x05B8;
  7850. t['qamats1a'] = 0x05B8;
  7851. t['qamats1c'] = 0x05B8;
  7852. t['qamats27'] = 0x05B8;
  7853. t['qamats29'] = 0x05B8;
  7854. t['qamats33'] = 0x05B8;
  7855. t['qamatsde'] = 0x05B8;
  7856. t['qamatshebrew'] = 0x05B8;
  7857. t['qamatsnarrowhebrew'] = 0x05B8;
  7858. t['qamatsqatanhebrew'] = 0x05B8;
  7859. t['qamatsqatannarrowhebrew'] = 0x05B8;
  7860. t['qamatsqatanquarterhebrew'] = 0x05B8;
  7861. t['qamatsqatanwidehebrew'] = 0x05B8;
  7862. t['qamatsquarterhebrew'] = 0x05B8;
  7863. t['qamatswidehebrew'] = 0x05B8;
  7864. t['qarneyparahebrew'] = 0x059F;
  7865. t['qbopomofo'] = 0x3111;
  7866. t['qcircle'] = 0x24E0;
  7867. t['qhook'] = 0x02A0;
  7868. t['qmonospace'] = 0xFF51;
  7869. t['qof'] = 0x05E7;
  7870. t['qofdagesh'] = 0xFB47;
  7871. t['qofdageshhebrew'] = 0xFB47;
  7872. t['qofhebrew'] = 0x05E7;
  7873. t['qparen'] = 0x24AC;
  7874. t['quarternote'] = 0x2669;
  7875. t['qubuts'] = 0x05BB;
  7876. t['qubuts18'] = 0x05BB;
  7877. t['qubuts25'] = 0x05BB;
  7878. t['qubuts31'] = 0x05BB;
  7879. t['qubutshebrew'] = 0x05BB;
  7880. t['qubutsnarrowhebrew'] = 0x05BB;
  7881. t['qubutsquarterhebrew'] = 0x05BB;
  7882. t['qubutswidehebrew'] = 0x05BB;
  7883. t['question'] = 0x003F;
  7884. t['questionarabic'] = 0x061F;
  7885. t['questionarmenian'] = 0x055E;
  7886. t['questiondown'] = 0x00BF;
  7887. t['questiondownsmall'] = 0xF7BF;
  7888. t['questiongreek'] = 0x037E;
  7889. t['questionmonospace'] = 0xFF1F;
  7890. t['questionsmall'] = 0xF73F;
  7891. t['quotedbl'] = 0x0022;
  7892. t['quotedblbase'] = 0x201E;
  7893. t['quotedblleft'] = 0x201C;
  7894. t['quotedblmonospace'] = 0xFF02;
  7895. t['quotedblprime'] = 0x301E;
  7896. t['quotedblprimereversed'] = 0x301D;
  7897. t['quotedblright'] = 0x201D;
  7898. t['quoteleft'] = 0x2018;
  7899. t['quoteleftreversed'] = 0x201B;
  7900. t['quotereversed'] = 0x201B;
  7901. t['quoteright'] = 0x2019;
  7902. t['quoterightn'] = 0x0149;
  7903. t['quotesinglbase'] = 0x201A;
  7904. t['quotesingle'] = 0x0027;
  7905. t['quotesinglemonospace'] = 0xFF07;
  7906. t['r'] = 0x0072;
  7907. t['raarmenian'] = 0x057C;
  7908. t['rabengali'] = 0x09B0;
  7909. t['racute'] = 0x0155;
  7910. t['radeva'] = 0x0930;
  7911. t['radical'] = 0x221A;
  7912. t['radicalex'] = 0xF8E5;
  7913. t['radoverssquare'] = 0x33AE;
  7914. t['radoverssquaredsquare'] = 0x33AF;
  7915. t['radsquare'] = 0x33AD;
  7916. t['rafe'] = 0x05BF;
  7917. t['rafehebrew'] = 0x05BF;
  7918. t['ragujarati'] = 0x0AB0;
  7919. t['ragurmukhi'] = 0x0A30;
  7920. t['rahiragana'] = 0x3089;
  7921. t['rakatakana'] = 0x30E9;
  7922. t['rakatakanahalfwidth'] = 0xFF97;
  7923. t['ralowerdiagonalbengali'] = 0x09F1;
  7924. t['ramiddlediagonalbengali'] = 0x09F0;
  7925. t['ramshorn'] = 0x0264;
  7926. t['ratio'] = 0x2236;
  7927. t['rbopomofo'] = 0x3116;
  7928. t['rcaron'] = 0x0159;
  7929. t['rcedilla'] = 0x0157;
  7930. t['rcircle'] = 0x24E1;
  7931. t['rcommaaccent'] = 0x0157;
  7932. t['rdblgrave'] = 0x0211;
  7933. t['rdotaccent'] = 0x1E59;
  7934. t['rdotbelow'] = 0x1E5B;
  7935. t['rdotbelowmacron'] = 0x1E5D;
  7936. t['referencemark'] = 0x203B;
  7937. t['reflexsubset'] = 0x2286;
  7938. t['reflexsuperset'] = 0x2287;
  7939. t['registered'] = 0x00AE;
  7940. t['registersans'] = 0xF8E8;
  7941. t['registerserif'] = 0xF6DA;
  7942. t['reharabic'] = 0x0631;
  7943. t['reharmenian'] = 0x0580;
  7944. t['rehfinalarabic'] = 0xFEAE;
  7945. t['rehiragana'] = 0x308C;
  7946. t['rekatakana'] = 0x30EC;
  7947. t['rekatakanahalfwidth'] = 0xFF9A;
  7948. t['resh'] = 0x05E8;
  7949. t['reshdageshhebrew'] = 0xFB48;
  7950. t['reshhebrew'] = 0x05E8;
  7951. t['reversedtilde'] = 0x223D;
  7952. t['reviahebrew'] = 0x0597;
  7953. t['reviamugrashhebrew'] = 0x0597;
  7954. t['revlogicalnot'] = 0x2310;
  7955. t['rfishhook'] = 0x027E;
  7956. t['rfishhookreversed'] = 0x027F;
  7957. t['rhabengali'] = 0x09DD;
  7958. t['rhadeva'] = 0x095D;
  7959. t['rho'] = 0x03C1;
  7960. t['rhook'] = 0x027D;
  7961. t['rhookturned'] = 0x027B;
  7962. t['rhookturnedsuperior'] = 0x02B5;
  7963. t['rhosymbolgreek'] = 0x03F1;
  7964. t['rhotichookmod'] = 0x02DE;
  7965. t['rieulacirclekorean'] = 0x3271;
  7966. t['rieulaparenkorean'] = 0x3211;
  7967. t['rieulcirclekorean'] = 0x3263;
  7968. t['rieulhieuhkorean'] = 0x3140;
  7969. t['rieulkiyeokkorean'] = 0x313A;
  7970. t['rieulkiyeoksioskorean'] = 0x3169;
  7971. t['rieulkorean'] = 0x3139;
  7972. t['rieulmieumkorean'] = 0x313B;
  7973. t['rieulpansioskorean'] = 0x316C;
  7974. t['rieulparenkorean'] = 0x3203;
  7975. t['rieulphieuphkorean'] = 0x313F;
  7976. t['rieulpieupkorean'] = 0x313C;
  7977. t['rieulpieupsioskorean'] = 0x316B;
  7978. t['rieulsioskorean'] = 0x313D;
  7979. t['rieulthieuthkorean'] = 0x313E;
  7980. t['rieultikeutkorean'] = 0x316A;
  7981. t['rieulyeorinhieuhkorean'] = 0x316D;
  7982. t['rightangle'] = 0x221F;
  7983. t['righttackbelowcmb'] = 0x0319;
  7984. t['righttriangle'] = 0x22BF;
  7985. t['rihiragana'] = 0x308A;
  7986. t['rikatakana'] = 0x30EA;
  7987. t['rikatakanahalfwidth'] = 0xFF98;
  7988. t['ring'] = 0x02DA;
  7989. t['ringbelowcmb'] = 0x0325;
  7990. t['ringcmb'] = 0x030A;
  7991. t['ringhalfleft'] = 0x02BF;
  7992. t['ringhalfleftarmenian'] = 0x0559;
  7993. t['ringhalfleftbelowcmb'] = 0x031C;
  7994. t['ringhalfleftcentered'] = 0x02D3;
  7995. t['ringhalfright'] = 0x02BE;
  7996. t['ringhalfrightbelowcmb'] = 0x0339;
  7997. t['ringhalfrightcentered'] = 0x02D2;
  7998. t['rinvertedbreve'] = 0x0213;
  7999. t['rittorusquare'] = 0x3351;
  8000. t['rlinebelow'] = 0x1E5F;
  8001. t['rlongleg'] = 0x027C;
  8002. t['rlonglegturned'] = 0x027A;
  8003. t['rmonospace'] = 0xFF52;
  8004. t['rohiragana'] = 0x308D;
  8005. t['rokatakana'] = 0x30ED;
  8006. t['rokatakanahalfwidth'] = 0xFF9B;
  8007. t['roruathai'] = 0x0E23;
  8008. t['rparen'] = 0x24AD;
  8009. t['rrabengali'] = 0x09DC;
  8010. t['rradeva'] = 0x0931;
  8011. t['rragurmukhi'] = 0x0A5C;
  8012. t['rreharabic'] = 0x0691;
  8013. t['rrehfinalarabic'] = 0xFB8D;
  8014. t['rrvocalicbengali'] = 0x09E0;
  8015. t['rrvocalicdeva'] = 0x0960;
  8016. t['rrvocalicgujarati'] = 0x0AE0;
  8017. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8018. t['rrvocalicvowelsigndeva'] = 0x0944;
  8019. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8020. t['rsuperior'] = 0xF6F1;
  8021. t['rtblock'] = 0x2590;
  8022. t['rturned'] = 0x0279;
  8023. t['rturnedsuperior'] = 0x02B4;
  8024. t['ruhiragana'] = 0x308B;
  8025. t['rukatakana'] = 0x30EB;
  8026. t['rukatakanahalfwidth'] = 0xFF99;
  8027. t['rupeemarkbengali'] = 0x09F2;
  8028. t['rupeesignbengali'] = 0x09F3;
  8029. t['rupiah'] = 0xF6DD;
  8030. t['ruthai'] = 0x0E24;
  8031. t['rvocalicbengali'] = 0x098B;
  8032. t['rvocalicdeva'] = 0x090B;
  8033. t['rvocalicgujarati'] = 0x0A8B;
  8034. t['rvocalicvowelsignbengali'] = 0x09C3;
  8035. t['rvocalicvowelsigndeva'] = 0x0943;
  8036. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8037. t['s'] = 0x0073;
  8038. t['sabengali'] = 0x09B8;
  8039. t['sacute'] = 0x015B;
  8040. t['sacutedotaccent'] = 0x1E65;
  8041. t['sadarabic'] = 0x0635;
  8042. t['sadeva'] = 0x0938;
  8043. t['sadfinalarabic'] = 0xFEBA;
  8044. t['sadinitialarabic'] = 0xFEBB;
  8045. t['sadmedialarabic'] = 0xFEBC;
  8046. t['sagujarati'] = 0x0AB8;
  8047. t['sagurmukhi'] = 0x0A38;
  8048. t['sahiragana'] = 0x3055;
  8049. t['sakatakana'] = 0x30B5;
  8050. t['sakatakanahalfwidth'] = 0xFF7B;
  8051. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8052. t['samekh'] = 0x05E1;
  8053. t['samekhdagesh'] = 0xFB41;
  8054. t['samekhdageshhebrew'] = 0xFB41;
  8055. t['samekhhebrew'] = 0x05E1;
  8056. t['saraaathai'] = 0x0E32;
  8057. t['saraaethai'] = 0x0E41;
  8058. t['saraaimaimalaithai'] = 0x0E44;
  8059. t['saraaimaimuanthai'] = 0x0E43;
  8060. t['saraamthai'] = 0x0E33;
  8061. t['saraathai'] = 0x0E30;
  8062. t['saraethai'] = 0x0E40;
  8063. t['saraiileftthai'] = 0xF886;
  8064. t['saraiithai'] = 0x0E35;
  8065. t['saraileftthai'] = 0xF885;
  8066. t['saraithai'] = 0x0E34;
  8067. t['saraothai'] = 0x0E42;
  8068. t['saraueeleftthai'] = 0xF888;
  8069. t['saraueethai'] = 0x0E37;
  8070. t['saraueleftthai'] = 0xF887;
  8071. t['sarauethai'] = 0x0E36;
  8072. t['sarauthai'] = 0x0E38;
  8073. t['sarauuthai'] = 0x0E39;
  8074. t['sbopomofo'] = 0x3119;
  8075. t['scaron'] = 0x0161;
  8076. t['scarondotaccent'] = 0x1E67;
  8077. t['scedilla'] = 0x015F;
  8078. t['schwa'] = 0x0259;
  8079. t['schwacyrillic'] = 0x04D9;
  8080. t['schwadieresiscyrillic'] = 0x04DB;
  8081. t['schwahook'] = 0x025A;
  8082. t['scircle'] = 0x24E2;
  8083. t['scircumflex'] = 0x015D;
  8084. t['scommaaccent'] = 0x0219;
  8085. t['sdotaccent'] = 0x1E61;
  8086. t['sdotbelow'] = 0x1E63;
  8087. t['sdotbelowdotaccent'] = 0x1E69;
  8088. t['seagullbelowcmb'] = 0x033C;
  8089. t['second'] = 0x2033;
  8090. t['secondtonechinese'] = 0x02CA;
  8091. t['section'] = 0x00A7;
  8092. t['seenarabic'] = 0x0633;
  8093. t['seenfinalarabic'] = 0xFEB2;
  8094. t['seeninitialarabic'] = 0xFEB3;
  8095. t['seenmedialarabic'] = 0xFEB4;
  8096. t['segol'] = 0x05B6;
  8097. t['segol13'] = 0x05B6;
  8098. t['segol1f'] = 0x05B6;
  8099. t['segol2c'] = 0x05B6;
  8100. t['segolhebrew'] = 0x05B6;
  8101. t['segolnarrowhebrew'] = 0x05B6;
  8102. t['segolquarterhebrew'] = 0x05B6;
  8103. t['segoltahebrew'] = 0x0592;
  8104. t['segolwidehebrew'] = 0x05B6;
  8105. t['seharmenian'] = 0x057D;
  8106. t['sehiragana'] = 0x305B;
  8107. t['sekatakana'] = 0x30BB;
  8108. t['sekatakanahalfwidth'] = 0xFF7E;
  8109. t['semicolon'] = 0x003B;
  8110. t['semicolonarabic'] = 0x061B;
  8111. t['semicolonmonospace'] = 0xFF1B;
  8112. t['semicolonsmall'] = 0xFE54;
  8113. t['semivoicedmarkkana'] = 0x309C;
  8114. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8115. t['sentisquare'] = 0x3322;
  8116. t['sentosquare'] = 0x3323;
  8117. t['seven'] = 0x0037;
  8118. t['sevenarabic'] = 0x0667;
  8119. t['sevenbengali'] = 0x09ED;
  8120. t['sevencircle'] = 0x2466;
  8121. t['sevencircleinversesansserif'] = 0x2790;
  8122. t['sevendeva'] = 0x096D;
  8123. t['seveneighths'] = 0x215E;
  8124. t['sevengujarati'] = 0x0AED;
  8125. t['sevengurmukhi'] = 0x0A6D;
  8126. t['sevenhackarabic'] = 0x0667;
  8127. t['sevenhangzhou'] = 0x3027;
  8128. t['sevenideographicparen'] = 0x3226;
  8129. t['seveninferior'] = 0x2087;
  8130. t['sevenmonospace'] = 0xFF17;
  8131. t['sevenoldstyle'] = 0xF737;
  8132. t['sevenparen'] = 0x247A;
  8133. t['sevenperiod'] = 0x248E;
  8134. t['sevenpersian'] = 0x06F7;
  8135. t['sevenroman'] = 0x2176;
  8136. t['sevensuperior'] = 0x2077;
  8137. t['seventeencircle'] = 0x2470;
  8138. t['seventeenparen'] = 0x2484;
  8139. t['seventeenperiod'] = 0x2498;
  8140. t['seventhai'] = 0x0E57;
  8141. t['sfthyphen'] = 0x00AD;
  8142. t['shaarmenian'] = 0x0577;
  8143. t['shabengali'] = 0x09B6;
  8144. t['shacyrillic'] = 0x0448;
  8145. t['shaddaarabic'] = 0x0651;
  8146. t['shaddadammaarabic'] = 0xFC61;
  8147. t['shaddadammatanarabic'] = 0xFC5E;
  8148. t['shaddafathaarabic'] = 0xFC60;
  8149. t['shaddakasraarabic'] = 0xFC62;
  8150. t['shaddakasratanarabic'] = 0xFC5F;
  8151. t['shade'] = 0x2592;
  8152. t['shadedark'] = 0x2593;
  8153. t['shadelight'] = 0x2591;
  8154. t['shademedium'] = 0x2592;
  8155. t['shadeva'] = 0x0936;
  8156. t['shagujarati'] = 0x0AB6;
  8157. t['shagurmukhi'] = 0x0A36;
  8158. t['shalshelethebrew'] = 0x0593;
  8159. t['shbopomofo'] = 0x3115;
  8160. t['shchacyrillic'] = 0x0449;
  8161. t['sheenarabic'] = 0x0634;
  8162. t['sheenfinalarabic'] = 0xFEB6;
  8163. t['sheeninitialarabic'] = 0xFEB7;
  8164. t['sheenmedialarabic'] = 0xFEB8;
  8165. t['sheicoptic'] = 0x03E3;
  8166. t['sheqel'] = 0x20AA;
  8167. t['sheqelhebrew'] = 0x20AA;
  8168. t['sheva'] = 0x05B0;
  8169. t['sheva115'] = 0x05B0;
  8170. t['sheva15'] = 0x05B0;
  8171. t['sheva22'] = 0x05B0;
  8172. t['sheva2e'] = 0x05B0;
  8173. t['shevahebrew'] = 0x05B0;
  8174. t['shevanarrowhebrew'] = 0x05B0;
  8175. t['shevaquarterhebrew'] = 0x05B0;
  8176. t['shevawidehebrew'] = 0x05B0;
  8177. t['shhacyrillic'] = 0x04BB;
  8178. t['shimacoptic'] = 0x03ED;
  8179. t['shin'] = 0x05E9;
  8180. t['shindagesh'] = 0xFB49;
  8181. t['shindageshhebrew'] = 0xFB49;
  8182. t['shindageshshindot'] = 0xFB2C;
  8183. t['shindageshshindothebrew'] = 0xFB2C;
  8184. t['shindageshsindot'] = 0xFB2D;
  8185. t['shindageshsindothebrew'] = 0xFB2D;
  8186. t['shindothebrew'] = 0x05C1;
  8187. t['shinhebrew'] = 0x05E9;
  8188. t['shinshindot'] = 0xFB2A;
  8189. t['shinshindothebrew'] = 0xFB2A;
  8190. t['shinsindot'] = 0xFB2B;
  8191. t['shinsindothebrew'] = 0xFB2B;
  8192. t['shook'] = 0x0282;
  8193. t['sigma'] = 0x03C3;
  8194. t['sigma1'] = 0x03C2;
  8195. t['sigmafinal'] = 0x03C2;
  8196. t['sigmalunatesymbolgreek'] = 0x03F2;
  8197. t['sihiragana'] = 0x3057;
  8198. t['sikatakana'] = 0x30B7;
  8199. t['sikatakanahalfwidth'] = 0xFF7C;
  8200. t['siluqhebrew'] = 0x05BD;
  8201. t['siluqlefthebrew'] = 0x05BD;
  8202. t['similar'] = 0x223C;
  8203. t['sindothebrew'] = 0x05C2;
  8204. t['siosacirclekorean'] = 0x3274;
  8205. t['siosaparenkorean'] = 0x3214;
  8206. t['sioscieuckorean'] = 0x317E;
  8207. t['sioscirclekorean'] = 0x3266;
  8208. t['sioskiyeokkorean'] = 0x317A;
  8209. t['sioskorean'] = 0x3145;
  8210. t['siosnieunkorean'] = 0x317B;
  8211. t['siosparenkorean'] = 0x3206;
  8212. t['siospieupkorean'] = 0x317D;
  8213. t['siostikeutkorean'] = 0x317C;
  8214. t['six'] = 0x0036;
  8215. t['sixarabic'] = 0x0666;
  8216. t['sixbengali'] = 0x09EC;
  8217. t['sixcircle'] = 0x2465;
  8218. t['sixcircleinversesansserif'] = 0x278F;
  8219. t['sixdeva'] = 0x096C;
  8220. t['sixgujarati'] = 0x0AEC;
  8221. t['sixgurmukhi'] = 0x0A6C;
  8222. t['sixhackarabic'] = 0x0666;
  8223. t['sixhangzhou'] = 0x3026;
  8224. t['sixideographicparen'] = 0x3225;
  8225. t['sixinferior'] = 0x2086;
  8226. t['sixmonospace'] = 0xFF16;
  8227. t['sixoldstyle'] = 0xF736;
  8228. t['sixparen'] = 0x2479;
  8229. t['sixperiod'] = 0x248D;
  8230. t['sixpersian'] = 0x06F6;
  8231. t['sixroman'] = 0x2175;
  8232. t['sixsuperior'] = 0x2076;
  8233. t['sixteencircle'] = 0x246F;
  8234. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8235. t['sixteenparen'] = 0x2483;
  8236. t['sixteenperiod'] = 0x2497;
  8237. t['sixthai'] = 0x0E56;
  8238. t['slash'] = 0x002F;
  8239. t['slashmonospace'] = 0xFF0F;
  8240. t['slong'] = 0x017F;
  8241. t['slongdotaccent'] = 0x1E9B;
  8242. t['smileface'] = 0x263A;
  8243. t['smonospace'] = 0xFF53;
  8244. t['sofpasuqhebrew'] = 0x05C3;
  8245. t['softhyphen'] = 0x00AD;
  8246. t['softsigncyrillic'] = 0x044C;
  8247. t['sohiragana'] = 0x305D;
  8248. t['sokatakana'] = 0x30BD;
  8249. t['sokatakanahalfwidth'] = 0xFF7F;
  8250. t['soliduslongoverlaycmb'] = 0x0338;
  8251. t['solidusshortoverlaycmb'] = 0x0337;
  8252. t['sorusithai'] = 0x0E29;
  8253. t['sosalathai'] = 0x0E28;
  8254. t['sosothai'] = 0x0E0B;
  8255. t['sosuathai'] = 0x0E2A;
  8256. t['space'] = 0x0020;
  8257. t['spacehackarabic'] = 0x0020;
  8258. t['spade'] = 0x2660;
  8259. t['spadesuitblack'] = 0x2660;
  8260. t['spadesuitwhite'] = 0x2664;
  8261. t['sparen'] = 0x24AE;
  8262. t['squarebelowcmb'] = 0x033B;
  8263. t['squarecc'] = 0x33C4;
  8264. t['squarecm'] = 0x339D;
  8265. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8266. t['squarehorizontalfill'] = 0x25A4;
  8267. t['squarekg'] = 0x338F;
  8268. t['squarekm'] = 0x339E;
  8269. t['squarekmcapital'] = 0x33CE;
  8270. t['squareln'] = 0x33D1;
  8271. t['squarelog'] = 0x33D2;
  8272. t['squaremg'] = 0x338E;
  8273. t['squaremil'] = 0x33D5;
  8274. t['squaremm'] = 0x339C;
  8275. t['squaremsquared'] = 0x33A1;
  8276. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8277. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8278. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8279. t['squareverticalfill'] = 0x25A5;
  8280. t['squarewhitewithsmallblack'] = 0x25A3;
  8281. t['srsquare'] = 0x33DB;
  8282. t['ssabengali'] = 0x09B7;
  8283. t['ssadeva'] = 0x0937;
  8284. t['ssagujarati'] = 0x0AB7;
  8285. t['ssangcieuckorean'] = 0x3149;
  8286. t['ssanghieuhkorean'] = 0x3185;
  8287. t['ssangieungkorean'] = 0x3180;
  8288. t['ssangkiyeokkorean'] = 0x3132;
  8289. t['ssangnieunkorean'] = 0x3165;
  8290. t['ssangpieupkorean'] = 0x3143;
  8291. t['ssangsioskorean'] = 0x3146;
  8292. t['ssangtikeutkorean'] = 0x3138;
  8293. t['ssuperior'] = 0xF6F2;
  8294. t['sterling'] = 0x00A3;
  8295. t['sterlingmonospace'] = 0xFFE1;
  8296. t['strokelongoverlaycmb'] = 0x0336;
  8297. t['strokeshortoverlaycmb'] = 0x0335;
  8298. t['subset'] = 0x2282;
  8299. t['subsetnotequal'] = 0x228A;
  8300. t['subsetorequal'] = 0x2286;
  8301. t['succeeds'] = 0x227B;
  8302. t['suchthat'] = 0x220B;
  8303. t['suhiragana'] = 0x3059;
  8304. t['sukatakana'] = 0x30B9;
  8305. t['sukatakanahalfwidth'] = 0xFF7D;
  8306. t['sukunarabic'] = 0x0652;
  8307. t['summation'] = 0x2211;
  8308. t['sun'] = 0x263C;
  8309. t['superset'] = 0x2283;
  8310. t['supersetnotequal'] = 0x228B;
  8311. t['supersetorequal'] = 0x2287;
  8312. t['svsquare'] = 0x33DC;
  8313. t['syouwaerasquare'] = 0x337C;
  8314. t['t'] = 0x0074;
  8315. t['tabengali'] = 0x09A4;
  8316. t['tackdown'] = 0x22A4;
  8317. t['tackleft'] = 0x22A3;
  8318. t['tadeva'] = 0x0924;
  8319. t['tagujarati'] = 0x0AA4;
  8320. t['tagurmukhi'] = 0x0A24;
  8321. t['taharabic'] = 0x0637;
  8322. t['tahfinalarabic'] = 0xFEC2;
  8323. t['tahinitialarabic'] = 0xFEC3;
  8324. t['tahiragana'] = 0x305F;
  8325. t['tahmedialarabic'] = 0xFEC4;
  8326. t['taisyouerasquare'] = 0x337D;
  8327. t['takatakana'] = 0x30BF;
  8328. t['takatakanahalfwidth'] = 0xFF80;
  8329. t['tatweelarabic'] = 0x0640;
  8330. t['tau'] = 0x03C4;
  8331. t['tav'] = 0x05EA;
  8332. t['tavdages'] = 0xFB4A;
  8333. t['tavdagesh'] = 0xFB4A;
  8334. t['tavdageshhebrew'] = 0xFB4A;
  8335. t['tavhebrew'] = 0x05EA;
  8336. t['tbar'] = 0x0167;
  8337. t['tbopomofo'] = 0x310A;
  8338. t['tcaron'] = 0x0165;
  8339. t['tccurl'] = 0x02A8;
  8340. t['tcedilla'] = 0x0163;
  8341. t['tcheharabic'] = 0x0686;
  8342. t['tchehfinalarabic'] = 0xFB7B;
  8343. t['tchehinitialarabic'] = 0xFB7C;
  8344. t['tchehmedialarabic'] = 0xFB7D;
  8345. t['tcircle'] = 0x24E3;
  8346. t['tcircumflexbelow'] = 0x1E71;
  8347. t['tcommaaccent'] = 0x0163;
  8348. t['tdieresis'] = 0x1E97;
  8349. t['tdotaccent'] = 0x1E6B;
  8350. t['tdotbelow'] = 0x1E6D;
  8351. t['tecyrillic'] = 0x0442;
  8352. t['tedescendercyrillic'] = 0x04AD;
  8353. t['teharabic'] = 0x062A;
  8354. t['tehfinalarabic'] = 0xFE96;
  8355. t['tehhahinitialarabic'] = 0xFCA2;
  8356. t['tehhahisolatedarabic'] = 0xFC0C;
  8357. t['tehinitialarabic'] = 0xFE97;
  8358. t['tehiragana'] = 0x3066;
  8359. t['tehjeeminitialarabic'] = 0xFCA1;
  8360. t['tehjeemisolatedarabic'] = 0xFC0B;
  8361. t['tehmarbutaarabic'] = 0x0629;
  8362. t['tehmarbutafinalarabic'] = 0xFE94;
  8363. t['tehmedialarabic'] = 0xFE98;
  8364. t['tehmeeminitialarabic'] = 0xFCA4;
  8365. t['tehmeemisolatedarabic'] = 0xFC0E;
  8366. t['tehnoonfinalarabic'] = 0xFC73;
  8367. t['tekatakana'] = 0x30C6;
  8368. t['tekatakanahalfwidth'] = 0xFF83;
  8369. t['telephone'] = 0x2121;
  8370. t['telephoneblack'] = 0x260E;
  8371. t['telishagedolahebrew'] = 0x05A0;
  8372. t['telishaqetanahebrew'] = 0x05A9;
  8373. t['tencircle'] = 0x2469;
  8374. t['tenideographicparen'] = 0x3229;
  8375. t['tenparen'] = 0x247D;
  8376. t['tenperiod'] = 0x2491;
  8377. t['tenroman'] = 0x2179;
  8378. t['tesh'] = 0x02A7;
  8379. t['tet'] = 0x05D8;
  8380. t['tetdagesh'] = 0xFB38;
  8381. t['tetdageshhebrew'] = 0xFB38;
  8382. t['tethebrew'] = 0x05D8;
  8383. t['tetsecyrillic'] = 0x04B5;
  8384. t['tevirhebrew'] = 0x059B;
  8385. t['tevirlefthebrew'] = 0x059B;
  8386. t['thabengali'] = 0x09A5;
  8387. t['thadeva'] = 0x0925;
  8388. t['thagujarati'] = 0x0AA5;
  8389. t['thagurmukhi'] = 0x0A25;
  8390. t['thalarabic'] = 0x0630;
  8391. t['thalfinalarabic'] = 0xFEAC;
  8392. t['thanthakhatlowleftthai'] = 0xF898;
  8393. t['thanthakhatlowrightthai'] = 0xF897;
  8394. t['thanthakhatthai'] = 0x0E4C;
  8395. t['thanthakhatupperleftthai'] = 0xF896;
  8396. t['theharabic'] = 0x062B;
  8397. t['thehfinalarabic'] = 0xFE9A;
  8398. t['thehinitialarabic'] = 0xFE9B;
  8399. t['thehmedialarabic'] = 0xFE9C;
  8400. t['thereexists'] = 0x2203;
  8401. t['therefore'] = 0x2234;
  8402. t['theta'] = 0x03B8;
  8403. t['theta1'] = 0x03D1;
  8404. t['thetasymbolgreek'] = 0x03D1;
  8405. t['thieuthacirclekorean'] = 0x3279;
  8406. t['thieuthaparenkorean'] = 0x3219;
  8407. t['thieuthcirclekorean'] = 0x326B;
  8408. t['thieuthkorean'] = 0x314C;
  8409. t['thieuthparenkorean'] = 0x320B;
  8410. t['thirteencircle'] = 0x246C;
  8411. t['thirteenparen'] = 0x2480;
  8412. t['thirteenperiod'] = 0x2494;
  8413. t['thonangmonthothai'] = 0x0E11;
  8414. t['thook'] = 0x01AD;
  8415. t['thophuthaothai'] = 0x0E12;
  8416. t['thorn'] = 0x00FE;
  8417. t['thothahanthai'] = 0x0E17;
  8418. t['thothanthai'] = 0x0E10;
  8419. t['thothongthai'] = 0x0E18;
  8420. t['thothungthai'] = 0x0E16;
  8421. t['thousandcyrillic'] = 0x0482;
  8422. t['thousandsseparatorarabic'] = 0x066C;
  8423. t['thousandsseparatorpersian'] = 0x066C;
  8424. t['three'] = 0x0033;
  8425. t['threearabic'] = 0x0663;
  8426. t['threebengali'] = 0x09E9;
  8427. t['threecircle'] = 0x2462;
  8428. t['threecircleinversesansserif'] = 0x278C;
  8429. t['threedeva'] = 0x0969;
  8430. t['threeeighths'] = 0x215C;
  8431. t['threegujarati'] = 0x0AE9;
  8432. t['threegurmukhi'] = 0x0A69;
  8433. t['threehackarabic'] = 0x0663;
  8434. t['threehangzhou'] = 0x3023;
  8435. t['threeideographicparen'] = 0x3222;
  8436. t['threeinferior'] = 0x2083;
  8437. t['threemonospace'] = 0xFF13;
  8438. t['threenumeratorbengali'] = 0x09F6;
  8439. t['threeoldstyle'] = 0xF733;
  8440. t['threeparen'] = 0x2476;
  8441. t['threeperiod'] = 0x248A;
  8442. t['threepersian'] = 0x06F3;
  8443. t['threequarters'] = 0x00BE;
  8444. t['threequartersemdash'] = 0xF6DE;
  8445. t['threeroman'] = 0x2172;
  8446. t['threesuperior'] = 0x00B3;
  8447. t['threethai'] = 0x0E53;
  8448. t['thzsquare'] = 0x3394;
  8449. t['tihiragana'] = 0x3061;
  8450. t['tikatakana'] = 0x30C1;
  8451. t['tikatakanahalfwidth'] = 0xFF81;
  8452. t['tikeutacirclekorean'] = 0x3270;
  8453. t['tikeutaparenkorean'] = 0x3210;
  8454. t['tikeutcirclekorean'] = 0x3262;
  8455. t['tikeutkorean'] = 0x3137;
  8456. t['tikeutparenkorean'] = 0x3202;
  8457. t['tilde'] = 0x02DC;
  8458. t['tildebelowcmb'] = 0x0330;
  8459. t['tildecmb'] = 0x0303;
  8460. t['tildecomb'] = 0x0303;
  8461. t['tildedoublecmb'] = 0x0360;
  8462. t['tildeoperator'] = 0x223C;
  8463. t['tildeoverlaycmb'] = 0x0334;
  8464. t['tildeverticalcmb'] = 0x033E;
  8465. t['timescircle'] = 0x2297;
  8466. t['tipehahebrew'] = 0x0596;
  8467. t['tipehalefthebrew'] = 0x0596;
  8468. t['tippigurmukhi'] = 0x0A70;
  8469. t['titlocyrilliccmb'] = 0x0483;
  8470. t['tiwnarmenian'] = 0x057F;
  8471. t['tlinebelow'] = 0x1E6F;
  8472. t['tmonospace'] = 0xFF54;
  8473. t['toarmenian'] = 0x0569;
  8474. t['tohiragana'] = 0x3068;
  8475. t['tokatakana'] = 0x30C8;
  8476. t['tokatakanahalfwidth'] = 0xFF84;
  8477. t['tonebarextrahighmod'] = 0x02E5;
  8478. t['tonebarextralowmod'] = 0x02E9;
  8479. t['tonebarhighmod'] = 0x02E6;
  8480. t['tonebarlowmod'] = 0x02E8;
  8481. t['tonebarmidmod'] = 0x02E7;
  8482. t['tonefive'] = 0x01BD;
  8483. t['tonesix'] = 0x0185;
  8484. t['tonetwo'] = 0x01A8;
  8485. t['tonos'] = 0x0384;
  8486. t['tonsquare'] = 0x3327;
  8487. t['topatakthai'] = 0x0E0F;
  8488. t['tortoiseshellbracketleft'] = 0x3014;
  8489. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8490. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8491. t['tortoiseshellbracketright'] = 0x3015;
  8492. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8493. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8494. t['totaothai'] = 0x0E15;
  8495. t['tpalatalhook'] = 0x01AB;
  8496. t['tparen'] = 0x24AF;
  8497. t['trademark'] = 0x2122;
  8498. t['trademarksans'] = 0xF8EA;
  8499. t['trademarkserif'] = 0xF6DB;
  8500. t['tretroflexhook'] = 0x0288;
  8501. t['triagdn'] = 0x25BC;
  8502. t['triaglf'] = 0x25C4;
  8503. t['triagrt'] = 0x25BA;
  8504. t['triagup'] = 0x25B2;
  8505. t['ts'] = 0x02A6;
  8506. t['tsadi'] = 0x05E6;
  8507. t['tsadidagesh'] = 0xFB46;
  8508. t['tsadidageshhebrew'] = 0xFB46;
  8509. t['tsadihebrew'] = 0x05E6;
  8510. t['tsecyrillic'] = 0x0446;
  8511. t['tsere'] = 0x05B5;
  8512. t['tsere12'] = 0x05B5;
  8513. t['tsere1e'] = 0x05B5;
  8514. t['tsere2b'] = 0x05B5;
  8515. t['tserehebrew'] = 0x05B5;
  8516. t['tserenarrowhebrew'] = 0x05B5;
  8517. t['tserequarterhebrew'] = 0x05B5;
  8518. t['tserewidehebrew'] = 0x05B5;
  8519. t['tshecyrillic'] = 0x045B;
  8520. t['tsuperior'] = 0xF6F3;
  8521. t['ttabengali'] = 0x099F;
  8522. t['ttadeva'] = 0x091F;
  8523. t['ttagujarati'] = 0x0A9F;
  8524. t['ttagurmukhi'] = 0x0A1F;
  8525. t['tteharabic'] = 0x0679;
  8526. t['ttehfinalarabic'] = 0xFB67;
  8527. t['ttehinitialarabic'] = 0xFB68;
  8528. t['ttehmedialarabic'] = 0xFB69;
  8529. t['tthabengali'] = 0x09A0;
  8530. t['tthadeva'] = 0x0920;
  8531. t['tthagujarati'] = 0x0AA0;
  8532. t['tthagurmukhi'] = 0x0A20;
  8533. t['tturned'] = 0x0287;
  8534. t['tuhiragana'] = 0x3064;
  8535. t['tukatakana'] = 0x30C4;
  8536. t['tukatakanahalfwidth'] = 0xFF82;
  8537. t['tusmallhiragana'] = 0x3063;
  8538. t['tusmallkatakana'] = 0x30C3;
  8539. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8540. t['twelvecircle'] = 0x246B;
  8541. t['twelveparen'] = 0x247F;
  8542. t['twelveperiod'] = 0x2493;
  8543. t['twelveroman'] = 0x217B;
  8544. t['twentycircle'] = 0x2473;
  8545. t['twentyhangzhou'] = 0x5344;
  8546. t['twentyparen'] = 0x2487;
  8547. t['twentyperiod'] = 0x249B;
  8548. t['two'] = 0x0032;
  8549. t['twoarabic'] = 0x0662;
  8550. t['twobengali'] = 0x09E8;
  8551. t['twocircle'] = 0x2461;
  8552. t['twocircleinversesansserif'] = 0x278B;
  8553. t['twodeva'] = 0x0968;
  8554. t['twodotenleader'] = 0x2025;
  8555. t['twodotleader'] = 0x2025;
  8556. t['twodotleadervertical'] = 0xFE30;
  8557. t['twogujarati'] = 0x0AE8;
  8558. t['twogurmukhi'] = 0x0A68;
  8559. t['twohackarabic'] = 0x0662;
  8560. t['twohangzhou'] = 0x3022;
  8561. t['twoideographicparen'] = 0x3221;
  8562. t['twoinferior'] = 0x2082;
  8563. t['twomonospace'] = 0xFF12;
  8564. t['twonumeratorbengali'] = 0x09F5;
  8565. t['twooldstyle'] = 0xF732;
  8566. t['twoparen'] = 0x2475;
  8567. t['twoperiod'] = 0x2489;
  8568. t['twopersian'] = 0x06F2;
  8569. t['tworoman'] = 0x2171;
  8570. t['twostroke'] = 0x01BB;
  8571. t['twosuperior'] = 0x00B2;
  8572. t['twothai'] = 0x0E52;
  8573. t['twothirds'] = 0x2154;
  8574. t['u'] = 0x0075;
  8575. t['uacute'] = 0x00FA;
  8576. t['ubar'] = 0x0289;
  8577. t['ubengali'] = 0x0989;
  8578. t['ubopomofo'] = 0x3128;
  8579. t['ubreve'] = 0x016D;
  8580. t['ucaron'] = 0x01D4;
  8581. t['ucircle'] = 0x24E4;
  8582. t['ucircumflex'] = 0x00FB;
  8583. t['ucircumflexbelow'] = 0x1E77;
  8584. t['ucyrillic'] = 0x0443;
  8585. t['udattadeva'] = 0x0951;
  8586. t['udblacute'] = 0x0171;
  8587. t['udblgrave'] = 0x0215;
  8588. t['udeva'] = 0x0909;
  8589. t['udieresis'] = 0x00FC;
  8590. t['udieresisacute'] = 0x01D8;
  8591. t['udieresisbelow'] = 0x1E73;
  8592. t['udieresiscaron'] = 0x01DA;
  8593. t['udieresiscyrillic'] = 0x04F1;
  8594. t['udieresisgrave'] = 0x01DC;
  8595. t['udieresismacron'] = 0x01D6;
  8596. t['udotbelow'] = 0x1EE5;
  8597. t['ugrave'] = 0x00F9;
  8598. t['ugujarati'] = 0x0A89;
  8599. t['ugurmukhi'] = 0x0A09;
  8600. t['uhiragana'] = 0x3046;
  8601. t['uhookabove'] = 0x1EE7;
  8602. t['uhorn'] = 0x01B0;
  8603. t['uhornacute'] = 0x1EE9;
  8604. t['uhorndotbelow'] = 0x1EF1;
  8605. t['uhorngrave'] = 0x1EEB;
  8606. t['uhornhookabove'] = 0x1EED;
  8607. t['uhorntilde'] = 0x1EEF;
  8608. t['uhungarumlaut'] = 0x0171;
  8609. t['uhungarumlautcyrillic'] = 0x04F3;
  8610. t['uinvertedbreve'] = 0x0217;
  8611. t['ukatakana'] = 0x30A6;
  8612. t['ukatakanahalfwidth'] = 0xFF73;
  8613. t['ukcyrillic'] = 0x0479;
  8614. t['ukorean'] = 0x315C;
  8615. t['umacron'] = 0x016B;
  8616. t['umacroncyrillic'] = 0x04EF;
  8617. t['umacrondieresis'] = 0x1E7B;
  8618. t['umatragurmukhi'] = 0x0A41;
  8619. t['umonospace'] = 0xFF55;
  8620. t['underscore'] = 0x005F;
  8621. t['underscoredbl'] = 0x2017;
  8622. t['underscoremonospace'] = 0xFF3F;
  8623. t['underscorevertical'] = 0xFE33;
  8624. t['underscorewavy'] = 0xFE4F;
  8625. t['union'] = 0x222A;
  8626. t['universal'] = 0x2200;
  8627. t['uogonek'] = 0x0173;
  8628. t['uparen'] = 0x24B0;
  8629. t['upblock'] = 0x2580;
  8630. t['upperdothebrew'] = 0x05C4;
  8631. t['upsilon'] = 0x03C5;
  8632. t['upsilondieresis'] = 0x03CB;
  8633. t['upsilondieresistonos'] = 0x03B0;
  8634. t['upsilonlatin'] = 0x028A;
  8635. t['upsilontonos'] = 0x03CD;
  8636. t['uptackbelowcmb'] = 0x031D;
  8637. t['uptackmod'] = 0x02D4;
  8638. t['uragurmukhi'] = 0x0A73;
  8639. t['uring'] = 0x016F;
  8640. t['ushortcyrillic'] = 0x045E;
  8641. t['usmallhiragana'] = 0x3045;
  8642. t['usmallkatakana'] = 0x30A5;
  8643. t['usmallkatakanahalfwidth'] = 0xFF69;
  8644. t['ustraightcyrillic'] = 0x04AF;
  8645. t['ustraightstrokecyrillic'] = 0x04B1;
  8646. t['utilde'] = 0x0169;
  8647. t['utildeacute'] = 0x1E79;
  8648. t['utildebelow'] = 0x1E75;
  8649. t['uubengali'] = 0x098A;
  8650. t['uudeva'] = 0x090A;
  8651. t['uugujarati'] = 0x0A8A;
  8652. t['uugurmukhi'] = 0x0A0A;
  8653. t['uumatragurmukhi'] = 0x0A42;
  8654. t['uuvowelsignbengali'] = 0x09C2;
  8655. t['uuvowelsigndeva'] = 0x0942;
  8656. t['uuvowelsigngujarati'] = 0x0AC2;
  8657. t['uvowelsignbengali'] = 0x09C1;
  8658. t['uvowelsigndeva'] = 0x0941;
  8659. t['uvowelsigngujarati'] = 0x0AC1;
  8660. t['v'] = 0x0076;
  8661. t['vadeva'] = 0x0935;
  8662. t['vagujarati'] = 0x0AB5;
  8663. t['vagurmukhi'] = 0x0A35;
  8664. t['vakatakana'] = 0x30F7;
  8665. t['vav'] = 0x05D5;
  8666. t['vavdagesh'] = 0xFB35;
  8667. t['vavdagesh65'] = 0xFB35;
  8668. t['vavdageshhebrew'] = 0xFB35;
  8669. t['vavhebrew'] = 0x05D5;
  8670. t['vavholam'] = 0xFB4B;
  8671. t['vavholamhebrew'] = 0xFB4B;
  8672. t['vavvavhebrew'] = 0x05F0;
  8673. t['vavyodhebrew'] = 0x05F1;
  8674. t['vcircle'] = 0x24E5;
  8675. t['vdotbelow'] = 0x1E7F;
  8676. t['vecyrillic'] = 0x0432;
  8677. t['veharabic'] = 0x06A4;
  8678. t['vehfinalarabic'] = 0xFB6B;
  8679. t['vehinitialarabic'] = 0xFB6C;
  8680. t['vehmedialarabic'] = 0xFB6D;
  8681. t['vekatakana'] = 0x30F9;
  8682. t['venus'] = 0x2640;
  8683. t['verticalbar'] = 0x007C;
  8684. t['verticallineabovecmb'] = 0x030D;
  8685. t['verticallinebelowcmb'] = 0x0329;
  8686. t['verticallinelowmod'] = 0x02CC;
  8687. t['verticallinemod'] = 0x02C8;
  8688. t['vewarmenian'] = 0x057E;
  8689. t['vhook'] = 0x028B;
  8690. t['vikatakana'] = 0x30F8;
  8691. t['viramabengali'] = 0x09CD;
  8692. t['viramadeva'] = 0x094D;
  8693. t['viramagujarati'] = 0x0ACD;
  8694. t['visargabengali'] = 0x0983;
  8695. t['visargadeva'] = 0x0903;
  8696. t['visargagujarati'] = 0x0A83;
  8697. t['vmonospace'] = 0xFF56;
  8698. t['voarmenian'] = 0x0578;
  8699. t['voicediterationhiragana'] = 0x309E;
  8700. t['voicediterationkatakana'] = 0x30FE;
  8701. t['voicedmarkkana'] = 0x309B;
  8702. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  8703. t['vokatakana'] = 0x30FA;
  8704. t['vparen'] = 0x24B1;
  8705. t['vtilde'] = 0x1E7D;
  8706. t['vturned'] = 0x028C;
  8707. t['vuhiragana'] = 0x3094;
  8708. t['vukatakana'] = 0x30F4;
  8709. t['w'] = 0x0077;
  8710. t['wacute'] = 0x1E83;
  8711. t['waekorean'] = 0x3159;
  8712. t['wahiragana'] = 0x308F;
  8713. t['wakatakana'] = 0x30EF;
  8714. t['wakatakanahalfwidth'] = 0xFF9C;
  8715. t['wakorean'] = 0x3158;
  8716. t['wasmallhiragana'] = 0x308E;
  8717. t['wasmallkatakana'] = 0x30EE;
  8718. t['wattosquare'] = 0x3357;
  8719. t['wavedash'] = 0x301C;
  8720. t['wavyunderscorevertical'] = 0xFE34;
  8721. t['wawarabic'] = 0x0648;
  8722. t['wawfinalarabic'] = 0xFEEE;
  8723. t['wawhamzaabovearabic'] = 0x0624;
  8724. t['wawhamzaabovefinalarabic'] = 0xFE86;
  8725. t['wbsquare'] = 0x33DD;
  8726. t['wcircle'] = 0x24E6;
  8727. t['wcircumflex'] = 0x0175;
  8728. t['wdieresis'] = 0x1E85;
  8729. t['wdotaccent'] = 0x1E87;
  8730. t['wdotbelow'] = 0x1E89;
  8731. t['wehiragana'] = 0x3091;
  8732. t['weierstrass'] = 0x2118;
  8733. t['wekatakana'] = 0x30F1;
  8734. t['wekorean'] = 0x315E;
  8735. t['weokorean'] = 0x315D;
  8736. t['wgrave'] = 0x1E81;
  8737. t['whitebullet'] = 0x25E6;
  8738. t['whitecircle'] = 0x25CB;
  8739. t['whitecircleinverse'] = 0x25D9;
  8740. t['whitecornerbracketleft'] = 0x300E;
  8741. t['whitecornerbracketleftvertical'] = 0xFE43;
  8742. t['whitecornerbracketright'] = 0x300F;
  8743. t['whitecornerbracketrightvertical'] = 0xFE44;
  8744. t['whitediamond'] = 0x25C7;
  8745. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  8746. t['whitedownpointingsmalltriangle'] = 0x25BF;
  8747. t['whitedownpointingtriangle'] = 0x25BD;
  8748. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  8749. t['whiteleftpointingtriangle'] = 0x25C1;
  8750. t['whitelenticularbracketleft'] = 0x3016;
  8751. t['whitelenticularbracketright'] = 0x3017;
  8752. t['whiterightpointingsmalltriangle'] = 0x25B9;
  8753. t['whiterightpointingtriangle'] = 0x25B7;
  8754. t['whitesmallsquare'] = 0x25AB;
  8755. t['whitesmilingface'] = 0x263A;
  8756. t['whitesquare'] = 0x25A1;
  8757. t['whitestar'] = 0x2606;
  8758. t['whitetelephone'] = 0x260F;
  8759. t['whitetortoiseshellbracketleft'] = 0x3018;
  8760. t['whitetortoiseshellbracketright'] = 0x3019;
  8761. t['whiteuppointingsmalltriangle'] = 0x25B5;
  8762. t['whiteuppointingtriangle'] = 0x25B3;
  8763. t['wihiragana'] = 0x3090;
  8764. t['wikatakana'] = 0x30F0;
  8765. t['wikorean'] = 0x315F;
  8766. t['wmonospace'] = 0xFF57;
  8767. t['wohiragana'] = 0x3092;
  8768. t['wokatakana'] = 0x30F2;
  8769. t['wokatakanahalfwidth'] = 0xFF66;
  8770. t['won'] = 0x20A9;
  8771. t['wonmonospace'] = 0xFFE6;
  8772. t['wowaenthai'] = 0x0E27;
  8773. t['wparen'] = 0x24B2;
  8774. t['wring'] = 0x1E98;
  8775. t['wsuperior'] = 0x02B7;
  8776. t['wturned'] = 0x028D;
  8777. t['wynn'] = 0x01BF;
  8778. t['x'] = 0x0078;
  8779. t['xabovecmb'] = 0x033D;
  8780. t['xbopomofo'] = 0x3112;
  8781. t['xcircle'] = 0x24E7;
  8782. t['xdieresis'] = 0x1E8D;
  8783. t['xdotaccent'] = 0x1E8B;
  8784. t['xeharmenian'] = 0x056D;
  8785. t['xi'] = 0x03BE;
  8786. t['xmonospace'] = 0xFF58;
  8787. t['xparen'] = 0x24B3;
  8788. t['xsuperior'] = 0x02E3;
  8789. t['y'] = 0x0079;
  8790. t['yaadosquare'] = 0x334E;
  8791. t['yabengali'] = 0x09AF;
  8792. t['yacute'] = 0x00FD;
  8793. t['yadeva'] = 0x092F;
  8794. t['yaekorean'] = 0x3152;
  8795. t['yagujarati'] = 0x0AAF;
  8796. t['yagurmukhi'] = 0x0A2F;
  8797. t['yahiragana'] = 0x3084;
  8798. t['yakatakana'] = 0x30E4;
  8799. t['yakatakanahalfwidth'] = 0xFF94;
  8800. t['yakorean'] = 0x3151;
  8801. t['yamakkanthai'] = 0x0E4E;
  8802. t['yasmallhiragana'] = 0x3083;
  8803. t['yasmallkatakana'] = 0x30E3;
  8804. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  8805. t['yatcyrillic'] = 0x0463;
  8806. t['ycircle'] = 0x24E8;
  8807. t['ycircumflex'] = 0x0177;
  8808. t['ydieresis'] = 0x00FF;
  8809. t['ydotaccent'] = 0x1E8F;
  8810. t['ydotbelow'] = 0x1EF5;
  8811. t['yeharabic'] = 0x064A;
  8812. t['yehbarreearabic'] = 0x06D2;
  8813. t['yehbarreefinalarabic'] = 0xFBAF;
  8814. t['yehfinalarabic'] = 0xFEF2;
  8815. t['yehhamzaabovearabic'] = 0x0626;
  8816. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  8817. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  8818. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  8819. t['yehinitialarabic'] = 0xFEF3;
  8820. t['yehmedialarabic'] = 0xFEF4;
  8821. t['yehmeeminitialarabic'] = 0xFCDD;
  8822. t['yehmeemisolatedarabic'] = 0xFC58;
  8823. t['yehnoonfinalarabic'] = 0xFC94;
  8824. t['yehthreedotsbelowarabic'] = 0x06D1;
  8825. t['yekorean'] = 0x3156;
  8826. t['yen'] = 0x00A5;
  8827. t['yenmonospace'] = 0xFFE5;
  8828. t['yeokorean'] = 0x3155;
  8829. t['yeorinhieuhkorean'] = 0x3186;
  8830. t['yerahbenyomohebrew'] = 0x05AA;
  8831. t['yerahbenyomolefthebrew'] = 0x05AA;
  8832. t['yericyrillic'] = 0x044B;
  8833. t['yerudieresiscyrillic'] = 0x04F9;
  8834. t['yesieungkorean'] = 0x3181;
  8835. t['yesieungpansioskorean'] = 0x3183;
  8836. t['yesieungsioskorean'] = 0x3182;
  8837. t['yetivhebrew'] = 0x059A;
  8838. t['ygrave'] = 0x1EF3;
  8839. t['yhook'] = 0x01B4;
  8840. t['yhookabove'] = 0x1EF7;
  8841. t['yiarmenian'] = 0x0575;
  8842. t['yicyrillic'] = 0x0457;
  8843. t['yikorean'] = 0x3162;
  8844. t['yinyang'] = 0x262F;
  8845. t['yiwnarmenian'] = 0x0582;
  8846. t['ymonospace'] = 0xFF59;
  8847. t['yod'] = 0x05D9;
  8848. t['yoddagesh'] = 0xFB39;
  8849. t['yoddageshhebrew'] = 0xFB39;
  8850. t['yodhebrew'] = 0x05D9;
  8851. t['yodyodhebrew'] = 0x05F2;
  8852. t['yodyodpatahhebrew'] = 0xFB1F;
  8853. t['yohiragana'] = 0x3088;
  8854. t['yoikorean'] = 0x3189;
  8855. t['yokatakana'] = 0x30E8;
  8856. t['yokatakanahalfwidth'] = 0xFF96;
  8857. t['yokorean'] = 0x315B;
  8858. t['yosmallhiragana'] = 0x3087;
  8859. t['yosmallkatakana'] = 0x30E7;
  8860. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  8861. t['yotgreek'] = 0x03F3;
  8862. t['yoyaekorean'] = 0x3188;
  8863. t['yoyakorean'] = 0x3187;
  8864. t['yoyakthai'] = 0x0E22;
  8865. t['yoyingthai'] = 0x0E0D;
  8866. t['yparen'] = 0x24B4;
  8867. t['ypogegrammeni'] = 0x037A;
  8868. t['ypogegrammenigreekcmb'] = 0x0345;
  8869. t['yr'] = 0x01A6;
  8870. t['yring'] = 0x1E99;
  8871. t['ysuperior'] = 0x02B8;
  8872. t['ytilde'] = 0x1EF9;
  8873. t['yturned'] = 0x028E;
  8874. t['yuhiragana'] = 0x3086;
  8875. t['yuikorean'] = 0x318C;
  8876. t['yukatakana'] = 0x30E6;
  8877. t['yukatakanahalfwidth'] = 0xFF95;
  8878. t['yukorean'] = 0x3160;
  8879. t['yusbigcyrillic'] = 0x046B;
  8880. t['yusbigiotifiedcyrillic'] = 0x046D;
  8881. t['yuslittlecyrillic'] = 0x0467;
  8882. t['yuslittleiotifiedcyrillic'] = 0x0469;
  8883. t['yusmallhiragana'] = 0x3085;
  8884. t['yusmallkatakana'] = 0x30E5;
  8885. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  8886. t['yuyekorean'] = 0x318B;
  8887. t['yuyeokorean'] = 0x318A;
  8888. t['yyabengali'] = 0x09DF;
  8889. t['yyadeva'] = 0x095F;
  8890. t['z'] = 0x007A;
  8891. t['zaarmenian'] = 0x0566;
  8892. t['zacute'] = 0x017A;
  8893. t['zadeva'] = 0x095B;
  8894. t['zagurmukhi'] = 0x0A5B;
  8895. t['zaharabic'] = 0x0638;
  8896. t['zahfinalarabic'] = 0xFEC6;
  8897. t['zahinitialarabic'] = 0xFEC7;
  8898. t['zahiragana'] = 0x3056;
  8899. t['zahmedialarabic'] = 0xFEC8;
  8900. t['zainarabic'] = 0x0632;
  8901. t['zainfinalarabic'] = 0xFEB0;
  8902. t['zakatakana'] = 0x30B6;
  8903. t['zaqefgadolhebrew'] = 0x0595;
  8904. t['zaqefqatanhebrew'] = 0x0594;
  8905. t['zarqahebrew'] = 0x0598;
  8906. t['zayin'] = 0x05D6;
  8907. t['zayindagesh'] = 0xFB36;
  8908. t['zayindageshhebrew'] = 0xFB36;
  8909. t['zayinhebrew'] = 0x05D6;
  8910. t['zbopomofo'] = 0x3117;
  8911. t['zcaron'] = 0x017E;
  8912. t['zcircle'] = 0x24E9;
  8913. t['zcircumflex'] = 0x1E91;
  8914. t['zcurl'] = 0x0291;
  8915. t['zdot'] = 0x017C;
  8916. t['zdotaccent'] = 0x017C;
  8917. t['zdotbelow'] = 0x1E93;
  8918. t['zecyrillic'] = 0x0437;
  8919. t['zedescendercyrillic'] = 0x0499;
  8920. t['zedieresiscyrillic'] = 0x04DF;
  8921. t['zehiragana'] = 0x305C;
  8922. t['zekatakana'] = 0x30BC;
  8923. t['zero'] = 0x0030;
  8924. t['zeroarabic'] = 0x0660;
  8925. t['zerobengali'] = 0x09E6;
  8926. t['zerodeva'] = 0x0966;
  8927. t['zerogujarati'] = 0x0AE6;
  8928. t['zerogurmukhi'] = 0x0A66;
  8929. t['zerohackarabic'] = 0x0660;
  8930. t['zeroinferior'] = 0x2080;
  8931. t['zeromonospace'] = 0xFF10;
  8932. t['zerooldstyle'] = 0xF730;
  8933. t['zeropersian'] = 0x06F0;
  8934. t['zerosuperior'] = 0x2070;
  8935. t['zerothai'] = 0x0E50;
  8936. t['zerowidthjoiner'] = 0xFEFF;
  8937. t['zerowidthnonjoiner'] = 0x200C;
  8938. t['zerowidthspace'] = 0x200B;
  8939. t['zeta'] = 0x03B6;
  8940. t['zhbopomofo'] = 0x3113;
  8941. t['zhearmenian'] = 0x056A;
  8942. t['zhebrevecyrillic'] = 0x04C2;
  8943. t['zhecyrillic'] = 0x0436;
  8944. t['zhedescendercyrillic'] = 0x0497;
  8945. t['zhedieresiscyrillic'] = 0x04DD;
  8946. t['zihiragana'] = 0x3058;
  8947. t['zikatakana'] = 0x30B8;
  8948. t['zinorhebrew'] = 0x05AE;
  8949. t['zlinebelow'] = 0x1E95;
  8950. t['zmonospace'] = 0xFF5A;
  8951. t['zohiragana'] = 0x305E;
  8952. t['zokatakana'] = 0x30BE;
  8953. t['zparen'] = 0x24B5;
  8954. t['zretroflexhook'] = 0x0290;
  8955. t['zstroke'] = 0x01B6;
  8956. t['zuhiragana'] = 0x305A;
  8957. t['zukatakana'] = 0x30BA;
  8958. t['.notdef'] = 0x0000;
  8959. });
  8960. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  8961. t['space'] = 0x0020;
  8962. t['a1'] = 0x2701;
  8963. t['a2'] = 0x2702;
  8964. t['a202'] = 0x2703;
  8965. t['a3'] = 0x2704;
  8966. t['a4'] = 0x260E;
  8967. t['a5'] = 0x2706;
  8968. t['a119'] = 0x2707;
  8969. t['a118'] = 0x2708;
  8970. t['a117'] = 0x2709;
  8971. t['a11'] = 0x261B;
  8972. t['a12'] = 0x261E;
  8973. t['a13'] = 0x270C;
  8974. t['a14'] = 0x270D;
  8975. t['a15'] = 0x270E;
  8976. t['a16'] = 0x270F;
  8977. t['a105'] = 0x2710;
  8978. t['a17'] = 0x2711;
  8979. t['a18'] = 0x2712;
  8980. t['a19'] = 0x2713;
  8981. t['a20'] = 0x2714;
  8982. t['a21'] = 0x2715;
  8983. t['a22'] = 0x2716;
  8984. t['a23'] = 0x2717;
  8985. t['a24'] = 0x2718;
  8986. t['a25'] = 0x2719;
  8987. t['a26'] = 0x271A;
  8988. t['a27'] = 0x271B;
  8989. t['a28'] = 0x271C;
  8990. t['a6'] = 0x271D;
  8991. t['a7'] = 0x271E;
  8992. t['a8'] = 0x271F;
  8993. t['a9'] = 0x2720;
  8994. t['a10'] = 0x2721;
  8995. t['a29'] = 0x2722;
  8996. t['a30'] = 0x2723;
  8997. t['a31'] = 0x2724;
  8998. t['a32'] = 0x2725;
  8999. t['a33'] = 0x2726;
  9000. t['a34'] = 0x2727;
  9001. t['a35'] = 0x2605;
  9002. t['a36'] = 0x2729;
  9003. t['a37'] = 0x272A;
  9004. t['a38'] = 0x272B;
  9005. t['a39'] = 0x272C;
  9006. t['a40'] = 0x272D;
  9007. t['a41'] = 0x272E;
  9008. t['a42'] = 0x272F;
  9009. t['a43'] = 0x2730;
  9010. t['a44'] = 0x2731;
  9011. t['a45'] = 0x2732;
  9012. t['a46'] = 0x2733;
  9013. t['a47'] = 0x2734;
  9014. t['a48'] = 0x2735;
  9015. t['a49'] = 0x2736;
  9016. t['a50'] = 0x2737;
  9017. t['a51'] = 0x2738;
  9018. t['a52'] = 0x2739;
  9019. t['a53'] = 0x273A;
  9020. t['a54'] = 0x273B;
  9021. t['a55'] = 0x273C;
  9022. t['a56'] = 0x273D;
  9023. t['a57'] = 0x273E;
  9024. t['a58'] = 0x273F;
  9025. t['a59'] = 0x2740;
  9026. t['a60'] = 0x2741;
  9027. t['a61'] = 0x2742;
  9028. t['a62'] = 0x2743;
  9029. t['a63'] = 0x2744;
  9030. t['a64'] = 0x2745;
  9031. t['a65'] = 0x2746;
  9032. t['a66'] = 0x2747;
  9033. t['a67'] = 0x2748;
  9034. t['a68'] = 0x2749;
  9035. t['a69'] = 0x274A;
  9036. t['a70'] = 0x274B;
  9037. t['a71'] = 0x25CF;
  9038. t['a72'] = 0x274D;
  9039. t['a73'] = 0x25A0;
  9040. t['a74'] = 0x274F;
  9041. t['a203'] = 0x2750;
  9042. t['a75'] = 0x2751;
  9043. t['a204'] = 0x2752;
  9044. t['a76'] = 0x25B2;
  9045. t['a77'] = 0x25BC;
  9046. t['a78'] = 0x25C6;
  9047. t['a79'] = 0x2756;
  9048. t['a81'] = 0x25D7;
  9049. t['a82'] = 0x2758;
  9050. t['a83'] = 0x2759;
  9051. t['a84'] = 0x275A;
  9052. t['a97'] = 0x275B;
  9053. t['a98'] = 0x275C;
  9054. t['a99'] = 0x275D;
  9055. t['a100'] = 0x275E;
  9056. t['a101'] = 0x2761;
  9057. t['a102'] = 0x2762;
  9058. t['a103'] = 0x2763;
  9059. t['a104'] = 0x2764;
  9060. t['a106'] = 0x2765;
  9061. t['a107'] = 0x2766;
  9062. t['a108'] = 0x2767;
  9063. t['a112'] = 0x2663;
  9064. t['a111'] = 0x2666;
  9065. t['a110'] = 0x2665;
  9066. t['a109'] = 0x2660;
  9067. t['a120'] = 0x2460;
  9068. t['a121'] = 0x2461;
  9069. t['a122'] = 0x2462;
  9070. t['a123'] = 0x2463;
  9071. t['a124'] = 0x2464;
  9072. t['a125'] = 0x2465;
  9073. t['a126'] = 0x2466;
  9074. t['a127'] = 0x2467;
  9075. t['a128'] = 0x2468;
  9076. t['a129'] = 0x2469;
  9077. t['a130'] = 0x2776;
  9078. t['a131'] = 0x2777;
  9079. t['a132'] = 0x2778;
  9080. t['a133'] = 0x2779;
  9081. t['a134'] = 0x277A;
  9082. t['a135'] = 0x277B;
  9083. t['a136'] = 0x277C;
  9084. t['a137'] = 0x277D;
  9085. t['a138'] = 0x277E;
  9086. t['a139'] = 0x277F;
  9087. t['a140'] = 0x2780;
  9088. t['a141'] = 0x2781;
  9089. t['a142'] = 0x2782;
  9090. t['a143'] = 0x2783;
  9091. t['a144'] = 0x2784;
  9092. t['a145'] = 0x2785;
  9093. t['a146'] = 0x2786;
  9094. t['a147'] = 0x2787;
  9095. t['a148'] = 0x2788;
  9096. t['a149'] = 0x2789;
  9097. t['a150'] = 0x278A;
  9098. t['a151'] = 0x278B;
  9099. t['a152'] = 0x278C;
  9100. t['a153'] = 0x278D;
  9101. t['a154'] = 0x278E;
  9102. t['a155'] = 0x278F;
  9103. t['a156'] = 0x2790;
  9104. t['a157'] = 0x2791;
  9105. t['a158'] = 0x2792;
  9106. t['a159'] = 0x2793;
  9107. t['a160'] = 0x2794;
  9108. t['a161'] = 0x2192;
  9109. t['a163'] = 0x2194;
  9110. t['a164'] = 0x2195;
  9111. t['a196'] = 0x2798;
  9112. t['a165'] = 0x2799;
  9113. t['a192'] = 0x279A;
  9114. t['a166'] = 0x279B;
  9115. t['a167'] = 0x279C;
  9116. t['a168'] = 0x279D;
  9117. t['a169'] = 0x279E;
  9118. t['a170'] = 0x279F;
  9119. t['a171'] = 0x27A0;
  9120. t['a172'] = 0x27A1;
  9121. t['a173'] = 0x27A2;
  9122. t['a162'] = 0x27A3;
  9123. t['a174'] = 0x27A4;
  9124. t['a175'] = 0x27A5;
  9125. t['a176'] = 0x27A6;
  9126. t['a177'] = 0x27A7;
  9127. t['a178'] = 0x27A8;
  9128. t['a179'] = 0x27A9;
  9129. t['a193'] = 0x27AA;
  9130. t['a180'] = 0x27AB;
  9131. t['a199'] = 0x27AC;
  9132. t['a181'] = 0x27AD;
  9133. t['a200'] = 0x27AE;
  9134. t['a182'] = 0x27AF;
  9135. t['a201'] = 0x27B1;
  9136. t['a183'] = 0x27B2;
  9137. t['a184'] = 0x27B3;
  9138. t['a197'] = 0x27B4;
  9139. t['a185'] = 0x27B5;
  9140. t['a194'] = 0x27B6;
  9141. t['a198'] = 0x27B7;
  9142. t['a186'] = 0x27B8;
  9143. t['a195'] = 0x27B9;
  9144. t['a187'] = 0x27BA;
  9145. t['a188'] = 0x27BB;
  9146. t['a189'] = 0x27BC;
  9147. t['a190'] = 0x27BD;
  9148. t['a191'] = 0x27BE;
  9149. t['a89'] = 0x2768; // 0xF8D7
  9150. t['a90'] = 0x2769; // 0xF8D8
  9151. t['a93'] = 0x276A; // 0xF8D9
  9152. t['a94'] = 0x276B; // 0xF8DA
  9153. t['a91'] = 0x276C; // 0xF8DB
  9154. t['a92'] = 0x276D; // 0xF8DC
  9155. t['a205'] = 0x276E; // 0xF8DD
  9156. t['a85'] = 0x276F; // 0xF8DE
  9157. t['a206'] = 0x2770; // 0xF8DF
  9158. t['a86'] = 0x2771; // 0xF8E0
  9159. t['a87'] = 0x2772; // 0xF8E1
  9160. t['a88'] = 0x2773; // 0xF8E2
  9161. t['a95'] = 0x2774; // 0xF8E3
  9162. t['a96'] = 0x2775; // 0xF8E4
  9163. t['.notdef'] = 0x0000;
  9164. });
  9165. exports.getGlyphsUnicode = getGlyphsUnicode;
  9166. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9167. }));
  9168. (function (root, factory) {
  9169. {
  9170. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9171. root.pdfjsCoreArithmeticDecoder);
  9172. }
  9173. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9174. var error = sharedUtil.error;
  9175. var log2 = sharedUtil.log2;
  9176. var readInt8 = sharedUtil.readInt8;
  9177. var readUint16 = sharedUtil.readUint16;
  9178. var readUint32 = sharedUtil.readUint32;
  9179. var shadow = sharedUtil.shadow;
  9180. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9181. var Jbig2Image = (function Jbig2ImageClosure() {
  9182. // Utility data structures
  9183. function ContextCache() {}
  9184. ContextCache.prototype = {
  9185. getContexts: function(id) {
  9186. if (id in this) {
  9187. return this[id];
  9188. }
  9189. return (this[id] = new Int8Array(1 << 16));
  9190. }
  9191. };
  9192. function DecodingContext(data, start, end) {
  9193. this.data = data;
  9194. this.start = start;
  9195. this.end = end;
  9196. }
  9197. DecodingContext.prototype = {
  9198. get decoder() {
  9199. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9200. return shadow(this, 'decoder', decoder);
  9201. },
  9202. get contextCache() {
  9203. var cache = new ContextCache();
  9204. return shadow(this, 'contextCache', cache);
  9205. }
  9206. };
  9207. // Annex A. Arithmetic Integer Decoding Procedure
  9208. // A.2 Procedure for decoding values
  9209. function decodeInteger(contextCache, procedure, decoder) {
  9210. var contexts = contextCache.getContexts(procedure);
  9211. var prev = 1;
  9212. function readBits(length) {
  9213. var v = 0;
  9214. for (var i = 0; i < length; i++) {
  9215. var bit = decoder.readBit(contexts, prev);
  9216. prev = (prev < 256 ? (prev << 1) | bit :
  9217. (((prev << 1) | bit) & 511) | 256);
  9218. v = (v << 1) | bit;
  9219. }
  9220. return v >>> 0;
  9221. }
  9222. var sign = readBits(1);
  9223. var value = readBits(1) ?
  9224. (readBits(1) ?
  9225. (readBits(1) ?
  9226. (readBits(1) ?
  9227. (readBits(1) ?
  9228. (readBits(32) + 4436) :
  9229. readBits(12) + 340) :
  9230. readBits(8) + 84) :
  9231. readBits(6) + 20) :
  9232. readBits(4) + 4) :
  9233. readBits(2);
  9234. return (sign === 0 ? value : (value > 0 ? -value : null));
  9235. }
  9236. // A.3 The IAID decoding procedure
  9237. function decodeIAID(contextCache, decoder, codeLength) {
  9238. var contexts = contextCache.getContexts('IAID');
  9239. var prev = 1;
  9240. for (var i = 0; i < codeLength; i++) {
  9241. var bit = decoder.readBit(contexts, prev);
  9242. prev = (prev << 1) | bit;
  9243. }
  9244. if (codeLength < 31) {
  9245. return prev & ((1 << codeLength) - 1);
  9246. }
  9247. return prev & 0x7FFFFFFF;
  9248. }
  9249. // 7.3 Segment types
  9250. var SegmentTypes = [
  9251. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9252. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9253. null, null, null, null, null, 'patternDictionary', null, null, null,
  9254. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9255. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9256. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9257. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9258. 'IntermediateGenericRefinementRegion', null,
  9259. 'ImmediateGenericRefinementRegion',
  9260. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9261. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9262. 'Tables', null, null, null, null, null, null, null, null,
  9263. 'Extension'
  9264. ];
  9265. var CodingTemplates = [
  9266. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9267. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9268. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9269. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9270. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9271. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9272. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9273. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9274. {x: -1, y: 0}],
  9275. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9276. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9277. ];
  9278. var RefinementTemplates = [
  9279. {
  9280. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9281. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9282. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9283. },
  9284. {
  9285. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9286. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9287. {x: 0, y: 1}, {x: 1, y: 1}]
  9288. }
  9289. ];
  9290. // See 6.2.5.7 Decoding the bitmap.
  9291. var ReusedContexts = [
  9292. 0x9B25, // 10011 0110010 0101
  9293. 0x0795, // 0011 110010 101
  9294. 0x00E5, // 001 11001 01
  9295. 0x0195 // 011001 0101
  9296. ];
  9297. var RefinementReusedContexts = [
  9298. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9299. 0x0008 // '0000' + '001000'
  9300. ];
  9301. function decodeBitmapTemplate0(width, height, decodingContext) {
  9302. var decoder = decodingContext.decoder;
  9303. var contexts = decodingContext.contextCache.getContexts('GB');
  9304. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9305. // ...ooooo....
  9306. // ..ooooooo... Context template for current pixel (X)
  9307. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9308. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9309. for (i = 0; i < height; i++) {
  9310. row = bitmap[i] = new Uint8Array(width);
  9311. row1 = (i < 1) ? row : bitmap[i - 1];
  9312. row2 = (i < 2) ? row : bitmap[i - 2];
  9313. // At the beginning of each row:
  9314. // Fill contextLabel with pixels that are above/right of (X)
  9315. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9316. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9317. (row1[3] << 4);
  9318. for (j = 0; j < width; j++) {
  9319. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9320. // At each pixel: Clear contextLabel pixels that are shifted
  9321. // out of the context, then add new ones.
  9322. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9323. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9324. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9325. }
  9326. }
  9327. return bitmap;
  9328. }
  9329. // 6.2 Generic Region Decoding Procedure
  9330. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9331. decodingContext) {
  9332. if (mmr) {
  9333. error('JBIG2 error: MMR encoding is not supported');
  9334. }
  9335. // Use optimized version for the most common case
  9336. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9337. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9338. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9339. return decodeBitmapTemplate0(width, height, decodingContext);
  9340. }
  9341. var useskip = !!skip;
  9342. var template = CodingTemplates[templateIndex].concat(at);
  9343. // Sorting is non-standard, and it is not required. But sorting increases
  9344. // the number of template bits that can be reused from the previous
  9345. // contextLabel in the main loop.
  9346. template.sort(function (a, b) {
  9347. return (a.y - b.y) || (a.x - b.x);
  9348. });
  9349. var templateLength = template.length;
  9350. var templateX = new Int8Array(templateLength);
  9351. var templateY = new Int8Array(templateLength);
  9352. var changingTemplateEntries = [];
  9353. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9354. var c, k;
  9355. for (k = 0; k < templateLength; k++) {
  9356. templateX[k] = template[k].x;
  9357. templateY[k] = template[k].y;
  9358. minX = Math.min(minX, template[k].x);
  9359. maxX = Math.max(maxX, template[k].x);
  9360. minY = Math.min(minY, template[k].y);
  9361. // Check if the template pixel appears in two consecutive context labels,
  9362. // so it can be reused. Otherwise, we add it to the list of changing
  9363. // template entries.
  9364. if (k < templateLength - 1 &&
  9365. template[k].y === template[k + 1].y &&
  9366. template[k].x === template[k + 1].x - 1) {
  9367. reuseMask |= 1 << (templateLength - 1 - k);
  9368. } else {
  9369. changingTemplateEntries.push(k);
  9370. }
  9371. }
  9372. var changingEntriesLength = changingTemplateEntries.length;
  9373. var changingTemplateX = new Int8Array(changingEntriesLength);
  9374. var changingTemplateY = new Int8Array(changingEntriesLength);
  9375. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9376. for (c = 0; c < changingEntriesLength; c++) {
  9377. k = changingTemplateEntries[c];
  9378. changingTemplateX[c] = template[k].x;
  9379. changingTemplateY[c] = template[k].y;
  9380. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9381. }
  9382. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9383. var sbb_left = -minX;
  9384. var sbb_top = -minY;
  9385. var sbb_right = width - maxX;
  9386. var pseudoPixelContext = ReusedContexts[templateIndex];
  9387. var row = new Uint8Array(width);
  9388. var bitmap = [];
  9389. var decoder = decodingContext.decoder;
  9390. var contexts = decodingContext.contextCache.getContexts('GB');
  9391. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9392. for (var i = 0; i < height; i++) {
  9393. if (prediction) {
  9394. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9395. ltp ^= sltp;
  9396. if (ltp) {
  9397. bitmap.push(row); // duplicate previous row
  9398. continue;
  9399. }
  9400. }
  9401. row = new Uint8Array(row);
  9402. bitmap.push(row);
  9403. for (j = 0; j < width; j++) {
  9404. if (useskip && skip[i][j]) {
  9405. row[j] = 0;
  9406. continue;
  9407. }
  9408. // Are we in the middle of a scanline, so we can reuse contextLabel
  9409. // bits?
  9410. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9411. // If yes, we can just shift the bits that are reusable and only
  9412. // fetch the remaining ones.
  9413. contextLabel = (contextLabel << 1) & reuseMask;
  9414. for (k = 0; k < changingEntriesLength; k++) {
  9415. i0 = i + changingTemplateY[k];
  9416. j0 = j + changingTemplateX[k];
  9417. bit = bitmap[i0][j0];
  9418. if (bit) {
  9419. bit = changingTemplateBit[k];
  9420. contextLabel |= bit;
  9421. }
  9422. }
  9423. } else {
  9424. // compute the contextLabel from scratch
  9425. contextLabel = 0;
  9426. shift = templateLength - 1;
  9427. for (k = 0; k < templateLength; k++, shift--) {
  9428. j0 = j + templateX[k];
  9429. if (j0 >= 0 && j0 < width) {
  9430. i0 = i + templateY[k];
  9431. if (i0 >= 0) {
  9432. bit = bitmap[i0][j0];
  9433. if (bit) {
  9434. contextLabel |= bit << shift;
  9435. }
  9436. }
  9437. }
  9438. }
  9439. }
  9440. var pixel = decoder.readBit(contexts, contextLabel);
  9441. row[j] = pixel;
  9442. }
  9443. }
  9444. return bitmap;
  9445. }
  9446. // 6.3.2 Generic Refinement Region Decoding Procedure
  9447. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9448. offsetX, offsetY, prediction, at,
  9449. decodingContext) {
  9450. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9451. if (templateIndex === 0) {
  9452. codingTemplate = codingTemplate.concat([at[0]]);
  9453. }
  9454. var codingTemplateLength = codingTemplate.length;
  9455. var codingTemplateX = new Int32Array(codingTemplateLength);
  9456. var codingTemplateY = new Int32Array(codingTemplateLength);
  9457. var k;
  9458. for (k = 0; k < codingTemplateLength; k++) {
  9459. codingTemplateX[k] = codingTemplate[k].x;
  9460. codingTemplateY[k] = codingTemplate[k].y;
  9461. }
  9462. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9463. if (templateIndex === 0) {
  9464. referenceTemplate = referenceTemplate.concat([at[1]]);
  9465. }
  9466. var referenceTemplateLength = referenceTemplate.length;
  9467. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9468. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9469. for (k = 0; k < referenceTemplateLength; k++) {
  9470. referenceTemplateX[k] = referenceTemplate[k].x;
  9471. referenceTemplateY[k] = referenceTemplate[k].y;
  9472. }
  9473. var referenceWidth = referenceBitmap[0].length;
  9474. var referenceHeight = referenceBitmap.length;
  9475. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9476. var bitmap = [];
  9477. var decoder = decodingContext.decoder;
  9478. var contexts = decodingContext.contextCache.getContexts('GR');
  9479. var ltp = 0;
  9480. for (var i = 0; i < height; i++) {
  9481. if (prediction) {
  9482. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9483. ltp ^= sltp;
  9484. if (ltp) {
  9485. error('JBIG2 error: prediction is not supported');
  9486. }
  9487. }
  9488. var row = new Uint8Array(width);
  9489. bitmap.push(row);
  9490. for (var j = 0; j < width; j++) {
  9491. var i0, j0;
  9492. var contextLabel = 0;
  9493. for (k = 0; k < codingTemplateLength; k++) {
  9494. i0 = i + codingTemplateY[k];
  9495. j0 = j + codingTemplateX[k];
  9496. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9497. contextLabel <<= 1; // out of bound pixel
  9498. } else {
  9499. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9500. }
  9501. }
  9502. for (k = 0; k < referenceTemplateLength; k++) {
  9503. i0 = i + referenceTemplateY[k] + offsetY;
  9504. j0 = j + referenceTemplateX[k] + offsetX;
  9505. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9506. j0 >= referenceWidth) {
  9507. contextLabel <<= 1; // out of bound pixel
  9508. } else {
  9509. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9510. }
  9511. }
  9512. var pixel = decoder.readBit(contexts, contextLabel);
  9513. row[j] = pixel;
  9514. }
  9515. }
  9516. return bitmap;
  9517. }
  9518. // 6.5.5 Decoding the symbol dictionary
  9519. function decodeSymbolDictionary(huffman, refinement, symbols,
  9520. numberOfNewSymbols, numberOfExportedSymbols,
  9521. huffmanTables, templateIndex, at,
  9522. refinementTemplateIndex, refinementAt,
  9523. decodingContext) {
  9524. if (huffman) {
  9525. error('JBIG2 error: huffman is not supported');
  9526. }
  9527. var newSymbols = [];
  9528. var currentHeight = 0;
  9529. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9530. var decoder = decodingContext.decoder;
  9531. var contextCache = decodingContext.contextCache;
  9532. while (newSymbols.length < numberOfNewSymbols) {
  9533. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9534. currentHeight += deltaHeight;
  9535. var currentWidth = 0;
  9536. var totalWidth = 0;
  9537. while (true) {
  9538. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9539. if (deltaWidth === null) {
  9540. break; // OOB
  9541. }
  9542. currentWidth += deltaWidth;
  9543. totalWidth += currentWidth;
  9544. var bitmap;
  9545. if (refinement) {
  9546. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9547. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9548. if (numberOfInstances > 1) {
  9549. bitmap = decodeTextRegion(huffman, refinement,
  9550. currentWidth, currentHeight, 0,
  9551. numberOfInstances, 1, //strip size
  9552. symbols.concat(newSymbols),
  9553. symbolCodeLength,
  9554. 0, //transposed
  9555. 0, //ds offset
  9556. 1, //top left 7.4.3.1.1
  9557. 0, //OR operator
  9558. huffmanTables,
  9559. refinementTemplateIndex, refinementAt,
  9560. decodingContext);
  9561. } else {
  9562. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9563. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9564. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9565. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9566. newSymbols[symbolId - symbols.length]);
  9567. bitmap = decodeRefinement(currentWidth, currentHeight,
  9568. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9569. decodingContext);
  9570. }
  9571. } else {
  9572. // 6.5.8.1 Direct-coded symbol bitmap
  9573. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  9574. templateIndex, false, null, at, decodingContext);
  9575. }
  9576. newSymbols.push(bitmap);
  9577. }
  9578. }
  9579. // 6.5.10 Exported symbols
  9580. var exportedSymbols = [];
  9581. var flags = [], currentFlag = false;
  9582. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  9583. while (flags.length < totalSymbolsLength) {
  9584. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  9585. while (runLength--) {
  9586. flags.push(currentFlag);
  9587. }
  9588. currentFlag = !currentFlag;
  9589. }
  9590. for (var i = 0, ii = symbols.length; i < ii; i++) {
  9591. if (flags[i]) {
  9592. exportedSymbols.push(symbols[i]);
  9593. }
  9594. }
  9595. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  9596. if (flags[i]) {
  9597. exportedSymbols.push(newSymbols[j]);
  9598. }
  9599. }
  9600. return exportedSymbols;
  9601. }
  9602. function decodeTextRegion(huffman, refinement, width, height,
  9603. defaultPixelValue, numberOfSymbolInstances,
  9604. stripSize, inputSymbols, symbolCodeLength,
  9605. transposed, dsOffset, referenceCorner,
  9606. combinationOperator, huffmanTables,
  9607. refinementTemplateIndex, refinementAt,
  9608. decodingContext) {
  9609. if (huffman) {
  9610. error('JBIG2 error: huffman is not supported');
  9611. }
  9612. // Prepare bitmap
  9613. var bitmap = [];
  9614. var i, row;
  9615. for (i = 0; i < height; i++) {
  9616. row = new Uint8Array(width);
  9617. if (defaultPixelValue) {
  9618. for (var j = 0; j < width; j++) {
  9619. row[j] = defaultPixelValue;
  9620. }
  9621. }
  9622. bitmap.push(row);
  9623. }
  9624. var decoder = decodingContext.decoder;
  9625. var contextCache = decodingContext.contextCache;
  9626. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9627. var firstS = 0;
  9628. i = 0;
  9629. while (i < numberOfSymbolInstances) {
  9630. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9631. stripT += deltaT;
  9632. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  9633. firstS += deltaFirstS;
  9634. var currentS = firstS;
  9635. do {
  9636. var currentT = (stripSize === 1 ? 0 :
  9637. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  9638. var t = stripSize * stripT + currentT;
  9639. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9640. var applyRefinement = (refinement &&
  9641. decodeInteger(contextCache, 'IARI', decoder));
  9642. var symbolBitmap = inputSymbols[symbolId];
  9643. var symbolWidth = symbolBitmap[0].length;
  9644. var symbolHeight = symbolBitmap.length;
  9645. if (applyRefinement) {
  9646. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  9647. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  9648. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9649. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9650. symbolWidth += rdw;
  9651. symbolHeight += rdh;
  9652. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  9653. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  9654. (rdh >> 1) + rdy, false, refinementAt,
  9655. decodingContext);
  9656. }
  9657. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  9658. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  9659. var s2, t2, symbolRow;
  9660. if (transposed) {
  9661. // Place Symbol Bitmap from T1,S1
  9662. for (s2 = 0; s2 < symbolHeight; s2++) {
  9663. row = bitmap[offsetS + s2];
  9664. if (!row) {
  9665. continue;
  9666. }
  9667. symbolRow = symbolBitmap[s2];
  9668. // To ignore Parts of Symbol bitmap which goes
  9669. // outside bitmap region
  9670. var maxWidth = Math.min(width - offsetT, symbolWidth);
  9671. switch (combinationOperator) {
  9672. case 0: // OR
  9673. for (t2 = 0; t2 < maxWidth; t2++) {
  9674. row[offsetT + t2] |= symbolRow[t2];
  9675. }
  9676. break;
  9677. case 2: // XOR
  9678. for (t2 = 0; t2 < maxWidth; t2++) {
  9679. row[offsetT + t2] ^= symbolRow[t2];
  9680. }
  9681. break;
  9682. default:
  9683. error('JBIG2 error: operator ' + combinationOperator +
  9684. ' is not supported');
  9685. }
  9686. }
  9687. currentS += symbolHeight - 1;
  9688. } else {
  9689. for (t2 = 0; t2 < symbolHeight; t2++) {
  9690. row = bitmap[offsetT + t2];
  9691. if (!row) {
  9692. continue;
  9693. }
  9694. symbolRow = symbolBitmap[t2];
  9695. switch (combinationOperator) {
  9696. case 0: // OR
  9697. for (s2 = 0; s2 < symbolWidth; s2++) {
  9698. row[offsetS + s2] |= symbolRow[s2];
  9699. }
  9700. break;
  9701. case 2: // XOR
  9702. for (s2 = 0; s2 < symbolWidth; s2++) {
  9703. row[offsetS + s2] ^= symbolRow[s2];
  9704. }
  9705. break;
  9706. default:
  9707. error('JBIG2 error: operator ' + combinationOperator +
  9708. ' is not supported');
  9709. }
  9710. }
  9711. currentS += symbolWidth - 1;
  9712. }
  9713. i++;
  9714. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  9715. if (deltaS === null) {
  9716. break; // OOB
  9717. }
  9718. currentS += deltaS + dsOffset;
  9719. } while (true);
  9720. }
  9721. return bitmap;
  9722. }
  9723. function readSegmentHeader(data, start) {
  9724. var segmentHeader = {};
  9725. segmentHeader.number = readUint32(data, start);
  9726. var flags = data[start + 4];
  9727. var segmentType = flags & 0x3F;
  9728. if (!SegmentTypes[segmentType]) {
  9729. error('JBIG2 error: invalid segment type: ' + segmentType);
  9730. }
  9731. segmentHeader.type = segmentType;
  9732. segmentHeader.typeName = SegmentTypes[segmentType];
  9733. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  9734. var pageAssociationFieldSize = !!(flags & 0x40);
  9735. var referredFlags = data[start + 5];
  9736. var referredToCount = (referredFlags >> 5) & 7;
  9737. var retainBits = [referredFlags & 31];
  9738. var position = start + 6;
  9739. if (referredFlags === 7) {
  9740. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  9741. position += 3;
  9742. var bytes = (referredToCount + 7) >> 3;
  9743. retainBits[0] = data[position++];
  9744. while (--bytes > 0) {
  9745. retainBits.push(data[position++]);
  9746. }
  9747. } else if (referredFlags === 5 || referredFlags === 6) {
  9748. error('JBIG2 error: invalid referred-to flags');
  9749. }
  9750. segmentHeader.retainBits = retainBits;
  9751. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  9752. (segmentHeader.number <= 65536 ? 2 : 4));
  9753. var referredTo = [];
  9754. var i, ii;
  9755. for (i = 0; i < referredToCount; i++) {
  9756. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  9757. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  9758. readUint32(data, position)));
  9759. referredTo.push(number);
  9760. position += referredToSegmentNumberSize;
  9761. }
  9762. segmentHeader.referredTo = referredTo;
  9763. if (!pageAssociationFieldSize) {
  9764. segmentHeader.pageAssociation = data[position++];
  9765. } else {
  9766. segmentHeader.pageAssociation = readUint32(data, position);
  9767. position += 4;
  9768. }
  9769. segmentHeader.length = readUint32(data, position);
  9770. position += 4;
  9771. if (segmentHeader.length === 0xFFFFFFFF) {
  9772. // 7.2.7 Segment data length, unknown segment length
  9773. if (segmentType === 38) { // ImmediateGenericRegion
  9774. var genericRegionInfo = readRegionSegmentInformation(data, position);
  9775. var genericRegionSegmentFlags = data[position +
  9776. RegionSegmentInformationFieldLength];
  9777. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  9778. // searching for the segment end
  9779. var searchPatternLength = 6;
  9780. var searchPattern = new Uint8Array(searchPatternLength);
  9781. if (!genericRegionMmr) {
  9782. searchPattern[0] = 0xFF;
  9783. searchPattern[1] = 0xAC;
  9784. }
  9785. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  9786. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  9787. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  9788. searchPattern[5] = genericRegionInfo.height & 0xFF;
  9789. for (i = position, ii = data.length; i < ii; i++) {
  9790. var j = 0;
  9791. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  9792. j++;
  9793. }
  9794. if (j === searchPatternLength) {
  9795. segmentHeader.length = i + searchPatternLength;
  9796. break;
  9797. }
  9798. }
  9799. if (segmentHeader.length === 0xFFFFFFFF) {
  9800. error('JBIG2 error: segment end was not found');
  9801. }
  9802. } else {
  9803. error('JBIG2 error: invalid unknown segment length');
  9804. }
  9805. }
  9806. segmentHeader.headerEnd = position;
  9807. return segmentHeader;
  9808. }
  9809. function readSegments(header, data, start, end) {
  9810. var segments = [];
  9811. var position = start;
  9812. while (position < end) {
  9813. var segmentHeader = readSegmentHeader(data, position);
  9814. position = segmentHeader.headerEnd;
  9815. var segment = {
  9816. header: segmentHeader,
  9817. data: data
  9818. };
  9819. if (!header.randomAccess) {
  9820. segment.start = position;
  9821. position += segmentHeader.length;
  9822. segment.end = position;
  9823. }
  9824. segments.push(segment);
  9825. if (segmentHeader.type === 51) {
  9826. break; // end of file is found
  9827. }
  9828. }
  9829. if (header.randomAccess) {
  9830. for (var i = 0, ii = segments.length; i < ii; i++) {
  9831. segments[i].start = position;
  9832. position += segments[i].header.length;
  9833. segments[i].end = position;
  9834. }
  9835. }
  9836. return segments;
  9837. }
  9838. // 7.4.1 Region segment information field
  9839. function readRegionSegmentInformation(data, start) {
  9840. return {
  9841. width: readUint32(data, start),
  9842. height: readUint32(data, start + 4),
  9843. x: readUint32(data, start + 8),
  9844. y: readUint32(data, start + 12),
  9845. combinationOperator: data[start + 16] & 7
  9846. };
  9847. }
  9848. var RegionSegmentInformationFieldLength = 17;
  9849. function processSegment(segment, visitor) {
  9850. var header = segment.header;
  9851. var data = segment.data, position = segment.start, end = segment.end;
  9852. var args, at, i, atLength;
  9853. switch (header.type) {
  9854. case 0: // SymbolDictionary
  9855. // 7.4.2 Symbol dictionary segment syntax
  9856. var dictionary = {};
  9857. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  9858. dictionary.huffman = !!(dictionaryFlags & 1);
  9859. dictionary.refinement = !!(dictionaryFlags & 2);
  9860. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  9861. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  9862. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  9863. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  9864. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  9865. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  9866. dictionary.template = (dictionaryFlags >> 10) & 3;
  9867. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  9868. position += 2;
  9869. if (!dictionary.huffman) {
  9870. atLength = dictionary.template === 0 ? 4 : 1;
  9871. at = [];
  9872. for (i = 0; i < atLength; i++) {
  9873. at.push({
  9874. x: readInt8(data, position),
  9875. y: readInt8(data, position + 1)
  9876. });
  9877. position += 2;
  9878. }
  9879. dictionary.at = at;
  9880. }
  9881. if (dictionary.refinement && !dictionary.refinementTemplate) {
  9882. at = [];
  9883. for (i = 0; i < 2; i++) {
  9884. at.push({
  9885. x: readInt8(data, position),
  9886. y: readInt8(data, position + 1)
  9887. });
  9888. position += 2;
  9889. }
  9890. dictionary.refinementAt = at;
  9891. }
  9892. dictionary.numberOfExportedSymbols = readUint32(data, position);
  9893. position += 4;
  9894. dictionary.numberOfNewSymbols = readUint32(data, position);
  9895. position += 4;
  9896. args = [dictionary, header.number, header.referredTo,
  9897. data, position, end];
  9898. break;
  9899. case 6: // ImmediateTextRegion
  9900. case 7: // ImmediateLosslessTextRegion
  9901. var textRegion = {};
  9902. textRegion.info = readRegionSegmentInformation(data, position);
  9903. position += RegionSegmentInformationFieldLength;
  9904. var textRegionSegmentFlags = readUint16(data, position);
  9905. position += 2;
  9906. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  9907. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  9908. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  9909. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  9910. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  9911. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  9912. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  9913. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  9914. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  9915. if (textRegion.huffman) {
  9916. var textRegionHuffmanFlags = readUint16(data, position);
  9917. position += 2;
  9918. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  9919. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  9920. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  9921. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  9922. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  9923. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  9924. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  9925. textRegion.huffmanRefinementSizeSelector =
  9926. !!(textRegionHuffmanFlags & 14);
  9927. }
  9928. if (textRegion.refinement && !textRegion.refinementTemplate) {
  9929. at = [];
  9930. for (i = 0; i < 2; i++) {
  9931. at.push({
  9932. x: readInt8(data, position),
  9933. y: readInt8(data, position + 1)
  9934. });
  9935. position += 2;
  9936. }
  9937. textRegion.refinementAt = at;
  9938. }
  9939. textRegion.numberOfSymbolInstances = readUint32(data, position);
  9940. position += 4;
  9941. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  9942. if (textRegion.huffman) {
  9943. error('JBIG2 error: huffman is not supported');
  9944. }
  9945. args = [textRegion, header.referredTo, data, position, end];
  9946. break;
  9947. case 38: // ImmediateGenericRegion
  9948. case 39: // ImmediateLosslessGenericRegion
  9949. var genericRegion = {};
  9950. genericRegion.info = readRegionSegmentInformation(data, position);
  9951. position += RegionSegmentInformationFieldLength;
  9952. var genericRegionSegmentFlags = data[position++];
  9953. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  9954. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  9955. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  9956. if (!genericRegion.mmr) {
  9957. atLength = genericRegion.template === 0 ? 4 : 1;
  9958. at = [];
  9959. for (i = 0; i < atLength; i++) {
  9960. at.push({
  9961. x: readInt8(data, position),
  9962. y: readInt8(data, position + 1)
  9963. });
  9964. position += 2;
  9965. }
  9966. genericRegion.at = at;
  9967. }
  9968. args = [genericRegion, data, position, end];
  9969. break;
  9970. case 48: // PageInformation
  9971. var pageInfo = {
  9972. width: readUint32(data, position),
  9973. height: readUint32(data, position + 4),
  9974. resolutionX: readUint32(data, position + 8),
  9975. resolutionY: readUint32(data, position + 12)
  9976. };
  9977. if (pageInfo.height === 0xFFFFFFFF) {
  9978. delete pageInfo.height;
  9979. }
  9980. var pageSegmentFlags = data[position + 16];
  9981. var pageStripingInformation = readUint16(data, position + 17);
  9982. pageInfo.lossless = !!(pageSegmentFlags & 1);
  9983. pageInfo.refinement = !!(pageSegmentFlags & 2);
  9984. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  9985. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  9986. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  9987. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  9988. args = [pageInfo];
  9989. break;
  9990. case 49: // EndOfPage
  9991. break;
  9992. case 50: // EndOfStripe
  9993. break;
  9994. case 51: // EndOfFile
  9995. break;
  9996. case 62: // 7.4.15 defines 2 extension types which
  9997. // are comments and can be ignored.
  9998. break;
  9999. default:
  10000. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10001. header.type + ') is not implemented');
  10002. }
  10003. var callbackName = 'on' + header.typeName;
  10004. if (callbackName in visitor) {
  10005. visitor[callbackName].apply(visitor, args);
  10006. }
  10007. }
  10008. function processSegments(segments, visitor) {
  10009. for (var i = 0, ii = segments.length; i < ii; i++) {
  10010. processSegment(segments[i], visitor);
  10011. }
  10012. }
  10013. function parseJbig2(data, start, end) {
  10014. var position = start;
  10015. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10016. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10017. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10018. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10019. error('JBIG2 error: invalid header');
  10020. }
  10021. var header = {};
  10022. position += 8;
  10023. var flags = data[position++];
  10024. header.randomAccess = !(flags & 1);
  10025. if (!(flags & 2)) {
  10026. header.numberOfPages = readUint32(data, position);
  10027. position += 4;
  10028. }
  10029. var segments = readSegments(header, data, position, end);
  10030. error('Not implemented');
  10031. // processSegments(segments, new SimpleSegmentVisitor());
  10032. }
  10033. function parseJbig2Chunks(chunks) {
  10034. var visitor = new SimpleSegmentVisitor();
  10035. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10036. var chunk = chunks[i];
  10037. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10038. processSegments(segments, visitor);
  10039. }
  10040. return visitor.buffer;
  10041. }
  10042. function SimpleSegmentVisitor() {}
  10043. SimpleSegmentVisitor.prototype = {
  10044. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10045. this.currentPageInfo = info;
  10046. var rowSize = (info.width + 7) >> 3;
  10047. var buffer = new Uint8Array(rowSize * info.height);
  10048. // The contents of ArrayBuffers are initialized to 0.
  10049. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10050. if (info.defaultPixelValue) {
  10051. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10052. buffer[i] = 0xFF;
  10053. }
  10054. }
  10055. this.buffer = buffer;
  10056. },
  10057. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10058. var pageInfo = this.currentPageInfo;
  10059. var width = regionInfo.width, height = regionInfo.height;
  10060. var rowSize = (pageInfo.width + 7) >> 3;
  10061. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10062. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10063. var buffer = this.buffer;
  10064. var mask0 = 128 >> (regionInfo.x & 7);
  10065. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10066. var i, j, mask, offset;
  10067. switch (combinationOperator) {
  10068. case 0: // OR
  10069. for (i = 0; i < height; i++) {
  10070. mask = mask0;
  10071. offset = offset0;
  10072. for (j = 0; j < width; j++) {
  10073. if (bitmap[i][j]) {
  10074. buffer[offset] |= mask;
  10075. }
  10076. mask >>= 1;
  10077. if (!mask) {
  10078. mask = 128;
  10079. offset++;
  10080. }
  10081. }
  10082. offset0 += rowSize;
  10083. }
  10084. break;
  10085. case 2: // XOR
  10086. for (i = 0; i < height; i++) {
  10087. mask = mask0;
  10088. offset = offset0;
  10089. for (j = 0; j < width; j++) {
  10090. if (bitmap[i][j]) {
  10091. buffer[offset] ^= mask;
  10092. }
  10093. mask >>= 1;
  10094. if (!mask) {
  10095. mask = 128;
  10096. offset++;
  10097. }
  10098. }
  10099. offset0 += rowSize;
  10100. }
  10101. break;
  10102. default:
  10103. error('JBIG2 error: operator ' + combinationOperator +
  10104. ' is not supported');
  10105. }
  10106. },
  10107. onImmediateGenericRegion:
  10108. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10109. start, end) {
  10110. var regionInfo = region.info;
  10111. var decodingContext = new DecodingContext(data, start, end);
  10112. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10113. region.template, region.prediction, null,
  10114. region.at, decodingContext);
  10115. this.drawBitmap(regionInfo, bitmap);
  10116. },
  10117. onImmediateLosslessGenericRegion:
  10118. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10119. this.onImmediateGenericRegion.apply(this, arguments);
  10120. },
  10121. onSymbolDictionary:
  10122. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10123. currentSegment,
  10124. referredSegments,
  10125. data, start, end) {
  10126. var huffmanTables;
  10127. if (dictionary.huffman) {
  10128. error('JBIG2 error: huffman is not supported');
  10129. }
  10130. // Combines exported symbols from all referred segments
  10131. var symbols = this.symbols;
  10132. if (!symbols) {
  10133. this.symbols = symbols = {};
  10134. }
  10135. var inputSymbols = [];
  10136. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10137. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10138. }
  10139. var decodingContext = new DecodingContext(data, start, end);
  10140. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10141. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10142. dictionary.numberOfExportedSymbols, huffmanTables,
  10143. dictionary.template, dictionary.at,
  10144. dictionary.refinementTemplate, dictionary.refinementAt,
  10145. decodingContext);
  10146. },
  10147. onImmediateTextRegion:
  10148. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10149. referredSegments,
  10150. data, start, end) {
  10151. var regionInfo = region.info;
  10152. var huffmanTables;
  10153. // Combines exported symbols from all referred segments
  10154. var symbols = this.symbols;
  10155. var inputSymbols = [];
  10156. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10157. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10158. }
  10159. var symbolCodeLength = log2(inputSymbols.length);
  10160. var decodingContext = new DecodingContext(data, start, end);
  10161. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10162. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10163. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10164. symbolCodeLength, region.transposed, region.dsOffset,
  10165. region.referenceCorner, region.combinationOperator, huffmanTables,
  10166. region.refinementTemplate, region.refinementAt, decodingContext);
  10167. this.drawBitmap(regionInfo, bitmap);
  10168. },
  10169. onImmediateLosslessTextRegion:
  10170. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10171. this.onImmediateTextRegion.apply(this, arguments);
  10172. }
  10173. };
  10174. function Jbig2Image() {}
  10175. Jbig2Image.prototype = {
  10176. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10177. return parseJbig2Chunks(chunks);
  10178. }
  10179. };
  10180. return Jbig2Image;
  10181. })();
  10182. exports.Jbig2Image = Jbig2Image;
  10183. }));
  10184. (function (root, factory) {
  10185. {
  10186. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  10187. root.pdfjsCoreArithmeticDecoder);
  10188. }
  10189. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10190. var info = sharedUtil.info;
  10191. var log2 = sharedUtil.log2;
  10192. var readUint16 = sharedUtil.readUint16;
  10193. var readUint32 = sharedUtil.readUint32;
  10194. var warn = sharedUtil.warn;
  10195. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10196. var JpxImage = (function JpxImageClosure() {
  10197. // Table E.1
  10198. var SubbandsGainLog2 = {
  10199. 'LL': 0,
  10200. 'LH': 1,
  10201. 'HL': 1,
  10202. 'HH': 2
  10203. };
  10204. function JpxImage() {
  10205. this.failOnCorruptedImage = false;
  10206. }
  10207. JpxImage.prototype = {
  10208. parse: function JpxImage_parse(data) {
  10209. var head = readUint16(data, 0);
  10210. // No box header, immediate start of codestream (SOC)
  10211. if (head === 0xFF4F) {
  10212. this.parseCodestream(data, 0, data.length);
  10213. return;
  10214. }
  10215. var position = 0, length = data.length;
  10216. while (position < length) {
  10217. var headerSize = 8;
  10218. var lbox = readUint32(data, position);
  10219. var tbox = readUint32(data, position + 4);
  10220. position += headerSize;
  10221. if (lbox === 1) {
  10222. // XLBox: read UInt64 according to spec.
  10223. // JavaScript's int precision of 53 bit should be sufficient here.
  10224. lbox = readUint32(data, position) * 4294967296 +
  10225. readUint32(data, position + 4);
  10226. position += 8;
  10227. headerSize += 8;
  10228. }
  10229. if (lbox === 0) {
  10230. lbox = length - position + headerSize;
  10231. }
  10232. if (lbox < headerSize) {
  10233. throw new Error('JPX Error: Invalid box field size');
  10234. }
  10235. var dataLength = lbox - headerSize;
  10236. var jumpDataLength = true;
  10237. switch (tbox) {
  10238. case 0x6A703268: // 'jp2h'
  10239. jumpDataLength = false; // parsing child boxes
  10240. break;
  10241. case 0x636F6C72: // 'colr'
  10242. // Colorspaces are not used, the CS from the PDF is used.
  10243. var method = data[position];
  10244. if (method === 1) {
  10245. // enumerated colorspace
  10246. var colorspace = readUint32(data, position + 3);
  10247. switch (colorspace) {
  10248. case 16: // this indicates a sRGB colorspace
  10249. case 17: // this indicates a grayscale colorspace
  10250. case 18: // this indicates a YUV colorspace
  10251. break;
  10252. default:
  10253. warn('Unknown colorspace ' + colorspace);
  10254. break;
  10255. }
  10256. } else if (method === 2) {
  10257. info('ICC profile not supported');
  10258. }
  10259. break;
  10260. case 0x6A703263: // 'jp2c'
  10261. this.parseCodestream(data, position, position + dataLength);
  10262. break;
  10263. case 0x6A502020: // 'jP\024\024'
  10264. if (0x0d0a870a !== readUint32(data, position)) {
  10265. warn('Invalid JP2 signature');
  10266. }
  10267. break;
  10268. // The following header types are valid but currently not used:
  10269. case 0x6A501A1A: // 'jP\032\032'
  10270. case 0x66747970: // 'ftyp'
  10271. case 0x72726571: // 'rreq'
  10272. case 0x72657320: // 'res '
  10273. case 0x69686472: // 'ihdr'
  10274. break;
  10275. default:
  10276. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  10277. (tbox >> 16) & 0xFF,
  10278. (tbox >> 8) & 0xFF,
  10279. tbox & 0xFF);
  10280. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  10281. break;
  10282. }
  10283. if (jumpDataLength) {
  10284. position += dataLength;
  10285. }
  10286. }
  10287. },
  10288. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  10289. var newByte = stream.getByte();
  10290. while (newByte >= 0) {
  10291. var oldByte = newByte;
  10292. newByte = stream.getByte();
  10293. var code = (oldByte << 8) | newByte;
  10294. // Image and tile size (SIZ)
  10295. if (code === 0xFF51) {
  10296. stream.skip(4);
  10297. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  10298. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  10299. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  10300. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  10301. stream.skip(16);
  10302. var Csiz = stream.getUint16(); // Byte 36
  10303. this.width = Xsiz - XOsiz;
  10304. this.height = Ysiz - YOsiz;
  10305. this.componentsCount = Csiz;
  10306. // Results are always returned as Uint8Arrays
  10307. this.bitsPerComponent = 8;
  10308. return;
  10309. }
  10310. }
  10311. throw new Error('JPX Error: No size marker found in JPX stream');
  10312. },
  10313. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  10314. var context = {};
  10315. try {
  10316. var doNotRecover = false;
  10317. var position = start;
  10318. while (position + 1 < end) {
  10319. var code = readUint16(data, position);
  10320. position += 2;
  10321. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  10322. switch (code) {
  10323. case 0xFF4F: // Start of codestream (SOC)
  10324. context.mainHeader = true;
  10325. break;
  10326. case 0xFFD9: // End of codestream (EOC)
  10327. break;
  10328. case 0xFF51: // Image and tile size (SIZ)
  10329. length = readUint16(data, position);
  10330. var siz = {};
  10331. siz.Xsiz = readUint32(data, position + 4);
  10332. siz.Ysiz = readUint32(data, position + 8);
  10333. siz.XOsiz = readUint32(data, position + 12);
  10334. siz.YOsiz = readUint32(data, position + 16);
  10335. siz.XTsiz = readUint32(data, position + 20);
  10336. siz.YTsiz = readUint32(data, position + 24);
  10337. siz.XTOsiz = readUint32(data, position + 28);
  10338. siz.YTOsiz = readUint32(data, position + 32);
  10339. var componentsCount = readUint16(data, position + 36);
  10340. siz.Csiz = componentsCount;
  10341. var components = [];
  10342. j = position + 38;
  10343. for (var i = 0; i < componentsCount; i++) {
  10344. var component = {
  10345. precision: (data[j] & 0x7F) + 1,
  10346. isSigned: !!(data[j] & 0x80),
  10347. XRsiz: data[j + 1],
  10348. YRsiz: data[j + 1]
  10349. };
  10350. calculateComponentDimensions(component, siz);
  10351. components.push(component);
  10352. }
  10353. context.SIZ = siz;
  10354. context.components = components;
  10355. calculateTileGrids(context, components);
  10356. context.QCC = [];
  10357. context.COC = [];
  10358. break;
  10359. case 0xFF5C: // Quantization default (QCD)
  10360. length = readUint16(data, position);
  10361. var qcd = {};
  10362. j = position + 2;
  10363. sqcd = data[j++];
  10364. switch (sqcd & 0x1F) {
  10365. case 0:
  10366. spqcdSize = 8;
  10367. scalarExpounded = true;
  10368. break;
  10369. case 1:
  10370. spqcdSize = 16;
  10371. scalarExpounded = false;
  10372. break;
  10373. case 2:
  10374. spqcdSize = 16;
  10375. scalarExpounded = true;
  10376. break;
  10377. default:
  10378. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10379. }
  10380. qcd.noQuantization = (spqcdSize === 8);
  10381. qcd.scalarExpounded = scalarExpounded;
  10382. qcd.guardBits = sqcd >> 5;
  10383. spqcds = [];
  10384. while (j < length + position) {
  10385. var spqcd = {};
  10386. if (spqcdSize === 8) {
  10387. spqcd.epsilon = data[j++] >> 3;
  10388. spqcd.mu = 0;
  10389. } else {
  10390. spqcd.epsilon = data[j] >> 3;
  10391. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10392. j += 2;
  10393. }
  10394. spqcds.push(spqcd);
  10395. }
  10396. qcd.SPqcds = spqcds;
  10397. if (context.mainHeader) {
  10398. context.QCD = qcd;
  10399. } else {
  10400. context.currentTile.QCD = qcd;
  10401. context.currentTile.QCC = [];
  10402. }
  10403. break;
  10404. case 0xFF5D: // Quantization component (QCC)
  10405. length = readUint16(data, position);
  10406. var qcc = {};
  10407. j = position + 2;
  10408. var cqcc;
  10409. if (context.SIZ.Csiz < 257) {
  10410. cqcc = data[j++];
  10411. } else {
  10412. cqcc = readUint16(data, j);
  10413. j += 2;
  10414. }
  10415. sqcd = data[j++];
  10416. switch (sqcd & 0x1F) {
  10417. case 0:
  10418. spqcdSize = 8;
  10419. scalarExpounded = true;
  10420. break;
  10421. case 1:
  10422. spqcdSize = 16;
  10423. scalarExpounded = false;
  10424. break;
  10425. case 2:
  10426. spqcdSize = 16;
  10427. scalarExpounded = true;
  10428. break;
  10429. default:
  10430. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10431. }
  10432. qcc.noQuantization = (spqcdSize === 8);
  10433. qcc.scalarExpounded = scalarExpounded;
  10434. qcc.guardBits = sqcd >> 5;
  10435. spqcds = [];
  10436. while (j < (length + position)) {
  10437. spqcd = {};
  10438. if (spqcdSize === 8) {
  10439. spqcd.epsilon = data[j++] >> 3;
  10440. spqcd.mu = 0;
  10441. } else {
  10442. spqcd.epsilon = data[j] >> 3;
  10443. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10444. j += 2;
  10445. }
  10446. spqcds.push(spqcd);
  10447. }
  10448. qcc.SPqcds = spqcds;
  10449. if (context.mainHeader) {
  10450. context.QCC[cqcc] = qcc;
  10451. } else {
  10452. context.currentTile.QCC[cqcc] = qcc;
  10453. }
  10454. break;
  10455. case 0xFF52: // Coding style default (COD)
  10456. length = readUint16(data, position);
  10457. var cod = {};
  10458. j = position + 2;
  10459. var scod = data[j++];
  10460. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  10461. cod.sopMarkerUsed = !!(scod & 2);
  10462. cod.ephMarkerUsed = !!(scod & 4);
  10463. cod.progressionOrder = data[j++];
  10464. cod.layersCount = readUint16(data, j);
  10465. j += 2;
  10466. cod.multipleComponentTransform = data[j++];
  10467. cod.decompositionLevelsCount = data[j++];
  10468. cod.xcb = (data[j++] & 0xF) + 2;
  10469. cod.ycb = (data[j++] & 0xF) + 2;
  10470. var blockStyle = data[j++];
  10471. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  10472. cod.resetContextProbabilities = !!(blockStyle & 2);
  10473. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  10474. cod.verticalyStripe = !!(blockStyle & 8);
  10475. cod.predictableTermination = !!(blockStyle & 16);
  10476. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  10477. cod.reversibleTransformation = data[j++];
  10478. if (cod.entropyCoderWithCustomPrecincts) {
  10479. var precinctsSizes = [];
  10480. while (j < length + position) {
  10481. var precinctsSize = data[j++];
  10482. precinctsSizes.push({
  10483. PPx: precinctsSize & 0xF,
  10484. PPy: precinctsSize >> 4
  10485. });
  10486. }
  10487. cod.precinctsSizes = precinctsSizes;
  10488. }
  10489. var unsupported = [];
  10490. if (cod.selectiveArithmeticCodingBypass) {
  10491. unsupported.push('selectiveArithmeticCodingBypass');
  10492. }
  10493. if (cod.resetContextProbabilities) {
  10494. unsupported.push('resetContextProbabilities');
  10495. }
  10496. if (cod.terminationOnEachCodingPass) {
  10497. unsupported.push('terminationOnEachCodingPass');
  10498. }
  10499. if (cod.verticalyStripe) {
  10500. unsupported.push('verticalyStripe');
  10501. }
  10502. if (cod.predictableTermination) {
  10503. unsupported.push('predictableTermination');
  10504. }
  10505. if (unsupported.length > 0) {
  10506. doNotRecover = true;
  10507. throw new Error('JPX Error: Unsupported COD options (' +
  10508. unsupported.join(', ') + ')');
  10509. }
  10510. if (context.mainHeader) {
  10511. context.COD = cod;
  10512. } else {
  10513. context.currentTile.COD = cod;
  10514. context.currentTile.COC = [];
  10515. }
  10516. break;
  10517. case 0xFF90: // Start of tile-part (SOT)
  10518. length = readUint16(data, position);
  10519. tile = {};
  10520. tile.index = readUint16(data, position + 2);
  10521. tile.length = readUint32(data, position + 4);
  10522. tile.dataEnd = tile.length + position - 2;
  10523. tile.partIndex = data[position + 8];
  10524. tile.partsCount = data[position + 9];
  10525. context.mainHeader = false;
  10526. if (tile.partIndex === 0) {
  10527. // reset component specific settings
  10528. tile.COD = context.COD;
  10529. tile.COC = context.COC.slice(0); // clone of the global COC
  10530. tile.QCD = context.QCD;
  10531. tile.QCC = context.QCC.slice(0); // clone of the global COC
  10532. }
  10533. context.currentTile = tile;
  10534. break;
  10535. case 0xFF93: // Start of data (SOD)
  10536. tile = context.currentTile;
  10537. if (tile.partIndex === 0) {
  10538. initializeTile(context, tile.index);
  10539. buildPackets(context);
  10540. }
  10541. // moving to the end of the data
  10542. length = tile.dataEnd - position;
  10543. parseTilePackets(context, data, position, length);
  10544. break;
  10545. case 0xFF55: // Tile-part lengths, main header (TLM)
  10546. case 0xFF57: // Packet length, main header (PLM)
  10547. case 0xFF58: // Packet length, tile-part header (PLT)
  10548. case 0xFF64: // Comment (COM)
  10549. length = readUint16(data, position);
  10550. // skipping content
  10551. break;
  10552. case 0xFF53: // Coding style component (COC)
  10553. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  10554. 'not implemented');
  10555. default:
  10556. throw new Error('JPX Error: Unknown codestream code: ' +
  10557. code.toString(16));
  10558. }
  10559. position += length;
  10560. }
  10561. } catch (e) {
  10562. if (doNotRecover || this.failOnCorruptedImage) {
  10563. throw e;
  10564. } else {
  10565. warn('Trying to recover from ' + e.message);
  10566. }
  10567. }
  10568. this.tiles = transformComponents(context);
  10569. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  10570. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  10571. this.componentsCount = context.SIZ.Csiz;
  10572. }
  10573. };
  10574. function calculateComponentDimensions(component, siz) {
  10575. // Section B.2 Component mapping
  10576. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  10577. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  10578. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  10579. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  10580. component.width = component.x1 - component.x0;
  10581. component.height = component.y1 - component.y0;
  10582. }
  10583. function calculateTileGrids(context, components) {
  10584. var siz = context.SIZ;
  10585. // Section B.3 Division into tile and tile-components
  10586. var tile, tiles = [];
  10587. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  10588. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  10589. for (var q = 0; q < numYtiles; q++) {
  10590. for (var p = 0; p < numXtiles; p++) {
  10591. tile = {};
  10592. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  10593. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  10594. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  10595. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  10596. tile.width = tile.tx1 - tile.tx0;
  10597. tile.height = tile.ty1 - tile.ty0;
  10598. tile.components = [];
  10599. tiles.push(tile);
  10600. }
  10601. }
  10602. context.tiles = tiles;
  10603. var componentsCount = siz.Csiz;
  10604. for (var i = 0, ii = componentsCount; i < ii; i++) {
  10605. var component = components[i];
  10606. for (var j = 0, jj = tiles.length; j < jj; j++) {
  10607. var tileComponent = {};
  10608. tile = tiles[j];
  10609. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  10610. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  10611. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  10612. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  10613. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  10614. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  10615. tile.components[i] = tileComponent;
  10616. }
  10617. }
  10618. }
  10619. function getBlocksDimensions(context, component, r) {
  10620. var codOrCoc = component.codingStyleParameters;
  10621. var result = {};
  10622. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  10623. result.PPx = 15;
  10624. result.PPy = 15;
  10625. } else {
  10626. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  10627. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  10628. }
  10629. // calculate codeblock size as described in section B.7
  10630. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  10631. Math.min(codOrCoc.xcb, result.PPx));
  10632. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  10633. Math.min(codOrCoc.ycb, result.PPy));
  10634. return result;
  10635. }
  10636. function buildPrecincts(context, resolution, dimensions) {
  10637. // Section B.6 Division resolution to precincts
  10638. var precinctWidth = 1 << dimensions.PPx;
  10639. var precinctHeight = 1 << dimensions.PPy;
  10640. // Jasper introduces codeblock groups for mapping each subband codeblocks
  10641. // to precincts. Precinct partition divides a resolution according to width
  10642. // and height parameters. The subband that belongs to the resolution level
  10643. // has a different size than the level, unless it is the zero resolution.
  10644. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  10645. // The precinct partitioning for a particular subband is derived from a
  10646. // partitioning of its parent LL band (i.e., the LL band at the next higher
  10647. // resolution level)... The LL band associated with each resolution level is
  10648. // divided into precincts... Each of the resulting precinct regions is then
  10649. // mapped into its child subbands (if any) at the next lower resolution
  10650. // level. This is accomplished by using the coordinate transformation
  10651. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  10652. // coordinates of a point in the LL band and child subband, respectively.
  10653. var isZeroRes = resolution.resLevel === 0;
  10654. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  10655. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  10656. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  10657. Math.ceil(resolution.trx1 / precinctWidth) -
  10658. Math.floor(resolution.trx0 / precinctWidth) : 0);
  10659. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  10660. Math.ceil(resolution.try1 / precinctHeight) -
  10661. Math.floor(resolution.try0 / precinctHeight) : 0);
  10662. var numprecincts = numprecinctswide * numprecinctshigh;
  10663. resolution.precinctParameters = {
  10664. precinctWidth: precinctWidth,
  10665. precinctHeight: precinctHeight,
  10666. numprecinctswide: numprecinctswide,
  10667. numprecinctshigh: numprecinctshigh,
  10668. numprecincts: numprecincts,
  10669. precinctWidthInSubband: precinctWidthInSubband,
  10670. precinctHeightInSubband: precinctHeightInSubband
  10671. };
  10672. }
  10673. function buildCodeblocks(context, subband, dimensions) {
  10674. // Section B.7 Division sub-band into code-blocks
  10675. var xcb_ = dimensions.xcb_;
  10676. var ycb_ = dimensions.ycb_;
  10677. var codeblockWidth = 1 << xcb_;
  10678. var codeblockHeight = 1 << ycb_;
  10679. var cbx0 = subband.tbx0 >> xcb_;
  10680. var cby0 = subband.tby0 >> ycb_;
  10681. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  10682. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  10683. var precinctParameters = subband.resolution.precinctParameters;
  10684. var codeblocks = [];
  10685. var precincts = [];
  10686. var i, j, codeblock, precinctNumber;
  10687. for (j = cby0; j < cby1; j++) {
  10688. for (i = cbx0; i < cbx1; i++) {
  10689. codeblock = {
  10690. cbx: i,
  10691. cby: j,
  10692. tbx0: codeblockWidth * i,
  10693. tby0: codeblockHeight * j,
  10694. tbx1: codeblockWidth * (i + 1),
  10695. tby1: codeblockHeight * (j + 1)
  10696. };
  10697. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  10698. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  10699. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  10700. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  10701. // Calculate precinct number for this codeblock, codeblock position
  10702. // should be relative to its subband, use actual dimension and position
  10703. // See comment about codeblock group width and height
  10704. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  10705. precinctParameters.precinctWidthInSubband);
  10706. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  10707. precinctParameters.precinctHeightInSubband);
  10708. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  10709. codeblock.precinctNumber = precinctNumber;
  10710. codeblock.subbandType = subband.type;
  10711. codeblock.Lblock = 3;
  10712. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  10713. codeblock.tby1_ <= codeblock.tby0_) {
  10714. continue;
  10715. }
  10716. codeblocks.push(codeblock);
  10717. // building precinct for the sub-band
  10718. var precinct = precincts[precinctNumber];
  10719. if (precinct !== undefined) {
  10720. if (i < precinct.cbxMin) {
  10721. precinct.cbxMin = i;
  10722. } else if (i > precinct.cbxMax) {
  10723. precinct.cbxMax = i;
  10724. }
  10725. if (j < precinct.cbyMin) {
  10726. precinct.cbxMin = j;
  10727. } else if (j > precinct.cbyMax) {
  10728. precinct.cbyMax = j;
  10729. }
  10730. } else {
  10731. precincts[precinctNumber] = precinct = {
  10732. cbxMin: i,
  10733. cbyMin: j,
  10734. cbxMax: i,
  10735. cbyMax: j
  10736. };
  10737. }
  10738. codeblock.precinct = precinct;
  10739. }
  10740. }
  10741. subband.codeblockParameters = {
  10742. codeblockWidth: xcb_,
  10743. codeblockHeight: ycb_,
  10744. numcodeblockwide: cbx1 - cbx0 + 1,
  10745. numcodeblockhigh: cby1 - cby0 + 1
  10746. };
  10747. subband.codeblocks = codeblocks;
  10748. subband.precincts = precincts;
  10749. }
  10750. function createPacket(resolution, precinctNumber, layerNumber) {
  10751. var precinctCodeblocks = [];
  10752. // Section B.10.8 Order of info in packet
  10753. var subbands = resolution.subbands;
  10754. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  10755. for (var i = 0, ii = subbands.length; i < ii; i++) {
  10756. var subband = subbands[i];
  10757. var codeblocks = subband.codeblocks;
  10758. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  10759. var codeblock = codeblocks[j];
  10760. if (codeblock.precinctNumber !== precinctNumber) {
  10761. continue;
  10762. }
  10763. precinctCodeblocks.push(codeblock);
  10764. }
  10765. }
  10766. return {
  10767. layerNumber: layerNumber,
  10768. codeblocks: precinctCodeblocks
  10769. };
  10770. }
  10771. function LayerResolutionComponentPositionIterator(context) {
  10772. var siz = context.SIZ;
  10773. var tileIndex = context.currentTile.index;
  10774. var tile = context.tiles[tileIndex];
  10775. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10776. var componentsCount = siz.Csiz;
  10777. var maxDecompositionLevelsCount = 0;
  10778. for (var q = 0; q < componentsCount; q++) {
  10779. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10780. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10781. }
  10782. var l = 0, r = 0, i = 0, k = 0;
  10783. this.nextPacket = function JpxImage_nextPacket() {
  10784. // Section B.12.1.1 Layer-resolution-component-position
  10785. for (; l < layersCount; l++) {
  10786. for (; r <= maxDecompositionLevelsCount; r++) {
  10787. for (; i < componentsCount; i++) {
  10788. var component = tile.components[i];
  10789. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10790. continue;
  10791. }
  10792. var resolution = component.resolutions[r];
  10793. var numprecincts = resolution.precinctParameters.numprecincts;
  10794. for (; k < numprecincts;) {
  10795. var packet = createPacket(resolution, k, l);
  10796. k++;
  10797. return packet;
  10798. }
  10799. k = 0;
  10800. }
  10801. i = 0;
  10802. }
  10803. r = 0;
  10804. }
  10805. throw new Error('JPX Error: Out of packets');
  10806. };
  10807. }
  10808. function ResolutionLayerComponentPositionIterator(context) {
  10809. var siz = context.SIZ;
  10810. var tileIndex = context.currentTile.index;
  10811. var tile = context.tiles[tileIndex];
  10812. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10813. var componentsCount = siz.Csiz;
  10814. var maxDecompositionLevelsCount = 0;
  10815. for (var q = 0; q < componentsCount; q++) {
  10816. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10817. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10818. }
  10819. var r = 0, l = 0, i = 0, k = 0;
  10820. this.nextPacket = function JpxImage_nextPacket() {
  10821. // Section B.12.1.2 Resolution-layer-component-position
  10822. for (; r <= maxDecompositionLevelsCount; r++) {
  10823. for (; l < layersCount; l++) {
  10824. for (; i < componentsCount; i++) {
  10825. var component = tile.components[i];
  10826. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10827. continue;
  10828. }
  10829. var resolution = component.resolutions[r];
  10830. var numprecincts = resolution.precinctParameters.numprecincts;
  10831. for (; k < numprecincts;) {
  10832. var packet = createPacket(resolution, k, l);
  10833. k++;
  10834. return packet;
  10835. }
  10836. k = 0;
  10837. }
  10838. i = 0;
  10839. }
  10840. l = 0;
  10841. }
  10842. throw new Error('JPX Error: Out of packets');
  10843. };
  10844. }
  10845. function ResolutionPositionComponentLayerIterator(context) {
  10846. var siz = context.SIZ;
  10847. var tileIndex = context.currentTile.index;
  10848. var tile = context.tiles[tileIndex];
  10849. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10850. var componentsCount = siz.Csiz;
  10851. var l, r, c, p;
  10852. var maxDecompositionLevelsCount = 0;
  10853. for (c = 0; c < componentsCount; c++) {
  10854. var component = tile.components[c];
  10855. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10856. component.codingStyleParameters.decompositionLevelsCount);
  10857. }
  10858. var maxNumPrecinctsInLevel = new Int32Array(
  10859. maxDecompositionLevelsCount + 1);
  10860. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  10861. var maxNumPrecincts = 0;
  10862. for (c = 0; c < componentsCount; ++c) {
  10863. var resolutions = tile.components[c].resolutions;
  10864. if (r < resolutions.length) {
  10865. maxNumPrecincts = Math.max(maxNumPrecincts,
  10866. resolutions[r].precinctParameters.numprecincts);
  10867. }
  10868. }
  10869. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  10870. }
  10871. l = 0;
  10872. r = 0;
  10873. c = 0;
  10874. p = 0;
  10875. this.nextPacket = function JpxImage_nextPacket() {
  10876. // Section B.12.1.3 Resolution-position-component-layer
  10877. for (; r <= maxDecompositionLevelsCount; r++) {
  10878. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  10879. for (; c < componentsCount; c++) {
  10880. var component = tile.components[c];
  10881. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10882. continue;
  10883. }
  10884. var resolution = component.resolutions[r];
  10885. var numprecincts = resolution.precinctParameters.numprecincts;
  10886. if (p >= numprecincts) {
  10887. continue;
  10888. }
  10889. for (; l < layersCount;) {
  10890. var packet = createPacket(resolution, p, l);
  10891. l++;
  10892. return packet;
  10893. }
  10894. l = 0;
  10895. }
  10896. c = 0;
  10897. }
  10898. p = 0;
  10899. }
  10900. throw new Error('JPX Error: Out of packets');
  10901. };
  10902. }
  10903. function PositionComponentResolutionLayerIterator(context) {
  10904. var siz = context.SIZ;
  10905. var tileIndex = context.currentTile.index;
  10906. var tile = context.tiles[tileIndex];
  10907. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10908. var componentsCount = siz.Csiz;
  10909. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10910. var precinctsIterationSizes = precinctsSizes;
  10911. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10912. this.nextPacket = function JpxImage_nextPacket() {
  10913. // Section B.12.1.4 Position-component-resolution-layer
  10914. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10915. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10916. for (; c < componentsCount; c++) {
  10917. var component = tile.components[c];
  10918. var decompositionLevelsCount =
  10919. component.codingStyleParameters.decompositionLevelsCount;
  10920. for (; r <= decompositionLevelsCount; r++) {
  10921. var resolution = component.resolutions[r];
  10922. var sizeInImageScale =
  10923. precinctsSizes.components[c].resolutions[r];
  10924. var k = getPrecinctIndexIfExist(
  10925. px,
  10926. py,
  10927. sizeInImageScale,
  10928. precinctsIterationSizes,
  10929. resolution);
  10930. if (k === null) {
  10931. continue;
  10932. }
  10933. for (; l < layersCount;) {
  10934. var packet = createPacket(resolution, k, l);
  10935. l++;
  10936. return packet;
  10937. }
  10938. l = 0;
  10939. }
  10940. r = 0;
  10941. }
  10942. c = 0;
  10943. }
  10944. px = 0;
  10945. }
  10946. throw new Error('JPX Error: Out of packets');
  10947. };
  10948. }
  10949. function ComponentPositionResolutionLayerIterator(context) {
  10950. var siz = context.SIZ;
  10951. var tileIndex = context.currentTile.index;
  10952. var tile = context.tiles[tileIndex];
  10953. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10954. var componentsCount = siz.Csiz;
  10955. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10956. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10957. this.nextPacket = function JpxImage_nextPacket() {
  10958. // Section B.12.1.5 Component-position-resolution-layer
  10959. for (; c < componentsCount; ++c) {
  10960. var component = tile.components[c];
  10961. var precinctsIterationSizes = precinctsSizes.components[c];
  10962. var decompositionLevelsCount =
  10963. component.codingStyleParameters.decompositionLevelsCount;
  10964. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10965. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10966. for (; r <= decompositionLevelsCount; r++) {
  10967. var resolution = component.resolutions[r];
  10968. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  10969. var k = getPrecinctIndexIfExist(
  10970. px,
  10971. py,
  10972. sizeInImageScale,
  10973. precinctsIterationSizes,
  10974. resolution);
  10975. if (k === null) {
  10976. continue;
  10977. }
  10978. for (; l < layersCount;) {
  10979. var packet = createPacket(resolution, k, l);
  10980. l++;
  10981. return packet;
  10982. }
  10983. l = 0;
  10984. }
  10985. r = 0;
  10986. }
  10987. px = 0;
  10988. }
  10989. py = 0;
  10990. }
  10991. throw new Error('JPX Error: Out of packets');
  10992. };
  10993. }
  10994. function getPrecinctIndexIfExist(
  10995. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  10996. var posX = pxIndex * precinctIterationSizes.minWidth;
  10997. var posY = pyIndex * precinctIterationSizes.minHeight;
  10998. if (posX % sizeInImageScale.width !== 0 ||
  10999. posY % sizeInImageScale.height !== 0) {
  11000. return null;
  11001. }
  11002. var startPrecinctRowIndex =
  11003. (posY / sizeInImageScale.width) *
  11004. resolution.precinctParameters.numprecinctswide;
  11005. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  11006. }
  11007. function getPrecinctSizesInImageScale(tile) {
  11008. var componentsCount = tile.components.length;
  11009. var minWidth = Number.MAX_VALUE;
  11010. var minHeight = Number.MAX_VALUE;
  11011. var maxNumWide = 0;
  11012. var maxNumHigh = 0;
  11013. var sizePerComponent = new Array(componentsCount);
  11014. for (var c = 0; c < componentsCount; c++) {
  11015. var component = tile.components[c];
  11016. var decompositionLevelsCount =
  11017. component.codingStyleParameters.decompositionLevelsCount;
  11018. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  11019. var minWidthCurrentComponent = Number.MAX_VALUE;
  11020. var minHeightCurrentComponent = Number.MAX_VALUE;
  11021. var maxNumWideCurrentComponent = 0;
  11022. var maxNumHighCurrentComponent = 0;
  11023. var scale = 1;
  11024. for (var r = decompositionLevelsCount; r >= 0; --r) {
  11025. var resolution = component.resolutions[r];
  11026. var widthCurrentResolution =
  11027. scale * resolution.precinctParameters.precinctWidth;
  11028. var heightCurrentResolution =
  11029. scale * resolution.precinctParameters.precinctHeight;
  11030. minWidthCurrentComponent = Math.min(
  11031. minWidthCurrentComponent,
  11032. widthCurrentResolution);
  11033. minHeightCurrentComponent = Math.min(
  11034. minHeightCurrentComponent,
  11035. heightCurrentResolution);
  11036. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  11037. resolution.precinctParameters.numprecinctswide);
  11038. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  11039. resolution.precinctParameters.numprecinctshigh);
  11040. sizePerResolution[r] = {
  11041. width: widthCurrentResolution,
  11042. height: heightCurrentResolution
  11043. };
  11044. scale <<= 1;
  11045. }
  11046. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  11047. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  11048. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  11049. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  11050. sizePerComponent[c] = {
  11051. resolutions: sizePerResolution,
  11052. minWidth: minWidthCurrentComponent,
  11053. minHeight: minHeightCurrentComponent,
  11054. maxNumWide: maxNumWideCurrentComponent,
  11055. maxNumHigh: maxNumHighCurrentComponent
  11056. };
  11057. }
  11058. return {
  11059. components: sizePerComponent,
  11060. minWidth: minWidth,
  11061. minHeight: minHeight,
  11062. maxNumWide: maxNumWide,
  11063. maxNumHigh: maxNumHigh
  11064. };
  11065. }
  11066. function buildPackets(context) {
  11067. var siz = context.SIZ;
  11068. var tileIndex = context.currentTile.index;
  11069. var tile = context.tiles[tileIndex];
  11070. var componentsCount = siz.Csiz;
  11071. // Creating resolutions and sub-bands for each component
  11072. for (var c = 0; c < componentsCount; c++) {
  11073. var component = tile.components[c];
  11074. var decompositionLevelsCount =
  11075. component.codingStyleParameters.decompositionLevelsCount;
  11076. // Section B.5 Resolution levels and sub-bands
  11077. var resolutions = [];
  11078. var subbands = [];
  11079. for (var r = 0; r <= decompositionLevelsCount; r++) {
  11080. var blocksDimensions = getBlocksDimensions(context, component, r);
  11081. var resolution = {};
  11082. var scale = 1 << (decompositionLevelsCount - r);
  11083. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  11084. resolution.try0 = Math.ceil(component.tcy0 / scale);
  11085. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  11086. resolution.try1 = Math.ceil(component.tcy1 / scale);
  11087. resolution.resLevel = r;
  11088. buildPrecincts(context, resolution, blocksDimensions);
  11089. resolutions.push(resolution);
  11090. var subband;
  11091. if (r === 0) {
  11092. // one sub-band (LL) with last decomposition
  11093. subband = {};
  11094. subband.type = 'LL';
  11095. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  11096. subband.tby0 = Math.ceil(component.tcy0 / scale);
  11097. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  11098. subband.tby1 = Math.ceil(component.tcy1 / scale);
  11099. subband.resolution = resolution;
  11100. buildCodeblocks(context, subband, blocksDimensions);
  11101. subbands.push(subband);
  11102. resolution.subbands = [subband];
  11103. } else {
  11104. var bscale = 1 << (decompositionLevelsCount - r + 1);
  11105. var resolutionSubbands = [];
  11106. // three sub-bands (HL, LH and HH) with rest of decompositions
  11107. subband = {};
  11108. subband.type = 'HL';
  11109. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11110. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  11111. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11112. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  11113. subband.resolution = resolution;
  11114. buildCodeblocks(context, subband, blocksDimensions);
  11115. subbands.push(subband);
  11116. resolutionSubbands.push(subband);
  11117. subband = {};
  11118. subband.type = 'LH';
  11119. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  11120. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11121. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  11122. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11123. subband.resolution = resolution;
  11124. buildCodeblocks(context, subband, blocksDimensions);
  11125. subbands.push(subband);
  11126. resolutionSubbands.push(subband);
  11127. subband = {};
  11128. subband.type = 'HH';
  11129. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11130. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11131. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11132. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11133. subband.resolution = resolution;
  11134. buildCodeblocks(context, subband, blocksDimensions);
  11135. subbands.push(subband);
  11136. resolutionSubbands.push(subband);
  11137. resolution.subbands = resolutionSubbands;
  11138. }
  11139. }
  11140. component.resolutions = resolutions;
  11141. component.subbands = subbands;
  11142. }
  11143. // Generate the packets sequence
  11144. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  11145. switch (progressionOrder) {
  11146. case 0:
  11147. tile.packetsIterator =
  11148. new LayerResolutionComponentPositionIterator(context);
  11149. break;
  11150. case 1:
  11151. tile.packetsIterator =
  11152. new ResolutionLayerComponentPositionIterator(context);
  11153. break;
  11154. case 2:
  11155. tile.packetsIterator =
  11156. new ResolutionPositionComponentLayerIterator(context);
  11157. break;
  11158. case 3:
  11159. tile.packetsIterator =
  11160. new PositionComponentResolutionLayerIterator(context);
  11161. break;
  11162. case 4:
  11163. tile.packetsIterator =
  11164. new ComponentPositionResolutionLayerIterator(context);
  11165. break;
  11166. default:
  11167. throw new Error('JPX Error: Unsupported progression order ' +
  11168. progressionOrder);
  11169. }
  11170. }
  11171. function parseTilePackets(context, data, offset, dataLength) {
  11172. var position = 0;
  11173. var buffer, bufferSize = 0, skipNextBit = false;
  11174. function readBits(count) {
  11175. while (bufferSize < count) {
  11176. var b = data[offset + position];
  11177. position++;
  11178. if (skipNextBit) {
  11179. buffer = (buffer << 7) | b;
  11180. bufferSize += 7;
  11181. skipNextBit = false;
  11182. } else {
  11183. buffer = (buffer << 8) | b;
  11184. bufferSize += 8;
  11185. }
  11186. if (b === 0xFF) {
  11187. skipNextBit = true;
  11188. }
  11189. }
  11190. bufferSize -= count;
  11191. return (buffer >>> bufferSize) & ((1 << count) - 1);
  11192. }
  11193. function skipMarkerIfEqual(value) {
  11194. if (data[offset + position - 1] === 0xFF &&
  11195. data[offset + position] === value) {
  11196. skipBytes(1);
  11197. return true;
  11198. } else if (data[offset + position] === 0xFF &&
  11199. data[offset + position + 1] === value) {
  11200. skipBytes(2);
  11201. return true;
  11202. }
  11203. return false;
  11204. }
  11205. function skipBytes(count) {
  11206. position += count;
  11207. }
  11208. function alignToByte() {
  11209. bufferSize = 0;
  11210. if (skipNextBit) {
  11211. position++;
  11212. skipNextBit = false;
  11213. }
  11214. }
  11215. function readCodingpasses() {
  11216. if (readBits(1) === 0) {
  11217. return 1;
  11218. }
  11219. if (readBits(1) === 0) {
  11220. return 2;
  11221. }
  11222. var value = readBits(2);
  11223. if (value < 3) {
  11224. return value + 3;
  11225. }
  11226. value = readBits(5);
  11227. if (value < 31) {
  11228. return value + 6;
  11229. }
  11230. value = readBits(7);
  11231. return value + 37;
  11232. }
  11233. var tileIndex = context.currentTile.index;
  11234. var tile = context.tiles[tileIndex];
  11235. var sopMarkerUsed = context.COD.sopMarkerUsed;
  11236. var ephMarkerUsed = context.COD.ephMarkerUsed;
  11237. var packetsIterator = tile.packetsIterator;
  11238. while (position < dataLength) {
  11239. alignToByte();
  11240. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  11241. // Skip also marker segment length and packet sequence ID
  11242. skipBytes(4);
  11243. }
  11244. var packet = packetsIterator.nextPacket();
  11245. if (!readBits(1)) {
  11246. continue;
  11247. }
  11248. var layerNumber = packet.layerNumber;
  11249. var queue = [], codeblock;
  11250. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  11251. codeblock = packet.codeblocks[i];
  11252. var precinct = codeblock.precinct;
  11253. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  11254. var codeblockRow = codeblock.cby - precinct.cbyMin;
  11255. var codeblockIncluded = false;
  11256. var firstTimeInclusion = false;
  11257. var valueReady;
  11258. if (codeblock['included'] !== undefined) {
  11259. codeblockIncluded = !!readBits(1);
  11260. } else {
  11261. // reading inclusion tree
  11262. precinct = codeblock.precinct;
  11263. var inclusionTree, zeroBitPlanesTree;
  11264. if (precinct['inclusionTree'] !== undefined) {
  11265. inclusionTree = precinct.inclusionTree;
  11266. } else {
  11267. // building inclusion and zero bit-planes trees
  11268. var width = precinct.cbxMax - precinct.cbxMin + 1;
  11269. var height = precinct.cbyMax - precinct.cbyMin + 1;
  11270. inclusionTree = new InclusionTree(width, height, layerNumber);
  11271. zeroBitPlanesTree = new TagTree(width, height);
  11272. precinct.inclusionTree = inclusionTree;
  11273. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  11274. }
  11275. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  11276. while (true) {
  11277. if (readBits(1)) {
  11278. valueReady = !inclusionTree.nextLevel();
  11279. if (valueReady) {
  11280. codeblock.included = true;
  11281. codeblockIncluded = firstTimeInclusion = true;
  11282. break;
  11283. }
  11284. } else {
  11285. inclusionTree.incrementValue(layerNumber);
  11286. break;
  11287. }
  11288. }
  11289. }
  11290. }
  11291. if (!codeblockIncluded) {
  11292. continue;
  11293. }
  11294. if (firstTimeInclusion) {
  11295. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  11296. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  11297. while (true) {
  11298. if (readBits(1)) {
  11299. valueReady = !zeroBitPlanesTree.nextLevel();
  11300. if (valueReady) {
  11301. break;
  11302. }
  11303. } else {
  11304. zeroBitPlanesTree.incrementValue();
  11305. }
  11306. }
  11307. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  11308. }
  11309. var codingpasses = readCodingpasses();
  11310. while (readBits(1)) {
  11311. codeblock.Lblock++;
  11312. }
  11313. var codingpassesLog2 = log2(codingpasses);
  11314. // rounding down log2
  11315. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  11316. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  11317. var codedDataLength = readBits(bits);
  11318. queue.push({
  11319. codeblock: codeblock,
  11320. codingpasses: codingpasses,
  11321. dataLength: codedDataLength
  11322. });
  11323. }
  11324. alignToByte();
  11325. if (ephMarkerUsed) {
  11326. skipMarkerIfEqual(0x92);
  11327. }
  11328. while (queue.length > 0) {
  11329. var packetItem = queue.shift();
  11330. codeblock = packetItem.codeblock;
  11331. if (codeblock['data'] === undefined) {
  11332. codeblock.data = [];
  11333. }
  11334. codeblock.data.push({
  11335. data: data,
  11336. start: offset + position,
  11337. end: offset + position + packetItem.dataLength,
  11338. codingpasses: packetItem.codingpasses
  11339. });
  11340. position += packetItem.dataLength;
  11341. }
  11342. }
  11343. return position;
  11344. }
  11345. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  11346. delta, mb, reversible, segmentationSymbolUsed) {
  11347. var x0 = subband.tbx0;
  11348. var y0 = subband.tby0;
  11349. var width = subband.tbx1 - subband.tbx0;
  11350. var codeblocks = subband.codeblocks;
  11351. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  11352. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  11353. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  11354. var codeblock = codeblocks[i];
  11355. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  11356. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  11357. if (blockWidth === 0 || blockHeight === 0) {
  11358. continue;
  11359. }
  11360. if (codeblock['data'] === undefined) {
  11361. continue;
  11362. }
  11363. var bitModel, currentCodingpassType;
  11364. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  11365. codeblock.zeroBitPlanes, mb);
  11366. currentCodingpassType = 2; // first bit plane starts from cleanup
  11367. // collect data
  11368. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  11369. var j, jj, dataItem;
  11370. for (j = 0, jj = data.length; j < jj; j++) {
  11371. dataItem = data[j];
  11372. totalLength += dataItem.end - dataItem.start;
  11373. codingpasses += dataItem.codingpasses;
  11374. }
  11375. var encodedData = new Uint8Array(totalLength);
  11376. var position = 0;
  11377. for (j = 0, jj = data.length; j < jj; j++) {
  11378. dataItem = data[j];
  11379. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  11380. encodedData.set(chunk, position);
  11381. position += chunk.length;
  11382. }
  11383. // decoding the item
  11384. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  11385. bitModel.setDecoder(decoder);
  11386. for (j = 0; j < codingpasses; j++) {
  11387. switch (currentCodingpassType) {
  11388. case 0:
  11389. bitModel.runSignificancePropogationPass();
  11390. break;
  11391. case 1:
  11392. bitModel.runMagnitudeRefinementPass();
  11393. break;
  11394. case 2:
  11395. bitModel.runCleanupPass();
  11396. if (segmentationSymbolUsed) {
  11397. bitModel.checkSegmentationSymbol();
  11398. }
  11399. break;
  11400. }
  11401. currentCodingpassType = (currentCodingpassType + 1) % 3;
  11402. }
  11403. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  11404. var sign = bitModel.coefficentsSign;
  11405. var magnitude = bitModel.coefficentsMagnitude;
  11406. var bitsDecoded = bitModel.bitsDecoded;
  11407. var magnitudeCorrection = reversible ? 0 : 0.5;
  11408. var k, n, nb;
  11409. position = 0;
  11410. // Do the interleaving of Section F.3.3 here, so we do not need
  11411. // to copy later. LL level is not interleaved, just copied.
  11412. var interleave = (subband.type !== 'LL');
  11413. for (j = 0; j < blockHeight; j++) {
  11414. var row = (offset / width) | 0; // row in the non-interleaved subband
  11415. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  11416. for (k = 0; k < blockWidth; k++) {
  11417. n = magnitude[position];
  11418. if (n !== 0) {
  11419. n = (n + magnitudeCorrection) * delta;
  11420. if (sign[position] !== 0) {
  11421. n = -n;
  11422. }
  11423. nb = bitsDecoded[position];
  11424. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  11425. if (reversible && (nb >= mb)) {
  11426. coefficients[pos] = n;
  11427. } else {
  11428. coefficients[pos] = n * (1 << (mb - nb));
  11429. }
  11430. }
  11431. offset++;
  11432. position++;
  11433. }
  11434. offset += width - blockWidth;
  11435. }
  11436. }
  11437. }
  11438. function transformTile(context, tile, c) {
  11439. var component = tile.components[c];
  11440. var codingStyleParameters = component.codingStyleParameters;
  11441. var quantizationParameters = component.quantizationParameters;
  11442. var decompositionLevelsCount =
  11443. codingStyleParameters.decompositionLevelsCount;
  11444. var spqcds = quantizationParameters.SPqcds;
  11445. var scalarExpounded = quantizationParameters.scalarExpounded;
  11446. var guardBits = quantizationParameters.guardBits;
  11447. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  11448. var precision = context.components[c].precision;
  11449. var reversible = codingStyleParameters.reversibleTransformation;
  11450. var transform = (reversible ? new ReversibleTransform() :
  11451. new IrreversibleTransform());
  11452. var subbandCoefficients = [];
  11453. var b = 0;
  11454. for (var i = 0; i <= decompositionLevelsCount; i++) {
  11455. var resolution = component.resolutions[i];
  11456. var width = resolution.trx1 - resolution.trx0;
  11457. var height = resolution.try1 - resolution.try0;
  11458. // Allocate space for the whole sublevel.
  11459. var coefficients = new Float32Array(width * height);
  11460. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  11461. var mu, epsilon;
  11462. if (!scalarExpounded) {
  11463. // formula E-5
  11464. mu = spqcds[0].mu;
  11465. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  11466. } else {
  11467. mu = spqcds[b].mu;
  11468. epsilon = spqcds[b].epsilon;
  11469. b++;
  11470. }
  11471. var subband = resolution.subbands[j];
  11472. var gainLog2 = SubbandsGainLog2[subband.type];
  11473. // calulate quantization coefficient (Section E.1.1.1)
  11474. var delta = (reversible ? 1 :
  11475. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  11476. var mb = (guardBits + epsilon - 1);
  11477. // In the first resolution level, copyCoefficients will fill the
  11478. // whole array with coefficients. In the succeding passes,
  11479. // copyCoefficients will consecutively fill in the values that belong
  11480. // to the interleaved positions of the HL, LH, and HH coefficients.
  11481. // The LL coefficients will then be interleaved in Transform.iterate().
  11482. copyCoefficients(coefficients, width, height, subband, delta, mb,
  11483. reversible, segmentationSymbolUsed);
  11484. }
  11485. subbandCoefficients.push({
  11486. width: width,
  11487. height: height,
  11488. items: coefficients
  11489. });
  11490. }
  11491. var result = transform.calculate(subbandCoefficients,
  11492. component.tcx0, component.tcy0);
  11493. return {
  11494. left: component.tcx0,
  11495. top: component.tcy0,
  11496. width: result.width,
  11497. height: result.height,
  11498. items: result.items
  11499. };
  11500. }
  11501. function transformComponents(context) {
  11502. var siz = context.SIZ;
  11503. var components = context.components;
  11504. var componentsCount = siz.Csiz;
  11505. var resultImages = [];
  11506. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  11507. var tile = context.tiles[i];
  11508. var transformedTiles = [];
  11509. var c;
  11510. for (c = 0; c < componentsCount; c++) {
  11511. transformedTiles[c] = transformTile(context, tile, c);
  11512. }
  11513. var tile0 = transformedTiles[0];
  11514. var out = new Uint8Array(tile0.items.length * componentsCount);
  11515. var result = {
  11516. left: tile0.left,
  11517. top: tile0.top,
  11518. width: tile0.width,
  11519. height: tile0.height,
  11520. items: out
  11521. };
  11522. // Section G.2.2 Inverse multi component transform
  11523. var shift, offset, max, min, maxK;
  11524. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  11525. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  11526. var fourComponents = componentsCount === 4;
  11527. var y0items = transformedTiles[0].items;
  11528. var y1items = transformedTiles[1].items;
  11529. var y2items = transformedTiles[2].items;
  11530. var y3items = fourComponents ? transformedTiles[3].items : null;
  11531. // HACK: The multiple component transform formulas below assume that
  11532. // all components have the same precision. With this in mind, we
  11533. // compute shift and offset only once.
  11534. shift = components[0].precision - 8;
  11535. offset = (128 << shift) + 0.5;
  11536. max = 255 * (1 << shift);
  11537. maxK = max * 0.5;
  11538. min = -maxK;
  11539. var component0 = tile.components[0];
  11540. var alpha01 = componentsCount - 3;
  11541. jj = y0items.length;
  11542. if (!component0.codingStyleParameters.reversibleTransformation) {
  11543. // inverse irreversible multiple component transform
  11544. for (j = 0; j < jj; j++, pos += alpha01) {
  11545. y0 = y0items[j] + offset;
  11546. y1 = y1items[j];
  11547. y2 = y2items[j];
  11548. r = y0 + 1.402 * y2;
  11549. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  11550. b = y0 + 1.772 * y1;
  11551. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11552. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11553. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11554. }
  11555. } else {
  11556. // inverse reversible multiple component transform
  11557. for (j = 0; j < jj; j++, pos += alpha01) {
  11558. y0 = y0items[j] + offset;
  11559. y1 = y1items[j];
  11560. y2 = y2items[j];
  11561. g = y0 - ((y2 + y1) >> 2);
  11562. r = g + y2;
  11563. b = g + y1;
  11564. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11565. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11566. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11567. }
  11568. }
  11569. if (fourComponents) {
  11570. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  11571. k = y3items[j];
  11572. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  11573. }
  11574. }
  11575. } else { // no multi-component transform
  11576. for (c = 0; c < componentsCount; c++) {
  11577. var items = transformedTiles[c].items;
  11578. shift = components[c].precision - 8;
  11579. offset = (128 << shift) + 0.5;
  11580. max = (127.5 * (1 << shift));
  11581. min = -max;
  11582. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  11583. val = items[j];
  11584. out[pos] = val <= min ? 0 :
  11585. val >= max ? 255 : (val + offset) >> shift;
  11586. pos += componentsCount;
  11587. }
  11588. }
  11589. }
  11590. resultImages.push(result);
  11591. }
  11592. return resultImages;
  11593. }
  11594. function initializeTile(context, tileIndex) {
  11595. var siz = context.SIZ;
  11596. var componentsCount = siz.Csiz;
  11597. var tile = context.tiles[tileIndex];
  11598. for (var c = 0; c < componentsCount; c++) {
  11599. var component = tile.components[c];
  11600. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  11601. context.currentTile.QCC[c] : context.currentTile.QCD);
  11602. component.quantizationParameters = qcdOrQcc;
  11603. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  11604. context.currentTile.COC[c] : context.currentTile.COD);
  11605. component.codingStyleParameters = codOrCoc;
  11606. }
  11607. tile.codingStyleDefaultParameters = context.currentTile.COD;
  11608. }
  11609. // Section B.10.2 Tag trees
  11610. var TagTree = (function TagTreeClosure() {
  11611. function TagTree(width, height) {
  11612. var levelsLength = log2(Math.max(width, height)) + 1;
  11613. this.levels = [];
  11614. for (var i = 0; i < levelsLength; i++) {
  11615. var level = {
  11616. width: width,
  11617. height: height,
  11618. items: []
  11619. };
  11620. this.levels.push(level);
  11621. width = Math.ceil(width / 2);
  11622. height = Math.ceil(height / 2);
  11623. }
  11624. }
  11625. TagTree.prototype = {
  11626. reset: function TagTree_reset(i, j) {
  11627. var currentLevel = 0, value = 0, level;
  11628. while (currentLevel < this.levels.length) {
  11629. level = this.levels[currentLevel];
  11630. var index = i + j * level.width;
  11631. if (level.items[index] !== undefined) {
  11632. value = level.items[index];
  11633. break;
  11634. }
  11635. level.index = index;
  11636. i >>= 1;
  11637. j >>= 1;
  11638. currentLevel++;
  11639. }
  11640. currentLevel--;
  11641. level = this.levels[currentLevel];
  11642. level.items[level.index] = value;
  11643. this.currentLevel = currentLevel;
  11644. delete this.value;
  11645. },
  11646. incrementValue: function TagTree_incrementValue() {
  11647. var level = this.levels[this.currentLevel];
  11648. level.items[level.index]++;
  11649. },
  11650. nextLevel: function TagTree_nextLevel() {
  11651. var currentLevel = this.currentLevel;
  11652. var level = this.levels[currentLevel];
  11653. var value = level.items[level.index];
  11654. currentLevel--;
  11655. if (currentLevel < 0) {
  11656. this.value = value;
  11657. return false;
  11658. }
  11659. this.currentLevel = currentLevel;
  11660. level = this.levels[currentLevel];
  11661. level.items[level.index] = value;
  11662. return true;
  11663. }
  11664. };
  11665. return TagTree;
  11666. })();
  11667. var InclusionTree = (function InclusionTreeClosure() {
  11668. function InclusionTree(width, height, defaultValue) {
  11669. var levelsLength = log2(Math.max(width, height)) + 1;
  11670. this.levels = [];
  11671. for (var i = 0; i < levelsLength; i++) {
  11672. var items = new Uint8Array(width * height);
  11673. for (var j = 0, jj = items.length; j < jj; j++) {
  11674. items[j] = defaultValue;
  11675. }
  11676. var level = {
  11677. width: width,
  11678. height: height,
  11679. items: items
  11680. };
  11681. this.levels.push(level);
  11682. width = Math.ceil(width / 2);
  11683. height = Math.ceil(height / 2);
  11684. }
  11685. }
  11686. InclusionTree.prototype = {
  11687. reset: function InclusionTree_reset(i, j, stopValue) {
  11688. var currentLevel = 0;
  11689. while (currentLevel < this.levels.length) {
  11690. var level = this.levels[currentLevel];
  11691. var index = i + j * level.width;
  11692. level.index = index;
  11693. var value = level.items[index];
  11694. if (value === 0xFF) {
  11695. break;
  11696. }
  11697. if (value > stopValue) {
  11698. this.currentLevel = currentLevel;
  11699. // already know about this one, propagating the value to top levels
  11700. this.propagateValues();
  11701. return false;
  11702. }
  11703. i >>= 1;
  11704. j >>= 1;
  11705. currentLevel++;
  11706. }
  11707. this.currentLevel = currentLevel - 1;
  11708. return true;
  11709. },
  11710. incrementValue: function InclusionTree_incrementValue(stopValue) {
  11711. var level = this.levels[this.currentLevel];
  11712. level.items[level.index] = stopValue + 1;
  11713. this.propagateValues();
  11714. },
  11715. propagateValues: function InclusionTree_propagateValues() {
  11716. var levelIndex = this.currentLevel;
  11717. var level = this.levels[levelIndex];
  11718. var currentValue = level.items[level.index];
  11719. while (--levelIndex >= 0) {
  11720. level = this.levels[levelIndex];
  11721. level.items[level.index] = currentValue;
  11722. }
  11723. },
  11724. nextLevel: function InclusionTree_nextLevel() {
  11725. var currentLevel = this.currentLevel;
  11726. var level = this.levels[currentLevel];
  11727. var value = level.items[level.index];
  11728. level.items[level.index] = 0xFF;
  11729. currentLevel--;
  11730. if (currentLevel < 0) {
  11731. return false;
  11732. }
  11733. this.currentLevel = currentLevel;
  11734. level = this.levels[currentLevel];
  11735. level.items[level.index] = value;
  11736. return true;
  11737. }
  11738. };
  11739. return InclusionTree;
  11740. })();
  11741. // Section D. Coefficient bit modeling
  11742. var BitModel = (function BitModelClosure() {
  11743. var UNIFORM_CONTEXT = 17;
  11744. var RUNLENGTH_CONTEXT = 18;
  11745. // Table D-1
  11746. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  11747. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  11748. var LLAndLHContextsLabel = new Uint8Array([
  11749. 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,
  11750. 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,
  11751. 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
  11752. ]);
  11753. var HLContextLabel = new Uint8Array([
  11754. 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,
  11755. 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,
  11756. 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
  11757. ]);
  11758. var HHContextLabel = new Uint8Array([
  11759. 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,
  11760. 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,
  11761. 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
  11762. ]);
  11763. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  11764. this.width = width;
  11765. this.height = height;
  11766. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  11767. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  11768. var coefficientCount = width * height;
  11769. // coefficients outside the encoding region treated as insignificant
  11770. // add border state cells for significanceState
  11771. this.neighborsSignificance = new Uint8Array(coefficientCount);
  11772. this.coefficentsSign = new Uint8Array(coefficientCount);
  11773. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  11774. mb > 6 ? new Uint16Array(coefficientCount) :
  11775. new Uint8Array(coefficientCount);
  11776. this.processingFlags = new Uint8Array(coefficientCount);
  11777. var bitsDecoded = new Uint8Array(coefficientCount);
  11778. if (zeroBitPlanes !== 0) {
  11779. for (var i = 0; i < coefficientCount; i++) {
  11780. bitsDecoded[i] = zeroBitPlanes;
  11781. }
  11782. }
  11783. this.bitsDecoded = bitsDecoded;
  11784. this.reset();
  11785. }
  11786. BitModel.prototype = {
  11787. setDecoder: function BitModel_setDecoder(decoder) {
  11788. this.decoder = decoder;
  11789. },
  11790. reset: function BitModel_reset() {
  11791. // We have 17 contexts that are accessed via context labels,
  11792. // plus the uniform and runlength context.
  11793. this.contexts = new Int8Array(19);
  11794. // Contexts are packed into 1 byte:
  11795. // highest 7 bits carry the index, lowest bit carries mps
  11796. this.contexts[0] = (4 << 1) | 0;
  11797. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  11798. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  11799. },
  11800. setNeighborsSignificance:
  11801. function BitModel_setNeighborsSignificance(row, column, index) {
  11802. var neighborsSignificance = this.neighborsSignificance;
  11803. var width = this.width, height = this.height;
  11804. var left = (column > 0);
  11805. var right = (column + 1 < width);
  11806. var i;
  11807. if (row > 0) {
  11808. i = index - width;
  11809. if (left) {
  11810. neighborsSignificance[i - 1] += 0x10;
  11811. }
  11812. if (right) {
  11813. neighborsSignificance[i + 1] += 0x10;
  11814. }
  11815. neighborsSignificance[i] += 0x04;
  11816. }
  11817. if (row + 1 < height) {
  11818. i = index + width;
  11819. if (left) {
  11820. neighborsSignificance[i - 1] += 0x10;
  11821. }
  11822. if (right) {
  11823. neighborsSignificance[i + 1] += 0x10;
  11824. }
  11825. neighborsSignificance[i] += 0x04;
  11826. }
  11827. if (left) {
  11828. neighborsSignificance[index - 1] += 0x01;
  11829. }
  11830. if (right) {
  11831. neighborsSignificance[index + 1] += 0x01;
  11832. }
  11833. neighborsSignificance[index] |= 0x80;
  11834. },
  11835. runSignificancePropogationPass:
  11836. function BitModel_runSignificancePropogationPass() {
  11837. var decoder = this.decoder;
  11838. var width = this.width, height = this.height;
  11839. var coefficentsMagnitude = this.coefficentsMagnitude;
  11840. var coefficentsSign = this.coefficentsSign;
  11841. var neighborsSignificance = this.neighborsSignificance;
  11842. var processingFlags = this.processingFlags;
  11843. var contexts = this.contexts;
  11844. var labels = this.contextLabelTable;
  11845. var bitsDecoded = this.bitsDecoded;
  11846. var processedInverseMask = ~1;
  11847. var processedMask = 1;
  11848. var firstMagnitudeBitMask = 2;
  11849. for (var i0 = 0; i0 < height; i0 += 4) {
  11850. for (var j = 0; j < width; j++) {
  11851. var index = i0 * width + j;
  11852. for (var i1 = 0; i1 < 4; i1++, index += width) {
  11853. var i = i0 + i1;
  11854. if (i >= height) {
  11855. break;
  11856. }
  11857. // clear processed flag first
  11858. processingFlags[index] &= processedInverseMask;
  11859. if (coefficentsMagnitude[index] ||
  11860. !neighborsSignificance[index]) {
  11861. continue;
  11862. }
  11863. var contextLabel = labels[neighborsSignificance[index]];
  11864. var decision = decoder.readBit(contexts, contextLabel);
  11865. if (decision) {
  11866. var sign = this.decodeSignBit(i, j, index);
  11867. coefficentsSign[index] = sign;
  11868. coefficentsMagnitude[index] = 1;
  11869. this.setNeighborsSignificance(i, j, index);
  11870. processingFlags[index] |= firstMagnitudeBitMask;
  11871. }
  11872. bitsDecoded[index]++;
  11873. processingFlags[index] |= processedMask;
  11874. }
  11875. }
  11876. }
  11877. },
  11878. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  11879. var width = this.width, height = this.height;
  11880. var coefficentsMagnitude = this.coefficentsMagnitude;
  11881. var coefficentsSign = this.coefficentsSign;
  11882. var contribution, sign0, sign1, significance1;
  11883. var contextLabel, decoded;
  11884. // calculate horizontal contribution
  11885. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  11886. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  11887. sign1 = coefficentsSign[index + 1];
  11888. if (significance1) {
  11889. sign0 = coefficentsSign[index - 1];
  11890. contribution = 1 - sign1 - sign0;
  11891. } else {
  11892. contribution = 1 - sign1 - sign1;
  11893. }
  11894. } else if (significance1) {
  11895. sign0 = coefficentsSign[index - 1];
  11896. contribution = 1 - sign0 - sign0;
  11897. } else {
  11898. contribution = 0;
  11899. }
  11900. var horizontalContribution = 3 * contribution;
  11901. // calculate vertical contribution and combine with the horizontal
  11902. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  11903. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  11904. sign1 = coefficentsSign[index + width];
  11905. if (significance1) {
  11906. sign0 = coefficentsSign[index - width];
  11907. contribution = 1 - sign1 - sign0 + horizontalContribution;
  11908. } else {
  11909. contribution = 1 - sign1 - sign1 + horizontalContribution;
  11910. }
  11911. } else if (significance1) {
  11912. sign0 = coefficentsSign[index - width];
  11913. contribution = 1 - sign0 - sign0 + horizontalContribution;
  11914. } else {
  11915. contribution = horizontalContribution;
  11916. }
  11917. if (contribution >= 0) {
  11918. contextLabel = 9 + contribution;
  11919. decoded = this.decoder.readBit(this.contexts, contextLabel);
  11920. } else {
  11921. contextLabel = 9 - contribution;
  11922. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  11923. }
  11924. return decoded;
  11925. },
  11926. runMagnitudeRefinementPass:
  11927. function BitModel_runMagnitudeRefinementPass() {
  11928. var decoder = this.decoder;
  11929. var width = this.width, height = this.height;
  11930. var coefficentsMagnitude = this.coefficentsMagnitude;
  11931. var neighborsSignificance = this.neighborsSignificance;
  11932. var contexts = this.contexts;
  11933. var bitsDecoded = this.bitsDecoded;
  11934. var processingFlags = this.processingFlags;
  11935. var processedMask = 1;
  11936. var firstMagnitudeBitMask = 2;
  11937. var length = width * height;
  11938. var width4 = width * 4;
  11939. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  11940. indexNext = Math.min(length, index0 + width4);
  11941. for (var j = 0; j < width; j++) {
  11942. for (var index = index0 + j; index < indexNext; index += width) {
  11943. // significant but not those that have just become
  11944. if (!coefficentsMagnitude[index] ||
  11945. (processingFlags[index] & processedMask) !== 0) {
  11946. continue;
  11947. }
  11948. var contextLabel = 16;
  11949. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  11950. processingFlags[index] ^= firstMagnitudeBitMask;
  11951. // first refinement
  11952. var significance = neighborsSignificance[index] & 127;
  11953. contextLabel = significance === 0 ? 15 : 14;
  11954. }
  11955. var bit = decoder.readBit(contexts, contextLabel);
  11956. coefficentsMagnitude[index] =
  11957. (coefficentsMagnitude[index] << 1) | bit;
  11958. bitsDecoded[index]++;
  11959. processingFlags[index] |= processedMask;
  11960. }
  11961. }
  11962. }
  11963. },
  11964. runCleanupPass: function BitModel_runCleanupPass() {
  11965. var decoder = this.decoder;
  11966. var width = this.width, height = this.height;
  11967. var neighborsSignificance = this.neighborsSignificance;
  11968. var coefficentsMagnitude = this.coefficentsMagnitude;
  11969. var coefficentsSign = this.coefficentsSign;
  11970. var contexts = this.contexts;
  11971. var labels = this.contextLabelTable;
  11972. var bitsDecoded = this.bitsDecoded;
  11973. var processingFlags = this.processingFlags;
  11974. var processedMask = 1;
  11975. var firstMagnitudeBitMask = 2;
  11976. var oneRowDown = width;
  11977. var twoRowsDown = width * 2;
  11978. var threeRowsDown = width * 3;
  11979. var iNext;
  11980. for (var i0 = 0; i0 < height; i0 = iNext) {
  11981. iNext = Math.min(i0 + 4, height);
  11982. var indexBase = i0 * width;
  11983. var checkAllEmpty = i0 + 3 < height;
  11984. for (var j = 0; j < width; j++) {
  11985. var index0 = indexBase + j;
  11986. // using the property: labels[neighborsSignificance[index]] === 0
  11987. // when neighborsSignificance[index] === 0
  11988. var allEmpty = (checkAllEmpty &&
  11989. processingFlags[index0] === 0 &&
  11990. processingFlags[index0 + oneRowDown] === 0 &&
  11991. processingFlags[index0 + twoRowsDown] === 0 &&
  11992. processingFlags[index0 + threeRowsDown] === 0 &&
  11993. neighborsSignificance[index0] === 0 &&
  11994. neighborsSignificance[index0 + oneRowDown] === 0 &&
  11995. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  11996. neighborsSignificance[index0 + threeRowsDown] === 0);
  11997. var i1 = 0, index = index0;
  11998. var i = i0, sign;
  11999. if (allEmpty) {
  12000. var hasSignificantCoefficent =
  12001. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  12002. if (!hasSignificantCoefficent) {
  12003. bitsDecoded[index0]++;
  12004. bitsDecoded[index0 + oneRowDown]++;
  12005. bitsDecoded[index0 + twoRowsDown]++;
  12006. bitsDecoded[index0 + threeRowsDown]++;
  12007. continue; // next column
  12008. }
  12009. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  12010. decoder.readBit(contexts, UNIFORM_CONTEXT);
  12011. if (i1 !== 0) {
  12012. i = i0 + i1;
  12013. index += i1 * width;
  12014. }
  12015. sign = this.decodeSignBit(i, j, index);
  12016. coefficentsSign[index] = sign;
  12017. coefficentsMagnitude[index] = 1;
  12018. this.setNeighborsSignificance(i, j, index);
  12019. processingFlags[index] |= firstMagnitudeBitMask;
  12020. index = index0;
  12021. for (var i2 = i0; i2 <= i; i2++, index += width) {
  12022. bitsDecoded[index]++;
  12023. }
  12024. i1++;
  12025. }
  12026. for (i = i0 + i1; i < iNext; i++, index += width) {
  12027. if (coefficentsMagnitude[index] ||
  12028. (processingFlags[index] & processedMask) !== 0) {
  12029. continue;
  12030. }
  12031. var contextLabel = labels[neighborsSignificance[index]];
  12032. var decision = decoder.readBit(contexts, contextLabel);
  12033. if (decision === 1) {
  12034. sign = this.decodeSignBit(i, j, index);
  12035. coefficentsSign[index] = sign;
  12036. coefficentsMagnitude[index] = 1;
  12037. this.setNeighborsSignificance(i, j, index);
  12038. processingFlags[index] |= firstMagnitudeBitMask;
  12039. }
  12040. bitsDecoded[index]++;
  12041. }
  12042. }
  12043. }
  12044. },
  12045. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  12046. var decoder = this.decoder;
  12047. var contexts = this.contexts;
  12048. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  12049. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  12050. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  12051. decoder.readBit(contexts, UNIFORM_CONTEXT);
  12052. if (symbol !== 0xA) {
  12053. throw new Error('JPX Error: Invalid segmentation symbol');
  12054. }
  12055. }
  12056. };
  12057. return BitModel;
  12058. })();
  12059. // Section F, Discrete wavelet transformation
  12060. var Transform = (function TransformClosure() {
  12061. function Transform() {}
  12062. Transform.prototype.calculate =
  12063. function transformCalculate(subbands, u0, v0) {
  12064. var ll = subbands[0];
  12065. for (var i = 1, ii = subbands.length; i < ii; i++) {
  12066. ll = this.iterate(ll, subbands[i], u0, v0);
  12067. }
  12068. return ll;
  12069. };
  12070. Transform.prototype.extend = function extend(buffer, offset, size) {
  12071. // Section F.3.7 extending... using max extension of 4
  12072. var i1 = offset - 1, j1 = offset + 1;
  12073. var i2 = offset + size - 2, j2 = offset + size;
  12074. buffer[i1--] = buffer[j1++];
  12075. buffer[j2++] = buffer[i2--];
  12076. buffer[i1--] = buffer[j1++];
  12077. buffer[j2++] = buffer[i2--];
  12078. buffer[i1--] = buffer[j1++];
  12079. buffer[j2++] = buffer[i2--];
  12080. buffer[i1] = buffer[j1];
  12081. buffer[j2] = buffer[i2];
  12082. };
  12083. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  12084. u0, v0) {
  12085. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  12086. var width = hl_lh_hh.width;
  12087. var height = hl_lh_hh.height;
  12088. var items = hl_lh_hh.items;
  12089. var i, j, k, l, u, v;
  12090. // Interleave LL according to Section F.3.3
  12091. for (k = 0, i = 0; i < llHeight; i++) {
  12092. l = i * 2 * width;
  12093. for (j = 0; j < llWidth; j++, k++, l += 2) {
  12094. items[l] = llItems[k];
  12095. }
  12096. }
  12097. // The LL band is not needed anymore.
  12098. llItems = ll.items = null;
  12099. var bufferPadding = 4;
  12100. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  12101. // Section F.3.4 HOR_SR
  12102. if (width === 1) {
  12103. // if width = 1, when u0 even keep items as is, when odd divide by 2
  12104. if ((u0 & 1) !== 0) {
  12105. for (v = 0, k = 0; v < height; v++, k += width) {
  12106. items[k] *= 0.5;
  12107. }
  12108. }
  12109. } else {
  12110. for (v = 0, k = 0; v < height; v++, k += width) {
  12111. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  12112. this.extend(rowBuffer, bufferPadding, width);
  12113. this.filter(rowBuffer, bufferPadding, width);
  12114. items.set(
  12115. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  12116. k);
  12117. }
  12118. }
  12119. // Accesses to the items array can take long, because it may not fit into
  12120. // CPU cache and has to be fetched from main memory. Since subsequent
  12121. // accesses to the items array are not local when reading columns, we
  12122. // have a cache miss every time. To reduce cache misses, get up to
  12123. // 'numBuffers' items at a time and store them into the individual
  12124. // buffers. The colBuffers should be small enough to fit into CPU cache.
  12125. var numBuffers = 16;
  12126. var colBuffers = [];
  12127. for (i = 0; i < numBuffers; i++) {
  12128. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  12129. }
  12130. var b, currentBuffer = 0;
  12131. ll = bufferPadding + height;
  12132. // Section F.3.5 VER_SR
  12133. if (height === 1) {
  12134. // if height = 1, when v0 even keep items as is, when odd divide by 2
  12135. if ((v0 & 1) !== 0) {
  12136. for (u = 0; u < width; u++) {
  12137. items[u] *= 0.5;
  12138. }
  12139. }
  12140. } else {
  12141. for (u = 0; u < width; u++) {
  12142. // if we ran out of buffers, copy several image columns at once
  12143. if (currentBuffer === 0) {
  12144. numBuffers = Math.min(width - u, numBuffers);
  12145. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  12146. for (b = 0; b < numBuffers; b++) {
  12147. colBuffers[b][l] = items[k + b];
  12148. }
  12149. }
  12150. currentBuffer = numBuffers;
  12151. }
  12152. currentBuffer--;
  12153. var buffer = colBuffers[currentBuffer];
  12154. this.extend(buffer, bufferPadding, height);
  12155. this.filter(buffer, bufferPadding, height);
  12156. // If this is last buffer in this group of buffers, flush all buffers.
  12157. if (currentBuffer === 0) {
  12158. k = u - numBuffers + 1;
  12159. for (l = bufferPadding; l < ll; k += width, l++) {
  12160. for (b = 0; b < numBuffers; b++) {
  12161. items[k + b] = colBuffers[b][l];
  12162. }
  12163. }
  12164. }
  12165. }
  12166. }
  12167. return {
  12168. width: width,
  12169. height: height,
  12170. items: items
  12171. };
  12172. };
  12173. return Transform;
  12174. })();
  12175. // Section 3.8.2 Irreversible 9-7 filter
  12176. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  12177. function IrreversibleTransform() {
  12178. Transform.call(this);
  12179. }
  12180. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  12181. IrreversibleTransform.prototype.filter =
  12182. function irreversibleTransformFilter(x, offset, length) {
  12183. var len = length >> 1;
  12184. offset = offset | 0;
  12185. var j, n, current, next;
  12186. var alpha = -1.586134342059924;
  12187. var beta = -0.052980118572961;
  12188. var gamma = 0.882911075530934;
  12189. var delta = 0.443506852043971;
  12190. var K = 1.230174104914001;
  12191. var K_ = 1 / K;
  12192. // step 1 is combined with step 3
  12193. // step 2
  12194. j = offset - 3;
  12195. for (n = len + 4; n--; j += 2) {
  12196. x[j] *= K_;
  12197. }
  12198. // step 1 & 3
  12199. j = offset - 2;
  12200. current = delta * x[j -1];
  12201. for (n = len + 3; n--; j += 2) {
  12202. next = delta * x[j + 1];
  12203. x[j] = K * x[j] - current - next;
  12204. if (n--) {
  12205. j += 2;
  12206. current = delta * x[j + 1];
  12207. x[j] = K * x[j] - current - next;
  12208. } else {
  12209. break;
  12210. }
  12211. }
  12212. // step 4
  12213. j = offset - 1;
  12214. current = gamma * x[j - 1];
  12215. for (n = len + 2; n--; j += 2) {
  12216. next = gamma * x[j + 1];
  12217. x[j] -= current + next;
  12218. if (n--) {
  12219. j += 2;
  12220. current = gamma * x[j + 1];
  12221. x[j] -= current + next;
  12222. } else {
  12223. break;
  12224. }
  12225. }
  12226. // step 5
  12227. j = offset;
  12228. current = beta * x[j - 1];
  12229. for (n = len + 1; n--; j += 2) {
  12230. next = beta * x[j + 1];
  12231. x[j] -= current + next;
  12232. if (n--) {
  12233. j += 2;
  12234. current = beta * x[j + 1];
  12235. x[j] -= current + next;
  12236. } else {
  12237. break;
  12238. }
  12239. }
  12240. // step 6
  12241. if (len !== 0) {
  12242. j = offset + 1;
  12243. current = alpha * x[j - 1];
  12244. for (n = len; n--; j += 2) {
  12245. next = alpha * x[j + 1];
  12246. x[j] -= current + next;
  12247. if (n--) {
  12248. j += 2;
  12249. current = alpha * x[j + 1];
  12250. x[j] -= current + next;
  12251. } else {
  12252. break;
  12253. }
  12254. }
  12255. }
  12256. };
  12257. return IrreversibleTransform;
  12258. })();
  12259. // Section 3.8.1 Reversible 5-3 filter
  12260. var ReversibleTransform = (function ReversibleTransformClosure() {
  12261. function ReversibleTransform() {
  12262. Transform.call(this);
  12263. }
  12264. ReversibleTransform.prototype = Object.create(Transform.prototype);
  12265. ReversibleTransform.prototype.filter =
  12266. function reversibleTransformFilter(x, offset, length) {
  12267. var len = length >> 1;
  12268. offset = offset | 0;
  12269. var j, n;
  12270. for (j = offset, n = len + 1; n--; j += 2) {
  12271. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  12272. }
  12273. for (j = offset + 1, n = len; n--; j += 2) {
  12274. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  12275. }
  12276. };
  12277. return ReversibleTransform;
  12278. })();
  12279. return JpxImage;
  12280. })();
  12281. exports.JpxImage = JpxImage;
  12282. }));
  12283. (function (root, factory) {
  12284. {
  12285. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  12286. }
  12287. }(this, function (exports, sharedUtil) {
  12288. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  12289. // The Metrics object contains glyph widths (in glyph space units).
  12290. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  12291. // space unit corresponds to 1/1000th of text space unit.
  12292. var getMetrics = getLookupTableFactory(function (t) {
  12293. t['Courier'] = 600;
  12294. t['Courier-Bold'] = 600;
  12295. t['Courier-BoldOblique'] = 600;
  12296. t['Courier-Oblique'] = 600;
  12297. t['Helvetica'] = getLookupTableFactory(function (t) {
  12298. t['space'] = 278;
  12299. t['exclam'] = 278;
  12300. t['quotedbl'] = 355;
  12301. t['numbersign'] = 556;
  12302. t['dollar'] = 556;
  12303. t['percent'] = 889;
  12304. t['ampersand'] = 667;
  12305. t['quoteright'] = 222;
  12306. t['parenleft'] = 333;
  12307. t['parenright'] = 333;
  12308. t['asterisk'] = 389;
  12309. t['plus'] = 584;
  12310. t['comma'] = 278;
  12311. t['hyphen'] = 333;
  12312. t['period'] = 278;
  12313. t['slash'] = 278;
  12314. t['zero'] = 556;
  12315. t['one'] = 556;
  12316. t['two'] = 556;
  12317. t['three'] = 556;
  12318. t['four'] = 556;
  12319. t['five'] = 556;
  12320. t['six'] = 556;
  12321. t['seven'] = 556;
  12322. t['eight'] = 556;
  12323. t['nine'] = 556;
  12324. t['colon'] = 278;
  12325. t['semicolon'] = 278;
  12326. t['less'] = 584;
  12327. t['equal'] = 584;
  12328. t['greater'] = 584;
  12329. t['question'] = 556;
  12330. t['at'] = 1015;
  12331. t['A'] = 667;
  12332. t['B'] = 667;
  12333. t['C'] = 722;
  12334. t['D'] = 722;
  12335. t['E'] = 667;
  12336. t['F'] = 611;
  12337. t['G'] = 778;
  12338. t['H'] = 722;
  12339. t['I'] = 278;
  12340. t['J'] = 500;
  12341. t['K'] = 667;
  12342. t['L'] = 556;
  12343. t['M'] = 833;
  12344. t['N'] = 722;
  12345. t['O'] = 778;
  12346. t['P'] = 667;
  12347. t['Q'] = 778;
  12348. t['R'] = 722;
  12349. t['S'] = 667;
  12350. t['T'] = 611;
  12351. t['U'] = 722;
  12352. t['V'] = 667;
  12353. t['W'] = 944;
  12354. t['X'] = 667;
  12355. t['Y'] = 667;
  12356. t['Z'] = 611;
  12357. t['bracketleft'] = 278;
  12358. t['backslash'] = 278;
  12359. t['bracketright'] = 278;
  12360. t['asciicircum'] = 469;
  12361. t['underscore'] = 556;
  12362. t['quoteleft'] = 222;
  12363. t['a'] = 556;
  12364. t['b'] = 556;
  12365. t['c'] = 500;
  12366. t['d'] = 556;
  12367. t['e'] = 556;
  12368. t['f'] = 278;
  12369. t['g'] = 556;
  12370. t['h'] = 556;
  12371. t['i'] = 222;
  12372. t['j'] = 222;
  12373. t['k'] = 500;
  12374. t['l'] = 222;
  12375. t['m'] = 833;
  12376. t['n'] = 556;
  12377. t['o'] = 556;
  12378. t['p'] = 556;
  12379. t['q'] = 556;
  12380. t['r'] = 333;
  12381. t['s'] = 500;
  12382. t['t'] = 278;
  12383. t['u'] = 556;
  12384. t['v'] = 500;
  12385. t['w'] = 722;
  12386. t['x'] = 500;
  12387. t['y'] = 500;
  12388. t['z'] = 500;
  12389. t['braceleft'] = 334;
  12390. t['bar'] = 260;
  12391. t['braceright'] = 334;
  12392. t['asciitilde'] = 584;
  12393. t['exclamdown'] = 333;
  12394. t['cent'] = 556;
  12395. t['sterling'] = 556;
  12396. t['fraction'] = 167;
  12397. t['yen'] = 556;
  12398. t['florin'] = 556;
  12399. t['section'] = 556;
  12400. t['currency'] = 556;
  12401. t['quotesingle'] = 191;
  12402. t['quotedblleft'] = 333;
  12403. t['guillemotleft'] = 556;
  12404. t['guilsinglleft'] = 333;
  12405. t['guilsinglright'] = 333;
  12406. t['fi'] = 500;
  12407. t['fl'] = 500;
  12408. t['endash'] = 556;
  12409. t['dagger'] = 556;
  12410. t['daggerdbl'] = 556;
  12411. t['periodcentered'] = 278;
  12412. t['paragraph'] = 537;
  12413. t['bullet'] = 350;
  12414. t['quotesinglbase'] = 222;
  12415. t['quotedblbase'] = 333;
  12416. t['quotedblright'] = 333;
  12417. t['guillemotright'] = 556;
  12418. t['ellipsis'] = 1000;
  12419. t['perthousand'] = 1000;
  12420. t['questiondown'] = 611;
  12421. t['grave'] = 333;
  12422. t['acute'] = 333;
  12423. t['circumflex'] = 333;
  12424. t['tilde'] = 333;
  12425. t['macron'] = 333;
  12426. t['breve'] = 333;
  12427. t['dotaccent'] = 333;
  12428. t['dieresis'] = 333;
  12429. t['ring'] = 333;
  12430. t['cedilla'] = 333;
  12431. t['hungarumlaut'] = 333;
  12432. t['ogonek'] = 333;
  12433. t['caron'] = 333;
  12434. t['emdash'] = 1000;
  12435. t['AE'] = 1000;
  12436. t['ordfeminine'] = 370;
  12437. t['Lslash'] = 556;
  12438. t['Oslash'] = 778;
  12439. t['OE'] = 1000;
  12440. t['ordmasculine'] = 365;
  12441. t['ae'] = 889;
  12442. t['dotlessi'] = 278;
  12443. t['lslash'] = 222;
  12444. t['oslash'] = 611;
  12445. t['oe'] = 944;
  12446. t['germandbls'] = 611;
  12447. t['Idieresis'] = 278;
  12448. t['eacute'] = 556;
  12449. t['abreve'] = 556;
  12450. t['uhungarumlaut'] = 556;
  12451. t['ecaron'] = 556;
  12452. t['Ydieresis'] = 667;
  12453. t['divide'] = 584;
  12454. t['Yacute'] = 667;
  12455. t['Acircumflex'] = 667;
  12456. t['aacute'] = 556;
  12457. t['Ucircumflex'] = 722;
  12458. t['yacute'] = 500;
  12459. t['scommaaccent'] = 500;
  12460. t['ecircumflex'] = 556;
  12461. t['Uring'] = 722;
  12462. t['Udieresis'] = 722;
  12463. t['aogonek'] = 556;
  12464. t['Uacute'] = 722;
  12465. t['uogonek'] = 556;
  12466. t['Edieresis'] = 667;
  12467. t['Dcroat'] = 722;
  12468. t['commaaccent'] = 250;
  12469. t['copyright'] = 737;
  12470. t['Emacron'] = 667;
  12471. t['ccaron'] = 500;
  12472. t['aring'] = 556;
  12473. t['Ncommaaccent'] = 722;
  12474. t['lacute'] = 222;
  12475. t['agrave'] = 556;
  12476. t['Tcommaaccent'] = 611;
  12477. t['Cacute'] = 722;
  12478. t['atilde'] = 556;
  12479. t['Edotaccent'] = 667;
  12480. t['scaron'] = 500;
  12481. t['scedilla'] = 500;
  12482. t['iacute'] = 278;
  12483. t['lozenge'] = 471;
  12484. t['Rcaron'] = 722;
  12485. t['Gcommaaccent'] = 778;
  12486. t['ucircumflex'] = 556;
  12487. t['acircumflex'] = 556;
  12488. t['Amacron'] = 667;
  12489. t['rcaron'] = 333;
  12490. t['ccedilla'] = 500;
  12491. t['Zdotaccent'] = 611;
  12492. t['Thorn'] = 667;
  12493. t['Omacron'] = 778;
  12494. t['Racute'] = 722;
  12495. t['Sacute'] = 667;
  12496. t['dcaron'] = 643;
  12497. t['Umacron'] = 722;
  12498. t['uring'] = 556;
  12499. t['threesuperior'] = 333;
  12500. t['Ograve'] = 778;
  12501. t['Agrave'] = 667;
  12502. t['Abreve'] = 667;
  12503. t['multiply'] = 584;
  12504. t['uacute'] = 556;
  12505. t['Tcaron'] = 611;
  12506. t['partialdiff'] = 476;
  12507. t['ydieresis'] = 500;
  12508. t['Nacute'] = 722;
  12509. t['icircumflex'] = 278;
  12510. t['Ecircumflex'] = 667;
  12511. t['adieresis'] = 556;
  12512. t['edieresis'] = 556;
  12513. t['cacute'] = 500;
  12514. t['nacute'] = 556;
  12515. t['umacron'] = 556;
  12516. t['Ncaron'] = 722;
  12517. t['Iacute'] = 278;
  12518. t['plusminus'] = 584;
  12519. t['brokenbar'] = 260;
  12520. t['registered'] = 737;
  12521. t['Gbreve'] = 778;
  12522. t['Idotaccent'] = 278;
  12523. t['summation'] = 600;
  12524. t['Egrave'] = 667;
  12525. t['racute'] = 333;
  12526. t['omacron'] = 556;
  12527. t['Zacute'] = 611;
  12528. t['Zcaron'] = 611;
  12529. t['greaterequal'] = 549;
  12530. t['Eth'] = 722;
  12531. t['Ccedilla'] = 722;
  12532. t['lcommaaccent'] = 222;
  12533. t['tcaron'] = 317;
  12534. t['eogonek'] = 556;
  12535. t['Uogonek'] = 722;
  12536. t['Aacute'] = 667;
  12537. t['Adieresis'] = 667;
  12538. t['egrave'] = 556;
  12539. t['zacute'] = 500;
  12540. t['iogonek'] = 222;
  12541. t['Oacute'] = 778;
  12542. t['oacute'] = 556;
  12543. t['amacron'] = 556;
  12544. t['sacute'] = 500;
  12545. t['idieresis'] = 278;
  12546. t['Ocircumflex'] = 778;
  12547. t['Ugrave'] = 722;
  12548. t['Delta'] = 612;
  12549. t['thorn'] = 556;
  12550. t['twosuperior'] = 333;
  12551. t['Odieresis'] = 778;
  12552. t['mu'] = 556;
  12553. t['igrave'] = 278;
  12554. t['ohungarumlaut'] = 556;
  12555. t['Eogonek'] = 667;
  12556. t['dcroat'] = 556;
  12557. t['threequarters'] = 834;
  12558. t['Scedilla'] = 667;
  12559. t['lcaron'] = 299;
  12560. t['Kcommaaccent'] = 667;
  12561. t['Lacute'] = 556;
  12562. t['trademark'] = 1000;
  12563. t['edotaccent'] = 556;
  12564. t['Igrave'] = 278;
  12565. t['Imacron'] = 278;
  12566. t['Lcaron'] = 556;
  12567. t['onehalf'] = 834;
  12568. t['lessequal'] = 549;
  12569. t['ocircumflex'] = 556;
  12570. t['ntilde'] = 556;
  12571. t['Uhungarumlaut'] = 722;
  12572. t['Eacute'] = 667;
  12573. t['emacron'] = 556;
  12574. t['gbreve'] = 556;
  12575. t['onequarter'] = 834;
  12576. t['Scaron'] = 667;
  12577. t['Scommaaccent'] = 667;
  12578. t['Ohungarumlaut'] = 778;
  12579. t['degree'] = 400;
  12580. t['ograve'] = 556;
  12581. t['Ccaron'] = 722;
  12582. t['ugrave'] = 556;
  12583. t['radical'] = 453;
  12584. t['Dcaron'] = 722;
  12585. t['rcommaaccent'] = 333;
  12586. t['Ntilde'] = 722;
  12587. t['otilde'] = 556;
  12588. t['Rcommaaccent'] = 722;
  12589. t['Lcommaaccent'] = 556;
  12590. t['Atilde'] = 667;
  12591. t['Aogonek'] = 667;
  12592. t['Aring'] = 667;
  12593. t['Otilde'] = 778;
  12594. t['zdotaccent'] = 500;
  12595. t['Ecaron'] = 667;
  12596. t['Iogonek'] = 278;
  12597. t['kcommaaccent'] = 500;
  12598. t['minus'] = 584;
  12599. t['Icircumflex'] = 278;
  12600. t['ncaron'] = 556;
  12601. t['tcommaaccent'] = 278;
  12602. t['logicalnot'] = 584;
  12603. t['odieresis'] = 556;
  12604. t['udieresis'] = 556;
  12605. t['notequal'] = 549;
  12606. t['gcommaaccent'] = 556;
  12607. t['eth'] = 556;
  12608. t['zcaron'] = 500;
  12609. t['ncommaaccent'] = 556;
  12610. t['onesuperior'] = 333;
  12611. t['imacron'] = 278;
  12612. t['Euro'] = 556;
  12613. });
  12614. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  12615. t['space'] = 278;
  12616. t['exclam'] = 333;
  12617. t['quotedbl'] = 474;
  12618. t['numbersign'] = 556;
  12619. t['dollar'] = 556;
  12620. t['percent'] = 889;
  12621. t['ampersand'] = 722;
  12622. t['quoteright'] = 278;
  12623. t['parenleft'] = 333;
  12624. t['parenright'] = 333;
  12625. t['asterisk'] = 389;
  12626. t['plus'] = 584;
  12627. t['comma'] = 278;
  12628. t['hyphen'] = 333;
  12629. t['period'] = 278;
  12630. t['slash'] = 278;
  12631. t['zero'] = 556;
  12632. t['one'] = 556;
  12633. t['two'] = 556;
  12634. t['three'] = 556;
  12635. t['four'] = 556;
  12636. t['five'] = 556;
  12637. t['six'] = 556;
  12638. t['seven'] = 556;
  12639. t['eight'] = 556;
  12640. t['nine'] = 556;
  12641. t['colon'] = 333;
  12642. t['semicolon'] = 333;
  12643. t['less'] = 584;
  12644. t['equal'] = 584;
  12645. t['greater'] = 584;
  12646. t['question'] = 611;
  12647. t['at'] = 975;
  12648. t['A'] = 722;
  12649. t['B'] = 722;
  12650. t['C'] = 722;
  12651. t['D'] = 722;
  12652. t['E'] = 667;
  12653. t['F'] = 611;
  12654. t['G'] = 778;
  12655. t['H'] = 722;
  12656. t['I'] = 278;
  12657. t['J'] = 556;
  12658. t['K'] = 722;
  12659. t['L'] = 611;
  12660. t['M'] = 833;
  12661. t['N'] = 722;
  12662. t['O'] = 778;
  12663. t['P'] = 667;
  12664. t['Q'] = 778;
  12665. t['R'] = 722;
  12666. t['S'] = 667;
  12667. t['T'] = 611;
  12668. t['U'] = 722;
  12669. t['V'] = 667;
  12670. t['W'] = 944;
  12671. t['X'] = 667;
  12672. t['Y'] = 667;
  12673. t['Z'] = 611;
  12674. t['bracketleft'] = 333;
  12675. t['backslash'] = 278;
  12676. t['bracketright'] = 333;
  12677. t['asciicircum'] = 584;
  12678. t['underscore'] = 556;
  12679. t['quoteleft'] = 278;
  12680. t['a'] = 556;
  12681. t['b'] = 611;
  12682. t['c'] = 556;
  12683. t['d'] = 611;
  12684. t['e'] = 556;
  12685. t['f'] = 333;
  12686. t['g'] = 611;
  12687. t['h'] = 611;
  12688. t['i'] = 278;
  12689. t['j'] = 278;
  12690. t['k'] = 556;
  12691. t['l'] = 278;
  12692. t['m'] = 889;
  12693. t['n'] = 611;
  12694. t['o'] = 611;
  12695. t['p'] = 611;
  12696. t['q'] = 611;
  12697. t['r'] = 389;
  12698. t['s'] = 556;
  12699. t['t'] = 333;
  12700. t['u'] = 611;
  12701. t['v'] = 556;
  12702. t['w'] = 778;
  12703. t['x'] = 556;
  12704. t['y'] = 556;
  12705. t['z'] = 500;
  12706. t['braceleft'] = 389;
  12707. t['bar'] = 280;
  12708. t['braceright'] = 389;
  12709. t['asciitilde'] = 584;
  12710. t['exclamdown'] = 333;
  12711. t['cent'] = 556;
  12712. t['sterling'] = 556;
  12713. t['fraction'] = 167;
  12714. t['yen'] = 556;
  12715. t['florin'] = 556;
  12716. t['section'] = 556;
  12717. t['currency'] = 556;
  12718. t['quotesingle'] = 238;
  12719. t['quotedblleft'] = 500;
  12720. t['guillemotleft'] = 556;
  12721. t['guilsinglleft'] = 333;
  12722. t['guilsinglright'] = 333;
  12723. t['fi'] = 611;
  12724. t['fl'] = 611;
  12725. t['endash'] = 556;
  12726. t['dagger'] = 556;
  12727. t['daggerdbl'] = 556;
  12728. t['periodcentered'] = 278;
  12729. t['paragraph'] = 556;
  12730. t['bullet'] = 350;
  12731. t['quotesinglbase'] = 278;
  12732. t['quotedblbase'] = 500;
  12733. t['quotedblright'] = 500;
  12734. t['guillemotright'] = 556;
  12735. t['ellipsis'] = 1000;
  12736. t['perthousand'] = 1000;
  12737. t['questiondown'] = 611;
  12738. t['grave'] = 333;
  12739. t['acute'] = 333;
  12740. t['circumflex'] = 333;
  12741. t['tilde'] = 333;
  12742. t['macron'] = 333;
  12743. t['breve'] = 333;
  12744. t['dotaccent'] = 333;
  12745. t['dieresis'] = 333;
  12746. t['ring'] = 333;
  12747. t['cedilla'] = 333;
  12748. t['hungarumlaut'] = 333;
  12749. t['ogonek'] = 333;
  12750. t['caron'] = 333;
  12751. t['emdash'] = 1000;
  12752. t['AE'] = 1000;
  12753. t['ordfeminine'] = 370;
  12754. t['Lslash'] = 611;
  12755. t['Oslash'] = 778;
  12756. t['OE'] = 1000;
  12757. t['ordmasculine'] = 365;
  12758. t['ae'] = 889;
  12759. t['dotlessi'] = 278;
  12760. t['lslash'] = 278;
  12761. t['oslash'] = 611;
  12762. t['oe'] = 944;
  12763. t['germandbls'] = 611;
  12764. t['Idieresis'] = 278;
  12765. t['eacute'] = 556;
  12766. t['abreve'] = 556;
  12767. t['uhungarumlaut'] = 611;
  12768. t['ecaron'] = 556;
  12769. t['Ydieresis'] = 667;
  12770. t['divide'] = 584;
  12771. t['Yacute'] = 667;
  12772. t['Acircumflex'] = 722;
  12773. t['aacute'] = 556;
  12774. t['Ucircumflex'] = 722;
  12775. t['yacute'] = 556;
  12776. t['scommaaccent'] = 556;
  12777. t['ecircumflex'] = 556;
  12778. t['Uring'] = 722;
  12779. t['Udieresis'] = 722;
  12780. t['aogonek'] = 556;
  12781. t['Uacute'] = 722;
  12782. t['uogonek'] = 611;
  12783. t['Edieresis'] = 667;
  12784. t['Dcroat'] = 722;
  12785. t['commaaccent'] = 250;
  12786. t['copyright'] = 737;
  12787. t['Emacron'] = 667;
  12788. t['ccaron'] = 556;
  12789. t['aring'] = 556;
  12790. t['Ncommaaccent'] = 722;
  12791. t['lacute'] = 278;
  12792. t['agrave'] = 556;
  12793. t['Tcommaaccent'] = 611;
  12794. t['Cacute'] = 722;
  12795. t['atilde'] = 556;
  12796. t['Edotaccent'] = 667;
  12797. t['scaron'] = 556;
  12798. t['scedilla'] = 556;
  12799. t['iacute'] = 278;
  12800. t['lozenge'] = 494;
  12801. t['Rcaron'] = 722;
  12802. t['Gcommaaccent'] = 778;
  12803. t['ucircumflex'] = 611;
  12804. t['acircumflex'] = 556;
  12805. t['Amacron'] = 722;
  12806. t['rcaron'] = 389;
  12807. t['ccedilla'] = 556;
  12808. t['Zdotaccent'] = 611;
  12809. t['Thorn'] = 667;
  12810. t['Omacron'] = 778;
  12811. t['Racute'] = 722;
  12812. t['Sacute'] = 667;
  12813. t['dcaron'] = 743;
  12814. t['Umacron'] = 722;
  12815. t['uring'] = 611;
  12816. t['threesuperior'] = 333;
  12817. t['Ograve'] = 778;
  12818. t['Agrave'] = 722;
  12819. t['Abreve'] = 722;
  12820. t['multiply'] = 584;
  12821. t['uacute'] = 611;
  12822. t['Tcaron'] = 611;
  12823. t['partialdiff'] = 494;
  12824. t['ydieresis'] = 556;
  12825. t['Nacute'] = 722;
  12826. t['icircumflex'] = 278;
  12827. t['Ecircumflex'] = 667;
  12828. t['adieresis'] = 556;
  12829. t['edieresis'] = 556;
  12830. t['cacute'] = 556;
  12831. t['nacute'] = 611;
  12832. t['umacron'] = 611;
  12833. t['Ncaron'] = 722;
  12834. t['Iacute'] = 278;
  12835. t['plusminus'] = 584;
  12836. t['brokenbar'] = 280;
  12837. t['registered'] = 737;
  12838. t['Gbreve'] = 778;
  12839. t['Idotaccent'] = 278;
  12840. t['summation'] = 600;
  12841. t['Egrave'] = 667;
  12842. t['racute'] = 389;
  12843. t['omacron'] = 611;
  12844. t['Zacute'] = 611;
  12845. t['Zcaron'] = 611;
  12846. t['greaterequal'] = 549;
  12847. t['Eth'] = 722;
  12848. t['Ccedilla'] = 722;
  12849. t['lcommaaccent'] = 278;
  12850. t['tcaron'] = 389;
  12851. t['eogonek'] = 556;
  12852. t['Uogonek'] = 722;
  12853. t['Aacute'] = 722;
  12854. t['Adieresis'] = 722;
  12855. t['egrave'] = 556;
  12856. t['zacute'] = 500;
  12857. t['iogonek'] = 278;
  12858. t['Oacute'] = 778;
  12859. t['oacute'] = 611;
  12860. t['amacron'] = 556;
  12861. t['sacute'] = 556;
  12862. t['idieresis'] = 278;
  12863. t['Ocircumflex'] = 778;
  12864. t['Ugrave'] = 722;
  12865. t['Delta'] = 612;
  12866. t['thorn'] = 611;
  12867. t['twosuperior'] = 333;
  12868. t['Odieresis'] = 778;
  12869. t['mu'] = 611;
  12870. t['igrave'] = 278;
  12871. t['ohungarumlaut'] = 611;
  12872. t['Eogonek'] = 667;
  12873. t['dcroat'] = 611;
  12874. t['threequarters'] = 834;
  12875. t['Scedilla'] = 667;
  12876. t['lcaron'] = 400;
  12877. t['Kcommaaccent'] = 722;
  12878. t['Lacute'] = 611;
  12879. t['trademark'] = 1000;
  12880. t['edotaccent'] = 556;
  12881. t['Igrave'] = 278;
  12882. t['Imacron'] = 278;
  12883. t['Lcaron'] = 611;
  12884. t['onehalf'] = 834;
  12885. t['lessequal'] = 549;
  12886. t['ocircumflex'] = 611;
  12887. t['ntilde'] = 611;
  12888. t['Uhungarumlaut'] = 722;
  12889. t['Eacute'] = 667;
  12890. t['emacron'] = 556;
  12891. t['gbreve'] = 611;
  12892. t['onequarter'] = 834;
  12893. t['Scaron'] = 667;
  12894. t['Scommaaccent'] = 667;
  12895. t['Ohungarumlaut'] = 778;
  12896. t['degree'] = 400;
  12897. t['ograve'] = 611;
  12898. t['Ccaron'] = 722;
  12899. t['ugrave'] = 611;
  12900. t['radical'] = 549;
  12901. t['Dcaron'] = 722;
  12902. t['rcommaaccent'] = 389;
  12903. t['Ntilde'] = 722;
  12904. t['otilde'] = 611;
  12905. t['Rcommaaccent'] = 722;
  12906. t['Lcommaaccent'] = 611;
  12907. t['Atilde'] = 722;
  12908. t['Aogonek'] = 722;
  12909. t['Aring'] = 722;
  12910. t['Otilde'] = 778;
  12911. t['zdotaccent'] = 500;
  12912. t['Ecaron'] = 667;
  12913. t['Iogonek'] = 278;
  12914. t['kcommaaccent'] = 556;
  12915. t['minus'] = 584;
  12916. t['Icircumflex'] = 278;
  12917. t['ncaron'] = 611;
  12918. t['tcommaaccent'] = 333;
  12919. t['logicalnot'] = 584;
  12920. t['odieresis'] = 611;
  12921. t['udieresis'] = 611;
  12922. t['notequal'] = 549;
  12923. t['gcommaaccent'] = 611;
  12924. t['eth'] = 611;
  12925. t['zcaron'] = 500;
  12926. t['ncommaaccent'] = 611;
  12927. t['onesuperior'] = 333;
  12928. t['imacron'] = 278;
  12929. t['Euro'] = 556;
  12930. });
  12931. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  12932. t['space'] = 278;
  12933. t['exclam'] = 333;
  12934. t['quotedbl'] = 474;
  12935. t['numbersign'] = 556;
  12936. t['dollar'] = 556;
  12937. t['percent'] = 889;
  12938. t['ampersand'] = 722;
  12939. t['quoteright'] = 278;
  12940. t['parenleft'] = 333;
  12941. t['parenright'] = 333;
  12942. t['asterisk'] = 389;
  12943. t['plus'] = 584;
  12944. t['comma'] = 278;
  12945. t['hyphen'] = 333;
  12946. t['period'] = 278;
  12947. t['slash'] = 278;
  12948. t['zero'] = 556;
  12949. t['one'] = 556;
  12950. t['two'] = 556;
  12951. t['three'] = 556;
  12952. t['four'] = 556;
  12953. t['five'] = 556;
  12954. t['six'] = 556;
  12955. t['seven'] = 556;
  12956. t['eight'] = 556;
  12957. t['nine'] = 556;
  12958. t['colon'] = 333;
  12959. t['semicolon'] = 333;
  12960. t['less'] = 584;
  12961. t['equal'] = 584;
  12962. t['greater'] = 584;
  12963. t['question'] = 611;
  12964. t['at'] = 975;
  12965. t['A'] = 722;
  12966. t['B'] = 722;
  12967. t['C'] = 722;
  12968. t['D'] = 722;
  12969. t['E'] = 667;
  12970. t['F'] = 611;
  12971. t['G'] = 778;
  12972. t['H'] = 722;
  12973. t['I'] = 278;
  12974. t['J'] = 556;
  12975. t['K'] = 722;
  12976. t['L'] = 611;
  12977. t['M'] = 833;
  12978. t['N'] = 722;
  12979. t['O'] = 778;
  12980. t['P'] = 667;
  12981. t['Q'] = 778;
  12982. t['R'] = 722;
  12983. t['S'] = 667;
  12984. t['T'] = 611;
  12985. t['U'] = 722;
  12986. t['V'] = 667;
  12987. t['W'] = 944;
  12988. t['X'] = 667;
  12989. t['Y'] = 667;
  12990. t['Z'] = 611;
  12991. t['bracketleft'] = 333;
  12992. t['backslash'] = 278;
  12993. t['bracketright'] = 333;
  12994. t['asciicircum'] = 584;
  12995. t['underscore'] = 556;
  12996. t['quoteleft'] = 278;
  12997. t['a'] = 556;
  12998. t['b'] = 611;
  12999. t['c'] = 556;
  13000. t['d'] = 611;
  13001. t['e'] = 556;
  13002. t['f'] = 333;
  13003. t['g'] = 611;
  13004. t['h'] = 611;
  13005. t['i'] = 278;
  13006. t['j'] = 278;
  13007. t['k'] = 556;
  13008. t['l'] = 278;
  13009. t['m'] = 889;
  13010. t['n'] = 611;
  13011. t['o'] = 611;
  13012. t['p'] = 611;
  13013. t['q'] = 611;
  13014. t['r'] = 389;
  13015. t['s'] = 556;
  13016. t['t'] = 333;
  13017. t['u'] = 611;
  13018. t['v'] = 556;
  13019. t['w'] = 778;
  13020. t['x'] = 556;
  13021. t['y'] = 556;
  13022. t['z'] = 500;
  13023. t['braceleft'] = 389;
  13024. t['bar'] = 280;
  13025. t['braceright'] = 389;
  13026. t['asciitilde'] = 584;
  13027. t['exclamdown'] = 333;
  13028. t['cent'] = 556;
  13029. t['sterling'] = 556;
  13030. t['fraction'] = 167;
  13031. t['yen'] = 556;
  13032. t['florin'] = 556;
  13033. t['section'] = 556;
  13034. t['currency'] = 556;
  13035. t['quotesingle'] = 238;
  13036. t['quotedblleft'] = 500;
  13037. t['guillemotleft'] = 556;
  13038. t['guilsinglleft'] = 333;
  13039. t['guilsinglright'] = 333;
  13040. t['fi'] = 611;
  13041. t['fl'] = 611;
  13042. t['endash'] = 556;
  13043. t['dagger'] = 556;
  13044. t['daggerdbl'] = 556;
  13045. t['periodcentered'] = 278;
  13046. t['paragraph'] = 556;
  13047. t['bullet'] = 350;
  13048. t['quotesinglbase'] = 278;
  13049. t['quotedblbase'] = 500;
  13050. t['quotedblright'] = 500;
  13051. t['guillemotright'] = 556;
  13052. t['ellipsis'] = 1000;
  13053. t['perthousand'] = 1000;
  13054. t['questiondown'] = 611;
  13055. t['grave'] = 333;
  13056. t['acute'] = 333;
  13057. t['circumflex'] = 333;
  13058. t['tilde'] = 333;
  13059. t['macron'] = 333;
  13060. t['breve'] = 333;
  13061. t['dotaccent'] = 333;
  13062. t['dieresis'] = 333;
  13063. t['ring'] = 333;
  13064. t['cedilla'] = 333;
  13065. t['hungarumlaut'] = 333;
  13066. t['ogonek'] = 333;
  13067. t['caron'] = 333;
  13068. t['emdash'] = 1000;
  13069. t['AE'] = 1000;
  13070. t['ordfeminine'] = 370;
  13071. t['Lslash'] = 611;
  13072. t['Oslash'] = 778;
  13073. t['OE'] = 1000;
  13074. t['ordmasculine'] = 365;
  13075. t['ae'] = 889;
  13076. t['dotlessi'] = 278;
  13077. t['lslash'] = 278;
  13078. t['oslash'] = 611;
  13079. t['oe'] = 944;
  13080. t['germandbls'] = 611;
  13081. t['Idieresis'] = 278;
  13082. t['eacute'] = 556;
  13083. t['abreve'] = 556;
  13084. t['uhungarumlaut'] = 611;
  13085. t['ecaron'] = 556;
  13086. t['Ydieresis'] = 667;
  13087. t['divide'] = 584;
  13088. t['Yacute'] = 667;
  13089. t['Acircumflex'] = 722;
  13090. t['aacute'] = 556;
  13091. t['Ucircumflex'] = 722;
  13092. t['yacute'] = 556;
  13093. t['scommaaccent'] = 556;
  13094. t['ecircumflex'] = 556;
  13095. t['Uring'] = 722;
  13096. t['Udieresis'] = 722;
  13097. t['aogonek'] = 556;
  13098. t['Uacute'] = 722;
  13099. t['uogonek'] = 611;
  13100. t['Edieresis'] = 667;
  13101. t['Dcroat'] = 722;
  13102. t['commaaccent'] = 250;
  13103. t['copyright'] = 737;
  13104. t['Emacron'] = 667;
  13105. t['ccaron'] = 556;
  13106. t['aring'] = 556;
  13107. t['Ncommaaccent'] = 722;
  13108. t['lacute'] = 278;
  13109. t['agrave'] = 556;
  13110. t['Tcommaaccent'] = 611;
  13111. t['Cacute'] = 722;
  13112. t['atilde'] = 556;
  13113. t['Edotaccent'] = 667;
  13114. t['scaron'] = 556;
  13115. t['scedilla'] = 556;
  13116. t['iacute'] = 278;
  13117. t['lozenge'] = 494;
  13118. t['Rcaron'] = 722;
  13119. t['Gcommaaccent'] = 778;
  13120. t['ucircumflex'] = 611;
  13121. t['acircumflex'] = 556;
  13122. t['Amacron'] = 722;
  13123. t['rcaron'] = 389;
  13124. t['ccedilla'] = 556;
  13125. t['Zdotaccent'] = 611;
  13126. t['Thorn'] = 667;
  13127. t['Omacron'] = 778;
  13128. t['Racute'] = 722;
  13129. t['Sacute'] = 667;
  13130. t['dcaron'] = 743;
  13131. t['Umacron'] = 722;
  13132. t['uring'] = 611;
  13133. t['threesuperior'] = 333;
  13134. t['Ograve'] = 778;
  13135. t['Agrave'] = 722;
  13136. t['Abreve'] = 722;
  13137. t['multiply'] = 584;
  13138. t['uacute'] = 611;
  13139. t['Tcaron'] = 611;
  13140. t['partialdiff'] = 494;
  13141. t['ydieresis'] = 556;
  13142. t['Nacute'] = 722;
  13143. t['icircumflex'] = 278;
  13144. t['Ecircumflex'] = 667;
  13145. t['adieresis'] = 556;
  13146. t['edieresis'] = 556;
  13147. t['cacute'] = 556;
  13148. t['nacute'] = 611;
  13149. t['umacron'] = 611;
  13150. t['Ncaron'] = 722;
  13151. t['Iacute'] = 278;
  13152. t['plusminus'] = 584;
  13153. t['brokenbar'] = 280;
  13154. t['registered'] = 737;
  13155. t['Gbreve'] = 778;
  13156. t['Idotaccent'] = 278;
  13157. t['summation'] = 600;
  13158. t['Egrave'] = 667;
  13159. t['racute'] = 389;
  13160. t['omacron'] = 611;
  13161. t['Zacute'] = 611;
  13162. t['Zcaron'] = 611;
  13163. t['greaterequal'] = 549;
  13164. t['Eth'] = 722;
  13165. t['Ccedilla'] = 722;
  13166. t['lcommaaccent'] = 278;
  13167. t['tcaron'] = 389;
  13168. t['eogonek'] = 556;
  13169. t['Uogonek'] = 722;
  13170. t['Aacute'] = 722;
  13171. t['Adieresis'] = 722;
  13172. t['egrave'] = 556;
  13173. t['zacute'] = 500;
  13174. t['iogonek'] = 278;
  13175. t['Oacute'] = 778;
  13176. t['oacute'] = 611;
  13177. t['amacron'] = 556;
  13178. t['sacute'] = 556;
  13179. t['idieresis'] = 278;
  13180. t['Ocircumflex'] = 778;
  13181. t['Ugrave'] = 722;
  13182. t['Delta'] = 612;
  13183. t['thorn'] = 611;
  13184. t['twosuperior'] = 333;
  13185. t['Odieresis'] = 778;
  13186. t['mu'] = 611;
  13187. t['igrave'] = 278;
  13188. t['ohungarumlaut'] = 611;
  13189. t['Eogonek'] = 667;
  13190. t['dcroat'] = 611;
  13191. t['threequarters'] = 834;
  13192. t['Scedilla'] = 667;
  13193. t['lcaron'] = 400;
  13194. t['Kcommaaccent'] = 722;
  13195. t['Lacute'] = 611;
  13196. t['trademark'] = 1000;
  13197. t['edotaccent'] = 556;
  13198. t['Igrave'] = 278;
  13199. t['Imacron'] = 278;
  13200. t['Lcaron'] = 611;
  13201. t['onehalf'] = 834;
  13202. t['lessequal'] = 549;
  13203. t['ocircumflex'] = 611;
  13204. t['ntilde'] = 611;
  13205. t['Uhungarumlaut'] = 722;
  13206. t['Eacute'] = 667;
  13207. t['emacron'] = 556;
  13208. t['gbreve'] = 611;
  13209. t['onequarter'] = 834;
  13210. t['Scaron'] = 667;
  13211. t['Scommaaccent'] = 667;
  13212. t['Ohungarumlaut'] = 778;
  13213. t['degree'] = 400;
  13214. t['ograve'] = 611;
  13215. t['Ccaron'] = 722;
  13216. t['ugrave'] = 611;
  13217. t['radical'] = 549;
  13218. t['Dcaron'] = 722;
  13219. t['rcommaaccent'] = 389;
  13220. t['Ntilde'] = 722;
  13221. t['otilde'] = 611;
  13222. t['Rcommaaccent'] = 722;
  13223. t['Lcommaaccent'] = 611;
  13224. t['Atilde'] = 722;
  13225. t['Aogonek'] = 722;
  13226. t['Aring'] = 722;
  13227. t['Otilde'] = 778;
  13228. t['zdotaccent'] = 500;
  13229. t['Ecaron'] = 667;
  13230. t['Iogonek'] = 278;
  13231. t['kcommaaccent'] = 556;
  13232. t['minus'] = 584;
  13233. t['Icircumflex'] = 278;
  13234. t['ncaron'] = 611;
  13235. t['tcommaaccent'] = 333;
  13236. t['logicalnot'] = 584;
  13237. t['odieresis'] = 611;
  13238. t['udieresis'] = 611;
  13239. t['notequal'] = 549;
  13240. t['gcommaaccent'] = 611;
  13241. t['eth'] = 611;
  13242. t['zcaron'] = 500;
  13243. t['ncommaaccent'] = 611;
  13244. t['onesuperior'] = 333;
  13245. t['imacron'] = 278;
  13246. t['Euro'] = 556;
  13247. });
  13248. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  13249. t['space'] = 278;
  13250. t['exclam'] = 278;
  13251. t['quotedbl'] = 355;
  13252. t['numbersign'] = 556;
  13253. t['dollar'] = 556;
  13254. t['percent'] = 889;
  13255. t['ampersand'] = 667;
  13256. t['quoteright'] = 222;
  13257. t['parenleft'] = 333;
  13258. t['parenright'] = 333;
  13259. t['asterisk'] = 389;
  13260. t['plus'] = 584;
  13261. t['comma'] = 278;
  13262. t['hyphen'] = 333;
  13263. t['period'] = 278;
  13264. t['slash'] = 278;
  13265. t['zero'] = 556;
  13266. t['one'] = 556;
  13267. t['two'] = 556;
  13268. t['three'] = 556;
  13269. t['four'] = 556;
  13270. t['five'] = 556;
  13271. t['six'] = 556;
  13272. t['seven'] = 556;
  13273. t['eight'] = 556;
  13274. t['nine'] = 556;
  13275. t['colon'] = 278;
  13276. t['semicolon'] = 278;
  13277. t['less'] = 584;
  13278. t['equal'] = 584;
  13279. t['greater'] = 584;
  13280. t['question'] = 556;
  13281. t['at'] = 1015;
  13282. t['A'] = 667;
  13283. t['B'] = 667;
  13284. t['C'] = 722;
  13285. t['D'] = 722;
  13286. t['E'] = 667;
  13287. t['F'] = 611;
  13288. t['G'] = 778;
  13289. t['H'] = 722;
  13290. t['I'] = 278;
  13291. t['J'] = 500;
  13292. t['K'] = 667;
  13293. t['L'] = 556;
  13294. t['M'] = 833;
  13295. t['N'] = 722;
  13296. t['O'] = 778;
  13297. t['P'] = 667;
  13298. t['Q'] = 778;
  13299. t['R'] = 722;
  13300. t['S'] = 667;
  13301. t['T'] = 611;
  13302. t['U'] = 722;
  13303. t['V'] = 667;
  13304. t['W'] = 944;
  13305. t['X'] = 667;
  13306. t['Y'] = 667;
  13307. t['Z'] = 611;
  13308. t['bracketleft'] = 278;
  13309. t['backslash'] = 278;
  13310. t['bracketright'] = 278;
  13311. t['asciicircum'] = 469;
  13312. t['underscore'] = 556;
  13313. t['quoteleft'] = 222;
  13314. t['a'] = 556;
  13315. t['b'] = 556;
  13316. t['c'] = 500;
  13317. t['d'] = 556;
  13318. t['e'] = 556;
  13319. t['f'] = 278;
  13320. t['g'] = 556;
  13321. t['h'] = 556;
  13322. t['i'] = 222;
  13323. t['j'] = 222;
  13324. t['k'] = 500;
  13325. t['l'] = 222;
  13326. t['m'] = 833;
  13327. t['n'] = 556;
  13328. t['o'] = 556;
  13329. t['p'] = 556;
  13330. t['q'] = 556;
  13331. t['r'] = 333;
  13332. t['s'] = 500;
  13333. t['t'] = 278;
  13334. t['u'] = 556;
  13335. t['v'] = 500;
  13336. t['w'] = 722;
  13337. t['x'] = 500;
  13338. t['y'] = 500;
  13339. t['z'] = 500;
  13340. t['braceleft'] = 334;
  13341. t['bar'] = 260;
  13342. t['braceright'] = 334;
  13343. t['asciitilde'] = 584;
  13344. t['exclamdown'] = 333;
  13345. t['cent'] = 556;
  13346. t['sterling'] = 556;
  13347. t['fraction'] = 167;
  13348. t['yen'] = 556;
  13349. t['florin'] = 556;
  13350. t['section'] = 556;
  13351. t['currency'] = 556;
  13352. t['quotesingle'] = 191;
  13353. t['quotedblleft'] = 333;
  13354. t['guillemotleft'] = 556;
  13355. t['guilsinglleft'] = 333;
  13356. t['guilsinglright'] = 333;
  13357. t['fi'] = 500;
  13358. t['fl'] = 500;
  13359. t['endash'] = 556;
  13360. t['dagger'] = 556;
  13361. t['daggerdbl'] = 556;
  13362. t['periodcentered'] = 278;
  13363. t['paragraph'] = 537;
  13364. t['bullet'] = 350;
  13365. t['quotesinglbase'] = 222;
  13366. t['quotedblbase'] = 333;
  13367. t['quotedblright'] = 333;
  13368. t['guillemotright'] = 556;
  13369. t['ellipsis'] = 1000;
  13370. t['perthousand'] = 1000;
  13371. t['questiondown'] = 611;
  13372. t['grave'] = 333;
  13373. t['acute'] = 333;
  13374. t['circumflex'] = 333;
  13375. t['tilde'] = 333;
  13376. t['macron'] = 333;
  13377. t['breve'] = 333;
  13378. t['dotaccent'] = 333;
  13379. t['dieresis'] = 333;
  13380. t['ring'] = 333;
  13381. t['cedilla'] = 333;
  13382. t['hungarumlaut'] = 333;
  13383. t['ogonek'] = 333;
  13384. t['caron'] = 333;
  13385. t['emdash'] = 1000;
  13386. t['AE'] = 1000;
  13387. t['ordfeminine'] = 370;
  13388. t['Lslash'] = 556;
  13389. t['Oslash'] = 778;
  13390. t['OE'] = 1000;
  13391. t['ordmasculine'] = 365;
  13392. t['ae'] = 889;
  13393. t['dotlessi'] = 278;
  13394. t['lslash'] = 222;
  13395. t['oslash'] = 611;
  13396. t['oe'] = 944;
  13397. t['germandbls'] = 611;
  13398. t['Idieresis'] = 278;
  13399. t['eacute'] = 556;
  13400. t['abreve'] = 556;
  13401. t['uhungarumlaut'] = 556;
  13402. t['ecaron'] = 556;
  13403. t['Ydieresis'] = 667;
  13404. t['divide'] = 584;
  13405. t['Yacute'] = 667;
  13406. t['Acircumflex'] = 667;
  13407. t['aacute'] = 556;
  13408. t['Ucircumflex'] = 722;
  13409. t['yacute'] = 500;
  13410. t['scommaaccent'] = 500;
  13411. t['ecircumflex'] = 556;
  13412. t['Uring'] = 722;
  13413. t['Udieresis'] = 722;
  13414. t['aogonek'] = 556;
  13415. t['Uacute'] = 722;
  13416. t['uogonek'] = 556;
  13417. t['Edieresis'] = 667;
  13418. t['Dcroat'] = 722;
  13419. t['commaaccent'] = 250;
  13420. t['copyright'] = 737;
  13421. t['Emacron'] = 667;
  13422. t['ccaron'] = 500;
  13423. t['aring'] = 556;
  13424. t['Ncommaaccent'] = 722;
  13425. t['lacute'] = 222;
  13426. t['agrave'] = 556;
  13427. t['Tcommaaccent'] = 611;
  13428. t['Cacute'] = 722;
  13429. t['atilde'] = 556;
  13430. t['Edotaccent'] = 667;
  13431. t['scaron'] = 500;
  13432. t['scedilla'] = 500;
  13433. t['iacute'] = 278;
  13434. t['lozenge'] = 471;
  13435. t['Rcaron'] = 722;
  13436. t['Gcommaaccent'] = 778;
  13437. t['ucircumflex'] = 556;
  13438. t['acircumflex'] = 556;
  13439. t['Amacron'] = 667;
  13440. t['rcaron'] = 333;
  13441. t['ccedilla'] = 500;
  13442. t['Zdotaccent'] = 611;
  13443. t['Thorn'] = 667;
  13444. t['Omacron'] = 778;
  13445. t['Racute'] = 722;
  13446. t['Sacute'] = 667;
  13447. t['dcaron'] = 643;
  13448. t['Umacron'] = 722;
  13449. t['uring'] = 556;
  13450. t['threesuperior'] = 333;
  13451. t['Ograve'] = 778;
  13452. t['Agrave'] = 667;
  13453. t['Abreve'] = 667;
  13454. t['multiply'] = 584;
  13455. t['uacute'] = 556;
  13456. t['Tcaron'] = 611;
  13457. t['partialdiff'] = 476;
  13458. t['ydieresis'] = 500;
  13459. t['Nacute'] = 722;
  13460. t['icircumflex'] = 278;
  13461. t['Ecircumflex'] = 667;
  13462. t['adieresis'] = 556;
  13463. t['edieresis'] = 556;
  13464. t['cacute'] = 500;
  13465. t['nacute'] = 556;
  13466. t['umacron'] = 556;
  13467. t['Ncaron'] = 722;
  13468. t['Iacute'] = 278;
  13469. t['plusminus'] = 584;
  13470. t['brokenbar'] = 260;
  13471. t['registered'] = 737;
  13472. t['Gbreve'] = 778;
  13473. t['Idotaccent'] = 278;
  13474. t['summation'] = 600;
  13475. t['Egrave'] = 667;
  13476. t['racute'] = 333;
  13477. t['omacron'] = 556;
  13478. t['Zacute'] = 611;
  13479. t['Zcaron'] = 611;
  13480. t['greaterequal'] = 549;
  13481. t['Eth'] = 722;
  13482. t['Ccedilla'] = 722;
  13483. t['lcommaaccent'] = 222;
  13484. t['tcaron'] = 317;
  13485. t['eogonek'] = 556;
  13486. t['Uogonek'] = 722;
  13487. t['Aacute'] = 667;
  13488. t['Adieresis'] = 667;
  13489. t['egrave'] = 556;
  13490. t['zacute'] = 500;
  13491. t['iogonek'] = 222;
  13492. t['Oacute'] = 778;
  13493. t['oacute'] = 556;
  13494. t['amacron'] = 556;
  13495. t['sacute'] = 500;
  13496. t['idieresis'] = 278;
  13497. t['Ocircumflex'] = 778;
  13498. t['Ugrave'] = 722;
  13499. t['Delta'] = 612;
  13500. t['thorn'] = 556;
  13501. t['twosuperior'] = 333;
  13502. t['Odieresis'] = 778;
  13503. t['mu'] = 556;
  13504. t['igrave'] = 278;
  13505. t['ohungarumlaut'] = 556;
  13506. t['Eogonek'] = 667;
  13507. t['dcroat'] = 556;
  13508. t['threequarters'] = 834;
  13509. t['Scedilla'] = 667;
  13510. t['lcaron'] = 299;
  13511. t['Kcommaaccent'] = 667;
  13512. t['Lacute'] = 556;
  13513. t['trademark'] = 1000;
  13514. t['edotaccent'] = 556;
  13515. t['Igrave'] = 278;
  13516. t['Imacron'] = 278;
  13517. t['Lcaron'] = 556;
  13518. t['onehalf'] = 834;
  13519. t['lessequal'] = 549;
  13520. t['ocircumflex'] = 556;
  13521. t['ntilde'] = 556;
  13522. t['Uhungarumlaut'] = 722;
  13523. t['Eacute'] = 667;
  13524. t['emacron'] = 556;
  13525. t['gbreve'] = 556;
  13526. t['onequarter'] = 834;
  13527. t['Scaron'] = 667;
  13528. t['Scommaaccent'] = 667;
  13529. t['Ohungarumlaut'] = 778;
  13530. t['degree'] = 400;
  13531. t['ograve'] = 556;
  13532. t['Ccaron'] = 722;
  13533. t['ugrave'] = 556;
  13534. t['radical'] = 453;
  13535. t['Dcaron'] = 722;
  13536. t['rcommaaccent'] = 333;
  13537. t['Ntilde'] = 722;
  13538. t['otilde'] = 556;
  13539. t['Rcommaaccent'] = 722;
  13540. t['Lcommaaccent'] = 556;
  13541. t['Atilde'] = 667;
  13542. t['Aogonek'] = 667;
  13543. t['Aring'] = 667;
  13544. t['Otilde'] = 778;
  13545. t['zdotaccent'] = 500;
  13546. t['Ecaron'] = 667;
  13547. t['Iogonek'] = 278;
  13548. t['kcommaaccent'] = 500;
  13549. t['minus'] = 584;
  13550. t['Icircumflex'] = 278;
  13551. t['ncaron'] = 556;
  13552. t['tcommaaccent'] = 278;
  13553. t['logicalnot'] = 584;
  13554. t['odieresis'] = 556;
  13555. t['udieresis'] = 556;
  13556. t['notequal'] = 549;
  13557. t['gcommaaccent'] = 556;
  13558. t['eth'] = 556;
  13559. t['zcaron'] = 500;
  13560. t['ncommaaccent'] = 556;
  13561. t['onesuperior'] = 333;
  13562. t['imacron'] = 278;
  13563. t['Euro'] = 556;
  13564. });
  13565. t['Symbol'] = getLookupTableFactory(function (t) {
  13566. t['space'] = 250;
  13567. t['exclam'] = 333;
  13568. t['universal'] = 713;
  13569. t['numbersign'] = 500;
  13570. t['existential'] = 549;
  13571. t['percent'] = 833;
  13572. t['ampersand'] = 778;
  13573. t['suchthat'] = 439;
  13574. t['parenleft'] = 333;
  13575. t['parenright'] = 333;
  13576. t['asteriskmath'] = 500;
  13577. t['plus'] = 549;
  13578. t['comma'] = 250;
  13579. t['minus'] = 549;
  13580. t['period'] = 250;
  13581. t['slash'] = 278;
  13582. t['zero'] = 500;
  13583. t['one'] = 500;
  13584. t['two'] = 500;
  13585. t['three'] = 500;
  13586. t['four'] = 500;
  13587. t['five'] = 500;
  13588. t['six'] = 500;
  13589. t['seven'] = 500;
  13590. t['eight'] = 500;
  13591. t['nine'] = 500;
  13592. t['colon'] = 278;
  13593. t['semicolon'] = 278;
  13594. t['less'] = 549;
  13595. t['equal'] = 549;
  13596. t['greater'] = 549;
  13597. t['question'] = 444;
  13598. t['congruent'] = 549;
  13599. t['Alpha'] = 722;
  13600. t['Beta'] = 667;
  13601. t['Chi'] = 722;
  13602. t['Delta'] = 612;
  13603. t['Epsilon'] = 611;
  13604. t['Phi'] = 763;
  13605. t['Gamma'] = 603;
  13606. t['Eta'] = 722;
  13607. t['Iota'] = 333;
  13608. t['theta1'] = 631;
  13609. t['Kappa'] = 722;
  13610. t['Lambda'] = 686;
  13611. t['Mu'] = 889;
  13612. t['Nu'] = 722;
  13613. t['Omicron'] = 722;
  13614. t['Pi'] = 768;
  13615. t['Theta'] = 741;
  13616. t['Rho'] = 556;
  13617. t['Sigma'] = 592;
  13618. t['Tau'] = 611;
  13619. t['Upsilon'] = 690;
  13620. t['sigma1'] = 439;
  13621. t['Omega'] = 768;
  13622. t['Xi'] = 645;
  13623. t['Psi'] = 795;
  13624. t['Zeta'] = 611;
  13625. t['bracketleft'] = 333;
  13626. t['therefore'] = 863;
  13627. t['bracketright'] = 333;
  13628. t['perpendicular'] = 658;
  13629. t['underscore'] = 500;
  13630. t['radicalex'] = 500;
  13631. t['alpha'] = 631;
  13632. t['beta'] = 549;
  13633. t['chi'] = 549;
  13634. t['delta'] = 494;
  13635. t['epsilon'] = 439;
  13636. t['phi'] = 521;
  13637. t['gamma'] = 411;
  13638. t['eta'] = 603;
  13639. t['iota'] = 329;
  13640. t['phi1'] = 603;
  13641. t['kappa'] = 549;
  13642. t['lambda'] = 549;
  13643. t['mu'] = 576;
  13644. t['nu'] = 521;
  13645. t['omicron'] = 549;
  13646. t['pi'] = 549;
  13647. t['theta'] = 521;
  13648. t['rho'] = 549;
  13649. t['sigma'] = 603;
  13650. t['tau'] = 439;
  13651. t['upsilon'] = 576;
  13652. t['omega1'] = 713;
  13653. t['omega'] = 686;
  13654. t['xi'] = 493;
  13655. t['psi'] = 686;
  13656. t['zeta'] = 494;
  13657. t['braceleft'] = 480;
  13658. t['bar'] = 200;
  13659. t['braceright'] = 480;
  13660. t['similar'] = 549;
  13661. t['Euro'] = 750;
  13662. t['Upsilon1'] = 620;
  13663. t['minute'] = 247;
  13664. t['lessequal'] = 549;
  13665. t['fraction'] = 167;
  13666. t['infinity'] = 713;
  13667. t['florin'] = 500;
  13668. t['club'] = 753;
  13669. t['diamond'] = 753;
  13670. t['heart'] = 753;
  13671. t['spade'] = 753;
  13672. t['arrowboth'] = 1042;
  13673. t['arrowleft'] = 987;
  13674. t['arrowup'] = 603;
  13675. t['arrowright'] = 987;
  13676. t['arrowdown'] = 603;
  13677. t['degree'] = 400;
  13678. t['plusminus'] = 549;
  13679. t['second'] = 411;
  13680. t['greaterequal'] = 549;
  13681. t['multiply'] = 549;
  13682. t['proportional'] = 713;
  13683. t['partialdiff'] = 494;
  13684. t['bullet'] = 460;
  13685. t['divide'] = 549;
  13686. t['notequal'] = 549;
  13687. t['equivalence'] = 549;
  13688. t['approxequal'] = 549;
  13689. t['ellipsis'] = 1000;
  13690. t['arrowvertex'] = 603;
  13691. t['arrowhorizex'] = 1000;
  13692. t['carriagereturn'] = 658;
  13693. t['aleph'] = 823;
  13694. t['Ifraktur'] = 686;
  13695. t['Rfraktur'] = 795;
  13696. t['weierstrass'] = 987;
  13697. t['circlemultiply'] = 768;
  13698. t['circleplus'] = 768;
  13699. t['emptyset'] = 823;
  13700. t['intersection'] = 768;
  13701. t['union'] = 768;
  13702. t['propersuperset'] = 713;
  13703. t['reflexsuperset'] = 713;
  13704. t['notsubset'] = 713;
  13705. t['propersubset'] = 713;
  13706. t['reflexsubset'] = 713;
  13707. t['element'] = 713;
  13708. t['notelement'] = 713;
  13709. t['angle'] = 768;
  13710. t['gradient'] = 713;
  13711. t['registerserif'] = 790;
  13712. t['copyrightserif'] = 790;
  13713. t['trademarkserif'] = 890;
  13714. t['product'] = 823;
  13715. t['radical'] = 549;
  13716. t['dotmath'] = 250;
  13717. t['logicalnot'] = 713;
  13718. t['logicaland'] = 603;
  13719. t['logicalor'] = 603;
  13720. t['arrowdblboth'] = 1042;
  13721. t['arrowdblleft'] = 987;
  13722. t['arrowdblup'] = 603;
  13723. t['arrowdblright'] = 987;
  13724. t['arrowdbldown'] = 603;
  13725. t['lozenge'] = 494;
  13726. t['angleleft'] = 329;
  13727. t['registersans'] = 790;
  13728. t['copyrightsans'] = 790;
  13729. t['trademarksans'] = 786;
  13730. t['summation'] = 713;
  13731. t['parenlefttp'] = 384;
  13732. t['parenleftex'] = 384;
  13733. t['parenleftbt'] = 384;
  13734. t['bracketlefttp'] = 384;
  13735. t['bracketleftex'] = 384;
  13736. t['bracketleftbt'] = 384;
  13737. t['bracelefttp'] = 494;
  13738. t['braceleftmid'] = 494;
  13739. t['braceleftbt'] = 494;
  13740. t['braceex'] = 494;
  13741. t['angleright'] = 329;
  13742. t['integral'] = 274;
  13743. t['integraltp'] = 686;
  13744. t['integralex'] = 686;
  13745. t['integralbt'] = 686;
  13746. t['parenrighttp'] = 384;
  13747. t['parenrightex'] = 384;
  13748. t['parenrightbt'] = 384;
  13749. t['bracketrighttp'] = 384;
  13750. t['bracketrightex'] = 384;
  13751. t['bracketrightbt'] = 384;
  13752. t['bracerighttp'] = 494;
  13753. t['bracerightmid'] = 494;
  13754. t['bracerightbt'] = 494;
  13755. t['apple'] = 790;
  13756. });
  13757. t['Times-Roman'] = getLookupTableFactory(function (t) {
  13758. t['space'] = 250;
  13759. t['exclam'] = 333;
  13760. t['quotedbl'] = 408;
  13761. t['numbersign'] = 500;
  13762. t['dollar'] = 500;
  13763. t['percent'] = 833;
  13764. t['ampersand'] = 778;
  13765. t['quoteright'] = 333;
  13766. t['parenleft'] = 333;
  13767. t['parenright'] = 333;
  13768. t['asterisk'] = 500;
  13769. t['plus'] = 564;
  13770. t['comma'] = 250;
  13771. t['hyphen'] = 333;
  13772. t['period'] = 250;
  13773. t['slash'] = 278;
  13774. t['zero'] = 500;
  13775. t['one'] = 500;
  13776. t['two'] = 500;
  13777. t['three'] = 500;
  13778. t['four'] = 500;
  13779. t['five'] = 500;
  13780. t['six'] = 500;
  13781. t['seven'] = 500;
  13782. t['eight'] = 500;
  13783. t['nine'] = 500;
  13784. t['colon'] = 278;
  13785. t['semicolon'] = 278;
  13786. t['less'] = 564;
  13787. t['equal'] = 564;
  13788. t['greater'] = 564;
  13789. t['question'] = 444;
  13790. t['at'] = 921;
  13791. t['A'] = 722;
  13792. t['B'] = 667;
  13793. t['C'] = 667;
  13794. t['D'] = 722;
  13795. t['E'] = 611;
  13796. t['F'] = 556;
  13797. t['G'] = 722;
  13798. t['H'] = 722;
  13799. t['I'] = 333;
  13800. t['J'] = 389;
  13801. t['K'] = 722;
  13802. t['L'] = 611;
  13803. t['M'] = 889;
  13804. t['N'] = 722;
  13805. t['O'] = 722;
  13806. t['P'] = 556;
  13807. t['Q'] = 722;
  13808. t['R'] = 667;
  13809. t['S'] = 556;
  13810. t['T'] = 611;
  13811. t['U'] = 722;
  13812. t['V'] = 722;
  13813. t['W'] = 944;
  13814. t['X'] = 722;
  13815. t['Y'] = 722;
  13816. t['Z'] = 611;
  13817. t['bracketleft'] = 333;
  13818. t['backslash'] = 278;
  13819. t['bracketright'] = 333;
  13820. t['asciicircum'] = 469;
  13821. t['underscore'] = 500;
  13822. t['quoteleft'] = 333;
  13823. t['a'] = 444;
  13824. t['b'] = 500;
  13825. t['c'] = 444;
  13826. t['d'] = 500;
  13827. t['e'] = 444;
  13828. t['f'] = 333;
  13829. t['g'] = 500;
  13830. t['h'] = 500;
  13831. t['i'] = 278;
  13832. t['j'] = 278;
  13833. t['k'] = 500;
  13834. t['l'] = 278;
  13835. t['m'] = 778;
  13836. t['n'] = 500;
  13837. t['o'] = 500;
  13838. t['p'] = 500;
  13839. t['q'] = 500;
  13840. t['r'] = 333;
  13841. t['s'] = 389;
  13842. t['t'] = 278;
  13843. t['u'] = 500;
  13844. t['v'] = 500;
  13845. t['w'] = 722;
  13846. t['x'] = 500;
  13847. t['y'] = 500;
  13848. t['z'] = 444;
  13849. t['braceleft'] = 480;
  13850. t['bar'] = 200;
  13851. t['braceright'] = 480;
  13852. t['asciitilde'] = 541;
  13853. t['exclamdown'] = 333;
  13854. t['cent'] = 500;
  13855. t['sterling'] = 500;
  13856. t['fraction'] = 167;
  13857. t['yen'] = 500;
  13858. t['florin'] = 500;
  13859. t['section'] = 500;
  13860. t['currency'] = 500;
  13861. t['quotesingle'] = 180;
  13862. t['quotedblleft'] = 444;
  13863. t['guillemotleft'] = 500;
  13864. t['guilsinglleft'] = 333;
  13865. t['guilsinglright'] = 333;
  13866. t['fi'] = 556;
  13867. t['fl'] = 556;
  13868. t['endash'] = 500;
  13869. t['dagger'] = 500;
  13870. t['daggerdbl'] = 500;
  13871. t['periodcentered'] = 250;
  13872. t['paragraph'] = 453;
  13873. t['bullet'] = 350;
  13874. t['quotesinglbase'] = 333;
  13875. t['quotedblbase'] = 444;
  13876. t['quotedblright'] = 444;
  13877. t['guillemotright'] = 500;
  13878. t['ellipsis'] = 1000;
  13879. t['perthousand'] = 1000;
  13880. t['questiondown'] = 444;
  13881. t['grave'] = 333;
  13882. t['acute'] = 333;
  13883. t['circumflex'] = 333;
  13884. t['tilde'] = 333;
  13885. t['macron'] = 333;
  13886. t['breve'] = 333;
  13887. t['dotaccent'] = 333;
  13888. t['dieresis'] = 333;
  13889. t['ring'] = 333;
  13890. t['cedilla'] = 333;
  13891. t['hungarumlaut'] = 333;
  13892. t['ogonek'] = 333;
  13893. t['caron'] = 333;
  13894. t['emdash'] = 1000;
  13895. t['AE'] = 889;
  13896. t['ordfeminine'] = 276;
  13897. t['Lslash'] = 611;
  13898. t['Oslash'] = 722;
  13899. t['OE'] = 889;
  13900. t['ordmasculine'] = 310;
  13901. t['ae'] = 667;
  13902. t['dotlessi'] = 278;
  13903. t['lslash'] = 278;
  13904. t['oslash'] = 500;
  13905. t['oe'] = 722;
  13906. t['germandbls'] = 500;
  13907. t['Idieresis'] = 333;
  13908. t['eacute'] = 444;
  13909. t['abreve'] = 444;
  13910. t['uhungarumlaut'] = 500;
  13911. t['ecaron'] = 444;
  13912. t['Ydieresis'] = 722;
  13913. t['divide'] = 564;
  13914. t['Yacute'] = 722;
  13915. t['Acircumflex'] = 722;
  13916. t['aacute'] = 444;
  13917. t['Ucircumflex'] = 722;
  13918. t['yacute'] = 500;
  13919. t['scommaaccent'] = 389;
  13920. t['ecircumflex'] = 444;
  13921. t['Uring'] = 722;
  13922. t['Udieresis'] = 722;
  13923. t['aogonek'] = 444;
  13924. t['Uacute'] = 722;
  13925. t['uogonek'] = 500;
  13926. t['Edieresis'] = 611;
  13927. t['Dcroat'] = 722;
  13928. t['commaaccent'] = 250;
  13929. t['copyright'] = 760;
  13930. t['Emacron'] = 611;
  13931. t['ccaron'] = 444;
  13932. t['aring'] = 444;
  13933. t['Ncommaaccent'] = 722;
  13934. t['lacute'] = 278;
  13935. t['agrave'] = 444;
  13936. t['Tcommaaccent'] = 611;
  13937. t['Cacute'] = 667;
  13938. t['atilde'] = 444;
  13939. t['Edotaccent'] = 611;
  13940. t['scaron'] = 389;
  13941. t['scedilla'] = 389;
  13942. t['iacute'] = 278;
  13943. t['lozenge'] = 471;
  13944. t['Rcaron'] = 667;
  13945. t['Gcommaaccent'] = 722;
  13946. t['ucircumflex'] = 500;
  13947. t['acircumflex'] = 444;
  13948. t['Amacron'] = 722;
  13949. t['rcaron'] = 333;
  13950. t['ccedilla'] = 444;
  13951. t['Zdotaccent'] = 611;
  13952. t['Thorn'] = 556;
  13953. t['Omacron'] = 722;
  13954. t['Racute'] = 667;
  13955. t['Sacute'] = 556;
  13956. t['dcaron'] = 588;
  13957. t['Umacron'] = 722;
  13958. t['uring'] = 500;
  13959. t['threesuperior'] = 300;
  13960. t['Ograve'] = 722;
  13961. t['Agrave'] = 722;
  13962. t['Abreve'] = 722;
  13963. t['multiply'] = 564;
  13964. t['uacute'] = 500;
  13965. t['Tcaron'] = 611;
  13966. t['partialdiff'] = 476;
  13967. t['ydieresis'] = 500;
  13968. t['Nacute'] = 722;
  13969. t['icircumflex'] = 278;
  13970. t['Ecircumflex'] = 611;
  13971. t['adieresis'] = 444;
  13972. t['edieresis'] = 444;
  13973. t['cacute'] = 444;
  13974. t['nacute'] = 500;
  13975. t['umacron'] = 500;
  13976. t['Ncaron'] = 722;
  13977. t['Iacute'] = 333;
  13978. t['plusminus'] = 564;
  13979. t['brokenbar'] = 200;
  13980. t['registered'] = 760;
  13981. t['Gbreve'] = 722;
  13982. t['Idotaccent'] = 333;
  13983. t['summation'] = 600;
  13984. t['Egrave'] = 611;
  13985. t['racute'] = 333;
  13986. t['omacron'] = 500;
  13987. t['Zacute'] = 611;
  13988. t['Zcaron'] = 611;
  13989. t['greaterequal'] = 549;
  13990. t['Eth'] = 722;
  13991. t['Ccedilla'] = 667;
  13992. t['lcommaaccent'] = 278;
  13993. t['tcaron'] = 326;
  13994. t['eogonek'] = 444;
  13995. t['Uogonek'] = 722;
  13996. t['Aacute'] = 722;
  13997. t['Adieresis'] = 722;
  13998. t['egrave'] = 444;
  13999. t['zacute'] = 444;
  14000. t['iogonek'] = 278;
  14001. t['Oacute'] = 722;
  14002. t['oacute'] = 500;
  14003. t['amacron'] = 444;
  14004. t['sacute'] = 389;
  14005. t['idieresis'] = 278;
  14006. t['Ocircumflex'] = 722;
  14007. t['Ugrave'] = 722;
  14008. t['Delta'] = 612;
  14009. t['thorn'] = 500;
  14010. t['twosuperior'] = 300;
  14011. t['Odieresis'] = 722;
  14012. t['mu'] = 500;
  14013. t['igrave'] = 278;
  14014. t['ohungarumlaut'] = 500;
  14015. t['Eogonek'] = 611;
  14016. t['dcroat'] = 500;
  14017. t['threequarters'] = 750;
  14018. t['Scedilla'] = 556;
  14019. t['lcaron'] = 344;
  14020. t['Kcommaaccent'] = 722;
  14021. t['Lacute'] = 611;
  14022. t['trademark'] = 980;
  14023. t['edotaccent'] = 444;
  14024. t['Igrave'] = 333;
  14025. t['Imacron'] = 333;
  14026. t['Lcaron'] = 611;
  14027. t['onehalf'] = 750;
  14028. t['lessequal'] = 549;
  14029. t['ocircumflex'] = 500;
  14030. t['ntilde'] = 500;
  14031. t['Uhungarumlaut'] = 722;
  14032. t['Eacute'] = 611;
  14033. t['emacron'] = 444;
  14034. t['gbreve'] = 500;
  14035. t['onequarter'] = 750;
  14036. t['Scaron'] = 556;
  14037. t['Scommaaccent'] = 556;
  14038. t['Ohungarumlaut'] = 722;
  14039. t['degree'] = 400;
  14040. t['ograve'] = 500;
  14041. t['Ccaron'] = 667;
  14042. t['ugrave'] = 500;
  14043. t['radical'] = 453;
  14044. t['Dcaron'] = 722;
  14045. t['rcommaaccent'] = 333;
  14046. t['Ntilde'] = 722;
  14047. t['otilde'] = 500;
  14048. t['Rcommaaccent'] = 667;
  14049. t['Lcommaaccent'] = 611;
  14050. t['Atilde'] = 722;
  14051. t['Aogonek'] = 722;
  14052. t['Aring'] = 722;
  14053. t['Otilde'] = 722;
  14054. t['zdotaccent'] = 444;
  14055. t['Ecaron'] = 611;
  14056. t['Iogonek'] = 333;
  14057. t['kcommaaccent'] = 500;
  14058. t['minus'] = 564;
  14059. t['Icircumflex'] = 333;
  14060. t['ncaron'] = 500;
  14061. t['tcommaaccent'] = 278;
  14062. t['logicalnot'] = 564;
  14063. t['odieresis'] = 500;
  14064. t['udieresis'] = 500;
  14065. t['notequal'] = 549;
  14066. t['gcommaaccent'] = 500;
  14067. t['eth'] = 500;
  14068. t['zcaron'] = 444;
  14069. t['ncommaaccent'] = 500;
  14070. t['onesuperior'] = 300;
  14071. t['imacron'] = 278;
  14072. t['Euro'] = 500;
  14073. });
  14074. t['Times-Bold'] = getLookupTableFactory(function (t) {
  14075. t['space'] = 250;
  14076. t['exclam'] = 333;
  14077. t['quotedbl'] = 555;
  14078. t['numbersign'] = 500;
  14079. t['dollar'] = 500;
  14080. t['percent'] = 1000;
  14081. t['ampersand'] = 833;
  14082. t['quoteright'] = 333;
  14083. t['parenleft'] = 333;
  14084. t['parenright'] = 333;
  14085. t['asterisk'] = 500;
  14086. t['plus'] = 570;
  14087. t['comma'] = 250;
  14088. t['hyphen'] = 333;
  14089. t['period'] = 250;
  14090. t['slash'] = 278;
  14091. t['zero'] = 500;
  14092. t['one'] = 500;
  14093. t['two'] = 500;
  14094. t['three'] = 500;
  14095. t['four'] = 500;
  14096. t['five'] = 500;
  14097. t['six'] = 500;
  14098. t['seven'] = 500;
  14099. t['eight'] = 500;
  14100. t['nine'] = 500;
  14101. t['colon'] = 333;
  14102. t['semicolon'] = 333;
  14103. t['less'] = 570;
  14104. t['equal'] = 570;
  14105. t['greater'] = 570;
  14106. t['question'] = 500;
  14107. t['at'] = 930;
  14108. t['A'] = 722;
  14109. t['B'] = 667;
  14110. t['C'] = 722;
  14111. t['D'] = 722;
  14112. t['E'] = 667;
  14113. t['F'] = 611;
  14114. t['G'] = 778;
  14115. t['H'] = 778;
  14116. t['I'] = 389;
  14117. t['J'] = 500;
  14118. t['K'] = 778;
  14119. t['L'] = 667;
  14120. t['M'] = 944;
  14121. t['N'] = 722;
  14122. t['O'] = 778;
  14123. t['P'] = 611;
  14124. t['Q'] = 778;
  14125. t['R'] = 722;
  14126. t['S'] = 556;
  14127. t['T'] = 667;
  14128. t['U'] = 722;
  14129. t['V'] = 722;
  14130. t['W'] = 1000;
  14131. t['X'] = 722;
  14132. t['Y'] = 722;
  14133. t['Z'] = 667;
  14134. t['bracketleft'] = 333;
  14135. t['backslash'] = 278;
  14136. t['bracketright'] = 333;
  14137. t['asciicircum'] = 581;
  14138. t['underscore'] = 500;
  14139. t['quoteleft'] = 333;
  14140. t['a'] = 500;
  14141. t['b'] = 556;
  14142. t['c'] = 444;
  14143. t['d'] = 556;
  14144. t['e'] = 444;
  14145. t['f'] = 333;
  14146. t['g'] = 500;
  14147. t['h'] = 556;
  14148. t['i'] = 278;
  14149. t['j'] = 333;
  14150. t['k'] = 556;
  14151. t['l'] = 278;
  14152. t['m'] = 833;
  14153. t['n'] = 556;
  14154. t['o'] = 500;
  14155. t['p'] = 556;
  14156. t['q'] = 556;
  14157. t['r'] = 444;
  14158. t['s'] = 389;
  14159. t['t'] = 333;
  14160. t['u'] = 556;
  14161. t['v'] = 500;
  14162. t['w'] = 722;
  14163. t['x'] = 500;
  14164. t['y'] = 500;
  14165. t['z'] = 444;
  14166. t['braceleft'] = 394;
  14167. t['bar'] = 220;
  14168. t['braceright'] = 394;
  14169. t['asciitilde'] = 520;
  14170. t['exclamdown'] = 333;
  14171. t['cent'] = 500;
  14172. t['sterling'] = 500;
  14173. t['fraction'] = 167;
  14174. t['yen'] = 500;
  14175. t['florin'] = 500;
  14176. t['section'] = 500;
  14177. t['currency'] = 500;
  14178. t['quotesingle'] = 278;
  14179. t['quotedblleft'] = 500;
  14180. t['guillemotleft'] = 500;
  14181. t['guilsinglleft'] = 333;
  14182. t['guilsinglright'] = 333;
  14183. t['fi'] = 556;
  14184. t['fl'] = 556;
  14185. t['endash'] = 500;
  14186. t['dagger'] = 500;
  14187. t['daggerdbl'] = 500;
  14188. t['periodcentered'] = 250;
  14189. t['paragraph'] = 540;
  14190. t['bullet'] = 350;
  14191. t['quotesinglbase'] = 333;
  14192. t['quotedblbase'] = 500;
  14193. t['quotedblright'] = 500;
  14194. t['guillemotright'] = 500;
  14195. t['ellipsis'] = 1000;
  14196. t['perthousand'] = 1000;
  14197. t['questiondown'] = 500;
  14198. t['grave'] = 333;
  14199. t['acute'] = 333;
  14200. t['circumflex'] = 333;
  14201. t['tilde'] = 333;
  14202. t['macron'] = 333;
  14203. t['breve'] = 333;
  14204. t['dotaccent'] = 333;
  14205. t['dieresis'] = 333;
  14206. t['ring'] = 333;
  14207. t['cedilla'] = 333;
  14208. t['hungarumlaut'] = 333;
  14209. t['ogonek'] = 333;
  14210. t['caron'] = 333;
  14211. t['emdash'] = 1000;
  14212. t['AE'] = 1000;
  14213. t['ordfeminine'] = 300;
  14214. t['Lslash'] = 667;
  14215. t['Oslash'] = 778;
  14216. t['OE'] = 1000;
  14217. t['ordmasculine'] = 330;
  14218. t['ae'] = 722;
  14219. t['dotlessi'] = 278;
  14220. t['lslash'] = 278;
  14221. t['oslash'] = 500;
  14222. t['oe'] = 722;
  14223. t['germandbls'] = 556;
  14224. t['Idieresis'] = 389;
  14225. t['eacute'] = 444;
  14226. t['abreve'] = 500;
  14227. t['uhungarumlaut'] = 556;
  14228. t['ecaron'] = 444;
  14229. t['Ydieresis'] = 722;
  14230. t['divide'] = 570;
  14231. t['Yacute'] = 722;
  14232. t['Acircumflex'] = 722;
  14233. t['aacute'] = 500;
  14234. t['Ucircumflex'] = 722;
  14235. t['yacute'] = 500;
  14236. t['scommaaccent'] = 389;
  14237. t['ecircumflex'] = 444;
  14238. t['Uring'] = 722;
  14239. t['Udieresis'] = 722;
  14240. t['aogonek'] = 500;
  14241. t['Uacute'] = 722;
  14242. t['uogonek'] = 556;
  14243. t['Edieresis'] = 667;
  14244. t['Dcroat'] = 722;
  14245. t['commaaccent'] = 250;
  14246. t['copyright'] = 747;
  14247. t['Emacron'] = 667;
  14248. t['ccaron'] = 444;
  14249. t['aring'] = 500;
  14250. t['Ncommaaccent'] = 722;
  14251. t['lacute'] = 278;
  14252. t['agrave'] = 500;
  14253. t['Tcommaaccent'] = 667;
  14254. t['Cacute'] = 722;
  14255. t['atilde'] = 500;
  14256. t['Edotaccent'] = 667;
  14257. t['scaron'] = 389;
  14258. t['scedilla'] = 389;
  14259. t['iacute'] = 278;
  14260. t['lozenge'] = 494;
  14261. t['Rcaron'] = 722;
  14262. t['Gcommaaccent'] = 778;
  14263. t['ucircumflex'] = 556;
  14264. t['acircumflex'] = 500;
  14265. t['Amacron'] = 722;
  14266. t['rcaron'] = 444;
  14267. t['ccedilla'] = 444;
  14268. t['Zdotaccent'] = 667;
  14269. t['Thorn'] = 611;
  14270. t['Omacron'] = 778;
  14271. t['Racute'] = 722;
  14272. t['Sacute'] = 556;
  14273. t['dcaron'] = 672;
  14274. t['Umacron'] = 722;
  14275. t['uring'] = 556;
  14276. t['threesuperior'] = 300;
  14277. t['Ograve'] = 778;
  14278. t['Agrave'] = 722;
  14279. t['Abreve'] = 722;
  14280. t['multiply'] = 570;
  14281. t['uacute'] = 556;
  14282. t['Tcaron'] = 667;
  14283. t['partialdiff'] = 494;
  14284. t['ydieresis'] = 500;
  14285. t['Nacute'] = 722;
  14286. t['icircumflex'] = 278;
  14287. t['Ecircumflex'] = 667;
  14288. t['adieresis'] = 500;
  14289. t['edieresis'] = 444;
  14290. t['cacute'] = 444;
  14291. t['nacute'] = 556;
  14292. t['umacron'] = 556;
  14293. t['Ncaron'] = 722;
  14294. t['Iacute'] = 389;
  14295. t['plusminus'] = 570;
  14296. t['brokenbar'] = 220;
  14297. t['registered'] = 747;
  14298. t['Gbreve'] = 778;
  14299. t['Idotaccent'] = 389;
  14300. t['summation'] = 600;
  14301. t['Egrave'] = 667;
  14302. t['racute'] = 444;
  14303. t['omacron'] = 500;
  14304. t['Zacute'] = 667;
  14305. t['Zcaron'] = 667;
  14306. t['greaterequal'] = 549;
  14307. t['Eth'] = 722;
  14308. t['Ccedilla'] = 722;
  14309. t['lcommaaccent'] = 278;
  14310. t['tcaron'] = 416;
  14311. t['eogonek'] = 444;
  14312. t['Uogonek'] = 722;
  14313. t['Aacute'] = 722;
  14314. t['Adieresis'] = 722;
  14315. t['egrave'] = 444;
  14316. t['zacute'] = 444;
  14317. t['iogonek'] = 278;
  14318. t['Oacute'] = 778;
  14319. t['oacute'] = 500;
  14320. t['amacron'] = 500;
  14321. t['sacute'] = 389;
  14322. t['idieresis'] = 278;
  14323. t['Ocircumflex'] = 778;
  14324. t['Ugrave'] = 722;
  14325. t['Delta'] = 612;
  14326. t['thorn'] = 556;
  14327. t['twosuperior'] = 300;
  14328. t['Odieresis'] = 778;
  14329. t['mu'] = 556;
  14330. t['igrave'] = 278;
  14331. t['ohungarumlaut'] = 500;
  14332. t['Eogonek'] = 667;
  14333. t['dcroat'] = 556;
  14334. t['threequarters'] = 750;
  14335. t['Scedilla'] = 556;
  14336. t['lcaron'] = 394;
  14337. t['Kcommaaccent'] = 778;
  14338. t['Lacute'] = 667;
  14339. t['trademark'] = 1000;
  14340. t['edotaccent'] = 444;
  14341. t['Igrave'] = 389;
  14342. t['Imacron'] = 389;
  14343. t['Lcaron'] = 667;
  14344. t['onehalf'] = 750;
  14345. t['lessequal'] = 549;
  14346. t['ocircumflex'] = 500;
  14347. t['ntilde'] = 556;
  14348. t['Uhungarumlaut'] = 722;
  14349. t['Eacute'] = 667;
  14350. t['emacron'] = 444;
  14351. t['gbreve'] = 500;
  14352. t['onequarter'] = 750;
  14353. t['Scaron'] = 556;
  14354. t['Scommaaccent'] = 556;
  14355. t['Ohungarumlaut'] = 778;
  14356. t['degree'] = 400;
  14357. t['ograve'] = 500;
  14358. t['Ccaron'] = 722;
  14359. t['ugrave'] = 556;
  14360. t['radical'] = 549;
  14361. t['Dcaron'] = 722;
  14362. t['rcommaaccent'] = 444;
  14363. t['Ntilde'] = 722;
  14364. t['otilde'] = 500;
  14365. t['Rcommaaccent'] = 722;
  14366. t['Lcommaaccent'] = 667;
  14367. t['Atilde'] = 722;
  14368. t['Aogonek'] = 722;
  14369. t['Aring'] = 722;
  14370. t['Otilde'] = 778;
  14371. t['zdotaccent'] = 444;
  14372. t['Ecaron'] = 667;
  14373. t['Iogonek'] = 389;
  14374. t['kcommaaccent'] = 556;
  14375. t['minus'] = 570;
  14376. t['Icircumflex'] = 389;
  14377. t['ncaron'] = 556;
  14378. t['tcommaaccent'] = 333;
  14379. t['logicalnot'] = 570;
  14380. t['odieresis'] = 500;
  14381. t['udieresis'] = 556;
  14382. t['notequal'] = 549;
  14383. t['gcommaaccent'] = 500;
  14384. t['eth'] = 500;
  14385. t['zcaron'] = 444;
  14386. t['ncommaaccent'] = 556;
  14387. t['onesuperior'] = 300;
  14388. t['imacron'] = 278;
  14389. t['Euro'] = 500;
  14390. });
  14391. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  14392. t['space'] = 250;
  14393. t['exclam'] = 389;
  14394. t['quotedbl'] = 555;
  14395. t['numbersign'] = 500;
  14396. t['dollar'] = 500;
  14397. t['percent'] = 833;
  14398. t['ampersand'] = 778;
  14399. t['quoteright'] = 333;
  14400. t['parenleft'] = 333;
  14401. t['parenright'] = 333;
  14402. t['asterisk'] = 500;
  14403. t['plus'] = 570;
  14404. t['comma'] = 250;
  14405. t['hyphen'] = 333;
  14406. t['period'] = 250;
  14407. t['slash'] = 278;
  14408. t['zero'] = 500;
  14409. t['one'] = 500;
  14410. t['two'] = 500;
  14411. t['three'] = 500;
  14412. t['four'] = 500;
  14413. t['five'] = 500;
  14414. t['six'] = 500;
  14415. t['seven'] = 500;
  14416. t['eight'] = 500;
  14417. t['nine'] = 500;
  14418. t['colon'] = 333;
  14419. t['semicolon'] = 333;
  14420. t['less'] = 570;
  14421. t['equal'] = 570;
  14422. t['greater'] = 570;
  14423. t['question'] = 500;
  14424. t['at'] = 832;
  14425. t['A'] = 667;
  14426. t['B'] = 667;
  14427. t['C'] = 667;
  14428. t['D'] = 722;
  14429. t['E'] = 667;
  14430. t['F'] = 667;
  14431. t['G'] = 722;
  14432. t['H'] = 778;
  14433. t['I'] = 389;
  14434. t['J'] = 500;
  14435. t['K'] = 667;
  14436. t['L'] = 611;
  14437. t['M'] = 889;
  14438. t['N'] = 722;
  14439. t['O'] = 722;
  14440. t['P'] = 611;
  14441. t['Q'] = 722;
  14442. t['R'] = 667;
  14443. t['S'] = 556;
  14444. t['T'] = 611;
  14445. t['U'] = 722;
  14446. t['V'] = 667;
  14447. t['W'] = 889;
  14448. t['X'] = 667;
  14449. t['Y'] = 611;
  14450. t['Z'] = 611;
  14451. t['bracketleft'] = 333;
  14452. t['backslash'] = 278;
  14453. t['bracketright'] = 333;
  14454. t['asciicircum'] = 570;
  14455. t['underscore'] = 500;
  14456. t['quoteleft'] = 333;
  14457. t['a'] = 500;
  14458. t['b'] = 500;
  14459. t['c'] = 444;
  14460. t['d'] = 500;
  14461. t['e'] = 444;
  14462. t['f'] = 333;
  14463. t['g'] = 500;
  14464. t['h'] = 556;
  14465. t['i'] = 278;
  14466. t['j'] = 278;
  14467. t['k'] = 500;
  14468. t['l'] = 278;
  14469. t['m'] = 778;
  14470. t['n'] = 556;
  14471. t['o'] = 500;
  14472. t['p'] = 500;
  14473. t['q'] = 500;
  14474. t['r'] = 389;
  14475. t['s'] = 389;
  14476. t['t'] = 278;
  14477. t['u'] = 556;
  14478. t['v'] = 444;
  14479. t['w'] = 667;
  14480. t['x'] = 500;
  14481. t['y'] = 444;
  14482. t['z'] = 389;
  14483. t['braceleft'] = 348;
  14484. t['bar'] = 220;
  14485. t['braceright'] = 348;
  14486. t['asciitilde'] = 570;
  14487. t['exclamdown'] = 389;
  14488. t['cent'] = 500;
  14489. t['sterling'] = 500;
  14490. t['fraction'] = 167;
  14491. t['yen'] = 500;
  14492. t['florin'] = 500;
  14493. t['section'] = 500;
  14494. t['currency'] = 500;
  14495. t['quotesingle'] = 278;
  14496. t['quotedblleft'] = 500;
  14497. t['guillemotleft'] = 500;
  14498. t['guilsinglleft'] = 333;
  14499. t['guilsinglright'] = 333;
  14500. t['fi'] = 556;
  14501. t['fl'] = 556;
  14502. t['endash'] = 500;
  14503. t['dagger'] = 500;
  14504. t['daggerdbl'] = 500;
  14505. t['periodcentered'] = 250;
  14506. t['paragraph'] = 500;
  14507. t['bullet'] = 350;
  14508. t['quotesinglbase'] = 333;
  14509. t['quotedblbase'] = 500;
  14510. t['quotedblright'] = 500;
  14511. t['guillemotright'] = 500;
  14512. t['ellipsis'] = 1000;
  14513. t['perthousand'] = 1000;
  14514. t['questiondown'] = 500;
  14515. t['grave'] = 333;
  14516. t['acute'] = 333;
  14517. t['circumflex'] = 333;
  14518. t['tilde'] = 333;
  14519. t['macron'] = 333;
  14520. t['breve'] = 333;
  14521. t['dotaccent'] = 333;
  14522. t['dieresis'] = 333;
  14523. t['ring'] = 333;
  14524. t['cedilla'] = 333;
  14525. t['hungarumlaut'] = 333;
  14526. t['ogonek'] = 333;
  14527. t['caron'] = 333;
  14528. t['emdash'] = 1000;
  14529. t['AE'] = 944;
  14530. t['ordfeminine'] = 266;
  14531. t['Lslash'] = 611;
  14532. t['Oslash'] = 722;
  14533. t['OE'] = 944;
  14534. t['ordmasculine'] = 300;
  14535. t['ae'] = 722;
  14536. t['dotlessi'] = 278;
  14537. t['lslash'] = 278;
  14538. t['oslash'] = 500;
  14539. t['oe'] = 722;
  14540. t['germandbls'] = 500;
  14541. t['Idieresis'] = 389;
  14542. t['eacute'] = 444;
  14543. t['abreve'] = 500;
  14544. t['uhungarumlaut'] = 556;
  14545. t['ecaron'] = 444;
  14546. t['Ydieresis'] = 611;
  14547. t['divide'] = 570;
  14548. t['Yacute'] = 611;
  14549. t['Acircumflex'] = 667;
  14550. t['aacute'] = 500;
  14551. t['Ucircumflex'] = 722;
  14552. t['yacute'] = 444;
  14553. t['scommaaccent'] = 389;
  14554. t['ecircumflex'] = 444;
  14555. t['Uring'] = 722;
  14556. t['Udieresis'] = 722;
  14557. t['aogonek'] = 500;
  14558. t['Uacute'] = 722;
  14559. t['uogonek'] = 556;
  14560. t['Edieresis'] = 667;
  14561. t['Dcroat'] = 722;
  14562. t['commaaccent'] = 250;
  14563. t['copyright'] = 747;
  14564. t['Emacron'] = 667;
  14565. t['ccaron'] = 444;
  14566. t['aring'] = 500;
  14567. t['Ncommaaccent'] = 722;
  14568. t['lacute'] = 278;
  14569. t['agrave'] = 500;
  14570. t['Tcommaaccent'] = 611;
  14571. t['Cacute'] = 667;
  14572. t['atilde'] = 500;
  14573. t['Edotaccent'] = 667;
  14574. t['scaron'] = 389;
  14575. t['scedilla'] = 389;
  14576. t['iacute'] = 278;
  14577. t['lozenge'] = 494;
  14578. t['Rcaron'] = 667;
  14579. t['Gcommaaccent'] = 722;
  14580. t['ucircumflex'] = 556;
  14581. t['acircumflex'] = 500;
  14582. t['Amacron'] = 667;
  14583. t['rcaron'] = 389;
  14584. t['ccedilla'] = 444;
  14585. t['Zdotaccent'] = 611;
  14586. t['Thorn'] = 611;
  14587. t['Omacron'] = 722;
  14588. t['Racute'] = 667;
  14589. t['Sacute'] = 556;
  14590. t['dcaron'] = 608;
  14591. t['Umacron'] = 722;
  14592. t['uring'] = 556;
  14593. t['threesuperior'] = 300;
  14594. t['Ograve'] = 722;
  14595. t['Agrave'] = 667;
  14596. t['Abreve'] = 667;
  14597. t['multiply'] = 570;
  14598. t['uacute'] = 556;
  14599. t['Tcaron'] = 611;
  14600. t['partialdiff'] = 494;
  14601. t['ydieresis'] = 444;
  14602. t['Nacute'] = 722;
  14603. t['icircumflex'] = 278;
  14604. t['Ecircumflex'] = 667;
  14605. t['adieresis'] = 500;
  14606. t['edieresis'] = 444;
  14607. t['cacute'] = 444;
  14608. t['nacute'] = 556;
  14609. t['umacron'] = 556;
  14610. t['Ncaron'] = 722;
  14611. t['Iacute'] = 389;
  14612. t['plusminus'] = 570;
  14613. t['brokenbar'] = 220;
  14614. t['registered'] = 747;
  14615. t['Gbreve'] = 722;
  14616. t['Idotaccent'] = 389;
  14617. t['summation'] = 600;
  14618. t['Egrave'] = 667;
  14619. t['racute'] = 389;
  14620. t['omacron'] = 500;
  14621. t['Zacute'] = 611;
  14622. t['Zcaron'] = 611;
  14623. t['greaterequal'] = 549;
  14624. t['Eth'] = 722;
  14625. t['Ccedilla'] = 667;
  14626. t['lcommaaccent'] = 278;
  14627. t['tcaron'] = 366;
  14628. t['eogonek'] = 444;
  14629. t['Uogonek'] = 722;
  14630. t['Aacute'] = 667;
  14631. t['Adieresis'] = 667;
  14632. t['egrave'] = 444;
  14633. t['zacute'] = 389;
  14634. t['iogonek'] = 278;
  14635. t['Oacute'] = 722;
  14636. t['oacute'] = 500;
  14637. t['amacron'] = 500;
  14638. t['sacute'] = 389;
  14639. t['idieresis'] = 278;
  14640. t['Ocircumflex'] = 722;
  14641. t['Ugrave'] = 722;
  14642. t['Delta'] = 612;
  14643. t['thorn'] = 500;
  14644. t['twosuperior'] = 300;
  14645. t['Odieresis'] = 722;
  14646. t['mu'] = 576;
  14647. t['igrave'] = 278;
  14648. t['ohungarumlaut'] = 500;
  14649. t['Eogonek'] = 667;
  14650. t['dcroat'] = 500;
  14651. t['threequarters'] = 750;
  14652. t['Scedilla'] = 556;
  14653. t['lcaron'] = 382;
  14654. t['Kcommaaccent'] = 667;
  14655. t['Lacute'] = 611;
  14656. t['trademark'] = 1000;
  14657. t['edotaccent'] = 444;
  14658. t['Igrave'] = 389;
  14659. t['Imacron'] = 389;
  14660. t['Lcaron'] = 611;
  14661. t['onehalf'] = 750;
  14662. t['lessequal'] = 549;
  14663. t['ocircumflex'] = 500;
  14664. t['ntilde'] = 556;
  14665. t['Uhungarumlaut'] = 722;
  14666. t['Eacute'] = 667;
  14667. t['emacron'] = 444;
  14668. t['gbreve'] = 500;
  14669. t['onequarter'] = 750;
  14670. t['Scaron'] = 556;
  14671. t['Scommaaccent'] = 556;
  14672. t['Ohungarumlaut'] = 722;
  14673. t['degree'] = 400;
  14674. t['ograve'] = 500;
  14675. t['Ccaron'] = 667;
  14676. t['ugrave'] = 556;
  14677. t['radical'] = 549;
  14678. t['Dcaron'] = 722;
  14679. t['rcommaaccent'] = 389;
  14680. t['Ntilde'] = 722;
  14681. t['otilde'] = 500;
  14682. t['Rcommaaccent'] = 667;
  14683. t['Lcommaaccent'] = 611;
  14684. t['Atilde'] = 667;
  14685. t['Aogonek'] = 667;
  14686. t['Aring'] = 667;
  14687. t['Otilde'] = 722;
  14688. t['zdotaccent'] = 389;
  14689. t['Ecaron'] = 667;
  14690. t['Iogonek'] = 389;
  14691. t['kcommaaccent'] = 500;
  14692. t['minus'] = 606;
  14693. t['Icircumflex'] = 389;
  14694. t['ncaron'] = 556;
  14695. t['tcommaaccent'] = 278;
  14696. t['logicalnot'] = 606;
  14697. t['odieresis'] = 500;
  14698. t['udieresis'] = 556;
  14699. t['notequal'] = 549;
  14700. t['gcommaaccent'] = 500;
  14701. t['eth'] = 500;
  14702. t['zcaron'] = 389;
  14703. t['ncommaaccent'] = 556;
  14704. t['onesuperior'] = 300;
  14705. t['imacron'] = 278;
  14706. t['Euro'] = 500;
  14707. });
  14708. t['Times-Italic'] = getLookupTableFactory(function (t) {
  14709. t['space'] = 250;
  14710. t['exclam'] = 333;
  14711. t['quotedbl'] = 420;
  14712. t['numbersign'] = 500;
  14713. t['dollar'] = 500;
  14714. t['percent'] = 833;
  14715. t['ampersand'] = 778;
  14716. t['quoteright'] = 333;
  14717. t['parenleft'] = 333;
  14718. t['parenright'] = 333;
  14719. t['asterisk'] = 500;
  14720. t['plus'] = 675;
  14721. t['comma'] = 250;
  14722. t['hyphen'] = 333;
  14723. t['period'] = 250;
  14724. t['slash'] = 278;
  14725. t['zero'] = 500;
  14726. t['one'] = 500;
  14727. t['two'] = 500;
  14728. t['three'] = 500;
  14729. t['four'] = 500;
  14730. t['five'] = 500;
  14731. t['six'] = 500;
  14732. t['seven'] = 500;
  14733. t['eight'] = 500;
  14734. t['nine'] = 500;
  14735. t['colon'] = 333;
  14736. t['semicolon'] = 333;
  14737. t['less'] = 675;
  14738. t['equal'] = 675;
  14739. t['greater'] = 675;
  14740. t['question'] = 500;
  14741. t['at'] = 920;
  14742. t['A'] = 611;
  14743. t['B'] = 611;
  14744. t['C'] = 667;
  14745. t['D'] = 722;
  14746. t['E'] = 611;
  14747. t['F'] = 611;
  14748. t['G'] = 722;
  14749. t['H'] = 722;
  14750. t['I'] = 333;
  14751. t['J'] = 444;
  14752. t['K'] = 667;
  14753. t['L'] = 556;
  14754. t['M'] = 833;
  14755. t['N'] = 667;
  14756. t['O'] = 722;
  14757. t['P'] = 611;
  14758. t['Q'] = 722;
  14759. t['R'] = 611;
  14760. t['S'] = 500;
  14761. t['T'] = 556;
  14762. t['U'] = 722;
  14763. t['V'] = 611;
  14764. t['W'] = 833;
  14765. t['X'] = 611;
  14766. t['Y'] = 556;
  14767. t['Z'] = 556;
  14768. t['bracketleft'] = 389;
  14769. t['backslash'] = 278;
  14770. t['bracketright'] = 389;
  14771. t['asciicircum'] = 422;
  14772. t['underscore'] = 500;
  14773. t['quoteleft'] = 333;
  14774. t['a'] = 500;
  14775. t['b'] = 500;
  14776. t['c'] = 444;
  14777. t['d'] = 500;
  14778. t['e'] = 444;
  14779. t['f'] = 278;
  14780. t['g'] = 500;
  14781. t['h'] = 500;
  14782. t['i'] = 278;
  14783. t['j'] = 278;
  14784. t['k'] = 444;
  14785. t['l'] = 278;
  14786. t['m'] = 722;
  14787. t['n'] = 500;
  14788. t['o'] = 500;
  14789. t['p'] = 500;
  14790. t['q'] = 500;
  14791. t['r'] = 389;
  14792. t['s'] = 389;
  14793. t['t'] = 278;
  14794. t['u'] = 500;
  14795. t['v'] = 444;
  14796. t['w'] = 667;
  14797. t['x'] = 444;
  14798. t['y'] = 444;
  14799. t['z'] = 389;
  14800. t['braceleft'] = 400;
  14801. t['bar'] = 275;
  14802. t['braceright'] = 400;
  14803. t['asciitilde'] = 541;
  14804. t['exclamdown'] = 389;
  14805. t['cent'] = 500;
  14806. t['sterling'] = 500;
  14807. t['fraction'] = 167;
  14808. t['yen'] = 500;
  14809. t['florin'] = 500;
  14810. t['section'] = 500;
  14811. t['currency'] = 500;
  14812. t['quotesingle'] = 214;
  14813. t['quotedblleft'] = 556;
  14814. t['guillemotleft'] = 500;
  14815. t['guilsinglleft'] = 333;
  14816. t['guilsinglright'] = 333;
  14817. t['fi'] = 500;
  14818. t['fl'] = 500;
  14819. t['endash'] = 500;
  14820. t['dagger'] = 500;
  14821. t['daggerdbl'] = 500;
  14822. t['periodcentered'] = 250;
  14823. t['paragraph'] = 523;
  14824. t['bullet'] = 350;
  14825. t['quotesinglbase'] = 333;
  14826. t['quotedblbase'] = 556;
  14827. t['quotedblright'] = 556;
  14828. t['guillemotright'] = 500;
  14829. t['ellipsis'] = 889;
  14830. t['perthousand'] = 1000;
  14831. t['questiondown'] = 500;
  14832. t['grave'] = 333;
  14833. t['acute'] = 333;
  14834. t['circumflex'] = 333;
  14835. t['tilde'] = 333;
  14836. t['macron'] = 333;
  14837. t['breve'] = 333;
  14838. t['dotaccent'] = 333;
  14839. t['dieresis'] = 333;
  14840. t['ring'] = 333;
  14841. t['cedilla'] = 333;
  14842. t['hungarumlaut'] = 333;
  14843. t['ogonek'] = 333;
  14844. t['caron'] = 333;
  14845. t['emdash'] = 889;
  14846. t['AE'] = 889;
  14847. t['ordfeminine'] = 276;
  14848. t['Lslash'] = 556;
  14849. t['Oslash'] = 722;
  14850. t['OE'] = 944;
  14851. t['ordmasculine'] = 310;
  14852. t['ae'] = 667;
  14853. t['dotlessi'] = 278;
  14854. t['lslash'] = 278;
  14855. t['oslash'] = 500;
  14856. t['oe'] = 667;
  14857. t['germandbls'] = 500;
  14858. t['Idieresis'] = 333;
  14859. t['eacute'] = 444;
  14860. t['abreve'] = 500;
  14861. t['uhungarumlaut'] = 500;
  14862. t['ecaron'] = 444;
  14863. t['Ydieresis'] = 556;
  14864. t['divide'] = 675;
  14865. t['Yacute'] = 556;
  14866. t['Acircumflex'] = 611;
  14867. t['aacute'] = 500;
  14868. t['Ucircumflex'] = 722;
  14869. t['yacute'] = 444;
  14870. t['scommaaccent'] = 389;
  14871. t['ecircumflex'] = 444;
  14872. t['Uring'] = 722;
  14873. t['Udieresis'] = 722;
  14874. t['aogonek'] = 500;
  14875. t['Uacute'] = 722;
  14876. t['uogonek'] = 500;
  14877. t['Edieresis'] = 611;
  14878. t['Dcroat'] = 722;
  14879. t['commaaccent'] = 250;
  14880. t['copyright'] = 760;
  14881. t['Emacron'] = 611;
  14882. t['ccaron'] = 444;
  14883. t['aring'] = 500;
  14884. t['Ncommaaccent'] = 667;
  14885. t['lacute'] = 278;
  14886. t['agrave'] = 500;
  14887. t['Tcommaaccent'] = 556;
  14888. t['Cacute'] = 667;
  14889. t['atilde'] = 500;
  14890. t['Edotaccent'] = 611;
  14891. t['scaron'] = 389;
  14892. t['scedilla'] = 389;
  14893. t['iacute'] = 278;
  14894. t['lozenge'] = 471;
  14895. t['Rcaron'] = 611;
  14896. t['Gcommaaccent'] = 722;
  14897. t['ucircumflex'] = 500;
  14898. t['acircumflex'] = 500;
  14899. t['Amacron'] = 611;
  14900. t['rcaron'] = 389;
  14901. t['ccedilla'] = 444;
  14902. t['Zdotaccent'] = 556;
  14903. t['Thorn'] = 611;
  14904. t['Omacron'] = 722;
  14905. t['Racute'] = 611;
  14906. t['Sacute'] = 500;
  14907. t['dcaron'] = 544;
  14908. t['Umacron'] = 722;
  14909. t['uring'] = 500;
  14910. t['threesuperior'] = 300;
  14911. t['Ograve'] = 722;
  14912. t['Agrave'] = 611;
  14913. t['Abreve'] = 611;
  14914. t['multiply'] = 675;
  14915. t['uacute'] = 500;
  14916. t['Tcaron'] = 556;
  14917. t['partialdiff'] = 476;
  14918. t['ydieresis'] = 444;
  14919. t['Nacute'] = 667;
  14920. t['icircumflex'] = 278;
  14921. t['Ecircumflex'] = 611;
  14922. t['adieresis'] = 500;
  14923. t['edieresis'] = 444;
  14924. t['cacute'] = 444;
  14925. t['nacute'] = 500;
  14926. t['umacron'] = 500;
  14927. t['Ncaron'] = 667;
  14928. t['Iacute'] = 333;
  14929. t['plusminus'] = 675;
  14930. t['brokenbar'] = 275;
  14931. t['registered'] = 760;
  14932. t['Gbreve'] = 722;
  14933. t['Idotaccent'] = 333;
  14934. t['summation'] = 600;
  14935. t['Egrave'] = 611;
  14936. t['racute'] = 389;
  14937. t['omacron'] = 500;
  14938. t['Zacute'] = 556;
  14939. t['Zcaron'] = 556;
  14940. t['greaterequal'] = 549;
  14941. t['Eth'] = 722;
  14942. t['Ccedilla'] = 667;
  14943. t['lcommaaccent'] = 278;
  14944. t['tcaron'] = 300;
  14945. t['eogonek'] = 444;
  14946. t['Uogonek'] = 722;
  14947. t['Aacute'] = 611;
  14948. t['Adieresis'] = 611;
  14949. t['egrave'] = 444;
  14950. t['zacute'] = 389;
  14951. t['iogonek'] = 278;
  14952. t['Oacute'] = 722;
  14953. t['oacute'] = 500;
  14954. t['amacron'] = 500;
  14955. t['sacute'] = 389;
  14956. t['idieresis'] = 278;
  14957. t['Ocircumflex'] = 722;
  14958. t['Ugrave'] = 722;
  14959. t['Delta'] = 612;
  14960. t['thorn'] = 500;
  14961. t['twosuperior'] = 300;
  14962. t['Odieresis'] = 722;
  14963. t['mu'] = 500;
  14964. t['igrave'] = 278;
  14965. t['ohungarumlaut'] = 500;
  14966. t['Eogonek'] = 611;
  14967. t['dcroat'] = 500;
  14968. t['threequarters'] = 750;
  14969. t['Scedilla'] = 500;
  14970. t['lcaron'] = 300;
  14971. t['Kcommaaccent'] = 667;
  14972. t['Lacute'] = 556;
  14973. t['trademark'] = 980;
  14974. t['edotaccent'] = 444;
  14975. t['Igrave'] = 333;
  14976. t['Imacron'] = 333;
  14977. t['Lcaron'] = 611;
  14978. t['onehalf'] = 750;
  14979. t['lessequal'] = 549;
  14980. t['ocircumflex'] = 500;
  14981. t['ntilde'] = 500;
  14982. t['Uhungarumlaut'] = 722;
  14983. t['Eacute'] = 611;
  14984. t['emacron'] = 444;
  14985. t['gbreve'] = 500;
  14986. t['onequarter'] = 750;
  14987. t['Scaron'] = 500;
  14988. t['Scommaaccent'] = 500;
  14989. t['Ohungarumlaut'] = 722;
  14990. t['degree'] = 400;
  14991. t['ograve'] = 500;
  14992. t['Ccaron'] = 667;
  14993. t['ugrave'] = 500;
  14994. t['radical'] = 453;
  14995. t['Dcaron'] = 722;
  14996. t['rcommaaccent'] = 389;
  14997. t['Ntilde'] = 667;
  14998. t['otilde'] = 500;
  14999. t['Rcommaaccent'] = 611;
  15000. t['Lcommaaccent'] = 556;
  15001. t['Atilde'] = 611;
  15002. t['Aogonek'] = 611;
  15003. t['Aring'] = 611;
  15004. t['Otilde'] = 722;
  15005. t['zdotaccent'] = 389;
  15006. t['Ecaron'] = 611;
  15007. t['Iogonek'] = 333;
  15008. t['kcommaaccent'] = 444;
  15009. t['minus'] = 675;
  15010. t['Icircumflex'] = 333;
  15011. t['ncaron'] = 500;
  15012. t['tcommaaccent'] = 278;
  15013. t['logicalnot'] = 675;
  15014. t['odieresis'] = 500;
  15015. t['udieresis'] = 500;
  15016. t['notequal'] = 549;
  15017. t['gcommaaccent'] = 500;
  15018. t['eth'] = 500;
  15019. t['zcaron'] = 389;
  15020. t['ncommaaccent'] = 500;
  15021. t['onesuperior'] = 300;
  15022. t['imacron'] = 278;
  15023. t['Euro'] = 500;
  15024. });
  15025. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  15026. t['space'] = 278;
  15027. t['a1'] = 974;
  15028. t['a2'] = 961;
  15029. t['a202'] = 974;
  15030. t['a3'] = 980;
  15031. t['a4'] = 719;
  15032. t['a5'] = 789;
  15033. t['a119'] = 790;
  15034. t['a118'] = 791;
  15035. t['a117'] = 690;
  15036. t['a11'] = 960;
  15037. t['a12'] = 939;
  15038. t['a13'] = 549;
  15039. t['a14'] = 855;
  15040. t['a15'] = 911;
  15041. t['a16'] = 933;
  15042. t['a105'] = 911;
  15043. t['a17'] = 945;
  15044. t['a18'] = 974;
  15045. t['a19'] = 755;
  15046. t['a20'] = 846;
  15047. t['a21'] = 762;
  15048. t['a22'] = 761;
  15049. t['a23'] = 571;
  15050. t['a24'] = 677;
  15051. t['a25'] = 763;
  15052. t['a26'] = 760;
  15053. t['a27'] = 759;
  15054. t['a28'] = 754;
  15055. t['a6'] = 494;
  15056. t['a7'] = 552;
  15057. t['a8'] = 537;
  15058. t['a9'] = 577;
  15059. t['a10'] = 692;
  15060. t['a29'] = 786;
  15061. t['a30'] = 788;
  15062. t['a31'] = 788;
  15063. t['a32'] = 790;
  15064. t['a33'] = 793;
  15065. t['a34'] = 794;
  15066. t['a35'] = 816;
  15067. t['a36'] = 823;
  15068. t['a37'] = 789;
  15069. t['a38'] = 841;
  15070. t['a39'] = 823;
  15071. t['a40'] = 833;
  15072. t['a41'] = 816;
  15073. t['a42'] = 831;
  15074. t['a43'] = 923;
  15075. t['a44'] = 744;
  15076. t['a45'] = 723;
  15077. t['a46'] = 749;
  15078. t['a47'] = 790;
  15079. t['a48'] = 792;
  15080. t['a49'] = 695;
  15081. t['a50'] = 776;
  15082. t['a51'] = 768;
  15083. t['a52'] = 792;
  15084. t['a53'] = 759;
  15085. t['a54'] = 707;
  15086. t['a55'] = 708;
  15087. t['a56'] = 682;
  15088. t['a57'] = 701;
  15089. t['a58'] = 826;
  15090. t['a59'] = 815;
  15091. t['a60'] = 789;
  15092. t['a61'] = 789;
  15093. t['a62'] = 707;
  15094. t['a63'] = 687;
  15095. t['a64'] = 696;
  15096. t['a65'] = 689;
  15097. t['a66'] = 786;
  15098. t['a67'] = 787;
  15099. t['a68'] = 713;
  15100. t['a69'] = 791;
  15101. t['a70'] = 785;
  15102. t['a71'] = 791;
  15103. t['a72'] = 873;
  15104. t['a73'] = 761;
  15105. t['a74'] = 762;
  15106. t['a203'] = 762;
  15107. t['a75'] = 759;
  15108. t['a204'] = 759;
  15109. t['a76'] = 892;
  15110. t['a77'] = 892;
  15111. t['a78'] = 788;
  15112. t['a79'] = 784;
  15113. t['a81'] = 438;
  15114. t['a82'] = 138;
  15115. t['a83'] = 277;
  15116. t['a84'] = 415;
  15117. t['a97'] = 392;
  15118. t['a98'] = 392;
  15119. t['a99'] = 668;
  15120. t['a100'] = 668;
  15121. t['a89'] = 390;
  15122. t['a90'] = 390;
  15123. t['a93'] = 317;
  15124. t['a94'] = 317;
  15125. t['a91'] = 276;
  15126. t['a92'] = 276;
  15127. t['a205'] = 509;
  15128. t['a85'] = 509;
  15129. t['a206'] = 410;
  15130. t['a86'] = 410;
  15131. t['a87'] = 234;
  15132. t['a88'] = 234;
  15133. t['a95'] = 334;
  15134. t['a96'] = 334;
  15135. t['a101'] = 732;
  15136. t['a102'] = 544;
  15137. t['a103'] = 544;
  15138. t['a104'] = 910;
  15139. t['a106'] = 667;
  15140. t['a107'] = 760;
  15141. t['a108'] = 760;
  15142. t['a112'] = 776;
  15143. t['a111'] = 595;
  15144. t['a110'] = 694;
  15145. t['a109'] = 626;
  15146. t['a120'] = 788;
  15147. t['a121'] = 788;
  15148. t['a122'] = 788;
  15149. t['a123'] = 788;
  15150. t['a124'] = 788;
  15151. t['a125'] = 788;
  15152. t['a126'] = 788;
  15153. t['a127'] = 788;
  15154. t['a128'] = 788;
  15155. t['a129'] = 788;
  15156. t['a130'] = 788;
  15157. t['a131'] = 788;
  15158. t['a132'] = 788;
  15159. t['a133'] = 788;
  15160. t['a134'] = 788;
  15161. t['a135'] = 788;
  15162. t['a136'] = 788;
  15163. t['a137'] = 788;
  15164. t['a138'] = 788;
  15165. t['a139'] = 788;
  15166. t['a140'] = 788;
  15167. t['a141'] = 788;
  15168. t['a142'] = 788;
  15169. t['a143'] = 788;
  15170. t['a144'] = 788;
  15171. t['a145'] = 788;
  15172. t['a146'] = 788;
  15173. t['a147'] = 788;
  15174. t['a148'] = 788;
  15175. t['a149'] = 788;
  15176. t['a150'] = 788;
  15177. t['a151'] = 788;
  15178. t['a152'] = 788;
  15179. t['a153'] = 788;
  15180. t['a154'] = 788;
  15181. t['a155'] = 788;
  15182. t['a156'] = 788;
  15183. t['a157'] = 788;
  15184. t['a158'] = 788;
  15185. t['a159'] = 788;
  15186. t['a160'] = 894;
  15187. t['a161'] = 838;
  15188. t['a163'] = 1016;
  15189. t['a164'] = 458;
  15190. t['a196'] = 748;
  15191. t['a165'] = 924;
  15192. t['a192'] = 748;
  15193. t['a166'] = 918;
  15194. t['a167'] = 927;
  15195. t['a168'] = 928;
  15196. t['a169'] = 928;
  15197. t['a170'] = 834;
  15198. t['a171'] = 873;
  15199. t['a172'] = 828;
  15200. t['a173'] = 924;
  15201. t['a162'] = 924;
  15202. t['a174'] = 917;
  15203. t['a175'] = 930;
  15204. t['a176'] = 931;
  15205. t['a177'] = 463;
  15206. t['a178'] = 883;
  15207. t['a179'] = 836;
  15208. t['a193'] = 836;
  15209. t['a180'] = 867;
  15210. t['a199'] = 867;
  15211. t['a181'] = 696;
  15212. t['a200'] = 696;
  15213. t['a182'] = 874;
  15214. t['a201'] = 874;
  15215. t['a183'] = 760;
  15216. t['a184'] = 946;
  15217. t['a197'] = 771;
  15218. t['a185'] = 865;
  15219. t['a194'] = 771;
  15220. t['a198'] = 888;
  15221. t['a186'] = 967;
  15222. t['a195'] = 888;
  15223. t['a187'] = 831;
  15224. t['a188'] = 873;
  15225. t['a189'] = 927;
  15226. t['a190'] = 970;
  15227. t['a191'] = 918;
  15228. });
  15229. });
  15230. exports.getMetrics = getMetrics;
  15231. }));
  15232. (function (root, factory) {
  15233. {
  15234. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  15235. }
  15236. }(this, function (exports, sharedUtil) {
  15237. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  15238. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  15239. // Workaround for missing math precison in JS.
  15240. var MASK_HIGH = 0xffff0000;
  15241. var MASK_LOW = 0xffff;
  15242. function MurmurHash3_64 (seed) {
  15243. var SEED = 0xc3d2e1f0;
  15244. this.h1 = seed ? seed & 0xffffffff : SEED;
  15245. this.h2 = seed ? seed & 0xffffffff : SEED;
  15246. }
  15247. var alwaysUseUint32ArrayView = false;
  15248. // old webkits have issues with non-aligned arrays
  15249. try {
  15250. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  15251. } catch (e) {
  15252. alwaysUseUint32ArrayView = true;
  15253. }
  15254. MurmurHash3_64.prototype = {
  15255. update: function MurmurHash3_64_update(input) {
  15256. var useUint32ArrayView = alwaysUseUint32ArrayView;
  15257. var i;
  15258. if (typeof input === 'string') {
  15259. var data = new Uint8Array(input.length * 2);
  15260. var length = 0;
  15261. for (i = 0; i < input.length; i++) {
  15262. var code = input.charCodeAt(i);
  15263. if (code <= 0xff) {
  15264. data[length++] = code;
  15265. }
  15266. else {
  15267. data[length++] = code >>> 8;
  15268. data[length++] = code & 0xff;
  15269. }
  15270. }
  15271. } else if (input instanceof Uint8Array) {
  15272. data = input;
  15273. length = data.length;
  15274. } else if (typeof input === 'object' && ('length' in input)) {
  15275. // processing regular arrays as well, e.g. for IE9
  15276. data = input;
  15277. length = data.length;
  15278. useUint32ArrayView = true;
  15279. } else {
  15280. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  15281. 'Input must be a string or array.');
  15282. }
  15283. var blockCounts = length >> 2;
  15284. var tailLength = length - blockCounts * 4;
  15285. // we don't care about endianness here
  15286. var dataUint32 = useUint32ArrayView ?
  15287. new Uint32ArrayView(data, blockCounts) :
  15288. new Uint32Array(data.buffer, 0, blockCounts);
  15289. var k1 = 0;
  15290. var k2 = 0;
  15291. var h1 = this.h1;
  15292. var h2 = this.h2;
  15293. var C1 = 0xcc9e2d51;
  15294. var C2 = 0x1b873593;
  15295. var C1_LOW = C1 & MASK_LOW;
  15296. var C2_LOW = C2 & MASK_LOW;
  15297. for (i = 0; i < blockCounts; i++) {
  15298. if (i & 1) {
  15299. k1 = dataUint32[i];
  15300. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15301. k1 = k1 << 15 | k1 >>> 17;
  15302. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15303. h1 ^= k1;
  15304. h1 = h1 << 13 | h1 >>> 19;
  15305. h1 = h1 * 5 + 0xe6546b64;
  15306. } else {
  15307. k2 = dataUint32[i];
  15308. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  15309. k2 = k2 << 15 | k2 >>> 17;
  15310. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  15311. h2 ^= k2;
  15312. h2 = h2 << 13 | h2 >>> 19;
  15313. h2 = h2 * 5 + 0xe6546b64;
  15314. }
  15315. }
  15316. k1 = 0;
  15317. switch (tailLength) {
  15318. case 3:
  15319. k1 ^= data[blockCounts * 4 + 2] << 16;
  15320. /* falls through */
  15321. case 2:
  15322. k1 ^= data[blockCounts * 4 + 1] << 8;
  15323. /* falls through */
  15324. case 1:
  15325. k1 ^= data[blockCounts * 4];
  15326. /* falls through */
  15327. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15328. k1 = k1 << 15 | k1 >>> 17;
  15329. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15330. if (blockCounts & 1) {
  15331. h1 ^= k1;
  15332. } else {
  15333. h2 ^= k1;
  15334. }
  15335. }
  15336. this.h1 = h1;
  15337. this.h2 = h2;
  15338. return this;
  15339. },
  15340. hexdigest: function MurmurHash3_64_hexdigest () {
  15341. var h1 = this.h1;
  15342. var h2 = this.h2;
  15343. h1 ^= h2 >>> 1;
  15344. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15345. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15346. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15347. h1 ^= h2 >>> 1;
  15348. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15349. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15350. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15351. h1 ^= h2 >>> 1;
  15352. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15353. var hex = (arr[i] >>> 0).toString(16);
  15354. while (hex.length < 8) {
  15355. hex = '0' + hex;
  15356. }
  15357. str += hex;
  15358. }
  15359. return str;
  15360. }
  15361. };
  15362. return MurmurHash3_64;
  15363. })();
  15364. exports.MurmurHash3_64 = MurmurHash3_64;
  15365. }));
  15366. (function (root, factory) {
  15367. {
  15368. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15369. }
  15370. }(this, function (exports, sharedUtil) {
  15371. var isArray = sharedUtil.isArray;
  15372. var Name = (function NameClosure() {
  15373. function Name(name) {
  15374. this.name = name;
  15375. }
  15376. Name.prototype = {};
  15377. var nameCache = Object.create(null);
  15378. Name.get = function Name_get(name) {
  15379. var nameValue = nameCache[name];
  15380. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15381. };
  15382. return Name;
  15383. })();
  15384. var Cmd = (function CmdClosure() {
  15385. function Cmd(cmd) {
  15386. this.cmd = cmd;
  15387. }
  15388. Cmd.prototype = {};
  15389. var cmdCache = Object.create(null);
  15390. Cmd.get = function Cmd_get(cmd) {
  15391. var cmdValue = cmdCache[cmd];
  15392. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15393. };
  15394. return Cmd;
  15395. })();
  15396. var Dict = (function DictClosure() {
  15397. var nonSerializable = function nonSerializableClosure() {
  15398. return nonSerializable; // creating closure on some variable
  15399. };
  15400. // xref is optional
  15401. function Dict(xref) {
  15402. // Map should only be used internally, use functions below to access.
  15403. this.map = Object.create(null);
  15404. this.xref = xref;
  15405. this.objId = null;
  15406. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15407. }
  15408. Dict.prototype = {
  15409. assignXref: function Dict_assignXref(newXref) {
  15410. this.xref = newXref;
  15411. },
  15412. // automatically dereferences Ref objects
  15413. get: function Dict_get(key1, key2, key3) {
  15414. var value;
  15415. var xref = this.xref;
  15416. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15417. typeof key2 === 'undefined') {
  15418. return xref ? xref.fetchIfRef(value) : value;
  15419. }
  15420. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15421. typeof key3 === 'undefined') {
  15422. return xref ? xref.fetchIfRef(value) : value;
  15423. }
  15424. value = this.map[key3] || null;
  15425. return xref ? xref.fetchIfRef(value) : value;
  15426. },
  15427. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15428. getAsync: function Dict_getAsync(key1, key2, key3) {
  15429. var value;
  15430. var xref = this.xref;
  15431. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15432. typeof key2 === 'undefined') {
  15433. if (xref) {
  15434. return xref.fetchIfRefAsync(value);
  15435. }
  15436. return Promise.resolve(value);
  15437. }
  15438. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15439. typeof key3 === 'undefined') {
  15440. if (xref) {
  15441. return xref.fetchIfRefAsync(value);
  15442. }
  15443. return Promise.resolve(value);
  15444. }
  15445. value = this.map[key3] || null;
  15446. if (xref) {
  15447. return xref.fetchIfRefAsync(value);
  15448. }
  15449. return Promise.resolve(value);
  15450. },
  15451. // Same as get(), but dereferences all elements if the result is an Array.
  15452. getArray: function Dict_getArray(key1, key2, key3) {
  15453. var value = this.get(key1, key2, key3);
  15454. var xref = this.xref;
  15455. if (!isArray(value) || !xref) {
  15456. return value;
  15457. }
  15458. value = value.slice(); // Ensure that we don't modify the Dict data.
  15459. for (var i = 0, ii = value.length; i < ii; i++) {
  15460. if (!isRef(value[i])) {
  15461. continue;
  15462. }
  15463. value[i] = xref.fetch(value[i]);
  15464. }
  15465. return value;
  15466. },
  15467. // no dereferencing
  15468. getRaw: function Dict_getRaw(key) {
  15469. return this.map[key];
  15470. },
  15471. getKeys: function Dict_getKeys() {
  15472. return Object.keys(this.map);
  15473. },
  15474. set: function Dict_set(key, value) {
  15475. this.map[key] = value;
  15476. },
  15477. has: function Dict_has(key) {
  15478. return key in this.map;
  15479. },
  15480. forEach: function Dict_forEach(callback) {
  15481. for (var key in this.map) {
  15482. callback(key, this.get(key));
  15483. }
  15484. }
  15485. };
  15486. Dict.empty = new Dict(null);
  15487. Dict.merge = function Dict_merge(xref, dictArray) {
  15488. var mergedDict = new Dict(xref);
  15489. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15490. var dict = dictArray[i];
  15491. if (!isDict(dict)) {
  15492. continue;
  15493. }
  15494. for (var keyName in dict.map) {
  15495. if (mergedDict.map[keyName]) {
  15496. continue;
  15497. }
  15498. mergedDict.map[keyName] = dict.map[keyName];
  15499. }
  15500. }
  15501. return mergedDict;
  15502. };
  15503. return Dict;
  15504. })();
  15505. var Ref = (function RefClosure() {
  15506. function Ref(num, gen) {
  15507. this.num = num;
  15508. this.gen = gen;
  15509. }
  15510. Ref.prototype = {
  15511. toString: function Ref_toString() {
  15512. // This function is hot, so we make the string as compact as possible.
  15513. // |this.gen| is almost always zero, so we treat that case specially.
  15514. var str = this.num + 'R';
  15515. if (this.gen !== 0) {
  15516. str += this.gen;
  15517. }
  15518. return str;
  15519. }
  15520. };
  15521. return Ref;
  15522. })();
  15523. // The reference is identified by number and generation.
  15524. // This structure stores only one instance of the reference.
  15525. var RefSet = (function RefSetClosure() {
  15526. function RefSet() {
  15527. this.dict = Object.create(null);
  15528. }
  15529. RefSet.prototype = {
  15530. has: function RefSet_has(ref) {
  15531. return ref.toString() in this.dict;
  15532. },
  15533. put: function RefSet_put(ref) {
  15534. this.dict[ref.toString()] = true;
  15535. },
  15536. remove: function RefSet_remove(ref) {
  15537. delete this.dict[ref.toString()];
  15538. }
  15539. };
  15540. return RefSet;
  15541. })();
  15542. var RefSetCache = (function RefSetCacheClosure() {
  15543. function RefSetCache() {
  15544. this.dict = Object.create(null);
  15545. }
  15546. RefSetCache.prototype = {
  15547. get: function RefSetCache_get(ref) {
  15548. return this.dict[ref.toString()];
  15549. },
  15550. has: function RefSetCache_has(ref) {
  15551. return ref.toString() in this.dict;
  15552. },
  15553. put: function RefSetCache_put(ref, obj) {
  15554. this.dict[ref.toString()] = obj;
  15555. },
  15556. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15557. this.dict[ref.toString()] = this.get(aliasRef);
  15558. },
  15559. forEach: function RefSetCache_forEach(fn, thisArg) {
  15560. for (var i in this.dict) {
  15561. fn.call(thisArg, this.dict[i]);
  15562. }
  15563. },
  15564. clear: function RefSetCache_clear() {
  15565. this.dict = Object.create(null);
  15566. }
  15567. };
  15568. return RefSetCache;
  15569. })();
  15570. function isName(v) {
  15571. return v instanceof Name;
  15572. }
  15573. function isCmd(v, cmd) {
  15574. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15575. }
  15576. function isDict(v, type) {
  15577. if (!(v instanceof Dict)) {
  15578. return false;
  15579. }
  15580. if (!type) {
  15581. return true;
  15582. }
  15583. var dictType = v.get('Type');
  15584. return isName(dictType) && dictType.name === type;
  15585. }
  15586. function isRef(v) {
  15587. return v instanceof Ref;
  15588. }
  15589. function isStream(v) {
  15590. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15591. }
  15592. exports.Cmd = Cmd;
  15593. exports.Dict = Dict;
  15594. exports.Name = Name;
  15595. exports.Ref = Ref;
  15596. exports.RefSet = RefSet;
  15597. exports.RefSetCache = RefSetCache;
  15598. exports.isCmd = isCmd;
  15599. exports.isDict = isDict;
  15600. exports.isName = isName;
  15601. exports.isRef = isRef;
  15602. exports.isStream = isStream;
  15603. }));
  15604. (function (root, factory) {
  15605. {
  15606. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  15607. }
  15608. }(this, function (exports, sharedUtil) {
  15609. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15610. /**
  15611. * Hold a map of decoded fonts and of the standard fourteen Type1
  15612. * fonts and their acronyms.
  15613. */
  15614. var getStdFontMap = getLookupTableFactory(function (t) {
  15615. t['ArialNarrow'] = 'Helvetica';
  15616. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  15617. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  15618. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  15619. t['ArialBlack'] = 'Helvetica';
  15620. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  15621. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  15622. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  15623. t['Arial'] = 'Helvetica';
  15624. t['Arial-Bold'] = 'Helvetica-Bold';
  15625. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  15626. t['Arial-Italic'] = 'Helvetica-Oblique';
  15627. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  15628. t['Arial-BoldMT'] = 'Helvetica-Bold';
  15629. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  15630. t['ArialMT'] = 'Helvetica';
  15631. t['Courier-Bold'] = 'Courier-Bold';
  15632. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  15633. t['Courier-Italic'] = 'Courier-Oblique';
  15634. t['CourierNew'] = 'Courier';
  15635. t['CourierNew-Bold'] = 'Courier-Bold';
  15636. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  15637. t['CourierNew-Italic'] = 'Courier-Oblique';
  15638. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  15639. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  15640. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  15641. t['CourierNewPSMT'] = 'Courier';
  15642. t['Helvetica'] = 'Helvetica';
  15643. t['Helvetica-Bold'] = 'Helvetica-Bold';
  15644. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  15645. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  15646. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  15647. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  15648. t['Symbol-Bold'] = 'Symbol';
  15649. t['Symbol-BoldItalic'] = 'Symbol';
  15650. t['Symbol-Italic'] = 'Symbol';
  15651. t['TimesNewRoman'] = 'Times-Roman';
  15652. t['TimesNewRoman-Bold'] = 'Times-Bold';
  15653. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  15654. t['TimesNewRoman-Italic'] = 'Times-Italic';
  15655. t['TimesNewRomanPS'] = 'Times-Roman';
  15656. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  15657. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  15658. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  15659. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  15660. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  15661. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  15662. t['TimesNewRomanPSMT'] = 'Times-Roman';
  15663. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  15664. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  15665. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  15666. });
  15667. /**
  15668. * Holds the map of the non-standard fonts that might be included as
  15669. * a standard fonts without glyph data.
  15670. */
  15671. var getNonStdFontMap = getLookupTableFactory(function (t) {
  15672. t['CenturyGothic'] = 'Helvetica';
  15673. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  15674. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  15675. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  15676. t['ComicSansMS'] = 'Comic Sans MS';
  15677. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  15678. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  15679. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  15680. t['LucidaConsole'] = 'Courier';
  15681. t['LucidaConsole-Bold'] = 'Courier-Bold';
  15682. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  15683. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  15684. t['MS-Gothic'] = 'MS Gothic';
  15685. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  15686. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  15687. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  15688. t['MS-Mincho'] = 'MS Mincho';
  15689. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  15690. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  15691. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  15692. t['MS-PGothic'] = 'MS PGothic';
  15693. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  15694. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  15695. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  15696. t['MS-PMincho'] = 'MS PMincho';
  15697. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  15698. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  15699. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  15700. t['Wingdings'] = 'ZapfDingbats';
  15701. });
  15702. var getSerifFonts = getLookupTableFactory(function (t) {
  15703. t['Adobe Jenson'] = true;
  15704. t['Adobe Text'] = true;
  15705. t['Albertus'] = true;
  15706. t['Aldus'] = true;
  15707. t['Alexandria'] = true;
  15708. t['Algerian'] = true;
  15709. t['American Typewriter'] = true;
  15710. t['Antiqua'] = true;
  15711. t['Apex'] = true;
  15712. t['Arno'] = true;
  15713. t['Aster'] = true;
  15714. t['Aurora'] = true;
  15715. t['Baskerville'] = true;
  15716. t['Bell'] = true;
  15717. t['Bembo'] = true;
  15718. t['Bembo Schoolbook'] = true;
  15719. t['Benguiat'] = true;
  15720. t['Berkeley Old Style'] = true;
  15721. t['Bernhard Modern'] = true;
  15722. t['Berthold City'] = true;
  15723. t['Bodoni'] = true;
  15724. t['Bauer Bodoni'] = true;
  15725. t['Book Antiqua'] = true;
  15726. t['Bookman'] = true;
  15727. t['Bordeaux Roman'] = true;
  15728. t['Californian FB'] = true;
  15729. t['Calisto'] = true;
  15730. t['Calvert'] = true;
  15731. t['Capitals'] = true;
  15732. t['Cambria'] = true;
  15733. t['Cartier'] = true;
  15734. t['Caslon'] = true;
  15735. t['Catull'] = true;
  15736. t['Centaur'] = true;
  15737. t['Century Old Style'] = true;
  15738. t['Century Schoolbook'] = true;
  15739. t['Chaparral'] = true;
  15740. t['Charis SIL'] = true;
  15741. t['Cheltenham'] = true;
  15742. t['Cholla Slab'] = true;
  15743. t['Clarendon'] = true;
  15744. t['Clearface'] = true;
  15745. t['Cochin'] = true;
  15746. t['Colonna'] = true;
  15747. t['Computer Modern'] = true;
  15748. t['Concrete Roman'] = true;
  15749. t['Constantia'] = true;
  15750. t['Cooper Black'] = true;
  15751. t['Corona'] = true;
  15752. t['Ecotype'] = true;
  15753. t['Egyptienne'] = true;
  15754. t['Elephant'] = true;
  15755. t['Excelsior'] = true;
  15756. t['Fairfield'] = true;
  15757. t['FF Scala'] = true;
  15758. t['Folkard'] = true;
  15759. t['Footlight'] = true;
  15760. t['FreeSerif'] = true;
  15761. t['Friz Quadrata'] = true;
  15762. t['Garamond'] = true;
  15763. t['Gentium'] = true;
  15764. t['Georgia'] = true;
  15765. t['Gloucester'] = true;
  15766. t['Goudy Old Style'] = true;
  15767. t['Goudy Schoolbook'] = true;
  15768. t['Goudy Pro Font'] = true;
  15769. t['Granjon'] = true;
  15770. t['Guardian Egyptian'] = true;
  15771. t['Heather'] = true;
  15772. t['Hercules'] = true;
  15773. t['High Tower Text'] = true;
  15774. t['Hiroshige'] = true;
  15775. t['Hoefler Text'] = true;
  15776. t['Humana Serif'] = true;
  15777. t['Imprint'] = true;
  15778. t['Ionic No. 5'] = true;
  15779. t['Janson'] = true;
  15780. t['Joanna'] = true;
  15781. t['Korinna'] = true;
  15782. t['Lexicon'] = true;
  15783. t['Liberation Serif'] = true;
  15784. t['Linux Libertine'] = true;
  15785. t['Literaturnaya'] = true;
  15786. t['Lucida'] = true;
  15787. t['Lucida Bright'] = true;
  15788. t['Melior'] = true;
  15789. t['Memphis'] = true;
  15790. t['Miller'] = true;
  15791. t['Minion'] = true;
  15792. t['Modern'] = true;
  15793. t['Mona Lisa'] = true;
  15794. t['Mrs Eaves'] = true;
  15795. t['MS Serif'] = true;
  15796. t['Museo Slab'] = true;
  15797. t['New York'] = true;
  15798. t['Nimbus Roman'] = true;
  15799. t['NPS Rawlinson Roadway'] = true;
  15800. t['Palatino'] = true;
  15801. t['Perpetua'] = true;
  15802. t['Plantin'] = true;
  15803. t['Plantin Schoolbook'] = true;
  15804. t['Playbill'] = true;
  15805. t['Poor Richard'] = true;
  15806. t['Rawlinson Roadway'] = true;
  15807. t['Renault'] = true;
  15808. t['Requiem'] = true;
  15809. t['Rockwell'] = true;
  15810. t['Roman'] = true;
  15811. t['Rotis Serif'] = true;
  15812. t['Sabon'] = true;
  15813. t['Scala'] = true;
  15814. t['Seagull'] = true;
  15815. t['Sistina'] = true;
  15816. t['Souvenir'] = true;
  15817. t['STIX'] = true;
  15818. t['Stone Informal'] = true;
  15819. t['Stone Serif'] = true;
  15820. t['Sylfaen'] = true;
  15821. t['Times'] = true;
  15822. t['Trajan'] = true;
  15823. t['Trinité'] = true;
  15824. t['Trump Mediaeval'] = true;
  15825. t['Utopia'] = true;
  15826. t['Vale Type'] = true;
  15827. t['Bitstream Vera'] = true;
  15828. t['Vera Serif'] = true;
  15829. t['Versailles'] = true;
  15830. t['Wanted'] = true;
  15831. t['Weiss'] = true;
  15832. t['Wide Latin'] = true;
  15833. t['Windsor'] = true;
  15834. t['XITS'] = true;
  15835. });
  15836. var getSymbolsFonts = getLookupTableFactory(function (t) {
  15837. t['Dingbats'] = true;
  15838. t['Symbol'] = true;
  15839. t['ZapfDingbats'] = true;
  15840. });
  15841. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  15842. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  15843. // for all glyphs, but common for some set of the standard fonts.
  15844. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  15845. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  15846. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  15847. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  15848. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  15849. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  15850. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  15851. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  15852. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  15853. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  15854. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  15855. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  15856. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  15857. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  15858. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  15859. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  15860. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  15861. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  15862. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  15863. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  15864. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  15865. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  15866. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  15867. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  15868. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  15869. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  15870. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  15871. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  15872. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  15873. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  15874. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  15875. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  15876. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  15877. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  15878. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  15879. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  15880. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  15881. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  15882. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  15883. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  15884. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  15885. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  15886. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  15887. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  15888. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  15889. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  15890. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  15891. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  15892. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  15893. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  15894. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  15895. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  15896. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  15897. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  15898. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  15899. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  15900. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  15901. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  15902. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  15903. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  15904. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  15905. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  15906. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  15907. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  15908. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  15909. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  15910. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  15911. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  15912. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  15913. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  15914. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  15915. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  15916. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  15917. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  15918. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  15919. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  15920. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  15921. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  15922. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  15923. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  15924. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  15925. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  15926. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  15927. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  15928. t[3416] = 8377;
  15929. });
  15930. // The glyph map for ArialBlack differs slightly from the glyph map used for
  15931. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  15932. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  15933. var getSupplementalGlyphMapForArialBlack =
  15934. getLookupTableFactory(function (t) {
  15935. t[227] = 322; t[264] = 261; t[291] = 346;
  15936. });
  15937. exports.getStdFontMap = getStdFontMap;
  15938. exports.getNonStdFontMap = getNonStdFontMap;
  15939. exports.getSerifFonts = getSerifFonts;
  15940. exports.getSymbolsFonts = getSymbolsFonts;
  15941. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  15942. exports.getSupplementalGlyphMapForArialBlack =
  15943. getSupplementalGlyphMapForArialBlack;
  15944. }));
  15945. (function (root, factory) {
  15946. {
  15947. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  15948. }
  15949. }(this, function (exports, sharedUtil) {
  15950. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15951. // Some characters, e.g. copyrightserif, are mapped to the private use area
  15952. // and might not be displayed using standard fonts. Mapping/hacking well-known
  15953. // chars to the similar equivalents in the normal characters range.
  15954. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  15955. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  15956. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  15957. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  15958. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  15959. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  15960. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  15961. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  15962. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  15963. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  15964. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  15965. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  15966. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  15967. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  15968. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  15969. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  15970. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  15971. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  15972. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  15973. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  15974. t[63724] = 0x239C; // parenleftex (0xF8EC)
  15975. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  15976. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  15977. t[63735] = 0x239F; // parenrightex (0xF8F7)
  15978. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  15979. });
  15980. function mapSpecialUnicodeValues(code) {
  15981. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  15982. return 0;
  15983. } else if (code >= 0xF600 && code <= 0xF8FF) {
  15984. return (getSpecialPUASymbols()[code] || code);
  15985. }
  15986. return code;
  15987. }
  15988. var UnicodeRanges = [
  15989. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  15990. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  15991. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  15992. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  15993. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  15994. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  15995. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  15996. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  15997. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  15998. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  15999. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  16000. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  16001. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  16002. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  16003. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  16004. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  16005. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  16006. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  16007. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  16008. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  16009. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  16010. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  16011. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  16012. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  16013. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  16014. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  16015. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  16016. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  16017. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  16018. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  16019. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  16020. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  16021. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  16022. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  16023. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  16024. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  16025. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  16026. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  16027. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  16028. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  16029. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  16030. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  16031. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  16032. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  16033. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  16034. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  16035. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  16036. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  16037. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  16038. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  16039. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  16040. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  16041. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  16042. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  16043. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  16044. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  16045. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  16046. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  16047. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  16048. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  16049. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  16050. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  16051. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  16052. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  16053. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  16054. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  16055. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  16056. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  16057. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  16058. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  16059. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  16060. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  16061. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  16062. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  16063. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  16064. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  16065. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  16066. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  16067. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  16068. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  16069. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  16070. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  16071. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  16072. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  16073. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  16074. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  16075. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  16076. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  16077. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  16078. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  16079. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  16080. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  16081. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  16082. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  16083. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  16084. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  16085. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  16086. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  16087. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  16088. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  16089. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  16090. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  16091. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  16092. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  16093. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  16094. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  16095. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  16096. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  16097. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  16098. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  16099. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  16100. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  16101. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  16102. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  16103. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  16104. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  16105. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  16106. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  16107. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  16108. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  16109. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  16110. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  16111. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  16112. ];
  16113. function getUnicodeRangeFor(value) {
  16114. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  16115. var range = UnicodeRanges[i];
  16116. if (value >= range.begin && value < range.end) {
  16117. return i;
  16118. }
  16119. }
  16120. return -1;
  16121. }
  16122. function isRTLRangeFor(value) {
  16123. var range = UnicodeRanges[13];
  16124. if (value >= range.begin && value < range.end) {
  16125. return true;
  16126. }
  16127. range = UnicodeRanges[11];
  16128. if (value >= range.begin && value < range.end) {
  16129. return true;
  16130. }
  16131. return false;
  16132. }
  16133. // The normalization table is obtained by filtering the Unicode characters
  16134. // database with <compat> entries.
  16135. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  16136. t['\u00A8'] = '\u0020\u0308';
  16137. t['\u00AF'] = '\u0020\u0304';
  16138. t['\u00B4'] = '\u0020\u0301';
  16139. t['\u00B5'] = '\u03BC';
  16140. t['\u00B8'] = '\u0020\u0327';
  16141. t['\u0132'] = '\u0049\u004A';
  16142. t['\u0133'] = '\u0069\u006A';
  16143. t['\u013F'] = '\u004C\u00B7';
  16144. t['\u0140'] = '\u006C\u00B7';
  16145. t['\u0149'] = '\u02BC\u006E';
  16146. t['\u017F'] = '\u0073';
  16147. t['\u01C4'] = '\u0044\u017D';
  16148. t['\u01C5'] = '\u0044\u017E';
  16149. t['\u01C6'] = '\u0064\u017E';
  16150. t['\u01C7'] = '\u004C\u004A';
  16151. t['\u01C8'] = '\u004C\u006A';
  16152. t['\u01C9'] = '\u006C\u006A';
  16153. t['\u01CA'] = '\u004E\u004A';
  16154. t['\u01CB'] = '\u004E\u006A';
  16155. t['\u01CC'] = '\u006E\u006A';
  16156. t['\u01F1'] = '\u0044\u005A';
  16157. t['\u01F2'] = '\u0044\u007A';
  16158. t['\u01F3'] = '\u0064\u007A';
  16159. t['\u02D8'] = '\u0020\u0306';
  16160. t['\u02D9'] = '\u0020\u0307';
  16161. t['\u02DA'] = '\u0020\u030A';
  16162. t['\u02DB'] = '\u0020\u0328';
  16163. t['\u02DC'] = '\u0020\u0303';
  16164. t['\u02DD'] = '\u0020\u030B';
  16165. t['\u037A'] = '\u0020\u0345';
  16166. t['\u0384'] = '\u0020\u0301';
  16167. t['\u03D0'] = '\u03B2';
  16168. t['\u03D1'] = '\u03B8';
  16169. t['\u03D2'] = '\u03A5';
  16170. t['\u03D5'] = '\u03C6';
  16171. t['\u03D6'] = '\u03C0';
  16172. t['\u03F0'] = '\u03BA';
  16173. t['\u03F1'] = '\u03C1';
  16174. t['\u03F2'] = '\u03C2';
  16175. t['\u03F4'] = '\u0398';
  16176. t['\u03F5'] = '\u03B5';
  16177. t['\u03F9'] = '\u03A3';
  16178. t['\u0587'] = '\u0565\u0582';
  16179. t['\u0675'] = '\u0627\u0674';
  16180. t['\u0676'] = '\u0648\u0674';
  16181. t['\u0677'] = '\u06C7\u0674';
  16182. t['\u0678'] = '\u064A\u0674';
  16183. t['\u0E33'] = '\u0E4D\u0E32';
  16184. t['\u0EB3'] = '\u0ECD\u0EB2';
  16185. t['\u0EDC'] = '\u0EAB\u0E99';
  16186. t['\u0EDD'] = '\u0EAB\u0EA1';
  16187. t['\u0F77'] = '\u0FB2\u0F81';
  16188. t['\u0F79'] = '\u0FB3\u0F81';
  16189. t['\u1E9A'] = '\u0061\u02BE';
  16190. t['\u1FBD'] = '\u0020\u0313';
  16191. t['\u1FBF'] = '\u0020\u0313';
  16192. t['\u1FC0'] = '\u0020\u0342';
  16193. t['\u1FFE'] = '\u0020\u0314';
  16194. t['\u2002'] = '\u0020';
  16195. t['\u2003'] = '\u0020';
  16196. t['\u2004'] = '\u0020';
  16197. t['\u2005'] = '\u0020';
  16198. t['\u2006'] = '\u0020';
  16199. t['\u2008'] = '\u0020';
  16200. t['\u2009'] = '\u0020';
  16201. t['\u200A'] = '\u0020';
  16202. t['\u2017'] = '\u0020\u0333';
  16203. t['\u2024'] = '\u002E';
  16204. t['\u2025'] = '\u002E\u002E';
  16205. t['\u2026'] = '\u002E\u002E\u002E';
  16206. t['\u2033'] = '\u2032\u2032';
  16207. t['\u2034'] = '\u2032\u2032\u2032';
  16208. t['\u2036'] = '\u2035\u2035';
  16209. t['\u2037'] = '\u2035\u2035\u2035';
  16210. t['\u203C'] = '\u0021\u0021';
  16211. t['\u203E'] = '\u0020\u0305';
  16212. t['\u2047'] = '\u003F\u003F';
  16213. t['\u2048'] = '\u003F\u0021';
  16214. t['\u2049'] = '\u0021\u003F';
  16215. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  16216. t['\u205F'] = '\u0020';
  16217. t['\u20A8'] = '\u0052\u0073';
  16218. t['\u2100'] = '\u0061\u002F\u0063';
  16219. t['\u2101'] = '\u0061\u002F\u0073';
  16220. t['\u2103'] = '\u00B0\u0043';
  16221. t['\u2105'] = '\u0063\u002F\u006F';
  16222. t['\u2106'] = '\u0063\u002F\u0075';
  16223. t['\u2107'] = '\u0190';
  16224. t['\u2109'] = '\u00B0\u0046';
  16225. t['\u2116'] = '\u004E\u006F';
  16226. t['\u2121'] = '\u0054\u0045\u004C';
  16227. t['\u2135'] = '\u05D0';
  16228. t['\u2136'] = '\u05D1';
  16229. t['\u2137'] = '\u05D2';
  16230. t['\u2138'] = '\u05D3';
  16231. t['\u213B'] = '\u0046\u0041\u0058';
  16232. t['\u2160'] = '\u0049';
  16233. t['\u2161'] = '\u0049\u0049';
  16234. t['\u2162'] = '\u0049\u0049\u0049';
  16235. t['\u2163'] = '\u0049\u0056';
  16236. t['\u2164'] = '\u0056';
  16237. t['\u2165'] = '\u0056\u0049';
  16238. t['\u2166'] = '\u0056\u0049\u0049';
  16239. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  16240. t['\u2168'] = '\u0049\u0058';
  16241. t['\u2169'] = '\u0058';
  16242. t['\u216A'] = '\u0058\u0049';
  16243. t['\u216B'] = '\u0058\u0049\u0049';
  16244. t['\u216C'] = '\u004C';
  16245. t['\u216D'] = '\u0043';
  16246. t['\u216E'] = '\u0044';
  16247. t['\u216F'] = '\u004D';
  16248. t['\u2170'] = '\u0069';
  16249. t['\u2171'] = '\u0069\u0069';
  16250. t['\u2172'] = '\u0069\u0069\u0069';
  16251. t['\u2173'] = '\u0069\u0076';
  16252. t['\u2174'] = '\u0076';
  16253. t['\u2175'] = '\u0076\u0069';
  16254. t['\u2176'] = '\u0076\u0069\u0069';
  16255. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  16256. t['\u2178'] = '\u0069\u0078';
  16257. t['\u2179'] = '\u0078';
  16258. t['\u217A'] = '\u0078\u0069';
  16259. t['\u217B'] = '\u0078\u0069\u0069';
  16260. t['\u217C'] = '\u006C';
  16261. t['\u217D'] = '\u0063';
  16262. t['\u217E'] = '\u0064';
  16263. t['\u217F'] = '\u006D';
  16264. t['\u222C'] = '\u222B\u222B';
  16265. t['\u222D'] = '\u222B\u222B\u222B';
  16266. t['\u222F'] = '\u222E\u222E';
  16267. t['\u2230'] = '\u222E\u222E\u222E';
  16268. t['\u2474'] = '\u0028\u0031\u0029';
  16269. t['\u2475'] = '\u0028\u0032\u0029';
  16270. t['\u2476'] = '\u0028\u0033\u0029';
  16271. t['\u2477'] = '\u0028\u0034\u0029';
  16272. t['\u2478'] = '\u0028\u0035\u0029';
  16273. t['\u2479'] = '\u0028\u0036\u0029';
  16274. t['\u247A'] = '\u0028\u0037\u0029';
  16275. t['\u247B'] = '\u0028\u0038\u0029';
  16276. t['\u247C'] = '\u0028\u0039\u0029';
  16277. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  16278. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  16279. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  16280. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  16281. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  16282. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  16283. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  16284. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  16285. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  16286. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  16287. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  16288. t['\u2488'] = '\u0031\u002E';
  16289. t['\u2489'] = '\u0032\u002E';
  16290. t['\u248A'] = '\u0033\u002E';
  16291. t['\u248B'] = '\u0034\u002E';
  16292. t['\u248C'] = '\u0035\u002E';
  16293. t['\u248D'] = '\u0036\u002E';
  16294. t['\u248E'] = '\u0037\u002E';
  16295. t['\u248F'] = '\u0038\u002E';
  16296. t['\u2490'] = '\u0039\u002E';
  16297. t['\u2491'] = '\u0031\u0030\u002E';
  16298. t['\u2492'] = '\u0031\u0031\u002E';
  16299. t['\u2493'] = '\u0031\u0032\u002E';
  16300. t['\u2494'] = '\u0031\u0033\u002E';
  16301. t['\u2495'] = '\u0031\u0034\u002E';
  16302. t['\u2496'] = '\u0031\u0035\u002E';
  16303. t['\u2497'] = '\u0031\u0036\u002E';
  16304. t['\u2498'] = '\u0031\u0037\u002E';
  16305. t['\u2499'] = '\u0031\u0038\u002E';
  16306. t['\u249A'] = '\u0031\u0039\u002E';
  16307. t['\u249B'] = '\u0032\u0030\u002E';
  16308. t['\u249C'] = '\u0028\u0061\u0029';
  16309. t['\u249D'] = '\u0028\u0062\u0029';
  16310. t['\u249E'] = '\u0028\u0063\u0029';
  16311. t['\u249F'] = '\u0028\u0064\u0029';
  16312. t['\u24A0'] = '\u0028\u0065\u0029';
  16313. t['\u24A1'] = '\u0028\u0066\u0029';
  16314. t['\u24A2'] = '\u0028\u0067\u0029';
  16315. t['\u24A3'] = '\u0028\u0068\u0029';
  16316. t['\u24A4'] = '\u0028\u0069\u0029';
  16317. t['\u24A5'] = '\u0028\u006A\u0029';
  16318. t['\u24A6'] = '\u0028\u006B\u0029';
  16319. t['\u24A7'] = '\u0028\u006C\u0029';
  16320. t['\u24A8'] = '\u0028\u006D\u0029';
  16321. t['\u24A9'] = '\u0028\u006E\u0029';
  16322. t['\u24AA'] = '\u0028\u006F\u0029';
  16323. t['\u24AB'] = '\u0028\u0070\u0029';
  16324. t['\u24AC'] = '\u0028\u0071\u0029';
  16325. t['\u24AD'] = '\u0028\u0072\u0029';
  16326. t['\u24AE'] = '\u0028\u0073\u0029';
  16327. t['\u24AF'] = '\u0028\u0074\u0029';
  16328. t['\u24B0'] = '\u0028\u0075\u0029';
  16329. t['\u24B1'] = '\u0028\u0076\u0029';
  16330. t['\u24B2'] = '\u0028\u0077\u0029';
  16331. t['\u24B3'] = '\u0028\u0078\u0029';
  16332. t['\u24B4'] = '\u0028\u0079\u0029';
  16333. t['\u24B5'] = '\u0028\u007A\u0029';
  16334. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  16335. t['\u2A74'] = '\u003A\u003A\u003D';
  16336. t['\u2A75'] = '\u003D\u003D';
  16337. t['\u2A76'] = '\u003D\u003D\u003D';
  16338. t['\u2E9F'] = '\u6BCD';
  16339. t['\u2EF3'] = '\u9F9F';
  16340. t['\u2F00'] = '\u4E00';
  16341. t['\u2F01'] = '\u4E28';
  16342. t['\u2F02'] = '\u4E36';
  16343. t['\u2F03'] = '\u4E3F';
  16344. t['\u2F04'] = '\u4E59';
  16345. t['\u2F05'] = '\u4E85';
  16346. t['\u2F06'] = '\u4E8C';
  16347. t['\u2F07'] = '\u4EA0';
  16348. t['\u2F08'] = '\u4EBA';
  16349. t['\u2F09'] = '\u513F';
  16350. t['\u2F0A'] = '\u5165';
  16351. t['\u2F0B'] = '\u516B';
  16352. t['\u2F0C'] = '\u5182';
  16353. t['\u2F0D'] = '\u5196';
  16354. t['\u2F0E'] = '\u51AB';
  16355. t['\u2F0F'] = '\u51E0';
  16356. t['\u2F10'] = '\u51F5';
  16357. t['\u2F11'] = '\u5200';
  16358. t['\u2F12'] = '\u529B';
  16359. t['\u2F13'] = '\u52F9';
  16360. t['\u2F14'] = '\u5315';
  16361. t['\u2F15'] = '\u531A';
  16362. t['\u2F16'] = '\u5338';
  16363. t['\u2F17'] = '\u5341';
  16364. t['\u2F18'] = '\u535C';
  16365. t['\u2F19'] = '\u5369';
  16366. t['\u2F1A'] = '\u5382';
  16367. t['\u2F1B'] = '\u53B6';
  16368. t['\u2F1C'] = '\u53C8';
  16369. t['\u2F1D'] = '\u53E3';
  16370. t['\u2F1E'] = '\u56D7';
  16371. t['\u2F1F'] = '\u571F';
  16372. t['\u2F20'] = '\u58EB';
  16373. t['\u2F21'] = '\u5902';
  16374. t['\u2F22'] = '\u590A';
  16375. t['\u2F23'] = '\u5915';
  16376. t['\u2F24'] = '\u5927';
  16377. t['\u2F25'] = '\u5973';
  16378. t['\u2F26'] = '\u5B50';
  16379. t['\u2F27'] = '\u5B80';
  16380. t['\u2F28'] = '\u5BF8';
  16381. t['\u2F29'] = '\u5C0F';
  16382. t['\u2F2A'] = '\u5C22';
  16383. t['\u2F2B'] = '\u5C38';
  16384. t['\u2F2C'] = '\u5C6E';
  16385. t['\u2F2D'] = '\u5C71';
  16386. t['\u2F2E'] = '\u5DDB';
  16387. t['\u2F2F'] = '\u5DE5';
  16388. t['\u2F30'] = '\u5DF1';
  16389. t['\u2F31'] = '\u5DFE';
  16390. t['\u2F32'] = '\u5E72';
  16391. t['\u2F33'] = '\u5E7A';
  16392. t['\u2F34'] = '\u5E7F';
  16393. t['\u2F35'] = '\u5EF4';
  16394. t['\u2F36'] = '\u5EFE';
  16395. t['\u2F37'] = '\u5F0B';
  16396. t['\u2F38'] = '\u5F13';
  16397. t['\u2F39'] = '\u5F50';
  16398. t['\u2F3A'] = '\u5F61';
  16399. t['\u2F3B'] = '\u5F73';
  16400. t['\u2F3C'] = '\u5FC3';
  16401. t['\u2F3D'] = '\u6208';
  16402. t['\u2F3E'] = '\u6236';
  16403. t['\u2F3F'] = '\u624B';
  16404. t['\u2F40'] = '\u652F';
  16405. t['\u2F41'] = '\u6534';
  16406. t['\u2F42'] = '\u6587';
  16407. t['\u2F43'] = '\u6597';
  16408. t['\u2F44'] = '\u65A4';
  16409. t['\u2F45'] = '\u65B9';
  16410. t['\u2F46'] = '\u65E0';
  16411. t['\u2F47'] = '\u65E5';
  16412. t['\u2F48'] = '\u66F0';
  16413. t['\u2F49'] = '\u6708';
  16414. t['\u2F4A'] = '\u6728';
  16415. t['\u2F4B'] = '\u6B20';
  16416. t['\u2F4C'] = '\u6B62';
  16417. t['\u2F4D'] = '\u6B79';
  16418. t['\u2F4E'] = '\u6BB3';
  16419. t['\u2F4F'] = '\u6BCB';
  16420. t['\u2F50'] = '\u6BD4';
  16421. t['\u2F51'] = '\u6BDB';
  16422. t['\u2F52'] = '\u6C0F';
  16423. t['\u2F53'] = '\u6C14';
  16424. t['\u2F54'] = '\u6C34';
  16425. t['\u2F55'] = '\u706B';
  16426. t['\u2F56'] = '\u722A';
  16427. t['\u2F57'] = '\u7236';
  16428. t['\u2F58'] = '\u723B';
  16429. t['\u2F59'] = '\u723F';
  16430. t['\u2F5A'] = '\u7247';
  16431. t['\u2F5B'] = '\u7259';
  16432. t['\u2F5C'] = '\u725B';
  16433. t['\u2F5D'] = '\u72AC';
  16434. t['\u2F5E'] = '\u7384';
  16435. t['\u2F5F'] = '\u7389';
  16436. t['\u2F60'] = '\u74DC';
  16437. t['\u2F61'] = '\u74E6';
  16438. t['\u2F62'] = '\u7518';
  16439. t['\u2F63'] = '\u751F';
  16440. t['\u2F64'] = '\u7528';
  16441. t['\u2F65'] = '\u7530';
  16442. t['\u2F66'] = '\u758B';
  16443. t['\u2F67'] = '\u7592';
  16444. t['\u2F68'] = '\u7676';
  16445. t['\u2F69'] = '\u767D';
  16446. t['\u2F6A'] = '\u76AE';
  16447. t['\u2F6B'] = '\u76BF';
  16448. t['\u2F6C'] = '\u76EE';
  16449. t['\u2F6D'] = '\u77DB';
  16450. t['\u2F6E'] = '\u77E2';
  16451. t['\u2F6F'] = '\u77F3';
  16452. t['\u2F70'] = '\u793A';
  16453. t['\u2F71'] = '\u79B8';
  16454. t['\u2F72'] = '\u79BE';
  16455. t['\u2F73'] = '\u7A74';
  16456. t['\u2F74'] = '\u7ACB';
  16457. t['\u2F75'] = '\u7AF9';
  16458. t['\u2F76'] = '\u7C73';
  16459. t['\u2F77'] = '\u7CF8';
  16460. t['\u2F78'] = '\u7F36';
  16461. t['\u2F79'] = '\u7F51';
  16462. t['\u2F7A'] = '\u7F8A';
  16463. t['\u2F7B'] = '\u7FBD';
  16464. t['\u2F7C'] = '\u8001';
  16465. t['\u2F7D'] = '\u800C';
  16466. t['\u2F7E'] = '\u8012';
  16467. t['\u2F7F'] = '\u8033';
  16468. t['\u2F80'] = '\u807F';
  16469. t['\u2F81'] = '\u8089';
  16470. t['\u2F82'] = '\u81E3';
  16471. t['\u2F83'] = '\u81EA';
  16472. t['\u2F84'] = '\u81F3';
  16473. t['\u2F85'] = '\u81FC';
  16474. t['\u2F86'] = '\u820C';
  16475. t['\u2F87'] = '\u821B';
  16476. t['\u2F88'] = '\u821F';
  16477. t['\u2F89'] = '\u826E';
  16478. t['\u2F8A'] = '\u8272';
  16479. t['\u2F8B'] = '\u8278';
  16480. t['\u2F8C'] = '\u864D';
  16481. t['\u2F8D'] = '\u866B';
  16482. t['\u2F8E'] = '\u8840';
  16483. t['\u2F8F'] = '\u884C';
  16484. t['\u2F90'] = '\u8863';
  16485. t['\u2F91'] = '\u897E';
  16486. t['\u2F92'] = '\u898B';
  16487. t['\u2F93'] = '\u89D2';
  16488. t['\u2F94'] = '\u8A00';
  16489. t['\u2F95'] = '\u8C37';
  16490. t['\u2F96'] = '\u8C46';
  16491. t['\u2F97'] = '\u8C55';
  16492. t['\u2F98'] = '\u8C78';
  16493. t['\u2F99'] = '\u8C9D';
  16494. t['\u2F9A'] = '\u8D64';
  16495. t['\u2F9B'] = '\u8D70';
  16496. t['\u2F9C'] = '\u8DB3';
  16497. t['\u2F9D'] = '\u8EAB';
  16498. t['\u2F9E'] = '\u8ECA';
  16499. t['\u2F9F'] = '\u8F9B';
  16500. t['\u2FA0'] = '\u8FB0';
  16501. t['\u2FA1'] = '\u8FB5';
  16502. t['\u2FA2'] = '\u9091';
  16503. t['\u2FA3'] = '\u9149';
  16504. t['\u2FA4'] = '\u91C6';
  16505. t['\u2FA5'] = '\u91CC';
  16506. t['\u2FA6'] = '\u91D1';
  16507. t['\u2FA7'] = '\u9577';
  16508. t['\u2FA8'] = '\u9580';
  16509. t['\u2FA9'] = '\u961C';
  16510. t['\u2FAA'] = '\u96B6';
  16511. t['\u2FAB'] = '\u96B9';
  16512. t['\u2FAC'] = '\u96E8';
  16513. t['\u2FAD'] = '\u9751';
  16514. t['\u2FAE'] = '\u975E';
  16515. t['\u2FAF'] = '\u9762';
  16516. t['\u2FB0'] = '\u9769';
  16517. t['\u2FB1'] = '\u97CB';
  16518. t['\u2FB2'] = '\u97ED';
  16519. t['\u2FB3'] = '\u97F3';
  16520. t['\u2FB4'] = '\u9801';
  16521. t['\u2FB5'] = '\u98A8';
  16522. t['\u2FB6'] = '\u98DB';
  16523. t['\u2FB7'] = '\u98DF';
  16524. t['\u2FB8'] = '\u9996';
  16525. t['\u2FB9'] = '\u9999';
  16526. t['\u2FBA'] = '\u99AC';
  16527. t['\u2FBB'] = '\u9AA8';
  16528. t['\u2FBC'] = '\u9AD8';
  16529. t['\u2FBD'] = '\u9ADF';
  16530. t['\u2FBE'] = '\u9B25';
  16531. t['\u2FBF'] = '\u9B2F';
  16532. t['\u2FC0'] = '\u9B32';
  16533. t['\u2FC1'] = '\u9B3C';
  16534. t['\u2FC2'] = '\u9B5A';
  16535. t['\u2FC3'] = '\u9CE5';
  16536. t['\u2FC4'] = '\u9E75';
  16537. t['\u2FC5'] = '\u9E7F';
  16538. t['\u2FC6'] = '\u9EA5';
  16539. t['\u2FC7'] = '\u9EBB';
  16540. t['\u2FC8'] = '\u9EC3';
  16541. t['\u2FC9'] = '\u9ECD';
  16542. t['\u2FCA'] = '\u9ED1';
  16543. t['\u2FCB'] = '\u9EF9';
  16544. t['\u2FCC'] = '\u9EFD';
  16545. t['\u2FCD'] = '\u9F0E';
  16546. t['\u2FCE'] = '\u9F13';
  16547. t['\u2FCF'] = '\u9F20';
  16548. t['\u2FD0'] = '\u9F3B';
  16549. t['\u2FD1'] = '\u9F4A';
  16550. t['\u2FD2'] = '\u9F52';
  16551. t['\u2FD3'] = '\u9F8D';
  16552. t['\u2FD4'] = '\u9F9C';
  16553. t['\u2FD5'] = '\u9FA0';
  16554. t['\u3036'] = '\u3012';
  16555. t['\u3038'] = '\u5341';
  16556. t['\u3039'] = '\u5344';
  16557. t['\u303A'] = '\u5345';
  16558. t['\u309B'] = '\u0020\u3099';
  16559. t['\u309C'] = '\u0020\u309A';
  16560. t['\u3131'] = '\u1100';
  16561. t['\u3132'] = '\u1101';
  16562. t['\u3133'] = '\u11AA';
  16563. t['\u3134'] = '\u1102';
  16564. t['\u3135'] = '\u11AC';
  16565. t['\u3136'] = '\u11AD';
  16566. t['\u3137'] = '\u1103';
  16567. t['\u3138'] = '\u1104';
  16568. t['\u3139'] = '\u1105';
  16569. t['\u313A'] = '\u11B0';
  16570. t['\u313B'] = '\u11B1';
  16571. t['\u313C'] = '\u11B2';
  16572. t['\u313D'] = '\u11B3';
  16573. t['\u313E'] = '\u11B4';
  16574. t['\u313F'] = '\u11B5';
  16575. t['\u3140'] = '\u111A';
  16576. t['\u3141'] = '\u1106';
  16577. t['\u3142'] = '\u1107';
  16578. t['\u3143'] = '\u1108';
  16579. t['\u3144'] = '\u1121';
  16580. t['\u3145'] = '\u1109';
  16581. t['\u3146'] = '\u110A';
  16582. t['\u3147'] = '\u110B';
  16583. t['\u3148'] = '\u110C';
  16584. t['\u3149'] = '\u110D';
  16585. t['\u314A'] = '\u110E';
  16586. t['\u314B'] = '\u110F';
  16587. t['\u314C'] = '\u1110';
  16588. t['\u314D'] = '\u1111';
  16589. t['\u314E'] = '\u1112';
  16590. t['\u314F'] = '\u1161';
  16591. t['\u3150'] = '\u1162';
  16592. t['\u3151'] = '\u1163';
  16593. t['\u3152'] = '\u1164';
  16594. t['\u3153'] = '\u1165';
  16595. t['\u3154'] = '\u1166';
  16596. t['\u3155'] = '\u1167';
  16597. t['\u3156'] = '\u1168';
  16598. t['\u3157'] = '\u1169';
  16599. t['\u3158'] = '\u116A';
  16600. t['\u3159'] = '\u116B';
  16601. t['\u315A'] = '\u116C';
  16602. t['\u315B'] = '\u116D';
  16603. t['\u315C'] = '\u116E';
  16604. t['\u315D'] = '\u116F';
  16605. t['\u315E'] = '\u1170';
  16606. t['\u315F'] = '\u1171';
  16607. t['\u3160'] = '\u1172';
  16608. t['\u3161'] = '\u1173';
  16609. t['\u3162'] = '\u1174';
  16610. t['\u3163'] = '\u1175';
  16611. t['\u3164'] = '\u1160';
  16612. t['\u3165'] = '\u1114';
  16613. t['\u3166'] = '\u1115';
  16614. t['\u3167'] = '\u11C7';
  16615. t['\u3168'] = '\u11C8';
  16616. t['\u3169'] = '\u11CC';
  16617. t['\u316A'] = '\u11CE';
  16618. t['\u316B'] = '\u11D3';
  16619. t['\u316C'] = '\u11D7';
  16620. t['\u316D'] = '\u11D9';
  16621. t['\u316E'] = '\u111C';
  16622. t['\u316F'] = '\u11DD';
  16623. t['\u3170'] = '\u11DF';
  16624. t['\u3171'] = '\u111D';
  16625. t['\u3172'] = '\u111E';
  16626. t['\u3173'] = '\u1120';
  16627. t['\u3174'] = '\u1122';
  16628. t['\u3175'] = '\u1123';
  16629. t['\u3176'] = '\u1127';
  16630. t['\u3177'] = '\u1129';
  16631. t['\u3178'] = '\u112B';
  16632. t['\u3179'] = '\u112C';
  16633. t['\u317A'] = '\u112D';
  16634. t['\u317B'] = '\u112E';
  16635. t['\u317C'] = '\u112F';
  16636. t['\u317D'] = '\u1132';
  16637. t['\u317E'] = '\u1136';
  16638. t['\u317F'] = '\u1140';
  16639. t['\u3180'] = '\u1147';
  16640. t['\u3181'] = '\u114C';
  16641. t['\u3182'] = '\u11F1';
  16642. t['\u3183'] = '\u11F2';
  16643. t['\u3184'] = '\u1157';
  16644. t['\u3185'] = '\u1158';
  16645. t['\u3186'] = '\u1159';
  16646. t['\u3187'] = '\u1184';
  16647. t['\u3188'] = '\u1185';
  16648. t['\u3189'] = '\u1188';
  16649. t['\u318A'] = '\u1191';
  16650. t['\u318B'] = '\u1192';
  16651. t['\u318C'] = '\u1194';
  16652. t['\u318D'] = '\u119E';
  16653. t['\u318E'] = '\u11A1';
  16654. t['\u3200'] = '\u0028\u1100\u0029';
  16655. t['\u3201'] = '\u0028\u1102\u0029';
  16656. t['\u3202'] = '\u0028\u1103\u0029';
  16657. t['\u3203'] = '\u0028\u1105\u0029';
  16658. t['\u3204'] = '\u0028\u1106\u0029';
  16659. t['\u3205'] = '\u0028\u1107\u0029';
  16660. t['\u3206'] = '\u0028\u1109\u0029';
  16661. t['\u3207'] = '\u0028\u110B\u0029';
  16662. t['\u3208'] = '\u0028\u110C\u0029';
  16663. t['\u3209'] = '\u0028\u110E\u0029';
  16664. t['\u320A'] = '\u0028\u110F\u0029';
  16665. t['\u320B'] = '\u0028\u1110\u0029';
  16666. t['\u320C'] = '\u0028\u1111\u0029';
  16667. t['\u320D'] = '\u0028\u1112\u0029';
  16668. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  16669. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  16670. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  16671. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  16672. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  16673. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  16674. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  16675. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  16676. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  16677. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  16678. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  16679. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  16680. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  16681. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  16682. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  16683. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  16684. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  16685. t['\u3220'] = '\u0028\u4E00\u0029';
  16686. t['\u3221'] = '\u0028\u4E8C\u0029';
  16687. t['\u3222'] = '\u0028\u4E09\u0029';
  16688. t['\u3223'] = '\u0028\u56DB\u0029';
  16689. t['\u3224'] = '\u0028\u4E94\u0029';
  16690. t['\u3225'] = '\u0028\u516D\u0029';
  16691. t['\u3226'] = '\u0028\u4E03\u0029';
  16692. t['\u3227'] = '\u0028\u516B\u0029';
  16693. t['\u3228'] = '\u0028\u4E5D\u0029';
  16694. t['\u3229'] = '\u0028\u5341\u0029';
  16695. t['\u322A'] = '\u0028\u6708\u0029';
  16696. t['\u322B'] = '\u0028\u706B\u0029';
  16697. t['\u322C'] = '\u0028\u6C34\u0029';
  16698. t['\u322D'] = '\u0028\u6728\u0029';
  16699. t['\u322E'] = '\u0028\u91D1\u0029';
  16700. t['\u322F'] = '\u0028\u571F\u0029';
  16701. t['\u3230'] = '\u0028\u65E5\u0029';
  16702. t['\u3231'] = '\u0028\u682A\u0029';
  16703. t['\u3232'] = '\u0028\u6709\u0029';
  16704. t['\u3233'] = '\u0028\u793E\u0029';
  16705. t['\u3234'] = '\u0028\u540D\u0029';
  16706. t['\u3235'] = '\u0028\u7279\u0029';
  16707. t['\u3236'] = '\u0028\u8CA1\u0029';
  16708. t['\u3237'] = '\u0028\u795D\u0029';
  16709. t['\u3238'] = '\u0028\u52B4\u0029';
  16710. t['\u3239'] = '\u0028\u4EE3\u0029';
  16711. t['\u323A'] = '\u0028\u547C\u0029';
  16712. t['\u323B'] = '\u0028\u5B66\u0029';
  16713. t['\u323C'] = '\u0028\u76E3\u0029';
  16714. t['\u323D'] = '\u0028\u4F01\u0029';
  16715. t['\u323E'] = '\u0028\u8CC7\u0029';
  16716. t['\u323F'] = '\u0028\u5354\u0029';
  16717. t['\u3240'] = '\u0028\u796D\u0029';
  16718. t['\u3241'] = '\u0028\u4F11\u0029';
  16719. t['\u3242'] = '\u0028\u81EA\u0029';
  16720. t['\u3243'] = '\u0028\u81F3\u0029';
  16721. t['\u32C0'] = '\u0031\u6708';
  16722. t['\u32C1'] = '\u0032\u6708';
  16723. t['\u32C2'] = '\u0033\u6708';
  16724. t['\u32C3'] = '\u0034\u6708';
  16725. t['\u32C4'] = '\u0035\u6708';
  16726. t['\u32C5'] = '\u0036\u6708';
  16727. t['\u32C6'] = '\u0037\u6708';
  16728. t['\u32C7'] = '\u0038\u6708';
  16729. t['\u32C8'] = '\u0039\u6708';
  16730. t['\u32C9'] = '\u0031\u0030\u6708';
  16731. t['\u32CA'] = '\u0031\u0031\u6708';
  16732. t['\u32CB'] = '\u0031\u0032\u6708';
  16733. t['\u3358'] = '\u0030\u70B9';
  16734. t['\u3359'] = '\u0031\u70B9';
  16735. t['\u335A'] = '\u0032\u70B9';
  16736. t['\u335B'] = '\u0033\u70B9';
  16737. t['\u335C'] = '\u0034\u70B9';
  16738. t['\u335D'] = '\u0035\u70B9';
  16739. t['\u335E'] = '\u0036\u70B9';
  16740. t['\u335F'] = '\u0037\u70B9';
  16741. t['\u3360'] = '\u0038\u70B9';
  16742. t['\u3361'] = '\u0039\u70B9';
  16743. t['\u3362'] = '\u0031\u0030\u70B9';
  16744. t['\u3363'] = '\u0031\u0031\u70B9';
  16745. t['\u3364'] = '\u0031\u0032\u70B9';
  16746. t['\u3365'] = '\u0031\u0033\u70B9';
  16747. t['\u3366'] = '\u0031\u0034\u70B9';
  16748. t['\u3367'] = '\u0031\u0035\u70B9';
  16749. t['\u3368'] = '\u0031\u0036\u70B9';
  16750. t['\u3369'] = '\u0031\u0037\u70B9';
  16751. t['\u336A'] = '\u0031\u0038\u70B9';
  16752. t['\u336B'] = '\u0031\u0039\u70B9';
  16753. t['\u336C'] = '\u0032\u0030\u70B9';
  16754. t['\u336D'] = '\u0032\u0031\u70B9';
  16755. t['\u336E'] = '\u0032\u0032\u70B9';
  16756. t['\u336F'] = '\u0032\u0033\u70B9';
  16757. t['\u3370'] = '\u0032\u0034\u70B9';
  16758. t['\u33E0'] = '\u0031\u65E5';
  16759. t['\u33E1'] = '\u0032\u65E5';
  16760. t['\u33E2'] = '\u0033\u65E5';
  16761. t['\u33E3'] = '\u0034\u65E5';
  16762. t['\u33E4'] = '\u0035\u65E5';
  16763. t['\u33E5'] = '\u0036\u65E5';
  16764. t['\u33E6'] = '\u0037\u65E5';
  16765. t['\u33E7'] = '\u0038\u65E5';
  16766. t['\u33E8'] = '\u0039\u65E5';
  16767. t['\u33E9'] = '\u0031\u0030\u65E5';
  16768. t['\u33EA'] = '\u0031\u0031\u65E5';
  16769. t['\u33EB'] = '\u0031\u0032\u65E5';
  16770. t['\u33EC'] = '\u0031\u0033\u65E5';
  16771. t['\u33ED'] = '\u0031\u0034\u65E5';
  16772. t['\u33EE'] = '\u0031\u0035\u65E5';
  16773. t['\u33EF'] = '\u0031\u0036\u65E5';
  16774. t['\u33F0'] = '\u0031\u0037\u65E5';
  16775. t['\u33F1'] = '\u0031\u0038\u65E5';
  16776. t['\u33F2'] = '\u0031\u0039\u65E5';
  16777. t['\u33F3'] = '\u0032\u0030\u65E5';
  16778. t['\u33F4'] = '\u0032\u0031\u65E5';
  16779. t['\u33F5'] = '\u0032\u0032\u65E5';
  16780. t['\u33F6'] = '\u0032\u0033\u65E5';
  16781. t['\u33F7'] = '\u0032\u0034\u65E5';
  16782. t['\u33F8'] = '\u0032\u0035\u65E5';
  16783. t['\u33F9'] = '\u0032\u0036\u65E5';
  16784. t['\u33FA'] = '\u0032\u0037\u65E5';
  16785. t['\u33FB'] = '\u0032\u0038\u65E5';
  16786. t['\u33FC'] = '\u0032\u0039\u65E5';
  16787. t['\u33FD'] = '\u0033\u0030\u65E5';
  16788. t['\u33FE'] = '\u0033\u0031\u65E5';
  16789. t['\uFB00'] = '\u0066\u0066';
  16790. t['\uFB01'] = '\u0066\u0069';
  16791. t['\uFB02'] = '\u0066\u006C';
  16792. t['\uFB03'] = '\u0066\u0066\u0069';
  16793. t['\uFB04'] = '\u0066\u0066\u006C';
  16794. t['\uFB05'] = '\u017F\u0074';
  16795. t['\uFB06'] = '\u0073\u0074';
  16796. t['\uFB13'] = '\u0574\u0576';
  16797. t['\uFB14'] = '\u0574\u0565';
  16798. t['\uFB15'] = '\u0574\u056B';
  16799. t['\uFB16'] = '\u057E\u0576';
  16800. t['\uFB17'] = '\u0574\u056D';
  16801. t['\uFB4F'] = '\u05D0\u05DC';
  16802. t['\uFB50'] = '\u0671';
  16803. t['\uFB51'] = '\u0671';
  16804. t['\uFB52'] = '\u067B';
  16805. t['\uFB53'] = '\u067B';
  16806. t['\uFB54'] = '\u067B';
  16807. t['\uFB55'] = '\u067B';
  16808. t['\uFB56'] = '\u067E';
  16809. t['\uFB57'] = '\u067E';
  16810. t['\uFB58'] = '\u067E';
  16811. t['\uFB59'] = '\u067E';
  16812. t['\uFB5A'] = '\u0680';
  16813. t['\uFB5B'] = '\u0680';
  16814. t['\uFB5C'] = '\u0680';
  16815. t['\uFB5D'] = '\u0680';
  16816. t['\uFB5E'] = '\u067A';
  16817. t['\uFB5F'] = '\u067A';
  16818. t['\uFB60'] = '\u067A';
  16819. t['\uFB61'] = '\u067A';
  16820. t['\uFB62'] = '\u067F';
  16821. t['\uFB63'] = '\u067F';
  16822. t['\uFB64'] = '\u067F';
  16823. t['\uFB65'] = '\u067F';
  16824. t['\uFB66'] = '\u0679';
  16825. t['\uFB67'] = '\u0679';
  16826. t['\uFB68'] = '\u0679';
  16827. t['\uFB69'] = '\u0679';
  16828. t['\uFB6A'] = '\u06A4';
  16829. t['\uFB6B'] = '\u06A4';
  16830. t['\uFB6C'] = '\u06A4';
  16831. t['\uFB6D'] = '\u06A4';
  16832. t['\uFB6E'] = '\u06A6';
  16833. t['\uFB6F'] = '\u06A6';
  16834. t['\uFB70'] = '\u06A6';
  16835. t['\uFB71'] = '\u06A6';
  16836. t['\uFB72'] = '\u0684';
  16837. t['\uFB73'] = '\u0684';
  16838. t['\uFB74'] = '\u0684';
  16839. t['\uFB75'] = '\u0684';
  16840. t['\uFB76'] = '\u0683';
  16841. t['\uFB77'] = '\u0683';
  16842. t['\uFB78'] = '\u0683';
  16843. t['\uFB79'] = '\u0683';
  16844. t['\uFB7A'] = '\u0686';
  16845. t['\uFB7B'] = '\u0686';
  16846. t['\uFB7C'] = '\u0686';
  16847. t['\uFB7D'] = '\u0686';
  16848. t['\uFB7E'] = '\u0687';
  16849. t['\uFB7F'] = '\u0687';
  16850. t['\uFB80'] = '\u0687';
  16851. t['\uFB81'] = '\u0687';
  16852. t['\uFB82'] = '\u068D';
  16853. t['\uFB83'] = '\u068D';
  16854. t['\uFB84'] = '\u068C';
  16855. t['\uFB85'] = '\u068C';
  16856. t['\uFB86'] = '\u068E';
  16857. t['\uFB87'] = '\u068E';
  16858. t['\uFB88'] = '\u0688';
  16859. t['\uFB89'] = '\u0688';
  16860. t['\uFB8A'] = '\u0698';
  16861. t['\uFB8B'] = '\u0698';
  16862. t['\uFB8C'] = '\u0691';
  16863. t['\uFB8D'] = '\u0691';
  16864. t['\uFB8E'] = '\u06A9';
  16865. t['\uFB8F'] = '\u06A9';
  16866. t['\uFB90'] = '\u06A9';
  16867. t['\uFB91'] = '\u06A9';
  16868. t['\uFB92'] = '\u06AF';
  16869. t['\uFB93'] = '\u06AF';
  16870. t['\uFB94'] = '\u06AF';
  16871. t['\uFB95'] = '\u06AF';
  16872. t['\uFB96'] = '\u06B3';
  16873. t['\uFB97'] = '\u06B3';
  16874. t['\uFB98'] = '\u06B3';
  16875. t['\uFB99'] = '\u06B3';
  16876. t['\uFB9A'] = '\u06B1';
  16877. t['\uFB9B'] = '\u06B1';
  16878. t['\uFB9C'] = '\u06B1';
  16879. t['\uFB9D'] = '\u06B1';
  16880. t['\uFB9E'] = '\u06BA';
  16881. t['\uFB9F'] = '\u06BA';
  16882. t['\uFBA0'] = '\u06BB';
  16883. t['\uFBA1'] = '\u06BB';
  16884. t['\uFBA2'] = '\u06BB';
  16885. t['\uFBA3'] = '\u06BB';
  16886. t['\uFBA4'] = '\u06C0';
  16887. t['\uFBA5'] = '\u06C0';
  16888. t['\uFBA6'] = '\u06C1';
  16889. t['\uFBA7'] = '\u06C1';
  16890. t['\uFBA8'] = '\u06C1';
  16891. t['\uFBA9'] = '\u06C1';
  16892. t['\uFBAA'] = '\u06BE';
  16893. t['\uFBAB'] = '\u06BE';
  16894. t['\uFBAC'] = '\u06BE';
  16895. t['\uFBAD'] = '\u06BE';
  16896. t['\uFBAE'] = '\u06D2';
  16897. t['\uFBAF'] = '\u06D2';
  16898. t['\uFBB0'] = '\u06D3';
  16899. t['\uFBB1'] = '\u06D3';
  16900. t['\uFBD3'] = '\u06AD';
  16901. t['\uFBD4'] = '\u06AD';
  16902. t['\uFBD5'] = '\u06AD';
  16903. t['\uFBD6'] = '\u06AD';
  16904. t['\uFBD7'] = '\u06C7';
  16905. t['\uFBD8'] = '\u06C7';
  16906. t['\uFBD9'] = '\u06C6';
  16907. t['\uFBDA'] = '\u06C6';
  16908. t['\uFBDB'] = '\u06C8';
  16909. t['\uFBDC'] = '\u06C8';
  16910. t['\uFBDD'] = '\u0677';
  16911. t['\uFBDE'] = '\u06CB';
  16912. t['\uFBDF'] = '\u06CB';
  16913. t['\uFBE0'] = '\u06C5';
  16914. t['\uFBE1'] = '\u06C5';
  16915. t['\uFBE2'] = '\u06C9';
  16916. t['\uFBE3'] = '\u06C9';
  16917. t['\uFBE4'] = '\u06D0';
  16918. t['\uFBE5'] = '\u06D0';
  16919. t['\uFBE6'] = '\u06D0';
  16920. t['\uFBE7'] = '\u06D0';
  16921. t['\uFBE8'] = '\u0649';
  16922. t['\uFBE9'] = '\u0649';
  16923. t['\uFBEA'] = '\u0626\u0627';
  16924. t['\uFBEB'] = '\u0626\u0627';
  16925. t['\uFBEC'] = '\u0626\u06D5';
  16926. t['\uFBED'] = '\u0626\u06D5';
  16927. t['\uFBEE'] = '\u0626\u0648';
  16928. t['\uFBEF'] = '\u0626\u0648';
  16929. t['\uFBF0'] = '\u0626\u06C7';
  16930. t['\uFBF1'] = '\u0626\u06C7';
  16931. t['\uFBF2'] = '\u0626\u06C6';
  16932. t['\uFBF3'] = '\u0626\u06C6';
  16933. t['\uFBF4'] = '\u0626\u06C8';
  16934. t['\uFBF5'] = '\u0626\u06C8';
  16935. t['\uFBF6'] = '\u0626\u06D0';
  16936. t['\uFBF7'] = '\u0626\u06D0';
  16937. t['\uFBF8'] = '\u0626\u06D0';
  16938. t['\uFBF9'] = '\u0626\u0649';
  16939. t['\uFBFA'] = '\u0626\u0649';
  16940. t['\uFBFB'] = '\u0626\u0649';
  16941. t['\uFBFC'] = '\u06CC';
  16942. t['\uFBFD'] = '\u06CC';
  16943. t['\uFBFE'] = '\u06CC';
  16944. t['\uFBFF'] = '\u06CC';
  16945. t['\uFC00'] = '\u0626\u062C';
  16946. t['\uFC01'] = '\u0626\u062D';
  16947. t['\uFC02'] = '\u0626\u0645';
  16948. t['\uFC03'] = '\u0626\u0649';
  16949. t['\uFC04'] = '\u0626\u064A';
  16950. t['\uFC05'] = '\u0628\u062C';
  16951. t['\uFC06'] = '\u0628\u062D';
  16952. t['\uFC07'] = '\u0628\u062E';
  16953. t['\uFC08'] = '\u0628\u0645';
  16954. t['\uFC09'] = '\u0628\u0649';
  16955. t['\uFC0A'] = '\u0628\u064A';
  16956. t['\uFC0B'] = '\u062A\u062C';
  16957. t['\uFC0C'] = '\u062A\u062D';
  16958. t['\uFC0D'] = '\u062A\u062E';
  16959. t['\uFC0E'] = '\u062A\u0645';
  16960. t['\uFC0F'] = '\u062A\u0649';
  16961. t['\uFC10'] = '\u062A\u064A';
  16962. t['\uFC11'] = '\u062B\u062C';
  16963. t['\uFC12'] = '\u062B\u0645';
  16964. t['\uFC13'] = '\u062B\u0649';
  16965. t['\uFC14'] = '\u062B\u064A';
  16966. t['\uFC15'] = '\u062C\u062D';
  16967. t['\uFC16'] = '\u062C\u0645';
  16968. t['\uFC17'] = '\u062D\u062C';
  16969. t['\uFC18'] = '\u062D\u0645';
  16970. t['\uFC19'] = '\u062E\u062C';
  16971. t['\uFC1A'] = '\u062E\u062D';
  16972. t['\uFC1B'] = '\u062E\u0645';
  16973. t['\uFC1C'] = '\u0633\u062C';
  16974. t['\uFC1D'] = '\u0633\u062D';
  16975. t['\uFC1E'] = '\u0633\u062E';
  16976. t['\uFC1F'] = '\u0633\u0645';
  16977. t['\uFC20'] = '\u0635\u062D';
  16978. t['\uFC21'] = '\u0635\u0645';
  16979. t['\uFC22'] = '\u0636\u062C';
  16980. t['\uFC23'] = '\u0636\u062D';
  16981. t['\uFC24'] = '\u0636\u062E';
  16982. t['\uFC25'] = '\u0636\u0645';
  16983. t['\uFC26'] = '\u0637\u062D';
  16984. t['\uFC27'] = '\u0637\u0645';
  16985. t['\uFC28'] = '\u0638\u0645';
  16986. t['\uFC29'] = '\u0639\u062C';
  16987. t['\uFC2A'] = '\u0639\u0645';
  16988. t['\uFC2B'] = '\u063A\u062C';
  16989. t['\uFC2C'] = '\u063A\u0645';
  16990. t['\uFC2D'] = '\u0641\u062C';
  16991. t['\uFC2E'] = '\u0641\u062D';
  16992. t['\uFC2F'] = '\u0641\u062E';
  16993. t['\uFC30'] = '\u0641\u0645';
  16994. t['\uFC31'] = '\u0641\u0649';
  16995. t['\uFC32'] = '\u0641\u064A';
  16996. t['\uFC33'] = '\u0642\u062D';
  16997. t['\uFC34'] = '\u0642\u0645';
  16998. t['\uFC35'] = '\u0642\u0649';
  16999. t['\uFC36'] = '\u0642\u064A';
  17000. t['\uFC37'] = '\u0643\u0627';
  17001. t['\uFC38'] = '\u0643\u062C';
  17002. t['\uFC39'] = '\u0643\u062D';
  17003. t['\uFC3A'] = '\u0643\u062E';
  17004. t['\uFC3B'] = '\u0643\u0644';
  17005. t['\uFC3C'] = '\u0643\u0645';
  17006. t['\uFC3D'] = '\u0643\u0649';
  17007. t['\uFC3E'] = '\u0643\u064A';
  17008. t['\uFC3F'] = '\u0644\u062C';
  17009. t['\uFC40'] = '\u0644\u062D';
  17010. t['\uFC41'] = '\u0644\u062E';
  17011. t['\uFC42'] = '\u0644\u0645';
  17012. t['\uFC43'] = '\u0644\u0649';
  17013. t['\uFC44'] = '\u0644\u064A';
  17014. t['\uFC45'] = '\u0645\u062C';
  17015. t['\uFC46'] = '\u0645\u062D';
  17016. t['\uFC47'] = '\u0645\u062E';
  17017. t['\uFC48'] = '\u0645\u0645';
  17018. t['\uFC49'] = '\u0645\u0649';
  17019. t['\uFC4A'] = '\u0645\u064A';
  17020. t['\uFC4B'] = '\u0646\u062C';
  17021. t['\uFC4C'] = '\u0646\u062D';
  17022. t['\uFC4D'] = '\u0646\u062E';
  17023. t['\uFC4E'] = '\u0646\u0645';
  17024. t['\uFC4F'] = '\u0646\u0649';
  17025. t['\uFC50'] = '\u0646\u064A';
  17026. t['\uFC51'] = '\u0647\u062C';
  17027. t['\uFC52'] = '\u0647\u0645';
  17028. t['\uFC53'] = '\u0647\u0649';
  17029. t['\uFC54'] = '\u0647\u064A';
  17030. t['\uFC55'] = '\u064A\u062C';
  17031. t['\uFC56'] = '\u064A\u062D';
  17032. t['\uFC57'] = '\u064A\u062E';
  17033. t['\uFC58'] = '\u064A\u0645';
  17034. t['\uFC59'] = '\u064A\u0649';
  17035. t['\uFC5A'] = '\u064A\u064A';
  17036. t['\uFC5B'] = '\u0630\u0670';
  17037. t['\uFC5C'] = '\u0631\u0670';
  17038. t['\uFC5D'] = '\u0649\u0670';
  17039. t['\uFC5E'] = '\u0020\u064C\u0651';
  17040. t['\uFC5F'] = '\u0020\u064D\u0651';
  17041. t['\uFC60'] = '\u0020\u064E\u0651';
  17042. t['\uFC61'] = '\u0020\u064F\u0651';
  17043. t['\uFC62'] = '\u0020\u0650\u0651';
  17044. t['\uFC63'] = '\u0020\u0651\u0670';
  17045. t['\uFC64'] = '\u0626\u0631';
  17046. t['\uFC65'] = '\u0626\u0632';
  17047. t['\uFC66'] = '\u0626\u0645';
  17048. t['\uFC67'] = '\u0626\u0646';
  17049. t['\uFC68'] = '\u0626\u0649';
  17050. t['\uFC69'] = '\u0626\u064A';
  17051. t['\uFC6A'] = '\u0628\u0631';
  17052. t['\uFC6B'] = '\u0628\u0632';
  17053. t['\uFC6C'] = '\u0628\u0645';
  17054. t['\uFC6D'] = '\u0628\u0646';
  17055. t['\uFC6E'] = '\u0628\u0649';
  17056. t['\uFC6F'] = '\u0628\u064A';
  17057. t['\uFC70'] = '\u062A\u0631';
  17058. t['\uFC71'] = '\u062A\u0632';
  17059. t['\uFC72'] = '\u062A\u0645';
  17060. t['\uFC73'] = '\u062A\u0646';
  17061. t['\uFC74'] = '\u062A\u0649';
  17062. t['\uFC75'] = '\u062A\u064A';
  17063. t['\uFC76'] = '\u062B\u0631';
  17064. t['\uFC77'] = '\u062B\u0632';
  17065. t['\uFC78'] = '\u062B\u0645';
  17066. t['\uFC79'] = '\u062B\u0646';
  17067. t['\uFC7A'] = '\u062B\u0649';
  17068. t['\uFC7B'] = '\u062B\u064A';
  17069. t['\uFC7C'] = '\u0641\u0649';
  17070. t['\uFC7D'] = '\u0641\u064A';
  17071. t['\uFC7E'] = '\u0642\u0649';
  17072. t['\uFC7F'] = '\u0642\u064A';
  17073. t['\uFC80'] = '\u0643\u0627';
  17074. t['\uFC81'] = '\u0643\u0644';
  17075. t['\uFC82'] = '\u0643\u0645';
  17076. t['\uFC83'] = '\u0643\u0649';
  17077. t['\uFC84'] = '\u0643\u064A';
  17078. t['\uFC85'] = '\u0644\u0645';
  17079. t['\uFC86'] = '\u0644\u0649';
  17080. t['\uFC87'] = '\u0644\u064A';
  17081. t['\uFC88'] = '\u0645\u0627';
  17082. t['\uFC89'] = '\u0645\u0645';
  17083. t['\uFC8A'] = '\u0646\u0631';
  17084. t['\uFC8B'] = '\u0646\u0632';
  17085. t['\uFC8C'] = '\u0646\u0645';
  17086. t['\uFC8D'] = '\u0646\u0646';
  17087. t['\uFC8E'] = '\u0646\u0649';
  17088. t['\uFC8F'] = '\u0646\u064A';
  17089. t['\uFC90'] = '\u0649\u0670';
  17090. t['\uFC91'] = '\u064A\u0631';
  17091. t['\uFC92'] = '\u064A\u0632';
  17092. t['\uFC93'] = '\u064A\u0645';
  17093. t['\uFC94'] = '\u064A\u0646';
  17094. t['\uFC95'] = '\u064A\u0649';
  17095. t['\uFC96'] = '\u064A\u064A';
  17096. t['\uFC97'] = '\u0626\u062C';
  17097. t['\uFC98'] = '\u0626\u062D';
  17098. t['\uFC99'] = '\u0626\u062E';
  17099. t['\uFC9A'] = '\u0626\u0645';
  17100. t['\uFC9B'] = '\u0626\u0647';
  17101. t['\uFC9C'] = '\u0628\u062C';
  17102. t['\uFC9D'] = '\u0628\u062D';
  17103. t['\uFC9E'] = '\u0628\u062E';
  17104. t['\uFC9F'] = '\u0628\u0645';
  17105. t['\uFCA0'] = '\u0628\u0647';
  17106. t['\uFCA1'] = '\u062A\u062C';
  17107. t['\uFCA2'] = '\u062A\u062D';
  17108. t['\uFCA3'] = '\u062A\u062E';
  17109. t['\uFCA4'] = '\u062A\u0645';
  17110. t['\uFCA5'] = '\u062A\u0647';
  17111. t['\uFCA6'] = '\u062B\u0645';
  17112. t['\uFCA7'] = '\u062C\u062D';
  17113. t['\uFCA8'] = '\u062C\u0645';
  17114. t['\uFCA9'] = '\u062D\u062C';
  17115. t['\uFCAA'] = '\u062D\u0645';
  17116. t['\uFCAB'] = '\u062E\u062C';
  17117. t['\uFCAC'] = '\u062E\u0645';
  17118. t['\uFCAD'] = '\u0633\u062C';
  17119. t['\uFCAE'] = '\u0633\u062D';
  17120. t['\uFCAF'] = '\u0633\u062E';
  17121. t['\uFCB0'] = '\u0633\u0645';
  17122. t['\uFCB1'] = '\u0635\u062D';
  17123. t['\uFCB2'] = '\u0635\u062E';
  17124. t['\uFCB3'] = '\u0635\u0645';
  17125. t['\uFCB4'] = '\u0636\u062C';
  17126. t['\uFCB5'] = '\u0636\u062D';
  17127. t['\uFCB6'] = '\u0636\u062E';
  17128. t['\uFCB7'] = '\u0636\u0645';
  17129. t['\uFCB8'] = '\u0637\u062D';
  17130. t['\uFCB9'] = '\u0638\u0645';
  17131. t['\uFCBA'] = '\u0639\u062C';
  17132. t['\uFCBB'] = '\u0639\u0645';
  17133. t['\uFCBC'] = '\u063A\u062C';
  17134. t['\uFCBD'] = '\u063A\u0645';
  17135. t['\uFCBE'] = '\u0641\u062C';
  17136. t['\uFCBF'] = '\u0641\u062D';
  17137. t['\uFCC0'] = '\u0641\u062E';
  17138. t['\uFCC1'] = '\u0641\u0645';
  17139. t['\uFCC2'] = '\u0642\u062D';
  17140. t['\uFCC3'] = '\u0642\u0645';
  17141. t['\uFCC4'] = '\u0643\u062C';
  17142. t['\uFCC5'] = '\u0643\u062D';
  17143. t['\uFCC6'] = '\u0643\u062E';
  17144. t['\uFCC7'] = '\u0643\u0644';
  17145. t['\uFCC8'] = '\u0643\u0645';
  17146. t['\uFCC9'] = '\u0644\u062C';
  17147. t['\uFCCA'] = '\u0644\u062D';
  17148. t['\uFCCB'] = '\u0644\u062E';
  17149. t['\uFCCC'] = '\u0644\u0645';
  17150. t['\uFCCD'] = '\u0644\u0647';
  17151. t['\uFCCE'] = '\u0645\u062C';
  17152. t['\uFCCF'] = '\u0645\u062D';
  17153. t['\uFCD0'] = '\u0645\u062E';
  17154. t['\uFCD1'] = '\u0645\u0645';
  17155. t['\uFCD2'] = '\u0646\u062C';
  17156. t['\uFCD3'] = '\u0646\u062D';
  17157. t['\uFCD4'] = '\u0646\u062E';
  17158. t['\uFCD5'] = '\u0646\u0645';
  17159. t['\uFCD6'] = '\u0646\u0647';
  17160. t['\uFCD7'] = '\u0647\u062C';
  17161. t['\uFCD8'] = '\u0647\u0645';
  17162. t['\uFCD9'] = '\u0647\u0670';
  17163. t['\uFCDA'] = '\u064A\u062C';
  17164. t['\uFCDB'] = '\u064A\u062D';
  17165. t['\uFCDC'] = '\u064A\u062E';
  17166. t['\uFCDD'] = '\u064A\u0645';
  17167. t['\uFCDE'] = '\u064A\u0647';
  17168. t['\uFCDF'] = '\u0626\u0645';
  17169. t['\uFCE0'] = '\u0626\u0647';
  17170. t['\uFCE1'] = '\u0628\u0645';
  17171. t['\uFCE2'] = '\u0628\u0647';
  17172. t['\uFCE3'] = '\u062A\u0645';
  17173. t['\uFCE4'] = '\u062A\u0647';
  17174. t['\uFCE5'] = '\u062B\u0645';
  17175. t['\uFCE6'] = '\u062B\u0647';
  17176. t['\uFCE7'] = '\u0633\u0645';
  17177. t['\uFCE8'] = '\u0633\u0647';
  17178. t['\uFCE9'] = '\u0634\u0645';
  17179. t['\uFCEA'] = '\u0634\u0647';
  17180. t['\uFCEB'] = '\u0643\u0644';
  17181. t['\uFCEC'] = '\u0643\u0645';
  17182. t['\uFCED'] = '\u0644\u0645';
  17183. t['\uFCEE'] = '\u0646\u0645';
  17184. t['\uFCEF'] = '\u0646\u0647';
  17185. t['\uFCF0'] = '\u064A\u0645';
  17186. t['\uFCF1'] = '\u064A\u0647';
  17187. t['\uFCF2'] = '\u0640\u064E\u0651';
  17188. t['\uFCF3'] = '\u0640\u064F\u0651';
  17189. t['\uFCF4'] = '\u0640\u0650\u0651';
  17190. t['\uFCF5'] = '\u0637\u0649';
  17191. t['\uFCF6'] = '\u0637\u064A';
  17192. t['\uFCF7'] = '\u0639\u0649';
  17193. t['\uFCF8'] = '\u0639\u064A';
  17194. t['\uFCF9'] = '\u063A\u0649';
  17195. t['\uFCFA'] = '\u063A\u064A';
  17196. t['\uFCFB'] = '\u0633\u0649';
  17197. t['\uFCFC'] = '\u0633\u064A';
  17198. t['\uFCFD'] = '\u0634\u0649';
  17199. t['\uFCFE'] = '\u0634\u064A';
  17200. t['\uFCFF'] = '\u062D\u0649';
  17201. t['\uFD00'] = '\u062D\u064A';
  17202. t['\uFD01'] = '\u062C\u0649';
  17203. t['\uFD02'] = '\u062C\u064A';
  17204. t['\uFD03'] = '\u062E\u0649';
  17205. t['\uFD04'] = '\u062E\u064A';
  17206. t['\uFD05'] = '\u0635\u0649';
  17207. t['\uFD06'] = '\u0635\u064A';
  17208. t['\uFD07'] = '\u0636\u0649';
  17209. t['\uFD08'] = '\u0636\u064A';
  17210. t['\uFD09'] = '\u0634\u062C';
  17211. t['\uFD0A'] = '\u0634\u062D';
  17212. t['\uFD0B'] = '\u0634\u062E';
  17213. t['\uFD0C'] = '\u0634\u0645';
  17214. t['\uFD0D'] = '\u0634\u0631';
  17215. t['\uFD0E'] = '\u0633\u0631';
  17216. t['\uFD0F'] = '\u0635\u0631';
  17217. t['\uFD10'] = '\u0636\u0631';
  17218. t['\uFD11'] = '\u0637\u0649';
  17219. t['\uFD12'] = '\u0637\u064A';
  17220. t['\uFD13'] = '\u0639\u0649';
  17221. t['\uFD14'] = '\u0639\u064A';
  17222. t['\uFD15'] = '\u063A\u0649';
  17223. t['\uFD16'] = '\u063A\u064A';
  17224. t['\uFD17'] = '\u0633\u0649';
  17225. t['\uFD18'] = '\u0633\u064A';
  17226. t['\uFD19'] = '\u0634\u0649';
  17227. t['\uFD1A'] = '\u0634\u064A';
  17228. t['\uFD1B'] = '\u062D\u0649';
  17229. t['\uFD1C'] = '\u062D\u064A';
  17230. t['\uFD1D'] = '\u062C\u0649';
  17231. t['\uFD1E'] = '\u062C\u064A';
  17232. t['\uFD1F'] = '\u062E\u0649';
  17233. t['\uFD20'] = '\u062E\u064A';
  17234. t['\uFD21'] = '\u0635\u0649';
  17235. t['\uFD22'] = '\u0635\u064A';
  17236. t['\uFD23'] = '\u0636\u0649';
  17237. t['\uFD24'] = '\u0636\u064A';
  17238. t['\uFD25'] = '\u0634\u062C';
  17239. t['\uFD26'] = '\u0634\u062D';
  17240. t['\uFD27'] = '\u0634\u062E';
  17241. t['\uFD28'] = '\u0634\u0645';
  17242. t['\uFD29'] = '\u0634\u0631';
  17243. t['\uFD2A'] = '\u0633\u0631';
  17244. t['\uFD2B'] = '\u0635\u0631';
  17245. t['\uFD2C'] = '\u0636\u0631';
  17246. t['\uFD2D'] = '\u0634\u062C';
  17247. t['\uFD2E'] = '\u0634\u062D';
  17248. t['\uFD2F'] = '\u0634\u062E';
  17249. t['\uFD30'] = '\u0634\u0645';
  17250. t['\uFD31'] = '\u0633\u0647';
  17251. t['\uFD32'] = '\u0634\u0647';
  17252. t['\uFD33'] = '\u0637\u0645';
  17253. t['\uFD34'] = '\u0633\u062C';
  17254. t['\uFD35'] = '\u0633\u062D';
  17255. t['\uFD36'] = '\u0633\u062E';
  17256. t['\uFD37'] = '\u0634\u062C';
  17257. t['\uFD38'] = '\u0634\u062D';
  17258. t['\uFD39'] = '\u0634\u062E';
  17259. t['\uFD3A'] = '\u0637\u0645';
  17260. t['\uFD3B'] = '\u0638\u0645';
  17261. t['\uFD3C'] = '\u0627\u064B';
  17262. t['\uFD3D'] = '\u0627\u064B';
  17263. t['\uFD50'] = '\u062A\u062C\u0645';
  17264. t['\uFD51'] = '\u062A\u062D\u062C';
  17265. t['\uFD52'] = '\u062A\u062D\u062C';
  17266. t['\uFD53'] = '\u062A\u062D\u0645';
  17267. t['\uFD54'] = '\u062A\u062E\u0645';
  17268. t['\uFD55'] = '\u062A\u0645\u062C';
  17269. t['\uFD56'] = '\u062A\u0645\u062D';
  17270. t['\uFD57'] = '\u062A\u0645\u062E';
  17271. t['\uFD58'] = '\u062C\u0645\u062D';
  17272. t['\uFD59'] = '\u062C\u0645\u062D';
  17273. t['\uFD5A'] = '\u062D\u0645\u064A';
  17274. t['\uFD5B'] = '\u062D\u0645\u0649';
  17275. t['\uFD5C'] = '\u0633\u062D\u062C';
  17276. t['\uFD5D'] = '\u0633\u062C\u062D';
  17277. t['\uFD5E'] = '\u0633\u062C\u0649';
  17278. t['\uFD5F'] = '\u0633\u0645\u062D';
  17279. t['\uFD60'] = '\u0633\u0645\u062D';
  17280. t['\uFD61'] = '\u0633\u0645\u062C';
  17281. t['\uFD62'] = '\u0633\u0645\u0645';
  17282. t['\uFD63'] = '\u0633\u0645\u0645';
  17283. t['\uFD64'] = '\u0635\u062D\u062D';
  17284. t['\uFD65'] = '\u0635\u062D\u062D';
  17285. t['\uFD66'] = '\u0635\u0645\u0645';
  17286. t['\uFD67'] = '\u0634\u062D\u0645';
  17287. t['\uFD68'] = '\u0634\u062D\u0645';
  17288. t['\uFD69'] = '\u0634\u062C\u064A';
  17289. t['\uFD6A'] = '\u0634\u0645\u062E';
  17290. t['\uFD6B'] = '\u0634\u0645\u062E';
  17291. t['\uFD6C'] = '\u0634\u0645\u0645';
  17292. t['\uFD6D'] = '\u0634\u0645\u0645';
  17293. t['\uFD6E'] = '\u0636\u062D\u0649';
  17294. t['\uFD6F'] = '\u0636\u062E\u0645';
  17295. t['\uFD70'] = '\u0636\u062E\u0645';
  17296. t['\uFD71'] = '\u0637\u0645\u062D';
  17297. t['\uFD72'] = '\u0637\u0645\u062D';
  17298. t['\uFD73'] = '\u0637\u0645\u0645';
  17299. t['\uFD74'] = '\u0637\u0645\u064A';
  17300. t['\uFD75'] = '\u0639\u062C\u0645';
  17301. t['\uFD76'] = '\u0639\u0645\u0645';
  17302. t['\uFD77'] = '\u0639\u0645\u0645';
  17303. t['\uFD78'] = '\u0639\u0645\u0649';
  17304. t['\uFD79'] = '\u063A\u0645\u0645';
  17305. t['\uFD7A'] = '\u063A\u0645\u064A';
  17306. t['\uFD7B'] = '\u063A\u0645\u0649';
  17307. t['\uFD7C'] = '\u0641\u062E\u0645';
  17308. t['\uFD7D'] = '\u0641\u062E\u0645';
  17309. t['\uFD7E'] = '\u0642\u0645\u062D';
  17310. t['\uFD7F'] = '\u0642\u0645\u0645';
  17311. t['\uFD80'] = '\u0644\u062D\u0645';
  17312. t['\uFD81'] = '\u0644\u062D\u064A';
  17313. t['\uFD82'] = '\u0644\u062D\u0649';
  17314. t['\uFD83'] = '\u0644\u062C\u062C';
  17315. t['\uFD84'] = '\u0644\u062C\u062C';
  17316. t['\uFD85'] = '\u0644\u062E\u0645';
  17317. t['\uFD86'] = '\u0644\u062E\u0645';
  17318. t['\uFD87'] = '\u0644\u0645\u062D';
  17319. t['\uFD88'] = '\u0644\u0645\u062D';
  17320. t['\uFD89'] = '\u0645\u062D\u062C';
  17321. t['\uFD8A'] = '\u0645\u062D\u0645';
  17322. t['\uFD8B'] = '\u0645\u062D\u064A';
  17323. t['\uFD8C'] = '\u0645\u062C\u062D';
  17324. t['\uFD8D'] = '\u0645\u062C\u0645';
  17325. t['\uFD8E'] = '\u0645\u062E\u062C';
  17326. t['\uFD8F'] = '\u0645\u062E\u0645';
  17327. t['\uFD92'] = '\u0645\u062C\u062E';
  17328. t['\uFD93'] = '\u0647\u0645\u062C';
  17329. t['\uFD94'] = '\u0647\u0645\u0645';
  17330. t['\uFD95'] = '\u0646\u062D\u0645';
  17331. t['\uFD96'] = '\u0646\u062D\u0649';
  17332. t['\uFD97'] = '\u0646\u062C\u0645';
  17333. t['\uFD98'] = '\u0646\u062C\u0645';
  17334. t['\uFD99'] = '\u0646\u062C\u0649';
  17335. t['\uFD9A'] = '\u0646\u0645\u064A';
  17336. t['\uFD9B'] = '\u0646\u0645\u0649';
  17337. t['\uFD9C'] = '\u064A\u0645\u0645';
  17338. t['\uFD9D'] = '\u064A\u0645\u0645';
  17339. t['\uFD9E'] = '\u0628\u062E\u064A';
  17340. t['\uFD9F'] = '\u062A\u062C\u064A';
  17341. t['\uFDA0'] = '\u062A\u062C\u0649';
  17342. t['\uFDA1'] = '\u062A\u062E\u064A';
  17343. t['\uFDA2'] = '\u062A\u062E\u0649';
  17344. t['\uFDA3'] = '\u062A\u0645\u064A';
  17345. t['\uFDA4'] = '\u062A\u0645\u0649';
  17346. t['\uFDA5'] = '\u062C\u0645\u064A';
  17347. t['\uFDA6'] = '\u062C\u062D\u0649';
  17348. t['\uFDA7'] = '\u062C\u0645\u0649';
  17349. t['\uFDA8'] = '\u0633\u062E\u0649';
  17350. t['\uFDA9'] = '\u0635\u062D\u064A';
  17351. t['\uFDAA'] = '\u0634\u062D\u064A';
  17352. t['\uFDAB'] = '\u0636\u062D\u064A';
  17353. t['\uFDAC'] = '\u0644\u062C\u064A';
  17354. t['\uFDAD'] = '\u0644\u0645\u064A';
  17355. t['\uFDAE'] = '\u064A\u062D\u064A';
  17356. t['\uFDAF'] = '\u064A\u062C\u064A';
  17357. t['\uFDB0'] = '\u064A\u0645\u064A';
  17358. t['\uFDB1'] = '\u0645\u0645\u064A';
  17359. t['\uFDB2'] = '\u0642\u0645\u064A';
  17360. t['\uFDB3'] = '\u0646\u062D\u064A';
  17361. t['\uFDB4'] = '\u0642\u0645\u062D';
  17362. t['\uFDB5'] = '\u0644\u062D\u0645';
  17363. t['\uFDB6'] = '\u0639\u0645\u064A';
  17364. t['\uFDB7'] = '\u0643\u0645\u064A';
  17365. t['\uFDB8'] = '\u0646\u062C\u062D';
  17366. t['\uFDB9'] = '\u0645\u062E\u064A';
  17367. t['\uFDBA'] = '\u0644\u062C\u0645';
  17368. t['\uFDBB'] = '\u0643\u0645\u0645';
  17369. t['\uFDBC'] = '\u0644\u062C\u0645';
  17370. t['\uFDBD'] = '\u0646\u062C\u062D';
  17371. t['\uFDBE'] = '\u062C\u062D\u064A';
  17372. t['\uFDBF'] = '\u062D\u062C\u064A';
  17373. t['\uFDC0'] = '\u0645\u062C\u064A';
  17374. t['\uFDC1'] = '\u0641\u0645\u064A';
  17375. t['\uFDC2'] = '\u0628\u062D\u064A';
  17376. t['\uFDC3'] = '\u0643\u0645\u0645';
  17377. t['\uFDC4'] = '\u0639\u062C\u0645';
  17378. t['\uFDC5'] = '\u0635\u0645\u0645';
  17379. t['\uFDC6'] = '\u0633\u062E\u064A';
  17380. t['\uFDC7'] = '\u0646\u062C\u064A';
  17381. t['\uFE49'] = '\u203E';
  17382. t['\uFE4A'] = '\u203E';
  17383. t['\uFE4B'] = '\u203E';
  17384. t['\uFE4C'] = '\u203E';
  17385. t['\uFE4D'] = '\u005F';
  17386. t['\uFE4E'] = '\u005F';
  17387. t['\uFE4F'] = '\u005F';
  17388. t['\uFE80'] = '\u0621';
  17389. t['\uFE81'] = '\u0622';
  17390. t['\uFE82'] = '\u0622';
  17391. t['\uFE83'] = '\u0623';
  17392. t['\uFE84'] = '\u0623';
  17393. t['\uFE85'] = '\u0624';
  17394. t['\uFE86'] = '\u0624';
  17395. t['\uFE87'] = '\u0625';
  17396. t['\uFE88'] = '\u0625';
  17397. t['\uFE89'] = '\u0626';
  17398. t['\uFE8A'] = '\u0626';
  17399. t['\uFE8B'] = '\u0626';
  17400. t['\uFE8C'] = '\u0626';
  17401. t['\uFE8D'] = '\u0627';
  17402. t['\uFE8E'] = '\u0627';
  17403. t['\uFE8F'] = '\u0628';
  17404. t['\uFE90'] = '\u0628';
  17405. t['\uFE91'] = '\u0628';
  17406. t['\uFE92'] = '\u0628';
  17407. t['\uFE93'] = '\u0629';
  17408. t['\uFE94'] = '\u0629';
  17409. t['\uFE95'] = '\u062A';
  17410. t['\uFE96'] = '\u062A';
  17411. t['\uFE97'] = '\u062A';
  17412. t['\uFE98'] = '\u062A';
  17413. t['\uFE99'] = '\u062B';
  17414. t['\uFE9A'] = '\u062B';
  17415. t['\uFE9B'] = '\u062B';
  17416. t['\uFE9C'] = '\u062B';
  17417. t['\uFE9D'] = '\u062C';
  17418. t['\uFE9E'] = '\u062C';
  17419. t['\uFE9F'] = '\u062C';
  17420. t['\uFEA0'] = '\u062C';
  17421. t['\uFEA1'] = '\u062D';
  17422. t['\uFEA2'] = '\u062D';
  17423. t['\uFEA3'] = '\u062D';
  17424. t['\uFEA4'] = '\u062D';
  17425. t['\uFEA5'] = '\u062E';
  17426. t['\uFEA6'] = '\u062E';
  17427. t['\uFEA7'] = '\u062E';
  17428. t['\uFEA8'] = '\u062E';
  17429. t['\uFEA9'] = '\u062F';
  17430. t['\uFEAA'] = '\u062F';
  17431. t['\uFEAB'] = '\u0630';
  17432. t['\uFEAC'] = '\u0630';
  17433. t['\uFEAD'] = '\u0631';
  17434. t['\uFEAE'] = '\u0631';
  17435. t['\uFEAF'] = '\u0632';
  17436. t['\uFEB0'] = '\u0632';
  17437. t['\uFEB1'] = '\u0633';
  17438. t['\uFEB2'] = '\u0633';
  17439. t['\uFEB3'] = '\u0633';
  17440. t['\uFEB4'] = '\u0633';
  17441. t['\uFEB5'] = '\u0634';
  17442. t['\uFEB6'] = '\u0634';
  17443. t['\uFEB7'] = '\u0634';
  17444. t['\uFEB8'] = '\u0634';
  17445. t['\uFEB9'] = '\u0635';
  17446. t['\uFEBA'] = '\u0635';
  17447. t['\uFEBB'] = '\u0635';
  17448. t['\uFEBC'] = '\u0635';
  17449. t['\uFEBD'] = '\u0636';
  17450. t['\uFEBE'] = '\u0636';
  17451. t['\uFEBF'] = '\u0636';
  17452. t['\uFEC0'] = '\u0636';
  17453. t['\uFEC1'] = '\u0637';
  17454. t['\uFEC2'] = '\u0637';
  17455. t['\uFEC3'] = '\u0637';
  17456. t['\uFEC4'] = '\u0637';
  17457. t['\uFEC5'] = '\u0638';
  17458. t['\uFEC6'] = '\u0638';
  17459. t['\uFEC7'] = '\u0638';
  17460. t['\uFEC8'] = '\u0638';
  17461. t['\uFEC9'] = '\u0639';
  17462. t['\uFECA'] = '\u0639';
  17463. t['\uFECB'] = '\u0639';
  17464. t['\uFECC'] = '\u0639';
  17465. t['\uFECD'] = '\u063A';
  17466. t['\uFECE'] = '\u063A';
  17467. t['\uFECF'] = '\u063A';
  17468. t['\uFED0'] = '\u063A';
  17469. t['\uFED1'] = '\u0641';
  17470. t['\uFED2'] = '\u0641';
  17471. t['\uFED3'] = '\u0641';
  17472. t['\uFED4'] = '\u0641';
  17473. t['\uFED5'] = '\u0642';
  17474. t['\uFED6'] = '\u0642';
  17475. t['\uFED7'] = '\u0642';
  17476. t['\uFED8'] = '\u0642';
  17477. t['\uFED9'] = '\u0643';
  17478. t['\uFEDA'] = '\u0643';
  17479. t['\uFEDB'] = '\u0643';
  17480. t['\uFEDC'] = '\u0643';
  17481. t['\uFEDD'] = '\u0644';
  17482. t['\uFEDE'] = '\u0644';
  17483. t['\uFEDF'] = '\u0644';
  17484. t['\uFEE0'] = '\u0644';
  17485. t['\uFEE1'] = '\u0645';
  17486. t['\uFEE2'] = '\u0645';
  17487. t['\uFEE3'] = '\u0645';
  17488. t['\uFEE4'] = '\u0645';
  17489. t['\uFEE5'] = '\u0646';
  17490. t['\uFEE6'] = '\u0646';
  17491. t['\uFEE7'] = '\u0646';
  17492. t['\uFEE8'] = '\u0646';
  17493. t['\uFEE9'] = '\u0647';
  17494. t['\uFEEA'] = '\u0647';
  17495. t['\uFEEB'] = '\u0647';
  17496. t['\uFEEC'] = '\u0647';
  17497. t['\uFEED'] = '\u0648';
  17498. t['\uFEEE'] = '\u0648';
  17499. t['\uFEEF'] = '\u0649';
  17500. t['\uFEF0'] = '\u0649';
  17501. t['\uFEF1'] = '\u064A';
  17502. t['\uFEF2'] = '\u064A';
  17503. t['\uFEF3'] = '\u064A';
  17504. t['\uFEF4'] = '\u064A';
  17505. t['\uFEF5'] = '\u0644\u0622';
  17506. t['\uFEF6'] = '\u0644\u0622';
  17507. t['\uFEF7'] = '\u0644\u0623';
  17508. t['\uFEF8'] = '\u0644\u0623';
  17509. t['\uFEF9'] = '\u0644\u0625';
  17510. t['\uFEFA'] = '\u0644\u0625';
  17511. t['\uFEFB'] = '\u0644\u0627';
  17512. t['\uFEFC'] = '\u0644\u0627';
  17513. });
  17514. function reverseIfRtl(chars) {
  17515. var charsLength = chars.length;
  17516. //reverse an arabic ligature
  17517. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  17518. return chars;
  17519. }
  17520. var s = '';
  17521. for (var ii = charsLength - 1; ii >= 0; ii--) {
  17522. s += chars[ii];
  17523. }
  17524. return s;
  17525. }
  17526. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  17527. exports.reverseIfRtl = reverseIfRtl;
  17528. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  17529. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  17530. }));
  17531. (function (root, factory) {
  17532. {
  17533. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  17534. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  17535. root.pdfjsCoreJpx);
  17536. }
  17537. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  17538. coreJpx) {
  17539. var Util = sharedUtil.Util;
  17540. var error = sharedUtil.error;
  17541. var info = sharedUtil.info;
  17542. var isArray = sharedUtil.isArray;
  17543. var shadow = sharedUtil.shadow;
  17544. var warn = sharedUtil.warn;
  17545. var Dict = corePrimitives.Dict;
  17546. var Jbig2Image = coreJbig2.Jbig2Image;
  17547. var JpegImage = coreJpg.JpegImage;
  17548. var JpxImage = coreJpx.JpxImage;
  17549. var coreParser; // see _setCoreParser below
  17550. var EOF; // = coreParser.EOF;
  17551. var Lexer; // = coreParser.Lexer;
  17552. var coreColorSpace; // see _setCoreColorSpace below
  17553. var ColorSpace; // = coreColorSpace.ColorSpace;
  17554. var Stream = (function StreamClosure() {
  17555. function Stream(arrayBuffer, start, length, dict) {
  17556. this.bytes = (arrayBuffer instanceof Uint8Array ?
  17557. arrayBuffer : new Uint8Array(arrayBuffer));
  17558. this.start = start || 0;
  17559. this.pos = this.start;
  17560. this.end = (start + length) || this.bytes.length;
  17561. this.dict = dict;
  17562. }
  17563. // required methods for a stream. if a particular stream does not
  17564. // implement these, an error should be thrown
  17565. Stream.prototype = {
  17566. get length() {
  17567. return this.end - this.start;
  17568. },
  17569. get isEmpty() {
  17570. return this.length === 0;
  17571. },
  17572. getByte: function Stream_getByte() {
  17573. if (this.pos >= this.end) {
  17574. return -1;
  17575. }
  17576. return this.bytes[this.pos++];
  17577. },
  17578. getUint16: function Stream_getUint16() {
  17579. var b0 = this.getByte();
  17580. var b1 = this.getByte();
  17581. if (b0 === -1 || b1 === -1) {
  17582. return -1;
  17583. }
  17584. return (b0 << 8) + b1;
  17585. },
  17586. getInt32: function Stream_getInt32() {
  17587. var b0 = this.getByte();
  17588. var b1 = this.getByte();
  17589. var b2 = this.getByte();
  17590. var b3 = this.getByte();
  17591. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17592. },
  17593. // returns subarray of original buffer
  17594. // should only be read
  17595. getBytes: function Stream_getBytes(length) {
  17596. var bytes = this.bytes;
  17597. var pos = this.pos;
  17598. var strEnd = this.end;
  17599. if (!length) {
  17600. return bytes.subarray(pos, strEnd);
  17601. }
  17602. var end = pos + length;
  17603. if (end > strEnd) {
  17604. end = strEnd;
  17605. }
  17606. this.pos = end;
  17607. return bytes.subarray(pos, end);
  17608. },
  17609. peekByte: function Stream_peekByte() {
  17610. var peekedByte = this.getByte();
  17611. this.pos--;
  17612. return peekedByte;
  17613. },
  17614. peekBytes: function Stream_peekBytes(length) {
  17615. var bytes = this.getBytes(length);
  17616. this.pos -= bytes.length;
  17617. return bytes;
  17618. },
  17619. skip: function Stream_skip(n) {
  17620. if (!n) {
  17621. n = 1;
  17622. }
  17623. this.pos += n;
  17624. },
  17625. reset: function Stream_reset() {
  17626. this.pos = this.start;
  17627. },
  17628. moveStart: function Stream_moveStart() {
  17629. this.start = this.pos;
  17630. },
  17631. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  17632. return new Stream(this.bytes.buffer, start, length, dict);
  17633. },
  17634. isStream: true
  17635. };
  17636. return Stream;
  17637. })();
  17638. var StringStream = (function StringStreamClosure() {
  17639. function StringStream(str) {
  17640. var length = str.length;
  17641. var bytes = new Uint8Array(length);
  17642. for (var n = 0; n < length; ++n) {
  17643. bytes[n] = str.charCodeAt(n);
  17644. }
  17645. Stream.call(this, bytes);
  17646. }
  17647. StringStream.prototype = Stream.prototype;
  17648. return StringStream;
  17649. })();
  17650. // super class for the decoding streams
  17651. var DecodeStream = (function DecodeStreamClosure() {
  17652. // Lots of DecodeStreams are created whose buffers are never used. For these
  17653. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  17654. // having special cases that would be required if we used |null| for an empty
  17655. // buffer.
  17656. var emptyBuffer = new Uint8Array(0);
  17657. function DecodeStream(maybeMinBufferLength) {
  17658. this.pos = 0;
  17659. this.bufferLength = 0;
  17660. this.eof = false;
  17661. this.buffer = emptyBuffer;
  17662. this.minBufferLength = 512;
  17663. if (maybeMinBufferLength) {
  17664. // Compute the first power of two that is as big as maybeMinBufferLength.
  17665. while (this.minBufferLength < maybeMinBufferLength) {
  17666. this.minBufferLength *= 2;
  17667. }
  17668. }
  17669. }
  17670. DecodeStream.prototype = {
  17671. get isEmpty() {
  17672. while (!this.eof && this.bufferLength === 0) {
  17673. this.readBlock();
  17674. }
  17675. return this.bufferLength === 0;
  17676. },
  17677. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  17678. var buffer = this.buffer;
  17679. if (requested <= buffer.byteLength) {
  17680. return buffer;
  17681. }
  17682. var size = this.minBufferLength;
  17683. while (size < requested) {
  17684. size *= 2;
  17685. }
  17686. var buffer2 = new Uint8Array(size);
  17687. buffer2.set(buffer);
  17688. return (this.buffer = buffer2);
  17689. },
  17690. getByte: function DecodeStream_getByte() {
  17691. var pos = this.pos;
  17692. while (this.bufferLength <= pos) {
  17693. if (this.eof) {
  17694. return -1;
  17695. }
  17696. this.readBlock();
  17697. }
  17698. return this.buffer[this.pos++];
  17699. },
  17700. getUint16: function DecodeStream_getUint16() {
  17701. var b0 = this.getByte();
  17702. var b1 = this.getByte();
  17703. if (b0 === -1 || b1 === -1) {
  17704. return -1;
  17705. }
  17706. return (b0 << 8) + b1;
  17707. },
  17708. getInt32: function DecodeStream_getInt32() {
  17709. var b0 = this.getByte();
  17710. var b1 = this.getByte();
  17711. var b2 = this.getByte();
  17712. var b3 = this.getByte();
  17713. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  17714. },
  17715. getBytes: function DecodeStream_getBytes(length) {
  17716. var end, pos = this.pos;
  17717. if (length) {
  17718. this.ensureBuffer(pos + length);
  17719. end = pos + length;
  17720. while (!this.eof && this.bufferLength < end) {
  17721. this.readBlock();
  17722. }
  17723. var bufEnd = this.bufferLength;
  17724. if (end > bufEnd) {
  17725. end = bufEnd;
  17726. }
  17727. } else {
  17728. while (!this.eof) {
  17729. this.readBlock();
  17730. }
  17731. end = this.bufferLength;
  17732. }
  17733. this.pos = end;
  17734. return this.buffer.subarray(pos, end);
  17735. },
  17736. peekByte: function DecodeStream_peekByte() {
  17737. var peekedByte = this.getByte();
  17738. this.pos--;
  17739. return peekedByte;
  17740. },
  17741. peekBytes: function DecodeStream_peekBytes(length) {
  17742. var bytes = this.getBytes(length);
  17743. this.pos -= bytes.length;
  17744. return bytes;
  17745. },
  17746. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  17747. var end = start + length;
  17748. while (this.bufferLength <= end && !this.eof) {
  17749. this.readBlock();
  17750. }
  17751. return new Stream(this.buffer, start, length, dict);
  17752. },
  17753. skip: function DecodeStream_skip(n) {
  17754. if (!n) {
  17755. n = 1;
  17756. }
  17757. this.pos += n;
  17758. },
  17759. reset: function DecodeStream_reset() {
  17760. this.pos = 0;
  17761. },
  17762. getBaseStreams: function DecodeStream_getBaseStreams() {
  17763. if (this.str && this.str.getBaseStreams) {
  17764. return this.str.getBaseStreams();
  17765. }
  17766. return [];
  17767. }
  17768. };
  17769. return DecodeStream;
  17770. })();
  17771. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  17772. function StreamsSequenceStream(streams) {
  17773. this.streams = streams;
  17774. DecodeStream.call(this, /* maybeLength = */ null);
  17775. }
  17776. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  17777. StreamsSequenceStream.prototype.readBlock =
  17778. function streamSequenceStreamReadBlock() {
  17779. var streams = this.streams;
  17780. if (streams.length === 0) {
  17781. this.eof = true;
  17782. return;
  17783. }
  17784. var stream = streams.shift();
  17785. var chunk = stream.getBytes();
  17786. var bufferLength = this.bufferLength;
  17787. var newLength = bufferLength + chunk.length;
  17788. var buffer = this.ensureBuffer(newLength);
  17789. buffer.set(chunk, bufferLength);
  17790. this.bufferLength = newLength;
  17791. };
  17792. StreamsSequenceStream.prototype.getBaseStreams =
  17793. function StreamsSequenceStream_getBaseStreams() {
  17794. var baseStreams = [];
  17795. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  17796. var stream = this.streams[i];
  17797. if (stream.getBaseStreams) {
  17798. Util.appendToArray(baseStreams, stream.getBaseStreams());
  17799. }
  17800. }
  17801. return baseStreams;
  17802. };
  17803. return StreamsSequenceStream;
  17804. })();
  17805. var FlateStream = (function FlateStreamClosure() {
  17806. var codeLenCodeMap = new Int32Array([
  17807. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  17808. ]);
  17809. var lengthDecode = new Int32Array([
  17810. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  17811. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  17812. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  17813. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  17814. ]);
  17815. var distDecode = new Int32Array([
  17816. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  17817. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  17818. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  17819. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  17820. ]);
  17821. var fixedLitCodeTab = [new Int32Array([
  17822. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  17823. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  17824. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  17825. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  17826. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  17827. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  17828. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  17829. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  17830. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  17831. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  17832. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  17833. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  17834. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  17835. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  17836. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  17837. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  17838. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  17839. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  17840. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  17841. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  17842. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  17843. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  17844. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  17845. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  17846. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  17847. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  17848. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  17849. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  17850. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  17851. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  17852. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  17853. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  17854. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  17855. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  17856. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  17857. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  17858. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  17859. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  17860. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  17861. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  17862. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  17863. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  17864. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  17865. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  17866. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  17867. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  17868. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  17869. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  17870. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  17871. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  17872. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  17873. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  17874. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  17875. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  17876. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  17877. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  17878. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  17879. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  17880. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  17881. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  17882. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  17883. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  17884. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  17885. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  17886. ]), 9];
  17887. var fixedDistCodeTab = [new Int32Array([
  17888. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  17889. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  17890. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  17891. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  17892. ]), 5];
  17893. function FlateStream(str, maybeLength) {
  17894. this.str = str;
  17895. this.dict = str.dict;
  17896. var cmf = str.getByte();
  17897. var flg = str.getByte();
  17898. if (cmf === -1 || flg === -1) {
  17899. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  17900. }
  17901. if ((cmf & 0x0f) !== 0x08) {
  17902. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  17903. }
  17904. if ((((cmf << 8) + flg) % 31) !== 0) {
  17905. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  17906. }
  17907. if (flg & 0x20) {
  17908. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  17909. }
  17910. this.codeSize = 0;
  17911. this.codeBuf = 0;
  17912. DecodeStream.call(this, maybeLength);
  17913. }
  17914. FlateStream.prototype = Object.create(DecodeStream.prototype);
  17915. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  17916. var str = this.str;
  17917. var codeSize = this.codeSize;
  17918. var codeBuf = this.codeBuf;
  17919. var b;
  17920. while (codeSize < bits) {
  17921. if ((b = str.getByte()) === -1) {
  17922. error('Bad encoding in flate stream');
  17923. }
  17924. codeBuf |= b << codeSize;
  17925. codeSize += 8;
  17926. }
  17927. b = codeBuf & ((1 << bits) - 1);
  17928. this.codeBuf = codeBuf >> bits;
  17929. this.codeSize = codeSize -= bits;
  17930. return b;
  17931. };
  17932. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  17933. var str = this.str;
  17934. var codes = table[0];
  17935. var maxLen = table[1];
  17936. var codeSize = this.codeSize;
  17937. var codeBuf = this.codeBuf;
  17938. var b;
  17939. while (codeSize < maxLen) {
  17940. if ((b = str.getByte()) === -1) {
  17941. // premature end of stream. code might however still be valid.
  17942. // codeSize < codeLen check below guards against incomplete codeVal.
  17943. break;
  17944. }
  17945. codeBuf |= (b << codeSize);
  17946. codeSize += 8;
  17947. }
  17948. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  17949. var codeLen = code >> 16;
  17950. var codeVal = code & 0xffff;
  17951. if (codeLen < 1 || codeSize < codeLen) {
  17952. error('Bad encoding in flate stream');
  17953. }
  17954. this.codeBuf = (codeBuf >> codeLen);
  17955. this.codeSize = (codeSize - codeLen);
  17956. return codeVal;
  17957. };
  17958. FlateStream.prototype.generateHuffmanTable =
  17959. function flateStreamGenerateHuffmanTable(lengths) {
  17960. var n = lengths.length;
  17961. // find max code length
  17962. var maxLen = 0;
  17963. var i;
  17964. for (i = 0; i < n; ++i) {
  17965. if (lengths[i] > maxLen) {
  17966. maxLen = lengths[i];
  17967. }
  17968. }
  17969. // build the table
  17970. var size = 1 << maxLen;
  17971. var codes = new Int32Array(size);
  17972. for (var len = 1, code = 0, skip = 2;
  17973. len <= maxLen;
  17974. ++len, code <<= 1, skip <<= 1) {
  17975. for (var val = 0; val < n; ++val) {
  17976. if (lengths[val] === len) {
  17977. // bit-reverse the code
  17978. var code2 = 0;
  17979. var t = code;
  17980. for (i = 0; i < len; ++i) {
  17981. code2 = (code2 << 1) | (t & 1);
  17982. t >>= 1;
  17983. }
  17984. // fill the table entries
  17985. for (i = code2; i < size; i += skip) {
  17986. codes[i] = (len << 16) | val;
  17987. }
  17988. ++code;
  17989. }
  17990. }
  17991. }
  17992. return [codes, maxLen];
  17993. };
  17994. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  17995. var buffer, len;
  17996. var str = this.str;
  17997. // read block header
  17998. var hdr = this.getBits(3);
  17999. if (hdr & 1) {
  18000. this.eof = true;
  18001. }
  18002. hdr >>= 1;
  18003. if (hdr === 0) { // uncompressed block
  18004. var b;
  18005. if ((b = str.getByte()) === -1) {
  18006. error('Bad block header in flate stream');
  18007. }
  18008. var blockLen = b;
  18009. if ((b = str.getByte()) === -1) {
  18010. error('Bad block header in flate stream');
  18011. }
  18012. blockLen |= (b << 8);
  18013. if ((b = str.getByte()) === -1) {
  18014. error('Bad block header in flate stream');
  18015. }
  18016. var check = b;
  18017. if ((b = str.getByte()) === -1) {
  18018. error('Bad block header in flate stream');
  18019. }
  18020. check |= (b << 8);
  18021. if (check !== (~blockLen & 0xffff) &&
  18022. (blockLen !== 0 || check !== 0)) {
  18023. // Ignoring error for bad "empty" block (see issue 1277)
  18024. error('Bad uncompressed block length in flate stream');
  18025. }
  18026. this.codeBuf = 0;
  18027. this.codeSize = 0;
  18028. var bufferLength = this.bufferLength;
  18029. buffer = this.ensureBuffer(bufferLength + blockLen);
  18030. var end = bufferLength + blockLen;
  18031. this.bufferLength = end;
  18032. if (blockLen === 0) {
  18033. if (str.peekByte() === -1) {
  18034. this.eof = true;
  18035. }
  18036. } else {
  18037. for (var n = bufferLength; n < end; ++n) {
  18038. if ((b = str.getByte()) === -1) {
  18039. this.eof = true;
  18040. break;
  18041. }
  18042. buffer[n] = b;
  18043. }
  18044. }
  18045. return;
  18046. }
  18047. var litCodeTable;
  18048. var distCodeTable;
  18049. if (hdr === 1) { // compressed block, fixed codes
  18050. litCodeTable = fixedLitCodeTab;
  18051. distCodeTable = fixedDistCodeTab;
  18052. } else if (hdr === 2) { // compressed block, dynamic codes
  18053. var numLitCodes = this.getBits(5) + 257;
  18054. var numDistCodes = this.getBits(5) + 1;
  18055. var numCodeLenCodes = this.getBits(4) + 4;
  18056. // build the code lengths code table
  18057. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  18058. var i;
  18059. for (i = 0; i < numCodeLenCodes; ++i) {
  18060. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  18061. }
  18062. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  18063. // build the literal and distance code tables
  18064. len = 0;
  18065. i = 0;
  18066. var codes = numLitCodes + numDistCodes;
  18067. var codeLengths = new Uint8Array(codes);
  18068. var bitsLength, bitsOffset, what;
  18069. while (i < codes) {
  18070. var code = this.getCode(codeLenCodeTab);
  18071. if (code === 16) {
  18072. bitsLength = 2; bitsOffset = 3; what = len;
  18073. } else if (code === 17) {
  18074. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  18075. } else if (code === 18) {
  18076. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  18077. } else {
  18078. codeLengths[i++] = len = code;
  18079. continue;
  18080. }
  18081. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  18082. while (repeatLength-- > 0) {
  18083. codeLengths[i++] = what;
  18084. }
  18085. }
  18086. litCodeTable =
  18087. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  18088. distCodeTable =
  18089. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  18090. } else {
  18091. error('Unknown block type in flate stream');
  18092. }
  18093. buffer = this.buffer;
  18094. var limit = buffer ? buffer.length : 0;
  18095. var pos = this.bufferLength;
  18096. while (true) {
  18097. var code1 = this.getCode(litCodeTable);
  18098. if (code1 < 256) {
  18099. if (pos + 1 >= limit) {
  18100. buffer = this.ensureBuffer(pos + 1);
  18101. limit = buffer.length;
  18102. }
  18103. buffer[pos++] = code1;
  18104. continue;
  18105. }
  18106. if (code1 === 256) {
  18107. this.bufferLength = pos;
  18108. return;
  18109. }
  18110. code1 -= 257;
  18111. code1 = lengthDecode[code1];
  18112. var code2 = code1 >> 16;
  18113. if (code2 > 0) {
  18114. code2 = this.getBits(code2);
  18115. }
  18116. len = (code1 & 0xffff) + code2;
  18117. code1 = this.getCode(distCodeTable);
  18118. code1 = distDecode[code1];
  18119. code2 = code1 >> 16;
  18120. if (code2 > 0) {
  18121. code2 = this.getBits(code2);
  18122. }
  18123. var dist = (code1 & 0xffff) + code2;
  18124. if (pos + len >= limit) {
  18125. buffer = this.ensureBuffer(pos + len);
  18126. limit = buffer.length;
  18127. }
  18128. for (var k = 0; k < len; ++k, ++pos) {
  18129. buffer[pos] = buffer[pos - dist];
  18130. }
  18131. }
  18132. };
  18133. return FlateStream;
  18134. })();
  18135. var PredictorStream = (function PredictorStreamClosure() {
  18136. function PredictorStream(str, maybeLength, params) {
  18137. var predictor = this.predictor = params.get('Predictor') || 1;
  18138. if (predictor <= 1) {
  18139. return str; // no prediction
  18140. }
  18141. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  18142. error('Unsupported predictor: ' + predictor);
  18143. }
  18144. if (predictor === 2) {
  18145. this.readBlock = this.readBlockTiff;
  18146. } else {
  18147. this.readBlock = this.readBlockPng;
  18148. }
  18149. this.str = str;
  18150. this.dict = str.dict;
  18151. var colors = this.colors = params.get('Colors') || 1;
  18152. var bits = this.bits = params.get('BitsPerComponent') || 8;
  18153. var columns = this.columns = params.get('Columns') || 1;
  18154. this.pixBytes = (colors * bits + 7) >> 3;
  18155. this.rowBytes = (columns * colors * bits + 7) >> 3;
  18156. DecodeStream.call(this, maybeLength);
  18157. return this;
  18158. }
  18159. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  18160. PredictorStream.prototype.readBlockTiff =
  18161. function predictorStreamReadBlockTiff() {
  18162. var rowBytes = this.rowBytes;
  18163. var bufferLength = this.bufferLength;
  18164. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18165. var bits = this.bits;
  18166. var colors = this.colors;
  18167. var rawBytes = this.str.getBytes(rowBytes);
  18168. this.eof = !rawBytes.length;
  18169. if (this.eof) {
  18170. return;
  18171. }
  18172. var inbuf = 0, outbuf = 0;
  18173. var inbits = 0, outbits = 0;
  18174. var pos = bufferLength;
  18175. var i;
  18176. if (bits === 1) {
  18177. for (i = 0; i < rowBytes; ++i) {
  18178. var c = rawBytes[i];
  18179. inbuf = (inbuf << 8) | c;
  18180. // bitwise addition is exclusive or
  18181. // first shift inbuf and then add
  18182. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  18183. // truncate inbuf (assumes colors < 16)
  18184. inbuf &= 0xFFFF;
  18185. }
  18186. } else if (bits === 8) {
  18187. for (i = 0; i < colors; ++i) {
  18188. buffer[pos++] = rawBytes[i];
  18189. }
  18190. for (; i < rowBytes; ++i) {
  18191. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  18192. pos++;
  18193. }
  18194. } else {
  18195. var compArray = new Uint8Array(colors + 1);
  18196. var bitMask = (1 << bits) - 1;
  18197. var j = 0, k = bufferLength;
  18198. var columns = this.columns;
  18199. for (i = 0; i < columns; ++i) {
  18200. for (var kk = 0; kk < colors; ++kk) {
  18201. if (inbits < bits) {
  18202. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  18203. inbits += 8;
  18204. }
  18205. compArray[kk] = (compArray[kk] +
  18206. (inbuf >> (inbits - bits))) & bitMask;
  18207. inbits -= bits;
  18208. outbuf = (outbuf << bits) | compArray[kk];
  18209. outbits += bits;
  18210. if (outbits >= 8) {
  18211. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  18212. outbits -= 8;
  18213. }
  18214. }
  18215. }
  18216. if (outbits > 0) {
  18217. buffer[k++] = (outbuf << (8 - outbits)) +
  18218. (inbuf & ((1 << (8 - outbits)) - 1));
  18219. }
  18220. }
  18221. this.bufferLength += rowBytes;
  18222. };
  18223. PredictorStream.prototype.readBlockPng =
  18224. function predictorStreamReadBlockPng() {
  18225. var rowBytes = this.rowBytes;
  18226. var pixBytes = this.pixBytes;
  18227. var predictor = this.str.getByte();
  18228. var rawBytes = this.str.getBytes(rowBytes);
  18229. this.eof = !rawBytes.length;
  18230. if (this.eof) {
  18231. return;
  18232. }
  18233. var bufferLength = this.bufferLength;
  18234. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  18235. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  18236. if (prevRow.length === 0) {
  18237. prevRow = new Uint8Array(rowBytes);
  18238. }
  18239. var i, j = bufferLength, up, c;
  18240. switch (predictor) {
  18241. case 0:
  18242. for (i = 0; i < rowBytes; ++i) {
  18243. buffer[j++] = rawBytes[i];
  18244. }
  18245. break;
  18246. case 1:
  18247. for (i = 0; i < pixBytes; ++i) {
  18248. buffer[j++] = rawBytes[i];
  18249. }
  18250. for (; i < rowBytes; ++i) {
  18251. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  18252. j++;
  18253. }
  18254. break;
  18255. case 2:
  18256. for (i = 0; i < rowBytes; ++i) {
  18257. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  18258. }
  18259. break;
  18260. case 3:
  18261. for (i = 0; i < pixBytes; ++i) {
  18262. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  18263. }
  18264. for (; i < rowBytes; ++i) {
  18265. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  18266. rawBytes[i]) & 0xFF;
  18267. j++;
  18268. }
  18269. break;
  18270. case 4:
  18271. // we need to save the up left pixels values. the simplest way
  18272. // is to create a new buffer
  18273. for (i = 0; i < pixBytes; ++i) {
  18274. up = prevRow[i];
  18275. c = rawBytes[i];
  18276. buffer[j++] = up + c;
  18277. }
  18278. for (; i < rowBytes; ++i) {
  18279. up = prevRow[i];
  18280. var upLeft = prevRow[i - pixBytes];
  18281. var left = buffer[j - pixBytes];
  18282. var p = left + up - upLeft;
  18283. var pa = p - left;
  18284. if (pa < 0) {
  18285. pa = -pa;
  18286. }
  18287. var pb = p - up;
  18288. if (pb < 0) {
  18289. pb = -pb;
  18290. }
  18291. var pc = p - upLeft;
  18292. if (pc < 0) {
  18293. pc = -pc;
  18294. }
  18295. c = rawBytes[i];
  18296. if (pa <= pb && pa <= pc) {
  18297. buffer[j++] = left + c;
  18298. } else if (pb <= pc) {
  18299. buffer[j++] = up + c;
  18300. } else {
  18301. buffer[j++] = upLeft + c;
  18302. }
  18303. }
  18304. break;
  18305. default:
  18306. error('Unsupported predictor: ' + predictor);
  18307. }
  18308. this.bufferLength += rowBytes;
  18309. };
  18310. return PredictorStream;
  18311. })();
  18312. /**
  18313. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  18314. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  18315. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  18316. * a library to decode these images and the stream behaves like all the other
  18317. * DecodeStreams.
  18318. */
  18319. var JpegStream = (function JpegStreamClosure() {
  18320. function JpegStream(stream, maybeLength, dict, xref) {
  18321. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  18322. // Note: this seems to mainly affect inline images.
  18323. var ch;
  18324. while ((ch = stream.getByte()) !== -1) {
  18325. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  18326. stream.skip(-1); // Reset the stream position to the SOI.
  18327. break;
  18328. }
  18329. }
  18330. this.stream = stream;
  18331. this.maybeLength = maybeLength;
  18332. this.dict = dict;
  18333. DecodeStream.call(this, maybeLength);
  18334. }
  18335. JpegStream.prototype = Object.create(DecodeStream.prototype);
  18336. Object.defineProperty(JpegStream.prototype, 'bytes', {
  18337. get: function JpegStream_bytes() {
  18338. // If this.maybeLength is null, we'll get the entire stream.
  18339. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18340. },
  18341. configurable: true
  18342. });
  18343. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  18344. if (this.bufferLength) {
  18345. return;
  18346. }
  18347. try {
  18348. var jpegImage = new JpegImage();
  18349. // checking if values needs to be transformed before conversion
  18350. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  18351. var decodeArr = this.dict.get('Decode');
  18352. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  18353. var decodeArrLength = decodeArr.length;
  18354. var transform = new Int32Array(decodeArrLength);
  18355. var transformNeeded = false;
  18356. var maxValue = (1 << bitsPerComponent) - 1;
  18357. for (var i = 0; i < decodeArrLength; i += 2) {
  18358. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  18359. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  18360. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  18361. transformNeeded = true;
  18362. }
  18363. }
  18364. if (transformNeeded) {
  18365. jpegImage.decodeTransform = transform;
  18366. }
  18367. }
  18368. jpegImage.parse(this.bytes);
  18369. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  18370. this.forceRGB);
  18371. this.buffer = data;
  18372. this.bufferLength = data.length;
  18373. this.eof = true;
  18374. } catch (e) {
  18375. error('JPEG error: ' + e);
  18376. }
  18377. };
  18378. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  18379. this.ensureBuffer();
  18380. return this.buffer;
  18381. };
  18382. JpegStream.prototype.getIR = function JpegStream_getIR() {
  18383. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  18384. };
  18385. /**
  18386. * Checks if the image can be decoded and displayed by the browser without any
  18387. * further processing such as color space conversions.
  18388. */
  18389. JpegStream.prototype.isNativelySupported =
  18390. function JpegStream_isNativelySupported(xref, res) {
  18391. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18392. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  18393. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18394. };
  18395. /**
  18396. * Checks if the image can be decoded by the browser.
  18397. */
  18398. JpegStream.prototype.isNativelyDecodable =
  18399. function JpegStream_isNativelyDecodable(xref, res) {
  18400. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  18401. return (cs.numComps === 1 || cs.numComps === 3) &&
  18402. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  18403. };
  18404. return JpegStream;
  18405. })();
  18406. /**
  18407. * For JPEG 2000's we use a library to decode these images and
  18408. * the stream behaves like all the other DecodeStreams.
  18409. */
  18410. var JpxStream = (function JpxStreamClosure() {
  18411. function JpxStream(stream, maybeLength, dict) {
  18412. this.stream = stream;
  18413. this.maybeLength = maybeLength;
  18414. this.dict = dict;
  18415. DecodeStream.call(this, maybeLength);
  18416. }
  18417. JpxStream.prototype = Object.create(DecodeStream.prototype);
  18418. Object.defineProperty(JpxStream.prototype, 'bytes', {
  18419. get: function JpxStream_bytes() {
  18420. // If this.maybeLength is null, we'll get the entire stream.
  18421. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18422. },
  18423. configurable: true
  18424. });
  18425. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  18426. if (this.bufferLength) {
  18427. return;
  18428. }
  18429. var jpxImage = new JpxImage();
  18430. jpxImage.parse(this.bytes);
  18431. var width = jpxImage.width;
  18432. var height = jpxImage.height;
  18433. var componentsCount = jpxImage.componentsCount;
  18434. var tileCount = jpxImage.tiles.length;
  18435. if (tileCount === 1) {
  18436. this.buffer = jpxImage.tiles[0].items;
  18437. } else {
  18438. var data = new Uint8Array(width * height * componentsCount);
  18439. for (var k = 0; k < tileCount; k++) {
  18440. var tileComponents = jpxImage.tiles[k];
  18441. var tileWidth = tileComponents.width;
  18442. var tileHeight = tileComponents.height;
  18443. var tileLeft = tileComponents.left;
  18444. var tileTop = tileComponents.top;
  18445. var src = tileComponents.items;
  18446. var srcPosition = 0;
  18447. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  18448. var imgRowSize = width * componentsCount;
  18449. var tileRowSize = tileWidth * componentsCount;
  18450. for (var j = 0; j < tileHeight; j++) {
  18451. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  18452. data.set(rowBytes, dataPosition);
  18453. srcPosition += tileRowSize;
  18454. dataPosition += imgRowSize;
  18455. }
  18456. }
  18457. this.buffer = data;
  18458. }
  18459. this.bufferLength = this.buffer.length;
  18460. this.eof = true;
  18461. };
  18462. return JpxStream;
  18463. })();
  18464. /**
  18465. * For JBIG2's we use a library to decode these images and
  18466. * the stream behaves like all the other DecodeStreams.
  18467. */
  18468. var Jbig2Stream = (function Jbig2StreamClosure() {
  18469. function Jbig2Stream(stream, maybeLength, dict) {
  18470. this.stream = stream;
  18471. this.maybeLength = maybeLength;
  18472. this.dict = dict;
  18473. DecodeStream.call(this, maybeLength);
  18474. }
  18475. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  18476. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  18477. get: function Jbig2Stream_bytes() {
  18478. // If this.maybeLength is null, we'll get the entire stream.
  18479. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  18480. },
  18481. configurable: true
  18482. });
  18483. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  18484. if (this.bufferLength) {
  18485. return;
  18486. }
  18487. var jbig2Image = new Jbig2Image();
  18488. var chunks = [], xref = this.dict.xref;
  18489. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  18490. // According to the PDF specification, DecodeParms can be either
  18491. // a dictionary, or an array whose elements are dictionaries.
  18492. if (isArray(decodeParams)) {
  18493. if (decodeParams.length > 1) {
  18494. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  18495. 'not supported.');
  18496. }
  18497. decodeParams = xref.fetchIfRef(decodeParams[0]);
  18498. }
  18499. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  18500. var globalsStream = decodeParams.get('JBIG2Globals');
  18501. var globals = globalsStream.getBytes();
  18502. chunks.push({data: globals, start: 0, end: globals.length});
  18503. }
  18504. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  18505. var data = jbig2Image.parseChunks(chunks);
  18506. var dataLength = data.length;
  18507. // JBIG2 had black as 1 and white as 0, inverting the colors
  18508. for (var i = 0; i < dataLength; i++) {
  18509. data[i] ^= 0xFF;
  18510. }
  18511. this.buffer = data;
  18512. this.bufferLength = dataLength;
  18513. this.eof = true;
  18514. };
  18515. return Jbig2Stream;
  18516. })();
  18517. var DecryptStream = (function DecryptStreamClosure() {
  18518. function DecryptStream(str, maybeLength, decrypt) {
  18519. this.str = str;
  18520. this.dict = str.dict;
  18521. this.decrypt = decrypt;
  18522. this.nextChunk = null;
  18523. this.initialized = false;
  18524. DecodeStream.call(this, maybeLength);
  18525. }
  18526. var chunkSize = 512;
  18527. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  18528. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  18529. var chunk;
  18530. if (this.initialized) {
  18531. chunk = this.nextChunk;
  18532. } else {
  18533. chunk = this.str.getBytes(chunkSize);
  18534. this.initialized = true;
  18535. }
  18536. if (!chunk || chunk.length === 0) {
  18537. this.eof = true;
  18538. return;
  18539. }
  18540. this.nextChunk = this.str.getBytes(chunkSize);
  18541. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  18542. var decrypt = this.decrypt;
  18543. chunk = decrypt(chunk, !hasMoreData);
  18544. var bufferLength = this.bufferLength;
  18545. var i, n = chunk.length;
  18546. var buffer = this.ensureBuffer(bufferLength + n);
  18547. for (i = 0; i < n; i++) {
  18548. buffer[bufferLength++] = chunk[i];
  18549. }
  18550. this.bufferLength = bufferLength;
  18551. };
  18552. return DecryptStream;
  18553. })();
  18554. var Ascii85Stream = (function Ascii85StreamClosure() {
  18555. function Ascii85Stream(str, maybeLength) {
  18556. this.str = str;
  18557. this.dict = str.dict;
  18558. this.input = new Uint8Array(5);
  18559. // Most streams increase in size when decoded, but Ascii85 streams
  18560. // typically shrink by ~20%.
  18561. if (maybeLength) {
  18562. maybeLength = 0.8 * maybeLength;
  18563. }
  18564. DecodeStream.call(this, maybeLength);
  18565. }
  18566. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  18567. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  18568. var TILDA_CHAR = 0x7E; // '~'
  18569. var Z_LOWER_CHAR = 0x7A; // 'z'
  18570. var EOF = -1;
  18571. var str = this.str;
  18572. var c = str.getByte();
  18573. while (Lexer.isSpace(c)) {
  18574. c = str.getByte();
  18575. }
  18576. if (c === EOF || c === TILDA_CHAR) {
  18577. this.eof = true;
  18578. return;
  18579. }
  18580. var bufferLength = this.bufferLength, buffer;
  18581. var i;
  18582. // special code for z
  18583. if (c === Z_LOWER_CHAR) {
  18584. buffer = this.ensureBuffer(bufferLength + 4);
  18585. for (i = 0; i < 4; ++i) {
  18586. buffer[bufferLength + i] = 0;
  18587. }
  18588. this.bufferLength += 4;
  18589. } else {
  18590. var input = this.input;
  18591. input[0] = c;
  18592. for (i = 1; i < 5; ++i) {
  18593. c = str.getByte();
  18594. while (Lexer.isSpace(c)) {
  18595. c = str.getByte();
  18596. }
  18597. input[i] = c;
  18598. if (c === EOF || c === TILDA_CHAR) {
  18599. break;
  18600. }
  18601. }
  18602. buffer = this.ensureBuffer(bufferLength + i - 1);
  18603. this.bufferLength += i - 1;
  18604. // partial ending;
  18605. if (i < 5) {
  18606. for (; i < 5; ++i) {
  18607. input[i] = 0x21 + 84;
  18608. }
  18609. this.eof = true;
  18610. }
  18611. var t = 0;
  18612. for (i = 0; i < 5; ++i) {
  18613. t = t * 85 + (input[i] - 0x21);
  18614. }
  18615. for (i = 3; i >= 0; --i) {
  18616. buffer[bufferLength + i] = t & 0xFF;
  18617. t >>= 8;
  18618. }
  18619. }
  18620. };
  18621. return Ascii85Stream;
  18622. })();
  18623. var AsciiHexStream = (function AsciiHexStreamClosure() {
  18624. function AsciiHexStream(str, maybeLength) {
  18625. this.str = str;
  18626. this.dict = str.dict;
  18627. this.firstDigit = -1;
  18628. // Most streams increase in size when decoded, but AsciiHex streams shrink
  18629. // by 50%.
  18630. if (maybeLength) {
  18631. maybeLength = 0.5 * maybeLength;
  18632. }
  18633. DecodeStream.call(this, maybeLength);
  18634. }
  18635. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  18636. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  18637. var UPSTREAM_BLOCK_SIZE = 8000;
  18638. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  18639. if (!bytes.length) {
  18640. this.eof = true;
  18641. return;
  18642. }
  18643. var maxDecodeLength = (bytes.length + 1) >> 1;
  18644. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  18645. var bufferLength = this.bufferLength;
  18646. var firstDigit = this.firstDigit;
  18647. for (var i = 0, ii = bytes.length; i < ii; i++) {
  18648. var ch = bytes[i], digit;
  18649. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  18650. digit = ch & 0x0F;
  18651. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  18652. // 'A'-'Z', 'a'-'z'
  18653. digit = (ch & 0x0F) + 9;
  18654. } else if (ch === 0x3E) { // '>'
  18655. this.eof = true;
  18656. break;
  18657. } else { // probably whitespace
  18658. continue; // ignoring
  18659. }
  18660. if (firstDigit < 0) {
  18661. firstDigit = digit;
  18662. } else {
  18663. buffer[bufferLength++] = (firstDigit << 4) | digit;
  18664. firstDigit = -1;
  18665. }
  18666. }
  18667. if (firstDigit >= 0 && this.eof) {
  18668. // incomplete byte
  18669. buffer[bufferLength++] = (firstDigit << 4);
  18670. firstDigit = -1;
  18671. }
  18672. this.firstDigit = firstDigit;
  18673. this.bufferLength = bufferLength;
  18674. };
  18675. return AsciiHexStream;
  18676. })();
  18677. var RunLengthStream = (function RunLengthStreamClosure() {
  18678. function RunLengthStream(str, maybeLength) {
  18679. this.str = str;
  18680. this.dict = str.dict;
  18681. DecodeStream.call(this, maybeLength);
  18682. }
  18683. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  18684. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  18685. // The repeatHeader has following format. The first byte defines type of run
  18686. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  18687. // (in addition to the second byte from the header), n = 129 through 255 -
  18688. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  18689. var repeatHeader = this.str.getBytes(2);
  18690. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  18691. this.eof = true;
  18692. return;
  18693. }
  18694. var buffer;
  18695. var bufferLength = this.bufferLength;
  18696. var n = repeatHeader[0];
  18697. if (n < 128) {
  18698. // copy n bytes
  18699. buffer = this.ensureBuffer(bufferLength + n + 1);
  18700. buffer[bufferLength++] = repeatHeader[1];
  18701. if (n > 0) {
  18702. var source = this.str.getBytes(n);
  18703. buffer.set(source, bufferLength);
  18704. bufferLength += n;
  18705. }
  18706. } else {
  18707. n = 257 - n;
  18708. var b = repeatHeader[1];
  18709. buffer = this.ensureBuffer(bufferLength + n + 1);
  18710. for (var i = 0; i < n; i++) {
  18711. buffer[bufferLength++] = b;
  18712. }
  18713. }
  18714. this.bufferLength = bufferLength;
  18715. };
  18716. return RunLengthStream;
  18717. })();
  18718. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  18719. var ccittEOL = -2;
  18720. var twoDimPass = 0;
  18721. var twoDimHoriz = 1;
  18722. var twoDimVert0 = 2;
  18723. var twoDimVertR1 = 3;
  18724. var twoDimVertL1 = 4;
  18725. var twoDimVertR2 = 5;
  18726. var twoDimVertL2 = 6;
  18727. var twoDimVertR3 = 7;
  18728. var twoDimVertL3 = 8;
  18729. var twoDimTable = [
  18730. [-1, -1], [-1, -1], // 000000x
  18731. [7, twoDimVertL3], // 0000010
  18732. [7, twoDimVertR3], // 0000011
  18733. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  18734. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  18735. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  18736. [4, twoDimPass], [4, twoDimPass],
  18737. [4, twoDimPass], [4, twoDimPass],
  18738. [4, twoDimPass], [4, twoDimPass],
  18739. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  18740. [3, twoDimHoriz], [3, twoDimHoriz],
  18741. [3, twoDimHoriz], [3, twoDimHoriz],
  18742. [3, twoDimHoriz], [3, twoDimHoriz],
  18743. [3, twoDimHoriz], [3, twoDimHoriz],
  18744. [3, twoDimHoriz], [3, twoDimHoriz],
  18745. [3, twoDimHoriz], [3, twoDimHoriz],
  18746. [3, twoDimHoriz], [3, twoDimHoriz],
  18747. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  18748. [3, twoDimVertL1], [3, twoDimVertL1],
  18749. [3, twoDimVertL1], [3, twoDimVertL1],
  18750. [3, twoDimVertL1], [3, twoDimVertL1],
  18751. [3, twoDimVertL1], [3, twoDimVertL1],
  18752. [3, twoDimVertL1], [3, twoDimVertL1],
  18753. [3, twoDimVertL1], [3, twoDimVertL1],
  18754. [3, twoDimVertL1], [3, twoDimVertL1],
  18755. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  18756. [3, twoDimVertR1], [3, twoDimVertR1],
  18757. [3, twoDimVertR1], [3, twoDimVertR1],
  18758. [3, twoDimVertR1], [3, twoDimVertR1],
  18759. [3, twoDimVertR1], [3, twoDimVertR1],
  18760. [3, twoDimVertR1], [3, twoDimVertR1],
  18761. [3, twoDimVertR1], [3, twoDimVertR1],
  18762. [3, twoDimVertR1], [3, twoDimVertR1],
  18763. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  18764. [1, twoDimVert0], [1, twoDimVert0],
  18765. [1, twoDimVert0], [1, twoDimVert0],
  18766. [1, twoDimVert0], [1, twoDimVert0],
  18767. [1, twoDimVert0], [1, twoDimVert0],
  18768. [1, twoDimVert0], [1, twoDimVert0],
  18769. [1, twoDimVert0], [1, twoDimVert0],
  18770. [1, twoDimVert0], [1, twoDimVert0],
  18771. [1, twoDimVert0], [1, twoDimVert0],
  18772. [1, twoDimVert0], [1, twoDimVert0],
  18773. [1, twoDimVert0], [1, twoDimVert0],
  18774. [1, twoDimVert0], [1, twoDimVert0],
  18775. [1, twoDimVert0], [1, twoDimVert0],
  18776. [1, twoDimVert0], [1, twoDimVert0],
  18777. [1, twoDimVert0], [1, twoDimVert0],
  18778. [1, twoDimVert0], [1, twoDimVert0],
  18779. [1, twoDimVert0], [1, twoDimVert0],
  18780. [1, twoDimVert0], [1, twoDimVert0],
  18781. [1, twoDimVert0], [1, twoDimVert0],
  18782. [1, twoDimVert0], [1, twoDimVert0],
  18783. [1, twoDimVert0], [1, twoDimVert0],
  18784. [1, twoDimVert0], [1, twoDimVert0],
  18785. [1, twoDimVert0], [1, twoDimVert0],
  18786. [1, twoDimVert0], [1, twoDimVert0],
  18787. [1, twoDimVert0], [1, twoDimVert0],
  18788. [1, twoDimVert0], [1, twoDimVert0],
  18789. [1, twoDimVert0], [1, twoDimVert0],
  18790. [1, twoDimVert0], [1, twoDimVert0],
  18791. [1, twoDimVert0], [1, twoDimVert0],
  18792. [1, twoDimVert0], [1, twoDimVert0],
  18793. [1, twoDimVert0], [1, twoDimVert0],
  18794. [1, twoDimVert0], [1, twoDimVert0]
  18795. ];
  18796. var whiteTable1 = [
  18797. [-1, -1], // 00000
  18798. [12, ccittEOL], // 00001
  18799. [-1, -1], [-1, -1], // 0001x
  18800. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  18801. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  18802. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  18803. [11, 1792], [11, 1792], // 1000x
  18804. [12, 1984], // 10010
  18805. [12, 2048], // 10011
  18806. [12, 2112], // 10100
  18807. [12, 2176], // 10101
  18808. [12, 2240], // 10110
  18809. [12, 2304], // 10111
  18810. [11, 1856], [11, 1856], // 1100x
  18811. [11, 1920], [11, 1920], // 1101x
  18812. [12, 2368], // 11100
  18813. [12, 2432], // 11101
  18814. [12, 2496], // 11110
  18815. [12, 2560] // 11111
  18816. ];
  18817. var whiteTable2 = [
  18818. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  18819. [8, 29], [8, 29], // 00000010x
  18820. [8, 30], [8, 30], // 00000011x
  18821. [8, 45], [8, 45], // 00000100x
  18822. [8, 46], [8, 46], // 00000101x
  18823. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  18824. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  18825. [8, 47], [8, 47], // 00001010x
  18826. [8, 48], [8, 48], // 00001011x
  18827. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  18828. [6, 13], [6, 13], [6, 13], [6, 13],
  18829. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  18830. [8, 33], [8, 33], // 00010010x
  18831. [8, 34], [8, 34], // 00010011x
  18832. [8, 35], [8, 35], // 00010100x
  18833. [8, 36], [8, 36], // 00010101x
  18834. [8, 37], [8, 37], // 00010110x
  18835. [8, 38], [8, 38], // 00010111x
  18836. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  18837. [8, 31], [8, 31], // 00011010x
  18838. [8, 32], [8, 32], // 00011011x
  18839. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  18840. [6, 1], [6, 1], [6, 1], [6, 1],
  18841. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  18842. [6, 12], [6, 12], [6, 12], [6, 12],
  18843. [8, 53], [8, 53], // 00100100x
  18844. [8, 54], [8, 54], // 00100101x
  18845. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  18846. [8, 39], [8, 39], // 00101000x
  18847. [8, 40], [8, 40], // 00101001x
  18848. [8, 41], [8, 41], // 00101010x
  18849. [8, 42], [8, 42], // 00101011x
  18850. [8, 43], [8, 43], // 00101100x
  18851. [8, 44], [8, 44], // 00101101x
  18852. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  18853. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  18854. [8, 61], [8, 61], // 00110010x
  18855. [8, 62], [8, 62], // 00110011x
  18856. [8, 63], [8, 63], // 00110100x
  18857. [8, 0], [8, 0], // 00110101x
  18858. [8, 320], [8, 320], // 00110110x
  18859. [8, 384], [8, 384], // 00110111x
  18860. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  18861. [5, 10], [5, 10], [5, 10], [5, 10],
  18862. [5, 10], [5, 10], [5, 10], [5, 10],
  18863. [5, 10], [5, 10], [5, 10], [5, 10],
  18864. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  18865. [5, 11], [5, 11], [5, 11], [5, 11],
  18866. [5, 11], [5, 11], [5, 11], [5, 11],
  18867. [5, 11], [5, 11], [5, 11], [5, 11],
  18868. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  18869. [8, 59], [8, 59], // 01001010x
  18870. [8, 60], [8, 60], // 01001011x
  18871. [9, 1472], // 010011000
  18872. [9, 1536], // 010011001
  18873. [9, 1600], // 010011010
  18874. [9, 1728], // 010011011
  18875. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  18876. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  18877. [8, 49], [8, 49], // 01010010x
  18878. [8, 50], [8, 50], // 01010011x
  18879. [8, 51], [8, 51], // 01010100x
  18880. [8, 52], [8, 52], // 01010101x
  18881. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  18882. [8, 55], [8, 55], // 01011000x
  18883. [8, 56], [8, 56], // 01011001x
  18884. [8, 57], [8, 57], // 01011010x
  18885. [8, 58], [8, 58], // 01011011x
  18886. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  18887. [6, 192], [6, 192], [6, 192], [6, 192],
  18888. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  18889. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  18890. [8, 448], [8, 448], // 01100100x
  18891. [8, 512], [8, 512], // 01100101x
  18892. [9, 704], // 011001100
  18893. [9, 768], // 011001101
  18894. [8, 640], [8, 640], // 01100111x
  18895. [8, 576], [8, 576], // 01101000x
  18896. [9, 832], // 011010010
  18897. [9, 896], // 011010011
  18898. [9, 960], // 011010100
  18899. [9, 1024], // 011010101
  18900. [9, 1088], // 011010110
  18901. [9, 1152], // 011010111
  18902. [9, 1216], // 011011000
  18903. [9, 1280], // 011011001
  18904. [9, 1344], // 011011010
  18905. [9, 1408], // 011011011
  18906. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  18907. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  18908. [4, 2], [4, 2], [4, 2], [4, 2],
  18909. [4, 2], [4, 2], [4, 2], [4, 2],
  18910. [4, 2], [4, 2], [4, 2], [4, 2],
  18911. [4, 2], [4, 2], [4, 2], [4, 2],
  18912. [4, 2], [4, 2], [4, 2], [4, 2],
  18913. [4, 2], [4, 2], [4, 2], [4, 2],
  18914. [4, 2], [4, 2], [4, 2], [4, 2],
  18915. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  18916. [4, 3], [4, 3], [4, 3], [4, 3],
  18917. [4, 3], [4, 3], [4, 3], [4, 3],
  18918. [4, 3], [4, 3], [4, 3], [4, 3],
  18919. [4, 3], [4, 3], [4, 3], [4, 3],
  18920. [4, 3], [4, 3], [4, 3], [4, 3],
  18921. [4, 3], [4, 3], [4, 3], [4, 3],
  18922. [4, 3], [4, 3], [4, 3], [4, 3],
  18923. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  18924. [5, 128], [5, 128], [5, 128], [5, 128],
  18925. [5, 128], [5, 128], [5, 128], [5, 128],
  18926. [5, 128], [5, 128], [5, 128], [5, 128],
  18927. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  18928. [5, 8], [5, 8], [5, 8], [5, 8],
  18929. [5, 8], [5, 8], [5, 8], [5, 8],
  18930. [5, 8], [5, 8], [5, 8], [5, 8],
  18931. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  18932. [5, 9], [5, 9], [5, 9], [5, 9],
  18933. [5, 9], [5, 9], [5, 9], [5, 9],
  18934. [5, 9], [5, 9], [5, 9], [5, 9],
  18935. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  18936. [6, 16], [6, 16], [6, 16], [6, 16],
  18937. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  18938. [6, 17], [6, 17], [6, 17], [6, 17],
  18939. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  18940. [4, 4], [4, 4], [4, 4], [4, 4],
  18941. [4, 4], [4, 4], [4, 4], [4, 4],
  18942. [4, 4], [4, 4], [4, 4], [4, 4],
  18943. [4, 4], [4, 4], [4, 4], [4, 4],
  18944. [4, 4], [4, 4], [4, 4], [4, 4],
  18945. [4, 4], [4, 4], [4, 4], [4, 4],
  18946. [4, 4], [4, 4], [4, 4], [4, 4],
  18947. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  18948. [4, 5], [4, 5], [4, 5], [4, 5],
  18949. [4, 5], [4, 5], [4, 5], [4, 5],
  18950. [4, 5], [4, 5], [4, 5], [4, 5],
  18951. [4, 5], [4, 5], [4, 5], [4, 5],
  18952. [4, 5], [4, 5], [4, 5], [4, 5],
  18953. [4, 5], [4, 5], [4, 5], [4, 5],
  18954. [4, 5], [4, 5], [4, 5], [4, 5],
  18955. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  18956. [6, 14], [6, 14], [6, 14], [6, 14],
  18957. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  18958. [6, 15], [6, 15], [6, 15], [6, 15],
  18959. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  18960. [5, 64], [5, 64], [5, 64], [5, 64],
  18961. [5, 64], [5, 64], [5, 64], [5, 64],
  18962. [5, 64], [5, 64], [5, 64], [5, 64],
  18963. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  18964. [4, 6], [4, 6], [4, 6], [4, 6],
  18965. [4, 6], [4, 6], [4, 6], [4, 6],
  18966. [4, 6], [4, 6], [4, 6], [4, 6],
  18967. [4, 6], [4, 6], [4, 6], [4, 6],
  18968. [4, 6], [4, 6], [4, 6], [4, 6],
  18969. [4, 6], [4, 6], [4, 6], [4, 6],
  18970. [4, 6], [4, 6], [4, 6], [4, 6],
  18971. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  18972. [4, 7], [4, 7], [4, 7], [4, 7],
  18973. [4, 7], [4, 7], [4, 7], [4, 7],
  18974. [4, 7], [4, 7], [4, 7], [4, 7],
  18975. [4, 7], [4, 7], [4, 7], [4, 7],
  18976. [4, 7], [4, 7], [4, 7], [4, 7],
  18977. [4, 7], [4, 7], [4, 7], [4, 7],
  18978. [4, 7], [4, 7], [4, 7], [4, 7]
  18979. ];
  18980. var blackTable1 = [
  18981. [-1, -1], [-1, -1], // 000000000000x
  18982. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  18983. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  18984. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  18985. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  18986. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  18987. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  18988. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  18989. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  18990. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  18991. [12, 1984], [12, 1984], // 000000010010x
  18992. [12, 2048], [12, 2048], // 000000010011x
  18993. [12, 2112], [12, 2112], // 000000010100x
  18994. [12, 2176], [12, 2176], // 000000010101x
  18995. [12, 2240], [12, 2240], // 000000010110x
  18996. [12, 2304], [12, 2304], // 000000010111x
  18997. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  18998. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  18999. [12, 2368], [12, 2368], // 000000011100x
  19000. [12, 2432], [12, 2432], // 000000011101x
  19001. [12, 2496], [12, 2496], // 000000011110x
  19002. [12, 2560], [12, 2560], // 000000011111x
  19003. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  19004. [10, 18], [10, 18], [10, 18], [10, 18],
  19005. [12, 52], [12, 52], // 000000100100x
  19006. [13, 640], // 0000001001010
  19007. [13, 704], // 0000001001011
  19008. [13, 768], // 0000001001100
  19009. [13, 832], // 0000001001101
  19010. [12, 55], [12, 55], // 000000100111x
  19011. [12, 56], [12, 56], // 000000101000x
  19012. [13, 1280], // 0000001010010
  19013. [13, 1344], // 0000001010011
  19014. [13, 1408], // 0000001010100
  19015. [13, 1472], // 0000001010101
  19016. [12, 59], [12, 59], // 000000101011x
  19017. [12, 60], [12, 60], // 000000101100x
  19018. [13, 1536], // 0000001011010
  19019. [13, 1600], // 0000001011011
  19020. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  19021. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  19022. [13, 1664], // 0000001100100
  19023. [13, 1728], // 0000001100101
  19024. [12, 320], [12, 320], // 000000110011x
  19025. [12, 384], [12, 384], // 000000110100x
  19026. [12, 448], [12, 448], // 000000110101x
  19027. [13, 512], // 0000001101100
  19028. [13, 576], // 0000001101101
  19029. [12, 53], [12, 53], // 000000110111x
  19030. [12, 54], [12, 54], // 000000111000x
  19031. [13, 896], // 0000001110010
  19032. [13, 960], // 0000001110011
  19033. [13, 1024], // 0000001110100
  19034. [13, 1088], // 0000001110101
  19035. [13, 1152], // 0000001110110
  19036. [13, 1216], // 0000001110111
  19037. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  19038. [10, 64], [10, 64], [10, 64], [10, 64]
  19039. ];
  19040. var blackTable2 = [
  19041. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  19042. [8, 13], [8, 13], [8, 13], [8, 13],
  19043. [8, 13], [8, 13], [8, 13], [8, 13],
  19044. [8, 13], [8, 13], [8, 13], [8, 13],
  19045. [11, 23], [11, 23], // 00000101000x
  19046. [12, 50], // 000001010010
  19047. [12, 51], // 000001010011
  19048. [12, 44], // 000001010100
  19049. [12, 45], // 000001010101
  19050. [12, 46], // 000001010110
  19051. [12, 47], // 000001010111
  19052. [12, 57], // 000001011000
  19053. [12, 58], // 000001011001
  19054. [12, 61], // 000001011010
  19055. [12, 256], // 000001011011
  19056. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  19057. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  19058. [12, 48], // 000001100100
  19059. [12, 49], // 000001100101
  19060. [12, 62], // 000001100110
  19061. [12, 63], // 000001100111
  19062. [12, 30], // 000001101000
  19063. [12, 31], // 000001101001
  19064. [12, 32], // 000001101010
  19065. [12, 33], // 000001101011
  19066. [12, 40], // 000001101100
  19067. [12, 41], // 000001101101
  19068. [11, 22], [11, 22], // 00000110111x
  19069. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  19070. [8, 14], [8, 14], [8, 14], [8, 14],
  19071. [8, 14], [8, 14], [8, 14], [8, 14],
  19072. [8, 14], [8, 14], [8, 14], [8, 14],
  19073. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  19074. [7, 10], [7, 10], [7, 10], [7, 10],
  19075. [7, 10], [7, 10], [7, 10], [7, 10],
  19076. [7, 10], [7, 10], [7, 10], [7, 10],
  19077. [7, 10], [7, 10], [7, 10], [7, 10],
  19078. [7, 10], [7, 10], [7, 10], [7, 10],
  19079. [7, 10], [7, 10], [7, 10], [7, 10],
  19080. [7, 10], [7, 10], [7, 10], [7, 10],
  19081. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  19082. [7, 11], [7, 11], [7, 11], [7, 11],
  19083. [7, 11], [7, 11], [7, 11], [7, 11],
  19084. [7, 11], [7, 11], [7, 11], [7, 11],
  19085. [7, 11], [7, 11], [7, 11], [7, 11],
  19086. [7, 11], [7, 11], [7, 11], [7, 11],
  19087. [7, 11], [7, 11], [7, 11], [7, 11],
  19088. [7, 11], [7, 11], [7, 11], [7, 11],
  19089. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  19090. [9, 15], [9, 15], [9, 15], [9, 15],
  19091. [12, 128], // 000011001000
  19092. [12, 192], // 000011001001
  19093. [12, 26], // 000011001010
  19094. [12, 27], // 000011001011
  19095. [12, 28], // 000011001100
  19096. [12, 29], // 000011001101
  19097. [11, 19], [11, 19], // 00001100111x
  19098. [11, 20], [11, 20], // 00001101000x
  19099. [12, 34], // 000011010010
  19100. [12, 35], // 000011010011
  19101. [12, 36], // 000011010100
  19102. [12, 37], // 000011010101
  19103. [12, 38], // 000011010110
  19104. [12, 39], // 000011010111
  19105. [11, 21], [11, 21], // 00001101100x
  19106. [12, 42], // 000011011010
  19107. [12, 43], // 000011011011
  19108. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  19109. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  19110. [7, 12], [7, 12], [7, 12], [7, 12],
  19111. [7, 12], [7, 12], [7, 12], [7, 12],
  19112. [7, 12], [7, 12], [7, 12], [7, 12],
  19113. [7, 12], [7, 12], [7, 12], [7, 12],
  19114. [7, 12], [7, 12], [7, 12], [7, 12],
  19115. [7, 12], [7, 12], [7, 12], [7, 12],
  19116. [7, 12], [7, 12], [7, 12], [7, 12]
  19117. ];
  19118. var blackTable3 = [
  19119. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  19120. [6, 9], // 000100
  19121. [6, 8], // 000101
  19122. [5, 7], [5, 7], // 00011x
  19123. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  19124. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  19125. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  19126. [3, 1], [3, 1], [3, 1], [3, 1],
  19127. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  19128. [3, 4], [3, 4], [3, 4], [3, 4],
  19129. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  19130. [2, 3], [2, 3], [2, 3], [2, 3],
  19131. [2, 3], [2, 3], [2, 3], [2, 3],
  19132. [2, 3], [2, 3], [2, 3], [2, 3],
  19133. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  19134. [2, 2], [2, 2], [2, 2], [2, 2],
  19135. [2, 2], [2, 2], [2, 2], [2, 2],
  19136. [2, 2], [2, 2], [2, 2], [2, 2]
  19137. ];
  19138. function CCITTFaxStream(str, maybeLength, params) {
  19139. this.str = str;
  19140. this.dict = str.dict;
  19141. params = params || Dict.empty;
  19142. this.encoding = params.get('K') || 0;
  19143. this.eoline = params.get('EndOfLine') || false;
  19144. this.byteAlign = params.get('EncodedByteAlign') || false;
  19145. this.columns = params.get('Columns') || 1728;
  19146. this.rows = params.get('Rows') || 0;
  19147. var eoblock = params.get('EndOfBlock');
  19148. if (eoblock === null || eoblock === undefined) {
  19149. eoblock = true;
  19150. }
  19151. this.eoblock = eoblock;
  19152. this.black = params.get('BlackIs1') || false;
  19153. this.codingLine = new Uint32Array(this.columns + 1);
  19154. this.refLine = new Uint32Array(this.columns + 2);
  19155. this.codingLine[0] = this.columns;
  19156. this.codingPos = 0;
  19157. this.row = 0;
  19158. this.nextLine2D = this.encoding < 0;
  19159. this.inputBits = 0;
  19160. this.inputBuf = 0;
  19161. this.outputBits = 0;
  19162. var code1;
  19163. while ((code1 = this.lookBits(12)) === 0) {
  19164. this.eatBits(1);
  19165. }
  19166. if (code1 === 1) {
  19167. this.eatBits(12);
  19168. }
  19169. if (this.encoding > 0) {
  19170. this.nextLine2D = !this.lookBits(1);
  19171. this.eatBits(1);
  19172. }
  19173. DecodeStream.call(this, maybeLength);
  19174. }
  19175. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  19176. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  19177. while (!this.eof) {
  19178. var c = this.lookChar();
  19179. this.ensureBuffer(this.bufferLength + 1);
  19180. this.buffer[this.bufferLength++] = c;
  19181. }
  19182. };
  19183. CCITTFaxStream.prototype.addPixels =
  19184. function ccittFaxStreamAddPixels(a1, blackPixels) {
  19185. var codingLine = this.codingLine;
  19186. var codingPos = this.codingPos;
  19187. if (a1 > codingLine[codingPos]) {
  19188. if (a1 > this.columns) {
  19189. info('row is wrong length');
  19190. this.err = true;
  19191. a1 = this.columns;
  19192. }
  19193. if ((codingPos & 1) ^ blackPixels) {
  19194. ++codingPos;
  19195. }
  19196. codingLine[codingPos] = a1;
  19197. }
  19198. this.codingPos = codingPos;
  19199. };
  19200. CCITTFaxStream.prototype.addPixelsNeg =
  19201. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  19202. var codingLine = this.codingLine;
  19203. var codingPos = this.codingPos;
  19204. if (a1 > codingLine[codingPos]) {
  19205. if (a1 > this.columns) {
  19206. info('row is wrong length');
  19207. this.err = true;
  19208. a1 = this.columns;
  19209. }
  19210. if ((codingPos & 1) ^ blackPixels) {
  19211. ++codingPos;
  19212. }
  19213. codingLine[codingPos] = a1;
  19214. } else if (a1 < codingLine[codingPos]) {
  19215. if (a1 < 0) {
  19216. info('invalid code');
  19217. this.err = true;
  19218. a1 = 0;
  19219. }
  19220. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  19221. --codingPos;
  19222. }
  19223. codingLine[codingPos] = a1;
  19224. }
  19225. this.codingPos = codingPos;
  19226. };
  19227. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  19228. var refLine = this.refLine;
  19229. var codingLine = this.codingLine;
  19230. var columns = this.columns;
  19231. var refPos, blackPixels, bits, i;
  19232. if (this.outputBits === 0) {
  19233. if (this.eof) {
  19234. return null;
  19235. }
  19236. this.err = false;
  19237. var code1, code2, code3;
  19238. if (this.nextLine2D) {
  19239. for (i = 0; codingLine[i] < columns; ++i) {
  19240. refLine[i] = codingLine[i];
  19241. }
  19242. refLine[i++] = columns;
  19243. refLine[i] = columns;
  19244. codingLine[0] = 0;
  19245. this.codingPos = 0;
  19246. refPos = 0;
  19247. blackPixels = 0;
  19248. while (codingLine[this.codingPos] < columns) {
  19249. code1 = this.getTwoDimCode();
  19250. switch (code1) {
  19251. case twoDimPass:
  19252. this.addPixels(refLine[refPos + 1], blackPixels);
  19253. if (refLine[refPos + 1] < columns) {
  19254. refPos += 2;
  19255. }
  19256. break;
  19257. case twoDimHoriz:
  19258. code1 = code2 = 0;
  19259. if (blackPixels) {
  19260. do {
  19261. code1 += (code3 = this.getBlackCode());
  19262. } while (code3 >= 64);
  19263. do {
  19264. code2 += (code3 = this.getWhiteCode());
  19265. } while (code3 >= 64);
  19266. } else {
  19267. do {
  19268. code1 += (code3 = this.getWhiteCode());
  19269. } while (code3 >= 64);
  19270. do {
  19271. code2 += (code3 = this.getBlackCode());
  19272. } while (code3 >= 64);
  19273. }
  19274. this.addPixels(codingLine[this.codingPos] +
  19275. code1, blackPixels);
  19276. if (codingLine[this.codingPos] < columns) {
  19277. this.addPixels(codingLine[this.codingPos] + code2,
  19278. blackPixels ^ 1);
  19279. }
  19280. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19281. refLine[refPos] < columns) {
  19282. refPos += 2;
  19283. }
  19284. break;
  19285. case twoDimVertR3:
  19286. this.addPixels(refLine[refPos] + 3, blackPixels);
  19287. blackPixels ^= 1;
  19288. if (codingLine[this.codingPos] < columns) {
  19289. ++refPos;
  19290. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19291. refLine[refPos] < columns) {
  19292. refPos += 2;
  19293. }
  19294. }
  19295. break;
  19296. case twoDimVertR2:
  19297. this.addPixels(refLine[refPos] + 2, blackPixels);
  19298. blackPixels ^= 1;
  19299. if (codingLine[this.codingPos] < columns) {
  19300. ++refPos;
  19301. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19302. refLine[refPos] < columns) {
  19303. refPos += 2;
  19304. }
  19305. }
  19306. break;
  19307. case twoDimVertR1:
  19308. this.addPixels(refLine[refPos] + 1, blackPixels);
  19309. blackPixels ^= 1;
  19310. if (codingLine[this.codingPos] < columns) {
  19311. ++refPos;
  19312. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19313. refLine[refPos] < columns) {
  19314. refPos += 2;
  19315. }
  19316. }
  19317. break;
  19318. case twoDimVert0:
  19319. this.addPixels(refLine[refPos], blackPixels);
  19320. blackPixels ^= 1;
  19321. if (codingLine[this.codingPos] < columns) {
  19322. ++refPos;
  19323. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19324. refLine[refPos] < columns) {
  19325. refPos += 2;
  19326. }
  19327. }
  19328. break;
  19329. case twoDimVertL3:
  19330. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  19331. blackPixels ^= 1;
  19332. if (codingLine[this.codingPos] < columns) {
  19333. if (refPos > 0) {
  19334. --refPos;
  19335. } else {
  19336. ++refPos;
  19337. }
  19338. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19339. refLine[refPos] < columns) {
  19340. refPos += 2;
  19341. }
  19342. }
  19343. break;
  19344. case twoDimVertL2:
  19345. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  19346. blackPixels ^= 1;
  19347. if (codingLine[this.codingPos] < columns) {
  19348. if (refPos > 0) {
  19349. --refPos;
  19350. } else {
  19351. ++refPos;
  19352. }
  19353. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19354. refLine[refPos] < columns) {
  19355. refPos += 2;
  19356. }
  19357. }
  19358. break;
  19359. case twoDimVertL1:
  19360. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  19361. blackPixels ^= 1;
  19362. if (codingLine[this.codingPos] < columns) {
  19363. if (refPos > 0) {
  19364. --refPos;
  19365. } else {
  19366. ++refPos;
  19367. }
  19368. while (refLine[refPos] <= codingLine[this.codingPos] &&
  19369. refLine[refPos] < columns) {
  19370. refPos += 2;
  19371. }
  19372. }
  19373. break;
  19374. case EOF:
  19375. this.addPixels(columns, 0);
  19376. this.eof = true;
  19377. break;
  19378. default:
  19379. info('bad 2d code');
  19380. this.addPixels(columns, 0);
  19381. this.err = true;
  19382. }
  19383. }
  19384. } else {
  19385. codingLine[0] = 0;
  19386. this.codingPos = 0;
  19387. blackPixels = 0;
  19388. while (codingLine[this.codingPos] < columns) {
  19389. code1 = 0;
  19390. if (blackPixels) {
  19391. do {
  19392. code1 += (code3 = this.getBlackCode());
  19393. } while (code3 >= 64);
  19394. } else {
  19395. do {
  19396. code1 += (code3 = this.getWhiteCode());
  19397. } while (code3 >= 64);
  19398. }
  19399. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  19400. blackPixels ^= 1;
  19401. }
  19402. }
  19403. var gotEOL = false;
  19404. if (this.byteAlign) {
  19405. this.inputBits &= ~7;
  19406. }
  19407. if (!this.eoblock && this.row === this.rows - 1) {
  19408. this.eof = true;
  19409. } else {
  19410. code1 = this.lookBits(12);
  19411. if (this.eoline) {
  19412. while (code1 !== EOF && code1 !== 1) {
  19413. this.eatBits(1);
  19414. code1 = this.lookBits(12);
  19415. }
  19416. } else {
  19417. while (code1 === 0) {
  19418. this.eatBits(1);
  19419. code1 = this.lookBits(12);
  19420. }
  19421. }
  19422. if (code1 === 1) {
  19423. this.eatBits(12);
  19424. gotEOL = true;
  19425. } else if (code1 === EOF) {
  19426. this.eof = true;
  19427. }
  19428. }
  19429. if (!this.eof && this.encoding > 0) {
  19430. this.nextLine2D = !this.lookBits(1);
  19431. this.eatBits(1);
  19432. }
  19433. if (this.eoblock && gotEOL && this.byteAlign) {
  19434. code1 = this.lookBits(12);
  19435. if (code1 === 1) {
  19436. this.eatBits(12);
  19437. if (this.encoding > 0) {
  19438. this.lookBits(1);
  19439. this.eatBits(1);
  19440. }
  19441. if (this.encoding >= 0) {
  19442. for (i = 0; i < 4; ++i) {
  19443. code1 = this.lookBits(12);
  19444. if (code1 !== 1) {
  19445. info('bad rtc code: ' + code1);
  19446. }
  19447. this.eatBits(12);
  19448. if (this.encoding > 0) {
  19449. this.lookBits(1);
  19450. this.eatBits(1);
  19451. }
  19452. }
  19453. }
  19454. this.eof = true;
  19455. }
  19456. } else if (this.err && this.eoline) {
  19457. while (true) {
  19458. code1 = this.lookBits(13);
  19459. if (code1 === EOF) {
  19460. this.eof = true;
  19461. return null;
  19462. }
  19463. if ((code1 >> 1) === 1) {
  19464. break;
  19465. }
  19466. this.eatBits(1);
  19467. }
  19468. this.eatBits(12);
  19469. if (this.encoding > 0) {
  19470. this.eatBits(1);
  19471. this.nextLine2D = !(code1 & 1);
  19472. }
  19473. }
  19474. if (codingLine[0] > 0) {
  19475. this.outputBits = codingLine[this.codingPos = 0];
  19476. } else {
  19477. this.outputBits = codingLine[this.codingPos = 1];
  19478. }
  19479. this.row++;
  19480. }
  19481. var c;
  19482. if (this.outputBits >= 8) {
  19483. c = (this.codingPos & 1) ? 0 : 0xFF;
  19484. this.outputBits -= 8;
  19485. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  19486. this.codingPos++;
  19487. this.outputBits = (codingLine[this.codingPos] -
  19488. codingLine[this.codingPos - 1]);
  19489. }
  19490. } else {
  19491. bits = 8;
  19492. c = 0;
  19493. do {
  19494. if (this.outputBits > bits) {
  19495. c <<= bits;
  19496. if (!(this.codingPos & 1)) {
  19497. c |= 0xFF >> (8 - bits);
  19498. }
  19499. this.outputBits -= bits;
  19500. bits = 0;
  19501. } else {
  19502. c <<= this.outputBits;
  19503. if (!(this.codingPos & 1)) {
  19504. c |= 0xFF >> (8 - this.outputBits);
  19505. }
  19506. bits -= this.outputBits;
  19507. this.outputBits = 0;
  19508. if (codingLine[this.codingPos] < columns) {
  19509. this.codingPos++;
  19510. this.outputBits = (codingLine[this.codingPos] -
  19511. codingLine[this.codingPos - 1]);
  19512. } else if (bits > 0) {
  19513. c <<= bits;
  19514. bits = 0;
  19515. }
  19516. }
  19517. } while (bits);
  19518. }
  19519. if (this.black) {
  19520. c ^= 0xFF;
  19521. }
  19522. return c;
  19523. };
  19524. // This functions returns the code found from the table.
  19525. // The start and end parameters set the boundaries for searching the table.
  19526. // The limit parameter is optional. Function returns an array with three
  19527. // values. The first array element indicates whether a valid code is being
  19528. // returned. The second array element is the actual code. The third array
  19529. // element indicates whether EOF was reached.
  19530. CCITTFaxStream.prototype.findTableCode =
  19531. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  19532. var limitValue = limit || 0;
  19533. for (var i = start; i <= end; ++i) {
  19534. var code = this.lookBits(i);
  19535. if (code === EOF) {
  19536. return [true, 1, false];
  19537. }
  19538. if (i < end) {
  19539. code <<= end - i;
  19540. }
  19541. if (!limitValue || code >= limitValue) {
  19542. var p = table[code - limitValue];
  19543. if (p[0] === i) {
  19544. this.eatBits(i);
  19545. return [true, p[1], true];
  19546. }
  19547. }
  19548. }
  19549. return [false, 0, false];
  19550. };
  19551. CCITTFaxStream.prototype.getTwoDimCode =
  19552. function ccittFaxStreamGetTwoDimCode() {
  19553. var code = 0;
  19554. var p;
  19555. if (this.eoblock) {
  19556. code = this.lookBits(7);
  19557. p = twoDimTable[code];
  19558. if (p && p[0] > 0) {
  19559. this.eatBits(p[0]);
  19560. return p[1];
  19561. }
  19562. } else {
  19563. var result = this.findTableCode(1, 7, twoDimTable);
  19564. if (result[0] && result[2]) {
  19565. return result[1];
  19566. }
  19567. }
  19568. info('Bad two dim code');
  19569. return EOF;
  19570. };
  19571. CCITTFaxStream.prototype.getWhiteCode =
  19572. function ccittFaxStreamGetWhiteCode() {
  19573. var code = 0;
  19574. var p;
  19575. if (this.eoblock) {
  19576. code = this.lookBits(12);
  19577. if (code === EOF) {
  19578. return 1;
  19579. }
  19580. if ((code >> 5) === 0) {
  19581. p = whiteTable1[code];
  19582. } else {
  19583. p = whiteTable2[code >> 3];
  19584. }
  19585. if (p[0] > 0) {
  19586. this.eatBits(p[0]);
  19587. return p[1];
  19588. }
  19589. } else {
  19590. var result = this.findTableCode(1, 9, whiteTable2);
  19591. if (result[0]) {
  19592. return result[1];
  19593. }
  19594. result = this.findTableCode(11, 12, whiteTable1);
  19595. if (result[0]) {
  19596. return result[1];
  19597. }
  19598. }
  19599. info('bad white code');
  19600. this.eatBits(1);
  19601. return 1;
  19602. };
  19603. CCITTFaxStream.prototype.getBlackCode =
  19604. function ccittFaxStreamGetBlackCode() {
  19605. var code, p;
  19606. if (this.eoblock) {
  19607. code = this.lookBits(13);
  19608. if (code === EOF) {
  19609. return 1;
  19610. }
  19611. if ((code >> 7) === 0) {
  19612. p = blackTable1[code];
  19613. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  19614. p = blackTable2[(code >> 1) - 64];
  19615. } else {
  19616. p = blackTable3[code >> 7];
  19617. }
  19618. if (p[0] > 0) {
  19619. this.eatBits(p[0]);
  19620. return p[1];
  19621. }
  19622. } else {
  19623. var result = this.findTableCode(2, 6, blackTable3);
  19624. if (result[0]) {
  19625. return result[1];
  19626. }
  19627. result = this.findTableCode(7, 12, blackTable2, 64);
  19628. if (result[0]) {
  19629. return result[1];
  19630. }
  19631. result = this.findTableCode(10, 13, blackTable1);
  19632. if (result[0]) {
  19633. return result[1];
  19634. }
  19635. }
  19636. info('bad black code');
  19637. this.eatBits(1);
  19638. return 1;
  19639. };
  19640. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  19641. var c;
  19642. while (this.inputBits < n) {
  19643. if ((c = this.str.getByte()) === -1) {
  19644. if (this.inputBits === 0) {
  19645. return EOF;
  19646. }
  19647. return ((this.inputBuf << (n - this.inputBits)) &
  19648. (0xFFFF >> (16 - n)));
  19649. }
  19650. this.inputBuf = (this.inputBuf << 8) + c;
  19651. this.inputBits += 8;
  19652. }
  19653. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  19654. };
  19655. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  19656. if ((this.inputBits -= n) < 0) {
  19657. this.inputBits = 0;
  19658. }
  19659. };
  19660. return CCITTFaxStream;
  19661. })();
  19662. var LZWStream = (function LZWStreamClosure() {
  19663. function LZWStream(str, maybeLength, earlyChange) {
  19664. this.str = str;
  19665. this.dict = str.dict;
  19666. this.cachedData = 0;
  19667. this.bitsCached = 0;
  19668. var maxLzwDictionarySize = 4096;
  19669. var lzwState = {
  19670. earlyChange: earlyChange,
  19671. codeLength: 9,
  19672. nextCode: 258,
  19673. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  19674. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  19675. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  19676. currentSequence: new Uint8Array(maxLzwDictionarySize),
  19677. currentSequenceLength: 0
  19678. };
  19679. for (var i = 0; i < 256; ++i) {
  19680. lzwState.dictionaryValues[i] = i;
  19681. lzwState.dictionaryLengths[i] = 1;
  19682. }
  19683. this.lzwState = lzwState;
  19684. DecodeStream.call(this, maybeLength);
  19685. }
  19686. LZWStream.prototype = Object.create(DecodeStream.prototype);
  19687. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  19688. var bitsCached = this.bitsCached;
  19689. var cachedData = this.cachedData;
  19690. while (bitsCached < n) {
  19691. var c = this.str.getByte();
  19692. if (c === -1) {
  19693. this.eof = true;
  19694. return null;
  19695. }
  19696. cachedData = (cachedData << 8) | c;
  19697. bitsCached += 8;
  19698. }
  19699. this.bitsCached = (bitsCached -= n);
  19700. this.cachedData = cachedData;
  19701. this.lastCode = null;
  19702. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  19703. };
  19704. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  19705. var blockSize = 512;
  19706. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  19707. var i, j, q;
  19708. var lzwState = this.lzwState;
  19709. if (!lzwState) {
  19710. return; // eof was found
  19711. }
  19712. var earlyChange = lzwState.earlyChange;
  19713. var nextCode = lzwState.nextCode;
  19714. var dictionaryValues = lzwState.dictionaryValues;
  19715. var dictionaryLengths = lzwState.dictionaryLengths;
  19716. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  19717. var codeLength = lzwState.codeLength;
  19718. var prevCode = lzwState.prevCode;
  19719. var currentSequence = lzwState.currentSequence;
  19720. var currentSequenceLength = lzwState.currentSequenceLength;
  19721. var decodedLength = 0;
  19722. var currentBufferLength = this.bufferLength;
  19723. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  19724. for (i = 0; i < blockSize; i++) {
  19725. var code = this.readBits(codeLength);
  19726. var hasPrev = currentSequenceLength > 0;
  19727. if (code < 256) {
  19728. currentSequence[0] = code;
  19729. currentSequenceLength = 1;
  19730. } else if (code >= 258) {
  19731. if (code < nextCode) {
  19732. currentSequenceLength = dictionaryLengths[code];
  19733. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  19734. currentSequence[j] = dictionaryValues[q];
  19735. q = dictionaryPrevCodes[q];
  19736. }
  19737. } else {
  19738. currentSequence[currentSequenceLength++] = currentSequence[0];
  19739. }
  19740. } else if (code === 256) {
  19741. codeLength = 9;
  19742. nextCode = 258;
  19743. currentSequenceLength = 0;
  19744. continue;
  19745. } else {
  19746. this.eof = true;
  19747. delete this.lzwState;
  19748. break;
  19749. }
  19750. if (hasPrev) {
  19751. dictionaryPrevCodes[nextCode] = prevCode;
  19752. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  19753. dictionaryValues[nextCode] = currentSequence[0];
  19754. nextCode++;
  19755. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  19756. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  19757. 0.6931471805599453 + 1, 12) | 0;
  19758. }
  19759. prevCode = code;
  19760. decodedLength += currentSequenceLength;
  19761. if (estimatedDecodedSize < decodedLength) {
  19762. do {
  19763. estimatedDecodedSize += decodedSizeDelta;
  19764. } while (estimatedDecodedSize < decodedLength);
  19765. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  19766. }
  19767. for (j = 0; j < currentSequenceLength; j++) {
  19768. buffer[currentBufferLength++] = currentSequence[j];
  19769. }
  19770. }
  19771. lzwState.nextCode = nextCode;
  19772. lzwState.codeLength = codeLength;
  19773. lzwState.prevCode = prevCode;
  19774. lzwState.currentSequenceLength = currentSequenceLength;
  19775. this.bufferLength = currentBufferLength;
  19776. };
  19777. return LZWStream;
  19778. })();
  19779. var NullStream = (function NullStreamClosure() {
  19780. function NullStream() {
  19781. Stream.call(this, new Uint8Array(0));
  19782. }
  19783. NullStream.prototype = Stream.prototype;
  19784. return NullStream;
  19785. })();
  19786. // TODO refactor to remove dependency on parser.js
  19787. function _setCoreParser(coreParser_) {
  19788. coreParser = coreParser_;
  19789. EOF = coreParser_.EOF;
  19790. Lexer = coreParser_.Lexer;
  19791. }
  19792. exports._setCoreParser = _setCoreParser;
  19793. // TODO refactor to remove dependency on colorspace.js
  19794. function _setCoreColorSpace(coreColorSpace_) {
  19795. coreColorSpace = coreColorSpace_;
  19796. ColorSpace = coreColorSpace_.ColorSpace;
  19797. }
  19798. exports._setCoreColorSpace = _setCoreColorSpace;
  19799. exports.Ascii85Stream = Ascii85Stream;
  19800. exports.AsciiHexStream = AsciiHexStream;
  19801. exports.CCITTFaxStream = CCITTFaxStream;
  19802. exports.DecryptStream = DecryptStream;
  19803. exports.DecodeStream = DecodeStream;
  19804. exports.FlateStream = FlateStream;
  19805. exports.Jbig2Stream = Jbig2Stream;
  19806. exports.JpegStream = JpegStream;
  19807. exports.JpxStream = JpxStream;
  19808. exports.NullStream = NullStream;
  19809. exports.PredictorStream = PredictorStream;
  19810. exports.RunLengthStream = RunLengthStream;
  19811. exports.Stream = Stream;
  19812. exports.StreamsSequenceStream = StreamsSequenceStream;
  19813. exports.StringStream = StringStream;
  19814. exports.LZWStream = LZWStream;
  19815. }));
  19816. (function (root, factory) {
  19817. {
  19818. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  19819. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  19820. }
  19821. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  19822. var PasswordException = sharedUtil.PasswordException;
  19823. var PasswordResponses = sharedUtil.PasswordResponses;
  19824. var bytesToString = sharedUtil.bytesToString;
  19825. var error = sharedUtil.error;
  19826. var isInt = sharedUtil.isInt;
  19827. var stringToBytes = sharedUtil.stringToBytes;
  19828. var utf8StringToString = sharedUtil.utf8StringToString;
  19829. var warn = sharedUtil.warn;
  19830. var Name = corePrimitives.Name;
  19831. var isName = corePrimitives.isName;
  19832. var isDict = corePrimitives.isDict;
  19833. var DecryptStream = coreStream.DecryptStream;
  19834. var ARCFourCipher = (function ARCFourCipherClosure() {
  19835. function ARCFourCipher(key) {
  19836. this.a = 0;
  19837. this.b = 0;
  19838. var s = new Uint8Array(256);
  19839. var i, j = 0, tmp, keyLength = key.length;
  19840. for (i = 0; i < 256; ++i) {
  19841. s[i] = i;
  19842. }
  19843. for (i = 0; i < 256; ++i) {
  19844. tmp = s[i];
  19845. j = (j + tmp + key[i % keyLength]) & 0xFF;
  19846. s[i] = s[j];
  19847. s[j] = tmp;
  19848. }
  19849. this.s = s;
  19850. }
  19851. ARCFourCipher.prototype = {
  19852. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  19853. var i, n = data.length, tmp, tmp2;
  19854. var a = this.a, b = this.b, s = this.s;
  19855. var output = new Uint8Array(n);
  19856. for (i = 0; i < n; ++i) {
  19857. a = (a + 1) & 0xFF;
  19858. tmp = s[a];
  19859. b = (b + tmp) & 0xFF;
  19860. tmp2 = s[b];
  19861. s[a] = tmp2;
  19862. s[b] = tmp;
  19863. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  19864. }
  19865. this.a = a;
  19866. this.b = b;
  19867. return output;
  19868. }
  19869. };
  19870. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  19871. return ARCFourCipher;
  19872. })();
  19873. var calculateMD5 = (function calculateMD5Closure() {
  19874. var r = new Uint8Array([
  19875. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  19876. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  19877. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  19878. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  19879. var k = new Int32Array([
  19880. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  19881. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  19882. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  19883. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  19884. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  19885. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  19886. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  19887. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  19888. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  19889. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  19890. -145523070, -1120210379, 718787259, -343485551]);
  19891. function hash(data, offset, length) {
  19892. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  19893. // pre-processing
  19894. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  19895. var padded = new Uint8Array(paddedLength);
  19896. var i, j, n;
  19897. for (i = 0; i < length; ++i) {
  19898. padded[i] = data[offset++];
  19899. }
  19900. padded[i++] = 0x80;
  19901. n = paddedLength - 8;
  19902. while (i < n) {
  19903. padded[i++] = 0;
  19904. }
  19905. padded[i++] = (length << 3) & 0xFF;
  19906. padded[i++] = (length >> 5) & 0xFF;
  19907. padded[i++] = (length >> 13) & 0xFF;
  19908. padded[i++] = (length >> 21) & 0xFF;
  19909. padded[i++] = (length >>> 29) & 0xFF;
  19910. padded[i++] = 0;
  19911. padded[i++] = 0;
  19912. padded[i++] = 0;
  19913. var w = new Int32Array(16);
  19914. for (i = 0; i < paddedLength;) {
  19915. for (j = 0; j < 16; ++j, i += 4) {
  19916. w[j] = (padded[i] | (padded[i + 1] << 8) |
  19917. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  19918. }
  19919. var a = h0, b = h1, c = h2, d = h3, f, g;
  19920. for (j = 0; j < 64; ++j) {
  19921. if (j < 16) {
  19922. f = (b & c) | ((~b) & d);
  19923. g = j;
  19924. } else if (j < 32) {
  19925. f = (d & b) | ((~d) & c);
  19926. g = (5 * j + 1) & 15;
  19927. } else if (j < 48) {
  19928. f = b ^ c ^ d;
  19929. g = (3 * j + 5) & 15;
  19930. } else {
  19931. f = c ^ (b | (~d));
  19932. g = (7 * j) & 15;
  19933. }
  19934. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  19935. d = c;
  19936. c = b;
  19937. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  19938. a = tmp;
  19939. }
  19940. h0 = (h0 + a) | 0;
  19941. h1 = (h1 + b) | 0;
  19942. h2 = (h2 + c) | 0;
  19943. h3 = (h3 + d) | 0;
  19944. }
  19945. return new Uint8Array([
  19946. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  19947. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  19948. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  19949. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  19950. ]);
  19951. }
  19952. return hash;
  19953. })();
  19954. var Word64 = (function Word64Closure() {
  19955. function Word64(highInteger, lowInteger) {
  19956. this.high = highInteger | 0;
  19957. this.low = lowInteger | 0;
  19958. }
  19959. Word64.prototype = {
  19960. and: function Word64_and(word) {
  19961. this.high &= word.high;
  19962. this.low &= word.low;
  19963. },
  19964. xor: function Word64_xor(word) {
  19965. this.high ^= word.high;
  19966. this.low ^= word.low;
  19967. },
  19968. or: function Word64_or(word) {
  19969. this.high |= word.high;
  19970. this.low |= word.low;
  19971. },
  19972. shiftRight: function Word64_shiftRight(places) {
  19973. if (places >= 32) {
  19974. this.low = (this.high >>> (places - 32)) | 0;
  19975. this.high = 0;
  19976. } else {
  19977. this.low = (this.low >>> places) | (this.high << (32 - places));
  19978. this.high = (this.high >>> places) | 0;
  19979. }
  19980. },
  19981. shiftLeft: function Word64_shiftLeft(places) {
  19982. if (places >= 32) {
  19983. this.high = this.low << (places - 32);
  19984. this.low = 0;
  19985. } else {
  19986. this.high = (this.high << places) | (this.low >>> (32 - places));
  19987. this.low = this.low << places;
  19988. }
  19989. },
  19990. rotateRight: function Word64_rotateRight(places) {
  19991. var low, high;
  19992. if (places & 32) {
  19993. high = this.low;
  19994. low = this.high;
  19995. } else {
  19996. low = this.low;
  19997. high = this.high;
  19998. }
  19999. places &= 31;
  20000. this.low = (low >>> places) | (high << (32 - places));
  20001. this.high = (high >>> places) | (low << (32 - places));
  20002. },
  20003. not: function Word64_not() {
  20004. this.high = ~this.high;
  20005. this.low = ~this.low;
  20006. },
  20007. add: function Word64_add(word) {
  20008. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  20009. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  20010. if (lowAdd > 0xFFFFFFFF) {
  20011. highAdd += 1;
  20012. }
  20013. this.low = lowAdd | 0;
  20014. this.high = highAdd | 0;
  20015. },
  20016. copyTo: function Word64_copyTo(bytes, offset) {
  20017. bytes[offset] = (this.high >>> 24) & 0xFF;
  20018. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  20019. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  20020. bytes[offset + 3] = this.high & 0xFF;
  20021. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  20022. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  20023. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  20024. bytes[offset + 7] = this.low & 0xFF;
  20025. },
  20026. assign: function Word64_assign(word) {
  20027. this.high = word.high;
  20028. this.low = word.low;
  20029. }
  20030. };
  20031. return Word64;
  20032. })();
  20033. var calculateSHA256 = (function calculateSHA256Closure() {
  20034. function rotr(x, n) {
  20035. return (x >>> n) | (x << 32 - n);
  20036. }
  20037. function ch(x, y, z) {
  20038. return (x & y) ^ (~x & z);
  20039. }
  20040. function maj(x, y, z) {
  20041. return (x & y) ^ (x & z) ^ (y & z);
  20042. }
  20043. function sigma(x) {
  20044. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  20045. }
  20046. function sigmaPrime(x) {
  20047. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  20048. }
  20049. function littleSigma(x) {
  20050. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  20051. }
  20052. function littleSigmaPrime(x) {
  20053. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  20054. }
  20055. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  20056. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  20057. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  20058. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  20059. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  20060. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  20061. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  20062. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  20063. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  20064. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  20065. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  20066. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  20067. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  20068. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  20069. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  20070. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  20071. function hash(data, offset, length) {
  20072. // initial hash values
  20073. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  20074. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  20075. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  20076. // pre-processing
  20077. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  20078. var padded = new Uint8Array(paddedLength);
  20079. var i, j, n;
  20080. for (i = 0; i < length; ++i) {
  20081. padded[i] = data[offset++];
  20082. }
  20083. padded[i++] = 0x80;
  20084. n = paddedLength - 8;
  20085. while (i < n) {
  20086. padded[i++] = 0;
  20087. }
  20088. padded[i++] = 0;
  20089. padded[i++] = 0;
  20090. padded[i++] = 0;
  20091. padded[i++] = (length >>> 29) & 0xFF;
  20092. padded[i++] = (length >> 21) & 0xFF;
  20093. padded[i++] = (length >> 13) & 0xFF;
  20094. padded[i++] = (length >> 5) & 0xFF;
  20095. padded[i++] = (length << 3) & 0xFF;
  20096. var w = new Uint32Array(64);
  20097. // for each 512 bit block
  20098. for (i = 0; i < paddedLength;) {
  20099. for (j = 0; j < 16; ++j) {
  20100. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  20101. (padded[i + 2] << 8) | (padded[i + 3]));
  20102. i += 4;
  20103. }
  20104. for (j = 16; j < 64; ++j) {
  20105. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  20106. littleSigma(w[j - 15]) + w[j - 16] | 0;
  20107. }
  20108. var a = h0, b = h1, c = h2, d = h3, e = h4,
  20109. f = h5, g = h6, h = h7, t1, t2;
  20110. for (j = 0; j < 64; ++j) {
  20111. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  20112. t2 = sigma(a) + maj(a, b, c);
  20113. h = g;
  20114. g = f;
  20115. f = e;
  20116. e = (d + t1) | 0;
  20117. d = c;
  20118. c = b;
  20119. b = a;
  20120. a = (t1 + t2) | 0;
  20121. }
  20122. h0 = (h0 + a) | 0;
  20123. h1 = (h1 + b) | 0;
  20124. h2 = (h2 + c) | 0;
  20125. h3 = (h3 + d) | 0;
  20126. h4 = (h4 + e) | 0;
  20127. h5 = (h5 + f) | 0;
  20128. h6 = (h6 + g) | 0;
  20129. h7 = (h7 + h) | 0;
  20130. }
  20131. return new Uint8Array([
  20132. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  20133. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  20134. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  20135. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  20136. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  20137. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  20138. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  20139. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  20140. ]);
  20141. }
  20142. return hash;
  20143. })();
  20144. var calculateSHA512 = (function calculateSHA512Closure() {
  20145. function ch(result, x, y, z, tmp) {
  20146. result.assign(x);
  20147. result.and(y);
  20148. tmp.assign(x);
  20149. tmp.not();
  20150. tmp.and(z);
  20151. result.xor(tmp);
  20152. }
  20153. function maj(result, x, y, z, tmp) {
  20154. result.assign(x);
  20155. result.and(y);
  20156. tmp.assign(x);
  20157. tmp.and(z);
  20158. result.xor(tmp);
  20159. tmp.assign(y);
  20160. tmp.and(z);
  20161. result.xor(tmp);
  20162. }
  20163. function sigma(result, x, tmp) {
  20164. result.assign(x);
  20165. result.rotateRight(28);
  20166. tmp.assign(x);
  20167. tmp.rotateRight(34);
  20168. result.xor(tmp);
  20169. tmp.assign(x);
  20170. tmp.rotateRight(39);
  20171. result.xor(tmp);
  20172. }
  20173. function sigmaPrime(result, x, tmp) {
  20174. result.assign(x);
  20175. result.rotateRight(14);
  20176. tmp.assign(x);
  20177. tmp.rotateRight(18);
  20178. result.xor(tmp);
  20179. tmp.assign(x);
  20180. tmp.rotateRight(41);
  20181. result.xor(tmp);
  20182. }
  20183. function littleSigma(result, x, tmp) {
  20184. result.assign(x);
  20185. result.rotateRight(1);
  20186. tmp.assign(x);
  20187. tmp.rotateRight(8);
  20188. result.xor(tmp);
  20189. tmp.assign(x);
  20190. tmp.shiftRight(7);
  20191. result.xor(tmp);
  20192. }
  20193. function littleSigmaPrime(result, x, tmp) {
  20194. result.assign(x);
  20195. result.rotateRight(19);
  20196. tmp.assign(x);
  20197. tmp.rotateRight(61);
  20198. result.xor(tmp);
  20199. tmp.assign(x);
  20200. tmp.shiftRight(6);
  20201. result.xor(tmp);
  20202. }
  20203. var k = [
  20204. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  20205. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  20206. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  20207. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  20208. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  20209. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  20210. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  20211. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  20212. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  20213. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  20214. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  20215. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  20216. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  20217. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  20218. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  20219. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  20220. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  20221. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  20222. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  20223. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  20224. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  20225. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  20226. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  20227. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  20228. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  20229. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  20230. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  20231. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  20232. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  20233. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  20234. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  20235. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  20236. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  20237. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  20238. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  20239. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  20240. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  20241. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  20242. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  20243. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  20244. function hash(data, offset, length, mode384) {
  20245. mode384 = !!mode384;
  20246. // initial hash values
  20247. var h0, h1, h2, h3, h4, h5, h6, h7;
  20248. if (!mode384) {
  20249. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  20250. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  20251. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  20252. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  20253. h4 = new Word64(0x510e527f, 0xade682d1);
  20254. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  20255. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  20256. h7 = new Word64(0x5be0cd19, 0x137e2179);
  20257. }
  20258. else {
  20259. // SHA384 is exactly the same
  20260. // except with different starting values and a trimmed result
  20261. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  20262. h1 = new Word64(0x629a292a, 0x367cd507);
  20263. h2 = new Word64(0x9159015a, 0x3070dd17);
  20264. h3 = new Word64(0x152fecd8, 0xf70e5939);
  20265. h4 = new Word64(0x67332667, 0xffc00b31);
  20266. h5 = new Word64(0x8eb44a87, 0x68581511);
  20267. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  20268. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  20269. }
  20270. // pre-processing
  20271. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  20272. var padded = new Uint8Array(paddedLength);
  20273. var i, j, n;
  20274. for (i = 0; i < length; ++i) {
  20275. padded[i] = data[offset++];
  20276. }
  20277. padded[i++] = 0x80;
  20278. n = paddedLength - 16;
  20279. while (i < n) {
  20280. padded[i++] = 0;
  20281. }
  20282. padded[i++] = 0;
  20283. padded[i++] = 0;
  20284. padded[i++] = 0;
  20285. padded[i++] = 0;
  20286. padded[i++] = 0;
  20287. padded[i++] = 0;
  20288. padded[i++] = 0;
  20289. padded[i++] = 0;
  20290. padded[i++] = 0;
  20291. padded[i++] = 0;
  20292. padded[i++] = 0;
  20293. padded[i++] = (length >>> 29) & 0xFF;
  20294. padded[i++] = (length >> 21) & 0xFF;
  20295. padded[i++] = (length >> 13) & 0xFF;
  20296. padded[i++] = (length >> 5) & 0xFF;
  20297. padded[i++] = (length << 3) & 0xFF;
  20298. var w = new Array(80);
  20299. for (i = 0; i < 80; i++) {
  20300. w[i] = new Word64(0, 0);
  20301. }
  20302. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  20303. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  20304. var g = new Word64(0, 0), h = new Word64(0, 0);
  20305. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  20306. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  20307. // for each 1024 bit block
  20308. for (i = 0; i < paddedLength;) {
  20309. for (j = 0; j < 16; ++j) {
  20310. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  20311. (padded[i + 2] << 8) | (padded[i + 3]);
  20312. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  20313. (padded[i + 6]) << 8 | (padded[i + 7]);
  20314. i += 8;
  20315. }
  20316. for (j = 16; j < 80; ++j) {
  20317. tmp3 = w[j];
  20318. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  20319. tmp3.add(w[j - 7]);
  20320. littleSigma(tmp1, w[j - 15], tmp2);
  20321. tmp3.add(tmp1);
  20322. tmp3.add(w[j - 16]);
  20323. }
  20324. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  20325. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  20326. for (j = 0; j < 80; ++j) {
  20327. t1.assign(h);
  20328. sigmaPrime(tmp1, e, tmp2);
  20329. t1.add(tmp1);
  20330. ch(tmp1, e, f, g, tmp2);
  20331. t1.add(tmp1);
  20332. t1.add(k[j]);
  20333. t1.add(w[j]);
  20334. sigma(t2, a, tmp2);
  20335. maj(tmp1, a, b, c, tmp2);
  20336. t2.add(tmp1);
  20337. tmp3 = h;
  20338. h = g;
  20339. g = f;
  20340. f = e;
  20341. d.add(t1);
  20342. e = d;
  20343. d = c;
  20344. c = b;
  20345. b = a;
  20346. tmp3.assign(t1);
  20347. tmp3.add(t2);
  20348. a = tmp3;
  20349. }
  20350. h0.add(a);
  20351. h1.add(b);
  20352. h2.add(c);
  20353. h3.add(d);
  20354. h4.add(e);
  20355. h5.add(f);
  20356. h6.add(g);
  20357. h7.add(h);
  20358. }
  20359. var result;
  20360. if (!mode384) {
  20361. result = new Uint8Array(64);
  20362. h0.copyTo(result,0);
  20363. h1.copyTo(result,8);
  20364. h2.copyTo(result,16);
  20365. h3.copyTo(result,24);
  20366. h4.copyTo(result,32);
  20367. h5.copyTo(result,40);
  20368. h6.copyTo(result,48);
  20369. h7.copyTo(result,56);
  20370. }
  20371. else {
  20372. result = new Uint8Array(48);
  20373. h0.copyTo(result,0);
  20374. h1.copyTo(result,8);
  20375. h2.copyTo(result,16);
  20376. h3.copyTo(result,24);
  20377. h4.copyTo(result,32);
  20378. h5.copyTo(result,40);
  20379. }
  20380. return result;
  20381. }
  20382. return hash;
  20383. })();
  20384. var calculateSHA384 = (function calculateSHA384Closure() {
  20385. function hash(data, offset, length) {
  20386. return calculateSHA512(data, offset, length, true);
  20387. }
  20388. return hash;
  20389. })();
  20390. var NullCipher = (function NullCipherClosure() {
  20391. function NullCipher() {
  20392. }
  20393. NullCipher.prototype = {
  20394. decryptBlock: function NullCipher_decryptBlock(data) {
  20395. return data;
  20396. }
  20397. };
  20398. return NullCipher;
  20399. })();
  20400. var AES128Cipher = (function AES128CipherClosure() {
  20401. var rcon = new Uint8Array([
  20402. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20403. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20404. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20405. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20406. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  20407. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  20408. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  20409. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  20410. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  20411. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  20412. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  20413. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  20414. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  20415. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  20416. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  20417. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  20418. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  20419. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20420. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20421. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20422. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20423. 0x74, 0xe8, 0xcb, 0x8d]);
  20424. var s = new Uint8Array([
  20425. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  20426. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  20427. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  20428. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  20429. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  20430. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  20431. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  20432. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  20433. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  20434. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  20435. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  20436. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  20437. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  20438. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  20439. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  20440. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  20441. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  20442. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  20443. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  20444. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  20445. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  20446. 0xb0, 0x54, 0xbb, 0x16]);
  20447. var inv_s = new Uint8Array([
  20448. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  20449. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  20450. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  20451. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  20452. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  20453. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  20454. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  20455. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  20456. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  20457. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  20458. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  20459. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  20460. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  20461. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  20462. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  20463. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  20464. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  20465. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  20466. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  20467. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  20468. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  20469. 0x55, 0x21, 0x0c, 0x7d]);
  20470. var mixCol = new Uint8Array(256);
  20471. for (var i = 0; i < 256; i++) {
  20472. if (i < 128) {
  20473. mixCol[i] = i << 1;
  20474. } else {
  20475. mixCol[i] = (i << 1) ^ 0x1b;
  20476. }
  20477. }
  20478. var mix = new Uint32Array([
  20479. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  20480. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  20481. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  20482. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  20483. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  20484. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  20485. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  20486. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  20487. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  20488. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  20489. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  20490. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  20491. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  20492. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  20493. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  20494. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  20495. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  20496. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  20497. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  20498. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  20499. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  20500. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  20501. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  20502. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  20503. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  20504. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  20505. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  20506. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  20507. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  20508. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  20509. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  20510. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  20511. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  20512. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  20513. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  20514. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  20515. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  20516. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  20517. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  20518. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  20519. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  20520. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  20521. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  20522. function expandKey128(cipherKey) {
  20523. var b = 176, result = new Uint8Array(b);
  20524. result.set(cipherKey);
  20525. for (var j = 16, i = 1; j < b; ++i) {
  20526. // RotWord
  20527. var t1 = result[j - 3], t2 = result[j - 2],
  20528. t3 = result[j - 1], t4 = result[j - 4];
  20529. // SubWord
  20530. t1 = s[t1];
  20531. t2 = s[t2];
  20532. t3 = s[t3];
  20533. t4 = s[t4];
  20534. // Rcon
  20535. t1 = t1 ^ rcon[i];
  20536. for (var n = 0; n < 4; ++n) {
  20537. result[j] = (t1 ^= result[j - 16]);
  20538. j++;
  20539. result[j] = (t2 ^= result[j - 16]);
  20540. j++;
  20541. result[j] = (t3 ^= result[j - 16]);
  20542. j++;
  20543. result[j] = (t4 ^= result[j - 16]);
  20544. j++;
  20545. }
  20546. }
  20547. return result;
  20548. }
  20549. function decrypt128(input, key) {
  20550. var state = new Uint8Array(16);
  20551. state.set(input);
  20552. var i, j, k;
  20553. var t, u, v;
  20554. // AddRoundKey
  20555. for (j = 0, k = 160; j < 16; ++j, ++k) {
  20556. state[j] ^= key[k];
  20557. }
  20558. for (i = 9; i >= 1; --i) {
  20559. // InvShiftRows
  20560. t = state[13];
  20561. state[13] = state[9];
  20562. state[9] = state[5];
  20563. state[5] = state[1];
  20564. state[1] = t;
  20565. t = state[14];
  20566. u = state[10];
  20567. state[14] = state[6];
  20568. state[10] = state[2];
  20569. state[6] = t;
  20570. state[2] = u;
  20571. t = state[15];
  20572. u = state[11];
  20573. v = state[7];
  20574. state[15] = state[3];
  20575. state[11] = t;
  20576. state[7] = u;
  20577. state[3] = v;
  20578. // InvSubBytes
  20579. for (j = 0; j < 16; ++j) {
  20580. state[j] = inv_s[state[j]];
  20581. }
  20582. // AddRoundKey
  20583. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20584. state[j] ^= key[k];
  20585. }
  20586. // InvMixColumns
  20587. for (j = 0; j < 16; j += 4) {
  20588. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  20589. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  20590. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  20591. (s3 >>> 24) ^ (s3 << 8));
  20592. state[j] = (t >>> 24) & 0xFF;
  20593. state[j + 1] = (t >> 16) & 0xFF;
  20594. state[j + 2] = (t >> 8) & 0xFF;
  20595. state[j + 3] = t & 0xFF;
  20596. }
  20597. }
  20598. // InvShiftRows
  20599. t = state[13];
  20600. state[13] = state[9];
  20601. state[9] = state[5];
  20602. state[5] = state[1];
  20603. state[1] = t;
  20604. t = state[14];
  20605. u = state[10];
  20606. state[14] = state[6];
  20607. state[10] = state[2];
  20608. state[6] = t;
  20609. state[2] = u;
  20610. t = state[15];
  20611. u = state[11];
  20612. v = state[7];
  20613. state[15] = state[3];
  20614. state[11] = t;
  20615. state[7] = u;
  20616. state[3] = v;
  20617. for (j = 0; j < 16; ++j) {
  20618. // InvSubBytes
  20619. state[j] = inv_s[state[j]];
  20620. // AddRoundKey
  20621. state[j] ^= key[j];
  20622. }
  20623. return state;
  20624. }
  20625. function encrypt128(input, key) {
  20626. var t, u, v, k;
  20627. var state = new Uint8Array(16);
  20628. state.set(input);
  20629. for (j = 0; j < 16; ++j) {
  20630. // AddRoundKey
  20631. state[j] ^= key[j];
  20632. }
  20633. for (i = 1; i < 10; i++) {
  20634. //SubBytes
  20635. for (j = 0; j < 16; ++j) {
  20636. state[j] = s[state[j]];
  20637. }
  20638. //ShiftRows
  20639. v = state[1];
  20640. state[1] = state[5];
  20641. state[5] = state[9];
  20642. state[9] = state[13];
  20643. state[13] = v;
  20644. v = state[2];
  20645. u = state[6];
  20646. state[2] = state[10];
  20647. state[6] = state[14];
  20648. state[10] = v;
  20649. state[14] = u;
  20650. v = state[3];
  20651. u = state[7];
  20652. t = state[11];
  20653. state[3] = state[15];
  20654. state[7] = v;
  20655. state[11] = u;
  20656. state[15] = t;
  20657. //MixColumns
  20658. for (var j = 0; j < 16; j += 4) {
  20659. var s0 = state[j + 0], s1 = state[j + 1];
  20660. var s2 = state[j + 2], s3 = state[j + 3];
  20661. t = s0 ^ s1 ^ s2 ^ s3;
  20662. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  20663. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  20664. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  20665. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  20666. }
  20667. //AddRoundKey
  20668. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  20669. state[j] ^= key[k];
  20670. }
  20671. }
  20672. //SubBytes
  20673. for (j = 0; j < 16; ++j) {
  20674. state[j] = s[state[j]];
  20675. }
  20676. //ShiftRows
  20677. v = state[1];
  20678. state[1] = state[5];
  20679. state[5] = state[9];
  20680. state[9] = state[13];
  20681. state[13] = v;
  20682. v = state[2];
  20683. u = state[6];
  20684. state[2] = state[10];
  20685. state[6] = state[14];
  20686. state[10] = v;
  20687. state[14] = u;
  20688. v = state[3];
  20689. u = state[7];
  20690. t = state[11];
  20691. state[3] = state[15];
  20692. state[7] = v;
  20693. state[11] = u;
  20694. state[15] = t;
  20695. //AddRoundKey
  20696. for (j = 0, k = 160; j < 16; ++j, ++k) {
  20697. state[j] ^= key[k];
  20698. }
  20699. return state;
  20700. }
  20701. function AES128Cipher(key) {
  20702. this.key = expandKey128(key);
  20703. this.buffer = new Uint8Array(16);
  20704. this.bufferPosition = 0;
  20705. }
  20706. function decryptBlock2(data, finalize) {
  20707. var i, j, ii, sourceLength = data.length,
  20708. buffer = this.buffer, bufferLength = this.bufferPosition,
  20709. result = [], iv = this.iv;
  20710. for (i = 0; i < sourceLength; ++i) {
  20711. buffer[bufferLength] = data[i];
  20712. ++bufferLength;
  20713. if (bufferLength < 16) {
  20714. continue;
  20715. }
  20716. // buffer is full, decrypting
  20717. var plain = decrypt128(buffer, this.key);
  20718. // xor-ing the IV vector to get plain text
  20719. for (j = 0; j < 16; ++j) {
  20720. plain[j] ^= iv[j];
  20721. }
  20722. iv = buffer;
  20723. result.push(plain);
  20724. buffer = new Uint8Array(16);
  20725. bufferLength = 0;
  20726. }
  20727. // saving incomplete buffer
  20728. this.buffer = buffer;
  20729. this.bufferLength = bufferLength;
  20730. this.iv = iv;
  20731. if (result.length === 0) {
  20732. return new Uint8Array([]);
  20733. }
  20734. // combining plain text blocks into one
  20735. var outputLength = 16 * result.length;
  20736. if (finalize) {
  20737. // undo a padding that is described in RFC 2898
  20738. var lastBlock = result[result.length - 1];
  20739. var psLen = lastBlock[15];
  20740. if (psLen <= 16) {
  20741. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  20742. if (lastBlock[i] !== psLen) {
  20743. // Invalid padding, assume that the block has no padding.
  20744. psLen = 0;
  20745. break;
  20746. }
  20747. }
  20748. outputLength -= psLen;
  20749. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  20750. }
  20751. }
  20752. var output = new Uint8Array(outputLength);
  20753. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  20754. output.set(result[i], j);
  20755. }
  20756. return output;
  20757. }
  20758. AES128Cipher.prototype = {
  20759. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  20760. var i, sourceLength = data.length;
  20761. var buffer = this.buffer, bufferLength = this.bufferPosition;
  20762. // waiting for IV values -- they are at the start of the stream
  20763. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  20764. buffer[bufferLength] = data[i];
  20765. }
  20766. if (bufferLength < 16) {
  20767. // need more data
  20768. this.bufferLength = bufferLength;
  20769. return new Uint8Array([]);
  20770. }
  20771. this.iv = buffer;
  20772. this.buffer = new Uint8Array(16);
  20773. this.bufferLength = 0;
  20774. // starting decryption
  20775. this.decryptBlock = decryptBlock2;
  20776. return this.decryptBlock(data.subarray(16), finalize);
  20777. },
  20778. encrypt: function AES128Cipher_encrypt(data, iv) {
  20779. var i, j, ii, sourceLength = data.length,
  20780. buffer = this.buffer, bufferLength = this.bufferPosition,
  20781. result = [];
  20782. if (!iv) {
  20783. iv = new Uint8Array(16);
  20784. }
  20785. for (i = 0; i < sourceLength; ++i) {
  20786. buffer[bufferLength] = data[i];
  20787. ++bufferLength;
  20788. if (bufferLength < 16) {
  20789. continue;
  20790. }
  20791. for (j = 0; j < 16; ++j) {
  20792. buffer[j] ^= iv[j];
  20793. }
  20794. // buffer is full, encrypting
  20795. var cipher = encrypt128(buffer, this.key);
  20796. iv = cipher;
  20797. result.push(cipher);
  20798. buffer = new Uint8Array(16);
  20799. bufferLength = 0;
  20800. }
  20801. // saving incomplete buffer
  20802. this.buffer = buffer;
  20803. this.bufferLength = bufferLength;
  20804. this.iv = iv;
  20805. if (result.length === 0) {
  20806. return new Uint8Array([]);
  20807. }
  20808. // combining plain text blocks into one
  20809. var outputLength = 16 * result.length;
  20810. var output = new Uint8Array(outputLength);
  20811. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  20812. output.set(result[i], j);
  20813. }
  20814. return output;
  20815. }
  20816. };
  20817. return AES128Cipher;
  20818. })();
  20819. var AES256Cipher = (function AES256CipherClosure() {
  20820. var rcon = new Uint8Array([
  20821. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20822. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20823. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20824. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20825. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  20826. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  20827. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  20828. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  20829. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  20830. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  20831. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  20832. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  20833. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  20834. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  20835. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  20836. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  20837. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  20838. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  20839. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  20840. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  20841. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  20842. 0x74, 0xe8, 0xcb, 0x8d]);
  20843. var s = new Uint8Array([
  20844. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  20845. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  20846. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  20847. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  20848. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  20849. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  20850. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  20851. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  20852. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  20853. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  20854. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  20855. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  20856. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  20857. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  20858. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  20859. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  20860. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  20861. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  20862. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  20863. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  20864. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  20865. 0xb0, 0x54, 0xbb, 0x16]);
  20866. var inv_s = new Uint8Array([
  20867. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  20868. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  20869. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  20870. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  20871. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  20872. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  20873. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  20874. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  20875. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  20876. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  20877. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  20878. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  20879. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  20880. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  20881. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  20882. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  20883. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  20884. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  20885. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  20886. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  20887. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  20888. 0x55, 0x21, 0x0c, 0x7d]);
  20889. var mixCol = new Uint8Array(256);
  20890. for (var i = 0; i < 256; i++) {
  20891. if (i < 128) {
  20892. mixCol[i] = i << 1;
  20893. } else {
  20894. mixCol[i] = (i << 1) ^ 0x1b;
  20895. }
  20896. }
  20897. var mix = new Uint32Array([
  20898. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  20899. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  20900. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  20901. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  20902. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  20903. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  20904. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  20905. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  20906. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  20907. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  20908. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  20909. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  20910. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  20911. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  20912. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  20913. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  20914. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  20915. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  20916. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  20917. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  20918. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  20919. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  20920. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  20921. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  20922. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  20923. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  20924. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  20925. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  20926. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  20927. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  20928. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  20929. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  20930. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  20931. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  20932. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  20933. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  20934. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  20935. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  20936. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  20937. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  20938. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  20939. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  20940. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  20941. function expandKey256(cipherKey) {
  20942. var b = 240, result = new Uint8Array(b);
  20943. var r = 1;
  20944. result.set(cipherKey);
  20945. for (var j = 32, i = 1; j < b; ++i) {
  20946. if (j % 32 === 16) {
  20947. t1 = s[t1];
  20948. t2 = s[t2];
  20949. t3 = s[t3];
  20950. t4 = s[t4];
  20951. } else if (j % 32 === 0) {
  20952. // RotWord
  20953. var t1 = result[j - 3], t2 = result[j - 2],
  20954. t3 = result[j - 1], t4 = result[j - 4];
  20955. // SubWord
  20956. t1 = s[t1];
  20957. t2 = s[t2];
  20958. t3 = s[t3];
  20959. t4 = s[t4];
  20960. // Rcon
  20961. t1 = t1 ^ r;
  20962. if ((r <<= 1) >= 256) {
  20963. r = (r ^ 0x1b) & 0xFF;
  20964. }
  20965. }
  20966. for (var n = 0; n < 4; ++n) {
  20967. result[j] = (t1 ^= result[j - 32]);
  20968. j++;
  20969. result[j] = (t2 ^= result[j - 32]);
  20970. j++;
  20971. result[j] = (t3 ^= result[j - 32]);
  20972. j++;
  20973. result[j] = (t4 ^= result[j - 32]);
  20974. j++;
  20975. }
  20976. }
  20977. return result;
  20978. }
  20979. function decrypt256(input, key) {
  20980. var state = new Uint8Array(16);
  20981. state.set(input);
  20982. var i, j, k;
  20983. var t, u, v;
  20984. // AddRoundKey
  20985. for (j = 0, k = 224; j < 16; ++j, ++k) {
  20986. state[j] ^= key[k];
  20987. }
  20988. for (i = 13; i >= 1; --i) {
  20989. // InvShiftRows
  20990. t = state[13];
  20991. state[13] = state[9];
  20992. state[9] = state[5];
  20993. state[5] = state[1];
  20994. state[1] = t;
  20995. t = state[14];
  20996. u = state[10];
  20997. state[14] = state[6];
  20998. state[10] = state[2];
  20999. state[6] = t;
  21000. state[2] = u;
  21001. t = state[15];
  21002. u = state[11];
  21003. v = state[7];
  21004. state[15] = state[3];
  21005. state[11] = t;
  21006. state[7] = u;
  21007. state[3] = v;
  21008. // InvSubBytes
  21009. for (j = 0; j < 16; ++j) {
  21010. state[j] = inv_s[state[j]];
  21011. }
  21012. // AddRoundKey
  21013. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21014. state[j] ^= key[k];
  21015. }
  21016. // InvMixColumns
  21017. for (j = 0; j < 16; j += 4) {
  21018. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  21019. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  21020. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  21021. (s3 >>> 24) ^ (s3 << 8));
  21022. state[j] = (t >>> 24) & 0xFF;
  21023. state[j + 1] = (t >> 16) & 0xFF;
  21024. state[j + 2] = (t >> 8) & 0xFF;
  21025. state[j + 3] = t & 0xFF;
  21026. }
  21027. }
  21028. // InvShiftRows
  21029. t = state[13];
  21030. state[13] = state[9];
  21031. state[9] = state[5];
  21032. state[5] = state[1];
  21033. state[1] = t;
  21034. t = state[14];
  21035. u = state[10];
  21036. state[14] = state[6];
  21037. state[10] = state[2];
  21038. state[6] = t;
  21039. state[2] = u;
  21040. t = state[15];
  21041. u = state[11];
  21042. v = state[7];
  21043. state[15] = state[3];
  21044. state[11] = t;
  21045. state[7] = u;
  21046. state[3] = v;
  21047. for (j = 0; j < 16; ++j) {
  21048. // InvSubBytes
  21049. state[j] = inv_s[state[j]];
  21050. // AddRoundKey
  21051. state[j] ^= key[j];
  21052. }
  21053. return state;
  21054. }
  21055. function encrypt256(input, key) {
  21056. var t, u, v, k;
  21057. var state = new Uint8Array(16);
  21058. state.set(input);
  21059. for (j = 0; j < 16; ++j) {
  21060. // AddRoundKey
  21061. state[j] ^= key[j];
  21062. }
  21063. for (i = 1; i < 14; i++) {
  21064. //SubBytes
  21065. for (j = 0; j < 16; ++j) {
  21066. state[j] = s[state[j]];
  21067. }
  21068. //ShiftRows
  21069. v = state[1];
  21070. state[1] = state[5];
  21071. state[5] = state[9];
  21072. state[9] = state[13];
  21073. state[13] = v;
  21074. v = state[2];
  21075. u = state[6];
  21076. state[2] = state[10];
  21077. state[6] = state[14];
  21078. state[10] = v;
  21079. state[14] = u;
  21080. v = state[3];
  21081. u = state[7];
  21082. t = state[11];
  21083. state[3] = state[15];
  21084. state[7] = v;
  21085. state[11] = u;
  21086. state[15] = t;
  21087. //MixColumns
  21088. for (var j = 0; j < 16; j += 4) {
  21089. var s0 = state[j + 0], s1 = state[j + 1];
  21090. var s2 = state[j + 2], s3 = state[j + 3];
  21091. t = s0 ^ s1 ^ s2 ^ s3;
  21092. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  21093. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  21094. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  21095. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  21096. }
  21097. //AddRoundKey
  21098. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  21099. state[j] ^= key[k];
  21100. }
  21101. }
  21102. //SubBytes
  21103. for (j = 0; j < 16; ++j) {
  21104. state[j] = s[state[j]];
  21105. }
  21106. //ShiftRows
  21107. v = state[1];
  21108. state[1] = state[5];
  21109. state[5] = state[9];
  21110. state[9] = state[13];
  21111. state[13] = v;
  21112. v = state[2];
  21113. u = state[6];
  21114. state[2] = state[10];
  21115. state[6] = state[14];
  21116. state[10] = v;
  21117. state[14] = u;
  21118. v = state[3];
  21119. u = state[7];
  21120. t = state[11];
  21121. state[3] = state[15];
  21122. state[7] = v;
  21123. state[11] = u;
  21124. state[15] = t;
  21125. //AddRoundKey
  21126. for (j = 0, k = 224; j < 16; ++j, ++k) {
  21127. state[j] ^= key[k];
  21128. }
  21129. return state;
  21130. }
  21131. function AES256Cipher(key) {
  21132. this.key = expandKey256(key);
  21133. this.buffer = new Uint8Array(16);
  21134. this.bufferPosition = 0;
  21135. }
  21136. function decryptBlock2(data, finalize) {
  21137. var i, j, ii, sourceLength = data.length,
  21138. buffer = this.buffer, bufferLength = this.bufferPosition,
  21139. result = [], iv = this.iv;
  21140. for (i = 0; i < sourceLength; ++i) {
  21141. buffer[bufferLength] = data[i];
  21142. ++bufferLength;
  21143. if (bufferLength < 16) {
  21144. continue;
  21145. }
  21146. // buffer is full, decrypting
  21147. var plain = decrypt256(buffer, this.key);
  21148. // xor-ing the IV vector to get plain text
  21149. for (j = 0; j < 16; ++j) {
  21150. plain[j] ^= iv[j];
  21151. }
  21152. iv = buffer;
  21153. result.push(plain);
  21154. buffer = new Uint8Array(16);
  21155. bufferLength = 0;
  21156. }
  21157. // saving incomplete buffer
  21158. this.buffer = buffer;
  21159. this.bufferLength = bufferLength;
  21160. this.iv = iv;
  21161. if (result.length === 0) {
  21162. return new Uint8Array([]);
  21163. }
  21164. // combining plain text blocks into one
  21165. var outputLength = 16 * result.length;
  21166. if (finalize) {
  21167. // undo a padding that is described in RFC 2898
  21168. var lastBlock = result[result.length - 1];
  21169. var psLen = lastBlock[15];
  21170. if (psLen <= 16) {
  21171. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  21172. if (lastBlock[i] !== psLen) {
  21173. // Invalid padding, assume that the block has no padding.
  21174. psLen = 0;
  21175. break;
  21176. }
  21177. }
  21178. outputLength -= psLen;
  21179. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  21180. }
  21181. }
  21182. var output = new Uint8Array(outputLength);
  21183. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21184. output.set(result[i], j);
  21185. }
  21186. return output;
  21187. }
  21188. AES256Cipher.prototype = {
  21189. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  21190. var i, sourceLength = data.length;
  21191. var buffer = this.buffer, bufferLength = this.bufferPosition;
  21192. // if not supplied an IV wait for IV values
  21193. // they are at the start of the stream
  21194. if (iv) {
  21195. this.iv = iv;
  21196. } else {
  21197. for (i = 0; bufferLength < 16 &&
  21198. i < sourceLength; ++i, ++bufferLength) {
  21199. buffer[bufferLength] = data[i];
  21200. }
  21201. if (bufferLength < 16) {
  21202. //need more data
  21203. this.bufferLength = bufferLength;
  21204. return new Uint8Array([]);
  21205. }
  21206. this.iv = buffer;
  21207. data = data.subarray(16);
  21208. }
  21209. this.buffer = new Uint8Array(16);
  21210. this.bufferLength = 0;
  21211. // starting decryption
  21212. this.decryptBlock = decryptBlock2;
  21213. return this.decryptBlock(data, finalize);
  21214. },
  21215. encrypt: function AES256Cipher_encrypt(data, iv) {
  21216. var i, j, ii, sourceLength = data.length,
  21217. buffer = this.buffer, bufferLength = this.bufferPosition,
  21218. result = [];
  21219. if (!iv) {
  21220. iv = new Uint8Array(16);
  21221. }
  21222. for (i = 0; i < sourceLength; ++i) {
  21223. buffer[bufferLength] = data[i];
  21224. ++bufferLength;
  21225. if (bufferLength < 16) {
  21226. continue;
  21227. }
  21228. for (j = 0; j < 16; ++j) {
  21229. buffer[j] ^= iv[j];
  21230. }
  21231. // buffer is full, encrypting
  21232. var cipher = encrypt256(buffer, this.key);
  21233. this.iv = cipher;
  21234. result.push(cipher);
  21235. buffer = new Uint8Array(16);
  21236. bufferLength = 0;
  21237. }
  21238. // saving incomplete buffer
  21239. this.buffer = buffer;
  21240. this.bufferLength = bufferLength;
  21241. this.iv = iv;
  21242. if (result.length === 0) {
  21243. return new Uint8Array([]);
  21244. }
  21245. // combining plain text blocks into one
  21246. var outputLength = 16 * result.length;
  21247. var output = new Uint8Array(outputLength);
  21248. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  21249. output.set(result[i], j);
  21250. }
  21251. return output;
  21252. }
  21253. };
  21254. return AES256Cipher;
  21255. })();
  21256. var PDF17 = (function PDF17Closure() {
  21257. function compareByteArrays(array1, array2) {
  21258. if (array1.length !== array2.length) {
  21259. return false;
  21260. }
  21261. for (var i = 0; i < array1.length; i++) {
  21262. if (array1[i] !== array2[i]) {
  21263. return false;
  21264. }
  21265. }
  21266. return true;
  21267. }
  21268. function PDF17() {
  21269. }
  21270. PDF17.prototype = {
  21271. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  21272. ownerValidationSalt,
  21273. userBytes,
  21274. ownerPassword) {
  21275. var hashData = new Uint8Array(password.length + 56);
  21276. hashData.set(password, 0);
  21277. hashData.set(ownerValidationSalt, password.length);
  21278. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  21279. var result = calculateSHA256(hashData, 0, hashData.length);
  21280. return compareByteArrays(result, ownerPassword);
  21281. },
  21282. checkUserPassword: function PDF17_checkUserPassword(password,
  21283. userValidationSalt,
  21284. userPassword) {
  21285. var hashData = new Uint8Array(password.length + 8);
  21286. hashData.set(password, 0);
  21287. hashData.set(userValidationSalt, password.length);
  21288. var result = calculateSHA256(hashData, 0, hashData.length);
  21289. return compareByteArrays(result, userPassword);
  21290. },
  21291. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  21292. ownerEncryption) {
  21293. var hashData = new Uint8Array(password.length + 56);
  21294. hashData.set(password, 0);
  21295. hashData.set(ownerKeySalt, password.length);
  21296. hashData.set(userBytes, password.length + ownerKeySalt.length);
  21297. var key = calculateSHA256(hashData, 0, hashData.length);
  21298. var cipher = new AES256Cipher(key);
  21299. return cipher.decryptBlock(ownerEncryption,
  21300. false,
  21301. new Uint8Array(16));
  21302. },
  21303. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  21304. userEncryption) {
  21305. var hashData = new Uint8Array(password.length + 8);
  21306. hashData.set(password, 0);
  21307. hashData.set(userKeySalt, password.length);
  21308. //key is the decryption key for the UE string
  21309. var key = calculateSHA256(hashData, 0, hashData.length);
  21310. var cipher = new AES256Cipher(key);
  21311. return cipher.decryptBlock(userEncryption,
  21312. false,
  21313. new Uint8Array(16));
  21314. }
  21315. };
  21316. return PDF17;
  21317. })();
  21318. var PDF20 = (function PDF20Closure() {
  21319. function concatArrays(array1, array2) {
  21320. var t = new Uint8Array(array1.length + array2.length);
  21321. t.set(array1, 0);
  21322. t.set(array2, array1.length);
  21323. return t;
  21324. }
  21325. function calculatePDF20Hash(password, input, userBytes) {
  21326. //This refers to Algorithm 2.B as defined in ISO 32000-2
  21327. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  21328. var e = [0];
  21329. var i = 0;
  21330. while (i < 64 || e[e.length - 1] > i - 32) {
  21331. var arrayLength = password.length + k.length + userBytes.length;
  21332. var k1 = new Uint8Array(arrayLength * 64);
  21333. var array = concatArrays(password, k);
  21334. array = concatArrays(array, userBytes);
  21335. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  21336. k1.set(array, pos);
  21337. }
  21338. //AES128 CBC NO PADDING with
  21339. //first 16 bytes of k as the key and the second 16 as the iv.
  21340. var cipher = new AES128Cipher(k.subarray(0, 16));
  21341. e = cipher.encrypt(k1, k.subarray(16, 32));
  21342. //Now we have to take the first 16 bytes of an unsigned
  21343. //big endian integer... and compute the remainder
  21344. //modulo 3.... That is a fairly large number and
  21345. //JavaScript isn't going to handle that well...
  21346. //So we're using a trick that allows us to perform
  21347. //modulo math byte by byte
  21348. var remainder = 0;
  21349. for (var z = 0; z < 16; z++) {
  21350. remainder *= (256 % 3);
  21351. remainder %= 3;
  21352. remainder += ((e[z] >>> 0) % 3);
  21353. remainder %= 3;
  21354. }
  21355. if (remainder === 0) {
  21356. k = calculateSHA256(e, 0, e.length);
  21357. }
  21358. else if (remainder === 1) {
  21359. k = calculateSHA384(e, 0, e.length);
  21360. }
  21361. else if (remainder === 2) {
  21362. k = calculateSHA512(e, 0, e.length);
  21363. }
  21364. i++;
  21365. }
  21366. return k.subarray(0, 32);
  21367. }
  21368. function PDF20() {
  21369. }
  21370. function compareByteArrays(array1, array2) {
  21371. if (array1.length !== array2.length) {
  21372. return false;
  21373. }
  21374. for (var i = 0; i < array1.length; i++) {
  21375. if (array1[i] !== array2[i]) {
  21376. return false;
  21377. }
  21378. }
  21379. return true;
  21380. }
  21381. PDF20.prototype = {
  21382. hash: function PDF20_hash(password, concatBytes, userBytes) {
  21383. return calculatePDF20Hash(password, concatBytes, userBytes);
  21384. },
  21385. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  21386. ownerValidationSalt,
  21387. userBytes,
  21388. ownerPassword) {
  21389. var hashData = new Uint8Array(password.length + 56);
  21390. hashData.set(password, 0);
  21391. hashData.set(ownerValidationSalt, password.length);
  21392. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  21393. var result = calculatePDF20Hash(password, hashData, userBytes);
  21394. return compareByteArrays(result, ownerPassword);
  21395. },
  21396. checkUserPassword: function PDF20_checkUserPassword(password,
  21397. userValidationSalt,
  21398. userPassword) {
  21399. var hashData = new Uint8Array(password.length + 8);
  21400. hashData.set(password, 0);
  21401. hashData.set(userValidationSalt, password.length);
  21402. var result = calculatePDF20Hash(password, hashData, []);
  21403. return compareByteArrays(result, userPassword);
  21404. },
  21405. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  21406. ownerEncryption) {
  21407. var hashData = new Uint8Array(password.length + 56);
  21408. hashData.set(password, 0);
  21409. hashData.set(ownerKeySalt, password.length);
  21410. hashData.set(userBytes, password.length + ownerKeySalt.length);
  21411. var key = calculatePDF20Hash(password, hashData, userBytes);
  21412. var cipher = new AES256Cipher(key);
  21413. return cipher.decryptBlock(ownerEncryption,
  21414. false,
  21415. new Uint8Array(16));
  21416. },
  21417. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  21418. userEncryption) {
  21419. var hashData = new Uint8Array(password.length + 8);
  21420. hashData.set(password, 0);
  21421. hashData.set(userKeySalt, password.length);
  21422. //key is the decryption key for the UE string
  21423. var key = calculatePDF20Hash(password, hashData, []);
  21424. var cipher = new AES256Cipher(key);
  21425. return cipher.decryptBlock(userEncryption,
  21426. false,
  21427. new Uint8Array(16));
  21428. }
  21429. };
  21430. return PDF20;
  21431. })();
  21432. var CipherTransform = (function CipherTransformClosure() {
  21433. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  21434. this.stringCipherConstructor = stringCipherConstructor;
  21435. this.streamCipherConstructor = streamCipherConstructor;
  21436. }
  21437. CipherTransform.prototype = {
  21438. createStream: function CipherTransform_createStream(stream, length) {
  21439. var cipher = new this.streamCipherConstructor();
  21440. return new DecryptStream(stream, length,
  21441. function cipherTransformDecryptStream(data, finalize) {
  21442. return cipher.decryptBlock(data, finalize);
  21443. }
  21444. );
  21445. },
  21446. decryptString: function CipherTransform_decryptString(s) {
  21447. var cipher = new this.stringCipherConstructor();
  21448. var data = stringToBytes(s);
  21449. data = cipher.decryptBlock(data, true);
  21450. return bytesToString(data);
  21451. }
  21452. };
  21453. return CipherTransform;
  21454. })();
  21455. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  21456. var defaultPasswordBytes = new Uint8Array([
  21457. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  21458. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  21459. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  21460. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  21461. function createEncryptionKey20(revision, password, ownerPassword,
  21462. ownerValidationSalt, ownerKeySalt, uBytes,
  21463. userPassword, userValidationSalt, userKeySalt,
  21464. ownerEncryption, userEncryption, perms) {
  21465. if (password) {
  21466. var passwordLength = Math.min(127, password.length);
  21467. password = password.subarray(0, passwordLength);
  21468. } else {
  21469. password = [];
  21470. }
  21471. var pdfAlgorithm;
  21472. if (revision === 6) {
  21473. pdfAlgorithm = new PDF20();
  21474. } else {
  21475. pdfAlgorithm = new PDF17();
  21476. }
  21477. if (pdfAlgorithm) {
  21478. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  21479. userPassword)) {
  21480. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  21481. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  21482. ownerValidationSalt,
  21483. uBytes,
  21484. ownerPassword)) {
  21485. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  21486. ownerEncryption);
  21487. }
  21488. }
  21489. return null;
  21490. }
  21491. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  21492. flags, revision, keyLength, encryptMetadata) {
  21493. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  21494. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  21495. if (password) {
  21496. n = Math.min(32, password.length);
  21497. for (; i < n; ++i) {
  21498. hashData[i] = password[i];
  21499. }
  21500. }
  21501. j = 0;
  21502. while (i < 32) {
  21503. hashData[i++] = defaultPasswordBytes[j++];
  21504. }
  21505. // as now the padded password in the hashData[0..i]
  21506. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  21507. hashData[i++] = ownerPassword[j];
  21508. }
  21509. hashData[i++] = flags & 0xFF;
  21510. hashData[i++] = (flags >> 8) & 0xFF;
  21511. hashData[i++] = (flags >> 16) & 0xFF;
  21512. hashData[i++] = (flags >>> 24) & 0xFF;
  21513. for (j = 0, n = fileId.length; j < n; ++j) {
  21514. hashData[i++] = fileId[j];
  21515. }
  21516. if (revision >= 4 && !encryptMetadata) {
  21517. hashData[i++] = 0xFF;
  21518. hashData[i++] = 0xFF;
  21519. hashData[i++] = 0xFF;
  21520. hashData[i++] = 0xFF;
  21521. }
  21522. var hash = calculateMD5(hashData, 0, i);
  21523. var keyLengthInBytes = keyLength >> 3;
  21524. if (revision >= 3) {
  21525. for (j = 0; j < 50; ++j) {
  21526. hash = calculateMD5(hash, 0, keyLengthInBytes);
  21527. }
  21528. }
  21529. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  21530. var cipher, checkData;
  21531. if (revision >= 3) {
  21532. for (i = 0; i < 32; ++i) {
  21533. hashData[i] = defaultPasswordBytes[i];
  21534. }
  21535. for (j = 0, n = fileId.length; j < n; ++j) {
  21536. hashData[i++] = fileId[j];
  21537. }
  21538. cipher = new ARCFourCipher(encryptionKey);
  21539. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  21540. n = encryptionKey.length;
  21541. var derivedKey = new Uint8Array(n), k;
  21542. for (j = 1; j <= 19; ++j) {
  21543. for (k = 0; k < n; ++k) {
  21544. derivedKey[k] = encryptionKey[k] ^ j;
  21545. }
  21546. cipher = new ARCFourCipher(derivedKey);
  21547. checkData = cipher.encryptBlock(checkData);
  21548. }
  21549. for (j = 0, n = checkData.length; j < n; ++j) {
  21550. if (userPassword[j] !== checkData[j]) {
  21551. return null;
  21552. }
  21553. }
  21554. } else {
  21555. cipher = new ARCFourCipher(encryptionKey);
  21556. checkData = cipher.encryptBlock(defaultPasswordBytes);
  21557. for (j = 0, n = checkData.length; j < n; ++j) {
  21558. if (userPassword[j] !== checkData[j]) {
  21559. return null;
  21560. }
  21561. }
  21562. }
  21563. return encryptionKey;
  21564. }
  21565. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  21566. var hashData = new Uint8Array(32), i = 0, j, n;
  21567. n = Math.min(32, password.length);
  21568. for (; i < n; ++i) {
  21569. hashData[i] = password[i];
  21570. }
  21571. j = 0;
  21572. while (i < 32) {
  21573. hashData[i++] = defaultPasswordBytes[j++];
  21574. }
  21575. var hash = calculateMD5(hashData, 0, i);
  21576. var keyLengthInBytes = keyLength >> 3;
  21577. if (revision >= 3) {
  21578. for (j = 0; j < 50; ++j) {
  21579. hash = calculateMD5(hash, 0, hash.length);
  21580. }
  21581. }
  21582. var cipher, userPassword;
  21583. if (revision >= 3) {
  21584. userPassword = ownerPassword;
  21585. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  21586. for (j = 19; j >= 0; j--) {
  21587. for (k = 0; k < keyLengthInBytes; ++k) {
  21588. derivedKey[k] = hash[k] ^ j;
  21589. }
  21590. cipher = new ARCFourCipher(derivedKey);
  21591. userPassword = cipher.encryptBlock(userPassword);
  21592. }
  21593. } else {
  21594. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  21595. userPassword = cipher.encryptBlock(ownerPassword);
  21596. }
  21597. return userPassword;
  21598. }
  21599. var identityName = Name.get('Identity');
  21600. function CipherTransformFactory(dict, fileId, password) {
  21601. var filter = dict.get('Filter');
  21602. if (!isName(filter) || filter.name !== 'Standard') {
  21603. error('unknown encryption method');
  21604. }
  21605. this.dict = dict;
  21606. var algorithm = dict.get('V');
  21607. if (!isInt(algorithm) ||
  21608. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  21609. algorithm !== 5)) {
  21610. error('unsupported encryption algorithm');
  21611. }
  21612. this.algorithm = algorithm;
  21613. var keyLength = dict.get('Length');
  21614. if (!keyLength) {
  21615. // Spec asks to rely on encryption dictionary's Length entry, however
  21616. // some PDFs don't have it. Trying to recover.
  21617. if (algorithm <= 3) {
  21618. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  21619. keyLength = 40;
  21620. } else {
  21621. // Trying to find default handler -- it usually has Length.
  21622. var cfDict = dict.get('CF');
  21623. var streamCryptoName = dict.get('StmF');
  21624. if (isDict(cfDict) && isName(streamCryptoName)) {
  21625. var handlerDict = cfDict.get(streamCryptoName.name);
  21626. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  21627. if (keyLength < 40) {
  21628. // Sometimes it's incorrect value of bits, generators specify bytes.
  21629. keyLength <<= 3;
  21630. }
  21631. }
  21632. }
  21633. }
  21634. if (!isInt(keyLength) ||
  21635. keyLength < 40 || (keyLength % 8) !== 0) {
  21636. error('invalid key length');
  21637. }
  21638. // prepare keys
  21639. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  21640. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  21641. var flags = dict.get('P');
  21642. var revision = dict.get('R');
  21643. // meaningful when V is 4 or 5
  21644. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  21645. dict.get('EncryptMetadata') !== false);
  21646. this.encryptMetadata = encryptMetadata;
  21647. var fileIdBytes = stringToBytes(fileId);
  21648. var passwordBytes;
  21649. if (password) {
  21650. if (revision === 6) {
  21651. try {
  21652. password = utf8StringToString(password);
  21653. } catch (ex) {
  21654. warn('CipherTransformFactory: ' +
  21655. 'Unable to convert UTF8 encoded password.');
  21656. }
  21657. }
  21658. passwordBytes = stringToBytes(password);
  21659. }
  21660. var encryptionKey;
  21661. if (algorithm !== 5) {
  21662. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  21663. ownerPassword, userPassword, flags,
  21664. revision, keyLength, encryptMetadata);
  21665. }
  21666. else {
  21667. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  21668. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  21669. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  21670. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  21671. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  21672. var ownerEncryption = stringToBytes(dict.get('OE'));
  21673. var userEncryption = stringToBytes(dict.get('UE'));
  21674. var perms = stringToBytes(dict.get('Perms'));
  21675. encryptionKey =
  21676. createEncryptionKey20(revision, passwordBytes,
  21677. ownerPassword, ownerValidationSalt,
  21678. ownerKeySalt, uBytes,
  21679. userPassword, userValidationSalt,
  21680. userKeySalt, ownerEncryption,
  21681. userEncryption, perms);
  21682. }
  21683. if (!encryptionKey && !password) {
  21684. throw new PasswordException('No password given',
  21685. PasswordResponses.NEED_PASSWORD);
  21686. } else if (!encryptionKey && password) {
  21687. // Attempting use the password as an owner password
  21688. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  21689. revision, keyLength);
  21690. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  21691. ownerPassword, userPassword, flags,
  21692. revision, keyLength, encryptMetadata);
  21693. }
  21694. if (!encryptionKey) {
  21695. throw new PasswordException('Incorrect Password',
  21696. PasswordResponses.INCORRECT_PASSWORD);
  21697. }
  21698. this.encryptionKey = encryptionKey;
  21699. if (algorithm >= 4) {
  21700. this.cf = dict.get('CF');
  21701. this.stmf = dict.get('StmF') || identityName;
  21702. this.strf = dict.get('StrF') || identityName;
  21703. this.eff = dict.get('EFF') || this.stmf;
  21704. }
  21705. }
  21706. function buildObjectKey(num, gen, encryptionKey, isAes) {
  21707. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  21708. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  21709. key[i] = encryptionKey[i];
  21710. }
  21711. key[i++] = num & 0xFF;
  21712. key[i++] = (num >> 8) & 0xFF;
  21713. key[i++] = (num >> 16) & 0xFF;
  21714. key[i++] = gen & 0xFF;
  21715. key[i++] = (gen >> 8) & 0xFF;
  21716. if (isAes) {
  21717. key[i++] = 0x73;
  21718. key[i++] = 0x41;
  21719. key[i++] = 0x6C;
  21720. key[i++] = 0x54;
  21721. }
  21722. var hash = calculateMD5(key, 0, i);
  21723. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  21724. }
  21725. function buildCipherConstructor(cf, name, num, gen, key) {
  21726. var cryptFilter = cf.get(name.name);
  21727. var cfm;
  21728. if (cryptFilter !== null && cryptFilter !== undefined) {
  21729. cfm = cryptFilter.get('CFM');
  21730. }
  21731. if (!cfm || cfm.name === 'None') {
  21732. return function cipherTransformFactoryBuildCipherConstructorNone() {
  21733. return new NullCipher();
  21734. };
  21735. }
  21736. if ('V2' === cfm.name) {
  21737. return function cipherTransformFactoryBuildCipherConstructorV2() {
  21738. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  21739. };
  21740. }
  21741. if ('AESV2' === cfm.name) {
  21742. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  21743. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  21744. };
  21745. }
  21746. if ('AESV3' === cfm.name) {
  21747. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  21748. return new AES256Cipher(key);
  21749. };
  21750. }
  21751. error('Unknown crypto method');
  21752. }
  21753. CipherTransformFactory.prototype = {
  21754. createCipherTransform:
  21755. function CipherTransformFactory_createCipherTransform(num, gen) {
  21756. if (this.algorithm === 4 || this.algorithm === 5) {
  21757. return new CipherTransform(
  21758. buildCipherConstructor(this.cf, this.stmf,
  21759. num, gen, this.encryptionKey),
  21760. buildCipherConstructor(this.cf, this.strf,
  21761. num, gen, this.encryptionKey));
  21762. }
  21763. // algorithms 1 and 2
  21764. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  21765. var cipherConstructor = function buildCipherCipherConstructor() {
  21766. return new ARCFourCipher(key);
  21767. };
  21768. return new CipherTransform(cipherConstructor, cipherConstructor);
  21769. }
  21770. };
  21771. return CipherTransformFactory;
  21772. })();
  21773. exports.AES128Cipher = AES128Cipher;
  21774. exports.AES256Cipher = AES256Cipher;
  21775. exports.ARCFourCipher = ARCFourCipher;
  21776. exports.CipherTransformFactory = CipherTransformFactory;
  21777. exports.PDF17 = PDF17;
  21778. exports.PDF20 = PDF20;
  21779. exports.calculateMD5 = calculateMD5;
  21780. exports.calculateSHA256 = calculateSHA256;
  21781. exports.calculateSHA384 = calculateSHA384;
  21782. exports.calculateSHA512 = calculateSHA512;
  21783. }));
  21784. (function (root, factory) {
  21785. {
  21786. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  21787. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings);
  21788. }
  21789. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  21790. coreEncodings) {
  21791. var Util = sharedUtil.Util;
  21792. var bytesToString = sharedUtil.bytesToString;
  21793. var error = sharedUtil.error;
  21794. var Stream = coreStream.Stream;
  21795. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  21796. var StandardEncoding = coreEncodings.StandardEncoding;
  21797. var coreFonts; // see _setCoreFonts below
  21798. var CFFParser; // = coreFonts.CFFParser;
  21799. var FontRendererFactory = (function FontRendererFactoryClosure() {
  21800. function getLong(data, offset) {
  21801. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21802. (data[offset + 2] << 8) | data[offset + 3];
  21803. }
  21804. function getUshort(data, offset) {
  21805. return (data[offset] << 8) | data[offset + 1];
  21806. }
  21807. function parseCmap(data, start, end) {
  21808. var offset = (getUshort(data, start + 2) === 1 ?
  21809. getLong(data, start + 8) : getLong(data, start + 16));
  21810. var format = getUshort(data, start + offset);
  21811. var length, ranges, p, i;
  21812. if (format === 4) {
  21813. length = getUshort(data, start + offset + 2);
  21814. var segCount = getUshort(data, start + offset + 6) >> 1;
  21815. p = start + offset + 14;
  21816. ranges = [];
  21817. for (i = 0; i < segCount; i++, p += 2) {
  21818. ranges[i] = {end: getUshort(data, p)};
  21819. }
  21820. p += 2;
  21821. for (i = 0; i < segCount; i++, p += 2) {
  21822. ranges[i].start = getUshort(data, p);
  21823. }
  21824. for (i = 0; i < segCount; i++, p += 2) {
  21825. ranges[i].idDelta = getUshort(data, p);
  21826. }
  21827. for (i = 0; i < segCount; i++, p += 2) {
  21828. var idOffset = getUshort(data, p);
  21829. if (idOffset === 0) {
  21830. continue;
  21831. }
  21832. ranges[i].ids = [];
  21833. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  21834. ranges[i].ids[j] = getUshort(data, p + idOffset);
  21835. idOffset += 2;
  21836. }
  21837. }
  21838. return ranges;
  21839. } else if (format === 12) {
  21840. length = getLong(data, start + offset + 4);
  21841. var groups = getLong(data, start + offset + 12);
  21842. p = start + offset + 16;
  21843. ranges = [];
  21844. for (i = 0; i < groups; i++) {
  21845. ranges.push({
  21846. start: getLong(data, p),
  21847. end: getLong(data, p + 4),
  21848. idDelta: getLong(data, p + 8) - getLong(data, p)
  21849. });
  21850. p += 12;
  21851. }
  21852. return ranges;
  21853. }
  21854. error('not supported cmap: ' + format);
  21855. }
  21856. function parseCff(data, start, end) {
  21857. var properties = {};
  21858. var parser = new CFFParser(new Stream(data, start, end - start),
  21859. properties);
  21860. var cff = parser.parse();
  21861. return {
  21862. glyphs: cff.charStrings.objects,
  21863. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  21864. cff.topDict.privateDict.subrsIndex.objects),
  21865. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  21866. };
  21867. }
  21868. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  21869. var itemSize, itemDecode;
  21870. if (isGlyphLocationsLong) {
  21871. itemSize = 4;
  21872. itemDecode = function fontItemDecodeLong(data, offset) {
  21873. return (data[offset] << 24) | (data[offset + 1] << 16) |
  21874. (data[offset + 2] << 8) | data[offset + 3];
  21875. };
  21876. } else {
  21877. itemSize = 2;
  21878. itemDecode = function fontItemDecode(data, offset) {
  21879. return (data[offset] << 9) | (data[offset + 1] << 1);
  21880. };
  21881. }
  21882. var glyphs = [];
  21883. var startOffset = itemDecode(loca, 0);
  21884. for (var j = itemSize; j < loca.length; j += itemSize) {
  21885. var endOffset = itemDecode(loca, j);
  21886. glyphs.push(glyf.subarray(startOffset, endOffset));
  21887. startOffset = endOffset;
  21888. }
  21889. return glyphs;
  21890. }
  21891. function lookupCmap(ranges, unicode) {
  21892. var code = unicode.charCodeAt(0);
  21893. var l = 0, r = ranges.length - 1;
  21894. while (l < r) {
  21895. var c = (l + r + 1) >> 1;
  21896. if (code < ranges[c].start) {
  21897. r = c - 1;
  21898. } else {
  21899. l = c;
  21900. }
  21901. }
  21902. if (ranges[l].start <= code && code <= ranges[l].end) {
  21903. return (ranges[l].idDelta + (ranges[l].ids ?
  21904. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  21905. }
  21906. return 0;
  21907. }
  21908. function compileGlyf(code, cmds, font) {
  21909. function moveTo(x, y) {
  21910. cmds.push({cmd: 'moveTo', args: [x, y]});
  21911. }
  21912. function lineTo(x, y) {
  21913. cmds.push({cmd: 'lineTo', args: [x, y]});
  21914. }
  21915. function quadraticCurveTo(xa, ya, x, y) {
  21916. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  21917. }
  21918. var i = 0;
  21919. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21920. var flags;
  21921. var x = 0, y = 0;
  21922. i += 10;
  21923. if (numberOfContours < 0) {
  21924. // composite glyph
  21925. do {
  21926. flags = (code[i] << 8) | code[i + 1];
  21927. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  21928. i += 4;
  21929. var arg1, arg2;
  21930. if ((flags & 0x01)) {
  21931. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21932. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  21933. i += 4;
  21934. } else {
  21935. arg1 = code[i++]; arg2 = code[i++];
  21936. }
  21937. if ((flags & 0x02)) {
  21938. x = arg1;
  21939. y = arg2;
  21940. } else {
  21941. x = 0; y = 0; // TODO "they are points" ?
  21942. }
  21943. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  21944. if ((flags & 0x08)) {
  21945. scaleX =
  21946. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21947. i += 2;
  21948. } else if ((flags & 0x40)) {
  21949. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21950. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  21951. i += 4;
  21952. } else if ((flags & 0x80)) {
  21953. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  21954. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  21955. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  21956. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  21957. i += 8;
  21958. }
  21959. var subglyph = font.glyphs[glyphIndex];
  21960. if (subglyph) {
  21961. cmds.push({cmd: 'save'});
  21962. cmds.push({cmd: 'transform',
  21963. args: [scaleX, scale01, scale10, scaleY, x, y]});
  21964. compileGlyf(subglyph, cmds, font);
  21965. cmds.push({cmd: 'restore'});
  21966. }
  21967. } while ((flags & 0x20));
  21968. } else {
  21969. // simple glyph
  21970. var endPtsOfContours = [];
  21971. var j, jj;
  21972. for (j = 0; j < numberOfContours; j++) {
  21973. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  21974. i += 2;
  21975. }
  21976. var instructionLength = (code[i] << 8) | code[i + 1];
  21977. i += 2 + instructionLength; // skipping the instructions
  21978. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  21979. var points = [];
  21980. while (points.length < numberOfPoints) {
  21981. flags = code[i++];
  21982. var repeat = 1;
  21983. if ((flags & 0x08)) {
  21984. repeat += code[i++];
  21985. }
  21986. while (repeat-- > 0) {
  21987. points.push({flags: flags});
  21988. }
  21989. }
  21990. for (j = 0; j < numberOfPoints; j++) {
  21991. switch (points[j].flags & 0x12) {
  21992. case 0x00:
  21993. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  21994. i += 2;
  21995. break;
  21996. case 0x02:
  21997. x -= code[i++];
  21998. break;
  21999. case 0x12:
  22000. x += code[i++];
  22001. break;
  22002. }
  22003. points[j].x = x;
  22004. }
  22005. for (j = 0; j < numberOfPoints; j++) {
  22006. switch (points[j].flags & 0x24) {
  22007. case 0x00:
  22008. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  22009. i += 2;
  22010. break;
  22011. case 0x04:
  22012. y -= code[i++];
  22013. break;
  22014. case 0x24:
  22015. y += code[i++];
  22016. break;
  22017. }
  22018. points[j].y = y;
  22019. }
  22020. var startPoint = 0;
  22021. for (i = 0; i < numberOfContours; i++) {
  22022. var endPoint = endPtsOfContours[i];
  22023. // contours might have implicit points, which is located in the middle
  22024. // between two neighboring off-curve points
  22025. var contour = points.slice(startPoint, endPoint + 1);
  22026. if ((contour[0].flags & 1)) {
  22027. contour.push(contour[0]); // using start point at the contour end
  22028. } else if ((contour[contour.length - 1].flags & 1)) {
  22029. // first is off-curve point, trying to use one from the end
  22030. contour.unshift(contour[contour.length - 1]);
  22031. } else {
  22032. // start and end are off-curve points, creating implicit one
  22033. var p = {
  22034. flags: 1,
  22035. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  22036. y: (contour[0].y + contour[contour.length - 1].y) / 2
  22037. };
  22038. contour.unshift(p);
  22039. contour.push(p);
  22040. }
  22041. moveTo(contour[0].x, contour[0].y);
  22042. for (j = 1, jj = contour.length; j < jj; j++) {
  22043. if ((contour[j].flags & 1)) {
  22044. lineTo(contour[j].x, contour[j].y);
  22045. } else if ((contour[j + 1].flags & 1)){
  22046. quadraticCurveTo(contour[j].x, contour[j].y,
  22047. contour[j + 1].x, contour[j + 1].y);
  22048. j++;
  22049. } else {
  22050. quadraticCurveTo(contour[j].x, contour[j].y,
  22051. (contour[j].x + contour[j + 1].x) / 2,
  22052. (contour[j].y + contour[j + 1].y) / 2);
  22053. }
  22054. }
  22055. startPoint = endPoint + 1;
  22056. }
  22057. }
  22058. }
  22059. function compileCharString(code, cmds, font) {
  22060. var stack = [];
  22061. var x = 0, y = 0;
  22062. var stems = 0;
  22063. function moveTo(x, y) {
  22064. cmds.push({cmd: 'moveTo', args: [x, y]});
  22065. }
  22066. function lineTo(x, y) {
  22067. cmds.push({cmd: 'lineTo', args: [x, y]});
  22068. }
  22069. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  22070. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  22071. }
  22072. function parse(code) {
  22073. var i = 0;
  22074. while (i < code.length) {
  22075. var stackClean = false;
  22076. var v = code[i++];
  22077. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  22078. switch (v) {
  22079. case 1: // hstem
  22080. stems += stack.length >> 1;
  22081. stackClean = true;
  22082. break;
  22083. case 3: // vstem
  22084. stems += stack.length >> 1;
  22085. stackClean = true;
  22086. break;
  22087. case 4: // vmoveto
  22088. y += stack.pop();
  22089. moveTo(x, y);
  22090. stackClean = true;
  22091. break;
  22092. case 5: // rlineto
  22093. while (stack.length > 0) {
  22094. x += stack.shift();
  22095. y += stack.shift();
  22096. lineTo(x, y);
  22097. }
  22098. break;
  22099. case 6: // hlineto
  22100. while (stack.length > 0) {
  22101. x += stack.shift();
  22102. lineTo(x, y);
  22103. if (stack.length === 0) {
  22104. break;
  22105. }
  22106. y += stack.shift();
  22107. lineTo(x, y);
  22108. }
  22109. break;
  22110. case 7: // vlineto
  22111. while (stack.length > 0) {
  22112. y += stack.shift();
  22113. lineTo(x, y);
  22114. if (stack.length === 0) {
  22115. break;
  22116. }
  22117. x += stack.shift();
  22118. lineTo(x, y);
  22119. }
  22120. break;
  22121. case 8: // rrcurveto
  22122. while (stack.length > 0) {
  22123. xa = x + stack.shift(); ya = y + stack.shift();
  22124. xb = xa + stack.shift(); yb = ya + stack.shift();
  22125. x = xb + stack.shift(); y = yb + stack.shift();
  22126. bezierCurveTo(xa, ya, xb, yb, x, y);
  22127. }
  22128. break;
  22129. case 10: // callsubr
  22130. n = stack.pop() + font.subrsBias;
  22131. subrCode = font.subrs[n];
  22132. if (subrCode) {
  22133. parse(subrCode);
  22134. }
  22135. break;
  22136. case 11: // return
  22137. return;
  22138. case 12:
  22139. v = code[i++];
  22140. switch (v) {
  22141. case 34: // flex
  22142. xa = x + stack.shift();
  22143. xb = xa + stack.shift(); y1 = y + stack.shift();
  22144. x = xb + stack.shift();
  22145. bezierCurveTo(xa, y, xb, y1, x, y1);
  22146. xa = x + stack.shift();
  22147. xb = xa + stack.shift();
  22148. x = xb + stack.shift();
  22149. bezierCurveTo(xa, y1, xb, y, x, y);
  22150. break;
  22151. case 35: // flex
  22152. xa = x + stack.shift(); ya = y + stack.shift();
  22153. xb = xa + stack.shift(); yb = ya + stack.shift();
  22154. x = xb + stack.shift(); y = yb + stack.shift();
  22155. bezierCurveTo(xa, ya, xb, yb, x, y);
  22156. xa = x + stack.shift(); ya = y + stack.shift();
  22157. xb = xa + stack.shift(); yb = ya + stack.shift();
  22158. x = xb + stack.shift(); y = yb + stack.shift();
  22159. bezierCurveTo(xa, ya, xb, yb, x, y);
  22160. stack.pop(); // fd
  22161. break;
  22162. case 36: // hflex1
  22163. xa = x + stack.shift(); y1 = y + stack.shift();
  22164. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  22165. x = xb + stack.shift();
  22166. bezierCurveTo(xa, y1, xb, y2, x, y2);
  22167. xa = x + stack.shift();
  22168. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  22169. x = xb + stack.shift();
  22170. bezierCurveTo(xa, y2, xb, y3, x, y);
  22171. break;
  22172. case 37: // flex1
  22173. var x0 = x, y0 = y;
  22174. xa = x + stack.shift(); ya = y + stack.shift();
  22175. xb = xa + stack.shift(); yb = ya + stack.shift();
  22176. x = xb + stack.shift(); y = yb + stack.shift();
  22177. bezierCurveTo(xa, ya, xb, yb, x, y);
  22178. xa = x + stack.shift(); ya = y + stack.shift();
  22179. xb = xa + stack.shift(); yb = ya + stack.shift();
  22180. x = xb; y = yb;
  22181. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  22182. x += stack.shift();
  22183. } else {
  22184. y += stack.shift();
  22185. }
  22186. bezierCurveTo(xa, ya, xb, yb, x, y);
  22187. break;
  22188. default:
  22189. error('unknown operator: 12 ' + v);
  22190. }
  22191. break;
  22192. case 14: // endchar
  22193. if (stack.length >= 4) {
  22194. var achar = stack.pop();
  22195. var bchar = stack.pop();
  22196. y = stack.pop();
  22197. x = stack.pop();
  22198. cmds.push({cmd: 'save'});
  22199. cmds.push({cmd: 'translate', args: [x, y]});
  22200. var gid = lookupCmap(font.cmap, String.fromCharCode(
  22201. font.glyphNameMap[StandardEncoding[achar]]));
  22202. compileCharString(font.glyphs[gid], cmds, font);
  22203. cmds.push({cmd: 'restore'});
  22204. gid = lookupCmap(font.cmap, String.fromCharCode(
  22205. font.glyphNameMap[StandardEncoding[bchar]]));
  22206. compileCharString(font.glyphs[gid], cmds, font);
  22207. }
  22208. return;
  22209. case 18: // hstemhm
  22210. stems += stack.length >> 1;
  22211. stackClean = true;
  22212. break;
  22213. case 19: // hintmask
  22214. stems += stack.length >> 1;
  22215. i += (stems + 7) >> 3;
  22216. stackClean = true;
  22217. break;
  22218. case 20: // cntrmask
  22219. stems += stack.length >> 1;
  22220. i += (stems + 7) >> 3;
  22221. stackClean = true;
  22222. break;
  22223. case 21: // rmoveto
  22224. y += stack.pop();
  22225. x += stack.pop();
  22226. moveTo(x, y);
  22227. stackClean = true;
  22228. break;
  22229. case 22: // hmoveto
  22230. x += stack.pop();
  22231. moveTo(x, y);
  22232. stackClean = true;
  22233. break;
  22234. case 23: // vstemhm
  22235. stems += stack.length >> 1;
  22236. stackClean = true;
  22237. break;
  22238. case 24: // rcurveline
  22239. while (stack.length > 2) {
  22240. xa = x + stack.shift(); ya = y + stack.shift();
  22241. xb = xa + stack.shift(); yb = ya + stack.shift();
  22242. x = xb + stack.shift(); y = yb + stack.shift();
  22243. bezierCurveTo(xa, ya, xb, yb, x, y);
  22244. }
  22245. x += stack.shift();
  22246. y += stack.shift();
  22247. lineTo(x, y);
  22248. break;
  22249. case 25: // rlinecurve
  22250. while (stack.length > 6) {
  22251. x += stack.shift();
  22252. y += stack.shift();
  22253. lineTo(x, y);
  22254. }
  22255. xa = x + stack.shift(); ya = y + stack.shift();
  22256. xb = xa + stack.shift(); yb = ya + stack.shift();
  22257. x = xb + stack.shift(); y = yb + stack.shift();
  22258. bezierCurveTo(xa, ya, xb, yb, x, y);
  22259. break;
  22260. case 26: // vvcurveto
  22261. if (stack.length % 2) {
  22262. x += stack.shift();
  22263. }
  22264. while (stack.length > 0) {
  22265. xa = x; ya = y + stack.shift();
  22266. xb = xa + stack.shift(); yb = ya + stack.shift();
  22267. x = xb; y = yb + stack.shift();
  22268. bezierCurveTo(xa, ya, xb, yb, x, y);
  22269. }
  22270. break;
  22271. case 27: // hhcurveto
  22272. if (stack.length % 2) {
  22273. y += stack.shift();
  22274. }
  22275. while (stack.length > 0) {
  22276. xa = x + stack.shift(); ya = y;
  22277. xb = xa + stack.shift(); yb = ya + stack.shift();
  22278. x = xb + stack.shift(); y = yb;
  22279. bezierCurveTo(xa, ya, xb, yb, x, y);
  22280. }
  22281. break;
  22282. case 28:
  22283. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  22284. i += 2;
  22285. break;
  22286. case 29: // callgsubr
  22287. n = stack.pop() + font.gsubrsBias;
  22288. subrCode = font.gsubrs[n];
  22289. if (subrCode) {
  22290. parse(subrCode);
  22291. }
  22292. break;
  22293. case 30: // vhcurveto
  22294. while (stack.length > 0) {
  22295. xa = x; ya = y + stack.shift();
  22296. xb = xa + stack.shift(); yb = ya + stack.shift();
  22297. x = xb + stack.shift();
  22298. y = yb + (stack.length === 1 ? stack.shift() : 0);
  22299. bezierCurveTo(xa, ya, xb, yb, x, y);
  22300. if (stack.length === 0) {
  22301. break;
  22302. }
  22303. xa = x + stack.shift(); ya = y;
  22304. xb = xa + stack.shift(); yb = ya + stack.shift();
  22305. y = yb + stack.shift();
  22306. x = xb + (stack.length === 1 ? stack.shift() : 0);
  22307. bezierCurveTo(xa, ya, xb, yb, x, y);
  22308. }
  22309. break;
  22310. case 31: // hvcurveto
  22311. while (stack.length > 0) {
  22312. xa = x + stack.shift(); ya = y;
  22313. xb = xa + stack.shift(); yb = ya + stack.shift();
  22314. y = yb + stack.shift();
  22315. x = xb + (stack.length === 1 ? stack.shift() : 0);
  22316. bezierCurveTo(xa, ya, xb, yb, x, y);
  22317. if (stack.length === 0) {
  22318. break;
  22319. }
  22320. xa = x; ya = y + stack.shift();
  22321. xb = xa + stack.shift(); yb = ya + stack.shift();
  22322. x = xb + stack.shift();
  22323. y = yb + (stack.length === 1 ? stack.shift() : 0);
  22324. bezierCurveTo(xa, ya, xb, yb, x, y);
  22325. }
  22326. break;
  22327. default:
  22328. if (v < 32) {
  22329. error('unknown operator: ' + v);
  22330. }
  22331. if (v < 247) {
  22332. stack.push(v - 139);
  22333. } else if (v < 251) {
  22334. stack.push((v - 247) * 256 + code[i++] + 108);
  22335. } else if (v < 255) {
  22336. stack.push(-(v - 251) * 256 - code[i++] - 108);
  22337. } else {
  22338. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  22339. (code[i + 2] << 8) | code[i + 3]) / 65536);
  22340. i += 4;
  22341. }
  22342. break;
  22343. }
  22344. if (stackClean) {
  22345. stack.length = 0;
  22346. }
  22347. }
  22348. }
  22349. parse(code);
  22350. }
  22351. var noop = '';
  22352. function CompiledFont(fontMatrix) {
  22353. this.compiledGlyphs = Object.create(null);
  22354. this.fontMatrix = fontMatrix;
  22355. }
  22356. CompiledFont.prototype = {
  22357. getPathJs: function (unicode) {
  22358. var gid = lookupCmap(this.cmap, unicode);
  22359. var fn = this.compiledGlyphs[gid];
  22360. if (!fn) {
  22361. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  22362. }
  22363. return fn;
  22364. },
  22365. compileGlyph: function (code) {
  22366. if (!code || code.length === 0 || code[0] === 14) {
  22367. return noop;
  22368. }
  22369. var cmds = [];
  22370. cmds.push({cmd: 'save'});
  22371. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  22372. cmds.push({cmd: 'scale', args: ['size', '-size']});
  22373. this.compileGlyphImpl(code, cmds);
  22374. cmds.push({cmd: 'restore'});
  22375. return cmds;
  22376. },
  22377. compileGlyphImpl: function () {
  22378. error('Children classes should implement this.');
  22379. },
  22380. hasBuiltPath: function (unicode) {
  22381. var gid = lookupCmap(this.cmap, unicode);
  22382. return gid in this.compiledGlyphs;
  22383. }
  22384. };
  22385. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  22386. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  22387. CompiledFont.call(this, fontMatrix);
  22388. this.glyphs = glyphs;
  22389. this.cmap = cmap;
  22390. this.compiledGlyphs = [];
  22391. }
  22392. Util.inherit(TrueTypeCompiled, CompiledFont, {
  22393. compileGlyphImpl: function (code, cmds) {
  22394. compileGlyf(code, cmds, this);
  22395. }
  22396. });
  22397. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  22398. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  22399. CompiledFont.call(this, fontMatrix);
  22400. this.glyphs = cffInfo.glyphs;
  22401. this.gsubrs = cffInfo.gsubrs || [];
  22402. this.subrs = cffInfo.subrs || [];
  22403. this.cmap = cmap;
  22404. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  22405. this.compiledGlyphs = [];
  22406. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  22407. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  22408. this.subrsBias = (this.subrs.length < 1240 ?
  22409. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  22410. }
  22411. Util.inherit(Type2Compiled, CompiledFont, {
  22412. compileGlyphImpl: function (code, cmds) {
  22413. compileCharString(code, cmds, this);
  22414. }
  22415. });
  22416. return {
  22417. create: function FontRendererFactory_create(font) {
  22418. var data = new Uint8Array(font.data);
  22419. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  22420. var numTables = getUshort(data, 4);
  22421. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  22422. var tag = bytesToString(data.subarray(p, p + 4));
  22423. var offset = getLong(data, p + 8);
  22424. var length = getLong(data, p + 12);
  22425. switch (tag) {
  22426. case 'cmap':
  22427. cmap = parseCmap(data, offset, offset + length);
  22428. break;
  22429. case 'glyf':
  22430. glyf = data.subarray(offset, offset + length);
  22431. break;
  22432. case 'loca':
  22433. loca = data.subarray(offset, offset + length);
  22434. break;
  22435. case 'head':
  22436. unitsPerEm = getUshort(data, offset + 18);
  22437. indexToLocFormat = getUshort(data, offset + 50);
  22438. break;
  22439. case 'CFF ':
  22440. cff = parseCff(data, offset, offset + length);
  22441. break;
  22442. }
  22443. }
  22444. if (glyf) {
  22445. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  22446. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  22447. return new TrueTypeCompiled(
  22448. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  22449. } else {
  22450. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  22451. }
  22452. }
  22453. };
  22454. })();
  22455. // TODO refactor to remove cyclic dependency on fonts.js
  22456. function _setCoreFonts(coreFonts_) {
  22457. coreFonts = coreFonts_;
  22458. CFFParser = coreFonts_.CFFParser;
  22459. }
  22460. exports._setCoreFonts = _setCoreFonts;
  22461. exports.FontRendererFactory = FontRendererFactory;
  22462. }));
  22463. (function (root, factory) {
  22464. {
  22465. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  22466. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  22467. }
  22468. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  22469. var MissingDataException = sharedUtil.MissingDataException;
  22470. var StreamType = sharedUtil.StreamType;
  22471. var assert = sharedUtil.assert;
  22472. var error = sharedUtil.error;
  22473. var info = sharedUtil.info;
  22474. var isArray = sharedUtil.isArray;
  22475. var isInt = sharedUtil.isInt;
  22476. var isNum = sharedUtil.isNum;
  22477. var isString = sharedUtil.isString;
  22478. var warn = sharedUtil.warn;
  22479. var Cmd = corePrimitives.Cmd;
  22480. var Dict = corePrimitives.Dict;
  22481. var Name = corePrimitives.Name;
  22482. var Ref = corePrimitives.Ref;
  22483. var isCmd = corePrimitives.isCmd;
  22484. var isDict = corePrimitives.isDict;
  22485. var isName = corePrimitives.isName;
  22486. var Ascii85Stream = coreStream.Ascii85Stream;
  22487. var AsciiHexStream = coreStream.AsciiHexStream;
  22488. var CCITTFaxStream = coreStream.CCITTFaxStream;
  22489. var FlateStream = coreStream.FlateStream;
  22490. var Jbig2Stream = coreStream.Jbig2Stream;
  22491. var JpegStream = coreStream.JpegStream;
  22492. var JpxStream = coreStream.JpxStream;
  22493. var LZWStream = coreStream.LZWStream;
  22494. var NullStream = coreStream.NullStream;
  22495. var PredictorStream = coreStream.PredictorStream;
  22496. var RunLengthStream = coreStream.RunLengthStream;
  22497. var EOF = {};
  22498. function isEOF(v) {
  22499. return (v === EOF);
  22500. }
  22501. var MAX_LENGTH_TO_CACHE = 1000;
  22502. var Parser = (function ParserClosure() {
  22503. function Parser(lexer, allowStreams, xref) {
  22504. this.lexer = lexer;
  22505. this.allowStreams = allowStreams;
  22506. this.xref = xref;
  22507. this.imageCache = Object.create(null);
  22508. this.refill();
  22509. }
  22510. Parser.prototype = {
  22511. refill: function Parser_refill() {
  22512. this.buf1 = this.lexer.getObj();
  22513. this.buf2 = this.lexer.getObj();
  22514. },
  22515. shift: function Parser_shift() {
  22516. if (isCmd(this.buf2, 'ID')) {
  22517. this.buf1 = this.buf2;
  22518. this.buf2 = null;
  22519. } else {
  22520. this.buf1 = this.buf2;
  22521. this.buf2 = this.lexer.getObj();
  22522. }
  22523. },
  22524. tryShift: function Parser_tryShift() {
  22525. try {
  22526. this.shift();
  22527. return true;
  22528. } catch (e) {
  22529. if (e instanceof MissingDataException) {
  22530. throw e;
  22531. }
  22532. // Upon failure, the caller should reset this.lexer.pos to a known good
  22533. // state and call this.shift() twice to reset the buffers.
  22534. return false;
  22535. }
  22536. },
  22537. getObj: function Parser_getObj(cipherTransform) {
  22538. var buf1 = this.buf1;
  22539. this.shift();
  22540. if (buf1 instanceof Cmd) {
  22541. switch (buf1.cmd) {
  22542. case 'BI': // inline image
  22543. return this.makeInlineImage(cipherTransform);
  22544. case '[': // array
  22545. var array = [];
  22546. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  22547. array.push(this.getObj(cipherTransform));
  22548. }
  22549. if (isEOF(this.buf1)) {
  22550. error('End of file inside array');
  22551. }
  22552. this.shift();
  22553. return array;
  22554. case '<<': // dictionary or stream
  22555. var dict = new Dict(this.xref);
  22556. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  22557. if (!isName(this.buf1)) {
  22558. info('Malformed dictionary: key must be a name object');
  22559. this.shift();
  22560. continue;
  22561. }
  22562. var key = this.buf1.name;
  22563. this.shift();
  22564. if (isEOF(this.buf1)) {
  22565. break;
  22566. }
  22567. dict.set(key, this.getObj(cipherTransform));
  22568. }
  22569. if (isEOF(this.buf1)) {
  22570. error('End of file inside dictionary');
  22571. }
  22572. // Stream objects are not allowed inside content streams or
  22573. // object streams.
  22574. if (isCmd(this.buf2, 'stream')) {
  22575. return (this.allowStreams ?
  22576. this.makeStream(dict, cipherTransform) : dict);
  22577. }
  22578. this.shift();
  22579. return dict;
  22580. default: // simple object
  22581. return buf1;
  22582. }
  22583. }
  22584. if (isInt(buf1)) { // indirect reference or integer
  22585. var num = buf1;
  22586. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  22587. var ref = new Ref(num, this.buf1);
  22588. this.shift();
  22589. this.shift();
  22590. return ref;
  22591. }
  22592. return num;
  22593. }
  22594. if (isString(buf1)) { // string
  22595. var str = buf1;
  22596. if (cipherTransform) {
  22597. str = cipherTransform.decryptString(str);
  22598. }
  22599. return str;
  22600. }
  22601. // simple object
  22602. return buf1;
  22603. },
  22604. /**
  22605. * Find the end of the stream by searching for the /EI\s/.
  22606. * @returns {number} The inline stream length.
  22607. */
  22608. findDefaultInlineStreamEnd:
  22609. function Parser_findDefaultInlineStreamEnd(stream) {
  22610. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  22611. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  22612. while ((ch = stream.getByte()) !== -1) {
  22613. if (state === 0) {
  22614. state = (ch === E) ? 1 : 0;
  22615. } else if (state === 1) {
  22616. state = (ch === I) ? 2 : 0;
  22617. } else {
  22618. assert(state === 2);
  22619. if (ch === SPACE || ch === LF || ch === CR) {
  22620. // Let's check the next five bytes are ASCII... just be sure.
  22621. n = 5;
  22622. followingBytes = stream.peekBytes(n);
  22623. for (i = 0; i < n; i++) {
  22624. ch = followingBytes[i];
  22625. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  22626. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  22627. // it's binary stuff. Resetting the state.
  22628. state = 0;
  22629. break;
  22630. }
  22631. }
  22632. if (state === 2) {
  22633. break; // Finished!
  22634. }
  22635. } else {
  22636. state = 0;
  22637. }
  22638. }
  22639. }
  22640. return ((stream.pos - 4) - startPos);
  22641. },
  22642. /**
  22643. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  22644. * @returns {number} The inline stream length.
  22645. */
  22646. findDCTDecodeInlineStreamEnd:
  22647. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  22648. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  22649. while ((b = stream.getByte()) !== -1) {
  22650. if (b !== 0xFF) { // Not a valid marker.
  22651. continue;
  22652. }
  22653. switch (stream.getByte()) {
  22654. case 0x00: // Byte stuffing.
  22655. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  22656. break;
  22657. case 0xFF: // Fill byte.
  22658. // Avoid skipping a valid marker, resetting the stream position.
  22659. stream.skip(-1);
  22660. break;
  22661. case 0xD9: // EOI
  22662. foundEOI = true;
  22663. break;
  22664. case 0xC0: // SOF0
  22665. case 0xC1: // SOF1
  22666. case 0xC2: // SOF2
  22667. case 0xC3: // SOF3
  22668. case 0xC5: // SOF5
  22669. case 0xC6: // SOF6
  22670. case 0xC7: // SOF7
  22671. case 0xC9: // SOF9
  22672. case 0xCA: // SOF10
  22673. case 0xCB: // SOF11
  22674. case 0xCD: // SOF13
  22675. case 0xCE: // SOF14
  22676. case 0xCF: // SOF15
  22677. case 0xC4: // DHT
  22678. case 0xCC: // DAC
  22679. case 0xDA: // SOS
  22680. case 0xDB: // DQT
  22681. case 0xDC: // DNL
  22682. case 0xDD: // DRI
  22683. case 0xDE: // DHP
  22684. case 0xDF: // EXP
  22685. case 0xE0: // APP0
  22686. case 0xE1: // APP1
  22687. case 0xE2: // APP2
  22688. case 0xE3: // APP3
  22689. case 0xE4: // APP4
  22690. case 0xE5: // APP5
  22691. case 0xE6: // APP6
  22692. case 0xE7: // APP7
  22693. case 0xE8: // APP8
  22694. case 0xE9: // APP9
  22695. case 0xEA: // APP10
  22696. case 0xEB: // APP11
  22697. case 0xEC: // APP12
  22698. case 0xED: // APP13
  22699. case 0xEE: // APP14
  22700. case 0xEF: // APP15
  22701. case 0xFE: // COM
  22702. // The marker should be followed by the length of the segment.
  22703. markerLength = stream.getUint16();
  22704. if (markerLength > 2) {
  22705. // |markerLength| contains the byte length of the marker segment,
  22706. // including its own length (2 bytes) and excluding the marker.
  22707. stream.skip(markerLength - 2); // Jump to the next marker.
  22708. } else {
  22709. // The marker length is invalid, resetting the stream position.
  22710. stream.skip(-2);
  22711. }
  22712. break;
  22713. }
  22714. if (foundEOI) {
  22715. break;
  22716. }
  22717. }
  22718. length = stream.pos - startPos;
  22719. if (b === -1) {
  22720. warn('Inline DCTDecode image stream: ' +
  22721. 'EOI marker not found, searching for /EI/ instead.');
  22722. stream.skip(-length); // Reset the stream position.
  22723. return this.findDefaultInlineStreamEnd(stream);
  22724. }
  22725. this.inlineStreamSkipEI(stream);
  22726. return length;
  22727. },
  22728. /**
  22729. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  22730. * @returns {number} The inline stream length.
  22731. */
  22732. findASCII85DecodeInlineStreamEnd:
  22733. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  22734. var TILDE = 0x7E, GT = 0x3E;
  22735. var startPos = stream.pos, ch, length;
  22736. while ((ch = stream.getByte()) !== -1) {
  22737. if (ch === TILDE && stream.peekByte() === GT) {
  22738. stream.skip();
  22739. break;
  22740. }
  22741. }
  22742. length = stream.pos - startPos;
  22743. if (ch === -1) {
  22744. warn('Inline ASCII85Decode image stream: ' +
  22745. 'EOD marker not found, searching for /EI/ instead.');
  22746. stream.skip(-length); // Reset the stream position.
  22747. return this.findDefaultInlineStreamEnd(stream);
  22748. }
  22749. this.inlineStreamSkipEI(stream);
  22750. return length;
  22751. },
  22752. /**
  22753. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  22754. * @returns {number} The inline stream length.
  22755. */
  22756. findASCIIHexDecodeInlineStreamEnd:
  22757. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  22758. var GT = 0x3E;
  22759. var startPos = stream.pos, ch, length;
  22760. while ((ch = stream.getByte()) !== -1) {
  22761. if (ch === GT) {
  22762. break;
  22763. }
  22764. }
  22765. length = stream.pos - startPos;
  22766. if (ch === -1) {
  22767. warn('Inline ASCIIHexDecode image stream: ' +
  22768. 'EOD marker not found, searching for /EI/ instead.');
  22769. stream.skip(-length); // Reset the stream position.
  22770. return this.findDefaultInlineStreamEnd(stream);
  22771. }
  22772. this.inlineStreamSkipEI(stream);
  22773. return length;
  22774. },
  22775. /**
  22776. * Skip over the /EI/ for streams where we search for an EOD marker.
  22777. */
  22778. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  22779. var E = 0x45, I = 0x49;
  22780. var state = 0, ch;
  22781. while ((ch = stream.getByte()) !== -1) {
  22782. if (state === 0) {
  22783. state = (ch === E) ? 1 : 0;
  22784. } else if (state === 1) {
  22785. state = (ch === I) ? 2 : 0;
  22786. } else if (state === 2) {
  22787. break;
  22788. }
  22789. }
  22790. },
  22791. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  22792. var lexer = this.lexer;
  22793. var stream = lexer.stream;
  22794. // Parse dictionary.
  22795. var dict = new Dict(this.xref);
  22796. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  22797. if (!isName(this.buf1)) {
  22798. error('Dictionary key must be a name object');
  22799. }
  22800. var key = this.buf1.name;
  22801. this.shift();
  22802. if (isEOF(this.buf1)) {
  22803. break;
  22804. }
  22805. dict.set(key, this.getObj(cipherTransform));
  22806. }
  22807. // Extract the name of the first (i.e. the current) image filter.
  22808. var filter = dict.get('Filter', 'F'), filterName;
  22809. if (isName(filter)) {
  22810. filterName = filter.name;
  22811. } else if (isArray(filter) && isName(filter[0])) {
  22812. filterName = filter[0].name;
  22813. }
  22814. // Parse image stream.
  22815. var startPos = stream.pos, length, i, ii;
  22816. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  22817. length = this.findDCTDecodeInlineStreamEnd(stream);
  22818. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  22819. length = this.findASCII85DecodeInlineStreamEnd(stream);
  22820. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  22821. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  22822. } else {
  22823. length = this.findDefaultInlineStreamEnd(stream);
  22824. }
  22825. var imageStream = stream.makeSubStream(startPos, length, dict);
  22826. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  22827. // adler32 checksum.
  22828. var adler32;
  22829. if (length < MAX_LENGTH_TO_CACHE) {
  22830. var imageBytes = imageStream.getBytes();
  22831. imageStream.reset();
  22832. var a = 1;
  22833. var b = 0;
  22834. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  22835. // No modulo required in the loop if imageBytes.length < 5552.
  22836. a += imageBytes[i] & 0xff;
  22837. b += a;
  22838. }
  22839. adler32 = ((b % 65521) << 16) | (a % 65521);
  22840. if (this.imageCache.adler32 === adler32) {
  22841. this.buf2 = Cmd.get('EI');
  22842. this.shift();
  22843. this.imageCache[adler32].reset();
  22844. return this.imageCache[adler32];
  22845. }
  22846. }
  22847. if (cipherTransform) {
  22848. imageStream = cipherTransform.createStream(imageStream, length);
  22849. }
  22850. imageStream = this.filter(imageStream, dict, length);
  22851. imageStream.dict = dict;
  22852. if (adler32 !== undefined) {
  22853. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  22854. this.imageCache[adler32] = imageStream;
  22855. }
  22856. this.buf2 = Cmd.get('EI');
  22857. this.shift();
  22858. return imageStream;
  22859. },
  22860. makeStream: function Parser_makeStream(dict, cipherTransform) {
  22861. var lexer = this.lexer;
  22862. var stream = lexer.stream;
  22863. // get stream start position
  22864. lexer.skipToNextLine();
  22865. var pos = stream.pos - 1;
  22866. // get length
  22867. var length = dict.get('Length');
  22868. if (!isInt(length)) {
  22869. info('Bad ' + length + ' attribute in stream');
  22870. length = 0;
  22871. }
  22872. // skip over the stream data
  22873. stream.pos = pos + length;
  22874. lexer.nextChar();
  22875. // Shift '>>' and check whether the new object marks the end of the stream
  22876. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  22877. this.shift(); // 'stream'
  22878. } else {
  22879. // bad stream length, scanning for endstream
  22880. stream.pos = pos;
  22881. var SCAN_BLOCK_SIZE = 2048;
  22882. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  22883. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  22884. 0x61, 0x6D];
  22885. var skipped = 0, found = false, i, j;
  22886. while (stream.pos < stream.end) {
  22887. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  22888. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  22889. if (scanLength <= 0) {
  22890. break;
  22891. }
  22892. found = false;
  22893. i = 0;
  22894. while (i < scanLength) {
  22895. j = 0;
  22896. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  22897. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  22898. j++;
  22899. }
  22900. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  22901. found = true;
  22902. break;
  22903. }
  22904. i++;
  22905. }
  22906. if (found) {
  22907. skipped += i;
  22908. stream.pos += i;
  22909. break;
  22910. }
  22911. skipped += scanLength;
  22912. stream.pos += scanLength;
  22913. }
  22914. if (!found) {
  22915. error('Missing endstream');
  22916. }
  22917. length = skipped;
  22918. lexer.nextChar();
  22919. this.shift();
  22920. this.shift();
  22921. }
  22922. this.shift(); // 'endstream'
  22923. stream = stream.makeSubStream(pos, length, dict);
  22924. if (cipherTransform) {
  22925. stream = cipherTransform.createStream(stream, length);
  22926. }
  22927. stream = this.filter(stream, dict, length);
  22928. stream.dict = dict;
  22929. return stream;
  22930. },
  22931. filter: function Parser_filter(stream, dict, length) {
  22932. var filter = dict.get('Filter', 'F');
  22933. var params = dict.get('DecodeParms', 'DP');
  22934. if (isName(filter)) {
  22935. return this.makeFilter(stream, filter.name, length, params);
  22936. }
  22937. var maybeLength = length;
  22938. if (isArray(filter)) {
  22939. var filterArray = filter;
  22940. var paramsArray = params;
  22941. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  22942. filter = filterArray[i];
  22943. if (!isName(filter)) {
  22944. error('Bad filter name: ' + filter);
  22945. }
  22946. params = null;
  22947. if (isArray(paramsArray) && (i in paramsArray)) {
  22948. params = paramsArray[i];
  22949. }
  22950. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  22951. // after the first stream the length variable is invalid
  22952. maybeLength = null;
  22953. }
  22954. }
  22955. return stream;
  22956. },
  22957. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  22958. if (stream.dict.get('Length') === 0 && !maybeLength) {
  22959. warn('Empty "' + name + '" stream.');
  22960. return new NullStream(stream);
  22961. }
  22962. try {
  22963. if (params && this.xref) {
  22964. params = this.xref.fetchIfRef(params);
  22965. }
  22966. var xrefStreamStats = this.xref.stats.streamTypes;
  22967. if (name === 'FlateDecode' || name === 'Fl') {
  22968. xrefStreamStats[StreamType.FLATE] = true;
  22969. if (params) {
  22970. return new PredictorStream(new FlateStream(stream, maybeLength),
  22971. maybeLength, params);
  22972. }
  22973. return new FlateStream(stream, maybeLength);
  22974. }
  22975. if (name === 'LZWDecode' || name === 'LZW') {
  22976. xrefStreamStats[StreamType.LZW] = true;
  22977. var earlyChange = 1;
  22978. if (params) {
  22979. if (params.has('EarlyChange')) {
  22980. earlyChange = params.get('EarlyChange');
  22981. }
  22982. return new PredictorStream(
  22983. new LZWStream(stream, maybeLength, earlyChange),
  22984. maybeLength, params);
  22985. }
  22986. return new LZWStream(stream, maybeLength, earlyChange);
  22987. }
  22988. if (name === 'DCTDecode' || name === 'DCT') {
  22989. xrefStreamStats[StreamType.DCT] = true;
  22990. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  22991. }
  22992. if (name === 'JPXDecode' || name === 'JPX') {
  22993. xrefStreamStats[StreamType.JPX] = true;
  22994. return new JpxStream(stream, maybeLength, stream.dict);
  22995. }
  22996. if (name === 'ASCII85Decode' || name === 'A85') {
  22997. xrefStreamStats[StreamType.A85] = true;
  22998. return new Ascii85Stream(stream, maybeLength);
  22999. }
  23000. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  23001. xrefStreamStats[StreamType.AHX] = true;
  23002. return new AsciiHexStream(stream, maybeLength);
  23003. }
  23004. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  23005. xrefStreamStats[StreamType.CCF] = true;
  23006. return new CCITTFaxStream(stream, maybeLength, params);
  23007. }
  23008. if (name === 'RunLengthDecode' || name === 'RL') {
  23009. xrefStreamStats[StreamType.RL] = true;
  23010. return new RunLengthStream(stream, maybeLength);
  23011. }
  23012. if (name === 'JBIG2Decode') {
  23013. xrefStreamStats[StreamType.JBIG] = true;
  23014. return new Jbig2Stream(stream, maybeLength, stream.dict);
  23015. }
  23016. warn('filter "' + name + '" not supported yet');
  23017. return stream;
  23018. } catch (ex) {
  23019. if (ex instanceof MissingDataException) {
  23020. throw ex;
  23021. }
  23022. warn('Invalid stream: \"' + ex + '\"');
  23023. return new NullStream(stream);
  23024. }
  23025. }
  23026. };
  23027. return Parser;
  23028. })();
  23029. var Lexer = (function LexerClosure() {
  23030. function Lexer(stream, knownCommands) {
  23031. this.stream = stream;
  23032. this.nextChar();
  23033. // While lexing, we build up many strings one char at a time. Using += for
  23034. // this can result in lots of garbage strings. It's better to build an
  23035. // array of single-char strings and then join() them together at the end.
  23036. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  23037. // purpose uses less memory than using a new array for each string.
  23038. this.strBuf = [];
  23039. // The PDFs might have "glued" commands with other commands, operands or
  23040. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  23041. // commands and their prefixes. The prefixes are built the following way:
  23042. // if there a command that is a prefix of the other valid command or
  23043. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  23044. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  23045. // other commands or literals as a prefix. The knowCommands is optional.
  23046. this.knownCommands = knownCommands;
  23047. }
  23048. Lexer.isSpace = function Lexer_isSpace(ch) {
  23049. // Space is one of the following characters: SPACE, TAB, CR or LF.
  23050. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  23051. };
  23052. // A '1' in this array means the character is white space. A '1' or
  23053. // '2' means the character ends a name or command.
  23054. var specialChars = [
  23055. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  23056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  23057. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  23058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  23059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  23060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  23061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  23062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  23063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  23064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  23065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  23066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  23067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  23068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  23069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  23070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  23071. ];
  23072. function toHexDigit(ch) {
  23073. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  23074. return ch & 0x0F;
  23075. }
  23076. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  23077. // 'A'-'F', 'a'-'f'
  23078. return (ch & 0x0F) + 9;
  23079. }
  23080. return -1;
  23081. }
  23082. Lexer.prototype = {
  23083. nextChar: function Lexer_nextChar() {
  23084. return (this.currentChar = this.stream.getByte());
  23085. },
  23086. peekChar: function Lexer_peekChar() {
  23087. return this.stream.peekByte();
  23088. },
  23089. getNumber: function Lexer_getNumber() {
  23090. var ch = this.currentChar;
  23091. var eNotation = false;
  23092. var divideBy = 0; // different from 0 if it's a floating point value
  23093. var sign = 1;
  23094. if (ch === 0x2D) { // '-'
  23095. sign = -1;
  23096. ch = this.nextChar();
  23097. if (ch === 0x2D) { // '-'
  23098. // Ignore double negative (this is consistent with Adobe Reader).
  23099. ch = this.nextChar();
  23100. }
  23101. } else if (ch === 0x2B) { // '+'
  23102. ch = this.nextChar();
  23103. }
  23104. if (ch === 0x2E) { // '.'
  23105. divideBy = 10;
  23106. ch = this.nextChar();
  23107. }
  23108. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  23109. error('Invalid number: ' + String.fromCharCode(ch));
  23110. return 0;
  23111. }
  23112. var baseValue = ch - 0x30; // '0'
  23113. var powerValue = 0;
  23114. var powerValueSign = 1;
  23115. while ((ch = this.nextChar()) >= 0) {
  23116. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  23117. var currentDigit = ch - 0x30; // '0'
  23118. if (eNotation) { // We are after an 'e' or 'E'
  23119. powerValue = powerValue * 10 + currentDigit;
  23120. } else {
  23121. if (divideBy !== 0) { // We are after a point
  23122. divideBy *= 10;
  23123. }
  23124. baseValue = baseValue * 10 + currentDigit;
  23125. }
  23126. } else if (ch === 0x2E) { // '.'
  23127. if (divideBy === 0) {
  23128. divideBy = 1;
  23129. } else {
  23130. // A number can have only one '.'
  23131. break;
  23132. }
  23133. } else if (ch === 0x2D) { // '-'
  23134. // ignore minus signs in the middle of numbers to match
  23135. // Adobe's behavior
  23136. warn('Badly formated number');
  23137. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  23138. // 'E' can be either a scientific notation or the beginning of a new
  23139. // operator
  23140. ch = this.peekChar();
  23141. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  23142. powerValueSign = (ch === 0x2D) ? -1 : 1;
  23143. this.nextChar(); // Consume the sign character
  23144. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  23145. // The 'E' must be the beginning of a new operator
  23146. break;
  23147. }
  23148. eNotation = true;
  23149. } else {
  23150. // the last character doesn't belong to us
  23151. break;
  23152. }
  23153. }
  23154. if (divideBy !== 0) {
  23155. baseValue /= divideBy;
  23156. }
  23157. if (eNotation) {
  23158. baseValue *= Math.pow(10, powerValueSign * powerValue);
  23159. }
  23160. return sign * baseValue;
  23161. },
  23162. getString: function Lexer_getString() {
  23163. var numParen = 1;
  23164. var done = false;
  23165. var strBuf = this.strBuf;
  23166. strBuf.length = 0;
  23167. var ch = this.nextChar();
  23168. while (true) {
  23169. var charBuffered = false;
  23170. switch (ch | 0) {
  23171. case -1:
  23172. warn('Unterminated string');
  23173. done = true;
  23174. break;
  23175. case 0x28: // '('
  23176. ++numParen;
  23177. strBuf.push('(');
  23178. break;
  23179. case 0x29: // ')'
  23180. if (--numParen === 0) {
  23181. this.nextChar(); // consume strings ')'
  23182. done = true;
  23183. } else {
  23184. strBuf.push(')');
  23185. }
  23186. break;
  23187. case 0x5C: // '\\'
  23188. ch = this.nextChar();
  23189. switch (ch) {
  23190. case -1:
  23191. warn('Unterminated string');
  23192. done = true;
  23193. break;
  23194. case 0x6E: // 'n'
  23195. strBuf.push('\n');
  23196. break;
  23197. case 0x72: // 'r'
  23198. strBuf.push('\r');
  23199. break;
  23200. case 0x74: // 't'
  23201. strBuf.push('\t');
  23202. break;
  23203. case 0x62: // 'b'
  23204. strBuf.push('\b');
  23205. break;
  23206. case 0x66: // 'f'
  23207. strBuf.push('\f');
  23208. break;
  23209. case 0x5C: // '\'
  23210. case 0x28: // '('
  23211. case 0x29: // ')'
  23212. strBuf.push(String.fromCharCode(ch));
  23213. break;
  23214. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  23215. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  23216. var x = ch & 0x0F;
  23217. ch = this.nextChar();
  23218. charBuffered = true;
  23219. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  23220. x = (x << 3) + (ch & 0x0F);
  23221. ch = this.nextChar();
  23222. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  23223. charBuffered = false;
  23224. x = (x << 3) + (ch & 0x0F);
  23225. }
  23226. }
  23227. strBuf.push(String.fromCharCode(x));
  23228. break;
  23229. case 0x0D: // CR
  23230. if (this.peekChar() === 0x0A) { // LF
  23231. this.nextChar();
  23232. }
  23233. break;
  23234. case 0x0A: // LF
  23235. break;
  23236. default:
  23237. strBuf.push(String.fromCharCode(ch));
  23238. break;
  23239. }
  23240. break;
  23241. default:
  23242. strBuf.push(String.fromCharCode(ch));
  23243. break;
  23244. }
  23245. if (done) {
  23246. break;
  23247. }
  23248. if (!charBuffered) {
  23249. ch = this.nextChar();
  23250. }
  23251. }
  23252. return strBuf.join('');
  23253. },
  23254. getName: function Lexer_getName() {
  23255. var ch, previousCh;
  23256. var strBuf = this.strBuf;
  23257. strBuf.length = 0;
  23258. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  23259. if (ch === 0x23) { // '#'
  23260. ch = this.nextChar();
  23261. if (specialChars[ch]) {
  23262. warn('Lexer_getName: ' +
  23263. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  23264. strBuf.push('#');
  23265. break;
  23266. }
  23267. var x = toHexDigit(ch);
  23268. if (x !== -1) {
  23269. previousCh = ch;
  23270. ch = this.nextChar();
  23271. var x2 = toHexDigit(ch);
  23272. if (x2 === -1) {
  23273. warn('Lexer_getName: Illegal digit (' +
  23274. String.fromCharCode(ch) +') in hexadecimal number.');
  23275. strBuf.push('#', String.fromCharCode(previousCh));
  23276. if (specialChars[ch]) {
  23277. break;
  23278. }
  23279. strBuf.push(String.fromCharCode(ch));
  23280. continue;
  23281. }
  23282. strBuf.push(String.fromCharCode((x << 4) | x2));
  23283. } else {
  23284. strBuf.push('#', String.fromCharCode(ch));
  23285. }
  23286. } else {
  23287. strBuf.push(String.fromCharCode(ch));
  23288. }
  23289. }
  23290. if (strBuf.length > 127) {
  23291. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  23292. }
  23293. return Name.get(strBuf.join(''));
  23294. },
  23295. getHexString: function Lexer_getHexString() {
  23296. var strBuf = this.strBuf;
  23297. strBuf.length = 0;
  23298. var ch = this.currentChar;
  23299. var isFirstHex = true;
  23300. var firstDigit;
  23301. var secondDigit;
  23302. while (true) {
  23303. if (ch < 0) {
  23304. warn('Unterminated hex string');
  23305. break;
  23306. } else if (ch === 0x3E) { // '>'
  23307. this.nextChar();
  23308. break;
  23309. } else if (specialChars[ch] === 1) {
  23310. ch = this.nextChar();
  23311. continue;
  23312. } else {
  23313. if (isFirstHex) {
  23314. firstDigit = toHexDigit(ch);
  23315. if (firstDigit === -1) {
  23316. warn('Ignoring invalid character "' + ch + '" in hex string');
  23317. ch = this.nextChar();
  23318. continue;
  23319. }
  23320. } else {
  23321. secondDigit = toHexDigit(ch);
  23322. if (secondDigit === -1) {
  23323. warn('Ignoring invalid character "' + ch + '" in hex string');
  23324. ch = this.nextChar();
  23325. continue;
  23326. }
  23327. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  23328. }
  23329. isFirstHex = !isFirstHex;
  23330. ch = this.nextChar();
  23331. }
  23332. }
  23333. return strBuf.join('');
  23334. },
  23335. getObj: function Lexer_getObj() {
  23336. // skip whitespace and comments
  23337. var comment = false;
  23338. var ch = this.currentChar;
  23339. while (true) {
  23340. if (ch < 0) {
  23341. return EOF;
  23342. }
  23343. if (comment) {
  23344. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  23345. comment = false;
  23346. }
  23347. } else if (ch === 0x25) { // '%'
  23348. comment = true;
  23349. } else if (specialChars[ch] !== 1) {
  23350. break;
  23351. }
  23352. ch = this.nextChar();
  23353. }
  23354. // start reading token
  23355. switch (ch | 0) {
  23356. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  23357. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  23358. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  23359. return this.getNumber();
  23360. case 0x28: // '('
  23361. return this.getString();
  23362. case 0x2F: // '/'
  23363. return this.getName();
  23364. // array punctuation
  23365. case 0x5B: // '['
  23366. this.nextChar();
  23367. return Cmd.get('[');
  23368. case 0x5D: // ']'
  23369. this.nextChar();
  23370. return Cmd.get(']');
  23371. // hex string or dict punctuation
  23372. case 0x3C: // '<'
  23373. ch = this.nextChar();
  23374. if (ch === 0x3C) {
  23375. // dict punctuation
  23376. this.nextChar();
  23377. return Cmd.get('<<');
  23378. }
  23379. return this.getHexString();
  23380. // dict punctuation
  23381. case 0x3E: // '>'
  23382. ch = this.nextChar();
  23383. if (ch === 0x3E) {
  23384. this.nextChar();
  23385. return Cmd.get('>>');
  23386. }
  23387. return Cmd.get('>');
  23388. case 0x7B: // '{'
  23389. this.nextChar();
  23390. return Cmd.get('{');
  23391. case 0x7D: // '}'
  23392. this.nextChar();
  23393. return Cmd.get('}');
  23394. case 0x29: // ')'
  23395. error('Illegal character: ' + ch);
  23396. break;
  23397. }
  23398. // command
  23399. var str = String.fromCharCode(ch);
  23400. var knownCommands = this.knownCommands;
  23401. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  23402. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  23403. // stop if known command is found and next character does not make
  23404. // the str a command
  23405. var possibleCommand = str + String.fromCharCode(ch);
  23406. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  23407. break;
  23408. }
  23409. if (str.length === 128) {
  23410. error('Command token too long: ' + str.length);
  23411. }
  23412. str = possibleCommand;
  23413. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  23414. }
  23415. if (str === 'true') {
  23416. return true;
  23417. }
  23418. if (str === 'false') {
  23419. return false;
  23420. }
  23421. if (str === 'null') {
  23422. return null;
  23423. }
  23424. return Cmd.get(str);
  23425. },
  23426. skipToNextLine: function Lexer_skipToNextLine() {
  23427. var ch = this.currentChar;
  23428. while (ch >= 0) {
  23429. if (ch === 0x0D) { // CR
  23430. ch = this.nextChar();
  23431. if (ch === 0x0A) { // LF
  23432. this.nextChar();
  23433. }
  23434. break;
  23435. } else if (ch === 0x0A) { // LF
  23436. this.nextChar();
  23437. break;
  23438. }
  23439. ch = this.nextChar();
  23440. }
  23441. }
  23442. };
  23443. return Lexer;
  23444. })();
  23445. var Linearization = {
  23446. create: function LinearizationCreate(stream) {
  23447. function getInt(name, allowZeroValue) {
  23448. var obj = linDict.get(name);
  23449. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  23450. return obj;
  23451. }
  23452. throw new Error('The "' + name + '" parameter in the linearization ' +
  23453. 'dictionary is invalid.');
  23454. }
  23455. function getHints() {
  23456. var hints = linDict.get('H'), hintsLength, item;
  23457. if (isArray(hints) &&
  23458. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  23459. for (var index = 0; index < hintsLength; index++) {
  23460. if (!(isInt(item = hints[index]) && item > 0)) {
  23461. throw new Error('Hint (' + index +
  23462. ') in the linearization dictionary is invalid.');
  23463. }
  23464. }
  23465. return hints;
  23466. }
  23467. throw new Error('Hint array in the linearization dictionary is invalid.');
  23468. }
  23469. var parser = new Parser(new Lexer(stream), false, null);
  23470. var obj1 = parser.getObj();
  23471. var obj2 = parser.getObj();
  23472. var obj3 = parser.getObj();
  23473. var linDict = parser.getObj();
  23474. var obj, length;
  23475. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  23476. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  23477. return null; // No valid linearization dictionary found.
  23478. } else if ((length = getInt('L')) !== stream.length) {
  23479. throw new Error('The "L" parameter in the linearization dictionary ' +
  23480. 'does not equal the stream length.');
  23481. }
  23482. return {
  23483. length: length,
  23484. hints: getHints(),
  23485. objectNumberFirst: getInt('O'),
  23486. endFirst: getInt('E'),
  23487. numPages: getInt('N'),
  23488. mainXRefEntriesOffset: getInt('T'),
  23489. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  23490. };
  23491. }
  23492. };
  23493. exports.EOF = EOF;
  23494. exports.Lexer = Lexer;
  23495. exports.Linearization = Linearization;
  23496. exports.Parser = Parser;
  23497. exports.isEOF = isEOF;
  23498. // TODO refactor to remove dependency on stream.js
  23499. coreStream._setCoreParser(exports);
  23500. }));
  23501. (function (root, factory) {
  23502. {
  23503. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  23504. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  23505. }
  23506. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  23507. var Util = sharedUtil.Util;
  23508. var assert = sharedUtil.assert;
  23509. var error = sharedUtil.error;
  23510. var isInt = sharedUtil.isInt;
  23511. var isString = sharedUtil.isString;
  23512. var warn = sharedUtil.warn;
  23513. var isName = corePrimitives.isName;
  23514. var isCmd = corePrimitives.isCmd;
  23515. var isStream = corePrimitives.isStream;
  23516. var StringStream = coreStream.StringStream;
  23517. var Lexer = coreParser.Lexer;
  23518. var isEOF = coreParser.isEOF;
  23519. var BUILT_IN_CMAPS = [
  23520. // << Start unicode maps.
  23521. 'Adobe-GB1-UCS2',
  23522. 'Adobe-CNS1-UCS2',
  23523. 'Adobe-Japan1-UCS2',
  23524. 'Adobe-Korea1-UCS2',
  23525. // >> End unicode maps.
  23526. '78-EUC-H',
  23527. '78-EUC-V',
  23528. '78-H',
  23529. '78-RKSJ-H',
  23530. '78-RKSJ-V',
  23531. '78-V',
  23532. '78ms-RKSJ-H',
  23533. '78ms-RKSJ-V',
  23534. '83pv-RKSJ-H',
  23535. '90ms-RKSJ-H',
  23536. '90ms-RKSJ-V',
  23537. '90msp-RKSJ-H',
  23538. '90msp-RKSJ-V',
  23539. '90pv-RKSJ-H',
  23540. '90pv-RKSJ-V',
  23541. 'Add-H',
  23542. 'Add-RKSJ-H',
  23543. 'Add-RKSJ-V',
  23544. 'Add-V',
  23545. 'Adobe-CNS1-0',
  23546. 'Adobe-CNS1-1',
  23547. 'Adobe-CNS1-2',
  23548. 'Adobe-CNS1-3',
  23549. 'Adobe-CNS1-4',
  23550. 'Adobe-CNS1-5',
  23551. 'Adobe-CNS1-6',
  23552. 'Adobe-GB1-0',
  23553. 'Adobe-GB1-1',
  23554. 'Adobe-GB1-2',
  23555. 'Adobe-GB1-3',
  23556. 'Adobe-GB1-4',
  23557. 'Adobe-GB1-5',
  23558. 'Adobe-Japan1-0',
  23559. 'Adobe-Japan1-1',
  23560. 'Adobe-Japan1-2',
  23561. 'Adobe-Japan1-3',
  23562. 'Adobe-Japan1-4',
  23563. 'Adobe-Japan1-5',
  23564. 'Adobe-Japan1-6',
  23565. 'Adobe-Korea1-0',
  23566. 'Adobe-Korea1-1',
  23567. 'Adobe-Korea1-2',
  23568. 'B5-H',
  23569. 'B5-V',
  23570. 'B5pc-H',
  23571. 'B5pc-V',
  23572. 'CNS-EUC-H',
  23573. 'CNS-EUC-V',
  23574. 'CNS1-H',
  23575. 'CNS1-V',
  23576. 'CNS2-H',
  23577. 'CNS2-V',
  23578. 'ETHK-B5-H',
  23579. 'ETHK-B5-V',
  23580. 'ETen-B5-H',
  23581. 'ETen-B5-V',
  23582. 'ETenms-B5-H',
  23583. 'ETenms-B5-V',
  23584. 'EUC-H',
  23585. 'EUC-V',
  23586. 'Ext-H',
  23587. 'Ext-RKSJ-H',
  23588. 'Ext-RKSJ-V',
  23589. 'Ext-V',
  23590. 'GB-EUC-H',
  23591. 'GB-EUC-V',
  23592. 'GB-H',
  23593. 'GB-V',
  23594. 'GBK-EUC-H',
  23595. 'GBK-EUC-V',
  23596. 'GBK2K-H',
  23597. 'GBK2K-V',
  23598. 'GBKp-EUC-H',
  23599. 'GBKp-EUC-V',
  23600. 'GBT-EUC-H',
  23601. 'GBT-EUC-V',
  23602. 'GBT-H',
  23603. 'GBT-V',
  23604. 'GBTpc-EUC-H',
  23605. 'GBTpc-EUC-V',
  23606. 'GBpc-EUC-H',
  23607. 'GBpc-EUC-V',
  23608. 'H',
  23609. 'HKdla-B5-H',
  23610. 'HKdla-B5-V',
  23611. 'HKdlb-B5-H',
  23612. 'HKdlb-B5-V',
  23613. 'HKgccs-B5-H',
  23614. 'HKgccs-B5-V',
  23615. 'HKm314-B5-H',
  23616. 'HKm314-B5-V',
  23617. 'HKm471-B5-H',
  23618. 'HKm471-B5-V',
  23619. 'HKscs-B5-H',
  23620. 'HKscs-B5-V',
  23621. 'Hankaku',
  23622. 'Hiragana',
  23623. 'KSC-EUC-H',
  23624. 'KSC-EUC-V',
  23625. 'KSC-H',
  23626. 'KSC-Johab-H',
  23627. 'KSC-Johab-V',
  23628. 'KSC-V',
  23629. 'KSCms-UHC-H',
  23630. 'KSCms-UHC-HW-H',
  23631. 'KSCms-UHC-HW-V',
  23632. 'KSCms-UHC-V',
  23633. 'KSCpc-EUC-H',
  23634. 'KSCpc-EUC-V',
  23635. 'Katakana',
  23636. 'NWP-H',
  23637. 'NWP-V',
  23638. 'RKSJ-H',
  23639. 'RKSJ-V',
  23640. 'Roman',
  23641. 'UniCNS-UCS2-H',
  23642. 'UniCNS-UCS2-V',
  23643. 'UniCNS-UTF16-H',
  23644. 'UniCNS-UTF16-V',
  23645. 'UniCNS-UTF32-H',
  23646. 'UniCNS-UTF32-V',
  23647. 'UniCNS-UTF8-H',
  23648. 'UniCNS-UTF8-V',
  23649. 'UniGB-UCS2-H',
  23650. 'UniGB-UCS2-V',
  23651. 'UniGB-UTF16-H',
  23652. 'UniGB-UTF16-V',
  23653. 'UniGB-UTF32-H',
  23654. 'UniGB-UTF32-V',
  23655. 'UniGB-UTF8-H',
  23656. 'UniGB-UTF8-V',
  23657. 'UniJIS-UCS2-H',
  23658. 'UniJIS-UCS2-HW-H',
  23659. 'UniJIS-UCS2-HW-V',
  23660. 'UniJIS-UCS2-V',
  23661. 'UniJIS-UTF16-H',
  23662. 'UniJIS-UTF16-V',
  23663. 'UniJIS-UTF32-H',
  23664. 'UniJIS-UTF32-V',
  23665. 'UniJIS-UTF8-H',
  23666. 'UniJIS-UTF8-V',
  23667. 'UniJIS2004-UTF16-H',
  23668. 'UniJIS2004-UTF16-V',
  23669. 'UniJIS2004-UTF32-H',
  23670. 'UniJIS2004-UTF32-V',
  23671. 'UniJIS2004-UTF8-H',
  23672. 'UniJIS2004-UTF8-V',
  23673. 'UniJISPro-UCS2-HW-V',
  23674. 'UniJISPro-UCS2-V',
  23675. 'UniJISPro-UTF8-V',
  23676. 'UniJISX0213-UTF32-H',
  23677. 'UniJISX0213-UTF32-V',
  23678. 'UniJISX02132004-UTF32-H',
  23679. 'UniJISX02132004-UTF32-V',
  23680. 'UniKS-UCS2-H',
  23681. 'UniKS-UCS2-V',
  23682. 'UniKS-UTF16-H',
  23683. 'UniKS-UTF16-V',
  23684. 'UniKS-UTF32-H',
  23685. 'UniKS-UTF32-V',
  23686. 'UniKS-UTF8-H',
  23687. 'UniKS-UTF8-V',
  23688. 'V',
  23689. 'WP-Symbol'];
  23690. // CMap, not to be confused with TrueType's cmap.
  23691. var CMap = (function CMapClosure() {
  23692. function CMap(builtInCMap) {
  23693. // Codespace ranges are stored as follows:
  23694. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  23695. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  23696. this.codespaceRanges = [[], [], [], []];
  23697. this.numCodespaceRanges = 0;
  23698. // Map entries have one of two forms.
  23699. // - cid chars are 16-bit unsigned integers, stored as integers.
  23700. // - bf chars are variable-length byte sequences, stored as strings, with
  23701. // one byte per character.
  23702. this._map = [];
  23703. this.name = '';
  23704. this.vertical = false;
  23705. this.useCMap = null;
  23706. this.builtInCMap = builtInCMap;
  23707. }
  23708. CMap.prototype = {
  23709. addCodespaceRange: function(n, low, high) {
  23710. this.codespaceRanges[n - 1].push(low, high);
  23711. this.numCodespaceRanges++;
  23712. },
  23713. mapCidRange: function(low, high, dstLow) {
  23714. while (low <= high) {
  23715. this._map[low++] = dstLow++;
  23716. }
  23717. },
  23718. mapBfRange: function(low, high, dstLow) {
  23719. var lastByte = dstLow.length - 1;
  23720. while (low <= high) {
  23721. this._map[low++] = dstLow;
  23722. // Only the last byte has to be incremented.
  23723. dstLow = dstLow.substr(0, lastByte) +
  23724. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  23725. }
  23726. },
  23727. mapBfRangeToArray: function(low, high, array) {
  23728. var i = 0, ii = array.length;
  23729. while (low <= high && i < ii) {
  23730. this._map[low] = array[i++];
  23731. ++low;
  23732. }
  23733. },
  23734. // This is used for both bf and cid chars.
  23735. mapOne: function(src, dst) {
  23736. this._map[src] = dst;
  23737. },
  23738. lookup: function(code) {
  23739. return this._map[code];
  23740. },
  23741. contains: function(code) {
  23742. return this._map[code] !== undefined;
  23743. },
  23744. forEach: function(callback) {
  23745. // Most maps have fewer than 65536 entries, and for those we use normal
  23746. // array iteration. But really sparse tables are possible -- e.g. with
  23747. // indices in the *billions*. For such tables we use for..in, which isn't
  23748. // ideal because it stringifies the indices for all present elements, but
  23749. // it does avoid iterating over every undefined entry.
  23750. var map = this._map;
  23751. var length = map.length;
  23752. var i;
  23753. if (length <= 0x10000) {
  23754. for (i = 0; i < length; i++) {
  23755. if (map[i] !== undefined) {
  23756. callback(i, map[i]);
  23757. }
  23758. }
  23759. } else {
  23760. for (i in this._map) {
  23761. callback(i, map[i]);
  23762. }
  23763. }
  23764. },
  23765. charCodeOf: function(value) {
  23766. return this._map.indexOf(value);
  23767. },
  23768. getMap: function() {
  23769. return this._map;
  23770. },
  23771. readCharCode: function(str, offset, out) {
  23772. var c = 0;
  23773. var codespaceRanges = this.codespaceRanges;
  23774. var codespaceRangesLen = this.codespaceRanges.length;
  23775. // 9.7.6.2 CMap Mapping
  23776. // The code length is at most 4.
  23777. for (var n = 0; n < codespaceRangesLen; n++) {
  23778. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  23779. // Check each codespace range to see if it falls within.
  23780. var codespaceRange = codespaceRanges[n];
  23781. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  23782. var low = codespaceRange[k++];
  23783. var high = codespaceRange[k++];
  23784. if (c >= low && c <= high) {
  23785. out.charcode = c;
  23786. out.length = n + 1;
  23787. return;
  23788. }
  23789. }
  23790. }
  23791. out.charcode = 0;
  23792. out.length = 1;
  23793. },
  23794. get length() {
  23795. return this._map.length;
  23796. },
  23797. get isIdentityCMap() {
  23798. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  23799. return false;
  23800. }
  23801. if (this._map.length !== 0x10000) {
  23802. return false;
  23803. }
  23804. for (var i = 0; i < 0x10000; i++) {
  23805. if (this._map[i] !== i) {
  23806. return false;
  23807. }
  23808. }
  23809. return true;
  23810. }
  23811. };
  23812. return CMap;
  23813. })();
  23814. // A special case of CMap, where the _map array implicitly has a length of
  23815. // 65536 and each element is equal to its index.
  23816. var IdentityCMap = (function IdentityCMapClosure() {
  23817. function IdentityCMap(vertical, n) {
  23818. CMap.call(this);
  23819. this.vertical = vertical;
  23820. this.addCodespaceRange(n, 0, 0xffff);
  23821. }
  23822. Util.inherit(IdentityCMap, CMap, {});
  23823. IdentityCMap.prototype = {
  23824. addCodespaceRange: CMap.prototype.addCodespaceRange,
  23825. mapCidRange: function(low, high, dstLow) {
  23826. error('should not call mapCidRange');
  23827. },
  23828. mapBfRange: function(low, high, dstLow) {
  23829. error('should not call mapBfRange');
  23830. },
  23831. mapBfRangeToArray: function(low, high, array) {
  23832. error('should not call mapBfRangeToArray');
  23833. },
  23834. mapOne: function(src, dst) {
  23835. error('should not call mapCidOne');
  23836. },
  23837. lookup: function(code) {
  23838. return (isInt(code) && code <= 0xffff) ? code : undefined;
  23839. },
  23840. contains: function(code) {
  23841. return isInt(code) && code <= 0xffff;
  23842. },
  23843. forEach: function(callback) {
  23844. for (var i = 0; i <= 0xffff; i++) {
  23845. callback(i, i);
  23846. }
  23847. },
  23848. charCodeOf: function(value) {
  23849. return (isInt(value) && value <= 0xffff) ? value : -1;
  23850. },
  23851. getMap: function() {
  23852. // Sometimes identity maps must be instantiated, but it's rare.
  23853. var map = new Array(0x10000);
  23854. for (var i = 0; i <= 0xffff; i++) {
  23855. map[i] = i;
  23856. }
  23857. return map;
  23858. },
  23859. readCharCode: CMap.prototype.readCharCode,
  23860. get length() {
  23861. return 0x10000;
  23862. },
  23863. get isIdentityCMap() {
  23864. error('should not access .isIdentityCMap');
  23865. }
  23866. };
  23867. return IdentityCMap;
  23868. })();
  23869. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  23870. function fetchBinaryData(url) {
  23871. var nonBinaryRequest = PDFJS.disableWorker;
  23872. var request = new XMLHttpRequest();
  23873. request.open('GET', url, false);
  23874. if (!nonBinaryRequest) {
  23875. try {
  23876. request.responseType = 'arraybuffer';
  23877. nonBinaryRequest = request.responseType !== 'arraybuffer';
  23878. } catch (e) {
  23879. nonBinaryRequest = true;
  23880. }
  23881. }
  23882. if (nonBinaryRequest && request.overrideMimeType) {
  23883. request.overrideMimeType('text/plain; charset=x-user-defined');
  23884. }
  23885. request.send(null);
  23886. if (nonBinaryRequest ? !request.responseText : !request.response) {
  23887. error('Unable to get binary cMap at: ' + url);
  23888. }
  23889. if (nonBinaryRequest) {
  23890. var data = Array.prototype.map.call(request.responseText, function (ch) {
  23891. return ch.charCodeAt(0) & 255;
  23892. });
  23893. return new Uint8Array(data);
  23894. }
  23895. return new Uint8Array(request.response);
  23896. }
  23897. function hexToInt(a, size) {
  23898. var n = 0;
  23899. for (var i = 0; i <= size; i++) {
  23900. n = (n << 8) | a[i];
  23901. }
  23902. return n >>> 0;
  23903. }
  23904. function hexToStr(a, size) {
  23905. // This code is hot. Special-case some common values to avoid creating an
  23906. // object with subarray().
  23907. if (size === 1) {
  23908. return String.fromCharCode(a[0], a[1]);
  23909. }
  23910. if (size === 3) {
  23911. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  23912. }
  23913. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  23914. }
  23915. function addHex(a, b, size) {
  23916. var c = 0;
  23917. for (var i = size; i >= 0; i--) {
  23918. c += a[i] + b[i];
  23919. a[i] = c & 255;
  23920. c >>= 8;
  23921. }
  23922. }
  23923. function incHex(a, size) {
  23924. var c = 1;
  23925. for (var i = size; i >= 0 && c > 0; i--) {
  23926. c += a[i];
  23927. a[i] = c & 255;
  23928. c >>= 8;
  23929. }
  23930. }
  23931. var MAX_NUM_SIZE = 16;
  23932. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  23933. function BinaryCMapStream(data) {
  23934. this.buffer = data;
  23935. this.pos = 0;
  23936. this.end = data.length;
  23937. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  23938. }
  23939. BinaryCMapStream.prototype = {
  23940. readByte: function () {
  23941. if (this.pos >= this.end) {
  23942. return -1;
  23943. }
  23944. return this.buffer[this.pos++];
  23945. },
  23946. readNumber: function () {
  23947. var n = 0;
  23948. var last;
  23949. do {
  23950. var b = this.readByte();
  23951. if (b < 0) {
  23952. error('unexpected EOF in bcmap');
  23953. }
  23954. last = !(b & 0x80);
  23955. n = (n << 7) | (b & 0x7F);
  23956. } while (!last);
  23957. return n;
  23958. },
  23959. readSigned: function () {
  23960. var n = this.readNumber();
  23961. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  23962. },
  23963. readHex: function (num, size) {
  23964. num.set(this.buffer.subarray(this.pos,
  23965. this.pos + size + 1));
  23966. this.pos += size + 1;
  23967. },
  23968. readHexNumber: function (num, size) {
  23969. var last;
  23970. var stack = this.tmpBuf, sp = 0;
  23971. do {
  23972. var b = this.readByte();
  23973. if (b < 0) {
  23974. error('unexpected EOF in bcmap');
  23975. }
  23976. last = !(b & 0x80);
  23977. stack[sp++] = b & 0x7F;
  23978. } while (!last);
  23979. var i = size, buffer = 0, bufferSize = 0;
  23980. while (i >= 0) {
  23981. while (bufferSize < 8 && stack.length > 0) {
  23982. buffer = (stack[--sp] << bufferSize) | buffer;
  23983. bufferSize += 7;
  23984. }
  23985. num[i] = buffer & 255;
  23986. i--;
  23987. buffer >>= 8;
  23988. bufferSize -= 8;
  23989. }
  23990. },
  23991. readHexSigned: function (num, size) {
  23992. this.readHexNumber(num, size);
  23993. var sign = num[size] & 1 ? 255 : 0;
  23994. var c = 0;
  23995. for (var i = 0; i <= size; i++) {
  23996. c = ((c & 1) << 8) | num[i];
  23997. num[i] = (c >> 1) ^ sign;
  23998. }
  23999. },
  24000. readString: function () {
  24001. var len = this.readNumber();
  24002. var s = '';
  24003. for (var i = 0; i < len; i++) {
  24004. s += String.fromCharCode(this.readNumber());
  24005. }
  24006. return s;
  24007. }
  24008. };
  24009. function processBinaryCMap(url, cMap, extend) {
  24010. var data = fetchBinaryData(url);
  24011. var stream = new BinaryCMapStream(data);
  24012. var header = stream.readByte();
  24013. cMap.vertical = !!(header & 1);
  24014. var useCMap = null;
  24015. var start = new Uint8Array(MAX_NUM_SIZE);
  24016. var end = new Uint8Array(MAX_NUM_SIZE);
  24017. var char = new Uint8Array(MAX_NUM_SIZE);
  24018. var charCode = new Uint8Array(MAX_NUM_SIZE);
  24019. var tmp = new Uint8Array(MAX_NUM_SIZE);
  24020. var code;
  24021. var b;
  24022. while ((b = stream.readByte()) >= 0) {
  24023. var type = b >> 5;
  24024. if (type === 7) { // metadata, e.g. comment or usecmap
  24025. switch (b & 0x1F) {
  24026. case 0:
  24027. stream.readString(); // skipping comment
  24028. break;
  24029. case 1:
  24030. useCMap = stream.readString();
  24031. break;
  24032. }
  24033. continue;
  24034. }
  24035. var sequence = !!(b & 0x10);
  24036. var dataSize = b & 15;
  24037. assert(dataSize + 1 <= MAX_NUM_SIZE);
  24038. var ucs2DataSize = 1;
  24039. var subitemsCount = stream.readNumber();
  24040. var i;
  24041. switch (type) {
  24042. case 0: // codespacerange
  24043. stream.readHex(start, dataSize);
  24044. stream.readHexNumber(end, dataSize);
  24045. addHex(end, start, dataSize);
  24046. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  24047. hexToInt(end, dataSize));
  24048. for (i = 1; i < subitemsCount; i++) {
  24049. incHex(end, dataSize);
  24050. stream.readHexNumber(start, dataSize);
  24051. addHex(start, end, dataSize);
  24052. stream.readHexNumber(end, dataSize);
  24053. addHex(end, start, dataSize);
  24054. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  24055. hexToInt(end, dataSize));
  24056. }
  24057. break;
  24058. case 1: // notdefrange
  24059. stream.readHex(start, dataSize);
  24060. stream.readHexNumber(end, dataSize);
  24061. addHex(end, start, dataSize);
  24062. code = stream.readNumber();
  24063. // undefined range, skipping
  24064. for (i = 1; i < subitemsCount; i++) {
  24065. incHex(end, dataSize);
  24066. stream.readHexNumber(start, dataSize);
  24067. addHex(start, end, dataSize);
  24068. stream.readHexNumber(end, dataSize);
  24069. addHex(end, start, dataSize);
  24070. code = stream.readNumber();
  24071. // nop
  24072. }
  24073. break;
  24074. case 2: // cidchar
  24075. stream.readHex(char, dataSize);
  24076. code = stream.readNumber();
  24077. cMap.mapOne(hexToInt(char, dataSize), code);
  24078. for (i = 1; i < subitemsCount; i++) {
  24079. incHex(char, dataSize);
  24080. if (!sequence) {
  24081. stream.readHexNumber(tmp, dataSize);
  24082. addHex(char, tmp, dataSize);
  24083. }
  24084. code = stream.readSigned() + (code + 1);
  24085. cMap.mapOne(hexToInt(char, dataSize), code);
  24086. }
  24087. break;
  24088. case 3: // cidrange
  24089. stream.readHex(start, dataSize);
  24090. stream.readHexNumber(end, dataSize);
  24091. addHex(end, start, dataSize);
  24092. code = stream.readNumber();
  24093. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  24094. code);
  24095. for (i = 1; i < subitemsCount; i++) {
  24096. incHex(end, dataSize);
  24097. if (!sequence) {
  24098. stream.readHexNumber(start, dataSize);
  24099. addHex(start, end, dataSize);
  24100. } else {
  24101. start.set(end);
  24102. }
  24103. stream.readHexNumber(end, dataSize);
  24104. addHex(end, start, dataSize);
  24105. code = stream.readNumber();
  24106. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  24107. code);
  24108. }
  24109. break;
  24110. case 4: // bfchar
  24111. stream.readHex(char, ucs2DataSize);
  24112. stream.readHex(charCode, dataSize);
  24113. cMap.mapOne(hexToInt(char, ucs2DataSize),
  24114. hexToStr(charCode, dataSize));
  24115. for (i = 1; i < subitemsCount; i++) {
  24116. incHex(char, ucs2DataSize);
  24117. if (!sequence) {
  24118. stream.readHexNumber(tmp, ucs2DataSize);
  24119. addHex(char, tmp, ucs2DataSize);
  24120. }
  24121. incHex(charCode, dataSize);
  24122. stream.readHexSigned(tmp, dataSize);
  24123. addHex(charCode, tmp, dataSize);
  24124. cMap.mapOne(hexToInt(char, ucs2DataSize),
  24125. hexToStr(charCode, dataSize));
  24126. }
  24127. break;
  24128. case 5: // bfrange
  24129. stream.readHex(start, ucs2DataSize);
  24130. stream.readHexNumber(end, ucs2DataSize);
  24131. addHex(end, start, ucs2DataSize);
  24132. stream.readHex(charCode, dataSize);
  24133. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  24134. hexToInt(end, ucs2DataSize),
  24135. hexToStr(charCode, dataSize));
  24136. for (i = 1; i < subitemsCount; i++) {
  24137. incHex(end, ucs2DataSize);
  24138. if (!sequence) {
  24139. stream.readHexNumber(start, ucs2DataSize);
  24140. addHex(start, end, ucs2DataSize);
  24141. } else {
  24142. start.set(end);
  24143. }
  24144. stream.readHexNumber(end, ucs2DataSize);
  24145. addHex(end, start, ucs2DataSize);
  24146. stream.readHex(charCode, dataSize);
  24147. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  24148. hexToInt(end, ucs2DataSize),
  24149. hexToStr(charCode, dataSize));
  24150. }
  24151. break;
  24152. default:
  24153. error('Unknown type: ' + type);
  24154. break;
  24155. }
  24156. }
  24157. if (useCMap) {
  24158. extend(useCMap);
  24159. }
  24160. return cMap;
  24161. }
  24162. function BinaryCMapReader() {}
  24163. BinaryCMapReader.prototype = {
  24164. read: processBinaryCMap
  24165. };
  24166. return BinaryCMapReader;
  24167. })();
  24168. var CMapFactory = (function CMapFactoryClosure() {
  24169. function strToInt(str) {
  24170. var a = 0;
  24171. for (var i = 0; i < str.length; i++) {
  24172. a = (a << 8) | str.charCodeAt(i);
  24173. }
  24174. return a >>> 0;
  24175. }
  24176. function expectString(obj) {
  24177. if (!isString(obj)) {
  24178. error('Malformed CMap: expected string.');
  24179. }
  24180. }
  24181. function expectInt(obj) {
  24182. if (!isInt(obj)) {
  24183. error('Malformed CMap: expected int.');
  24184. }
  24185. }
  24186. function parseBfChar(cMap, lexer) {
  24187. while (true) {
  24188. var obj = lexer.getObj();
  24189. if (isEOF(obj)) {
  24190. break;
  24191. }
  24192. if (isCmd(obj, 'endbfchar')) {
  24193. return;
  24194. }
  24195. expectString(obj);
  24196. var src = strToInt(obj);
  24197. obj = lexer.getObj();
  24198. // TODO are /dstName used?
  24199. expectString(obj);
  24200. var dst = obj;
  24201. cMap.mapOne(src, dst);
  24202. }
  24203. }
  24204. function parseBfRange(cMap, lexer) {
  24205. while (true) {
  24206. var obj = lexer.getObj();
  24207. if (isEOF(obj)) {
  24208. break;
  24209. }
  24210. if (isCmd(obj, 'endbfrange')) {
  24211. return;
  24212. }
  24213. expectString(obj);
  24214. var low = strToInt(obj);
  24215. obj = lexer.getObj();
  24216. expectString(obj);
  24217. var high = strToInt(obj);
  24218. obj = lexer.getObj();
  24219. if (isInt(obj) || isString(obj)) {
  24220. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  24221. cMap.mapBfRange(low, high, dstLow);
  24222. } else if (isCmd(obj, '[')) {
  24223. obj = lexer.getObj();
  24224. var array = [];
  24225. while (!isCmd(obj, ']') && !isEOF(obj)) {
  24226. array.push(obj);
  24227. obj = lexer.getObj();
  24228. }
  24229. cMap.mapBfRangeToArray(low, high, array);
  24230. } else {
  24231. break;
  24232. }
  24233. }
  24234. error('Invalid bf range.');
  24235. }
  24236. function parseCidChar(cMap, lexer) {
  24237. while (true) {
  24238. var obj = lexer.getObj();
  24239. if (isEOF(obj)) {
  24240. break;
  24241. }
  24242. if (isCmd(obj, 'endcidchar')) {
  24243. return;
  24244. }
  24245. expectString(obj);
  24246. var src = strToInt(obj);
  24247. obj = lexer.getObj();
  24248. expectInt(obj);
  24249. var dst = obj;
  24250. cMap.mapOne(src, dst);
  24251. }
  24252. }
  24253. function parseCidRange(cMap, lexer) {
  24254. while (true) {
  24255. var obj = lexer.getObj();
  24256. if (isEOF(obj)) {
  24257. break;
  24258. }
  24259. if (isCmd(obj, 'endcidrange')) {
  24260. return;
  24261. }
  24262. expectString(obj);
  24263. var low = strToInt(obj);
  24264. obj = lexer.getObj();
  24265. expectString(obj);
  24266. var high = strToInt(obj);
  24267. obj = lexer.getObj();
  24268. expectInt(obj);
  24269. var dstLow = obj;
  24270. cMap.mapCidRange(low, high, dstLow);
  24271. }
  24272. }
  24273. function parseCodespaceRange(cMap, lexer) {
  24274. while (true) {
  24275. var obj = lexer.getObj();
  24276. if (isEOF(obj)) {
  24277. break;
  24278. }
  24279. if (isCmd(obj, 'endcodespacerange')) {
  24280. return;
  24281. }
  24282. if (!isString(obj)) {
  24283. break;
  24284. }
  24285. var low = strToInt(obj);
  24286. obj = lexer.getObj();
  24287. if (!isString(obj)) {
  24288. break;
  24289. }
  24290. var high = strToInt(obj);
  24291. cMap.addCodespaceRange(obj.length, low, high);
  24292. }
  24293. error('Invalid codespace range.');
  24294. }
  24295. function parseWMode(cMap, lexer) {
  24296. var obj = lexer.getObj();
  24297. if (isInt(obj)) {
  24298. cMap.vertical = !!obj;
  24299. }
  24300. }
  24301. function parseCMapName(cMap, lexer) {
  24302. var obj = lexer.getObj();
  24303. if (isName(obj) && isString(obj.name)) {
  24304. cMap.name = obj.name;
  24305. }
  24306. }
  24307. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  24308. var previous;
  24309. var embededUseCMap;
  24310. objLoop: while (true) {
  24311. var obj = lexer.getObj();
  24312. if (isEOF(obj)) {
  24313. break;
  24314. } else if (isName(obj)) {
  24315. if (obj.name === 'WMode') {
  24316. parseWMode(cMap, lexer);
  24317. } else if (obj.name === 'CMapName') {
  24318. parseCMapName(cMap, lexer);
  24319. }
  24320. previous = obj;
  24321. } else if (isCmd(obj)) {
  24322. switch (obj.cmd) {
  24323. case 'endcmap':
  24324. break objLoop;
  24325. case 'usecmap':
  24326. if (isName(previous)) {
  24327. embededUseCMap = previous.name;
  24328. }
  24329. break;
  24330. case 'begincodespacerange':
  24331. parseCodespaceRange(cMap, lexer);
  24332. break;
  24333. case 'beginbfchar':
  24334. parseBfChar(cMap, lexer);
  24335. break;
  24336. case 'begincidchar':
  24337. parseCidChar(cMap, lexer);
  24338. break;
  24339. case 'beginbfrange':
  24340. parseBfRange(cMap, lexer);
  24341. break;
  24342. case 'begincidrange':
  24343. parseCidRange(cMap, lexer);
  24344. break;
  24345. }
  24346. }
  24347. }
  24348. if (!useCMap && embededUseCMap) {
  24349. // Load the usecmap definition from the file only if there wasn't one
  24350. // specified.
  24351. useCMap = embededUseCMap;
  24352. }
  24353. if (useCMap) {
  24354. extendCMap(cMap, builtInCMapParams, useCMap);
  24355. }
  24356. }
  24357. function extendCMap(cMap, builtInCMapParams, useCMap) {
  24358. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  24359. // If there aren't any code space ranges defined clone all the parent ones
  24360. // into this cMap.
  24361. if (cMap.numCodespaceRanges === 0) {
  24362. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  24363. for (var i = 0; i < useCodespaceRanges.length; i++) {
  24364. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  24365. }
  24366. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  24367. }
  24368. // Merge the map into the current one, making sure not to override
  24369. // any previously defined entries.
  24370. cMap.useCMap.forEach(function(key, value) {
  24371. if (!cMap.contains(key)) {
  24372. cMap.mapOne(key, cMap.useCMap.lookup(key));
  24373. }
  24374. });
  24375. }
  24376. function parseBinaryCMap(name, builtInCMapParams) {
  24377. var url = builtInCMapParams.url + name + '.bcmap';
  24378. var cMap = new CMap(true);
  24379. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  24380. extendCMap(cMap, builtInCMapParams, useCMap);
  24381. });
  24382. return cMap;
  24383. }
  24384. function createBuiltInCMap(name, builtInCMapParams) {
  24385. if (name === 'Identity-H') {
  24386. return new IdentityCMap(false, 2);
  24387. } else if (name === 'Identity-V') {
  24388. return new IdentityCMap(true, 2);
  24389. }
  24390. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  24391. error('Unknown cMap name: ' + name);
  24392. }
  24393. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  24394. if (builtInCMapParams.packed) {
  24395. return parseBinaryCMap(name, builtInCMapParams);
  24396. }
  24397. var request = new XMLHttpRequest();
  24398. var url = builtInCMapParams.url + name;
  24399. request.open('GET', url, false);
  24400. request.send(null);
  24401. if (!request.responseText) {
  24402. error('Unable to get cMap at: ' + url);
  24403. }
  24404. var cMap = new CMap(true);
  24405. var lexer = new Lexer(new StringStream(request.responseText));
  24406. parseCMap(cMap, lexer, builtInCMapParams, null);
  24407. return cMap;
  24408. }
  24409. return {
  24410. create: function (encoding, builtInCMapParams, useCMap) {
  24411. if (isName(encoding)) {
  24412. return createBuiltInCMap(encoding.name, builtInCMapParams);
  24413. } else if (isStream(encoding)) {
  24414. var cMap = new CMap();
  24415. var lexer = new Lexer(encoding);
  24416. try {
  24417. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  24418. } catch (e) {
  24419. warn('Invalid CMap data. ' + e);
  24420. }
  24421. if (cMap.isIdentityCMap) {
  24422. return createBuiltInCMap(cMap.name, builtInCMapParams);
  24423. }
  24424. return cMap;
  24425. }
  24426. error('Encoding required.');
  24427. }
  24428. };
  24429. })();
  24430. exports.CMap = CMap;
  24431. exports.CMapFactory = CMapFactory;
  24432. exports.IdentityCMap = IdentityCMap;
  24433. }));
  24434. (function (root, factory) {
  24435. {
  24436. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  24437. root.pdfjsCoreParser);
  24438. }
  24439. }(this, function (exports, sharedUtil, coreParser) {
  24440. var error = sharedUtil.error;
  24441. var EOF = coreParser.EOF;
  24442. var Lexer = coreParser.Lexer;
  24443. var PostScriptParser = (function PostScriptParserClosure() {
  24444. function PostScriptParser(lexer) {
  24445. this.lexer = lexer;
  24446. this.operators = [];
  24447. this.token = null;
  24448. this.prev = null;
  24449. }
  24450. PostScriptParser.prototype = {
  24451. nextToken: function PostScriptParser_nextToken() {
  24452. this.prev = this.token;
  24453. this.token = this.lexer.getToken();
  24454. },
  24455. accept: function PostScriptParser_accept(type) {
  24456. if (this.token.type === type) {
  24457. this.nextToken();
  24458. return true;
  24459. }
  24460. return false;
  24461. },
  24462. expect: function PostScriptParser_expect(type) {
  24463. if (this.accept(type)) {
  24464. return true;
  24465. }
  24466. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  24467. type + '.');
  24468. },
  24469. parse: function PostScriptParser_parse() {
  24470. this.nextToken();
  24471. this.expect(PostScriptTokenTypes.LBRACE);
  24472. this.parseBlock();
  24473. this.expect(PostScriptTokenTypes.RBRACE);
  24474. return this.operators;
  24475. },
  24476. parseBlock: function PostScriptParser_parseBlock() {
  24477. while (true) {
  24478. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  24479. this.operators.push(this.prev.value);
  24480. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  24481. this.operators.push(this.prev.value);
  24482. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  24483. this.parseCondition();
  24484. } else {
  24485. return;
  24486. }
  24487. }
  24488. },
  24489. parseCondition: function PostScriptParser_parseCondition() {
  24490. // Add two place holders that will be updated later
  24491. var conditionLocation = this.operators.length;
  24492. this.operators.push(null, null);
  24493. this.parseBlock();
  24494. this.expect(PostScriptTokenTypes.RBRACE);
  24495. if (this.accept(PostScriptTokenTypes.IF)) {
  24496. // The true block is right after the 'if' so it just falls through on
  24497. // true else it jumps and skips the true block.
  24498. this.operators[conditionLocation] = this.operators.length;
  24499. this.operators[conditionLocation + 1] = 'jz';
  24500. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  24501. var jumpLocation = this.operators.length;
  24502. this.operators.push(null, null);
  24503. var endOfTrue = this.operators.length;
  24504. this.parseBlock();
  24505. this.expect(PostScriptTokenTypes.RBRACE);
  24506. this.expect(PostScriptTokenTypes.IFELSE);
  24507. // The jump is added at the end of the true block to skip the false
  24508. // block.
  24509. this.operators[jumpLocation] = this.operators.length;
  24510. this.operators[jumpLocation + 1] = 'j';
  24511. this.operators[conditionLocation] = endOfTrue;
  24512. this.operators[conditionLocation + 1] = 'jz';
  24513. } else {
  24514. error('PS Function: error parsing conditional.');
  24515. }
  24516. }
  24517. };
  24518. return PostScriptParser;
  24519. })();
  24520. var PostScriptTokenTypes = {
  24521. LBRACE: 0,
  24522. RBRACE: 1,
  24523. NUMBER: 2,
  24524. OPERATOR: 3,
  24525. IF: 4,
  24526. IFELSE: 5
  24527. };
  24528. var PostScriptToken = (function PostScriptTokenClosure() {
  24529. function PostScriptToken(type, value) {
  24530. this.type = type;
  24531. this.value = value;
  24532. }
  24533. var opCache = Object.create(null);
  24534. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  24535. var opValue = opCache[op];
  24536. if (opValue) {
  24537. return opValue;
  24538. }
  24539. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  24540. };
  24541. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  24542. '{');
  24543. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  24544. '}');
  24545. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  24546. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  24547. 'IFELSE');
  24548. return PostScriptToken;
  24549. })();
  24550. var PostScriptLexer = (function PostScriptLexerClosure() {
  24551. function PostScriptLexer(stream) {
  24552. this.stream = stream;
  24553. this.nextChar();
  24554. this.strBuf = [];
  24555. }
  24556. PostScriptLexer.prototype = {
  24557. nextChar: function PostScriptLexer_nextChar() {
  24558. return (this.currentChar = this.stream.getByte());
  24559. },
  24560. getToken: function PostScriptLexer_getToken() {
  24561. var comment = false;
  24562. var ch = this.currentChar;
  24563. // skip comments
  24564. while (true) {
  24565. if (ch < 0) {
  24566. return EOF;
  24567. }
  24568. if (comment) {
  24569. if (ch === 0x0A || ch === 0x0D) {
  24570. comment = false;
  24571. }
  24572. } else if (ch === 0x25) { // '%'
  24573. comment = true;
  24574. } else if (!Lexer.isSpace(ch)) {
  24575. break;
  24576. }
  24577. ch = this.nextChar();
  24578. }
  24579. switch (ch | 0) {
  24580. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  24581. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  24582. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  24583. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  24584. this.getNumber());
  24585. case 0x7B: // '{'
  24586. this.nextChar();
  24587. return PostScriptToken.LBRACE;
  24588. case 0x7D: // '}'
  24589. this.nextChar();
  24590. return PostScriptToken.RBRACE;
  24591. }
  24592. // operator
  24593. var strBuf = this.strBuf;
  24594. strBuf.length = 0;
  24595. strBuf[0] = String.fromCharCode(ch);
  24596. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  24597. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  24598. strBuf.push(String.fromCharCode(ch));
  24599. }
  24600. var str = strBuf.join('');
  24601. switch (str.toLowerCase()) {
  24602. case 'if':
  24603. return PostScriptToken.IF;
  24604. case 'ifelse':
  24605. return PostScriptToken.IFELSE;
  24606. default:
  24607. return PostScriptToken.getOperator(str);
  24608. }
  24609. },
  24610. getNumber: function PostScriptLexer_getNumber() {
  24611. var ch = this.currentChar;
  24612. var strBuf = this.strBuf;
  24613. strBuf.length = 0;
  24614. strBuf[0] = String.fromCharCode(ch);
  24615. while ((ch = this.nextChar()) >= 0) {
  24616. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  24617. ch === 0x2D || ch === 0x2E) { // '-', '.'
  24618. strBuf.push(String.fromCharCode(ch));
  24619. } else {
  24620. break;
  24621. }
  24622. }
  24623. var value = parseFloat(strBuf.join(''));
  24624. if (isNaN(value)) {
  24625. error('Invalid floating point number: ' + value);
  24626. }
  24627. return value;
  24628. }
  24629. };
  24630. return PostScriptLexer;
  24631. })();
  24632. exports.PostScriptLexer = PostScriptLexer;
  24633. exports.PostScriptParser = PostScriptParser;
  24634. }));
  24635. (function (root, factory) {
  24636. {
  24637. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  24638. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  24639. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  24640. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  24641. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
  24642. }
  24643. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  24644. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer,
  24645. coreEncodings, coreStandardFonts, coreUnicode) {
  24646. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  24647. var FontType = sharedUtil.FontType;
  24648. var Util = sharedUtil.Util;
  24649. var assert = sharedUtil.assert;
  24650. var bytesToString = sharedUtil.bytesToString;
  24651. var error = sharedUtil.error;
  24652. var info = sharedUtil.info;
  24653. var isArray = sharedUtil.isArray;
  24654. var isInt = sharedUtil.isInt;
  24655. var isNum = sharedUtil.isNum;
  24656. var readUint32 = sharedUtil.readUint32;
  24657. var shadow = sharedUtil.shadow;
  24658. var stringToBytes = sharedUtil.stringToBytes;
  24659. var string32 = sharedUtil.string32;
  24660. var warn = sharedUtil.warn;
  24661. var Name = corePrimitives.Name;
  24662. var Stream = coreStream.Stream;
  24663. var Lexer = coreParser.Lexer;
  24664. var CMapFactory = coreCMap.CMapFactory;
  24665. var IdentityCMap = coreCMap.IdentityCMap;
  24666. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  24667. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  24668. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  24669. var ExpertCharset = coreCharsets.ExpertCharset;
  24670. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  24671. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  24672. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  24673. var StandardEncoding = coreEncodings.StandardEncoding;
  24674. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  24675. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  24676. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  24677. var ExpertEncoding = coreEncodings.ExpertEncoding;
  24678. var getEncoding = coreEncodings.getEncoding;
  24679. var getStdFontMap = coreStandardFonts.getStdFontMap;
  24680. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  24681. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  24682. var getSupplementalGlyphMapForArialBlack =
  24683. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  24684. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  24685. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  24686. // Unicode Private Use Area
  24687. var PRIVATE_USE_OFFSET_START = 0xE000;
  24688. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  24689. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  24690. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  24691. // except for Type 3 fonts
  24692. var PDF_GLYPH_SPACE_UNITS = 1000;
  24693. // Hinting is currently disabled due to unknown problems on windows
  24694. // in tracemonkey and various other pdfs with type1 fonts.
  24695. var HINTING_ENABLED = false;
  24696. // Accented charactars are not displayed properly on windows, using this flag
  24697. // to control analysis of seac charstrings.
  24698. var SEAC_ANALYSIS_ENABLED = false;
  24699. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  24700. var MAX_SUBR_NESTING = 10;
  24701. var FontFlags = {
  24702. FixedPitch: 1,
  24703. Serif: 2,
  24704. Symbolic: 4,
  24705. Script: 8,
  24706. Nonsymbolic: 32,
  24707. Italic: 64,
  24708. AllCap: 65536,
  24709. SmallCap: 131072,
  24710. ForceBold: 262144
  24711. };
  24712. var MacStandardGlyphOrdering = [
  24713. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  24714. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  24715. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  24716. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  24717. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  24718. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  24719. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  24720. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  24721. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  24722. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  24723. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  24724. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  24725. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  24726. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  24727. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  24728. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  24729. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  24730. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  24731. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  24732. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  24733. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  24734. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  24735. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  24736. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  24737. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  24738. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  24739. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  24740. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  24741. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  24742. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  24743. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  24744. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  24745. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  24746. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  24747. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  24748. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  24749. function adjustWidths(properties) {
  24750. if (!properties.fontMatrix) {
  24751. return;
  24752. }
  24753. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  24754. return;
  24755. }
  24756. // adjusting width to fontMatrix scale
  24757. var scale = 0.001 / properties.fontMatrix[0];
  24758. var glyphsWidths = properties.widths;
  24759. for (var glyph in glyphsWidths) {
  24760. glyphsWidths[glyph] *= scale;
  24761. }
  24762. properties.defaultWidth *= scale;
  24763. }
  24764. function getFontType(type, subtype) {
  24765. switch (type) {
  24766. case 'Type1':
  24767. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  24768. case 'CIDFontType0':
  24769. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  24770. FontType.CIDFONTTYPE0;
  24771. case 'OpenType':
  24772. return FontType.OPENTYPE;
  24773. case 'TrueType':
  24774. return FontType.TRUETYPE;
  24775. case 'CIDFontType2':
  24776. return FontType.CIDFONTTYPE2;
  24777. case 'MMType1':
  24778. return FontType.MMTYPE1;
  24779. case 'Type0':
  24780. return FontType.TYPE0;
  24781. default:
  24782. return FontType.UNKNOWN;
  24783. }
  24784. }
  24785. var Glyph = (function GlyphClosure() {
  24786. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  24787. isSpace) {
  24788. this.fontChar = fontChar;
  24789. this.unicode = unicode;
  24790. this.accent = accent;
  24791. this.width = width;
  24792. this.vmetric = vmetric;
  24793. this.operatorListId = operatorListId;
  24794. this.isSpace = isSpace;
  24795. }
  24796. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  24797. vmetric, operatorListId, isSpace) {
  24798. return this.fontChar === fontChar &&
  24799. this.unicode === unicode &&
  24800. this.accent === accent &&
  24801. this.width === width &&
  24802. this.vmetric === vmetric &&
  24803. this.operatorListId === operatorListId &&
  24804. this.isSpace === isSpace;
  24805. };
  24806. return Glyph;
  24807. })();
  24808. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  24809. function ToUnicodeMap(cmap) {
  24810. // The elements of this._map can be integers or strings, depending on how
  24811. // |cmap| was created.
  24812. this._map = cmap;
  24813. }
  24814. ToUnicodeMap.prototype = {
  24815. get length() {
  24816. return this._map.length;
  24817. },
  24818. forEach: function(callback) {
  24819. for (var charCode in this._map) {
  24820. callback(charCode, this._map[charCode].charCodeAt(0));
  24821. }
  24822. },
  24823. has: function(i) {
  24824. return this._map[i] !== undefined;
  24825. },
  24826. get: function(i) {
  24827. return this._map[i];
  24828. },
  24829. charCodeOf: function(v) {
  24830. return this._map.indexOf(v);
  24831. }
  24832. };
  24833. return ToUnicodeMap;
  24834. })();
  24835. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  24836. function IdentityToUnicodeMap(firstChar, lastChar) {
  24837. this.firstChar = firstChar;
  24838. this.lastChar = lastChar;
  24839. }
  24840. IdentityToUnicodeMap.prototype = {
  24841. get length() {
  24842. return (this.lastChar + 1) - this.firstChar;
  24843. },
  24844. forEach: function (callback) {
  24845. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  24846. callback(i, i);
  24847. }
  24848. },
  24849. has: function (i) {
  24850. return this.firstChar <= i && i <= this.lastChar;
  24851. },
  24852. get: function (i) {
  24853. if (this.firstChar <= i && i <= this.lastChar) {
  24854. return String.fromCharCode(i);
  24855. }
  24856. return undefined;
  24857. },
  24858. charCodeOf: function (v) {
  24859. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  24860. }
  24861. };
  24862. return IdentityToUnicodeMap;
  24863. })();
  24864. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  24865. function writeInt16(dest, offset, num) {
  24866. dest[offset] = (num >> 8) & 0xFF;
  24867. dest[offset + 1] = num & 0xFF;
  24868. }
  24869. function writeInt32(dest, offset, num) {
  24870. dest[offset] = (num >> 24) & 0xFF;
  24871. dest[offset + 1] = (num >> 16) & 0xFF;
  24872. dest[offset + 2] = (num >> 8) & 0xFF;
  24873. dest[offset + 3] = num & 0xFF;
  24874. }
  24875. function writeData(dest, offset, data) {
  24876. var i, ii;
  24877. if (data instanceof Uint8Array) {
  24878. dest.set(data, offset);
  24879. } else if (typeof data === 'string') {
  24880. for (i = 0, ii = data.length; i < ii; i++) {
  24881. dest[offset++] = data.charCodeAt(i) & 0xFF;
  24882. }
  24883. } else {
  24884. // treating everything else as array
  24885. for (i = 0, ii = data.length; i < ii; i++) {
  24886. dest[offset++] = data[i] & 0xFF;
  24887. }
  24888. }
  24889. }
  24890. function OpenTypeFileBuilder(sfnt) {
  24891. this.sfnt = sfnt;
  24892. this.tables = Object.create(null);
  24893. }
  24894. OpenTypeFileBuilder.getSearchParams =
  24895. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  24896. var maxPower2 = 1, log2 = 0;
  24897. while ((maxPower2 ^ entriesCount) > maxPower2) {
  24898. maxPower2 <<= 1;
  24899. log2++;
  24900. }
  24901. var searchRange = maxPower2 * entrySize;
  24902. return {
  24903. range: searchRange,
  24904. entry: log2,
  24905. rangeShift: entrySize * entriesCount - searchRange
  24906. };
  24907. };
  24908. var OTF_HEADER_SIZE = 12;
  24909. var OTF_TABLE_ENTRY_SIZE = 16;
  24910. OpenTypeFileBuilder.prototype = {
  24911. toArray: function OpenTypeFileBuilder_toArray() {
  24912. var sfnt = this.sfnt;
  24913. // Tables needs to be written by ascendant alphabetic order
  24914. var tables = this.tables;
  24915. var tablesNames = Object.keys(tables);
  24916. tablesNames.sort();
  24917. var numTables = tablesNames.length;
  24918. var i, j, jj, table, tableName;
  24919. // layout the tables data
  24920. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  24921. var tableOffsets = [offset];
  24922. for (i = 0; i < numTables; i++) {
  24923. table = tables[tablesNames[i]];
  24924. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  24925. offset += paddedLength;
  24926. tableOffsets.push(offset);
  24927. }
  24928. var file = new Uint8Array(offset);
  24929. // write the table data first (mostly for checksum)
  24930. for (i = 0; i < numTables; i++) {
  24931. table = tables[tablesNames[i]];
  24932. writeData(file, tableOffsets[i], table);
  24933. }
  24934. // sfnt version (4 bytes)
  24935. if (sfnt === 'true') {
  24936. // Windows hates the Mac TrueType sfnt version number
  24937. sfnt = string32(0x00010000);
  24938. }
  24939. file[0] = sfnt.charCodeAt(0) & 0xFF;
  24940. file[1] = sfnt.charCodeAt(1) & 0xFF;
  24941. file[2] = sfnt.charCodeAt(2) & 0xFF;
  24942. file[3] = sfnt.charCodeAt(3) & 0xFF;
  24943. // numTables (2 bytes)
  24944. writeInt16(file, 4, numTables);
  24945. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  24946. // searchRange (2 bytes)
  24947. writeInt16(file, 6, searchParams.range);
  24948. // entrySelector (2 bytes)
  24949. writeInt16(file, 8, searchParams.entry);
  24950. // rangeShift (2 bytes)
  24951. writeInt16(file, 10, searchParams.rangeShift);
  24952. offset = OTF_HEADER_SIZE;
  24953. // writing table entries
  24954. for (i = 0; i < numTables; i++) {
  24955. tableName = tablesNames[i];
  24956. file[offset] = tableName.charCodeAt(0) & 0xFF;
  24957. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  24958. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  24959. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  24960. // checksum
  24961. var checksum = 0;
  24962. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  24963. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  24964. (file[j + 2] << 8) + file[j + 3];
  24965. checksum = (checksum + quad) | 0;
  24966. }
  24967. writeInt32(file, offset + 4, checksum);
  24968. // offset
  24969. writeInt32(file, offset + 8, tableOffsets[i]);
  24970. // length
  24971. writeInt32(file, offset + 12, tables[tableName].length);
  24972. offset += OTF_TABLE_ENTRY_SIZE;
  24973. }
  24974. return file;
  24975. },
  24976. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  24977. if (tag in this.tables) {
  24978. throw new Error('Table ' + tag + ' already exists');
  24979. }
  24980. this.tables[tag] = data;
  24981. }
  24982. };
  24983. return OpenTypeFileBuilder;
  24984. })();
  24985. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  24986. // issues when they are painted on the canvas, e.g. complex-script shaping or
  24987. // control/whitespace characters. The ranges are listed in pairs: the first item
  24988. // is a code of the first problematic code, the second one is the next
  24989. // non-problematic code. The ranges must be in sorted order.
  24990. var ProblematicCharRanges = new Int32Array([
  24991. // Control characters.
  24992. 0x0000, 0x0020,
  24993. 0x007F, 0x00A1,
  24994. 0x00AD, 0x00AE,
  24995. // Chars that is used in complex-script shaping.
  24996. 0x0600, 0x0780,
  24997. 0x08A0, 0x10A0,
  24998. 0x1780, 0x1800,
  24999. // General punctuation chars.
  25000. 0x2000, 0x2010,
  25001. 0x2011, 0x2012,
  25002. 0x2028, 0x2030,
  25003. 0x205F, 0x2070,
  25004. 0x25CC, 0x25CD,
  25005. // Chars that is used in complex-script shaping.
  25006. 0xAA60, 0xAA80,
  25007. // Specials Unicode block.
  25008. 0xFFF0, 0x10000
  25009. ]);
  25010. /**
  25011. * 'Font' is the class the outside world should use, it encapsulate all the font
  25012. * decoding logics whatever type it is (assuming the font type is supported).
  25013. *
  25014. * For example to read a Type1 font and to attach it to the document:
  25015. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  25016. * type1Font.bind();
  25017. */
  25018. var Font = (function FontClosure() {
  25019. function Font(name, file, properties) {
  25020. var charCode, glyphName, fontChar;
  25021. this.name = name;
  25022. this.loadedName = properties.loadedName;
  25023. this.isType3Font = properties.isType3Font;
  25024. this.sizes = [];
  25025. this.glyphCache = Object.create(null);
  25026. var names = name.split('+');
  25027. names = names.length > 1 ? names[1] : names[0];
  25028. names = names.split(/[-,_]/g)[0];
  25029. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  25030. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  25031. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  25032. var type = properties.type;
  25033. var subtype = properties.subtype;
  25034. this.type = type;
  25035. this.fallbackName = (this.isMonospace ? 'monospace' :
  25036. (this.isSerifFont ? 'serif' : 'sans-serif'));
  25037. this.differences = properties.differences;
  25038. this.widths = properties.widths;
  25039. this.defaultWidth = properties.defaultWidth;
  25040. this.composite = properties.composite;
  25041. this.wideChars = properties.wideChars;
  25042. this.cMap = properties.cMap;
  25043. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  25044. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  25045. this.fontMatrix = properties.fontMatrix;
  25046. this.bbox = properties.bbox;
  25047. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  25048. this.toFontChar = [];
  25049. if (properties.type === 'Type3') {
  25050. for (charCode = 0; charCode < 256; charCode++) {
  25051. this.toFontChar[charCode] = (this.differences[charCode] ||
  25052. properties.defaultEncoding[charCode]);
  25053. }
  25054. this.fontType = FontType.TYPE3;
  25055. return;
  25056. }
  25057. this.cidEncoding = properties.cidEncoding;
  25058. this.vertical = properties.vertical;
  25059. if (this.vertical) {
  25060. this.vmetrics = properties.vmetrics;
  25061. this.defaultVMetrics = properties.defaultVMetrics;
  25062. }
  25063. var glyphsUnicodeMap;
  25064. if (!file || file.isEmpty) {
  25065. if (file) {
  25066. // Some bad PDF generators will include empty font files,
  25067. // attempting to recover by assuming that no file exists.
  25068. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  25069. }
  25070. this.missingFile = true;
  25071. // The file data is not specified. Trying to fix the font name
  25072. // to be used with the canvas.font.
  25073. var fontName = name.replace(/[,_]/g, '-');
  25074. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  25075. var isStandardFont = !!stdFontMap[fontName] ||
  25076. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  25077. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  25078. this.bold = (fontName.search(/bold/gi) !== -1);
  25079. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  25080. (fontName.search(/italic/gi) !== -1));
  25081. // Use 'name' instead of 'fontName' here because the original
  25082. // name ArialBlack for example will be replaced by Helvetica.
  25083. this.black = (name.search(/Black/g) !== -1);
  25084. // if at least one width is present, remeasure all chars when exists
  25085. this.remeasure = Object.keys(this.widths).length > 0;
  25086. if (isStandardFont && type === 'CIDFontType2' &&
  25087. properties.cidEncoding.indexOf('Identity-') === 0) {
  25088. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  25089. // Standard fonts might be embedded as CID font without glyph mapping.
  25090. // Building one based on GlyphMapForStandardFonts.
  25091. var map = [];
  25092. for (charCode in GlyphMapForStandardFonts) {
  25093. map[+charCode] = GlyphMapForStandardFonts[charCode];
  25094. }
  25095. if (/ArialBlack/i.test(name)) {
  25096. var SupplementalGlyphMapForArialBlack =
  25097. getSupplementalGlyphMapForArialBlack();
  25098. for (charCode in SupplementalGlyphMapForArialBlack) {
  25099. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  25100. }
  25101. }
  25102. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  25103. if (!isIdentityUnicode) {
  25104. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25105. map[+charCode] = unicodeCharCode;
  25106. });
  25107. }
  25108. this.toFontChar = map;
  25109. this.toUnicode = new ToUnicodeMap(map);
  25110. } else if (/Symbol/i.test(fontName)) {
  25111. var symbols = SymbolSetEncoding;
  25112. glyphsUnicodeMap = getGlyphsUnicode();
  25113. for (charCode in symbols) {
  25114. fontChar = glyphsUnicodeMap[symbols[charCode]];
  25115. if (!fontChar) {
  25116. continue;
  25117. }
  25118. this.toFontChar[charCode] = fontChar;
  25119. }
  25120. for (charCode in properties.differences) {
  25121. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  25122. if (!fontChar) {
  25123. continue;
  25124. }
  25125. this.toFontChar[charCode] = fontChar;
  25126. }
  25127. } else if (/Dingbats/i.test(fontName)) {
  25128. glyphsUnicodeMap = getDingbatsGlyphsUnicode();
  25129. if (/Wingdings/i.test(name)) {
  25130. warn('Wingdings font without embedded font file, ' +
  25131. 'falling back to the ZapfDingbats encoding.');
  25132. }
  25133. var dingbats = ZapfDingbatsEncoding;
  25134. for (charCode in dingbats) {
  25135. fontChar = glyphsUnicodeMap[dingbats[charCode]];
  25136. if (!fontChar) {
  25137. continue;
  25138. }
  25139. this.toFontChar[charCode] = fontChar;
  25140. }
  25141. for (charCode in properties.differences) {
  25142. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  25143. if (!fontChar) {
  25144. continue;
  25145. }
  25146. this.toFontChar[charCode] = fontChar;
  25147. }
  25148. } else if (isStandardFont) {
  25149. this.toFontChar = [];
  25150. glyphsUnicodeMap = getGlyphsUnicode();
  25151. for (charCode in properties.defaultEncoding) {
  25152. glyphName = (properties.differences[charCode] ||
  25153. properties.defaultEncoding[charCode]);
  25154. this.toFontChar[charCode] = glyphsUnicodeMap[glyphName];
  25155. }
  25156. } else {
  25157. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  25158. glyphsUnicodeMap = getGlyphsUnicode();
  25159. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  25160. if (notCidFont) {
  25161. glyphName = (properties.differences[charCode] ||
  25162. properties.defaultEncoding[charCode]);
  25163. unicodeCharCode = (glyphsUnicodeMap[glyphName] || unicodeCharCode);
  25164. }
  25165. this.toFontChar[charCode] = unicodeCharCode;
  25166. }.bind(this));
  25167. }
  25168. this.loadedName = fontName.split('-')[0];
  25169. this.loading = false;
  25170. this.fontType = getFontType(type, subtype);
  25171. return;
  25172. }
  25173. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  25174. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  25175. // Some TrueType fonts by mistake claim Type1C
  25176. if (isTrueTypeFile(file)) {
  25177. subtype = 'TrueType';
  25178. } else {
  25179. type = 'Type1';
  25180. }
  25181. }
  25182. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  25183. type = 'CIDFontType0';
  25184. }
  25185. if (subtype === 'OpenType') {
  25186. type = 'OpenType';
  25187. }
  25188. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  25189. if (type === 'CIDFontType0') {
  25190. if (isType1File(file)) {
  25191. subtype = 'CIDFontType0';
  25192. } else if (isOpenTypeFile(file)) {
  25193. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  25194. type = subtype = 'OpenType';
  25195. } else {
  25196. subtype = 'CIDFontType0C';
  25197. }
  25198. }
  25199. var data;
  25200. switch (type) {
  25201. case 'MMType1':
  25202. info('MMType1 font (' + name + '), falling back to Type1.');
  25203. /* falls through */
  25204. case 'Type1':
  25205. case 'CIDFontType0':
  25206. this.mimetype = 'font/opentype';
  25207. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  25208. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  25209. adjustWidths(properties);
  25210. // Wrap the CFF data inside an OTF font file
  25211. data = this.convert(name, cff, properties);
  25212. break;
  25213. case 'OpenType':
  25214. case 'TrueType':
  25215. case 'CIDFontType2':
  25216. this.mimetype = 'font/opentype';
  25217. // Repair the TrueType file. It is can be damaged in the point of
  25218. // view of the sanitizer
  25219. data = this.checkAndRepair(name, file, properties);
  25220. if (this.isOpenType) {
  25221. adjustWidths(properties);
  25222. type = 'OpenType';
  25223. }
  25224. break;
  25225. default:
  25226. error('Font ' + type + ' is not supported');
  25227. break;
  25228. }
  25229. this.data = data;
  25230. this.fontType = getFontType(type, subtype);
  25231. // Transfer some properties again that could change during font conversion
  25232. this.fontMatrix = properties.fontMatrix;
  25233. this.widths = properties.widths;
  25234. this.defaultWidth = properties.defaultWidth;
  25235. this.encoding = properties.baseEncoding;
  25236. this.seacMap = properties.seacMap;
  25237. this.loading = true;
  25238. }
  25239. Font.getFontID = (function () {
  25240. var ID = 1;
  25241. return function Font_getFontID() {
  25242. return String(ID++);
  25243. };
  25244. })();
  25245. function int16(b0, b1) {
  25246. return (b0 << 8) + b1;
  25247. }
  25248. function int32(b0, b1, b2, b3) {
  25249. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  25250. }
  25251. function string16(value) {
  25252. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25253. }
  25254. function safeString16(value) {
  25255. // clamp value to the 16-bit int range
  25256. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  25257. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  25258. }
  25259. function isTrueTypeFile(file) {
  25260. var header = file.peekBytes(4);
  25261. return readUint32(header, 0) === 0x00010000;
  25262. }
  25263. function isOpenTypeFile(file) {
  25264. var header = file.peekBytes(4);
  25265. return bytesToString(header) === 'OTTO';
  25266. }
  25267. function isType1File(file) {
  25268. var header = file.peekBytes(2);
  25269. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  25270. if (header[0] === 0x25 && header[1] === 0x21) {
  25271. return true;
  25272. }
  25273. // ... obviously some fonts violate that part of the specification,
  25274. // please refer to the comment in |Type1Font| below.
  25275. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  25276. return true;
  25277. }
  25278. return false;
  25279. }
  25280. /**
  25281. * Helper function for |adjustMapping|.
  25282. * @return {boolean}
  25283. */
  25284. function isProblematicUnicodeLocation(code) {
  25285. // Using binary search to find a range start.
  25286. var i = 0, j = ProblematicCharRanges.length - 1;
  25287. while (i < j) {
  25288. var c = (i + j + 1) >> 1;
  25289. if (code < ProblematicCharRanges[c]) {
  25290. j = c - 1;
  25291. } else {
  25292. i = c;
  25293. }
  25294. }
  25295. // Even index means code in problematic range.
  25296. return !(i & 1);
  25297. }
  25298. /**
  25299. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  25300. * with their unicode value. It also moves char codes that are in known
  25301. * problematic locations.
  25302. * @return {Object} Two properties:
  25303. * 'toFontChar' - maps original char codes(the value that will be read
  25304. * from commands such as show text) to the char codes that will be used in the
  25305. * font that we build
  25306. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  25307. */
  25308. function adjustMapping(charCodeToGlyphId, properties) {
  25309. var toUnicode = properties.toUnicode;
  25310. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  25311. var isIdentityUnicode =
  25312. properties.toUnicode instanceof IdentityToUnicodeMap;
  25313. var newMap = Object.create(null);
  25314. var toFontChar = [];
  25315. var usedFontCharCodes = [];
  25316. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  25317. for (var originalCharCode in charCodeToGlyphId) {
  25318. originalCharCode |= 0;
  25319. var glyphId = charCodeToGlyphId[originalCharCode];
  25320. var fontCharCode = originalCharCode;
  25321. // First try to map the value to a unicode position if a non identity map
  25322. // was created.
  25323. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  25324. var unicode = toUnicode.get(fontCharCode);
  25325. // TODO: Try to map ligatures to the correct spot.
  25326. if (unicode.length === 1) {
  25327. fontCharCode = unicode.charCodeAt(0);
  25328. }
  25329. }
  25330. // Try to move control characters, special characters and already mapped
  25331. // characters to the private use area since they will not be drawn by
  25332. // canvas if left in their current position. Also, move characters if the
  25333. // font was symbolic and there is only an identity unicode map since the
  25334. // characters probably aren't in the correct position (fixes an issue
  25335. // with firefox and thuluthfont).
  25336. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  25337. isProblematicUnicodeLocation(fontCharCode) ||
  25338. (isSymbolic && isIdentityUnicode)) &&
  25339. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  25340. // Loop to try and find a free spot in the private use area.
  25341. do {
  25342. fontCharCode = nextAvailableFontCharCode++;
  25343. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  25344. fontCharCode = 0xF020;
  25345. nextAvailableFontCharCode = fontCharCode + 1;
  25346. }
  25347. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  25348. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  25349. }
  25350. newMap[fontCharCode] = glyphId;
  25351. toFontChar[originalCharCode] = fontCharCode;
  25352. usedFontCharCodes[fontCharCode] = true;
  25353. }
  25354. return {
  25355. toFontChar: toFontChar,
  25356. charCodeToGlyphId: newMap,
  25357. nextAvailableFontCharCode: nextAvailableFontCharCode
  25358. };
  25359. }
  25360. function getRanges(glyphs, numGlyphs) {
  25361. // Array.sort() sorts by characters, not numerically, so convert to an
  25362. // array of characters.
  25363. var codes = [];
  25364. for (var charCode in glyphs) {
  25365. // Remove an invalid glyph ID mappings to make OTS happy.
  25366. if (glyphs[charCode] >= numGlyphs) {
  25367. continue;
  25368. }
  25369. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  25370. }
  25371. codes.sort(function fontGetRangesSort(a, b) {
  25372. return a.fontCharCode - b.fontCharCode;
  25373. });
  25374. // Split the sorted codes into ranges.
  25375. var ranges = [];
  25376. var length = codes.length;
  25377. for (var n = 0; n < length; ) {
  25378. var start = codes[n].fontCharCode;
  25379. var codeIndices = [codes[n].glyphId];
  25380. ++n;
  25381. var end = start;
  25382. while (n < length && end + 1 === codes[n].fontCharCode) {
  25383. codeIndices.push(codes[n].glyphId);
  25384. ++end;
  25385. ++n;
  25386. if (end === 0xFFFF) {
  25387. break;
  25388. }
  25389. }
  25390. ranges.push([start, end, codeIndices]);
  25391. }
  25392. return ranges;
  25393. }
  25394. function createCmapTable(glyphs, numGlyphs) {
  25395. var ranges = getRanges(glyphs, numGlyphs);
  25396. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  25397. var cmap = '\x00\x00' + // version
  25398. string16(numTables) + // numTables
  25399. '\x00\x03' + // platformID
  25400. '\x00\x01' + // encodingID
  25401. string32(4 + numTables * 8); // start of the table record
  25402. var i, ii, j, jj;
  25403. for (i = ranges.length - 1; i >= 0; --i) {
  25404. if (ranges[i][0] <= 0xFFFF) { break; }
  25405. }
  25406. var bmpLength = i + 1;
  25407. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  25408. ranges[i][1] = 0xFFFE;
  25409. }
  25410. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  25411. var segCount = bmpLength + trailingRangesCount;
  25412. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  25413. // Fill up the 4 parallel arrays describing the segments.
  25414. var startCount = '';
  25415. var endCount = '';
  25416. var idDeltas = '';
  25417. var idRangeOffsets = '';
  25418. var glyphsIds = '';
  25419. var bias = 0;
  25420. var range, start, end, codes;
  25421. for (i = 0, ii = bmpLength; i < ii; i++) {
  25422. range = ranges[i];
  25423. start = range[0];
  25424. end = range[1];
  25425. startCount += string16(start);
  25426. endCount += string16(end);
  25427. codes = range[2];
  25428. var contiguous = true;
  25429. for (j = 1, jj = codes.length; j < jj; ++j) {
  25430. if (codes[j] !== codes[j - 1] + 1) {
  25431. contiguous = false;
  25432. break;
  25433. }
  25434. }
  25435. if (!contiguous) {
  25436. var offset = (segCount - i) * 2 + bias * 2;
  25437. bias += (end - start + 1);
  25438. idDeltas += string16(0);
  25439. idRangeOffsets += string16(offset);
  25440. for (j = 0, jj = codes.length; j < jj; ++j) {
  25441. glyphsIds += string16(codes[j]);
  25442. }
  25443. } else {
  25444. var startCode = codes[0];
  25445. idDeltas += string16((startCode - start) & 0xFFFF);
  25446. idRangeOffsets += string16(0);
  25447. }
  25448. }
  25449. if (trailingRangesCount > 0) {
  25450. endCount += '\xFF\xFF';
  25451. startCount += '\xFF\xFF';
  25452. idDeltas += '\x00\x01';
  25453. idRangeOffsets += '\x00\x00';
  25454. }
  25455. var format314 = '\x00\x00' + // language
  25456. string16(2 * segCount) +
  25457. string16(searchParams.range) +
  25458. string16(searchParams.entry) +
  25459. string16(searchParams.rangeShift) +
  25460. endCount + '\x00\x00' + startCount +
  25461. idDeltas + idRangeOffsets + glyphsIds;
  25462. var format31012 = '';
  25463. var header31012 = '';
  25464. if (numTables > 1) {
  25465. cmap += '\x00\x03' + // platformID
  25466. '\x00\x0A' + // encodingID
  25467. string32(4 + numTables * 8 +
  25468. 4 + format314.length); // start of the table record
  25469. format31012 = '';
  25470. for (i = 0, ii = ranges.length; i < ii; i++) {
  25471. range = ranges[i];
  25472. start = range[0];
  25473. codes = range[2];
  25474. var code = codes[0];
  25475. for (j = 1, jj = codes.length; j < jj; ++j) {
  25476. if (codes[j] !== codes[j - 1] + 1) {
  25477. end = range[0] + j - 1;
  25478. format31012 += string32(start) + // startCharCode
  25479. string32(end) + // endCharCode
  25480. string32(code); // startGlyphID
  25481. start = end + 1;
  25482. code = codes[j];
  25483. }
  25484. }
  25485. format31012 += string32(start) + // startCharCode
  25486. string32(range[1]) + // endCharCode
  25487. string32(code); // startGlyphID
  25488. }
  25489. header31012 = '\x00\x0C' + // format
  25490. '\x00\x00' + // reserved
  25491. string32(format31012.length + 16) + // length
  25492. '\x00\x00\x00\x00' + // language
  25493. string32(format31012.length / 12); // nGroups
  25494. }
  25495. return cmap + '\x00\x04' + // format
  25496. string16(format314.length + 4) + // length
  25497. format314 + header31012 + format31012;
  25498. }
  25499. function validateOS2Table(os2) {
  25500. var stream = new Stream(os2.data);
  25501. var version = stream.getUint16();
  25502. // TODO verify all OS/2 tables fields, but currently we validate only those
  25503. // that give us issues
  25504. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  25505. var selection = stream.getUint16();
  25506. if (version < 4 && (selection & 0x0300)) {
  25507. return false;
  25508. }
  25509. var firstChar = stream.getUint16();
  25510. var lastChar = stream.getUint16();
  25511. if (firstChar > lastChar) {
  25512. return false;
  25513. }
  25514. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  25515. var usWinAscent = stream.getUint16();
  25516. if (usWinAscent === 0) { // makes font unreadable by windows
  25517. return false;
  25518. }
  25519. // OS/2 appears to be valid, resetting some fields
  25520. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  25521. return true;
  25522. }
  25523. function createOS2Table(properties, charstrings, override) {
  25524. override = override || {
  25525. unitsPerEm: 0,
  25526. yMax: 0,
  25527. yMin: 0,
  25528. ascent: 0,
  25529. descent: 0
  25530. };
  25531. var ulUnicodeRange1 = 0;
  25532. var ulUnicodeRange2 = 0;
  25533. var ulUnicodeRange3 = 0;
  25534. var ulUnicodeRange4 = 0;
  25535. var firstCharIndex = null;
  25536. var lastCharIndex = 0;
  25537. if (charstrings) {
  25538. for (var code in charstrings) {
  25539. code |= 0;
  25540. if (firstCharIndex > code || !firstCharIndex) {
  25541. firstCharIndex = code;
  25542. }
  25543. if (lastCharIndex < code) {
  25544. lastCharIndex = code;
  25545. }
  25546. var position = getUnicodeRangeFor(code);
  25547. if (position < 32) {
  25548. ulUnicodeRange1 |= 1 << position;
  25549. } else if (position < 64) {
  25550. ulUnicodeRange2 |= 1 << position - 32;
  25551. } else if (position < 96) {
  25552. ulUnicodeRange3 |= 1 << position - 64;
  25553. } else if (position < 123) {
  25554. ulUnicodeRange4 |= 1 << position - 96;
  25555. } else {
  25556. error('Unicode ranges Bits > 123 are reserved for internal usage');
  25557. }
  25558. }
  25559. } else {
  25560. // TODO
  25561. firstCharIndex = 0;
  25562. lastCharIndex = 255;
  25563. }
  25564. var bbox = properties.bbox || [0, 0, 0, 0];
  25565. var unitsPerEm = (override.unitsPerEm ||
  25566. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  25567. // if the font units differ to the PDF glyph space units
  25568. // then scale up the values
  25569. var scale = (properties.ascentScaled ? 1.0 :
  25570. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  25571. var typoAscent = (override.ascent ||
  25572. Math.round(scale * (properties.ascent || bbox[3])));
  25573. var typoDescent = (override.descent ||
  25574. Math.round(scale * (properties.descent || bbox[1])));
  25575. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  25576. typoDescent = -typoDescent; // fixing incorrect descent
  25577. }
  25578. var winAscent = override.yMax || typoAscent;
  25579. var winDescent = -override.yMin || -typoDescent;
  25580. return '\x00\x03' + // version
  25581. '\x02\x24' + // xAvgCharWidth
  25582. '\x01\xF4' + // usWeightClass
  25583. '\x00\x05' + // usWidthClass
  25584. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  25585. '\x02\x8A' + // ySubscriptXSize
  25586. '\x02\xBB' + // ySubscriptYSize
  25587. '\x00\x00' + // ySubscriptXOffset
  25588. '\x00\x8C' + // ySubscriptYOffset
  25589. '\x02\x8A' + // ySuperScriptXSize
  25590. '\x02\xBB' + // ySuperScriptYSize
  25591. '\x00\x00' + // ySuperScriptXOffset
  25592. '\x01\xDF' + // ySuperScriptYOffset
  25593. '\x00\x31' + // yStrikeOutSize
  25594. '\x01\x02' + // yStrikeOutPosition
  25595. '\x00\x00' + // sFamilyClass
  25596. '\x00\x00\x06' +
  25597. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  25598. '\x00\x00\x00\x00\x00\x00' + // Panose
  25599. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  25600. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  25601. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  25602. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  25603. '\x2A\x32\x31\x2A' + // achVendID
  25604. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  25605. string16(firstCharIndex ||
  25606. properties.firstChar) + // usFirstCharIndex
  25607. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  25608. string16(typoAscent) + // sTypoAscender
  25609. string16(typoDescent) + // sTypoDescender
  25610. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  25611. string16(winAscent) + // usWinAscent
  25612. string16(winDescent) + // usWinDescent
  25613. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  25614. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  25615. string16(properties.xHeight) + // sxHeight
  25616. string16(properties.capHeight) + // sCapHeight
  25617. string16(0) + // usDefaultChar
  25618. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  25619. '\x00\x03'; // usMaxContext
  25620. }
  25621. function createPostTable(properties) {
  25622. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  25623. return ('\x00\x03\x00\x00' + // Version number
  25624. string32(angle) + // italicAngle
  25625. '\x00\x00' + // underlinePosition
  25626. '\x00\x00' + // underlineThickness
  25627. string32(properties.fixedPitch) + // isFixedPitch
  25628. '\x00\x00\x00\x00' + // minMemType42
  25629. '\x00\x00\x00\x00' + // maxMemType42
  25630. '\x00\x00\x00\x00' + // minMemType1
  25631. '\x00\x00\x00\x00'); // maxMemType1
  25632. }
  25633. function createNameTable(name, proto) {
  25634. if (!proto) {
  25635. proto = [[], []]; // no strings and unicode strings
  25636. }
  25637. var strings = [
  25638. proto[0][0] || 'Original licence', // 0.Copyright
  25639. proto[0][1] || name, // 1.Font family
  25640. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  25641. proto[0][3] || 'uniqueID', // 3.Unique ID
  25642. proto[0][4] || name, // 4.Full font name
  25643. proto[0][5] || 'Version 0.11', // 5.Version
  25644. proto[0][6] || '', // 6.Postscript name
  25645. proto[0][7] || 'Unknown', // 7.Trademark
  25646. proto[0][8] || 'Unknown', // 8.Manufacturer
  25647. proto[0][9] || 'Unknown' // 9.Designer
  25648. ];
  25649. // Mac want 1-byte per character strings while Windows want
  25650. // 2-bytes per character, so duplicate the names table
  25651. var stringsUnicode = [];
  25652. var i, ii, j, jj, str;
  25653. for (i = 0, ii = strings.length; i < ii; i++) {
  25654. str = proto[1][i] || strings[i];
  25655. var strBufUnicode = [];
  25656. for (j = 0, jj = str.length; j < jj; j++) {
  25657. strBufUnicode.push(string16(str.charCodeAt(j)));
  25658. }
  25659. stringsUnicode.push(strBufUnicode.join(''));
  25660. }
  25661. var names = [strings, stringsUnicode];
  25662. var platforms = ['\x00\x01', '\x00\x03'];
  25663. var encodings = ['\x00\x00', '\x00\x01'];
  25664. var languages = ['\x00\x00', '\x04\x09'];
  25665. var namesRecordCount = strings.length * platforms.length;
  25666. var nameTable =
  25667. '\x00\x00' + // format
  25668. string16(namesRecordCount) + // Number of names Record
  25669. string16(namesRecordCount * 12 + 6); // Storage
  25670. // Build the name records field
  25671. var strOffset = 0;
  25672. for (i = 0, ii = platforms.length; i < ii; i++) {
  25673. var strs = names[i];
  25674. for (j = 0, jj = strs.length; j < jj; j++) {
  25675. str = strs[j];
  25676. var nameRecord =
  25677. platforms[i] + // platform ID
  25678. encodings[i] + // encoding ID
  25679. languages[i] + // language ID
  25680. string16(j) + // name ID
  25681. string16(str.length) +
  25682. string16(strOffset);
  25683. nameTable += nameRecord;
  25684. strOffset += str.length;
  25685. }
  25686. }
  25687. nameTable += strings.join('') + stringsUnicode.join('');
  25688. return nameTable;
  25689. }
  25690. Font.prototype = {
  25691. name: null,
  25692. font: null,
  25693. mimetype: null,
  25694. encoding: null,
  25695. get renderer() {
  25696. var renderer = FontRendererFactory.create(this);
  25697. return shadow(this, 'renderer', renderer);
  25698. },
  25699. exportData: function Font_exportData() {
  25700. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  25701. var data = {};
  25702. for (var i in this) {
  25703. if (this.hasOwnProperty(i)) {
  25704. data[i] = this[i];
  25705. }
  25706. }
  25707. return data;
  25708. },
  25709. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  25710. function readTableEntry(file) {
  25711. var tag = bytesToString(file.getBytes(4));
  25712. var checksum = file.getInt32();
  25713. var offset = file.getInt32() >>> 0;
  25714. var length = file.getInt32() >>> 0;
  25715. // Read the table associated data
  25716. var previousPosition = file.pos;
  25717. file.pos = file.start ? file.start : 0;
  25718. file.skip(offset);
  25719. var data = file.getBytes(length);
  25720. file.pos = previousPosition;
  25721. if (tag === 'head') {
  25722. // clearing checksum adjustment
  25723. data[8] = data[9] = data[10] = data[11] = 0;
  25724. data[17] |= 0x20; //Set font optimized for cleartype flag
  25725. }
  25726. return {
  25727. tag: tag,
  25728. checksum: checksum,
  25729. length: length,
  25730. offset: offset,
  25731. data: data
  25732. };
  25733. }
  25734. function readOpenTypeHeader(ttf) {
  25735. return {
  25736. version: bytesToString(ttf.getBytes(4)),
  25737. numTables: ttf.getUint16(),
  25738. searchRange: ttf.getUint16(),
  25739. entrySelector: ttf.getUint16(),
  25740. rangeShift: ttf.getUint16()
  25741. };
  25742. }
  25743. /**
  25744. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  25745. * PDF spec
  25746. */
  25747. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  25748. if (!cmap) {
  25749. warn('No cmap table available.');
  25750. return {
  25751. platformId: -1,
  25752. encodingId: -1,
  25753. mappings: [],
  25754. hasShortCmap: false
  25755. };
  25756. }
  25757. var segment;
  25758. var start = (font.start ? font.start : 0) + cmap.offset;
  25759. font.pos = start;
  25760. var version = font.getUint16();
  25761. var numTables = font.getUint16();
  25762. var potentialTable;
  25763. var canBreak = false;
  25764. // There's an order of preference in terms of which cmap subtable to
  25765. // use:
  25766. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  25767. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  25768. // The following takes advantage of the fact that the tables are sorted
  25769. // to work.
  25770. for (var i = 0; i < numTables; i++) {
  25771. var platformId = font.getUint16();
  25772. var encodingId = font.getUint16();
  25773. var offset = font.getInt32() >>> 0;
  25774. var useTable = false;
  25775. if (platformId === 0 && encodingId === 0) {
  25776. useTable = true;
  25777. // Continue the loop since there still may be a higher priority
  25778. // table.
  25779. } else if (platformId === 1 && encodingId === 0) {
  25780. useTable = true;
  25781. // Continue the loop since there still may be a higher priority
  25782. // table.
  25783. } else if (platformId === 3 && encodingId === 1 &&
  25784. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  25785. useTable = true;
  25786. if (!isSymbolicFont) {
  25787. canBreak = true;
  25788. }
  25789. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  25790. useTable = true;
  25791. canBreak = true;
  25792. }
  25793. if (useTable) {
  25794. potentialTable = {
  25795. platformId: platformId,
  25796. encodingId: encodingId,
  25797. offset: offset
  25798. };
  25799. }
  25800. if (canBreak) {
  25801. break;
  25802. }
  25803. }
  25804. if (potentialTable) {
  25805. font.pos = start + potentialTable.offset;
  25806. }
  25807. if (!potentialTable || font.peekByte() === -1) {
  25808. warn('Could not find a preferred cmap table.');
  25809. return {
  25810. platformId: -1,
  25811. encodingId: -1,
  25812. mappings: [],
  25813. hasShortCmap: false
  25814. };
  25815. }
  25816. var format = font.getUint16();
  25817. var length = font.getUint16();
  25818. var language = font.getUint16();
  25819. var hasShortCmap = false;
  25820. var mappings = [];
  25821. var j, glyphId;
  25822. // TODO(mack): refactor this cmap subtable reading logic out
  25823. if (format === 0) {
  25824. for (j = 0; j < 256; j++) {
  25825. var index = font.getByte();
  25826. if (!index) {
  25827. continue;
  25828. }
  25829. mappings.push({
  25830. charCode: j,
  25831. glyphId: index
  25832. });
  25833. }
  25834. hasShortCmap = true;
  25835. } else if (format === 4) {
  25836. // re-creating the table in format 4 since the encoding
  25837. // might be changed
  25838. var segCount = (font.getUint16() >> 1);
  25839. font.getBytes(6); // skipping range fields
  25840. var segIndex, segments = [];
  25841. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25842. segments.push({ end: font.getUint16() });
  25843. }
  25844. font.getUint16();
  25845. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25846. segments[segIndex].start = font.getUint16();
  25847. }
  25848. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25849. segments[segIndex].delta = font.getUint16();
  25850. }
  25851. var offsetsCount = 0;
  25852. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25853. segment = segments[segIndex];
  25854. var rangeOffset = font.getUint16();
  25855. if (!rangeOffset) {
  25856. segment.offsetIndex = -1;
  25857. continue;
  25858. }
  25859. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  25860. segment.offsetIndex = offsetIndex;
  25861. offsetsCount = Math.max(offsetsCount, offsetIndex +
  25862. segment.end - segment.start + 1);
  25863. }
  25864. var offsets = [];
  25865. for (j = 0; j < offsetsCount; j++) {
  25866. offsets.push(font.getUint16());
  25867. }
  25868. for (segIndex = 0; segIndex < segCount; segIndex++) {
  25869. segment = segments[segIndex];
  25870. start = segment.start;
  25871. var end = segment.end;
  25872. var delta = segment.delta;
  25873. offsetIndex = segment.offsetIndex;
  25874. for (j = start; j <= end; j++) {
  25875. if (j === 0xFFFF) {
  25876. continue;
  25877. }
  25878. glyphId = (offsetIndex < 0 ?
  25879. j : offsets[offsetIndex + j - start]);
  25880. glyphId = (glyphId + delta) & 0xFFFF;
  25881. if (glyphId === 0) {
  25882. continue;
  25883. }
  25884. mappings.push({
  25885. charCode: j,
  25886. glyphId: glyphId
  25887. });
  25888. }
  25889. }
  25890. } else if (format === 6) {
  25891. // Format 6 is a 2-bytes dense mapping, which means the font data
  25892. // lives glue together even if they are pretty far in the unicode
  25893. // table. (This looks weird, so I can have missed something), this
  25894. // works on Linux but seems to fails on Mac so let's rewrite the
  25895. // cmap table to a 3-1-4 style
  25896. var firstCode = font.getUint16();
  25897. var entryCount = font.getUint16();
  25898. for (j = 0; j < entryCount; j++) {
  25899. glyphId = font.getUint16();
  25900. var charCode = firstCode + j;
  25901. mappings.push({
  25902. charCode: charCode,
  25903. glyphId: glyphId
  25904. });
  25905. }
  25906. } else {
  25907. warn('cmap table has unsupported format: ' + format);
  25908. return {
  25909. platformId: -1,
  25910. encodingId: -1,
  25911. mappings: [],
  25912. hasShortCmap: false
  25913. };
  25914. }
  25915. // removing duplicate entries
  25916. mappings.sort(function (a, b) {
  25917. return a.charCode - b.charCode;
  25918. });
  25919. for (i = 1; i < mappings.length; i++) {
  25920. if (mappings[i - 1].charCode === mappings[i].charCode) {
  25921. mappings.splice(i, 1);
  25922. i--;
  25923. }
  25924. }
  25925. return {
  25926. platformId: potentialTable.platformId,
  25927. encodingId: potentialTable.encodingId,
  25928. mappings: mappings,
  25929. hasShortCmap: hasShortCmap
  25930. };
  25931. }
  25932. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  25933. if (!header) {
  25934. if (metrics) {
  25935. metrics.data = null;
  25936. }
  25937. return;
  25938. }
  25939. font.pos = (font.start ? font.start : 0) + header.offset;
  25940. font.pos += header.length - 2;
  25941. var numOfMetrics = font.getUint16();
  25942. if (numOfMetrics > numGlyphs) {
  25943. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  25944. 'greater than the numGlyphs (' + numGlyphs + ')');
  25945. // Reduce numOfMetrics if it is greater than numGlyphs
  25946. numOfMetrics = numGlyphs;
  25947. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  25948. header.data[35] = numOfMetrics & 0x00ff;
  25949. }
  25950. var numOfSidebearings = numGlyphs - numOfMetrics;
  25951. var numMissing = numOfSidebearings -
  25952. ((metrics.length - numOfMetrics * 4) >> 1);
  25953. if (numMissing > 0) {
  25954. // For each missing glyph, we set both the width and lsb to 0 (zero).
  25955. // Since we need to add two properties for each glyph, this explains
  25956. // the use of |numMissing * 2| when initializing the typed array.
  25957. var entries = new Uint8Array(metrics.length + numMissing * 2);
  25958. entries.set(metrics.data);
  25959. metrics.data = entries;
  25960. }
  25961. }
  25962. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  25963. hintsValid) {
  25964. if (sourceEnd - sourceStart <= 12) {
  25965. // glyph with data less than 12 is invalid one
  25966. return 0;
  25967. }
  25968. var glyf = source.subarray(sourceStart, sourceEnd);
  25969. var contoursCount = (glyf[0] << 8) | glyf[1];
  25970. if (contoursCount & 0x8000) {
  25971. // complex glyph, writing as is
  25972. dest.set(glyf, destStart);
  25973. return glyf.length;
  25974. }
  25975. var i, j = 10, flagsCount = 0;
  25976. for (i = 0; i < contoursCount; i++) {
  25977. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  25978. flagsCount = endPoint + 1;
  25979. j += 2;
  25980. }
  25981. // skipping instructions
  25982. var instructionsStart = j;
  25983. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  25984. j += 2 + instructionsLength;
  25985. var instructionsEnd = j;
  25986. // validating flags
  25987. var coordinatesLength = 0;
  25988. for (i = 0; i < flagsCount; i++) {
  25989. var flag = glyf[j++];
  25990. if (flag & 0xC0) {
  25991. // reserved flags must be zero, cleaning up
  25992. glyf[j - 1] = flag & 0x3F;
  25993. }
  25994. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  25995. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  25996. coordinatesLength += xyLength;
  25997. if (flag & 8) {
  25998. var repeat = glyf[j++];
  25999. i += repeat;
  26000. coordinatesLength += repeat * xyLength;
  26001. }
  26002. }
  26003. // glyph without coordinates will be rejected
  26004. if (coordinatesLength === 0) {
  26005. return 0;
  26006. }
  26007. var glyphDataLength = j + coordinatesLength;
  26008. if (glyphDataLength > glyf.length) {
  26009. // not enough data for coordinates
  26010. return 0;
  26011. }
  26012. if (!hintsValid && instructionsLength > 0) {
  26013. dest.set(glyf.subarray(0, instructionsStart), destStart);
  26014. dest.set([0, 0], destStart + instructionsStart);
  26015. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  26016. destStart + instructionsStart + 2);
  26017. glyphDataLength -= instructionsLength;
  26018. if (glyf.length - glyphDataLength > 3) {
  26019. glyphDataLength = (glyphDataLength + 3) & ~3;
  26020. }
  26021. return glyphDataLength;
  26022. }
  26023. if (glyf.length - glyphDataLength > 3) {
  26024. // truncating and aligning to 4 bytes the long glyph data
  26025. glyphDataLength = (glyphDataLength + 3) & ~3;
  26026. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  26027. return glyphDataLength;
  26028. }
  26029. // glyph data is fine
  26030. dest.set(glyf, destStart);
  26031. return glyf.length;
  26032. }
  26033. function sanitizeHead(head, numGlyphs, locaLength) {
  26034. var data = head.data;
  26035. // Validate version:
  26036. // Should always be 0x00010000
  26037. var version = int32(data[0], data[1], data[2], data[3]);
  26038. if (version >> 16 !== 1) {
  26039. info('Attempting to fix invalid version in head table: ' + version);
  26040. data[0] = 0;
  26041. data[1] = 1;
  26042. data[2] = 0;
  26043. data[3] = 0;
  26044. }
  26045. var indexToLocFormat = int16(data[50], data[51]);
  26046. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  26047. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  26048. indexToLocFormat);
  26049. // The value of indexToLocFormat should be 0 if the loca table
  26050. // consists of short offsets, and should be 1 if the loca table
  26051. // consists of long offsets.
  26052. //
  26053. // The number of entries in the loca table should be numGlyphs + 1.
  26054. //
  26055. // Using this information, we can work backwards to deduce if the
  26056. // size of each offset in the loca table, and thus figure out the
  26057. // appropriate value for indexToLocFormat.
  26058. var numGlyphsPlusOne = numGlyphs + 1;
  26059. if (locaLength === numGlyphsPlusOne << 1) {
  26060. // 0x0000 indicates the loca table consists of short offsets
  26061. data[50] = 0;
  26062. data[51] = 0;
  26063. } else if (locaLength === numGlyphsPlusOne << 2) {
  26064. // 0x0001 indicates the loca table consists of long offsets
  26065. data[50] = 0;
  26066. data[51] = 1;
  26067. } else {
  26068. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  26069. }
  26070. }
  26071. }
  26072. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  26073. isGlyphLocationsLong, hintsValid,
  26074. dupFirstEntry) {
  26075. var itemSize, itemDecode, itemEncode;
  26076. if (isGlyphLocationsLong) {
  26077. itemSize = 4;
  26078. itemDecode = function fontItemDecodeLong(data, offset) {
  26079. return (data[offset] << 24) | (data[offset + 1] << 16) |
  26080. (data[offset + 2] << 8) | data[offset + 3];
  26081. };
  26082. itemEncode = function fontItemEncodeLong(data, offset, value) {
  26083. data[offset] = (value >>> 24) & 0xFF;
  26084. data[offset + 1] = (value >> 16) & 0xFF;
  26085. data[offset + 2] = (value >> 8) & 0xFF;
  26086. data[offset + 3] = value & 0xFF;
  26087. };
  26088. } else {
  26089. itemSize = 2;
  26090. itemDecode = function fontItemDecode(data, offset) {
  26091. return (data[offset] << 9) | (data[offset + 1] << 1);
  26092. };
  26093. itemEncode = function fontItemEncode(data, offset, value) {
  26094. data[offset] = (value >> 9) & 0xFF;
  26095. data[offset + 1] = (value >> 1) & 0xFF;
  26096. };
  26097. }
  26098. var locaData = loca.data;
  26099. var locaDataSize = itemSize * (1 + numGlyphs);
  26100. // is loca.data too short or long?
  26101. if (locaData.length !== locaDataSize) {
  26102. locaData = new Uint8Array(locaDataSize);
  26103. locaData.set(loca.data.subarray(0, locaDataSize));
  26104. loca.data = locaData;
  26105. }
  26106. // removing the invalid glyphs
  26107. var oldGlyfData = glyf.data;
  26108. var oldGlyfDataLength = oldGlyfData.length;
  26109. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  26110. var startOffset = itemDecode(locaData, 0);
  26111. var writeOffset = 0;
  26112. var missingGlyphData = Object.create(null);
  26113. itemEncode(locaData, 0, writeOffset);
  26114. var i, j;
  26115. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26116. var endOffset = itemDecode(locaData, j);
  26117. if (endOffset > oldGlyfDataLength &&
  26118. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  26119. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  26120. // the glyf table size, which makes last glyph out of range.
  26121. endOffset = oldGlyfDataLength;
  26122. }
  26123. if (endOffset > oldGlyfDataLength) {
  26124. // glyph end offset points outside glyf data, rejecting the glyph
  26125. itemEncode(locaData, j, writeOffset);
  26126. startOffset = endOffset;
  26127. continue;
  26128. }
  26129. if (startOffset === endOffset) {
  26130. missingGlyphData[i] = true;
  26131. }
  26132. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  26133. newGlyfData, writeOffset, hintsValid);
  26134. writeOffset += newLength;
  26135. itemEncode(locaData, j, writeOffset);
  26136. startOffset = endOffset;
  26137. }
  26138. if (writeOffset === 0) {
  26139. // glyf table cannot be empty -- redoing the glyf and loca tables
  26140. // to have single glyph with one point
  26141. var simpleGlyph = new Uint8Array(
  26142. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  26143. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  26144. itemEncode(locaData, j, simpleGlyph.length);
  26145. }
  26146. glyf.data = simpleGlyph;
  26147. return missingGlyphData;
  26148. }
  26149. if (dupFirstEntry) {
  26150. var firstEntryLength = itemDecode(locaData, itemSize);
  26151. if (newGlyfData.length > firstEntryLength + writeOffset) {
  26152. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  26153. } else {
  26154. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  26155. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  26156. }
  26157. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  26158. itemEncode(loca.data, locaData.length - itemSize,
  26159. writeOffset + firstEntryLength);
  26160. } else {
  26161. glyf.data = newGlyfData.subarray(0, writeOffset);
  26162. }
  26163. return missingGlyphData;
  26164. }
  26165. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  26166. var start = (font.start ? font.start : 0) + post.offset;
  26167. font.pos = start;
  26168. var length = post.length, end = start + length;
  26169. var version = font.getInt32();
  26170. // skip rest to the tables
  26171. font.getBytes(28);
  26172. var glyphNames;
  26173. var valid = true;
  26174. var i;
  26175. switch (version) {
  26176. case 0x00010000:
  26177. glyphNames = MacStandardGlyphOrdering;
  26178. break;
  26179. case 0x00020000:
  26180. var numGlyphs = font.getUint16();
  26181. if (numGlyphs !== maxpNumGlyphs) {
  26182. valid = false;
  26183. break;
  26184. }
  26185. var glyphNameIndexes = [];
  26186. for (i = 0; i < numGlyphs; ++i) {
  26187. var index = font.getUint16();
  26188. if (index >= 32768) {
  26189. valid = false;
  26190. break;
  26191. }
  26192. glyphNameIndexes.push(index);
  26193. }
  26194. if (!valid) {
  26195. break;
  26196. }
  26197. var customNames = [];
  26198. var strBuf = [];
  26199. while (font.pos < end) {
  26200. var stringLength = font.getByte();
  26201. strBuf.length = stringLength;
  26202. for (i = 0; i < stringLength; ++i) {
  26203. strBuf[i] = String.fromCharCode(font.getByte());
  26204. }
  26205. customNames.push(strBuf.join(''));
  26206. }
  26207. glyphNames = [];
  26208. for (i = 0; i < numGlyphs; ++i) {
  26209. var j = glyphNameIndexes[i];
  26210. if (j < 258) {
  26211. glyphNames.push(MacStandardGlyphOrdering[j]);
  26212. continue;
  26213. }
  26214. glyphNames.push(customNames[j - 258]);
  26215. }
  26216. break;
  26217. case 0x00030000:
  26218. break;
  26219. default:
  26220. warn('Unknown/unsupported post table version ' + version);
  26221. valid = false;
  26222. if (properties.defaultEncoding) {
  26223. glyphNames = properties.defaultEncoding;
  26224. }
  26225. break;
  26226. }
  26227. properties.glyphNames = glyphNames;
  26228. return valid;
  26229. }
  26230. function readNameTable(nameTable) {
  26231. var start = (font.start ? font.start : 0) + nameTable.offset;
  26232. font.pos = start;
  26233. var names = [[], []];
  26234. var length = nameTable.length, end = start + length;
  26235. var format = font.getUint16();
  26236. var FORMAT_0_HEADER_LENGTH = 6;
  26237. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  26238. // unsupported name table format or table "too" small
  26239. return names;
  26240. }
  26241. var numRecords = font.getUint16();
  26242. var stringsStart = font.getUint16();
  26243. var records = [];
  26244. var NAME_RECORD_LENGTH = 12;
  26245. var i, ii;
  26246. for (i = 0; i < numRecords &&
  26247. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  26248. var r = {
  26249. platform: font.getUint16(),
  26250. encoding: font.getUint16(),
  26251. language: font.getUint16(),
  26252. name: font.getUint16(),
  26253. length: font.getUint16(),
  26254. offset: font.getUint16()
  26255. };
  26256. // using only Macintosh and Windows platform/encoding names
  26257. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  26258. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  26259. records.push(r);
  26260. }
  26261. }
  26262. for (i = 0, ii = records.length; i < ii; i++) {
  26263. var record = records[i];
  26264. var pos = start + stringsStart + record.offset;
  26265. if (pos + record.length > end) {
  26266. continue; // outside of name table, ignoring
  26267. }
  26268. font.pos = pos;
  26269. var nameIndex = record.name;
  26270. if (record.encoding) {
  26271. // unicode
  26272. var str = '';
  26273. for (var j = 0, jj = record.length; j < jj; j += 2) {
  26274. str += String.fromCharCode(font.getUint16());
  26275. }
  26276. names[1][nameIndex] = str;
  26277. } else {
  26278. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  26279. }
  26280. }
  26281. return names;
  26282. }
  26283. var TTOpsStackDeltas = [
  26284. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  26285. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  26286. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  26287. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  26288. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  26289. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  26290. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  26291. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  26292. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  26293. // 0xC0-DF == -1 and 0xE0-FF == -2
  26294. function sanitizeTTProgram(table, ttContext) {
  26295. var data = table.data;
  26296. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  26297. var stack = [];
  26298. var callstack = [];
  26299. var functionsCalled = [];
  26300. var tooComplexToFollowFunctions =
  26301. ttContext.tooComplexToFollowFunctions;
  26302. var inFDEF = false, ifLevel = 0, inELSE = 0;
  26303. for (var ii = data.length; i < ii;) {
  26304. var op = data[i++];
  26305. // The TrueType instruction set docs can be found at
  26306. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  26307. if (op === 0x40) { // NPUSHB - pushes n bytes
  26308. n = data[i++];
  26309. if (inFDEF || inELSE) {
  26310. i += n;
  26311. } else {
  26312. for (j = 0; j < n; j++) {
  26313. stack.push(data[i++]);
  26314. }
  26315. }
  26316. } else if (op === 0x41) { // NPUSHW - pushes n words
  26317. n = data[i++];
  26318. if (inFDEF || inELSE) {
  26319. i += n * 2;
  26320. } else {
  26321. for (j = 0; j < n; j++) {
  26322. b = data[i++];
  26323. stack.push((b << 8) | data[i++]);
  26324. }
  26325. }
  26326. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  26327. n = op - 0xB0 + 1;
  26328. if (inFDEF || inELSE) {
  26329. i += n;
  26330. } else {
  26331. for (j = 0; j < n; j++) {
  26332. stack.push(data[i++]);
  26333. }
  26334. }
  26335. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  26336. n = op - 0xB8 + 1;
  26337. if (inFDEF || inELSE) {
  26338. i += n * 2;
  26339. } else {
  26340. for (j = 0; j < n; j++) {
  26341. b = data[i++];
  26342. stack.push((b << 8) | data[i++]);
  26343. }
  26344. }
  26345. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  26346. if (!inFDEF && !inELSE) {
  26347. // collecting inforamtion about which functions are used
  26348. funcId = stack[stack.length - 1];
  26349. ttContext.functionsUsed[funcId] = true;
  26350. if (funcId in ttContext.functionsStackDeltas) {
  26351. stack.length += ttContext.functionsStackDeltas[funcId];
  26352. } else if (funcId in ttContext.functionsDefined &&
  26353. functionsCalled.indexOf(funcId) < 0) {
  26354. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  26355. functionsCalled.push(funcId);
  26356. pc = ttContext.functionsDefined[funcId];
  26357. if (!pc) {
  26358. warn('TT: CALL non-existent function');
  26359. ttContext.hintsValid = false;
  26360. return;
  26361. }
  26362. data = pc.data;
  26363. i = pc.i;
  26364. }
  26365. }
  26366. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  26367. if (inFDEF || inELSE) {
  26368. warn('TT: nested FDEFs not allowed');
  26369. tooComplexToFollowFunctions = true;
  26370. }
  26371. inFDEF = true;
  26372. // collecting inforamtion about which functions are defined
  26373. lastDeff = i;
  26374. funcId = stack.pop();
  26375. ttContext.functionsDefined[funcId] = {data: data, i: i};
  26376. } else if (op === 0x2D) { // ENDF - end of function
  26377. if (inFDEF) {
  26378. inFDEF = false;
  26379. lastEndf = i;
  26380. } else {
  26381. pc = callstack.pop();
  26382. if (!pc) {
  26383. warn('TT: ENDF bad stack');
  26384. ttContext.hintsValid = false;
  26385. return;
  26386. }
  26387. funcId = functionsCalled.pop();
  26388. data = pc.data;
  26389. i = pc.i;
  26390. ttContext.functionsStackDeltas[funcId] =
  26391. stack.length - pc.stackTop;
  26392. }
  26393. } else if (op === 0x89) { // IDEF - instruction definition
  26394. if (inFDEF || inELSE) {
  26395. warn('TT: nested IDEFs not allowed');
  26396. tooComplexToFollowFunctions = true;
  26397. }
  26398. inFDEF = true;
  26399. // recording it as a function to track ENDF
  26400. lastDeff = i;
  26401. } else if (op === 0x58) { // IF
  26402. ++ifLevel;
  26403. } else if (op === 0x1B) { // ELSE
  26404. inELSE = ifLevel;
  26405. } else if (op === 0x59) { // EIF
  26406. if (inELSE === ifLevel) {
  26407. inELSE = 0;
  26408. }
  26409. --ifLevel;
  26410. } else if (op === 0x1C) { // JMPR
  26411. if (!inFDEF && !inELSE) {
  26412. var offset = stack[stack.length - 1];
  26413. // only jumping forward to prevent infinite loop
  26414. if (offset > 0) {
  26415. i += offset - 1;
  26416. }
  26417. }
  26418. }
  26419. // Adjusting stack not extactly, but just enough to get function id
  26420. if (!inFDEF && !inELSE) {
  26421. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  26422. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  26423. if (op >= 0x71 && op <= 0x75) {
  26424. n = stack.pop();
  26425. if (n === n) {
  26426. stackDelta = -n * 2;
  26427. }
  26428. }
  26429. while (stackDelta < 0 && stack.length > 0) {
  26430. stack.pop();
  26431. stackDelta++;
  26432. }
  26433. while (stackDelta > 0) {
  26434. stack.push(NaN); // pushing any number into stack
  26435. stackDelta--;
  26436. }
  26437. }
  26438. }
  26439. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  26440. var content = [data];
  26441. if (i > data.length) {
  26442. content.push(new Uint8Array(i - data.length));
  26443. }
  26444. if (lastDeff > lastEndf) {
  26445. warn('TT: complementing a missing function tail');
  26446. // new function definition started, but not finished
  26447. // complete function by [CLEAR, ENDF]
  26448. content.push(new Uint8Array([0x22, 0x2D]));
  26449. }
  26450. foldTTTable(table, content);
  26451. }
  26452. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  26453. if (ttContext.tooComplexToFollowFunctions) {
  26454. return;
  26455. }
  26456. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  26457. warn('TT: more functions defined than expected');
  26458. ttContext.hintsValid = false;
  26459. return;
  26460. }
  26461. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  26462. if (j > maxFunctionDefs) {
  26463. warn('TT: invalid function id: ' + j);
  26464. ttContext.hintsValid = false;
  26465. return;
  26466. }
  26467. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  26468. warn('TT: undefined function: ' + j);
  26469. ttContext.hintsValid = false;
  26470. return;
  26471. }
  26472. }
  26473. }
  26474. function foldTTTable(table, content) {
  26475. if (content.length > 1) {
  26476. // concatenating the content items
  26477. var newLength = 0;
  26478. var j, jj;
  26479. for (j = 0, jj = content.length; j < jj; j++) {
  26480. newLength += content[j].length;
  26481. }
  26482. newLength = (newLength + 3) & ~3;
  26483. var result = new Uint8Array(newLength);
  26484. var pos = 0;
  26485. for (j = 0, jj = content.length; j < jj; j++) {
  26486. result.set(content[j], pos);
  26487. pos += content[j].length;
  26488. }
  26489. table.data = result;
  26490. table.length = newLength;
  26491. }
  26492. }
  26493. function sanitizeTTPrograms(fpgm, prep, cvt) {
  26494. var ttContext = {
  26495. functionsDefined: [],
  26496. functionsUsed: [],
  26497. functionsStackDeltas: [],
  26498. tooComplexToFollowFunctions: false,
  26499. hintsValid: true
  26500. };
  26501. if (fpgm) {
  26502. sanitizeTTProgram(fpgm, ttContext);
  26503. }
  26504. if (prep) {
  26505. sanitizeTTProgram(prep, ttContext);
  26506. }
  26507. if (fpgm) {
  26508. checkInvalidFunctions(ttContext, maxFunctionDefs);
  26509. }
  26510. if (cvt && (cvt.length & 1)) {
  26511. var cvtData = new Uint8Array(cvt.length + 1);
  26512. cvtData.set(cvt.data);
  26513. cvt.data = cvtData;
  26514. }
  26515. return ttContext.hintsValid;
  26516. }
  26517. // The following steps modify the original font data, making copy
  26518. font = new Stream(new Uint8Array(font.getBytes()));
  26519. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  26520. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  26521. var header = readOpenTypeHeader(font);
  26522. var numTables = header.numTables;
  26523. var cff, cffFile;
  26524. var tables = Object.create(null);
  26525. tables['OS/2'] = null;
  26526. tables['cmap'] = null;
  26527. tables['head'] = null;
  26528. tables['hhea'] = null;
  26529. tables['hmtx'] = null;
  26530. tables['maxp'] = null;
  26531. tables['name'] = null;
  26532. tables['post'] = null;
  26533. var table;
  26534. for (var i = 0; i < numTables; i++) {
  26535. table = readTableEntry(font);
  26536. if (VALID_TABLES.indexOf(table.tag) < 0) {
  26537. continue; // skipping table if it's not a required or optional table
  26538. }
  26539. if (table.length === 0) {
  26540. continue; // skipping empty tables
  26541. }
  26542. tables[table.tag] = table;
  26543. }
  26544. var isTrueType = !tables['CFF '];
  26545. if (!isTrueType) {
  26546. // OpenType font
  26547. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  26548. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  26549. !tables['post']) {
  26550. // no major tables: throwing everything at CFFFont
  26551. cffFile = new Stream(tables['CFF '].data);
  26552. cff = new CFFFont(cffFile, properties);
  26553. adjustWidths(properties);
  26554. return this.convert(name, cff, properties);
  26555. }
  26556. delete tables['glyf'];
  26557. delete tables['loca'];
  26558. delete tables['fpgm'];
  26559. delete tables['prep'];
  26560. delete tables['cvt '];
  26561. this.isOpenType = true;
  26562. } else {
  26563. if (!tables['loca']) {
  26564. error('Required "loca" table is not found');
  26565. }
  26566. if (!tables['glyf']) {
  26567. warn('Required "glyf" table is not found -- trying to recover.');
  26568. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  26569. tables['glyf'] = {
  26570. tag: 'glyf',
  26571. data: new Uint8Array(0),
  26572. };
  26573. }
  26574. this.isOpenType = false;
  26575. }
  26576. if (!tables['maxp']) {
  26577. error('Required "maxp" table is not found');
  26578. }
  26579. font.pos = (font.start || 0) + tables['maxp'].offset;
  26580. var version = font.getInt32();
  26581. var numGlyphs = font.getUint16();
  26582. var maxFunctionDefs = 0;
  26583. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  26584. // maxZones can be invalid
  26585. font.pos += 8;
  26586. var maxZones = font.getUint16();
  26587. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  26588. tables['maxp'].data[14] = 0;
  26589. tables['maxp'].data[15] = 2;
  26590. }
  26591. font.pos += 4;
  26592. maxFunctionDefs = font.getUint16();
  26593. }
  26594. var dupFirstEntry = false;
  26595. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  26596. properties.toUnicode.get(0) > '\u0000') {
  26597. // oracle's defect (see 3427), duplicating first entry
  26598. dupFirstEntry = true;
  26599. numGlyphs++;
  26600. tables['maxp'].data[4] = numGlyphs >> 8;
  26601. tables['maxp'].data[5] = numGlyphs & 255;
  26602. }
  26603. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  26604. tables['cvt '], maxFunctionDefs);
  26605. if (!hintsValid) {
  26606. delete tables['fpgm'];
  26607. delete tables['prep'];
  26608. delete tables['cvt '];
  26609. }
  26610. // Ensure the hmtx table contains the advance width and
  26611. // sidebearings information for numGlyphs in the maxp table
  26612. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  26613. if (!tables['head']) {
  26614. error('Required "head" table is not found');
  26615. }
  26616. sanitizeHead(tables['head'], numGlyphs,
  26617. isTrueType ? tables['loca'].length : 0);
  26618. var missingGlyphs = Object.create(null);
  26619. if (isTrueType) {
  26620. var isGlyphLocationsLong = int16(tables['head'].data[50],
  26621. tables['head'].data[51]);
  26622. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  26623. numGlyphs, isGlyphLocationsLong,
  26624. hintsValid, dupFirstEntry);
  26625. }
  26626. if (!tables['hhea']) {
  26627. error('Required "hhea" table is not found');
  26628. }
  26629. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  26630. // Sometimes it's 0. That needs to be fixed
  26631. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  26632. tables['hhea'].data[10] = 0xFF;
  26633. tables['hhea'].data[11] = 0xFF;
  26634. }
  26635. // Extract some more font properties from the OpenType head and
  26636. // hhea tables; yMin and descent value are always negative.
  26637. var metricsOverride = {
  26638. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  26639. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  26640. yMin: int16(tables['head'].data[38], tables['head'].data[39]) - 0x10000,
  26641. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  26642. descent: int16(tables['hhea'].data[6], tables['hhea'].data[7]) - 0x10000
  26643. };
  26644. // PDF FontDescriptor metrics lie -- using data from actual font.
  26645. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  26646. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  26647. // The 'post' table has glyphs names.
  26648. if (tables['post']) {
  26649. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  26650. if (!valid) {
  26651. tables['post'] = null;
  26652. }
  26653. }
  26654. var charCodeToGlyphId = [], charCode;
  26655. var toUnicode = properties.toUnicode, widths = properties.widths;
  26656. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  26657. toUnicode.length === 0x10000);
  26658. // Helper function to try to skip mapping of empty glyphs.
  26659. // Note: In some cases, just relying on the glyph data doesn't work,
  26660. // hence we also use a few heuristics to fix various PDF files.
  26661. function hasGlyph(glyphId, charCode, widthCode) {
  26662. if (!missingGlyphs[glyphId]) {
  26663. return true;
  26664. }
  26665. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  26666. return true;
  26667. }
  26668. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  26669. return true;
  26670. }
  26671. return false;
  26672. }
  26673. if (properties.type === 'CIDFontType2') {
  26674. var cidToGidMap = properties.cidToGidMap || [];
  26675. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  26676. properties.cMap.forEach(function(charCode, cid) {
  26677. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  26678. var glyphId = -1;
  26679. if (isCidToGidMapEmpty) {
  26680. glyphId = charCode;
  26681. } else if (cidToGidMap[cid] !== undefined) {
  26682. glyphId = cidToGidMap[cid];
  26683. }
  26684. if (glyphId >= 0 && glyphId < numGlyphs &&
  26685. hasGlyph(glyphId, charCode, cid)) {
  26686. charCodeToGlyphId[charCode] = glyphId;
  26687. }
  26688. });
  26689. if (dupFirstEntry) {
  26690. charCodeToGlyphId[0] = numGlyphs - 1;
  26691. }
  26692. } else {
  26693. // Most of the following logic in this code branch is based on the
  26694. // 9.6.6.4 of the PDF spec.
  26695. var hasEncoding =
  26696. properties.differences.length > 0 || !!properties.baseEncodingName;
  26697. var cmapTable =
  26698. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  26699. var cmapPlatformId = cmapTable.platformId;
  26700. var cmapEncodingId = cmapTable.encodingId;
  26701. var cmapMappings = cmapTable.mappings;
  26702. var cmapMappingsLength = cmapMappings.length;
  26703. // The spec seems to imply that if the font is symbolic the encoding
  26704. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  26705. // where the the font is symbolic and it has an encoding.
  26706. if (hasEncoding &&
  26707. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  26708. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  26709. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  26710. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  26711. // When no preferred cmap table was found and |baseEncodingName| is
  26712. // one of the predefined encodings, we seem to obtain a better
  26713. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  26714. // TODO: Note that this is a hack which should be removed as soon as
  26715. // we have proper support for more exotic cmap tables.
  26716. var baseEncoding = [];
  26717. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  26718. properties.baseEncodingName === 'WinAnsiEncoding') {
  26719. baseEncoding = getEncoding(properties.baseEncodingName);
  26720. }
  26721. var glyphsUnicodeMap = getGlyphsUnicode();
  26722. for (charCode = 0; charCode < 256; charCode++) {
  26723. var glyphName;
  26724. if (this.differences && charCode in this.differences) {
  26725. glyphName = this.differences[charCode];
  26726. } else if (charCode in baseEncoding &&
  26727. baseEncoding[charCode] !== '') {
  26728. glyphName = baseEncoding[charCode];
  26729. } else {
  26730. glyphName = StandardEncoding[charCode];
  26731. }
  26732. if (!glyphName) {
  26733. continue;
  26734. }
  26735. var unicodeOrCharCode, isUnicode = false;
  26736. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  26737. unicodeOrCharCode = glyphsUnicodeMap[glyphName];
  26738. isUnicode = true;
  26739. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  26740. // TODO: the encoding needs to be updated with mac os table.
  26741. unicodeOrCharCode = MacRomanEncoding.indexOf(glyphName);
  26742. }
  26743. var found = false;
  26744. for (i = 0; i < cmapMappingsLength; ++i) {
  26745. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  26746. continue;
  26747. }
  26748. var code = isUnicode ? charCode : unicodeOrCharCode;
  26749. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  26750. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  26751. found = true;
  26752. break;
  26753. }
  26754. }
  26755. if (!found && properties.glyphNames) {
  26756. // Try to map using the post table.
  26757. var glyphId = properties.glyphNames.indexOf(glyphName);
  26758. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  26759. charCodeToGlyphId[charCode] = glyphId;
  26760. found = true;
  26761. }
  26762. }
  26763. if (!found) {
  26764. charCodeToGlyphId[charCode] = 0; // notdef
  26765. }
  26766. }
  26767. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  26768. // Default Unicode semantics, use the charcodes as is.
  26769. for (i = 0; i < cmapMappingsLength; ++i) {
  26770. charCodeToGlyphId[cmapMappings[i].charCode] =
  26771. cmapMappings[i].glyphId;
  26772. }
  26773. } else {
  26774. // For (3, 0) cmap tables:
  26775. // The charcode key being stored in charCodeToGlyphId is the lower
  26776. // byte of the two-byte charcodes of the cmap table since according to
  26777. // the spec: 'each byte from the string shall be prepended with the
  26778. // high byte of the range [of charcodes in the cmap table], to form
  26779. // a two-byte character, which shall be used to select the
  26780. // associated glyph description from the subtable'.
  26781. //
  26782. // For (1, 0) cmap tables:
  26783. // 'single bytes from the string shall be used to look up the
  26784. // associated glyph descriptions from the subtable'. This means
  26785. // charcodes in the cmap will be single bytes, so no-op since
  26786. // glyph.charCode & 0xFF === glyph.charCode
  26787. for (i = 0; i < cmapMappingsLength; ++i) {
  26788. charCode = cmapMappings[i].charCode & 0xFF;
  26789. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  26790. }
  26791. }
  26792. }
  26793. if (charCodeToGlyphId.length === 0) {
  26794. // defines at least one glyph
  26795. charCodeToGlyphId[0] = 0;
  26796. }
  26797. // Converting glyphs and ids into font's cmap table
  26798. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  26799. this.toFontChar = newMapping.toFontChar;
  26800. tables['cmap'] = {
  26801. tag: 'cmap',
  26802. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  26803. };
  26804. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  26805. tables['OS/2'] = {
  26806. tag: 'OS/2',
  26807. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  26808. metricsOverride)
  26809. };
  26810. }
  26811. // Rewrite the 'post' table if needed
  26812. if (!tables['post']) {
  26813. tables['post'] = {
  26814. tag: 'post',
  26815. data: createPostTable(properties)
  26816. };
  26817. }
  26818. if (!isTrueType) {
  26819. try {
  26820. // Trying to repair CFF file
  26821. cffFile = new Stream(tables['CFF '].data);
  26822. var parser = new CFFParser(cffFile, properties);
  26823. cff = parser.parse();
  26824. var compiler = new CFFCompiler(cff);
  26825. tables['CFF '].data = compiler.compile();
  26826. } catch (e) {
  26827. warn('Failed to compile font ' + properties.loadedName);
  26828. }
  26829. }
  26830. // Re-creating 'name' table
  26831. if (!tables['name']) {
  26832. tables['name'] = {
  26833. tag: 'name',
  26834. data: createNameTable(this.name)
  26835. };
  26836. } else {
  26837. // ... using existing 'name' table as prototype
  26838. var namePrototype = readNameTable(tables['name']);
  26839. tables['name'].data = createNameTable(name, namePrototype);
  26840. }
  26841. var builder = new OpenTypeFileBuilder(header.version);
  26842. for (var tableTag in tables) {
  26843. builder.addTable(tableTag, tables[tableTag].data);
  26844. }
  26845. return builder.toArray();
  26846. },
  26847. convert: function Font_convert(fontName, font, properties) {
  26848. // TODO: Check the charstring widths to determine this.
  26849. properties.fixedPitch = false;
  26850. var mapping = font.getGlyphMapping(properties);
  26851. var newMapping = adjustMapping(mapping, properties);
  26852. this.toFontChar = newMapping.toFontChar;
  26853. var numGlyphs = font.numGlyphs;
  26854. function getCharCodes(charCodeToGlyphId, glyphId) {
  26855. var charCodes = null;
  26856. for (var charCode in charCodeToGlyphId) {
  26857. if (glyphId === charCodeToGlyphId[charCode]) {
  26858. if (!charCodes) {
  26859. charCodes = [];
  26860. }
  26861. charCodes.push(charCode | 0);
  26862. }
  26863. }
  26864. return charCodes;
  26865. }
  26866. function createCharCode(charCodeToGlyphId, glyphId) {
  26867. for (var charCode in charCodeToGlyphId) {
  26868. if (glyphId === charCodeToGlyphId[charCode]) {
  26869. return charCode | 0;
  26870. }
  26871. }
  26872. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  26873. glyphId;
  26874. return newMapping.nextAvailableFontCharCode++;
  26875. }
  26876. var seacs = font.seacs;
  26877. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  26878. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  26879. var charset = font.getCharset();
  26880. var seacMap = Object.create(null);
  26881. for (var glyphId in seacs) {
  26882. glyphId |= 0;
  26883. var seac = seacs[glyphId];
  26884. var baseGlyphName = StandardEncoding[seac[2]];
  26885. var accentGlyphName = StandardEncoding[seac[3]];
  26886. var baseGlyphId = charset.indexOf(baseGlyphName);
  26887. var accentGlyphId = charset.indexOf(accentGlyphName);
  26888. if (baseGlyphId < 0 || accentGlyphId < 0) {
  26889. continue;
  26890. }
  26891. var accentOffset = {
  26892. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  26893. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  26894. };
  26895. var charCodes = getCharCodes(mapping, glyphId);
  26896. if (!charCodes) {
  26897. // There's no point in mapping it if the char code was never mapped
  26898. // to begin with.
  26899. continue;
  26900. }
  26901. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  26902. var charCode = charCodes[i];
  26903. // Find a fontCharCode that maps to the base and accent glyphs.
  26904. // If one doesn't exists, create it.
  26905. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  26906. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  26907. baseGlyphId);
  26908. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  26909. accentGlyphId);
  26910. seacMap[charCode] = {
  26911. baseFontCharCode: baseFontCharCode,
  26912. accentFontCharCode: accentFontCharCode,
  26913. accentOffset: accentOffset
  26914. };
  26915. }
  26916. }
  26917. properties.seacMap = seacMap;
  26918. }
  26919. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  26920. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  26921. // PostScript Font Program
  26922. builder.addTable('CFF ', font.data);
  26923. // OS/2 and Windows Specific metrics
  26924. builder.addTable('OS/2', createOS2Table(properties,
  26925. newMapping.charCodeToGlyphId));
  26926. // Character to glyphs mapping
  26927. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  26928. numGlyphs));
  26929. // Font header
  26930. builder.addTable('head',
  26931. '\x00\x01\x00\x00' + // Version number
  26932. '\x00\x00\x10\x00' + // fontRevision
  26933. '\x00\x00\x00\x00' + // checksumAdjustement
  26934. '\x5F\x0F\x3C\xF5' + // magicNumber
  26935. '\x00\x00' + // Flags
  26936. safeString16(unitsPerEm) + // unitsPerEM
  26937. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  26938. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  26939. '\x00\x00' + // xMin
  26940. safeString16(properties.descent) + // yMin
  26941. '\x0F\xFF' + // xMax
  26942. safeString16(properties.ascent) + // yMax
  26943. string16(properties.italicAngle ? 2 : 0) + // macStyle
  26944. '\x00\x11' + // lowestRecPPEM
  26945. '\x00\x00' + // fontDirectionHint
  26946. '\x00\x00' + // indexToLocFormat
  26947. '\x00\x00'); // glyphDataFormat
  26948. // Horizontal header
  26949. builder.addTable('hhea',
  26950. '\x00\x01\x00\x00' + // Version number
  26951. safeString16(properties.ascent) + // Typographic Ascent
  26952. safeString16(properties.descent) + // Typographic Descent
  26953. '\x00\x00' + // Line Gap
  26954. '\xFF\xFF' + // advanceWidthMax
  26955. '\x00\x00' + // minLeftSidebearing
  26956. '\x00\x00' + // minRightSidebearing
  26957. '\x00\x00' + // xMaxExtent
  26958. safeString16(properties.capHeight) + // caretSlopeRise
  26959. safeString16(Math.tan(properties.italicAngle) *
  26960. properties.xHeight) + // caretSlopeRun
  26961. '\x00\x00' + // caretOffset
  26962. '\x00\x00' + // -reserved-
  26963. '\x00\x00' + // -reserved-
  26964. '\x00\x00' + // -reserved-
  26965. '\x00\x00' + // -reserved-
  26966. '\x00\x00' + // metricDataFormat
  26967. string16(numGlyphs)); // Number of HMetrics
  26968. // Horizontal metrics
  26969. builder.addTable('hmtx', (function fontFieldsHmtx() {
  26970. var charstrings = font.charstrings;
  26971. var cffWidths = font.cff ? font.cff.widths : null;
  26972. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  26973. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  26974. var width = 0;
  26975. if (charstrings) {
  26976. var charstring = charstrings[i - 1];
  26977. width = 'width' in charstring ? charstring.width : 0;
  26978. } else if (cffWidths) {
  26979. width = Math.ceil(cffWidths[i] || 0);
  26980. }
  26981. hmtx += string16(width) + string16(0);
  26982. }
  26983. return hmtx;
  26984. })());
  26985. // Maximum profile
  26986. builder.addTable('maxp',
  26987. '\x00\x00\x50\x00' + // Version number
  26988. string16(numGlyphs)); // Num of glyphs
  26989. // Naming tables
  26990. builder.addTable('name', createNameTable(fontName));
  26991. // PostScript informations
  26992. builder.addTable('post', createPostTable(properties));
  26993. return builder.toArray();
  26994. },
  26995. /**
  26996. * Builds a char code to unicode map based on section 9.10 of the spec.
  26997. * @param {Object} properties Font properties object.
  26998. * @return {Object} A ToUnicodeMap object.
  26999. */
  27000. buildToUnicode: function Font_buildToUnicode(properties) {
  27001. // Section 9.10.2 Mapping Character Codes to Unicode Values
  27002. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  27003. return properties.toUnicode;
  27004. }
  27005. // According to the spec if the font is a simple font we should only map
  27006. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  27007. // the differences array only contains adobe standard or symbol set names,
  27008. // in pratice it seems better to always try to create a toUnicode
  27009. // map based of the default encoding.
  27010. var toUnicode, charcode;
  27011. if (!properties.composite /* is simple font */) {
  27012. toUnicode = [];
  27013. var encoding = properties.defaultEncoding.slice();
  27014. var baseEncodingName = properties.baseEncodingName;
  27015. // Merge in the differences array.
  27016. var differences = properties.differences;
  27017. for (charcode in differences) {
  27018. encoding[charcode] = differences[charcode];
  27019. }
  27020. var glyphsUnicodeMap = getGlyphsUnicode();
  27021. for (charcode in encoding) {
  27022. // a) Map the character code to a character name.
  27023. var glyphName = encoding[charcode];
  27024. // b) Look up the character name in the Adobe Glyph List (see the
  27025. // Bibliography) to obtain the corresponding Unicode value.
  27026. if (glyphName === '') {
  27027. continue;
  27028. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  27029. // (undocumented) c) Few heuristics to recognize unknown glyphs
  27030. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  27031. var code = 0;
  27032. switch (glyphName[0]) {
  27033. case 'G': // Gxx glyph
  27034. if (glyphName.length === 3) {
  27035. code = parseInt(glyphName.substr(1), 16);
  27036. }
  27037. break;
  27038. case 'g': // g00xx glyph
  27039. if (glyphName.length === 5) {
  27040. code = parseInt(glyphName.substr(1), 16);
  27041. }
  27042. break;
  27043. case 'C': // Cddd glyph
  27044. case 'c': // cddd glyph
  27045. if (glyphName.length >= 3) {
  27046. code = +glyphName.substr(1);
  27047. }
  27048. break;
  27049. }
  27050. if (code) {
  27051. // If |baseEncodingName| is one the predefined encodings,
  27052. // and |code| equals |charcode|, using the glyph defined in the
  27053. // baseEncoding seems to yield a better |toUnicode| mapping
  27054. // (fixes issue 5070).
  27055. if (baseEncodingName && code === +charcode) {
  27056. var baseEncoding = getEncoding(baseEncodingName);
  27057. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  27058. toUnicode[charcode] =
  27059. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  27060. continue;
  27061. }
  27062. }
  27063. toUnicode[charcode] = String.fromCharCode(code);
  27064. }
  27065. continue;
  27066. }
  27067. toUnicode[charcode] =
  27068. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  27069. }
  27070. return new ToUnicodeMap(toUnicode);
  27071. }
  27072. // If the font is a composite font that uses one of the predefined CMaps
  27073. // listed in Table 118 (except Identity–H and Identity–V) or whose
  27074. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  27075. // Adobe-Korea1 character collection:
  27076. if (properties.composite && (
  27077. (properties.cMap.builtInCMap &&
  27078. !(properties.cMap instanceof IdentityCMap)) ||
  27079. (properties.cidSystemInfo.registry === 'Adobe' &&
  27080. (properties.cidSystemInfo.ordering === 'GB1' ||
  27081. properties.cidSystemInfo.ordering === 'CNS1' ||
  27082. properties.cidSystemInfo.ordering === 'Japan1' ||
  27083. properties.cidSystemInfo.ordering === 'Korea1')))) {
  27084. // Then:
  27085. // a) Map the character code to a character identifier (CID) according
  27086. // to the font’s CMap.
  27087. // b) Obtain the registry and ordering of the character collection used
  27088. // by the font’s CMap (for example, Adobe and Japan1) from its
  27089. // CIDSystemInfo dictionary.
  27090. var registry = properties.cidSystemInfo.registry;
  27091. var ordering = properties.cidSystemInfo.ordering;
  27092. // c) Construct a second CMap name by concatenating the registry and
  27093. // ordering obtained in step (b) in the format registry–ordering–UCS2
  27094. // (for example, Adobe–Japan1–UCS2).
  27095. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  27096. // d) Obtain the CMap with the name constructed in step (c) (available
  27097. // from the ASN Web site; see the Bibliography).
  27098. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  27099. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  27100. var cMap = properties.cMap;
  27101. toUnicode = [];
  27102. cMap.forEach(function(charcode, cid) {
  27103. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  27104. // e) Map the CID obtained in step (a) according to the CMap obtained
  27105. // in step (d), producing a Unicode value.
  27106. var ucs2 = ucs2CMap.lookup(cid);
  27107. if (ucs2) {
  27108. toUnicode[charcode] =
  27109. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  27110. ucs2.charCodeAt(1));
  27111. }
  27112. });
  27113. return new ToUnicodeMap(toUnicode);
  27114. }
  27115. // The viewer's choice, just use an identity map.
  27116. return new IdentityToUnicodeMap(properties.firstChar,
  27117. properties.lastChar);
  27118. },
  27119. get spaceWidth() {
  27120. if ('_shadowWidth' in this) {
  27121. return this._shadowWidth;
  27122. }
  27123. // trying to estimate space character width
  27124. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  27125. var width;
  27126. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  27127. var glyphName = possibleSpaceReplacements[i];
  27128. // if possible, getting width by glyph name
  27129. if (glyphName in this.widths) {
  27130. width = this.widths[glyphName];
  27131. break;
  27132. }
  27133. var glyphsUnicodeMap = getGlyphsUnicode();
  27134. var glyphUnicode = glyphsUnicodeMap[glyphName];
  27135. // finding the charcode via unicodeToCID map
  27136. var charcode = 0;
  27137. if (this.composite) {
  27138. if (this.cMap.contains(glyphUnicode)) {
  27139. charcode = this.cMap.lookup(glyphUnicode);
  27140. }
  27141. }
  27142. // ... via toUnicode map
  27143. if (!charcode && this.toUnicode) {
  27144. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  27145. }
  27146. // setting it to unicode if negative or undefined
  27147. if (charcode <= 0) {
  27148. charcode = glyphUnicode;
  27149. }
  27150. // trying to get width via charcode
  27151. width = this.widths[charcode];
  27152. if (width) {
  27153. break; // the non-zero width found
  27154. }
  27155. }
  27156. width = width || this.defaultWidth;
  27157. // Do not shadow the property here. See discussion:
  27158. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  27159. this._shadowWidth = width;
  27160. return width;
  27161. },
  27162. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  27163. var fontCharCode, width, operatorListId;
  27164. var widthCode = charcode;
  27165. if (this.cMap && this.cMap.contains(charcode)) {
  27166. widthCode = this.cMap.lookup(charcode);
  27167. }
  27168. width = this.widths[widthCode];
  27169. width = isNum(width) ? width : this.defaultWidth;
  27170. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  27171. var unicode = this.toUnicode.get(charcode) || charcode;
  27172. if (typeof unicode === 'number') {
  27173. unicode = String.fromCharCode(unicode);
  27174. }
  27175. // First try the toFontChar map, if it's not there then try falling
  27176. // back to the char code.
  27177. fontCharCode = this.toFontChar[charcode] || charcode;
  27178. if (this.missingFile) {
  27179. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  27180. }
  27181. if (this.isType3Font) {
  27182. // Font char code in this case is actually a glyph name.
  27183. operatorListId = fontCharCode;
  27184. }
  27185. var accent = null;
  27186. if (this.seacMap && this.seacMap[charcode]) {
  27187. var seac = this.seacMap[charcode];
  27188. fontCharCode = seac.baseFontCharCode;
  27189. accent = {
  27190. fontChar: String.fromCharCode(seac.accentFontCharCode),
  27191. offset: seac.accentOffset
  27192. };
  27193. }
  27194. var fontChar = String.fromCharCode(fontCharCode);
  27195. var glyph = this.glyphCache[charcode];
  27196. if (!glyph ||
  27197. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  27198. operatorListId, isSpace)) {
  27199. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  27200. operatorListId, isSpace);
  27201. this.glyphCache[charcode] = glyph;
  27202. }
  27203. return glyph;
  27204. },
  27205. charsToGlyphs: function Font_charsToGlyphs(chars) {
  27206. var charsCache = this.charsCache;
  27207. var glyphs, glyph, charcode;
  27208. // if we translated this string before, just grab it from the cache
  27209. if (charsCache) {
  27210. glyphs = charsCache[chars];
  27211. if (glyphs) {
  27212. return glyphs;
  27213. }
  27214. }
  27215. // lazily create the translation cache
  27216. if (!charsCache) {
  27217. charsCache = this.charsCache = Object.create(null);
  27218. }
  27219. glyphs = [];
  27220. var charsCacheKey = chars;
  27221. var i = 0, ii;
  27222. if (this.cMap) {
  27223. // composite fonts have multi-byte strings convert the string from
  27224. // single-byte to multi-byte
  27225. var c = Object.create(null);
  27226. while (i < chars.length) {
  27227. this.cMap.readCharCode(chars, i, c);
  27228. charcode = c.charcode;
  27229. var length = c.length;
  27230. i += length;
  27231. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  27232. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  27233. glyph = this.charToGlyph(charcode, isSpace);
  27234. glyphs.push(glyph);
  27235. }
  27236. } else {
  27237. for (i = 0, ii = chars.length; i < ii; ++i) {
  27238. charcode = chars.charCodeAt(i);
  27239. glyph = this.charToGlyph(charcode, charcode === 0x20);
  27240. glyphs.push(glyph);
  27241. }
  27242. }
  27243. // Enter the translated string into the cache
  27244. return (charsCache[charsCacheKey] = glyphs);
  27245. }
  27246. };
  27247. return Font;
  27248. })();
  27249. var ErrorFont = (function ErrorFontClosure() {
  27250. function ErrorFont(error) {
  27251. this.error = error;
  27252. this.loadedName = 'g_font_error';
  27253. this.loading = false;
  27254. }
  27255. ErrorFont.prototype = {
  27256. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  27257. return [];
  27258. },
  27259. exportData: function ErrorFont_exportData() {
  27260. return {error: this.error};
  27261. }
  27262. };
  27263. return ErrorFont;
  27264. })();
  27265. /**
  27266. * Shared logic for building a char code to glyph id mapping for Type1 and
  27267. * simple CFF fonts. See section 9.6.6.2 of the spec.
  27268. * @param {Object} properties Font properties object.
  27269. * @param {Object} builtInEncoding The encoding contained within the actual font
  27270. * data.
  27271. * @param {Array} Array of glyph names where the index is the glyph ID.
  27272. * @returns {Object} A char code to glyph ID map.
  27273. */
  27274. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  27275. var charCodeToGlyphId = Object.create(null);
  27276. var glyphId, charCode, baseEncoding;
  27277. if (properties.baseEncodingName) {
  27278. // If a valid base encoding name was used, the mapping is initialized with
  27279. // that.
  27280. baseEncoding = getEncoding(properties.baseEncodingName);
  27281. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27282. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27283. if (glyphId >= 0) {
  27284. charCodeToGlyphId[charCode] = glyphId;
  27285. } else {
  27286. charCodeToGlyphId[charCode] = 0; // notdef
  27287. }
  27288. }
  27289. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  27290. // For a symbolic font the encoding should be the fonts built-in
  27291. // encoding.
  27292. for (charCode in builtInEncoding) {
  27293. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  27294. }
  27295. } else {
  27296. // For non-symbolic fonts that don't have a base encoding the standard
  27297. // encoding should be used.
  27298. baseEncoding = StandardEncoding;
  27299. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  27300. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  27301. if (glyphId >= 0) {
  27302. charCodeToGlyphId[charCode] = glyphId;
  27303. } else {
  27304. charCodeToGlyphId[charCode] = 0; // notdef
  27305. }
  27306. }
  27307. }
  27308. // Lastly, merge in the differences.
  27309. var differences = properties.differences;
  27310. if (differences) {
  27311. for (charCode in differences) {
  27312. var glyphName = differences[charCode];
  27313. glyphId = glyphNames.indexOf(glyphName);
  27314. if (glyphId >= 0) {
  27315. charCodeToGlyphId[charCode] = glyphId;
  27316. } else {
  27317. charCodeToGlyphId[charCode] = 0; // notdef
  27318. }
  27319. }
  27320. }
  27321. return charCodeToGlyphId;
  27322. }
  27323. /*
  27324. * CharStrings are encoded following the the CharString Encoding sequence
  27325. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  27326. * The value in a byte indicates a command, a number, or subsequent bytes
  27327. * that are to be interpreted in a special way.
  27328. *
  27329. * CharString Number Encoding:
  27330. * A CharString byte containing the values from 32 through 255 inclusive
  27331. * indicate an integer. These values are decoded in four ranges.
  27332. *
  27333. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  27334. * indicate the integer v - 139. Thus, the integer values from -107 through
  27335. * 107 inclusive may be encoded in single byte.
  27336. *
  27337. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  27338. * indicates an integer involving the next byte, w, according to the formula:
  27339. * [(v - 247) x 256] + w + 108
  27340. *
  27341. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  27342. * indicates an integer involving the next byte, w, according to the formula:
  27343. * -[(v - 251) * 256] - w - 108
  27344. *
  27345. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  27346. * are a two complement signed integer. The first of these bytes contains the
  27347. * highest order bits, the second byte contains the next higher order bits
  27348. * and the fourth byte contain the lowest order bits.
  27349. *
  27350. *
  27351. * CharString Command Encoding:
  27352. * CharStrings commands are encoded in 1 or 2 bytes.
  27353. *
  27354. * Single byte commands are encoded in 1 byte that contains a value between
  27355. * 0 and 31 inclusive.
  27356. * If a command byte contains the value 12, then the value in the next byte
  27357. * indicates a command. This "escape" mechanism allows many extra commands
  27358. * to be encoded and this encoding technique helps to minimize the length of
  27359. * the charStrings.
  27360. */
  27361. var Type1CharString = (function Type1CharStringClosure() {
  27362. var COMMAND_MAP = {
  27363. 'hstem': [1],
  27364. 'vstem': [3],
  27365. 'vmoveto': [4],
  27366. 'rlineto': [5],
  27367. 'hlineto': [6],
  27368. 'vlineto': [7],
  27369. 'rrcurveto': [8],
  27370. 'callsubr': [10],
  27371. 'flex': [12, 35],
  27372. 'drop' : [12, 18],
  27373. 'endchar': [14],
  27374. 'rmoveto': [21],
  27375. 'hmoveto': [22],
  27376. 'vhcurveto': [30],
  27377. 'hvcurveto': [31]
  27378. };
  27379. function Type1CharString() {
  27380. this.width = 0;
  27381. this.lsb = 0;
  27382. this.flexing = false;
  27383. this.output = [];
  27384. this.stack = [];
  27385. }
  27386. Type1CharString.prototype = {
  27387. convert: function Type1CharString_convert(encoded, subrs) {
  27388. var count = encoded.length;
  27389. var error = false;
  27390. var wx, sbx, subrNumber;
  27391. for (var i = 0; i < count; i++) {
  27392. var value = encoded[i];
  27393. if (value < 32) {
  27394. if (value === 12) {
  27395. value = (value << 8) + encoded[++i];
  27396. }
  27397. switch (value) {
  27398. case 1: // hstem
  27399. if (!HINTING_ENABLED) {
  27400. this.stack = [];
  27401. break;
  27402. }
  27403. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27404. break;
  27405. case 3: // vstem
  27406. if (!HINTING_ENABLED) {
  27407. this.stack = [];
  27408. break;
  27409. }
  27410. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27411. break;
  27412. case 4: // vmoveto
  27413. if (this.flexing) {
  27414. if (this.stack.length < 1) {
  27415. error = true;
  27416. break;
  27417. }
  27418. // Add the dx for flex and but also swap the values so they are
  27419. // the right order.
  27420. var dy = this.stack.pop();
  27421. this.stack.push(0, dy);
  27422. break;
  27423. }
  27424. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  27425. break;
  27426. case 5: // rlineto
  27427. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  27428. break;
  27429. case 6: // hlineto
  27430. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  27431. break;
  27432. case 7: // vlineto
  27433. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  27434. break;
  27435. case 8: // rrcurveto
  27436. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  27437. break;
  27438. case 9: // closepath
  27439. // closepath is a Type1 command that does not take argument and is
  27440. // useless in Type2 and it can simply be ignored.
  27441. this.stack = [];
  27442. break;
  27443. case 10: // callsubr
  27444. if (this.stack.length < 1) {
  27445. error = true;
  27446. break;
  27447. }
  27448. subrNumber = this.stack.pop();
  27449. error = this.convert(subrs[subrNumber], subrs);
  27450. break;
  27451. case 11: // return
  27452. return error;
  27453. case 13: // hsbw
  27454. if (this.stack.length < 2) {
  27455. error = true;
  27456. break;
  27457. }
  27458. // To convert to type2 we have to move the width value to the
  27459. // first part of the charstring and then use hmoveto with lsb.
  27460. wx = this.stack.pop();
  27461. sbx = this.stack.pop();
  27462. this.lsb = sbx;
  27463. this.width = wx;
  27464. this.stack.push(wx, sbx);
  27465. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  27466. break;
  27467. case 14: // endchar
  27468. this.output.push(COMMAND_MAP.endchar[0]);
  27469. break;
  27470. case 21: // rmoveto
  27471. if (this.flexing) {
  27472. break;
  27473. }
  27474. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  27475. break;
  27476. case 22: // hmoveto
  27477. if (this.flexing) {
  27478. // Add the dy for flex.
  27479. this.stack.push(0);
  27480. break;
  27481. }
  27482. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  27483. break;
  27484. case 30: // vhcurveto
  27485. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  27486. break;
  27487. case 31: // hvcurveto
  27488. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  27489. break;
  27490. case (12 << 8) + 0: // dotsection
  27491. // dotsection is a Type1 command to specify some hinting feature
  27492. // for dots that do not take a parameter and it can safely be
  27493. // ignored for Type2.
  27494. this.stack = [];
  27495. break;
  27496. case (12 << 8) + 1: // vstem3
  27497. if (!HINTING_ENABLED) {
  27498. this.stack = [];
  27499. break;
  27500. }
  27501. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  27502. // multiple parameters, so instead of returning [vh]stem3 take a
  27503. // shortcut and return [vhstem] instead.
  27504. error = this.executeCommand(2, COMMAND_MAP.vstem);
  27505. break;
  27506. case (12 << 8) + 2: // hstem3
  27507. if (!HINTING_ENABLED) {
  27508. this.stack = [];
  27509. break;
  27510. }
  27511. // See vstem3.
  27512. error = this.executeCommand(2, COMMAND_MAP.hstem);
  27513. break;
  27514. case (12 << 8) + 6: // seac
  27515. // seac is like type 2's special endchar but it doesn't use the
  27516. // first argument asb, so remove it.
  27517. if (SEAC_ANALYSIS_ENABLED) {
  27518. this.seac = this.stack.splice(-4, 4);
  27519. error = this.executeCommand(0, COMMAND_MAP.endchar);
  27520. } else {
  27521. error = this.executeCommand(4, COMMAND_MAP.endchar);
  27522. }
  27523. break;
  27524. case (12 << 8) + 7: // sbw
  27525. if (this.stack.length < 4) {
  27526. error = true;
  27527. break;
  27528. }
  27529. // To convert to type2 we have to move the width value to the
  27530. // first part of the charstring and then use rmoveto with
  27531. // (dx, dy). The height argument will not be used for vmtx and
  27532. // vhea tables reconstruction -- ignoring it.
  27533. var wy = this.stack.pop();
  27534. wx = this.stack.pop();
  27535. var sby = this.stack.pop();
  27536. sbx = this.stack.pop();
  27537. this.lsb = sbx;
  27538. this.width = wx;
  27539. this.stack.push(wx, sbx, sby);
  27540. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  27541. break;
  27542. case (12 << 8) + 12: // div
  27543. if (this.stack.length < 2) {
  27544. error = true;
  27545. break;
  27546. }
  27547. var num2 = this.stack.pop();
  27548. var num1 = this.stack.pop();
  27549. this.stack.push(num1 / num2);
  27550. break;
  27551. case (12 << 8) + 16: // callothersubr
  27552. if (this.stack.length < 2) {
  27553. error = true;
  27554. break;
  27555. }
  27556. subrNumber = this.stack.pop();
  27557. var numArgs = this.stack.pop();
  27558. if (subrNumber === 0 && numArgs === 3) {
  27559. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  27560. this.stack.push(
  27561. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  27562. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  27563. flexArgs[4], // bcp2x
  27564. flexArgs[5], // bcp2y
  27565. flexArgs[6], // p2x
  27566. flexArgs[7], // p2y
  27567. flexArgs[8], // bcp3x
  27568. flexArgs[9], // bcp3y
  27569. flexArgs[10], // bcp4x
  27570. flexArgs[11], // bcp4y
  27571. flexArgs[12], // p3x
  27572. flexArgs[13], // p3y
  27573. flexArgs[14] // flexDepth
  27574. // 15 = finalx unused by flex
  27575. // 16 = finaly unused by flex
  27576. );
  27577. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  27578. this.flexing = false;
  27579. this.stack.push(flexArgs[15], flexArgs[16]);
  27580. } else if (subrNumber === 1 && numArgs === 0) {
  27581. this.flexing = true;
  27582. }
  27583. break;
  27584. case (12 << 8) + 17: // pop
  27585. // Ignore this since it is only used with othersubr.
  27586. break;
  27587. case (12 << 8) + 33: // setcurrentpoint
  27588. // Ignore for now.
  27589. this.stack = [];
  27590. break;
  27591. default:
  27592. warn('Unknown type 1 charstring command of "' + value + '"');
  27593. break;
  27594. }
  27595. if (error) {
  27596. break;
  27597. }
  27598. continue;
  27599. } else if (value <= 246) {
  27600. value = value - 139;
  27601. } else if (value <= 250) {
  27602. value = ((value - 247) * 256) + encoded[++i] + 108;
  27603. } else if (value <= 254) {
  27604. value = -((value - 251) * 256) - encoded[++i] - 108;
  27605. } else {
  27606. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  27607. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  27608. }
  27609. this.stack.push(value);
  27610. }
  27611. return error;
  27612. },
  27613. executeCommand: function(howManyArgs, command, keepStack) {
  27614. var stackLength = this.stack.length;
  27615. if (howManyArgs > stackLength) {
  27616. return true;
  27617. }
  27618. var start = stackLength - howManyArgs;
  27619. for (var i = start; i < stackLength; i++) {
  27620. var value = this.stack[i];
  27621. if (value === (value | 0)) { // int
  27622. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  27623. } else { // fixed point
  27624. value = (65536 * value) | 0;
  27625. this.output.push(255,
  27626. (value >> 24) & 0xFF,
  27627. (value >> 16) & 0xFF,
  27628. (value >> 8) & 0xFF,
  27629. value & 0xFF);
  27630. }
  27631. }
  27632. this.output.push.apply(this.output, command);
  27633. if (keepStack) {
  27634. this.stack.splice(start, howManyArgs);
  27635. } else {
  27636. this.stack.length = 0;
  27637. }
  27638. return false;
  27639. }
  27640. };
  27641. return Type1CharString;
  27642. })();
  27643. /*
  27644. * Type1Parser encapsulate the needed code for parsing a Type1 font
  27645. * program. Some of its logic depends on the Type2 charstrings
  27646. * structure.
  27647. * Note: this doesn't really parse the font since that would require evaluation
  27648. * of PostScript, but it is possible in most cases to extract what we need
  27649. * without a full parse.
  27650. */
  27651. var Type1Parser = (function Type1ParserClosure() {
  27652. /*
  27653. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  27654. * of Plaintext Bytes. The function took a key as a parameter which can be
  27655. * for decrypting the eexec block of for decoding charStrings.
  27656. */
  27657. var EEXEC_ENCRYPT_KEY = 55665;
  27658. var CHAR_STRS_ENCRYPT_KEY = 4330;
  27659. function isHexDigit(code) {
  27660. return code >= 48 && code <= 57 || // '0'-'9'
  27661. code >= 65 && code <= 70 || // 'A'-'F'
  27662. code >= 97 && code <= 102; // 'a'-'f'
  27663. }
  27664. function decrypt(data, key, discardNumber) {
  27665. if (discardNumber >= data.length) {
  27666. return new Uint8Array(0);
  27667. }
  27668. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  27669. for (i = 0; i < discardNumber; i++) {
  27670. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  27671. }
  27672. var count = data.length - discardNumber;
  27673. var decrypted = new Uint8Array(count);
  27674. for (i = discardNumber, j = 0; j < count; i++, j++) {
  27675. var value = data[i];
  27676. decrypted[j] = value ^ (r >> 8);
  27677. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  27678. }
  27679. return decrypted;
  27680. }
  27681. function decryptAscii(data, key, discardNumber) {
  27682. var r = key | 0, c1 = 52845, c2 = 22719;
  27683. var count = data.length, maybeLength = count >>> 1;
  27684. var decrypted = new Uint8Array(maybeLength);
  27685. var i, j;
  27686. for (i = 0, j = 0; i < count; i++) {
  27687. var digit1 = data[i];
  27688. if (!isHexDigit(digit1)) {
  27689. continue;
  27690. }
  27691. i++;
  27692. var digit2;
  27693. while (i < count && !isHexDigit(digit2 = data[i])) {
  27694. i++;
  27695. }
  27696. if (i < count) {
  27697. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  27698. decrypted[j++] = value ^ (r >> 8);
  27699. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  27700. }
  27701. }
  27702. return Array.prototype.slice.call(decrypted, discardNumber, j);
  27703. }
  27704. function isSpecial(c) {
  27705. return c === 0x2F || // '/'
  27706. c === 0x5B || c === 0x5D || // '[', ']'
  27707. c === 0x7B || c === 0x7D || // '{', '}'
  27708. c === 0x28 || c === 0x29; // '(', ')'
  27709. }
  27710. function Type1Parser(stream, encrypted) {
  27711. if (encrypted) {
  27712. var data = stream.getBytes();
  27713. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  27714. isHexDigit(data[2]) && isHexDigit(data[3]));
  27715. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  27716. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  27717. }
  27718. this.stream = stream;
  27719. this.nextChar();
  27720. }
  27721. Type1Parser.prototype = {
  27722. readNumberArray: function Type1Parser_readNumberArray() {
  27723. this.getToken(); // read '[' or '{' (arrays can start with either)
  27724. var array = [];
  27725. while (true) {
  27726. var token = this.getToken();
  27727. if (token === null || token === ']' || token === '}') {
  27728. break;
  27729. }
  27730. array.push(parseFloat(token || 0));
  27731. }
  27732. return array;
  27733. },
  27734. readNumber: function Type1Parser_readNumber() {
  27735. var token = this.getToken();
  27736. return parseFloat(token || 0);
  27737. },
  27738. readInt: function Type1Parser_readInt() {
  27739. // Use '| 0' to prevent setting a double into length such as the double
  27740. // does not flow into the loop variable.
  27741. var token = this.getToken();
  27742. return parseInt(token || 0, 10) | 0;
  27743. },
  27744. readBoolean: function Type1Parser_readBoolean() {
  27745. var token = this.getToken();
  27746. // Use 1 and 0 since that's what type2 charstrings use.
  27747. return token === 'true' ? 1 : 0;
  27748. },
  27749. nextChar : function Type1_nextChar() {
  27750. return (this.currentChar = this.stream.getByte());
  27751. },
  27752. getToken: function Type1Parser_getToken() {
  27753. // Eat whitespace and comments.
  27754. var comment = false;
  27755. var ch = this.currentChar;
  27756. while (true) {
  27757. if (ch === -1) {
  27758. return null;
  27759. }
  27760. if (comment) {
  27761. if (ch === 0x0A || ch === 0x0D) {
  27762. comment = false;
  27763. }
  27764. } else if (ch === 0x25) { // '%'
  27765. comment = true;
  27766. } else if (!Lexer.isSpace(ch)) {
  27767. break;
  27768. }
  27769. ch = this.nextChar();
  27770. }
  27771. if (isSpecial(ch)) {
  27772. this.nextChar();
  27773. return String.fromCharCode(ch);
  27774. }
  27775. var token = '';
  27776. do {
  27777. token += String.fromCharCode(ch);
  27778. ch = this.nextChar();
  27779. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  27780. return token;
  27781. },
  27782. /*
  27783. * Returns an object containing a Subrs array and a CharStrings
  27784. * array extracted from and eexec encrypted block of data
  27785. */
  27786. extractFontProgram: function Type1Parser_extractFontProgram() {
  27787. var stream = this.stream;
  27788. var subrs = [], charstrings = [];
  27789. var privateData = Object.create(null);
  27790. privateData['lenIV'] = 4;
  27791. var program = {
  27792. subrs: [],
  27793. charstrings: [],
  27794. properties: {
  27795. 'privateData': privateData
  27796. }
  27797. };
  27798. var token, length, data, lenIV, encoded;
  27799. while ((token = this.getToken()) !== null) {
  27800. if (token !== '/') {
  27801. continue;
  27802. }
  27803. token = this.getToken();
  27804. switch (token) {
  27805. case 'CharStrings':
  27806. // The number immediately following CharStrings must be greater or
  27807. // equal to the number of CharStrings.
  27808. this.getToken();
  27809. this.getToken(); // read in 'dict'
  27810. this.getToken(); // read in 'dup'
  27811. this.getToken(); // read in 'begin'
  27812. while(true) {
  27813. token = this.getToken();
  27814. if (token === null || token === 'end') {
  27815. break;
  27816. }
  27817. if (token !== '/') {
  27818. continue;
  27819. }
  27820. var glyph = this.getToken();
  27821. length = this.readInt();
  27822. this.getToken(); // read in 'RD' or '-|'
  27823. data = stream.makeSubStream(stream.pos, length);
  27824. lenIV = program.properties.privateData['lenIV'];
  27825. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  27826. // Skip past the required space and binary data.
  27827. stream.skip(length);
  27828. this.nextChar();
  27829. token = this.getToken(); // read in 'ND' or '|-'
  27830. if (token === 'noaccess') {
  27831. this.getToken(); // read in 'def'
  27832. }
  27833. charstrings.push({
  27834. glyph: glyph,
  27835. encoded: encoded
  27836. });
  27837. }
  27838. break;
  27839. case 'Subrs':
  27840. var num = this.readInt();
  27841. this.getToken(); // read in 'array'
  27842. while ((token = this.getToken()) === 'dup') {
  27843. var index = this.readInt();
  27844. length = this.readInt();
  27845. this.getToken(); // read in 'RD' or '-|'
  27846. data = stream.makeSubStream(stream.pos, length);
  27847. lenIV = program.properties.privateData['lenIV'];
  27848. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  27849. // Skip past the required space and binary data.
  27850. stream.skip(length);
  27851. this.nextChar();
  27852. token = this.getToken(); // read in 'NP' or '|'
  27853. if (token === 'noaccess') {
  27854. this.getToken(); // read in 'put'
  27855. }
  27856. subrs[index] = encoded;
  27857. }
  27858. break;
  27859. case 'BlueValues':
  27860. case 'OtherBlues':
  27861. case 'FamilyBlues':
  27862. case 'FamilyOtherBlues':
  27863. var blueArray = this.readNumberArray();
  27864. // *Blue* values may contain invalid data: disables reading of
  27865. // those values when hinting is disabled.
  27866. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  27867. HINTING_ENABLED) {
  27868. program.properties.privateData[token] = blueArray;
  27869. }
  27870. break;
  27871. case 'StemSnapH':
  27872. case 'StemSnapV':
  27873. program.properties.privateData[token] = this.readNumberArray();
  27874. break;
  27875. case 'StdHW':
  27876. case 'StdVW':
  27877. program.properties.privateData[token] =
  27878. this.readNumberArray()[0];
  27879. break;
  27880. case 'BlueShift':
  27881. case 'lenIV':
  27882. case 'BlueFuzz':
  27883. case 'BlueScale':
  27884. case 'LanguageGroup':
  27885. case 'ExpansionFactor':
  27886. program.properties.privateData[token] = this.readNumber();
  27887. break;
  27888. case 'ForceBold':
  27889. program.properties.privateData[token] = this.readBoolean();
  27890. break;
  27891. }
  27892. }
  27893. for (var i = 0; i < charstrings.length; i++) {
  27894. glyph = charstrings[i].glyph;
  27895. encoded = charstrings[i].encoded;
  27896. var charString = new Type1CharString();
  27897. var error = charString.convert(encoded, subrs);
  27898. var output = charString.output;
  27899. if (error) {
  27900. // It seems when FreeType encounters an error while evaluating a glyph
  27901. // that it completely ignores the glyph so we'll mimic that behaviour
  27902. // here and put an endchar to make the validator happy.
  27903. output = [14];
  27904. }
  27905. program.charstrings.push({
  27906. glyphName: glyph,
  27907. charstring: output,
  27908. width: charString.width,
  27909. lsb: charString.lsb,
  27910. seac: charString.seac
  27911. });
  27912. }
  27913. return program;
  27914. },
  27915. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  27916. var token;
  27917. while ((token = this.getToken()) !== null) {
  27918. if (token !== '/') {
  27919. continue;
  27920. }
  27921. token = this.getToken();
  27922. switch (token) {
  27923. case 'FontMatrix':
  27924. var matrix = this.readNumberArray();
  27925. properties.fontMatrix = matrix;
  27926. break;
  27927. case 'Encoding':
  27928. var encodingArg = this.getToken();
  27929. var encoding;
  27930. if (!/^\d+$/.test(encodingArg)) {
  27931. // encoding name is specified
  27932. encoding = getEncoding(encodingArg);
  27933. } else {
  27934. encoding = [];
  27935. var size = parseInt(encodingArg, 10) | 0;
  27936. this.getToken(); // read in 'array'
  27937. for (var j = 0; j < size; j++) {
  27938. token = this.getToken();
  27939. // skipping till first dup or def (e.g. ignoring for statement)
  27940. while (token !== 'dup' && token !== 'def') {
  27941. token = this.getToken();
  27942. if (token === null) {
  27943. return; // invalid header
  27944. }
  27945. }
  27946. if (token === 'def') {
  27947. break; // read all array data
  27948. }
  27949. var index = this.readInt();
  27950. this.getToken(); // read in '/'
  27951. var glyph = this.getToken();
  27952. encoding[index] = glyph;
  27953. this.getToken(); // read the in 'put'
  27954. }
  27955. }
  27956. properties.builtInEncoding = encoding;
  27957. break;
  27958. case 'FontBBox':
  27959. var fontBBox = this.readNumberArray();
  27960. // adjusting ascent/descent
  27961. properties.ascent = fontBBox[3];
  27962. properties.descent = fontBBox[1];
  27963. properties.ascentScaled = true;
  27964. break;
  27965. }
  27966. }
  27967. }
  27968. };
  27969. return Type1Parser;
  27970. })();
  27971. /**
  27972. * The CFF class takes a Type1 file and wrap it into a
  27973. * 'Compact Font Format' which itself embed Type2 charstrings.
  27974. */
  27975. var CFFStandardStrings = [
  27976. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  27977. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  27978. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  27979. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  27980. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  27981. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  27982. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  27983. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  27984. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  27985. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  27986. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  27987. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  27988. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  27989. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  27990. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  27991. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  27992. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  27993. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  27994. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  27995. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  27996. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  27997. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  27998. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  27999. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  28000. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  28001. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  28002. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  28003. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  28004. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  28005. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  28006. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  28007. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  28008. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  28009. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  28010. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  28011. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  28012. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  28013. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  28014. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  28015. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  28016. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  28017. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  28018. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  28019. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  28020. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  28021. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  28022. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  28023. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  28024. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  28025. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  28026. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  28027. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  28028. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  28029. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  28030. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  28031. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  28032. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  28033. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  28034. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  28035. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  28036. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  28037. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  28038. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  28039. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  28040. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  28041. ];
  28042. // Type1Font is also a CIDFontType0.
  28043. var Type1Font = function Type1Font(name, file, properties) {
  28044. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  28045. // Also, length1 and length2 might be off by 6 bytes as well.
  28046. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  28047. var PFB_HEADER_SIZE = 6;
  28048. var headerBlockLength = properties.length1;
  28049. var eexecBlockLength = properties.length2;
  28050. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  28051. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  28052. if (pfbHeaderPresent) {
  28053. file.skip(PFB_HEADER_SIZE);
  28054. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28055. (pfbHeader[3] << 8) | pfbHeader[2];
  28056. }
  28057. // Get the data block containing glyphs and subrs informations
  28058. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  28059. var headerBlockParser = new Type1Parser(headerBlock);
  28060. headerBlockParser.extractFontHeader(properties);
  28061. if (pfbHeaderPresent) {
  28062. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  28063. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  28064. (pfbHeader[3] << 8) | pfbHeader[2];
  28065. }
  28066. // Decrypt the data blocks and retrieve it's content
  28067. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  28068. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  28069. var data = eexecBlockParser.extractFontProgram();
  28070. for (var info in data.properties) {
  28071. properties[info] = data.properties[info];
  28072. }
  28073. var charstrings = data.charstrings;
  28074. var type2Charstrings = this.getType2Charstrings(charstrings);
  28075. var subrs = this.getType2Subrs(data.subrs);
  28076. this.charstrings = charstrings;
  28077. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  28078. subrs, properties);
  28079. this.seacs = this.getSeacs(data.charstrings);
  28080. };
  28081. Type1Font.prototype = {
  28082. get numGlyphs() {
  28083. return this.charstrings.length + 1;
  28084. },
  28085. getCharset: function Type1Font_getCharset() {
  28086. var charset = ['.notdef'];
  28087. var charstrings = this.charstrings;
  28088. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28089. charset.push(charstrings[glyphId].glyphName);
  28090. }
  28091. return charset;
  28092. },
  28093. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  28094. var charstrings = this.charstrings;
  28095. var glyphNames = ['.notdef'], glyphId;
  28096. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  28097. glyphNames.push(charstrings[glyphId].glyphName);
  28098. }
  28099. var encoding = properties.builtInEncoding;
  28100. if (encoding) {
  28101. var builtInEncoding = Object.create(null);
  28102. for (var charCode in encoding) {
  28103. glyphId = glyphNames.indexOf(encoding[charCode]);
  28104. if (glyphId >= 0) {
  28105. builtInEncoding[charCode] = glyphId;
  28106. }
  28107. }
  28108. }
  28109. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  28110. },
  28111. getSeacs: function Type1Font_getSeacs(charstrings) {
  28112. var i, ii;
  28113. var seacMap = [];
  28114. for (i = 0, ii = charstrings.length; i < ii; i++) {
  28115. var charstring = charstrings[i];
  28116. if (charstring.seac) {
  28117. // Offset by 1 for .notdef
  28118. seacMap[i + 1] = charstring.seac;
  28119. }
  28120. }
  28121. return seacMap;
  28122. },
  28123. getType2Charstrings: function Type1Font_getType2Charstrings(
  28124. type1Charstrings) {
  28125. var type2Charstrings = [];
  28126. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  28127. type2Charstrings.push(type1Charstrings[i].charstring);
  28128. }
  28129. return type2Charstrings;
  28130. },
  28131. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  28132. var bias = 0;
  28133. var count = type1Subrs.length;
  28134. if (count < 1133) {
  28135. bias = 107;
  28136. } else if (count < 33769) {
  28137. bias = 1131;
  28138. } else {
  28139. bias = 32768;
  28140. }
  28141. // Add a bunch of empty subrs to deal with the Type2 bias
  28142. var type2Subrs = [];
  28143. var i;
  28144. for (i = 0; i < bias; i++) {
  28145. type2Subrs.push([0x0B]);
  28146. }
  28147. for (i = 0; i < count; i++) {
  28148. type2Subrs.push(type1Subrs[i]);
  28149. }
  28150. return type2Subrs;
  28151. },
  28152. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  28153. var cff = new CFF();
  28154. cff.header = new CFFHeader(1, 0, 4, 4);
  28155. cff.names = [name];
  28156. var topDict = new CFFTopDict();
  28157. // CFF strings IDs 0...390 are predefined names, so refering
  28158. // to entries in our own String INDEX starts at SID 391.
  28159. topDict.setByName('version', 391);
  28160. topDict.setByName('Notice', 392);
  28161. topDict.setByName('FullName', 393);
  28162. topDict.setByName('FamilyName', 394);
  28163. topDict.setByName('Weight', 395);
  28164. topDict.setByName('Encoding', null); // placeholder
  28165. topDict.setByName('FontMatrix', properties.fontMatrix);
  28166. topDict.setByName('FontBBox', properties.bbox);
  28167. topDict.setByName('charset', null); // placeholder
  28168. topDict.setByName('CharStrings', null); // placeholder
  28169. topDict.setByName('Private', null); // placeholder
  28170. cff.topDict = topDict;
  28171. var strings = new CFFStrings();
  28172. strings.add('Version 0.11'); // Version
  28173. strings.add('See original notice'); // Notice
  28174. strings.add(name); // FullName
  28175. strings.add(name); // FamilyName
  28176. strings.add('Medium'); // Weight
  28177. cff.strings = strings;
  28178. cff.globalSubrIndex = new CFFIndex();
  28179. var count = glyphs.length;
  28180. var charsetArray = [0];
  28181. var i, ii;
  28182. for (i = 0; i < count; i++) {
  28183. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  28184. // TODO: Insert the string and correctly map it. Previously it was
  28185. // thought mapping names that aren't in the standard strings to .notdef
  28186. // was fine, however in issue818 when mapping them all to .notdef the
  28187. // adieresis glyph no longer worked.
  28188. if (index === -1) {
  28189. index = 0;
  28190. }
  28191. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  28192. }
  28193. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  28194. var charStringsIndex = new CFFIndex();
  28195. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  28196. for (i = 0; i < count; i++) {
  28197. charStringsIndex.add(glyphs[i]);
  28198. }
  28199. cff.charStrings = charStringsIndex;
  28200. var privateDict = new CFFPrivateDict();
  28201. privateDict.setByName('Subrs', null); // placeholder
  28202. var fields = [
  28203. 'BlueValues',
  28204. 'OtherBlues',
  28205. 'FamilyBlues',
  28206. 'FamilyOtherBlues',
  28207. 'StemSnapH',
  28208. 'StemSnapV',
  28209. 'BlueShift',
  28210. 'BlueFuzz',
  28211. 'BlueScale',
  28212. 'LanguageGroup',
  28213. 'ExpansionFactor',
  28214. 'ForceBold',
  28215. 'StdHW',
  28216. 'StdVW'
  28217. ];
  28218. for (i = 0, ii = fields.length; i < ii; i++) {
  28219. var field = fields[i];
  28220. if (!(field in properties.privateData)) {
  28221. continue;
  28222. }
  28223. var value = properties.privateData[field];
  28224. if (isArray(value)) {
  28225. // All of the private dictionary array data in CFF must be stored as
  28226. // "delta-encoded" numbers.
  28227. for (var j = value.length - 1; j > 0; j--) {
  28228. value[j] -= value[j - 1]; // ... difference from previous value
  28229. }
  28230. }
  28231. privateDict.setByName(field, value);
  28232. }
  28233. cff.topDict.privateDict = privateDict;
  28234. var subrIndex = new CFFIndex();
  28235. for (i = 0, ii = subrs.length; i < ii; i++) {
  28236. subrIndex.add(subrs[i]);
  28237. }
  28238. privateDict.subrsIndex = subrIndex;
  28239. var compiler = new CFFCompiler(cff);
  28240. return compiler.compile();
  28241. }
  28242. };
  28243. var CFFFont = (function CFFFontClosure() {
  28244. function CFFFont(file, properties) {
  28245. this.properties = properties;
  28246. var parser = new CFFParser(file, properties);
  28247. this.cff = parser.parse();
  28248. var compiler = new CFFCompiler(this.cff);
  28249. this.seacs = this.cff.seacs;
  28250. try {
  28251. this.data = compiler.compile();
  28252. } catch (e) {
  28253. warn('Failed to compile font ' + properties.loadedName);
  28254. // There may have just been an issue with the compiler, set the data
  28255. // anyway and hope the font loaded.
  28256. this.data = file;
  28257. }
  28258. }
  28259. CFFFont.prototype = {
  28260. get numGlyphs() {
  28261. return this.cff.charStrings.count;
  28262. },
  28263. getCharset: function CFFFont_getCharset() {
  28264. return this.cff.charset.charset;
  28265. },
  28266. getGlyphMapping: function CFFFont_getGlyphMapping() {
  28267. var cff = this.cff;
  28268. var properties = this.properties;
  28269. var charsets = cff.charset.charset;
  28270. var charCodeToGlyphId;
  28271. var glyphId;
  28272. if (properties.composite) {
  28273. charCodeToGlyphId = Object.create(null);
  28274. if (cff.isCIDFont) {
  28275. // If the font is actually a CID font then we should use the charset
  28276. // to map CIDs to GIDs.
  28277. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  28278. var cid = charsets[glyphId];
  28279. var charCode = properties.cMap.charCodeOf(cid);
  28280. charCodeToGlyphId[charCode] = glyphId;
  28281. }
  28282. } else {
  28283. // If it is NOT actually a CID font then CIDs should be mapped
  28284. // directly to GIDs.
  28285. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  28286. charCodeToGlyphId[glyphId] = glyphId;
  28287. }
  28288. }
  28289. return charCodeToGlyphId;
  28290. }
  28291. var encoding = cff.encoding ? cff.encoding.encoding : null;
  28292. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  28293. return charCodeToGlyphId;
  28294. }
  28295. };
  28296. return CFFFont;
  28297. })();
  28298. var CFFParser = (function CFFParserClosure() {
  28299. var CharstringValidationData = [
  28300. null,
  28301. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  28302. null,
  28303. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  28304. { id: 'vmoveto', min: 1, stackClearing: true },
  28305. { id: 'rlineto', min: 2, resetStack: true },
  28306. { id: 'hlineto', min: 1, resetStack: true },
  28307. { id: 'vlineto', min: 1, resetStack: true },
  28308. { id: 'rrcurveto', min: 6, resetStack: true },
  28309. null,
  28310. { id: 'callsubr', min: 1, undefStack: true },
  28311. { id: 'return', min: 0, undefStack: true },
  28312. null, // 12
  28313. null,
  28314. { id: 'endchar', min: 0, stackClearing: true },
  28315. null,
  28316. null,
  28317. null,
  28318. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  28319. { id: 'hintmask', min: 0, stackClearing: true },
  28320. { id: 'cntrmask', min: 0, stackClearing: true },
  28321. { id: 'rmoveto', min: 2, stackClearing: true },
  28322. { id: 'hmoveto', min: 1, stackClearing: true },
  28323. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  28324. { id: 'rcurveline', min: 8, resetStack: true },
  28325. { id: 'rlinecurve', min: 8, resetStack: true },
  28326. { id: 'vvcurveto', min: 4, resetStack: true },
  28327. { id: 'hhcurveto', min: 4, resetStack: true },
  28328. null, // shortint
  28329. { id: 'callgsubr', min: 1, undefStack: true },
  28330. { id: 'vhcurveto', min: 4, resetStack: true },
  28331. { id: 'hvcurveto', min: 4, resetStack: true }
  28332. ];
  28333. var CharstringValidationData12 = [
  28334. null,
  28335. null,
  28336. null,
  28337. { id: 'and', min: 2, stackDelta: -1 },
  28338. { id: 'or', min: 2, stackDelta: -1 },
  28339. { id: 'not', min: 1, stackDelta: 0 },
  28340. null,
  28341. null,
  28342. null,
  28343. { id: 'abs', min: 1, stackDelta: 0 },
  28344. { id: 'add', min: 2, stackDelta: -1,
  28345. stackFn: function stack_div(stack, index) {
  28346. stack[index - 2] = stack[index - 2] + stack[index - 1];
  28347. }
  28348. },
  28349. { id: 'sub', min: 2, stackDelta: -1,
  28350. stackFn: function stack_div(stack, index) {
  28351. stack[index - 2] = stack[index - 2] - stack[index - 1];
  28352. }
  28353. },
  28354. { id: 'div', min: 2, stackDelta: -1,
  28355. stackFn: function stack_div(stack, index) {
  28356. stack[index - 2] = stack[index - 2] / stack[index - 1];
  28357. }
  28358. },
  28359. null,
  28360. { id: 'neg', min: 1, stackDelta: 0,
  28361. stackFn: function stack_div(stack, index) {
  28362. stack[index - 1] = -stack[index - 1];
  28363. }
  28364. },
  28365. { id: 'eq', min: 2, stackDelta: -1 },
  28366. null,
  28367. null,
  28368. { id: 'drop', min: 1, stackDelta: -1 },
  28369. null,
  28370. { id: 'put', min: 2, stackDelta: -2 },
  28371. { id: 'get', min: 1, stackDelta: 0 },
  28372. { id: 'ifelse', min: 4, stackDelta: -3 },
  28373. { id: 'random', min: 0, stackDelta: 1 },
  28374. { id: 'mul', min: 2, stackDelta: -1,
  28375. stackFn: function stack_div(stack, index) {
  28376. stack[index - 2] = stack[index - 2] * stack[index - 1];
  28377. }
  28378. },
  28379. null,
  28380. { id: 'sqrt', min: 1, stackDelta: 0 },
  28381. { id: 'dup', min: 1, stackDelta: 1 },
  28382. { id: 'exch', min: 2, stackDelta: 0 },
  28383. { id: 'index', min: 2, stackDelta: 0 },
  28384. { id: 'roll', min: 3, stackDelta: -2 },
  28385. null,
  28386. null,
  28387. null,
  28388. { id: 'hflex', min: 7, resetStack: true },
  28389. { id: 'flex', min: 13, resetStack: true },
  28390. { id: 'hflex1', min: 9, resetStack: true },
  28391. { id: 'flex1', min: 11, resetStack: true }
  28392. ];
  28393. function CFFParser(file, properties) {
  28394. this.bytes = file.getBytes();
  28395. this.properties = properties;
  28396. }
  28397. CFFParser.prototype = {
  28398. parse: function CFFParser_parse() {
  28399. var properties = this.properties;
  28400. var cff = new CFF();
  28401. this.cff = cff;
  28402. // The first five sections must be in order, all the others are reached
  28403. // via offsets contained in one of the below.
  28404. var header = this.parseHeader();
  28405. var nameIndex = this.parseIndex(header.endPos);
  28406. var topDictIndex = this.parseIndex(nameIndex.endPos);
  28407. var stringIndex = this.parseIndex(topDictIndex.endPos);
  28408. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  28409. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  28410. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  28411. cff.header = header.obj;
  28412. cff.names = this.parseNameIndex(nameIndex.obj);
  28413. cff.strings = this.parseStringIndex(stringIndex.obj);
  28414. cff.topDict = topDict;
  28415. cff.globalSubrIndex = globalSubrIndex.obj;
  28416. this.parsePrivateDict(cff.topDict);
  28417. cff.isCIDFont = topDict.hasName('ROS');
  28418. var charStringOffset = topDict.getByName('CharStrings');
  28419. var charStringIndex = this.parseIndex(charStringOffset).obj;
  28420. var fontMatrix = topDict.getByName('FontMatrix');
  28421. if (fontMatrix) {
  28422. properties.fontMatrix = fontMatrix;
  28423. }
  28424. var fontBBox = topDict.getByName('FontBBox');
  28425. if (fontBBox) {
  28426. // adjusting ascent/descent
  28427. properties.ascent = fontBBox[3];
  28428. properties.descent = fontBBox[1];
  28429. properties.ascentScaled = true;
  28430. }
  28431. var charset, encoding;
  28432. if (cff.isCIDFont) {
  28433. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  28434. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  28435. var dictRaw = fdArrayIndex.get(i);
  28436. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  28437. cff.strings);
  28438. this.parsePrivateDict(fontDict);
  28439. cff.fdArray.push(fontDict);
  28440. }
  28441. // cid fonts don't have an encoding
  28442. encoding = null;
  28443. charset = this.parseCharsets(topDict.getByName('charset'),
  28444. charStringIndex.count, cff.strings, true);
  28445. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  28446. charStringIndex.count);
  28447. } else {
  28448. charset = this.parseCharsets(topDict.getByName('charset'),
  28449. charStringIndex.count, cff.strings, false);
  28450. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  28451. properties,
  28452. cff.strings, charset.charset);
  28453. }
  28454. cff.charset = charset;
  28455. cff.encoding = encoding;
  28456. var charStringsAndSeacs = this.parseCharStrings(
  28457. charStringIndex,
  28458. topDict.privateDict.subrsIndex,
  28459. globalSubrIndex.obj,
  28460. cff.fdSelect,
  28461. cff.fdArray);
  28462. cff.charStrings = charStringsAndSeacs.charStrings;
  28463. cff.seacs = charStringsAndSeacs.seacs;
  28464. cff.widths = charStringsAndSeacs.widths;
  28465. return cff;
  28466. },
  28467. parseHeader: function CFFParser_parseHeader() {
  28468. var bytes = this.bytes;
  28469. var bytesLength = bytes.length;
  28470. var offset = 0;
  28471. // Prevent an infinite loop, by checking that the offset is within the
  28472. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  28473. while (offset < bytesLength && bytes[offset] !== 1) {
  28474. ++offset;
  28475. }
  28476. if (offset >= bytesLength) {
  28477. error('Invalid CFF header');
  28478. } else if (offset !== 0) {
  28479. info('cff data is shifted');
  28480. bytes = bytes.subarray(offset);
  28481. this.bytes = bytes;
  28482. }
  28483. var major = bytes[0];
  28484. var minor = bytes[1];
  28485. var hdrSize = bytes[2];
  28486. var offSize = bytes[3];
  28487. var header = new CFFHeader(major, minor, hdrSize, offSize);
  28488. return { obj: header, endPos: hdrSize };
  28489. },
  28490. parseDict: function CFFParser_parseDict(dict) {
  28491. var pos = 0;
  28492. function parseOperand() {
  28493. var value = dict[pos++];
  28494. if (value === 30) {
  28495. return parseFloatOperand(pos);
  28496. } else if (value === 28) {
  28497. value = dict[pos++];
  28498. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  28499. return value;
  28500. } else if (value === 29) {
  28501. value = dict[pos++];
  28502. value = (value << 8) | dict[pos++];
  28503. value = (value << 8) | dict[pos++];
  28504. value = (value << 8) | dict[pos++];
  28505. return value;
  28506. } else if (value >= 32 && value <= 246) {
  28507. return value - 139;
  28508. } else if (value >= 247 && value <= 250) {
  28509. return ((value - 247) * 256) + dict[pos++] + 108;
  28510. } else if (value >= 251 && value <= 254) {
  28511. return -((value - 251) * 256) - dict[pos++] - 108;
  28512. } else {
  28513. error('255 is not a valid DICT command');
  28514. }
  28515. return -1;
  28516. }
  28517. function parseFloatOperand() {
  28518. var str = '';
  28519. var eof = 15;
  28520. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  28521. '9', '.', 'E', 'E-', null, '-'];
  28522. var length = dict.length;
  28523. while (pos < length) {
  28524. var b = dict[pos++];
  28525. var b1 = b >> 4;
  28526. var b2 = b & 15;
  28527. if (b1 === eof) {
  28528. break;
  28529. }
  28530. str += lookup[b1];
  28531. if (b2 === eof) {
  28532. break;
  28533. }
  28534. str += lookup[b2];
  28535. }
  28536. return parseFloat(str);
  28537. }
  28538. var operands = [];
  28539. var entries = [];
  28540. pos = 0;
  28541. var end = dict.length;
  28542. while (pos < end) {
  28543. var b = dict[pos];
  28544. if (b <= 21) {
  28545. if (b === 12) {
  28546. b = (b << 8) | dict[++pos];
  28547. }
  28548. entries.push([b, operands]);
  28549. operands = [];
  28550. ++pos;
  28551. } else {
  28552. operands.push(parseOperand());
  28553. }
  28554. }
  28555. return entries;
  28556. },
  28557. parseIndex: function CFFParser_parseIndex(pos) {
  28558. var cffIndex = new CFFIndex();
  28559. var bytes = this.bytes;
  28560. var count = (bytes[pos++] << 8) | bytes[pos++];
  28561. var offsets = [];
  28562. var end = pos;
  28563. var i, ii;
  28564. if (count !== 0) {
  28565. var offsetSize = bytes[pos++];
  28566. // add 1 for offset to determine size of last object
  28567. var startPos = pos + ((count + 1) * offsetSize) - 1;
  28568. for (i = 0, ii = count + 1; i < ii; ++i) {
  28569. var offset = 0;
  28570. for (var j = 0; j < offsetSize; ++j) {
  28571. offset <<= 8;
  28572. offset += bytes[pos++];
  28573. }
  28574. offsets.push(startPos + offset);
  28575. }
  28576. end = offsets[count];
  28577. }
  28578. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  28579. var offsetStart = offsets[i];
  28580. var offsetEnd = offsets[i + 1];
  28581. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  28582. }
  28583. return {obj: cffIndex, endPos: end};
  28584. },
  28585. parseNameIndex: function CFFParser_parseNameIndex(index) {
  28586. var names = [];
  28587. for (var i = 0, ii = index.count; i < ii; ++i) {
  28588. var name = index.get(i);
  28589. // OTS doesn't allow names to be over 127 characters.
  28590. var length = Math.min(name.length, 127);
  28591. var data = [];
  28592. // OTS also only permits certain characters in the name.
  28593. for (var j = 0; j < length; ++j) {
  28594. var c = name[j];
  28595. if (j === 0 && c === 0) {
  28596. data[j] = c;
  28597. continue;
  28598. }
  28599. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  28600. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  28601. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  28602. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  28603. data[j] = 95;
  28604. continue;
  28605. }
  28606. data[j] = c;
  28607. }
  28608. names.push(bytesToString(data));
  28609. }
  28610. return names;
  28611. },
  28612. parseStringIndex: function CFFParser_parseStringIndex(index) {
  28613. var strings = new CFFStrings();
  28614. for (var i = 0, ii = index.count; i < ii; ++i) {
  28615. var data = index.get(i);
  28616. strings.add(bytesToString(data));
  28617. }
  28618. return strings;
  28619. },
  28620. createDict: function CFFParser_createDict(Type, dict, strings) {
  28621. var cffDict = new Type(strings);
  28622. for (var i = 0, ii = dict.length; i < ii; ++i) {
  28623. var pair = dict[i];
  28624. var key = pair[0];
  28625. var value = pair[1];
  28626. cffDict.setByKey(key, value);
  28627. }
  28628. return cffDict;
  28629. },
  28630. parseCharString: function CFFParser_parseCharString(state, data,
  28631. localSubrIndex,
  28632. globalSubrIndex) {
  28633. if (state.callDepth > MAX_SUBR_NESTING) {
  28634. return false;
  28635. }
  28636. var stackSize = state.stackSize;
  28637. var stack = state.stack;
  28638. var length = data.length;
  28639. for (var j = 0; j < length;) {
  28640. var value = data[j++];
  28641. var validationCommand = null;
  28642. if (value === 12) {
  28643. var q = data[j++];
  28644. if (q === 0) {
  28645. // The CFF specification state that the 'dotsection' command
  28646. // (12, 0) is deprecated and treated as a no-op, but all Type2
  28647. // charstrings processors should support them. Unfortunately
  28648. // the font sanitizer don't. As a workaround the sequence (12, 0)
  28649. // is replaced by a useless (0, hmoveto).
  28650. data[j - 2] = 139;
  28651. data[j - 1] = 22;
  28652. stackSize = 0;
  28653. } else {
  28654. validationCommand = CharstringValidationData12[q];
  28655. }
  28656. } else if (value === 28) { // number (16 bit)
  28657. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  28658. j += 2;
  28659. stackSize++;
  28660. } else if (value === 14) {
  28661. if (stackSize >= 4) {
  28662. stackSize -= 4;
  28663. if (SEAC_ANALYSIS_ENABLED) {
  28664. state.seac = stack.slice(stackSize, stackSize + 4);
  28665. return false;
  28666. }
  28667. }
  28668. validationCommand = CharstringValidationData[value];
  28669. } else if (value >= 32 && value <= 246) { // number
  28670. stack[stackSize] = value - 139;
  28671. stackSize++;
  28672. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  28673. stack[stackSize] = (value < 251 ?
  28674. ((value - 247) << 8) + data[j] + 108 :
  28675. -((value - 251) << 8) - data[j] - 108);
  28676. j++;
  28677. stackSize++;
  28678. } else if (value === 255) { // number (32 bit)
  28679. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  28680. (data[j + 2] << 8) | data[j + 3]) / 65536;
  28681. j += 4;
  28682. stackSize++;
  28683. } else if (value === 19 || value === 20) {
  28684. state.hints += stackSize >> 1;
  28685. // skipping right amount of hints flag data
  28686. j += (state.hints + 7) >> 3;
  28687. stackSize %= 2;
  28688. validationCommand = CharstringValidationData[value];
  28689. } else if (value === 10 || value === 29) {
  28690. var subrsIndex;
  28691. if (value === 10) {
  28692. subrsIndex = localSubrIndex;
  28693. } else {
  28694. subrsIndex = globalSubrIndex;
  28695. }
  28696. if (!subrsIndex) {
  28697. validationCommand = CharstringValidationData[value];
  28698. warn('Missing subrsIndex for ' + validationCommand.id);
  28699. return false;
  28700. }
  28701. var bias = 32768;
  28702. if (subrsIndex.count < 1240) {
  28703. bias = 107;
  28704. } else if (subrsIndex.count < 33900) {
  28705. bias = 1131;
  28706. }
  28707. var subrNumber = stack[--stackSize] + bias;
  28708. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  28709. validationCommand = CharstringValidationData[value];
  28710. warn('Out of bounds subrIndex for ' + validationCommand.id);
  28711. return false;
  28712. }
  28713. state.stackSize = stackSize;
  28714. state.callDepth++;
  28715. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  28716. localSubrIndex, globalSubrIndex);
  28717. if (!valid) {
  28718. return false;
  28719. }
  28720. state.callDepth--;
  28721. stackSize = state.stackSize;
  28722. continue;
  28723. } else if (value === 11) {
  28724. state.stackSize = stackSize;
  28725. return true;
  28726. } else {
  28727. validationCommand = CharstringValidationData[value];
  28728. }
  28729. if (validationCommand) {
  28730. if (validationCommand.stem) {
  28731. state.hints += stackSize >> 1;
  28732. }
  28733. if ('min' in validationCommand) {
  28734. if (!state.undefStack && stackSize < validationCommand.min) {
  28735. warn('Not enough parameters for ' + validationCommand.id +
  28736. '; actual: ' + stackSize +
  28737. ', expected: ' + validationCommand.min);
  28738. return false;
  28739. }
  28740. }
  28741. if (state.firstStackClearing && validationCommand.stackClearing) {
  28742. state.firstStackClearing = false;
  28743. // the optional character width can be found before the first
  28744. // stack-clearing command arguments
  28745. stackSize -= validationCommand.min;
  28746. if (stackSize >= 2 && validationCommand.stem) {
  28747. // there are even amount of arguments for stem commands
  28748. stackSize %= 2;
  28749. } else if (stackSize > 1) {
  28750. warn('Found too many parameters for stack-clearing command');
  28751. }
  28752. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  28753. state.width = stack[stackSize - 1];
  28754. }
  28755. }
  28756. if ('stackDelta' in validationCommand) {
  28757. if ('stackFn' in validationCommand) {
  28758. validationCommand.stackFn(stack, stackSize);
  28759. }
  28760. stackSize += validationCommand.stackDelta;
  28761. } else if (validationCommand.stackClearing) {
  28762. stackSize = 0;
  28763. } else if (validationCommand.resetStack) {
  28764. stackSize = 0;
  28765. state.undefStack = false;
  28766. } else if (validationCommand.undefStack) {
  28767. stackSize = 0;
  28768. state.undefStack = true;
  28769. state.firstStackClearing = false;
  28770. }
  28771. }
  28772. }
  28773. state.stackSize = stackSize;
  28774. return true;
  28775. },
  28776. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  28777. localSubrIndex,
  28778. globalSubrIndex,
  28779. fdSelect,
  28780. fdArray) {
  28781. var seacs = [];
  28782. var widths = [];
  28783. var count = charStrings.count;
  28784. for (var i = 0; i < count; i++) {
  28785. var charstring = charStrings.get(i);
  28786. var state = {
  28787. callDepth: 0,
  28788. stackSize: 0,
  28789. stack: [],
  28790. undefStack: true,
  28791. hints: 0,
  28792. firstStackClearing: true,
  28793. seac: null,
  28794. width: null
  28795. };
  28796. var valid = true;
  28797. var localSubrToUse = null;
  28798. if (fdSelect && fdArray.length) {
  28799. var fdIndex = fdSelect.getFDIndex(i);
  28800. if (fdIndex === -1) {
  28801. warn('Glyph index is not in fd select.');
  28802. valid = false;
  28803. }
  28804. if (fdIndex >= fdArray.length) {
  28805. warn('Invalid fd index for glyph index.');
  28806. valid = false;
  28807. }
  28808. if (valid) {
  28809. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  28810. }
  28811. } else if (localSubrIndex) {
  28812. localSubrToUse = localSubrIndex;
  28813. }
  28814. if (valid) {
  28815. valid = this.parseCharString(state, charstring, localSubrToUse,
  28816. globalSubrIndex);
  28817. }
  28818. if (state.width !== null) {
  28819. widths[i] = state.width;
  28820. }
  28821. if (state.seac !== null) {
  28822. seacs[i] = state.seac;
  28823. }
  28824. if (!valid) {
  28825. // resetting invalid charstring to single 'endchar'
  28826. charStrings.set(i, new Uint8Array([14]));
  28827. }
  28828. }
  28829. return { charStrings: charStrings, seacs: seacs, widths: widths };
  28830. },
  28831. emptyPrivateDictionary:
  28832. function CFFParser_emptyPrivateDictionary(parentDict) {
  28833. var privateDict = this.createDict(CFFPrivateDict, [],
  28834. parentDict.strings);
  28835. parentDict.setByKey(18, [0, 0]);
  28836. parentDict.privateDict = privateDict;
  28837. },
  28838. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  28839. // no private dict, do nothing
  28840. if (!parentDict.hasName('Private')) {
  28841. this.emptyPrivateDictionary(parentDict);
  28842. return;
  28843. }
  28844. var privateOffset = parentDict.getByName('Private');
  28845. // make sure the params are formatted correctly
  28846. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  28847. parentDict.removeByName('Private');
  28848. return;
  28849. }
  28850. var size = privateOffset[0];
  28851. var offset = privateOffset[1];
  28852. // remove empty dicts or ones that refer to invalid location
  28853. if (size === 0 || offset >= this.bytes.length) {
  28854. this.emptyPrivateDictionary(parentDict);
  28855. return;
  28856. }
  28857. var privateDictEnd = offset + size;
  28858. var dictData = this.bytes.subarray(offset, privateDictEnd);
  28859. var dict = this.parseDict(dictData);
  28860. var privateDict = this.createDict(CFFPrivateDict, dict,
  28861. parentDict.strings);
  28862. parentDict.privateDict = privateDict;
  28863. // Parse the Subrs index also since it's relative to the private dict.
  28864. if (!privateDict.getByName('Subrs')) {
  28865. return;
  28866. }
  28867. var subrsOffset = privateDict.getByName('Subrs');
  28868. var relativeOffset = offset + subrsOffset;
  28869. // Validate the offset.
  28870. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  28871. this.emptyPrivateDictionary(parentDict);
  28872. return;
  28873. }
  28874. var subrsIndex = this.parseIndex(relativeOffset);
  28875. privateDict.subrsIndex = subrsIndex.obj;
  28876. },
  28877. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  28878. if (pos === 0) {
  28879. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  28880. ISOAdobeCharset);
  28881. } else if (pos === 1) {
  28882. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  28883. ExpertCharset);
  28884. } else if (pos === 2) {
  28885. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  28886. ExpertSubsetCharset);
  28887. }
  28888. var bytes = this.bytes;
  28889. var start = pos;
  28890. var format = bytes[pos++];
  28891. var charset = ['.notdef'];
  28892. var id, count, i;
  28893. // subtract 1 for the .notdef glyph
  28894. length -= 1;
  28895. switch (format) {
  28896. case 0:
  28897. for (i = 0; i < length; i++) {
  28898. id = (bytes[pos++] << 8) | bytes[pos++];
  28899. charset.push(cid ? id : strings.get(id));
  28900. }
  28901. break;
  28902. case 1:
  28903. while (charset.length <= length) {
  28904. id = (bytes[pos++] << 8) | bytes[pos++];
  28905. count = bytes[pos++];
  28906. for (i = 0; i <= count; i++) {
  28907. charset.push(cid ? id++ : strings.get(id++));
  28908. }
  28909. }
  28910. break;
  28911. case 2:
  28912. while (charset.length <= length) {
  28913. id = (bytes[pos++] << 8) | bytes[pos++];
  28914. count = (bytes[pos++] << 8) | bytes[pos++];
  28915. for (i = 0; i <= count; i++) {
  28916. charset.push(cid ? id++ : strings.get(id++));
  28917. }
  28918. }
  28919. break;
  28920. default:
  28921. error('Unknown charset format');
  28922. }
  28923. // Raw won't be needed if we actually compile the charset.
  28924. var end = pos;
  28925. var raw = bytes.subarray(start, end);
  28926. return new CFFCharset(false, format, charset, raw);
  28927. },
  28928. parseEncoding: function CFFParser_parseEncoding(pos,
  28929. properties,
  28930. strings,
  28931. charset) {
  28932. var encoding = Object.create(null);
  28933. var bytes = this.bytes;
  28934. var predefined = false;
  28935. var hasSupplement = false;
  28936. var format, i, ii;
  28937. var raw = null;
  28938. function readSupplement() {
  28939. var supplementsCount = bytes[pos++];
  28940. for (i = 0; i < supplementsCount; i++) {
  28941. var code = bytes[pos++];
  28942. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  28943. encoding[code] = charset.indexOf(strings.get(sid));
  28944. }
  28945. }
  28946. if (pos === 0 || pos === 1) {
  28947. predefined = true;
  28948. format = pos;
  28949. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  28950. for (i = 0, ii = charset.length; i < ii; i++) {
  28951. var index = baseEncoding.indexOf(charset[i]);
  28952. if (index !== -1) {
  28953. encoding[index] = i;
  28954. }
  28955. }
  28956. } else {
  28957. var dataStart = pos;
  28958. format = bytes[pos++];
  28959. switch (format & 0x7f) {
  28960. case 0:
  28961. var glyphsCount = bytes[pos++];
  28962. for (i = 1; i <= glyphsCount; i++) {
  28963. encoding[bytes[pos++]] = i;
  28964. }
  28965. break;
  28966. case 1:
  28967. var rangesCount = bytes[pos++];
  28968. var gid = 1;
  28969. for (i = 0; i < rangesCount; i++) {
  28970. var start = bytes[pos++];
  28971. var left = bytes[pos++];
  28972. for (var j = start; j <= start + left; j++) {
  28973. encoding[j] = gid++;
  28974. }
  28975. }
  28976. break;
  28977. default:
  28978. error('Unknow encoding format: ' + format + ' in CFF');
  28979. break;
  28980. }
  28981. var dataEnd = pos;
  28982. if (format & 0x80) {
  28983. // The font sanitizer does not support CFF encoding with a
  28984. // supplement, since the encoding is not really used to map
  28985. // between gid to glyph, let's overwrite what is declared in
  28986. // the top dictionary to let the sanitizer think the font use
  28987. // StandardEncoding, that's a lie but that's ok.
  28988. bytes[dataStart] &= 0x7f;
  28989. readSupplement();
  28990. hasSupplement = true;
  28991. }
  28992. raw = bytes.subarray(dataStart, dataEnd);
  28993. }
  28994. format = format & 0x7f;
  28995. return new CFFEncoding(predefined, format, encoding, raw);
  28996. },
  28997. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  28998. var start = pos;
  28999. var bytes = this.bytes;
  29000. var format = bytes[pos++];
  29001. var fdSelect = [];
  29002. var i;
  29003. switch (format) {
  29004. case 0:
  29005. for (i = 0; i < length; ++i) {
  29006. var id = bytes[pos++];
  29007. fdSelect.push(id);
  29008. }
  29009. break;
  29010. case 3:
  29011. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  29012. for (i = 0; i < rangesCount; ++i) {
  29013. var first = (bytes[pos++] << 8) | bytes[pos++];
  29014. var fdIndex = bytes[pos++];
  29015. var next = (bytes[pos] << 8) | bytes[pos + 1];
  29016. for (var j = first; j < next; ++j) {
  29017. fdSelect.push(fdIndex);
  29018. }
  29019. }
  29020. // Advance past the sentinel(next).
  29021. pos += 2;
  29022. break;
  29023. default:
  29024. error('Unknown fdselect format ' + format);
  29025. break;
  29026. }
  29027. var end = pos;
  29028. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  29029. }
  29030. };
  29031. return CFFParser;
  29032. })();
  29033. // Compact Font Format
  29034. var CFF = (function CFFClosure() {
  29035. function CFF() {
  29036. this.header = null;
  29037. this.names = [];
  29038. this.topDict = null;
  29039. this.strings = new CFFStrings();
  29040. this.globalSubrIndex = null;
  29041. // The following could really be per font, but since we only have one font
  29042. // store them here.
  29043. this.encoding = null;
  29044. this.charset = null;
  29045. this.charStrings = null;
  29046. this.fdArray = [];
  29047. this.fdSelect = null;
  29048. this.isCIDFont = false;
  29049. }
  29050. return CFF;
  29051. })();
  29052. var CFFHeader = (function CFFHeaderClosure() {
  29053. function CFFHeader(major, minor, hdrSize, offSize) {
  29054. this.major = major;
  29055. this.minor = minor;
  29056. this.hdrSize = hdrSize;
  29057. this.offSize = offSize;
  29058. }
  29059. return CFFHeader;
  29060. })();
  29061. var CFFStrings = (function CFFStringsClosure() {
  29062. function CFFStrings() {
  29063. this.strings = [];
  29064. }
  29065. CFFStrings.prototype = {
  29066. get: function CFFStrings_get(index) {
  29067. if (index >= 0 && index <= 390) {
  29068. return CFFStandardStrings[index];
  29069. }
  29070. if (index - 391 <= this.strings.length) {
  29071. return this.strings[index - 391];
  29072. }
  29073. return CFFStandardStrings[0];
  29074. },
  29075. add: function CFFStrings_add(value) {
  29076. this.strings.push(value);
  29077. },
  29078. get count() {
  29079. return this.strings.length;
  29080. }
  29081. };
  29082. return CFFStrings;
  29083. })();
  29084. var CFFIndex = (function CFFIndexClosure() {
  29085. function CFFIndex() {
  29086. this.objects = [];
  29087. this.length = 0;
  29088. }
  29089. CFFIndex.prototype = {
  29090. add: function CFFIndex_add(data) {
  29091. this.length += data.length;
  29092. this.objects.push(data);
  29093. },
  29094. set: function CFFIndex_set(index, data) {
  29095. this.length += data.length - this.objects[index].length;
  29096. this.objects[index] = data;
  29097. },
  29098. get: function CFFIndex_get(index) {
  29099. return this.objects[index];
  29100. },
  29101. get count() {
  29102. return this.objects.length;
  29103. }
  29104. };
  29105. return CFFIndex;
  29106. })();
  29107. var CFFDict = (function CFFDictClosure() {
  29108. function CFFDict(tables, strings) {
  29109. this.keyToNameMap = tables.keyToNameMap;
  29110. this.nameToKeyMap = tables.nameToKeyMap;
  29111. this.defaults = tables.defaults;
  29112. this.types = tables.types;
  29113. this.opcodes = tables.opcodes;
  29114. this.order = tables.order;
  29115. this.strings = strings;
  29116. this.values = Object.create(null);
  29117. }
  29118. CFFDict.prototype = {
  29119. // value should always be an array
  29120. setByKey: function CFFDict_setByKey(key, value) {
  29121. if (!(key in this.keyToNameMap)) {
  29122. return false;
  29123. }
  29124. // ignore empty values
  29125. if (value.length === 0) {
  29126. return true;
  29127. }
  29128. var type = this.types[key];
  29129. // remove the array wrapping these types of values
  29130. if (type === 'num' || type === 'sid' || type === 'offset') {
  29131. value = value[0];
  29132. }
  29133. this.values[key] = value;
  29134. return true;
  29135. },
  29136. setByName: function CFFDict_setByName(name, value) {
  29137. if (!(name in this.nameToKeyMap)) {
  29138. error('Invalid dictionary name "' + name + '"');
  29139. }
  29140. this.values[this.nameToKeyMap[name]] = value;
  29141. },
  29142. hasName: function CFFDict_hasName(name) {
  29143. return this.nameToKeyMap[name] in this.values;
  29144. },
  29145. getByName: function CFFDict_getByName(name) {
  29146. if (!(name in this.nameToKeyMap)) {
  29147. error('Invalid dictionary name "' + name + '"');
  29148. }
  29149. var key = this.nameToKeyMap[name];
  29150. if (!(key in this.values)) {
  29151. return this.defaults[key];
  29152. }
  29153. return this.values[key];
  29154. },
  29155. removeByName: function CFFDict_removeByName(name) {
  29156. delete this.values[this.nameToKeyMap[name]];
  29157. }
  29158. };
  29159. CFFDict.createTables = function CFFDict_createTables(layout) {
  29160. var tables = {
  29161. keyToNameMap: {},
  29162. nameToKeyMap: {},
  29163. defaults: {},
  29164. types: {},
  29165. opcodes: {},
  29166. order: []
  29167. };
  29168. for (var i = 0, ii = layout.length; i < ii; ++i) {
  29169. var entry = layout[i];
  29170. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  29171. tables.keyToNameMap[key] = entry[1];
  29172. tables.nameToKeyMap[entry[1]] = key;
  29173. tables.types[key] = entry[2];
  29174. tables.defaults[key] = entry[3];
  29175. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  29176. tables.order.push(key);
  29177. }
  29178. return tables;
  29179. };
  29180. return CFFDict;
  29181. })();
  29182. var CFFTopDict = (function CFFTopDictClosure() {
  29183. var layout = [
  29184. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  29185. [[12, 20], 'SyntheticBase', 'num', null],
  29186. [0, 'version', 'sid', null],
  29187. [1, 'Notice', 'sid', null],
  29188. [[12, 0], 'Copyright', 'sid', null],
  29189. [2, 'FullName', 'sid', null],
  29190. [3, 'FamilyName', 'sid', null],
  29191. [4, 'Weight', 'sid', null],
  29192. [[12, 1], 'isFixedPitch', 'num', 0],
  29193. [[12, 2], 'ItalicAngle', 'num', 0],
  29194. [[12, 3], 'UnderlinePosition', 'num', -100],
  29195. [[12, 4], 'UnderlineThickness', 'num', 50],
  29196. [[12, 5], 'PaintType', 'num', 0],
  29197. [[12, 6], 'CharstringType', 'num', 2],
  29198. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  29199. [0.001, 0, 0, 0.001, 0, 0]],
  29200. [13, 'UniqueID', 'num', null],
  29201. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  29202. [[12, 8], 'StrokeWidth', 'num', 0],
  29203. [14, 'XUID', 'array', null],
  29204. [15, 'charset', 'offset', 0],
  29205. [16, 'Encoding', 'offset', 0],
  29206. [17, 'CharStrings', 'offset', 0],
  29207. [18, 'Private', ['offset', 'offset'], null],
  29208. [[12, 21], 'PostScript', 'sid', null],
  29209. [[12, 22], 'BaseFontName', 'sid', null],
  29210. [[12, 23], 'BaseFontBlend', 'delta', null],
  29211. [[12, 31], 'CIDFontVersion', 'num', 0],
  29212. [[12, 32], 'CIDFontRevision', 'num', 0],
  29213. [[12, 33], 'CIDFontType', 'num', 0],
  29214. [[12, 34], 'CIDCount', 'num', 8720],
  29215. [[12, 35], 'UIDBase', 'num', null],
  29216. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  29217. // before FDArray.
  29218. [[12, 37], 'FDSelect', 'offset', null],
  29219. [[12, 36], 'FDArray', 'offset', null],
  29220. [[12, 38], 'FontName', 'sid', null]
  29221. ];
  29222. var tables = null;
  29223. function CFFTopDict(strings) {
  29224. if (tables === null) {
  29225. tables = CFFDict.createTables(layout);
  29226. }
  29227. CFFDict.call(this, tables, strings);
  29228. this.privateDict = null;
  29229. }
  29230. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  29231. return CFFTopDict;
  29232. })();
  29233. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  29234. var layout = [
  29235. [6, 'BlueValues', 'delta', null],
  29236. [7, 'OtherBlues', 'delta', null],
  29237. [8, 'FamilyBlues', 'delta', null],
  29238. [9, 'FamilyOtherBlues', 'delta', null],
  29239. [[12, 9], 'BlueScale', 'num', 0.039625],
  29240. [[12, 10], 'BlueShift', 'num', 7],
  29241. [[12, 11], 'BlueFuzz', 'num', 1],
  29242. [10, 'StdHW', 'num', null],
  29243. [11, 'StdVW', 'num', null],
  29244. [[12, 12], 'StemSnapH', 'delta', null],
  29245. [[12, 13], 'StemSnapV', 'delta', null],
  29246. [[12, 14], 'ForceBold', 'num', 0],
  29247. [[12, 17], 'LanguageGroup', 'num', 0],
  29248. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  29249. [[12, 19], 'initialRandomSeed', 'num', 0],
  29250. [20, 'defaultWidthX', 'num', 0],
  29251. [21, 'nominalWidthX', 'num', 0],
  29252. [19, 'Subrs', 'offset', null]
  29253. ];
  29254. var tables = null;
  29255. function CFFPrivateDict(strings) {
  29256. if (tables === null) {
  29257. tables = CFFDict.createTables(layout);
  29258. }
  29259. CFFDict.call(this, tables, strings);
  29260. this.subrsIndex = null;
  29261. }
  29262. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  29263. return CFFPrivateDict;
  29264. })();
  29265. var CFFCharsetPredefinedTypes = {
  29266. ISO_ADOBE: 0,
  29267. EXPERT: 1,
  29268. EXPERT_SUBSET: 2
  29269. };
  29270. var CFFCharset = (function CFFCharsetClosure() {
  29271. function CFFCharset(predefined, format, charset, raw) {
  29272. this.predefined = predefined;
  29273. this.format = format;
  29274. this.charset = charset;
  29275. this.raw = raw;
  29276. }
  29277. return CFFCharset;
  29278. })();
  29279. var CFFEncoding = (function CFFEncodingClosure() {
  29280. function CFFEncoding(predefined, format, encoding, raw) {
  29281. this.predefined = predefined;
  29282. this.format = format;
  29283. this.encoding = encoding;
  29284. this.raw = raw;
  29285. }
  29286. return CFFEncoding;
  29287. })();
  29288. var CFFFDSelect = (function CFFFDSelectClosure() {
  29289. function CFFFDSelect(fdSelect, raw) {
  29290. this.fdSelect = fdSelect;
  29291. this.raw = raw;
  29292. }
  29293. CFFFDSelect.prototype = {
  29294. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  29295. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  29296. return -1;
  29297. }
  29298. return this.fdSelect[glyphIndex];
  29299. }
  29300. };
  29301. return CFFFDSelect;
  29302. })();
  29303. // Helper class to keep track of where an offset is within the data and helps
  29304. // filling in that offset once it's known.
  29305. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  29306. function CFFOffsetTracker() {
  29307. this.offsets = Object.create(null);
  29308. }
  29309. CFFOffsetTracker.prototype = {
  29310. isTracking: function CFFOffsetTracker_isTracking(key) {
  29311. return key in this.offsets;
  29312. },
  29313. track: function CFFOffsetTracker_track(key, location) {
  29314. if (key in this.offsets) {
  29315. error('Already tracking location of ' + key);
  29316. }
  29317. this.offsets[key] = location;
  29318. },
  29319. offset: function CFFOffsetTracker_offset(value) {
  29320. for (var key in this.offsets) {
  29321. this.offsets[key] += value;
  29322. }
  29323. },
  29324. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  29325. values,
  29326. output) {
  29327. if (!(key in this.offsets)) {
  29328. error('Not tracking location of ' + key);
  29329. }
  29330. var data = output.data;
  29331. var dataOffset = this.offsets[key];
  29332. var size = 5;
  29333. for (var i = 0, ii = values.length; i < ii; ++i) {
  29334. var offset0 = i * size + dataOffset;
  29335. var offset1 = offset0 + 1;
  29336. var offset2 = offset0 + 2;
  29337. var offset3 = offset0 + 3;
  29338. var offset4 = offset0 + 4;
  29339. // It's easy to screw up offsets so perform this sanity check.
  29340. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  29341. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  29342. error('writing to an offset that is not empty');
  29343. }
  29344. var value = values[i];
  29345. data[offset0] = 0x1d;
  29346. data[offset1] = (value >> 24) & 0xFF;
  29347. data[offset2] = (value >> 16) & 0xFF;
  29348. data[offset3] = (value >> 8) & 0xFF;
  29349. data[offset4] = value & 0xFF;
  29350. }
  29351. }
  29352. };
  29353. return CFFOffsetTracker;
  29354. })();
  29355. // Takes a CFF and converts it to the binary representation.
  29356. var CFFCompiler = (function CFFCompilerClosure() {
  29357. function CFFCompiler(cff) {
  29358. this.cff = cff;
  29359. }
  29360. CFFCompiler.prototype = {
  29361. compile: function CFFCompiler_compile() {
  29362. var cff = this.cff;
  29363. var output = {
  29364. data: [],
  29365. length: 0,
  29366. add: function CFFCompiler_add(data) {
  29367. this.data = this.data.concat(data);
  29368. this.length = this.data.length;
  29369. }
  29370. };
  29371. // Compile the five entries that must be in order.
  29372. var header = this.compileHeader(cff.header);
  29373. output.add(header);
  29374. var nameIndex = this.compileNameIndex(cff.names);
  29375. output.add(nameIndex);
  29376. if (cff.isCIDFont) {
  29377. // The spec is unclear on how font matrices should relate to each other
  29378. // when there is one in the main top dict and the sub top dicts.
  29379. // Windows handles this differently than linux and osx so we have to
  29380. // normalize to work on all.
  29381. // Rules based off of some mailing list discussions:
  29382. // - If main font has a matrix and subfont doesn't, use the main matrix.
  29383. // - If no main font matrix and there is a subfont matrix, use the
  29384. // subfont matrix.
  29385. // - If both have matrices, concat together.
  29386. // - If neither have matrices, use default.
  29387. // To make this work on all platforms we move the top matrix into each
  29388. // sub top dict and concat if necessary.
  29389. if (cff.topDict.hasName('FontMatrix')) {
  29390. var base = cff.topDict.getByName('FontMatrix');
  29391. cff.topDict.removeByName('FontMatrix');
  29392. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  29393. var subDict = cff.fdArray[i];
  29394. var matrix = base.slice(0);
  29395. if (subDict.hasName('FontMatrix')) {
  29396. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  29397. }
  29398. subDict.setByName('FontMatrix', matrix);
  29399. }
  29400. }
  29401. }
  29402. var compiled = this.compileTopDicts([cff.topDict],
  29403. output.length,
  29404. cff.isCIDFont);
  29405. output.add(compiled.output);
  29406. var topDictTracker = compiled.trackers[0];
  29407. var stringIndex = this.compileStringIndex(cff.strings.strings);
  29408. output.add(stringIndex);
  29409. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  29410. output.add(globalSubrIndex);
  29411. // Now start on the other entries that have no specfic order.
  29412. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  29413. if (cff.encoding.predefined) {
  29414. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  29415. output);
  29416. } else {
  29417. var encoding = this.compileEncoding(cff.encoding);
  29418. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  29419. output.add(encoding);
  29420. }
  29421. }
  29422. if (cff.charset && cff.topDict.hasName('charset')) {
  29423. if (cff.charset.predefined) {
  29424. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  29425. output);
  29426. } else {
  29427. var charset = this.compileCharset(cff.charset);
  29428. topDictTracker.setEntryLocation('charset', [output.length], output);
  29429. output.add(charset);
  29430. }
  29431. }
  29432. var charStrings = this.compileCharStrings(cff.charStrings);
  29433. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  29434. output.add(charStrings);
  29435. if (cff.isCIDFont) {
  29436. // For some reason FDSelect must be in front of FDArray on windows. OSX
  29437. // and linux don't seem to care.
  29438. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  29439. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  29440. output.add(fdSelect);
  29441. // It is unclear if the sub font dictionary can have CID related
  29442. // dictionary keys, but the sanitizer doesn't like them so remove them.
  29443. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  29444. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  29445. output.add(compiled.output);
  29446. var fontDictTrackers = compiled.trackers;
  29447. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  29448. }
  29449. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  29450. // If the font data ends with INDEX whose object data is zero-length,
  29451. // the sanitizer will bail out. Add a dummy byte to avoid that.
  29452. output.add([0]);
  29453. return output.data;
  29454. },
  29455. encodeNumber: function CFFCompiler_encodeNumber(value) {
  29456. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  29457. return this.encodeInteger(value);
  29458. } else {
  29459. return this.encodeFloat(value);
  29460. }
  29461. },
  29462. encodeFloat: function CFFCompiler_encodeFloat(num) {
  29463. var value = num.toString();
  29464. // rounding inaccurate doubles
  29465. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  29466. if (m) {
  29467. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  29468. value = (Math.round(num * epsilon) / epsilon).toString();
  29469. }
  29470. var nibbles = '';
  29471. var i, ii;
  29472. for (i = 0, ii = value.length; i < ii; ++i) {
  29473. var a = value[i];
  29474. if (a === 'e') {
  29475. nibbles += value[++i] === '-' ? 'c' : 'b';
  29476. } else if (a === '.') {
  29477. nibbles += 'a';
  29478. } else if (a === '-') {
  29479. nibbles += 'e';
  29480. } else {
  29481. nibbles += a;
  29482. }
  29483. }
  29484. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  29485. var out = [30];
  29486. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  29487. out.push(parseInt(nibbles.substr(i, 2), 16));
  29488. }
  29489. return out;
  29490. },
  29491. encodeInteger: function CFFCompiler_encodeInteger(value) {
  29492. var code;
  29493. if (value >= -107 && value <= 107) {
  29494. code = [value + 139];
  29495. } else if (value >= 108 && value <= 1131) {
  29496. value = [value - 108];
  29497. code = [(value >> 8) + 247, value & 0xFF];
  29498. } else if (value >= -1131 && value <= -108) {
  29499. value = -value - 108;
  29500. code = [(value >> 8) + 251, value & 0xFF];
  29501. } else if (value >= -32768 && value <= 32767) {
  29502. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  29503. } else {
  29504. code = [0x1d,
  29505. (value >> 24) & 0xFF,
  29506. (value >> 16) & 0xFF,
  29507. (value >> 8) & 0xFF,
  29508. value & 0xFF];
  29509. }
  29510. return code;
  29511. },
  29512. compileHeader: function CFFCompiler_compileHeader(header) {
  29513. return [
  29514. header.major,
  29515. header.minor,
  29516. header.hdrSize,
  29517. header.offSize
  29518. ];
  29519. },
  29520. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  29521. var nameIndex = new CFFIndex();
  29522. for (var i = 0, ii = names.length; i < ii; ++i) {
  29523. nameIndex.add(stringToBytes(names[i]));
  29524. }
  29525. return this.compileIndex(nameIndex);
  29526. },
  29527. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  29528. length,
  29529. removeCidKeys) {
  29530. var fontDictTrackers = [];
  29531. var fdArrayIndex = new CFFIndex();
  29532. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29533. var fontDict = dicts[i];
  29534. if (removeCidKeys) {
  29535. fontDict.removeByName('CIDFontVersion');
  29536. fontDict.removeByName('CIDFontRevision');
  29537. fontDict.removeByName('CIDFontType');
  29538. fontDict.removeByName('CIDCount');
  29539. fontDict.removeByName('UIDBase');
  29540. }
  29541. var fontDictTracker = new CFFOffsetTracker();
  29542. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  29543. fontDictTrackers.push(fontDictTracker);
  29544. fdArrayIndex.add(fontDictData);
  29545. fontDictTracker.offset(length);
  29546. }
  29547. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  29548. return {
  29549. trackers: fontDictTrackers,
  29550. output: fdArrayIndex
  29551. };
  29552. },
  29553. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  29554. trackers,
  29555. output) {
  29556. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  29557. var fontDict = dicts[i];
  29558. assert(fontDict.privateDict && fontDict.hasName('Private'),
  29559. 'There must be an private dictionary.');
  29560. var privateDict = fontDict.privateDict;
  29561. var privateDictTracker = new CFFOffsetTracker();
  29562. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  29563. var outputLength = output.length;
  29564. privateDictTracker.offset(outputLength);
  29565. if (!privateDictData.length) {
  29566. // The private dictionary was empty, set the output length to zero to
  29567. // ensure the offset length isn't out of bounds in the eyes of the
  29568. // sanitizer.
  29569. outputLength = 0;
  29570. }
  29571. trackers[i].setEntryLocation('Private',
  29572. [privateDictData.length, outputLength],
  29573. output);
  29574. output.add(privateDictData);
  29575. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  29576. var subrs = this.compileIndex(privateDict.subrsIndex);
  29577. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  29578. output);
  29579. output.add(subrs);
  29580. }
  29581. }
  29582. },
  29583. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  29584. var out = [];
  29585. // The dictionary keys must be in a certain order.
  29586. var order = dict.order;
  29587. for (var i = 0; i < order.length; ++i) {
  29588. var key = order[i];
  29589. if (!(key in dict.values)) {
  29590. continue;
  29591. }
  29592. var values = dict.values[key];
  29593. var types = dict.types[key];
  29594. if (!isArray(types)) {
  29595. types = [types];
  29596. }
  29597. if (!isArray(values)) {
  29598. values = [values];
  29599. }
  29600. // Remove any empty dict values.
  29601. if (values.length === 0) {
  29602. continue;
  29603. }
  29604. for (var j = 0, jj = types.length; j < jj; ++j) {
  29605. var type = types[j];
  29606. var value = values[j];
  29607. switch (type) {
  29608. case 'num':
  29609. case 'sid':
  29610. out = out.concat(this.encodeNumber(value));
  29611. break;
  29612. case 'offset':
  29613. // For offsets we just insert a 32bit integer so we don't have to
  29614. // deal with figuring out the length of the offset when it gets
  29615. // replaced later on by the compiler.
  29616. var name = dict.keyToNameMap[key];
  29617. // Some offsets have the offset and the length, so just record the
  29618. // position of the first one.
  29619. if (!offsetTracker.isTracking(name)) {
  29620. offsetTracker.track(name, out.length);
  29621. }
  29622. out = out.concat([0x1d, 0, 0, 0, 0]);
  29623. break;
  29624. case 'array':
  29625. case 'delta':
  29626. out = out.concat(this.encodeNumber(value));
  29627. for (var k = 1, kk = values.length; k < kk; ++k) {
  29628. out = out.concat(this.encodeNumber(values[k]));
  29629. }
  29630. break;
  29631. default:
  29632. error('Unknown data type of ' + type);
  29633. break;
  29634. }
  29635. }
  29636. out = out.concat(dict.opcodes[key]);
  29637. }
  29638. return out;
  29639. },
  29640. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  29641. var stringIndex = new CFFIndex();
  29642. for (var i = 0, ii = strings.length; i < ii; ++i) {
  29643. stringIndex.add(stringToBytes(strings[i]));
  29644. }
  29645. return this.compileIndex(stringIndex);
  29646. },
  29647. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  29648. var globalSubrIndex = this.cff.globalSubrIndex;
  29649. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  29650. },
  29651. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  29652. return this.compileIndex(charStrings);
  29653. },
  29654. compileCharset: function CFFCompiler_compileCharset(charset) {
  29655. return this.compileTypedArray(charset.raw);
  29656. },
  29657. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  29658. return this.compileTypedArray(encoding.raw);
  29659. },
  29660. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  29661. return this.compileTypedArray(fdSelect);
  29662. },
  29663. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  29664. var out = [];
  29665. for (var i = 0, ii = data.length; i < ii; ++i) {
  29666. out[i] = data[i];
  29667. }
  29668. return out;
  29669. },
  29670. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  29671. trackers = trackers || [];
  29672. var objects = index.objects;
  29673. // First 2 bytes contains the number of objects contained into this index
  29674. var count = objects.length;
  29675. // If there is no object, just create an index. This technically
  29676. // should just be [0, 0] but OTS has an issue with that.
  29677. if (count === 0) {
  29678. return [0, 0, 0];
  29679. }
  29680. var data = [(count >> 8) & 0xFF, count & 0xff];
  29681. var lastOffset = 1, i;
  29682. for (i = 0; i < count; ++i) {
  29683. lastOffset += objects[i].length;
  29684. }
  29685. var offsetSize;
  29686. if (lastOffset < 0x100) {
  29687. offsetSize = 1;
  29688. } else if (lastOffset < 0x10000) {
  29689. offsetSize = 2;
  29690. } else if (lastOffset < 0x1000000) {
  29691. offsetSize = 3;
  29692. } else {
  29693. offsetSize = 4;
  29694. }
  29695. // Next byte contains the offset size use to reference object in the file
  29696. data.push(offsetSize);
  29697. // Add another offset after this one because we need a new offset
  29698. var relativeOffset = 1;
  29699. for (i = 0; i < count + 1; i++) {
  29700. if (offsetSize === 1) {
  29701. data.push(relativeOffset & 0xFF);
  29702. } else if (offsetSize === 2) {
  29703. data.push((relativeOffset >> 8) & 0xFF,
  29704. relativeOffset & 0xFF);
  29705. } else if (offsetSize === 3) {
  29706. data.push((relativeOffset >> 16) & 0xFF,
  29707. (relativeOffset >> 8) & 0xFF,
  29708. relativeOffset & 0xFF);
  29709. } else {
  29710. data.push((relativeOffset >>> 24) & 0xFF,
  29711. (relativeOffset >> 16) & 0xFF,
  29712. (relativeOffset >> 8) & 0xFF,
  29713. relativeOffset & 0xFF);
  29714. }
  29715. if (objects[i]) {
  29716. relativeOffset += objects[i].length;
  29717. }
  29718. }
  29719. for (i = 0; i < count; i++) {
  29720. // Notify the tracker where the object will be offset in the data.
  29721. if (trackers[i]) {
  29722. trackers[i].offset(data.length);
  29723. }
  29724. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  29725. data.push(objects[i][j]);
  29726. }
  29727. }
  29728. return data;
  29729. }
  29730. };
  29731. return CFFCompiler;
  29732. })();
  29733. function _enableSeacAnalysis(enabled) {
  29734. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  29735. }
  29736. // Workaround for seac on Windows.
  29737. (function checkSeacSupport() {
  29738. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  29739. SEAC_ANALYSIS_ENABLED = true;
  29740. }
  29741. })();
  29742. // Workaround for Private Use Area characters in Chrome on Windows
  29743. // http://code.google.com/p/chromium/issues/detail?id=122465
  29744. // https://github.com/mozilla/pdf.js/issues/1689
  29745. (function checkChromeWindows() {
  29746. if (typeof navigator !== 'undefined' &&
  29747. /Windows.*Chrome/.test(navigator.userAgent)) {
  29748. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  29749. }
  29750. })();
  29751. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  29752. exports.CFFCompiler = CFFCompiler;
  29753. exports.CFFIndex = CFFIndex;
  29754. exports.CFFParser = CFFParser;
  29755. exports.CFFStrings = CFFStrings;
  29756. exports.ErrorFont = ErrorFont;
  29757. exports.FontFlags = FontFlags;
  29758. exports.Font = Font;
  29759. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  29760. exports.ToUnicodeMap = ToUnicodeMap;
  29761. exports.Type1Parser = Type1Parser;
  29762. exports.getFontType = getFontType;
  29763. exports._enableSeacAnalysis = _enableSeacAnalysis;
  29764. // TODO refactor to remove cyclic dependency on font_renderer.js
  29765. coreFontRenderer._setCoreFonts(exports);
  29766. }));
  29767. (function (root, factory) {
  29768. {
  29769. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  29770. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  29771. }
  29772. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  29773. var error = sharedUtil.error;
  29774. var info = sharedUtil.info;
  29775. var isArray = sharedUtil.isArray;
  29776. var isBool = sharedUtil.isBool;
  29777. var isDict = corePrimitives.isDict;
  29778. var isStream = corePrimitives.isStream;
  29779. var PostScriptLexer = corePsParser.PostScriptLexer;
  29780. var PostScriptParser = corePsParser.PostScriptParser;
  29781. var PDFFunction = (function PDFFunctionClosure() {
  29782. var CONSTRUCT_SAMPLED = 0;
  29783. var CONSTRUCT_INTERPOLATED = 2;
  29784. var CONSTRUCT_STICHED = 3;
  29785. var CONSTRUCT_POSTSCRIPT = 4;
  29786. return {
  29787. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  29788. str) {
  29789. var i, ii;
  29790. var length = 1;
  29791. for (i = 0, ii = size.length; i < ii; i++) {
  29792. length *= size[i];
  29793. }
  29794. length *= outputSize;
  29795. var array = new Array(length);
  29796. var codeSize = 0;
  29797. var codeBuf = 0;
  29798. // 32 is a valid bps so shifting won't work
  29799. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  29800. var strBytes = str.getBytes((length * bps + 7) / 8);
  29801. var strIdx = 0;
  29802. for (i = 0; i < length; i++) {
  29803. while (codeSize < bps) {
  29804. codeBuf <<= 8;
  29805. codeBuf |= strBytes[strIdx++];
  29806. codeSize += 8;
  29807. }
  29808. codeSize -= bps;
  29809. array[i] = (codeBuf >> codeSize) * sampleMul;
  29810. codeBuf &= (1 << codeSize) - 1;
  29811. }
  29812. return array;
  29813. },
  29814. getIR: function PDFFunction_getIR(xref, fn) {
  29815. var dict = fn.dict;
  29816. if (!dict) {
  29817. dict = fn;
  29818. }
  29819. var types = [this.constructSampled,
  29820. null,
  29821. this.constructInterpolated,
  29822. this.constructStiched,
  29823. this.constructPostScript];
  29824. var typeNum = dict.get('FunctionType');
  29825. var typeFn = types[typeNum];
  29826. if (!typeFn) {
  29827. error('Unknown type of function');
  29828. }
  29829. return typeFn.call(this, fn, dict, xref);
  29830. },
  29831. fromIR: function PDFFunction_fromIR(IR) {
  29832. var type = IR[0];
  29833. switch (type) {
  29834. case CONSTRUCT_SAMPLED:
  29835. return this.constructSampledFromIR(IR);
  29836. case CONSTRUCT_INTERPOLATED:
  29837. return this.constructInterpolatedFromIR(IR);
  29838. case CONSTRUCT_STICHED:
  29839. return this.constructStichedFromIR(IR);
  29840. //case CONSTRUCT_POSTSCRIPT:
  29841. default:
  29842. return this.constructPostScriptFromIR(IR);
  29843. }
  29844. },
  29845. parse: function PDFFunction_parse(xref, fn) {
  29846. var IR = this.getIR(xref, fn);
  29847. return this.fromIR(IR);
  29848. },
  29849. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  29850. if (!isArray(fnObj)) {
  29851. // not an array -- parsing as regular function
  29852. return this.parse(xref, fnObj);
  29853. }
  29854. var fnArray = [];
  29855. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  29856. var obj = xref.fetchIfRef(fnObj[j]);
  29857. fnArray.push(PDFFunction.parse(xref, obj));
  29858. }
  29859. return function (src, srcOffset, dest, destOffset) {
  29860. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  29861. fnArray[i](src, srcOffset, dest, destOffset + i);
  29862. }
  29863. };
  29864. },
  29865. constructSampled: function PDFFunction_constructSampled(str, dict) {
  29866. function toMultiArray(arr) {
  29867. var inputLength = arr.length;
  29868. var out = [];
  29869. var index = 0;
  29870. for (var i = 0; i < inputLength; i += 2) {
  29871. out[index] = [arr[i], arr[i + 1]];
  29872. ++index;
  29873. }
  29874. return out;
  29875. }
  29876. var domain = dict.get('Domain');
  29877. var range = dict.get('Range');
  29878. if (!domain || !range) {
  29879. error('No domain or range');
  29880. }
  29881. var inputSize = domain.length / 2;
  29882. var outputSize = range.length / 2;
  29883. domain = toMultiArray(domain);
  29884. range = toMultiArray(range);
  29885. var size = dict.get('Size');
  29886. var bps = dict.get('BitsPerSample');
  29887. var order = dict.get('Order') || 1;
  29888. if (order !== 1) {
  29889. // No description how cubic spline interpolation works in PDF32000:2008
  29890. // As in poppler, ignoring order, linear interpolation may work as good
  29891. info('No support for cubic spline interpolation: ' + order);
  29892. }
  29893. var encode = dict.get('Encode');
  29894. if (!encode) {
  29895. encode = [];
  29896. for (var i = 0; i < inputSize; ++i) {
  29897. encode.push(0);
  29898. encode.push(size[i] - 1);
  29899. }
  29900. }
  29901. encode = toMultiArray(encode);
  29902. var decode = dict.get('Decode');
  29903. if (!decode) {
  29904. decode = range;
  29905. } else {
  29906. decode = toMultiArray(decode);
  29907. }
  29908. var samples = this.getSampleArray(size, outputSize, bps, str);
  29909. return [
  29910. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  29911. outputSize, Math.pow(2, bps) - 1, range
  29912. ];
  29913. },
  29914. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  29915. // See chapter 3, page 109 of the PDF reference
  29916. function interpolate(x, xmin, xmax, ymin, ymax) {
  29917. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  29918. }
  29919. return function constructSampledFromIRResult(src, srcOffset,
  29920. dest, destOffset) {
  29921. // See chapter 3, page 110 of the PDF reference.
  29922. var m = IR[1];
  29923. var domain = IR[2];
  29924. var encode = IR[3];
  29925. var decode = IR[4];
  29926. var samples = IR[5];
  29927. var size = IR[6];
  29928. var n = IR[7];
  29929. //var mask = IR[8];
  29930. var range = IR[9];
  29931. // Building the cube vertices: its part and sample index
  29932. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  29933. var cubeVertices = 1 << m;
  29934. var cubeN = new Float64Array(cubeVertices);
  29935. var cubeVertex = new Uint32Array(cubeVertices);
  29936. var i, j;
  29937. for (j = 0; j < cubeVertices; j++) {
  29938. cubeN[j] = 1;
  29939. }
  29940. var k = n, pos = 1;
  29941. // Map x_i to y_j for 0 <= i < m using the sampled function.
  29942. for (i = 0; i < m; ++i) {
  29943. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  29944. var domain_2i = domain[i][0];
  29945. var domain_2i_1 = domain[i][1];
  29946. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  29947. domain_2i_1);
  29948. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  29949. // Encode_2i, Encode_2i+1)
  29950. var e = interpolate(xi, domain_2i, domain_2i_1,
  29951. encode[i][0], encode[i][1]);
  29952. // e_i' = min(max(e_i, 0), Size_i - 1)
  29953. var size_i = size[i];
  29954. e = Math.min(Math.max(e, 0), size_i - 1);
  29955. // Adjusting the cube: N and vertex sample index
  29956. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  29957. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  29958. var n1 = e - e0; // (e - e0) / (e1 - e0);
  29959. var offset0 = e0 * k;
  29960. var offset1 = offset0 + k; // e1 * k
  29961. for (j = 0; j < cubeVertices; j++) {
  29962. if (j & pos) {
  29963. cubeN[j] *= n1;
  29964. cubeVertex[j] += offset1;
  29965. } else {
  29966. cubeN[j] *= n0;
  29967. cubeVertex[j] += offset0;
  29968. }
  29969. }
  29970. k *= size_i;
  29971. pos <<= 1;
  29972. }
  29973. for (j = 0; j < n; ++j) {
  29974. // Sum all cube vertices' samples portions
  29975. var rj = 0;
  29976. for (i = 0; i < cubeVertices; i++) {
  29977. rj += samples[cubeVertex[i] + j] * cubeN[i];
  29978. }
  29979. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  29980. // Decode_2j, Decode_2j+1)
  29981. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  29982. // y_j = min(max(r_j, range_2j), range_2j+1)
  29983. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  29984. range[j][1]);
  29985. }
  29986. };
  29987. },
  29988. constructInterpolated: function PDFFunction_constructInterpolated(str,
  29989. dict) {
  29990. var c0 = dict.get('C0') || [0];
  29991. var c1 = dict.get('C1') || [1];
  29992. var n = dict.get('N');
  29993. if (!isArray(c0) || !isArray(c1)) {
  29994. error('Illegal dictionary for interpolated function');
  29995. }
  29996. var length = c0.length;
  29997. var diff = [];
  29998. for (var i = 0; i < length; ++i) {
  29999. diff.push(c1[i] - c0[i]);
  30000. }
  30001. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  30002. },
  30003. constructInterpolatedFromIR:
  30004. function PDFFunction_constructInterpolatedFromIR(IR) {
  30005. var c0 = IR[1];
  30006. var diff = IR[2];
  30007. var n = IR[3];
  30008. var length = diff.length;
  30009. return function constructInterpolatedFromIRResult(src, srcOffset,
  30010. dest, destOffset) {
  30011. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  30012. for (var j = 0; j < length; ++j) {
  30013. dest[destOffset + j] = c0[j] + (x * diff[j]);
  30014. }
  30015. };
  30016. },
  30017. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  30018. var domain = dict.get('Domain');
  30019. if (!domain) {
  30020. error('No domain');
  30021. }
  30022. var inputSize = domain.length / 2;
  30023. if (inputSize !== 1) {
  30024. error('Bad domain for stiched function');
  30025. }
  30026. var fnRefs = dict.get('Functions');
  30027. var fns = [];
  30028. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  30029. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  30030. }
  30031. var bounds = dict.get('Bounds');
  30032. var encode = dict.get('Encode');
  30033. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  30034. },
  30035. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  30036. var domain = IR[1];
  30037. var bounds = IR[2];
  30038. var encode = IR[3];
  30039. var fnsIR = IR[4];
  30040. var fns = [];
  30041. var tmpBuf = new Float32Array(1);
  30042. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  30043. fns.push(PDFFunction.fromIR(fnsIR[i]));
  30044. }
  30045. return function constructStichedFromIRResult(src, srcOffset,
  30046. dest, destOffset) {
  30047. var clip = function constructStichedFromIRClip(v, min, max) {
  30048. if (v > max) {
  30049. v = max;
  30050. } else if (v < min) {
  30051. v = min;
  30052. }
  30053. return v;
  30054. };
  30055. // clip to domain
  30056. var v = clip(src[srcOffset], domain[0], domain[1]);
  30057. // calulate which bound the value is in
  30058. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  30059. if (v < bounds[i]) {
  30060. break;
  30061. }
  30062. }
  30063. // encode value into domain of function
  30064. var dmin = domain[0];
  30065. if (i > 0) {
  30066. dmin = bounds[i - 1];
  30067. }
  30068. var dmax = domain[1];
  30069. if (i < bounds.length) {
  30070. dmax = bounds[i];
  30071. }
  30072. var rmin = encode[2 * i];
  30073. var rmax = encode[2 * i + 1];
  30074. // Prevent the value from becoming NaN as a result
  30075. // of division by zero (fixes issue6113.pdf).
  30076. tmpBuf[0] = dmin === dmax ? rmin :
  30077. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  30078. // call the appropriate function
  30079. fns[i](tmpBuf, 0, dest, destOffset);
  30080. };
  30081. },
  30082. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  30083. xref) {
  30084. var domain = dict.get('Domain');
  30085. var range = dict.get('Range');
  30086. if (!domain) {
  30087. error('No domain.');
  30088. }
  30089. if (!range) {
  30090. error('No range.');
  30091. }
  30092. var lexer = new PostScriptLexer(fn);
  30093. var parser = new PostScriptParser(lexer);
  30094. var code = parser.parse();
  30095. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  30096. },
  30097. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  30098. IR) {
  30099. var domain = IR[1];
  30100. var range = IR[2];
  30101. var code = IR[3];
  30102. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  30103. if (compiled) {
  30104. // Compiled function consists of simple expressions such as addition,
  30105. // subtraction, Math.max, and also contains 'var' and 'return'
  30106. // statements. See the generation in the PostScriptCompiler below.
  30107. /*jshint -W054 */
  30108. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  30109. }
  30110. info('Unable to compile PS function');
  30111. var numOutputs = range.length >> 1;
  30112. var numInputs = domain.length >> 1;
  30113. var evaluator = new PostScriptEvaluator(code);
  30114. // Cache the values for a big speed up, the cache size is limited though
  30115. // since the number of possible values can be huge from a PS function.
  30116. var cache = Object.create(null);
  30117. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  30118. // seen in our tests.
  30119. var MAX_CACHE_SIZE = 2048 * 4;
  30120. var cache_available = MAX_CACHE_SIZE;
  30121. var tmpBuf = new Float32Array(numInputs);
  30122. return function constructPostScriptFromIRResult(src, srcOffset,
  30123. dest, destOffset) {
  30124. var i, value;
  30125. var key = '';
  30126. var input = tmpBuf;
  30127. for (i = 0; i < numInputs; i++) {
  30128. value = src[srcOffset + i];
  30129. input[i] = value;
  30130. key += value + '_';
  30131. }
  30132. var cachedValue = cache[key];
  30133. if (cachedValue !== undefined) {
  30134. dest.set(cachedValue, destOffset);
  30135. return;
  30136. }
  30137. var output = new Float32Array(numOutputs);
  30138. var stack = evaluator.execute(input);
  30139. var stackIndex = stack.length - numOutputs;
  30140. for (i = 0; i < numOutputs; i++) {
  30141. value = stack[stackIndex + i];
  30142. var bound = range[i * 2];
  30143. if (value < bound) {
  30144. value = bound;
  30145. } else {
  30146. bound = range[i * 2 +1];
  30147. if (value > bound) {
  30148. value = bound;
  30149. }
  30150. }
  30151. output[i] = value;
  30152. }
  30153. if (cache_available > 0) {
  30154. cache_available--;
  30155. cache[key] = output;
  30156. }
  30157. dest.set(output, destOffset);
  30158. };
  30159. }
  30160. };
  30161. })();
  30162. function isPDFFunction(v) {
  30163. var fnDict;
  30164. if (typeof v !== 'object') {
  30165. return false;
  30166. } else if (isDict(v)) {
  30167. fnDict = v;
  30168. } else if (isStream(v)) {
  30169. fnDict = v.dict;
  30170. } else {
  30171. return false;
  30172. }
  30173. return fnDict.has('FunctionType');
  30174. }
  30175. var PostScriptStack = (function PostScriptStackClosure() {
  30176. var MAX_STACK_SIZE = 100;
  30177. function PostScriptStack(initialStack) {
  30178. this.stack = !initialStack ? [] :
  30179. Array.prototype.slice.call(initialStack, 0);
  30180. }
  30181. PostScriptStack.prototype = {
  30182. push: function PostScriptStack_push(value) {
  30183. if (this.stack.length >= MAX_STACK_SIZE) {
  30184. error('PostScript function stack overflow.');
  30185. }
  30186. this.stack.push(value);
  30187. },
  30188. pop: function PostScriptStack_pop() {
  30189. if (this.stack.length <= 0) {
  30190. error('PostScript function stack underflow.');
  30191. }
  30192. return this.stack.pop();
  30193. },
  30194. copy: function PostScriptStack_copy(n) {
  30195. if (this.stack.length + n >= MAX_STACK_SIZE) {
  30196. error('PostScript function stack overflow.');
  30197. }
  30198. var stack = this.stack;
  30199. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  30200. stack.push(stack[i]);
  30201. }
  30202. },
  30203. index: function PostScriptStack_index(n) {
  30204. this.push(this.stack[this.stack.length - n - 1]);
  30205. },
  30206. // rotate the last n stack elements p times
  30207. roll: function PostScriptStack_roll(n, p) {
  30208. var stack = this.stack;
  30209. var l = stack.length - n;
  30210. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  30211. for (i = l, j = r; i < j; i++, j--) {
  30212. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30213. }
  30214. for (i = l, j = c - 1; i < j; i++, j--) {
  30215. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30216. }
  30217. for (i = c, j = r; i < j; i++, j--) {
  30218. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  30219. }
  30220. }
  30221. };
  30222. return PostScriptStack;
  30223. })();
  30224. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  30225. function PostScriptEvaluator(operators) {
  30226. this.operators = operators;
  30227. }
  30228. PostScriptEvaluator.prototype = {
  30229. execute: function PostScriptEvaluator_execute(initialStack) {
  30230. var stack = new PostScriptStack(initialStack);
  30231. var counter = 0;
  30232. var operators = this.operators;
  30233. var length = operators.length;
  30234. var operator, a, b;
  30235. while (counter < length) {
  30236. operator = operators[counter++];
  30237. if (typeof operator === 'number') {
  30238. // Operator is really an operand and should be pushed to the stack.
  30239. stack.push(operator);
  30240. continue;
  30241. }
  30242. switch (operator) {
  30243. // non standard ps operators
  30244. case 'jz': // jump if false
  30245. b = stack.pop();
  30246. a = stack.pop();
  30247. if (!a) {
  30248. counter = b;
  30249. }
  30250. break;
  30251. case 'j': // jump
  30252. a = stack.pop();
  30253. counter = a;
  30254. break;
  30255. // all ps operators in alphabetical order (excluding if/ifelse)
  30256. case 'abs':
  30257. a = stack.pop();
  30258. stack.push(Math.abs(a));
  30259. break;
  30260. case 'add':
  30261. b = stack.pop();
  30262. a = stack.pop();
  30263. stack.push(a + b);
  30264. break;
  30265. case 'and':
  30266. b = stack.pop();
  30267. a = stack.pop();
  30268. if (isBool(a) && isBool(b)) {
  30269. stack.push(a && b);
  30270. } else {
  30271. stack.push(a & b);
  30272. }
  30273. break;
  30274. case 'atan':
  30275. a = stack.pop();
  30276. stack.push(Math.atan(a));
  30277. break;
  30278. case 'bitshift':
  30279. b = stack.pop();
  30280. a = stack.pop();
  30281. if (a > 0) {
  30282. stack.push(a << b);
  30283. } else {
  30284. stack.push(a >> b);
  30285. }
  30286. break;
  30287. case 'ceiling':
  30288. a = stack.pop();
  30289. stack.push(Math.ceil(a));
  30290. break;
  30291. case 'copy':
  30292. a = stack.pop();
  30293. stack.copy(a);
  30294. break;
  30295. case 'cos':
  30296. a = stack.pop();
  30297. stack.push(Math.cos(a));
  30298. break;
  30299. case 'cvi':
  30300. a = stack.pop() | 0;
  30301. stack.push(a);
  30302. break;
  30303. case 'cvr':
  30304. // noop
  30305. break;
  30306. case 'div':
  30307. b = stack.pop();
  30308. a = stack.pop();
  30309. stack.push(a / b);
  30310. break;
  30311. case 'dup':
  30312. stack.copy(1);
  30313. break;
  30314. case 'eq':
  30315. b = stack.pop();
  30316. a = stack.pop();
  30317. stack.push(a === b);
  30318. break;
  30319. case 'exch':
  30320. stack.roll(2, 1);
  30321. break;
  30322. case 'exp':
  30323. b = stack.pop();
  30324. a = stack.pop();
  30325. stack.push(Math.pow(a, b));
  30326. break;
  30327. case 'false':
  30328. stack.push(false);
  30329. break;
  30330. case 'floor':
  30331. a = stack.pop();
  30332. stack.push(Math.floor(a));
  30333. break;
  30334. case 'ge':
  30335. b = stack.pop();
  30336. a = stack.pop();
  30337. stack.push(a >= b);
  30338. break;
  30339. case 'gt':
  30340. b = stack.pop();
  30341. a = stack.pop();
  30342. stack.push(a > b);
  30343. break;
  30344. case 'idiv':
  30345. b = stack.pop();
  30346. a = stack.pop();
  30347. stack.push((a / b) | 0);
  30348. break;
  30349. case 'index':
  30350. a = stack.pop();
  30351. stack.index(a);
  30352. break;
  30353. case 'le':
  30354. b = stack.pop();
  30355. a = stack.pop();
  30356. stack.push(a <= b);
  30357. break;
  30358. case 'ln':
  30359. a = stack.pop();
  30360. stack.push(Math.log(a));
  30361. break;
  30362. case 'log':
  30363. a = stack.pop();
  30364. stack.push(Math.log(a) / Math.LN10);
  30365. break;
  30366. case 'lt':
  30367. b = stack.pop();
  30368. a = stack.pop();
  30369. stack.push(a < b);
  30370. break;
  30371. case 'mod':
  30372. b = stack.pop();
  30373. a = stack.pop();
  30374. stack.push(a % b);
  30375. break;
  30376. case 'mul':
  30377. b = stack.pop();
  30378. a = stack.pop();
  30379. stack.push(a * b);
  30380. break;
  30381. case 'ne':
  30382. b = stack.pop();
  30383. a = stack.pop();
  30384. stack.push(a !== b);
  30385. break;
  30386. case 'neg':
  30387. a = stack.pop();
  30388. stack.push(-a);
  30389. break;
  30390. case 'not':
  30391. a = stack.pop();
  30392. if (isBool(a)) {
  30393. stack.push(!a);
  30394. } else {
  30395. stack.push(~a);
  30396. }
  30397. break;
  30398. case 'or':
  30399. b = stack.pop();
  30400. a = stack.pop();
  30401. if (isBool(a) && isBool(b)) {
  30402. stack.push(a || b);
  30403. } else {
  30404. stack.push(a | b);
  30405. }
  30406. break;
  30407. case 'pop':
  30408. stack.pop();
  30409. break;
  30410. case 'roll':
  30411. b = stack.pop();
  30412. a = stack.pop();
  30413. stack.roll(a, b);
  30414. break;
  30415. case 'round':
  30416. a = stack.pop();
  30417. stack.push(Math.round(a));
  30418. break;
  30419. case 'sin':
  30420. a = stack.pop();
  30421. stack.push(Math.sin(a));
  30422. break;
  30423. case 'sqrt':
  30424. a = stack.pop();
  30425. stack.push(Math.sqrt(a));
  30426. break;
  30427. case 'sub':
  30428. b = stack.pop();
  30429. a = stack.pop();
  30430. stack.push(a - b);
  30431. break;
  30432. case 'true':
  30433. stack.push(true);
  30434. break;
  30435. case 'truncate':
  30436. a = stack.pop();
  30437. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  30438. stack.push(a);
  30439. break;
  30440. case 'xor':
  30441. b = stack.pop();
  30442. a = stack.pop();
  30443. if (isBool(a) && isBool(b)) {
  30444. stack.push(a !== b);
  30445. } else {
  30446. stack.push(a ^ b);
  30447. }
  30448. break;
  30449. default:
  30450. error('Unknown operator ' + operator);
  30451. break;
  30452. }
  30453. }
  30454. return stack.stack;
  30455. }
  30456. };
  30457. return PostScriptEvaluator;
  30458. })();
  30459. // Most of the PDFs functions consist of simple operations such as:
  30460. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  30461. //
  30462. // We can compile most of such programs, and at the same moment, we can
  30463. // optimize some expressions using basic math properties. Keeping track of
  30464. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  30465. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  30466. function AstNode(type) {
  30467. this.type = type;
  30468. }
  30469. AstNode.prototype.visit = function (visitor) {
  30470. throw new Error('abstract method');
  30471. };
  30472. function AstArgument(index, min, max) {
  30473. AstNode.call(this, 'args');
  30474. this.index = index;
  30475. this.min = min;
  30476. this.max = max;
  30477. }
  30478. AstArgument.prototype = Object.create(AstNode.prototype);
  30479. AstArgument.prototype.visit = function (visitor) {
  30480. visitor.visitArgument(this);
  30481. };
  30482. function AstLiteral(number) {
  30483. AstNode.call(this, 'literal');
  30484. this.number = number;
  30485. this.min = number;
  30486. this.max = number;
  30487. }
  30488. AstLiteral.prototype = Object.create(AstNode.prototype);
  30489. AstLiteral.prototype.visit = function (visitor) {
  30490. visitor.visitLiteral(this);
  30491. };
  30492. function AstBinaryOperation(op, arg1, arg2, min, max) {
  30493. AstNode.call(this, 'binary');
  30494. this.op = op;
  30495. this.arg1 = arg1;
  30496. this.arg2 = arg2;
  30497. this.min = min;
  30498. this.max = max;
  30499. }
  30500. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  30501. AstBinaryOperation.prototype.visit = function (visitor) {
  30502. visitor.visitBinaryOperation(this);
  30503. };
  30504. function AstMin(arg, max) {
  30505. AstNode.call(this, 'max');
  30506. this.arg = arg;
  30507. this.min = arg.min;
  30508. this.max = max;
  30509. }
  30510. AstMin.prototype = Object.create(AstNode.prototype);
  30511. AstMin.prototype.visit = function (visitor) {
  30512. visitor.visitMin(this);
  30513. };
  30514. function AstVariable(index, min, max) {
  30515. AstNode.call(this, 'var');
  30516. this.index = index;
  30517. this.min = min;
  30518. this.max = max;
  30519. }
  30520. AstVariable.prototype = Object.create(AstNode.prototype);
  30521. AstVariable.prototype.visit = function (visitor) {
  30522. visitor.visitVariable(this);
  30523. };
  30524. function AstVariableDefinition(variable, arg) {
  30525. AstNode.call(this, 'definition');
  30526. this.variable = variable;
  30527. this.arg = arg;
  30528. }
  30529. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  30530. AstVariableDefinition.prototype.visit = function (visitor) {
  30531. visitor.visitVariableDefinition(this);
  30532. };
  30533. function ExpressionBuilderVisitor() {
  30534. this.parts = [];
  30535. }
  30536. ExpressionBuilderVisitor.prototype = {
  30537. visitArgument: function (arg) {
  30538. this.parts.push('Math.max(', arg.min, ', Math.min(',
  30539. arg.max, ', src[srcOffset + ', arg.index, ']))');
  30540. },
  30541. visitVariable: function (variable) {
  30542. this.parts.push('v', variable.index);
  30543. },
  30544. visitLiteral: function (literal) {
  30545. this.parts.push(literal.number);
  30546. },
  30547. visitBinaryOperation: function (operation) {
  30548. this.parts.push('(');
  30549. operation.arg1.visit(this);
  30550. this.parts.push(' ', operation.op, ' ');
  30551. operation.arg2.visit(this);
  30552. this.parts.push(')');
  30553. },
  30554. visitVariableDefinition: function (definition) {
  30555. this.parts.push('var ');
  30556. definition.variable.visit(this);
  30557. this.parts.push(' = ');
  30558. definition.arg.visit(this);
  30559. this.parts.push(';');
  30560. },
  30561. visitMin: function (max) {
  30562. this.parts.push('Math.min(');
  30563. max.arg.visit(this);
  30564. this.parts.push(', ', max.max, ')');
  30565. },
  30566. toString: function () {
  30567. return this.parts.join('');
  30568. }
  30569. };
  30570. function buildAddOperation(num1, num2) {
  30571. if (num2.type === 'literal' && num2.number === 0) {
  30572. // optimization: second operand is 0
  30573. return num1;
  30574. }
  30575. if (num1.type === 'literal' && num1.number === 0) {
  30576. // optimization: first operand is 0
  30577. return num2;
  30578. }
  30579. if (num2.type === 'literal' && num1.type === 'literal') {
  30580. // optimization: operands operand are literals
  30581. return new AstLiteral(num1.number + num2.number);
  30582. }
  30583. return new AstBinaryOperation('+', num1, num2,
  30584. num1.min + num2.min, num1.max + num2.max);
  30585. }
  30586. function buildMulOperation(num1, num2) {
  30587. if (num2.type === 'literal') {
  30588. // optimization: second operands is a literal...
  30589. if (num2.number === 0) {
  30590. return new AstLiteral(0); // and it's 0
  30591. } else if (num2.number === 1) {
  30592. return num1; // and it's 1
  30593. } else if (num1.type === 'literal') {
  30594. // ... and first operands is a literal too
  30595. return new AstLiteral(num1.number * num2.number);
  30596. }
  30597. }
  30598. if (num1.type === 'literal') {
  30599. // optimization: first operands is a literal...
  30600. if (num1.number === 0) {
  30601. return new AstLiteral(0); // and it's 0
  30602. } else if (num1.number === 1) {
  30603. return num2; // and it's 1
  30604. }
  30605. }
  30606. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  30607. num1.max * num2.min, num1.max * num2.max);
  30608. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  30609. num1.max * num2.min, num1.max * num2.max);
  30610. return new AstBinaryOperation('*', num1, num2, min, max);
  30611. }
  30612. function buildSubOperation(num1, num2) {
  30613. if (num2.type === 'literal') {
  30614. // optimization: second operands is a literal...
  30615. if (num2.number === 0) {
  30616. return num1; // ... and it's 0
  30617. } else if (num1.type === 'literal') {
  30618. // ... and first operands is a literal too
  30619. return new AstLiteral(num1.number - num2.number);
  30620. }
  30621. }
  30622. if (num2.type === 'binary' && num2.op === '-' &&
  30623. num1.type === 'literal' && num1.number === 1 &&
  30624. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  30625. // optimization for case: 1 - (1 - x)
  30626. return num2.arg2;
  30627. }
  30628. return new AstBinaryOperation('-', num1, num2,
  30629. num1.min - num2.max, num1.max - num2.min);
  30630. }
  30631. function buildMinOperation(num1, max) {
  30632. if (num1.min >= max) {
  30633. // optimization: num1 min value is not less than required max
  30634. return new AstLiteral(max); // just returning max
  30635. } else if (num1.max <= max) {
  30636. // optimization: num1 max value is not greater than required max
  30637. return num1; // just returning an argument
  30638. }
  30639. return new AstMin(num1, max);
  30640. }
  30641. function PostScriptCompiler() {}
  30642. PostScriptCompiler.prototype = {
  30643. compile: function PostScriptCompiler_compile(code, domain, range) {
  30644. var stack = [];
  30645. var i, ii;
  30646. var instructions = [];
  30647. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  30648. var lastRegister = 0;
  30649. var n, j;
  30650. var num1, num2, ast1, ast2, tmpVar, item;
  30651. for (i = 0; i < inputSize; i++) {
  30652. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  30653. }
  30654. for (i = 0, ii = code.length; i < ii; i++) {
  30655. item = code[i];
  30656. if (typeof item === 'number') {
  30657. stack.push(new AstLiteral(item));
  30658. continue;
  30659. }
  30660. switch (item) {
  30661. case 'add':
  30662. if (stack.length < 2) {
  30663. return null;
  30664. }
  30665. num2 = stack.pop();
  30666. num1 = stack.pop();
  30667. stack.push(buildAddOperation(num1, num2));
  30668. break;
  30669. case 'cvr':
  30670. if (stack.length < 1) {
  30671. return null;
  30672. }
  30673. break;
  30674. case 'mul':
  30675. if (stack.length < 2) {
  30676. return null;
  30677. }
  30678. num2 = stack.pop();
  30679. num1 = stack.pop();
  30680. stack.push(buildMulOperation(num1, num2));
  30681. break;
  30682. case 'sub':
  30683. if (stack.length < 2) {
  30684. return null;
  30685. }
  30686. num2 = stack.pop();
  30687. num1 = stack.pop();
  30688. stack.push(buildSubOperation(num1, num2));
  30689. break;
  30690. case 'exch':
  30691. if (stack.length < 2) {
  30692. return null;
  30693. }
  30694. ast1 = stack.pop(); ast2 = stack.pop();
  30695. stack.push(ast1, ast2);
  30696. break;
  30697. case 'pop':
  30698. if (stack.length < 1) {
  30699. return null;
  30700. }
  30701. stack.pop();
  30702. break;
  30703. case 'index':
  30704. if (stack.length < 1) {
  30705. return null;
  30706. }
  30707. num1 = stack.pop();
  30708. if (num1.type !== 'literal') {
  30709. return null;
  30710. }
  30711. n = num1.number;
  30712. if (n < 0 || (n|0) !== n || stack.length < n) {
  30713. return null;
  30714. }
  30715. ast1 = stack[stack.length - n - 1];
  30716. if (ast1.type === 'literal' || ast1.type === 'var') {
  30717. stack.push(ast1);
  30718. break;
  30719. }
  30720. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30721. stack[stack.length - n - 1] = tmpVar;
  30722. stack.push(tmpVar);
  30723. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30724. break;
  30725. case 'dup':
  30726. if (stack.length < 1) {
  30727. return null;
  30728. }
  30729. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  30730. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  30731. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  30732. // special case of the commands sequence for the min operation
  30733. num1 = stack.pop();
  30734. stack.push(buildMinOperation(num1, code[i + 1]));
  30735. i += 6;
  30736. break;
  30737. }
  30738. ast1 = stack[stack.length - 1];
  30739. if (ast1.type === 'literal' || ast1.type === 'var') {
  30740. // we don't have to save into intermediate variable a literal or
  30741. // variable.
  30742. stack.push(ast1);
  30743. break;
  30744. }
  30745. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  30746. stack[stack.length - 1] = tmpVar;
  30747. stack.push(tmpVar);
  30748. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  30749. break;
  30750. case 'roll':
  30751. if (stack.length < 2) {
  30752. return null;
  30753. }
  30754. num2 = stack.pop();
  30755. num1 = stack.pop();
  30756. if (num2.type !== 'literal' || num1.type !== 'literal') {
  30757. // both roll operands must be numbers
  30758. return null;
  30759. }
  30760. j = num2.number;
  30761. n = num1.number;
  30762. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  30763. // ... and integers
  30764. return null;
  30765. }
  30766. j = ((j % n) + n) % n;
  30767. if (j === 0) {
  30768. break; // just skipping -- there are nothing to rotate
  30769. }
  30770. Array.prototype.push.apply(stack,
  30771. stack.splice(stack.length - n, n - j));
  30772. break;
  30773. default:
  30774. return null; // unsupported operator
  30775. }
  30776. }
  30777. if (stack.length !== outputSize) {
  30778. return null;
  30779. }
  30780. var result = [];
  30781. instructions.forEach(function (instruction) {
  30782. var statementBuilder = new ExpressionBuilderVisitor();
  30783. instruction.visit(statementBuilder);
  30784. result.push(statementBuilder.toString());
  30785. });
  30786. stack.forEach(function (expr, i) {
  30787. var statementBuilder = new ExpressionBuilderVisitor();
  30788. expr.visit(statementBuilder);
  30789. var min = range[i * 2], max = range[i * 2 + 1];
  30790. var out = [statementBuilder.toString()];
  30791. if (min > expr.min) {
  30792. out.unshift('Math.max(', min, ', ');
  30793. out.push(')');
  30794. }
  30795. if (max < expr.max) {
  30796. out.unshift('Math.min(', max, ', ');
  30797. out.push(')');
  30798. }
  30799. out.unshift('dest[destOffset + ', i, '] = ');
  30800. out.push(';');
  30801. result.push(out.join(''));
  30802. });
  30803. return result.join('\n');
  30804. }
  30805. };
  30806. return PostScriptCompiler;
  30807. })();
  30808. exports.isPDFFunction = isPDFFunction;
  30809. exports.PDFFunction = PDFFunction;
  30810. exports.PostScriptEvaluator = PostScriptEvaluator;
  30811. exports.PostScriptCompiler = PostScriptCompiler;
  30812. }));
  30813. (function (root, factory) {
  30814. {
  30815. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  30816. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  30817. }
  30818. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  30819. coreStream) {
  30820. var error = sharedUtil.error;
  30821. var info = sharedUtil.info;
  30822. var isArray = sharedUtil.isArray;
  30823. var isString = sharedUtil.isString;
  30824. var shadow = sharedUtil.shadow;
  30825. var warn = sharedUtil.warn;
  30826. var isDict = corePrimitives.isDict;
  30827. var isName = corePrimitives.isName;
  30828. var isStream = corePrimitives.isStream;
  30829. var PDFFunction = coreFunction.PDFFunction;
  30830. var coreImage; // see _setCoreImage below
  30831. var PDFImage; // = coreImage.PDFImage;
  30832. var ColorSpace = (function ColorSpaceClosure() {
  30833. // Constructor should define this.numComps, this.defaultColor, this.name
  30834. function ColorSpace() {
  30835. error('should not call ColorSpace constructor');
  30836. }
  30837. ColorSpace.prototype = {
  30838. /**
  30839. * Converts the color value to the RGB color. The color components are
  30840. * located in the src array starting from the srcOffset. Returns the array
  30841. * of the rgb components, each value ranging from [0,255].
  30842. */
  30843. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  30844. var rgb = new Uint8Array(3);
  30845. this.getRgbItem(src, srcOffset, rgb, 0);
  30846. return rgb;
  30847. },
  30848. /**
  30849. * Converts the color value to the RGB color, similar to the getRgb method.
  30850. * The result placed into the dest array starting from the destOffset.
  30851. */
  30852. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  30853. dest, destOffset) {
  30854. error('Should not call ColorSpace.getRgbItem');
  30855. },
  30856. /**
  30857. * Converts the specified number of the color values to the RGB colors.
  30858. * The colors are located in the src array starting from the srcOffset.
  30859. * The result is placed into the dest array starting from the destOffset.
  30860. * The src array items shall be in [0,2^bits) range, the dest array items
  30861. * will be in [0,255] range. alpha01 indicates how many alpha components
  30862. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  30863. * array).
  30864. */
  30865. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  30866. dest, destOffset, bits,
  30867. alpha01) {
  30868. error('Should not call ColorSpace.getRgbBuffer');
  30869. },
  30870. /**
  30871. * Determines the number of bytes required to store the result of the
  30872. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  30873. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  30874. */
  30875. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  30876. alpha01) {
  30877. error('Should not call ColorSpace.getOutputLength');
  30878. },
  30879. /**
  30880. * Returns true if source data will be equal the result/output data.
  30881. */
  30882. isPassthrough: function ColorSpace_isPassthrough(bits) {
  30883. return false;
  30884. },
  30885. /**
  30886. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  30887. * how many alpha components there are in the dest array; it will be either
  30888. * 0 (RGB array) or 1 (RGBA array).
  30889. */
  30890. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  30891. originalHeight, width, height,
  30892. actualHeight, bpc, comps, alpha01) {
  30893. var count = originalWidth * originalHeight;
  30894. var rgbBuf = null;
  30895. var numComponentColors = 1 << bpc;
  30896. var needsResizing = originalHeight !== height || originalWidth !== width;
  30897. var i, ii;
  30898. if (this.isPassthrough(bpc)) {
  30899. rgbBuf = comps;
  30900. } else if (this.numComps === 1 && count > numComponentColors &&
  30901. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  30902. // Optimization: create a color map when there is just one component and
  30903. // we are converting more colors than the size of the color map. We
  30904. // don't build the map if the colorspace is gray or rgb since those
  30905. // methods are faster than building a map. This mainly offers big speed
  30906. // ups for indexed and alternate colorspaces.
  30907. //
  30908. // TODO it may be worth while to cache the color map. While running
  30909. // testing I never hit a cache so I will leave that out for now (perhaps
  30910. // we are reparsing colorspaces too much?).
  30911. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  30912. new Uint16Array(numComponentColors);
  30913. var key;
  30914. for (i = 0; i < numComponentColors; i++) {
  30915. allColors[i] = i;
  30916. }
  30917. var colorMap = new Uint8Array(numComponentColors * 3);
  30918. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  30919. /* alpha01 = */ 0);
  30920. var destPos, rgbPos;
  30921. if (!needsResizing) {
  30922. // Fill in the RGB values directly into |dest|.
  30923. destPos = 0;
  30924. for (i = 0; i < count; ++i) {
  30925. key = comps[i] * 3;
  30926. dest[destPos++] = colorMap[key];
  30927. dest[destPos++] = colorMap[key + 1];
  30928. dest[destPos++] = colorMap[key + 2];
  30929. destPos += alpha01;
  30930. }
  30931. } else {
  30932. rgbBuf = new Uint8Array(count * 3);
  30933. rgbPos = 0;
  30934. for (i = 0; i < count; ++i) {
  30935. key = comps[i] * 3;
  30936. rgbBuf[rgbPos++] = colorMap[key];
  30937. rgbBuf[rgbPos++] = colorMap[key + 1];
  30938. rgbBuf[rgbPos++] = colorMap[key + 2];
  30939. }
  30940. }
  30941. } else {
  30942. if (!needsResizing) {
  30943. // Fill in the RGB values directly into |dest|.
  30944. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  30945. alpha01);
  30946. } else {
  30947. rgbBuf = new Uint8Array(count * 3);
  30948. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  30949. /* alpha01 = */ 0);
  30950. }
  30951. }
  30952. if (rgbBuf) {
  30953. if (needsResizing) {
  30954. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  30955. height, dest, alpha01);
  30956. } else {
  30957. rgbPos = 0;
  30958. destPos = 0;
  30959. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  30960. dest[destPos++] = rgbBuf[rgbPos++];
  30961. dest[destPos++] = rgbBuf[rgbPos++];
  30962. dest[destPos++] = rgbBuf[rgbPos++];
  30963. destPos += alpha01;
  30964. }
  30965. }
  30966. }
  30967. },
  30968. /**
  30969. * True if the colorspace has components in the default range of [0, 1].
  30970. * This should be true for all colorspaces except for lab color spaces
  30971. * which are [0,100], [-128, 127], [-128, 127].
  30972. */
  30973. usesZeroToOneRange: true
  30974. };
  30975. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  30976. var IR = ColorSpace.parseToIR(cs, xref, res);
  30977. if (IR instanceof AlternateCS) {
  30978. return IR;
  30979. }
  30980. return ColorSpace.fromIR(IR);
  30981. };
  30982. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  30983. var name = isArray(IR) ? IR[0] : IR;
  30984. var whitePoint, blackPoint, gamma;
  30985. switch (name) {
  30986. case 'DeviceGrayCS':
  30987. return this.singletons.gray;
  30988. case 'DeviceRgbCS':
  30989. return this.singletons.rgb;
  30990. case 'DeviceCmykCS':
  30991. return this.singletons.cmyk;
  30992. case 'CalGrayCS':
  30993. whitePoint = IR[1];
  30994. blackPoint = IR[2];
  30995. gamma = IR[3];
  30996. return new CalGrayCS(whitePoint, blackPoint, gamma);
  30997. case 'CalRGBCS':
  30998. whitePoint = IR[1];
  30999. blackPoint = IR[2];
  31000. gamma = IR[3];
  31001. var matrix = IR[4];
  31002. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  31003. case 'PatternCS':
  31004. var basePatternCS = IR[1];
  31005. if (basePatternCS) {
  31006. basePatternCS = ColorSpace.fromIR(basePatternCS);
  31007. }
  31008. return new PatternCS(basePatternCS);
  31009. case 'IndexedCS':
  31010. var baseIndexedCS = IR[1];
  31011. var hiVal = IR[2];
  31012. var lookup = IR[3];
  31013. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  31014. case 'AlternateCS':
  31015. var numComps = IR[1];
  31016. var alt = IR[2];
  31017. var tintFnIR = IR[3];
  31018. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  31019. PDFFunction.fromIR(tintFnIR));
  31020. case 'LabCS':
  31021. whitePoint = IR[1];
  31022. blackPoint = IR[2];
  31023. var range = IR[3];
  31024. return new LabCS(whitePoint, blackPoint, range);
  31025. default:
  31026. error('Unknown name ' + name);
  31027. }
  31028. return null;
  31029. };
  31030. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  31031. if (isName(cs)) {
  31032. var colorSpaces = res.get('ColorSpace');
  31033. if (isDict(colorSpaces)) {
  31034. var refcs = colorSpaces.get(cs.name);
  31035. if (refcs) {
  31036. cs = refcs;
  31037. }
  31038. }
  31039. }
  31040. cs = xref.fetchIfRef(cs);
  31041. var mode;
  31042. if (isName(cs)) {
  31043. mode = cs.name;
  31044. this.mode = mode;
  31045. switch (mode) {
  31046. case 'DeviceGray':
  31047. case 'G':
  31048. return 'DeviceGrayCS';
  31049. case 'DeviceRGB':
  31050. case 'RGB':
  31051. return 'DeviceRgbCS';
  31052. case 'DeviceCMYK':
  31053. case 'CMYK':
  31054. return 'DeviceCmykCS';
  31055. case 'Pattern':
  31056. return ['PatternCS', null];
  31057. default:
  31058. error('unrecognized colorspace ' + mode);
  31059. }
  31060. } else if (isArray(cs)) {
  31061. mode = xref.fetchIfRef(cs[0]).name;
  31062. this.mode = mode;
  31063. var numComps, params, alt, whitePoint, blackPoint, gamma;
  31064. switch (mode) {
  31065. case 'DeviceGray':
  31066. case 'G':
  31067. return 'DeviceGrayCS';
  31068. case 'DeviceRGB':
  31069. case 'RGB':
  31070. return 'DeviceRgbCS';
  31071. case 'DeviceCMYK':
  31072. case 'CMYK':
  31073. return 'DeviceCmykCS';
  31074. case 'CalGray':
  31075. params = xref.fetchIfRef(cs[1]);
  31076. whitePoint = params.get('WhitePoint');
  31077. blackPoint = params.get('BlackPoint');
  31078. gamma = params.get('Gamma');
  31079. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  31080. case 'CalRGB':
  31081. params = xref.fetchIfRef(cs[1]);
  31082. whitePoint = params.get('WhitePoint');
  31083. blackPoint = params.get('BlackPoint');
  31084. gamma = params.get('Gamma');
  31085. var matrix = params.get('Matrix');
  31086. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  31087. case 'ICCBased':
  31088. var stream = xref.fetchIfRef(cs[1]);
  31089. var dict = stream.dict;
  31090. numComps = dict.get('N');
  31091. alt = dict.get('Alternate');
  31092. if (alt) {
  31093. var altIR = ColorSpace.parseToIR(alt, xref, res);
  31094. // Parse the /Alternate CS to ensure that the number of components
  31095. // are correct, and also (indirectly) that it is not a PatternCS.
  31096. var altCS = ColorSpace.fromIR(altIR);
  31097. if (altCS.numComps === numComps) {
  31098. return altIR;
  31099. }
  31100. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  31101. }
  31102. if (numComps === 1) {
  31103. return 'DeviceGrayCS';
  31104. } else if (numComps === 3) {
  31105. return 'DeviceRgbCS';
  31106. } else if (numComps === 4) {
  31107. return 'DeviceCmykCS';
  31108. }
  31109. break;
  31110. case 'Pattern':
  31111. var basePatternCS = cs[1] || null;
  31112. if (basePatternCS) {
  31113. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  31114. }
  31115. return ['PatternCS', basePatternCS];
  31116. case 'Indexed':
  31117. case 'I':
  31118. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  31119. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  31120. var lookup = xref.fetchIfRef(cs[3]);
  31121. if (isStream(lookup)) {
  31122. lookup = lookup.getBytes();
  31123. }
  31124. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  31125. case 'Separation':
  31126. case 'DeviceN':
  31127. var name = xref.fetchIfRef(cs[1]);
  31128. numComps = 1;
  31129. if (isName(name)) {
  31130. numComps = 1;
  31131. } else if (isArray(name)) {
  31132. numComps = name.length;
  31133. }
  31134. alt = ColorSpace.parseToIR(cs[2], xref, res);
  31135. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  31136. return ['AlternateCS', numComps, alt, tintFnIR];
  31137. case 'Lab':
  31138. params = xref.fetchIfRef(cs[1]);
  31139. whitePoint = params.get('WhitePoint');
  31140. blackPoint = params.get('BlackPoint');
  31141. var range = params.get('Range');
  31142. return ['LabCS', whitePoint, blackPoint, range];
  31143. default:
  31144. error('unimplemented color space object "' + mode + '"');
  31145. }
  31146. } else {
  31147. error('unrecognized color space object: "' + cs + '"');
  31148. }
  31149. return null;
  31150. };
  31151. /**
  31152. * Checks if a decode map matches the default decode map for a color space.
  31153. * This handles the general decode maps where there are two values per
  31154. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  31155. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  31156. * slightly different.
  31157. * @param {Array} decode Decode map (usually from an image).
  31158. * @param {Number} n Number of components the color space has.
  31159. */
  31160. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  31161. if (!isArray(decode)) {
  31162. return true;
  31163. }
  31164. if (n * 2 !== decode.length) {
  31165. warn('The decode map is not the correct length');
  31166. return true;
  31167. }
  31168. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  31169. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  31170. return false;
  31171. }
  31172. }
  31173. return true;
  31174. };
  31175. ColorSpace.singletons = {
  31176. get gray() {
  31177. return shadow(this, 'gray', new DeviceGrayCS());
  31178. },
  31179. get rgb() {
  31180. return shadow(this, 'rgb', new DeviceRgbCS());
  31181. },
  31182. get cmyk() {
  31183. return shadow(this, 'cmyk', new DeviceCmykCS());
  31184. }
  31185. };
  31186. return ColorSpace;
  31187. })();
  31188. /**
  31189. * Alternate color space handles both Separation and DeviceN color spaces. A
  31190. * Separation color space is actually just a DeviceN with one color component.
  31191. * Both color spaces use a tinting function to convert colors to a base color
  31192. * space.
  31193. */
  31194. var AlternateCS = (function AlternateCSClosure() {
  31195. function AlternateCS(numComps, base, tintFn) {
  31196. this.name = 'Alternate';
  31197. this.numComps = numComps;
  31198. this.defaultColor = new Float32Array(numComps);
  31199. for (var i = 0; i < numComps; ++i) {
  31200. this.defaultColor[i] = 1;
  31201. }
  31202. this.base = base;
  31203. this.tintFn = tintFn;
  31204. this.tmpBuf = new Float32Array(base.numComps);
  31205. }
  31206. AlternateCS.prototype = {
  31207. getRgb: ColorSpace.prototype.getRgb,
  31208. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  31209. dest, destOffset) {
  31210. var tmpBuf = this.tmpBuf;
  31211. this.tintFn(src, srcOffset, tmpBuf, 0);
  31212. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  31213. },
  31214. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  31215. dest, destOffset, bits,
  31216. alpha01) {
  31217. var tintFn = this.tintFn;
  31218. var base = this.base;
  31219. var scale = 1 / ((1 << bits) - 1);
  31220. var baseNumComps = base.numComps;
  31221. var usesZeroToOneRange = base.usesZeroToOneRange;
  31222. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  31223. alpha01 === 0;
  31224. var pos = isPassthrough ? destOffset : 0;
  31225. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  31226. var numComps = this.numComps;
  31227. var scaled = new Float32Array(numComps);
  31228. var tinted = new Float32Array(baseNumComps);
  31229. var i, j;
  31230. if (usesZeroToOneRange) {
  31231. for (i = 0; i < count; i++) {
  31232. for (j = 0; j < numComps; j++) {
  31233. scaled[j] = src[srcOffset++] * scale;
  31234. }
  31235. tintFn(scaled, 0, tinted, 0);
  31236. for (j = 0; j < baseNumComps; j++) {
  31237. baseBuf[pos++] = tinted[j] * 255;
  31238. }
  31239. }
  31240. } else {
  31241. for (i = 0; i < count; i++) {
  31242. for (j = 0; j < numComps; j++) {
  31243. scaled[j] = src[srcOffset++] * scale;
  31244. }
  31245. tintFn(scaled, 0, tinted, 0);
  31246. base.getRgbItem(tinted, 0, baseBuf, pos);
  31247. pos += baseNumComps;
  31248. }
  31249. }
  31250. if (!isPassthrough) {
  31251. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  31252. }
  31253. },
  31254. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  31255. alpha01) {
  31256. return this.base.getOutputLength(inputLength *
  31257. this.base.numComps / this.numComps,
  31258. alpha01);
  31259. },
  31260. isPassthrough: ColorSpace.prototype.isPassthrough,
  31261. fillRgb: ColorSpace.prototype.fillRgb,
  31262. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  31263. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31264. },
  31265. usesZeroToOneRange: true
  31266. };
  31267. return AlternateCS;
  31268. })();
  31269. var PatternCS = (function PatternCSClosure() {
  31270. function PatternCS(baseCS) {
  31271. this.name = 'Pattern';
  31272. this.base = baseCS;
  31273. }
  31274. PatternCS.prototype = {};
  31275. return PatternCS;
  31276. })();
  31277. var IndexedCS = (function IndexedCSClosure() {
  31278. function IndexedCS(base, highVal, lookup) {
  31279. this.name = 'Indexed';
  31280. this.numComps = 1;
  31281. this.defaultColor = new Uint8Array([0]);
  31282. this.base = base;
  31283. this.highVal = highVal;
  31284. var baseNumComps = base.numComps;
  31285. var length = baseNumComps * highVal;
  31286. var lookupArray;
  31287. if (isStream(lookup)) {
  31288. lookupArray = new Uint8Array(length);
  31289. var bytes = lookup.getBytes(length);
  31290. lookupArray.set(bytes);
  31291. } else if (isString(lookup)) {
  31292. lookupArray = new Uint8Array(length);
  31293. for (var i = 0; i < length; ++i) {
  31294. lookupArray[i] = lookup.charCodeAt(i);
  31295. }
  31296. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  31297. lookupArray = lookup;
  31298. } else {
  31299. error('Unrecognized lookup table: ' + lookup);
  31300. }
  31301. this.lookup = lookupArray;
  31302. }
  31303. IndexedCS.prototype = {
  31304. getRgb: ColorSpace.prototype.getRgb,
  31305. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  31306. dest, destOffset) {
  31307. var numComps = this.base.numComps;
  31308. var start = src[srcOffset] * numComps;
  31309. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  31310. },
  31311. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  31312. dest, destOffset, bits,
  31313. alpha01) {
  31314. var base = this.base;
  31315. var numComps = base.numComps;
  31316. var outputDelta = base.getOutputLength(numComps, alpha01);
  31317. var lookup = this.lookup;
  31318. for (var i = 0; i < count; ++i) {
  31319. var lookupPos = src[srcOffset++] * numComps;
  31320. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  31321. destOffset += outputDelta;
  31322. }
  31323. },
  31324. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  31325. return this.base.getOutputLength(inputLength * this.base.numComps,
  31326. alpha01);
  31327. },
  31328. isPassthrough: ColorSpace.prototype.isPassthrough,
  31329. fillRgb: ColorSpace.prototype.fillRgb,
  31330. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  31331. // indexed color maps shouldn't be changed
  31332. return true;
  31333. },
  31334. usesZeroToOneRange: true
  31335. };
  31336. return IndexedCS;
  31337. })();
  31338. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  31339. function DeviceGrayCS() {
  31340. this.name = 'DeviceGray';
  31341. this.numComps = 1;
  31342. this.defaultColor = new Float32Array([0]);
  31343. }
  31344. DeviceGrayCS.prototype = {
  31345. getRgb: ColorSpace.prototype.getRgb,
  31346. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  31347. dest, destOffset) {
  31348. var c = (src[srcOffset] * 255) | 0;
  31349. c = c < 0 ? 0 : c > 255 ? 255 : c;
  31350. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  31351. },
  31352. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  31353. dest, destOffset, bits,
  31354. alpha01) {
  31355. var scale = 255 / ((1 << bits) - 1);
  31356. var j = srcOffset, q = destOffset;
  31357. for (var i = 0; i < count; ++i) {
  31358. var c = (scale * src[j++]) | 0;
  31359. dest[q++] = c;
  31360. dest[q++] = c;
  31361. dest[q++] = c;
  31362. q += alpha01;
  31363. }
  31364. },
  31365. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  31366. alpha01) {
  31367. return inputLength * (3 + alpha01);
  31368. },
  31369. isPassthrough: ColorSpace.prototype.isPassthrough,
  31370. fillRgb: ColorSpace.prototype.fillRgb,
  31371. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  31372. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31373. },
  31374. usesZeroToOneRange: true
  31375. };
  31376. return DeviceGrayCS;
  31377. })();
  31378. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  31379. function DeviceRgbCS() {
  31380. this.name = 'DeviceRGB';
  31381. this.numComps = 3;
  31382. this.defaultColor = new Float32Array([0, 0, 0]);
  31383. }
  31384. DeviceRgbCS.prototype = {
  31385. getRgb: ColorSpace.prototype.getRgb,
  31386. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  31387. dest, destOffset) {
  31388. var r = (src[srcOffset] * 255) | 0;
  31389. var g = (src[srcOffset + 1] * 255) | 0;
  31390. var b = (src[srcOffset + 2] * 255) | 0;
  31391. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  31392. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  31393. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  31394. },
  31395. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  31396. dest, destOffset, bits,
  31397. alpha01) {
  31398. if (bits === 8 && alpha01 === 0) {
  31399. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  31400. return;
  31401. }
  31402. var scale = 255 / ((1 << bits) - 1);
  31403. var j = srcOffset, q = destOffset;
  31404. for (var i = 0; i < count; ++i) {
  31405. dest[q++] = (scale * src[j++]) | 0;
  31406. dest[q++] = (scale * src[j++]) | 0;
  31407. dest[q++] = (scale * src[j++]) | 0;
  31408. q += alpha01;
  31409. }
  31410. },
  31411. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  31412. alpha01) {
  31413. return (inputLength * (3 + alpha01) / 3) | 0;
  31414. },
  31415. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  31416. return bits === 8;
  31417. },
  31418. fillRgb: ColorSpace.prototype.fillRgb,
  31419. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  31420. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31421. },
  31422. usesZeroToOneRange: true
  31423. };
  31424. return DeviceRgbCS;
  31425. })();
  31426. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  31427. // The coefficients below was found using numerical analysis: the method of
  31428. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  31429. // where color_value is the tabular value from the table of sampled RGB colors
  31430. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  31431. // CMYK color conversion using the estimation below:
  31432. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  31433. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  31434. var c = src[srcOffset + 0] * srcScale;
  31435. var m = src[srcOffset + 1] * srcScale;
  31436. var y = src[srcOffset + 2] * srcScale;
  31437. var k = src[srcOffset + 3] * srcScale;
  31438. var r =
  31439. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  31440. 18.82290502165302 * y + 212.25662451639585 * k +
  31441. -285.2331026137004) +
  31442. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  31443. -17.873870861415444 * k - 5.497006427196366) +
  31444. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  31445. 17.5119270841813) +
  31446. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  31447. var g =
  31448. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  31449. 6.871425592049007 * y + 31.159100130055922 * k +
  31450. -79.2970844816548) +
  31451. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  31452. 131.35250912493976 * k - 190.9453302588951) +
  31453. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  31454. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  31455. var b =
  31456. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  31457. 30.89978309703729 * y - 0.23883238689178934 * k +
  31458. -14.183576799673286) +
  31459. m * (10.49593273432072 * m + 63.02378494754052 * y +
  31460. 50.606957656360734 * k - 112.23884253719248) +
  31461. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  31462. -193.58209356861505) +
  31463. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  31464. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  31465. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  31466. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  31467. }
  31468. function DeviceCmykCS() {
  31469. this.name = 'DeviceCMYK';
  31470. this.numComps = 4;
  31471. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  31472. }
  31473. DeviceCmykCS.prototype = {
  31474. getRgb: ColorSpace.prototype.getRgb,
  31475. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  31476. dest, destOffset) {
  31477. convertToRgb(src, srcOffset, 1, dest, destOffset);
  31478. },
  31479. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  31480. dest, destOffset, bits,
  31481. alpha01) {
  31482. var scale = 1 / ((1 << bits) - 1);
  31483. for (var i = 0; i < count; i++) {
  31484. convertToRgb(src, srcOffset, scale, dest, destOffset);
  31485. srcOffset += 4;
  31486. destOffset += 3 + alpha01;
  31487. }
  31488. },
  31489. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  31490. alpha01) {
  31491. return (inputLength / 4 * (3 + alpha01)) | 0;
  31492. },
  31493. isPassthrough: ColorSpace.prototype.isPassthrough,
  31494. fillRgb: ColorSpace.prototype.fillRgb,
  31495. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  31496. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31497. },
  31498. usesZeroToOneRange: true
  31499. };
  31500. return DeviceCmykCS;
  31501. })();
  31502. //
  31503. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  31504. //
  31505. var CalGrayCS = (function CalGrayCSClosure() {
  31506. function CalGrayCS(whitePoint, blackPoint, gamma) {
  31507. this.name = 'CalGray';
  31508. this.numComps = 1;
  31509. this.defaultColor = new Float32Array([0]);
  31510. if (!whitePoint) {
  31511. error('WhitePoint missing - required for color space CalGray');
  31512. }
  31513. blackPoint = blackPoint || [0, 0, 0];
  31514. gamma = gamma || 1;
  31515. // Translate arguments to spec variables.
  31516. this.XW = whitePoint[0];
  31517. this.YW = whitePoint[1];
  31518. this.ZW = whitePoint[2];
  31519. this.XB = blackPoint[0];
  31520. this.YB = blackPoint[1];
  31521. this.ZB = blackPoint[2];
  31522. this.G = gamma;
  31523. // Validate variables as per spec.
  31524. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31525. error('Invalid WhitePoint components for ' + this.name +
  31526. ', no fallback available');
  31527. }
  31528. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31529. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  31530. this.XB = this.YB = this.ZB = 0;
  31531. }
  31532. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  31533. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  31534. ', ZB: ' + this.ZB + ', only default values are supported.');
  31535. }
  31536. if (this.G < 1) {
  31537. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  31538. ', falling back to default');
  31539. this.G = 1;
  31540. }
  31541. }
  31542. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31543. // A represents a gray component of a calibrated gray space.
  31544. // A <---> AG in the spec
  31545. var A = src[srcOffset] * scale;
  31546. var AG = Math.pow(A, cs.G);
  31547. // Computes L as per spec. ( = cs.YW * AG )
  31548. // Except if other than default BlackPoint values are used.
  31549. var L = cs.YW * AG;
  31550. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  31551. // Convert values to rgb range [0, 255].
  31552. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  31553. dest[destOffset] = val;
  31554. dest[destOffset + 1] = val;
  31555. dest[destOffset + 2] = val;
  31556. }
  31557. CalGrayCS.prototype = {
  31558. getRgb: ColorSpace.prototype.getRgb,
  31559. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  31560. dest, destOffset) {
  31561. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31562. },
  31563. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  31564. dest, destOffset, bits,
  31565. alpha01) {
  31566. var scale = 1 / ((1 << bits) - 1);
  31567. for (var i = 0; i < count; ++i) {
  31568. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31569. srcOffset += 1;
  31570. destOffset += 3 + alpha01;
  31571. }
  31572. },
  31573. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  31574. return inputLength * (3 + alpha01);
  31575. },
  31576. isPassthrough: ColorSpace.prototype.isPassthrough,
  31577. fillRgb: ColorSpace.prototype.fillRgb,
  31578. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  31579. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31580. },
  31581. usesZeroToOneRange: true
  31582. };
  31583. return CalGrayCS;
  31584. })();
  31585. //
  31586. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  31587. //
  31588. var CalRGBCS = (function CalRGBCSClosure() {
  31589. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  31590. // matrices.
  31591. var BRADFORD_SCALE_MATRIX = new Float32Array([
  31592. 0.8951, 0.2664, -0.1614,
  31593. -0.7502, 1.7135, 0.0367,
  31594. 0.0389, -0.0685, 1.0296]);
  31595. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  31596. 0.9869929, -0.1470543, 0.1599627,
  31597. 0.4323053, 0.5183603, 0.0492912,
  31598. -0.0085287, 0.0400428, 0.9684867]);
  31599. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  31600. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  31601. 3.2404542, -1.5371385, -0.4985314,
  31602. -0.9692660, 1.8760108, 0.0415560,
  31603. 0.0556434, -0.2040259, 1.0572252]);
  31604. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  31605. var tempNormalizeMatrix = new Float32Array(3);
  31606. var tempConvertMatrix1 = new Float32Array(3);
  31607. var tempConvertMatrix2 = new Float32Array(3);
  31608. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  31609. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  31610. this.name = 'CalRGB';
  31611. this.numComps = 3;
  31612. this.defaultColor = new Float32Array(3);
  31613. if (!whitePoint) {
  31614. error('WhitePoint missing - required for color space CalRGB');
  31615. }
  31616. blackPoint = blackPoint || new Float32Array(3);
  31617. gamma = gamma || new Float32Array([1, 1, 1]);
  31618. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  31619. // Translate arguments to spec variables.
  31620. var XW = whitePoint[0];
  31621. var YW = whitePoint[1];
  31622. var ZW = whitePoint[2];
  31623. this.whitePoint = whitePoint;
  31624. var XB = blackPoint[0];
  31625. var YB = blackPoint[1];
  31626. var ZB = blackPoint[2];
  31627. this.blackPoint = blackPoint;
  31628. this.GR = gamma[0];
  31629. this.GG = gamma[1];
  31630. this.GB = gamma[2];
  31631. this.MXA = matrix[0];
  31632. this.MYA = matrix[1];
  31633. this.MZA = matrix[2];
  31634. this.MXB = matrix[3];
  31635. this.MYB = matrix[4];
  31636. this.MZB = matrix[5];
  31637. this.MXC = matrix[6];
  31638. this.MYC = matrix[7];
  31639. this.MZC = matrix[8];
  31640. // Validate variables as per spec.
  31641. if (XW < 0 || ZW < 0 || YW !== 1) {
  31642. error('Invalid WhitePoint components for ' + this.name +
  31643. ', no fallback available');
  31644. }
  31645. if (XB < 0 || YB < 0 || ZB < 0) {
  31646. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  31647. ', ' + ZB + '], falling back to default');
  31648. this.blackPoint = new Float32Array(3);
  31649. }
  31650. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  31651. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  31652. '] for ' + this.name + ', falling back to default');
  31653. this.GR = this.GG = this.GB = 1;
  31654. }
  31655. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  31656. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  31657. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  31658. info('Invalid Matrix for ' + this.name + ' [' +
  31659. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  31660. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  31661. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  31662. '], falling back to default');
  31663. this.MXA = this.MYB = this.MZC = 1;
  31664. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  31665. }
  31666. }
  31667. function matrixProduct(a, b, result) {
  31668. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  31669. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  31670. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  31671. }
  31672. function convertToFlat(sourceWhitePoint, LMS, result) {
  31673. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  31674. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  31675. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  31676. }
  31677. function convertToD65(sourceWhitePoint, LMS, result) {
  31678. var D65X = 0.95047;
  31679. var D65Y = 1;
  31680. var D65Z = 1.08883;
  31681. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  31682. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  31683. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  31684. }
  31685. function sRGBTransferFunction(color) {
  31686. // See http://en.wikipedia.org/wiki/SRGB.
  31687. if (color <= 0.0031308){
  31688. return adjustToRange(0, 1, 12.92 * color);
  31689. }
  31690. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  31691. }
  31692. function adjustToRange(min, max, value) {
  31693. return Math.max(min, Math.min(max, value));
  31694. }
  31695. function decodeL(L) {
  31696. if (L < 0) {
  31697. return -decodeL(-L);
  31698. }
  31699. if (L > 8.0) {
  31700. return Math.pow(((L + 16) / 116), 3);
  31701. }
  31702. return L * DECODE_L_CONSTANT;
  31703. }
  31704. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  31705. // In case the blackPoint is already the default blackPoint then there is
  31706. // no need to do compensation.
  31707. if (sourceBlackPoint[0] === 0 &&
  31708. sourceBlackPoint[1] === 0 &&
  31709. sourceBlackPoint[2] === 0) {
  31710. result[0] = XYZ_Flat[0];
  31711. result[1] = XYZ_Flat[1];
  31712. result[2] = XYZ_Flat[2];
  31713. return;
  31714. }
  31715. // For the blackPoint calculation details, please see
  31716. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31717. // AdobeBPC.pdf.
  31718. // The destination blackPoint is the default blackPoint [0, 0, 0].
  31719. var zeroDecodeL = decodeL(0);
  31720. var X_DST = zeroDecodeL;
  31721. var X_SRC = decodeL(sourceBlackPoint[0]);
  31722. var Y_DST = zeroDecodeL;
  31723. var Y_SRC = decodeL(sourceBlackPoint[1]);
  31724. var Z_DST = zeroDecodeL;
  31725. var Z_SRC = decodeL(sourceBlackPoint[2]);
  31726. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  31727. var X_Offset = 1 - X_Scale;
  31728. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  31729. var Y_Offset = 1 - Y_Scale;
  31730. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  31731. var Z_Offset = 1 - Z_Scale;
  31732. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  31733. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  31734. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  31735. }
  31736. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  31737. // In case the whitePoint is already flat then there is no need to do
  31738. // normalization.
  31739. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  31740. result[0] = XYZ_In[0];
  31741. result[1] = XYZ_In[1];
  31742. result[2] = XYZ_In[2];
  31743. return;
  31744. }
  31745. var LMS = result;
  31746. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31747. var LMS_Flat = tempNormalizeMatrix;
  31748. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  31749. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  31750. }
  31751. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  31752. var LMS = result;
  31753. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  31754. var LMS_D65 = tempNormalizeMatrix;
  31755. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  31756. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  31757. }
  31758. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  31759. // A, B and C represent a red, green and blue components of a calibrated
  31760. // rgb space.
  31761. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  31762. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  31763. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  31764. // A <---> AGR in the spec
  31765. // B <---> BGG in the spec
  31766. // C <---> CGB in the spec
  31767. var AGR = Math.pow(A, cs.GR);
  31768. var BGG = Math.pow(B, cs.GG);
  31769. var CGB = Math.pow(C, cs.GB);
  31770. // Computes intermediate variables L, M, N as per spec.
  31771. // To decode X, Y, Z values map L, M, N directly to them.
  31772. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  31773. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  31774. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  31775. // The following calculations are based on this document:
  31776. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  31777. // AdobeBPC.pdf.
  31778. var XYZ = tempConvertMatrix1;
  31779. XYZ[0] = X;
  31780. XYZ[1] = Y;
  31781. XYZ[2] = Z;
  31782. var XYZ_Flat = tempConvertMatrix2;
  31783. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  31784. var XYZ_Black = tempConvertMatrix1;
  31785. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  31786. var XYZ_D65 = tempConvertMatrix2;
  31787. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  31788. var SRGB = tempConvertMatrix1;
  31789. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  31790. var sR = sRGBTransferFunction(SRGB[0]);
  31791. var sG = sRGBTransferFunction(SRGB[1]);
  31792. var sB = sRGBTransferFunction(SRGB[2]);
  31793. // Convert the values to rgb range [0, 255].
  31794. dest[destOffset] = Math.round(sR * 255);
  31795. dest[destOffset + 1] = Math.round(sG * 255);
  31796. dest[destOffset + 2] = Math.round(sB * 255);
  31797. }
  31798. CalRGBCS.prototype = {
  31799. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  31800. var rgb = new Uint8Array(3);
  31801. this.getRgbItem(src, srcOffset, rgb, 0);
  31802. return rgb;
  31803. },
  31804. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  31805. dest, destOffset) {
  31806. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  31807. },
  31808. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  31809. dest, destOffset, bits,
  31810. alpha01) {
  31811. var scale = 1 / ((1 << bits) - 1);
  31812. for (var i = 0; i < count; ++i) {
  31813. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  31814. srcOffset += 3;
  31815. destOffset += 3 + alpha01;
  31816. }
  31817. },
  31818. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  31819. return (inputLength * (3 + alpha01) / 3) | 0;
  31820. },
  31821. isPassthrough: ColorSpace.prototype.isPassthrough,
  31822. fillRgb: ColorSpace.prototype.fillRgb,
  31823. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  31824. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  31825. },
  31826. usesZeroToOneRange: true
  31827. };
  31828. return CalRGBCS;
  31829. })();
  31830. //
  31831. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  31832. //
  31833. var LabCS = (function LabCSClosure() {
  31834. function LabCS(whitePoint, blackPoint, range) {
  31835. this.name = 'Lab';
  31836. this.numComps = 3;
  31837. this.defaultColor = new Float32Array([0, 0, 0]);
  31838. if (!whitePoint) {
  31839. error('WhitePoint missing - required for color space Lab');
  31840. }
  31841. blackPoint = blackPoint || [0, 0, 0];
  31842. range = range || [-100, 100, -100, 100];
  31843. // Translate args to spec variables
  31844. this.XW = whitePoint[0];
  31845. this.YW = whitePoint[1];
  31846. this.ZW = whitePoint[2];
  31847. this.amin = range[0];
  31848. this.amax = range[1];
  31849. this.bmin = range[2];
  31850. this.bmax = range[3];
  31851. // These are here just for completeness - the spec doesn't offer any
  31852. // formulas that use BlackPoint in Lab
  31853. this.XB = blackPoint[0];
  31854. this.YB = blackPoint[1];
  31855. this.ZB = blackPoint[2];
  31856. // Validate vars as per spec
  31857. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  31858. error('Invalid WhitePoint components, no fallback available');
  31859. }
  31860. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  31861. info('Invalid BlackPoint, falling back to default');
  31862. this.XB = this.YB = this.ZB = 0;
  31863. }
  31864. if (this.amin > this.amax || this.bmin > this.bmax) {
  31865. info('Invalid Range, falling back to defaults');
  31866. this.amin = -100;
  31867. this.amax = 100;
  31868. this.bmin = -100;
  31869. this.bmax = 100;
  31870. }
  31871. }
  31872. // Function g(x) from spec
  31873. function fn_g(x) {
  31874. if (x >= 6 / 29) {
  31875. return x * x * x;
  31876. } else {
  31877. return (108 / 841) * (x - 4 / 29);
  31878. }
  31879. }
  31880. function decode(value, high1, low2, high2) {
  31881. return low2 + (value) * (high2 - low2) / (high1);
  31882. }
  31883. // If decoding is needed maxVal should be 2^bits per component - 1.
  31884. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  31885. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  31886. // not the usual [0, 1]. If a command like setFillColor is used the src
  31887. // values will already be within the correct range. However, if we are
  31888. // converting an image we have to map the values to the correct range given
  31889. // above.
  31890. // Ls,as,bs <---> L*,a*,b* in the spec
  31891. var Ls = src[srcOffset];
  31892. var as = src[srcOffset + 1];
  31893. var bs = src[srcOffset + 2];
  31894. if (maxVal !== false) {
  31895. Ls = decode(Ls, maxVal, 0, 100);
  31896. as = decode(as, maxVal, cs.amin, cs.amax);
  31897. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  31898. }
  31899. // Adjust limits of 'as' and 'bs'
  31900. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  31901. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  31902. // Computes intermediate variables X,Y,Z as per spec
  31903. var M = (Ls + 16) / 116;
  31904. var L = M + (as / 500);
  31905. var N = M - (bs / 200);
  31906. var X = cs.XW * fn_g(L);
  31907. var Y = cs.YW * fn_g(M);
  31908. var Z = cs.ZW * fn_g(N);
  31909. var r, g, b;
  31910. // Using different conversions for D50 and D65 white points,
  31911. // per http://www.color.org/srgb.pdf
  31912. if (cs.ZW < 1) {
  31913. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  31914. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  31915. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  31916. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  31917. } else {
  31918. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  31919. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  31920. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  31921. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  31922. }
  31923. // clamp color values to [0,1] range then convert to [0,255] range.
  31924. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  31925. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  31926. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  31927. }
  31928. LabCS.prototype = {
  31929. getRgb: ColorSpace.prototype.getRgb,
  31930. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  31931. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  31932. },
  31933. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  31934. dest, destOffset, bits,
  31935. alpha01) {
  31936. var maxVal = (1 << bits) - 1;
  31937. for (var i = 0; i < count; i++) {
  31938. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  31939. srcOffset += 3;
  31940. destOffset += 3 + alpha01;
  31941. }
  31942. },
  31943. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  31944. return (inputLength * (3 + alpha01) / 3) | 0;
  31945. },
  31946. isPassthrough: ColorSpace.prototype.isPassthrough,
  31947. fillRgb: ColorSpace.prototype.fillRgb,
  31948. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  31949. // XXX: Decoding is handled with the lab conversion because of the strange
  31950. // ranges that are used.
  31951. return true;
  31952. },
  31953. usesZeroToOneRange: false
  31954. };
  31955. return LabCS;
  31956. })();
  31957. // TODO refactor to remove dependency on image.js
  31958. function _setCoreImage(coreImage_) {
  31959. coreImage = coreImage_;
  31960. PDFImage = coreImage_.PDFImage;
  31961. }
  31962. exports._setCoreImage = _setCoreImage;
  31963. exports.ColorSpace = ColorSpace;
  31964. // TODO refactor to remove dependency on colorspace.js
  31965. coreStream._setCoreColorSpace(exports);
  31966. }));
  31967. (function (root, factory) {
  31968. {
  31969. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  31970. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  31971. root.pdfjsCoreJpx);
  31972. }
  31973. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  31974. coreStream, coreJpx) {
  31975. var ImageKind = sharedUtil.ImageKind;
  31976. var assert = sharedUtil.assert;
  31977. var error = sharedUtil.error;
  31978. var info = sharedUtil.info;
  31979. var isArray = sharedUtil.isArray;
  31980. var warn = sharedUtil.warn;
  31981. var Name = corePrimitives.Name;
  31982. var isStream = corePrimitives.isStream;
  31983. var ColorSpace = coreColorSpace.ColorSpace;
  31984. var DecodeStream = coreStream.DecodeStream;
  31985. var Stream = coreStream.Stream;
  31986. var JpegStream = coreStream.JpegStream;
  31987. var JpxImage = coreJpx.JpxImage;
  31988. var PDFImage = (function PDFImageClosure() {
  31989. /**
  31990. * Decode the image in the main thread if it supported. Resovles the promise
  31991. * when the image data is ready.
  31992. */
  31993. function handleImageData(handler, xref, res, image) {
  31994. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  31995. // For natively supported jpegs send them to the main thread for decoding.
  31996. var dict = image.dict;
  31997. var colorSpace = dict.get('ColorSpace', 'CS');
  31998. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  31999. var numComps = colorSpace.numComps;
  32000. var decodePromise = handler.sendWithPromise('JpegDecode',
  32001. [image.getIR(), numComps]);
  32002. return decodePromise.then(function (message) {
  32003. var data = message.data;
  32004. return new Stream(data, 0, data.length, image.dict);
  32005. });
  32006. } else {
  32007. return Promise.resolve(image);
  32008. }
  32009. }
  32010. /**
  32011. * Decode and clamp a value. The formula is different from the spec because we
  32012. * don't decode to float range [0,1], we decode it in the [0,max] range.
  32013. */
  32014. function decodeAndClamp(value, addend, coefficient, max) {
  32015. value = addend + value * coefficient;
  32016. // Clamp the value to the range
  32017. return (value < 0 ? 0 : (value > max ? max : value));
  32018. }
  32019. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  32020. this.image = image;
  32021. var dict = image.dict;
  32022. if (dict.has('Filter')) {
  32023. var filter = dict.get('Filter').name;
  32024. if (filter === 'JPXDecode') {
  32025. var jpxImage = new JpxImage();
  32026. jpxImage.parseImageProperties(image.stream);
  32027. image.stream.reset();
  32028. image.bitsPerComponent = jpxImage.bitsPerComponent;
  32029. image.numComps = jpxImage.componentsCount;
  32030. } else if (filter === 'JBIG2Decode') {
  32031. image.bitsPerComponent = 1;
  32032. image.numComps = 1;
  32033. }
  32034. }
  32035. // TODO cache rendered images?
  32036. this.width = dict.get('Width', 'W');
  32037. this.height = dict.get('Height', 'H');
  32038. if (this.width < 1 || this.height < 1) {
  32039. error('Invalid image width: ' + this.width + ' or height: ' +
  32040. this.height);
  32041. }
  32042. this.interpolate = dict.get('Interpolate', 'I') || false;
  32043. this.imageMask = dict.get('ImageMask', 'IM') || false;
  32044. this.matte = dict.get('Matte') || false;
  32045. var bitsPerComponent = image.bitsPerComponent;
  32046. if (!bitsPerComponent) {
  32047. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  32048. if (!bitsPerComponent) {
  32049. if (this.imageMask) {
  32050. bitsPerComponent = 1;
  32051. } else {
  32052. error('Bits per component missing in image: ' + this.imageMask);
  32053. }
  32054. }
  32055. }
  32056. this.bpc = bitsPerComponent;
  32057. if (!this.imageMask) {
  32058. var colorSpace = dict.get('ColorSpace', 'CS');
  32059. if (!colorSpace) {
  32060. info('JPX images (which do not require color spaces)');
  32061. switch (image.numComps) {
  32062. case 1:
  32063. colorSpace = Name.get('DeviceGray');
  32064. break;
  32065. case 3:
  32066. colorSpace = Name.get('DeviceRGB');
  32067. break;
  32068. case 4:
  32069. colorSpace = Name.get('DeviceCMYK');
  32070. break;
  32071. default:
  32072. error('JPX images with ' + this.numComps +
  32073. ' color components not supported.');
  32074. }
  32075. }
  32076. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  32077. this.numComps = this.colorSpace.numComps;
  32078. }
  32079. this.decode = dict.get('Decode', 'D');
  32080. this.needsDecode = false;
  32081. if (this.decode &&
  32082. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  32083. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  32084. this.needsDecode = true;
  32085. // Do some preprocessing to avoid more math.
  32086. var max = (1 << bitsPerComponent) - 1;
  32087. this.decodeCoefficients = [];
  32088. this.decodeAddends = [];
  32089. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  32090. var dmin = this.decode[i];
  32091. var dmax = this.decode[i + 1];
  32092. this.decodeCoefficients[j] = dmax - dmin;
  32093. this.decodeAddends[j] = max * dmin;
  32094. }
  32095. }
  32096. if (smask) {
  32097. this.smask = new PDFImage(xref, res, smask, false);
  32098. } else if (mask) {
  32099. if (isStream(mask)) {
  32100. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  32101. if (!imageMask) {
  32102. warn('Ignoring /Mask in image without /ImageMask.');
  32103. } else {
  32104. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  32105. }
  32106. } else {
  32107. // Color key mask (just an array).
  32108. this.mask = mask;
  32109. }
  32110. }
  32111. }
  32112. /**
  32113. * Handles processing of image data and returns the Promise that is resolved
  32114. * with a PDFImage when the image is ready to be used.
  32115. */
  32116. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  32117. res, image, inline) {
  32118. var imagePromise = handleImageData(handler, xref, res, image);
  32119. var smaskPromise;
  32120. var maskPromise;
  32121. var smask = image.dict.get('SMask');
  32122. var mask = image.dict.get('Mask');
  32123. if (smask) {
  32124. smaskPromise = handleImageData(handler, xref, res, smask);
  32125. maskPromise = Promise.resolve(null);
  32126. } else {
  32127. smaskPromise = Promise.resolve(null);
  32128. if (mask) {
  32129. if (isStream(mask)) {
  32130. maskPromise = handleImageData(handler, xref, res, mask);
  32131. } else if (isArray(mask)) {
  32132. maskPromise = Promise.resolve(mask);
  32133. } else {
  32134. warn('Unsupported mask format.');
  32135. maskPromise = Promise.resolve(null);
  32136. }
  32137. } else {
  32138. maskPromise = Promise.resolve(null);
  32139. }
  32140. }
  32141. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  32142. function(results) {
  32143. var imageData = results[0];
  32144. var smaskData = results[1];
  32145. var maskData = results[2];
  32146. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  32147. });
  32148. };
  32149. /**
  32150. * Resize an image using the nearest neighbor algorithm. Currently only
  32151. * supports one and three component images.
  32152. * @param {TypedArray} pixels The original image with one component.
  32153. * @param {Number} bpc Number of bits per component.
  32154. * @param {Number} components Number of color components, 1 or 3 is supported.
  32155. * @param {Number} w1 Original width.
  32156. * @param {Number} h1 Original height.
  32157. * @param {Number} w2 New width.
  32158. * @param {Number} h2 New height.
  32159. * @param {TypedArray} dest (Optional) The destination buffer.
  32160. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  32161. * @return {TypedArray} Resized image data.
  32162. */
  32163. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  32164. w1, h1, w2, h2, dest, alpha01) {
  32165. if (components !== 1 && components !== 3) {
  32166. error('Unsupported component count for resizing.');
  32167. }
  32168. var length = w2 * h2 * components;
  32169. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  32170. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32171. var xRatio = w1 / w2;
  32172. var yRatio = h1 / h2;
  32173. var i, j, py, newIndex = 0, oldIndex;
  32174. var xScaled = new Uint16Array(w2);
  32175. var w1Scanline = w1 * components;
  32176. if (alpha01 !== 1) {
  32177. alpha01 = 0;
  32178. }
  32179. for (j = 0; j < w2; j++) {
  32180. xScaled[j] = Math.floor(j * xRatio) * components;
  32181. }
  32182. if (components === 1) {
  32183. for (i = 0; i < h2; i++) {
  32184. py = Math.floor(i * yRatio) * w1Scanline;
  32185. for (j = 0; j < w2; j++) {
  32186. oldIndex = py + xScaled[j];
  32187. temp[newIndex++] = pixels[oldIndex];
  32188. }
  32189. }
  32190. } else if (components === 3) {
  32191. for (i = 0; i < h2; i++) {
  32192. py = Math.floor(i * yRatio) * w1Scanline;
  32193. for (j = 0; j < w2; j++) {
  32194. oldIndex = py + xScaled[j];
  32195. temp[newIndex++] = pixels[oldIndex++];
  32196. temp[newIndex++] = pixels[oldIndex++];
  32197. temp[newIndex++] = pixels[oldIndex++];
  32198. newIndex += alpha01;
  32199. }
  32200. }
  32201. }
  32202. return temp;
  32203. };
  32204. PDFImage.createMask =
  32205. function PDFImage_createMask(imgArray, width, height,
  32206. imageIsFromDecodeStream, inverseDecode) {
  32207. // |imgArray| might not contain full data for every pixel of the mask, so
  32208. // we need to distinguish between |computedLength| and |actualLength|.
  32209. // In particular, if inverseDecode is true, then the array we return must
  32210. // have a length of |computedLength|.
  32211. var computedLength = ((width + 7) >> 3) * height;
  32212. var actualLength = imgArray.byteLength;
  32213. var haveFullData = computedLength === actualLength;
  32214. var data, i;
  32215. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  32216. // imgArray came from a DecodeStream and its data is in an appropriate
  32217. // form, so we can just transfer it.
  32218. data = imgArray;
  32219. } else if (!inverseDecode) {
  32220. data = new Uint8Array(actualLength);
  32221. data.set(imgArray);
  32222. } else {
  32223. data = new Uint8Array(computedLength);
  32224. data.set(imgArray);
  32225. for (i = actualLength; i < computedLength; i++) {
  32226. data[i] = 0xff;
  32227. }
  32228. }
  32229. // If necessary, invert the original mask data (but not any extra we might
  32230. // have added above). It's safe to modify the array -- whether it's the
  32231. // original or a copy, we're about to transfer it anyway, so nothing else
  32232. // in this thread can be relying on its contents.
  32233. if (inverseDecode) {
  32234. for (i = 0; i < actualLength; i++) {
  32235. data[i] = ~data[i];
  32236. }
  32237. }
  32238. return {data: data, width: width, height: height};
  32239. };
  32240. PDFImage.prototype = {
  32241. get drawWidth() {
  32242. return Math.max(this.width,
  32243. this.smask && this.smask.width || 0,
  32244. this.mask && this.mask.width || 0);
  32245. },
  32246. get drawHeight() {
  32247. return Math.max(this.height,
  32248. this.smask && this.smask.height || 0,
  32249. this.mask && this.mask.height || 0);
  32250. },
  32251. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  32252. var bpc = this.bpc;
  32253. var numComps = this.numComps;
  32254. var decodeAddends = this.decodeAddends;
  32255. var decodeCoefficients = this.decodeCoefficients;
  32256. var max = (1 << bpc) - 1;
  32257. var i, ii;
  32258. if (bpc === 1) {
  32259. // If the buffer needed decode that means it just needs to be inverted.
  32260. for (i = 0, ii = buffer.length; i < ii; i++) {
  32261. buffer[i] = +!(buffer[i]);
  32262. }
  32263. return;
  32264. }
  32265. var index = 0;
  32266. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  32267. for (var j = 0; j < numComps; j++) {
  32268. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  32269. decodeCoefficients[j], max);
  32270. index++;
  32271. }
  32272. }
  32273. },
  32274. getComponents: function PDFImage_getComponents(buffer) {
  32275. var bpc = this.bpc;
  32276. // This image doesn't require any extra work.
  32277. if (bpc === 8) {
  32278. return buffer;
  32279. }
  32280. var width = this.width;
  32281. var height = this.height;
  32282. var numComps = this.numComps;
  32283. var length = width * height * numComps;
  32284. var bufferPos = 0;
  32285. var output = (bpc <= 8 ? new Uint8Array(length) :
  32286. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  32287. var rowComps = width * numComps;
  32288. var max = (1 << bpc) - 1;
  32289. var i = 0, ii, buf;
  32290. if (bpc === 1) {
  32291. // Optimization for reading 1 bpc images.
  32292. var mask, loop1End, loop2End;
  32293. for (var j = 0; j < height; j++) {
  32294. loop1End = i + (rowComps & ~7);
  32295. loop2End = i + rowComps;
  32296. // unroll loop for all full bytes
  32297. while (i < loop1End) {
  32298. buf = buffer[bufferPos++];
  32299. output[i] = (buf >> 7) & 1;
  32300. output[i + 1] = (buf >> 6) & 1;
  32301. output[i + 2] = (buf >> 5) & 1;
  32302. output[i + 3] = (buf >> 4) & 1;
  32303. output[i + 4] = (buf >> 3) & 1;
  32304. output[i + 5] = (buf >> 2) & 1;
  32305. output[i + 6] = (buf >> 1) & 1;
  32306. output[i + 7] = buf & 1;
  32307. i += 8;
  32308. }
  32309. // handle remaing bits
  32310. if (i < loop2End) {
  32311. buf = buffer[bufferPos++];
  32312. mask = 128;
  32313. while (i < loop2End) {
  32314. output[i++] = +!!(buf & mask);
  32315. mask >>= 1;
  32316. }
  32317. }
  32318. }
  32319. } else {
  32320. // The general case that handles all other bpc values.
  32321. var bits = 0;
  32322. buf = 0;
  32323. for (i = 0, ii = length; i < ii; ++i) {
  32324. if (i % rowComps === 0) {
  32325. buf = 0;
  32326. bits = 0;
  32327. }
  32328. while (bits < bpc) {
  32329. buf = (buf << 8) | buffer[bufferPos++];
  32330. bits += 8;
  32331. }
  32332. var remainingBits = bits - bpc;
  32333. var value = buf >> remainingBits;
  32334. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  32335. buf = buf & ((1 << remainingBits) - 1);
  32336. bits = remainingBits;
  32337. }
  32338. }
  32339. return output;
  32340. },
  32341. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  32342. actualHeight, image) {
  32343. var smask = this.smask;
  32344. var mask = this.mask;
  32345. var alphaBuf, sw, sh, i, ii, j;
  32346. if (smask) {
  32347. sw = smask.width;
  32348. sh = smask.height;
  32349. alphaBuf = new Uint8Array(sw * sh);
  32350. smask.fillGrayBuffer(alphaBuf);
  32351. if (sw !== width || sh !== height) {
  32352. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  32353. height);
  32354. }
  32355. } else if (mask) {
  32356. if (mask instanceof PDFImage) {
  32357. sw = mask.width;
  32358. sh = mask.height;
  32359. alphaBuf = new Uint8Array(sw * sh);
  32360. mask.numComps = 1;
  32361. mask.fillGrayBuffer(alphaBuf);
  32362. // Need to invert values in rgbaBuf
  32363. for (i = 0, ii = sw * sh; i < ii; ++i) {
  32364. alphaBuf[i] = 255 - alphaBuf[i];
  32365. }
  32366. if (sw !== width || sh !== height) {
  32367. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  32368. height);
  32369. }
  32370. } else if (isArray(mask)) {
  32371. // Color key mask: if any of the compontents are outside the range
  32372. // then they should be painted.
  32373. alphaBuf = new Uint8Array(width * height);
  32374. var numComps = this.numComps;
  32375. for (i = 0, ii = width * height; i < ii; ++i) {
  32376. var opacity = 0;
  32377. var imageOffset = i * numComps;
  32378. for (j = 0; j < numComps; ++j) {
  32379. var color = image[imageOffset + j];
  32380. var maskOffset = j * 2;
  32381. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  32382. opacity = 255;
  32383. break;
  32384. }
  32385. }
  32386. alphaBuf[i] = opacity;
  32387. }
  32388. } else {
  32389. error('Unknown mask format.');
  32390. }
  32391. }
  32392. if (alphaBuf) {
  32393. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32394. rgbaBuf[j] = alphaBuf[i];
  32395. }
  32396. } else {
  32397. // No mask.
  32398. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  32399. rgbaBuf[j] = 255;
  32400. }
  32401. }
  32402. },
  32403. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  32404. var matte = this.smask && this.smask.matte;
  32405. if (!matte) {
  32406. return;
  32407. }
  32408. var matteRgb = this.colorSpace.getRgb(matte, 0);
  32409. var matteR = matteRgb[0];
  32410. var matteG = matteRgb[1];
  32411. var matteB = matteRgb[2];
  32412. var length = width * height * 4;
  32413. var r, g, b;
  32414. for (var i = 0; i < length; i += 4) {
  32415. var alpha = buffer[i + 3];
  32416. if (alpha === 0) {
  32417. // according formula we have to get Infinity in all components
  32418. // making it white (typical paper color) should be okay
  32419. buffer[i] = 255;
  32420. buffer[i + 1] = 255;
  32421. buffer[i + 2] = 255;
  32422. continue;
  32423. }
  32424. var k = 255 / alpha;
  32425. r = (buffer[i] - matteR) * k + matteR;
  32426. g = (buffer[i + 1] - matteG) * k + matteG;
  32427. b = (buffer[i + 2] - matteB) * k + matteB;
  32428. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  32429. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  32430. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  32431. }
  32432. },
  32433. createImageData: function PDFImage_createImageData(forceRGBA) {
  32434. var drawWidth = this.drawWidth;
  32435. var drawHeight = this.drawHeight;
  32436. var imgData = { // other fields are filled in below
  32437. width: drawWidth,
  32438. height: drawHeight
  32439. };
  32440. var numComps = this.numComps;
  32441. var originalWidth = this.width;
  32442. var originalHeight = this.height;
  32443. var bpc = this.bpc;
  32444. // Rows start at byte boundary.
  32445. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  32446. var imgArray;
  32447. if (!forceRGBA) {
  32448. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  32449. // without any complications, we pass a same-sized copy to the main
  32450. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  32451. // of memory for many scanned documents. It's also much faster.
  32452. //
  32453. // Similarly, if it is a 24-bit-per pixel RGB image without any
  32454. // complications, we avoid expanding by 1.333x to RGBA form.
  32455. var kind;
  32456. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  32457. kind = ImageKind.GRAYSCALE_1BPP;
  32458. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  32459. !this.needsDecode) {
  32460. kind = ImageKind.RGB_24BPP;
  32461. }
  32462. if (kind && !this.smask && !this.mask &&
  32463. drawWidth === originalWidth && drawHeight === originalHeight) {
  32464. imgData.kind = kind;
  32465. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32466. // If imgArray came from a DecodeStream, we're safe to transfer it
  32467. // (and thus detach its underlying buffer) because it will constitute
  32468. // the entire DecodeStream's data. But if it came from a Stream, we
  32469. // need to copy it because it'll only be a portion of the Stream's
  32470. // data, and the rest will be read later on.
  32471. if (this.image instanceof DecodeStream) {
  32472. imgData.data = imgArray;
  32473. } else {
  32474. var newArray = new Uint8Array(imgArray.length);
  32475. newArray.set(imgArray);
  32476. imgData.data = newArray;
  32477. }
  32478. if (this.needsDecode) {
  32479. // Invert the buffer (which must be grayscale if we reached here).
  32480. assert(kind === ImageKind.GRAYSCALE_1BPP);
  32481. var buffer = imgData.data;
  32482. for (var i = 0, ii = buffer.length; i < ii; i++) {
  32483. buffer[i] ^= 0xff;
  32484. }
  32485. }
  32486. return imgData;
  32487. }
  32488. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  32489. (this.colorSpace.name === 'DeviceGray' ||
  32490. this.colorSpace.name === 'DeviceRGB' ||
  32491. this.colorSpace.name === 'DeviceCMYK')) {
  32492. imgData.kind = ImageKind.RGB_24BPP;
  32493. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  32494. drawWidth, drawHeight, true);
  32495. return imgData;
  32496. }
  32497. }
  32498. imgArray = this.getImageBytes(originalHeight * rowBytes);
  32499. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  32500. var actualHeight = 0 | (imgArray.length / rowBytes *
  32501. drawHeight / originalHeight);
  32502. var comps = this.getComponents(imgArray);
  32503. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  32504. // more compact RGB_24BPP form if allowable.
  32505. var alpha01, maybeUndoPreblend;
  32506. if (!forceRGBA && !this.smask && !this.mask) {
  32507. imgData.kind = ImageKind.RGB_24BPP;
  32508. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  32509. alpha01 = 0;
  32510. maybeUndoPreblend = false;
  32511. } else {
  32512. imgData.kind = ImageKind.RGBA_32BPP;
  32513. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  32514. alpha01 = 1;
  32515. maybeUndoPreblend = true;
  32516. // Color key masking (opacity) must be performed before decoding.
  32517. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  32518. comps);
  32519. }
  32520. if (this.needsDecode) {
  32521. this.decodeBuffer(comps);
  32522. }
  32523. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  32524. drawWidth, drawHeight, actualHeight, bpc, comps,
  32525. alpha01);
  32526. if (maybeUndoPreblend) {
  32527. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  32528. }
  32529. return imgData;
  32530. },
  32531. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  32532. var numComps = this.numComps;
  32533. if (numComps !== 1) {
  32534. error('Reading gray scale from a color image: ' + numComps);
  32535. }
  32536. var width = this.width;
  32537. var height = this.height;
  32538. var bpc = this.bpc;
  32539. // rows start at byte boundary
  32540. var rowBytes = (width * numComps * bpc + 7) >> 3;
  32541. var imgArray = this.getImageBytes(height * rowBytes);
  32542. var comps = this.getComponents(imgArray);
  32543. var i, length;
  32544. if (bpc === 1) {
  32545. // inline decoding (= inversion) for 1 bpc images
  32546. length = width * height;
  32547. if (this.needsDecode) {
  32548. // invert and scale to {0, 255}
  32549. for (i = 0; i < length; ++i) {
  32550. buffer[i] = (comps[i] - 1) & 255;
  32551. }
  32552. } else {
  32553. // scale to {0, 255}
  32554. for (i = 0; i < length; ++i) {
  32555. buffer[i] = (-comps[i]) & 255;
  32556. }
  32557. }
  32558. return;
  32559. }
  32560. if (this.needsDecode) {
  32561. this.decodeBuffer(comps);
  32562. }
  32563. length = width * height;
  32564. // we aren't using a colorspace so we need to scale the value
  32565. var scale = 255 / ((1 << bpc) - 1);
  32566. for (i = 0; i < length; ++i) {
  32567. buffer[i] = (scale * comps[i]) | 0;
  32568. }
  32569. },
  32570. getImageBytes: function PDFImage_getImageBytes(length,
  32571. drawWidth, drawHeight,
  32572. forceRGB) {
  32573. this.image.reset();
  32574. this.image.drawWidth = drawWidth || this.width;
  32575. this.image.drawHeight = drawHeight || this.height;
  32576. this.image.forceRGB = !!forceRGB;
  32577. return this.image.getBytes(length);
  32578. }
  32579. };
  32580. return PDFImage;
  32581. })();
  32582. exports.PDFImage = PDFImage;
  32583. // TODO refactor to remove dependency on colorspace.js
  32584. coreColorSpace._setCoreImage(exports);
  32585. }));
  32586. (function (root, factory) {
  32587. {
  32588. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  32589. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  32590. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  32591. }
  32592. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  32593. coreChunkedStream, coreColorSpace) {
  32594. var InvalidPDFException = sharedUtil.InvalidPDFException;
  32595. var MissingDataException = sharedUtil.MissingDataException;
  32596. var XRefParseException = sharedUtil.XRefParseException;
  32597. var assert = sharedUtil.assert;
  32598. var bytesToString = sharedUtil.bytesToString;
  32599. var createPromiseCapability = sharedUtil.createPromiseCapability;
  32600. var error = sharedUtil.error;
  32601. var info = sharedUtil.info;
  32602. var isArray = sharedUtil.isArray;
  32603. var isInt = sharedUtil.isInt;
  32604. var isString = sharedUtil.isString;
  32605. var shadow = sharedUtil.shadow;
  32606. var stringToPDFString = sharedUtil.stringToPDFString;
  32607. var stringToUTF8String = sharedUtil.stringToUTF8String;
  32608. var warn = sharedUtil.warn;
  32609. var isValidUrl = sharedUtil.isValidUrl;
  32610. var Util = sharedUtil.Util;
  32611. var Ref = corePrimitives.Ref;
  32612. var RefSet = corePrimitives.RefSet;
  32613. var RefSetCache = corePrimitives.RefSetCache;
  32614. var isName = corePrimitives.isName;
  32615. var isCmd = corePrimitives.isCmd;
  32616. var isDict = corePrimitives.isDict;
  32617. var isRef = corePrimitives.isRef;
  32618. var isStream = corePrimitives.isStream;
  32619. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  32620. var Lexer = coreParser.Lexer;
  32621. var Parser = coreParser.Parser;
  32622. var ChunkedStream = coreChunkedStream.ChunkedStream;
  32623. var ColorSpace = coreColorSpace.ColorSpace;
  32624. var Catalog = (function CatalogClosure() {
  32625. function Catalog(pdfManager, xref, pageFactory) {
  32626. this.pdfManager = pdfManager;
  32627. this.xref = xref;
  32628. this.catDict = xref.getCatalogObj();
  32629. this.fontCache = new RefSetCache();
  32630. assert(isDict(this.catDict),
  32631. 'catalog object is not a dictionary');
  32632. // TODO refactor to move getPage() to the PDFDocument.
  32633. this.pageFactory = pageFactory;
  32634. this.pagePromises = [];
  32635. }
  32636. Catalog.prototype = {
  32637. get metadata() {
  32638. var streamRef = this.catDict.getRaw('Metadata');
  32639. if (!isRef(streamRef)) {
  32640. return shadow(this, 'metadata', null);
  32641. }
  32642. var encryptMetadata = (!this.xref.encrypt ? false :
  32643. this.xref.encrypt.encryptMetadata);
  32644. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  32645. var metadata;
  32646. if (stream && isDict(stream.dict)) {
  32647. var type = stream.dict.get('Type');
  32648. var subtype = stream.dict.get('Subtype');
  32649. if (isName(type) && isName(subtype) &&
  32650. type.name === 'Metadata' && subtype.name === 'XML') {
  32651. // XXX: This should examine the charset the XML document defines,
  32652. // however since there are currently no real means to decode
  32653. // arbitrary charsets, let's just hope that the author of the PDF
  32654. // was reasonable enough to stick with the XML default charset,
  32655. // which is UTF-8.
  32656. try {
  32657. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  32658. } catch (e) {
  32659. info('Skipping invalid metadata.');
  32660. }
  32661. }
  32662. }
  32663. return shadow(this, 'metadata', metadata);
  32664. },
  32665. get toplevelPagesDict() {
  32666. var pagesObj = this.catDict.get('Pages');
  32667. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  32668. // shadow the prototype getter
  32669. return shadow(this, 'toplevelPagesDict', pagesObj);
  32670. },
  32671. get documentOutline() {
  32672. var obj = null;
  32673. try {
  32674. obj = this.readDocumentOutline();
  32675. } catch (ex) {
  32676. if (ex instanceof MissingDataException) {
  32677. throw ex;
  32678. }
  32679. warn('Unable to read document outline');
  32680. }
  32681. return shadow(this, 'documentOutline', obj);
  32682. },
  32683. readDocumentOutline: function Catalog_readDocumentOutline() {
  32684. var obj = this.catDict.get('Outlines');
  32685. if (!isDict(obj)) {
  32686. return null;
  32687. }
  32688. obj = obj.getRaw('First');
  32689. if (!isRef(obj)) {
  32690. return null;
  32691. }
  32692. var root = { items: [] };
  32693. var queue = [{obj: obj, parent: root}];
  32694. // To avoid recursion, keep track of the already processed items.
  32695. var processed = new RefSet();
  32696. processed.put(obj);
  32697. var xref = this.xref, blackColor = new Uint8Array(3);
  32698. while (queue.length > 0) {
  32699. var i = queue.shift();
  32700. var outlineDict = xref.fetchIfRef(i.obj);
  32701. if (outlineDict === null) {
  32702. continue;
  32703. }
  32704. assert(outlineDict.has('Title'), 'Invalid outline item');
  32705. var actionDict = outlineDict.get('A'), dest = null, url = null;
  32706. if (actionDict) {
  32707. var destEntry = actionDict.get('D');
  32708. if (destEntry) {
  32709. dest = destEntry;
  32710. } else {
  32711. var uriEntry = actionDict.get('URI');
  32712. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  32713. url = uriEntry;
  32714. }
  32715. }
  32716. } else if (outlineDict.has('Dest')) {
  32717. dest = outlineDict.getRaw('Dest');
  32718. if (isName(dest)) {
  32719. dest = dest.name;
  32720. }
  32721. }
  32722. var title = outlineDict.get('Title');
  32723. var flags = outlineDict.get('F') || 0;
  32724. var color = outlineDict.get('C'), rgbColor = blackColor;
  32725. // We only need to parse the color when it's valid, and non-default.
  32726. if (isArray(color) && color.length === 3 &&
  32727. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  32728. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  32729. }
  32730. var outlineItem = {
  32731. dest: dest,
  32732. url: url,
  32733. title: stringToPDFString(title),
  32734. color: rgbColor,
  32735. count: outlineDict.get('Count'),
  32736. bold: !!(flags & 2),
  32737. italic: !!(flags & 1),
  32738. items: []
  32739. };
  32740. i.parent.items.push(outlineItem);
  32741. obj = outlineDict.getRaw('First');
  32742. if (isRef(obj) && !processed.has(obj)) {
  32743. queue.push({obj: obj, parent: outlineItem});
  32744. processed.put(obj);
  32745. }
  32746. obj = outlineDict.getRaw('Next');
  32747. if (isRef(obj) && !processed.has(obj)) {
  32748. queue.push({obj: obj, parent: i.parent});
  32749. processed.put(obj);
  32750. }
  32751. }
  32752. return (root.items.length > 0 ? root.items : null);
  32753. },
  32754. get numPages() {
  32755. var obj = this.toplevelPagesDict.get('Count');
  32756. assert(
  32757. isInt(obj),
  32758. 'page count in top level pages object is not an integer'
  32759. );
  32760. // shadow the prototype getter
  32761. return shadow(this, 'num', obj);
  32762. },
  32763. get destinations() {
  32764. function fetchDestination(dest) {
  32765. return isDict(dest) ? dest.get('D') : dest;
  32766. }
  32767. var xref = this.xref;
  32768. var dests = {}, nameTreeRef, nameDictionaryRef;
  32769. var obj = this.catDict.get('Names');
  32770. if (obj && obj.has('Dests')) {
  32771. nameTreeRef = obj.getRaw('Dests');
  32772. } else if (this.catDict.has('Dests')) {
  32773. nameDictionaryRef = this.catDict.get('Dests');
  32774. }
  32775. if (nameDictionaryRef) {
  32776. // reading simple destination dictionary
  32777. obj = nameDictionaryRef;
  32778. obj.forEach(function catalogForEach(key, value) {
  32779. if (!value) {
  32780. return;
  32781. }
  32782. dests[key] = fetchDestination(value);
  32783. });
  32784. }
  32785. if (nameTreeRef) {
  32786. var nameTree = new NameTree(nameTreeRef, xref);
  32787. var names = nameTree.getAll();
  32788. for (var name in names) {
  32789. dests[name] = fetchDestination(names[name]);
  32790. }
  32791. }
  32792. return shadow(this, 'destinations', dests);
  32793. },
  32794. getDestination: function Catalog_getDestination(destinationId) {
  32795. function fetchDestination(dest) {
  32796. return isDict(dest) ? dest.get('D') : dest;
  32797. }
  32798. var xref = this.xref;
  32799. var dest = null, nameTreeRef, nameDictionaryRef;
  32800. var obj = this.catDict.get('Names');
  32801. if (obj && obj.has('Dests')) {
  32802. nameTreeRef = obj.getRaw('Dests');
  32803. } else if (this.catDict.has('Dests')) {
  32804. nameDictionaryRef = this.catDict.get('Dests');
  32805. }
  32806. if (nameDictionaryRef) { // Simple destination dictionary.
  32807. var value = nameDictionaryRef.get(destinationId);
  32808. if (value) {
  32809. dest = fetchDestination(value);
  32810. }
  32811. }
  32812. if (nameTreeRef) {
  32813. var nameTree = new NameTree(nameTreeRef, xref);
  32814. dest = fetchDestination(nameTree.get(destinationId));
  32815. }
  32816. return dest;
  32817. },
  32818. get pageLabels() {
  32819. var obj = null;
  32820. try {
  32821. obj = this.readPageLabels();
  32822. } catch (ex) {
  32823. if (ex instanceof MissingDataException) {
  32824. throw ex;
  32825. }
  32826. warn('Unable to read page labels.');
  32827. }
  32828. return shadow(this, 'pageLabels', obj);
  32829. },
  32830. readPageLabels: function Catalog_readPageLabels() {
  32831. var obj = this.catDict.getRaw('PageLabels');
  32832. if (!obj) {
  32833. return null;
  32834. }
  32835. var pageLabels = new Array(this.numPages);
  32836. var style = null;
  32837. var prefix = '';
  32838. var start = 1;
  32839. var numberTree = new NumberTree(obj, this.xref);
  32840. var nums = numberTree.getAll();
  32841. var currentLabel = '', currentIndex = 1;
  32842. for (var i = 0, ii = this.numPages; i < ii; i++) {
  32843. if (i in nums) {
  32844. var labelDict = nums[i];
  32845. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  32846. var type = labelDict.get('Type');
  32847. assert(!type || (isName(type) && type.name === 'PageLabel'),
  32848. 'Invalid type in PageLabel dictionary.');
  32849. var s = labelDict.get('S');
  32850. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  32851. style = (s ? s.name : null);
  32852. prefix = labelDict.get('P') || '';
  32853. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  32854. start = labelDict.get('St') || 1;
  32855. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  32856. currentIndex = start;
  32857. }
  32858. switch (style) {
  32859. case 'D':
  32860. currentLabel = currentIndex;
  32861. break;
  32862. case 'R':
  32863. case 'r':
  32864. currentLabel = Util.toRoman(currentIndex, style === 'r');
  32865. break;
  32866. case 'A':
  32867. case 'a':
  32868. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  32869. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  32870. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  32871. var letterIndex = currentIndex - 1;
  32872. var character = String.fromCharCode(baseCharCode +
  32873. (letterIndex % LIMIT));
  32874. var charBuf = [];
  32875. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  32876. charBuf.push(character);
  32877. }
  32878. currentLabel = charBuf.join('');
  32879. break;
  32880. default:
  32881. assert(!style,
  32882. 'Invalid style "' + style + '" in PageLabel dictionary.');
  32883. }
  32884. pageLabels[i] = prefix + currentLabel;
  32885. currentLabel = '';
  32886. currentIndex++;
  32887. }
  32888. return pageLabels;
  32889. },
  32890. get attachments() {
  32891. var xref = this.xref;
  32892. var attachments = null, nameTreeRef;
  32893. var obj = this.catDict.get('Names');
  32894. if (obj) {
  32895. nameTreeRef = obj.getRaw('EmbeddedFiles');
  32896. }
  32897. if (nameTreeRef) {
  32898. var nameTree = new NameTree(nameTreeRef, xref);
  32899. var names = nameTree.getAll();
  32900. for (var name in names) {
  32901. var fs = new FileSpec(names[name], xref);
  32902. if (!attachments) {
  32903. attachments = Object.create(null);
  32904. }
  32905. attachments[stringToPDFString(name)] = fs.serializable;
  32906. }
  32907. }
  32908. return shadow(this, 'attachments', attachments);
  32909. },
  32910. get javaScript() {
  32911. var xref = this.xref;
  32912. var obj = this.catDict.get('Names');
  32913. var javaScript = [];
  32914. function appendIfJavaScriptDict(jsDict) {
  32915. var type = jsDict.get('S');
  32916. if (!isName(type) || type.name !== 'JavaScript') {
  32917. return;
  32918. }
  32919. var js = jsDict.get('JS');
  32920. if (isStream(js)) {
  32921. js = bytesToString(js.getBytes());
  32922. } else if (!isString(js)) {
  32923. return;
  32924. }
  32925. javaScript.push(stringToPDFString(js));
  32926. }
  32927. if (obj && obj.has('JavaScript')) {
  32928. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  32929. var names = nameTree.getAll();
  32930. for (var name in names) {
  32931. // We don't really use the JavaScript right now. This code is
  32932. // defensive so we don't cause errors on document load.
  32933. var jsDict = names[name];
  32934. if (isDict(jsDict)) {
  32935. appendIfJavaScriptDict(jsDict);
  32936. }
  32937. }
  32938. }
  32939. // Append OpenAction actions to javaScript array
  32940. var openactionDict = this.catDict.get('OpenAction');
  32941. if (isDict(openactionDict, 'Action')) {
  32942. var actionType = openactionDict.get('S');
  32943. if (isName(actionType) && actionType.name === 'Named') {
  32944. // The named Print action is not a part of the PDF 1.7 specification,
  32945. // but is supported by many PDF readers/writers (including Adobe's).
  32946. var action = openactionDict.get('N');
  32947. if (isName(action) && action.name === 'Print') {
  32948. javaScript.push('print({});');
  32949. }
  32950. } else {
  32951. appendIfJavaScriptDict(openactionDict);
  32952. }
  32953. }
  32954. return shadow(this, 'javaScript', javaScript);
  32955. },
  32956. cleanup: function Catalog_cleanup() {
  32957. var promises = [];
  32958. this.fontCache.forEach(function (promise) {
  32959. promises.push(promise);
  32960. });
  32961. return Promise.all(promises).then(function (translatedFonts) {
  32962. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  32963. var font = translatedFonts[i].dict;
  32964. delete font.translated;
  32965. }
  32966. this.fontCache.clear();
  32967. }.bind(this));
  32968. },
  32969. getPage: function Catalog_getPage(pageIndex) {
  32970. if (!(pageIndex in this.pagePromises)) {
  32971. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  32972. function (a) {
  32973. var dict = a[0];
  32974. var ref = a[1];
  32975. return this.pageFactory.createPage(pageIndex, dict, ref,
  32976. this.fontCache);
  32977. }.bind(this)
  32978. );
  32979. }
  32980. return this.pagePromises[pageIndex];
  32981. },
  32982. getPageDict: function Catalog_getPageDict(pageIndex) {
  32983. var capability = createPromiseCapability();
  32984. var nodesToVisit = [this.catDict.getRaw('Pages')];
  32985. var currentPageIndex = 0;
  32986. var xref = this.xref;
  32987. var checkAllKids = false;
  32988. function next() {
  32989. while (nodesToVisit.length) {
  32990. var currentNode = nodesToVisit.pop();
  32991. if (isRef(currentNode)) {
  32992. xref.fetchAsync(currentNode).then(function (obj) {
  32993. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  32994. if (pageIndex === currentPageIndex) {
  32995. capability.resolve([obj, currentNode]);
  32996. } else {
  32997. currentPageIndex++;
  32998. next();
  32999. }
  33000. return;
  33001. }
  33002. nodesToVisit.push(obj);
  33003. next();
  33004. }, capability.reject);
  33005. return;
  33006. }
  33007. // Must be a child page dictionary.
  33008. assert(
  33009. isDict(currentNode),
  33010. 'page dictionary kid reference points to wrong type of object'
  33011. );
  33012. var count = currentNode.get('Count');
  33013. // If the current node doesn't have any children, avoid getting stuck
  33014. // in an empty node further down in the tree (see issue5644.pdf).
  33015. if (count === 0) {
  33016. checkAllKids = true;
  33017. }
  33018. // Skip nodes where the page can't be.
  33019. if (currentPageIndex + count <= pageIndex) {
  33020. currentPageIndex += count;
  33021. continue;
  33022. }
  33023. var kids = currentNode.get('Kids');
  33024. assert(isArray(kids), 'page dictionary kids object is not an array');
  33025. if (!checkAllKids && count === kids.length) {
  33026. // Nodes that don't have the page have been skipped and this is the
  33027. // bottom of the tree which means the page requested must be a
  33028. // descendant of this pages node. Ideally we would just resolve the
  33029. // promise with the page ref here, but there is the case where more
  33030. // pages nodes could link to single a page (see issue 3666 pdf). To
  33031. // handle this push it back on the queue so if it is a pages node it
  33032. // will be descended into.
  33033. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  33034. currentPageIndex = pageIndex;
  33035. continue;
  33036. } else {
  33037. for (var last = kids.length - 1; last >= 0; last--) {
  33038. nodesToVisit.push(kids[last]);
  33039. }
  33040. }
  33041. }
  33042. capability.reject('Page index ' + pageIndex + ' not found.');
  33043. }
  33044. next();
  33045. return capability.promise;
  33046. },
  33047. getPageIndex: function Catalog_getPageIndex(ref) {
  33048. // The page tree nodes have the count of all the leaves below them. To get
  33049. // how many pages are before we just have to walk up the tree and keep
  33050. // adding the count of siblings to the left of the node.
  33051. var xref = this.xref;
  33052. function pagesBeforeRef(kidRef) {
  33053. var total = 0;
  33054. var parentRef;
  33055. return xref.fetchAsync(kidRef).then(function (node) {
  33056. if (!node) {
  33057. return null;
  33058. }
  33059. parentRef = node.getRaw('Parent');
  33060. return node.getAsync('Parent');
  33061. }).then(function (parent) {
  33062. if (!parent) {
  33063. return null;
  33064. }
  33065. return parent.getAsync('Kids');
  33066. }).then(function (kids) {
  33067. if (!kids) {
  33068. return null;
  33069. }
  33070. var kidPromises = [];
  33071. var found = false;
  33072. for (var i = 0; i < kids.length; i++) {
  33073. var kid = kids[i];
  33074. assert(isRef(kid), 'kids must be a ref');
  33075. if (kid.num === kidRef.num) {
  33076. found = true;
  33077. break;
  33078. }
  33079. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  33080. if (kid.has('Count')) {
  33081. var count = kid.get('Count');
  33082. total += count;
  33083. } else { // page leaf node
  33084. total++;
  33085. }
  33086. }));
  33087. }
  33088. if (!found) {
  33089. error('kid ref not found in parents kids');
  33090. }
  33091. return Promise.all(kidPromises).then(function () {
  33092. return [total, parentRef];
  33093. });
  33094. });
  33095. }
  33096. var total = 0;
  33097. function next(ref) {
  33098. return pagesBeforeRef(ref).then(function (args) {
  33099. if (!args) {
  33100. return total;
  33101. }
  33102. var count = args[0];
  33103. var parentRef = args[1];
  33104. total += count;
  33105. return next(parentRef);
  33106. });
  33107. }
  33108. return next(ref);
  33109. }
  33110. };
  33111. return Catalog;
  33112. })();
  33113. var XRef = (function XRefClosure() {
  33114. function XRef(stream, password) {
  33115. this.stream = stream;
  33116. this.entries = [];
  33117. this.xrefstms = Object.create(null);
  33118. // prepare the XRef cache
  33119. this.cache = [];
  33120. this.password = password;
  33121. this.stats = {
  33122. streamTypes: [],
  33123. fontTypes: []
  33124. };
  33125. }
  33126. XRef.prototype = {
  33127. setStartXRef: function XRef_setStartXRef(startXRef) {
  33128. // Store the starting positions of xref tables as we process them
  33129. // so we can recover from missing data errors
  33130. this.startXRefQueue = [startXRef];
  33131. },
  33132. parse: function XRef_parse(recoveryMode) {
  33133. var trailerDict;
  33134. if (!recoveryMode) {
  33135. trailerDict = this.readXRef();
  33136. } else {
  33137. warn('Indexing all PDF objects');
  33138. trailerDict = this.indexObjects();
  33139. }
  33140. trailerDict.assignXref(this);
  33141. this.trailer = trailerDict;
  33142. var encrypt = trailerDict.get('Encrypt');
  33143. if (encrypt) {
  33144. var ids = trailerDict.get('ID');
  33145. var fileId = (ids && ids.length) ? ids[0] : '';
  33146. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  33147. this.password);
  33148. }
  33149. // get the root dictionary (catalog) object
  33150. if (!(this.root = trailerDict.get('Root'))) {
  33151. error('Invalid root reference');
  33152. }
  33153. },
  33154. processXRefTable: function XRef_processXRefTable(parser) {
  33155. if (!('tableState' in this)) {
  33156. // Stores state of the table as we process it so we can resume
  33157. // from middle of table in case of missing data error
  33158. this.tableState = {
  33159. entryNum: 0,
  33160. streamPos: parser.lexer.stream.pos,
  33161. parserBuf1: parser.buf1,
  33162. parserBuf2: parser.buf2
  33163. };
  33164. }
  33165. var obj = this.readXRefTable(parser);
  33166. // Sanity check
  33167. if (!isCmd(obj, 'trailer')) {
  33168. error('Invalid XRef table: could not find trailer dictionary');
  33169. }
  33170. // Read trailer dictionary, e.g.
  33171. // trailer
  33172. // << /Size 22
  33173. // /Root 20R
  33174. // /Info 10R
  33175. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  33176. // >>
  33177. // The parser goes through the entire stream << ... >> and provides
  33178. // a getter interface for the key-value table
  33179. var dict = parser.getObj();
  33180. // The pdflib PDF generator can generate a nested trailer dictionary
  33181. if (!isDict(dict) && dict.dict) {
  33182. dict = dict.dict;
  33183. }
  33184. if (!isDict(dict)) {
  33185. error('Invalid XRef table: could not parse trailer dictionary');
  33186. }
  33187. delete this.tableState;
  33188. return dict;
  33189. },
  33190. readXRefTable: function XRef_readXRefTable(parser) {
  33191. // Example of cross-reference table:
  33192. // xref
  33193. // 0 1 <-- subsection header (first obj #, obj count)
  33194. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  33195. // 23 2 <-- subsection header ... and so on ...
  33196. // 0000025518 00002 n
  33197. // 0000025635 00000 n
  33198. // trailer
  33199. // ...
  33200. var stream = parser.lexer.stream;
  33201. var tableState = this.tableState;
  33202. stream.pos = tableState.streamPos;
  33203. parser.buf1 = tableState.parserBuf1;
  33204. parser.buf2 = tableState.parserBuf2;
  33205. // Outer loop is over subsection headers
  33206. var obj;
  33207. while (true) {
  33208. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  33209. if (isCmd(obj = parser.getObj(), 'trailer')) {
  33210. break;
  33211. }
  33212. tableState.firstEntryNum = obj;
  33213. tableState.entryCount = parser.getObj();
  33214. }
  33215. var first = tableState.firstEntryNum;
  33216. var count = tableState.entryCount;
  33217. if (!isInt(first) || !isInt(count)) {
  33218. error('Invalid XRef table: wrong types in subsection header');
  33219. }
  33220. // Inner loop is over objects themselves
  33221. for (var i = tableState.entryNum; i < count; i++) {
  33222. tableState.streamPos = stream.pos;
  33223. tableState.entryNum = i;
  33224. tableState.parserBuf1 = parser.buf1;
  33225. tableState.parserBuf2 = parser.buf2;
  33226. var entry = {};
  33227. entry.offset = parser.getObj();
  33228. entry.gen = parser.getObj();
  33229. var type = parser.getObj();
  33230. if (isCmd(type, 'f')) {
  33231. entry.free = true;
  33232. } else if (isCmd(type, 'n')) {
  33233. entry.uncompressed = true;
  33234. }
  33235. // Validate entry obj
  33236. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  33237. !(entry.free || entry.uncompressed)) {
  33238. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  33239. }
  33240. if (!this.entries[i + first]) {
  33241. this.entries[i + first] = entry;
  33242. }
  33243. }
  33244. tableState.entryNum = 0;
  33245. tableState.streamPos = stream.pos;
  33246. tableState.parserBuf1 = parser.buf1;
  33247. tableState.parserBuf2 = parser.buf2;
  33248. delete tableState.firstEntryNum;
  33249. delete tableState.entryCount;
  33250. }
  33251. // Per issue 3248: hp scanners generate bad XRef
  33252. if (first === 1 && this.entries[1] && this.entries[1].free) {
  33253. // shifting the entries
  33254. this.entries.shift();
  33255. }
  33256. // Sanity check: as per spec, first object must be free
  33257. if (this.entries[0] && !this.entries[0].free) {
  33258. error('Invalid XRef table: unexpected first object');
  33259. }
  33260. return obj;
  33261. },
  33262. processXRefStream: function XRef_processXRefStream(stream) {
  33263. if (!('streamState' in this)) {
  33264. // Stores state of the stream as we process it so we can resume
  33265. // from middle of stream in case of missing data error
  33266. var streamParameters = stream.dict;
  33267. var byteWidths = streamParameters.get('W');
  33268. var range = streamParameters.get('Index');
  33269. if (!range) {
  33270. range = [0, streamParameters.get('Size')];
  33271. }
  33272. this.streamState = {
  33273. entryRanges: range,
  33274. byteWidths: byteWidths,
  33275. entryNum: 0,
  33276. streamPos: stream.pos
  33277. };
  33278. }
  33279. this.readXRefStream(stream);
  33280. delete this.streamState;
  33281. return stream.dict;
  33282. },
  33283. readXRefStream: function XRef_readXRefStream(stream) {
  33284. var i, j;
  33285. var streamState = this.streamState;
  33286. stream.pos = streamState.streamPos;
  33287. var byteWidths = streamState.byteWidths;
  33288. var typeFieldWidth = byteWidths[0];
  33289. var offsetFieldWidth = byteWidths[1];
  33290. var generationFieldWidth = byteWidths[2];
  33291. var entryRanges = streamState.entryRanges;
  33292. while (entryRanges.length > 0) {
  33293. var first = entryRanges[0];
  33294. var n = entryRanges[1];
  33295. if (!isInt(first) || !isInt(n)) {
  33296. error('Invalid XRef range fields: ' + first + ', ' + n);
  33297. }
  33298. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  33299. !isInt(generationFieldWidth)) {
  33300. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  33301. }
  33302. for (i = streamState.entryNum; i < n; ++i) {
  33303. streamState.entryNum = i;
  33304. streamState.streamPos = stream.pos;
  33305. var type = 0, offset = 0, generation = 0;
  33306. for (j = 0; j < typeFieldWidth; ++j) {
  33307. type = (type << 8) | stream.getByte();
  33308. }
  33309. // if type field is absent, its default value is 1
  33310. if (typeFieldWidth === 0) {
  33311. type = 1;
  33312. }
  33313. for (j = 0; j < offsetFieldWidth; ++j) {
  33314. offset = (offset << 8) | stream.getByte();
  33315. }
  33316. for (j = 0; j < generationFieldWidth; ++j) {
  33317. generation = (generation << 8) | stream.getByte();
  33318. }
  33319. var entry = {};
  33320. entry.offset = offset;
  33321. entry.gen = generation;
  33322. switch (type) {
  33323. case 0:
  33324. entry.free = true;
  33325. break;
  33326. case 1:
  33327. entry.uncompressed = true;
  33328. break;
  33329. case 2:
  33330. break;
  33331. default:
  33332. error('Invalid XRef entry type: ' + type);
  33333. }
  33334. if (!this.entries[first + i]) {
  33335. this.entries[first + i] = entry;
  33336. }
  33337. }
  33338. streamState.entryNum = 0;
  33339. streamState.streamPos = stream.pos;
  33340. entryRanges.splice(0, 2);
  33341. }
  33342. },
  33343. indexObjects: function XRef_indexObjects() {
  33344. // Simple scan through the PDF content to find objects,
  33345. // trailers and XRef streams.
  33346. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  33347. var PERCENT = 0x25, LT = 0x3C;
  33348. function readToken(data, offset) {
  33349. var token = '', ch = data[offset];
  33350. while (ch !== LF && ch !== CR && ch !== LT) {
  33351. if (++offset >= data.length) {
  33352. break;
  33353. }
  33354. token += String.fromCharCode(ch);
  33355. ch = data[offset];
  33356. }
  33357. return token;
  33358. }
  33359. function skipUntil(data, offset, what) {
  33360. var length = what.length, dataLength = data.length;
  33361. var skipped = 0;
  33362. // finding byte sequence
  33363. while (offset < dataLength) {
  33364. var i = 0;
  33365. while (i < length && data[offset + i] === what[i]) {
  33366. ++i;
  33367. }
  33368. if (i >= length) {
  33369. break; // sequence found
  33370. }
  33371. offset++;
  33372. skipped++;
  33373. }
  33374. return skipped;
  33375. }
  33376. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  33377. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  33378. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  33379. 101, 102]);
  33380. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  33381. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  33382. // Clear out any existing entries, since they may be bogus.
  33383. this.entries.length = 0;
  33384. var stream = this.stream;
  33385. stream.pos = 0;
  33386. var buffer = stream.getBytes();
  33387. var position = stream.start, length = buffer.length;
  33388. var trailers = [], xrefStms = [];
  33389. while (position < length) {
  33390. var ch = buffer[position];
  33391. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  33392. ++position;
  33393. continue;
  33394. }
  33395. if (ch === PERCENT) { // %-comment
  33396. do {
  33397. ++position;
  33398. if (position >= length) {
  33399. break;
  33400. }
  33401. ch = buffer[position];
  33402. } while (ch !== LF && ch !== CR);
  33403. continue;
  33404. }
  33405. var token = readToken(buffer, position);
  33406. var m;
  33407. if (token.indexOf('xref') === 0 &&
  33408. (token.length === 4 || /\s/.test(token[4]))) {
  33409. position += skipUntil(buffer, position, trailerBytes);
  33410. trailers.push(position);
  33411. position += skipUntil(buffer, position, startxrefBytes);
  33412. } else if ((m = objRegExp.exec(token))) {
  33413. if (typeof this.entries[m[1]] === 'undefined') {
  33414. this.entries[m[1]] = {
  33415. offset: position - stream.start,
  33416. gen: m[2] | 0,
  33417. uncompressed: true
  33418. };
  33419. }
  33420. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  33421. var content = buffer.subarray(position, position + contentLength);
  33422. // checking XRef stream suspect
  33423. // (it shall have '/XRef' and next char is not a letter)
  33424. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  33425. if (xrefTagOffset < contentLength &&
  33426. content[xrefTagOffset + 5] < 64) {
  33427. xrefStms.push(position - stream.start);
  33428. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  33429. }
  33430. position += contentLength;
  33431. } else if (token.indexOf('trailer') === 0 &&
  33432. (token.length === 7 || /\s/.test(token[7]))) {
  33433. trailers.push(position);
  33434. position += skipUntil(buffer, position, startxrefBytes);
  33435. } else {
  33436. position += token.length + 1;
  33437. }
  33438. }
  33439. // reading XRef streams
  33440. var i, ii;
  33441. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  33442. this.startXRefQueue.push(xrefStms[i]);
  33443. this.readXRef(/* recoveryMode */ true);
  33444. }
  33445. // finding main trailer
  33446. var dict;
  33447. for (i = 0, ii = trailers.length; i < ii; ++i) {
  33448. stream.pos = trailers[i];
  33449. var parser = new Parser(new Lexer(stream), true, this);
  33450. var obj = parser.getObj();
  33451. if (!isCmd(obj, 'trailer')) {
  33452. continue;
  33453. }
  33454. // read the trailer dictionary
  33455. if (!isDict(dict = parser.getObj())) {
  33456. continue;
  33457. }
  33458. // taking the first one with 'ID'
  33459. if (dict.has('ID')) {
  33460. return dict;
  33461. }
  33462. }
  33463. // no tailer with 'ID', taking last one (if exists)
  33464. if (dict) {
  33465. return dict;
  33466. }
  33467. // nothing helps
  33468. // calling error() would reject worker with an UnknownErrorException.
  33469. throw new InvalidPDFException('Invalid PDF structure');
  33470. },
  33471. readXRef: function XRef_readXRef(recoveryMode) {
  33472. var stream = this.stream;
  33473. try {
  33474. while (this.startXRefQueue.length) {
  33475. var startXRef = this.startXRefQueue[0];
  33476. stream.pos = startXRef + stream.start;
  33477. var parser = new Parser(new Lexer(stream), true, this);
  33478. var obj = parser.getObj();
  33479. var dict;
  33480. // Get dictionary
  33481. if (isCmd(obj, 'xref')) {
  33482. // Parse end-of-file XRef
  33483. dict = this.processXRefTable(parser);
  33484. if (!this.topDict) {
  33485. this.topDict = dict;
  33486. }
  33487. // Recursively get other XRefs 'XRefStm', if any
  33488. obj = dict.get('XRefStm');
  33489. if (isInt(obj)) {
  33490. var pos = obj;
  33491. // ignore previously loaded xref streams
  33492. // (possible infinite recursion)
  33493. if (!(pos in this.xrefstms)) {
  33494. this.xrefstms[pos] = 1;
  33495. this.startXRefQueue.push(pos);
  33496. }
  33497. }
  33498. } else if (isInt(obj)) {
  33499. // Parse in-stream XRef
  33500. if (!isInt(parser.getObj()) ||
  33501. !isCmd(parser.getObj(), 'obj') ||
  33502. !isStream(obj = parser.getObj())) {
  33503. error('Invalid XRef stream');
  33504. }
  33505. dict = this.processXRefStream(obj);
  33506. if (!this.topDict) {
  33507. this.topDict = dict;
  33508. }
  33509. if (!dict) {
  33510. error('Failed to read XRef stream');
  33511. }
  33512. } else {
  33513. error('Invalid XRef stream header');
  33514. }
  33515. // Recursively get previous dictionary, if any
  33516. obj = dict.get('Prev');
  33517. if (isInt(obj)) {
  33518. this.startXRefQueue.push(obj);
  33519. } else if (isRef(obj)) {
  33520. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  33521. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  33522. this.startXRefQueue.push(obj.num);
  33523. }
  33524. this.startXRefQueue.shift();
  33525. }
  33526. return this.topDict;
  33527. } catch (e) {
  33528. if (e instanceof MissingDataException) {
  33529. throw e;
  33530. }
  33531. info('(while reading XRef): ' + e);
  33532. }
  33533. if (recoveryMode) {
  33534. return;
  33535. }
  33536. throw new XRefParseException();
  33537. },
  33538. getEntry: function XRef_getEntry(i) {
  33539. var xrefEntry = this.entries[i];
  33540. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  33541. return xrefEntry;
  33542. }
  33543. return null;
  33544. },
  33545. fetchIfRef: function XRef_fetchIfRef(obj) {
  33546. if (!isRef(obj)) {
  33547. return obj;
  33548. }
  33549. return this.fetch(obj);
  33550. },
  33551. fetch: function XRef_fetch(ref, suppressEncryption) {
  33552. assert(isRef(ref), 'ref object is not a reference');
  33553. var num = ref.num;
  33554. if (num in this.cache) {
  33555. var cacheEntry = this.cache[num];
  33556. return cacheEntry;
  33557. }
  33558. var xrefEntry = this.getEntry(num);
  33559. // the referenced entry can be free
  33560. if (xrefEntry === null) {
  33561. return (this.cache[num] = null);
  33562. }
  33563. if (xrefEntry.uncompressed) {
  33564. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  33565. } else {
  33566. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  33567. }
  33568. if (isDict(xrefEntry)){
  33569. xrefEntry.objId = ref.toString();
  33570. } else if (isStream(xrefEntry)) {
  33571. xrefEntry.dict.objId = ref.toString();
  33572. }
  33573. return xrefEntry;
  33574. },
  33575. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  33576. suppressEncryption) {
  33577. var gen = ref.gen;
  33578. var num = ref.num;
  33579. if (xrefEntry.gen !== gen) {
  33580. error('inconsistent generation in XRef');
  33581. }
  33582. var stream = this.stream.makeSubStream(xrefEntry.offset +
  33583. this.stream.start);
  33584. var parser = new Parser(new Lexer(stream), true, this);
  33585. var obj1 = parser.getObj();
  33586. var obj2 = parser.getObj();
  33587. var obj3 = parser.getObj();
  33588. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  33589. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  33590. !isCmd(obj3)) {
  33591. error('bad XRef entry');
  33592. }
  33593. if (!isCmd(obj3, 'obj')) {
  33594. // some bad PDFs use "obj1234" and really mean 1234
  33595. if (obj3.cmd.indexOf('obj') === 0) {
  33596. num = parseInt(obj3.cmd.substring(3), 10);
  33597. if (!isNaN(num)) {
  33598. return num;
  33599. }
  33600. }
  33601. error('bad XRef entry');
  33602. }
  33603. if (this.encrypt && !suppressEncryption) {
  33604. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  33605. } else {
  33606. xrefEntry = parser.getObj();
  33607. }
  33608. if (!isStream(xrefEntry)) {
  33609. this.cache[num] = xrefEntry;
  33610. }
  33611. return xrefEntry;
  33612. },
  33613. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  33614. suppressEncryption) {
  33615. var tableOffset = xrefEntry.offset;
  33616. var stream = this.fetch(new Ref(tableOffset, 0));
  33617. if (!isStream(stream)) {
  33618. error('bad ObjStm stream');
  33619. }
  33620. var first = stream.dict.get('First');
  33621. var n = stream.dict.get('N');
  33622. if (!isInt(first) || !isInt(n)) {
  33623. error('invalid first and n parameters for ObjStm stream');
  33624. }
  33625. var parser = new Parser(new Lexer(stream), false, this);
  33626. parser.allowStreams = true;
  33627. var i, entries = [], num, nums = [];
  33628. // read the object numbers to populate cache
  33629. for (i = 0; i < n; ++i) {
  33630. num = parser.getObj();
  33631. if (!isInt(num)) {
  33632. error('invalid object number in the ObjStm stream: ' + num);
  33633. }
  33634. nums.push(num);
  33635. var offset = parser.getObj();
  33636. if (!isInt(offset)) {
  33637. error('invalid object offset in the ObjStm stream: ' + offset);
  33638. }
  33639. }
  33640. // read stream objects for cache
  33641. for (i = 0; i < n; ++i) {
  33642. entries.push(parser.getObj());
  33643. num = nums[i];
  33644. var entry = this.entries[num];
  33645. if (entry && entry.offset === tableOffset && entry.gen === i) {
  33646. this.cache[num] = entries[i];
  33647. }
  33648. }
  33649. xrefEntry = entries[xrefEntry.gen];
  33650. if (xrefEntry === undefined) {
  33651. error('bad XRef entry for compressed object');
  33652. }
  33653. return xrefEntry;
  33654. },
  33655. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  33656. if (!isRef(obj)) {
  33657. return Promise.resolve(obj);
  33658. }
  33659. return this.fetchAsync(obj);
  33660. },
  33661. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  33662. var streamManager = this.stream.manager;
  33663. var xref = this;
  33664. return new Promise(function tryFetch(resolve, reject) {
  33665. try {
  33666. resolve(xref.fetch(ref, suppressEncryption));
  33667. } catch (e) {
  33668. if (e instanceof MissingDataException) {
  33669. streamManager.requestRange(e.begin, e.end).then(function () {
  33670. tryFetch(resolve, reject);
  33671. }, reject);
  33672. return;
  33673. }
  33674. reject(e);
  33675. }
  33676. });
  33677. },
  33678. getCatalogObj: function XRef_getCatalogObj() {
  33679. return this.root;
  33680. }
  33681. };
  33682. return XRef;
  33683. })();
  33684. /**
  33685. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  33686. * see the specification (7.9.6 and 7.9.7) for additional details.
  33687. * TODO: implement all the Dict functions and make this more efficient.
  33688. */
  33689. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  33690. function NameOrNumberTree(root, xref) {
  33691. throw new Error('Cannot initialize NameOrNumberTree.');
  33692. }
  33693. NameOrNumberTree.prototype = {
  33694. getAll: function NameOrNumberTree_getAll() {
  33695. var dict = Object.create(null);
  33696. if (!this.root) {
  33697. return dict;
  33698. }
  33699. var xref = this.xref;
  33700. // Reading Name/Number tree.
  33701. var processed = new RefSet();
  33702. processed.put(this.root);
  33703. var queue = [this.root];
  33704. while (queue.length > 0) {
  33705. var i, n;
  33706. var obj = xref.fetchIfRef(queue.shift());
  33707. if (!isDict(obj)) {
  33708. continue;
  33709. }
  33710. if (obj.has('Kids')) {
  33711. var kids = obj.get('Kids');
  33712. for (i = 0, n = kids.length; i < n; i++) {
  33713. var kid = kids[i];
  33714. assert(!processed.has(kid),
  33715. 'Duplicate entry in "' + this._type + '" tree.');
  33716. queue.push(kid);
  33717. processed.put(kid);
  33718. }
  33719. continue;
  33720. }
  33721. var entries = obj.get(this._type);
  33722. if (isArray(entries)) {
  33723. for (i = 0, n = entries.length; i < n; i += 2) {
  33724. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  33725. }
  33726. }
  33727. }
  33728. return dict;
  33729. },
  33730. get: function NameOrNumberTree_get(key) {
  33731. if (!this.root) {
  33732. return null;
  33733. }
  33734. var xref = this.xref;
  33735. var kidsOrEntries = xref.fetchIfRef(this.root);
  33736. var loopCount = 0;
  33737. var MAX_LEVELS = 10;
  33738. var l, r, m;
  33739. // Perform a binary search to quickly find the entry that
  33740. // contains the key we are looking for.
  33741. while (kidsOrEntries.has('Kids')) {
  33742. if (++loopCount > MAX_LEVELS) {
  33743. warn('Search depth limit reached for "' + this._type + '" tree.');
  33744. return null;
  33745. }
  33746. var kids = kidsOrEntries.get('Kids');
  33747. if (!isArray(kids)) {
  33748. return null;
  33749. }
  33750. l = 0;
  33751. r = kids.length - 1;
  33752. while (l <= r) {
  33753. m = (l + r) >> 1;
  33754. var kid = xref.fetchIfRef(kids[m]);
  33755. var limits = kid.get('Limits');
  33756. if (key < xref.fetchIfRef(limits[0])) {
  33757. r = m - 1;
  33758. } else if (key > xref.fetchIfRef(limits[1])) {
  33759. l = m + 1;
  33760. } else {
  33761. kidsOrEntries = xref.fetchIfRef(kids[m]);
  33762. break;
  33763. }
  33764. }
  33765. if (l > r) {
  33766. return null;
  33767. }
  33768. }
  33769. // If we get here, then we have found the right entry. Now go through the
  33770. // entries in the dictionary until we find the key we're looking for.
  33771. var entries = kidsOrEntries.get(this._type);
  33772. if (isArray(entries)) {
  33773. // Perform a binary search to reduce the lookup time.
  33774. l = 0;
  33775. r = entries.length - 2;
  33776. while (l <= r) {
  33777. // Check only even indices (0, 2, 4, ...) because the
  33778. // odd indices contain the actual data.
  33779. m = (l + r) & ~1;
  33780. var currentKey = xref.fetchIfRef(entries[m]);
  33781. if (key < currentKey) {
  33782. r = m - 2;
  33783. } else if (key > currentKey) {
  33784. l = m + 2;
  33785. } else {
  33786. return xref.fetchIfRef(entries[m + 1]);
  33787. }
  33788. }
  33789. }
  33790. return null;
  33791. }
  33792. };
  33793. return NameOrNumberTree;
  33794. })();
  33795. var NameTree = (function NameTreeClosure() {
  33796. function NameTree(root, xref) {
  33797. this.root = root;
  33798. this.xref = xref;
  33799. this._type = 'Names';
  33800. }
  33801. Util.inherit(NameTree, NameOrNumberTree, {});
  33802. return NameTree;
  33803. })();
  33804. var NumberTree = (function NumberTreeClosure() {
  33805. function NumberTree(root, xref) {
  33806. this.root = root;
  33807. this.xref = xref;
  33808. this._type = 'Nums';
  33809. }
  33810. Util.inherit(NumberTree, NameOrNumberTree, {});
  33811. return NumberTree;
  33812. })();
  33813. /**
  33814. * "A PDF file can refer to the contents of another file by using a File
  33815. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  33816. * NOTE: Only embedded files are supported (as part of the attachments support)
  33817. * TODO: support the 'URL' file system (with caching if !/V), portable
  33818. * collections attributes and related files (/RF)
  33819. */
  33820. var FileSpec = (function FileSpecClosure() {
  33821. function FileSpec(root, xref) {
  33822. if (!root || !isDict(root)) {
  33823. return;
  33824. }
  33825. this.xref = xref;
  33826. this.root = root;
  33827. if (root.has('FS')) {
  33828. this.fs = root.get('FS');
  33829. }
  33830. this.description = root.has('Desc') ?
  33831. stringToPDFString(root.get('Desc')) :
  33832. '';
  33833. if (root.has('RF')) {
  33834. warn('Related file specifications are not supported');
  33835. }
  33836. this.contentAvailable = true;
  33837. if (!root.has('EF')) {
  33838. this.contentAvailable = false;
  33839. warn('Non-embedded file specifications are not supported');
  33840. }
  33841. }
  33842. function pickPlatformItem(dict) {
  33843. // Look for the filename in this order:
  33844. // UF, F, Unix, Mac, DOS
  33845. if (dict.has('UF')) {
  33846. return dict.get('UF');
  33847. } else if (dict.has('F')) {
  33848. return dict.get('F');
  33849. } else if (dict.has('Unix')) {
  33850. return dict.get('Unix');
  33851. } else if (dict.has('Mac')) {
  33852. return dict.get('Mac');
  33853. } else if (dict.has('DOS')) {
  33854. return dict.get('DOS');
  33855. } else {
  33856. return null;
  33857. }
  33858. }
  33859. FileSpec.prototype = {
  33860. get filename() {
  33861. if (!this._filename && this.root) {
  33862. var filename = pickPlatformItem(this.root) || 'unnamed';
  33863. this._filename = stringToPDFString(filename).
  33864. replace(/\\\\/g, '\\').
  33865. replace(/\\\//g, '/').
  33866. replace(/\\/g, '/');
  33867. }
  33868. return this._filename;
  33869. },
  33870. get content() {
  33871. if (!this.contentAvailable) {
  33872. return null;
  33873. }
  33874. if (!this.contentRef && this.root) {
  33875. this.contentRef = pickPlatformItem(this.root.get('EF'));
  33876. }
  33877. var content = null;
  33878. if (this.contentRef) {
  33879. var xref = this.xref;
  33880. var fileObj = xref.fetchIfRef(this.contentRef);
  33881. if (fileObj && isStream(fileObj)) {
  33882. content = fileObj.getBytes();
  33883. } else {
  33884. warn('Embedded file specification points to non-existing/invalid ' +
  33885. 'content');
  33886. }
  33887. } else {
  33888. warn('Embedded file specification does not have a content');
  33889. }
  33890. return content;
  33891. },
  33892. get serializable() {
  33893. return {
  33894. filename: this.filename,
  33895. content: this.content
  33896. };
  33897. }
  33898. };
  33899. return FileSpec;
  33900. })();
  33901. /**
  33902. * A helper for loading missing data in object graphs. It traverses the graph
  33903. * depth first and queues up any objects that have missing data. Once it has
  33904. * has traversed as many objects that are available it attempts to bundle the
  33905. * missing data requests and then resume from the nodes that weren't ready.
  33906. *
  33907. * NOTE: It provides protection from circular references by keeping track of
  33908. * of loaded references. However, you must be careful not to load any graphs
  33909. * that have references to the catalog or other pages since that will cause the
  33910. * entire PDF document object graph to be traversed.
  33911. */
  33912. var ObjectLoader = (function() {
  33913. function mayHaveChildren(value) {
  33914. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  33915. }
  33916. function addChildren(node, nodesToVisit) {
  33917. var value;
  33918. if (isDict(node) || isStream(node)) {
  33919. var map;
  33920. if (isDict(node)) {
  33921. map = node.map;
  33922. } else {
  33923. map = node.dict.map;
  33924. }
  33925. for (var key in map) {
  33926. value = map[key];
  33927. if (mayHaveChildren(value)) {
  33928. nodesToVisit.push(value);
  33929. }
  33930. }
  33931. } else if (isArray(node)) {
  33932. for (var i = 0, ii = node.length; i < ii; i++) {
  33933. value = node[i];
  33934. if (mayHaveChildren(value)) {
  33935. nodesToVisit.push(value);
  33936. }
  33937. }
  33938. }
  33939. }
  33940. function ObjectLoader(obj, keys, xref) {
  33941. this.obj = obj;
  33942. this.keys = keys;
  33943. this.xref = xref;
  33944. this.refSet = null;
  33945. this.capability = null;
  33946. }
  33947. ObjectLoader.prototype = {
  33948. load: function ObjectLoader_load() {
  33949. var keys = this.keys;
  33950. this.capability = createPromiseCapability();
  33951. // Don't walk the graph if all the data is already loaded.
  33952. if (!(this.xref.stream instanceof ChunkedStream) ||
  33953. this.xref.stream.getMissingChunks().length === 0) {
  33954. this.capability.resolve();
  33955. return this.capability.promise;
  33956. }
  33957. this.refSet = new RefSet();
  33958. // Setup the initial nodes to visit.
  33959. var nodesToVisit = [];
  33960. for (var i = 0; i < keys.length; i++) {
  33961. nodesToVisit.push(this.obj[keys[i]]);
  33962. }
  33963. this._walk(nodesToVisit);
  33964. return this.capability.promise;
  33965. },
  33966. _walk: function ObjectLoader_walk(nodesToVisit) {
  33967. var nodesToRevisit = [];
  33968. var pendingRequests = [];
  33969. // DFS walk of the object graph.
  33970. while (nodesToVisit.length) {
  33971. var currentNode = nodesToVisit.pop();
  33972. // Only references or chunked streams can cause missing data exceptions.
  33973. if (isRef(currentNode)) {
  33974. // Skip nodes that have already been visited.
  33975. if (this.refSet.has(currentNode)) {
  33976. continue;
  33977. }
  33978. try {
  33979. var ref = currentNode;
  33980. this.refSet.put(ref);
  33981. currentNode = this.xref.fetch(currentNode);
  33982. } catch (e) {
  33983. if (!(e instanceof MissingDataException)) {
  33984. throw e;
  33985. }
  33986. nodesToRevisit.push(currentNode);
  33987. pendingRequests.push({ begin: e.begin, end: e.end });
  33988. }
  33989. }
  33990. if (currentNode && currentNode.getBaseStreams) {
  33991. var baseStreams = currentNode.getBaseStreams();
  33992. var foundMissingData = false;
  33993. for (var i = 0; i < baseStreams.length; i++) {
  33994. var stream = baseStreams[i];
  33995. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  33996. foundMissingData = true;
  33997. pendingRequests.push({
  33998. begin: stream.start,
  33999. end: stream.end
  34000. });
  34001. }
  34002. }
  34003. if (foundMissingData) {
  34004. nodesToRevisit.push(currentNode);
  34005. }
  34006. }
  34007. addChildren(currentNode, nodesToVisit);
  34008. }
  34009. if (pendingRequests.length) {
  34010. this.xref.stream.manager.requestRanges(pendingRequests).then(
  34011. function pendingRequestCallback() {
  34012. nodesToVisit = nodesToRevisit;
  34013. for (var i = 0; i < nodesToRevisit.length; i++) {
  34014. var node = nodesToRevisit[i];
  34015. // Remove any reference nodes from the currrent refset so they
  34016. // aren't skipped when we revist them.
  34017. if (isRef(node)) {
  34018. this.refSet.remove(node);
  34019. }
  34020. }
  34021. this._walk(nodesToVisit);
  34022. }.bind(this), this.capability.reject);
  34023. return;
  34024. }
  34025. // Everything is loaded.
  34026. this.refSet = null;
  34027. this.capability.resolve();
  34028. }
  34029. };
  34030. return ObjectLoader;
  34031. })();
  34032. exports.Catalog = Catalog;
  34033. exports.ObjectLoader = ObjectLoader;
  34034. exports.XRef = XRef;
  34035. }));
  34036. (function (root, factory) {
  34037. {
  34038. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  34039. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  34040. root.pdfjsCoreColorSpace);
  34041. }
  34042. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  34043. coreColorSpace) {
  34044. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34045. var MissingDataException = sharedUtil.MissingDataException;
  34046. var Util = sharedUtil.Util;
  34047. var assert = sharedUtil.assert;
  34048. var error = sharedUtil.error;
  34049. var info = sharedUtil.info;
  34050. var warn = sharedUtil.warn;
  34051. var isStream = corePrimitives.isStream;
  34052. var PDFFunction = coreFunction.PDFFunction;
  34053. var ColorSpace = coreColorSpace.ColorSpace;
  34054. var ShadingType = {
  34055. FUNCTION_BASED: 1,
  34056. AXIAL: 2,
  34057. RADIAL: 3,
  34058. FREE_FORM_MESH: 4,
  34059. LATTICE_FORM_MESH: 5,
  34060. COONS_PATCH_MESH: 6,
  34061. TENSOR_PATCH_MESH: 7
  34062. };
  34063. var Pattern = (function PatternClosure() {
  34064. // Constructor should define this.getPattern
  34065. function Pattern() {
  34066. error('should not call Pattern constructor');
  34067. }
  34068. Pattern.prototype = {
  34069. // Input: current Canvas context
  34070. // Output: the appropriate fillStyle or strokeStyle
  34071. getPattern: function Pattern_getPattern(ctx) {
  34072. error('Should not call Pattern.getStyle: ' + ctx);
  34073. }
  34074. };
  34075. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  34076. res, handler) {
  34077. var dict = isStream(shading) ? shading.dict : shading;
  34078. var type = dict.get('ShadingType');
  34079. try {
  34080. switch (type) {
  34081. case ShadingType.AXIAL:
  34082. case ShadingType.RADIAL:
  34083. // Both radial and axial shadings are handled by RadialAxial shading.
  34084. return new Shadings.RadialAxial(dict, matrix, xref, res);
  34085. case ShadingType.FREE_FORM_MESH:
  34086. case ShadingType.LATTICE_FORM_MESH:
  34087. case ShadingType.COONS_PATCH_MESH:
  34088. case ShadingType.TENSOR_PATCH_MESH:
  34089. return new Shadings.Mesh(shading, matrix, xref, res);
  34090. default:
  34091. throw new Error('Unsupported ShadingType: ' + type);
  34092. }
  34093. } catch (ex) {
  34094. if (ex instanceof MissingDataException) {
  34095. throw ex;
  34096. }
  34097. handler.send('UnsupportedFeature',
  34098. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  34099. warn(ex);
  34100. return new Shadings.Dummy();
  34101. }
  34102. };
  34103. return Pattern;
  34104. })();
  34105. var Shadings = {};
  34106. // A small number to offset the first/last color stops so we can insert ones to
  34107. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  34108. Shadings.SMALL_NUMBER = 1e-6;
  34109. // Radial and axial shading have very similar implementations
  34110. // If needed, the implementations can be broken into two classes
  34111. Shadings.RadialAxial = (function RadialAxialClosure() {
  34112. function RadialAxial(dict, matrix, xref, res) {
  34113. this.matrix = matrix;
  34114. this.coordsArr = dict.get('Coords');
  34115. this.shadingType = dict.get('ShadingType');
  34116. this.type = 'Pattern';
  34117. var cs = dict.get('ColorSpace', 'CS');
  34118. cs = ColorSpace.parse(cs, xref, res);
  34119. this.cs = cs;
  34120. var t0 = 0.0, t1 = 1.0;
  34121. if (dict.has('Domain')) {
  34122. var domainArr = dict.get('Domain');
  34123. t0 = domainArr[0];
  34124. t1 = domainArr[1];
  34125. }
  34126. var extendStart = false, extendEnd = false;
  34127. if (dict.has('Extend')) {
  34128. var extendArr = dict.get('Extend');
  34129. extendStart = extendArr[0];
  34130. extendEnd = extendArr[1];
  34131. }
  34132. if (this.shadingType === ShadingType.RADIAL &&
  34133. (!extendStart || !extendEnd)) {
  34134. // Radial gradient only currently works if either circle is fully within
  34135. // the other circle.
  34136. var x1 = this.coordsArr[0];
  34137. var y1 = this.coordsArr[1];
  34138. var r1 = this.coordsArr[2];
  34139. var x2 = this.coordsArr[3];
  34140. var y2 = this.coordsArr[4];
  34141. var r2 = this.coordsArr[5];
  34142. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  34143. if (r1 <= r2 + distance &&
  34144. r2 <= r1 + distance) {
  34145. warn('Unsupported radial gradient.');
  34146. }
  34147. }
  34148. this.extendStart = extendStart;
  34149. this.extendEnd = extendEnd;
  34150. var fnObj = dict.get('Function');
  34151. var fn = PDFFunction.parseArray(xref, fnObj);
  34152. // 10 samples seems good enough for now, but probably won't work
  34153. // if there are sharp color changes. Ideally, we would implement
  34154. // the spec faithfully and add lossless optimizations.
  34155. var diff = t1 - t0;
  34156. var step = diff / 10;
  34157. var colorStops = this.colorStops = [];
  34158. // Protect against bad domains so we don't end up in an infinte loop below.
  34159. if (t0 >= t1 || step <= 0) {
  34160. // Acrobat doesn't seem to handle these cases so we'll ignore for
  34161. // now.
  34162. info('Bad shading domain.');
  34163. return;
  34164. }
  34165. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  34166. var rgbColor;
  34167. for (var i = t0; i <= t1; i += step) {
  34168. ratio[0] = i;
  34169. fn(ratio, 0, color, 0);
  34170. rgbColor = cs.getRgb(color, 0);
  34171. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34172. colorStops.push([(i - t0) / diff, cssColor]);
  34173. }
  34174. var background = 'transparent';
  34175. if (dict.has('Background')) {
  34176. rgbColor = cs.getRgb(dict.get('Background'), 0);
  34177. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  34178. }
  34179. if (!extendStart) {
  34180. // Insert a color stop at the front and offset the first real color stop
  34181. // so it doesn't conflict with the one we insert.
  34182. colorStops.unshift([0, background]);
  34183. colorStops[1][0] += Shadings.SMALL_NUMBER;
  34184. }
  34185. if (!extendEnd) {
  34186. // Same idea as above in extendStart but for the end.
  34187. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  34188. colorStops.push([1, background]);
  34189. }
  34190. this.colorStops = colorStops;
  34191. }
  34192. RadialAxial.prototype = {
  34193. getIR: function RadialAxial_getIR() {
  34194. var coordsArr = this.coordsArr;
  34195. var shadingType = this.shadingType;
  34196. var type, p0, p1, r0, r1;
  34197. if (shadingType === ShadingType.AXIAL) {
  34198. p0 = [coordsArr[0], coordsArr[1]];
  34199. p1 = [coordsArr[2], coordsArr[3]];
  34200. r0 = null;
  34201. r1 = null;
  34202. type = 'axial';
  34203. } else if (shadingType === ShadingType.RADIAL) {
  34204. p0 = [coordsArr[0], coordsArr[1]];
  34205. p1 = [coordsArr[3], coordsArr[4]];
  34206. r0 = coordsArr[2];
  34207. r1 = coordsArr[5];
  34208. type = 'radial';
  34209. } else {
  34210. error('getPattern type unknown: ' + shadingType);
  34211. }
  34212. var matrix = this.matrix;
  34213. if (matrix) {
  34214. p0 = Util.applyTransform(p0, matrix);
  34215. p1 = Util.applyTransform(p1, matrix);
  34216. if (shadingType === ShadingType.RADIAL) {
  34217. var scale = Util.singularValueDecompose2dScale(matrix);
  34218. r0 *= scale[0];
  34219. r1 *= scale[1];
  34220. }
  34221. }
  34222. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  34223. }
  34224. };
  34225. return RadialAxial;
  34226. })();
  34227. // All mesh shading. For now, they will be presented as set of the triangles
  34228. // to be drawn on the canvas and rgb color for each vertex.
  34229. Shadings.Mesh = (function MeshClosure() {
  34230. function MeshStreamReader(stream, context) {
  34231. this.stream = stream;
  34232. this.context = context;
  34233. this.buffer = 0;
  34234. this.bufferLength = 0;
  34235. var numComps = context.numComps;
  34236. this.tmpCompsBuf = new Float32Array(numComps);
  34237. var csNumComps = context.colorSpace.numComps;
  34238. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  34239. this.tmpCompsBuf;
  34240. }
  34241. MeshStreamReader.prototype = {
  34242. get hasData() {
  34243. if (this.stream.end) {
  34244. return this.stream.pos < this.stream.end;
  34245. }
  34246. if (this.bufferLength > 0) {
  34247. return true;
  34248. }
  34249. var nextByte = this.stream.getByte();
  34250. if (nextByte < 0) {
  34251. return false;
  34252. }
  34253. this.buffer = nextByte;
  34254. this.bufferLength = 8;
  34255. return true;
  34256. },
  34257. readBits: function MeshStreamReader_readBits(n) {
  34258. var buffer = this.buffer;
  34259. var bufferLength = this.bufferLength;
  34260. if (n === 32) {
  34261. if (bufferLength === 0) {
  34262. return ((this.stream.getByte() << 24) |
  34263. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  34264. this.stream.getByte()) >>> 0;
  34265. }
  34266. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  34267. (this.stream.getByte() << 8) | this.stream.getByte();
  34268. var nextByte = this.stream.getByte();
  34269. this.buffer = nextByte & ((1 << bufferLength) - 1);
  34270. return ((buffer << (8 - bufferLength)) |
  34271. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  34272. }
  34273. if (n === 8 && bufferLength === 0) {
  34274. return this.stream.getByte();
  34275. }
  34276. while (bufferLength < n) {
  34277. buffer = (buffer << 8) | this.stream.getByte();
  34278. bufferLength += 8;
  34279. }
  34280. bufferLength -= n;
  34281. this.bufferLength = bufferLength;
  34282. this.buffer = buffer & ((1 << bufferLength) - 1);
  34283. return buffer >> bufferLength;
  34284. },
  34285. align: function MeshStreamReader_align() {
  34286. this.buffer = 0;
  34287. this.bufferLength = 0;
  34288. },
  34289. readFlag: function MeshStreamReader_readFlag() {
  34290. return this.readBits(this.context.bitsPerFlag);
  34291. },
  34292. readCoordinate: function MeshStreamReader_readCoordinate() {
  34293. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  34294. var xi = this.readBits(bitsPerCoordinate);
  34295. var yi = this.readBits(bitsPerCoordinate);
  34296. var decode = this.context.decode;
  34297. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  34298. 2.3283064365386963e-10; // 2 ^ -32
  34299. return [
  34300. xi * scale * (decode[1] - decode[0]) + decode[0],
  34301. yi * scale * (decode[3] - decode[2]) + decode[2]
  34302. ];
  34303. },
  34304. readComponents: function MeshStreamReader_readComponents() {
  34305. var numComps = this.context.numComps;
  34306. var bitsPerComponent = this.context.bitsPerComponent;
  34307. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  34308. 2.3283064365386963e-10; // 2 ^ -32
  34309. var decode = this.context.decode;
  34310. var components = this.tmpCompsBuf;
  34311. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  34312. var ci = this.readBits(bitsPerComponent);
  34313. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  34314. }
  34315. var color = this.tmpCsCompsBuf;
  34316. if (this.context.colorFn) {
  34317. this.context.colorFn(components, 0, color, 0);
  34318. }
  34319. return this.context.colorSpace.getRgb(color, 0);
  34320. }
  34321. };
  34322. function decodeType4Shading(mesh, reader) {
  34323. var coords = mesh.coords;
  34324. var colors = mesh.colors;
  34325. var operators = [];
  34326. var ps = []; // not maintaining cs since that will match ps
  34327. var verticesLeft = 0; // assuming we have all data to start a new triangle
  34328. while (reader.hasData) {
  34329. var f = reader.readFlag();
  34330. var coord = reader.readCoordinate();
  34331. var color = reader.readComponents();
  34332. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  34333. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  34334. switch (f) {
  34335. case 0:
  34336. verticesLeft = 3;
  34337. break;
  34338. case 1:
  34339. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  34340. verticesLeft = 1;
  34341. break;
  34342. case 2:
  34343. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  34344. verticesLeft = 1;
  34345. break;
  34346. }
  34347. operators.push(f);
  34348. }
  34349. ps.push(coords.length);
  34350. coords.push(coord);
  34351. colors.push(color);
  34352. verticesLeft--;
  34353. reader.align();
  34354. }
  34355. mesh.figures.push({
  34356. type: 'triangles',
  34357. coords: new Int32Array(ps),
  34358. colors: new Int32Array(ps),
  34359. });
  34360. }
  34361. function decodeType5Shading(mesh, reader, verticesPerRow) {
  34362. var coords = mesh.coords;
  34363. var colors = mesh.colors;
  34364. var ps = []; // not maintaining cs since that will match ps
  34365. while (reader.hasData) {
  34366. var coord = reader.readCoordinate();
  34367. var color = reader.readComponents();
  34368. ps.push(coords.length);
  34369. coords.push(coord);
  34370. colors.push(color);
  34371. }
  34372. mesh.figures.push({
  34373. type: 'lattice',
  34374. coords: new Int32Array(ps),
  34375. colors: new Int32Array(ps),
  34376. verticesPerRow: verticesPerRow
  34377. });
  34378. }
  34379. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  34380. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  34381. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  34382. var getB = (function getBClosure() {
  34383. function buildB(count) {
  34384. var lut = [];
  34385. for (var i = 0; i <= count; i++) {
  34386. var t = i / count, t_ = 1 - t;
  34387. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  34388. 3 * t * t * t_, t * t * t]));
  34389. }
  34390. return lut;
  34391. }
  34392. var cache = [];
  34393. return function getB(count) {
  34394. if (!cache[count]) {
  34395. cache[count] = buildB(count);
  34396. }
  34397. return cache[count];
  34398. };
  34399. })();
  34400. function buildFigureFromPatch(mesh, index) {
  34401. var figure = mesh.figures[index];
  34402. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  34403. var coords = mesh.coords, colors = mesh.colors;
  34404. var pi = figure.coords;
  34405. var ci = figure.colors;
  34406. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  34407. coords[pi[12]][0], coords[pi[15]][0]);
  34408. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  34409. coords[pi[12]][1], coords[pi[15]][1]);
  34410. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  34411. coords[pi[12]][0], coords[pi[15]][0]);
  34412. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  34413. coords[pi[12]][1], coords[pi[15]][1]);
  34414. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  34415. (mesh.bounds[2] - mesh.bounds[0]));
  34416. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34417. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  34418. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  34419. (mesh.bounds[3] - mesh.bounds[1]));
  34420. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  34421. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  34422. var verticesPerRow = splitXBy + 1;
  34423. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  34424. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  34425. var k = 0;
  34426. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  34427. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  34428. c2 = colors[ci[2]], c3 = colors[ci[3]];
  34429. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  34430. for (var row = 0; row <= splitYBy; row++) {
  34431. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  34432. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  34433. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  34434. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  34435. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  34436. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  34437. for (var col = 0; col <= splitXBy; col++, k++) {
  34438. if ((row === 0 || row === splitYBy) &&
  34439. (col === 0 || col === splitXBy)) {
  34440. continue;
  34441. }
  34442. var x = 0, y = 0;
  34443. var q = 0;
  34444. for (var i = 0; i <= 3; i++) {
  34445. for (var j = 0; j <= 3; j++, q++) {
  34446. var m = bRow[row][i] * bCol[col][j];
  34447. x += coords[pi[q]][0] * m;
  34448. y += coords[pi[q]][1] * m;
  34449. }
  34450. }
  34451. figureCoords[k] = coords.length;
  34452. coords.push([x, y]);
  34453. figureColors[k] = colors.length;
  34454. var newColor = new Uint8Array(3);
  34455. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  34456. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  34457. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  34458. colors.push(newColor);
  34459. }
  34460. }
  34461. figureCoords[0] = pi[0];
  34462. figureColors[0] = ci[0];
  34463. figureCoords[splitXBy] = pi[3];
  34464. figureColors[splitXBy] = ci[1];
  34465. figureCoords[verticesPerRow * splitYBy] = pi[12];
  34466. figureColors[verticesPerRow * splitYBy] = ci[2];
  34467. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  34468. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  34469. mesh.figures[index] = {
  34470. type: 'lattice',
  34471. coords: figureCoords,
  34472. colors: figureColors,
  34473. verticesPerRow: verticesPerRow
  34474. };
  34475. }
  34476. function decodeType6Shading(mesh, reader) {
  34477. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  34478. var coords = mesh.coords;
  34479. var colors = mesh.colors;
  34480. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34481. var cs = new Int32Array(4); // c00, c30, c03, c33
  34482. while (reader.hasData) {
  34483. var f = reader.readFlag();
  34484. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  34485. var i, ii;
  34486. var pi = coords.length;
  34487. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  34488. coords.push(reader.readCoordinate());
  34489. }
  34490. var ci = colors.length;
  34491. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34492. colors.push(reader.readComponents());
  34493. }
  34494. var tmp1, tmp2, tmp3, tmp4;
  34495. switch (f) {
  34496. case 0:
  34497. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34498. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  34499. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  34500. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34501. cs[2] = ci + 1; cs[3] = ci + 2;
  34502. cs[0] = ci; cs[1] = ci + 3;
  34503. break;
  34504. case 1:
  34505. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34506. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34507. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34508. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34509. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34510. tmp1 = cs[2]; tmp2 = cs[3];
  34511. cs[2] = tmp2; cs[3] = ci;
  34512. cs[0] = tmp1; cs[1] = ci + 1;
  34513. break;
  34514. case 2:
  34515. tmp1 = ps[15];
  34516. tmp2 = ps[11];
  34517. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34518. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34519. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  34520. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34521. tmp1 = cs[3];
  34522. cs[2] = cs[1]; cs[3] = ci;
  34523. cs[0] = tmp1; cs[1] = ci + 1;
  34524. break;
  34525. case 3:
  34526. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34527. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  34528. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  34529. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34530. cs[2] = cs[0]; cs[3] = ci;
  34531. cs[0] = cs[1]; cs[1] = ci + 1;
  34532. break;
  34533. }
  34534. // set p11, p12, p21, p22
  34535. ps[5] = coords.length;
  34536. coords.push([
  34537. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  34538. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  34539. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34540. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  34541. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  34542. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  34543. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34544. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  34545. ]);
  34546. ps[6] = coords.length;
  34547. coords.push([
  34548. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  34549. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  34550. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34551. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  34552. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  34553. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  34554. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34555. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  34556. ]);
  34557. ps[9] = coords.length;
  34558. coords.push([
  34559. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  34560. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  34561. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  34562. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  34563. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  34564. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  34565. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  34566. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  34567. ]);
  34568. ps[10] = coords.length;
  34569. coords.push([
  34570. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  34571. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  34572. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  34573. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  34574. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  34575. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  34576. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  34577. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  34578. ]);
  34579. mesh.figures.push({
  34580. type: 'patch',
  34581. coords: new Int32Array(ps), // making copies of ps and cs
  34582. colors: new Int32Array(cs)
  34583. });
  34584. }
  34585. }
  34586. function decodeType7Shading(mesh, reader) {
  34587. var coords = mesh.coords;
  34588. var colors = mesh.colors;
  34589. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  34590. var cs = new Int32Array(4); // c00, c30, c03, c33
  34591. while (reader.hasData) {
  34592. var f = reader.readFlag();
  34593. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  34594. var i, ii;
  34595. var pi = coords.length;
  34596. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  34597. coords.push(reader.readCoordinate());
  34598. }
  34599. var ci = colors.length;
  34600. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  34601. colors.push(reader.readComponents());
  34602. }
  34603. var tmp1, tmp2, tmp3, tmp4;
  34604. switch (f) {
  34605. case 0:
  34606. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  34607. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  34608. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  34609. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  34610. cs[2] = ci + 1; cs[3] = ci + 2;
  34611. cs[0] = ci; cs[1] = ci + 3;
  34612. break;
  34613. case 1:
  34614. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  34615. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34616. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34617. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34618. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34619. tmp1 = cs[2]; tmp2 = cs[3];
  34620. cs[2] = tmp2; cs[3] = ci;
  34621. cs[0] = tmp1; cs[1] = ci + 1;
  34622. break;
  34623. case 2:
  34624. tmp1 = ps[15];
  34625. tmp2 = ps[11];
  34626. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34627. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34628. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34629. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34630. tmp1 = cs[3];
  34631. cs[2] = cs[1]; cs[3] = ci;
  34632. cs[0] = tmp1; cs[1] = ci + 1;
  34633. break;
  34634. case 3:
  34635. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  34636. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  34637. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  34638. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  34639. cs[2] = cs[0]; cs[3] = ci;
  34640. cs[0] = cs[1]; cs[1] = ci + 1;
  34641. break;
  34642. }
  34643. mesh.figures.push({
  34644. type: 'patch',
  34645. coords: new Int32Array(ps), // making copies of ps and cs
  34646. colors: new Int32Array(cs)
  34647. });
  34648. }
  34649. }
  34650. function updateBounds(mesh) {
  34651. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  34652. maxX = minX, maxY = minY;
  34653. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  34654. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  34655. minX = minX > x ? x : minX;
  34656. minY = minY > y ? y : minY;
  34657. maxX = maxX < x ? x : maxX;
  34658. maxY = maxY < y ? y : maxY;
  34659. }
  34660. mesh.bounds = [minX, minY, maxX, maxY];
  34661. }
  34662. function packData(mesh) {
  34663. var i, ii, j, jj;
  34664. var coords = mesh.coords;
  34665. var coordsPacked = new Float32Array(coords.length * 2);
  34666. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  34667. var xy = coords[i];
  34668. coordsPacked[j++] = xy[0];
  34669. coordsPacked[j++] = xy[1];
  34670. }
  34671. mesh.coords = coordsPacked;
  34672. var colors = mesh.colors;
  34673. var colorsPacked = new Uint8Array(colors.length * 3);
  34674. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  34675. var c = colors[i];
  34676. colorsPacked[j++] = c[0];
  34677. colorsPacked[j++] = c[1];
  34678. colorsPacked[j++] = c[2];
  34679. }
  34680. mesh.colors = colorsPacked;
  34681. var figures = mesh.figures;
  34682. for (i = 0, ii = figures.length; i < ii; i++) {
  34683. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  34684. for (j = 0, jj = ps.length; j < jj; j++) {
  34685. ps[j] *= 2;
  34686. cs[j] *= 3;
  34687. }
  34688. }
  34689. }
  34690. function Mesh(stream, matrix, xref, res) {
  34691. assert(isStream(stream), 'Mesh data is not a stream');
  34692. var dict = stream.dict;
  34693. this.matrix = matrix;
  34694. this.shadingType = dict.get('ShadingType');
  34695. this.type = 'Pattern';
  34696. this.bbox = dict.get('BBox');
  34697. var cs = dict.get('ColorSpace', 'CS');
  34698. cs = ColorSpace.parse(cs, xref, res);
  34699. this.cs = cs;
  34700. this.background = dict.has('Background') ?
  34701. cs.getRgb(dict.get('Background'), 0) : null;
  34702. var fnObj = dict.get('Function');
  34703. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  34704. this.coords = [];
  34705. this.colors = [];
  34706. this.figures = [];
  34707. var decodeContext = {
  34708. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  34709. bitsPerComponent: dict.get('BitsPerComponent'),
  34710. bitsPerFlag: dict.get('BitsPerFlag'),
  34711. decode: dict.get('Decode'),
  34712. colorFn: fn,
  34713. colorSpace: cs,
  34714. numComps: fn ? 1 : cs.numComps
  34715. };
  34716. var reader = new MeshStreamReader(stream, decodeContext);
  34717. var patchMesh = false;
  34718. switch (this.shadingType) {
  34719. case ShadingType.FREE_FORM_MESH:
  34720. decodeType4Shading(this, reader);
  34721. break;
  34722. case ShadingType.LATTICE_FORM_MESH:
  34723. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  34724. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  34725. decodeType5Shading(this, reader, verticesPerRow);
  34726. break;
  34727. case ShadingType.COONS_PATCH_MESH:
  34728. decodeType6Shading(this, reader);
  34729. patchMesh = true;
  34730. break;
  34731. case ShadingType.TENSOR_PATCH_MESH:
  34732. decodeType7Shading(this, reader);
  34733. patchMesh = true;
  34734. break;
  34735. default:
  34736. error('Unsupported mesh type.');
  34737. break;
  34738. }
  34739. if (patchMesh) {
  34740. // dirty bounds calculation for determining, how dense shall be triangles
  34741. updateBounds(this);
  34742. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  34743. buildFigureFromPatch(this, i);
  34744. }
  34745. }
  34746. // calculate bounds
  34747. updateBounds(this);
  34748. packData(this);
  34749. }
  34750. Mesh.prototype = {
  34751. getIR: function Mesh_getIR() {
  34752. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  34753. this.bounds, this.matrix, this.bbox, this.background];
  34754. }
  34755. };
  34756. return Mesh;
  34757. })();
  34758. Shadings.Dummy = (function DummyClosure() {
  34759. function Dummy() {
  34760. this.type = 'Pattern';
  34761. }
  34762. Dummy.prototype = {
  34763. getIR: function Dummy_getIR() {
  34764. return ['Dummy'];
  34765. }
  34766. };
  34767. return Dummy;
  34768. })();
  34769. function getTilingPatternIR(operatorList, dict, args) {
  34770. var matrix = dict.get('Matrix');
  34771. var bbox = dict.get('BBox');
  34772. var xstep = dict.get('XStep');
  34773. var ystep = dict.get('YStep');
  34774. var paintType = dict.get('PaintType');
  34775. var tilingType = dict.get('TilingType');
  34776. return [
  34777. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  34778. paintType, tilingType
  34779. ];
  34780. }
  34781. exports.Pattern = Pattern;
  34782. exports.getTilingPatternIR = getTilingPatternIR;
  34783. }));
  34784. (function (root, factory) {
  34785. {
  34786. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  34787. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  34788. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  34789. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  34790. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  34791. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  34792. root.pdfjsCoreUnicode);
  34793. }
  34794. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  34795. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  34796. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  34797. coreEncodings, coreStandardFonts, coreUnicode) {
  34798. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  34799. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  34800. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  34801. var ImageKind = sharedUtil.ImageKind;
  34802. var OPS = sharedUtil.OPS;
  34803. var TextRenderingMode = sharedUtil.TextRenderingMode;
  34804. var Util = sharedUtil.Util;
  34805. var assert = sharedUtil.assert;
  34806. var createPromiseCapability = sharedUtil.createPromiseCapability;
  34807. var error = sharedUtil.error;
  34808. var info = sharedUtil.info;
  34809. var isArray = sharedUtil.isArray;
  34810. var isNum = sharedUtil.isNum;
  34811. var isString = sharedUtil.isString;
  34812. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  34813. var warn = sharedUtil.warn;
  34814. var Dict = corePrimitives.Dict;
  34815. var Name = corePrimitives.Name;
  34816. var isCmd = corePrimitives.isCmd;
  34817. var isDict = corePrimitives.isDict;
  34818. var isName = corePrimitives.isName;
  34819. var isRef = corePrimitives.isRef;
  34820. var isStream = corePrimitives.isStream;
  34821. var DecodeStream = coreStream.DecodeStream;
  34822. var JpegStream = coreStream.JpegStream;
  34823. var Lexer = coreParser.Lexer;
  34824. var Parser = coreParser.Parser;
  34825. var isEOF = coreParser.isEOF;
  34826. var PDFImage = coreImage.PDFImage;
  34827. var ColorSpace = coreColorSpace.ColorSpace;
  34828. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  34829. var ErrorFont = coreFonts.ErrorFont;
  34830. var FontFlags = coreFonts.FontFlags;
  34831. var Font = coreFonts.Font;
  34832. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  34833. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  34834. var getFontType = coreFonts.getFontType;
  34835. var isPDFFunction = coreFunction.isPDFFunction;
  34836. var PDFFunction = coreFunction.PDFFunction;
  34837. var Pattern = corePattern.Pattern;
  34838. var getTilingPatternIR = corePattern.getTilingPatternIR;
  34839. var CMapFactory = coreCMap.CMapFactory;
  34840. var IdentityCMap = coreCMap.IdentityCMap;
  34841. var getMetrics = coreMetrics.getMetrics;
  34842. var bidi = coreBidi.bidi;
  34843. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  34844. var StandardEncoding = coreEncodings.StandardEncoding;
  34845. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  34846. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  34847. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  34848. var getEncoding = coreEncodings.getEncoding;
  34849. var getStdFontMap = coreStandardFonts.getStdFontMap;
  34850. var getSerifFonts = coreStandardFonts.getSerifFonts;
  34851. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  34852. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  34853. var reverseIfRtl = coreUnicode.reverseIfRtl;
  34854. var PartialEvaluator = (function PartialEvaluatorClosure() {
  34855. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  34856. uniquePrefix, idCounters, fontCache) {
  34857. this.pdfManager = pdfManager;
  34858. this.xref = xref;
  34859. this.handler = handler;
  34860. this.pageIndex = pageIndex;
  34861. this.uniquePrefix = uniquePrefix;
  34862. this.idCounters = idCounters;
  34863. this.fontCache = fontCache;
  34864. }
  34865. // Trying to minimize Date.now() usage and check every 100 time
  34866. var TIME_SLOT_DURATION_MS = 20;
  34867. var CHECK_TIME_EVERY = 100;
  34868. function TimeSlotManager() {
  34869. this.reset();
  34870. }
  34871. TimeSlotManager.prototype = {
  34872. check: function TimeSlotManager_check() {
  34873. if (++this.checked < CHECK_TIME_EVERY) {
  34874. return false;
  34875. }
  34876. this.checked = 0;
  34877. return this.endTime <= Date.now();
  34878. },
  34879. reset: function TimeSlotManager_reset() {
  34880. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  34881. this.checked = 0;
  34882. }
  34883. };
  34884. var deferred = Promise.resolve();
  34885. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  34886. PartialEvaluator.prototype = {
  34887. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  34888. if (!isDict(resources)) {
  34889. return false;
  34890. }
  34891. var processed = Object.create(null);
  34892. if (resources.objId) {
  34893. processed[resources.objId] = true;
  34894. }
  34895. var nodes = [resources], xref = this.xref;
  34896. while (nodes.length) {
  34897. var key, i, ii;
  34898. var node = nodes.shift();
  34899. // First check the current resources for blend modes.
  34900. var graphicStates = node.get('ExtGState');
  34901. if (isDict(graphicStates)) {
  34902. var graphicStatesKeys = graphicStates.getKeys();
  34903. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  34904. key = graphicStatesKeys[i];
  34905. var graphicState = graphicStates.get(key);
  34906. var bm = graphicState.get('BM');
  34907. if (isName(bm) && bm.name !== 'Normal') {
  34908. return true;
  34909. }
  34910. }
  34911. }
  34912. // Descend into the XObjects to look for more resources and blend modes.
  34913. var xObjects = node.get('XObject');
  34914. if (!isDict(xObjects)) {
  34915. continue;
  34916. }
  34917. var xObjectsKeys = xObjects.getKeys();
  34918. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  34919. key = xObjectsKeys[i];
  34920. var xObject = xObjects.getRaw(key);
  34921. if (isRef(xObject)) {
  34922. if (processed[xObject.toString()]) {
  34923. // The XObject has already been processed, and by avoiding a
  34924. // redundant `xref.fetch` we can *significantly* reduce the load
  34925. // time for badly generated PDF files (fixes issue6961.pdf).
  34926. continue;
  34927. }
  34928. xObject = xref.fetch(xObject);
  34929. }
  34930. if (!isStream(xObject)) {
  34931. continue;
  34932. }
  34933. if (xObject.dict.objId) {
  34934. if (processed[xObject.dict.objId]) {
  34935. // stream has objId and is processed already
  34936. continue;
  34937. }
  34938. processed[xObject.dict.objId] = true;
  34939. }
  34940. var xResources = xObject.dict.get('Resources');
  34941. // Checking objId to detect an infinite loop.
  34942. if (isDict(xResources) &&
  34943. (!xResources.objId || !processed[xResources.objId])) {
  34944. nodes.push(xResources);
  34945. if (xResources.objId) {
  34946. processed[xResources.objId] = true;
  34947. }
  34948. }
  34949. }
  34950. }
  34951. return false;
  34952. },
  34953. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  34954. xobj, smask,
  34955. operatorList,
  34956. task,
  34957. initialState) {
  34958. var matrix = xobj.dict.getArray('Matrix');
  34959. var bbox = xobj.dict.getArray('BBox');
  34960. var group = xobj.dict.get('Group');
  34961. if (group) {
  34962. var groupOptions = {
  34963. matrix: matrix,
  34964. bbox: bbox,
  34965. smask: smask,
  34966. isolated: false,
  34967. knockout: false
  34968. };
  34969. var groupSubtype = group.get('S');
  34970. var colorSpace;
  34971. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  34972. groupOptions.isolated = (group.get('I') || false);
  34973. groupOptions.knockout = (group.get('K') || false);
  34974. colorSpace = (group.has('CS') ?
  34975. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  34976. }
  34977. if (smask && smask.backdrop) {
  34978. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  34979. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  34980. }
  34981. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  34982. }
  34983. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  34984. return this.getOperatorList(xobj, task,
  34985. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  34986. then(function () {
  34987. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  34988. if (group) {
  34989. operatorList.addOp(OPS.endGroup, [groupOptions]);
  34990. }
  34991. });
  34992. },
  34993. buildPaintImageXObject:
  34994. function PartialEvaluator_buildPaintImageXObject(resources, image,
  34995. inline, operatorList,
  34996. cacheKey, imageCache) {
  34997. var self = this;
  34998. var dict = image.dict;
  34999. var w = dict.get('Width', 'W');
  35000. var h = dict.get('Height', 'H');
  35001. if (!(w && isNum(w)) || !(h && isNum(h))) {
  35002. warn('Image dimensions are missing, or not numbers.');
  35003. return;
  35004. }
  35005. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  35006. warn('Image exceeded maximum allowed size and was removed.');
  35007. return;
  35008. }
  35009. var imageMask = (dict.get('ImageMask', 'IM') || false);
  35010. var imgData, args;
  35011. if (imageMask) {
  35012. // This depends on a tmpCanvas being filled with the
  35013. // current fillStyle, such that processing the pixel
  35014. // data can't be done here. Instead of creating a
  35015. // complete PDFImage, only read the information needed
  35016. // for later.
  35017. var width = dict.get('Width', 'W');
  35018. var height = dict.get('Height', 'H');
  35019. var bitStrideLength = (width + 7) >> 3;
  35020. var imgArray = image.getBytes(bitStrideLength * height);
  35021. var decode = dict.get('Decode', 'D');
  35022. var inverseDecode = (!!decode && decode[0] > 0);
  35023. imgData = PDFImage.createMask(imgArray, width, height,
  35024. image instanceof DecodeStream,
  35025. inverseDecode);
  35026. imgData.cached = true;
  35027. args = [imgData];
  35028. operatorList.addOp(OPS.paintImageMaskXObject, args);
  35029. if (cacheKey) {
  35030. imageCache[cacheKey] = {
  35031. fn: OPS.paintImageMaskXObject,
  35032. args: args
  35033. };
  35034. }
  35035. return;
  35036. }
  35037. var softMask = (dict.get('SMask', 'SM') || false);
  35038. var mask = (dict.get('Mask') || false);
  35039. var SMALL_IMAGE_DIMENSIONS = 200;
  35040. // Inlining small images into the queue as RGB data
  35041. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  35042. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  35043. var imageObj = new PDFImage(this.xref, resources, image,
  35044. inline, null, null);
  35045. // We force the use of RGBA_32BPP images here, because we can't handle
  35046. // any other kind.
  35047. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  35048. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  35049. return;
  35050. }
  35051. // If there is no imageMask, create the PDFImage and a lot
  35052. // of image processing can be done here.
  35053. var uniquePrefix = (this.uniquePrefix || '');
  35054. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  35055. operatorList.addDependency(objId);
  35056. args = [objId, w, h];
  35057. if (!softMask && !mask && image instanceof JpegStream &&
  35058. image.isNativelySupported(this.xref, resources)) {
  35059. // These JPEGs don't need any more processing so we can just send it.
  35060. operatorList.addOp(OPS.paintJpegXObject, args);
  35061. this.handler.send('obj',
  35062. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  35063. return;
  35064. }
  35065. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  35066. then(function(imageObj) {
  35067. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  35068. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  35069. [imgData.data.buffer]);
  35070. }).then(undefined, function (reason) {
  35071. warn('Unable to decode image: ' + reason);
  35072. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  35073. });
  35074. operatorList.addOp(OPS.paintImageXObject, args);
  35075. if (cacheKey) {
  35076. imageCache[cacheKey] = {
  35077. fn: OPS.paintImageXObject,
  35078. args: args
  35079. };
  35080. }
  35081. },
  35082. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  35083. operatorList, task,
  35084. stateManager) {
  35085. var smaskContent = smask.get('G');
  35086. var smaskOptions = {
  35087. subtype: smask.get('S').name,
  35088. backdrop: smask.get('BC')
  35089. };
  35090. // The SMask might have a alpha/luminosity value transfer function --
  35091. // we will build a map of integer values in range 0..255 to be fast.
  35092. var transferObj = smask.get('TR');
  35093. if (isPDFFunction(transferObj)) {
  35094. var transferFn = PDFFunction.parse(this.xref, transferObj);
  35095. var transferMap = new Uint8Array(256);
  35096. var tmp = new Float32Array(1);
  35097. for (var i = 0; i < 256; i++) {
  35098. tmp[0] = i / 255;
  35099. transferFn(tmp, 0, tmp, 0);
  35100. transferMap[i] = (tmp[0] * 255) | 0;
  35101. }
  35102. smaskOptions.transferMap = transferMap;
  35103. }
  35104. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  35105. operatorList, task, stateManager.state.clone());
  35106. },
  35107. handleTilingType:
  35108. function PartialEvaluator_handleTilingType(fn, args, resources,
  35109. pattern, patternDict,
  35110. operatorList, task) {
  35111. // Create an IR of the pattern code.
  35112. var tilingOpList = new OperatorList();
  35113. // Merge the available resources, to prevent issues when the patternDict
  35114. // is missing some /Resources entries (fixes issue6541.pdf).
  35115. var resourcesArray = [patternDict.get('Resources'), resources];
  35116. var patternResources = Dict.merge(this.xref, resourcesArray);
  35117. return this.getOperatorList(pattern, task, patternResources,
  35118. tilingOpList).then(function () {
  35119. // Add the dependencies to the parent operator list so they are
  35120. // resolved before sub operator list is executed synchronously.
  35121. operatorList.addDependencies(tilingOpList.dependencies);
  35122. operatorList.addOp(fn, getTilingPatternIR({
  35123. fnArray: tilingOpList.fnArray,
  35124. argsArray: tilingOpList.argsArray
  35125. }, patternDict, args));
  35126. });
  35127. },
  35128. handleSetFont:
  35129. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  35130. operatorList, task, state) {
  35131. // TODO(mack): Not needed?
  35132. var fontName;
  35133. if (fontArgs) {
  35134. fontArgs = fontArgs.slice();
  35135. fontName = fontArgs[0].name;
  35136. }
  35137. var self = this;
  35138. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  35139. function (translated) {
  35140. if (!translated.font.isType3Font) {
  35141. return translated;
  35142. }
  35143. return translated.loadType3Data(self, resources, operatorList, task).
  35144. then(function () {
  35145. return translated;
  35146. }, function (reason) {
  35147. // Error in the font data -- sending unsupported feature notification.
  35148. self.handler.send('UnsupportedFeature',
  35149. {featureId: UNSUPPORTED_FEATURES.font});
  35150. return new TranslatedFont('g_font_error',
  35151. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  35152. });
  35153. }).then(function (translated) {
  35154. state.font = translated.font;
  35155. translated.send(self.handler);
  35156. return translated.loadedName;
  35157. });
  35158. },
  35159. handleText: function PartialEvaluator_handleText(chars, state) {
  35160. var font = state.font;
  35161. var glyphs = font.charsToGlyphs(chars);
  35162. var isAddToPathSet = !!(state.textRenderingMode &
  35163. TextRenderingMode.ADD_TO_PATH_FLAG);
  35164. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  35165. var buildPath = function (fontChar) {
  35166. if (!font.renderer.hasBuiltPath(fontChar)) {
  35167. var path = font.renderer.getPathJs(fontChar);
  35168. this.handler.send('commonobj', [
  35169. font.loadedName + '_path_' + fontChar,
  35170. 'FontPath',
  35171. path
  35172. ]);
  35173. }
  35174. }.bind(this);
  35175. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  35176. var glyph = glyphs[i];
  35177. buildPath(glyph.fontChar);
  35178. // If the glyph has an accent we need to build a path for its
  35179. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  35180. var accent = glyph.accent;
  35181. if (accent && accent.fontChar) {
  35182. buildPath(accent.fontChar);
  35183. }
  35184. }
  35185. }
  35186. return glyphs;
  35187. },
  35188. setGState: function PartialEvaluator_setGState(resources, gState,
  35189. operatorList, task,
  35190. xref, stateManager) {
  35191. // This array holds the converted/processed state data.
  35192. var gStateObj = [];
  35193. var gStateKeys = gState.getKeys();
  35194. var self = this;
  35195. var promise = Promise.resolve();
  35196. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  35197. var key = gStateKeys[i];
  35198. var value = gState.get(key);
  35199. switch (key) {
  35200. case 'Type':
  35201. break;
  35202. case 'LW':
  35203. case 'LC':
  35204. case 'LJ':
  35205. case 'ML':
  35206. case 'D':
  35207. case 'RI':
  35208. case 'FL':
  35209. case 'CA':
  35210. case 'ca':
  35211. gStateObj.push([key, value]);
  35212. break;
  35213. case 'Font':
  35214. promise = promise.then(function () {
  35215. return self.handleSetFont(resources, null, value[0], operatorList,
  35216. task, stateManager.state).
  35217. then(function (loadedName) {
  35218. operatorList.addDependency(loadedName);
  35219. gStateObj.push([key, [loadedName, value[1]]]);
  35220. });
  35221. });
  35222. break;
  35223. case 'BM':
  35224. gStateObj.push([key, value]);
  35225. break;
  35226. case 'SMask':
  35227. if (isName(value) && value.name === 'None') {
  35228. gStateObj.push([key, false]);
  35229. break;
  35230. }
  35231. if (isDict(value)) {
  35232. promise = promise.then(function (dict) {
  35233. return self.handleSMask(dict, resources, operatorList,
  35234. task, stateManager);
  35235. }.bind(this, value));
  35236. gStateObj.push([key, true]);
  35237. } else {
  35238. warn('Unsupported SMask type');
  35239. }
  35240. break;
  35241. // Only generate info log messages for the following since
  35242. // they are unlikely to have a big impact on the rendering.
  35243. case 'OP':
  35244. case 'op':
  35245. case 'OPM':
  35246. case 'BG':
  35247. case 'BG2':
  35248. case 'UCR':
  35249. case 'UCR2':
  35250. case 'TR':
  35251. case 'TR2':
  35252. case 'HT':
  35253. case 'SM':
  35254. case 'SA':
  35255. case 'AIS':
  35256. case 'TK':
  35257. // TODO implement these operators.
  35258. info('graphic state operator ' + key);
  35259. break;
  35260. default:
  35261. info('Unknown graphic state operator ' + key);
  35262. break;
  35263. }
  35264. }
  35265. return promise.then(function () {
  35266. if (gStateObj.length > 0) {
  35267. operatorList.addOp(OPS.setGState, [gStateObj]);
  35268. }
  35269. });
  35270. },
  35271. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  35272. resources) {
  35273. function errorFont() {
  35274. return Promise.resolve(new TranslatedFont('g_font_error',
  35275. new ErrorFont('Font ' + fontName + ' is not available'), font));
  35276. }
  35277. var fontRef;
  35278. if (font) { // Loading by ref.
  35279. assert(isRef(font));
  35280. fontRef = font;
  35281. } else { // Loading by name.
  35282. var fontRes = resources.get('Font');
  35283. if (fontRes) {
  35284. fontRef = fontRes.getRaw(fontName);
  35285. } else {
  35286. warn('fontRes not available');
  35287. return errorFont();
  35288. }
  35289. }
  35290. if (!fontRef) {
  35291. warn('fontRef not available');
  35292. return errorFont();
  35293. }
  35294. if (this.fontCache.has(fontRef)) {
  35295. return this.fontCache.get(fontRef);
  35296. }
  35297. font = xref.fetchIfRef(fontRef);
  35298. if (!isDict(font)) {
  35299. return errorFont();
  35300. }
  35301. // We are holding font.translated references just for fontRef that are not
  35302. // dictionaries (Dict). See explanation below.
  35303. if (font.translated) {
  35304. return font.translated;
  35305. }
  35306. var fontCapability = createPromiseCapability();
  35307. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  35308. var descriptor = preEvaluatedFont.descriptor;
  35309. var fontID = fontRef.num + '_' + fontRef.gen;
  35310. if (isDict(descriptor)) {
  35311. if (!descriptor.fontAliases) {
  35312. descriptor.fontAliases = Object.create(null);
  35313. }
  35314. var fontAliases = descriptor.fontAliases;
  35315. var hash = preEvaluatedFont.hash;
  35316. if (fontAliases[hash]) {
  35317. var aliasFontRef = fontAliases[hash].aliasRef;
  35318. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  35319. this.fontCache.putAlias(fontRef, aliasFontRef);
  35320. return this.fontCache.get(fontRef);
  35321. }
  35322. }
  35323. if (!fontAliases[hash]) {
  35324. fontAliases[hash] = {
  35325. fontID: Font.getFontID()
  35326. };
  35327. }
  35328. fontAliases[hash].aliasRef = fontRef;
  35329. fontID = fontAliases[hash].fontID;
  35330. }
  35331. // Workaround for bad PDF generators that don't reference fonts
  35332. // properly, i.e. by not using an object identifier.
  35333. // Check if the fontRef is a Dict (as opposed to a standard object),
  35334. // in which case we don't cache the font and instead reference it by
  35335. // fontName in font.loadedName below.
  35336. var fontRefIsDict = isDict(fontRef);
  35337. if (!fontRefIsDict) {
  35338. this.fontCache.put(fontRef, fontCapability.promise);
  35339. }
  35340. // Keep track of each font we translated so the caller can
  35341. // load them asynchronously before calling display on a page.
  35342. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  35343. fontName.replace(/\W/g, '') : fontID);
  35344. font.translated = fontCapability.promise;
  35345. // TODO move promises into translate font
  35346. var translatedPromise;
  35347. try {
  35348. translatedPromise = Promise.resolve(
  35349. this.translateFont(preEvaluatedFont, xref));
  35350. } catch (e) {
  35351. translatedPromise = Promise.reject(e);
  35352. }
  35353. var self = this;
  35354. translatedPromise.then(function (translatedFont) {
  35355. if (translatedFont.fontType !== undefined) {
  35356. var xrefFontStats = xref.stats.fontTypes;
  35357. xrefFontStats[translatedFont.fontType] = true;
  35358. }
  35359. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35360. translatedFont, font));
  35361. }, function (reason) {
  35362. // TODO fontCapability.reject?
  35363. // Error in the font data -- sending unsupported feature notification.
  35364. self.handler.send('UnsupportedFeature',
  35365. {featureId: UNSUPPORTED_FEATURES.font});
  35366. try {
  35367. // error, but it's still nice to have font type reported
  35368. var descriptor = preEvaluatedFont.descriptor;
  35369. var fontFile3 = descriptor && descriptor.get('FontFile3');
  35370. var subtype = fontFile3 && fontFile3.get('Subtype');
  35371. var fontType = getFontType(preEvaluatedFont.type,
  35372. subtype && subtype.name);
  35373. var xrefFontStats = xref.stats.fontTypes;
  35374. xrefFontStats[fontType] = true;
  35375. } catch (ex) { }
  35376. fontCapability.resolve(new TranslatedFont(font.loadedName,
  35377. new ErrorFont(reason instanceof Error ? reason.message : reason),
  35378. font));
  35379. });
  35380. return fontCapability.promise;
  35381. },
  35382. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  35383. var lastIndex = operatorList.length - 1;
  35384. if (!args) {
  35385. args = [];
  35386. }
  35387. if (lastIndex < 0 ||
  35388. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  35389. operatorList.addOp(OPS.constructPath, [[fn], args]);
  35390. } else {
  35391. var opArgs = operatorList.argsArray[lastIndex];
  35392. opArgs[0].push(fn);
  35393. Array.prototype.push.apply(opArgs[1], args);
  35394. }
  35395. },
  35396. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  35397. cs, patterns, resources, task, xref) {
  35398. // compile tiling patterns
  35399. var patternName = args[args.length - 1];
  35400. // SCN/scn applies patterns along with normal colors
  35401. var pattern;
  35402. if (isName(patternName) &&
  35403. (pattern = patterns.get(patternName.name))) {
  35404. var dict = (isStream(pattern) ? pattern.dict : pattern);
  35405. var typeNum = dict.get('PatternType');
  35406. if (typeNum === TILING_PATTERN) {
  35407. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  35408. return this.handleTilingType(fn, color, resources, pattern,
  35409. dict, operatorList, task);
  35410. } else if (typeNum === SHADING_PATTERN) {
  35411. var shading = dict.get('Shading');
  35412. var matrix = dict.get('Matrix');
  35413. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  35414. this.handler);
  35415. operatorList.addOp(fn, pattern.getIR());
  35416. return Promise.resolve();
  35417. } else {
  35418. return Promise.reject('Unknown PatternType: ' + typeNum);
  35419. }
  35420. }
  35421. // TODO shall we fail here?
  35422. operatorList.addOp(fn, args);
  35423. return Promise.resolve();
  35424. },
  35425. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  35426. task,
  35427. resources,
  35428. operatorList,
  35429. initialState) {
  35430. var self = this;
  35431. var xref = this.xref;
  35432. var imageCache = Object.create(null);
  35433. assert(operatorList);
  35434. resources = (resources || Dict.empty);
  35435. var xobjs = (resources.get('XObject') || Dict.empty);
  35436. var patterns = (resources.get('Pattern') || Dict.empty);
  35437. var stateManager = new StateManager(initialState || new EvalState());
  35438. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35439. var timeSlotManager = new TimeSlotManager();
  35440. return new Promise(function next(resolve, reject) {
  35441. task.ensureNotTerminated();
  35442. timeSlotManager.reset();
  35443. var stop, operation = {}, i, ii, cs;
  35444. while (!(stop = timeSlotManager.check())) {
  35445. // The arguments parsed by read() are used beyond this loop, so we
  35446. // cannot reuse the same array on each iteration. Therefore we pass
  35447. // in |null| as the initial value (see the comment on
  35448. // EvaluatorPreprocessor_read() for why).
  35449. operation.args = null;
  35450. if (!(preprocessor.read(operation))) {
  35451. break;
  35452. }
  35453. var args = operation.args;
  35454. var fn = operation.fn;
  35455. switch (fn | 0) {
  35456. case OPS.paintXObject:
  35457. if (args[0].code) {
  35458. break;
  35459. }
  35460. // eagerly compile XForm objects
  35461. var name = args[0].name;
  35462. if (!name) {
  35463. warn('XObject must be referred to by name.');
  35464. continue;
  35465. }
  35466. if (imageCache[name] !== undefined) {
  35467. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  35468. args = null;
  35469. continue;
  35470. }
  35471. var xobj = xobjs.get(name);
  35472. if (xobj) {
  35473. assert(isStream(xobj), 'XObject should be a stream');
  35474. var type = xobj.dict.get('Subtype');
  35475. assert(isName(type),
  35476. 'XObject should have a Name subtype');
  35477. if (type.name === 'Form') {
  35478. stateManager.save();
  35479. return self.buildFormXObject(resources, xobj, null,
  35480. operatorList, task,
  35481. stateManager.state.clone()).
  35482. then(function () {
  35483. stateManager.restore();
  35484. next(resolve, reject);
  35485. }, reject);
  35486. } else if (type.name === 'Image') {
  35487. self.buildPaintImageXObject(resources, xobj, false,
  35488. operatorList, name, imageCache);
  35489. args = null;
  35490. continue;
  35491. } else if (type.name === 'PS') {
  35492. // PostScript XObjects are unused when viewing documents.
  35493. // See section 4.7.1 of Adobe's PDF reference.
  35494. info('Ignored XObject subtype PS');
  35495. continue;
  35496. } else {
  35497. error('Unhandled XObject subtype ' + type.name);
  35498. }
  35499. }
  35500. break;
  35501. case OPS.setFont:
  35502. var fontSize = args[1];
  35503. // eagerly collect all fonts
  35504. return self.handleSetFont(resources, args, null, operatorList,
  35505. task, stateManager.state).
  35506. then(function (loadedName) {
  35507. operatorList.addDependency(loadedName);
  35508. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  35509. next(resolve, reject);
  35510. }, reject);
  35511. case OPS.endInlineImage:
  35512. var cacheKey = args[0].cacheKey;
  35513. if (cacheKey) {
  35514. var cacheEntry = imageCache[cacheKey];
  35515. if (cacheEntry !== undefined) {
  35516. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  35517. args = null;
  35518. continue;
  35519. }
  35520. }
  35521. self.buildPaintImageXObject(resources, args[0], true,
  35522. operatorList, cacheKey, imageCache);
  35523. args = null;
  35524. continue;
  35525. case OPS.showText:
  35526. args[0] = self.handleText(args[0], stateManager.state);
  35527. break;
  35528. case OPS.showSpacedText:
  35529. var arr = args[0];
  35530. var combinedGlyphs = [];
  35531. var arrLength = arr.length;
  35532. var state = stateManager.state;
  35533. for (i = 0; i < arrLength; ++i) {
  35534. var arrItem = arr[i];
  35535. if (isString(arrItem)) {
  35536. Array.prototype.push.apply(combinedGlyphs,
  35537. self.handleText(arrItem, state));
  35538. } else if (isNum(arrItem)) {
  35539. combinedGlyphs.push(arrItem);
  35540. }
  35541. }
  35542. args[0] = combinedGlyphs;
  35543. fn = OPS.showText;
  35544. break;
  35545. case OPS.nextLineShowText:
  35546. operatorList.addOp(OPS.nextLine);
  35547. args[0] = self.handleText(args[0], stateManager.state);
  35548. fn = OPS.showText;
  35549. break;
  35550. case OPS.nextLineSetSpacingShowText:
  35551. operatorList.addOp(OPS.nextLine);
  35552. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  35553. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  35554. args[0] = self.handleText(args[0], stateManager.state);
  35555. fn = OPS.showText;
  35556. break;
  35557. case OPS.setTextRenderingMode:
  35558. stateManager.state.textRenderingMode = args[0];
  35559. break;
  35560. case OPS.setFillColorSpace:
  35561. stateManager.state.fillColorSpace =
  35562. ColorSpace.parse(args[0], xref, resources);
  35563. continue;
  35564. case OPS.setStrokeColorSpace:
  35565. stateManager.state.strokeColorSpace =
  35566. ColorSpace.parse(args[0], xref, resources);
  35567. continue;
  35568. case OPS.setFillColor:
  35569. cs = stateManager.state.fillColorSpace;
  35570. args = cs.getRgb(args, 0);
  35571. fn = OPS.setFillRGBColor;
  35572. break;
  35573. case OPS.setStrokeColor:
  35574. cs = stateManager.state.strokeColorSpace;
  35575. args = cs.getRgb(args, 0);
  35576. fn = OPS.setStrokeRGBColor;
  35577. break;
  35578. case OPS.setFillGray:
  35579. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  35580. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35581. fn = OPS.setFillRGBColor;
  35582. break;
  35583. case OPS.setStrokeGray:
  35584. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  35585. args = ColorSpace.singletons.gray.getRgb(args, 0);
  35586. fn = OPS.setStrokeRGBColor;
  35587. break;
  35588. case OPS.setFillCMYKColor:
  35589. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  35590. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35591. fn = OPS.setFillRGBColor;
  35592. break;
  35593. case OPS.setStrokeCMYKColor:
  35594. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  35595. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  35596. fn = OPS.setStrokeRGBColor;
  35597. break;
  35598. case OPS.setFillRGBColor:
  35599. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  35600. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35601. break;
  35602. case OPS.setStrokeRGBColor:
  35603. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  35604. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  35605. break;
  35606. case OPS.setFillColorN:
  35607. cs = stateManager.state.fillColorSpace;
  35608. if (cs.name === 'Pattern') {
  35609. return self.handleColorN(operatorList, OPS.setFillColorN,
  35610. args, cs, patterns, resources, task, xref).then(function() {
  35611. next(resolve, reject);
  35612. }, reject);
  35613. }
  35614. args = cs.getRgb(args, 0);
  35615. fn = OPS.setFillRGBColor;
  35616. break;
  35617. case OPS.setStrokeColorN:
  35618. cs = stateManager.state.strokeColorSpace;
  35619. if (cs.name === 'Pattern') {
  35620. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  35621. args, cs, patterns, resources, task, xref).then(function() {
  35622. next(resolve, reject);
  35623. }, reject);
  35624. }
  35625. args = cs.getRgb(args, 0);
  35626. fn = OPS.setStrokeRGBColor;
  35627. break;
  35628. case OPS.shadingFill:
  35629. var shadingRes = resources.get('Shading');
  35630. if (!shadingRes) {
  35631. error('No shading resource found');
  35632. }
  35633. var shading = shadingRes.get(args[0].name);
  35634. if (!shading) {
  35635. error('No shading object found');
  35636. }
  35637. var shadingFill = Pattern.parseShading(shading, null, xref,
  35638. resources, self.handler);
  35639. var patternIR = shadingFill.getIR();
  35640. args = [patternIR];
  35641. fn = OPS.shadingFill;
  35642. break;
  35643. case OPS.setGState:
  35644. var dictName = args[0];
  35645. var extGState = resources.get('ExtGState');
  35646. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  35647. break;
  35648. }
  35649. var gState = extGState.get(dictName.name);
  35650. return self.setGState(resources, gState, operatorList, task,
  35651. xref, stateManager).then(function() {
  35652. next(resolve, reject);
  35653. }, reject);
  35654. case OPS.moveTo:
  35655. case OPS.lineTo:
  35656. case OPS.curveTo:
  35657. case OPS.curveTo2:
  35658. case OPS.curveTo3:
  35659. case OPS.closePath:
  35660. self.buildPath(operatorList, fn, args);
  35661. continue;
  35662. case OPS.rectangle:
  35663. self.buildPath(operatorList, fn, args);
  35664. continue;
  35665. case OPS.markPoint:
  35666. case OPS.markPointProps:
  35667. case OPS.beginMarkedContent:
  35668. case OPS.beginMarkedContentProps:
  35669. case OPS.endMarkedContent:
  35670. case OPS.beginCompat:
  35671. case OPS.endCompat:
  35672. // Ignore operators where the corresponding handlers are known to
  35673. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  35674. // serialization errors and is also a bit more efficient.
  35675. // We could also try to serialize all objects in a general way,
  35676. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  35677. // but doing so is meaningless without knowing the semantics.
  35678. continue;
  35679. default:
  35680. // Note: Ignore the operator if it has `Dict` arguments, since
  35681. // those are non-serializable, otherwise postMessage will throw
  35682. // "An object could not be cloned.".
  35683. if (args !== null) {
  35684. for (i = 0, ii = args.length; i < ii; i++) {
  35685. if (args[i] instanceof Dict) {
  35686. break;
  35687. }
  35688. }
  35689. if (i < ii) {
  35690. warn('getOperatorList - ignoring operator: ' + fn);
  35691. continue;
  35692. }
  35693. }
  35694. }
  35695. operatorList.addOp(fn, args);
  35696. }
  35697. if (stop) {
  35698. deferred.then(function () {
  35699. next(resolve, reject);
  35700. }, reject);
  35701. return;
  35702. }
  35703. // Some PDFs don't close all restores inside object/form.
  35704. // Closing those for them.
  35705. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  35706. operatorList.addOp(OPS.restore, []);
  35707. }
  35708. resolve();
  35709. });
  35710. },
  35711. getTextContent:
  35712. function PartialEvaluator_getTextContent(stream, task, resources,
  35713. stateManager,
  35714. normalizeWhitespace) {
  35715. stateManager = (stateManager || new StateManager(new TextState()));
  35716. var WhitespaceRegexp = /\s/g;
  35717. var textContent = {
  35718. items: [],
  35719. styles: Object.create(null)
  35720. };
  35721. var textContentItem = {
  35722. initialized: false,
  35723. str: [],
  35724. width: 0,
  35725. height: 0,
  35726. vertical: false,
  35727. lastAdvanceWidth: 0,
  35728. lastAdvanceHeight: 0,
  35729. textAdvanceScale: 0,
  35730. spaceWidth: 0,
  35731. fakeSpaceMin: Infinity,
  35732. fakeMultiSpaceMin: Infinity,
  35733. fakeMultiSpaceMax: -0,
  35734. textRunBreakAllowed: false,
  35735. transform: null,
  35736. fontName: null
  35737. };
  35738. var SPACE_FACTOR = 0.3;
  35739. var MULTI_SPACE_FACTOR = 1.5;
  35740. var MULTI_SPACE_FACTOR_MAX = 4;
  35741. var self = this;
  35742. var xref = this.xref;
  35743. resources = (xref.fetchIfRef(resources) || Dict.empty);
  35744. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  35745. var xobjs = null;
  35746. var xobjsCache = Object.create(null);
  35747. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  35748. var textState;
  35749. function ensureTextContentItem() {
  35750. if (textContentItem.initialized) {
  35751. return textContentItem;
  35752. }
  35753. var font = textState.font;
  35754. if (!(font.loadedName in textContent.styles)) {
  35755. textContent.styles[font.loadedName] = {
  35756. fontFamily: font.fallbackName,
  35757. ascent: font.ascent,
  35758. descent: font.descent,
  35759. vertical: font.vertical
  35760. };
  35761. }
  35762. textContentItem.fontName = font.loadedName;
  35763. // 9.4.4 Text Space Details
  35764. var tsm = [textState.fontSize * textState.textHScale, 0,
  35765. 0, textState.fontSize,
  35766. 0, textState.textRise];
  35767. if (font.isType3Font &&
  35768. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  35769. textState.fontSize === 1) {
  35770. var glyphHeight = font.bbox[3] - font.bbox[1];
  35771. if (glyphHeight > 0) {
  35772. glyphHeight = glyphHeight * textState.fontMatrix[3];
  35773. tsm[3] *= glyphHeight;
  35774. }
  35775. }
  35776. var trm = Util.transform(textState.ctm,
  35777. Util.transform(textState.textMatrix, tsm));
  35778. textContentItem.transform = trm;
  35779. if (!font.vertical) {
  35780. textContentItem.width = 0;
  35781. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  35782. textContentItem.vertical = false;
  35783. } else {
  35784. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  35785. textContentItem.height = 0;
  35786. textContentItem.vertical = true;
  35787. }
  35788. var a = textState.textLineMatrix[0];
  35789. var b = textState.textLineMatrix[1];
  35790. var scaleLineX = Math.sqrt(a * a + b * b);
  35791. a = textState.ctm[0];
  35792. b = textState.ctm[1];
  35793. var scaleCtmX = Math.sqrt(a * a + b * b);
  35794. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  35795. textContentItem.lastAdvanceWidth = 0;
  35796. textContentItem.lastAdvanceHeight = 0;
  35797. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  35798. if (spaceWidth) {
  35799. textContentItem.spaceWidth = spaceWidth;
  35800. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  35801. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  35802. textContentItem.fakeMultiSpaceMax =
  35803. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  35804. // It's okay for monospace fonts to fake as much space as needed.
  35805. textContentItem.textRunBreakAllowed = !font.isMonospace;
  35806. } else {
  35807. textContentItem.spaceWidth = 0;
  35808. textContentItem.fakeSpaceMin = Infinity;
  35809. textContentItem.fakeMultiSpaceMin = Infinity;
  35810. textContentItem.fakeMultiSpaceMax = 0;
  35811. textContentItem.textRunBreakAllowed = false;
  35812. }
  35813. textContentItem.initialized = true;
  35814. return textContentItem;
  35815. }
  35816. function replaceWhitespace(str) {
  35817. // Replaces all whitespaces with standard spaces (0x20), to avoid
  35818. // alignment issues between the textLayer and the canvas if the text
  35819. // contains e.g. tabs (fixes issue6612.pdf).
  35820. var i = 0, ii = str.length, code;
  35821. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  35822. i++;
  35823. }
  35824. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  35825. }
  35826. function runBidiTransform(textChunk) {
  35827. var str = textChunk.str.join('');
  35828. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  35829. return {
  35830. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  35831. bidiResult.str),
  35832. dir: bidiResult.dir,
  35833. width: textChunk.width,
  35834. height: textChunk.height,
  35835. transform: textChunk.transform,
  35836. fontName: textChunk.fontName
  35837. };
  35838. }
  35839. function handleSetFont(fontName, fontRef) {
  35840. return self.loadFont(fontName, fontRef, xref, resources).
  35841. then(function (translated) {
  35842. textState.font = translated.font;
  35843. textState.fontMatrix = translated.font.fontMatrix ||
  35844. FONT_IDENTITY_MATRIX;
  35845. });
  35846. }
  35847. function buildTextContentItem(chars) {
  35848. var font = textState.font;
  35849. var textChunk = ensureTextContentItem();
  35850. var width = 0;
  35851. var height = 0;
  35852. var glyphs = font.charsToGlyphs(chars);
  35853. var defaultVMetrics = font.defaultVMetrics;
  35854. for (var i = 0; i < glyphs.length; i++) {
  35855. var glyph = glyphs[i];
  35856. var vMetricX = null;
  35857. var vMetricY = null;
  35858. var glyphWidth = null;
  35859. if (font.vertical) {
  35860. if (glyph.vmetric) {
  35861. glyphWidth = glyph.vmetric[0];
  35862. vMetricX = glyph.vmetric[1];
  35863. vMetricY = glyph.vmetric[2];
  35864. } else {
  35865. glyphWidth = glyph.width;
  35866. vMetricX = glyph.width * 0.5;
  35867. vMetricY = defaultVMetrics[2];
  35868. }
  35869. } else {
  35870. glyphWidth = glyph.width;
  35871. }
  35872. var glyphUnicode = glyph.unicode;
  35873. var NormalizedUnicodes = getNormalizedUnicodes();
  35874. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  35875. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  35876. }
  35877. glyphUnicode = reverseIfRtl(glyphUnicode);
  35878. // The following will calculate the x and y of the individual glyphs.
  35879. // if (font.vertical) {
  35880. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  35881. // textState.fontMatrix[0];
  35882. // tsm[5] -= vMetricY * textState.fontSize *
  35883. // textState.fontMatrix[0];
  35884. // }
  35885. // var trm = Util.transform(textState.textMatrix, tsm);
  35886. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  35887. // var x = pt[0];
  35888. // var y = pt[1];
  35889. var charSpacing = textState.charSpacing;
  35890. if (glyph.isSpace) {
  35891. var wordSpacing = textState.wordSpacing;
  35892. charSpacing += wordSpacing;
  35893. if (wordSpacing > 0) {
  35894. addFakeSpaces(wordSpacing, textChunk.str);
  35895. }
  35896. }
  35897. var tx = 0;
  35898. var ty = 0;
  35899. if (!font.vertical) {
  35900. var w0 = glyphWidth * textState.fontMatrix[0];
  35901. tx = (w0 * textState.fontSize + charSpacing) *
  35902. textState.textHScale;
  35903. width += tx;
  35904. } else {
  35905. var w1 = glyphWidth * textState.fontMatrix[0];
  35906. ty = w1 * textState.fontSize + charSpacing;
  35907. height += ty;
  35908. }
  35909. textState.translateTextMatrix(tx, ty);
  35910. textChunk.str.push(glyphUnicode);
  35911. }
  35912. if (!font.vertical) {
  35913. textChunk.lastAdvanceWidth = width;
  35914. textChunk.width += width * textChunk.textAdvanceScale;
  35915. } else {
  35916. textChunk.lastAdvanceHeight = height;
  35917. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  35918. }
  35919. return textChunk;
  35920. }
  35921. function addFakeSpaces(width, strBuf) {
  35922. if (width < textContentItem.fakeSpaceMin) {
  35923. return;
  35924. }
  35925. if (width < textContentItem.fakeMultiSpaceMin) {
  35926. strBuf.push(' ');
  35927. return;
  35928. }
  35929. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  35930. while (fakeSpaces-- > 0) {
  35931. strBuf.push(' ');
  35932. }
  35933. }
  35934. function flushTextContentItem() {
  35935. if (!textContentItem.initialized) {
  35936. return;
  35937. }
  35938. textContent.items.push(runBidiTransform(textContentItem));
  35939. textContentItem.initialized = false;
  35940. textContentItem.str.length = 0;
  35941. }
  35942. var timeSlotManager = new TimeSlotManager();
  35943. return new Promise(function next(resolve, reject) {
  35944. task.ensureNotTerminated();
  35945. timeSlotManager.reset();
  35946. var stop, operation = {}, args = [];
  35947. while (!(stop = timeSlotManager.check())) {
  35948. // The arguments parsed by read() are not used beyond this loop, so
  35949. // we can reuse the same array on every iteration, thus avoiding
  35950. // unnecessary allocations.
  35951. args.length = 0;
  35952. operation.args = args;
  35953. if (!(preprocessor.read(operation))) {
  35954. break;
  35955. }
  35956. textState = stateManager.state;
  35957. var fn = operation.fn;
  35958. args = operation.args;
  35959. var advance;
  35960. switch (fn | 0) {
  35961. case OPS.setFont:
  35962. flushTextContentItem();
  35963. textState.fontSize = args[1];
  35964. return handleSetFont(args[0].name).then(function() {
  35965. next(resolve, reject);
  35966. }, reject);
  35967. case OPS.setTextRise:
  35968. flushTextContentItem();
  35969. textState.textRise = args[0];
  35970. break;
  35971. case OPS.setHScale:
  35972. flushTextContentItem();
  35973. textState.textHScale = args[0] / 100;
  35974. break;
  35975. case OPS.setLeading:
  35976. flushTextContentItem();
  35977. textState.leading = args[0];
  35978. break;
  35979. case OPS.moveText:
  35980. // Optimization to treat same line movement as advance
  35981. var isSameTextLine = !textState.font ? false :
  35982. ((textState.font.vertical ? args[0] : args[1]) === 0);
  35983. advance = args[0] - args[1];
  35984. if (isSameTextLine && textContentItem.initialized &&
  35985. advance > 0 &&
  35986. advance <= textContentItem.fakeMultiSpaceMax) {
  35987. textState.translateTextLineMatrix(args[0], args[1]);
  35988. textContentItem.width +=
  35989. (args[0] - textContentItem.lastAdvanceWidth);
  35990. textContentItem.height +=
  35991. (args[1] - textContentItem.lastAdvanceHeight);
  35992. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  35993. (args[1] - textContentItem.lastAdvanceHeight);
  35994. addFakeSpaces(diff, textContentItem.str);
  35995. break;
  35996. }
  35997. flushTextContentItem();
  35998. textState.translateTextLineMatrix(args[0], args[1]);
  35999. textState.textMatrix = textState.textLineMatrix.slice();
  36000. break;
  36001. case OPS.setLeadingMoveText:
  36002. flushTextContentItem();
  36003. textState.leading = -args[1];
  36004. textState.translateTextLineMatrix(args[0], args[1]);
  36005. textState.textMatrix = textState.textLineMatrix.slice();
  36006. break;
  36007. case OPS.nextLine:
  36008. flushTextContentItem();
  36009. textState.carriageReturn();
  36010. break;
  36011. case OPS.setTextMatrix:
  36012. flushTextContentItem();
  36013. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  36014. args[4], args[5]);
  36015. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  36016. args[4], args[5]);
  36017. break;
  36018. case OPS.setCharSpacing:
  36019. textState.charSpacing = args[0];
  36020. break;
  36021. case OPS.setWordSpacing:
  36022. textState.wordSpacing = args[0];
  36023. break;
  36024. case OPS.beginText:
  36025. flushTextContentItem();
  36026. textState.textMatrix = IDENTITY_MATRIX.slice();
  36027. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  36028. break;
  36029. case OPS.showSpacedText:
  36030. var items = args[0];
  36031. var offset;
  36032. for (var j = 0, jj = items.length; j < jj; j++) {
  36033. if (typeof items[j] === 'string') {
  36034. buildTextContentItem(items[j]);
  36035. } else {
  36036. ensureTextContentItem();
  36037. // PDF Specification 5.3.2 states:
  36038. // The number is expressed in thousandths of a unit of text
  36039. // space.
  36040. // This amount is subtracted from the current horizontal or
  36041. // vertical coordinate, depending on the writing mode.
  36042. // In the default coordinate system, a positive adjustment
  36043. // has the effect of moving the next glyph painted either to
  36044. // the left or down by the given amount.
  36045. advance = items[j] * textState.fontSize / 1000;
  36046. var breakTextRun = false;
  36047. if (textState.font.vertical) {
  36048. offset = advance *
  36049. (textState.textHScale * textState.textMatrix[2] +
  36050. textState.textMatrix[3]);
  36051. textState.translateTextMatrix(0, advance);
  36052. breakTextRun = textContentItem.textRunBreakAllowed &&
  36053. advance > textContentItem.fakeMultiSpaceMax;
  36054. if (!breakTextRun) {
  36055. // Value needs to be added to height to paint down.
  36056. textContentItem.height += offset;
  36057. }
  36058. } else {
  36059. advance = -advance;
  36060. offset = advance * (
  36061. textState.textHScale * textState.textMatrix[0] +
  36062. textState.textMatrix[1]);
  36063. textState.translateTextMatrix(advance, 0);
  36064. breakTextRun = textContentItem.textRunBreakAllowed &&
  36065. advance > textContentItem.fakeMultiSpaceMax;
  36066. if (!breakTextRun) {
  36067. // Value needs to be subtracted from width to paint left.
  36068. textContentItem.width += offset;
  36069. }
  36070. }
  36071. if (breakTextRun) {
  36072. flushTextContentItem();
  36073. } else if (advance > 0) {
  36074. addFakeSpaces(advance, textContentItem.str);
  36075. }
  36076. }
  36077. }
  36078. break;
  36079. case OPS.showText:
  36080. buildTextContentItem(args[0]);
  36081. break;
  36082. case OPS.nextLineShowText:
  36083. flushTextContentItem();
  36084. textState.carriageReturn();
  36085. buildTextContentItem(args[0]);
  36086. break;
  36087. case OPS.nextLineSetSpacingShowText:
  36088. flushTextContentItem();
  36089. textState.wordSpacing = args[0];
  36090. textState.charSpacing = args[1];
  36091. textState.carriageReturn();
  36092. buildTextContentItem(args[2]);
  36093. break;
  36094. case OPS.paintXObject:
  36095. flushTextContentItem();
  36096. if (args[0].code) {
  36097. break;
  36098. }
  36099. if (!xobjs) {
  36100. xobjs = (resources.get('XObject') || Dict.empty);
  36101. }
  36102. var name = args[0].name;
  36103. if (xobjsCache.key === name) {
  36104. if (xobjsCache.texts) {
  36105. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  36106. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  36107. }
  36108. break;
  36109. }
  36110. var xobj = xobjs.get(name);
  36111. if (!xobj) {
  36112. break;
  36113. }
  36114. assert(isStream(xobj), 'XObject should be a stream');
  36115. var type = xobj.dict.get('Subtype');
  36116. assert(isName(type),
  36117. 'XObject should have a Name subtype');
  36118. if ('Form' !== type.name) {
  36119. xobjsCache.key = name;
  36120. xobjsCache.texts = null;
  36121. break;
  36122. }
  36123. stateManager.save();
  36124. var matrix = xobj.dict.get('Matrix');
  36125. if (isArray(matrix) && matrix.length === 6) {
  36126. stateManager.transform(matrix);
  36127. }
  36128. return self.getTextContent(xobj, task,
  36129. xobj.dict.get('Resources') || resources, stateManager,
  36130. normalizeWhitespace).then(function (formTextContent) {
  36131. Util.appendToArray(textContent.items, formTextContent.items);
  36132. Util.extendObj(textContent.styles, formTextContent.styles);
  36133. stateManager.restore();
  36134. xobjsCache.key = name;
  36135. xobjsCache.texts = formTextContent;
  36136. next(resolve, reject);
  36137. }, reject);
  36138. case OPS.setGState:
  36139. flushTextContentItem();
  36140. var dictName = args[0];
  36141. var extGState = resources.get('ExtGState');
  36142. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  36143. break;
  36144. }
  36145. var gsStateMap = extGState.get(dictName.name);
  36146. var gsStateFont = null;
  36147. for (var key in gsStateMap) {
  36148. if (key === 'Font') {
  36149. assert(!gsStateFont);
  36150. gsStateFont = gsStateMap[key];
  36151. }
  36152. }
  36153. if (gsStateFont) {
  36154. textState.fontSize = gsStateFont[1];
  36155. return handleSetFont(gsStateFont[0]).then(function() {
  36156. next(resolve, reject);
  36157. }, reject);
  36158. }
  36159. break;
  36160. } // switch
  36161. } // while
  36162. if (stop) {
  36163. deferred.then(function () {
  36164. next(resolve, reject);
  36165. }, reject);
  36166. return;
  36167. }
  36168. flushTextContentItem();
  36169. resolve(textContent);
  36170. });
  36171. },
  36172. extractDataStructures: function
  36173. partialEvaluatorExtractDataStructures(dict, baseDict,
  36174. xref, properties) {
  36175. // 9.10.2
  36176. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  36177. if (toUnicode) {
  36178. properties.toUnicode = this.readToUnicode(toUnicode);
  36179. }
  36180. if (properties.composite) {
  36181. // CIDSystemInfo helps to match CID to glyphs
  36182. var cidSystemInfo = dict.get('CIDSystemInfo');
  36183. if (isDict(cidSystemInfo)) {
  36184. properties.cidSystemInfo = {
  36185. registry: cidSystemInfo.get('Registry'),
  36186. ordering: cidSystemInfo.get('Ordering'),
  36187. supplement: cidSystemInfo.get('Supplement')
  36188. };
  36189. }
  36190. var cidToGidMap = dict.get('CIDToGIDMap');
  36191. if (isStream(cidToGidMap)) {
  36192. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  36193. }
  36194. }
  36195. // Based on 9.6.6 of the spec the encoding can come from multiple places
  36196. // and depends on the font type. The base encoding and differences are
  36197. // read here, but the encoding that is actually used is chosen during
  36198. // glyph mapping in the font.
  36199. // TODO: Loading the built in encoding in the font would allow the
  36200. // differences to be merged in here not require us to hold on to it.
  36201. var differences = [];
  36202. var baseEncodingName = null;
  36203. var encoding;
  36204. if (dict.has('Encoding')) {
  36205. encoding = dict.get('Encoding');
  36206. if (isDict(encoding)) {
  36207. baseEncodingName = encoding.get('BaseEncoding');
  36208. baseEncodingName = (isName(baseEncodingName) ?
  36209. baseEncodingName.name : null);
  36210. // Load the differences between the base and original
  36211. if (encoding.has('Differences')) {
  36212. var diffEncoding = encoding.get('Differences');
  36213. var index = 0;
  36214. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  36215. var data = xref.fetchIfRef(diffEncoding[j]);
  36216. if (isNum(data)) {
  36217. index = data;
  36218. } else if (isName(data)) {
  36219. differences[index++] = data.name;
  36220. } else {
  36221. error('Invalid entry in \'Differences\' array: ' + data);
  36222. }
  36223. }
  36224. }
  36225. } else if (isName(encoding)) {
  36226. baseEncodingName = encoding.name;
  36227. } else {
  36228. error('Encoding is not a Name nor a Dict');
  36229. }
  36230. // According to table 114 if the encoding is a named encoding it must be
  36231. // one of these predefined encodings.
  36232. if ((baseEncodingName !== 'MacRomanEncoding' &&
  36233. baseEncodingName !== 'MacExpertEncoding' &&
  36234. baseEncodingName !== 'WinAnsiEncoding')) {
  36235. baseEncodingName = null;
  36236. }
  36237. }
  36238. if (baseEncodingName) {
  36239. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  36240. } else {
  36241. encoding = (properties.type === 'TrueType' ?
  36242. WinAnsiEncoding : StandardEncoding);
  36243. // The Symbolic attribute can be misused for regular fonts
  36244. // Heuristic: we have to check if the font is a standard one also
  36245. if (!!(properties.flags & FontFlags.Symbolic)) {
  36246. encoding = MacRomanEncoding;
  36247. if (!properties.file) {
  36248. if (/Symbol/i.test(properties.name)) {
  36249. encoding = SymbolSetEncoding;
  36250. } else if (/Dingbats/i.test(properties.name)) {
  36251. encoding = ZapfDingbatsEncoding;
  36252. }
  36253. }
  36254. }
  36255. properties.defaultEncoding = encoding;
  36256. }
  36257. properties.differences = differences;
  36258. properties.baseEncodingName = baseEncodingName;
  36259. properties.dict = dict;
  36260. },
  36261. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  36262. var cmap, cmapObj = toUnicode;
  36263. if (isName(cmapObj)) {
  36264. cmap = CMapFactory.create(cmapObj,
  36265. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36266. if (cmap instanceof IdentityCMap) {
  36267. return new IdentityToUnicodeMap(0, 0xFFFF);
  36268. }
  36269. return new ToUnicodeMap(cmap.getMap());
  36270. } else if (isStream(cmapObj)) {
  36271. cmap = CMapFactory.create(cmapObj,
  36272. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36273. if (cmap instanceof IdentityCMap) {
  36274. return new IdentityToUnicodeMap(0, 0xFFFF);
  36275. }
  36276. var map = new Array(cmap.length);
  36277. // Convert UTF-16BE
  36278. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  36279. // to iterate over all keys.
  36280. cmap.forEach(function(charCode, token) {
  36281. var str = [];
  36282. for (var k = 0; k < token.length; k += 2) {
  36283. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36284. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  36285. str.push(w1);
  36286. continue;
  36287. }
  36288. k += 2;
  36289. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  36290. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  36291. }
  36292. map[charCode] = String.fromCharCode.apply(String, str);
  36293. });
  36294. return new ToUnicodeMap(map);
  36295. }
  36296. return null;
  36297. },
  36298. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  36299. // Extract the encoding from the CIDToGIDMap
  36300. var glyphsData = cidToGidStream.getBytes();
  36301. // Set encoding 0 to later verify the font has an encoding
  36302. var result = [];
  36303. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  36304. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  36305. if (glyphID === 0) {
  36306. continue;
  36307. }
  36308. var code = j >> 1;
  36309. result[code] = glyphID;
  36310. }
  36311. return result;
  36312. },
  36313. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  36314. descriptor,
  36315. properties) {
  36316. var glyphsWidths = [];
  36317. var defaultWidth = 0;
  36318. var glyphsVMetrics = [];
  36319. var defaultVMetrics;
  36320. var i, ii, j, jj, start, code, widths;
  36321. if (properties.composite) {
  36322. defaultWidth = dict.get('DW') || 1000;
  36323. widths = dict.get('W');
  36324. if (widths) {
  36325. for (i = 0, ii = widths.length; i < ii; i++) {
  36326. start = widths[i++];
  36327. code = xref.fetchIfRef(widths[i]);
  36328. if (isArray(code)) {
  36329. for (j = 0, jj = code.length; j < jj; j++) {
  36330. glyphsWidths[start++] = code[j];
  36331. }
  36332. } else {
  36333. var width = widths[++i];
  36334. for (j = start; j <= code; j++) {
  36335. glyphsWidths[j] = width;
  36336. }
  36337. }
  36338. }
  36339. }
  36340. if (properties.vertical) {
  36341. var vmetrics = (dict.get('DW2') || [880, -1000]);
  36342. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  36343. vmetrics = dict.get('W2');
  36344. if (vmetrics) {
  36345. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  36346. start = vmetrics[i++];
  36347. code = xref.fetchIfRef(vmetrics[i]);
  36348. if (isArray(code)) {
  36349. for (j = 0, jj = code.length; j < jj; j++) {
  36350. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  36351. }
  36352. } else {
  36353. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  36354. for (j = start; j <= code; j++) {
  36355. glyphsVMetrics[j] = vmetric;
  36356. }
  36357. }
  36358. }
  36359. }
  36360. }
  36361. } else {
  36362. var firstChar = properties.firstChar;
  36363. widths = dict.get('Widths');
  36364. if (widths) {
  36365. j = firstChar;
  36366. for (i = 0, ii = widths.length; i < ii; i++) {
  36367. glyphsWidths[j++] = widths[i];
  36368. }
  36369. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  36370. } else {
  36371. // Trying get the BaseFont metrics (see comment above).
  36372. var baseFontName = dict.get('BaseFont');
  36373. if (isName(baseFontName)) {
  36374. var metrics = this.getBaseFontMetrics(baseFontName.name);
  36375. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  36376. properties);
  36377. defaultWidth = metrics.defaultWidth;
  36378. }
  36379. }
  36380. }
  36381. // Heuristic: detection of monospace font by checking all non-zero widths
  36382. var isMonospace = true;
  36383. var firstWidth = defaultWidth;
  36384. for (var glyph in glyphsWidths) {
  36385. var glyphWidth = glyphsWidths[glyph];
  36386. if (!glyphWidth) {
  36387. continue;
  36388. }
  36389. if (!firstWidth) {
  36390. firstWidth = glyphWidth;
  36391. continue;
  36392. }
  36393. if (firstWidth !== glyphWidth) {
  36394. isMonospace = false;
  36395. break;
  36396. }
  36397. }
  36398. if (isMonospace) {
  36399. properties.flags |= FontFlags.FixedPitch;
  36400. }
  36401. properties.defaultWidth = defaultWidth;
  36402. properties.widths = glyphsWidths;
  36403. properties.defaultVMetrics = defaultVMetrics;
  36404. properties.vmetrics = glyphsVMetrics;
  36405. },
  36406. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  36407. // Simulating descriptor flags attribute
  36408. var fontNameWoStyle = baseFontName.split('-')[0];
  36409. return (fontNameWoStyle in getSerifFonts()) ||
  36410. (fontNameWoStyle.search(/serif/gi) !== -1);
  36411. },
  36412. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  36413. var defaultWidth = 0;
  36414. var widths = [];
  36415. var monospace = false;
  36416. var stdFontMap = getStdFontMap();
  36417. var lookupName = (stdFontMap[name] || name);
  36418. var Metrics = getMetrics();
  36419. if (!(lookupName in Metrics)) {
  36420. // Use default fonts for looking up font metrics if the passed
  36421. // font is not a base font
  36422. if (this.isSerifFont(name)) {
  36423. lookupName = 'Times-Roman';
  36424. } else {
  36425. lookupName = 'Helvetica';
  36426. }
  36427. }
  36428. var glyphWidths = Metrics[lookupName];
  36429. if (isNum(glyphWidths)) {
  36430. defaultWidth = glyphWidths;
  36431. monospace = true;
  36432. } else {
  36433. widths = glyphWidths(); // expand lazy widths array
  36434. }
  36435. return {
  36436. defaultWidth: defaultWidth,
  36437. monospace: monospace,
  36438. widths: widths
  36439. };
  36440. },
  36441. buildCharCodeToWidth:
  36442. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  36443. properties) {
  36444. var widths = Object.create(null);
  36445. var differences = properties.differences;
  36446. var encoding = properties.defaultEncoding;
  36447. for (var charCode = 0; charCode < 256; charCode++) {
  36448. if (charCode in differences &&
  36449. widthsByGlyphName[differences[charCode]]) {
  36450. widths[charCode] = widthsByGlyphName[differences[charCode]];
  36451. continue;
  36452. }
  36453. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  36454. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  36455. continue;
  36456. }
  36457. }
  36458. return widths;
  36459. },
  36460. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  36461. var baseDict = dict;
  36462. var type = dict.get('Subtype');
  36463. assert(isName(type), 'invalid font Subtype');
  36464. var composite = false;
  36465. var uint8array;
  36466. if (type.name === 'Type0') {
  36467. // If font is a composite
  36468. // - get the descendant font
  36469. // - set the type according to the descendant font
  36470. // - get the FontDescriptor from the descendant font
  36471. var df = dict.get('DescendantFonts');
  36472. if (!df) {
  36473. error('Descendant fonts are not specified');
  36474. }
  36475. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  36476. type = dict.get('Subtype');
  36477. assert(isName(type), 'invalid font Subtype');
  36478. composite = true;
  36479. }
  36480. var descriptor = dict.get('FontDescriptor');
  36481. if (descriptor) {
  36482. var hash = new MurmurHash3_64();
  36483. var encoding = baseDict.getRaw('Encoding');
  36484. if (isName(encoding)) {
  36485. hash.update(encoding.name);
  36486. } else if (isRef(encoding)) {
  36487. hash.update(encoding.num + '_' + encoding.gen);
  36488. } else if (isDict(encoding)) {
  36489. var keys = encoding.getKeys();
  36490. for (var i = 0, ii = keys.length; i < ii; i++) {
  36491. var entry = encoding.getRaw(keys[i]);
  36492. if (isName(entry)) {
  36493. hash.update(entry.name);
  36494. } else if (isRef(entry)) {
  36495. hash.update(entry.num + '_' + entry.gen);
  36496. } else if (isArray(entry)) { // 'Differences' entry.
  36497. // Ideally we should check the contents of the array, but to avoid
  36498. // parsing it here and then again in |extractDataStructures|,
  36499. // we only use the array length for now (fixes bug1157493.pdf).
  36500. hash.update(entry.length.toString());
  36501. }
  36502. }
  36503. }
  36504. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  36505. if (isStream(toUnicode)) {
  36506. var stream = toUnicode.str || toUnicode;
  36507. uint8array = stream.buffer ?
  36508. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  36509. new Uint8Array(stream.bytes.buffer,
  36510. stream.start, stream.end - stream.start);
  36511. hash.update(uint8array);
  36512. } else if (isName(toUnicode)) {
  36513. hash.update(toUnicode.name);
  36514. }
  36515. var widths = dict.get('Widths') || baseDict.get('Widths');
  36516. if (widths) {
  36517. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  36518. hash.update(uint8array);
  36519. }
  36520. }
  36521. return {
  36522. descriptor: descriptor,
  36523. dict: dict,
  36524. baseDict: baseDict,
  36525. composite: composite,
  36526. type: type.name,
  36527. hash: hash ? hash.hexdigest() : ''
  36528. };
  36529. },
  36530. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  36531. xref) {
  36532. var baseDict = preEvaluatedFont.baseDict;
  36533. var dict = preEvaluatedFont.dict;
  36534. var composite = preEvaluatedFont.composite;
  36535. var descriptor = preEvaluatedFont.descriptor;
  36536. var type = preEvaluatedFont.type;
  36537. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  36538. var properties;
  36539. if (!descriptor) {
  36540. if (type === 'Type3') {
  36541. // FontDescriptor is only required for Type3 fonts when the document
  36542. // is a tagged pdf. Create a barbebones one to get by.
  36543. descriptor = new Dict(null);
  36544. descriptor.set('FontName', Name.get(type));
  36545. descriptor.set('FontBBox', dict.get('FontBBox'));
  36546. } else {
  36547. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  36548. // FontDescriptor was not required.
  36549. // This case is here for compatibility.
  36550. var baseFontName = dict.get('BaseFont');
  36551. if (!isName(baseFontName)) {
  36552. error('Base font is not specified');
  36553. }
  36554. // Using base font name as a font name.
  36555. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  36556. var metrics = this.getBaseFontMetrics(baseFontName);
  36557. // Simulating descriptor flags attribute
  36558. var fontNameWoStyle = baseFontName.split('-')[0];
  36559. var flags =
  36560. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  36561. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  36562. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  36563. FontFlags.Nonsymbolic);
  36564. properties = {
  36565. type: type,
  36566. name: baseFontName,
  36567. widths: metrics.widths,
  36568. defaultWidth: metrics.defaultWidth,
  36569. flags: flags,
  36570. firstChar: 0,
  36571. lastChar: maxCharIndex
  36572. };
  36573. this.extractDataStructures(dict, dict, xref, properties);
  36574. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  36575. properties);
  36576. return new Font(baseFontName, null, properties);
  36577. }
  36578. }
  36579. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  36580. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  36581. // to ignore this rule when a variant of a standart font is used.
  36582. // TODO Fill the width array depending on which of the base font this is
  36583. // a variant.
  36584. var firstChar = (dict.get('FirstChar') || 0);
  36585. var lastChar = (dict.get('LastChar') || maxCharIndex);
  36586. var fontName = descriptor.get('FontName');
  36587. var baseFont = dict.get('BaseFont');
  36588. // Some bad PDFs have a string as the font name.
  36589. if (isString(fontName)) {
  36590. fontName = Name.get(fontName);
  36591. }
  36592. if (isString(baseFont)) {
  36593. baseFont = Name.get(baseFont);
  36594. }
  36595. if (type !== 'Type3') {
  36596. var fontNameStr = fontName && fontName.name;
  36597. var baseFontStr = baseFont && baseFont.name;
  36598. if (fontNameStr !== baseFontStr) {
  36599. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  36600. '" but should be the same as the Font\'s BaseFont "' +
  36601. baseFontStr + '"');
  36602. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  36603. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  36604. if (fontNameStr && baseFontStr &&
  36605. baseFontStr.indexOf(fontNameStr) === 0) {
  36606. fontName = baseFont;
  36607. }
  36608. }
  36609. }
  36610. fontName = (fontName || baseFont);
  36611. assert(isName(fontName), 'invalid font name');
  36612. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  36613. if (fontFile) {
  36614. if (fontFile.dict) {
  36615. var subtype = fontFile.dict.get('Subtype');
  36616. if (subtype) {
  36617. subtype = subtype.name;
  36618. }
  36619. var length1 = fontFile.dict.get('Length1');
  36620. var length2 = fontFile.dict.get('Length2');
  36621. }
  36622. }
  36623. properties = {
  36624. type: type,
  36625. name: fontName.name,
  36626. subtype: subtype,
  36627. file: fontFile,
  36628. length1: length1,
  36629. length2: length2,
  36630. loadedName: baseDict.loadedName,
  36631. composite: composite,
  36632. wideChars: composite,
  36633. fixedPitch: false,
  36634. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  36635. firstChar: firstChar || 0,
  36636. lastChar: (lastChar || maxCharIndex),
  36637. bbox: descriptor.get('FontBBox'),
  36638. ascent: descriptor.get('Ascent'),
  36639. descent: descriptor.get('Descent'),
  36640. xHeight: descriptor.get('XHeight'),
  36641. capHeight: descriptor.get('CapHeight'),
  36642. flags: descriptor.get('Flags'),
  36643. italicAngle: descriptor.get('ItalicAngle'),
  36644. coded: false
  36645. };
  36646. if (composite) {
  36647. var cidEncoding = baseDict.get('Encoding');
  36648. if (isName(cidEncoding)) {
  36649. properties.cidEncoding = cidEncoding.name;
  36650. }
  36651. properties.cMap = CMapFactory.create(cidEncoding,
  36652. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  36653. properties.vertical = properties.cMap.vertical;
  36654. }
  36655. this.extractDataStructures(dict, baseDict, xref, properties);
  36656. this.extractWidths(dict, xref, descriptor, properties);
  36657. if (type === 'Type3') {
  36658. properties.isType3Font = true;
  36659. }
  36660. return new Font(fontName.name, fontFile, properties);
  36661. }
  36662. };
  36663. return PartialEvaluator;
  36664. })();
  36665. var TranslatedFont = (function TranslatedFontClosure() {
  36666. function TranslatedFont(loadedName, font, dict) {
  36667. this.loadedName = loadedName;
  36668. this.font = font;
  36669. this.dict = dict;
  36670. this.type3Loaded = null;
  36671. this.sent = false;
  36672. }
  36673. TranslatedFont.prototype = {
  36674. send: function (handler) {
  36675. if (this.sent) {
  36676. return;
  36677. }
  36678. var fontData = this.font.exportData();
  36679. handler.send('commonobj', [
  36680. this.loadedName,
  36681. 'Font',
  36682. fontData
  36683. ]);
  36684. this.sent = true;
  36685. },
  36686. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  36687. assert(this.font.isType3Font);
  36688. if (this.type3Loaded) {
  36689. return this.type3Loaded;
  36690. }
  36691. var translatedFont = this.font;
  36692. var loadCharProcsPromise = Promise.resolve();
  36693. var charProcs = this.dict.get('CharProcs');
  36694. var fontResources = this.dict.get('Resources') || resources;
  36695. var charProcKeys = charProcs.getKeys();
  36696. var charProcOperatorList = Object.create(null);
  36697. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  36698. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  36699. var glyphStream = charProcs.get(key);
  36700. var operatorList = new OperatorList();
  36701. return evaluator.getOperatorList(glyphStream, task, fontResources,
  36702. operatorList).then(function () {
  36703. charProcOperatorList[key] = operatorList.getIR();
  36704. // Add the dependencies to the parent operator list so they are
  36705. // resolved before sub operator list is executed synchronously.
  36706. parentOperatorList.addDependencies(operatorList.dependencies);
  36707. }, function (reason) {
  36708. warn('Type3 font resource \"' + key + '\" is not available');
  36709. var operatorList = new OperatorList();
  36710. charProcOperatorList[key] = operatorList.getIR();
  36711. });
  36712. }.bind(this, charProcKeys[i]));
  36713. }
  36714. this.type3Loaded = loadCharProcsPromise.then(function () {
  36715. translatedFont.charProcOperatorList = charProcOperatorList;
  36716. });
  36717. return this.type3Loaded;
  36718. }
  36719. };
  36720. return TranslatedFont;
  36721. })();
  36722. var OperatorList = (function OperatorListClosure() {
  36723. var CHUNK_SIZE = 1000;
  36724. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  36725. function getTransfers(queue) {
  36726. var transfers = [];
  36727. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  36728. for (var i = 0, ii = queue.length; i < ii; i++) {
  36729. switch (fnArray[i]) {
  36730. case OPS.paintInlineImageXObject:
  36731. case OPS.paintInlineImageXObjectGroup:
  36732. case OPS.paintImageMaskXObject:
  36733. var arg = argsArray[i][0]; // first param in imgData
  36734. if (!arg.cached) {
  36735. transfers.push(arg.data.buffer);
  36736. }
  36737. break;
  36738. }
  36739. }
  36740. return transfers;
  36741. }
  36742. function OperatorList(intent, messageHandler, pageIndex) {
  36743. this.messageHandler = messageHandler;
  36744. this.fnArray = [];
  36745. this.argsArray = [];
  36746. this.dependencies = Object.create(null);
  36747. this._totalLength = 0;
  36748. this.pageIndex = pageIndex;
  36749. this.intent = intent;
  36750. }
  36751. OperatorList.prototype = {
  36752. get length() {
  36753. return this.argsArray.length;
  36754. },
  36755. /**
  36756. * @returns {number} The total length of the entire operator list,
  36757. * since `this.length === 0` after flushing.
  36758. */
  36759. get totalLength() {
  36760. return (this._totalLength + this.length);
  36761. },
  36762. addOp: function(fn, args) {
  36763. this.fnArray.push(fn);
  36764. this.argsArray.push(args);
  36765. if (this.messageHandler) {
  36766. if (this.fnArray.length >= CHUNK_SIZE) {
  36767. this.flush();
  36768. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  36769. (fn === OPS.restore || fn === OPS.endText)) {
  36770. // heuristic to flush on boundary of restore or endText
  36771. this.flush();
  36772. }
  36773. }
  36774. },
  36775. addDependency: function(dependency) {
  36776. if (dependency in this.dependencies) {
  36777. return;
  36778. }
  36779. this.dependencies[dependency] = true;
  36780. this.addOp(OPS.dependency, [dependency]);
  36781. },
  36782. addDependencies: function(dependencies) {
  36783. for (var key in dependencies) {
  36784. this.addDependency(key);
  36785. }
  36786. },
  36787. addOpList: function(opList) {
  36788. Util.extendObj(this.dependencies, opList.dependencies);
  36789. for (var i = 0, ii = opList.length; i < ii; i++) {
  36790. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  36791. }
  36792. },
  36793. getIR: function() {
  36794. return {
  36795. fnArray: this.fnArray,
  36796. argsArray: this.argsArray,
  36797. length: this.length
  36798. };
  36799. },
  36800. flush: function(lastChunk) {
  36801. if (this.intent !== 'oplist') {
  36802. new QueueOptimizer().optimize(this);
  36803. }
  36804. var transfers = getTransfers(this);
  36805. var length = this.length;
  36806. this._totalLength += length;
  36807. this.messageHandler.send('RenderPageChunk', {
  36808. operatorList: {
  36809. fnArray: this.fnArray,
  36810. argsArray: this.argsArray,
  36811. lastChunk: lastChunk,
  36812. length: length
  36813. },
  36814. pageIndex: this.pageIndex,
  36815. intent: this.intent
  36816. }, transfers);
  36817. this.dependencies = Object.create(null);
  36818. this.fnArray.length = 0;
  36819. this.argsArray.length = 0;
  36820. }
  36821. };
  36822. return OperatorList;
  36823. })();
  36824. var StateManager = (function StateManagerClosure() {
  36825. function StateManager(initialState) {
  36826. this.state = initialState;
  36827. this.stateStack = [];
  36828. }
  36829. StateManager.prototype = {
  36830. save: function () {
  36831. var old = this.state;
  36832. this.stateStack.push(this.state);
  36833. this.state = old.clone();
  36834. },
  36835. restore: function () {
  36836. var prev = this.stateStack.pop();
  36837. if (prev) {
  36838. this.state = prev;
  36839. }
  36840. },
  36841. transform: function (args) {
  36842. this.state.ctm = Util.transform(this.state.ctm, args);
  36843. }
  36844. };
  36845. return StateManager;
  36846. })();
  36847. var TextState = (function TextStateClosure() {
  36848. function TextState() {
  36849. this.ctm = new Float32Array(IDENTITY_MATRIX);
  36850. this.fontSize = 0;
  36851. this.font = null;
  36852. this.fontMatrix = FONT_IDENTITY_MATRIX;
  36853. this.textMatrix = IDENTITY_MATRIX.slice();
  36854. this.textLineMatrix = IDENTITY_MATRIX.slice();
  36855. this.charSpacing = 0;
  36856. this.wordSpacing = 0;
  36857. this.leading = 0;
  36858. this.textHScale = 1;
  36859. this.textRise = 0;
  36860. }
  36861. TextState.prototype = {
  36862. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  36863. var m = this.textMatrix;
  36864. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  36865. },
  36866. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  36867. var m = this.textLineMatrix;
  36868. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  36869. },
  36870. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  36871. var m = this.textMatrix;
  36872. m[4] = m[0] * x + m[2] * y + m[4];
  36873. m[5] = m[1] * x + m[3] * y + m[5];
  36874. },
  36875. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  36876. var m = this.textLineMatrix;
  36877. m[4] = m[0] * x + m[2] * y + m[4];
  36878. m[5] = m[1] * x + m[3] * y + m[5];
  36879. },
  36880. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  36881. // 9.4.4 Text Space Details
  36882. var tsm = [this.fontSize * this.textHScale, 0,
  36883. 0, this.fontSize,
  36884. 0, this.textRise];
  36885. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  36886. },
  36887. carriageReturn: function TextState_carriageReturn() {
  36888. this.translateTextLineMatrix(0, -this.leading);
  36889. this.textMatrix = this.textLineMatrix.slice();
  36890. },
  36891. clone: function TextState_clone() {
  36892. var clone = Object.create(this);
  36893. clone.textMatrix = this.textMatrix.slice();
  36894. clone.textLineMatrix = this.textLineMatrix.slice();
  36895. clone.fontMatrix = this.fontMatrix.slice();
  36896. return clone;
  36897. }
  36898. };
  36899. return TextState;
  36900. })();
  36901. var EvalState = (function EvalStateClosure() {
  36902. function EvalState() {
  36903. this.ctm = new Float32Array(IDENTITY_MATRIX);
  36904. this.font = null;
  36905. this.textRenderingMode = TextRenderingMode.FILL;
  36906. this.fillColorSpace = ColorSpace.singletons.gray;
  36907. this.strokeColorSpace = ColorSpace.singletons.gray;
  36908. }
  36909. EvalState.prototype = {
  36910. clone: function CanvasExtraState_clone() {
  36911. return Object.create(this);
  36912. },
  36913. };
  36914. return EvalState;
  36915. })();
  36916. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  36917. // Specifies properties for each command
  36918. //
  36919. // If variableArgs === true: [0, `numArgs`] expected
  36920. // If variableArgs === false: exactly `numArgs` expected
  36921. var getOPMap = getLookupTableFactory(function (t) {
  36922. // Graphic state
  36923. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  36924. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  36925. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  36926. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  36927. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  36928. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  36929. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  36930. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  36931. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  36932. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  36933. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  36934. // Path
  36935. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  36936. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  36937. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  36938. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  36939. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  36940. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  36941. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  36942. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  36943. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  36944. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  36945. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  36946. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  36947. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  36948. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  36949. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  36950. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  36951. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  36952. // Clipping
  36953. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  36954. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  36955. // Text
  36956. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  36957. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  36958. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  36959. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  36960. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  36961. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  36962. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  36963. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  36964. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  36965. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  36966. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  36967. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  36968. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  36969. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  36970. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  36971. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  36972. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  36973. variableArgs: false };
  36974. // Type3 fonts
  36975. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  36976. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  36977. variableArgs: false };
  36978. // Color
  36979. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  36980. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  36981. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  36982. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  36983. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  36984. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  36985. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  36986. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  36987. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  36988. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  36989. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  36990. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  36991. // Shading
  36992. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  36993. // Images
  36994. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  36995. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  36996. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  36997. // XObjects
  36998. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  36999. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  37000. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  37001. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  37002. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  37003. variableArgs: false };
  37004. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  37005. // Compatibility
  37006. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  37007. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  37008. // (reserved partial commands for the lexer)
  37009. t['BM'] = null;
  37010. t['BD'] = null;
  37011. t['true'] = null;
  37012. t['fa'] = null;
  37013. t['fal'] = null;
  37014. t['fals'] = null;
  37015. t['false'] = null;
  37016. t['nu'] = null;
  37017. t['nul'] = null;
  37018. t['null'] = null;
  37019. });
  37020. function EvaluatorPreprocessor(stream, xref, stateManager) {
  37021. this.opMap = getOPMap();
  37022. // TODO(mduan): pass array of knownCommands rather than this.opMap
  37023. // dictionary
  37024. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  37025. this.stateManager = stateManager;
  37026. this.nonProcessedArgs = [];
  37027. }
  37028. EvaluatorPreprocessor.prototype = {
  37029. get savedStatesDepth() {
  37030. return this.stateManager.stateStack.length;
  37031. },
  37032. // |operation| is an object with two fields:
  37033. //
  37034. // - |fn| is an out param.
  37035. //
  37036. // - |args| is an inout param. On entry, it should have one of two values.
  37037. //
  37038. // - An empty array. This indicates that the caller is providing the
  37039. // array in which the args will be stored in. The caller should use
  37040. // this value if it can reuse a single array for each call to read().
  37041. //
  37042. // - |null|. This indicates that the caller needs this function to create
  37043. // the array in which any args are stored in. If there are zero args,
  37044. // this function will leave |operation.args| as |null| (thus avoiding
  37045. // allocations that would occur if we used an empty array to represent
  37046. // zero arguments). Otherwise, it will replace |null| with a new array
  37047. // containing the arguments. The caller should use this value if it
  37048. // cannot reuse an array for each call to read().
  37049. //
  37050. // These two modes are present because this function is very hot and so
  37051. // avoiding allocations where possible is worthwhile.
  37052. //
  37053. read: function EvaluatorPreprocessor_read(operation) {
  37054. var args = operation.args;
  37055. while (true) {
  37056. var obj = this.parser.getObj();
  37057. if (isCmd(obj)) {
  37058. var cmd = obj.cmd;
  37059. // Check that the command is valid
  37060. var opSpec = this.opMap[cmd];
  37061. if (!opSpec) {
  37062. warn('Unknown command "' + cmd + '"');
  37063. continue;
  37064. }
  37065. var fn = opSpec.id;
  37066. var numArgs = opSpec.numArgs;
  37067. var argsLength = args !== null ? args.length : 0;
  37068. if (!opSpec.variableArgs) {
  37069. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  37070. if (argsLength !== numArgs) {
  37071. var nonProcessedArgs = this.nonProcessedArgs;
  37072. while (argsLength > numArgs) {
  37073. nonProcessedArgs.push(args.shift());
  37074. argsLength--;
  37075. }
  37076. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  37077. if (!args) {
  37078. args = [];
  37079. }
  37080. args.unshift(nonProcessedArgs.pop());
  37081. argsLength++;
  37082. }
  37083. }
  37084. if (argsLength < numArgs) {
  37085. // If we receive too few args, it's not possible to possible
  37086. // to execute the command, so skip the command
  37087. info('Command ' + fn + ': because expected ' +
  37088. numArgs + ' args, but received ' + argsLength +
  37089. ' args; skipping');
  37090. args = null;
  37091. continue;
  37092. }
  37093. } else if (argsLength > numArgs) {
  37094. info('Command ' + fn + ': expected [0,' + numArgs +
  37095. '] args, but received ' + argsLength + ' args');
  37096. }
  37097. // TODO figure out how to type-check vararg functions
  37098. this.preprocessCommand(fn, args);
  37099. operation.fn = fn;
  37100. operation.args = args;
  37101. return true;
  37102. } else {
  37103. if (isEOF(obj)) {
  37104. return false; // no more commands
  37105. }
  37106. // argument
  37107. if (obj !== null) {
  37108. if (!args) {
  37109. args = [];
  37110. }
  37111. args.push(obj);
  37112. assert(args.length <= 33, 'Too many arguments');
  37113. }
  37114. }
  37115. }
  37116. },
  37117. preprocessCommand:
  37118. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  37119. switch (fn | 0) {
  37120. case OPS.save:
  37121. this.stateManager.save();
  37122. break;
  37123. case OPS.restore:
  37124. this.stateManager.restore();
  37125. break;
  37126. case OPS.transform:
  37127. this.stateManager.transform(args);
  37128. break;
  37129. }
  37130. }
  37131. };
  37132. return EvaluatorPreprocessor;
  37133. })();
  37134. var QueueOptimizer = (function QueueOptimizerClosure() {
  37135. function addState(parentState, pattern, fn) {
  37136. var state = parentState;
  37137. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  37138. var item = pattern[i];
  37139. state = (state[item] || (state[item] = []));
  37140. }
  37141. state[pattern[pattern.length - 1]] = fn;
  37142. }
  37143. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37144. argsArray) {
  37145. // Handles special case of mainly LaTeX documents which use image masks to
  37146. // draw lines with the current fill style.
  37147. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  37148. // have been found at iFirstSave.
  37149. var iFirstPIMXO = iFirstSave + 2;
  37150. for (var i = 0; i < count; i++) {
  37151. var arg = argsArray[iFirstPIMXO + 4 * i];
  37152. var imageMask = arg.length === 1 && arg[0];
  37153. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  37154. (!imageMask.data.length ||
  37155. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  37156. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  37157. continue;
  37158. }
  37159. break;
  37160. }
  37161. return count - i;
  37162. }
  37163. var InitialState = [];
  37164. // This replaces (save, transform, paintInlineImageXObject, restore)+
  37165. // sequences with one |paintInlineImageXObjectGroup| operation.
  37166. addState(InitialState,
  37167. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  37168. function foundInlineImageGroup(context) {
  37169. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  37170. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  37171. var MAX_WIDTH = 1000;
  37172. var IMAGE_PADDING = 1;
  37173. var fnArray = context.fnArray, argsArray = context.argsArray;
  37174. var curr = context.iCurr;
  37175. var iFirstSave = curr - 3;
  37176. var iFirstTransform = curr - 2;
  37177. var iFirstPIIXO = curr - 1;
  37178. // Look for the quartets.
  37179. var i = iFirstSave + 4;
  37180. var ii = fnArray.length;
  37181. while (i + 3 < ii) {
  37182. if (fnArray[i] !== OPS.save ||
  37183. fnArray[i + 1] !== OPS.transform ||
  37184. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  37185. fnArray[i + 3] !== OPS.restore) {
  37186. break; // ops don't match
  37187. }
  37188. i += 4;
  37189. }
  37190. // At this point, i is the index of the first op past the last valid
  37191. // quartet.
  37192. var count = Math.min((i - iFirstSave) / 4,
  37193. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  37194. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  37195. return i;
  37196. }
  37197. // assuming that heights of those image is too small (~1 pixel)
  37198. // packing as much as possible by lines
  37199. var maxX = 0;
  37200. var map = [], maxLineHeight = 0;
  37201. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  37202. var q;
  37203. for (q = 0; q < count; q++) {
  37204. var transform = argsArray[iFirstTransform + (q << 2)];
  37205. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  37206. if (currentX + img.width > MAX_WIDTH) {
  37207. // starting new line
  37208. maxX = Math.max(maxX, currentX);
  37209. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  37210. currentX = 0;
  37211. maxLineHeight = 0;
  37212. }
  37213. map.push({
  37214. transform: transform,
  37215. x: currentX, y: currentY,
  37216. w: img.width, h: img.height
  37217. });
  37218. currentX += img.width + 2 * IMAGE_PADDING;
  37219. maxLineHeight = Math.max(maxLineHeight, img.height);
  37220. }
  37221. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  37222. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  37223. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  37224. var imgRowSize = imgWidth << 2;
  37225. for (q = 0; q < count; q++) {
  37226. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  37227. // Copy image by lines and extends pixels into padding.
  37228. var rowSize = map[q].w << 2;
  37229. var dataOffset = 0;
  37230. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  37231. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  37232. for (var k = 0, kk = map[q].h; k < kk; k++) {
  37233. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  37234. dataOffset += rowSize;
  37235. offset += imgRowSize;
  37236. }
  37237. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  37238. while (offset >= 0) {
  37239. data[offset - 4] = data[offset];
  37240. data[offset - 3] = data[offset + 1];
  37241. data[offset - 2] = data[offset + 2];
  37242. data[offset - 1] = data[offset + 3];
  37243. data[offset + rowSize] = data[offset + rowSize - 4];
  37244. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  37245. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  37246. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  37247. offset -= imgRowSize;
  37248. }
  37249. }
  37250. // Replace queue items.
  37251. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  37252. argsArray.splice(iFirstSave, count * 4,
  37253. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  37254. data: imgData }, map]);
  37255. return iFirstSave + 1;
  37256. });
  37257. // This replaces (save, transform, paintImageMaskXObject, restore)+
  37258. // sequences with one |paintImageMaskXObjectGroup| or one
  37259. // |paintImageMaskXObjectRepeat| operation.
  37260. addState(InitialState,
  37261. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  37262. function foundImageMaskGroup(context) {
  37263. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  37264. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  37265. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  37266. var fnArray = context.fnArray, argsArray = context.argsArray;
  37267. var curr = context.iCurr;
  37268. var iFirstSave = curr - 3;
  37269. var iFirstTransform = curr - 2;
  37270. var iFirstPIMXO = curr - 1;
  37271. // Look for the quartets.
  37272. var i = iFirstSave + 4;
  37273. var ii = fnArray.length;
  37274. while (i + 3 < ii) {
  37275. if (fnArray[i] !== OPS.save ||
  37276. fnArray[i + 1] !== OPS.transform ||
  37277. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  37278. fnArray[i + 3] !== OPS.restore) {
  37279. break; // ops don't match
  37280. }
  37281. i += 4;
  37282. }
  37283. // At this point, i is the index of the first op past the last valid
  37284. // quartet.
  37285. var count = (i - iFirstSave) / 4;
  37286. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  37287. argsArray);
  37288. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  37289. return i;
  37290. }
  37291. var q;
  37292. var isSameImage = false;
  37293. var iTransform, transformArgs;
  37294. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  37295. if (argsArray[iFirstTransform][1] === 0 &&
  37296. argsArray[iFirstTransform][2] === 0) {
  37297. isSameImage = true;
  37298. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37299. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37300. iTransform = iFirstTransform + 4;
  37301. var iPIMXO = iFirstPIMXO + 4;
  37302. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  37303. transformArgs = argsArray[iTransform];
  37304. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  37305. transformArgs[0] !== firstTransformArg0 ||
  37306. transformArgs[1] !== 0 ||
  37307. transformArgs[2] !== 0 ||
  37308. transformArgs[3] !== firstTransformArg3) {
  37309. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  37310. isSameImage = false;
  37311. } else {
  37312. count = q;
  37313. }
  37314. break; // different image or transform
  37315. }
  37316. }
  37317. }
  37318. if (isSameImage) {
  37319. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  37320. var positions = new Float32Array(count * 2);
  37321. iTransform = iFirstTransform;
  37322. for (q = 0; q < count; q++, iTransform += 4) {
  37323. transformArgs = argsArray[iTransform];
  37324. positions[(q << 1)] = transformArgs[4];
  37325. positions[(q << 1) + 1] = transformArgs[5];
  37326. }
  37327. // Replace queue items.
  37328. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  37329. argsArray.splice(iFirstSave, count * 4,
  37330. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  37331. } else {
  37332. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  37333. var images = [];
  37334. for (q = 0; q < count; q++) {
  37335. transformArgs = argsArray[iFirstTransform + (q << 2)];
  37336. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  37337. images.push({ data: maskParams.data, width: maskParams.width,
  37338. height: maskParams.height,
  37339. transform: transformArgs });
  37340. }
  37341. // Replace queue items.
  37342. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  37343. argsArray.splice(iFirstSave, count * 4, [images]);
  37344. }
  37345. return iFirstSave + 1;
  37346. });
  37347. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  37348. // with one paintImageXObjectRepeat operation, if the |transform| and
  37349. // |paintImageXObjectRepeat| ops are appropriate.
  37350. addState(InitialState,
  37351. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  37352. function (context) {
  37353. var MIN_IMAGES_IN_BLOCK = 3;
  37354. var MAX_IMAGES_IN_BLOCK = 1000;
  37355. var fnArray = context.fnArray, argsArray = context.argsArray;
  37356. var curr = context.iCurr;
  37357. var iFirstSave = curr - 3;
  37358. var iFirstTransform = curr - 2;
  37359. var iFirstPIXO = curr - 1;
  37360. var iFirstRestore = curr;
  37361. if (argsArray[iFirstTransform][1] !== 0 ||
  37362. argsArray[iFirstTransform][2] !== 0) {
  37363. return iFirstRestore + 1; // transform has the wrong form
  37364. }
  37365. // Look for the quartets.
  37366. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  37367. var firstTransformArg0 = argsArray[iFirstTransform][0];
  37368. var firstTransformArg3 = argsArray[iFirstTransform][3];
  37369. var i = iFirstSave + 4;
  37370. var ii = fnArray.length;
  37371. while (i + 3 < ii) {
  37372. if (fnArray[i] !== OPS.save ||
  37373. fnArray[i + 1] !== OPS.transform ||
  37374. fnArray[i + 2] !== OPS.paintImageXObject ||
  37375. fnArray[i + 3] !== OPS.restore) {
  37376. break; // ops don't match
  37377. }
  37378. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  37379. argsArray[i + 1][1] !== 0 ||
  37380. argsArray[i + 1][2] !== 0 ||
  37381. argsArray[i + 1][3] !== firstTransformArg3) {
  37382. break; // transforms don't match
  37383. }
  37384. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  37385. break; // images don't match
  37386. }
  37387. i += 4;
  37388. }
  37389. // At this point, i is the index of the first op past the last valid
  37390. // quartet.
  37391. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  37392. if (count < MIN_IMAGES_IN_BLOCK) {
  37393. return i;
  37394. }
  37395. // Extract the (x,y) positions from all of the matching transforms.
  37396. var positions = new Float32Array(count * 2);
  37397. var iTransform = iFirstTransform;
  37398. for (var q = 0; q < count; q++, iTransform += 4) {
  37399. var transformArgs = argsArray[iTransform];
  37400. positions[(q << 1)] = transformArgs[4];
  37401. positions[(q << 1) + 1] = transformArgs[5];
  37402. }
  37403. // Replace queue items.
  37404. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  37405. positions];
  37406. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  37407. argsArray.splice(iFirstSave, count * 4, args);
  37408. return iFirstSave + 1;
  37409. });
  37410. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  37411. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  37412. // sequences, if the font for each one is the same.
  37413. addState(InitialState,
  37414. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  37415. function (context) {
  37416. var MIN_CHARS_IN_BLOCK = 3;
  37417. var MAX_CHARS_IN_BLOCK = 1000;
  37418. var fnArray = context.fnArray, argsArray = context.argsArray;
  37419. var curr = context.iCurr;
  37420. var iFirstBeginText = curr - 4;
  37421. var iFirstSetFont = curr - 3;
  37422. var iFirstSetTextMatrix = curr - 2;
  37423. var iFirstShowText = curr - 1;
  37424. var iFirstEndText = curr;
  37425. // Look for the quintets.
  37426. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  37427. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  37428. var i = iFirstBeginText + 5;
  37429. var ii = fnArray.length;
  37430. while (i + 4 < ii) {
  37431. if (fnArray[i] !== OPS.beginText ||
  37432. fnArray[i + 1] !== OPS.setFont ||
  37433. fnArray[i + 2] !== OPS.setTextMatrix ||
  37434. fnArray[i + 3] !== OPS.showText ||
  37435. fnArray[i + 4] !== OPS.endText) {
  37436. break; // ops don't match
  37437. }
  37438. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  37439. argsArray[i + 1][1] !== firstSetFontArg1) {
  37440. break; // fonts don't match
  37441. }
  37442. i += 5;
  37443. }
  37444. // At this point, i is the index of the first op past the last valid
  37445. // quintet.
  37446. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  37447. if (count < MIN_CHARS_IN_BLOCK) {
  37448. return i;
  37449. }
  37450. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  37451. // showText, endText), include that as well. (E.g. <something> might be
  37452. // |dependency|.)
  37453. var iFirst = iFirstBeginText;
  37454. if (iFirstBeginText >= 4 &&
  37455. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  37456. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  37457. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  37458. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  37459. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  37460. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  37461. count++;
  37462. iFirst -= 5;
  37463. }
  37464. // Remove (endText, beginText, setFont) trios.
  37465. var iEndText = iFirst + 4;
  37466. for (var q = 1; q < count; q++) {
  37467. fnArray.splice(iEndText, 3);
  37468. argsArray.splice(iEndText, 3);
  37469. iEndText += 2;
  37470. }
  37471. return iEndText + 1;
  37472. });
  37473. function QueueOptimizer() {}
  37474. QueueOptimizer.prototype = {
  37475. optimize: function QueueOptimizer_optimize(queue) {
  37476. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  37477. var context = {
  37478. iCurr: 0,
  37479. fnArray: fnArray,
  37480. argsArray: argsArray
  37481. };
  37482. var state;
  37483. var i = 0, ii = fnArray.length;
  37484. while (i < ii) {
  37485. state = (state || InitialState)[fnArray[i]];
  37486. if (typeof state === 'function') { // we found some handler
  37487. context.iCurr = i;
  37488. // state() returns the index of the first non-matching op (if we
  37489. // didn't match) or the first op past the modified ops (if we did
  37490. // match and replace).
  37491. i = state(context);
  37492. state = undefined; // reset the state machine
  37493. ii = context.fnArray.length;
  37494. } else {
  37495. i++;
  37496. }
  37497. }
  37498. }
  37499. };
  37500. return QueueOptimizer;
  37501. })();
  37502. exports.OperatorList = OperatorList;
  37503. exports.PartialEvaluator = PartialEvaluator;
  37504. }));
  37505. (function (root, factory) {
  37506. {
  37507. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  37508. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  37509. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  37510. }
  37511. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  37512. coreColorSpace, coreObj, coreEvaluator) {
  37513. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  37514. var AnnotationFlag = sharedUtil.AnnotationFlag;
  37515. var AnnotationType = sharedUtil.AnnotationType;
  37516. var OPS = sharedUtil.OPS;
  37517. var Util = sharedUtil.Util;
  37518. var isArray = sharedUtil.isArray;
  37519. var isInt = sharedUtil.isInt;
  37520. var isValidUrl = sharedUtil.isValidUrl;
  37521. var stringToBytes = sharedUtil.stringToBytes;
  37522. var stringToPDFString = sharedUtil.stringToPDFString;
  37523. var stringToUTF8String = sharedUtil.stringToUTF8String;
  37524. var warn = sharedUtil.warn;
  37525. var Dict = corePrimitives.Dict;
  37526. var isDict = corePrimitives.isDict;
  37527. var isName = corePrimitives.isName;
  37528. var Stream = coreStream.Stream;
  37529. var ColorSpace = coreColorSpace.ColorSpace;
  37530. var ObjectLoader = coreObj.ObjectLoader;
  37531. var OperatorList = coreEvaluator.OperatorList;
  37532. /**
  37533. * @class
  37534. * @alias AnnotationFactory
  37535. */
  37536. function AnnotationFactory() {}
  37537. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  37538. /**
  37539. * @param {XRef} xref
  37540. * @param {Object} ref
  37541. * @returns {Annotation}
  37542. */
  37543. create: function AnnotationFactory_create(xref, ref) {
  37544. var dict = xref.fetchIfRef(ref);
  37545. if (!isDict(dict)) {
  37546. return;
  37547. }
  37548. // Determine the annotation's subtype.
  37549. var subtype = dict.get('Subtype');
  37550. subtype = isName(subtype) ? subtype.name : '';
  37551. // Return the right annotation object based on the subtype and field type.
  37552. var parameters = {
  37553. dict: dict,
  37554. ref: ref
  37555. };
  37556. switch (subtype) {
  37557. case 'Link':
  37558. return new LinkAnnotation(parameters);
  37559. case 'Text':
  37560. return new TextAnnotation(parameters);
  37561. case 'Widget':
  37562. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37563. if (isName(fieldType) && fieldType.name === 'Tx') {
  37564. return new TextWidgetAnnotation(parameters);
  37565. }
  37566. return new WidgetAnnotation(parameters);
  37567. case 'Popup':
  37568. return new PopupAnnotation(parameters);
  37569. case 'Highlight':
  37570. return new HighlightAnnotation(parameters);
  37571. case 'Underline':
  37572. return new UnderlineAnnotation(parameters);
  37573. case 'Squiggly':
  37574. return new SquigglyAnnotation(parameters);
  37575. case 'StrikeOut':
  37576. return new StrikeOutAnnotation(parameters);
  37577. default:
  37578. warn('Unimplemented annotation type "' + subtype + '", ' +
  37579. 'falling back to base annotation');
  37580. return new Annotation(parameters);
  37581. }
  37582. }
  37583. };
  37584. var Annotation = (function AnnotationClosure() {
  37585. // 12.5.5: Algorithm: Appearance streams
  37586. function getTransformMatrix(rect, bbox, matrix) {
  37587. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  37588. var minX = bounds[0];
  37589. var minY = bounds[1];
  37590. var maxX = bounds[2];
  37591. var maxY = bounds[3];
  37592. if (minX === maxX || minY === maxY) {
  37593. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  37594. // just apply the transform for rect
  37595. return [1, 0, 0, 1, rect[0], rect[1]];
  37596. }
  37597. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  37598. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  37599. return [
  37600. xRatio,
  37601. 0,
  37602. 0,
  37603. yRatio,
  37604. rect[0] - minX * xRatio,
  37605. rect[1] - minY * yRatio
  37606. ];
  37607. }
  37608. function getDefaultAppearance(dict) {
  37609. var appearanceState = dict.get('AP');
  37610. if (!isDict(appearanceState)) {
  37611. return;
  37612. }
  37613. var appearance;
  37614. var appearances = appearanceState.get('N');
  37615. if (isDict(appearances)) {
  37616. var as = dict.get('AS');
  37617. if (as && appearances.has(as.name)) {
  37618. appearance = appearances.get(as.name);
  37619. }
  37620. } else {
  37621. appearance = appearances;
  37622. }
  37623. return appearance;
  37624. }
  37625. function Annotation(params) {
  37626. var dict = params.dict;
  37627. this.setFlags(dict.get('F'));
  37628. this.setRectangle(dict.get('Rect'));
  37629. this.setColor(dict.get('C'));
  37630. this.setBorderStyle(dict);
  37631. this.appearance = getDefaultAppearance(dict);
  37632. // Expose public properties using a data object.
  37633. this.data = {};
  37634. this.data.id = params.ref.toString();
  37635. this.data.subtype = dict.get('Subtype').name;
  37636. this.data.annotationFlags = this.flags;
  37637. this.data.rect = this.rectangle;
  37638. this.data.color = this.color;
  37639. this.data.borderStyle = this.borderStyle;
  37640. this.data.hasAppearance = !!this.appearance;
  37641. }
  37642. Annotation.prototype = {
  37643. /**
  37644. * @return {boolean}
  37645. */
  37646. get viewable() {
  37647. if (this.flags) {
  37648. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  37649. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  37650. !this.hasFlag(AnnotationFlag.NOVIEW);
  37651. }
  37652. return true;
  37653. },
  37654. /**
  37655. * @return {boolean}
  37656. */
  37657. get printable() {
  37658. if (this.flags) {
  37659. return this.hasFlag(AnnotationFlag.PRINT) &&
  37660. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  37661. !this.hasFlag(AnnotationFlag.HIDDEN);
  37662. }
  37663. return false;
  37664. },
  37665. /**
  37666. * Set the flags.
  37667. *
  37668. * @public
  37669. * @memberof Annotation
  37670. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  37671. * characteristics
  37672. * @see {@link shared/util.js}
  37673. */
  37674. setFlags: function Annotation_setFlags(flags) {
  37675. if (isInt(flags)) {
  37676. this.flags = flags;
  37677. } else {
  37678. this.flags = 0;
  37679. }
  37680. },
  37681. /**
  37682. * Check if a provided flag is set.
  37683. *
  37684. * @public
  37685. * @memberof Annotation
  37686. * @param {number} flag - Hexadecimal representation for an annotation
  37687. * characteristic
  37688. * @return {boolean}
  37689. * @see {@link shared/util.js}
  37690. */
  37691. hasFlag: function Annotation_hasFlag(flag) {
  37692. if (this.flags) {
  37693. return (this.flags & flag) > 0;
  37694. }
  37695. return false;
  37696. },
  37697. /**
  37698. * Set the rectangle.
  37699. *
  37700. * @public
  37701. * @memberof Annotation
  37702. * @param {Array} rectangle - The rectangle array with exactly four entries
  37703. */
  37704. setRectangle: function Annotation_setRectangle(rectangle) {
  37705. if (isArray(rectangle) && rectangle.length === 4) {
  37706. this.rectangle = Util.normalizeRect(rectangle);
  37707. } else {
  37708. this.rectangle = [0, 0, 0, 0];
  37709. }
  37710. },
  37711. /**
  37712. * Set the color and take care of color space conversion.
  37713. *
  37714. * @public
  37715. * @memberof Annotation
  37716. * @param {Array} color - The color array containing either 0
  37717. * (transparent), 1 (grayscale), 3 (RGB) or
  37718. * 4 (CMYK) elements
  37719. */
  37720. setColor: function Annotation_setColor(color) {
  37721. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  37722. if (!isArray(color)) {
  37723. this.color = rgbColor;
  37724. return;
  37725. }
  37726. switch (color.length) {
  37727. case 0: // Transparent, which we indicate with a null value
  37728. this.color = null;
  37729. break;
  37730. case 1: // Convert grayscale to RGB
  37731. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  37732. this.color = rgbColor;
  37733. break;
  37734. case 3: // Convert RGB percentages to RGB
  37735. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  37736. this.color = rgbColor;
  37737. break;
  37738. case 4: // Convert CMYK to RGB
  37739. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  37740. this.color = rgbColor;
  37741. break;
  37742. default:
  37743. this.color = rgbColor;
  37744. break;
  37745. }
  37746. },
  37747. /**
  37748. * Set the border style (as AnnotationBorderStyle object).
  37749. *
  37750. * @public
  37751. * @memberof Annotation
  37752. * @param {Dict} borderStyle - The border style dictionary
  37753. */
  37754. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  37755. this.borderStyle = new AnnotationBorderStyle();
  37756. if (!isDict(borderStyle)) {
  37757. return;
  37758. }
  37759. if (borderStyle.has('BS')) {
  37760. var dict = borderStyle.get('BS');
  37761. var dictType;
  37762. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  37763. dictType.name === 'Border')) {
  37764. this.borderStyle.setWidth(dict.get('W'));
  37765. this.borderStyle.setStyle(dict.get('S'));
  37766. this.borderStyle.setDashArray(dict.get('D'));
  37767. }
  37768. } else if (borderStyle.has('Border')) {
  37769. var array = borderStyle.get('Border');
  37770. if (isArray(array) && array.length >= 3) {
  37771. this.borderStyle.setHorizontalCornerRadius(array[0]);
  37772. this.borderStyle.setVerticalCornerRadius(array[1]);
  37773. this.borderStyle.setWidth(array[2]);
  37774. if (array.length === 4) { // Dash array available
  37775. this.borderStyle.setDashArray(array[3]);
  37776. }
  37777. }
  37778. } else {
  37779. // There are no border entries in the dictionary. According to the
  37780. // specification, we should draw a solid border of width 1 in that
  37781. // case, but Adobe Reader did not implement that part of the
  37782. // specification and instead draws no border at all, so we do the same.
  37783. // See also https://github.com/mozilla/pdf.js/issues/6179.
  37784. this.borderStyle.setWidth(0);
  37785. }
  37786. },
  37787. loadResources: function Annotation_loadResources(keys) {
  37788. return new Promise(function (resolve, reject) {
  37789. this.appearance.dict.getAsync('Resources').then(function (resources) {
  37790. if (!resources) {
  37791. resolve();
  37792. return;
  37793. }
  37794. var objectLoader = new ObjectLoader(resources.map,
  37795. keys,
  37796. resources.xref);
  37797. objectLoader.load().then(function() {
  37798. resolve(resources);
  37799. }, reject);
  37800. }, reject);
  37801. }.bind(this));
  37802. },
  37803. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  37804. if (!this.appearance) {
  37805. return Promise.resolve(new OperatorList());
  37806. }
  37807. var data = this.data;
  37808. var appearanceDict = this.appearance.dict;
  37809. var resourcesPromise = this.loadResources([
  37810. 'ExtGState',
  37811. 'ColorSpace',
  37812. 'Pattern',
  37813. 'Shading',
  37814. 'XObject',
  37815. 'Font'
  37816. // ProcSet
  37817. // Properties
  37818. ]);
  37819. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  37820. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  37821. var transform = getTransformMatrix(data.rect, bbox, matrix);
  37822. var self = this;
  37823. return resourcesPromise.then(function(resources) {
  37824. var opList = new OperatorList();
  37825. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  37826. return evaluator.getOperatorList(self.appearance, task,
  37827. resources, opList).
  37828. then(function () {
  37829. opList.addOp(OPS.endAnnotation, []);
  37830. self.appearance.reset();
  37831. return opList;
  37832. });
  37833. });
  37834. }
  37835. };
  37836. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  37837. annotations, opList, partialEvaluator, task, intent) {
  37838. var annotationPromises = [];
  37839. for (var i = 0, n = annotations.length; i < n; ++i) {
  37840. if ((intent === 'display' && annotations[i].viewable) ||
  37841. (intent === 'print' && annotations[i].printable)) {
  37842. annotationPromises.push(
  37843. annotations[i].getOperatorList(partialEvaluator, task));
  37844. }
  37845. }
  37846. return Promise.all(annotationPromises).then(function(operatorLists) {
  37847. opList.addOp(OPS.beginAnnotations, []);
  37848. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  37849. opList.addOpList(operatorLists[i]);
  37850. }
  37851. opList.addOp(OPS.endAnnotations, []);
  37852. });
  37853. };
  37854. return Annotation;
  37855. })();
  37856. /**
  37857. * Contains all data regarding an annotation's border style.
  37858. *
  37859. * @class
  37860. */
  37861. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  37862. /**
  37863. * @constructor
  37864. * @private
  37865. */
  37866. function AnnotationBorderStyle() {
  37867. this.width = 1;
  37868. this.style = AnnotationBorderStyleType.SOLID;
  37869. this.dashArray = [3];
  37870. this.horizontalCornerRadius = 0;
  37871. this.verticalCornerRadius = 0;
  37872. }
  37873. AnnotationBorderStyle.prototype = {
  37874. /**
  37875. * Set the width.
  37876. *
  37877. * @public
  37878. * @memberof AnnotationBorderStyle
  37879. * @param {integer} width - The width
  37880. */
  37881. setWidth: function AnnotationBorderStyle_setWidth(width) {
  37882. if (width === (width | 0)) {
  37883. this.width = width;
  37884. }
  37885. },
  37886. /**
  37887. * Set the style.
  37888. *
  37889. * @public
  37890. * @memberof AnnotationBorderStyle
  37891. * @param {Object} style - The style object
  37892. * @see {@link shared/util.js}
  37893. */
  37894. setStyle: function AnnotationBorderStyle_setStyle(style) {
  37895. if (!style) {
  37896. return;
  37897. }
  37898. switch (style.name) {
  37899. case 'S':
  37900. this.style = AnnotationBorderStyleType.SOLID;
  37901. break;
  37902. case 'D':
  37903. this.style = AnnotationBorderStyleType.DASHED;
  37904. break;
  37905. case 'B':
  37906. this.style = AnnotationBorderStyleType.BEVELED;
  37907. break;
  37908. case 'I':
  37909. this.style = AnnotationBorderStyleType.INSET;
  37910. break;
  37911. case 'U':
  37912. this.style = AnnotationBorderStyleType.UNDERLINE;
  37913. break;
  37914. default:
  37915. break;
  37916. }
  37917. },
  37918. /**
  37919. * Set the dash array.
  37920. *
  37921. * @public
  37922. * @memberof AnnotationBorderStyle
  37923. * @param {Array} dashArray - The dash array with at least one element
  37924. */
  37925. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  37926. // We validate the dash array, but we do not use it because CSS does not
  37927. // allow us to change spacing of dashes. For more information, visit
  37928. // http://www.w3.org/TR/css3-background/#the-border-style.
  37929. if (isArray(dashArray) && dashArray.length > 0) {
  37930. // According to the PDF specification: the elements in a dashArray
  37931. // shall be numbers that are nonnegative and not all equal to zero.
  37932. var isValid = true;
  37933. var allZeros = true;
  37934. for (var i = 0, len = dashArray.length; i < len; i++) {
  37935. var element = dashArray[i];
  37936. var validNumber = (+element >= 0);
  37937. if (!validNumber) {
  37938. isValid = false;
  37939. break;
  37940. } else if (element > 0) {
  37941. allZeros = false;
  37942. }
  37943. }
  37944. if (isValid && !allZeros) {
  37945. this.dashArray = dashArray;
  37946. } else {
  37947. this.width = 0; // Adobe behavior when the array is invalid.
  37948. }
  37949. } else if (dashArray) {
  37950. this.width = 0; // Adobe behavior when the array is invalid.
  37951. }
  37952. },
  37953. /**
  37954. * Set the horizontal corner radius (from a Border dictionary).
  37955. *
  37956. * @public
  37957. * @memberof AnnotationBorderStyle
  37958. * @param {integer} radius - The horizontal corner radius
  37959. */
  37960. setHorizontalCornerRadius:
  37961. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  37962. if (radius === (radius | 0)) {
  37963. this.horizontalCornerRadius = radius;
  37964. }
  37965. },
  37966. /**
  37967. * Set the vertical corner radius (from a Border dictionary).
  37968. *
  37969. * @public
  37970. * @memberof AnnotationBorderStyle
  37971. * @param {integer} radius - The vertical corner radius
  37972. */
  37973. setVerticalCornerRadius:
  37974. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  37975. if (radius === (radius | 0)) {
  37976. this.verticalCornerRadius = radius;
  37977. }
  37978. }
  37979. };
  37980. return AnnotationBorderStyle;
  37981. })();
  37982. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  37983. function WidgetAnnotation(params) {
  37984. Annotation.call(this, params);
  37985. var dict = params.dict;
  37986. var data = this.data;
  37987. data.annotationType = AnnotationType.WIDGET;
  37988. data.fieldValue = stringToPDFString(
  37989. Util.getInheritableProperty(dict, 'V') || '');
  37990. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  37991. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  37992. var fieldType = Util.getInheritableProperty(dict, 'FT');
  37993. data.fieldType = isName(fieldType) ? fieldType.name : '';
  37994. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  37995. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  37996. // Hide unsupported Widget signatures.
  37997. if (data.fieldType === 'Sig') {
  37998. warn('unimplemented annotation type: Widget signature');
  37999. this.setFlags(AnnotationFlag.HIDDEN);
  38000. }
  38001. // Building the full field name by collecting the field and
  38002. // its ancestors 'T' data and joining them using '.'.
  38003. var fieldName = [];
  38004. var namedItem = dict;
  38005. var ref = params.ref;
  38006. while (namedItem) {
  38007. var parent = namedItem.get('Parent');
  38008. var parentRef = namedItem.getRaw('Parent');
  38009. var name = namedItem.get('T');
  38010. if (name) {
  38011. fieldName.unshift(stringToPDFString(name));
  38012. } else if (parent && ref) {
  38013. // The field name is absent, that means more than one field
  38014. // with the same name may exist. Replacing the empty name
  38015. // with the '`' plus index in the parent's 'Kids' array.
  38016. // This is not in the PDF spec but necessary to id the
  38017. // the input controls.
  38018. var kids = parent.get('Kids');
  38019. var j, jj;
  38020. for (j = 0, jj = kids.length; j < jj; j++) {
  38021. var kidRef = kids[j];
  38022. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  38023. break;
  38024. }
  38025. }
  38026. fieldName.unshift('`' + j);
  38027. }
  38028. namedItem = parent;
  38029. ref = parentRef;
  38030. }
  38031. data.fullName = fieldName.join('.');
  38032. }
  38033. Util.inherit(WidgetAnnotation, Annotation, {});
  38034. return WidgetAnnotation;
  38035. })();
  38036. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  38037. function TextWidgetAnnotation(params) {
  38038. WidgetAnnotation.call(this, params);
  38039. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  38040. }
  38041. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  38042. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  38043. task) {
  38044. if (this.appearance) {
  38045. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  38046. }
  38047. var opList = new OperatorList();
  38048. var data = this.data;
  38049. // Even if there is an appearance stream, ignore it. This is the
  38050. // behaviour used by Adobe Reader.
  38051. if (!data.defaultAppearance) {
  38052. return Promise.resolve(opList);
  38053. }
  38054. var stream = new Stream(stringToBytes(data.defaultAppearance));
  38055. return evaluator.getOperatorList(stream, task,
  38056. this.fieldResources, opList).
  38057. then(function () {
  38058. return opList;
  38059. });
  38060. }
  38061. });
  38062. return TextWidgetAnnotation;
  38063. })();
  38064. var TextAnnotation = (function TextAnnotationClosure() {
  38065. var DEFAULT_ICON_SIZE = 22; // px
  38066. function TextAnnotation(parameters) {
  38067. Annotation.call(this, parameters);
  38068. this.data.annotationType = AnnotationType.TEXT;
  38069. var dict = parameters.dict;
  38070. if (this.data.hasAppearance) {
  38071. this.data.name = 'NoIcon';
  38072. } else {
  38073. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  38074. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  38075. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  38076. }
  38077. if (!dict.has('C')) {
  38078. // Fall back to the default background color.
  38079. this.data.color = null;
  38080. }
  38081. this.data.hasPopup = dict.has('Popup');
  38082. if (!this.data.hasPopup) {
  38083. // There is no associated Popup annotation, so the Text annotation
  38084. // must create its own popup.
  38085. this.data.title = stringToPDFString(dict.get('T') || '');
  38086. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  38087. }
  38088. }
  38089. Util.inherit(TextAnnotation, Annotation, {});
  38090. return TextAnnotation;
  38091. })();
  38092. var LinkAnnotation = (function LinkAnnotationClosure() {
  38093. function LinkAnnotation(params) {
  38094. Annotation.call(this, params);
  38095. var dict = params.dict;
  38096. var data = this.data;
  38097. data.annotationType = AnnotationType.LINK;
  38098. var action = dict.get('A');
  38099. if (action && isDict(action)) {
  38100. var linkType = action.get('S').name;
  38101. if (linkType === 'URI') {
  38102. var url = action.get('URI');
  38103. if (isName(url)) {
  38104. // Some bad PDFs do not put parentheses around relative URLs.
  38105. url = '/' + url.name;
  38106. } else if (url) {
  38107. url = addDefaultProtocolToUrl(url);
  38108. }
  38109. // TODO: pdf spec mentions urls can be relative to a Base
  38110. // entry in the dictionary.
  38111. if (!isValidUrl(url, false)) {
  38112. url = '';
  38113. }
  38114. // According to ISO 32000-1:2008, section 12.6.4.7,
  38115. // URI should to be encoded in 7-bit ASCII.
  38116. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  38117. try {
  38118. data.url = stringToUTF8String(url);
  38119. } catch (e) {
  38120. // Fall back to a simple copy.
  38121. data.url = url;
  38122. }
  38123. } else if (linkType === 'GoTo') {
  38124. data.dest = action.get('D');
  38125. } else if (linkType === 'GoToR') {
  38126. var urlDict = action.get('F');
  38127. if (isDict(urlDict)) {
  38128. // We assume that the 'url' is a Filspec dictionary
  38129. // and fetch the url without checking any further
  38130. url = urlDict.get('F') || '';
  38131. }
  38132. // TODO: pdf reference says that GoToR
  38133. // can also have 'NewWindow' attribute
  38134. if (!isValidUrl(url, false)) {
  38135. url = '';
  38136. }
  38137. data.url = url;
  38138. data.dest = action.get('D');
  38139. } else if (linkType === 'Named') {
  38140. data.action = action.get('N').name;
  38141. } else {
  38142. warn('unrecognized link type: ' + linkType);
  38143. }
  38144. } else if (dict.has('Dest')) {
  38145. // simple destination link
  38146. var dest = dict.get('Dest');
  38147. data.dest = isName(dest) ? dest.name : dest;
  38148. }
  38149. }
  38150. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  38151. function addDefaultProtocolToUrl(url) {
  38152. if (url && url.indexOf('www.') === 0) {
  38153. return ('http://' + url);
  38154. }
  38155. return url;
  38156. }
  38157. Util.inherit(LinkAnnotation, Annotation, {});
  38158. return LinkAnnotation;
  38159. })();
  38160. var PopupAnnotation = (function PopupAnnotationClosure() {
  38161. function PopupAnnotation(parameters) {
  38162. Annotation.call(this, parameters);
  38163. this.data.annotationType = AnnotationType.POPUP;
  38164. var dict = parameters.dict;
  38165. var parentItem = dict.get('Parent');
  38166. if (!parentItem) {
  38167. warn('Popup annotation has a missing or invalid parent annotation.');
  38168. return;
  38169. }
  38170. this.data.parentId = dict.getRaw('Parent').toString();
  38171. this.data.title = stringToPDFString(parentItem.get('T') || '');
  38172. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  38173. if (!parentItem.has('C')) {
  38174. // Fall back to the default background color.
  38175. this.data.color = null;
  38176. } else {
  38177. this.setColor(parentItem.get('C'));
  38178. this.data.color = this.color;
  38179. }
  38180. }
  38181. Util.inherit(PopupAnnotation, Annotation, {});
  38182. return PopupAnnotation;
  38183. })();
  38184. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  38185. function HighlightAnnotation(parameters) {
  38186. Annotation.call(this, parameters);
  38187. this.data.annotationType = AnnotationType.HIGHLIGHT;
  38188. this.data.hasPopup = parameters.dict.has('Popup');
  38189. // PDF viewers completely ignore any border styles.
  38190. this.data.borderStyle.setWidth(0);
  38191. }
  38192. Util.inherit(HighlightAnnotation, Annotation, {});
  38193. return HighlightAnnotation;
  38194. })();
  38195. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  38196. function UnderlineAnnotation(parameters) {
  38197. Annotation.call(this, parameters);
  38198. this.data.annotationType = AnnotationType.UNDERLINE;
  38199. this.data.hasPopup = parameters.dict.has('Popup');
  38200. // PDF viewers completely ignore any border styles.
  38201. this.data.borderStyle.setWidth(0);
  38202. }
  38203. Util.inherit(UnderlineAnnotation, Annotation, {});
  38204. return UnderlineAnnotation;
  38205. })();
  38206. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  38207. function SquigglyAnnotation(parameters) {
  38208. Annotation.call(this, parameters);
  38209. this.data.annotationType = AnnotationType.SQUIGGLY;
  38210. this.data.hasPopup = parameters.dict.has('Popup');
  38211. // PDF viewers completely ignore any border styles.
  38212. this.data.borderStyle.setWidth(0);
  38213. }
  38214. Util.inherit(SquigglyAnnotation, Annotation, {});
  38215. return SquigglyAnnotation;
  38216. })();
  38217. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  38218. function StrikeOutAnnotation(parameters) {
  38219. Annotation.call(this, parameters);
  38220. this.data.annotationType = AnnotationType.STRIKEOUT;
  38221. this.data.hasPopup = parameters.dict.has('Popup');
  38222. // PDF viewers completely ignore any border styles.
  38223. this.data.borderStyle.setWidth(0);
  38224. }
  38225. Util.inherit(StrikeOutAnnotation, Annotation, {});
  38226. return StrikeOutAnnotation;
  38227. })();
  38228. exports.Annotation = Annotation;
  38229. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  38230. exports.AnnotationFactory = AnnotationFactory;
  38231. }));
  38232. (function (root, factory) {
  38233. {
  38234. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  38235. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  38236. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  38237. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  38238. }
  38239. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  38240. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  38241. var MissingDataException = sharedUtil.MissingDataException;
  38242. var Util = sharedUtil.Util;
  38243. var assert = sharedUtil.assert;
  38244. var error = sharedUtil.error;
  38245. var info = sharedUtil.info;
  38246. var isArray = sharedUtil.isArray;
  38247. var isArrayBuffer = sharedUtil.isArrayBuffer;
  38248. var isString = sharedUtil.isString;
  38249. var shadow = sharedUtil.shadow;
  38250. var stringToBytes = sharedUtil.stringToBytes;
  38251. var stringToPDFString = sharedUtil.stringToPDFString;
  38252. var warn = sharedUtil.warn;
  38253. var Dict = corePrimitives.Dict;
  38254. var isDict = corePrimitives.isDict;
  38255. var isName = corePrimitives.isName;
  38256. var isStream = corePrimitives.isStream;
  38257. var NullStream = coreStream.NullStream;
  38258. var Stream = coreStream.Stream;
  38259. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  38260. var Catalog = coreObj.Catalog;
  38261. var ObjectLoader = coreObj.ObjectLoader;
  38262. var XRef = coreObj.XRef;
  38263. var Lexer = coreParser.Lexer;
  38264. var Linearization = coreParser.Linearization;
  38265. var calculateMD5 = coreCrypto.calculateMD5;
  38266. var OperatorList = coreEvaluator.OperatorList;
  38267. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  38268. var Annotation = coreAnnotation.Annotation;
  38269. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  38270. var Page = (function PageClosure() {
  38271. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  38272. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  38273. this.pdfManager = pdfManager;
  38274. this.pageIndex = pageIndex;
  38275. this.pageDict = pageDict;
  38276. this.xref = xref;
  38277. this.ref = ref;
  38278. this.fontCache = fontCache;
  38279. this.idCounters = {
  38280. obj: 0
  38281. };
  38282. this.resourcesPromise = null;
  38283. }
  38284. Page.prototype = {
  38285. getPageProp: function Page_getPageProp(key) {
  38286. return this.pageDict.get(key);
  38287. },
  38288. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  38289. var dict = this.pageDict, valueArray = null, loopCount = 0;
  38290. var MAX_LOOP_COUNT = 100;
  38291. // Always walk up the entire parent chain, to be able to find
  38292. // e.g. \Resources placed on multiple levels of the tree.
  38293. while (dict) {
  38294. var value = dict.get(key);
  38295. if (value) {
  38296. if (!valueArray) {
  38297. valueArray = [];
  38298. }
  38299. valueArray.push(value);
  38300. }
  38301. if (++loopCount > MAX_LOOP_COUNT) {
  38302. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  38303. break;
  38304. }
  38305. dict = dict.get('Parent');
  38306. }
  38307. if (!valueArray) {
  38308. return Dict.empty;
  38309. }
  38310. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  38311. loopCount > MAX_LOOP_COUNT) {
  38312. return valueArray[0];
  38313. }
  38314. return Dict.merge(this.xref, valueArray);
  38315. },
  38316. get content() {
  38317. return this.getPageProp('Contents');
  38318. },
  38319. get resources() {
  38320. // For robustness: The spec states that a \Resources entry has to be
  38321. // present, but can be empty. Some document omit it still, in this case
  38322. // we return an empty dictionary.
  38323. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  38324. },
  38325. get mediaBox() {
  38326. var obj = this.getInheritedPageProp('MediaBox');
  38327. // Reset invalid media box to letter size.
  38328. if (!isArray(obj) || obj.length !== 4) {
  38329. obj = LETTER_SIZE_MEDIABOX;
  38330. }
  38331. return shadow(this, 'mediaBox', obj);
  38332. },
  38333. get view() {
  38334. var mediaBox = this.mediaBox;
  38335. var cropBox = this.getInheritedPageProp('CropBox');
  38336. if (!isArray(cropBox) || cropBox.length !== 4) {
  38337. return shadow(this, 'view', mediaBox);
  38338. }
  38339. // From the spec, 6th ed., p.963:
  38340. // "The crop, bleed, trim, and art boxes should not ordinarily
  38341. // extend beyond the boundaries of the media box. If they do, they are
  38342. // effectively reduced to their intersection with the media box."
  38343. cropBox = Util.intersect(cropBox, mediaBox);
  38344. if (!cropBox) {
  38345. return shadow(this, 'view', mediaBox);
  38346. }
  38347. return shadow(this, 'view', cropBox);
  38348. },
  38349. get rotate() {
  38350. var rotate = this.getInheritedPageProp('Rotate') || 0;
  38351. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  38352. if (rotate % 90 !== 0) {
  38353. rotate = 0;
  38354. } else if (rotate >= 360) {
  38355. rotate = rotate % 360;
  38356. } else if (rotate < 0) {
  38357. // The spec doesn't cover negatives, assume its counterclockwise
  38358. // rotation. The following is the other implementation of modulo.
  38359. rotate = ((rotate % 360) + 360) % 360;
  38360. }
  38361. return shadow(this, 'rotate', rotate);
  38362. },
  38363. getContentStream: function Page_getContentStream() {
  38364. var content = this.content;
  38365. var stream;
  38366. if (isArray(content)) {
  38367. // fetching items
  38368. var xref = this.xref;
  38369. var i, n = content.length;
  38370. var streams = [];
  38371. for (i = 0; i < n; ++i) {
  38372. streams.push(xref.fetchIfRef(content[i]));
  38373. }
  38374. stream = new StreamsSequenceStream(streams);
  38375. } else if (isStream(content)) {
  38376. stream = content;
  38377. } else {
  38378. // replacing non-existent page content with empty one
  38379. stream = new NullStream();
  38380. }
  38381. return stream;
  38382. },
  38383. loadResources: function Page_loadResources(keys) {
  38384. if (!this.resourcesPromise) {
  38385. // TODO: add async getInheritedPageProp and remove this.
  38386. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  38387. }
  38388. return this.resourcesPromise.then(function resourceSuccess() {
  38389. var objectLoader = new ObjectLoader(this.resources.map,
  38390. keys,
  38391. this.xref);
  38392. return objectLoader.load();
  38393. }.bind(this));
  38394. },
  38395. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  38396. var self = this;
  38397. var pdfManager = this.pdfManager;
  38398. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38399. []);
  38400. var resourcesPromise = this.loadResources([
  38401. 'ExtGState',
  38402. 'ColorSpace',
  38403. 'Pattern',
  38404. 'Shading',
  38405. 'XObject',
  38406. 'Font'
  38407. // ProcSet
  38408. // Properties
  38409. ]);
  38410. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  38411. handler, this.pageIndex,
  38412. 'p' + this.pageIndex + '_',
  38413. this.idCounters,
  38414. this.fontCache);
  38415. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  38416. var pageListPromise = dataPromises.then(function(data) {
  38417. var contentStream = data[0];
  38418. var opList = new OperatorList(intent, handler, self.pageIndex);
  38419. handler.send('StartRenderPage', {
  38420. transparency: partialEvaluator.hasBlendModes(self.resources),
  38421. pageIndex: self.pageIndex,
  38422. intent: intent
  38423. });
  38424. return partialEvaluator.getOperatorList(contentStream, task,
  38425. self.resources, opList).then(function () {
  38426. return opList;
  38427. });
  38428. });
  38429. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  38430. return Promise.all([pageListPromise, annotationsPromise]).then(
  38431. function(datas) {
  38432. var pageOpList = datas[0];
  38433. var annotations = datas[1];
  38434. if (annotations.length === 0) {
  38435. pageOpList.flush(true);
  38436. return pageOpList;
  38437. }
  38438. var annotationsReadyPromise = Annotation.appendToOperatorList(
  38439. annotations, pageOpList, partialEvaluator, task, intent);
  38440. return annotationsReadyPromise.then(function () {
  38441. pageOpList.flush(true);
  38442. return pageOpList;
  38443. });
  38444. });
  38445. },
  38446. extractTextContent: function Page_extractTextContent(task,
  38447. normalizeWhitespace) {
  38448. var handler = {
  38449. on: function nullHandlerOn() {},
  38450. send: function nullHandlerSend() {}
  38451. };
  38452. var self = this;
  38453. var pdfManager = this.pdfManager;
  38454. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  38455. []);
  38456. var resourcesPromise = this.loadResources([
  38457. 'ExtGState',
  38458. 'XObject',
  38459. 'Font'
  38460. ]);
  38461. var dataPromises = Promise.all([contentStreamPromise,
  38462. resourcesPromise]);
  38463. return dataPromises.then(function(data) {
  38464. var contentStream = data[0];
  38465. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  38466. handler, self.pageIndex,
  38467. 'p' + self.pageIndex + '_',
  38468. self.idCounters,
  38469. self.fontCache);
  38470. return partialEvaluator.getTextContent(contentStream,
  38471. task,
  38472. self.resources,
  38473. /* stateManager = */ null,
  38474. normalizeWhitespace);
  38475. });
  38476. },
  38477. getAnnotationsData: function Page_getAnnotationsData(intent) {
  38478. var annotations = this.annotations;
  38479. var annotationsData = [];
  38480. for (var i = 0, n = annotations.length; i < n; ++i) {
  38481. if (intent) {
  38482. if (!(intent === 'display' && annotations[i].viewable) &&
  38483. !(intent === 'print' && annotations[i].printable)) {
  38484. continue;
  38485. }
  38486. }
  38487. annotationsData.push(annotations[i].data);
  38488. }
  38489. return annotationsData;
  38490. },
  38491. get annotations() {
  38492. var annotations = [];
  38493. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  38494. var annotationFactory = new AnnotationFactory();
  38495. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  38496. var annotationRef = annotationRefs[i];
  38497. var annotation = annotationFactory.create(this.xref, annotationRef);
  38498. if (annotation) {
  38499. annotations.push(annotation);
  38500. }
  38501. }
  38502. return shadow(this, 'annotations', annotations);
  38503. }
  38504. };
  38505. return Page;
  38506. })();
  38507. /**
  38508. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  38509. * `PDFDoc`, this one doesn't have any job management code.
  38510. * Right now there exists one PDFDocument on the main thread + one object
  38511. * for each worker. If there is no worker support enabled, there are two
  38512. * `PDFDocument` objects on the main thread created.
  38513. */
  38514. var PDFDocument = (function PDFDocumentClosure() {
  38515. var FINGERPRINT_FIRST_BYTES = 1024;
  38516. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  38517. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  38518. function PDFDocument(pdfManager, arg, password) {
  38519. if (isStream(arg)) {
  38520. init.call(this, pdfManager, arg, password);
  38521. } else if (isArrayBuffer(arg)) {
  38522. init.call(this, pdfManager, new Stream(arg), password);
  38523. } else {
  38524. error('PDFDocument: Unknown argument type');
  38525. }
  38526. }
  38527. function init(pdfManager, stream, password) {
  38528. assert(stream.length > 0, 'stream must have data');
  38529. this.pdfManager = pdfManager;
  38530. this.stream = stream;
  38531. var xref = new XRef(this.stream, password, pdfManager);
  38532. this.xref = xref;
  38533. }
  38534. function find(stream, needle, limit, backwards) {
  38535. var pos = stream.pos;
  38536. var end = stream.end;
  38537. var strBuf = [];
  38538. if (pos + limit > end) {
  38539. limit = end - pos;
  38540. }
  38541. for (var n = 0; n < limit; ++n) {
  38542. strBuf.push(String.fromCharCode(stream.getByte()));
  38543. }
  38544. var str = strBuf.join('');
  38545. stream.pos = pos;
  38546. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  38547. if (index === -1) {
  38548. return false; /* not found */
  38549. }
  38550. stream.pos += index;
  38551. return true; /* found */
  38552. }
  38553. var DocumentInfoValidators = {
  38554. get entries() {
  38555. // Lazily build this since all the validation functions below are not
  38556. // defined until after this file loads.
  38557. return shadow(this, 'entries', {
  38558. Title: isString,
  38559. Author: isString,
  38560. Subject: isString,
  38561. Keywords: isString,
  38562. Creator: isString,
  38563. Producer: isString,
  38564. CreationDate: isString,
  38565. ModDate: isString,
  38566. Trapped: isName
  38567. });
  38568. }
  38569. };
  38570. PDFDocument.prototype = {
  38571. parse: function PDFDocument_parse(recoveryMode) {
  38572. this.setup(recoveryMode);
  38573. var version = this.catalog.catDict.get('Version');
  38574. if (isName(version)) {
  38575. this.pdfFormatVersion = version.name;
  38576. }
  38577. try {
  38578. // checking if AcroForm is present
  38579. this.acroForm = this.catalog.catDict.get('AcroForm');
  38580. if (this.acroForm) {
  38581. this.xfa = this.acroForm.get('XFA');
  38582. var fields = this.acroForm.get('Fields');
  38583. if ((!fields || !isArray(fields) || fields.length === 0) &&
  38584. !this.xfa) {
  38585. // no fields and no XFA -- not a form (?)
  38586. this.acroForm = null;
  38587. }
  38588. }
  38589. } catch (ex) {
  38590. info('Something wrong with AcroForm entry');
  38591. this.acroForm = null;
  38592. }
  38593. },
  38594. get linearization() {
  38595. var linearization = null;
  38596. if (this.stream.length) {
  38597. try {
  38598. linearization = Linearization.create(this.stream);
  38599. } catch (err) {
  38600. if (err instanceof MissingDataException) {
  38601. throw err;
  38602. }
  38603. info(err);
  38604. }
  38605. }
  38606. // shadow the prototype getter with a data property
  38607. return shadow(this, 'linearization', linearization);
  38608. },
  38609. get startXRef() {
  38610. var stream = this.stream;
  38611. var startXRef = 0;
  38612. var linearization = this.linearization;
  38613. if (linearization) {
  38614. // Find end of first obj.
  38615. stream.reset();
  38616. if (find(stream, 'endobj', 1024)) {
  38617. startXRef = stream.pos + 6;
  38618. }
  38619. } else {
  38620. // Find startxref by jumping backward from the end of the file.
  38621. var step = 1024;
  38622. var found = false, pos = stream.end;
  38623. while (!found && pos > 0) {
  38624. pos -= step - 'startxref'.length;
  38625. if (pos < 0) {
  38626. pos = 0;
  38627. }
  38628. stream.pos = pos;
  38629. found = find(stream, 'startxref', step, true);
  38630. }
  38631. if (found) {
  38632. stream.skip(9);
  38633. var ch;
  38634. do {
  38635. ch = stream.getByte();
  38636. } while (Lexer.isSpace(ch));
  38637. var str = '';
  38638. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  38639. str += String.fromCharCode(ch);
  38640. ch = stream.getByte();
  38641. }
  38642. startXRef = parseInt(str, 10);
  38643. if (isNaN(startXRef)) {
  38644. startXRef = 0;
  38645. }
  38646. }
  38647. }
  38648. // shadow the prototype getter with a data property
  38649. return shadow(this, 'startXRef', startXRef);
  38650. },
  38651. get mainXRefEntriesOffset() {
  38652. var mainXRefEntriesOffset = 0;
  38653. var linearization = this.linearization;
  38654. if (linearization) {
  38655. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  38656. }
  38657. // shadow the prototype getter with a data property
  38658. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  38659. },
  38660. // Find the header, remove leading garbage and setup the stream
  38661. // starting from the header.
  38662. checkHeader: function PDFDocument_checkHeader() {
  38663. var stream = this.stream;
  38664. stream.reset();
  38665. if (find(stream, '%PDF-', 1024)) {
  38666. // Found the header, trim off any garbage before it.
  38667. stream.moveStart();
  38668. // Reading file format version
  38669. var MAX_VERSION_LENGTH = 12;
  38670. var version = '', ch;
  38671. while ((ch = stream.getByte()) > 0x20) { // SPACE
  38672. if (version.length >= MAX_VERSION_LENGTH) {
  38673. break;
  38674. }
  38675. version += String.fromCharCode(ch);
  38676. }
  38677. if (!this.pdfFormatVersion) {
  38678. // removing "%PDF-"-prefix
  38679. this.pdfFormatVersion = version.substring(5);
  38680. }
  38681. return;
  38682. }
  38683. // May not be a PDF file, continue anyway.
  38684. },
  38685. parseStartXRef: function PDFDocument_parseStartXRef() {
  38686. var startXRef = this.startXRef;
  38687. this.xref.setStartXRef(startXRef);
  38688. },
  38689. setup: function PDFDocument_setup(recoveryMode) {
  38690. this.xref.parse(recoveryMode);
  38691. var self = this;
  38692. var pageFactory = {
  38693. createPage: function (pageIndex, dict, ref, fontCache) {
  38694. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  38695. fontCache);
  38696. }
  38697. };
  38698. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  38699. },
  38700. get numPages() {
  38701. var linearization = this.linearization;
  38702. var num = linearization ? linearization.numPages : this.catalog.numPages;
  38703. // shadow the prototype getter
  38704. return shadow(this, 'numPages', num);
  38705. },
  38706. get documentInfo() {
  38707. var docInfo = {
  38708. PDFFormatVersion: this.pdfFormatVersion,
  38709. IsAcroFormPresent: !!this.acroForm,
  38710. IsXFAPresent: !!this.xfa
  38711. };
  38712. var infoDict;
  38713. try {
  38714. infoDict = this.xref.trailer.get('Info');
  38715. } catch (err) {
  38716. info('The document information dictionary is invalid.');
  38717. }
  38718. if (infoDict) {
  38719. var validEntries = DocumentInfoValidators.entries;
  38720. // Only fill the document info with valid entries from the spec.
  38721. for (var key in validEntries) {
  38722. if (infoDict.has(key)) {
  38723. var value = infoDict.get(key);
  38724. // Make sure the value conforms to the spec.
  38725. if (validEntries[key](value)) {
  38726. docInfo[key] = (typeof value !== 'string' ?
  38727. value : stringToPDFString(value));
  38728. } else {
  38729. info('Bad value in document info for "' + key + '"');
  38730. }
  38731. }
  38732. }
  38733. }
  38734. return shadow(this, 'documentInfo', docInfo);
  38735. },
  38736. get fingerprint() {
  38737. var xref = this.xref, hash, fileID = '';
  38738. var idArray = xref.trailer.get('ID');
  38739. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  38740. idArray[0] !== EMPTY_FINGERPRINT) {
  38741. hash = stringToBytes(idArray[0]);
  38742. } else {
  38743. if (this.stream.ensureRange) {
  38744. this.stream.ensureRange(0,
  38745. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  38746. }
  38747. hash = calculateMD5(this.stream.bytes.subarray(0,
  38748. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  38749. }
  38750. for (var i = 0, n = hash.length; i < n; i++) {
  38751. var hex = hash[i].toString(16);
  38752. fileID += hex.length === 1 ? '0' + hex : hex;
  38753. }
  38754. return shadow(this, 'fingerprint', fileID);
  38755. },
  38756. getPage: function PDFDocument_getPage(pageIndex) {
  38757. return this.catalog.getPage(pageIndex);
  38758. },
  38759. cleanup: function PDFDocument_cleanup() {
  38760. return this.catalog.cleanup();
  38761. }
  38762. };
  38763. return PDFDocument;
  38764. })();
  38765. exports.Page = Page;
  38766. exports.PDFDocument = PDFDocument;
  38767. }));
  38768. (function (root, factory) {
  38769. {
  38770. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  38771. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  38772. root.pdfjsCoreDocument);
  38773. }
  38774. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  38775. coreDocument) {
  38776. var NotImplementedException = sharedUtil.NotImplementedException;
  38777. var MissingDataException = sharedUtil.MissingDataException;
  38778. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38779. var Util = sharedUtil.Util;
  38780. var Stream = coreStream.Stream;
  38781. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  38782. var PDFDocument = coreDocument.PDFDocument;
  38783. var BasePdfManager = (function BasePdfManagerClosure() {
  38784. function BasePdfManager() {
  38785. throw new Error('Cannot initialize BaseManagerManager');
  38786. }
  38787. BasePdfManager.prototype = {
  38788. get docId() {
  38789. return this._docId;
  38790. },
  38791. onLoadedStream: function BasePdfManager_onLoadedStream() {
  38792. throw new NotImplementedException();
  38793. },
  38794. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  38795. return this.ensure(this.pdfDocument, prop, args);
  38796. },
  38797. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  38798. return this.ensure(this.pdfDocument.xref, prop, args);
  38799. },
  38800. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  38801. return this.ensure(this.pdfDocument.catalog, prop, args);
  38802. },
  38803. getPage: function BasePdfManager_getPage(pageIndex) {
  38804. return this.pdfDocument.getPage(pageIndex);
  38805. },
  38806. cleanup: function BasePdfManager_cleanup() {
  38807. return this.pdfDocument.cleanup();
  38808. },
  38809. ensure: function BasePdfManager_ensure(obj, prop, args) {
  38810. return new NotImplementedException();
  38811. },
  38812. requestRange: function BasePdfManager_requestRange(begin, end) {
  38813. return new NotImplementedException();
  38814. },
  38815. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  38816. return new NotImplementedException();
  38817. },
  38818. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  38819. return new NotImplementedException();
  38820. },
  38821. updatePassword: function BasePdfManager_updatePassword(password) {
  38822. this.pdfDocument.xref.password = this.password = password;
  38823. if (this._passwordChangedCapability) {
  38824. this._passwordChangedCapability.resolve();
  38825. }
  38826. },
  38827. passwordChanged: function BasePdfManager_passwordChanged() {
  38828. this._passwordChangedCapability = createPromiseCapability();
  38829. return this._passwordChangedCapability.promise;
  38830. },
  38831. terminate: function BasePdfManager_terminate() {
  38832. return new NotImplementedException();
  38833. }
  38834. };
  38835. return BasePdfManager;
  38836. })();
  38837. var LocalPdfManager = (function LocalPdfManagerClosure() {
  38838. function LocalPdfManager(docId, data, password) {
  38839. this._docId = docId;
  38840. var stream = new Stream(data);
  38841. this.pdfDocument = new PDFDocument(this, stream, password);
  38842. this._loadedStreamCapability = createPromiseCapability();
  38843. this._loadedStreamCapability.resolve(stream);
  38844. }
  38845. Util.inherit(LocalPdfManager, BasePdfManager, {
  38846. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  38847. return new Promise(function (resolve, reject) {
  38848. try {
  38849. var value = obj[prop];
  38850. var result;
  38851. if (typeof value === 'function') {
  38852. result = value.apply(obj, args);
  38853. } else {
  38854. result = value;
  38855. }
  38856. resolve(result);
  38857. } catch (e) {
  38858. reject(e);
  38859. }
  38860. });
  38861. },
  38862. requestRange: function LocalPdfManager_requestRange(begin, end) {
  38863. return Promise.resolve();
  38864. },
  38865. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  38866. return;
  38867. },
  38868. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  38869. return this._loadedStreamCapability.promise;
  38870. },
  38871. terminate: function LocalPdfManager_terminate() {
  38872. return;
  38873. }
  38874. });
  38875. return LocalPdfManager;
  38876. })();
  38877. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  38878. function NetworkPdfManager(docId, args, msgHandler) {
  38879. this._docId = docId;
  38880. this.msgHandler = msgHandler;
  38881. var params = {
  38882. msgHandler: msgHandler,
  38883. httpHeaders: args.httpHeaders,
  38884. withCredentials: args.withCredentials,
  38885. chunkedViewerLoading: args.chunkedViewerLoading,
  38886. disableAutoFetch: args.disableAutoFetch,
  38887. initialData: args.initialData
  38888. };
  38889. this.streamManager = new ChunkedStreamManager(args.length,
  38890. args.rangeChunkSize,
  38891. args.url, params);
  38892. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  38893. args.password);
  38894. }
  38895. Util.inherit(NetworkPdfManager, BasePdfManager, {
  38896. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  38897. var pdfManager = this;
  38898. return new Promise(function (resolve, reject) {
  38899. function ensureHelper() {
  38900. try {
  38901. var result;
  38902. var value = obj[prop];
  38903. if (typeof value === 'function') {
  38904. result = value.apply(obj, args);
  38905. } else {
  38906. result = value;
  38907. }
  38908. resolve(result);
  38909. } catch(e) {
  38910. if (!(e instanceof MissingDataException)) {
  38911. reject(e);
  38912. return;
  38913. }
  38914. pdfManager.streamManager.requestRange(e.begin, e.end).
  38915. then(ensureHelper, reject);
  38916. }
  38917. }
  38918. ensureHelper();
  38919. });
  38920. },
  38921. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  38922. return this.streamManager.requestRange(begin, end);
  38923. },
  38924. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  38925. this.streamManager.requestAllChunks();
  38926. },
  38927. sendProgressiveData:
  38928. function NetworkPdfManager_sendProgressiveData(chunk) {
  38929. this.streamManager.onReceiveData({ chunk: chunk });
  38930. },
  38931. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  38932. return this.streamManager.onLoadedStream();
  38933. },
  38934. terminate: function NetworkPdfManager_terminate() {
  38935. this.streamManager.abort();
  38936. }
  38937. });
  38938. return NetworkPdfManager;
  38939. })();
  38940. exports.LocalPdfManager = LocalPdfManager;
  38941. exports.NetworkPdfManager = NetworkPdfManager;
  38942. }));
  38943. (function (root, factory) {
  38944. {
  38945. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  38946. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  38947. root.pdfjsSharedGlobal);
  38948. }
  38949. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  38950. sharedGlobal) {
  38951. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  38952. var InvalidPDFException = sharedUtil.InvalidPDFException;
  38953. var MessageHandler = sharedUtil.MessageHandler;
  38954. var MissingPDFException = sharedUtil.MissingPDFException;
  38955. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  38956. var PasswordException = sharedUtil.PasswordException;
  38957. var PasswordResponses = sharedUtil.PasswordResponses;
  38958. var UnknownErrorException = sharedUtil.UnknownErrorException;
  38959. var XRefParseException = sharedUtil.XRefParseException;
  38960. var createPromiseCapability = sharedUtil.createPromiseCapability;
  38961. var error = sharedUtil.error;
  38962. var info = sharedUtil.info;
  38963. var isInt = sharedUtil.isInt;
  38964. var warn = sharedUtil.warn;
  38965. var Ref = corePrimitives.Ref;
  38966. var LocalPdfManager = corePdfManager.LocalPdfManager;
  38967. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  38968. var globalScope = sharedGlobal.globalScope;
  38969. var PDFJS = sharedGlobal.PDFJS;
  38970. var WorkerTask = (function WorkerTaskClosure() {
  38971. function WorkerTask(name) {
  38972. this.name = name;
  38973. this.terminated = false;
  38974. this._capability = createPromiseCapability();
  38975. }
  38976. WorkerTask.prototype = {
  38977. get finished() {
  38978. return this._capability.promise;
  38979. },
  38980. finish: function () {
  38981. this._capability.resolve();
  38982. },
  38983. terminate: function () {
  38984. this.terminated = true;
  38985. },
  38986. ensureNotTerminated: function () {
  38987. if (this.terminated) {
  38988. throw new Error('Worker task was terminated');
  38989. }
  38990. }
  38991. };
  38992. return WorkerTask;
  38993. })();
  38994. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  38995. setup: function wphSetup(handler, port) {
  38996. var testMessageProcessed = false;
  38997. handler.on('test', function wphSetupTest(data) {
  38998. if (testMessageProcessed) {
  38999. return; // we already processed 'test' message once
  39000. }
  39001. testMessageProcessed = true;
  39002. // check if Uint8Array can be sent to worker
  39003. if (!(data instanceof Uint8Array)) {
  39004. handler.send('test', 'main', false);
  39005. return;
  39006. }
  39007. // making sure postMessage transfers are working
  39008. var supportTransfers = data[0] === 255;
  39009. handler.postMessageTransfers = supportTransfers;
  39010. // check if the response property is supported by xhr
  39011. var xhr = new XMLHttpRequest();
  39012. var responseExists = 'response' in xhr;
  39013. // check if the property is actually implemented
  39014. try {
  39015. var dummy = xhr.responseType;
  39016. } catch (e) {
  39017. responseExists = false;
  39018. }
  39019. if (!responseExists) {
  39020. handler.send('test', false);
  39021. return;
  39022. }
  39023. handler.send('test', {
  39024. supportTypedArray: true,
  39025. supportTransfers: supportTransfers
  39026. });
  39027. });
  39028. handler.on('GetDocRequest', function wphSetupDoc(data) {
  39029. return WorkerMessageHandler.createDocumentHandler(data, port);
  39030. });
  39031. },
  39032. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  39033. // This context is actually holds references on pdfManager and handler,
  39034. // until the latter is destroyed.
  39035. var pdfManager;
  39036. var terminated = false;
  39037. var cancelXHRs = null;
  39038. var WorkerTasks = [];
  39039. var docId = docParams.docId;
  39040. var workerHandlerName = docParams.docId + '_worker';
  39041. var handler = new MessageHandler(workerHandlerName, docId, port);
  39042. function ensureNotTerminated() {
  39043. if (terminated) {
  39044. throw new Error('Worker was terminated');
  39045. }
  39046. }
  39047. function startWorkerTask(task) {
  39048. WorkerTasks.push(task);
  39049. }
  39050. function finishWorkerTask(task) {
  39051. task.finish();
  39052. var i = WorkerTasks.indexOf(task);
  39053. WorkerTasks.splice(i, 1);
  39054. }
  39055. function loadDocument(recoveryMode) {
  39056. var loadDocumentCapability = createPromiseCapability();
  39057. var parseSuccess = function parseSuccess() {
  39058. var numPagesPromise = pdfManager.ensureDoc('numPages');
  39059. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  39060. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  39061. Promise.all([numPagesPromise, fingerprintPromise,
  39062. encryptedPromise]).then(function onDocReady(results) {
  39063. var doc = {
  39064. numPages: results[0],
  39065. fingerprint: results[1],
  39066. encrypted: !!results[2],
  39067. };
  39068. loadDocumentCapability.resolve(doc);
  39069. },
  39070. parseFailure);
  39071. };
  39072. var parseFailure = function parseFailure(e) {
  39073. loadDocumentCapability.reject(e);
  39074. };
  39075. pdfManager.ensureDoc('checkHeader', []).then(function() {
  39076. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  39077. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  39078. parseSuccess, parseFailure);
  39079. }, parseFailure);
  39080. }, parseFailure);
  39081. return loadDocumentCapability.promise;
  39082. }
  39083. function getPdfManager(data) {
  39084. var pdfManagerCapability = createPromiseCapability();
  39085. var pdfManager;
  39086. var source = data.source;
  39087. var disableRange = data.disableRange;
  39088. if (source.data) {
  39089. try {
  39090. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  39091. pdfManagerCapability.resolve(pdfManager);
  39092. } catch (ex) {
  39093. pdfManagerCapability.reject(ex);
  39094. }
  39095. return pdfManagerCapability.promise;
  39096. } else if (source.chunkedViewerLoading) {
  39097. try {
  39098. pdfManager = new NetworkPdfManager(docId, source, handler);
  39099. pdfManagerCapability.resolve(pdfManager);
  39100. } catch (ex) {
  39101. pdfManagerCapability.reject(ex);
  39102. }
  39103. return pdfManagerCapability.promise;
  39104. }
  39105. var networkManager = new NetworkManager(source.url, {
  39106. httpHeaders: source.httpHeaders,
  39107. withCredentials: source.withCredentials
  39108. });
  39109. var cachedChunks = [];
  39110. var fullRequestXhrId = networkManager.requestFull({
  39111. onHeadersReceived: function onHeadersReceived() {
  39112. if (disableRange) {
  39113. return;
  39114. }
  39115. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  39116. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  39117. return;
  39118. }
  39119. var contentEncoding =
  39120. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  39121. if (contentEncoding !== 'identity') {
  39122. return;
  39123. }
  39124. var length = fullRequestXhr.getResponseHeader('Content-Length');
  39125. length = parseInt(length, 10);
  39126. if (!isInt(length)) {
  39127. return;
  39128. }
  39129. source.length = length;
  39130. if (length <= 2 * source.rangeChunkSize) {
  39131. // The file size is smaller than the size of two chunks, so it does
  39132. // not make any sense to abort the request and retry with a range
  39133. // request.
  39134. return;
  39135. }
  39136. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  39137. // We can continue fetching when progressive loading is enabled,
  39138. // and we don't need the autoFetch feature.
  39139. source.disableAutoFetch = true;
  39140. } else {
  39141. // NOTE: by cancelling the full request, and then issuing range
  39142. // requests, there will be an issue for sites where you can only
  39143. // request the pdf once. However, if this is the case, then the
  39144. // server should not be returning that it can support range
  39145. // requests.
  39146. networkManager.abortRequest(fullRequestXhrId);
  39147. }
  39148. try {
  39149. pdfManager = new NetworkPdfManager(docId, source, handler);
  39150. pdfManagerCapability.resolve(pdfManager);
  39151. } catch (ex) {
  39152. pdfManagerCapability.reject(ex);
  39153. }
  39154. cancelXHRs = null;
  39155. },
  39156. onProgressiveData: source.disableStream ? null :
  39157. function onProgressiveData(chunk) {
  39158. if (!pdfManager) {
  39159. cachedChunks.push(chunk);
  39160. return;
  39161. }
  39162. pdfManager.sendProgressiveData(chunk);
  39163. },
  39164. onDone: function onDone(args) {
  39165. if (pdfManager) {
  39166. return; // already processed
  39167. }
  39168. var pdfFile;
  39169. if (args === null) {
  39170. // TODO add some streaming manager, e.g. for unknown length files.
  39171. // The data was returned in the onProgressiveData, combining...
  39172. var pdfFileLength = 0, pos = 0;
  39173. cachedChunks.forEach(function (chunk) {
  39174. pdfFileLength += chunk.byteLength;
  39175. });
  39176. if (source.length && pdfFileLength !== source.length) {
  39177. warn('reported HTTP length is different from actual');
  39178. }
  39179. var pdfFileArray = new Uint8Array(pdfFileLength);
  39180. cachedChunks.forEach(function (chunk) {
  39181. pdfFileArray.set(new Uint8Array(chunk), pos);
  39182. pos += chunk.byteLength;
  39183. });
  39184. pdfFile = pdfFileArray.buffer;
  39185. } else {
  39186. pdfFile = args.chunk;
  39187. }
  39188. // the data is array, instantiating directly from it
  39189. try {
  39190. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  39191. pdfManagerCapability.resolve(pdfManager);
  39192. } catch (ex) {
  39193. pdfManagerCapability.reject(ex);
  39194. }
  39195. cancelXHRs = null;
  39196. },
  39197. onError: function onError(status) {
  39198. var exception;
  39199. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  39200. exception = new MissingPDFException('Missing PDF "' +
  39201. source.url + '".');
  39202. handler.send('MissingPDF', exception);
  39203. } else {
  39204. exception = new UnexpectedResponseException(
  39205. 'Unexpected server response (' + status +
  39206. ') while retrieving PDF "' + source.url + '".', status);
  39207. handler.send('UnexpectedResponse', exception);
  39208. }
  39209. cancelXHRs = null;
  39210. },
  39211. onProgress: function onProgress(evt) {
  39212. handler.send('DocProgress', {
  39213. loaded: evt.loaded,
  39214. total: evt.lengthComputable ? evt.total : source.length
  39215. });
  39216. }
  39217. });
  39218. cancelXHRs = function () {
  39219. networkManager.abortRequest(fullRequestXhrId);
  39220. };
  39221. return pdfManagerCapability.promise;
  39222. }
  39223. var setupDoc = function(data) {
  39224. var onSuccess = function(doc) {
  39225. ensureNotTerminated();
  39226. handler.send('GetDoc', { pdfInfo: doc });
  39227. };
  39228. var onFailure = function(e) {
  39229. if (e instanceof PasswordException) {
  39230. if (e.code === PasswordResponses.NEED_PASSWORD) {
  39231. handler.send('NeedPassword', e);
  39232. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  39233. handler.send('IncorrectPassword', e);
  39234. }
  39235. } else if (e instanceof InvalidPDFException) {
  39236. handler.send('InvalidPDF', e);
  39237. } else if (e instanceof MissingPDFException) {
  39238. handler.send('MissingPDF', e);
  39239. } else if (e instanceof UnexpectedResponseException) {
  39240. handler.send('UnexpectedResponse', e);
  39241. } else {
  39242. handler.send('UnknownError',
  39243. new UnknownErrorException(e.message, e.toString()));
  39244. }
  39245. };
  39246. ensureNotTerminated();
  39247. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  39248. -1 : data.maxImageSize;
  39249. PDFJS.disableFontFace = data.disableFontFace;
  39250. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  39251. PDFJS.verbosity = data.verbosity;
  39252. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  39253. null : data.cMapUrl;
  39254. PDFJS.cMapPacked = data.cMapPacked === true;
  39255. getPdfManager(data).then(function (newPdfManager) {
  39256. if (terminated) {
  39257. // We were in a process of setting up the manager, but it got
  39258. // terminated in the middle.
  39259. newPdfManager.terminate();
  39260. throw new Error('Worker was terminated');
  39261. }
  39262. pdfManager = newPdfManager;
  39263. handler.send('PDFManagerReady', null);
  39264. pdfManager.onLoadedStream().then(function(stream) {
  39265. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  39266. });
  39267. }).then(function pdfManagerReady() {
  39268. ensureNotTerminated();
  39269. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  39270. ensureNotTerminated();
  39271. // Try again with recoveryMode == true
  39272. if (!(ex instanceof XRefParseException)) {
  39273. if (ex instanceof PasswordException) {
  39274. // after password exception prepare to receive a new password
  39275. // to repeat loading
  39276. pdfManager.passwordChanged().then(pdfManagerReady);
  39277. }
  39278. onFailure(ex);
  39279. return;
  39280. }
  39281. pdfManager.requestLoadedStream();
  39282. pdfManager.onLoadedStream().then(function() {
  39283. ensureNotTerminated();
  39284. loadDocument(true).then(onSuccess, onFailure);
  39285. });
  39286. }, onFailure);
  39287. }, onFailure);
  39288. };
  39289. handler.on('GetPage', function wphSetupGetPage(data) {
  39290. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39291. var rotatePromise = pdfManager.ensure(page, 'rotate');
  39292. var refPromise = pdfManager.ensure(page, 'ref');
  39293. var viewPromise = pdfManager.ensure(page, 'view');
  39294. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  39295. function(results) {
  39296. return {
  39297. rotate: results[0],
  39298. ref: results[1],
  39299. view: results[2]
  39300. };
  39301. });
  39302. });
  39303. });
  39304. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  39305. var ref = new Ref(data.ref.num, data.ref.gen);
  39306. var catalog = pdfManager.pdfDocument.catalog;
  39307. return catalog.getPageIndex(ref);
  39308. });
  39309. handler.on('GetDestinations',
  39310. function wphSetupGetDestinations(data) {
  39311. return pdfManager.ensureCatalog('destinations');
  39312. }
  39313. );
  39314. handler.on('GetDestination',
  39315. function wphSetupGetDestination(data) {
  39316. return pdfManager.ensureCatalog('getDestination', [data.id]);
  39317. }
  39318. );
  39319. handler.on('GetPageLabels',
  39320. function wphSetupGetPageLabels(data) {
  39321. return pdfManager.ensureCatalog('pageLabels');
  39322. }
  39323. );
  39324. handler.on('GetAttachments',
  39325. function wphSetupGetAttachments(data) {
  39326. return pdfManager.ensureCatalog('attachments');
  39327. }
  39328. );
  39329. handler.on('GetJavaScript',
  39330. function wphSetupGetJavaScript(data) {
  39331. return pdfManager.ensureCatalog('javaScript');
  39332. }
  39333. );
  39334. handler.on('GetOutline',
  39335. function wphSetupGetOutline(data) {
  39336. return pdfManager.ensureCatalog('documentOutline');
  39337. }
  39338. );
  39339. handler.on('GetMetadata',
  39340. function wphSetupGetMetadata(data) {
  39341. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  39342. pdfManager.ensureCatalog('metadata')]);
  39343. }
  39344. );
  39345. handler.on('GetData', function wphSetupGetData(data) {
  39346. pdfManager.requestLoadedStream();
  39347. return pdfManager.onLoadedStream().then(function(stream) {
  39348. return stream.bytes;
  39349. });
  39350. });
  39351. handler.on('GetStats',
  39352. function wphSetupGetStats(data) {
  39353. return pdfManager.pdfDocument.xref.stats;
  39354. }
  39355. );
  39356. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  39357. pdfManager.updatePassword(data);
  39358. });
  39359. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  39360. return pdfManager.getPage(data.pageIndex).then(function(page) {
  39361. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  39362. });
  39363. });
  39364. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  39365. var pageIndex = data.pageIndex;
  39366. pdfManager.getPage(pageIndex).then(function(page) {
  39367. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  39368. startWorkerTask(task);
  39369. var pageNum = pageIndex + 1;
  39370. var start = Date.now();
  39371. // Pre compile the pdf page and fetch the fonts/images.
  39372. page.getOperatorList(handler, task, data.intent).then(
  39373. function(operatorList) {
  39374. finishWorkerTask(task);
  39375. info('page=' + pageNum + ' - getOperatorList: time=' +
  39376. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  39377. }, function(e) {
  39378. finishWorkerTask(task);
  39379. if (task.terminated) {
  39380. return; // ignoring errors from the terminated thread
  39381. }
  39382. // For compatibility with older behavior, generating unknown
  39383. // unsupported feature notification on errors.
  39384. handler.send('UnsupportedFeature',
  39385. {featureId: UNSUPPORTED_FEATURES.unknown});
  39386. var minimumStackMessage =
  39387. 'worker.js: while trying to getPage() and getOperatorList()';
  39388. var wrappedException;
  39389. // Turn the error into an obj that can be serialized
  39390. if (typeof e === 'string') {
  39391. wrappedException = {
  39392. message: e,
  39393. stack: minimumStackMessage
  39394. };
  39395. } else if (typeof e === 'object') {
  39396. wrappedException = {
  39397. message: e.message || e.toString(),
  39398. stack: e.stack || minimumStackMessage
  39399. };
  39400. } else {
  39401. wrappedException = {
  39402. message: 'Unknown exception type: ' + (typeof e),
  39403. stack: minimumStackMessage
  39404. };
  39405. }
  39406. handler.send('PageError', {
  39407. pageNum: pageNum,
  39408. error: wrappedException,
  39409. intent: data.intent
  39410. });
  39411. });
  39412. });
  39413. }, this);
  39414. handler.on('GetTextContent', function wphExtractText(data) {
  39415. var pageIndex = data.pageIndex;
  39416. var normalizeWhitespace = data.normalizeWhitespace;
  39417. return pdfManager.getPage(pageIndex).then(function(page) {
  39418. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  39419. startWorkerTask(task);
  39420. var pageNum = pageIndex + 1;
  39421. var start = Date.now();
  39422. return page.extractTextContent(task, normalizeWhitespace).then(
  39423. function(textContent) {
  39424. finishWorkerTask(task);
  39425. info('text indexing: page=' + pageNum + ' - time=' +
  39426. (Date.now() - start) + 'ms');
  39427. return textContent;
  39428. }, function (reason) {
  39429. finishWorkerTask(task);
  39430. if (task.terminated) {
  39431. return; // ignoring errors from the terminated thread
  39432. }
  39433. throw reason;
  39434. });
  39435. });
  39436. });
  39437. handler.on('Cleanup', function wphCleanup(data) {
  39438. return pdfManager.cleanup();
  39439. });
  39440. handler.on('Terminate', function wphTerminate(data) {
  39441. terminated = true;
  39442. if (pdfManager) {
  39443. pdfManager.terminate();
  39444. pdfManager = null;
  39445. }
  39446. if (cancelXHRs) {
  39447. cancelXHRs();
  39448. }
  39449. var waitOn = [];
  39450. WorkerTasks.forEach(function (task) {
  39451. waitOn.push(task.finished);
  39452. task.terminate();
  39453. });
  39454. return Promise.all(waitOn).then(function () {
  39455. // Notice that even if we destroying handler, resolved response promise
  39456. // must be sent back.
  39457. handler.destroy();
  39458. handler = null;
  39459. });
  39460. });
  39461. handler.on('Ready', function wphReady(data) {
  39462. setupDoc(docParams);
  39463. docParams = null; // we don't need docParams anymore -- saving memory.
  39464. });
  39465. return workerHandlerName;
  39466. }
  39467. };
  39468. function initializeWorker() {
  39469. if (!('console' in globalScope)) {
  39470. var consoleTimer = {};
  39471. var workerConsole = {
  39472. log: function log() {
  39473. var args = Array.prototype.slice.call(arguments);
  39474. globalScope.postMessage({
  39475. targetName: 'main',
  39476. action: 'console_log',
  39477. data: args
  39478. });
  39479. },
  39480. error: function error() {
  39481. var args = Array.prototype.slice.call(arguments);
  39482. globalScope.postMessage({
  39483. targetName: 'main',
  39484. action: 'console_error',
  39485. data: args
  39486. });
  39487. throw 'pdf.js execution error';
  39488. },
  39489. time: function time(name) {
  39490. consoleTimer[name] = Date.now();
  39491. },
  39492. timeEnd: function timeEnd(name) {
  39493. var time = consoleTimer[name];
  39494. if (!time) {
  39495. error('Unknown timer name ' + name);
  39496. }
  39497. this.log('Timer:', name, Date.now() - time);
  39498. }
  39499. };
  39500. globalScope.console = workerConsole;
  39501. }
  39502. var handler = new MessageHandler('worker', 'main', self);
  39503. WorkerMessageHandler.setup(handler, self);
  39504. handler.send('ready', null);
  39505. }
  39506. // Worker thread (and not node.js)?
  39507. if (typeof window === 'undefined' &&
  39508. !(typeof module !== 'undefined' && module.require)) {
  39509. initializeWorker();
  39510. }
  39511. exports.WorkerTask = WorkerTask;
  39512. exports.WorkerMessageHandler = WorkerMessageHandler;
  39513. }));
  39514. }).call(pdfjsLibs);
  39515. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  39516. }));