pdf.combined.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147
  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.combined', ['exports'], factory);
  21. } else if (typeof exports !== 'undefined') {
  22. factory(exports);
  23. } else {
  24. factory((root.pdfjsDistBuildPdfCombined = {}));
  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.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  2151. }
  2152. }(this, function (exports, sharedGlobal) {
  2153. var PDFJS = sharedGlobal.PDFJS;
  2154. /**
  2155. * Optimised CSS custom property getter/setter.
  2156. * @class
  2157. */
  2158. var CustomStyle = (function CustomStyleClosure() {
  2159. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  2160. // animate-css-transforms-firefox-webkit.html
  2161. // in some versions of IE9 it is critical that ms appear in this list
  2162. // before Moz
  2163. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  2164. var _cache = Object.create(null);
  2165. function CustomStyle() {}
  2166. CustomStyle.getProp = function get(propName, element) {
  2167. // check cache only when no element is given
  2168. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  2169. return _cache[propName];
  2170. }
  2171. element = element || document.documentElement;
  2172. var style = element.style, prefixed, uPropName;
  2173. // test standard property first
  2174. if (typeof style[propName] === 'string') {
  2175. return (_cache[propName] = propName);
  2176. }
  2177. // capitalize
  2178. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  2179. // test vendor specific properties
  2180. for (var i = 0, l = prefixes.length; i < l; i++) {
  2181. prefixed = prefixes[i] + uPropName;
  2182. if (typeof style[prefixed] === 'string') {
  2183. return (_cache[propName] = prefixed);
  2184. }
  2185. }
  2186. //if all fails then set to undefined
  2187. return (_cache[propName] = 'undefined');
  2188. };
  2189. CustomStyle.setProp = function set(propName, element, str) {
  2190. var prop = this.getProp(propName);
  2191. if (prop !== 'undefined') {
  2192. element.style[prop] = str;
  2193. }
  2194. };
  2195. return CustomStyle;
  2196. })();
  2197. PDFJS.CustomStyle = CustomStyle;
  2198. exports.CustomStyle = CustomStyle;
  2199. }));
  2200. (function (root, factory) {
  2201. {
  2202. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  2203. }
  2204. }(this, function (exports, sharedGlobal) {
  2205. var PDFJS = sharedGlobal.PDFJS;
  2206. var globalScope = sharedGlobal.globalScope;
  2207. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  2208. var TextRenderingMode = {
  2209. FILL: 0,
  2210. STROKE: 1,
  2211. FILL_STROKE: 2,
  2212. INVISIBLE: 3,
  2213. FILL_ADD_TO_PATH: 4,
  2214. STROKE_ADD_TO_PATH: 5,
  2215. FILL_STROKE_ADD_TO_PATH: 6,
  2216. ADD_TO_PATH: 7,
  2217. FILL_STROKE_MASK: 3,
  2218. ADD_TO_PATH_FLAG: 4
  2219. };
  2220. var ImageKind = {
  2221. GRAYSCALE_1BPP: 1,
  2222. RGB_24BPP: 2,
  2223. RGBA_32BPP: 3
  2224. };
  2225. var AnnotationType = {
  2226. TEXT: 1,
  2227. LINK: 2,
  2228. FREETEXT: 3,
  2229. LINE: 4,
  2230. SQUARE: 5,
  2231. CIRCLE: 6,
  2232. POLYGON: 7,
  2233. POLYLINE: 8,
  2234. HIGHLIGHT: 9,
  2235. UNDERLINE: 10,
  2236. SQUIGGLY: 11,
  2237. STRIKEOUT: 12,
  2238. STAMP: 13,
  2239. CARET: 14,
  2240. INK: 15,
  2241. POPUP: 16,
  2242. FILEATTACHMENT: 17,
  2243. SOUND: 18,
  2244. MOVIE: 19,
  2245. WIDGET: 20,
  2246. SCREEN: 21,
  2247. PRINTERMARK: 22,
  2248. TRAPNET: 23,
  2249. WATERMARK: 24,
  2250. THREED: 25,
  2251. REDACT: 26
  2252. };
  2253. var AnnotationFlag = {
  2254. INVISIBLE: 0x01,
  2255. HIDDEN: 0x02,
  2256. PRINT: 0x04,
  2257. NOZOOM: 0x08,
  2258. NOROTATE: 0x10,
  2259. NOVIEW: 0x20,
  2260. READONLY: 0x40,
  2261. LOCKED: 0x80,
  2262. TOGGLENOVIEW: 0x100,
  2263. LOCKEDCONTENTS: 0x200
  2264. };
  2265. var AnnotationBorderStyleType = {
  2266. SOLID: 1,
  2267. DASHED: 2,
  2268. BEVELED: 3,
  2269. INSET: 4,
  2270. UNDERLINE: 5
  2271. };
  2272. var StreamType = {
  2273. UNKNOWN: 0,
  2274. FLATE: 1,
  2275. LZW: 2,
  2276. DCT: 3,
  2277. JPX: 4,
  2278. JBIG: 5,
  2279. A85: 6,
  2280. AHX: 7,
  2281. CCF: 8,
  2282. RL: 9
  2283. };
  2284. var FontType = {
  2285. UNKNOWN: 0,
  2286. TYPE1: 1,
  2287. TYPE1C: 2,
  2288. CIDFONTTYPE0: 3,
  2289. CIDFONTTYPE0C: 4,
  2290. TRUETYPE: 5,
  2291. CIDFONTTYPE2: 6,
  2292. TYPE3: 7,
  2293. OPENTYPE: 8,
  2294. TYPE0: 9,
  2295. MMTYPE1: 10
  2296. };
  2297. PDFJS.VERBOSITY_LEVELS = {
  2298. errors: 0,
  2299. warnings: 1,
  2300. infos: 5
  2301. };
  2302. // All the possible operations for an operator list.
  2303. var OPS = PDFJS.OPS = {
  2304. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2305. // 0's.
  2306. dependency: 1,
  2307. setLineWidth: 2,
  2308. setLineCap: 3,
  2309. setLineJoin: 4,
  2310. setMiterLimit: 5,
  2311. setDash: 6,
  2312. setRenderingIntent: 7,
  2313. setFlatness: 8,
  2314. setGState: 9,
  2315. save: 10,
  2316. restore: 11,
  2317. transform: 12,
  2318. moveTo: 13,
  2319. lineTo: 14,
  2320. curveTo: 15,
  2321. curveTo2: 16,
  2322. curveTo3: 17,
  2323. closePath: 18,
  2324. rectangle: 19,
  2325. stroke: 20,
  2326. closeStroke: 21,
  2327. fill: 22,
  2328. eoFill: 23,
  2329. fillStroke: 24,
  2330. eoFillStroke: 25,
  2331. closeFillStroke: 26,
  2332. closeEOFillStroke: 27,
  2333. endPath: 28,
  2334. clip: 29,
  2335. eoClip: 30,
  2336. beginText: 31,
  2337. endText: 32,
  2338. setCharSpacing: 33,
  2339. setWordSpacing: 34,
  2340. setHScale: 35,
  2341. setLeading: 36,
  2342. setFont: 37,
  2343. setTextRenderingMode: 38,
  2344. setTextRise: 39,
  2345. moveText: 40,
  2346. setLeadingMoveText: 41,
  2347. setTextMatrix: 42,
  2348. nextLine: 43,
  2349. showText: 44,
  2350. showSpacedText: 45,
  2351. nextLineShowText: 46,
  2352. nextLineSetSpacingShowText: 47,
  2353. setCharWidth: 48,
  2354. setCharWidthAndBounds: 49,
  2355. setStrokeColorSpace: 50,
  2356. setFillColorSpace: 51,
  2357. setStrokeColor: 52,
  2358. setStrokeColorN: 53,
  2359. setFillColor: 54,
  2360. setFillColorN: 55,
  2361. setStrokeGray: 56,
  2362. setFillGray: 57,
  2363. setStrokeRGBColor: 58,
  2364. setFillRGBColor: 59,
  2365. setStrokeCMYKColor: 60,
  2366. setFillCMYKColor: 61,
  2367. shadingFill: 62,
  2368. beginInlineImage: 63,
  2369. beginImageData: 64,
  2370. endInlineImage: 65,
  2371. paintXObject: 66,
  2372. markPoint: 67,
  2373. markPointProps: 68,
  2374. beginMarkedContent: 69,
  2375. beginMarkedContentProps: 70,
  2376. endMarkedContent: 71,
  2377. beginCompat: 72,
  2378. endCompat: 73,
  2379. paintFormXObjectBegin: 74,
  2380. paintFormXObjectEnd: 75,
  2381. beginGroup: 76,
  2382. endGroup: 77,
  2383. beginAnnotations: 78,
  2384. endAnnotations: 79,
  2385. beginAnnotation: 80,
  2386. endAnnotation: 81,
  2387. paintJpegXObject: 82,
  2388. paintImageMaskXObject: 83,
  2389. paintImageMaskXObjectGroup: 84,
  2390. paintImageXObject: 85,
  2391. paintInlineImageXObject: 86,
  2392. paintInlineImageXObjectGroup: 87,
  2393. paintImageXObjectRepeat: 88,
  2394. paintImageMaskXObjectRepeat: 89,
  2395. paintSolidColorImageMask: 90,
  2396. constructPath: 91
  2397. };
  2398. // A notice for devs. These are good for things that are helpful to devs, such
  2399. // as warning that Workers were disabled, which is important to devs but not
  2400. // end users.
  2401. function info(msg) {
  2402. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  2403. console.log('Info: ' + msg);
  2404. }
  2405. }
  2406. // Non-fatal warnings.
  2407. function warn(msg) {
  2408. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  2409. console.log('Warning: ' + msg);
  2410. }
  2411. }
  2412. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2413. function deprecated(details) {
  2414. console.log('Deprecated API usage: ' + details);
  2415. }
  2416. // Fatal errors that should trigger the fallback UI and halt execution by
  2417. // throwing an exception.
  2418. function error(msg) {
  2419. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  2420. console.log('Error: ' + msg);
  2421. console.log(backtrace());
  2422. }
  2423. throw new Error(msg);
  2424. }
  2425. function backtrace() {
  2426. try {
  2427. throw new Error();
  2428. } catch (e) {
  2429. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2430. }
  2431. }
  2432. function assert(cond, msg) {
  2433. if (!cond) {
  2434. error(msg);
  2435. }
  2436. }
  2437. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  2438. unknown: 'unknown',
  2439. forms: 'forms',
  2440. javaScript: 'javaScript',
  2441. smask: 'smask',
  2442. shadingPattern: 'shadingPattern',
  2443. font: 'font'
  2444. };
  2445. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  2446. // absolute URL, it will be returned as is.
  2447. function combineUrl(baseUrl, url) {
  2448. if (!url) {
  2449. return baseUrl;
  2450. }
  2451. return new URL(url, baseUrl).href;
  2452. }
  2453. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2454. function isSameOrigin(baseUrl, otherUrl) {
  2455. try {
  2456. var base = new URL(baseUrl);
  2457. if (!base.origin || base.origin === 'null') {
  2458. return false; // non-HTTP url
  2459. }
  2460. } catch (e) {
  2461. return false;
  2462. }
  2463. var other = new URL(otherUrl, base);
  2464. return base.origin === other.origin;
  2465. }
  2466. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2467. function isValidUrl(url, allowRelative) {
  2468. if (!url) {
  2469. return false;
  2470. }
  2471. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2472. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2473. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2474. if (!protocol) {
  2475. return allowRelative;
  2476. }
  2477. protocol = protocol[0].toLowerCase();
  2478. switch (protocol) {
  2479. case 'http':
  2480. case 'https':
  2481. case 'ftp':
  2482. case 'mailto':
  2483. case 'tel':
  2484. return true;
  2485. default:
  2486. return false;
  2487. }
  2488. }
  2489. PDFJS.isValidUrl = isValidUrl;
  2490. /**
  2491. * Adds various attributes (href, title, target, rel) to hyperlinks.
  2492. * @param {HTMLLinkElement} link - The link element.
  2493. * @param {Object} params - An object with the properties:
  2494. * @param {string} params.url - An absolute URL.
  2495. */
  2496. function addLinkAttributes(link, params) {
  2497. var url = params && params.url;
  2498. link.href = link.title = (url ? removeNullCharacters(url) : '');
  2499. if (url) {
  2500. if (isExternalLinkTargetSet()) {
  2501. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  2502. }
  2503. // Strip referrer from the URL.
  2504. link.rel = PDFJS.externalLinkRel;
  2505. }
  2506. }
  2507. PDFJS.addLinkAttributes = addLinkAttributes;
  2508. function shadow(obj, prop, value) {
  2509. Object.defineProperty(obj, prop, { value: value,
  2510. enumerable: true,
  2511. configurable: true,
  2512. writable: false });
  2513. return value;
  2514. }
  2515. PDFJS.shadow = shadow;
  2516. function getLookupTableFactory(initializer) {
  2517. var lookup;
  2518. return function () {
  2519. if (initializer) {
  2520. lookup = Object.create(null);
  2521. initializer(lookup);
  2522. initializer = null;
  2523. }
  2524. return lookup;
  2525. };
  2526. }
  2527. var LinkTarget = PDFJS.LinkTarget = {
  2528. NONE: 0, // Default value.
  2529. SELF: 1,
  2530. BLANK: 2,
  2531. PARENT: 3,
  2532. TOP: 4,
  2533. };
  2534. var LinkTargetStringMap = [
  2535. '',
  2536. '_self',
  2537. '_blank',
  2538. '_parent',
  2539. '_top'
  2540. ];
  2541. function isExternalLinkTargetSet() {
  2542. if (PDFJS.openExternalLinksInNewWindow) {
  2543. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  2544. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  2545. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  2546. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  2547. }
  2548. // Reset the deprecated parameter, to suppress further warnings.
  2549. PDFJS.openExternalLinksInNewWindow = false;
  2550. }
  2551. switch (PDFJS.externalLinkTarget) {
  2552. case LinkTarget.NONE:
  2553. return false;
  2554. case LinkTarget.SELF:
  2555. case LinkTarget.BLANK:
  2556. case LinkTarget.PARENT:
  2557. case LinkTarget.TOP:
  2558. return true;
  2559. }
  2560. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  2561. // Reset the external link target, to suppress further warnings.
  2562. PDFJS.externalLinkTarget = LinkTarget.NONE;
  2563. return false;
  2564. }
  2565. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  2566. var PasswordResponses = PDFJS.PasswordResponses = {
  2567. NEED_PASSWORD: 1,
  2568. INCORRECT_PASSWORD: 2
  2569. };
  2570. var PasswordException = (function PasswordExceptionClosure() {
  2571. function PasswordException(msg, code) {
  2572. this.name = 'PasswordException';
  2573. this.message = msg;
  2574. this.code = code;
  2575. }
  2576. PasswordException.prototype = new Error();
  2577. PasswordException.constructor = PasswordException;
  2578. return PasswordException;
  2579. })();
  2580. PDFJS.PasswordException = PasswordException;
  2581. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2582. function UnknownErrorException(msg, details) {
  2583. this.name = 'UnknownErrorException';
  2584. this.message = msg;
  2585. this.details = details;
  2586. }
  2587. UnknownErrorException.prototype = new Error();
  2588. UnknownErrorException.constructor = UnknownErrorException;
  2589. return UnknownErrorException;
  2590. })();
  2591. PDFJS.UnknownErrorException = UnknownErrorException;
  2592. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2593. function InvalidPDFException(msg) {
  2594. this.name = 'InvalidPDFException';
  2595. this.message = msg;
  2596. }
  2597. InvalidPDFException.prototype = new Error();
  2598. InvalidPDFException.constructor = InvalidPDFException;
  2599. return InvalidPDFException;
  2600. })();
  2601. PDFJS.InvalidPDFException = InvalidPDFException;
  2602. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2603. function MissingPDFException(msg) {
  2604. this.name = 'MissingPDFException';
  2605. this.message = msg;
  2606. }
  2607. MissingPDFException.prototype = new Error();
  2608. MissingPDFException.constructor = MissingPDFException;
  2609. return MissingPDFException;
  2610. })();
  2611. PDFJS.MissingPDFException = MissingPDFException;
  2612. var UnexpectedResponseException =
  2613. (function UnexpectedResponseExceptionClosure() {
  2614. function UnexpectedResponseException(msg, status) {
  2615. this.name = 'UnexpectedResponseException';
  2616. this.message = msg;
  2617. this.status = status;
  2618. }
  2619. UnexpectedResponseException.prototype = new Error();
  2620. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2621. return UnexpectedResponseException;
  2622. })();
  2623. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  2624. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2625. function NotImplementedException(msg) {
  2626. this.message = msg;
  2627. }
  2628. NotImplementedException.prototype = new Error();
  2629. NotImplementedException.prototype.name = 'NotImplementedException';
  2630. NotImplementedException.constructor = NotImplementedException;
  2631. return NotImplementedException;
  2632. })();
  2633. var MissingDataException = (function MissingDataExceptionClosure() {
  2634. function MissingDataException(begin, end) {
  2635. this.begin = begin;
  2636. this.end = end;
  2637. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2638. }
  2639. MissingDataException.prototype = new Error();
  2640. MissingDataException.prototype.name = 'MissingDataException';
  2641. MissingDataException.constructor = MissingDataException;
  2642. return MissingDataException;
  2643. })();
  2644. var XRefParseException = (function XRefParseExceptionClosure() {
  2645. function XRefParseException(msg) {
  2646. this.message = msg;
  2647. }
  2648. XRefParseException.prototype = new Error();
  2649. XRefParseException.prototype.name = 'XRefParseException';
  2650. XRefParseException.constructor = XRefParseException;
  2651. return XRefParseException;
  2652. })();
  2653. var NullCharactersRegExp = /\x00/g;
  2654. function removeNullCharacters(str) {
  2655. if (typeof str !== 'string') {
  2656. warn('The argument for removeNullCharacters must be a string.');
  2657. return str;
  2658. }
  2659. return str.replace(NullCharactersRegExp, '');
  2660. }
  2661. PDFJS.removeNullCharacters = removeNullCharacters;
  2662. function bytesToString(bytes) {
  2663. assert(bytes !== null && typeof bytes === 'object' &&
  2664. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2665. var length = bytes.length;
  2666. var MAX_ARGUMENT_COUNT = 8192;
  2667. if (length < MAX_ARGUMENT_COUNT) {
  2668. return String.fromCharCode.apply(null, bytes);
  2669. }
  2670. var strBuf = [];
  2671. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2672. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2673. var chunk = bytes.subarray(i, chunkEnd);
  2674. strBuf.push(String.fromCharCode.apply(null, chunk));
  2675. }
  2676. return strBuf.join('');
  2677. }
  2678. function stringToBytes(str) {
  2679. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2680. var length = str.length;
  2681. var bytes = new Uint8Array(length);
  2682. for (var i = 0; i < length; ++i) {
  2683. bytes[i] = str.charCodeAt(i) & 0xFF;
  2684. }
  2685. return bytes;
  2686. }
  2687. function string32(value) {
  2688. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2689. (value >> 8) & 0xff, value & 0xff);
  2690. }
  2691. function log2(x) {
  2692. var n = 1, i = 0;
  2693. while (x > n) {
  2694. n <<= 1;
  2695. i++;
  2696. }
  2697. return i;
  2698. }
  2699. function readInt8(data, start) {
  2700. return (data[start] << 24) >> 24;
  2701. }
  2702. function readUint16(data, offset) {
  2703. return (data[offset] << 8) | data[offset + 1];
  2704. }
  2705. function readUint32(data, offset) {
  2706. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2707. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2708. }
  2709. // Lazy test the endianness of the platform
  2710. // NOTE: This will be 'true' for simulated TypedArrays
  2711. function isLittleEndian() {
  2712. var buffer8 = new Uint8Array(2);
  2713. buffer8[0] = 1;
  2714. var buffer16 = new Uint16Array(buffer8.buffer);
  2715. return (buffer16[0] === 1);
  2716. }
  2717. Object.defineProperty(PDFJS, 'isLittleEndian', {
  2718. configurable: true,
  2719. get: function PDFJS_isLittleEndian() {
  2720. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  2721. }
  2722. });
  2723. // Lazy test if the userAgent support CanvasTypedArrays
  2724. function hasCanvasTypedArrays() {
  2725. var canvas = document.createElement('canvas');
  2726. canvas.width = canvas.height = 1;
  2727. var ctx = canvas.getContext('2d');
  2728. var imageData = ctx.createImageData(1, 1);
  2729. return (typeof imageData.data.buffer !== 'undefined');
  2730. }
  2731. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  2732. configurable: true,
  2733. get: function PDFJS_hasCanvasTypedArrays() {
  2734. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  2735. }
  2736. });
  2737. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2738. function Uint32ArrayView(buffer, length) {
  2739. this.buffer = buffer;
  2740. this.byteLength = buffer.length;
  2741. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2742. ensureUint32ArrayViewProps(this.length);
  2743. }
  2744. Uint32ArrayView.prototype = Object.create(null);
  2745. var uint32ArrayViewSetters = 0;
  2746. function createUint32ArrayProp(index) {
  2747. return {
  2748. get: function () {
  2749. var buffer = this.buffer, offset = index << 2;
  2750. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2751. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2752. },
  2753. set: function (value) {
  2754. var buffer = this.buffer, offset = index << 2;
  2755. buffer[offset] = value & 255;
  2756. buffer[offset + 1] = (value >> 8) & 255;
  2757. buffer[offset + 2] = (value >> 16) & 255;
  2758. buffer[offset + 3] = (value >>> 24) & 255;
  2759. }
  2760. };
  2761. }
  2762. function ensureUint32ArrayViewProps(length) {
  2763. while (uint32ArrayViewSetters < length) {
  2764. Object.defineProperty(Uint32ArrayView.prototype,
  2765. uint32ArrayViewSetters,
  2766. createUint32ArrayProp(uint32ArrayViewSetters));
  2767. uint32ArrayViewSetters++;
  2768. }
  2769. }
  2770. return Uint32ArrayView;
  2771. })();
  2772. exports.Uint32ArrayView = Uint32ArrayView;
  2773. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2774. var Util = PDFJS.Util = (function UtilClosure() {
  2775. function Util() {}
  2776. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2777. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2778. // creating many intermediate strings.
  2779. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2780. rgbBuf[1] = r;
  2781. rgbBuf[3] = g;
  2782. rgbBuf[5] = b;
  2783. return rgbBuf.join('');
  2784. };
  2785. // Concatenates two transformation matrices together and returns the result.
  2786. Util.transform = function Util_transform(m1, m2) {
  2787. return [
  2788. m1[0] * m2[0] + m1[2] * m2[1],
  2789. m1[1] * m2[0] + m1[3] * m2[1],
  2790. m1[0] * m2[2] + m1[2] * m2[3],
  2791. m1[1] * m2[2] + m1[3] * m2[3],
  2792. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2793. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2794. ];
  2795. };
  2796. // For 2d affine transforms
  2797. Util.applyTransform = function Util_applyTransform(p, m) {
  2798. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2799. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2800. return [xt, yt];
  2801. };
  2802. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2803. var d = m[0] * m[3] - m[1] * m[2];
  2804. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2805. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2806. return [xt, yt];
  2807. };
  2808. // Applies the transform to the rectangle and finds the minimum axially
  2809. // aligned bounding box.
  2810. Util.getAxialAlignedBoundingBox =
  2811. function Util_getAxialAlignedBoundingBox(r, m) {
  2812. var p1 = Util.applyTransform(r, m);
  2813. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2814. var p3 = Util.applyTransform([r[0], r[3]], m);
  2815. var p4 = Util.applyTransform([r[2], r[1]], m);
  2816. return [
  2817. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2818. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2819. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2820. Math.max(p1[1], p2[1], p3[1], p4[1])
  2821. ];
  2822. };
  2823. Util.inverseTransform = function Util_inverseTransform(m) {
  2824. var d = m[0] * m[3] - m[1] * m[2];
  2825. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2826. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2827. };
  2828. // Apply a generic 3d matrix M on a 3-vector v:
  2829. // | a b c | | X |
  2830. // | d e f | x | Y |
  2831. // | g h i | | Z |
  2832. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2833. // with v as [X,Y,Z]
  2834. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2835. return [
  2836. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2837. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2838. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2839. ];
  2840. };
  2841. // This calculation uses Singular Value Decomposition.
  2842. // The SVD can be represented with formula A = USV. We are interested in the
  2843. // matrix S here because it represents the scale values.
  2844. Util.singularValueDecompose2dScale =
  2845. function Util_singularValueDecompose2dScale(m) {
  2846. var transpose = [m[0], m[2], m[1], m[3]];
  2847. // Multiply matrix m with its transpose.
  2848. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2849. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2850. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2851. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2852. // Solve the second degree polynomial to get roots.
  2853. var first = (a + d) / 2;
  2854. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2855. var sx = first + second || 1;
  2856. var sy = first - second || 1;
  2857. // Scale values are the square roots of the eigenvalues.
  2858. return [Math.sqrt(sx), Math.sqrt(sy)];
  2859. };
  2860. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2861. // For coordinate systems whose origin lies in the bottom-left, this
  2862. // means normalization to (BL,TR) ordering. For systems with origin in the
  2863. // top-left, this means (TL,BR) ordering.
  2864. Util.normalizeRect = function Util_normalizeRect(rect) {
  2865. var r = rect.slice(0); // clone rect
  2866. if (rect[0] > rect[2]) {
  2867. r[0] = rect[2];
  2868. r[2] = rect[0];
  2869. }
  2870. if (rect[1] > rect[3]) {
  2871. r[1] = rect[3];
  2872. r[3] = rect[1];
  2873. }
  2874. return r;
  2875. };
  2876. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2877. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2878. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2879. Util.intersect = function Util_intersect(rect1, rect2) {
  2880. function compare(a, b) {
  2881. return a - b;
  2882. }
  2883. // Order points along the axes
  2884. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2885. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2886. result = [];
  2887. rect1 = Util.normalizeRect(rect1);
  2888. rect2 = Util.normalizeRect(rect2);
  2889. // X: first and second points belong to different rectangles?
  2890. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2891. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2892. // Intersection must be between second and third points
  2893. result[0] = orderedX[1];
  2894. result[2] = orderedX[2];
  2895. } else {
  2896. return false;
  2897. }
  2898. // Y: first and second points belong to different rectangles?
  2899. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2900. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2901. // Intersection must be between second and third points
  2902. result[1] = orderedY[1];
  2903. result[3] = orderedY[2];
  2904. } else {
  2905. return false;
  2906. }
  2907. return result;
  2908. };
  2909. Util.sign = function Util_sign(num) {
  2910. return num < 0 ? -1 : 1;
  2911. };
  2912. var ROMAN_NUMBER_MAP = [
  2913. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2914. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2915. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2916. ];
  2917. /**
  2918. * Converts positive integers to (upper case) Roman numerals.
  2919. * @param {integer} number - The number that should be converted.
  2920. * @param {boolean} lowerCase - Indicates if the result should be converted
  2921. * to lower case letters. The default is false.
  2922. * @return {string} The resulting Roman number.
  2923. */
  2924. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2925. assert(isInt(number) && number > 0,
  2926. 'The number should be a positive integer.');
  2927. var pos, romanBuf = [];
  2928. // Thousands
  2929. while (number >= 1000) {
  2930. number -= 1000;
  2931. romanBuf.push('M');
  2932. }
  2933. // Hundreds
  2934. pos = (number / 100) | 0;
  2935. number %= 100;
  2936. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2937. // Tens
  2938. pos = (number / 10) | 0;
  2939. number %= 10;
  2940. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2941. // Ones
  2942. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2943. var romanStr = romanBuf.join('');
  2944. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2945. };
  2946. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2947. Array.prototype.push.apply(arr1, arr2);
  2948. };
  2949. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2950. Array.prototype.unshift.apply(arr1, arr2);
  2951. };
  2952. Util.extendObj = function extendObj(obj1, obj2) {
  2953. for (var key in obj2) {
  2954. obj1[key] = obj2[key];
  2955. }
  2956. };
  2957. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2958. name) {
  2959. while (dict && !dict.has(name)) {
  2960. dict = dict.get('Parent');
  2961. }
  2962. if (!dict) {
  2963. return null;
  2964. }
  2965. return dict.get(name);
  2966. };
  2967. Util.inherit = function Util_inherit(sub, base, prototype) {
  2968. sub.prototype = Object.create(base.prototype);
  2969. sub.prototype.constructor = sub;
  2970. for (var prop in prototype) {
  2971. sub.prototype[prop] = prototype[prop];
  2972. }
  2973. };
  2974. Util.loadScript = function Util_loadScript(src, callback) {
  2975. var script = document.createElement('script');
  2976. var loaded = false;
  2977. script.setAttribute('src', src);
  2978. if (callback) {
  2979. script.onload = function() {
  2980. if (!loaded) {
  2981. callback();
  2982. }
  2983. loaded = true;
  2984. };
  2985. }
  2986. document.getElementsByTagName('head')[0].appendChild(script);
  2987. };
  2988. return Util;
  2989. })();
  2990. /**
  2991. * PDF page viewport created based on scale, rotation and offset.
  2992. * @class
  2993. * @alias PDFJS.PageViewport
  2994. */
  2995. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  2996. /**
  2997. * @constructor
  2998. * @private
  2999. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  3000. * @param scale {number} scale of the viewport.
  3001. * @param rotation {number} rotations of the viewport in degrees.
  3002. * @param offsetX {number} offset X
  3003. * @param offsetY {number} offset Y
  3004. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  3005. */
  3006. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  3007. this.viewBox = viewBox;
  3008. this.scale = scale;
  3009. this.rotation = rotation;
  3010. this.offsetX = offsetX;
  3011. this.offsetY = offsetY;
  3012. // creating transform to convert pdf coordinate system to the normal
  3013. // canvas like coordinates taking in account scale and rotation
  3014. var centerX = (viewBox[2] + viewBox[0]) / 2;
  3015. var centerY = (viewBox[3] + viewBox[1]) / 2;
  3016. var rotateA, rotateB, rotateC, rotateD;
  3017. rotation = rotation % 360;
  3018. rotation = rotation < 0 ? rotation + 360 : rotation;
  3019. switch (rotation) {
  3020. case 180:
  3021. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  3022. break;
  3023. case 90:
  3024. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  3025. break;
  3026. case 270:
  3027. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  3028. break;
  3029. //case 0:
  3030. default:
  3031. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  3032. break;
  3033. }
  3034. if (dontFlip) {
  3035. rotateC = -rotateC; rotateD = -rotateD;
  3036. }
  3037. var offsetCanvasX, offsetCanvasY;
  3038. var width, height;
  3039. if (rotateA === 0) {
  3040. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  3041. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  3042. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  3043. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  3044. } else {
  3045. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  3046. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  3047. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  3048. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  3049. }
  3050. // creating transform for the following operations:
  3051. // translate(-centerX, -centerY), rotate and flip vertically,
  3052. // scale, and translate(offsetCanvasX, offsetCanvasY)
  3053. this.transform = [
  3054. rotateA * scale,
  3055. rotateB * scale,
  3056. rotateC * scale,
  3057. rotateD * scale,
  3058. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  3059. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  3060. ];
  3061. this.width = width;
  3062. this.height = height;
  3063. this.fontScale = scale;
  3064. }
  3065. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  3066. /**
  3067. * Clones viewport with additional properties.
  3068. * @param args {Object} (optional) If specified, may contain the 'scale' or
  3069. * 'rotation' properties to override the corresponding properties in
  3070. * the cloned viewport.
  3071. * @returns {PDFJS.PageViewport} Cloned viewport.
  3072. */
  3073. clone: function PageViewPort_clone(args) {
  3074. args = args || {};
  3075. var scale = 'scale' in args ? args.scale : this.scale;
  3076. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  3077. return new PageViewport(this.viewBox.slice(), scale, rotation,
  3078. this.offsetX, this.offsetY, args.dontFlip);
  3079. },
  3080. /**
  3081. * Converts PDF point to the viewport coordinates. For examples, useful for
  3082. * converting PDF location into canvas pixel coordinates.
  3083. * @param x {number} X coordinate.
  3084. * @param y {number} Y coordinate.
  3085. * @returns {Object} Object that contains 'x' and 'y' properties of the
  3086. * point in the viewport coordinate space.
  3087. * @see {@link convertToPdfPoint}
  3088. * @see {@link convertToViewportRectangle}
  3089. */
  3090. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  3091. return Util.applyTransform([x, y], this.transform);
  3092. },
  3093. /**
  3094. * Converts PDF rectangle to the viewport coordinates.
  3095. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  3096. * @returns {Array} Contains corresponding coordinates of the rectangle
  3097. * in the viewport coordinate space.
  3098. * @see {@link convertToViewportPoint}
  3099. */
  3100. convertToViewportRectangle:
  3101. function PageViewport_convertToViewportRectangle(rect) {
  3102. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  3103. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  3104. return [tl[0], tl[1], br[0], br[1]];
  3105. },
  3106. /**
  3107. * Converts viewport coordinates to the PDF location. For examples, useful
  3108. * for converting canvas pixel location into PDF one.
  3109. * @param x {number} X coordinate.
  3110. * @param y {number} Y coordinate.
  3111. * @returns {Object} Object that contains 'x' and 'y' properties of the
  3112. * point in the PDF coordinate space.
  3113. * @see {@link convertToViewportPoint}
  3114. */
  3115. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  3116. return Util.applyInverseTransform([x, y], this.transform);
  3117. }
  3118. };
  3119. return PageViewport;
  3120. })();
  3121. var PDFStringTranslateTable = [
  3122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3123. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  3124. 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,
  3125. 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,
  3126. 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,
  3127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  3128. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  3129. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  3130. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  3131. ];
  3132. function stringToPDFString(str) {
  3133. var i, n = str.length, strBuf = [];
  3134. if (str[0] === '\xFE' && str[1] === '\xFF') {
  3135. // UTF16BE BOM
  3136. for (i = 2; i < n; i += 2) {
  3137. strBuf.push(String.fromCharCode(
  3138. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  3139. }
  3140. } else {
  3141. for (i = 0; i < n; ++i) {
  3142. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  3143. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  3144. }
  3145. }
  3146. return strBuf.join('');
  3147. }
  3148. function stringToUTF8String(str) {
  3149. return decodeURIComponent(escape(str));
  3150. }
  3151. function utf8StringToString(str) {
  3152. return unescape(encodeURIComponent(str));
  3153. }
  3154. function isEmptyObj(obj) {
  3155. for (var key in obj) {
  3156. return false;
  3157. }
  3158. return true;
  3159. }
  3160. function isBool(v) {
  3161. return typeof v === 'boolean';
  3162. }
  3163. function isInt(v) {
  3164. return typeof v === 'number' && ((v | 0) === v);
  3165. }
  3166. function isNum(v) {
  3167. return typeof v === 'number';
  3168. }
  3169. function isString(v) {
  3170. return typeof v === 'string';
  3171. }
  3172. function isArray(v) {
  3173. return v instanceof Array;
  3174. }
  3175. function isArrayBuffer(v) {
  3176. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  3177. }
  3178. /**
  3179. * Promise Capability object.
  3180. *
  3181. * @typedef {Object} PromiseCapability
  3182. * @property {Promise} promise - A promise object.
  3183. * @property {function} resolve - Fullfills the promise.
  3184. * @property {function} reject - Rejects the promise.
  3185. */
  3186. /**
  3187. * Creates a promise capability object.
  3188. * @alias PDFJS.createPromiseCapability
  3189. *
  3190. * @return {PromiseCapability} A capability object contains:
  3191. * - a Promise, resolve and reject methods.
  3192. */
  3193. function createPromiseCapability() {
  3194. var capability = {};
  3195. capability.promise = new Promise(function (resolve, reject) {
  3196. capability.resolve = resolve;
  3197. capability.reject = reject;
  3198. });
  3199. return capability;
  3200. }
  3201. PDFJS.createPromiseCapability = createPromiseCapability;
  3202. /**
  3203. * Polyfill for Promises:
  3204. * The following promise implementation tries to generally implement the
  3205. * Promise/A+ spec. Some notable differences from other promise libaries are:
  3206. * - There currently isn't a seperate deferred and promise object.
  3207. * - Unhandled rejections eventually show an error if they aren't handled.
  3208. *
  3209. * Based off of the work in:
  3210. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  3211. */
  3212. (function PromiseClosure() {
  3213. if (globalScope.Promise) {
  3214. // Promises existing in the DOM/Worker, checking presence of all/resolve
  3215. if (typeof globalScope.Promise.all !== 'function') {
  3216. globalScope.Promise.all = function (iterable) {
  3217. var count = 0, results = [], resolve, reject;
  3218. var promise = new globalScope.Promise(function (resolve_, reject_) {
  3219. resolve = resolve_;
  3220. reject = reject_;
  3221. });
  3222. iterable.forEach(function (p, i) {
  3223. count++;
  3224. p.then(function (result) {
  3225. results[i] = result;
  3226. count--;
  3227. if (count === 0) {
  3228. resolve(results);
  3229. }
  3230. }, reject);
  3231. });
  3232. if (count === 0) {
  3233. resolve(results);
  3234. }
  3235. return promise;
  3236. };
  3237. }
  3238. if (typeof globalScope.Promise.resolve !== 'function') {
  3239. globalScope.Promise.resolve = function (value) {
  3240. return new globalScope.Promise(function (resolve) { resolve(value); });
  3241. };
  3242. }
  3243. if (typeof globalScope.Promise.reject !== 'function') {
  3244. globalScope.Promise.reject = function (reason) {
  3245. return new globalScope.Promise(function (resolve, reject) {
  3246. reject(reason);
  3247. });
  3248. };
  3249. }
  3250. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  3251. globalScope.Promise.prototype.catch = function (onReject) {
  3252. return globalScope.Promise.prototype.then(undefined, onReject);
  3253. };
  3254. }
  3255. return;
  3256. }
  3257. var STATUS_PENDING = 0;
  3258. var STATUS_RESOLVED = 1;
  3259. var STATUS_REJECTED = 2;
  3260. // In an attempt to avoid silent exceptions, unhandled rejections are
  3261. // tracked and if they aren't handled in a certain amount of time an
  3262. // error is logged.
  3263. var REJECTION_TIMEOUT = 500;
  3264. var HandlerManager = {
  3265. handlers: [],
  3266. running: false,
  3267. unhandledRejections: [],
  3268. pendingRejectionCheck: false,
  3269. scheduleHandlers: function scheduleHandlers(promise) {
  3270. if (promise._status === STATUS_PENDING) {
  3271. return;
  3272. }
  3273. this.handlers = this.handlers.concat(promise._handlers);
  3274. promise._handlers = [];
  3275. if (this.running) {
  3276. return;
  3277. }
  3278. this.running = true;
  3279. setTimeout(this.runHandlers.bind(this), 0);
  3280. },
  3281. runHandlers: function runHandlers() {
  3282. var RUN_TIMEOUT = 1; // ms
  3283. var timeoutAt = Date.now() + RUN_TIMEOUT;
  3284. while (this.handlers.length > 0) {
  3285. var handler = this.handlers.shift();
  3286. var nextStatus = handler.thisPromise._status;
  3287. var nextValue = handler.thisPromise._value;
  3288. try {
  3289. if (nextStatus === STATUS_RESOLVED) {
  3290. if (typeof handler.onResolve === 'function') {
  3291. nextValue = handler.onResolve(nextValue);
  3292. }
  3293. } else if (typeof handler.onReject === 'function') {
  3294. nextValue = handler.onReject(nextValue);
  3295. nextStatus = STATUS_RESOLVED;
  3296. if (handler.thisPromise._unhandledRejection) {
  3297. this.removeUnhandeledRejection(handler.thisPromise);
  3298. }
  3299. }
  3300. } catch (ex) {
  3301. nextStatus = STATUS_REJECTED;
  3302. nextValue = ex;
  3303. }
  3304. handler.nextPromise._updateStatus(nextStatus, nextValue);
  3305. if (Date.now() >= timeoutAt) {
  3306. break;
  3307. }
  3308. }
  3309. if (this.handlers.length > 0) {
  3310. setTimeout(this.runHandlers.bind(this), 0);
  3311. return;
  3312. }
  3313. this.running = false;
  3314. },
  3315. addUnhandledRejection: function addUnhandledRejection(promise) {
  3316. this.unhandledRejections.push({
  3317. promise: promise,
  3318. time: Date.now()
  3319. });
  3320. this.scheduleRejectionCheck();
  3321. },
  3322. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  3323. promise._unhandledRejection = false;
  3324. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3325. if (this.unhandledRejections[i].promise === promise) {
  3326. this.unhandledRejections.splice(i);
  3327. i--;
  3328. }
  3329. }
  3330. },
  3331. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3332. if (this.pendingRejectionCheck) {
  3333. return;
  3334. }
  3335. this.pendingRejectionCheck = true;
  3336. setTimeout(function rejectionCheck() {
  3337. this.pendingRejectionCheck = false;
  3338. var now = Date.now();
  3339. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3340. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3341. var unhandled = this.unhandledRejections[i].promise._value;
  3342. var msg = 'Unhandled rejection: ' + unhandled;
  3343. if (unhandled.stack) {
  3344. msg += '\n' + unhandled.stack;
  3345. }
  3346. warn(msg);
  3347. this.unhandledRejections.splice(i);
  3348. i--;
  3349. }
  3350. }
  3351. if (this.unhandledRejections.length) {
  3352. this.scheduleRejectionCheck();
  3353. }
  3354. }.bind(this), REJECTION_TIMEOUT);
  3355. }
  3356. };
  3357. function Promise(resolver) {
  3358. this._status = STATUS_PENDING;
  3359. this._handlers = [];
  3360. try {
  3361. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3362. } catch (e) {
  3363. this._reject(e);
  3364. }
  3365. }
  3366. /**
  3367. * Builds a promise that is resolved when all the passed in promises are
  3368. * resolved.
  3369. * @param {array} array of data and/or promises to wait for.
  3370. * @return {Promise} New dependant promise.
  3371. */
  3372. Promise.all = function Promise_all(promises) {
  3373. var resolveAll, rejectAll;
  3374. var deferred = new Promise(function (resolve, reject) {
  3375. resolveAll = resolve;
  3376. rejectAll = reject;
  3377. });
  3378. var unresolved = promises.length;
  3379. var results = [];
  3380. if (unresolved === 0) {
  3381. resolveAll(results);
  3382. return deferred;
  3383. }
  3384. function reject(reason) {
  3385. if (deferred._status === STATUS_REJECTED) {
  3386. return;
  3387. }
  3388. results = [];
  3389. rejectAll(reason);
  3390. }
  3391. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3392. var promise = promises[i];
  3393. var resolve = (function(i) {
  3394. return function(value) {
  3395. if (deferred._status === STATUS_REJECTED) {
  3396. return;
  3397. }
  3398. results[i] = value;
  3399. unresolved--;
  3400. if (unresolved === 0) {
  3401. resolveAll(results);
  3402. }
  3403. };
  3404. })(i);
  3405. if (Promise.isPromise(promise)) {
  3406. promise.then(resolve, reject);
  3407. } else {
  3408. resolve(promise);
  3409. }
  3410. }
  3411. return deferred;
  3412. };
  3413. /**
  3414. * Checks if the value is likely a promise (has a 'then' function).
  3415. * @return {boolean} true if value is thenable
  3416. */
  3417. Promise.isPromise = function Promise_isPromise(value) {
  3418. return value && typeof value.then === 'function';
  3419. };
  3420. /**
  3421. * Creates resolved promise
  3422. * @param value resolve value
  3423. * @returns {Promise}
  3424. */
  3425. Promise.resolve = function Promise_resolve(value) {
  3426. return new Promise(function (resolve) { resolve(value); });
  3427. };
  3428. /**
  3429. * Creates rejected promise
  3430. * @param reason rejection value
  3431. * @returns {Promise}
  3432. */
  3433. Promise.reject = function Promise_reject(reason) {
  3434. return new Promise(function (resolve, reject) { reject(reason); });
  3435. };
  3436. Promise.prototype = {
  3437. _status: null,
  3438. _value: null,
  3439. _handlers: null,
  3440. _unhandledRejection: null,
  3441. _updateStatus: function Promise__updateStatus(status, value) {
  3442. if (this._status === STATUS_RESOLVED ||
  3443. this._status === STATUS_REJECTED) {
  3444. return;
  3445. }
  3446. if (status === STATUS_RESOLVED &&
  3447. Promise.isPromise(value)) {
  3448. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3449. this._updateStatus.bind(this, STATUS_REJECTED));
  3450. return;
  3451. }
  3452. this._status = status;
  3453. this._value = value;
  3454. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3455. this._unhandledRejection = true;
  3456. HandlerManager.addUnhandledRejection(this);
  3457. }
  3458. HandlerManager.scheduleHandlers(this);
  3459. },
  3460. _resolve: function Promise_resolve(value) {
  3461. this._updateStatus(STATUS_RESOLVED, value);
  3462. },
  3463. _reject: function Promise_reject(reason) {
  3464. this._updateStatus(STATUS_REJECTED, reason);
  3465. },
  3466. then: function Promise_then(onResolve, onReject) {
  3467. var nextPromise = new Promise(function (resolve, reject) {
  3468. this.resolve = resolve;
  3469. this.reject = reject;
  3470. });
  3471. this._handlers.push({
  3472. thisPromise: this,
  3473. onResolve: onResolve,
  3474. onReject: onReject,
  3475. nextPromise: nextPromise
  3476. });
  3477. HandlerManager.scheduleHandlers(this);
  3478. return nextPromise;
  3479. },
  3480. catch: function Promise_catch(onReject) {
  3481. return this.then(undefined, onReject);
  3482. }
  3483. };
  3484. globalScope.Promise = Promise;
  3485. })();
  3486. var StatTimer = (function StatTimerClosure() {
  3487. function rpad(str, pad, length) {
  3488. while (str.length < length) {
  3489. str += pad;
  3490. }
  3491. return str;
  3492. }
  3493. function StatTimer() {
  3494. this.started = Object.create(null);
  3495. this.times = [];
  3496. this.enabled = true;
  3497. }
  3498. StatTimer.prototype = {
  3499. time: function StatTimer_time(name) {
  3500. if (!this.enabled) {
  3501. return;
  3502. }
  3503. if (name in this.started) {
  3504. warn('Timer is already running for ' + name);
  3505. }
  3506. this.started[name] = Date.now();
  3507. },
  3508. timeEnd: function StatTimer_timeEnd(name) {
  3509. if (!this.enabled) {
  3510. return;
  3511. }
  3512. if (!(name in this.started)) {
  3513. warn('Timer has not been started for ' + name);
  3514. }
  3515. this.times.push({
  3516. 'name': name,
  3517. 'start': this.started[name],
  3518. 'end': Date.now()
  3519. });
  3520. // Remove timer from started so it can be called again.
  3521. delete this.started[name];
  3522. },
  3523. toString: function StatTimer_toString() {
  3524. var i, ii;
  3525. var times = this.times;
  3526. var out = '';
  3527. // Find the longest name for padding purposes.
  3528. var longest = 0;
  3529. for (i = 0, ii = times.length; i < ii; ++i) {
  3530. var name = times[i]['name'];
  3531. if (name.length > longest) {
  3532. longest = name.length;
  3533. }
  3534. }
  3535. for (i = 0, ii = times.length; i < ii; ++i) {
  3536. var span = times[i];
  3537. var duration = span.end - span.start;
  3538. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3539. }
  3540. return out;
  3541. }
  3542. };
  3543. return StatTimer;
  3544. })();
  3545. PDFJS.createBlob = function createBlob(data, contentType) {
  3546. if (typeof Blob !== 'undefined') {
  3547. return new Blob([data], { type: contentType });
  3548. }
  3549. // Blob builder is deprecated in FF14 and removed in FF18.
  3550. var bb = new MozBlobBuilder();
  3551. bb.append(data);
  3552. return bb.getBlob(contentType);
  3553. };
  3554. PDFJS.createObjectURL = (function createObjectURLClosure() {
  3555. // Blob/createObjectURL is not available, falling back to data schema.
  3556. var digits =
  3557. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3558. return function createObjectURL(data, contentType) {
  3559. if (!PDFJS.disableCreateObjectURL &&
  3560. typeof URL !== 'undefined' && URL.createObjectURL) {
  3561. var blob = PDFJS.createBlob(data, contentType);
  3562. return URL.createObjectURL(blob);
  3563. }
  3564. var buffer = 'data:' + contentType + ';base64,';
  3565. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3566. var b1 = data[i] & 0xFF;
  3567. var b2 = data[i + 1] & 0xFF;
  3568. var b3 = data[i + 2] & 0xFF;
  3569. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3570. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3571. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3572. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3573. }
  3574. return buffer;
  3575. };
  3576. })();
  3577. function MessageHandler(sourceName, targetName, comObj) {
  3578. this.sourceName = sourceName;
  3579. this.targetName = targetName;
  3580. this.comObj = comObj;
  3581. this.callbackIndex = 1;
  3582. this.postMessageTransfers = true;
  3583. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3584. var ah = this.actionHandler = Object.create(null);
  3585. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3586. var data = event.data;
  3587. if (data.targetName !== this.sourceName) {
  3588. return;
  3589. }
  3590. if (data.isReply) {
  3591. var callbackId = data.callbackId;
  3592. if (data.callbackId in callbacksCapabilities) {
  3593. var callback = callbacksCapabilities[callbackId];
  3594. delete callbacksCapabilities[callbackId];
  3595. if ('error' in data) {
  3596. callback.reject(data.error);
  3597. } else {
  3598. callback.resolve(data.data);
  3599. }
  3600. } else {
  3601. error('Cannot resolve callback ' + callbackId);
  3602. }
  3603. } else if (data.action in ah) {
  3604. var action = ah[data.action];
  3605. if (data.callbackId) {
  3606. var sourceName = this.sourceName;
  3607. var targetName = data.sourceName;
  3608. Promise.resolve().then(function () {
  3609. return action[0].call(action[1], data.data);
  3610. }).then(function (result) {
  3611. comObj.postMessage({
  3612. sourceName: sourceName,
  3613. targetName: targetName,
  3614. isReply: true,
  3615. callbackId: data.callbackId,
  3616. data: result
  3617. });
  3618. }, function (reason) {
  3619. if (reason instanceof Error) {
  3620. // Serialize error to avoid "DataCloneError"
  3621. reason = reason + '';
  3622. }
  3623. comObj.postMessage({
  3624. sourceName: sourceName,
  3625. targetName: targetName,
  3626. isReply: true,
  3627. callbackId: data.callbackId,
  3628. error: reason
  3629. });
  3630. });
  3631. } else {
  3632. action[0].call(action[1], data.data);
  3633. }
  3634. } else {
  3635. error('Unknown action from worker: ' + data.action);
  3636. }
  3637. }.bind(this);
  3638. comObj.addEventListener('message', this._onComObjOnMessage);
  3639. }
  3640. MessageHandler.prototype = {
  3641. on: function messageHandlerOn(actionName, handler, scope) {
  3642. var ah = this.actionHandler;
  3643. if (ah[actionName]) {
  3644. error('There is already an actionName called "' + actionName + '"');
  3645. }
  3646. ah[actionName] = [handler, scope];
  3647. },
  3648. /**
  3649. * Sends a message to the comObj to invoke the action with the supplied data.
  3650. * @param {String} actionName Action to call.
  3651. * @param {JSON} data JSON data to send.
  3652. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3653. */
  3654. send: function messageHandlerSend(actionName, data, transfers) {
  3655. var message = {
  3656. sourceName: this.sourceName,
  3657. targetName: this.targetName,
  3658. action: actionName,
  3659. data: data
  3660. };
  3661. this.postMessage(message, transfers);
  3662. },
  3663. /**
  3664. * Sends a message to the comObj to invoke the action with the supplied data.
  3665. * Expects that other side will callback with the response.
  3666. * @param {String} actionName Action to call.
  3667. * @param {JSON} data JSON data to send.
  3668. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3669. * @returns {Promise} Promise to be resolved with response data.
  3670. */
  3671. sendWithPromise:
  3672. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3673. var callbackId = this.callbackIndex++;
  3674. var message = {
  3675. sourceName: this.sourceName,
  3676. targetName: this.targetName,
  3677. action: actionName,
  3678. data: data,
  3679. callbackId: callbackId
  3680. };
  3681. var capability = createPromiseCapability();
  3682. this.callbacksCapabilities[callbackId] = capability;
  3683. try {
  3684. this.postMessage(message, transfers);
  3685. } catch (e) {
  3686. capability.reject(e);
  3687. }
  3688. return capability.promise;
  3689. },
  3690. /**
  3691. * Sends raw message to the comObj.
  3692. * @private
  3693. * @param message {Object} Raw message.
  3694. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3695. */
  3696. postMessage: function (message, transfers) {
  3697. if (transfers && this.postMessageTransfers) {
  3698. this.comObj.postMessage(message, transfers);
  3699. } else {
  3700. this.comObj.postMessage(message);
  3701. }
  3702. },
  3703. destroy: function () {
  3704. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3705. }
  3706. };
  3707. function loadJpegStream(id, imageUrl, objs) {
  3708. var img = new Image();
  3709. img.onload = (function loadJpegStream_onloadClosure() {
  3710. objs.resolve(id, img);
  3711. });
  3712. img.onerror = (function loadJpegStream_onerrorClosure() {
  3713. objs.resolve(id, null);
  3714. warn('Error during JPEG image loading');
  3715. });
  3716. img.src = imageUrl;
  3717. }
  3718. // Polyfill from https://github.com/Polymer/URL
  3719. /* Any copyright is dedicated to the Public Domain.
  3720. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3721. (function checkURLConstructor(scope) {
  3722. /* jshint ignore:start */
  3723. // feature detect for URL constructor
  3724. var hasWorkingUrl = false;
  3725. try {
  3726. if (typeof URL === 'function' &&
  3727. typeof URL.prototype === 'object' &&
  3728. ('origin' in URL.prototype)) {
  3729. var u = new URL('b', 'http://a');
  3730. u.pathname = 'c%20d';
  3731. hasWorkingUrl = u.href === 'http://a/c%20d';
  3732. }
  3733. } catch(e) { }
  3734. if (hasWorkingUrl)
  3735. return;
  3736. var relative = Object.create(null);
  3737. relative['ftp'] = 21;
  3738. relative['file'] = 0;
  3739. relative['gopher'] = 70;
  3740. relative['http'] = 80;
  3741. relative['https'] = 443;
  3742. relative['ws'] = 80;
  3743. relative['wss'] = 443;
  3744. var relativePathDotMapping = Object.create(null);
  3745. relativePathDotMapping['%2e'] = '.';
  3746. relativePathDotMapping['.%2e'] = '..';
  3747. relativePathDotMapping['%2e.'] = '..';
  3748. relativePathDotMapping['%2e%2e'] = '..';
  3749. function isRelativeScheme(scheme) {
  3750. return relative[scheme] !== undefined;
  3751. }
  3752. function invalid() {
  3753. clear.call(this);
  3754. this._isInvalid = true;
  3755. }
  3756. function IDNAToASCII(h) {
  3757. if ('' == h) {
  3758. invalid.call(this)
  3759. }
  3760. // XXX
  3761. return h.toLowerCase()
  3762. }
  3763. function percentEscape(c) {
  3764. var unicode = c.charCodeAt(0);
  3765. if (unicode > 0x20 &&
  3766. unicode < 0x7F &&
  3767. // " # < > ? `
  3768. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3769. ) {
  3770. return c;
  3771. }
  3772. return encodeURIComponent(c);
  3773. }
  3774. function percentEscapeQuery(c) {
  3775. // XXX This actually needs to encode c using encoding and then
  3776. // convert the bytes one-by-one.
  3777. var unicode = c.charCodeAt(0);
  3778. if (unicode > 0x20 &&
  3779. unicode < 0x7F &&
  3780. // " # < > ` (do not escape '?')
  3781. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3782. ) {
  3783. return c;
  3784. }
  3785. return encodeURIComponent(c);
  3786. }
  3787. var EOF = undefined,
  3788. ALPHA = /[a-zA-Z]/,
  3789. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3790. function parse(input, stateOverride, base) {
  3791. function err(message) {
  3792. errors.push(message)
  3793. }
  3794. var state = stateOverride || 'scheme start',
  3795. cursor = 0,
  3796. buffer = '',
  3797. seenAt = false,
  3798. seenBracket = false,
  3799. errors = [];
  3800. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3801. var c = input[cursor];
  3802. switch (state) {
  3803. case 'scheme start':
  3804. if (c && ALPHA.test(c)) {
  3805. buffer += c.toLowerCase(); // ASCII-safe
  3806. state = 'scheme';
  3807. } else if (!stateOverride) {
  3808. buffer = '';
  3809. state = 'no scheme';
  3810. continue;
  3811. } else {
  3812. err('Invalid scheme.');
  3813. break loop;
  3814. }
  3815. break;
  3816. case 'scheme':
  3817. if (c && ALPHANUMERIC.test(c)) {
  3818. buffer += c.toLowerCase(); // ASCII-safe
  3819. } else if (':' == c) {
  3820. this._scheme = buffer;
  3821. buffer = '';
  3822. if (stateOverride) {
  3823. break loop;
  3824. }
  3825. if (isRelativeScheme(this._scheme)) {
  3826. this._isRelative = true;
  3827. }
  3828. if ('file' == this._scheme) {
  3829. state = 'relative';
  3830. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3831. state = 'relative or authority';
  3832. } else if (this._isRelative) {
  3833. state = 'authority first slash';
  3834. } else {
  3835. state = 'scheme data';
  3836. }
  3837. } else if (!stateOverride) {
  3838. buffer = '';
  3839. cursor = 0;
  3840. state = 'no scheme';
  3841. continue;
  3842. } else if (EOF == c) {
  3843. break loop;
  3844. } else {
  3845. err('Code point not allowed in scheme: ' + c)
  3846. break loop;
  3847. }
  3848. break;
  3849. case 'scheme data':
  3850. if ('?' == c) {
  3851. this._query = '?';
  3852. state = 'query';
  3853. } else if ('#' == c) {
  3854. this._fragment = '#';
  3855. state = 'fragment';
  3856. } else {
  3857. // XXX error handling
  3858. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3859. this._schemeData += percentEscape(c);
  3860. }
  3861. }
  3862. break;
  3863. case 'no scheme':
  3864. if (!base || !(isRelativeScheme(base._scheme))) {
  3865. err('Missing scheme.');
  3866. invalid.call(this);
  3867. } else {
  3868. state = 'relative';
  3869. continue;
  3870. }
  3871. break;
  3872. case 'relative or authority':
  3873. if ('/' == c && '/' == input[cursor+1]) {
  3874. state = 'authority ignore slashes';
  3875. } else {
  3876. err('Expected /, got: ' + c);
  3877. state = 'relative';
  3878. continue
  3879. }
  3880. break;
  3881. case 'relative':
  3882. this._isRelative = true;
  3883. if ('file' != this._scheme)
  3884. this._scheme = base._scheme;
  3885. if (EOF == c) {
  3886. this._host = base._host;
  3887. this._port = base._port;
  3888. this._path = base._path.slice();
  3889. this._query = base._query;
  3890. this._username = base._username;
  3891. this._password = base._password;
  3892. break loop;
  3893. } else if ('/' == c || '\\' == c) {
  3894. if ('\\' == c)
  3895. err('\\ is an invalid code point.');
  3896. state = 'relative slash';
  3897. } else if ('?' == c) {
  3898. this._host = base._host;
  3899. this._port = base._port;
  3900. this._path = base._path.slice();
  3901. this._query = '?';
  3902. this._username = base._username;
  3903. this._password = base._password;
  3904. state = 'query';
  3905. } else if ('#' == c) {
  3906. this._host = base._host;
  3907. this._port = base._port;
  3908. this._path = base._path.slice();
  3909. this._query = base._query;
  3910. this._fragment = '#';
  3911. this._username = base._username;
  3912. this._password = base._password;
  3913. state = 'fragment';
  3914. } else {
  3915. var nextC = input[cursor+1]
  3916. var nextNextC = input[cursor+2]
  3917. if (
  3918. 'file' != this._scheme || !ALPHA.test(c) ||
  3919. (nextC != ':' && nextC != '|') ||
  3920. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3921. this._host = base._host;
  3922. this._port = base._port;
  3923. this._username = base._username;
  3924. this._password = base._password;
  3925. this._path = base._path.slice();
  3926. this._path.pop();
  3927. }
  3928. state = 'relative path';
  3929. continue;
  3930. }
  3931. break;
  3932. case 'relative slash':
  3933. if ('/' == c || '\\' == c) {
  3934. if ('\\' == c) {
  3935. err('\\ is an invalid code point.');
  3936. }
  3937. if ('file' == this._scheme) {
  3938. state = 'file host';
  3939. } else {
  3940. state = 'authority ignore slashes';
  3941. }
  3942. } else {
  3943. if ('file' != this._scheme) {
  3944. this._host = base._host;
  3945. this._port = base._port;
  3946. this._username = base._username;
  3947. this._password = base._password;
  3948. }
  3949. state = 'relative path';
  3950. continue;
  3951. }
  3952. break;
  3953. case 'authority first slash':
  3954. if ('/' == c) {
  3955. state = 'authority second slash';
  3956. } else {
  3957. err("Expected '/', got: " + c);
  3958. state = 'authority ignore slashes';
  3959. continue;
  3960. }
  3961. break;
  3962. case 'authority second slash':
  3963. state = 'authority ignore slashes';
  3964. if ('/' != c) {
  3965. err("Expected '/', got: " + c);
  3966. continue;
  3967. }
  3968. break;
  3969. case 'authority ignore slashes':
  3970. if ('/' != c && '\\' != c) {
  3971. state = 'authority';
  3972. continue;
  3973. } else {
  3974. err('Expected authority, got: ' + c);
  3975. }
  3976. break;
  3977. case 'authority':
  3978. if ('@' == c) {
  3979. if (seenAt) {
  3980. err('@ already seen.');
  3981. buffer += '%40';
  3982. }
  3983. seenAt = true;
  3984. for (var i = 0; i < buffer.length; i++) {
  3985. var cp = buffer[i];
  3986. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3987. err('Invalid whitespace in authority.');
  3988. continue;
  3989. }
  3990. // XXX check URL code points
  3991. if (':' == cp && null === this._password) {
  3992. this._password = '';
  3993. continue;
  3994. }
  3995. var tempC = percentEscape(cp);
  3996. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3997. }
  3998. buffer = '';
  3999. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  4000. cursor -= buffer.length;
  4001. buffer = '';
  4002. state = 'host';
  4003. continue;
  4004. } else {
  4005. buffer += c;
  4006. }
  4007. break;
  4008. case 'file host':
  4009. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  4010. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  4011. state = 'relative path';
  4012. } else if (buffer.length == 0) {
  4013. state = 'relative path start';
  4014. } else {
  4015. this._host = IDNAToASCII.call(this, buffer);
  4016. buffer = '';
  4017. state = 'relative path start';
  4018. }
  4019. continue;
  4020. } else if ('\t' == c || '\n' == c || '\r' == c) {
  4021. err('Invalid whitespace in file host.');
  4022. } else {
  4023. buffer += c;
  4024. }
  4025. break;
  4026. case 'host':
  4027. case 'hostname':
  4028. if (':' == c && !seenBracket) {
  4029. // XXX host parsing
  4030. this._host = IDNAToASCII.call(this, buffer);
  4031. buffer = '';
  4032. state = 'port';
  4033. if ('hostname' == stateOverride) {
  4034. break loop;
  4035. }
  4036. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  4037. this._host = IDNAToASCII.call(this, buffer);
  4038. buffer = '';
  4039. state = 'relative path start';
  4040. if (stateOverride) {
  4041. break loop;
  4042. }
  4043. continue;
  4044. } else if ('\t' != c && '\n' != c && '\r' != c) {
  4045. if ('[' == c) {
  4046. seenBracket = true;
  4047. } else if (']' == c) {
  4048. seenBracket = false;
  4049. }
  4050. buffer += c;
  4051. } else {
  4052. err('Invalid code point in host/hostname: ' + c);
  4053. }
  4054. break;
  4055. case 'port':
  4056. if (/[0-9]/.test(c)) {
  4057. buffer += c;
  4058. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  4059. if ('' != buffer) {
  4060. var temp = parseInt(buffer, 10);
  4061. if (temp != relative[this._scheme]) {
  4062. this._port = temp + '';
  4063. }
  4064. buffer = '';
  4065. }
  4066. if (stateOverride) {
  4067. break loop;
  4068. }
  4069. state = 'relative path start';
  4070. continue;
  4071. } else if ('\t' == c || '\n' == c || '\r' == c) {
  4072. err('Invalid code point in port: ' + c);
  4073. } else {
  4074. invalid.call(this);
  4075. }
  4076. break;
  4077. case 'relative path start':
  4078. if ('\\' == c)
  4079. err("'\\' not allowed in path.");
  4080. state = 'relative path';
  4081. if ('/' != c && '\\' != c) {
  4082. continue;
  4083. }
  4084. break;
  4085. case 'relative path':
  4086. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  4087. if ('\\' == c) {
  4088. err('\\ not allowed in relative path.');
  4089. }
  4090. var tmp;
  4091. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  4092. buffer = tmp;
  4093. }
  4094. if ('..' == buffer) {
  4095. this._path.pop();
  4096. if ('/' != c && '\\' != c) {
  4097. this._path.push('');
  4098. }
  4099. } else if ('.' == buffer && '/' != c && '\\' != c) {
  4100. this._path.push('');
  4101. } else if ('.' != buffer) {
  4102. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  4103. buffer = buffer[0] + ':';
  4104. }
  4105. this._path.push(buffer);
  4106. }
  4107. buffer = '';
  4108. if ('?' == c) {
  4109. this._query = '?';
  4110. state = 'query';
  4111. } else if ('#' == c) {
  4112. this._fragment = '#';
  4113. state = 'fragment';
  4114. }
  4115. } else if ('\t' != c && '\n' != c && '\r' != c) {
  4116. buffer += percentEscape(c);
  4117. }
  4118. break;
  4119. case 'query':
  4120. if (!stateOverride && '#' == c) {
  4121. this._fragment = '#';
  4122. state = 'fragment';
  4123. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  4124. this._query += percentEscapeQuery(c);
  4125. }
  4126. break;
  4127. case 'fragment':
  4128. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  4129. this._fragment += c;
  4130. }
  4131. break;
  4132. }
  4133. cursor++;
  4134. }
  4135. }
  4136. function clear() {
  4137. this._scheme = '';
  4138. this._schemeData = '';
  4139. this._username = '';
  4140. this._password = null;
  4141. this._host = '';
  4142. this._port = '';
  4143. this._path = [];
  4144. this._query = '';
  4145. this._fragment = '';
  4146. this._isInvalid = false;
  4147. this._isRelative = false;
  4148. }
  4149. // Does not process domain names or IP addresses.
  4150. // Does not handle encoding for the query parameter.
  4151. function jURL(url, base /* , encoding */) {
  4152. if (base !== undefined && !(base instanceof jURL))
  4153. base = new jURL(String(base));
  4154. this._url = url;
  4155. clear.call(this);
  4156. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  4157. // encoding = encoding || 'utf-8'
  4158. parse.call(this, input, null, base);
  4159. }
  4160. jURL.prototype = {
  4161. toString: function() {
  4162. return this.href;
  4163. },
  4164. get href() {
  4165. if (this._isInvalid)
  4166. return this._url;
  4167. var authority = '';
  4168. if ('' != this._username || null != this._password) {
  4169. authority = this._username +
  4170. (null != this._password ? ':' + this._password : '') + '@';
  4171. }
  4172. return this.protocol +
  4173. (this._isRelative ? '//' + authority + this.host : '') +
  4174. this.pathname + this._query + this._fragment;
  4175. },
  4176. set href(href) {
  4177. clear.call(this);
  4178. parse.call(this, href);
  4179. },
  4180. get protocol() {
  4181. return this._scheme + ':';
  4182. },
  4183. set protocol(protocol) {
  4184. if (this._isInvalid)
  4185. return;
  4186. parse.call(this, protocol + ':', 'scheme start');
  4187. },
  4188. get host() {
  4189. return this._isInvalid ? '' : this._port ?
  4190. this._host + ':' + this._port : this._host;
  4191. },
  4192. set host(host) {
  4193. if (this._isInvalid || !this._isRelative)
  4194. return;
  4195. parse.call(this, host, 'host');
  4196. },
  4197. get hostname() {
  4198. return this._host;
  4199. },
  4200. set hostname(hostname) {
  4201. if (this._isInvalid || !this._isRelative)
  4202. return;
  4203. parse.call(this, hostname, 'hostname');
  4204. },
  4205. get port() {
  4206. return this._port;
  4207. },
  4208. set port(port) {
  4209. if (this._isInvalid || !this._isRelative)
  4210. return;
  4211. parse.call(this, port, 'port');
  4212. },
  4213. get pathname() {
  4214. return this._isInvalid ? '' : this._isRelative ?
  4215. '/' + this._path.join('/') : this._schemeData;
  4216. },
  4217. set pathname(pathname) {
  4218. if (this._isInvalid || !this._isRelative)
  4219. return;
  4220. this._path = [];
  4221. parse.call(this, pathname, 'relative path start');
  4222. },
  4223. get search() {
  4224. return this._isInvalid || !this._query || '?' == this._query ?
  4225. '' : this._query;
  4226. },
  4227. set search(search) {
  4228. if (this._isInvalid || !this._isRelative)
  4229. return;
  4230. this._query = '?';
  4231. if ('?' == search[0])
  4232. search = search.slice(1);
  4233. parse.call(this, search, 'query');
  4234. },
  4235. get hash() {
  4236. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  4237. '' : this._fragment;
  4238. },
  4239. set hash(hash) {
  4240. if (this._isInvalid)
  4241. return;
  4242. this._fragment = '#';
  4243. if ('#' == hash[0])
  4244. hash = hash.slice(1);
  4245. parse.call(this, hash, 'fragment');
  4246. },
  4247. get origin() {
  4248. var host;
  4249. if (this._isInvalid || !this._scheme) {
  4250. return '';
  4251. }
  4252. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  4253. // Gecko throws error for "data://"
  4254. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  4255. // Gecko returns String("") for file: mailto:
  4256. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  4257. switch (this._scheme) {
  4258. case 'data':
  4259. case 'file':
  4260. case 'javascript':
  4261. case 'mailto':
  4262. return 'null';
  4263. }
  4264. host = this.host;
  4265. if (!host) {
  4266. return '';
  4267. }
  4268. return this._scheme + '://' + host;
  4269. }
  4270. };
  4271. // Copy over the static methods
  4272. var OriginalURL = scope.URL;
  4273. if (OriginalURL) {
  4274. jURL.createObjectURL = function(blob) {
  4275. // IE extension allows a second optional options argument.
  4276. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  4277. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  4278. };
  4279. jURL.revokeObjectURL = function(url) {
  4280. OriginalURL.revokeObjectURL(url);
  4281. };
  4282. }
  4283. scope.URL = jURL;
  4284. /* jshint ignore:end */
  4285. })(globalScope);
  4286. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  4287. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  4288. exports.OPS = OPS;
  4289. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  4290. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  4291. exports.AnnotationFlag = AnnotationFlag;
  4292. exports.AnnotationType = AnnotationType;
  4293. exports.FontType = FontType;
  4294. exports.ImageKind = ImageKind;
  4295. exports.InvalidPDFException = InvalidPDFException;
  4296. exports.LinkTarget = LinkTarget;
  4297. exports.LinkTargetStringMap = LinkTargetStringMap;
  4298. exports.MessageHandler = MessageHandler;
  4299. exports.MissingDataException = MissingDataException;
  4300. exports.MissingPDFException = MissingPDFException;
  4301. exports.NotImplementedException = NotImplementedException;
  4302. exports.PasswordException = PasswordException;
  4303. exports.PasswordResponses = PasswordResponses;
  4304. exports.StatTimer = StatTimer;
  4305. exports.StreamType = StreamType;
  4306. exports.TextRenderingMode = TextRenderingMode;
  4307. exports.UnexpectedResponseException = UnexpectedResponseException;
  4308. exports.UnknownErrorException = UnknownErrorException;
  4309. exports.Util = Util;
  4310. exports.XRefParseException = XRefParseException;
  4311. exports.assert = assert;
  4312. exports.bytesToString = bytesToString;
  4313. exports.combineUrl = combineUrl;
  4314. exports.createPromiseCapability = createPromiseCapability;
  4315. exports.deprecated = deprecated;
  4316. exports.error = error;
  4317. exports.getLookupTableFactory = getLookupTableFactory;
  4318. exports.info = info;
  4319. exports.isArray = isArray;
  4320. exports.isArrayBuffer = isArrayBuffer;
  4321. exports.isBool = isBool;
  4322. exports.isEmptyObj = isEmptyObj;
  4323. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  4324. exports.isInt = isInt;
  4325. exports.isNum = isNum;
  4326. exports.isString = isString;
  4327. exports.isSameOrigin = isSameOrigin;
  4328. exports.isValidUrl = isValidUrl;
  4329. exports.addLinkAttributes = addLinkAttributes;
  4330. exports.loadJpegStream = loadJpegStream;
  4331. exports.log2 = log2;
  4332. exports.readInt8 = readInt8;
  4333. exports.readUint16 = readUint16;
  4334. exports.readUint32 = readUint32;
  4335. exports.removeNullCharacters = removeNullCharacters;
  4336. exports.shadow = shadow;
  4337. exports.string32 = string32;
  4338. exports.stringToBytes = stringToBytes;
  4339. exports.stringToPDFString = stringToPDFString;
  4340. exports.stringToUTF8String = stringToUTF8String;
  4341. exports.utf8StringToString = utf8StringToString;
  4342. exports.warn = warn;
  4343. }));
  4344. (function (root, factory) {
  4345. {
  4346. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4347. }
  4348. }(this, function (exports, sharedUtil) {
  4349. var MissingDataException = sharedUtil.MissingDataException;
  4350. var assert = sharedUtil.assert;
  4351. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4352. var isInt = sharedUtil.isInt;
  4353. var isEmptyObj = sharedUtil.isEmptyObj;
  4354. var ChunkedStream = (function ChunkedStreamClosure() {
  4355. function ChunkedStream(length, chunkSize, manager) {
  4356. this.bytes = new Uint8Array(length);
  4357. this.start = 0;
  4358. this.pos = 0;
  4359. this.end = length;
  4360. this.chunkSize = chunkSize;
  4361. this.loadedChunks = [];
  4362. this.numChunksLoaded = 0;
  4363. this.numChunks = Math.ceil(length / chunkSize);
  4364. this.manager = manager;
  4365. this.progressiveDataLength = 0;
  4366. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4367. }
  4368. // required methods for a stream. if a particular stream does not
  4369. // implement these, an error should be thrown
  4370. ChunkedStream.prototype = {
  4371. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4372. var chunks = [];
  4373. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4374. if (!this.loadedChunks[chunk]) {
  4375. chunks.push(chunk);
  4376. }
  4377. }
  4378. return chunks;
  4379. },
  4380. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4381. return [this];
  4382. },
  4383. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4384. return this.numChunksLoaded === this.numChunks;
  4385. },
  4386. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4387. var end = begin + chunk.byteLength;
  4388. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4389. // Using this.length is inaccurate here since this.start can be moved
  4390. // See ChunkedStream.moveStart()
  4391. var length = this.bytes.length;
  4392. assert(end % this.chunkSize === 0 || end === length,
  4393. 'Bad end offset: ' + end);
  4394. this.bytes.set(new Uint8Array(chunk), begin);
  4395. var chunkSize = this.chunkSize;
  4396. var beginChunk = Math.floor(begin / chunkSize);
  4397. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4398. var curChunk;
  4399. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4400. if (!this.loadedChunks[curChunk]) {
  4401. this.loadedChunks[curChunk] = true;
  4402. ++this.numChunksLoaded;
  4403. }
  4404. }
  4405. },
  4406. onReceiveProgressiveData:
  4407. function ChunkedStream_onReceiveProgressiveData(data) {
  4408. var position = this.progressiveDataLength;
  4409. var beginChunk = Math.floor(position / this.chunkSize);
  4410. this.bytes.set(new Uint8Array(data), position);
  4411. position += data.byteLength;
  4412. this.progressiveDataLength = position;
  4413. var endChunk = position >= this.end ? this.numChunks :
  4414. Math.floor(position / this.chunkSize);
  4415. var curChunk;
  4416. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4417. if (!this.loadedChunks[curChunk]) {
  4418. this.loadedChunks[curChunk] = true;
  4419. ++this.numChunksLoaded;
  4420. }
  4421. }
  4422. },
  4423. ensureByte: function ChunkedStream_ensureByte(pos) {
  4424. var chunk = Math.floor(pos / this.chunkSize);
  4425. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4426. return;
  4427. }
  4428. if (!this.loadedChunks[chunk]) {
  4429. throw new MissingDataException(pos, pos + 1);
  4430. }
  4431. this.lastSuccessfulEnsureByteChunk = chunk;
  4432. },
  4433. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4434. if (begin >= end) {
  4435. return;
  4436. }
  4437. if (end <= this.progressiveDataLength) {
  4438. return;
  4439. }
  4440. var chunkSize = this.chunkSize;
  4441. var beginChunk = Math.floor(begin / chunkSize);
  4442. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4443. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4444. if (!this.loadedChunks[chunk]) {
  4445. throw new MissingDataException(begin, end);
  4446. }
  4447. }
  4448. },
  4449. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4450. var chunk, numChunks = this.numChunks;
  4451. for (var i = 0; i < numChunks; ++i) {
  4452. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4453. if (!this.loadedChunks[chunk]) {
  4454. return chunk;
  4455. }
  4456. }
  4457. return null;
  4458. },
  4459. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4460. return !!this.loadedChunks[chunk];
  4461. },
  4462. get length() {
  4463. return this.end - this.start;
  4464. },
  4465. get isEmpty() {
  4466. return this.length === 0;
  4467. },
  4468. getByte: function ChunkedStream_getByte() {
  4469. var pos = this.pos;
  4470. if (pos >= this.end) {
  4471. return -1;
  4472. }
  4473. this.ensureByte(pos);
  4474. return this.bytes[this.pos++];
  4475. },
  4476. getUint16: function ChunkedStream_getUint16() {
  4477. var b0 = this.getByte();
  4478. var b1 = this.getByte();
  4479. if (b0 === -1 || b1 === -1) {
  4480. return -1;
  4481. }
  4482. return (b0 << 8) + b1;
  4483. },
  4484. getInt32: function ChunkedStream_getInt32() {
  4485. var b0 = this.getByte();
  4486. var b1 = this.getByte();
  4487. var b2 = this.getByte();
  4488. var b3 = this.getByte();
  4489. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4490. },
  4491. // returns subarray of original buffer
  4492. // should only be read
  4493. getBytes: function ChunkedStream_getBytes(length) {
  4494. var bytes = this.bytes;
  4495. var pos = this.pos;
  4496. var strEnd = this.end;
  4497. if (!length) {
  4498. this.ensureRange(pos, strEnd);
  4499. return bytes.subarray(pos, strEnd);
  4500. }
  4501. var end = pos + length;
  4502. if (end > strEnd) {
  4503. end = strEnd;
  4504. }
  4505. this.ensureRange(pos, end);
  4506. this.pos = end;
  4507. return bytes.subarray(pos, end);
  4508. },
  4509. peekByte: function ChunkedStream_peekByte() {
  4510. var peekedByte = this.getByte();
  4511. this.pos--;
  4512. return peekedByte;
  4513. },
  4514. peekBytes: function ChunkedStream_peekBytes(length) {
  4515. var bytes = this.getBytes(length);
  4516. this.pos -= bytes.length;
  4517. return bytes;
  4518. },
  4519. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4520. this.ensureRange(begin, end);
  4521. return this.bytes.subarray(begin, end);
  4522. },
  4523. skip: function ChunkedStream_skip(n) {
  4524. if (!n) {
  4525. n = 1;
  4526. }
  4527. this.pos += n;
  4528. },
  4529. reset: function ChunkedStream_reset() {
  4530. this.pos = this.start;
  4531. },
  4532. moveStart: function ChunkedStream_moveStart() {
  4533. this.start = this.pos;
  4534. },
  4535. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4536. this.ensureRange(start, start + length);
  4537. function ChunkedStreamSubstream() {}
  4538. ChunkedStreamSubstream.prototype = Object.create(this);
  4539. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4540. var chunkSize = this.chunkSize;
  4541. var beginChunk = Math.floor(this.start / chunkSize);
  4542. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4543. var missingChunks = [];
  4544. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4545. if (!this.loadedChunks[chunk]) {
  4546. missingChunks.push(chunk);
  4547. }
  4548. }
  4549. return missingChunks;
  4550. };
  4551. var subStream = new ChunkedStreamSubstream();
  4552. subStream.pos = subStream.start = start;
  4553. subStream.end = start + length || this.end;
  4554. subStream.dict = dict;
  4555. return subStream;
  4556. },
  4557. isStream: true
  4558. };
  4559. return ChunkedStream;
  4560. })();
  4561. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4562. function ChunkedStreamManager(length, chunkSize, url, args) {
  4563. this.stream = new ChunkedStream(length, chunkSize, this);
  4564. this.length = length;
  4565. this.chunkSize = chunkSize;
  4566. this.url = url;
  4567. this.disableAutoFetch = args.disableAutoFetch;
  4568. var msgHandler = this.msgHandler = args.msgHandler;
  4569. if (args.chunkedViewerLoading) {
  4570. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  4571. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  4572. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  4573. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  4574. };
  4575. } else {
  4576. var getXhr = function getXhr() {
  4577. return new XMLHttpRequest();
  4578. };
  4579. this.networkManager = new NetworkManager(this.url, {
  4580. getXhr: getXhr,
  4581. httpHeaders: args.httpHeaders,
  4582. withCredentials: args.withCredentials
  4583. });
  4584. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  4585. this.networkManager.requestRange(begin, end, {
  4586. onDone: this.onReceiveData.bind(this),
  4587. onProgress: this.onProgress.bind(this)
  4588. });
  4589. };
  4590. }
  4591. this.currRequestId = 0;
  4592. this.chunksNeededByRequest = Object.create(null);
  4593. this.requestsByChunk = Object.create(null);
  4594. this.promisesByRequest = Object.create(null);
  4595. this.progressiveDataLength = 0;
  4596. this._loadedStreamCapability = createPromiseCapability();
  4597. if (args.initialData) {
  4598. this.onReceiveData({chunk: args.initialData});
  4599. }
  4600. }
  4601. ChunkedStreamManager.prototype = {
  4602. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4603. return this._loadedStreamCapability.promise;
  4604. },
  4605. // Get all the chunks that are not yet loaded and groups them into
  4606. // contiguous ranges to load in as few requests as possible
  4607. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4608. var missingChunks = this.stream.getMissingChunks();
  4609. this._requestChunks(missingChunks);
  4610. return this._loadedStreamCapability.promise;
  4611. },
  4612. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4613. var requestId = this.currRequestId++;
  4614. var i, ii;
  4615. var chunksNeeded = Object.create(null);
  4616. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4617. for (i = 0, ii = chunks.length; i < ii; i++) {
  4618. if (!this.stream.hasChunk(chunks[i])) {
  4619. chunksNeeded[chunks[i]] = true;
  4620. }
  4621. }
  4622. if (isEmptyObj(chunksNeeded)) {
  4623. return Promise.resolve();
  4624. }
  4625. var capability = createPromiseCapability();
  4626. this.promisesByRequest[requestId] = capability;
  4627. var chunksToRequest = [];
  4628. for (var chunk in chunksNeeded) {
  4629. chunk = chunk | 0;
  4630. if (!(chunk in this.requestsByChunk)) {
  4631. this.requestsByChunk[chunk] = [];
  4632. chunksToRequest.push(chunk);
  4633. }
  4634. this.requestsByChunk[chunk].push(requestId);
  4635. }
  4636. if (!chunksToRequest.length) {
  4637. return capability.promise;
  4638. }
  4639. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  4640. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  4641. var groupedChunk = groupedChunksToRequest[i];
  4642. var begin = groupedChunk.beginChunk * this.chunkSize;
  4643. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  4644. this.sendRequest(begin, end);
  4645. }
  4646. return capability.promise;
  4647. },
  4648. getStream: function ChunkedStreamManager_getStream() {
  4649. return this.stream;
  4650. },
  4651. // Loads any chunks in the requested range that are not yet loaded
  4652. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  4653. end = Math.min(end, this.length);
  4654. var beginChunk = this.getBeginChunk(begin);
  4655. var endChunk = this.getEndChunk(end);
  4656. var chunks = [];
  4657. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4658. chunks.push(chunk);
  4659. }
  4660. return this._requestChunks(chunks);
  4661. },
  4662. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  4663. ranges = ranges || [];
  4664. var chunksToRequest = [];
  4665. for (var i = 0; i < ranges.length; i++) {
  4666. var beginChunk = this.getBeginChunk(ranges[i].begin);
  4667. var endChunk = this.getEndChunk(ranges[i].end);
  4668. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4669. if (chunksToRequest.indexOf(chunk) < 0) {
  4670. chunksToRequest.push(chunk);
  4671. }
  4672. }
  4673. }
  4674. chunksToRequest.sort(function(a, b) { return a - b; });
  4675. return this._requestChunks(chunksToRequest);
  4676. },
  4677. // Groups a sorted array of chunks into as few contiguous larger
  4678. // chunks as possible
  4679. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  4680. var groupedChunks = [];
  4681. var beginChunk = -1;
  4682. var prevChunk = -1;
  4683. for (var i = 0; i < chunks.length; ++i) {
  4684. var chunk = chunks[i];
  4685. if (beginChunk < 0) {
  4686. beginChunk = chunk;
  4687. }
  4688. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  4689. groupedChunks.push({ beginChunk: beginChunk,
  4690. endChunk: prevChunk + 1 });
  4691. beginChunk = chunk;
  4692. }
  4693. if (i + 1 === chunks.length) {
  4694. groupedChunks.push({ beginChunk: beginChunk,
  4695. endChunk: chunk + 1 });
  4696. }
  4697. prevChunk = chunk;
  4698. }
  4699. return groupedChunks;
  4700. },
  4701. onProgress: function ChunkedStreamManager_onProgress(args) {
  4702. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  4703. args.loaded);
  4704. this.msgHandler.send('DocProgress', {
  4705. loaded: bytesLoaded,
  4706. total: this.length
  4707. });
  4708. },
  4709. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  4710. var chunk = args.chunk;
  4711. var isProgressive = args.begin === undefined;
  4712. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  4713. var end = begin + chunk.byteLength;
  4714. var beginChunk = Math.floor(begin / this.chunkSize);
  4715. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  4716. Math.ceil(end / this.chunkSize);
  4717. if (isProgressive) {
  4718. this.stream.onReceiveProgressiveData(chunk);
  4719. this.progressiveDataLength = end;
  4720. } else {
  4721. this.stream.onReceiveData(begin, chunk);
  4722. }
  4723. if (this.stream.allChunksLoaded()) {
  4724. this._loadedStreamCapability.resolve(this.stream);
  4725. }
  4726. var loadedRequests = [];
  4727. var i, requestId;
  4728. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  4729. // The server might return more chunks than requested
  4730. var requestIds = this.requestsByChunk[chunk] || [];
  4731. delete this.requestsByChunk[chunk];
  4732. for (i = 0; i < requestIds.length; ++i) {
  4733. requestId = requestIds[i];
  4734. var chunksNeeded = this.chunksNeededByRequest[requestId];
  4735. if (chunk in chunksNeeded) {
  4736. delete chunksNeeded[chunk];
  4737. }
  4738. if (!isEmptyObj(chunksNeeded)) {
  4739. continue;
  4740. }
  4741. loadedRequests.push(requestId);
  4742. }
  4743. }
  4744. // If there are no pending requests, automatically fetch the next
  4745. // unfetched chunk of the PDF
  4746. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  4747. var nextEmptyChunk;
  4748. if (this.stream.numChunksLoaded === 1) {
  4749. // This is a special optimization so that after fetching the first
  4750. // chunk, rather than fetching the second chunk, we fetch the last
  4751. // chunk.
  4752. var lastChunk = this.stream.numChunks - 1;
  4753. if (!this.stream.hasChunk(lastChunk)) {
  4754. nextEmptyChunk = lastChunk;
  4755. }
  4756. } else {
  4757. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  4758. }
  4759. if (isInt(nextEmptyChunk)) {
  4760. this._requestChunks([nextEmptyChunk]);
  4761. }
  4762. }
  4763. for (i = 0; i < loadedRequests.length; ++i) {
  4764. requestId = loadedRequests[i];
  4765. var capability = this.promisesByRequest[requestId];
  4766. delete this.promisesByRequest[requestId];
  4767. capability.resolve();
  4768. }
  4769. this.msgHandler.send('DocProgress', {
  4770. loaded: this.stream.numChunksLoaded * this.chunkSize,
  4771. total: this.length
  4772. });
  4773. },
  4774. onError: function ChunkedStreamManager_onError(err) {
  4775. this._loadedStreamCapability.reject(err);
  4776. },
  4777. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  4778. var chunk = Math.floor(begin / this.chunkSize);
  4779. return chunk;
  4780. },
  4781. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  4782. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  4783. return chunk;
  4784. },
  4785. abort: function ChunkedStreamManager_abort() {
  4786. if (this.networkManager) {
  4787. this.networkManager.abortAllRequests();
  4788. }
  4789. for(var requestId in this.promisesByRequest) {
  4790. var capability = this.promisesByRequest[requestId];
  4791. capability.reject(new Error('Request was aborted'));
  4792. }
  4793. }
  4794. };
  4795. return ChunkedStreamManager;
  4796. })();
  4797. exports.ChunkedStream = ChunkedStream;
  4798. exports.ChunkedStreamManager = ChunkedStreamManager;
  4799. }));
  4800. (function (root, factory) {
  4801. {
  4802. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  4803. }
  4804. }(this, function (exports, sharedUtil) {
  4805. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  4806. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  4807. t['A'] = 0x0041;
  4808. t['AE'] = 0x00C6;
  4809. t['AEacute'] = 0x01FC;
  4810. t['AEmacron'] = 0x01E2;
  4811. t['AEsmall'] = 0xF7E6;
  4812. t['Aacute'] = 0x00C1;
  4813. t['Aacutesmall'] = 0xF7E1;
  4814. t['Abreve'] = 0x0102;
  4815. t['Abreveacute'] = 0x1EAE;
  4816. t['Abrevecyrillic'] = 0x04D0;
  4817. t['Abrevedotbelow'] = 0x1EB6;
  4818. t['Abrevegrave'] = 0x1EB0;
  4819. t['Abrevehookabove'] = 0x1EB2;
  4820. t['Abrevetilde'] = 0x1EB4;
  4821. t['Acaron'] = 0x01CD;
  4822. t['Acircle'] = 0x24B6;
  4823. t['Acircumflex'] = 0x00C2;
  4824. t['Acircumflexacute'] = 0x1EA4;
  4825. t['Acircumflexdotbelow'] = 0x1EAC;
  4826. t['Acircumflexgrave'] = 0x1EA6;
  4827. t['Acircumflexhookabove'] = 0x1EA8;
  4828. t['Acircumflexsmall'] = 0xF7E2;
  4829. t['Acircumflextilde'] = 0x1EAA;
  4830. t['Acute'] = 0xF6C9;
  4831. t['Acutesmall'] = 0xF7B4;
  4832. t['Acyrillic'] = 0x0410;
  4833. t['Adblgrave'] = 0x0200;
  4834. t['Adieresis'] = 0x00C4;
  4835. t['Adieresiscyrillic'] = 0x04D2;
  4836. t['Adieresismacron'] = 0x01DE;
  4837. t['Adieresissmall'] = 0xF7E4;
  4838. t['Adotbelow'] = 0x1EA0;
  4839. t['Adotmacron'] = 0x01E0;
  4840. t['Agrave'] = 0x00C0;
  4841. t['Agravesmall'] = 0xF7E0;
  4842. t['Ahookabove'] = 0x1EA2;
  4843. t['Aiecyrillic'] = 0x04D4;
  4844. t['Ainvertedbreve'] = 0x0202;
  4845. t['Alpha'] = 0x0391;
  4846. t['Alphatonos'] = 0x0386;
  4847. t['Amacron'] = 0x0100;
  4848. t['Amonospace'] = 0xFF21;
  4849. t['Aogonek'] = 0x0104;
  4850. t['Aring'] = 0x00C5;
  4851. t['Aringacute'] = 0x01FA;
  4852. t['Aringbelow'] = 0x1E00;
  4853. t['Aringsmall'] = 0xF7E5;
  4854. t['Asmall'] = 0xF761;
  4855. t['Atilde'] = 0x00C3;
  4856. t['Atildesmall'] = 0xF7E3;
  4857. t['Aybarmenian'] = 0x0531;
  4858. t['B'] = 0x0042;
  4859. t['Bcircle'] = 0x24B7;
  4860. t['Bdotaccent'] = 0x1E02;
  4861. t['Bdotbelow'] = 0x1E04;
  4862. t['Becyrillic'] = 0x0411;
  4863. t['Benarmenian'] = 0x0532;
  4864. t['Beta'] = 0x0392;
  4865. t['Bhook'] = 0x0181;
  4866. t['Blinebelow'] = 0x1E06;
  4867. t['Bmonospace'] = 0xFF22;
  4868. t['Brevesmall'] = 0xF6F4;
  4869. t['Bsmall'] = 0xF762;
  4870. t['Btopbar'] = 0x0182;
  4871. t['C'] = 0x0043;
  4872. t['Caarmenian'] = 0x053E;
  4873. t['Cacute'] = 0x0106;
  4874. t['Caron'] = 0xF6CA;
  4875. t['Caronsmall'] = 0xF6F5;
  4876. t['Ccaron'] = 0x010C;
  4877. t['Ccedilla'] = 0x00C7;
  4878. t['Ccedillaacute'] = 0x1E08;
  4879. t['Ccedillasmall'] = 0xF7E7;
  4880. t['Ccircle'] = 0x24B8;
  4881. t['Ccircumflex'] = 0x0108;
  4882. t['Cdot'] = 0x010A;
  4883. t['Cdotaccent'] = 0x010A;
  4884. t['Cedillasmall'] = 0xF7B8;
  4885. t['Chaarmenian'] = 0x0549;
  4886. t['Cheabkhasiancyrillic'] = 0x04BC;
  4887. t['Checyrillic'] = 0x0427;
  4888. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  4889. t['Chedescendercyrillic'] = 0x04B6;
  4890. t['Chedieresiscyrillic'] = 0x04F4;
  4891. t['Cheharmenian'] = 0x0543;
  4892. t['Chekhakassiancyrillic'] = 0x04CB;
  4893. t['Cheverticalstrokecyrillic'] = 0x04B8;
  4894. t['Chi'] = 0x03A7;
  4895. t['Chook'] = 0x0187;
  4896. t['Circumflexsmall'] = 0xF6F6;
  4897. t['Cmonospace'] = 0xFF23;
  4898. t['Coarmenian'] = 0x0551;
  4899. t['Csmall'] = 0xF763;
  4900. t['D'] = 0x0044;
  4901. t['DZ'] = 0x01F1;
  4902. t['DZcaron'] = 0x01C4;
  4903. t['Daarmenian'] = 0x0534;
  4904. t['Dafrican'] = 0x0189;
  4905. t['Dcaron'] = 0x010E;
  4906. t['Dcedilla'] = 0x1E10;
  4907. t['Dcircle'] = 0x24B9;
  4908. t['Dcircumflexbelow'] = 0x1E12;
  4909. t['Dcroat'] = 0x0110;
  4910. t['Ddotaccent'] = 0x1E0A;
  4911. t['Ddotbelow'] = 0x1E0C;
  4912. t['Decyrillic'] = 0x0414;
  4913. t['Deicoptic'] = 0x03EE;
  4914. t['Delta'] = 0x2206;
  4915. t['Deltagreek'] = 0x0394;
  4916. t['Dhook'] = 0x018A;
  4917. t['Dieresis'] = 0xF6CB;
  4918. t['DieresisAcute'] = 0xF6CC;
  4919. t['DieresisGrave'] = 0xF6CD;
  4920. t['Dieresissmall'] = 0xF7A8;
  4921. t['Digammagreek'] = 0x03DC;
  4922. t['Djecyrillic'] = 0x0402;
  4923. t['Dlinebelow'] = 0x1E0E;
  4924. t['Dmonospace'] = 0xFF24;
  4925. t['Dotaccentsmall'] = 0xF6F7;
  4926. t['Dslash'] = 0x0110;
  4927. t['Dsmall'] = 0xF764;
  4928. t['Dtopbar'] = 0x018B;
  4929. t['Dz'] = 0x01F2;
  4930. t['Dzcaron'] = 0x01C5;
  4931. t['Dzeabkhasiancyrillic'] = 0x04E0;
  4932. t['Dzecyrillic'] = 0x0405;
  4933. t['Dzhecyrillic'] = 0x040F;
  4934. t['E'] = 0x0045;
  4935. t['Eacute'] = 0x00C9;
  4936. t['Eacutesmall'] = 0xF7E9;
  4937. t['Ebreve'] = 0x0114;
  4938. t['Ecaron'] = 0x011A;
  4939. t['Ecedillabreve'] = 0x1E1C;
  4940. t['Echarmenian'] = 0x0535;
  4941. t['Ecircle'] = 0x24BA;
  4942. t['Ecircumflex'] = 0x00CA;
  4943. t['Ecircumflexacute'] = 0x1EBE;
  4944. t['Ecircumflexbelow'] = 0x1E18;
  4945. t['Ecircumflexdotbelow'] = 0x1EC6;
  4946. t['Ecircumflexgrave'] = 0x1EC0;
  4947. t['Ecircumflexhookabove'] = 0x1EC2;
  4948. t['Ecircumflexsmall'] = 0xF7EA;
  4949. t['Ecircumflextilde'] = 0x1EC4;
  4950. t['Ecyrillic'] = 0x0404;
  4951. t['Edblgrave'] = 0x0204;
  4952. t['Edieresis'] = 0x00CB;
  4953. t['Edieresissmall'] = 0xF7EB;
  4954. t['Edot'] = 0x0116;
  4955. t['Edotaccent'] = 0x0116;
  4956. t['Edotbelow'] = 0x1EB8;
  4957. t['Efcyrillic'] = 0x0424;
  4958. t['Egrave'] = 0x00C8;
  4959. t['Egravesmall'] = 0xF7E8;
  4960. t['Eharmenian'] = 0x0537;
  4961. t['Ehookabove'] = 0x1EBA;
  4962. t['Eightroman'] = 0x2167;
  4963. t['Einvertedbreve'] = 0x0206;
  4964. t['Eiotifiedcyrillic'] = 0x0464;
  4965. t['Elcyrillic'] = 0x041B;
  4966. t['Elevenroman'] = 0x216A;
  4967. t['Emacron'] = 0x0112;
  4968. t['Emacronacute'] = 0x1E16;
  4969. t['Emacrongrave'] = 0x1E14;
  4970. t['Emcyrillic'] = 0x041C;
  4971. t['Emonospace'] = 0xFF25;
  4972. t['Encyrillic'] = 0x041D;
  4973. t['Endescendercyrillic'] = 0x04A2;
  4974. t['Eng'] = 0x014A;
  4975. t['Enghecyrillic'] = 0x04A4;
  4976. t['Enhookcyrillic'] = 0x04C7;
  4977. t['Eogonek'] = 0x0118;
  4978. t['Eopen'] = 0x0190;
  4979. t['Epsilon'] = 0x0395;
  4980. t['Epsilontonos'] = 0x0388;
  4981. t['Ercyrillic'] = 0x0420;
  4982. t['Ereversed'] = 0x018E;
  4983. t['Ereversedcyrillic'] = 0x042D;
  4984. t['Escyrillic'] = 0x0421;
  4985. t['Esdescendercyrillic'] = 0x04AA;
  4986. t['Esh'] = 0x01A9;
  4987. t['Esmall'] = 0xF765;
  4988. t['Eta'] = 0x0397;
  4989. t['Etarmenian'] = 0x0538;
  4990. t['Etatonos'] = 0x0389;
  4991. t['Eth'] = 0x00D0;
  4992. t['Ethsmall'] = 0xF7F0;
  4993. t['Etilde'] = 0x1EBC;
  4994. t['Etildebelow'] = 0x1E1A;
  4995. t['Euro'] = 0x20AC;
  4996. t['Ezh'] = 0x01B7;
  4997. t['Ezhcaron'] = 0x01EE;
  4998. t['Ezhreversed'] = 0x01B8;
  4999. t['F'] = 0x0046;
  5000. t['Fcircle'] = 0x24BB;
  5001. t['Fdotaccent'] = 0x1E1E;
  5002. t['Feharmenian'] = 0x0556;
  5003. t['Feicoptic'] = 0x03E4;
  5004. t['Fhook'] = 0x0191;
  5005. t['Fitacyrillic'] = 0x0472;
  5006. t['Fiveroman'] = 0x2164;
  5007. t['Fmonospace'] = 0xFF26;
  5008. t['Fourroman'] = 0x2163;
  5009. t['Fsmall'] = 0xF766;
  5010. t['G'] = 0x0047;
  5011. t['GBsquare'] = 0x3387;
  5012. t['Gacute'] = 0x01F4;
  5013. t['Gamma'] = 0x0393;
  5014. t['Gammaafrican'] = 0x0194;
  5015. t['Gangiacoptic'] = 0x03EA;
  5016. t['Gbreve'] = 0x011E;
  5017. t['Gcaron'] = 0x01E6;
  5018. t['Gcedilla'] = 0x0122;
  5019. t['Gcircle'] = 0x24BC;
  5020. t['Gcircumflex'] = 0x011C;
  5021. t['Gcommaaccent'] = 0x0122;
  5022. t['Gdot'] = 0x0120;
  5023. t['Gdotaccent'] = 0x0120;
  5024. t['Gecyrillic'] = 0x0413;
  5025. t['Ghadarmenian'] = 0x0542;
  5026. t['Ghemiddlehookcyrillic'] = 0x0494;
  5027. t['Ghestrokecyrillic'] = 0x0492;
  5028. t['Gheupturncyrillic'] = 0x0490;
  5029. t['Ghook'] = 0x0193;
  5030. t['Gimarmenian'] = 0x0533;
  5031. t['Gjecyrillic'] = 0x0403;
  5032. t['Gmacron'] = 0x1E20;
  5033. t['Gmonospace'] = 0xFF27;
  5034. t['Grave'] = 0xF6CE;
  5035. t['Gravesmall'] = 0xF760;
  5036. t['Gsmall'] = 0xF767;
  5037. t['Gsmallhook'] = 0x029B;
  5038. t['Gstroke'] = 0x01E4;
  5039. t['H'] = 0x0048;
  5040. t['H18533'] = 0x25CF;
  5041. t['H18543'] = 0x25AA;
  5042. t['H18551'] = 0x25AB;
  5043. t['H22073'] = 0x25A1;
  5044. t['HPsquare'] = 0x33CB;
  5045. t['Haabkhasiancyrillic'] = 0x04A8;
  5046. t['Hadescendercyrillic'] = 0x04B2;
  5047. t['Hardsigncyrillic'] = 0x042A;
  5048. t['Hbar'] = 0x0126;
  5049. t['Hbrevebelow'] = 0x1E2A;
  5050. t['Hcedilla'] = 0x1E28;
  5051. t['Hcircle'] = 0x24BD;
  5052. t['Hcircumflex'] = 0x0124;
  5053. t['Hdieresis'] = 0x1E26;
  5054. t['Hdotaccent'] = 0x1E22;
  5055. t['Hdotbelow'] = 0x1E24;
  5056. t['Hmonospace'] = 0xFF28;
  5057. t['Hoarmenian'] = 0x0540;
  5058. t['Horicoptic'] = 0x03E8;
  5059. t['Hsmall'] = 0xF768;
  5060. t['Hungarumlaut'] = 0xF6CF;
  5061. t['Hungarumlautsmall'] = 0xF6F8;
  5062. t['Hzsquare'] = 0x3390;
  5063. t['I'] = 0x0049;
  5064. t['IAcyrillic'] = 0x042F;
  5065. t['IJ'] = 0x0132;
  5066. t['IUcyrillic'] = 0x042E;
  5067. t['Iacute'] = 0x00CD;
  5068. t['Iacutesmall'] = 0xF7ED;
  5069. t['Ibreve'] = 0x012C;
  5070. t['Icaron'] = 0x01CF;
  5071. t['Icircle'] = 0x24BE;
  5072. t['Icircumflex'] = 0x00CE;
  5073. t['Icircumflexsmall'] = 0xF7EE;
  5074. t['Icyrillic'] = 0x0406;
  5075. t['Idblgrave'] = 0x0208;
  5076. t['Idieresis'] = 0x00CF;
  5077. t['Idieresisacute'] = 0x1E2E;
  5078. t['Idieresiscyrillic'] = 0x04E4;
  5079. t['Idieresissmall'] = 0xF7EF;
  5080. t['Idot'] = 0x0130;
  5081. t['Idotaccent'] = 0x0130;
  5082. t['Idotbelow'] = 0x1ECA;
  5083. t['Iebrevecyrillic'] = 0x04D6;
  5084. t['Iecyrillic'] = 0x0415;
  5085. t['Ifraktur'] = 0x2111;
  5086. t['Igrave'] = 0x00CC;
  5087. t['Igravesmall'] = 0xF7EC;
  5088. t['Ihookabove'] = 0x1EC8;
  5089. t['Iicyrillic'] = 0x0418;
  5090. t['Iinvertedbreve'] = 0x020A;
  5091. t['Iishortcyrillic'] = 0x0419;
  5092. t['Imacron'] = 0x012A;
  5093. t['Imacroncyrillic'] = 0x04E2;
  5094. t['Imonospace'] = 0xFF29;
  5095. t['Iniarmenian'] = 0x053B;
  5096. t['Iocyrillic'] = 0x0401;
  5097. t['Iogonek'] = 0x012E;
  5098. t['Iota'] = 0x0399;
  5099. t['Iotaafrican'] = 0x0196;
  5100. t['Iotadieresis'] = 0x03AA;
  5101. t['Iotatonos'] = 0x038A;
  5102. t['Ismall'] = 0xF769;
  5103. t['Istroke'] = 0x0197;
  5104. t['Itilde'] = 0x0128;
  5105. t['Itildebelow'] = 0x1E2C;
  5106. t['Izhitsacyrillic'] = 0x0474;
  5107. t['Izhitsadblgravecyrillic'] = 0x0476;
  5108. t['J'] = 0x004A;
  5109. t['Jaarmenian'] = 0x0541;
  5110. t['Jcircle'] = 0x24BF;
  5111. t['Jcircumflex'] = 0x0134;
  5112. t['Jecyrillic'] = 0x0408;
  5113. t['Jheharmenian'] = 0x054B;
  5114. t['Jmonospace'] = 0xFF2A;
  5115. t['Jsmall'] = 0xF76A;
  5116. t['K'] = 0x004B;
  5117. t['KBsquare'] = 0x3385;
  5118. t['KKsquare'] = 0x33CD;
  5119. t['Kabashkircyrillic'] = 0x04A0;
  5120. t['Kacute'] = 0x1E30;
  5121. t['Kacyrillic'] = 0x041A;
  5122. t['Kadescendercyrillic'] = 0x049A;
  5123. t['Kahookcyrillic'] = 0x04C3;
  5124. t['Kappa'] = 0x039A;
  5125. t['Kastrokecyrillic'] = 0x049E;
  5126. t['Kaverticalstrokecyrillic'] = 0x049C;
  5127. t['Kcaron'] = 0x01E8;
  5128. t['Kcedilla'] = 0x0136;
  5129. t['Kcircle'] = 0x24C0;
  5130. t['Kcommaaccent'] = 0x0136;
  5131. t['Kdotbelow'] = 0x1E32;
  5132. t['Keharmenian'] = 0x0554;
  5133. t['Kenarmenian'] = 0x053F;
  5134. t['Khacyrillic'] = 0x0425;
  5135. t['Kheicoptic'] = 0x03E6;
  5136. t['Khook'] = 0x0198;
  5137. t['Kjecyrillic'] = 0x040C;
  5138. t['Klinebelow'] = 0x1E34;
  5139. t['Kmonospace'] = 0xFF2B;
  5140. t['Koppacyrillic'] = 0x0480;
  5141. t['Koppagreek'] = 0x03DE;
  5142. t['Ksicyrillic'] = 0x046E;
  5143. t['Ksmall'] = 0xF76B;
  5144. t['L'] = 0x004C;
  5145. t['LJ'] = 0x01C7;
  5146. t['LL'] = 0xF6BF;
  5147. t['Lacute'] = 0x0139;
  5148. t['Lambda'] = 0x039B;
  5149. t['Lcaron'] = 0x013D;
  5150. t['Lcedilla'] = 0x013B;
  5151. t['Lcircle'] = 0x24C1;
  5152. t['Lcircumflexbelow'] = 0x1E3C;
  5153. t['Lcommaaccent'] = 0x013B;
  5154. t['Ldot'] = 0x013F;
  5155. t['Ldotaccent'] = 0x013F;
  5156. t['Ldotbelow'] = 0x1E36;
  5157. t['Ldotbelowmacron'] = 0x1E38;
  5158. t['Liwnarmenian'] = 0x053C;
  5159. t['Lj'] = 0x01C8;
  5160. t['Ljecyrillic'] = 0x0409;
  5161. t['Llinebelow'] = 0x1E3A;
  5162. t['Lmonospace'] = 0xFF2C;
  5163. t['Lslash'] = 0x0141;
  5164. t['Lslashsmall'] = 0xF6F9;
  5165. t['Lsmall'] = 0xF76C;
  5166. t['M'] = 0x004D;
  5167. t['MBsquare'] = 0x3386;
  5168. t['Macron'] = 0xF6D0;
  5169. t['Macronsmall'] = 0xF7AF;
  5170. t['Macute'] = 0x1E3E;
  5171. t['Mcircle'] = 0x24C2;
  5172. t['Mdotaccent'] = 0x1E40;
  5173. t['Mdotbelow'] = 0x1E42;
  5174. t['Menarmenian'] = 0x0544;
  5175. t['Mmonospace'] = 0xFF2D;
  5176. t['Msmall'] = 0xF76D;
  5177. t['Mturned'] = 0x019C;
  5178. t['Mu'] = 0x039C;
  5179. t['N'] = 0x004E;
  5180. t['NJ'] = 0x01CA;
  5181. t['Nacute'] = 0x0143;
  5182. t['Ncaron'] = 0x0147;
  5183. t['Ncedilla'] = 0x0145;
  5184. t['Ncircle'] = 0x24C3;
  5185. t['Ncircumflexbelow'] = 0x1E4A;
  5186. t['Ncommaaccent'] = 0x0145;
  5187. t['Ndotaccent'] = 0x1E44;
  5188. t['Ndotbelow'] = 0x1E46;
  5189. t['Nhookleft'] = 0x019D;
  5190. t['Nineroman'] = 0x2168;
  5191. t['Nj'] = 0x01CB;
  5192. t['Njecyrillic'] = 0x040A;
  5193. t['Nlinebelow'] = 0x1E48;
  5194. t['Nmonospace'] = 0xFF2E;
  5195. t['Nowarmenian'] = 0x0546;
  5196. t['Nsmall'] = 0xF76E;
  5197. t['Ntilde'] = 0x00D1;
  5198. t['Ntildesmall'] = 0xF7F1;
  5199. t['Nu'] = 0x039D;
  5200. t['O'] = 0x004F;
  5201. t['OE'] = 0x0152;
  5202. t['OEsmall'] = 0xF6FA;
  5203. t['Oacute'] = 0x00D3;
  5204. t['Oacutesmall'] = 0xF7F3;
  5205. t['Obarredcyrillic'] = 0x04E8;
  5206. t['Obarreddieresiscyrillic'] = 0x04EA;
  5207. t['Obreve'] = 0x014E;
  5208. t['Ocaron'] = 0x01D1;
  5209. t['Ocenteredtilde'] = 0x019F;
  5210. t['Ocircle'] = 0x24C4;
  5211. t['Ocircumflex'] = 0x00D4;
  5212. t['Ocircumflexacute'] = 0x1ED0;
  5213. t['Ocircumflexdotbelow'] = 0x1ED8;
  5214. t['Ocircumflexgrave'] = 0x1ED2;
  5215. t['Ocircumflexhookabove'] = 0x1ED4;
  5216. t['Ocircumflexsmall'] = 0xF7F4;
  5217. t['Ocircumflextilde'] = 0x1ED6;
  5218. t['Ocyrillic'] = 0x041E;
  5219. t['Odblacute'] = 0x0150;
  5220. t['Odblgrave'] = 0x020C;
  5221. t['Odieresis'] = 0x00D6;
  5222. t['Odieresiscyrillic'] = 0x04E6;
  5223. t['Odieresissmall'] = 0xF7F6;
  5224. t['Odotbelow'] = 0x1ECC;
  5225. t['Ogoneksmall'] = 0xF6FB;
  5226. t['Ograve'] = 0x00D2;
  5227. t['Ogravesmall'] = 0xF7F2;
  5228. t['Oharmenian'] = 0x0555;
  5229. t['Ohm'] = 0x2126;
  5230. t['Ohookabove'] = 0x1ECE;
  5231. t['Ohorn'] = 0x01A0;
  5232. t['Ohornacute'] = 0x1EDA;
  5233. t['Ohorndotbelow'] = 0x1EE2;
  5234. t['Ohorngrave'] = 0x1EDC;
  5235. t['Ohornhookabove'] = 0x1EDE;
  5236. t['Ohorntilde'] = 0x1EE0;
  5237. t['Ohungarumlaut'] = 0x0150;
  5238. t['Oi'] = 0x01A2;
  5239. t['Oinvertedbreve'] = 0x020E;
  5240. t['Omacron'] = 0x014C;
  5241. t['Omacronacute'] = 0x1E52;
  5242. t['Omacrongrave'] = 0x1E50;
  5243. t['Omega'] = 0x2126;
  5244. t['Omegacyrillic'] = 0x0460;
  5245. t['Omegagreek'] = 0x03A9;
  5246. t['Omegaroundcyrillic'] = 0x047A;
  5247. t['Omegatitlocyrillic'] = 0x047C;
  5248. t['Omegatonos'] = 0x038F;
  5249. t['Omicron'] = 0x039F;
  5250. t['Omicrontonos'] = 0x038C;
  5251. t['Omonospace'] = 0xFF2F;
  5252. t['Oneroman'] = 0x2160;
  5253. t['Oogonek'] = 0x01EA;
  5254. t['Oogonekmacron'] = 0x01EC;
  5255. t['Oopen'] = 0x0186;
  5256. t['Oslash'] = 0x00D8;
  5257. t['Oslashacute'] = 0x01FE;
  5258. t['Oslashsmall'] = 0xF7F8;
  5259. t['Osmall'] = 0xF76F;
  5260. t['Ostrokeacute'] = 0x01FE;
  5261. t['Otcyrillic'] = 0x047E;
  5262. t['Otilde'] = 0x00D5;
  5263. t['Otildeacute'] = 0x1E4C;
  5264. t['Otildedieresis'] = 0x1E4E;
  5265. t['Otildesmall'] = 0xF7F5;
  5266. t['P'] = 0x0050;
  5267. t['Pacute'] = 0x1E54;
  5268. t['Pcircle'] = 0x24C5;
  5269. t['Pdotaccent'] = 0x1E56;
  5270. t['Pecyrillic'] = 0x041F;
  5271. t['Peharmenian'] = 0x054A;
  5272. t['Pemiddlehookcyrillic'] = 0x04A6;
  5273. t['Phi'] = 0x03A6;
  5274. t['Phook'] = 0x01A4;
  5275. t['Pi'] = 0x03A0;
  5276. t['Piwrarmenian'] = 0x0553;
  5277. t['Pmonospace'] = 0xFF30;
  5278. t['Psi'] = 0x03A8;
  5279. t['Psicyrillic'] = 0x0470;
  5280. t['Psmall'] = 0xF770;
  5281. t['Q'] = 0x0051;
  5282. t['Qcircle'] = 0x24C6;
  5283. t['Qmonospace'] = 0xFF31;
  5284. t['Qsmall'] = 0xF771;
  5285. t['R'] = 0x0052;
  5286. t['Raarmenian'] = 0x054C;
  5287. t['Racute'] = 0x0154;
  5288. t['Rcaron'] = 0x0158;
  5289. t['Rcedilla'] = 0x0156;
  5290. t['Rcircle'] = 0x24C7;
  5291. t['Rcommaaccent'] = 0x0156;
  5292. t['Rdblgrave'] = 0x0210;
  5293. t['Rdotaccent'] = 0x1E58;
  5294. t['Rdotbelow'] = 0x1E5A;
  5295. t['Rdotbelowmacron'] = 0x1E5C;
  5296. t['Reharmenian'] = 0x0550;
  5297. t['Rfraktur'] = 0x211C;
  5298. t['Rho'] = 0x03A1;
  5299. t['Ringsmall'] = 0xF6FC;
  5300. t['Rinvertedbreve'] = 0x0212;
  5301. t['Rlinebelow'] = 0x1E5E;
  5302. t['Rmonospace'] = 0xFF32;
  5303. t['Rsmall'] = 0xF772;
  5304. t['Rsmallinverted'] = 0x0281;
  5305. t['Rsmallinvertedsuperior'] = 0x02B6;
  5306. t['S'] = 0x0053;
  5307. t['SF010000'] = 0x250C;
  5308. t['SF020000'] = 0x2514;
  5309. t['SF030000'] = 0x2510;
  5310. t['SF040000'] = 0x2518;
  5311. t['SF050000'] = 0x253C;
  5312. t['SF060000'] = 0x252C;
  5313. t['SF070000'] = 0x2534;
  5314. t['SF080000'] = 0x251C;
  5315. t['SF090000'] = 0x2524;
  5316. t['SF100000'] = 0x2500;
  5317. t['SF110000'] = 0x2502;
  5318. t['SF190000'] = 0x2561;
  5319. t['SF200000'] = 0x2562;
  5320. t['SF210000'] = 0x2556;
  5321. t['SF220000'] = 0x2555;
  5322. t['SF230000'] = 0x2563;
  5323. t['SF240000'] = 0x2551;
  5324. t['SF250000'] = 0x2557;
  5325. t['SF260000'] = 0x255D;
  5326. t['SF270000'] = 0x255C;
  5327. t['SF280000'] = 0x255B;
  5328. t['SF360000'] = 0x255E;
  5329. t['SF370000'] = 0x255F;
  5330. t['SF380000'] = 0x255A;
  5331. t['SF390000'] = 0x2554;
  5332. t['SF400000'] = 0x2569;
  5333. t['SF410000'] = 0x2566;
  5334. t['SF420000'] = 0x2560;
  5335. t['SF430000'] = 0x2550;
  5336. t['SF440000'] = 0x256C;
  5337. t['SF450000'] = 0x2567;
  5338. t['SF460000'] = 0x2568;
  5339. t['SF470000'] = 0x2564;
  5340. t['SF480000'] = 0x2565;
  5341. t['SF490000'] = 0x2559;
  5342. t['SF500000'] = 0x2558;
  5343. t['SF510000'] = 0x2552;
  5344. t['SF520000'] = 0x2553;
  5345. t['SF530000'] = 0x256B;
  5346. t['SF540000'] = 0x256A;
  5347. t['Sacute'] = 0x015A;
  5348. t['Sacutedotaccent'] = 0x1E64;
  5349. t['Sampigreek'] = 0x03E0;
  5350. t['Scaron'] = 0x0160;
  5351. t['Scarondotaccent'] = 0x1E66;
  5352. t['Scaronsmall'] = 0xF6FD;
  5353. t['Scedilla'] = 0x015E;
  5354. t['Schwa'] = 0x018F;
  5355. t['Schwacyrillic'] = 0x04D8;
  5356. t['Schwadieresiscyrillic'] = 0x04DA;
  5357. t['Scircle'] = 0x24C8;
  5358. t['Scircumflex'] = 0x015C;
  5359. t['Scommaaccent'] = 0x0218;
  5360. t['Sdotaccent'] = 0x1E60;
  5361. t['Sdotbelow'] = 0x1E62;
  5362. t['Sdotbelowdotaccent'] = 0x1E68;
  5363. t['Seharmenian'] = 0x054D;
  5364. t['Sevenroman'] = 0x2166;
  5365. t['Shaarmenian'] = 0x0547;
  5366. t['Shacyrillic'] = 0x0428;
  5367. t['Shchacyrillic'] = 0x0429;
  5368. t['Sheicoptic'] = 0x03E2;
  5369. t['Shhacyrillic'] = 0x04BA;
  5370. t['Shimacoptic'] = 0x03EC;
  5371. t['Sigma'] = 0x03A3;
  5372. t['Sixroman'] = 0x2165;
  5373. t['Smonospace'] = 0xFF33;
  5374. t['Softsigncyrillic'] = 0x042C;
  5375. t['Ssmall'] = 0xF773;
  5376. t['Stigmagreek'] = 0x03DA;
  5377. t['T'] = 0x0054;
  5378. t['Tau'] = 0x03A4;
  5379. t['Tbar'] = 0x0166;
  5380. t['Tcaron'] = 0x0164;
  5381. t['Tcedilla'] = 0x0162;
  5382. t['Tcircle'] = 0x24C9;
  5383. t['Tcircumflexbelow'] = 0x1E70;
  5384. t['Tcommaaccent'] = 0x0162;
  5385. t['Tdotaccent'] = 0x1E6A;
  5386. t['Tdotbelow'] = 0x1E6C;
  5387. t['Tecyrillic'] = 0x0422;
  5388. t['Tedescendercyrillic'] = 0x04AC;
  5389. t['Tenroman'] = 0x2169;
  5390. t['Tetsecyrillic'] = 0x04B4;
  5391. t['Theta'] = 0x0398;
  5392. t['Thook'] = 0x01AC;
  5393. t['Thorn'] = 0x00DE;
  5394. t['Thornsmall'] = 0xF7FE;
  5395. t['Threeroman'] = 0x2162;
  5396. t['Tildesmall'] = 0xF6FE;
  5397. t['Tiwnarmenian'] = 0x054F;
  5398. t['Tlinebelow'] = 0x1E6E;
  5399. t['Tmonospace'] = 0xFF34;
  5400. t['Toarmenian'] = 0x0539;
  5401. t['Tonefive'] = 0x01BC;
  5402. t['Tonesix'] = 0x0184;
  5403. t['Tonetwo'] = 0x01A7;
  5404. t['Tretroflexhook'] = 0x01AE;
  5405. t['Tsecyrillic'] = 0x0426;
  5406. t['Tshecyrillic'] = 0x040B;
  5407. t['Tsmall'] = 0xF774;
  5408. t['Twelveroman'] = 0x216B;
  5409. t['Tworoman'] = 0x2161;
  5410. t['U'] = 0x0055;
  5411. t['Uacute'] = 0x00DA;
  5412. t['Uacutesmall'] = 0xF7FA;
  5413. t['Ubreve'] = 0x016C;
  5414. t['Ucaron'] = 0x01D3;
  5415. t['Ucircle'] = 0x24CA;
  5416. t['Ucircumflex'] = 0x00DB;
  5417. t['Ucircumflexbelow'] = 0x1E76;
  5418. t['Ucircumflexsmall'] = 0xF7FB;
  5419. t['Ucyrillic'] = 0x0423;
  5420. t['Udblacute'] = 0x0170;
  5421. t['Udblgrave'] = 0x0214;
  5422. t['Udieresis'] = 0x00DC;
  5423. t['Udieresisacute'] = 0x01D7;
  5424. t['Udieresisbelow'] = 0x1E72;
  5425. t['Udieresiscaron'] = 0x01D9;
  5426. t['Udieresiscyrillic'] = 0x04F0;
  5427. t['Udieresisgrave'] = 0x01DB;
  5428. t['Udieresismacron'] = 0x01D5;
  5429. t['Udieresissmall'] = 0xF7FC;
  5430. t['Udotbelow'] = 0x1EE4;
  5431. t['Ugrave'] = 0x00D9;
  5432. t['Ugravesmall'] = 0xF7F9;
  5433. t['Uhookabove'] = 0x1EE6;
  5434. t['Uhorn'] = 0x01AF;
  5435. t['Uhornacute'] = 0x1EE8;
  5436. t['Uhorndotbelow'] = 0x1EF0;
  5437. t['Uhorngrave'] = 0x1EEA;
  5438. t['Uhornhookabove'] = 0x1EEC;
  5439. t['Uhorntilde'] = 0x1EEE;
  5440. t['Uhungarumlaut'] = 0x0170;
  5441. t['Uhungarumlautcyrillic'] = 0x04F2;
  5442. t['Uinvertedbreve'] = 0x0216;
  5443. t['Ukcyrillic'] = 0x0478;
  5444. t['Umacron'] = 0x016A;
  5445. t['Umacroncyrillic'] = 0x04EE;
  5446. t['Umacrondieresis'] = 0x1E7A;
  5447. t['Umonospace'] = 0xFF35;
  5448. t['Uogonek'] = 0x0172;
  5449. t['Upsilon'] = 0x03A5;
  5450. t['Upsilon1'] = 0x03D2;
  5451. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5452. t['Upsilonafrican'] = 0x01B1;
  5453. t['Upsilondieresis'] = 0x03AB;
  5454. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5455. t['Upsilonhooksymbol'] = 0x03D2;
  5456. t['Upsilontonos'] = 0x038E;
  5457. t['Uring'] = 0x016E;
  5458. t['Ushortcyrillic'] = 0x040E;
  5459. t['Usmall'] = 0xF775;
  5460. t['Ustraightcyrillic'] = 0x04AE;
  5461. t['Ustraightstrokecyrillic'] = 0x04B0;
  5462. t['Utilde'] = 0x0168;
  5463. t['Utildeacute'] = 0x1E78;
  5464. t['Utildebelow'] = 0x1E74;
  5465. t['V'] = 0x0056;
  5466. t['Vcircle'] = 0x24CB;
  5467. t['Vdotbelow'] = 0x1E7E;
  5468. t['Vecyrillic'] = 0x0412;
  5469. t['Vewarmenian'] = 0x054E;
  5470. t['Vhook'] = 0x01B2;
  5471. t['Vmonospace'] = 0xFF36;
  5472. t['Voarmenian'] = 0x0548;
  5473. t['Vsmall'] = 0xF776;
  5474. t['Vtilde'] = 0x1E7C;
  5475. t['W'] = 0x0057;
  5476. t['Wacute'] = 0x1E82;
  5477. t['Wcircle'] = 0x24CC;
  5478. t['Wcircumflex'] = 0x0174;
  5479. t['Wdieresis'] = 0x1E84;
  5480. t['Wdotaccent'] = 0x1E86;
  5481. t['Wdotbelow'] = 0x1E88;
  5482. t['Wgrave'] = 0x1E80;
  5483. t['Wmonospace'] = 0xFF37;
  5484. t['Wsmall'] = 0xF777;
  5485. t['X'] = 0x0058;
  5486. t['Xcircle'] = 0x24CD;
  5487. t['Xdieresis'] = 0x1E8C;
  5488. t['Xdotaccent'] = 0x1E8A;
  5489. t['Xeharmenian'] = 0x053D;
  5490. t['Xi'] = 0x039E;
  5491. t['Xmonospace'] = 0xFF38;
  5492. t['Xsmall'] = 0xF778;
  5493. t['Y'] = 0x0059;
  5494. t['Yacute'] = 0x00DD;
  5495. t['Yacutesmall'] = 0xF7FD;
  5496. t['Yatcyrillic'] = 0x0462;
  5497. t['Ycircle'] = 0x24CE;
  5498. t['Ycircumflex'] = 0x0176;
  5499. t['Ydieresis'] = 0x0178;
  5500. t['Ydieresissmall'] = 0xF7FF;
  5501. t['Ydotaccent'] = 0x1E8E;
  5502. t['Ydotbelow'] = 0x1EF4;
  5503. t['Yericyrillic'] = 0x042B;
  5504. t['Yerudieresiscyrillic'] = 0x04F8;
  5505. t['Ygrave'] = 0x1EF2;
  5506. t['Yhook'] = 0x01B3;
  5507. t['Yhookabove'] = 0x1EF6;
  5508. t['Yiarmenian'] = 0x0545;
  5509. t['Yicyrillic'] = 0x0407;
  5510. t['Yiwnarmenian'] = 0x0552;
  5511. t['Ymonospace'] = 0xFF39;
  5512. t['Ysmall'] = 0xF779;
  5513. t['Ytilde'] = 0x1EF8;
  5514. t['Yusbigcyrillic'] = 0x046A;
  5515. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5516. t['Yuslittlecyrillic'] = 0x0466;
  5517. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5518. t['Z'] = 0x005A;
  5519. t['Zaarmenian'] = 0x0536;
  5520. t['Zacute'] = 0x0179;
  5521. t['Zcaron'] = 0x017D;
  5522. t['Zcaronsmall'] = 0xF6FF;
  5523. t['Zcircle'] = 0x24CF;
  5524. t['Zcircumflex'] = 0x1E90;
  5525. t['Zdot'] = 0x017B;
  5526. t['Zdotaccent'] = 0x017B;
  5527. t['Zdotbelow'] = 0x1E92;
  5528. t['Zecyrillic'] = 0x0417;
  5529. t['Zedescendercyrillic'] = 0x0498;
  5530. t['Zedieresiscyrillic'] = 0x04DE;
  5531. t['Zeta'] = 0x0396;
  5532. t['Zhearmenian'] = 0x053A;
  5533. t['Zhebrevecyrillic'] = 0x04C1;
  5534. t['Zhecyrillic'] = 0x0416;
  5535. t['Zhedescendercyrillic'] = 0x0496;
  5536. t['Zhedieresiscyrillic'] = 0x04DC;
  5537. t['Zlinebelow'] = 0x1E94;
  5538. t['Zmonospace'] = 0xFF3A;
  5539. t['Zsmall'] = 0xF77A;
  5540. t['Zstroke'] = 0x01B5;
  5541. t['a'] = 0x0061;
  5542. t['aabengali'] = 0x0986;
  5543. t['aacute'] = 0x00E1;
  5544. t['aadeva'] = 0x0906;
  5545. t['aagujarati'] = 0x0A86;
  5546. t['aagurmukhi'] = 0x0A06;
  5547. t['aamatragurmukhi'] = 0x0A3E;
  5548. t['aarusquare'] = 0x3303;
  5549. t['aavowelsignbengali'] = 0x09BE;
  5550. t['aavowelsigndeva'] = 0x093E;
  5551. t['aavowelsigngujarati'] = 0x0ABE;
  5552. t['abbreviationmarkarmenian'] = 0x055F;
  5553. t['abbreviationsigndeva'] = 0x0970;
  5554. t['abengali'] = 0x0985;
  5555. t['abopomofo'] = 0x311A;
  5556. t['abreve'] = 0x0103;
  5557. t['abreveacute'] = 0x1EAF;
  5558. t['abrevecyrillic'] = 0x04D1;
  5559. t['abrevedotbelow'] = 0x1EB7;
  5560. t['abrevegrave'] = 0x1EB1;
  5561. t['abrevehookabove'] = 0x1EB3;
  5562. t['abrevetilde'] = 0x1EB5;
  5563. t['acaron'] = 0x01CE;
  5564. t['acircle'] = 0x24D0;
  5565. t['acircumflex'] = 0x00E2;
  5566. t['acircumflexacute'] = 0x1EA5;
  5567. t['acircumflexdotbelow'] = 0x1EAD;
  5568. t['acircumflexgrave'] = 0x1EA7;
  5569. t['acircumflexhookabove'] = 0x1EA9;
  5570. t['acircumflextilde'] = 0x1EAB;
  5571. t['acute'] = 0x00B4;
  5572. t['acutebelowcmb'] = 0x0317;
  5573. t['acutecmb'] = 0x0301;
  5574. t['acutecomb'] = 0x0301;
  5575. t['acutedeva'] = 0x0954;
  5576. t['acutelowmod'] = 0x02CF;
  5577. t['acutetonecmb'] = 0x0341;
  5578. t['acyrillic'] = 0x0430;
  5579. t['adblgrave'] = 0x0201;
  5580. t['addakgurmukhi'] = 0x0A71;
  5581. t['adeva'] = 0x0905;
  5582. t['adieresis'] = 0x00E4;
  5583. t['adieresiscyrillic'] = 0x04D3;
  5584. t['adieresismacron'] = 0x01DF;
  5585. t['adotbelow'] = 0x1EA1;
  5586. t['adotmacron'] = 0x01E1;
  5587. t['ae'] = 0x00E6;
  5588. t['aeacute'] = 0x01FD;
  5589. t['aekorean'] = 0x3150;
  5590. t['aemacron'] = 0x01E3;
  5591. t['afii00208'] = 0x2015;
  5592. t['afii08941'] = 0x20A4;
  5593. t['afii10017'] = 0x0410;
  5594. t['afii10018'] = 0x0411;
  5595. t['afii10019'] = 0x0412;
  5596. t['afii10020'] = 0x0413;
  5597. t['afii10021'] = 0x0414;
  5598. t['afii10022'] = 0x0415;
  5599. t['afii10023'] = 0x0401;
  5600. t['afii10024'] = 0x0416;
  5601. t['afii10025'] = 0x0417;
  5602. t['afii10026'] = 0x0418;
  5603. t['afii10027'] = 0x0419;
  5604. t['afii10028'] = 0x041A;
  5605. t['afii10029'] = 0x041B;
  5606. t['afii10030'] = 0x041C;
  5607. t['afii10031'] = 0x041D;
  5608. t['afii10032'] = 0x041E;
  5609. t['afii10033'] = 0x041F;
  5610. t['afii10034'] = 0x0420;
  5611. t['afii10035'] = 0x0421;
  5612. t['afii10036'] = 0x0422;
  5613. t['afii10037'] = 0x0423;
  5614. t['afii10038'] = 0x0424;
  5615. t['afii10039'] = 0x0425;
  5616. t['afii10040'] = 0x0426;
  5617. t['afii10041'] = 0x0427;
  5618. t['afii10042'] = 0x0428;
  5619. t['afii10043'] = 0x0429;
  5620. t['afii10044'] = 0x042A;
  5621. t['afii10045'] = 0x042B;
  5622. t['afii10046'] = 0x042C;
  5623. t['afii10047'] = 0x042D;
  5624. t['afii10048'] = 0x042E;
  5625. t['afii10049'] = 0x042F;
  5626. t['afii10050'] = 0x0490;
  5627. t['afii10051'] = 0x0402;
  5628. t['afii10052'] = 0x0403;
  5629. t['afii10053'] = 0x0404;
  5630. t['afii10054'] = 0x0405;
  5631. t['afii10055'] = 0x0406;
  5632. t['afii10056'] = 0x0407;
  5633. t['afii10057'] = 0x0408;
  5634. t['afii10058'] = 0x0409;
  5635. t['afii10059'] = 0x040A;
  5636. t['afii10060'] = 0x040B;
  5637. t['afii10061'] = 0x040C;
  5638. t['afii10062'] = 0x040E;
  5639. t['afii10063'] = 0xF6C4;
  5640. t['afii10064'] = 0xF6C5;
  5641. t['afii10065'] = 0x0430;
  5642. t['afii10066'] = 0x0431;
  5643. t['afii10067'] = 0x0432;
  5644. t['afii10068'] = 0x0433;
  5645. t['afii10069'] = 0x0434;
  5646. t['afii10070'] = 0x0435;
  5647. t['afii10071'] = 0x0451;
  5648. t['afii10072'] = 0x0436;
  5649. t['afii10073'] = 0x0437;
  5650. t['afii10074'] = 0x0438;
  5651. t['afii10075'] = 0x0439;
  5652. t['afii10076'] = 0x043A;
  5653. t['afii10077'] = 0x043B;
  5654. t['afii10078'] = 0x043C;
  5655. t['afii10079'] = 0x043D;
  5656. t['afii10080'] = 0x043E;
  5657. t['afii10081'] = 0x043F;
  5658. t['afii10082'] = 0x0440;
  5659. t['afii10083'] = 0x0441;
  5660. t['afii10084'] = 0x0442;
  5661. t['afii10085'] = 0x0443;
  5662. t['afii10086'] = 0x0444;
  5663. t['afii10087'] = 0x0445;
  5664. t['afii10088'] = 0x0446;
  5665. t['afii10089'] = 0x0447;
  5666. t['afii10090'] = 0x0448;
  5667. t['afii10091'] = 0x0449;
  5668. t['afii10092'] = 0x044A;
  5669. t['afii10093'] = 0x044B;
  5670. t['afii10094'] = 0x044C;
  5671. t['afii10095'] = 0x044D;
  5672. t['afii10096'] = 0x044E;
  5673. t['afii10097'] = 0x044F;
  5674. t['afii10098'] = 0x0491;
  5675. t['afii10099'] = 0x0452;
  5676. t['afii10100'] = 0x0453;
  5677. t['afii10101'] = 0x0454;
  5678. t['afii10102'] = 0x0455;
  5679. t['afii10103'] = 0x0456;
  5680. t['afii10104'] = 0x0457;
  5681. t['afii10105'] = 0x0458;
  5682. t['afii10106'] = 0x0459;
  5683. t['afii10107'] = 0x045A;
  5684. t['afii10108'] = 0x045B;
  5685. t['afii10109'] = 0x045C;
  5686. t['afii10110'] = 0x045E;
  5687. t['afii10145'] = 0x040F;
  5688. t['afii10146'] = 0x0462;
  5689. t['afii10147'] = 0x0472;
  5690. t['afii10148'] = 0x0474;
  5691. t['afii10192'] = 0xF6C6;
  5692. t['afii10193'] = 0x045F;
  5693. t['afii10194'] = 0x0463;
  5694. t['afii10195'] = 0x0473;
  5695. t['afii10196'] = 0x0475;
  5696. t['afii10831'] = 0xF6C7;
  5697. t['afii10832'] = 0xF6C8;
  5698. t['afii10846'] = 0x04D9;
  5699. t['afii299'] = 0x200E;
  5700. t['afii300'] = 0x200F;
  5701. t['afii301'] = 0x200D;
  5702. t['afii57381'] = 0x066A;
  5703. t['afii57388'] = 0x060C;
  5704. t['afii57392'] = 0x0660;
  5705. t['afii57393'] = 0x0661;
  5706. t['afii57394'] = 0x0662;
  5707. t['afii57395'] = 0x0663;
  5708. t['afii57396'] = 0x0664;
  5709. t['afii57397'] = 0x0665;
  5710. t['afii57398'] = 0x0666;
  5711. t['afii57399'] = 0x0667;
  5712. t['afii57400'] = 0x0668;
  5713. t['afii57401'] = 0x0669;
  5714. t['afii57403'] = 0x061B;
  5715. t['afii57407'] = 0x061F;
  5716. t['afii57409'] = 0x0621;
  5717. t['afii57410'] = 0x0622;
  5718. t['afii57411'] = 0x0623;
  5719. t['afii57412'] = 0x0624;
  5720. t['afii57413'] = 0x0625;
  5721. t['afii57414'] = 0x0626;
  5722. t['afii57415'] = 0x0627;
  5723. t['afii57416'] = 0x0628;
  5724. t['afii57417'] = 0x0629;
  5725. t['afii57418'] = 0x062A;
  5726. t['afii57419'] = 0x062B;
  5727. t['afii57420'] = 0x062C;
  5728. t['afii57421'] = 0x062D;
  5729. t['afii57422'] = 0x062E;
  5730. t['afii57423'] = 0x062F;
  5731. t['afii57424'] = 0x0630;
  5732. t['afii57425'] = 0x0631;
  5733. t['afii57426'] = 0x0632;
  5734. t['afii57427'] = 0x0633;
  5735. t['afii57428'] = 0x0634;
  5736. t['afii57429'] = 0x0635;
  5737. t['afii57430'] = 0x0636;
  5738. t['afii57431'] = 0x0637;
  5739. t['afii57432'] = 0x0638;
  5740. t['afii57433'] = 0x0639;
  5741. t['afii57434'] = 0x063A;
  5742. t['afii57440'] = 0x0640;
  5743. t['afii57441'] = 0x0641;
  5744. t['afii57442'] = 0x0642;
  5745. t['afii57443'] = 0x0643;
  5746. t['afii57444'] = 0x0644;
  5747. t['afii57445'] = 0x0645;
  5748. t['afii57446'] = 0x0646;
  5749. t['afii57448'] = 0x0648;
  5750. t['afii57449'] = 0x0649;
  5751. t['afii57450'] = 0x064A;
  5752. t['afii57451'] = 0x064B;
  5753. t['afii57452'] = 0x064C;
  5754. t['afii57453'] = 0x064D;
  5755. t['afii57454'] = 0x064E;
  5756. t['afii57455'] = 0x064F;
  5757. t['afii57456'] = 0x0650;
  5758. t['afii57457'] = 0x0651;
  5759. t['afii57458'] = 0x0652;
  5760. t['afii57470'] = 0x0647;
  5761. t['afii57505'] = 0x06A4;
  5762. t['afii57506'] = 0x067E;
  5763. t['afii57507'] = 0x0686;
  5764. t['afii57508'] = 0x0698;
  5765. t['afii57509'] = 0x06AF;
  5766. t['afii57511'] = 0x0679;
  5767. t['afii57512'] = 0x0688;
  5768. t['afii57513'] = 0x0691;
  5769. t['afii57514'] = 0x06BA;
  5770. t['afii57519'] = 0x06D2;
  5771. t['afii57534'] = 0x06D5;
  5772. t['afii57636'] = 0x20AA;
  5773. t['afii57645'] = 0x05BE;
  5774. t['afii57658'] = 0x05C3;
  5775. t['afii57664'] = 0x05D0;
  5776. t['afii57665'] = 0x05D1;
  5777. t['afii57666'] = 0x05D2;
  5778. t['afii57667'] = 0x05D3;
  5779. t['afii57668'] = 0x05D4;
  5780. t['afii57669'] = 0x05D5;
  5781. t['afii57670'] = 0x05D6;
  5782. t['afii57671'] = 0x05D7;
  5783. t['afii57672'] = 0x05D8;
  5784. t['afii57673'] = 0x05D9;
  5785. t['afii57674'] = 0x05DA;
  5786. t['afii57675'] = 0x05DB;
  5787. t['afii57676'] = 0x05DC;
  5788. t['afii57677'] = 0x05DD;
  5789. t['afii57678'] = 0x05DE;
  5790. t['afii57679'] = 0x05DF;
  5791. t['afii57680'] = 0x05E0;
  5792. t['afii57681'] = 0x05E1;
  5793. t['afii57682'] = 0x05E2;
  5794. t['afii57683'] = 0x05E3;
  5795. t['afii57684'] = 0x05E4;
  5796. t['afii57685'] = 0x05E5;
  5797. t['afii57686'] = 0x05E6;
  5798. t['afii57687'] = 0x05E7;
  5799. t['afii57688'] = 0x05E8;
  5800. t['afii57689'] = 0x05E9;
  5801. t['afii57690'] = 0x05EA;
  5802. t['afii57694'] = 0xFB2A;
  5803. t['afii57695'] = 0xFB2B;
  5804. t['afii57700'] = 0xFB4B;
  5805. t['afii57705'] = 0xFB1F;
  5806. t['afii57716'] = 0x05F0;
  5807. t['afii57717'] = 0x05F1;
  5808. t['afii57718'] = 0x05F2;
  5809. t['afii57723'] = 0xFB35;
  5810. t['afii57793'] = 0x05B4;
  5811. t['afii57794'] = 0x05B5;
  5812. t['afii57795'] = 0x05B6;
  5813. t['afii57796'] = 0x05BB;
  5814. t['afii57797'] = 0x05B8;
  5815. t['afii57798'] = 0x05B7;
  5816. t['afii57799'] = 0x05B0;
  5817. t['afii57800'] = 0x05B2;
  5818. t['afii57801'] = 0x05B1;
  5819. t['afii57802'] = 0x05B3;
  5820. t['afii57803'] = 0x05C2;
  5821. t['afii57804'] = 0x05C1;
  5822. t['afii57806'] = 0x05B9;
  5823. t['afii57807'] = 0x05BC;
  5824. t['afii57839'] = 0x05BD;
  5825. t['afii57841'] = 0x05BF;
  5826. t['afii57842'] = 0x05C0;
  5827. t['afii57929'] = 0x02BC;
  5828. t['afii61248'] = 0x2105;
  5829. t['afii61289'] = 0x2113;
  5830. t['afii61352'] = 0x2116;
  5831. t['afii61573'] = 0x202C;
  5832. t['afii61574'] = 0x202D;
  5833. t['afii61575'] = 0x202E;
  5834. t['afii61664'] = 0x200C;
  5835. t['afii63167'] = 0x066D;
  5836. t['afii64937'] = 0x02BD;
  5837. t['agrave'] = 0x00E0;
  5838. t['agujarati'] = 0x0A85;
  5839. t['agurmukhi'] = 0x0A05;
  5840. t['ahiragana'] = 0x3042;
  5841. t['ahookabove'] = 0x1EA3;
  5842. t['aibengali'] = 0x0990;
  5843. t['aibopomofo'] = 0x311E;
  5844. t['aideva'] = 0x0910;
  5845. t['aiecyrillic'] = 0x04D5;
  5846. t['aigujarati'] = 0x0A90;
  5847. t['aigurmukhi'] = 0x0A10;
  5848. t['aimatragurmukhi'] = 0x0A48;
  5849. t['ainarabic'] = 0x0639;
  5850. t['ainfinalarabic'] = 0xFECA;
  5851. t['aininitialarabic'] = 0xFECB;
  5852. t['ainmedialarabic'] = 0xFECC;
  5853. t['ainvertedbreve'] = 0x0203;
  5854. t['aivowelsignbengali'] = 0x09C8;
  5855. t['aivowelsigndeva'] = 0x0948;
  5856. t['aivowelsigngujarati'] = 0x0AC8;
  5857. t['akatakana'] = 0x30A2;
  5858. t['akatakanahalfwidth'] = 0xFF71;
  5859. t['akorean'] = 0x314F;
  5860. t['alef'] = 0x05D0;
  5861. t['alefarabic'] = 0x0627;
  5862. t['alefdageshhebrew'] = 0xFB30;
  5863. t['aleffinalarabic'] = 0xFE8E;
  5864. t['alefhamzaabovearabic'] = 0x0623;
  5865. t['alefhamzaabovefinalarabic'] = 0xFE84;
  5866. t['alefhamzabelowarabic'] = 0x0625;
  5867. t['alefhamzabelowfinalarabic'] = 0xFE88;
  5868. t['alefhebrew'] = 0x05D0;
  5869. t['aleflamedhebrew'] = 0xFB4F;
  5870. t['alefmaddaabovearabic'] = 0x0622;
  5871. t['alefmaddaabovefinalarabic'] = 0xFE82;
  5872. t['alefmaksuraarabic'] = 0x0649;
  5873. t['alefmaksurafinalarabic'] = 0xFEF0;
  5874. t['alefmaksurainitialarabic'] = 0xFEF3;
  5875. t['alefmaksuramedialarabic'] = 0xFEF4;
  5876. t['alefpatahhebrew'] = 0xFB2E;
  5877. t['alefqamatshebrew'] = 0xFB2F;
  5878. t['aleph'] = 0x2135;
  5879. t['allequal'] = 0x224C;
  5880. t['alpha'] = 0x03B1;
  5881. t['alphatonos'] = 0x03AC;
  5882. t['amacron'] = 0x0101;
  5883. t['amonospace'] = 0xFF41;
  5884. t['ampersand'] = 0x0026;
  5885. t['ampersandmonospace'] = 0xFF06;
  5886. t['ampersandsmall'] = 0xF726;
  5887. t['amsquare'] = 0x33C2;
  5888. t['anbopomofo'] = 0x3122;
  5889. t['angbopomofo'] = 0x3124;
  5890. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  5891. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  5892. t['angkhankhuthai'] = 0x0E5A;
  5893. t['angle'] = 0x2220;
  5894. t['anglebracketleft'] = 0x3008;
  5895. t['anglebracketleftvertical'] = 0xFE3F;
  5896. t['anglebracketright'] = 0x3009;
  5897. t['anglebracketrightvertical'] = 0xFE40;
  5898. t['angleleft'] = 0x2329;
  5899. t['angleright'] = 0x232A;
  5900. t['angstrom'] = 0x212B;
  5901. t['anoteleia'] = 0x0387;
  5902. t['anudattadeva'] = 0x0952;
  5903. t['anusvarabengali'] = 0x0982;
  5904. t['anusvaradeva'] = 0x0902;
  5905. t['anusvaragujarati'] = 0x0A82;
  5906. t['aogonek'] = 0x0105;
  5907. t['apaatosquare'] = 0x3300;
  5908. t['aparen'] = 0x249C;
  5909. t['apostrophearmenian'] = 0x055A;
  5910. t['apostrophemod'] = 0x02BC;
  5911. t['apple'] = 0xF8FF;
  5912. t['approaches'] = 0x2250;
  5913. t['approxequal'] = 0x2248;
  5914. t['approxequalorimage'] = 0x2252;
  5915. t['approximatelyequal'] = 0x2245;
  5916. t['araeaekorean'] = 0x318E;
  5917. t['araeakorean'] = 0x318D;
  5918. t['arc'] = 0x2312;
  5919. t['arighthalfring'] = 0x1E9A;
  5920. t['aring'] = 0x00E5;
  5921. t['aringacute'] = 0x01FB;
  5922. t['aringbelow'] = 0x1E01;
  5923. t['arrowboth'] = 0x2194;
  5924. t['arrowdashdown'] = 0x21E3;
  5925. t['arrowdashleft'] = 0x21E0;
  5926. t['arrowdashright'] = 0x21E2;
  5927. t['arrowdashup'] = 0x21E1;
  5928. t['arrowdblboth'] = 0x21D4;
  5929. t['arrowdbldown'] = 0x21D3;
  5930. t['arrowdblleft'] = 0x21D0;
  5931. t['arrowdblright'] = 0x21D2;
  5932. t['arrowdblup'] = 0x21D1;
  5933. t['arrowdown'] = 0x2193;
  5934. t['arrowdownleft'] = 0x2199;
  5935. t['arrowdownright'] = 0x2198;
  5936. t['arrowdownwhite'] = 0x21E9;
  5937. t['arrowheaddownmod'] = 0x02C5;
  5938. t['arrowheadleftmod'] = 0x02C2;
  5939. t['arrowheadrightmod'] = 0x02C3;
  5940. t['arrowheadupmod'] = 0x02C4;
  5941. t['arrowhorizex'] = 0xF8E7;
  5942. t['arrowleft'] = 0x2190;
  5943. t['arrowleftdbl'] = 0x21D0;
  5944. t['arrowleftdblstroke'] = 0x21CD;
  5945. t['arrowleftoverright'] = 0x21C6;
  5946. t['arrowleftwhite'] = 0x21E6;
  5947. t['arrowright'] = 0x2192;
  5948. t['arrowrightdblstroke'] = 0x21CF;
  5949. t['arrowrightheavy'] = 0x279E;
  5950. t['arrowrightoverleft'] = 0x21C4;
  5951. t['arrowrightwhite'] = 0x21E8;
  5952. t['arrowtableft'] = 0x21E4;
  5953. t['arrowtabright'] = 0x21E5;
  5954. t['arrowup'] = 0x2191;
  5955. t['arrowupdn'] = 0x2195;
  5956. t['arrowupdnbse'] = 0x21A8;
  5957. t['arrowupdownbase'] = 0x21A8;
  5958. t['arrowupleft'] = 0x2196;
  5959. t['arrowupleftofdown'] = 0x21C5;
  5960. t['arrowupright'] = 0x2197;
  5961. t['arrowupwhite'] = 0x21E7;
  5962. t['arrowvertex'] = 0xF8E6;
  5963. t['asciicircum'] = 0x005E;
  5964. t['asciicircummonospace'] = 0xFF3E;
  5965. t['asciitilde'] = 0x007E;
  5966. t['asciitildemonospace'] = 0xFF5E;
  5967. t['ascript'] = 0x0251;
  5968. t['ascriptturned'] = 0x0252;
  5969. t['asmallhiragana'] = 0x3041;
  5970. t['asmallkatakana'] = 0x30A1;
  5971. t['asmallkatakanahalfwidth'] = 0xFF67;
  5972. t['asterisk'] = 0x002A;
  5973. t['asteriskaltonearabic'] = 0x066D;
  5974. t['asteriskarabic'] = 0x066D;
  5975. t['asteriskmath'] = 0x2217;
  5976. t['asteriskmonospace'] = 0xFF0A;
  5977. t['asterisksmall'] = 0xFE61;
  5978. t['asterism'] = 0x2042;
  5979. t['asuperior'] = 0xF6E9;
  5980. t['asymptoticallyequal'] = 0x2243;
  5981. t['at'] = 0x0040;
  5982. t['atilde'] = 0x00E3;
  5983. t['atmonospace'] = 0xFF20;
  5984. t['atsmall'] = 0xFE6B;
  5985. t['aturned'] = 0x0250;
  5986. t['aubengali'] = 0x0994;
  5987. t['aubopomofo'] = 0x3120;
  5988. t['audeva'] = 0x0914;
  5989. t['augujarati'] = 0x0A94;
  5990. t['augurmukhi'] = 0x0A14;
  5991. t['aulengthmarkbengali'] = 0x09D7;
  5992. t['aumatragurmukhi'] = 0x0A4C;
  5993. t['auvowelsignbengali'] = 0x09CC;
  5994. t['auvowelsigndeva'] = 0x094C;
  5995. t['auvowelsigngujarati'] = 0x0ACC;
  5996. t['avagrahadeva'] = 0x093D;
  5997. t['aybarmenian'] = 0x0561;
  5998. t['ayin'] = 0x05E2;
  5999. t['ayinaltonehebrew'] = 0xFB20;
  6000. t['ayinhebrew'] = 0x05E2;
  6001. t['b'] = 0x0062;
  6002. t['babengali'] = 0x09AC;
  6003. t['backslash'] = 0x005C;
  6004. t['backslashmonospace'] = 0xFF3C;
  6005. t['badeva'] = 0x092C;
  6006. t['bagujarati'] = 0x0AAC;
  6007. t['bagurmukhi'] = 0x0A2C;
  6008. t['bahiragana'] = 0x3070;
  6009. t['bahtthai'] = 0x0E3F;
  6010. t['bakatakana'] = 0x30D0;
  6011. t['bar'] = 0x007C;
  6012. t['barmonospace'] = 0xFF5C;
  6013. t['bbopomofo'] = 0x3105;
  6014. t['bcircle'] = 0x24D1;
  6015. t['bdotaccent'] = 0x1E03;
  6016. t['bdotbelow'] = 0x1E05;
  6017. t['beamedsixteenthnotes'] = 0x266C;
  6018. t['because'] = 0x2235;
  6019. t['becyrillic'] = 0x0431;
  6020. t['beharabic'] = 0x0628;
  6021. t['behfinalarabic'] = 0xFE90;
  6022. t['behinitialarabic'] = 0xFE91;
  6023. t['behiragana'] = 0x3079;
  6024. t['behmedialarabic'] = 0xFE92;
  6025. t['behmeeminitialarabic'] = 0xFC9F;
  6026. t['behmeemisolatedarabic'] = 0xFC08;
  6027. t['behnoonfinalarabic'] = 0xFC6D;
  6028. t['bekatakana'] = 0x30D9;
  6029. t['benarmenian'] = 0x0562;
  6030. t['bet'] = 0x05D1;
  6031. t['beta'] = 0x03B2;
  6032. t['betasymbolgreek'] = 0x03D0;
  6033. t['betdagesh'] = 0xFB31;
  6034. t['betdageshhebrew'] = 0xFB31;
  6035. t['bethebrew'] = 0x05D1;
  6036. t['betrafehebrew'] = 0xFB4C;
  6037. t['bhabengali'] = 0x09AD;
  6038. t['bhadeva'] = 0x092D;
  6039. t['bhagujarati'] = 0x0AAD;
  6040. t['bhagurmukhi'] = 0x0A2D;
  6041. t['bhook'] = 0x0253;
  6042. t['bihiragana'] = 0x3073;
  6043. t['bikatakana'] = 0x30D3;
  6044. t['bilabialclick'] = 0x0298;
  6045. t['bindigurmukhi'] = 0x0A02;
  6046. t['birusquare'] = 0x3331;
  6047. t['blackcircle'] = 0x25CF;
  6048. t['blackdiamond'] = 0x25C6;
  6049. t['blackdownpointingtriangle'] = 0x25BC;
  6050. t['blackleftpointingpointer'] = 0x25C4;
  6051. t['blackleftpointingtriangle'] = 0x25C0;
  6052. t['blacklenticularbracketleft'] = 0x3010;
  6053. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  6054. t['blacklenticularbracketright'] = 0x3011;
  6055. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  6056. t['blacklowerlefttriangle'] = 0x25E3;
  6057. t['blacklowerrighttriangle'] = 0x25E2;
  6058. t['blackrectangle'] = 0x25AC;
  6059. t['blackrightpointingpointer'] = 0x25BA;
  6060. t['blackrightpointingtriangle'] = 0x25B6;
  6061. t['blacksmallsquare'] = 0x25AA;
  6062. t['blacksmilingface'] = 0x263B;
  6063. t['blacksquare'] = 0x25A0;
  6064. t['blackstar'] = 0x2605;
  6065. t['blackupperlefttriangle'] = 0x25E4;
  6066. t['blackupperrighttriangle'] = 0x25E5;
  6067. t['blackuppointingsmalltriangle'] = 0x25B4;
  6068. t['blackuppointingtriangle'] = 0x25B2;
  6069. t['blank'] = 0x2423;
  6070. t['blinebelow'] = 0x1E07;
  6071. t['block'] = 0x2588;
  6072. t['bmonospace'] = 0xFF42;
  6073. t['bobaimaithai'] = 0x0E1A;
  6074. t['bohiragana'] = 0x307C;
  6075. t['bokatakana'] = 0x30DC;
  6076. t['bparen'] = 0x249D;
  6077. t['bqsquare'] = 0x33C3;
  6078. t['braceex'] = 0xF8F4;
  6079. t['braceleft'] = 0x007B;
  6080. t['braceleftbt'] = 0xF8F3;
  6081. t['braceleftmid'] = 0xF8F2;
  6082. t['braceleftmonospace'] = 0xFF5B;
  6083. t['braceleftsmall'] = 0xFE5B;
  6084. t['bracelefttp'] = 0xF8F1;
  6085. t['braceleftvertical'] = 0xFE37;
  6086. t['braceright'] = 0x007D;
  6087. t['bracerightbt'] = 0xF8FE;
  6088. t['bracerightmid'] = 0xF8FD;
  6089. t['bracerightmonospace'] = 0xFF5D;
  6090. t['bracerightsmall'] = 0xFE5C;
  6091. t['bracerighttp'] = 0xF8FC;
  6092. t['bracerightvertical'] = 0xFE38;
  6093. t['bracketleft'] = 0x005B;
  6094. t['bracketleftbt'] = 0xF8F0;
  6095. t['bracketleftex'] = 0xF8EF;
  6096. t['bracketleftmonospace'] = 0xFF3B;
  6097. t['bracketlefttp'] = 0xF8EE;
  6098. t['bracketright'] = 0x005D;
  6099. t['bracketrightbt'] = 0xF8FB;
  6100. t['bracketrightex'] = 0xF8FA;
  6101. t['bracketrightmonospace'] = 0xFF3D;
  6102. t['bracketrighttp'] = 0xF8F9;
  6103. t['breve'] = 0x02D8;
  6104. t['brevebelowcmb'] = 0x032E;
  6105. t['brevecmb'] = 0x0306;
  6106. t['breveinvertedbelowcmb'] = 0x032F;
  6107. t['breveinvertedcmb'] = 0x0311;
  6108. t['breveinverteddoublecmb'] = 0x0361;
  6109. t['bridgebelowcmb'] = 0x032A;
  6110. t['bridgeinvertedbelowcmb'] = 0x033A;
  6111. t['brokenbar'] = 0x00A6;
  6112. t['bstroke'] = 0x0180;
  6113. t['bsuperior'] = 0xF6EA;
  6114. t['btopbar'] = 0x0183;
  6115. t['buhiragana'] = 0x3076;
  6116. t['bukatakana'] = 0x30D6;
  6117. t['bullet'] = 0x2022;
  6118. t['bulletinverse'] = 0x25D8;
  6119. t['bulletoperator'] = 0x2219;
  6120. t['bullseye'] = 0x25CE;
  6121. t['c'] = 0x0063;
  6122. t['caarmenian'] = 0x056E;
  6123. t['cabengali'] = 0x099A;
  6124. t['cacute'] = 0x0107;
  6125. t['cadeva'] = 0x091A;
  6126. t['cagujarati'] = 0x0A9A;
  6127. t['cagurmukhi'] = 0x0A1A;
  6128. t['calsquare'] = 0x3388;
  6129. t['candrabindubengali'] = 0x0981;
  6130. t['candrabinducmb'] = 0x0310;
  6131. t['candrabindudeva'] = 0x0901;
  6132. t['candrabindugujarati'] = 0x0A81;
  6133. t['capslock'] = 0x21EA;
  6134. t['careof'] = 0x2105;
  6135. t['caron'] = 0x02C7;
  6136. t['caronbelowcmb'] = 0x032C;
  6137. t['caroncmb'] = 0x030C;
  6138. t['carriagereturn'] = 0x21B5;
  6139. t['cbopomofo'] = 0x3118;
  6140. t['ccaron'] = 0x010D;
  6141. t['ccedilla'] = 0x00E7;
  6142. t['ccedillaacute'] = 0x1E09;
  6143. t['ccircle'] = 0x24D2;
  6144. t['ccircumflex'] = 0x0109;
  6145. t['ccurl'] = 0x0255;
  6146. t['cdot'] = 0x010B;
  6147. t['cdotaccent'] = 0x010B;
  6148. t['cdsquare'] = 0x33C5;
  6149. t['cedilla'] = 0x00B8;
  6150. t['cedillacmb'] = 0x0327;
  6151. t['cent'] = 0x00A2;
  6152. t['centigrade'] = 0x2103;
  6153. t['centinferior'] = 0xF6DF;
  6154. t['centmonospace'] = 0xFFE0;
  6155. t['centoldstyle'] = 0xF7A2;
  6156. t['centsuperior'] = 0xF6E0;
  6157. t['chaarmenian'] = 0x0579;
  6158. t['chabengali'] = 0x099B;
  6159. t['chadeva'] = 0x091B;
  6160. t['chagujarati'] = 0x0A9B;
  6161. t['chagurmukhi'] = 0x0A1B;
  6162. t['chbopomofo'] = 0x3114;
  6163. t['cheabkhasiancyrillic'] = 0x04BD;
  6164. t['checkmark'] = 0x2713;
  6165. t['checyrillic'] = 0x0447;
  6166. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6167. t['chedescendercyrillic'] = 0x04B7;
  6168. t['chedieresiscyrillic'] = 0x04F5;
  6169. t['cheharmenian'] = 0x0573;
  6170. t['chekhakassiancyrillic'] = 0x04CC;
  6171. t['cheverticalstrokecyrillic'] = 0x04B9;
  6172. t['chi'] = 0x03C7;
  6173. t['chieuchacirclekorean'] = 0x3277;
  6174. t['chieuchaparenkorean'] = 0x3217;
  6175. t['chieuchcirclekorean'] = 0x3269;
  6176. t['chieuchkorean'] = 0x314A;
  6177. t['chieuchparenkorean'] = 0x3209;
  6178. t['chochangthai'] = 0x0E0A;
  6179. t['chochanthai'] = 0x0E08;
  6180. t['chochingthai'] = 0x0E09;
  6181. t['chochoethai'] = 0x0E0C;
  6182. t['chook'] = 0x0188;
  6183. t['cieucacirclekorean'] = 0x3276;
  6184. t['cieucaparenkorean'] = 0x3216;
  6185. t['cieuccirclekorean'] = 0x3268;
  6186. t['cieuckorean'] = 0x3148;
  6187. t['cieucparenkorean'] = 0x3208;
  6188. t['cieucuparenkorean'] = 0x321C;
  6189. t['circle'] = 0x25CB;
  6190. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6191. t['circlemultiply'] = 0x2297;
  6192. t['circleot'] = 0x2299;
  6193. t['circleplus'] = 0x2295;
  6194. t['circlepostalmark'] = 0x3036;
  6195. t['circlewithlefthalfblack'] = 0x25D0;
  6196. t['circlewithrighthalfblack'] = 0x25D1;
  6197. t['circumflex'] = 0x02C6;
  6198. t['circumflexbelowcmb'] = 0x032D;
  6199. t['circumflexcmb'] = 0x0302;
  6200. t['clear'] = 0x2327;
  6201. t['clickalveolar'] = 0x01C2;
  6202. t['clickdental'] = 0x01C0;
  6203. t['clicklateral'] = 0x01C1;
  6204. t['clickretroflex'] = 0x01C3;
  6205. t['club'] = 0x2663;
  6206. t['clubsuitblack'] = 0x2663;
  6207. t['clubsuitwhite'] = 0x2667;
  6208. t['cmcubedsquare'] = 0x33A4;
  6209. t['cmonospace'] = 0xFF43;
  6210. t['cmsquaredsquare'] = 0x33A0;
  6211. t['coarmenian'] = 0x0581;
  6212. t['colon'] = 0x003A;
  6213. t['colonmonetary'] = 0x20A1;
  6214. t['colonmonospace'] = 0xFF1A;
  6215. t['colonsign'] = 0x20A1;
  6216. t['colonsmall'] = 0xFE55;
  6217. t['colontriangularhalfmod'] = 0x02D1;
  6218. t['colontriangularmod'] = 0x02D0;
  6219. t['comma'] = 0x002C;
  6220. t['commaabovecmb'] = 0x0313;
  6221. t['commaaboverightcmb'] = 0x0315;
  6222. t['commaaccent'] = 0xF6C3;
  6223. t['commaarabic'] = 0x060C;
  6224. t['commaarmenian'] = 0x055D;
  6225. t['commainferior'] = 0xF6E1;
  6226. t['commamonospace'] = 0xFF0C;
  6227. t['commareversedabovecmb'] = 0x0314;
  6228. t['commareversedmod'] = 0x02BD;
  6229. t['commasmall'] = 0xFE50;
  6230. t['commasuperior'] = 0xF6E2;
  6231. t['commaturnedabovecmb'] = 0x0312;
  6232. t['commaturnedmod'] = 0x02BB;
  6233. t['compass'] = 0x263C;
  6234. t['congruent'] = 0x2245;
  6235. t['contourintegral'] = 0x222E;
  6236. t['control'] = 0x2303;
  6237. t['controlACK'] = 0x0006;
  6238. t['controlBEL'] = 0x0007;
  6239. t['controlBS'] = 0x0008;
  6240. t['controlCAN'] = 0x0018;
  6241. t['controlCR'] = 0x000D;
  6242. t['controlDC1'] = 0x0011;
  6243. t['controlDC2'] = 0x0012;
  6244. t['controlDC3'] = 0x0013;
  6245. t['controlDC4'] = 0x0014;
  6246. t['controlDEL'] = 0x007F;
  6247. t['controlDLE'] = 0x0010;
  6248. t['controlEM'] = 0x0019;
  6249. t['controlENQ'] = 0x0005;
  6250. t['controlEOT'] = 0x0004;
  6251. t['controlESC'] = 0x001B;
  6252. t['controlETB'] = 0x0017;
  6253. t['controlETX'] = 0x0003;
  6254. t['controlFF'] = 0x000C;
  6255. t['controlFS'] = 0x001C;
  6256. t['controlGS'] = 0x001D;
  6257. t['controlHT'] = 0x0009;
  6258. t['controlLF'] = 0x000A;
  6259. t['controlNAK'] = 0x0015;
  6260. t['controlRS'] = 0x001E;
  6261. t['controlSI'] = 0x000F;
  6262. t['controlSO'] = 0x000E;
  6263. t['controlSOT'] = 0x0002;
  6264. t['controlSTX'] = 0x0001;
  6265. t['controlSUB'] = 0x001A;
  6266. t['controlSYN'] = 0x0016;
  6267. t['controlUS'] = 0x001F;
  6268. t['controlVT'] = 0x000B;
  6269. t['copyright'] = 0x00A9;
  6270. t['copyrightsans'] = 0xF8E9;
  6271. t['copyrightserif'] = 0xF6D9;
  6272. t['cornerbracketleft'] = 0x300C;
  6273. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6274. t['cornerbracketleftvertical'] = 0xFE41;
  6275. t['cornerbracketright'] = 0x300D;
  6276. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6277. t['cornerbracketrightvertical'] = 0xFE42;
  6278. t['corporationsquare'] = 0x337F;
  6279. t['cosquare'] = 0x33C7;
  6280. t['coverkgsquare'] = 0x33C6;
  6281. t['cparen'] = 0x249E;
  6282. t['cruzeiro'] = 0x20A2;
  6283. t['cstretched'] = 0x0297;
  6284. t['curlyand'] = 0x22CF;
  6285. t['curlyor'] = 0x22CE;
  6286. t['currency'] = 0x00A4;
  6287. t['cyrBreve'] = 0xF6D1;
  6288. t['cyrFlex'] = 0xF6D2;
  6289. t['cyrbreve'] = 0xF6D4;
  6290. t['cyrflex'] = 0xF6D5;
  6291. t['d'] = 0x0064;
  6292. t['daarmenian'] = 0x0564;
  6293. t['dabengali'] = 0x09A6;
  6294. t['dadarabic'] = 0x0636;
  6295. t['dadeva'] = 0x0926;
  6296. t['dadfinalarabic'] = 0xFEBE;
  6297. t['dadinitialarabic'] = 0xFEBF;
  6298. t['dadmedialarabic'] = 0xFEC0;
  6299. t['dagesh'] = 0x05BC;
  6300. t['dageshhebrew'] = 0x05BC;
  6301. t['dagger'] = 0x2020;
  6302. t['daggerdbl'] = 0x2021;
  6303. t['dagujarati'] = 0x0AA6;
  6304. t['dagurmukhi'] = 0x0A26;
  6305. t['dahiragana'] = 0x3060;
  6306. t['dakatakana'] = 0x30C0;
  6307. t['dalarabic'] = 0x062F;
  6308. t['dalet'] = 0x05D3;
  6309. t['daletdagesh'] = 0xFB33;
  6310. t['daletdageshhebrew'] = 0xFB33;
  6311. t['dalethebrew'] = 0x05D3;
  6312. t['dalfinalarabic'] = 0xFEAA;
  6313. t['dammaarabic'] = 0x064F;
  6314. t['dammalowarabic'] = 0x064F;
  6315. t['dammatanaltonearabic'] = 0x064C;
  6316. t['dammatanarabic'] = 0x064C;
  6317. t['danda'] = 0x0964;
  6318. t['dargahebrew'] = 0x05A7;
  6319. t['dargalefthebrew'] = 0x05A7;
  6320. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6321. t['dblGrave'] = 0xF6D3;
  6322. t['dblanglebracketleft'] = 0x300A;
  6323. t['dblanglebracketleftvertical'] = 0xFE3D;
  6324. t['dblanglebracketright'] = 0x300B;
  6325. t['dblanglebracketrightvertical'] = 0xFE3E;
  6326. t['dblarchinvertedbelowcmb'] = 0x032B;
  6327. t['dblarrowleft'] = 0x21D4;
  6328. t['dblarrowright'] = 0x21D2;
  6329. t['dbldanda'] = 0x0965;
  6330. t['dblgrave'] = 0xF6D6;
  6331. t['dblgravecmb'] = 0x030F;
  6332. t['dblintegral'] = 0x222C;
  6333. t['dbllowline'] = 0x2017;
  6334. t['dbllowlinecmb'] = 0x0333;
  6335. t['dbloverlinecmb'] = 0x033F;
  6336. t['dblprimemod'] = 0x02BA;
  6337. t['dblverticalbar'] = 0x2016;
  6338. t['dblverticallineabovecmb'] = 0x030E;
  6339. t['dbopomofo'] = 0x3109;
  6340. t['dbsquare'] = 0x33C8;
  6341. t['dcaron'] = 0x010F;
  6342. t['dcedilla'] = 0x1E11;
  6343. t['dcircle'] = 0x24D3;
  6344. t['dcircumflexbelow'] = 0x1E13;
  6345. t['dcroat'] = 0x0111;
  6346. t['ddabengali'] = 0x09A1;
  6347. t['ddadeva'] = 0x0921;
  6348. t['ddagujarati'] = 0x0AA1;
  6349. t['ddagurmukhi'] = 0x0A21;
  6350. t['ddalarabic'] = 0x0688;
  6351. t['ddalfinalarabic'] = 0xFB89;
  6352. t['dddhadeva'] = 0x095C;
  6353. t['ddhabengali'] = 0x09A2;
  6354. t['ddhadeva'] = 0x0922;
  6355. t['ddhagujarati'] = 0x0AA2;
  6356. t['ddhagurmukhi'] = 0x0A22;
  6357. t['ddotaccent'] = 0x1E0B;
  6358. t['ddotbelow'] = 0x1E0D;
  6359. t['decimalseparatorarabic'] = 0x066B;
  6360. t['decimalseparatorpersian'] = 0x066B;
  6361. t['decyrillic'] = 0x0434;
  6362. t['degree'] = 0x00B0;
  6363. t['dehihebrew'] = 0x05AD;
  6364. t['dehiragana'] = 0x3067;
  6365. t['deicoptic'] = 0x03EF;
  6366. t['dekatakana'] = 0x30C7;
  6367. t['deleteleft'] = 0x232B;
  6368. t['deleteright'] = 0x2326;
  6369. t['delta'] = 0x03B4;
  6370. t['deltaturned'] = 0x018D;
  6371. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6372. t['dezh'] = 0x02A4;
  6373. t['dhabengali'] = 0x09A7;
  6374. t['dhadeva'] = 0x0927;
  6375. t['dhagujarati'] = 0x0AA7;
  6376. t['dhagurmukhi'] = 0x0A27;
  6377. t['dhook'] = 0x0257;
  6378. t['dialytikatonos'] = 0x0385;
  6379. t['dialytikatonoscmb'] = 0x0344;
  6380. t['diamond'] = 0x2666;
  6381. t['diamondsuitwhite'] = 0x2662;
  6382. t['dieresis'] = 0x00A8;
  6383. t['dieresisacute'] = 0xF6D7;
  6384. t['dieresisbelowcmb'] = 0x0324;
  6385. t['dieresiscmb'] = 0x0308;
  6386. t['dieresisgrave'] = 0xF6D8;
  6387. t['dieresistonos'] = 0x0385;
  6388. t['dihiragana'] = 0x3062;
  6389. t['dikatakana'] = 0x30C2;
  6390. t['dittomark'] = 0x3003;
  6391. t['divide'] = 0x00F7;
  6392. t['divides'] = 0x2223;
  6393. t['divisionslash'] = 0x2215;
  6394. t['djecyrillic'] = 0x0452;
  6395. t['dkshade'] = 0x2593;
  6396. t['dlinebelow'] = 0x1E0F;
  6397. t['dlsquare'] = 0x3397;
  6398. t['dmacron'] = 0x0111;
  6399. t['dmonospace'] = 0xFF44;
  6400. t['dnblock'] = 0x2584;
  6401. t['dochadathai'] = 0x0E0E;
  6402. t['dodekthai'] = 0x0E14;
  6403. t['dohiragana'] = 0x3069;
  6404. t['dokatakana'] = 0x30C9;
  6405. t['dollar'] = 0x0024;
  6406. t['dollarinferior'] = 0xF6E3;
  6407. t['dollarmonospace'] = 0xFF04;
  6408. t['dollaroldstyle'] = 0xF724;
  6409. t['dollarsmall'] = 0xFE69;
  6410. t['dollarsuperior'] = 0xF6E4;
  6411. t['dong'] = 0x20AB;
  6412. t['dorusquare'] = 0x3326;
  6413. t['dotaccent'] = 0x02D9;
  6414. t['dotaccentcmb'] = 0x0307;
  6415. t['dotbelowcmb'] = 0x0323;
  6416. t['dotbelowcomb'] = 0x0323;
  6417. t['dotkatakana'] = 0x30FB;
  6418. t['dotlessi'] = 0x0131;
  6419. t['dotlessj'] = 0xF6BE;
  6420. t['dotlessjstrokehook'] = 0x0284;
  6421. t['dotmath'] = 0x22C5;
  6422. t['dottedcircle'] = 0x25CC;
  6423. t['doubleyodpatah'] = 0xFB1F;
  6424. t['doubleyodpatahhebrew'] = 0xFB1F;
  6425. t['downtackbelowcmb'] = 0x031E;
  6426. t['downtackmod'] = 0x02D5;
  6427. t['dparen'] = 0x249F;
  6428. t['dsuperior'] = 0xF6EB;
  6429. t['dtail'] = 0x0256;
  6430. t['dtopbar'] = 0x018C;
  6431. t['duhiragana'] = 0x3065;
  6432. t['dukatakana'] = 0x30C5;
  6433. t['dz'] = 0x01F3;
  6434. t['dzaltone'] = 0x02A3;
  6435. t['dzcaron'] = 0x01C6;
  6436. t['dzcurl'] = 0x02A5;
  6437. t['dzeabkhasiancyrillic'] = 0x04E1;
  6438. t['dzecyrillic'] = 0x0455;
  6439. t['dzhecyrillic'] = 0x045F;
  6440. t['e'] = 0x0065;
  6441. t['eacute'] = 0x00E9;
  6442. t['earth'] = 0x2641;
  6443. t['ebengali'] = 0x098F;
  6444. t['ebopomofo'] = 0x311C;
  6445. t['ebreve'] = 0x0115;
  6446. t['ecandradeva'] = 0x090D;
  6447. t['ecandragujarati'] = 0x0A8D;
  6448. t['ecandravowelsigndeva'] = 0x0945;
  6449. t['ecandravowelsigngujarati'] = 0x0AC5;
  6450. t['ecaron'] = 0x011B;
  6451. t['ecedillabreve'] = 0x1E1D;
  6452. t['echarmenian'] = 0x0565;
  6453. t['echyiwnarmenian'] = 0x0587;
  6454. t['ecircle'] = 0x24D4;
  6455. t['ecircumflex'] = 0x00EA;
  6456. t['ecircumflexacute'] = 0x1EBF;
  6457. t['ecircumflexbelow'] = 0x1E19;
  6458. t['ecircumflexdotbelow'] = 0x1EC7;
  6459. t['ecircumflexgrave'] = 0x1EC1;
  6460. t['ecircumflexhookabove'] = 0x1EC3;
  6461. t['ecircumflextilde'] = 0x1EC5;
  6462. t['ecyrillic'] = 0x0454;
  6463. t['edblgrave'] = 0x0205;
  6464. t['edeva'] = 0x090F;
  6465. t['edieresis'] = 0x00EB;
  6466. t['edot'] = 0x0117;
  6467. t['edotaccent'] = 0x0117;
  6468. t['edotbelow'] = 0x1EB9;
  6469. t['eegurmukhi'] = 0x0A0F;
  6470. t['eematragurmukhi'] = 0x0A47;
  6471. t['efcyrillic'] = 0x0444;
  6472. t['egrave'] = 0x00E8;
  6473. t['egujarati'] = 0x0A8F;
  6474. t['eharmenian'] = 0x0567;
  6475. t['ehbopomofo'] = 0x311D;
  6476. t['ehiragana'] = 0x3048;
  6477. t['ehookabove'] = 0x1EBB;
  6478. t['eibopomofo'] = 0x311F;
  6479. t['eight'] = 0x0038;
  6480. t['eightarabic'] = 0x0668;
  6481. t['eightbengali'] = 0x09EE;
  6482. t['eightcircle'] = 0x2467;
  6483. t['eightcircleinversesansserif'] = 0x2791;
  6484. t['eightdeva'] = 0x096E;
  6485. t['eighteencircle'] = 0x2471;
  6486. t['eighteenparen'] = 0x2485;
  6487. t['eighteenperiod'] = 0x2499;
  6488. t['eightgujarati'] = 0x0AEE;
  6489. t['eightgurmukhi'] = 0x0A6E;
  6490. t['eighthackarabic'] = 0x0668;
  6491. t['eighthangzhou'] = 0x3028;
  6492. t['eighthnotebeamed'] = 0x266B;
  6493. t['eightideographicparen'] = 0x3227;
  6494. t['eightinferior'] = 0x2088;
  6495. t['eightmonospace'] = 0xFF18;
  6496. t['eightoldstyle'] = 0xF738;
  6497. t['eightparen'] = 0x247B;
  6498. t['eightperiod'] = 0x248F;
  6499. t['eightpersian'] = 0x06F8;
  6500. t['eightroman'] = 0x2177;
  6501. t['eightsuperior'] = 0x2078;
  6502. t['eightthai'] = 0x0E58;
  6503. t['einvertedbreve'] = 0x0207;
  6504. t['eiotifiedcyrillic'] = 0x0465;
  6505. t['ekatakana'] = 0x30A8;
  6506. t['ekatakanahalfwidth'] = 0xFF74;
  6507. t['ekonkargurmukhi'] = 0x0A74;
  6508. t['ekorean'] = 0x3154;
  6509. t['elcyrillic'] = 0x043B;
  6510. t['element'] = 0x2208;
  6511. t['elevencircle'] = 0x246A;
  6512. t['elevenparen'] = 0x247E;
  6513. t['elevenperiod'] = 0x2492;
  6514. t['elevenroman'] = 0x217A;
  6515. t['ellipsis'] = 0x2026;
  6516. t['ellipsisvertical'] = 0x22EE;
  6517. t['emacron'] = 0x0113;
  6518. t['emacronacute'] = 0x1E17;
  6519. t['emacrongrave'] = 0x1E15;
  6520. t['emcyrillic'] = 0x043C;
  6521. t['emdash'] = 0x2014;
  6522. t['emdashvertical'] = 0xFE31;
  6523. t['emonospace'] = 0xFF45;
  6524. t['emphasismarkarmenian'] = 0x055B;
  6525. t['emptyset'] = 0x2205;
  6526. t['enbopomofo'] = 0x3123;
  6527. t['encyrillic'] = 0x043D;
  6528. t['endash'] = 0x2013;
  6529. t['endashvertical'] = 0xFE32;
  6530. t['endescendercyrillic'] = 0x04A3;
  6531. t['eng'] = 0x014B;
  6532. t['engbopomofo'] = 0x3125;
  6533. t['enghecyrillic'] = 0x04A5;
  6534. t['enhookcyrillic'] = 0x04C8;
  6535. t['enspace'] = 0x2002;
  6536. t['eogonek'] = 0x0119;
  6537. t['eokorean'] = 0x3153;
  6538. t['eopen'] = 0x025B;
  6539. t['eopenclosed'] = 0x029A;
  6540. t['eopenreversed'] = 0x025C;
  6541. t['eopenreversedclosed'] = 0x025E;
  6542. t['eopenreversedhook'] = 0x025D;
  6543. t['eparen'] = 0x24A0;
  6544. t['epsilon'] = 0x03B5;
  6545. t['epsilontonos'] = 0x03AD;
  6546. t['equal'] = 0x003D;
  6547. t['equalmonospace'] = 0xFF1D;
  6548. t['equalsmall'] = 0xFE66;
  6549. t['equalsuperior'] = 0x207C;
  6550. t['equivalence'] = 0x2261;
  6551. t['erbopomofo'] = 0x3126;
  6552. t['ercyrillic'] = 0x0440;
  6553. t['ereversed'] = 0x0258;
  6554. t['ereversedcyrillic'] = 0x044D;
  6555. t['escyrillic'] = 0x0441;
  6556. t['esdescendercyrillic'] = 0x04AB;
  6557. t['esh'] = 0x0283;
  6558. t['eshcurl'] = 0x0286;
  6559. t['eshortdeva'] = 0x090E;
  6560. t['eshortvowelsigndeva'] = 0x0946;
  6561. t['eshreversedloop'] = 0x01AA;
  6562. t['eshsquatreversed'] = 0x0285;
  6563. t['esmallhiragana'] = 0x3047;
  6564. t['esmallkatakana'] = 0x30A7;
  6565. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6566. t['estimated'] = 0x212E;
  6567. t['esuperior'] = 0xF6EC;
  6568. t['eta'] = 0x03B7;
  6569. t['etarmenian'] = 0x0568;
  6570. t['etatonos'] = 0x03AE;
  6571. t['eth'] = 0x00F0;
  6572. t['etilde'] = 0x1EBD;
  6573. t['etildebelow'] = 0x1E1B;
  6574. t['etnahtafoukhhebrew'] = 0x0591;
  6575. t['etnahtafoukhlefthebrew'] = 0x0591;
  6576. t['etnahtahebrew'] = 0x0591;
  6577. t['etnahtalefthebrew'] = 0x0591;
  6578. t['eturned'] = 0x01DD;
  6579. t['eukorean'] = 0x3161;
  6580. t['euro'] = 0x20AC;
  6581. t['evowelsignbengali'] = 0x09C7;
  6582. t['evowelsigndeva'] = 0x0947;
  6583. t['evowelsigngujarati'] = 0x0AC7;
  6584. t['exclam'] = 0x0021;
  6585. t['exclamarmenian'] = 0x055C;
  6586. t['exclamdbl'] = 0x203C;
  6587. t['exclamdown'] = 0x00A1;
  6588. t['exclamdownsmall'] = 0xF7A1;
  6589. t['exclammonospace'] = 0xFF01;
  6590. t['exclamsmall'] = 0xF721;
  6591. t['existential'] = 0x2203;
  6592. t['ezh'] = 0x0292;
  6593. t['ezhcaron'] = 0x01EF;
  6594. t['ezhcurl'] = 0x0293;
  6595. t['ezhreversed'] = 0x01B9;
  6596. t['ezhtail'] = 0x01BA;
  6597. t['f'] = 0x0066;
  6598. t['fadeva'] = 0x095E;
  6599. t['fagurmukhi'] = 0x0A5E;
  6600. t['fahrenheit'] = 0x2109;
  6601. t['fathaarabic'] = 0x064E;
  6602. t['fathalowarabic'] = 0x064E;
  6603. t['fathatanarabic'] = 0x064B;
  6604. t['fbopomofo'] = 0x3108;
  6605. t['fcircle'] = 0x24D5;
  6606. t['fdotaccent'] = 0x1E1F;
  6607. t['feharabic'] = 0x0641;
  6608. t['feharmenian'] = 0x0586;
  6609. t['fehfinalarabic'] = 0xFED2;
  6610. t['fehinitialarabic'] = 0xFED3;
  6611. t['fehmedialarabic'] = 0xFED4;
  6612. t['feicoptic'] = 0x03E5;
  6613. t['female'] = 0x2640;
  6614. t['ff'] = 0xFB00;
  6615. t['ffi'] = 0xFB03;
  6616. t['ffl'] = 0xFB04;
  6617. t['fi'] = 0xFB01;
  6618. t['fifteencircle'] = 0x246E;
  6619. t['fifteenparen'] = 0x2482;
  6620. t['fifteenperiod'] = 0x2496;
  6621. t['figuredash'] = 0x2012;
  6622. t['filledbox'] = 0x25A0;
  6623. t['filledrect'] = 0x25AC;
  6624. t['finalkaf'] = 0x05DA;
  6625. t['finalkafdagesh'] = 0xFB3A;
  6626. t['finalkafdageshhebrew'] = 0xFB3A;
  6627. t['finalkafhebrew'] = 0x05DA;
  6628. t['finalmem'] = 0x05DD;
  6629. t['finalmemhebrew'] = 0x05DD;
  6630. t['finalnun'] = 0x05DF;
  6631. t['finalnunhebrew'] = 0x05DF;
  6632. t['finalpe'] = 0x05E3;
  6633. t['finalpehebrew'] = 0x05E3;
  6634. t['finaltsadi'] = 0x05E5;
  6635. t['finaltsadihebrew'] = 0x05E5;
  6636. t['firsttonechinese'] = 0x02C9;
  6637. t['fisheye'] = 0x25C9;
  6638. t['fitacyrillic'] = 0x0473;
  6639. t['five'] = 0x0035;
  6640. t['fivearabic'] = 0x0665;
  6641. t['fivebengali'] = 0x09EB;
  6642. t['fivecircle'] = 0x2464;
  6643. t['fivecircleinversesansserif'] = 0x278E;
  6644. t['fivedeva'] = 0x096B;
  6645. t['fiveeighths'] = 0x215D;
  6646. t['fivegujarati'] = 0x0AEB;
  6647. t['fivegurmukhi'] = 0x0A6B;
  6648. t['fivehackarabic'] = 0x0665;
  6649. t['fivehangzhou'] = 0x3025;
  6650. t['fiveideographicparen'] = 0x3224;
  6651. t['fiveinferior'] = 0x2085;
  6652. t['fivemonospace'] = 0xFF15;
  6653. t['fiveoldstyle'] = 0xF735;
  6654. t['fiveparen'] = 0x2478;
  6655. t['fiveperiod'] = 0x248C;
  6656. t['fivepersian'] = 0x06F5;
  6657. t['fiveroman'] = 0x2174;
  6658. t['fivesuperior'] = 0x2075;
  6659. t['fivethai'] = 0x0E55;
  6660. t['fl'] = 0xFB02;
  6661. t['florin'] = 0x0192;
  6662. t['fmonospace'] = 0xFF46;
  6663. t['fmsquare'] = 0x3399;
  6664. t['fofanthai'] = 0x0E1F;
  6665. t['fofathai'] = 0x0E1D;
  6666. t['fongmanthai'] = 0x0E4F;
  6667. t['forall'] = 0x2200;
  6668. t['four'] = 0x0034;
  6669. t['fourarabic'] = 0x0664;
  6670. t['fourbengali'] = 0x09EA;
  6671. t['fourcircle'] = 0x2463;
  6672. t['fourcircleinversesansserif'] = 0x278D;
  6673. t['fourdeva'] = 0x096A;
  6674. t['fourgujarati'] = 0x0AEA;
  6675. t['fourgurmukhi'] = 0x0A6A;
  6676. t['fourhackarabic'] = 0x0664;
  6677. t['fourhangzhou'] = 0x3024;
  6678. t['fourideographicparen'] = 0x3223;
  6679. t['fourinferior'] = 0x2084;
  6680. t['fourmonospace'] = 0xFF14;
  6681. t['fournumeratorbengali'] = 0x09F7;
  6682. t['fouroldstyle'] = 0xF734;
  6683. t['fourparen'] = 0x2477;
  6684. t['fourperiod'] = 0x248B;
  6685. t['fourpersian'] = 0x06F4;
  6686. t['fourroman'] = 0x2173;
  6687. t['foursuperior'] = 0x2074;
  6688. t['fourteencircle'] = 0x246D;
  6689. t['fourteenparen'] = 0x2481;
  6690. t['fourteenperiod'] = 0x2495;
  6691. t['fourthai'] = 0x0E54;
  6692. t['fourthtonechinese'] = 0x02CB;
  6693. t['fparen'] = 0x24A1;
  6694. t['fraction'] = 0x2044;
  6695. t['franc'] = 0x20A3;
  6696. t['g'] = 0x0067;
  6697. t['gabengali'] = 0x0997;
  6698. t['gacute'] = 0x01F5;
  6699. t['gadeva'] = 0x0917;
  6700. t['gafarabic'] = 0x06AF;
  6701. t['gaffinalarabic'] = 0xFB93;
  6702. t['gafinitialarabic'] = 0xFB94;
  6703. t['gafmedialarabic'] = 0xFB95;
  6704. t['gagujarati'] = 0x0A97;
  6705. t['gagurmukhi'] = 0x0A17;
  6706. t['gahiragana'] = 0x304C;
  6707. t['gakatakana'] = 0x30AC;
  6708. t['gamma'] = 0x03B3;
  6709. t['gammalatinsmall'] = 0x0263;
  6710. t['gammasuperior'] = 0x02E0;
  6711. t['gangiacoptic'] = 0x03EB;
  6712. t['gbopomofo'] = 0x310D;
  6713. t['gbreve'] = 0x011F;
  6714. t['gcaron'] = 0x01E7;
  6715. t['gcedilla'] = 0x0123;
  6716. t['gcircle'] = 0x24D6;
  6717. t['gcircumflex'] = 0x011D;
  6718. t['gcommaaccent'] = 0x0123;
  6719. t['gdot'] = 0x0121;
  6720. t['gdotaccent'] = 0x0121;
  6721. t['gecyrillic'] = 0x0433;
  6722. t['gehiragana'] = 0x3052;
  6723. t['gekatakana'] = 0x30B2;
  6724. t['geometricallyequal'] = 0x2251;
  6725. t['gereshaccenthebrew'] = 0x059C;
  6726. t['gereshhebrew'] = 0x05F3;
  6727. t['gereshmuqdamhebrew'] = 0x059D;
  6728. t['germandbls'] = 0x00DF;
  6729. t['gershayimaccenthebrew'] = 0x059E;
  6730. t['gershayimhebrew'] = 0x05F4;
  6731. t['getamark'] = 0x3013;
  6732. t['ghabengali'] = 0x0998;
  6733. t['ghadarmenian'] = 0x0572;
  6734. t['ghadeva'] = 0x0918;
  6735. t['ghagujarati'] = 0x0A98;
  6736. t['ghagurmukhi'] = 0x0A18;
  6737. t['ghainarabic'] = 0x063A;
  6738. t['ghainfinalarabic'] = 0xFECE;
  6739. t['ghaininitialarabic'] = 0xFECF;
  6740. t['ghainmedialarabic'] = 0xFED0;
  6741. t['ghemiddlehookcyrillic'] = 0x0495;
  6742. t['ghestrokecyrillic'] = 0x0493;
  6743. t['gheupturncyrillic'] = 0x0491;
  6744. t['ghhadeva'] = 0x095A;
  6745. t['ghhagurmukhi'] = 0x0A5A;
  6746. t['ghook'] = 0x0260;
  6747. t['ghzsquare'] = 0x3393;
  6748. t['gihiragana'] = 0x304E;
  6749. t['gikatakana'] = 0x30AE;
  6750. t['gimarmenian'] = 0x0563;
  6751. t['gimel'] = 0x05D2;
  6752. t['gimeldagesh'] = 0xFB32;
  6753. t['gimeldageshhebrew'] = 0xFB32;
  6754. t['gimelhebrew'] = 0x05D2;
  6755. t['gjecyrillic'] = 0x0453;
  6756. t['glottalinvertedstroke'] = 0x01BE;
  6757. t['glottalstop'] = 0x0294;
  6758. t['glottalstopinverted'] = 0x0296;
  6759. t['glottalstopmod'] = 0x02C0;
  6760. t['glottalstopreversed'] = 0x0295;
  6761. t['glottalstopreversedmod'] = 0x02C1;
  6762. t['glottalstopreversedsuperior'] = 0x02E4;
  6763. t['glottalstopstroke'] = 0x02A1;
  6764. t['glottalstopstrokereversed'] = 0x02A2;
  6765. t['gmacron'] = 0x1E21;
  6766. t['gmonospace'] = 0xFF47;
  6767. t['gohiragana'] = 0x3054;
  6768. t['gokatakana'] = 0x30B4;
  6769. t['gparen'] = 0x24A2;
  6770. t['gpasquare'] = 0x33AC;
  6771. t['gradient'] = 0x2207;
  6772. t['grave'] = 0x0060;
  6773. t['gravebelowcmb'] = 0x0316;
  6774. t['gravecmb'] = 0x0300;
  6775. t['gravecomb'] = 0x0300;
  6776. t['gravedeva'] = 0x0953;
  6777. t['gravelowmod'] = 0x02CE;
  6778. t['gravemonospace'] = 0xFF40;
  6779. t['gravetonecmb'] = 0x0340;
  6780. t['greater'] = 0x003E;
  6781. t['greaterequal'] = 0x2265;
  6782. t['greaterequalorless'] = 0x22DB;
  6783. t['greatermonospace'] = 0xFF1E;
  6784. t['greaterorequivalent'] = 0x2273;
  6785. t['greaterorless'] = 0x2277;
  6786. t['greateroverequal'] = 0x2267;
  6787. t['greatersmall'] = 0xFE65;
  6788. t['gscript'] = 0x0261;
  6789. t['gstroke'] = 0x01E5;
  6790. t['guhiragana'] = 0x3050;
  6791. t['guillemotleft'] = 0x00AB;
  6792. t['guillemotright'] = 0x00BB;
  6793. t['guilsinglleft'] = 0x2039;
  6794. t['guilsinglright'] = 0x203A;
  6795. t['gukatakana'] = 0x30B0;
  6796. t['guramusquare'] = 0x3318;
  6797. t['gysquare'] = 0x33C9;
  6798. t['h'] = 0x0068;
  6799. t['haabkhasiancyrillic'] = 0x04A9;
  6800. t['haaltonearabic'] = 0x06C1;
  6801. t['habengali'] = 0x09B9;
  6802. t['hadescendercyrillic'] = 0x04B3;
  6803. t['hadeva'] = 0x0939;
  6804. t['hagujarati'] = 0x0AB9;
  6805. t['hagurmukhi'] = 0x0A39;
  6806. t['haharabic'] = 0x062D;
  6807. t['hahfinalarabic'] = 0xFEA2;
  6808. t['hahinitialarabic'] = 0xFEA3;
  6809. t['hahiragana'] = 0x306F;
  6810. t['hahmedialarabic'] = 0xFEA4;
  6811. t['haitusquare'] = 0x332A;
  6812. t['hakatakana'] = 0x30CF;
  6813. t['hakatakanahalfwidth'] = 0xFF8A;
  6814. t['halantgurmukhi'] = 0x0A4D;
  6815. t['hamzaarabic'] = 0x0621;
  6816. t['hamzalowarabic'] = 0x0621;
  6817. t['hangulfiller'] = 0x3164;
  6818. t['hardsigncyrillic'] = 0x044A;
  6819. t['harpoonleftbarbup'] = 0x21BC;
  6820. t['harpoonrightbarbup'] = 0x21C0;
  6821. t['hasquare'] = 0x33CA;
  6822. t['hatafpatah'] = 0x05B2;
  6823. t['hatafpatah16'] = 0x05B2;
  6824. t['hatafpatah23'] = 0x05B2;
  6825. t['hatafpatah2f'] = 0x05B2;
  6826. t['hatafpatahhebrew'] = 0x05B2;
  6827. t['hatafpatahnarrowhebrew'] = 0x05B2;
  6828. t['hatafpatahquarterhebrew'] = 0x05B2;
  6829. t['hatafpatahwidehebrew'] = 0x05B2;
  6830. t['hatafqamats'] = 0x05B3;
  6831. t['hatafqamats1b'] = 0x05B3;
  6832. t['hatafqamats28'] = 0x05B3;
  6833. t['hatafqamats34'] = 0x05B3;
  6834. t['hatafqamatshebrew'] = 0x05B3;
  6835. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  6836. t['hatafqamatsquarterhebrew'] = 0x05B3;
  6837. t['hatafqamatswidehebrew'] = 0x05B3;
  6838. t['hatafsegol'] = 0x05B1;
  6839. t['hatafsegol17'] = 0x05B1;
  6840. t['hatafsegol24'] = 0x05B1;
  6841. t['hatafsegol30'] = 0x05B1;
  6842. t['hatafsegolhebrew'] = 0x05B1;
  6843. t['hatafsegolnarrowhebrew'] = 0x05B1;
  6844. t['hatafsegolquarterhebrew'] = 0x05B1;
  6845. t['hatafsegolwidehebrew'] = 0x05B1;
  6846. t['hbar'] = 0x0127;
  6847. t['hbopomofo'] = 0x310F;
  6848. t['hbrevebelow'] = 0x1E2B;
  6849. t['hcedilla'] = 0x1E29;
  6850. t['hcircle'] = 0x24D7;
  6851. t['hcircumflex'] = 0x0125;
  6852. t['hdieresis'] = 0x1E27;
  6853. t['hdotaccent'] = 0x1E23;
  6854. t['hdotbelow'] = 0x1E25;
  6855. t['he'] = 0x05D4;
  6856. t['heart'] = 0x2665;
  6857. t['heartsuitblack'] = 0x2665;
  6858. t['heartsuitwhite'] = 0x2661;
  6859. t['hedagesh'] = 0xFB34;
  6860. t['hedageshhebrew'] = 0xFB34;
  6861. t['hehaltonearabic'] = 0x06C1;
  6862. t['heharabic'] = 0x0647;
  6863. t['hehebrew'] = 0x05D4;
  6864. t['hehfinalaltonearabic'] = 0xFBA7;
  6865. t['hehfinalalttwoarabic'] = 0xFEEA;
  6866. t['hehfinalarabic'] = 0xFEEA;
  6867. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  6868. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  6869. t['hehinitialaltonearabic'] = 0xFBA8;
  6870. t['hehinitialarabic'] = 0xFEEB;
  6871. t['hehiragana'] = 0x3078;
  6872. t['hehmedialaltonearabic'] = 0xFBA9;
  6873. t['hehmedialarabic'] = 0xFEEC;
  6874. t['heiseierasquare'] = 0x337B;
  6875. t['hekatakana'] = 0x30D8;
  6876. t['hekatakanahalfwidth'] = 0xFF8D;
  6877. t['hekutaarusquare'] = 0x3336;
  6878. t['henghook'] = 0x0267;
  6879. t['herutusquare'] = 0x3339;
  6880. t['het'] = 0x05D7;
  6881. t['hethebrew'] = 0x05D7;
  6882. t['hhook'] = 0x0266;
  6883. t['hhooksuperior'] = 0x02B1;
  6884. t['hieuhacirclekorean'] = 0x327B;
  6885. t['hieuhaparenkorean'] = 0x321B;
  6886. t['hieuhcirclekorean'] = 0x326D;
  6887. t['hieuhkorean'] = 0x314E;
  6888. t['hieuhparenkorean'] = 0x320D;
  6889. t['hihiragana'] = 0x3072;
  6890. t['hikatakana'] = 0x30D2;
  6891. t['hikatakanahalfwidth'] = 0xFF8B;
  6892. t['hiriq'] = 0x05B4;
  6893. t['hiriq14'] = 0x05B4;
  6894. t['hiriq21'] = 0x05B4;
  6895. t['hiriq2d'] = 0x05B4;
  6896. t['hiriqhebrew'] = 0x05B4;
  6897. t['hiriqnarrowhebrew'] = 0x05B4;
  6898. t['hiriqquarterhebrew'] = 0x05B4;
  6899. t['hiriqwidehebrew'] = 0x05B4;
  6900. t['hlinebelow'] = 0x1E96;
  6901. t['hmonospace'] = 0xFF48;
  6902. t['hoarmenian'] = 0x0570;
  6903. t['hohipthai'] = 0x0E2B;
  6904. t['hohiragana'] = 0x307B;
  6905. t['hokatakana'] = 0x30DB;
  6906. t['hokatakanahalfwidth'] = 0xFF8E;
  6907. t['holam'] = 0x05B9;
  6908. t['holam19'] = 0x05B9;
  6909. t['holam26'] = 0x05B9;
  6910. t['holam32'] = 0x05B9;
  6911. t['holamhebrew'] = 0x05B9;
  6912. t['holamnarrowhebrew'] = 0x05B9;
  6913. t['holamquarterhebrew'] = 0x05B9;
  6914. t['holamwidehebrew'] = 0x05B9;
  6915. t['honokhukthai'] = 0x0E2E;
  6916. t['hookabovecomb'] = 0x0309;
  6917. t['hookcmb'] = 0x0309;
  6918. t['hookpalatalizedbelowcmb'] = 0x0321;
  6919. t['hookretroflexbelowcmb'] = 0x0322;
  6920. t['hoonsquare'] = 0x3342;
  6921. t['horicoptic'] = 0x03E9;
  6922. t['horizontalbar'] = 0x2015;
  6923. t['horncmb'] = 0x031B;
  6924. t['hotsprings'] = 0x2668;
  6925. t['house'] = 0x2302;
  6926. t['hparen'] = 0x24A3;
  6927. t['hsuperior'] = 0x02B0;
  6928. t['hturned'] = 0x0265;
  6929. t['huhiragana'] = 0x3075;
  6930. t['huiitosquare'] = 0x3333;
  6931. t['hukatakana'] = 0x30D5;
  6932. t['hukatakanahalfwidth'] = 0xFF8C;
  6933. t['hungarumlaut'] = 0x02DD;
  6934. t['hungarumlautcmb'] = 0x030B;
  6935. t['hv'] = 0x0195;
  6936. t['hyphen'] = 0x002D;
  6937. t['hypheninferior'] = 0xF6E5;
  6938. t['hyphenmonospace'] = 0xFF0D;
  6939. t['hyphensmall'] = 0xFE63;
  6940. t['hyphensuperior'] = 0xF6E6;
  6941. t['hyphentwo'] = 0x2010;
  6942. t['i'] = 0x0069;
  6943. t['iacute'] = 0x00ED;
  6944. t['iacyrillic'] = 0x044F;
  6945. t['ibengali'] = 0x0987;
  6946. t['ibopomofo'] = 0x3127;
  6947. t['ibreve'] = 0x012D;
  6948. t['icaron'] = 0x01D0;
  6949. t['icircle'] = 0x24D8;
  6950. t['icircumflex'] = 0x00EE;
  6951. t['icyrillic'] = 0x0456;
  6952. t['idblgrave'] = 0x0209;
  6953. t['ideographearthcircle'] = 0x328F;
  6954. t['ideographfirecircle'] = 0x328B;
  6955. t['ideographicallianceparen'] = 0x323F;
  6956. t['ideographiccallparen'] = 0x323A;
  6957. t['ideographiccentrecircle'] = 0x32A5;
  6958. t['ideographicclose'] = 0x3006;
  6959. t['ideographiccomma'] = 0x3001;
  6960. t['ideographiccommaleft'] = 0xFF64;
  6961. t['ideographiccongratulationparen'] = 0x3237;
  6962. t['ideographiccorrectcircle'] = 0x32A3;
  6963. t['ideographicearthparen'] = 0x322F;
  6964. t['ideographicenterpriseparen'] = 0x323D;
  6965. t['ideographicexcellentcircle'] = 0x329D;
  6966. t['ideographicfestivalparen'] = 0x3240;
  6967. t['ideographicfinancialcircle'] = 0x3296;
  6968. t['ideographicfinancialparen'] = 0x3236;
  6969. t['ideographicfireparen'] = 0x322B;
  6970. t['ideographichaveparen'] = 0x3232;
  6971. t['ideographichighcircle'] = 0x32A4;
  6972. t['ideographiciterationmark'] = 0x3005;
  6973. t['ideographiclaborcircle'] = 0x3298;
  6974. t['ideographiclaborparen'] = 0x3238;
  6975. t['ideographicleftcircle'] = 0x32A7;
  6976. t['ideographiclowcircle'] = 0x32A6;
  6977. t['ideographicmedicinecircle'] = 0x32A9;
  6978. t['ideographicmetalparen'] = 0x322E;
  6979. t['ideographicmoonparen'] = 0x322A;
  6980. t['ideographicnameparen'] = 0x3234;
  6981. t['ideographicperiod'] = 0x3002;
  6982. t['ideographicprintcircle'] = 0x329E;
  6983. t['ideographicreachparen'] = 0x3243;
  6984. t['ideographicrepresentparen'] = 0x3239;
  6985. t['ideographicresourceparen'] = 0x323E;
  6986. t['ideographicrightcircle'] = 0x32A8;
  6987. t['ideographicsecretcircle'] = 0x3299;
  6988. t['ideographicselfparen'] = 0x3242;
  6989. t['ideographicsocietyparen'] = 0x3233;
  6990. t['ideographicspace'] = 0x3000;
  6991. t['ideographicspecialparen'] = 0x3235;
  6992. t['ideographicstockparen'] = 0x3231;
  6993. t['ideographicstudyparen'] = 0x323B;
  6994. t['ideographicsunparen'] = 0x3230;
  6995. t['ideographicsuperviseparen'] = 0x323C;
  6996. t['ideographicwaterparen'] = 0x322C;
  6997. t['ideographicwoodparen'] = 0x322D;
  6998. t['ideographiczero'] = 0x3007;
  6999. t['ideographmetalcircle'] = 0x328E;
  7000. t['ideographmooncircle'] = 0x328A;
  7001. t['ideographnamecircle'] = 0x3294;
  7002. t['ideographsuncircle'] = 0x3290;
  7003. t['ideographwatercircle'] = 0x328C;
  7004. t['ideographwoodcircle'] = 0x328D;
  7005. t['ideva'] = 0x0907;
  7006. t['idieresis'] = 0x00EF;
  7007. t['idieresisacute'] = 0x1E2F;
  7008. t['idieresiscyrillic'] = 0x04E5;
  7009. t['idotbelow'] = 0x1ECB;
  7010. t['iebrevecyrillic'] = 0x04D7;
  7011. t['iecyrillic'] = 0x0435;
  7012. t['ieungacirclekorean'] = 0x3275;
  7013. t['ieungaparenkorean'] = 0x3215;
  7014. t['ieungcirclekorean'] = 0x3267;
  7015. t['ieungkorean'] = 0x3147;
  7016. t['ieungparenkorean'] = 0x3207;
  7017. t['igrave'] = 0x00EC;
  7018. t['igujarati'] = 0x0A87;
  7019. t['igurmukhi'] = 0x0A07;
  7020. t['ihiragana'] = 0x3044;
  7021. t['ihookabove'] = 0x1EC9;
  7022. t['iibengali'] = 0x0988;
  7023. t['iicyrillic'] = 0x0438;
  7024. t['iideva'] = 0x0908;
  7025. t['iigujarati'] = 0x0A88;
  7026. t['iigurmukhi'] = 0x0A08;
  7027. t['iimatragurmukhi'] = 0x0A40;
  7028. t['iinvertedbreve'] = 0x020B;
  7029. t['iishortcyrillic'] = 0x0439;
  7030. t['iivowelsignbengali'] = 0x09C0;
  7031. t['iivowelsigndeva'] = 0x0940;
  7032. t['iivowelsigngujarati'] = 0x0AC0;
  7033. t['ij'] = 0x0133;
  7034. t['ikatakana'] = 0x30A4;
  7035. t['ikatakanahalfwidth'] = 0xFF72;
  7036. t['ikorean'] = 0x3163;
  7037. t['ilde'] = 0x02DC;
  7038. t['iluyhebrew'] = 0x05AC;
  7039. t['imacron'] = 0x012B;
  7040. t['imacroncyrillic'] = 0x04E3;
  7041. t['imageorapproximatelyequal'] = 0x2253;
  7042. t['imatragurmukhi'] = 0x0A3F;
  7043. t['imonospace'] = 0xFF49;
  7044. t['increment'] = 0x2206;
  7045. t['infinity'] = 0x221E;
  7046. t['iniarmenian'] = 0x056B;
  7047. t['integral'] = 0x222B;
  7048. t['integralbottom'] = 0x2321;
  7049. t['integralbt'] = 0x2321;
  7050. t['integralex'] = 0xF8F5;
  7051. t['integraltop'] = 0x2320;
  7052. t['integraltp'] = 0x2320;
  7053. t['intersection'] = 0x2229;
  7054. t['intisquare'] = 0x3305;
  7055. t['invbullet'] = 0x25D8;
  7056. t['invcircle'] = 0x25D9;
  7057. t['invsmileface'] = 0x263B;
  7058. t['iocyrillic'] = 0x0451;
  7059. t['iogonek'] = 0x012F;
  7060. t['iota'] = 0x03B9;
  7061. t['iotadieresis'] = 0x03CA;
  7062. t['iotadieresistonos'] = 0x0390;
  7063. t['iotalatin'] = 0x0269;
  7064. t['iotatonos'] = 0x03AF;
  7065. t['iparen'] = 0x24A4;
  7066. t['irigurmukhi'] = 0x0A72;
  7067. t['ismallhiragana'] = 0x3043;
  7068. t['ismallkatakana'] = 0x30A3;
  7069. t['ismallkatakanahalfwidth'] = 0xFF68;
  7070. t['issharbengali'] = 0x09FA;
  7071. t['istroke'] = 0x0268;
  7072. t['isuperior'] = 0xF6ED;
  7073. t['iterationhiragana'] = 0x309D;
  7074. t['iterationkatakana'] = 0x30FD;
  7075. t['itilde'] = 0x0129;
  7076. t['itildebelow'] = 0x1E2D;
  7077. t['iubopomofo'] = 0x3129;
  7078. t['iucyrillic'] = 0x044E;
  7079. t['ivowelsignbengali'] = 0x09BF;
  7080. t['ivowelsigndeva'] = 0x093F;
  7081. t['ivowelsigngujarati'] = 0x0ABF;
  7082. t['izhitsacyrillic'] = 0x0475;
  7083. t['izhitsadblgravecyrillic'] = 0x0477;
  7084. t['j'] = 0x006A;
  7085. t['jaarmenian'] = 0x0571;
  7086. t['jabengali'] = 0x099C;
  7087. t['jadeva'] = 0x091C;
  7088. t['jagujarati'] = 0x0A9C;
  7089. t['jagurmukhi'] = 0x0A1C;
  7090. t['jbopomofo'] = 0x3110;
  7091. t['jcaron'] = 0x01F0;
  7092. t['jcircle'] = 0x24D9;
  7093. t['jcircumflex'] = 0x0135;
  7094. t['jcrossedtail'] = 0x029D;
  7095. t['jdotlessstroke'] = 0x025F;
  7096. t['jecyrillic'] = 0x0458;
  7097. t['jeemarabic'] = 0x062C;
  7098. t['jeemfinalarabic'] = 0xFE9E;
  7099. t['jeeminitialarabic'] = 0xFE9F;
  7100. t['jeemmedialarabic'] = 0xFEA0;
  7101. t['jeharabic'] = 0x0698;
  7102. t['jehfinalarabic'] = 0xFB8B;
  7103. t['jhabengali'] = 0x099D;
  7104. t['jhadeva'] = 0x091D;
  7105. t['jhagujarati'] = 0x0A9D;
  7106. t['jhagurmukhi'] = 0x0A1D;
  7107. t['jheharmenian'] = 0x057B;
  7108. t['jis'] = 0x3004;
  7109. t['jmonospace'] = 0xFF4A;
  7110. t['jparen'] = 0x24A5;
  7111. t['jsuperior'] = 0x02B2;
  7112. t['k'] = 0x006B;
  7113. t['kabashkircyrillic'] = 0x04A1;
  7114. t['kabengali'] = 0x0995;
  7115. t['kacute'] = 0x1E31;
  7116. t['kacyrillic'] = 0x043A;
  7117. t['kadescendercyrillic'] = 0x049B;
  7118. t['kadeva'] = 0x0915;
  7119. t['kaf'] = 0x05DB;
  7120. t['kafarabic'] = 0x0643;
  7121. t['kafdagesh'] = 0xFB3B;
  7122. t['kafdageshhebrew'] = 0xFB3B;
  7123. t['kaffinalarabic'] = 0xFEDA;
  7124. t['kafhebrew'] = 0x05DB;
  7125. t['kafinitialarabic'] = 0xFEDB;
  7126. t['kafmedialarabic'] = 0xFEDC;
  7127. t['kafrafehebrew'] = 0xFB4D;
  7128. t['kagujarati'] = 0x0A95;
  7129. t['kagurmukhi'] = 0x0A15;
  7130. t['kahiragana'] = 0x304B;
  7131. t['kahookcyrillic'] = 0x04C4;
  7132. t['kakatakana'] = 0x30AB;
  7133. t['kakatakanahalfwidth'] = 0xFF76;
  7134. t['kappa'] = 0x03BA;
  7135. t['kappasymbolgreek'] = 0x03F0;
  7136. t['kapyeounmieumkorean'] = 0x3171;
  7137. t['kapyeounphieuphkorean'] = 0x3184;
  7138. t['kapyeounpieupkorean'] = 0x3178;
  7139. t['kapyeounssangpieupkorean'] = 0x3179;
  7140. t['karoriisquare'] = 0x330D;
  7141. t['kashidaautoarabic'] = 0x0640;
  7142. t['kashidaautonosidebearingarabic'] = 0x0640;
  7143. t['kasmallkatakana'] = 0x30F5;
  7144. t['kasquare'] = 0x3384;
  7145. t['kasraarabic'] = 0x0650;
  7146. t['kasratanarabic'] = 0x064D;
  7147. t['kastrokecyrillic'] = 0x049F;
  7148. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7149. t['kaverticalstrokecyrillic'] = 0x049D;
  7150. t['kbopomofo'] = 0x310E;
  7151. t['kcalsquare'] = 0x3389;
  7152. t['kcaron'] = 0x01E9;
  7153. t['kcedilla'] = 0x0137;
  7154. t['kcircle'] = 0x24DA;
  7155. t['kcommaaccent'] = 0x0137;
  7156. t['kdotbelow'] = 0x1E33;
  7157. t['keharmenian'] = 0x0584;
  7158. t['kehiragana'] = 0x3051;
  7159. t['kekatakana'] = 0x30B1;
  7160. t['kekatakanahalfwidth'] = 0xFF79;
  7161. t['kenarmenian'] = 0x056F;
  7162. t['kesmallkatakana'] = 0x30F6;
  7163. t['kgreenlandic'] = 0x0138;
  7164. t['khabengali'] = 0x0996;
  7165. t['khacyrillic'] = 0x0445;
  7166. t['khadeva'] = 0x0916;
  7167. t['khagujarati'] = 0x0A96;
  7168. t['khagurmukhi'] = 0x0A16;
  7169. t['khaharabic'] = 0x062E;
  7170. t['khahfinalarabic'] = 0xFEA6;
  7171. t['khahinitialarabic'] = 0xFEA7;
  7172. t['khahmedialarabic'] = 0xFEA8;
  7173. t['kheicoptic'] = 0x03E7;
  7174. t['khhadeva'] = 0x0959;
  7175. t['khhagurmukhi'] = 0x0A59;
  7176. t['khieukhacirclekorean'] = 0x3278;
  7177. t['khieukhaparenkorean'] = 0x3218;
  7178. t['khieukhcirclekorean'] = 0x326A;
  7179. t['khieukhkorean'] = 0x314B;
  7180. t['khieukhparenkorean'] = 0x320A;
  7181. t['khokhaithai'] = 0x0E02;
  7182. t['khokhonthai'] = 0x0E05;
  7183. t['khokhuatthai'] = 0x0E03;
  7184. t['khokhwaithai'] = 0x0E04;
  7185. t['khomutthai'] = 0x0E5B;
  7186. t['khook'] = 0x0199;
  7187. t['khorakhangthai'] = 0x0E06;
  7188. t['khzsquare'] = 0x3391;
  7189. t['kihiragana'] = 0x304D;
  7190. t['kikatakana'] = 0x30AD;
  7191. t['kikatakanahalfwidth'] = 0xFF77;
  7192. t['kiroguramusquare'] = 0x3315;
  7193. t['kiromeetorusquare'] = 0x3316;
  7194. t['kirosquare'] = 0x3314;
  7195. t['kiyeokacirclekorean'] = 0x326E;
  7196. t['kiyeokaparenkorean'] = 0x320E;
  7197. t['kiyeokcirclekorean'] = 0x3260;
  7198. t['kiyeokkorean'] = 0x3131;
  7199. t['kiyeokparenkorean'] = 0x3200;
  7200. t['kiyeoksioskorean'] = 0x3133;
  7201. t['kjecyrillic'] = 0x045C;
  7202. t['klinebelow'] = 0x1E35;
  7203. t['klsquare'] = 0x3398;
  7204. t['kmcubedsquare'] = 0x33A6;
  7205. t['kmonospace'] = 0xFF4B;
  7206. t['kmsquaredsquare'] = 0x33A2;
  7207. t['kohiragana'] = 0x3053;
  7208. t['kohmsquare'] = 0x33C0;
  7209. t['kokaithai'] = 0x0E01;
  7210. t['kokatakana'] = 0x30B3;
  7211. t['kokatakanahalfwidth'] = 0xFF7A;
  7212. t['kooposquare'] = 0x331E;
  7213. t['koppacyrillic'] = 0x0481;
  7214. t['koreanstandardsymbol'] = 0x327F;
  7215. t['koroniscmb'] = 0x0343;
  7216. t['kparen'] = 0x24A6;
  7217. t['kpasquare'] = 0x33AA;
  7218. t['ksicyrillic'] = 0x046F;
  7219. t['ktsquare'] = 0x33CF;
  7220. t['kturned'] = 0x029E;
  7221. t['kuhiragana'] = 0x304F;
  7222. t['kukatakana'] = 0x30AF;
  7223. t['kukatakanahalfwidth'] = 0xFF78;
  7224. t['kvsquare'] = 0x33B8;
  7225. t['kwsquare'] = 0x33BE;
  7226. t['l'] = 0x006C;
  7227. t['labengali'] = 0x09B2;
  7228. t['lacute'] = 0x013A;
  7229. t['ladeva'] = 0x0932;
  7230. t['lagujarati'] = 0x0AB2;
  7231. t['lagurmukhi'] = 0x0A32;
  7232. t['lakkhangyaothai'] = 0x0E45;
  7233. t['lamaleffinalarabic'] = 0xFEFC;
  7234. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7235. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7236. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7237. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7238. t['lamalefisolatedarabic'] = 0xFEFB;
  7239. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7240. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7241. t['lamarabic'] = 0x0644;
  7242. t['lambda'] = 0x03BB;
  7243. t['lambdastroke'] = 0x019B;
  7244. t['lamed'] = 0x05DC;
  7245. t['lameddagesh'] = 0xFB3C;
  7246. t['lameddageshhebrew'] = 0xFB3C;
  7247. t['lamedhebrew'] = 0x05DC;
  7248. t['lamfinalarabic'] = 0xFEDE;
  7249. t['lamhahinitialarabic'] = 0xFCCA;
  7250. t['laminitialarabic'] = 0xFEDF;
  7251. t['lamjeeminitialarabic'] = 0xFCC9;
  7252. t['lamkhahinitialarabic'] = 0xFCCB;
  7253. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7254. t['lammedialarabic'] = 0xFEE0;
  7255. t['lammeemhahinitialarabic'] = 0xFD88;
  7256. t['lammeeminitialarabic'] = 0xFCCC;
  7257. t['largecircle'] = 0x25EF;
  7258. t['lbar'] = 0x019A;
  7259. t['lbelt'] = 0x026C;
  7260. t['lbopomofo'] = 0x310C;
  7261. t['lcaron'] = 0x013E;
  7262. t['lcedilla'] = 0x013C;
  7263. t['lcircle'] = 0x24DB;
  7264. t['lcircumflexbelow'] = 0x1E3D;
  7265. t['lcommaaccent'] = 0x013C;
  7266. t['ldot'] = 0x0140;
  7267. t['ldotaccent'] = 0x0140;
  7268. t['ldotbelow'] = 0x1E37;
  7269. t['ldotbelowmacron'] = 0x1E39;
  7270. t['leftangleabovecmb'] = 0x031A;
  7271. t['lefttackbelowcmb'] = 0x0318;
  7272. t['less'] = 0x003C;
  7273. t['lessequal'] = 0x2264;
  7274. t['lessequalorgreater'] = 0x22DA;
  7275. t['lessmonospace'] = 0xFF1C;
  7276. t['lessorequivalent'] = 0x2272;
  7277. t['lessorgreater'] = 0x2276;
  7278. t['lessoverequal'] = 0x2266;
  7279. t['lesssmall'] = 0xFE64;
  7280. t['lezh'] = 0x026E;
  7281. t['lfblock'] = 0x258C;
  7282. t['lhookretroflex'] = 0x026D;
  7283. t['lira'] = 0x20A4;
  7284. t['liwnarmenian'] = 0x056C;
  7285. t['lj'] = 0x01C9;
  7286. t['ljecyrillic'] = 0x0459;
  7287. t['ll'] = 0xF6C0;
  7288. t['lladeva'] = 0x0933;
  7289. t['llagujarati'] = 0x0AB3;
  7290. t['llinebelow'] = 0x1E3B;
  7291. t['llladeva'] = 0x0934;
  7292. t['llvocalicbengali'] = 0x09E1;
  7293. t['llvocalicdeva'] = 0x0961;
  7294. t['llvocalicvowelsignbengali'] = 0x09E3;
  7295. t['llvocalicvowelsigndeva'] = 0x0963;
  7296. t['lmiddletilde'] = 0x026B;
  7297. t['lmonospace'] = 0xFF4C;
  7298. t['lmsquare'] = 0x33D0;
  7299. t['lochulathai'] = 0x0E2C;
  7300. t['logicaland'] = 0x2227;
  7301. t['logicalnot'] = 0x00AC;
  7302. t['logicalnotreversed'] = 0x2310;
  7303. t['logicalor'] = 0x2228;
  7304. t['lolingthai'] = 0x0E25;
  7305. t['longs'] = 0x017F;
  7306. t['lowlinecenterline'] = 0xFE4E;
  7307. t['lowlinecmb'] = 0x0332;
  7308. t['lowlinedashed'] = 0xFE4D;
  7309. t['lozenge'] = 0x25CA;
  7310. t['lparen'] = 0x24A7;
  7311. t['lslash'] = 0x0142;
  7312. t['lsquare'] = 0x2113;
  7313. t['lsuperior'] = 0xF6EE;
  7314. t['ltshade'] = 0x2591;
  7315. t['luthai'] = 0x0E26;
  7316. t['lvocalicbengali'] = 0x098C;
  7317. t['lvocalicdeva'] = 0x090C;
  7318. t['lvocalicvowelsignbengali'] = 0x09E2;
  7319. t['lvocalicvowelsigndeva'] = 0x0962;
  7320. t['lxsquare'] = 0x33D3;
  7321. t['m'] = 0x006D;
  7322. t['mabengali'] = 0x09AE;
  7323. t['macron'] = 0x00AF;
  7324. t['macronbelowcmb'] = 0x0331;
  7325. t['macroncmb'] = 0x0304;
  7326. t['macronlowmod'] = 0x02CD;
  7327. t['macronmonospace'] = 0xFFE3;
  7328. t['macute'] = 0x1E3F;
  7329. t['madeva'] = 0x092E;
  7330. t['magujarati'] = 0x0AAE;
  7331. t['magurmukhi'] = 0x0A2E;
  7332. t['mahapakhhebrew'] = 0x05A4;
  7333. t['mahapakhlefthebrew'] = 0x05A4;
  7334. t['mahiragana'] = 0x307E;
  7335. t['maichattawalowleftthai'] = 0xF895;
  7336. t['maichattawalowrightthai'] = 0xF894;
  7337. t['maichattawathai'] = 0x0E4B;
  7338. t['maichattawaupperleftthai'] = 0xF893;
  7339. t['maieklowleftthai'] = 0xF88C;
  7340. t['maieklowrightthai'] = 0xF88B;
  7341. t['maiekthai'] = 0x0E48;
  7342. t['maiekupperleftthai'] = 0xF88A;
  7343. t['maihanakatleftthai'] = 0xF884;
  7344. t['maihanakatthai'] = 0x0E31;
  7345. t['maitaikhuleftthai'] = 0xF889;
  7346. t['maitaikhuthai'] = 0x0E47;
  7347. t['maitholowleftthai'] = 0xF88F;
  7348. t['maitholowrightthai'] = 0xF88E;
  7349. t['maithothai'] = 0x0E49;
  7350. t['maithoupperleftthai'] = 0xF88D;
  7351. t['maitrilowleftthai'] = 0xF892;
  7352. t['maitrilowrightthai'] = 0xF891;
  7353. t['maitrithai'] = 0x0E4A;
  7354. t['maitriupperleftthai'] = 0xF890;
  7355. t['maiyamokthai'] = 0x0E46;
  7356. t['makatakana'] = 0x30DE;
  7357. t['makatakanahalfwidth'] = 0xFF8F;
  7358. t['male'] = 0x2642;
  7359. t['mansyonsquare'] = 0x3347;
  7360. t['maqafhebrew'] = 0x05BE;
  7361. t['mars'] = 0x2642;
  7362. t['masoracirclehebrew'] = 0x05AF;
  7363. t['masquare'] = 0x3383;
  7364. t['mbopomofo'] = 0x3107;
  7365. t['mbsquare'] = 0x33D4;
  7366. t['mcircle'] = 0x24DC;
  7367. t['mcubedsquare'] = 0x33A5;
  7368. t['mdotaccent'] = 0x1E41;
  7369. t['mdotbelow'] = 0x1E43;
  7370. t['meemarabic'] = 0x0645;
  7371. t['meemfinalarabic'] = 0xFEE2;
  7372. t['meeminitialarabic'] = 0xFEE3;
  7373. t['meemmedialarabic'] = 0xFEE4;
  7374. t['meemmeeminitialarabic'] = 0xFCD1;
  7375. t['meemmeemisolatedarabic'] = 0xFC48;
  7376. t['meetorusquare'] = 0x334D;
  7377. t['mehiragana'] = 0x3081;
  7378. t['meizierasquare'] = 0x337E;
  7379. t['mekatakana'] = 0x30E1;
  7380. t['mekatakanahalfwidth'] = 0xFF92;
  7381. t['mem'] = 0x05DE;
  7382. t['memdagesh'] = 0xFB3E;
  7383. t['memdageshhebrew'] = 0xFB3E;
  7384. t['memhebrew'] = 0x05DE;
  7385. t['menarmenian'] = 0x0574;
  7386. t['merkhahebrew'] = 0x05A5;
  7387. t['merkhakefulahebrew'] = 0x05A6;
  7388. t['merkhakefulalefthebrew'] = 0x05A6;
  7389. t['merkhalefthebrew'] = 0x05A5;
  7390. t['mhook'] = 0x0271;
  7391. t['mhzsquare'] = 0x3392;
  7392. t['middledotkatakanahalfwidth'] = 0xFF65;
  7393. t['middot'] = 0x00B7;
  7394. t['mieumacirclekorean'] = 0x3272;
  7395. t['mieumaparenkorean'] = 0x3212;
  7396. t['mieumcirclekorean'] = 0x3264;
  7397. t['mieumkorean'] = 0x3141;
  7398. t['mieumpansioskorean'] = 0x3170;
  7399. t['mieumparenkorean'] = 0x3204;
  7400. t['mieumpieupkorean'] = 0x316E;
  7401. t['mieumsioskorean'] = 0x316F;
  7402. t['mihiragana'] = 0x307F;
  7403. t['mikatakana'] = 0x30DF;
  7404. t['mikatakanahalfwidth'] = 0xFF90;
  7405. t['minus'] = 0x2212;
  7406. t['minusbelowcmb'] = 0x0320;
  7407. t['minuscircle'] = 0x2296;
  7408. t['minusmod'] = 0x02D7;
  7409. t['minusplus'] = 0x2213;
  7410. t['minute'] = 0x2032;
  7411. t['miribaarusquare'] = 0x334A;
  7412. t['mirisquare'] = 0x3349;
  7413. t['mlonglegturned'] = 0x0270;
  7414. t['mlsquare'] = 0x3396;
  7415. t['mmcubedsquare'] = 0x33A3;
  7416. t['mmonospace'] = 0xFF4D;
  7417. t['mmsquaredsquare'] = 0x339F;
  7418. t['mohiragana'] = 0x3082;
  7419. t['mohmsquare'] = 0x33C1;
  7420. t['mokatakana'] = 0x30E2;
  7421. t['mokatakanahalfwidth'] = 0xFF93;
  7422. t['molsquare'] = 0x33D6;
  7423. t['momathai'] = 0x0E21;
  7424. t['moverssquare'] = 0x33A7;
  7425. t['moverssquaredsquare'] = 0x33A8;
  7426. t['mparen'] = 0x24A8;
  7427. t['mpasquare'] = 0x33AB;
  7428. t['mssquare'] = 0x33B3;
  7429. t['msuperior'] = 0xF6EF;
  7430. t['mturned'] = 0x026F;
  7431. t['mu'] = 0x00B5;
  7432. t['mu1'] = 0x00B5;
  7433. t['muasquare'] = 0x3382;
  7434. t['muchgreater'] = 0x226B;
  7435. t['muchless'] = 0x226A;
  7436. t['mufsquare'] = 0x338C;
  7437. t['mugreek'] = 0x03BC;
  7438. t['mugsquare'] = 0x338D;
  7439. t['muhiragana'] = 0x3080;
  7440. t['mukatakana'] = 0x30E0;
  7441. t['mukatakanahalfwidth'] = 0xFF91;
  7442. t['mulsquare'] = 0x3395;
  7443. t['multiply'] = 0x00D7;
  7444. t['mumsquare'] = 0x339B;
  7445. t['munahhebrew'] = 0x05A3;
  7446. t['munahlefthebrew'] = 0x05A3;
  7447. t['musicalnote'] = 0x266A;
  7448. t['musicalnotedbl'] = 0x266B;
  7449. t['musicflatsign'] = 0x266D;
  7450. t['musicsharpsign'] = 0x266F;
  7451. t['mussquare'] = 0x33B2;
  7452. t['muvsquare'] = 0x33B6;
  7453. t['muwsquare'] = 0x33BC;
  7454. t['mvmegasquare'] = 0x33B9;
  7455. t['mvsquare'] = 0x33B7;
  7456. t['mwmegasquare'] = 0x33BF;
  7457. t['mwsquare'] = 0x33BD;
  7458. t['n'] = 0x006E;
  7459. t['nabengali'] = 0x09A8;
  7460. t['nabla'] = 0x2207;
  7461. t['nacute'] = 0x0144;
  7462. t['nadeva'] = 0x0928;
  7463. t['nagujarati'] = 0x0AA8;
  7464. t['nagurmukhi'] = 0x0A28;
  7465. t['nahiragana'] = 0x306A;
  7466. t['nakatakana'] = 0x30CA;
  7467. t['nakatakanahalfwidth'] = 0xFF85;
  7468. t['napostrophe'] = 0x0149;
  7469. t['nasquare'] = 0x3381;
  7470. t['nbopomofo'] = 0x310B;
  7471. t['nbspace'] = 0x00A0;
  7472. t['ncaron'] = 0x0148;
  7473. t['ncedilla'] = 0x0146;
  7474. t['ncircle'] = 0x24DD;
  7475. t['ncircumflexbelow'] = 0x1E4B;
  7476. t['ncommaaccent'] = 0x0146;
  7477. t['ndotaccent'] = 0x1E45;
  7478. t['ndotbelow'] = 0x1E47;
  7479. t['nehiragana'] = 0x306D;
  7480. t['nekatakana'] = 0x30CD;
  7481. t['nekatakanahalfwidth'] = 0xFF88;
  7482. t['newsheqelsign'] = 0x20AA;
  7483. t['nfsquare'] = 0x338B;
  7484. t['ngabengali'] = 0x0999;
  7485. t['ngadeva'] = 0x0919;
  7486. t['ngagujarati'] = 0x0A99;
  7487. t['ngagurmukhi'] = 0x0A19;
  7488. t['ngonguthai'] = 0x0E07;
  7489. t['nhiragana'] = 0x3093;
  7490. t['nhookleft'] = 0x0272;
  7491. t['nhookretroflex'] = 0x0273;
  7492. t['nieunacirclekorean'] = 0x326F;
  7493. t['nieunaparenkorean'] = 0x320F;
  7494. t['nieuncieuckorean'] = 0x3135;
  7495. t['nieuncirclekorean'] = 0x3261;
  7496. t['nieunhieuhkorean'] = 0x3136;
  7497. t['nieunkorean'] = 0x3134;
  7498. t['nieunpansioskorean'] = 0x3168;
  7499. t['nieunparenkorean'] = 0x3201;
  7500. t['nieunsioskorean'] = 0x3167;
  7501. t['nieuntikeutkorean'] = 0x3166;
  7502. t['nihiragana'] = 0x306B;
  7503. t['nikatakana'] = 0x30CB;
  7504. t['nikatakanahalfwidth'] = 0xFF86;
  7505. t['nikhahitleftthai'] = 0xF899;
  7506. t['nikhahitthai'] = 0x0E4D;
  7507. t['nine'] = 0x0039;
  7508. t['ninearabic'] = 0x0669;
  7509. t['ninebengali'] = 0x09EF;
  7510. t['ninecircle'] = 0x2468;
  7511. t['ninecircleinversesansserif'] = 0x2792;
  7512. t['ninedeva'] = 0x096F;
  7513. t['ninegujarati'] = 0x0AEF;
  7514. t['ninegurmukhi'] = 0x0A6F;
  7515. t['ninehackarabic'] = 0x0669;
  7516. t['ninehangzhou'] = 0x3029;
  7517. t['nineideographicparen'] = 0x3228;
  7518. t['nineinferior'] = 0x2089;
  7519. t['ninemonospace'] = 0xFF19;
  7520. t['nineoldstyle'] = 0xF739;
  7521. t['nineparen'] = 0x247C;
  7522. t['nineperiod'] = 0x2490;
  7523. t['ninepersian'] = 0x06F9;
  7524. t['nineroman'] = 0x2178;
  7525. t['ninesuperior'] = 0x2079;
  7526. t['nineteencircle'] = 0x2472;
  7527. t['nineteenparen'] = 0x2486;
  7528. t['nineteenperiod'] = 0x249A;
  7529. t['ninethai'] = 0x0E59;
  7530. t['nj'] = 0x01CC;
  7531. t['njecyrillic'] = 0x045A;
  7532. t['nkatakana'] = 0x30F3;
  7533. t['nkatakanahalfwidth'] = 0xFF9D;
  7534. t['nlegrightlong'] = 0x019E;
  7535. t['nlinebelow'] = 0x1E49;
  7536. t['nmonospace'] = 0xFF4E;
  7537. t['nmsquare'] = 0x339A;
  7538. t['nnabengali'] = 0x09A3;
  7539. t['nnadeva'] = 0x0923;
  7540. t['nnagujarati'] = 0x0AA3;
  7541. t['nnagurmukhi'] = 0x0A23;
  7542. t['nnnadeva'] = 0x0929;
  7543. t['nohiragana'] = 0x306E;
  7544. t['nokatakana'] = 0x30CE;
  7545. t['nokatakanahalfwidth'] = 0xFF89;
  7546. t['nonbreakingspace'] = 0x00A0;
  7547. t['nonenthai'] = 0x0E13;
  7548. t['nonuthai'] = 0x0E19;
  7549. t['noonarabic'] = 0x0646;
  7550. t['noonfinalarabic'] = 0xFEE6;
  7551. t['noonghunnaarabic'] = 0x06BA;
  7552. t['noonghunnafinalarabic'] = 0xFB9F;
  7553. t['nooninitialarabic'] = 0xFEE7;
  7554. t['noonjeeminitialarabic'] = 0xFCD2;
  7555. t['noonjeemisolatedarabic'] = 0xFC4B;
  7556. t['noonmedialarabic'] = 0xFEE8;
  7557. t['noonmeeminitialarabic'] = 0xFCD5;
  7558. t['noonmeemisolatedarabic'] = 0xFC4E;
  7559. t['noonnoonfinalarabic'] = 0xFC8D;
  7560. t['notcontains'] = 0x220C;
  7561. t['notelement'] = 0x2209;
  7562. t['notelementof'] = 0x2209;
  7563. t['notequal'] = 0x2260;
  7564. t['notgreater'] = 0x226F;
  7565. t['notgreaternorequal'] = 0x2271;
  7566. t['notgreaternorless'] = 0x2279;
  7567. t['notidentical'] = 0x2262;
  7568. t['notless'] = 0x226E;
  7569. t['notlessnorequal'] = 0x2270;
  7570. t['notparallel'] = 0x2226;
  7571. t['notprecedes'] = 0x2280;
  7572. t['notsubset'] = 0x2284;
  7573. t['notsucceeds'] = 0x2281;
  7574. t['notsuperset'] = 0x2285;
  7575. t['nowarmenian'] = 0x0576;
  7576. t['nparen'] = 0x24A9;
  7577. t['nssquare'] = 0x33B1;
  7578. t['nsuperior'] = 0x207F;
  7579. t['ntilde'] = 0x00F1;
  7580. t['nu'] = 0x03BD;
  7581. t['nuhiragana'] = 0x306C;
  7582. t['nukatakana'] = 0x30CC;
  7583. t['nukatakanahalfwidth'] = 0xFF87;
  7584. t['nuktabengali'] = 0x09BC;
  7585. t['nuktadeva'] = 0x093C;
  7586. t['nuktagujarati'] = 0x0ABC;
  7587. t['nuktagurmukhi'] = 0x0A3C;
  7588. t['numbersign'] = 0x0023;
  7589. t['numbersignmonospace'] = 0xFF03;
  7590. t['numbersignsmall'] = 0xFE5F;
  7591. t['numeralsigngreek'] = 0x0374;
  7592. t['numeralsignlowergreek'] = 0x0375;
  7593. t['numero'] = 0x2116;
  7594. t['nun'] = 0x05E0;
  7595. t['nundagesh'] = 0xFB40;
  7596. t['nundageshhebrew'] = 0xFB40;
  7597. t['nunhebrew'] = 0x05E0;
  7598. t['nvsquare'] = 0x33B5;
  7599. t['nwsquare'] = 0x33BB;
  7600. t['nyabengali'] = 0x099E;
  7601. t['nyadeva'] = 0x091E;
  7602. t['nyagujarati'] = 0x0A9E;
  7603. t['nyagurmukhi'] = 0x0A1E;
  7604. t['o'] = 0x006F;
  7605. t['oacute'] = 0x00F3;
  7606. t['oangthai'] = 0x0E2D;
  7607. t['obarred'] = 0x0275;
  7608. t['obarredcyrillic'] = 0x04E9;
  7609. t['obarreddieresiscyrillic'] = 0x04EB;
  7610. t['obengali'] = 0x0993;
  7611. t['obopomofo'] = 0x311B;
  7612. t['obreve'] = 0x014F;
  7613. t['ocandradeva'] = 0x0911;
  7614. t['ocandragujarati'] = 0x0A91;
  7615. t['ocandravowelsigndeva'] = 0x0949;
  7616. t['ocandravowelsigngujarati'] = 0x0AC9;
  7617. t['ocaron'] = 0x01D2;
  7618. t['ocircle'] = 0x24DE;
  7619. t['ocircumflex'] = 0x00F4;
  7620. t['ocircumflexacute'] = 0x1ED1;
  7621. t['ocircumflexdotbelow'] = 0x1ED9;
  7622. t['ocircumflexgrave'] = 0x1ED3;
  7623. t['ocircumflexhookabove'] = 0x1ED5;
  7624. t['ocircumflextilde'] = 0x1ED7;
  7625. t['ocyrillic'] = 0x043E;
  7626. t['odblacute'] = 0x0151;
  7627. t['odblgrave'] = 0x020D;
  7628. t['odeva'] = 0x0913;
  7629. t['odieresis'] = 0x00F6;
  7630. t['odieresiscyrillic'] = 0x04E7;
  7631. t['odotbelow'] = 0x1ECD;
  7632. t['oe'] = 0x0153;
  7633. t['oekorean'] = 0x315A;
  7634. t['ogonek'] = 0x02DB;
  7635. t['ogonekcmb'] = 0x0328;
  7636. t['ograve'] = 0x00F2;
  7637. t['ogujarati'] = 0x0A93;
  7638. t['oharmenian'] = 0x0585;
  7639. t['ohiragana'] = 0x304A;
  7640. t['ohookabove'] = 0x1ECF;
  7641. t['ohorn'] = 0x01A1;
  7642. t['ohornacute'] = 0x1EDB;
  7643. t['ohorndotbelow'] = 0x1EE3;
  7644. t['ohorngrave'] = 0x1EDD;
  7645. t['ohornhookabove'] = 0x1EDF;
  7646. t['ohorntilde'] = 0x1EE1;
  7647. t['ohungarumlaut'] = 0x0151;
  7648. t['oi'] = 0x01A3;
  7649. t['oinvertedbreve'] = 0x020F;
  7650. t['okatakana'] = 0x30AA;
  7651. t['okatakanahalfwidth'] = 0xFF75;
  7652. t['okorean'] = 0x3157;
  7653. t['olehebrew'] = 0x05AB;
  7654. t['omacron'] = 0x014D;
  7655. t['omacronacute'] = 0x1E53;
  7656. t['omacrongrave'] = 0x1E51;
  7657. t['omdeva'] = 0x0950;
  7658. t['omega'] = 0x03C9;
  7659. t['omega1'] = 0x03D6;
  7660. t['omegacyrillic'] = 0x0461;
  7661. t['omegalatinclosed'] = 0x0277;
  7662. t['omegaroundcyrillic'] = 0x047B;
  7663. t['omegatitlocyrillic'] = 0x047D;
  7664. t['omegatonos'] = 0x03CE;
  7665. t['omgujarati'] = 0x0AD0;
  7666. t['omicron'] = 0x03BF;
  7667. t['omicrontonos'] = 0x03CC;
  7668. t['omonospace'] = 0xFF4F;
  7669. t['one'] = 0x0031;
  7670. t['onearabic'] = 0x0661;
  7671. t['onebengali'] = 0x09E7;
  7672. t['onecircle'] = 0x2460;
  7673. t['onecircleinversesansserif'] = 0x278A;
  7674. t['onedeva'] = 0x0967;
  7675. t['onedotenleader'] = 0x2024;
  7676. t['oneeighth'] = 0x215B;
  7677. t['onefitted'] = 0xF6DC;
  7678. t['onegujarati'] = 0x0AE7;
  7679. t['onegurmukhi'] = 0x0A67;
  7680. t['onehackarabic'] = 0x0661;
  7681. t['onehalf'] = 0x00BD;
  7682. t['onehangzhou'] = 0x3021;
  7683. t['oneideographicparen'] = 0x3220;
  7684. t['oneinferior'] = 0x2081;
  7685. t['onemonospace'] = 0xFF11;
  7686. t['onenumeratorbengali'] = 0x09F4;
  7687. t['oneoldstyle'] = 0xF731;
  7688. t['oneparen'] = 0x2474;
  7689. t['oneperiod'] = 0x2488;
  7690. t['onepersian'] = 0x06F1;
  7691. t['onequarter'] = 0x00BC;
  7692. t['oneroman'] = 0x2170;
  7693. t['onesuperior'] = 0x00B9;
  7694. t['onethai'] = 0x0E51;
  7695. t['onethird'] = 0x2153;
  7696. t['oogonek'] = 0x01EB;
  7697. t['oogonekmacron'] = 0x01ED;
  7698. t['oogurmukhi'] = 0x0A13;
  7699. t['oomatragurmukhi'] = 0x0A4B;
  7700. t['oopen'] = 0x0254;
  7701. t['oparen'] = 0x24AA;
  7702. t['openbullet'] = 0x25E6;
  7703. t['option'] = 0x2325;
  7704. t['ordfeminine'] = 0x00AA;
  7705. t['ordmasculine'] = 0x00BA;
  7706. t['orthogonal'] = 0x221F;
  7707. t['oshortdeva'] = 0x0912;
  7708. t['oshortvowelsigndeva'] = 0x094A;
  7709. t['oslash'] = 0x00F8;
  7710. t['oslashacute'] = 0x01FF;
  7711. t['osmallhiragana'] = 0x3049;
  7712. t['osmallkatakana'] = 0x30A9;
  7713. t['osmallkatakanahalfwidth'] = 0xFF6B;
  7714. t['ostrokeacute'] = 0x01FF;
  7715. t['osuperior'] = 0xF6F0;
  7716. t['otcyrillic'] = 0x047F;
  7717. t['otilde'] = 0x00F5;
  7718. t['otildeacute'] = 0x1E4D;
  7719. t['otildedieresis'] = 0x1E4F;
  7720. t['oubopomofo'] = 0x3121;
  7721. t['overline'] = 0x203E;
  7722. t['overlinecenterline'] = 0xFE4A;
  7723. t['overlinecmb'] = 0x0305;
  7724. t['overlinedashed'] = 0xFE49;
  7725. t['overlinedblwavy'] = 0xFE4C;
  7726. t['overlinewavy'] = 0xFE4B;
  7727. t['overscore'] = 0x00AF;
  7728. t['ovowelsignbengali'] = 0x09CB;
  7729. t['ovowelsigndeva'] = 0x094B;
  7730. t['ovowelsigngujarati'] = 0x0ACB;
  7731. t['p'] = 0x0070;
  7732. t['paampssquare'] = 0x3380;
  7733. t['paasentosquare'] = 0x332B;
  7734. t['pabengali'] = 0x09AA;
  7735. t['pacute'] = 0x1E55;
  7736. t['padeva'] = 0x092A;
  7737. t['pagedown'] = 0x21DF;
  7738. t['pageup'] = 0x21DE;
  7739. t['pagujarati'] = 0x0AAA;
  7740. t['pagurmukhi'] = 0x0A2A;
  7741. t['pahiragana'] = 0x3071;
  7742. t['paiyannoithai'] = 0x0E2F;
  7743. t['pakatakana'] = 0x30D1;
  7744. t['palatalizationcyrilliccmb'] = 0x0484;
  7745. t['palochkacyrillic'] = 0x04C0;
  7746. t['pansioskorean'] = 0x317F;
  7747. t['paragraph'] = 0x00B6;
  7748. t['parallel'] = 0x2225;
  7749. t['parenleft'] = 0x0028;
  7750. t['parenleftaltonearabic'] = 0xFD3E;
  7751. t['parenleftbt'] = 0xF8ED;
  7752. t['parenleftex'] = 0xF8EC;
  7753. t['parenleftinferior'] = 0x208D;
  7754. t['parenleftmonospace'] = 0xFF08;
  7755. t['parenleftsmall'] = 0xFE59;
  7756. t['parenleftsuperior'] = 0x207D;
  7757. t['parenlefttp'] = 0xF8EB;
  7758. t['parenleftvertical'] = 0xFE35;
  7759. t['parenright'] = 0x0029;
  7760. t['parenrightaltonearabic'] = 0xFD3F;
  7761. t['parenrightbt'] = 0xF8F8;
  7762. t['parenrightex'] = 0xF8F7;
  7763. t['parenrightinferior'] = 0x208E;
  7764. t['parenrightmonospace'] = 0xFF09;
  7765. t['parenrightsmall'] = 0xFE5A;
  7766. t['parenrightsuperior'] = 0x207E;
  7767. t['parenrighttp'] = 0xF8F6;
  7768. t['parenrightvertical'] = 0xFE36;
  7769. t['partialdiff'] = 0x2202;
  7770. t['paseqhebrew'] = 0x05C0;
  7771. t['pashtahebrew'] = 0x0599;
  7772. t['pasquare'] = 0x33A9;
  7773. t['patah'] = 0x05B7;
  7774. t['patah11'] = 0x05B7;
  7775. t['patah1d'] = 0x05B7;
  7776. t['patah2a'] = 0x05B7;
  7777. t['patahhebrew'] = 0x05B7;
  7778. t['patahnarrowhebrew'] = 0x05B7;
  7779. t['patahquarterhebrew'] = 0x05B7;
  7780. t['patahwidehebrew'] = 0x05B7;
  7781. t['pazerhebrew'] = 0x05A1;
  7782. t['pbopomofo'] = 0x3106;
  7783. t['pcircle'] = 0x24DF;
  7784. t['pdotaccent'] = 0x1E57;
  7785. t['pe'] = 0x05E4;
  7786. t['pecyrillic'] = 0x043F;
  7787. t['pedagesh'] = 0xFB44;
  7788. t['pedageshhebrew'] = 0xFB44;
  7789. t['peezisquare'] = 0x333B;
  7790. t['pefinaldageshhebrew'] = 0xFB43;
  7791. t['peharabic'] = 0x067E;
  7792. t['peharmenian'] = 0x057A;
  7793. t['pehebrew'] = 0x05E4;
  7794. t['pehfinalarabic'] = 0xFB57;
  7795. t['pehinitialarabic'] = 0xFB58;
  7796. t['pehiragana'] = 0x307A;
  7797. t['pehmedialarabic'] = 0xFB59;
  7798. t['pekatakana'] = 0x30DA;
  7799. t['pemiddlehookcyrillic'] = 0x04A7;
  7800. t['perafehebrew'] = 0xFB4E;
  7801. t['percent'] = 0x0025;
  7802. t['percentarabic'] = 0x066A;
  7803. t['percentmonospace'] = 0xFF05;
  7804. t['percentsmall'] = 0xFE6A;
  7805. t['period'] = 0x002E;
  7806. t['periodarmenian'] = 0x0589;
  7807. t['periodcentered'] = 0x00B7;
  7808. t['periodhalfwidth'] = 0xFF61;
  7809. t['periodinferior'] = 0xF6E7;
  7810. t['periodmonospace'] = 0xFF0E;
  7811. t['periodsmall'] = 0xFE52;
  7812. t['periodsuperior'] = 0xF6E8;
  7813. t['perispomenigreekcmb'] = 0x0342;
  7814. t['perpendicular'] = 0x22A5;
  7815. t['perthousand'] = 0x2030;
  7816. t['peseta'] = 0x20A7;
  7817. t['pfsquare'] = 0x338A;
  7818. t['phabengali'] = 0x09AB;
  7819. t['phadeva'] = 0x092B;
  7820. t['phagujarati'] = 0x0AAB;
  7821. t['phagurmukhi'] = 0x0A2B;
  7822. t['phi'] = 0x03C6;
  7823. t['phi1'] = 0x03D5;
  7824. t['phieuphacirclekorean'] = 0x327A;
  7825. t['phieuphaparenkorean'] = 0x321A;
  7826. t['phieuphcirclekorean'] = 0x326C;
  7827. t['phieuphkorean'] = 0x314D;
  7828. t['phieuphparenkorean'] = 0x320C;
  7829. t['philatin'] = 0x0278;
  7830. t['phinthuthai'] = 0x0E3A;
  7831. t['phisymbolgreek'] = 0x03D5;
  7832. t['phook'] = 0x01A5;
  7833. t['phophanthai'] = 0x0E1E;
  7834. t['phophungthai'] = 0x0E1C;
  7835. t['phosamphaothai'] = 0x0E20;
  7836. t['pi'] = 0x03C0;
  7837. t['pieupacirclekorean'] = 0x3273;
  7838. t['pieupaparenkorean'] = 0x3213;
  7839. t['pieupcieuckorean'] = 0x3176;
  7840. t['pieupcirclekorean'] = 0x3265;
  7841. t['pieupkiyeokkorean'] = 0x3172;
  7842. t['pieupkorean'] = 0x3142;
  7843. t['pieupparenkorean'] = 0x3205;
  7844. t['pieupsioskiyeokkorean'] = 0x3174;
  7845. t['pieupsioskorean'] = 0x3144;
  7846. t['pieupsiostikeutkorean'] = 0x3175;
  7847. t['pieupthieuthkorean'] = 0x3177;
  7848. t['pieuptikeutkorean'] = 0x3173;
  7849. t['pihiragana'] = 0x3074;
  7850. t['pikatakana'] = 0x30D4;
  7851. t['pisymbolgreek'] = 0x03D6;
  7852. t['piwrarmenian'] = 0x0583;
  7853. t['plus'] = 0x002B;
  7854. t['plusbelowcmb'] = 0x031F;
  7855. t['pluscircle'] = 0x2295;
  7856. t['plusminus'] = 0x00B1;
  7857. t['plusmod'] = 0x02D6;
  7858. t['plusmonospace'] = 0xFF0B;
  7859. t['plussmall'] = 0xFE62;
  7860. t['plussuperior'] = 0x207A;
  7861. t['pmonospace'] = 0xFF50;
  7862. t['pmsquare'] = 0x33D8;
  7863. t['pohiragana'] = 0x307D;
  7864. t['pointingindexdownwhite'] = 0x261F;
  7865. t['pointingindexleftwhite'] = 0x261C;
  7866. t['pointingindexrightwhite'] = 0x261E;
  7867. t['pointingindexupwhite'] = 0x261D;
  7868. t['pokatakana'] = 0x30DD;
  7869. t['poplathai'] = 0x0E1B;
  7870. t['postalmark'] = 0x3012;
  7871. t['postalmarkface'] = 0x3020;
  7872. t['pparen'] = 0x24AB;
  7873. t['precedes'] = 0x227A;
  7874. t['prescription'] = 0x211E;
  7875. t['primemod'] = 0x02B9;
  7876. t['primereversed'] = 0x2035;
  7877. t['product'] = 0x220F;
  7878. t['projective'] = 0x2305;
  7879. t['prolongedkana'] = 0x30FC;
  7880. t['propellor'] = 0x2318;
  7881. t['propersubset'] = 0x2282;
  7882. t['propersuperset'] = 0x2283;
  7883. t['proportion'] = 0x2237;
  7884. t['proportional'] = 0x221D;
  7885. t['psi'] = 0x03C8;
  7886. t['psicyrillic'] = 0x0471;
  7887. t['psilipneumatacyrilliccmb'] = 0x0486;
  7888. t['pssquare'] = 0x33B0;
  7889. t['puhiragana'] = 0x3077;
  7890. t['pukatakana'] = 0x30D7;
  7891. t['pvsquare'] = 0x33B4;
  7892. t['pwsquare'] = 0x33BA;
  7893. t['q'] = 0x0071;
  7894. t['qadeva'] = 0x0958;
  7895. t['qadmahebrew'] = 0x05A8;
  7896. t['qafarabic'] = 0x0642;
  7897. t['qaffinalarabic'] = 0xFED6;
  7898. t['qafinitialarabic'] = 0xFED7;
  7899. t['qafmedialarabic'] = 0xFED8;
  7900. t['qamats'] = 0x05B8;
  7901. t['qamats10'] = 0x05B8;
  7902. t['qamats1a'] = 0x05B8;
  7903. t['qamats1c'] = 0x05B8;
  7904. t['qamats27'] = 0x05B8;
  7905. t['qamats29'] = 0x05B8;
  7906. t['qamats33'] = 0x05B8;
  7907. t['qamatsde'] = 0x05B8;
  7908. t['qamatshebrew'] = 0x05B8;
  7909. t['qamatsnarrowhebrew'] = 0x05B8;
  7910. t['qamatsqatanhebrew'] = 0x05B8;
  7911. t['qamatsqatannarrowhebrew'] = 0x05B8;
  7912. t['qamatsqatanquarterhebrew'] = 0x05B8;
  7913. t['qamatsqatanwidehebrew'] = 0x05B8;
  7914. t['qamatsquarterhebrew'] = 0x05B8;
  7915. t['qamatswidehebrew'] = 0x05B8;
  7916. t['qarneyparahebrew'] = 0x059F;
  7917. t['qbopomofo'] = 0x3111;
  7918. t['qcircle'] = 0x24E0;
  7919. t['qhook'] = 0x02A0;
  7920. t['qmonospace'] = 0xFF51;
  7921. t['qof'] = 0x05E7;
  7922. t['qofdagesh'] = 0xFB47;
  7923. t['qofdageshhebrew'] = 0xFB47;
  7924. t['qofhebrew'] = 0x05E7;
  7925. t['qparen'] = 0x24AC;
  7926. t['quarternote'] = 0x2669;
  7927. t['qubuts'] = 0x05BB;
  7928. t['qubuts18'] = 0x05BB;
  7929. t['qubuts25'] = 0x05BB;
  7930. t['qubuts31'] = 0x05BB;
  7931. t['qubutshebrew'] = 0x05BB;
  7932. t['qubutsnarrowhebrew'] = 0x05BB;
  7933. t['qubutsquarterhebrew'] = 0x05BB;
  7934. t['qubutswidehebrew'] = 0x05BB;
  7935. t['question'] = 0x003F;
  7936. t['questionarabic'] = 0x061F;
  7937. t['questionarmenian'] = 0x055E;
  7938. t['questiondown'] = 0x00BF;
  7939. t['questiondownsmall'] = 0xF7BF;
  7940. t['questiongreek'] = 0x037E;
  7941. t['questionmonospace'] = 0xFF1F;
  7942. t['questionsmall'] = 0xF73F;
  7943. t['quotedbl'] = 0x0022;
  7944. t['quotedblbase'] = 0x201E;
  7945. t['quotedblleft'] = 0x201C;
  7946. t['quotedblmonospace'] = 0xFF02;
  7947. t['quotedblprime'] = 0x301E;
  7948. t['quotedblprimereversed'] = 0x301D;
  7949. t['quotedblright'] = 0x201D;
  7950. t['quoteleft'] = 0x2018;
  7951. t['quoteleftreversed'] = 0x201B;
  7952. t['quotereversed'] = 0x201B;
  7953. t['quoteright'] = 0x2019;
  7954. t['quoterightn'] = 0x0149;
  7955. t['quotesinglbase'] = 0x201A;
  7956. t['quotesingle'] = 0x0027;
  7957. t['quotesinglemonospace'] = 0xFF07;
  7958. t['r'] = 0x0072;
  7959. t['raarmenian'] = 0x057C;
  7960. t['rabengali'] = 0x09B0;
  7961. t['racute'] = 0x0155;
  7962. t['radeva'] = 0x0930;
  7963. t['radical'] = 0x221A;
  7964. t['radicalex'] = 0xF8E5;
  7965. t['radoverssquare'] = 0x33AE;
  7966. t['radoverssquaredsquare'] = 0x33AF;
  7967. t['radsquare'] = 0x33AD;
  7968. t['rafe'] = 0x05BF;
  7969. t['rafehebrew'] = 0x05BF;
  7970. t['ragujarati'] = 0x0AB0;
  7971. t['ragurmukhi'] = 0x0A30;
  7972. t['rahiragana'] = 0x3089;
  7973. t['rakatakana'] = 0x30E9;
  7974. t['rakatakanahalfwidth'] = 0xFF97;
  7975. t['ralowerdiagonalbengali'] = 0x09F1;
  7976. t['ramiddlediagonalbengali'] = 0x09F0;
  7977. t['ramshorn'] = 0x0264;
  7978. t['ratio'] = 0x2236;
  7979. t['rbopomofo'] = 0x3116;
  7980. t['rcaron'] = 0x0159;
  7981. t['rcedilla'] = 0x0157;
  7982. t['rcircle'] = 0x24E1;
  7983. t['rcommaaccent'] = 0x0157;
  7984. t['rdblgrave'] = 0x0211;
  7985. t['rdotaccent'] = 0x1E59;
  7986. t['rdotbelow'] = 0x1E5B;
  7987. t['rdotbelowmacron'] = 0x1E5D;
  7988. t['referencemark'] = 0x203B;
  7989. t['reflexsubset'] = 0x2286;
  7990. t['reflexsuperset'] = 0x2287;
  7991. t['registered'] = 0x00AE;
  7992. t['registersans'] = 0xF8E8;
  7993. t['registerserif'] = 0xF6DA;
  7994. t['reharabic'] = 0x0631;
  7995. t['reharmenian'] = 0x0580;
  7996. t['rehfinalarabic'] = 0xFEAE;
  7997. t['rehiragana'] = 0x308C;
  7998. t['rekatakana'] = 0x30EC;
  7999. t['rekatakanahalfwidth'] = 0xFF9A;
  8000. t['resh'] = 0x05E8;
  8001. t['reshdageshhebrew'] = 0xFB48;
  8002. t['reshhebrew'] = 0x05E8;
  8003. t['reversedtilde'] = 0x223D;
  8004. t['reviahebrew'] = 0x0597;
  8005. t['reviamugrashhebrew'] = 0x0597;
  8006. t['revlogicalnot'] = 0x2310;
  8007. t['rfishhook'] = 0x027E;
  8008. t['rfishhookreversed'] = 0x027F;
  8009. t['rhabengali'] = 0x09DD;
  8010. t['rhadeva'] = 0x095D;
  8011. t['rho'] = 0x03C1;
  8012. t['rhook'] = 0x027D;
  8013. t['rhookturned'] = 0x027B;
  8014. t['rhookturnedsuperior'] = 0x02B5;
  8015. t['rhosymbolgreek'] = 0x03F1;
  8016. t['rhotichookmod'] = 0x02DE;
  8017. t['rieulacirclekorean'] = 0x3271;
  8018. t['rieulaparenkorean'] = 0x3211;
  8019. t['rieulcirclekorean'] = 0x3263;
  8020. t['rieulhieuhkorean'] = 0x3140;
  8021. t['rieulkiyeokkorean'] = 0x313A;
  8022. t['rieulkiyeoksioskorean'] = 0x3169;
  8023. t['rieulkorean'] = 0x3139;
  8024. t['rieulmieumkorean'] = 0x313B;
  8025. t['rieulpansioskorean'] = 0x316C;
  8026. t['rieulparenkorean'] = 0x3203;
  8027. t['rieulphieuphkorean'] = 0x313F;
  8028. t['rieulpieupkorean'] = 0x313C;
  8029. t['rieulpieupsioskorean'] = 0x316B;
  8030. t['rieulsioskorean'] = 0x313D;
  8031. t['rieulthieuthkorean'] = 0x313E;
  8032. t['rieultikeutkorean'] = 0x316A;
  8033. t['rieulyeorinhieuhkorean'] = 0x316D;
  8034. t['rightangle'] = 0x221F;
  8035. t['righttackbelowcmb'] = 0x0319;
  8036. t['righttriangle'] = 0x22BF;
  8037. t['rihiragana'] = 0x308A;
  8038. t['rikatakana'] = 0x30EA;
  8039. t['rikatakanahalfwidth'] = 0xFF98;
  8040. t['ring'] = 0x02DA;
  8041. t['ringbelowcmb'] = 0x0325;
  8042. t['ringcmb'] = 0x030A;
  8043. t['ringhalfleft'] = 0x02BF;
  8044. t['ringhalfleftarmenian'] = 0x0559;
  8045. t['ringhalfleftbelowcmb'] = 0x031C;
  8046. t['ringhalfleftcentered'] = 0x02D3;
  8047. t['ringhalfright'] = 0x02BE;
  8048. t['ringhalfrightbelowcmb'] = 0x0339;
  8049. t['ringhalfrightcentered'] = 0x02D2;
  8050. t['rinvertedbreve'] = 0x0213;
  8051. t['rittorusquare'] = 0x3351;
  8052. t['rlinebelow'] = 0x1E5F;
  8053. t['rlongleg'] = 0x027C;
  8054. t['rlonglegturned'] = 0x027A;
  8055. t['rmonospace'] = 0xFF52;
  8056. t['rohiragana'] = 0x308D;
  8057. t['rokatakana'] = 0x30ED;
  8058. t['rokatakanahalfwidth'] = 0xFF9B;
  8059. t['roruathai'] = 0x0E23;
  8060. t['rparen'] = 0x24AD;
  8061. t['rrabengali'] = 0x09DC;
  8062. t['rradeva'] = 0x0931;
  8063. t['rragurmukhi'] = 0x0A5C;
  8064. t['rreharabic'] = 0x0691;
  8065. t['rrehfinalarabic'] = 0xFB8D;
  8066. t['rrvocalicbengali'] = 0x09E0;
  8067. t['rrvocalicdeva'] = 0x0960;
  8068. t['rrvocalicgujarati'] = 0x0AE0;
  8069. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8070. t['rrvocalicvowelsigndeva'] = 0x0944;
  8071. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8072. t['rsuperior'] = 0xF6F1;
  8073. t['rtblock'] = 0x2590;
  8074. t['rturned'] = 0x0279;
  8075. t['rturnedsuperior'] = 0x02B4;
  8076. t['ruhiragana'] = 0x308B;
  8077. t['rukatakana'] = 0x30EB;
  8078. t['rukatakanahalfwidth'] = 0xFF99;
  8079. t['rupeemarkbengali'] = 0x09F2;
  8080. t['rupeesignbengali'] = 0x09F3;
  8081. t['rupiah'] = 0xF6DD;
  8082. t['ruthai'] = 0x0E24;
  8083. t['rvocalicbengali'] = 0x098B;
  8084. t['rvocalicdeva'] = 0x090B;
  8085. t['rvocalicgujarati'] = 0x0A8B;
  8086. t['rvocalicvowelsignbengali'] = 0x09C3;
  8087. t['rvocalicvowelsigndeva'] = 0x0943;
  8088. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8089. t['s'] = 0x0073;
  8090. t['sabengali'] = 0x09B8;
  8091. t['sacute'] = 0x015B;
  8092. t['sacutedotaccent'] = 0x1E65;
  8093. t['sadarabic'] = 0x0635;
  8094. t['sadeva'] = 0x0938;
  8095. t['sadfinalarabic'] = 0xFEBA;
  8096. t['sadinitialarabic'] = 0xFEBB;
  8097. t['sadmedialarabic'] = 0xFEBC;
  8098. t['sagujarati'] = 0x0AB8;
  8099. t['sagurmukhi'] = 0x0A38;
  8100. t['sahiragana'] = 0x3055;
  8101. t['sakatakana'] = 0x30B5;
  8102. t['sakatakanahalfwidth'] = 0xFF7B;
  8103. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8104. t['samekh'] = 0x05E1;
  8105. t['samekhdagesh'] = 0xFB41;
  8106. t['samekhdageshhebrew'] = 0xFB41;
  8107. t['samekhhebrew'] = 0x05E1;
  8108. t['saraaathai'] = 0x0E32;
  8109. t['saraaethai'] = 0x0E41;
  8110. t['saraaimaimalaithai'] = 0x0E44;
  8111. t['saraaimaimuanthai'] = 0x0E43;
  8112. t['saraamthai'] = 0x0E33;
  8113. t['saraathai'] = 0x0E30;
  8114. t['saraethai'] = 0x0E40;
  8115. t['saraiileftthai'] = 0xF886;
  8116. t['saraiithai'] = 0x0E35;
  8117. t['saraileftthai'] = 0xF885;
  8118. t['saraithai'] = 0x0E34;
  8119. t['saraothai'] = 0x0E42;
  8120. t['saraueeleftthai'] = 0xF888;
  8121. t['saraueethai'] = 0x0E37;
  8122. t['saraueleftthai'] = 0xF887;
  8123. t['sarauethai'] = 0x0E36;
  8124. t['sarauthai'] = 0x0E38;
  8125. t['sarauuthai'] = 0x0E39;
  8126. t['sbopomofo'] = 0x3119;
  8127. t['scaron'] = 0x0161;
  8128. t['scarondotaccent'] = 0x1E67;
  8129. t['scedilla'] = 0x015F;
  8130. t['schwa'] = 0x0259;
  8131. t['schwacyrillic'] = 0x04D9;
  8132. t['schwadieresiscyrillic'] = 0x04DB;
  8133. t['schwahook'] = 0x025A;
  8134. t['scircle'] = 0x24E2;
  8135. t['scircumflex'] = 0x015D;
  8136. t['scommaaccent'] = 0x0219;
  8137. t['sdotaccent'] = 0x1E61;
  8138. t['sdotbelow'] = 0x1E63;
  8139. t['sdotbelowdotaccent'] = 0x1E69;
  8140. t['seagullbelowcmb'] = 0x033C;
  8141. t['second'] = 0x2033;
  8142. t['secondtonechinese'] = 0x02CA;
  8143. t['section'] = 0x00A7;
  8144. t['seenarabic'] = 0x0633;
  8145. t['seenfinalarabic'] = 0xFEB2;
  8146. t['seeninitialarabic'] = 0xFEB3;
  8147. t['seenmedialarabic'] = 0xFEB4;
  8148. t['segol'] = 0x05B6;
  8149. t['segol13'] = 0x05B6;
  8150. t['segol1f'] = 0x05B6;
  8151. t['segol2c'] = 0x05B6;
  8152. t['segolhebrew'] = 0x05B6;
  8153. t['segolnarrowhebrew'] = 0x05B6;
  8154. t['segolquarterhebrew'] = 0x05B6;
  8155. t['segoltahebrew'] = 0x0592;
  8156. t['segolwidehebrew'] = 0x05B6;
  8157. t['seharmenian'] = 0x057D;
  8158. t['sehiragana'] = 0x305B;
  8159. t['sekatakana'] = 0x30BB;
  8160. t['sekatakanahalfwidth'] = 0xFF7E;
  8161. t['semicolon'] = 0x003B;
  8162. t['semicolonarabic'] = 0x061B;
  8163. t['semicolonmonospace'] = 0xFF1B;
  8164. t['semicolonsmall'] = 0xFE54;
  8165. t['semivoicedmarkkana'] = 0x309C;
  8166. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8167. t['sentisquare'] = 0x3322;
  8168. t['sentosquare'] = 0x3323;
  8169. t['seven'] = 0x0037;
  8170. t['sevenarabic'] = 0x0667;
  8171. t['sevenbengali'] = 0x09ED;
  8172. t['sevencircle'] = 0x2466;
  8173. t['sevencircleinversesansserif'] = 0x2790;
  8174. t['sevendeva'] = 0x096D;
  8175. t['seveneighths'] = 0x215E;
  8176. t['sevengujarati'] = 0x0AED;
  8177. t['sevengurmukhi'] = 0x0A6D;
  8178. t['sevenhackarabic'] = 0x0667;
  8179. t['sevenhangzhou'] = 0x3027;
  8180. t['sevenideographicparen'] = 0x3226;
  8181. t['seveninferior'] = 0x2087;
  8182. t['sevenmonospace'] = 0xFF17;
  8183. t['sevenoldstyle'] = 0xF737;
  8184. t['sevenparen'] = 0x247A;
  8185. t['sevenperiod'] = 0x248E;
  8186. t['sevenpersian'] = 0x06F7;
  8187. t['sevenroman'] = 0x2176;
  8188. t['sevensuperior'] = 0x2077;
  8189. t['seventeencircle'] = 0x2470;
  8190. t['seventeenparen'] = 0x2484;
  8191. t['seventeenperiod'] = 0x2498;
  8192. t['seventhai'] = 0x0E57;
  8193. t['sfthyphen'] = 0x00AD;
  8194. t['shaarmenian'] = 0x0577;
  8195. t['shabengali'] = 0x09B6;
  8196. t['shacyrillic'] = 0x0448;
  8197. t['shaddaarabic'] = 0x0651;
  8198. t['shaddadammaarabic'] = 0xFC61;
  8199. t['shaddadammatanarabic'] = 0xFC5E;
  8200. t['shaddafathaarabic'] = 0xFC60;
  8201. t['shaddakasraarabic'] = 0xFC62;
  8202. t['shaddakasratanarabic'] = 0xFC5F;
  8203. t['shade'] = 0x2592;
  8204. t['shadedark'] = 0x2593;
  8205. t['shadelight'] = 0x2591;
  8206. t['shademedium'] = 0x2592;
  8207. t['shadeva'] = 0x0936;
  8208. t['shagujarati'] = 0x0AB6;
  8209. t['shagurmukhi'] = 0x0A36;
  8210. t['shalshelethebrew'] = 0x0593;
  8211. t['shbopomofo'] = 0x3115;
  8212. t['shchacyrillic'] = 0x0449;
  8213. t['sheenarabic'] = 0x0634;
  8214. t['sheenfinalarabic'] = 0xFEB6;
  8215. t['sheeninitialarabic'] = 0xFEB7;
  8216. t['sheenmedialarabic'] = 0xFEB8;
  8217. t['sheicoptic'] = 0x03E3;
  8218. t['sheqel'] = 0x20AA;
  8219. t['sheqelhebrew'] = 0x20AA;
  8220. t['sheva'] = 0x05B0;
  8221. t['sheva115'] = 0x05B0;
  8222. t['sheva15'] = 0x05B0;
  8223. t['sheva22'] = 0x05B0;
  8224. t['sheva2e'] = 0x05B0;
  8225. t['shevahebrew'] = 0x05B0;
  8226. t['shevanarrowhebrew'] = 0x05B0;
  8227. t['shevaquarterhebrew'] = 0x05B0;
  8228. t['shevawidehebrew'] = 0x05B0;
  8229. t['shhacyrillic'] = 0x04BB;
  8230. t['shimacoptic'] = 0x03ED;
  8231. t['shin'] = 0x05E9;
  8232. t['shindagesh'] = 0xFB49;
  8233. t['shindageshhebrew'] = 0xFB49;
  8234. t['shindageshshindot'] = 0xFB2C;
  8235. t['shindageshshindothebrew'] = 0xFB2C;
  8236. t['shindageshsindot'] = 0xFB2D;
  8237. t['shindageshsindothebrew'] = 0xFB2D;
  8238. t['shindothebrew'] = 0x05C1;
  8239. t['shinhebrew'] = 0x05E9;
  8240. t['shinshindot'] = 0xFB2A;
  8241. t['shinshindothebrew'] = 0xFB2A;
  8242. t['shinsindot'] = 0xFB2B;
  8243. t['shinsindothebrew'] = 0xFB2B;
  8244. t['shook'] = 0x0282;
  8245. t['sigma'] = 0x03C3;
  8246. t['sigma1'] = 0x03C2;
  8247. t['sigmafinal'] = 0x03C2;
  8248. t['sigmalunatesymbolgreek'] = 0x03F2;
  8249. t['sihiragana'] = 0x3057;
  8250. t['sikatakana'] = 0x30B7;
  8251. t['sikatakanahalfwidth'] = 0xFF7C;
  8252. t['siluqhebrew'] = 0x05BD;
  8253. t['siluqlefthebrew'] = 0x05BD;
  8254. t['similar'] = 0x223C;
  8255. t['sindothebrew'] = 0x05C2;
  8256. t['siosacirclekorean'] = 0x3274;
  8257. t['siosaparenkorean'] = 0x3214;
  8258. t['sioscieuckorean'] = 0x317E;
  8259. t['sioscirclekorean'] = 0x3266;
  8260. t['sioskiyeokkorean'] = 0x317A;
  8261. t['sioskorean'] = 0x3145;
  8262. t['siosnieunkorean'] = 0x317B;
  8263. t['siosparenkorean'] = 0x3206;
  8264. t['siospieupkorean'] = 0x317D;
  8265. t['siostikeutkorean'] = 0x317C;
  8266. t['six'] = 0x0036;
  8267. t['sixarabic'] = 0x0666;
  8268. t['sixbengali'] = 0x09EC;
  8269. t['sixcircle'] = 0x2465;
  8270. t['sixcircleinversesansserif'] = 0x278F;
  8271. t['sixdeva'] = 0x096C;
  8272. t['sixgujarati'] = 0x0AEC;
  8273. t['sixgurmukhi'] = 0x0A6C;
  8274. t['sixhackarabic'] = 0x0666;
  8275. t['sixhangzhou'] = 0x3026;
  8276. t['sixideographicparen'] = 0x3225;
  8277. t['sixinferior'] = 0x2086;
  8278. t['sixmonospace'] = 0xFF16;
  8279. t['sixoldstyle'] = 0xF736;
  8280. t['sixparen'] = 0x2479;
  8281. t['sixperiod'] = 0x248D;
  8282. t['sixpersian'] = 0x06F6;
  8283. t['sixroman'] = 0x2175;
  8284. t['sixsuperior'] = 0x2076;
  8285. t['sixteencircle'] = 0x246F;
  8286. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8287. t['sixteenparen'] = 0x2483;
  8288. t['sixteenperiod'] = 0x2497;
  8289. t['sixthai'] = 0x0E56;
  8290. t['slash'] = 0x002F;
  8291. t['slashmonospace'] = 0xFF0F;
  8292. t['slong'] = 0x017F;
  8293. t['slongdotaccent'] = 0x1E9B;
  8294. t['smileface'] = 0x263A;
  8295. t['smonospace'] = 0xFF53;
  8296. t['sofpasuqhebrew'] = 0x05C3;
  8297. t['softhyphen'] = 0x00AD;
  8298. t['softsigncyrillic'] = 0x044C;
  8299. t['sohiragana'] = 0x305D;
  8300. t['sokatakana'] = 0x30BD;
  8301. t['sokatakanahalfwidth'] = 0xFF7F;
  8302. t['soliduslongoverlaycmb'] = 0x0338;
  8303. t['solidusshortoverlaycmb'] = 0x0337;
  8304. t['sorusithai'] = 0x0E29;
  8305. t['sosalathai'] = 0x0E28;
  8306. t['sosothai'] = 0x0E0B;
  8307. t['sosuathai'] = 0x0E2A;
  8308. t['space'] = 0x0020;
  8309. t['spacehackarabic'] = 0x0020;
  8310. t['spade'] = 0x2660;
  8311. t['spadesuitblack'] = 0x2660;
  8312. t['spadesuitwhite'] = 0x2664;
  8313. t['sparen'] = 0x24AE;
  8314. t['squarebelowcmb'] = 0x033B;
  8315. t['squarecc'] = 0x33C4;
  8316. t['squarecm'] = 0x339D;
  8317. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8318. t['squarehorizontalfill'] = 0x25A4;
  8319. t['squarekg'] = 0x338F;
  8320. t['squarekm'] = 0x339E;
  8321. t['squarekmcapital'] = 0x33CE;
  8322. t['squareln'] = 0x33D1;
  8323. t['squarelog'] = 0x33D2;
  8324. t['squaremg'] = 0x338E;
  8325. t['squaremil'] = 0x33D5;
  8326. t['squaremm'] = 0x339C;
  8327. t['squaremsquared'] = 0x33A1;
  8328. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8329. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8330. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8331. t['squareverticalfill'] = 0x25A5;
  8332. t['squarewhitewithsmallblack'] = 0x25A3;
  8333. t['srsquare'] = 0x33DB;
  8334. t['ssabengali'] = 0x09B7;
  8335. t['ssadeva'] = 0x0937;
  8336. t['ssagujarati'] = 0x0AB7;
  8337. t['ssangcieuckorean'] = 0x3149;
  8338. t['ssanghieuhkorean'] = 0x3185;
  8339. t['ssangieungkorean'] = 0x3180;
  8340. t['ssangkiyeokkorean'] = 0x3132;
  8341. t['ssangnieunkorean'] = 0x3165;
  8342. t['ssangpieupkorean'] = 0x3143;
  8343. t['ssangsioskorean'] = 0x3146;
  8344. t['ssangtikeutkorean'] = 0x3138;
  8345. t['ssuperior'] = 0xF6F2;
  8346. t['sterling'] = 0x00A3;
  8347. t['sterlingmonospace'] = 0xFFE1;
  8348. t['strokelongoverlaycmb'] = 0x0336;
  8349. t['strokeshortoverlaycmb'] = 0x0335;
  8350. t['subset'] = 0x2282;
  8351. t['subsetnotequal'] = 0x228A;
  8352. t['subsetorequal'] = 0x2286;
  8353. t['succeeds'] = 0x227B;
  8354. t['suchthat'] = 0x220B;
  8355. t['suhiragana'] = 0x3059;
  8356. t['sukatakana'] = 0x30B9;
  8357. t['sukatakanahalfwidth'] = 0xFF7D;
  8358. t['sukunarabic'] = 0x0652;
  8359. t['summation'] = 0x2211;
  8360. t['sun'] = 0x263C;
  8361. t['superset'] = 0x2283;
  8362. t['supersetnotequal'] = 0x228B;
  8363. t['supersetorequal'] = 0x2287;
  8364. t['svsquare'] = 0x33DC;
  8365. t['syouwaerasquare'] = 0x337C;
  8366. t['t'] = 0x0074;
  8367. t['tabengali'] = 0x09A4;
  8368. t['tackdown'] = 0x22A4;
  8369. t['tackleft'] = 0x22A3;
  8370. t['tadeva'] = 0x0924;
  8371. t['tagujarati'] = 0x0AA4;
  8372. t['tagurmukhi'] = 0x0A24;
  8373. t['taharabic'] = 0x0637;
  8374. t['tahfinalarabic'] = 0xFEC2;
  8375. t['tahinitialarabic'] = 0xFEC3;
  8376. t['tahiragana'] = 0x305F;
  8377. t['tahmedialarabic'] = 0xFEC4;
  8378. t['taisyouerasquare'] = 0x337D;
  8379. t['takatakana'] = 0x30BF;
  8380. t['takatakanahalfwidth'] = 0xFF80;
  8381. t['tatweelarabic'] = 0x0640;
  8382. t['tau'] = 0x03C4;
  8383. t['tav'] = 0x05EA;
  8384. t['tavdages'] = 0xFB4A;
  8385. t['tavdagesh'] = 0xFB4A;
  8386. t['tavdageshhebrew'] = 0xFB4A;
  8387. t['tavhebrew'] = 0x05EA;
  8388. t['tbar'] = 0x0167;
  8389. t['tbopomofo'] = 0x310A;
  8390. t['tcaron'] = 0x0165;
  8391. t['tccurl'] = 0x02A8;
  8392. t['tcedilla'] = 0x0163;
  8393. t['tcheharabic'] = 0x0686;
  8394. t['tchehfinalarabic'] = 0xFB7B;
  8395. t['tchehinitialarabic'] = 0xFB7C;
  8396. t['tchehmedialarabic'] = 0xFB7D;
  8397. t['tcircle'] = 0x24E3;
  8398. t['tcircumflexbelow'] = 0x1E71;
  8399. t['tcommaaccent'] = 0x0163;
  8400. t['tdieresis'] = 0x1E97;
  8401. t['tdotaccent'] = 0x1E6B;
  8402. t['tdotbelow'] = 0x1E6D;
  8403. t['tecyrillic'] = 0x0442;
  8404. t['tedescendercyrillic'] = 0x04AD;
  8405. t['teharabic'] = 0x062A;
  8406. t['tehfinalarabic'] = 0xFE96;
  8407. t['tehhahinitialarabic'] = 0xFCA2;
  8408. t['tehhahisolatedarabic'] = 0xFC0C;
  8409. t['tehinitialarabic'] = 0xFE97;
  8410. t['tehiragana'] = 0x3066;
  8411. t['tehjeeminitialarabic'] = 0xFCA1;
  8412. t['tehjeemisolatedarabic'] = 0xFC0B;
  8413. t['tehmarbutaarabic'] = 0x0629;
  8414. t['tehmarbutafinalarabic'] = 0xFE94;
  8415. t['tehmedialarabic'] = 0xFE98;
  8416. t['tehmeeminitialarabic'] = 0xFCA4;
  8417. t['tehmeemisolatedarabic'] = 0xFC0E;
  8418. t['tehnoonfinalarabic'] = 0xFC73;
  8419. t['tekatakana'] = 0x30C6;
  8420. t['tekatakanahalfwidth'] = 0xFF83;
  8421. t['telephone'] = 0x2121;
  8422. t['telephoneblack'] = 0x260E;
  8423. t['telishagedolahebrew'] = 0x05A0;
  8424. t['telishaqetanahebrew'] = 0x05A9;
  8425. t['tencircle'] = 0x2469;
  8426. t['tenideographicparen'] = 0x3229;
  8427. t['tenparen'] = 0x247D;
  8428. t['tenperiod'] = 0x2491;
  8429. t['tenroman'] = 0x2179;
  8430. t['tesh'] = 0x02A7;
  8431. t['tet'] = 0x05D8;
  8432. t['tetdagesh'] = 0xFB38;
  8433. t['tetdageshhebrew'] = 0xFB38;
  8434. t['tethebrew'] = 0x05D8;
  8435. t['tetsecyrillic'] = 0x04B5;
  8436. t['tevirhebrew'] = 0x059B;
  8437. t['tevirlefthebrew'] = 0x059B;
  8438. t['thabengali'] = 0x09A5;
  8439. t['thadeva'] = 0x0925;
  8440. t['thagujarati'] = 0x0AA5;
  8441. t['thagurmukhi'] = 0x0A25;
  8442. t['thalarabic'] = 0x0630;
  8443. t['thalfinalarabic'] = 0xFEAC;
  8444. t['thanthakhatlowleftthai'] = 0xF898;
  8445. t['thanthakhatlowrightthai'] = 0xF897;
  8446. t['thanthakhatthai'] = 0x0E4C;
  8447. t['thanthakhatupperleftthai'] = 0xF896;
  8448. t['theharabic'] = 0x062B;
  8449. t['thehfinalarabic'] = 0xFE9A;
  8450. t['thehinitialarabic'] = 0xFE9B;
  8451. t['thehmedialarabic'] = 0xFE9C;
  8452. t['thereexists'] = 0x2203;
  8453. t['therefore'] = 0x2234;
  8454. t['theta'] = 0x03B8;
  8455. t['theta1'] = 0x03D1;
  8456. t['thetasymbolgreek'] = 0x03D1;
  8457. t['thieuthacirclekorean'] = 0x3279;
  8458. t['thieuthaparenkorean'] = 0x3219;
  8459. t['thieuthcirclekorean'] = 0x326B;
  8460. t['thieuthkorean'] = 0x314C;
  8461. t['thieuthparenkorean'] = 0x320B;
  8462. t['thirteencircle'] = 0x246C;
  8463. t['thirteenparen'] = 0x2480;
  8464. t['thirteenperiod'] = 0x2494;
  8465. t['thonangmonthothai'] = 0x0E11;
  8466. t['thook'] = 0x01AD;
  8467. t['thophuthaothai'] = 0x0E12;
  8468. t['thorn'] = 0x00FE;
  8469. t['thothahanthai'] = 0x0E17;
  8470. t['thothanthai'] = 0x0E10;
  8471. t['thothongthai'] = 0x0E18;
  8472. t['thothungthai'] = 0x0E16;
  8473. t['thousandcyrillic'] = 0x0482;
  8474. t['thousandsseparatorarabic'] = 0x066C;
  8475. t['thousandsseparatorpersian'] = 0x066C;
  8476. t['three'] = 0x0033;
  8477. t['threearabic'] = 0x0663;
  8478. t['threebengali'] = 0x09E9;
  8479. t['threecircle'] = 0x2462;
  8480. t['threecircleinversesansserif'] = 0x278C;
  8481. t['threedeva'] = 0x0969;
  8482. t['threeeighths'] = 0x215C;
  8483. t['threegujarati'] = 0x0AE9;
  8484. t['threegurmukhi'] = 0x0A69;
  8485. t['threehackarabic'] = 0x0663;
  8486. t['threehangzhou'] = 0x3023;
  8487. t['threeideographicparen'] = 0x3222;
  8488. t['threeinferior'] = 0x2083;
  8489. t['threemonospace'] = 0xFF13;
  8490. t['threenumeratorbengali'] = 0x09F6;
  8491. t['threeoldstyle'] = 0xF733;
  8492. t['threeparen'] = 0x2476;
  8493. t['threeperiod'] = 0x248A;
  8494. t['threepersian'] = 0x06F3;
  8495. t['threequarters'] = 0x00BE;
  8496. t['threequartersemdash'] = 0xF6DE;
  8497. t['threeroman'] = 0x2172;
  8498. t['threesuperior'] = 0x00B3;
  8499. t['threethai'] = 0x0E53;
  8500. t['thzsquare'] = 0x3394;
  8501. t['tihiragana'] = 0x3061;
  8502. t['tikatakana'] = 0x30C1;
  8503. t['tikatakanahalfwidth'] = 0xFF81;
  8504. t['tikeutacirclekorean'] = 0x3270;
  8505. t['tikeutaparenkorean'] = 0x3210;
  8506. t['tikeutcirclekorean'] = 0x3262;
  8507. t['tikeutkorean'] = 0x3137;
  8508. t['tikeutparenkorean'] = 0x3202;
  8509. t['tilde'] = 0x02DC;
  8510. t['tildebelowcmb'] = 0x0330;
  8511. t['tildecmb'] = 0x0303;
  8512. t['tildecomb'] = 0x0303;
  8513. t['tildedoublecmb'] = 0x0360;
  8514. t['tildeoperator'] = 0x223C;
  8515. t['tildeoverlaycmb'] = 0x0334;
  8516. t['tildeverticalcmb'] = 0x033E;
  8517. t['timescircle'] = 0x2297;
  8518. t['tipehahebrew'] = 0x0596;
  8519. t['tipehalefthebrew'] = 0x0596;
  8520. t['tippigurmukhi'] = 0x0A70;
  8521. t['titlocyrilliccmb'] = 0x0483;
  8522. t['tiwnarmenian'] = 0x057F;
  8523. t['tlinebelow'] = 0x1E6F;
  8524. t['tmonospace'] = 0xFF54;
  8525. t['toarmenian'] = 0x0569;
  8526. t['tohiragana'] = 0x3068;
  8527. t['tokatakana'] = 0x30C8;
  8528. t['tokatakanahalfwidth'] = 0xFF84;
  8529. t['tonebarextrahighmod'] = 0x02E5;
  8530. t['tonebarextralowmod'] = 0x02E9;
  8531. t['tonebarhighmod'] = 0x02E6;
  8532. t['tonebarlowmod'] = 0x02E8;
  8533. t['tonebarmidmod'] = 0x02E7;
  8534. t['tonefive'] = 0x01BD;
  8535. t['tonesix'] = 0x0185;
  8536. t['tonetwo'] = 0x01A8;
  8537. t['tonos'] = 0x0384;
  8538. t['tonsquare'] = 0x3327;
  8539. t['topatakthai'] = 0x0E0F;
  8540. t['tortoiseshellbracketleft'] = 0x3014;
  8541. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8542. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8543. t['tortoiseshellbracketright'] = 0x3015;
  8544. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8545. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8546. t['totaothai'] = 0x0E15;
  8547. t['tpalatalhook'] = 0x01AB;
  8548. t['tparen'] = 0x24AF;
  8549. t['trademark'] = 0x2122;
  8550. t['trademarksans'] = 0xF8EA;
  8551. t['trademarkserif'] = 0xF6DB;
  8552. t['tretroflexhook'] = 0x0288;
  8553. t['triagdn'] = 0x25BC;
  8554. t['triaglf'] = 0x25C4;
  8555. t['triagrt'] = 0x25BA;
  8556. t['triagup'] = 0x25B2;
  8557. t['ts'] = 0x02A6;
  8558. t['tsadi'] = 0x05E6;
  8559. t['tsadidagesh'] = 0xFB46;
  8560. t['tsadidageshhebrew'] = 0xFB46;
  8561. t['tsadihebrew'] = 0x05E6;
  8562. t['tsecyrillic'] = 0x0446;
  8563. t['tsere'] = 0x05B5;
  8564. t['tsere12'] = 0x05B5;
  8565. t['tsere1e'] = 0x05B5;
  8566. t['tsere2b'] = 0x05B5;
  8567. t['tserehebrew'] = 0x05B5;
  8568. t['tserenarrowhebrew'] = 0x05B5;
  8569. t['tserequarterhebrew'] = 0x05B5;
  8570. t['tserewidehebrew'] = 0x05B5;
  8571. t['tshecyrillic'] = 0x045B;
  8572. t['tsuperior'] = 0xF6F3;
  8573. t['ttabengali'] = 0x099F;
  8574. t['ttadeva'] = 0x091F;
  8575. t['ttagujarati'] = 0x0A9F;
  8576. t['ttagurmukhi'] = 0x0A1F;
  8577. t['tteharabic'] = 0x0679;
  8578. t['ttehfinalarabic'] = 0xFB67;
  8579. t['ttehinitialarabic'] = 0xFB68;
  8580. t['ttehmedialarabic'] = 0xFB69;
  8581. t['tthabengali'] = 0x09A0;
  8582. t['tthadeva'] = 0x0920;
  8583. t['tthagujarati'] = 0x0AA0;
  8584. t['tthagurmukhi'] = 0x0A20;
  8585. t['tturned'] = 0x0287;
  8586. t['tuhiragana'] = 0x3064;
  8587. t['tukatakana'] = 0x30C4;
  8588. t['tukatakanahalfwidth'] = 0xFF82;
  8589. t['tusmallhiragana'] = 0x3063;
  8590. t['tusmallkatakana'] = 0x30C3;
  8591. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8592. t['twelvecircle'] = 0x246B;
  8593. t['twelveparen'] = 0x247F;
  8594. t['twelveperiod'] = 0x2493;
  8595. t['twelveroman'] = 0x217B;
  8596. t['twentycircle'] = 0x2473;
  8597. t['twentyhangzhou'] = 0x5344;
  8598. t['twentyparen'] = 0x2487;
  8599. t['twentyperiod'] = 0x249B;
  8600. t['two'] = 0x0032;
  8601. t['twoarabic'] = 0x0662;
  8602. t['twobengali'] = 0x09E8;
  8603. t['twocircle'] = 0x2461;
  8604. t['twocircleinversesansserif'] = 0x278B;
  8605. t['twodeva'] = 0x0968;
  8606. t['twodotenleader'] = 0x2025;
  8607. t['twodotleader'] = 0x2025;
  8608. t['twodotleadervertical'] = 0xFE30;
  8609. t['twogujarati'] = 0x0AE8;
  8610. t['twogurmukhi'] = 0x0A68;
  8611. t['twohackarabic'] = 0x0662;
  8612. t['twohangzhou'] = 0x3022;
  8613. t['twoideographicparen'] = 0x3221;
  8614. t['twoinferior'] = 0x2082;
  8615. t['twomonospace'] = 0xFF12;
  8616. t['twonumeratorbengali'] = 0x09F5;
  8617. t['twooldstyle'] = 0xF732;
  8618. t['twoparen'] = 0x2475;
  8619. t['twoperiod'] = 0x2489;
  8620. t['twopersian'] = 0x06F2;
  8621. t['tworoman'] = 0x2171;
  8622. t['twostroke'] = 0x01BB;
  8623. t['twosuperior'] = 0x00B2;
  8624. t['twothai'] = 0x0E52;
  8625. t['twothirds'] = 0x2154;
  8626. t['u'] = 0x0075;
  8627. t['uacute'] = 0x00FA;
  8628. t['ubar'] = 0x0289;
  8629. t['ubengali'] = 0x0989;
  8630. t['ubopomofo'] = 0x3128;
  8631. t['ubreve'] = 0x016D;
  8632. t['ucaron'] = 0x01D4;
  8633. t['ucircle'] = 0x24E4;
  8634. t['ucircumflex'] = 0x00FB;
  8635. t['ucircumflexbelow'] = 0x1E77;
  8636. t['ucyrillic'] = 0x0443;
  8637. t['udattadeva'] = 0x0951;
  8638. t['udblacute'] = 0x0171;
  8639. t['udblgrave'] = 0x0215;
  8640. t['udeva'] = 0x0909;
  8641. t['udieresis'] = 0x00FC;
  8642. t['udieresisacute'] = 0x01D8;
  8643. t['udieresisbelow'] = 0x1E73;
  8644. t['udieresiscaron'] = 0x01DA;
  8645. t['udieresiscyrillic'] = 0x04F1;
  8646. t['udieresisgrave'] = 0x01DC;
  8647. t['udieresismacron'] = 0x01D6;
  8648. t['udotbelow'] = 0x1EE5;
  8649. t['ugrave'] = 0x00F9;
  8650. t['ugujarati'] = 0x0A89;
  8651. t['ugurmukhi'] = 0x0A09;
  8652. t['uhiragana'] = 0x3046;
  8653. t['uhookabove'] = 0x1EE7;
  8654. t['uhorn'] = 0x01B0;
  8655. t['uhornacute'] = 0x1EE9;
  8656. t['uhorndotbelow'] = 0x1EF1;
  8657. t['uhorngrave'] = 0x1EEB;
  8658. t['uhornhookabove'] = 0x1EED;
  8659. t['uhorntilde'] = 0x1EEF;
  8660. t['uhungarumlaut'] = 0x0171;
  8661. t['uhungarumlautcyrillic'] = 0x04F3;
  8662. t['uinvertedbreve'] = 0x0217;
  8663. t['ukatakana'] = 0x30A6;
  8664. t['ukatakanahalfwidth'] = 0xFF73;
  8665. t['ukcyrillic'] = 0x0479;
  8666. t['ukorean'] = 0x315C;
  8667. t['umacron'] = 0x016B;
  8668. t['umacroncyrillic'] = 0x04EF;
  8669. t['umacrondieresis'] = 0x1E7B;
  8670. t['umatragurmukhi'] = 0x0A41;
  8671. t['umonospace'] = 0xFF55;
  8672. t['underscore'] = 0x005F;
  8673. t['underscoredbl'] = 0x2017;
  8674. t['underscoremonospace'] = 0xFF3F;
  8675. t['underscorevertical'] = 0xFE33;
  8676. t['underscorewavy'] = 0xFE4F;
  8677. t['union'] = 0x222A;
  8678. t['universal'] = 0x2200;
  8679. t['uogonek'] = 0x0173;
  8680. t['uparen'] = 0x24B0;
  8681. t['upblock'] = 0x2580;
  8682. t['upperdothebrew'] = 0x05C4;
  8683. t['upsilon'] = 0x03C5;
  8684. t['upsilondieresis'] = 0x03CB;
  8685. t['upsilondieresistonos'] = 0x03B0;
  8686. t['upsilonlatin'] = 0x028A;
  8687. t['upsilontonos'] = 0x03CD;
  8688. t['uptackbelowcmb'] = 0x031D;
  8689. t['uptackmod'] = 0x02D4;
  8690. t['uragurmukhi'] = 0x0A73;
  8691. t['uring'] = 0x016F;
  8692. t['ushortcyrillic'] = 0x045E;
  8693. t['usmallhiragana'] = 0x3045;
  8694. t['usmallkatakana'] = 0x30A5;
  8695. t['usmallkatakanahalfwidth'] = 0xFF69;
  8696. t['ustraightcyrillic'] = 0x04AF;
  8697. t['ustraightstrokecyrillic'] = 0x04B1;
  8698. t['utilde'] = 0x0169;
  8699. t['utildeacute'] = 0x1E79;
  8700. t['utildebelow'] = 0x1E75;
  8701. t['uubengali'] = 0x098A;
  8702. t['uudeva'] = 0x090A;
  8703. t['uugujarati'] = 0x0A8A;
  8704. t['uugurmukhi'] = 0x0A0A;
  8705. t['uumatragurmukhi'] = 0x0A42;
  8706. t['uuvowelsignbengali'] = 0x09C2;
  8707. t['uuvowelsigndeva'] = 0x0942;
  8708. t['uuvowelsigngujarati'] = 0x0AC2;
  8709. t['uvowelsignbengali'] = 0x09C1;
  8710. t['uvowelsigndeva'] = 0x0941;
  8711. t['uvowelsigngujarati'] = 0x0AC1;
  8712. t['v'] = 0x0076;
  8713. t['vadeva'] = 0x0935;
  8714. t['vagujarati'] = 0x0AB5;
  8715. t['vagurmukhi'] = 0x0A35;
  8716. t['vakatakana'] = 0x30F7;
  8717. t['vav'] = 0x05D5;
  8718. t['vavdagesh'] = 0xFB35;
  8719. t['vavdagesh65'] = 0xFB35;
  8720. t['vavdageshhebrew'] = 0xFB35;
  8721. t['vavhebrew'] = 0x05D5;
  8722. t['vavholam'] = 0xFB4B;
  8723. t['vavholamhebrew'] = 0xFB4B;
  8724. t['vavvavhebrew'] = 0x05F0;
  8725. t['vavyodhebrew'] = 0x05F1;
  8726. t['vcircle'] = 0x24E5;
  8727. t['vdotbelow'] = 0x1E7F;
  8728. t['vecyrillic'] = 0x0432;
  8729. t['veharabic'] = 0x06A4;
  8730. t['vehfinalarabic'] = 0xFB6B;
  8731. t['vehinitialarabic'] = 0xFB6C;
  8732. t['vehmedialarabic'] = 0xFB6D;
  8733. t['vekatakana'] = 0x30F9;
  8734. t['venus'] = 0x2640;
  8735. t['verticalbar'] = 0x007C;
  8736. t['verticallineabovecmb'] = 0x030D;
  8737. t['verticallinebelowcmb'] = 0x0329;
  8738. t['verticallinelowmod'] = 0x02CC;
  8739. t['verticallinemod'] = 0x02C8;
  8740. t['vewarmenian'] = 0x057E;
  8741. t['vhook'] = 0x028B;
  8742. t['vikatakana'] = 0x30F8;
  8743. t['viramabengali'] = 0x09CD;
  8744. t['viramadeva'] = 0x094D;
  8745. t['viramagujarati'] = 0x0ACD;
  8746. t['visargabengali'] = 0x0983;
  8747. t['visargadeva'] = 0x0903;
  8748. t['visargagujarati'] = 0x0A83;
  8749. t['vmonospace'] = 0xFF56;
  8750. t['voarmenian'] = 0x0578;
  8751. t['voicediterationhiragana'] = 0x309E;
  8752. t['voicediterationkatakana'] = 0x30FE;
  8753. t['voicedmarkkana'] = 0x309B;
  8754. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  8755. t['vokatakana'] = 0x30FA;
  8756. t['vparen'] = 0x24B1;
  8757. t['vtilde'] = 0x1E7D;
  8758. t['vturned'] = 0x028C;
  8759. t['vuhiragana'] = 0x3094;
  8760. t['vukatakana'] = 0x30F4;
  8761. t['w'] = 0x0077;
  8762. t['wacute'] = 0x1E83;
  8763. t['waekorean'] = 0x3159;
  8764. t['wahiragana'] = 0x308F;
  8765. t['wakatakana'] = 0x30EF;
  8766. t['wakatakanahalfwidth'] = 0xFF9C;
  8767. t['wakorean'] = 0x3158;
  8768. t['wasmallhiragana'] = 0x308E;
  8769. t['wasmallkatakana'] = 0x30EE;
  8770. t['wattosquare'] = 0x3357;
  8771. t['wavedash'] = 0x301C;
  8772. t['wavyunderscorevertical'] = 0xFE34;
  8773. t['wawarabic'] = 0x0648;
  8774. t['wawfinalarabic'] = 0xFEEE;
  8775. t['wawhamzaabovearabic'] = 0x0624;
  8776. t['wawhamzaabovefinalarabic'] = 0xFE86;
  8777. t['wbsquare'] = 0x33DD;
  8778. t['wcircle'] = 0x24E6;
  8779. t['wcircumflex'] = 0x0175;
  8780. t['wdieresis'] = 0x1E85;
  8781. t['wdotaccent'] = 0x1E87;
  8782. t['wdotbelow'] = 0x1E89;
  8783. t['wehiragana'] = 0x3091;
  8784. t['weierstrass'] = 0x2118;
  8785. t['wekatakana'] = 0x30F1;
  8786. t['wekorean'] = 0x315E;
  8787. t['weokorean'] = 0x315D;
  8788. t['wgrave'] = 0x1E81;
  8789. t['whitebullet'] = 0x25E6;
  8790. t['whitecircle'] = 0x25CB;
  8791. t['whitecircleinverse'] = 0x25D9;
  8792. t['whitecornerbracketleft'] = 0x300E;
  8793. t['whitecornerbracketleftvertical'] = 0xFE43;
  8794. t['whitecornerbracketright'] = 0x300F;
  8795. t['whitecornerbracketrightvertical'] = 0xFE44;
  8796. t['whitediamond'] = 0x25C7;
  8797. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  8798. t['whitedownpointingsmalltriangle'] = 0x25BF;
  8799. t['whitedownpointingtriangle'] = 0x25BD;
  8800. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  8801. t['whiteleftpointingtriangle'] = 0x25C1;
  8802. t['whitelenticularbracketleft'] = 0x3016;
  8803. t['whitelenticularbracketright'] = 0x3017;
  8804. t['whiterightpointingsmalltriangle'] = 0x25B9;
  8805. t['whiterightpointingtriangle'] = 0x25B7;
  8806. t['whitesmallsquare'] = 0x25AB;
  8807. t['whitesmilingface'] = 0x263A;
  8808. t['whitesquare'] = 0x25A1;
  8809. t['whitestar'] = 0x2606;
  8810. t['whitetelephone'] = 0x260F;
  8811. t['whitetortoiseshellbracketleft'] = 0x3018;
  8812. t['whitetortoiseshellbracketright'] = 0x3019;
  8813. t['whiteuppointingsmalltriangle'] = 0x25B5;
  8814. t['whiteuppointingtriangle'] = 0x25B3;
  8815. t['wihiragana'] = 0x3090;
  8816. t['wikatakana'] = 0x30F0;
  8817. t['wikorean'] = 0x315F;
  8818. t['wmonospace'] = 0xFF57;
  8819. t['wohiragana'] = 0x3092;
  8820. t['wokatakana'] = 0x30F2;
  8821. t['wokatakanahalfwidth'] = 0xFF66;
  8822. t['won'] = 0x20A9;
  8823. t['wonmonospace'] = 0xFFE6;
  8824. t['wowaenthai'] = 0x0E27;
  8825. t['wparen'] = 0x24B2;
  8826. t['wring'] = 0x1E98;
  8827. t['wsuperior'] = 0x02B7;
  8828. t['wturned'] = 0x028D;
  8829. t['wynn'] = 0x01BF;
  8830. t['x'] = 0x0078;
  8831. t['xabovecmb'] = 0x033D;
  8832. t['xbopomofo'] = 0x3112;
  8833. t['xcircle'] = 0x24E7;
  8834. t['xdieresis'] = 0x1E8D;
  8835. t['xdotaccent'] = 0x1E8B;
  8836. t['xeharmenian'] = 0x056D;
  8837. t['xi'] = 0x03BE;
  8838. t['xmonospace'] = 0xFF58;
  8839. t['xparen'] = 0x24B3;
  8840. t['xsuperior'] = 0x02E3;
  8841. t['y'] = 0x0079;
  8842. t['yaadosquare'] = 0x334E;
  8843. t['yabengali'] = 0x09AF;
  8844. t['yacute'] = 0x00FD;
  8845. t['yadeva'] = 0x092F;
  8846. t['yaekorean'] = 0x3152;
  8847. t['yagujarati'] = 0x0AAF;
  8848. t['yagurmukhi'] = 0x0A2F;
  8849. t['yahiragana'] = 0x3084;
  8850. t['yakatakana'] = 0x30E4;
  8851. t['yakatakanahalfwidth'] = 0xFF94;
  8852. t['yakorean'] = 0x3151;
  8853. t['yamakkanthai'] = 0x0E4E;
  8854. t['yasmallhiragana'] = 0x3083;
  8855. t['yasmallkatakana'] = 0x30E3;
  8856. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  8857. t['yatcyrillic'] = 0x0463;
  8858. t['ycircle'] = 0x24E8;
  8859. t['ycircumflex'] = 0x0177;
  8860. t['ydieresis'] = 0x00FF;
  8861. t['ydotaccent'] = 0x1E8F;
  8862. t['ydotbelow'] = 0x1EF5;
  8863. t['yeharabic'] = 0x064A;
  8864. t['yehbarreearabic'] = 0x06D2;
  8865. t['yehbarreefinalarabic'] = 0xFBAF;
  8866. t['yehfinalarabic'] = 0xFEF2;
  8867. t['yehhamzaabovearabic'] = 0x0626;
  8868. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  8869. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  8870. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  8871. t['yehinitialarabic'] = 0xFEF3;
  8872. t['yehmedialarabic'] = 0xFEF4;
  8873. t['yehmeeminitialarabic'] = 0xFCDD;
  8874. t['yehmeemisolatedarabic'] = 0xFC58;
  8875. t['yehnoonfinalarabic'] = 0xFC94;
  8876. t['yehthreedotsbelowarabic'] = 0x06D1;
  8877. t['yekorean'] = 0x3156;
  8878. t['yen'] = 0x00A5;
  8879. t['yenmonospace'] = 0xFFE5;
  8880. t['yeokorean'] = 0x3155;
  8881. t['yeorinhieuhkorean'] = 0x3186;
  8882. t['yerahbenyomohebrew'] = 0x05AA;
  8883. t['yerahbenyomolefthebrew'] = 0x05AA;
  8884. t['yericyrillic'] = 0x044B;
  8885. t['yerudieresiscyrillic'] = 0x04F9;
  8886. t['yesieungkorean'] = 0x3181;
  8887. t['yesieungpansioskorean'] = 0x3183;
  8888. t['yesieungsioskorean'] = 0x3182;
  8889. t['yetivhebrew'] = 0x059A;
  8890. t['ygrave'] = 0x1EF3;
  8891. t['yhook'] = 0x01B4;
  8892. t['yhookabove'] = 0x1EF7;
  8893. t['yiarmenian'] = 0x0575;
  8894. t['yicyrillic'] = 0x0457;
  8895. t['yikorean'] = 0x3162;
  8896. t['yinyang'] = 0x262F;
  8897. t['yiwnarmenian'] = 0x0582;
  8898. t['ymonospace'] = 0xFF59;
  8899. t['yod'] = 0x05D9;
  8900. t['yoddagesh'] = 0xFB39;
  8901. t['yoddageshhebrew'] = 0xFB39;
  8902. t['yodhebrew'] = 0x05D9;
  8903. t['yodyodhebrew'] = 0x05F2;
  8904. t['yodyodpatahhebrew'] = 0xFB1F;
  8905. t['yohiragana'] = 0x3088;
  8906. t['yoikorean'] = 0x3189;
  8907. t['yokatakana'] = 0x30E8;
  8908. t['yokatakanahalfwidth'] = 0xFF96;
  8909. t['yokorean'] = 0x315B;
  8910. t['yosmallhiragana'] = 0x3087;
  8911. t['yosmallkatakana'] = 0x30E7;
  8912. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  8913. t['yotgreek'] = 0x03F3;
  8914. t['yoyaekorean'] = 0x3188;
  8915. t['yoyakorean'] = 0x3187;
  8916. t['yoyakthai'] = 0x0E22;
  8917. t['yoyingthai'] = 0x0E0D;
  8918. t['yparen'] = 0x24B4;
  8919. t['ypogegrammeni'] = 0x037A;
  8920. t['ypogegrammenigreekcmb'] = 0x0345;
  8921. t['yr'] = 0x01A6;
  8922. t['yring'] = 0x1E99;
  8923. t['ysuperior'] = 0x02B8;
  8924. t['ytilde'] = 0x1EF9;
  8925. t['yturned'] = 0x028E;
  8926. t['yuhiragana'] = 0x3086;
  8927. t['yuikorean'] = 0x318C;
  8928. t['yukatakana'] = 0x30E6;
  8929. t['yukatakanahalfwidth'] = 0xFF95;
  8930. t['yukorean'] = 0x3160;
  8931. t['yusbigcyrillic'] = 0x046B;
  8932. t['yusbigiotifiedcyrillic'] = 0x046D;
  8933. t['yuslittlecyrillic'] = 0x0467;
  8934. t['yuslittleiotifiedcyrillic'] = 0x0469;
  8935. t['yusmallhiragana'] = 0x3085;
  8936. t['yusmallkatakana'] = 0x30E5;
  8937. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  8938. t['yuyekorean'] = 0x318B;
  8939. t['yuyeokorean'] = 0x318A;
  8940. t['yyabengali'] = 0x09DF;
  8941. t['yyadeva'] = 0x095F;
  8942. t['z'] = 0x007A;
  8943. t['zaarmenian'] = 0x0566;
  8944. t['zacute'] = 0x017A;
  8945. t['zadeva'] = 0x095B;
  8946. t['zagurmukhi'] = 0x0A5B;
  8947. t['zaharabic'] = 0x0638;
  8948. t['zahfinalarabic'] = 0xFEC6;
  8949. t['zahinitialarabic'] = 0xFEC7;
  8950. t['zahiragana'] = 0x3056;
  8951. t['zahmedialarabic'] = 0xFEC8;
  8952. t['zainarabic'] = 0x0632;
  8953. t['zainfinalarabic'] = 0xFEB0;
  8954. t['zakatakana'] = 0x30B6;
  8955. t['zaqefgadolhebrew'] = 0x0595;
  8956. t['zaqefqatanhebrew'] = 0x0594;
  8957. t['zarqahebrew'] = 0x0598;
  8958. t['zayin'] = 0x05D6;
  8959. t['zayindagesh'] = 0xFB36;
  8960. t['zayindageshhebrew'] = 0xFB36;
  8961. t['zayinhebrew'] = 0x05D6;
  8962. t['zbopomofo'] = 0x3117;
  8963. t['zcaron'] = 0x017E;
  8964. t['zcircle'] = 0x24E9;
  8965. t['zcircumflex'] = 0x1E91;
  8966. t['zcurl'] = 0x0291;
  8967. t['zdot'] = 0x017C;
  8968. t['zdotaccent'] = 0x017C;
  8969. t['zdotbelow'] = 0x1E93;
  8970. t['zecyrillic'] = 0x0437;
  8971. t['zedescendercyrillic'] = 0x0499;
  8972. t['zedieresiscyrillic'] = 0x04DF;
  8973. t['zehiragana'] = 0x305C;
  8974. t['zekatakana'] = 0x30BC;
  8975. t['zero'] = 0x0030;
  8976. t['zeroarabic'] = 0x0660;
  8977. t['zerobengali'] = 0x09E6;
  8978. t['zerodeva'] = 0x0966;
  8979. t['zerogujarati'] = 0x0AE6;
  8980. t['zerogurmukhi'] = 0x0A66;
  8981. t['zerohackarabic'] = 0x0660;
  8982. t['zeroinferior'] = 0x2080;
  8983. t['zeromonospace'] = 0xFF10;
  8984. t['zerooldstyle'] = 0xF730;
  8985. t['zeropersian'] = 0x06F0;
  8986. t['zerosuperior'] = 0x2070;
  8987. t['zerothai'] = 0x0E50;
  8988. t['zerowidthjoiner'] = 0xFEFF;
  8989. t['zerowidthnonjoiner'] = 0x200C;
  8990. t['zerowidthspace'] = 0x200B;
  8991. t['zeta'] = 0x03B6;
  8992. t['zhbopomofo'] = 0x3113;
  8993. t['zhearmenian'] = 0x056A;
  8994. t['zhebrevecyrillic'] = 0x04C2;
  8995. t['zhecyrillic'] = 0x0436;
  8996. t['zhedescendercyrillic'] = 0x0497;
  8997. t['zhedieresiscyrillic'] = 0x04DD;
  8998. t['zihiragana'] = 0x3058;
  8999. t['zikatakana'] = 0x30B8;
  9000. t['zinorhebrew'] = 0x05AE;
  9001. t['zlinebelow'] = 0x1E95;
  9002. t['zmonospace'] = 0xFF5A;
  9003. t['zohiragana'] = 0x305E;
  9004. t['zokatakana'] = 0x30BE;
  9005. t['zparen'] = 0x24B5;
  9006. t['zretroflexhook'] = 0x0290;
  9007. t['zstroke'] = 0x01B6;
  9008. t['zuhiragana'] = 0x305A;
  9009. t['zukatakana'] = 0x30BA;
  9010. t['.notdef'] = 0x0000;
  9011. });
  9012. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9013. t['space'] = 0x0020;
  9014. t['a1'] = 0x2701;
  9015. t['a2'] = 0x2702;
  9016. t['a202'] = 0x2703;
  9017. t['a3'] = 0x2704;
  9018. t['a4'] = 0x260E;
  9019. t['a5'] = 0x2706;
  9020. t['a119'] = 0x2707;
  9021. t['a118'] = 0x2708;
  9022. t['a117'] = 0x2709;
  9023. t['a11'] = 0x261B;
  9024. t['a12'] = 0x261E;
  9025. t['a13'] = 0x270C;
  9026. t['a14'] = 0x270D;
  9027. t['a15'] = 0x270E;
  9028. t['a16'] = 0x270F;
  9029. t['a105'] = 0x2710;
  9030. t['a17'] = 0x2711;
  9031. t['a18'] = 0x2712;
  9032. t['a19'] = 0x2713;
  9033. t['a20'] = 0x2714;
  9034. t['a21'] = 0x2715;
  9035. t['a22'] = 0x2716;
  9036. t['a23'] = 0x2717;
  9037. t['a24'] = 0x2718;
  9038. t['a25'] = 0x2719;
  9039. t['a26'] = 0x271A;
  9040. t['a27'] = 0x271B;
  9041. t['a28'] = 0x271C;
  9042. t['a6'] = 0x271D;
  9043. t['a7'] = 0x271E;
  9044. t['a8'] = 0x271F;
  9045. t['a9'] = 0x2720;
  9046. t['a10'] = 0x2721;
  9047. t['a29'] = 0x2722;
  9048. t['a30'] = 0x2723;
  9049. t['a31'] = 0x2724;
  9050. t['a32'] = 0x2725;
  9051. t['a33'] = 0x2726;
  9052. t['a34'] = 0x2727;
  9053. t['a35'] = 0x2605;
  9054. t['a36'] = 0x2729;
  9055. t['a37'] = 0x272A;
  9056. t['a38'] = 0x272B;
  9057. t['a39'] = 0x272C;
  9058. t['a40'] = 0x272D;
  9059. t['a41'] = 0x272E;
  9060. t['a42'] = 0x272F;
  9061. t['a43'] = 0x2730;
  9062. t['a44'] = 0x2731;
  9063. t['a45'] = 0x2732;
  9064. t['a46'] = 0x2733;
  9065. t['a47'] = 0x2734;
  9066. t['a48'] = 0x2735;
  9067. t['a49'] = 0x2736;
  9068. t['a50'] = 0x2737;
  9069. t['a51'] = 0x2738;
  9070. t['a52'] = 0x2739;
  9071. t['a53'] = 0x273A;
  9072. t['a54'] = 0x273B;
  9073. t['a55'] = 0x273C;
  9074. t['a56'] = 0x273D;
  9075. t['a57'] = 0x273E;
  9076. t['a58'] = 0x273F;
  9077. t['a59'] = 0x2740;
  9078. t['a60'] = 0x2741;
  9079. t['a61'] = 0x2742;
  9080. t['a62'] = 0x2743;
  9081. t['a63'] = 0x2744;
  9082. t['a64'] = 0x2745;
  9083. t['a65'] = 0x2746;
  9084. t['a66'] = 0x2747;
  9085. t['a67'] = 0x2748;
  9086. t['a68'] = 0x2749;
  9087. t['a69'] = 0x274A;
  9088. t['a70'] = 0x274B;
  9089. t['a71'] = 0x25CF;
  9090. t['a72'] = 0x274D;
  9091. t['a73'] = 0x25A0;
  9092. t['a74'] = 0x274F;
  9093. t['a203'] = 0x2750;
  9094. t['a75'] = 0x2751;
  9095. t['a204'] = 0x2752;
  9096. t['a76'] = 0x25B2;
  9097. t['a77'] = 0x25BC;
  9098. t['a78'] = 0x25C6;
  9099. t['a79'] = 0x2756;
  9100. t['a81'] = 0x25D7;
  9101. t['a82'] = 0x2758;
  9102. t['a83'] = 0x2759;
  9103. t['a84'] = 0x275A;
  9104. t['a97'] = 0x275B;
  9105. t['a98'] = 0x275C;
  9106. t['a99'] = 0x275D;
  9107. t['a100'] = 0x275E;
  9108. t['a101'] = 0x2761;
  9109. t['a102'] = 0x2762;
  9110. t['a103'] = 0x2763;
  9111. t['a104'] = 0x2764;
  9112. t['a106'] = 0x2765;
  9113. t['a107'] = 0x2766;
  9114. t['a108'] = 0x2767;
  9115. t['a112'] = 0x2663;
  9116. t['a111'] = 0x2666;
  9117. t['a110'] = 0x2665;
  9118. t['a109'] = 0x2660;
  9119. t['a120'] = 0x2460;
  9120. t['a121'] = 0x2461;
  9121. t['a122'] = 0x2462;
  9122. t['a123'] = 0x2463;
  9123. t['a124'] = 0x2464;
  9124. t['a125'] = 0x2465;
  9125. t['a126'] = 0x2466;
  9126. t['a127'] = 0x2467;
  9127. t['a128'] = 0x2468;
  9128. t['a129'] = 0x2469;
  9129. t['a130'] = 0x2776;
  9130. t['a131'] = 0x2777;
  9131. t['a132'] = 0x2778;
  9132. t['a133'] = 0x2779;
  9133. t['a134'] = 0x277A;
  9134. t['a135'] = 0x277B;
  9135. t['a136'] = 0x277C;
  9136. t['a137'] = 0x277D;
  9137. t['a138'] = 0x277E;
  9138. t['a139'] = 0x277F;
  9139. t['a140'] = 0x2780;
  9140. t['a141'] = 0x2781;
  9141. t['a142'] = 0x2782;
  9142. t['a143'] = 0x2783;
  9143. t['a144'] = 0x2784;
  9144. t['a145'] = 0x2785;
  9145. t['a146'] = 0x2786;
  9146. t['a147'] = 0x2787;
  9147. t['a148'] = 0x2788;
  9148. t['a149'] = 0x2789;
  9149. t['a150'] = 0x278A;
  9150. t['a151'] = 0x278B;
  9151. t['a152'] = 0x278C;
  9152. t['a153'] = 0x278D;
  9153. t['a154'] = 0x278E;
  9154. t['a155'] = 0x278F;
  9155. t['a156'] = 0x2790;
  9156. t['a157'] = 0x2791;
  9157. t['a158'] = 0x2792;
  9158. t['a159'] = 0x2793;
  9159. t['a160'] = 0x2794;
  9160. t['a161'] = 0x2192;
  9161. t['a163'] = 0x2194;
  9162. t['a164'] = 0x2195;
  9163. t['a196'] = 0x2798;
  9164. t['a165'] = 0x2799;
  9165. t['a192'] = 0x279A;
  9166. t['a166'] = 0x279B;
  9167. t['a167'] = 0x279C;
  9168. t['a168'] = 0x279D;
  9169. t['a169'] = 0x279E;
  9170. t['a170'] = 0x279F;
  9171. t['a171'] = 0x27A0;
  9172. t['a172'] = 0x27A1;
  9173. t['a173'] = 0x27A2;
  9174. t['a162'] = 0x27A3;
  9175. t['a174'] = 0x27A4;
  9176. t['a175'] = 0x27A5;
  9177. t['a176'] = 0x27A6;
  9178. t['a177'] = 0x27A7;
  9179. t['a178'] = 0x27A8;
  9180. t['a179'] = 0x27A9;
  9181. t['a193'] = 0x27AA;
  9182. t['a180'] = 0x27AB;
  9183. t['a199'] = 0x27AC;
  9184. t['a181'] = 0x27AD;
  9185. t['a200'] = 0x27AE;
  9186. t['a182'] = 0x27AF;
  9187. t['a201'] = 0x27B1;
  9188. t['a183'] = 0x27B2;
  9189. t['a184'] = 0x27B3;
  9190. t['a197'] = 0x27B4;
  9191. t['a185'] = 0x27B5;
  9192. t['a194'] = 0x27B6;
  9193. t['a198'] = 0x27B7;
  9194. t['a186'] = 0x27B8;
  9195. t['a195'] = 0x27B9;
  9196. t['a187'] = 0x27BA;
  9197. t['a188'] = 0x27BB;
  9198. t['a189'] = 0x27BC;
  9199. t['a190'] = 0x27BD;
  9200. t['a191'] = 0x27BE;
  9201. t['a89'] = 0x2768; // 0xF8D7
  9202. t['a90'] = 0x2769; // 0xF8D8
  9203. t['a93'] = 0x276A; // 0xF8D9
  9204. t['a94'] = 0x276B; // 0xF8DA
  9205. t['a91'] = 0x276C; // 0xF8DB
  9206. t['a92'] = 0x276D; // 0xF8DC
  9207. t['a205'] = 0x276E; // 0xF8DD
  9208. t['a85'] = 0x276F; // 0xF8DE
  9209. t['a206'] = 0x2770; // 0xF8DF
  9210. t['a86'] = 0x2771; // 0xF8E0
  9211. t['a87'] = 0x2772; // 0xF8E1
  9212. t['a88'] = 0x2773; // 0xF8E2
  9213. t['a95'] = 0x2774; // 0xF8E3
  9214. t['a96'] = 0x2775; // 0xF8E4
  9215. t['.notdef'] = 0x0000;
  9216. });
  9217. exports.getGlyphsUnicode = getGlyphsUnicode;
  9218. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9219. }));
  9220. (function (root, factory) {
  9221. {
  9222. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9223. root.pdfjsCoreArithmeticDecoder);
  9224. }
  9225. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9226. var error = sharedUtil.error;
  9227. var log2 = sharedUtil.log2;
  9228. var readInt8 = sharedUtil.readInt8;
  9229. var readUint16 = sharedUtil.readUint16;
  9230. var readUint32 = sharedUtil.readUint32;
  9231. var shadow = sharedUtil.shadow;
  9232. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9233. var Jbig2Image = (function Jbig2ImageClosure() {
  9234. // Utility data structures
  9235. function ContextCache() {}
  9236. ContextCache.prototype = {
  9237. getContexts: function(id) {
  9238. if (id in this) {
  9239. return this[id];
  9240. }
  9241. return (this[id] = new Int8Array(1 << 16));
  9242. }
  9243. };
  9244. function DecodingContext(data, start, end) {
  9245. this.data = data;
  9246. this.start = start;
  9247. this.end = end;
  9248. }
  9249. DecodingContext.prototype = {
  9250. get decoder() {
  9251. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9252. return shadow(this, 'decoder', decoder);
  9253. },
  9254. get contextCache() {
  9255. var cache = new ContextCache();
  9256. return shadow(this, 'contextCache', cache);
  9257. }
  9258. };
  9259. // Annex A. Arithmetic Integer Decoding Procedure
  9260. // A.2 Procedure for decoding values
  9261. function decodeInteger(contextCache, procedure, decoder) {
  9262. var contexts = contextCache.getContexts(procedure);
  9263. var prev = 1;
  9264. function readBits(length) {
  9265. var v = 0;
  9266. for (var i = 0; i < length; i++) {
  9267. var bit = decoder.readBit(contexts, prev);
  9268. prev = (prev < 256 ? (prev << 1) | bit :
  9269. (((prev << 1) | bit) & 511) | 256);
  9270. v = (v << 1) | bit;
  9271. }
  9272. return v >>> 0;
  9273. }
  9274. var sign = readBits(1);
  9275. var value = readBits(1) ?
  9276. (readBits(1) ?
  9277. (readBits(1) ?
  9278. (readBits(1) ?
  9279. (readBits(1) ?
  9280. (readBits(32) + 4436) :
  9281. readBits(12) + 340) :
  9282. readBits(8) + 84) :
  9283. readBits(6) + 20) :
  9284. readBits(4) + 4) :
  9285. readBits(2);
  9286. return (sign === 0 ? value : (value > 0 ? -value : null));
  9287. }
  9288. // A.3 The IAID decoding procedure
  9289. function decodeIAID(contextCache, decoder, codeLength) {
  9290. var contexts = contextCache.getContexts('IAID');
  9291. var prev = 1;
  9292. for (var i = 0; i < codeLength; i++) {
  9293. var bit = decoder.readBit(contexts, prev);
  9294. prev = (prev << 1) | bit;
  9295. }
  9296. if (codeLength < 31) {
  9297. return prev & ((1 << codeLength) - 1);
  9298. }
  9299. return prev & 0x7FFFFFFF;
  9300. }
  9301. // 7.3 Segment types
  9302. var SegmentTypes = [
  9303. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9304. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9305. null, null, null, null, null, 'patternDictionary', null, null, null,
  9306. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9307. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9308. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9309. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9310. 'IntermediateGenericRefinementRegion', null,
  9311. 'ImmediateGenericRefinementRegion',
  9312. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9313. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9314. 'Tables', null, null, null, null, null, null, null, null,
  9315. 'Extension'
  9316. ];
  9317. var CodingTemplates = [
  9318. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9319. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9320. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9321. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9322. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9323. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9324. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9325. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9326. {x: -1, y: 0}],
  9327. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9328. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9329. ];
  9330. var RefinementTemplates = [
  9331. {
  9332. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9333. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9334. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9335. },
  9336. {
  9337. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9338. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9339. {x: 0, y: 1}, {x: 1, y: 1}]
  9340. }
  9341. ];
  9342. // See 6.2.5.7 Decoding the bitmap.
  9343. var ReusedContexts = [
  9344. 0x9B25, // 10011 0110010 0101
  9345. 0x0795, // 0011 110010 101
  9346. 0x00E5, // 001 11001 01
  9347. 0x0195 // 011001 0101
  9348. ];
  9349. var RefinementReusedContexts = [
  9350. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9351. 0x0008 // '0000' + '001000'
  9352. ];
  9353. function decodeBitmapTemplate0(width, height, decodingContext) {
  9354. var decoder = decodingContext.decoder;
  9355. var contexts = decodingContext.contextCache.getContexts('GB');
  9356. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9357. // ...ooooo....
  9358. // ..ooooooo... Context template for current pixel (X)
  9359. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9360. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9361. for (i = 0; i < height; i++) {
  9362. row = bitmap[i] = new Uint8Array(width);
  9363. row1 = (i < 1) ? row : bitmap[i - 1];
  9364. row2 = (i < 2) ? row : bitmap[i - 2];
  9365. // At the beginning of each row:
  9366. // Fill contextLabel with pixels that are above/right of (X)
  9367. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9368. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9369. (row1[3] << 4);
  9370. for (j = 0; j < width; j++) {
  9371. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9372. // At each pixel: Clear contextLabel pixels that are shifted
  9373. // out of the context, then add new ones.
  9374. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9375. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9376. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9377. }
  9378. }
  9379. return bitmap;
  9380. }
  9381. // 6.2 Generic Region Decoding Procedure
  9382. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9383. decodingContext) {
  9384. if (mmr) {
  9385. error('JBIG2 error: MMR encoding is not supported');
  9386. }
  9387. // Use optimized version for the most common case
  9388. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9389. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9390. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9391. return decodeBitmapTemplate0(width, height, decodingContext);
  9392. }
  9393. var useskip = !!skip;
  9394. var template = CodingTemplates[templateIndex].concat(at);
  9395. // Sorting is non-standard, and it is not required. But sorting increases
  9396. // the number of template bits that can be reused from the previous
  9397. // contextLabel in the main loop.
  9398. template.sort(function (a, b) {
  9399. return (a.y - b.y) || (a.x - b.x);
  9400. });
  9401. var templateLength = template.length;
  9402. var templateX = new Int8Array(templateLength);
  9403. var templateY = new Int8Array(templateLength);
  9404. var changingTemplateEntries = [];
  9405. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9406. var c, k;
  9407. for (k = 0; k < templateLength; k++) {
  9408. templateX[k] = template[k].x;
  9409. templateY[k] = template[k].y;
  9410. minX = Math.min(minX, template[k].x);
  9411. maxX = Math.max(maxX, template[k].x);
  9412. minY = Math.min(minY, template[k].y);
  9413. // Check if the template pixel appears in two consecutive context labels,
  9414. // so it can be reused. Otherwise, we add it to the list of changing
  9415. // template entries.
  9416. if (k < templateLength - 1 &&
  9417. template[k].y === template[k + 1].y &&
  9418. template[k].x === template[k + 1].x - 1) {
  9419. reuseMask |= 1 << (templateLength - 1 - k);
  9420. } else {
  9421. changingTemplateEntries.push(k);
  9422. }
  9423. }
  9424. var changingEntriesLength = changingTemplateEntries.length;
  9425. var changingTemplateX = new Int8Array(changingEntriesLength);
  9426. var changingTemplateY = new Int8Array(changingEntriesLength);
  9427. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9428. for (c = 0; c < changingEntriesLength; c++) {
  9429. k = changingTemplateEntries[c];
  9430. changingTemplateX[c] = template[k].x;
  9431. changingTemplateY[c] = template[k].y;
  9432. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9433. }
  9434. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9435. var sbb_left = -minX;
  9436. var sbb_top = -minY;
  9437. var sbb_right = width - maxX;
  9438. var pseudoPixelContext = ReusedContexts[templateIndex];
  9439. var row = new Uint8Array(width);
  9440. var bitmap = [];
  9441. var decoder = decodingContext.decoder;
  9442. var contexts = decodingContext.contextCache.getContexts('GB');
  9443. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9444. for (var i = 0; i < height; i++) {
  9445. if (prediction) {
  9446. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9447. ltp ^= sltp;
  9448. if (ltp) {
  9449. bitmap.push(row); // duplicate previous row
  9450. continue;
  9451. }
  9452. }
  9453. row = new Uint8Array(row);
  9454. bitmap.push(row);
  9455. for (j = 0; j < width; j++) {
  9456. if (useskip && skip[i][j]) {
  9457. row[j] = 0;
  9458. continue;
  9459. }
  9460. // Are we in the middle of a scanline, so we can reuse contextLabel
  9461. // bits?
  9462. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9463. // If yes, we can just shift the bits that are reusable and only
  9464. // fetch the remaining ones.
  9465. contextLabel = (contextLabel << 1) & reuseMask;
  9466. for (k = 0; k < changingEntriesLength; k++) {
  9467. i0 = i + changingTemplateY[k];
  9468. j0 = j + changingTemplateX[k];
  9469. bit = bitmap[i0][j0];
  9470. if (bit) {
  9471. bit = changingTemplateBit[k];
  9472. contextLabel |= bit;
  9473. }
  9474. }
  9475. } else {
  9476. // compute the contextLabel from scratch
  9477. contextLabel = 0;
  9478. shift = templateLength - 1;
  9479. for (k = 0; k < templateLength; k++, shift--) {
  9480. j0 = j + templateX[k];
  9481. if (j0 >= 0 && j0 < width) {
  9482. i0 = i + templateY[k];
  9483. if (i0 >= 0) {
  9484. bit = bitmap[i0][j0];
  9485. if (bit) {
  9486. contextLabel |= bit << shift;
  9487. }
  9488. }
  9489. }
  9490. }
  9491. }
  9492. var pixel = decoder.readBit(contexts, contextLabel);
  9493. row[j] = pixel;
  9494. }
  9495. }
  9496. return bitmap;
  9497. }
  9498. // 6.3.2 Generic Refinement Region Decoding Procedure
  9499. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9500. offsetX, offsetY, prediction, at,
  9501. decodingContext) {
  9502. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9503. if (templateIndex === 0) {
  9504. codingTemplate = codingTemplate.concat([at[0]]);
  9505. }
  9506. var codingTemplateLength = codingTemplate.length;
  9507. var codingTemplateX = new Int32Array(codingTemplateLength);
  9508. var codingTemplateY = new Int32Array(codingTemplateLength);
  9509. var k;
  9510. for (k = 0; k < codingTemplateLength; k++) {
  9511. codingTemplateX[k] = codingTemplate[k].x;
  9512. codingTemplateY[k] = codingTemplate[k].y;
  9513. }
  9514. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9515. if (templateIndex === 0) {
  9516. referenceTemplate = referenceTemplate.concat([at[1]]);
  9517. }
  9518. var referenceTemplateLength = referenceTemplate.length;
  9519. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9520. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9521. for (k = 0; k < referenceTemplateLength; k++) {
  9522. referenceTemplateX[k] = referenceTemplate[k].x;
  9523. referenceTemplateY[k] = referenceTemplate[k].y;
  9524. }
  9525. var referenceWidth = referenceBitmap[0].length;
  9526. var referenceHeight = referenceBitmap.length;
  9527. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9528. var bitmap = [];
  9529. var decoder = decodingContext.decoder;
  9530. var contexts = decodingContext.contextCache.getContexts('GR');
  9531. var ltp = 0;
  9532. for (var i = 0; i < height; i++) {
  9533. if (prediction) {
  9534. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9535. ltp ^= sltp;
  9536. if (ltp) {
  9537. error('JBIG2 error: prediction is not supported');
  9538. }
  9539. }
  9540. var row = new Uint8Array(width);
  9541. bitmap.push(row);
  9542. for (var j = 0; j < width; j++) {
  9543. var i0, j0;
  9544. var contextLabel = 0;
  9545. for (k = 0; k < codingTemplateLength; k++) {
  9546. i0 = i + codingTemplateY[k];
  9547. j0 = j + codingTemplateX[k];
  9548. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9549. contextLabel <<= 1; // out of bound pixel
  9550. } else {
  9551. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9552. }
  9553. }
  9554. for (k = 0; k < referenceTemplateLength; k++) {
  9555. i0 = i + referenceTemplateY[k] + offsetY;
  9556. j0 = j + referenceTemplateX[k] + offsetX;
  9557. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9558. j0 >= referenceWidth) {
  9559. contextLabel <<= 1; // out of bound pixel
  9560. } else {
  9561. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9562. }
  9563. }
  9564. var pixel = decoder.readBit(contexts, contextLabel);
  9565. row[j] = pixel;
  9566. }
  9567. }
  9568. return bitmap;
  9569. }
  9570. // 6.5.5 Decoding the symbol dictionary
  9571. function decodeSymbolDictionary(huffman, refinement, symbols,
  9572. numberOfNewSymbols, numberOfExportedSymbols,
  9573. huffmanTables, templateIndex, at,
  9574. refinementTemplateIndex, refinementAt,
  9575. decodingContext) {
  9576. if (huffman) {
  9577. error('JBIG2 error: huffman is not supported');
  9578. }
  9579. var newSymbols = [];
  9580. var currentHeight = 0;
  9581. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9582. var decoder = decodingContext.decoder;
  9583. var contextCache = decodingContext.contextCache;
  9584. while (newSymbols.length < numberOfNewSymbols) {
  9585. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9586. currentHeight += deltaHeight;
  9587. var currentWidth = 0;
  9588. var totalWidth = 0;
  9589. while (true) {
  9590. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9591. if (deltaWidth === null) {
  9592. break; // OOB
  9593. }
  9594. currentWidth += deltaWidth;
  9595. totalWidth += currentWidth;
  9596. var bitmap;
  9597. if (refinement) {
  9598. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9599. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9600. if (numberOfInstances > 1) {
  9601. bitmap = decodeTextRegion(huffman, refinement,
  9602. currentWidth, currentHeight, 0,
  9603. numberOfInstances, 1, //strip size
  9604. symbols.concat(newSymbols),
  9605. symbolCodeLength,
  9606. 0, //transposed
  9607. 0, //ds offset
  9608. 1, //top left 7.4.3.1.1
  9609. 0, //OR operator
  9610. huffmanTables,
  9611. refinementTemplateIndex, refinementAt,
  9612. decodingContext);
  9613. } else {
  9614. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9615. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9616. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9617. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9618. newSymbols[symbolId - symbols.length]);
  9619. bitmap = decodeRefinement(currentWidth, currentHeight,
  9620. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9621. decodingContext);
  9622. }
  9623. } else {
  9624. // 6.5.8.1 Direct-coded symbol bitmap
  9625. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  9626. templateIndex, false, null, at, decodingContext);
  9627. }
  9628. newSymbols.push(bitmap);
  9629. }
  9630. }
  9631. // 6.5.10 Exported symbols
  9632. var exportedSymbols = [];
  9633. var flags = [], currentFlag = false;
  9634. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  9635. while (flags.length < totalSymbolsLength) {
  9636. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  9637. while (runLength--) {
  9638. flags.push(currentFlag);
  9639. }
  9640. currentFlag = !currentFlag;
  9641. }
  9642. for (var i = 0, ii = symbols.length; i < ii; i++) {
  9643. if (flags[i]) {
  9644. exportedSymbols.push(symbols[i]);
  9645. }
  9646. }
  9647. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  9648. if (flags[i]) {
  9649. exportedSymbols.push(newSymbols[j]);
  9650. }
  9651. }
  9652. return exportedSymbols;
  9653. }
  9654. function decodeTextRegion(huffman, refinement, width, height,
  9655. defaultPixelValue, numberOfSymbolInstances,
  9656. stripSize, inputSymbols, symbolCodeLength,
  9657. transposed, dsOffset, referenceCorner,
  9658. combinationOperator, huffmanTables,
  9659. refinementTemplateIndex, refinementAt,
  9660. decodingContext) {
  9661. if (huffman) {
  9662. error('JBIG2 error: huffman is not supported');
  9663. }
  9664. // Prepare bitmap
  9665. var bitmap = [];
  9666. var i, row;
  9667. for (i = 0; i < height; i++) {
  9668. row = new Uint8Array(width);
  9669. if (defaultPixelValue) {
  9670. for (var j = 0; j < width; j++) {
  9671. row[j] = defaultPixelValue;
  9672. }
  9673. }
  9674. bitmap.push(row);
  9675. }
  9676. var decoder = decodingContext.decoder;
  9677. var contextCache = decodingContext.contextCache;
  9678. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9679. var firstS = 0;
  9680. i = 0;
  9681. while (i < numberOfSymbolInstances) {
  9682. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9683. stripT += deltaT;
  9684. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  9685. firstS += deltaFirstS;
  9686. var currentS = firstS;
  9687. do {
  9688. var currentT = (stripSize === 1 ? 0 :
  9689. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  9690. var t = stripSize * stripT + currentT;
  9691. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9692. var applyRefinement = (refinement &&
  9693. decodeInteger(contextCache, 'IARI', decoder));
  9694. var symbolBitmap = inputSymbols[symbolId];
  9695. var symbolWidth = symbolBitmap[0].length;
  9696. var symbolHeight = symbolBitmap.length;
  9697. if (applyRefinement) {
  9698. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  9699. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  9700. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9701. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9702. symbolWidth += rdw;
  9703. symbolHeight += rdh;
  9704. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  9705. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  9706. (rdh >> 1) + rdy, false, refinementAt,
  9707. decodingContext);
  9708. }
  9709. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  9710. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  9711. var s2, t2, symbolRow;
  9712. if (transposed) {
  9713. // Place Symbol Bitmap from T1,S1
  9714. for (s2 = 0; s2 < symbolHeight; s2++) {
  9715. row = bitmap[offsetS + s2];
  9716. if (!row) {
  9717. continue;
  9718. }
  9719. symbolRow = symbolBitmap[s2];
  9720. // To ignore Parts of Symbol bitmap which goes
  9721. // outside bitmap region
  9722. var maxWidth = Math.min(width - offsetT, symbolWidth);
  9723. switch (combinationOperator) {
  9724. case 0: // OR
  9725. for (t2 = 0; t2 < maxWidth; t2++) {
  9726. row[offsetT + t2] |= symbolRow[t2];
  9727. }
  9728. break;
  9729. case 2: // XOR
  9730. for (t2 = 0; t2 < maxWidth; t2++) {
  9731. row[offsetT + t2] ^= symbolRow[t2];
  9732. }
  9733. break;
  9734. default:
  9735. error('JBIG2 error: operator ' + combinationOperator +
  9736. ' is not supported');
  9737. }
  9738. }
  9739. currentS += symbolHeight - 1;
  9740. } else {
  9741. for (t2 = 0; t2 < symbolHeight; t2++) {
  9742. row = bitmap[offsetT + t2];
  9743. if (!row) {
  9744. continue;
  9745. }
  9746. symbolRow = symbolBitmap[t2];
  9747. switch (combinationOperator) {
  9748. case 0: // OR
  9749. for (s2 = 0; s2 < symbolWidth; s2++) {
  9750. row[offsetS + s2] |= symbolRow[s2];
  9751. }
  9752. break;
  9753. case 2: // XOR
  9754. for (s2 = 0; s2 < symbolWidth; s2++) {
  9755. row[offsetS + s2] ^= symbolRow[s2];
  9756. }
  9757. break;
  9758. default:
  9759. error('JBIG2 error: operator ' + combinationOperator +
  9760. ' is not supported');
  9761. }
  9762. }
  9763. currentS += symbolWidth - 1;
  9764. }
  9765. i++;
  9766. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  9767. if (deltaS === null) {
  9768. break; // OOB
  9769. }
  9770. currentS += deltaS + dsOffset;
  9771. } while (true);
  9772. }
  9773. return bitmap;
  9774. }
  9775. function readSegmentHeader(data, start) {
  9776. var segmentHeader = {};
  9777. segmentHeader.number = readUint32(data, start);
  9778. var flags = data[start + 4];
  9779. var segmentType = flags & 0x3F;
  9780. if (!SegmentTypes[segmentType]) {
  9781. error('JBIG2 error: invalid segment type: ' + segmentType);
  9782. }
  9783. segmentHeader.type = segmentType;
  9784. segmentHeader.typeName = SegmentTypes[segmentType];
  9785. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  9786. var pageAssociationFieldSize = !!(flags & 0x40);
  9787. var referredFlags = data[start + 5];
  9788. var referredToCount = (referredFlags >> 5) & 7;
  9789. var retainBits = [referredFlags & 31];
  9790. var position = start + 6;
  9791. if (referredFlags === 7) {
  9792. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  9793. position += 3;
  9794. var bytes = (referredToCount + 7) >> 3;
  9795. retainBits[0] = data[position++];
  9796. while (--bytes > 0) {
  9797. retainBits.push(data[position++]);
  9798. }
  9799. } else if (referredFlags === 5 || referredFlags === 6) {
  9800. error('JBIG2 error: invalid referred-to flags');
  9801. }
  9802. segmentHeader.retainBits = retainBits;
  9803. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  9804. (segmentHeader.number <= 65536 ? 2 : 4));
  9805. var referredTo = [];
  9806. var i, ii;
  9807. for (i = 0; i < referredToCount; i++) {
  9808. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  9809. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  9810. readUint32(data, position)));
  9811. referredTo.push(number);
  9812. position += referredToSegmentNumberSize;
  9813. }
  9814. segmentHeader.referredTo = referredTo;
  9815. if (!pageAssociationFieldSize) {
  9816. segmentHeader.pageAssociation = data[position++];
  9817. } else {
  9818. segmentHeader.pageAssociation = readUint32(data, position);
  9819. position += 4;
  9820. }
  9821. segmentHeader.length = readUint32(data, position);
  9822. position += 4;
  9823. if (segmentHeader.length === 0xFFFFFFFF) {
  9824. // 7.2.7 Segment data length, unknown segment length
  9825. if (segmentType === 38) { // ImmediateGenericRegion
  9826. var genericRegionInfo = readRegionSegmentInformation(data, position);
  9827. var genericRegionSegmentFlags = data[position +
  9828. RegionSegmentInformationFieldLength];
  9829. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  9830. // searching for the segment end
  9831. var searchPatternLength = 6;
  9832. var searchPattern = new Uint8Array(searchPatternLength);
  9833. if (!genericRegionMmr) {
  9834. searchPattern[0] = 0xFF;
  9835. searchPattern[1] = 0xAC;
  9836. }
  9837. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  9838. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  9839. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  9840. searchPattern[5] = genericRegionInfo.height & 0xFF;
  9841. for (i = position, ii = data.length; i < ii; i++) {
  9842. var j = 0;
  9843. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  9844. j++;
  9845. }
  9846. if (j === searchPatternLength) {
  9847. segmentHeader.length = i + searchPatternLength;
  9848. break;
  9849. }
  9850. }
  9851. if (segmentHeader.length === 0xFFFFFFFF) {
  9852. error('JBIG2 error: segment end was not found');
  9853. }
  9854. } else {
  9855. error('JBIG2 error: invalid unknown segment length');
  9856. }
  9857. }
  9858. segmentHeader.headerEnd = position;
  9859. return segmentHeader;
  9860. }
  9861. function readSegments(header, data, start, end) {
  9862. var segments = [];
  9863. var position = start;
  9864. while (position < end) {
  9865. var segmentHeader = readSegmentHeader(data, position);
  9866. position = segmentHeader.headerEnd;
  9867. var segment = {
  9868. header: segmentHeader,
  9869. data: data
  9870. };
  9871. if (!header.randomAccess) {
  9872. segment.start = position;
  9873. position += segmentHeader.length;
  9874. segment.end = position;
  9875. }
  9876. segments.push(segment);
  9877. if (segmentHeader.type === 51) {
  9878. break; // end of file is found
  9879. }
  9880. }
  9881. if (header.randomAccess) {
  9882. for (var i = 0, ii = segments.length; i < ii; i++) {
  9883. segments[i].start = position;
  9884. position += segments[i].header.length;
  9885. segments[i].end = position;
  9886. }
  9887. }
  9888. return segments;
  9889. }
  9890. // 7.4.1 Region segment information field
  9891. function readRegionSegmentInformation(data, start) {
  9892. return {
  9893. width: readUint32(data, start),
  9894. height: readUint32(data, start + 4),
  9895. x: readUint32(data, start + 8),
  9896. y: readUint32(data, start + 12),
  9897. combinationOperator: data[start + 16] & 7
  9898. };
  9899. }
  9900. var RegionSegmentInformationFieldLength = 17;
  9901. function processSegment(segment, visitor) {
  9902. var header = segment.header;
  9903. var data = segment.data, position = segment.start, end = segment.end;
  9904. var args, at, i, atLength;
  9905. switch (header.type) {
  9906. case 0: // SymbolDictionary
  9907. // 7.4.2 Symbol dictionary segment syntax
  9908. var dictionary = {};
  9909. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  9910. dictionary.huffman = !!(dictionaryFlags & 1);
  9911. dictionary.refinement = !!(dictionaryFlags & 2);
  9912. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  9913. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  9914. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  9915. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  9916. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  9917. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  9918. dictionary.template = (dictionaryFlags >> 10) & 3;
  9919. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  9920. position += 2;
  9921. if (!dictionary.huffman) {
  9922. atLength = dictionary.template === 0 ? 4 : 1;
  9923. at = [];
  9924. for (i = 0; i < atLength; i++) {
  9925. at.push({
  9926. x: readInt8(data, position),
  9927. y: readInt8(data, position + 1)
  9928. });
  9929. position += 2;
  9930. }
  9931. dictionary.at = at;
  9932. }
  9933. if (dictionary.refinement && !dictionary.refinementTemplate) {
  9934. at = [];
  9935. for (i = 0; i < 2; i++) {
  9936. at.push({
  9937. x: readInt8(data, position),
  9938. y: readInt8(data, position + 1)
  9939. });
  9940. position += 2;
  9941. }
  9942. dictionary.refinementAt = at;
  9943. }
  9944. dictionary.numberOfExportedSymbols = readUint32(data, position);
  9945. position += 4;
  9946. dictionary.numberOfNewSymbols = readUint32(data, position);
  9947. position += 4;
  9948. args = [dictionary, header.number, header.referredTo,
  9949. data, position, end];
  9950. break;
  9951. case 6: // ImmediateTextRegion
  9952. case 7: // ImmediateLosslessTextRegion
  9953. var textRegion = {};
  9954. textRegion.info = readRegionSegmentInformation(data, position);
  9955. position += RegionSegmentInformationFieldLength;
  9956. var textRegionSegmentFlags = readUint16(data, position);
  9957. position += 2;
  9958. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  9959. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  9960. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  9961. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  9962. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  9963. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  9964. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  9965. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  9966. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  9967. if (textRegion.huffman) {
  9968. var textRegionHuffmanFlags = readUint16(data, position);
  9969. position += 2;
  9970. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  9971. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  9972. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  9973. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  9974. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  9975. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  9976. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  9977. textRegion.huffmanRefinementSizeSelector =
  9978. !!(textRegionHuffmanFlags & 14);
  9979. }
  9980. if (textRegion.refinement && !textRegion.refinementTemplate) {
  9981. at = [];
  9982. for (i = 0; i < 2; i++) {
  9983. at.push({
  9984. x: readInt8(data, position),
  9985. y: readInt8(data, position + 1)
  9986. });
  9987. position += 2;
  9988. }
  9989. textRegion.refinementAt = at;
  9990. }
  9991. textRegion.numberOfSymbolInstances = readUint32(data, position);
  9992. position += 4;
  9993. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  9994. if (textRegion.huffman) {
  9995. error('JBIG2 error: huffman is not supported');
  9996. }
  9997. args = [textRegion, header.referredTo, data, position, end];
  9998. break;
  9999. case 38: // ImmediateGenericRegion
  10000. case 39: // ImmediateLosslessGenericRegion
  10001. var genericRegion = {};
  10002. genericRegion.info = readRegionSegmentInformation(data, position);
  10003. position += RegionSegmentInformationFieldLength;
  10004. var genericRegionSegmentFlags = data[position++];
  10005. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  10006. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  10007. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  10008. if (!genericRegion.mmr) {
  10009. atLength = genericRegion.template === 0 ? 4 : 1;
  10010. at = [];
  10011. for (i = 0; i < atLength; i++) {
  10012. at.push({
  10013. x: readInt8(data, position),
  10014. y: readInt8(data, position + 1)
  10015. });
  10016. position += 2;
  10017. }
  10018. genericRegion.at = at;
  10019. }
  10020. args = [genericRegion, data, position, end];
  10021. break;
  10022. case 48: // PageInformation
  10023. var pageInfo = {
  10024. width: readUint32(data, position),
  10025. height: readUint32(data, position + 4),
  10026. resolutionX: readUint32(data, position + 8),
  10027. resolutionY: readUint32(data, position + 12)
  10028. };
  10029. if (pageInfo.height === 0xFFFFFFFF) {
  10030. delete pageInfo.height;
  10031. }
  10032. var pageSegmentFlags = data[position + 16];
  10033. var pageStripingInformation = readUint16(data, position + 17);
  10034. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10035. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10036. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10037. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10038. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10039. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10040. args = [pageInfo];
  10041. break;
  10042. case 49: // EndOfPage
  10043. break;
  10044. case 50: // EndOfStripe
  10045. break;
  10046. case 51: // EndOfFile
  10047. break;
  10048. case 62: // 7.4.15 defines 2 extension types which
  10049. // are comments and can be ignored.
  10050. break;
  10051. default:
  10052. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10053. header.type + ') is not implemented');
  10054. }
  10055. var callbackName = 'on' + header.typeName;
  10056. if (callbackName in visitor) {
  10057. visitor[callbackName].apply(visitor, args);
  10058. }
  10059. }
  10060. function processSegments(segments, visitor) {
  10061. for (var i = 0, ii = segments.length; i < ii; i++) {
  10062. processSegment(segments[i], visitor);
  10063. }
  10064. }
  10065. function parseJbig2(data, start, end) {
  10066. var position = start;
  10067. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10068. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10069. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10070. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10071. error('JBIG2 error: invalid header');
  10072. }
  10073. var header = {};
  10074. position += 8;
  10075. var flags = data[position++];
  10076. header.randomAccess = !(flags & 1);
  10077. if (!(flags & 2)) {
  10078. header.numberOfPages = readUint32(data, position);
  10079. position += 4;
  10080. }
  10081. var segments = readSegments(header, data, position, end);
  10082. error('Not implemented');
  10083. // processSegments(segments, new SimpleSegmentVisitor());
  10084. }
  10085. function parseJbig2Chunks(chunks) {
  10086. var visitor = new SimpleSegmentVisitor();
  10087. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10088. var chunk = chunks[i];
  10089. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10090. processSegments(segments, visitor);
  10091. }
  10092. return visitor.buffer;
  10093. }
  10094. function SimpleSegmentVisitor() {}
  10095. SimpleSegmentVisitor.prototype = {
  10096. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10097. this.currentPageInfo = info;
  10098. var rowSize = (info.width + 7) >> 3;
  10099. var buffer = new Uint8Array(rowSize * info.height);
  10100. // The contents of ArrayBuffers are initialized to 0.
  10101. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10102. if (info.defaultPixelValue) {
  10103. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10104. buffer[i] = 0xFF;
  10105. }
  10106. }
  10107. this.buffer = buffer;
  10108. },
  10109. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10110. var pageInfo = this.currentPageInfo;
  10111. var width = regionInfo.width, height = regionInfo.height;
  10112. var rowSize = (pageInfo.width + 7) >> 3;
  10113. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10114. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10115. var buffer = this.buffer;
  10116. var mask0 = 128 >> (regionInfo.x & 7);
  10117. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10118. var i, j, mask, offset;
  10119. switch (combinationOperator) {
  10120. case 0: // OR
  10121. for (i = 0; i < height; i++) {
  10122. mask = mask0;
  10123. offset = offset0;
  10124. for (j = 0; j < width; j++) {
  10125. if (bitmap[i][j]) {
  10126. buffer[offset] |= mask;
  10127. }
  10128. mask >>= 1;
  10129. if (!mask) {
  10130. mask = 128;
  10131. offset++;
  10132. }
  10133. }
  10134. offset0 += rowSize;
  10135. }
  10136. break;
  10137. case 2: // XOR
  10138. for (i = 0; i < height; i++) {
  10139. mask = mask0;
  10140. offset = offset0;
  10141. for (j = 0; j < width; j++) {
  10142. if (bitmap[i][j]) {
  10143. buffer[offset] ^= mask;
  10144. }
  10145. mask >>= 1;
  10146. if (!mask) {
  10147. mask = 128;
  10148. offset++;
  10149. }
  10150. }
  10151. offset0 += rowSize;
  10152. }
  10153. break;
  10154. default:
  10155. error('JBIG2 error: operator ' + combinationOperator +
  10156. ' is not supported');
  10157. }
  10158. },
  10159. onImmediateGenericRegion:
  10160. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10161. start, end) {
  10162. var regionInfo = region.info;
  10163. var decodingContext = new DecodingContext(data, start, end);
  10164. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10165. region.template, region.prediction, null,
  10166. region.at, decodingContext);
  10167. this.drawBitmap(regionInfo, bitmap);
  10168. },
  10169. onImmediateLosslessGenericRegion:
  10170. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10171. this.onImmediateGenericRegion.apply(this, arguments);
  10172. },
  10173. onSymbolDictionary:
  10174. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10175. currentSegment,
  10176. referredSegments,
  10177. data, start, end) {
  10178. var huffmanTables;
  10179. if (dictionary.huffman) {
  10180. error('JBIG2 error: huffman is not supported');
  10181. }
  10182. // Combines exported symbols from all referred segments
  10183. var symbols = this.symbols;
  10184. if (!symbols) {
  10185. this.symbols = symbols = {};
  10186. }
  10187. var inputSymbols = [];
  10188. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10189. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10190. }
  10191. var decodingContext = new DecodingContext(data, start, end);
  10192. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10193. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10194. dictionary.numberOfExportedSymbols, huffmanTables,
  10195. dictionary.template, dictionary.at,
  10196. dictionary.refinementTemplate, dictionary.refinementAt,
  10197. decodingContext);
  10198. },
  10199. onImmediateTextRegion:
  10200. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10201. referredSegments,
  10202. data, start, end) {
  10203. var regionInfo = region.info;
  10204. var huffmanTables;
  10205. // Combines exported symbols from all referred segments
  10206. var symbols = this.symbols;
  10207. var inputSymbols = [];
  10208. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10209. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10210. }
  10211. var symbolCodeLength = log2(inputSymbols.length);
  10212. var decodingContext = new DecodingContext(data, start, end);
  10213. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10214. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10215. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10216. symbolCodeLength, region.transposed, region.dsOffset,
  10217. region.referenceCorner, region.combinationOperator, huffmanTables,
  10218. region.refinementTemplate, region.refinementAt, decodingContext);
  10219. this.drawBitmap(regionInfo, bitmap);
  10220. },
  10221. onImmediateLosslessTextRegion:
  10222. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10223. this.onImmediateTextRegion.apply(this, arguments);
  10224. }
  10225. };
  10226. function Jbig2Image() {}
  10227. Jbig2Image.prototype = {
  10228. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10229. return parseJbig2Chunks(chunks);
  10230. }
  10231. };
  10232. return Jbig2Image;
  10233. })();
  10234. exports.Jbig2Image = Jbig2Image;
  10235. }));
  10236. (function (root, factory) {
  10237. {
  10238. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  10239. root.pdfjsCoreArithmeticDecoder);
  10240. }
  10241. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10242. var info = sharedUtil.info;
  10243. var log2 = sharedUtil.log2;
  10244. var readUint16 = sharedUtil.readUint16;
  10245. var readUint32 = sharedUtil.readUint32;
  10246. var warn = sharedUtil.warn;
  10247. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10248. var JpxImage = (function JpxImageClosure() {
  10249. // Table E.1
  10250. var SubbandsGainLog2 = {
  10251. 'LL': 0,
  10252. 'LH': 1,
  10253. 'HL': 1,
  10254. 'HH': 2
  10255. };
  10256. function JpxImage() {
  10257. this.failOnCorruptedImage = false;
  10258. }
  10259. JpxImage.prototype = {
  10260. parse: function JpxImage_parse(data) {
  10261. var head = readUint16(data, 0);
  10262. // No box header, immediate start of codestream (SOC)
  10263. if (head === 0xFF4F) {
  10264. this.parseCodestream(data, 0, data.length);
  10265. return;
  10266. }
  10267. var position = 0, length = data.length;
  10268. while (position < length) {
  10269. var headerSize = 8;
  10270. var lbox = readUint32(data, position);
  10271. var tbox = readUint32(data, position + 4);
  10272. position += headerSize;
  10273. if (lbox === 1) {
  10274. // XLBox: read UInt64 according to spec.
  10275. // JavaScript's int precision of 53 bit should be sufficient here.
  10276. lbox = readUint32(data, position) * 4294967296 +
  10277. readUint32(data, position + 4);
  10278. position += 8;
  10279. headerSize += 8;
  10280. }
  10281. if (lbox === 0) {
  10282. lbox = length - position + headerSize;
  10283. }
  10284. if (lbox < headerSize) {
  10285. throw new Error('JPX Error: Invalid box field size');
  10286. }
  10287. var dataLength = lbox - headerSize;
  10288. var jumpDataLength = true;
  10289. switch (tbox) {
  10290. case 0x6A703268: // 'jp2h'
  10291. jumpDataLength = false; // parsing child boxes
  10292. break;
  10293. case 0x636F6C72: // 'colr'
  10294. // Colorspaces are not used, the CS from the PDF is used.
  10295. var method = data[position];
  10296. if (method === 1) {
  10297. // enumerated colorspace
  10298. var colorspace = readUint32(data, position + 3);
  10299. switch (colorspace) {
  10300. case 16: // this indicates a sRGB colorspace
  10301. case 17: // this indicates a grayscale colorspace
  10302. case 18: // this indicates a YUV colorspace
  10303. break;
  10304. default:
  10305. warn('Unknown colorspace ' + colorspace);
  10306. break;
  10307. }
  10308. } else if (method === 2) {
  10309. info('ICC profile not supported');
  10310. }
  10311. break;
  10312. case 0x6A703263: // 'jp2c'
  10313. this.parseCodestream(data, position, position + dataLength);
  10314. break;
  10315. case 0x6A502020: // 'jP\024\024'
  10316. if (0x0d0a870a !== readUint32(data, position)) {
  10317. warn('Invalid JP2 signature');
  10318. }
  10319. break;
  10320. // The following header types are valid but currently not used:
  10321. case 0x6A501A1A: // 'jP\032\032'
  10322. case 0x66747970: // 'ftyp'
  10323. case 0x72726571: // 'rreq'
  10324. case 0x72657320: // 'res '
  10325. case 0x69686472: // 'ihdr'
  10326. break;
  10327. default:
  10328. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  10329. (tbox >> 16) & 0xFF,
  10330. (tbox >> 8) & 0xFF,
  10331. tbox & 0xFF);
  10332. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  10333. break;
  10334. }
  10335. if (jumpDataLength) {
  10336. position += dataLength;
  10337. }
  10338. }
  10339. },
  10340. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  10341. var newByte = stream.getByte();
  10342. while (newByte >= 0) {
  10343. var oldByte = newByte;
  10344. newByte = stream.getByte();
  10345. var code = (oldByte << 8) | newByte;
  10346. // Image and tile size (SIZ)
  10347. if (code === 0xFF51) {
  10348. stream.skip(4);
  10349. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  10350. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  10351. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  10352. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  10353. stream.skip(16);
  10354. var Csiz = stream.getUint16(); // Byte 36
  10355. this.width = Xsiz - XOsiz;
  10356. this.height = Ysiz - YOsiz;
  10357. this.componentsCount = Csiz;
  10358. // Results are always returned as Uint8Arrays
  10359. this.bitsPerComponent = 8;
  10360. return;
  10361. }
  10362. }
  10363. throw new Error('JPX Error: No size marker found in JPX stream');
  10364. },
  10365. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  10366. var context = {};
  10367. try {
  10368. var doNotRecover = false;
  10369. var position = start;
  10370. while (position + 1 < end) {
  10371. var code = readUint16(data, position);
  10372. position += 2;
  10373. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  10374. switch (code) {
  10375. case 0xFF4F: // Start of codestream (SOC)
  10376. context.mainHeader = true;
  10377. break;
  10378. case 0xFFD9: // End of codestream (EOC)
  10379. break;
  10380. case 0xFF51: // Image and tile size (SIZ)
  10381. length = readUint16(data, position);
  10382. var siz = {};
  10383. siz.Xsiz = readUint32(data, position + 4);
  10384. siz.Ysiz = readUint32(data, position + 8);
  10385. siz.XOsiz = readUint32(data, position + 12);
  10386. siz.YOsiz = readUint32(data, position + 16);
  10387. siz.XTsiz = readUint32(data, position + 20);
  10388. siz.YTsiz = readUint32(data, position + 24);
  10389. siz.XTOsiz = readUint32(data, position + 28);
  10390. siz.YTOsiz = readUint32(data, position + 32);
  10391. var componentsCount = readUint16(data, position + 36);
  10392. siz.Csiz = componentsCount;
  10393. var components = [];
  10394. j = position + 38;
  10395. for (var i = 0; i < componentsCount; i++) {
  10396. var component = {
  10397. precision: (data[j] & 0x7F) + 1,
  10398. isSigned: !!(data[j] & 0x80),
  10399. XRsiz: data[j + 1],
  10400. YRsiz: data[j + 1]
  10401. };
  10402. calculateComponentDimensions(component, siz);
  10403. components.push(component);
  10404. }
  10405. context.SIZ = siz;
  10406. context.components = components;
  10407. calculateTileGrids(context, components);
  10408. context.QCC = [];
  10409. context.COC = [];
  10410. break;
  10411. case 0xFF5C: // Quantization default (QCD)
  10412. length = readUint16(data, position);
  10413. var qcd = {};
  10414. j = position + 2;
  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. qcd.noQuantization = (spqcdSize === 8);
  10433. qcd.scalarExpounded = scalarExpounded;
  10434. qcd.guardBits = sqcd >> 5;
  10435. spqcds = [];
  10436. while (j < length + position) {
  10437. var 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. qcd.SPqcds = spqcds;
  10449. if (context.mainHeader) {
  10450. context.QCD = qcd;
  10451. } else {
  10452. context.currentTile.QCD = qcd;
  10453. context.currentTile.QCC = [];
  10454. }
  10455. break;
  10456. case 0xFF5D: // Quantization component (QCC)
  10457. length = readUint16(data, position);
  10458. var qcc = {};
  10459. j = position + 2;
  10460. var cqcc;
  10461. if (context.SIZ.Csiz < 257) {
  10462. cqcc = data[j++];
  10463. } else {
  10464. cqcc = readUint16(data, j);
  10465. j += 2;
  10466. }
  10467. sqcd = data[j++];
  10468. switch (sqcd & 0x1F) {
  10469. case 0:
  10470. spqcdSize = 8;
  10471. scalarExpounded = true;
  10472. break;
  10473. case 1:
  10474. spqcdSize = 16;
  10475. scalarExpounded = false;
  10476. break;
  10477. case 2:
  10478. spqcdSize = 16;
  10479. scalarExpounded = true;
  10480. break;
  10481. default:
  10482. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10483. }
  10484. qcc.noQuantization = (spqcdSize === 8);
  10485. qcc.scalarExpounded = scalarExpounded;
  10486. qcc.guardBits = sqcd >> 5;
  10487. spqcds = [];
  10488. while (j < (length + position)) {
  10489. spqcd = {};
  10490. if (spqcdSize === 8) {
  10491. spqcd.epsilon = data[j++] >> 3;
  10492. spqcd.mu = 0;
  10493. } else {
  10494. spqcd.epsilon = data[j] >> 3;
  10495. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10496. j += 2;
  10497. }
  10498. spqcds.push(spqcd);
  10499. }
  10500. qcc.SPqcds = spqcds;
  10501. if (context.mainHeader) {
  10502. context.QCC[cqcc] = qcc;
  10503. } else {
  10504. context.currentTile.QCC[cqcc] = qcc;
  10505. }
  10506. break;
  10507. case 0xFF52: // Coding style default (COD)
  10508. length = readUint16(data, position);
  10509. var cod = {};
  10510. j = position + 2;
  10511. var scod = data[j++];
  10512. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  10513. cod.sopMarkerUsed = !!(scod & 2);
  10514. cod.ephMarkerUsed = !!(scod & 4);
  10515. cod.progressionOrder = data[j++];
  10516. cod.layersCount = readUint16(data, j);
  10517. j += 2;
  10518. cod.multipleComponentTransform = data[j++];
  10519. cod.decompositionLevelsCount = data[j++];
  10520. cod.xcb = (data[j++] & 0xF) + 2;
  10521. cod.ycb = (data[j++] & 0xF) + 2;
  10522. var blockStyle = data[j++];
  10523. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  10524. cod.resetContextProbabilities = !!(blockStyle & 2);
  10525. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  10526. cod.verticalyStripe = !!(blockStyle & 8);
  10527. cod.predictableTermination = !!(blockStyle & 16);
  10528. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  10529. cod.reversibleTransformation = data[j++];
  10530. if (cod.entropyCoderWithCustomPrecincts) {
  10531. var precinctsSizes = [];
  10532. while (j < length + position) {
  10533. var precinctsSize = data[j++];
  10534. precinctsSizes.push({
  10535. PPx: precinctsSize & 0xF,
  10536. PPy: precinctsSize >> 4
  10537. });
  10538. }
  10539. cod.precinctsSizes = precinctsSizes;
  10540. }
  10541. var unsupported = [];
  10542. if (cod.selectiveArithmeticCodingBypass) {
  10543. unsupported.push('selectiveArithmeticCodingBypass');
  10544. }
  10545. if (cod.resetContextProbabilities) {
  10546. unsupported.push('resetContextProbabilities');
  10547. }
  10548. if (cod.terminationOnEachCodingPass) {
  10549. unsupported.push('terminationOnEachCodingPass');
  10550. }
  10551. if (cod.verticalyStripe) {
  10552. unsupported.push('verticalyStripe');
  10553. }
  10554. if (cod.predictableTermination) {
  10555. unsupported.push('predictableTermination');
  10556. }
  10557. if (unsupported.length > 0) {
  10558. doNotRecover = true;
  10559. throw new Error('JPX Error: Unsupported COD options (' +
  10560. unsupported.join(', ') + ')');
  10561. }
  10562. if (context.mainHeader) {
  10563. context.COD = cod;
  10564. } else {
  10565. context.currentTile.COD = cod;
  10566. context.currentTile.COC = [];
  10567. }
  10568. break;
  10569. case 0xFF90: // Start of tile-part (SOT)
  10570. length = readUint16(data, position);
  10571. tile = {};
  10572. tile.index = readUint16(data, position + 2);
  10573. tile.length = readUint32(data, position + 4);
  10574. tile.dataEnd = tile.length + position - 2;
  10575. tile.partIndex = data[position + 8];
  10576. tile.partsCount = data[position + 9];
  10577. context.mainHeader = false;
  10578. if (tile.partIndex === 0) {
  10579. // reset component specific settings
  10580. tile.COD = context.COD;
  10581. tile.COC = context.COC.slice(0); // clone of the global COC
  10582. tile.QCD = context.QCD;
  10583. tile.QCC = context.QCC.slice(0); // clone of the global COC
  10584. }
  10585. context.currentTile = tile;
  10586. break;
  10587. case 0xFF93: // Start of data (SOD)
  10588. tile = context.currentTile;
  10589. if (tile.partIndex === 0) {
  10590. initializeTile(context, tile.index);
  10591. buildPackets(context);
  10592. }
  10593. // moving to the end of the data
  10594. length = tile.dataEnd - position;
  10595. parseTilePackets(context, data, position, length);
  10596. break;
  10597. case 0xFF55: // Tile-part lengths, main header (TLM)
  10598. case 0xFF57: // Packet length, main header (PLM)
  10599. case 0xFF58: // Packet length, tile-part header (PLT)
  10600. case 0xFF64: // Comment (COM)
  10601. length = readUint16(data, position);
  10602. // skipping content
  10603. break;
  10604. case 0xFF53: // Coding style component (COC)
  10605. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  10606. 'not implemented');
  10607. default:
  10608. throw new Error('JPX Error: Unknown codestream code: ' +
  10609. code.toString(16));
  10610. }
  10611. position += length;
  10612. }
  10613. } catch (e) {
  10614. if (doNotRecover || this.failOnCorruptedImage) {
  10615. throw e;
  10616. } else {
  10617. warn('Trying to recover from ' + e.message);
  10618. }
  10619. }
  10620. this.tiles = transformComponents(context);
  10621. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  10622. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  10623. this.componentsCount = context.SIZ.Csiz;
  10624. }
  10625. };
  10626. function calculateComponentDimensions(component, siz) {
  10627. // Section B.2 Component mapping
  10628. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  10629. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  10630. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  10631. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  10632. component.width = component.x1 - component.x0;
  10633. component.height = component.y1 - component.y0;
  10634. }
  10635. function calculateTileGrids(context, components) {
  10636. var siz = context.SIZ;
  10637. // Section B.3 Division into tile and tile-components
  10638. var tile, tiles = [];
  10639. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  10640. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  10641. for (var q = 0; q < numYtiles; q++) {
  10642. for (var p = 0; p < numXtiles; p++) {
  10643. tile = {};
  10644. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  10645. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  10646. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  10647. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  10648. tile.width = tile.tx1 - tile.tx0;
  10649. tile.height = tile.ty1 - tile.ty0;
  10650. tile.components = [];
  10651. tiles.push(tile);
  10652. }
  10653. }
  10654. context.tiles = tiles;
  10655. var componentsCount = siz.Csiz;
  10656. for (var i = 0, ii = componentsCount; i < ii; i++) {
  10657. var component = components[i];
  10658. for (var j = 0, jj = tiles.length; j < jj; j++) {
  10659. var tileComponent = {};
  10660. tile = tiles[j];
  10661. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  10662. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  10663. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  10664. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  10665. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  10666. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  10667. tile.components[i] = tileComponent;
  10668. }
  10669. }
  10670. }
  10671. function getBlocksDimensions(context, component, r) {
  10672. var codOrCoc = component.codingStyleParameters;
  10673. var result = {};
  10674. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  10675. result.PPx = 15;
  10676. result.PPy = 15;
  10677. } else {
  10678. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  10679. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  10680. }
  10681. // calculate codeblock size as described in section B.7
  10682. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  10683. Math.min(codOrCoc.xcb, result.PPx));
  10684. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  10685. Math.min(codOrCoc.ycb, result.PPy));
  10686. return result;
  10687. }
  10688. function buildPrecincts(context, resolution, dimensions) {
  10689. // Section B.6 Division resolution to precincts
  10690. var precinctWidth = 1 << dimensions.PPx;
  10691. var precinctHeight = 1 << dimensions.PPy;
  10692. // Jasper introduces codeblock groups for mapping each subband codeblocks
  10693. // to precincts. Precinct partition divides a resolution according to width
  10694. // and height parameters. The subband that belongs to the resolution level
  10695. // has a different size than the level, unless it is the zero resolution.
  10696. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  10697. // The precinct partitioning for a particular subband is derived from a
  10698. // partitioning of its parent LL band (i.e., the LL band at the next higher
  10699. // resolution level)... The LL band associated with each resolution level is
  10700. // divided into precincts... Each of the resulting precinct regions is then
  10701. // mapped into its child subbands (if any) at the next lower resolution
  10702. // level. This is accomplished by using the coordinate transformation
  10703. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  10704. // coordinates of a point in the LL band and child subband, respectively.
  10705. var isZeroRes = resolution.resLevel === 0;
  10706. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  10707. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  10708. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  10709. Math.ceil(resolution.trx1 / precinctWidth) -
  10710. Math.floor(resolution.trx0 / precinctWidth) : 0);
  10711. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  10712. Math.ceil(resolution.try1 / precinctHeight) -
  10713. Math.floor(resolution.try0 / precinctHeight) : 0);
  10714. var numprecincts = numprecinctswide * numprecinctshigh;
  10715. resolution.precinctParameters = {
  10716. precinctWidth: precinctWidth,
  10717. precinctHeight: precinctHeight,
  10718. numprecinctswide: numprecinctswide,
  10719. numprecinctshigh: numprecinctshigh,
  10720. numprecincts: numprecincts,
  10721. precinctWidthInSubband: precinctWidthInSubband,
  10722. precinctHeightInSubband: precinctHeightInSubband
  10723. };
  10724. }
  10725. function buildCodeblocks(context, subband, dimensions) {
  10726. // Section B.7 Division sub-band into code-blocks
  10727. var xcb_ = dimensions.xcb_;
  10728. var ycb_ = dimensions.ycb_;
  10729. var codeblockWidth = 1 << xcb_;
  10730. var codeblockHeight = 1 << ycb_;
  10731. var cbx0 = subband.tbx0 >> xcb_;
  10732. var cby0 = subband.tby0 >> ycb_;
  10733. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  10734. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  10735. var precinctParameters = subband.resolution.precinctParameters;
  10736. var codeblocks = [];
  10737. var precincts = [];
  10738. var i, j, codeblock, precinctNumber;
  10739. for (j = cby0; j < cby1; j++) {
  10740. for (i = cbx0; i < cbx1; i++) {
  10741. codeblock = {
  10742. cbx: i,
  10743. cby: j,
  10744. tbx0: codeblockWidth * i,
  10745. tby0: codeblockHeight * j,
  10746. tbx1: codeblockWidth * (i + 1),
  10747. tby1: codeblockHeight * (j + 1)
  10748. };
  10749. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  10750. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  10751. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  10752. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  10753. // Calculate precinct number for this codeblock, codeblock position
  10754. // should be relative to its subband, use actual dimension and position
  10755. // See comment about codeblock group width and height
  10756. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  10757. precinctParameters.precinctWidthInSubband);
  10758. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  10759. precinctParameters.precinctHeightInSubband);
  10760. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  10761. codeblock.precinctNumber = precinctNumber;
  10762. codeblock.subbandType = subband.type;
  10763. codeblock.Lblock = 3;
  10764. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  10765. codeblock.tby1_ <= codeblock.tby0_) {
  10766. continue;
  10767. }
  10768. codeblocks.push(codeblock);
  10769. // building precinct for the sub-band
  10770. var precinct = precincts[precinctNumber];
  10771. if (precinct !== undefined) {
  10772. if (i < precinct.cbxMin) {
  10773. precinct.cbxMin = i;
  10774. } else if (i > precinct.cbxMax) {
  10775. precinct.cbxMax = i;
  10776. }
  10777. if (j < precinct.cbyMin) {
  10778. precinct.cbxMin = j;
  10779. } else if (j > precinct.cbyMax) {
  10780. precinct.cbyMax = j;
  10781. }
  10782. } else {
  10783. precincts[precinctNumber] = precinct = {
  10784. cbxMin: i,
  10785. cbyMin: j,
  10786. cbxMax: i,
  10787. cbyMax: j
  10788. };
  10789. }
  10790. codeblock.precinct = precinct;
  10791. }
  10792. }
  10793. subband.codeblockParameters = {
  10794. codeblockWidth: xcb_,
  10795. codeblockHeight: ycb_,
  10796. numcodeblockwide: cbx1 - cbx0 + 1,
  10797. numcodeblockhigh: cby1 - cby0 + 1
  10798. };
  10799. subband.codeblocks = codeblocks;
  10800. subband.precincts = precincts;
  10801. }
  10802. function createPacket(resolution, precinctNumber, layerNumber) {
  10803. var precinctCodeblocks = [];
  10804. // Section B.10.8 Order of info in packet
  10805. var subbands = resolution.subbands;
  10806. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  10807. for (var i = 0, ii = subbands.length; i < ii; i++) {
  10808. var subband = subbands[i];
  10809. var codeblocks = subband.codeblocks;
  10810. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  10811. var codeblock = codeblocks[j];
  10812. if (codeblock.precinctNumber !== precinctNumber) {
  10813. continue;
  10814. }
  10815. precinctCodeblocks.push(codeblock);
  10816. }
  10817. }
  10818. return {
  10819. layerNumber: layerNumber,
  10820. codeblocks: precinctCodeblocks
  10821. };
  10822. }
  10823. function LayerResolutionComponentPositionIterator(context) {
  10824. var siz = context.SIZ;
  10825. var tileIndex = context.currentTile.index;
  10826. var tile = context.tiles[tileIndex];
  10827. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10828. var componentsCount = siz.Csiz;
  10829. var maxDecompositionLevelsCount = 0;
  10830. for (var q = 0; q < componentsCount; q++) {
  10831. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10832. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10833. }
  10834. var l = 0, r = 0, i = 0, k = 0;
  10835. this.nextPacket = function JpxImage_nextPacket() {
  10836. // Section B.12.1.1 Layer-resolution-component-position
  10837. for (; l < layersCount; l++) {
  10838. for (; r <= maxDecompositionLevelsCount; r++) {
  10839. for (; i < componentsCount; i++) {
  10840. var component = tile.components[i];
  10841. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10842. continue;
  10843. }
  10844. var resolution = component.resolutions[r];
  10845. var numprecincts = resolution.precinctParameters.numprecincts;
  10846. for (; k < numprecincts;) {
  10847. var packet = createPacket(resolution, k, l);
  10848. k++;
  10849. return packet;
  10850. }
  10851. k = 0;
  10852. }
  10853. i = 0;
  10854. }
  10855. r = 0;
  10856. }
  10857. throw new Error('JPX Error: Out of packets');
  10858. };
  10859. }
  10860. function ResolutionLayerComponentPositionIterator(context) {
  10861. var siz = context.SIZ;
  10862. var tileIndex = context.currentTile.index;
  10863. var tile = context.tiles[tileIndex];
  10864. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10865. var componentsCount = siz.Csiz;
  10866. var maxDecompositionLevelsCount = 0;
  10867. for (var q = 0; q < componentsCount; q++) {
  10868. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10869. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10870. }
  10871. var r = 0, l = 0, i = 0, k = 0;
  10872. this.nextPacket = function JpxImage_nextPacket() {
  10873. // Section B.12.1.2 Resolution-layer-component-position
  10874. for (; r <= maxDecompositionLevelsCount; r++) {
  10875. for (; l < layersCount; l++) {
  10876. for (; i < componentsCount; i++) {
  10877. var component = tile.components[i];
  10878. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10879. continue;
  10880. }
  10881. var resolution = component.resolutions[r];
  10882. var numprecincts = resolution.precinctParameters.numprecincts;
  10883. for (; k < numprecincts;) {
  10884. var packet = createPacket(resolution, k, l);
  10885. k++;
  10886. return packet;
  10887. }
  10888. k = 0;
  10889. }
  10890. i = 0;
  10891. }
  10892. l = 0;
  10893. }
  10894. throw new Error('JPX Error: Out of packets');
  10895. };
  10896. }
  10897. function ResolutionPositionComponentLayerIterator(context) {
  10898. var siz = context.SIZ;
  10899. var tileIndex = context.currentTile.index;
  10900. var tile = context.tiles[tileIndex];
  10901. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10902. var componentsCount = siz.Csiz;
  10903. var l, r, c, p;
  10904. var maxDecompositionLevelsCount = 0;
  10905. for (c = 0; c < componentsCount; c++) {
  10906. var component = tile.components[c];
  10907. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10908. component.codingStyleParameters.decompositionLevelsCount);
  10909. }
  10910. var maxNumPrecinctsInLevel = new Int32Array(
  10911. maxDecompositionLevelsCount + 1);
  10912. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  10913. var maxNumPrecincts = 0;
  10914. for (c = 0; c < componentsCount; ++c) {
  10915. var resolutions = tile.components[c].resolutions;
  10916. if (r < resolutions.length) {
  10917. maxNumPrecincts = Math.max(maxNumPrecincts,
  10918. resolutions[r].precinctParameters.numprecincts);
  10919. }
  10920. }
  10921. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  10922. }
  10923. l = 0;
  10924. r = 0;
  10925. c = 0;
  10926. p = 0;
  10927. this.nextPacket = function JpxImage_nextPacket() {
  10928. // Section B.12.1.3 Resolution-position-component-layer
  10929. for (; r <= maxDecompositionLevelsCount; r++) {
  10930. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  10931. for (; c < componentsCount; c++) {
  10932. var component = tile.components[c];
  10933. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10934. continue;
  10935. }
  10936. var resolution = component.resolutions[r];
  10937. var numprecincts = resolution.precinctParameters.numprecincts;
  10938. if (p >= numprecincts) {
  10939. continue;
  10940. }
  10941. for (; l < layersCount;) {
  10942. var packet = createPacket(resolution, p, l);
  10943. l++;
  10944. return packet;
  10945. }
  10946. l = 0;
  10947. }
  10948. c = 0;
  10949. }
  10950. p = 0;
  10951. }
  10952. throw new Error('JPX Error: Out of packets');
  10953. };
  10954. }
  10955. function PositionComponentResolutionLayerIterator(context) {
  10956. var siz = context.SIZ;
  10957. var tileIndex = context.currentTile.index;
  10958. var tile = context.tiles[tileIndex];
  10959. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10960. var componentsCount = siz.Csiz;
  10961. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10962. var precinctsIterationSizes = precinctsSizes;
  10963. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10964. this.nextPacket = function JpxImage_nextPacket() {
  10965. // Section B.12.1.4 Position-component-resolution-layer
  10966. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10967. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10968. for (; c < componentsCount; c++) {
  10969. var component = tile.components[c];
  10970. var decompositionLevelsCount =
  10971. component.codingStyleParameters.decompositionLevelsCount;
  10972. for (; r <= decompositionLevelsCount; r++) {
  10973. var resolution = component.resolutions[r];
  10974. var sizeInImageScale =
  10975. precinctsSizes.components[c].resolutions[r];
  10976. var k = getPrecinctIndexIfExist(
  10977. px,
  10978. py,
  10979. sizeInImageScale,
  10980. precinctsIterationSizes,
  10981. resolution);
  10982. if (k === null) {
  10983. continue;
  10984. }
  10985. for (; l < layersCount;) {
  10986. var packet = createPacket(resolution, k, l);
  10987. l++;
  10988. return packet;
  10989. }
  10990. l = 0;
  10991. }
  10992. r = 0;
  10993. }
  10994. c = 0;
  10995. }
  10996. px = 0;
  10997. }
  10998. throw new Error('JPX Error: Out of packets');
  10999. };
  11000. }
  11001. function ComponentPositionResolutionLayerIterator(context) {
  11002. var siz = context.SIZ;
  11003. var tileIndex = context.currentTile.index;
  11004. var tile = context.tiles[tileIndex];
  11005. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  11006. var componentsCount = siz.Csiz;
  11007. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  11008. var l = 0, r = 0, c = 0, px = 0, py = 0;
  11009. this.nextPacket = function JpxImage_nextPacket() {
  11010. // Section B.12.1.5 Component-position-resolution-layer
  11011. for (; c < componentsCount; ++c) {
  11012. var component = tile.components[c];
  11013. var precinctsIterationSizes = precinctsSizes.components[c];
  11014. var decompositionLevelsCount =
  11015. component.codingStyleParameters.decompositionLevelsCount;
  11016. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  11017. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  11018. for (; r <= decompositionLevelsCount; r++) {
  11019. var resolution = component.resolutions[r];
  11020. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  11021. var k = getPrecinctIndexIfExist(
  11022. px,
  11023. py,
  11024. sizeInImageScale,
  11025. precinctsIterationSizes,
  11026. resolution);
  11027. if (k === null) {
  11028. continue;
  11029. }
  11030. for (; l < layersCount;) {
  11031. var packet = createPacket(resolution, k, l);
  11032. l++;
  11033. return packet;
  11034. }
  11035. l = 0;
  11036. }
  11037. r = 0;
  11038. }
  11039. px = 0;
  11040. }
  11041. py = 0;
  11042. }
  11043. throw new Error('JPX Error: Out of packets');
  11044. };
  11045. }
  11046. function getPrecinctIndexIfExist(
  11047. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  11048. var posX = pxIndex * precinctIterationSizes.minWidth;
  11049. var posY = pyIndex * precinctIterationSizes.minHeight;
  11050. if (posX % sizeInImageScale.width !== 0 ||
  11051. posY % sizeInImageScale.height !== 0) {
  11052. return null;
  11053. }
  11054. var startPrecinctRowIndex =
  11055. (posY / sizeInImageScale.width) *
  11056. resolution.precinctParameters.numprecinctswide;
  11057. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  11058. }
  11059. function getPrecinctSizesInImageScale(tile) {
  11060. var componentsCount = tile.components.length;
  11061. var minWidth = Number.MAX_VALUE;
  11062. var minHeight = Number.MAX_VALUE;
  11063. var maxNumWide = 0;
  11064. var maxNumHigh = 0;
  11065. var sizePerComponent = new Array(componentsCount);
  11066. for (var c = 0; c < componentsCount; c++) {
  11067. var component = tile.components[c];
  11068. var decompositionLevelsCount =
  11069. component.codingStyleParameters.decompositionLevelsCount;
  11070. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  11071. var minWidthCurrentComponent = Number.MAX_VALUE;
  11072. var minHeightCurrentComponent = Number.MAX_VALUE;
  11073. var maxNumWideCurrentComponent = 0;
  11074. var maxNumHighCurrentComponent = 0;
  11075. var scale = 1;
  11076. for (var r = decompositionLevelsCount; r >= 0; --r) {
  11077. var resolution = component.resolutions[r];
  11078. var widthCurrentResolution =
  11079. scale * resolution.precinctParameters.precinctWidth;
  11080. var heightCurrentResolution =
  11081. scale * resolution.precinctParameters.precinctHeight;
  11082. minWidthCurrentComponent = Math.min(
  11083. minWidthCurrentComponent,
  11084. widthCurrentResolution);
  11085. minHeightCurrentComponent = Math.min(
  11086. minHeightCurrentComponent,
  11087. heightCurrentResolution);
  11088. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  11089. resolution.precinctParameters.numprecinctswide);
  11090. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  11091. resolution.precinctParameters.numprecinctshigh);
  11092. sizePerResolution[r] = {
  11093. width: widthCurrentResolution,
  11094. height: heightCurrentResolution
  11095. };
  11096. scale <<= 1;
  11097. }
  11098. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  11099. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  11100. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  11101. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  11102. sizePerComponent[c] = {
  11103. resolutions: sizePerResolution,
  11104. minWidth: minWidthCurrentComponent,
  11105. minHeight: minHeightCurrentComponent,
  11106. maxNumWide: maxNumWideCurrentComponent,
  11107. maxNumHigh: maxNumHighCurrentComponent
  11108. };
  11109. }
  11110. return {
  11111. components: sizePerComponent,
  11112. minWidth: minWidth,
  11113. minHeight: minHeight,
  11114. maxNumWide: maxNumWide,
  11115. maxNumHigh: maxNumHigh
  11116. };
  11117. }
  11118. function buildPackets(context) {
  11119. var siz = context.SIZ;
  11120. var tileIndex = context.currentTile.index;
  11121. var tile = context.tiles[tileIndex];
  11122. var componentsCount = siz.Csiz;
  11123. // Creating resolutions and sub-bands for each component
  11124. for (var c = 0; c < componentsCount; c++) {
  11125. var component = tile.components[c];
  11126. var decompositionLevelsCount =
  11127. component.codingStyleParameters.decompositionLevelsCount;
  11128. // Section B.5 Resolution levels and sub-bands
  11129. var resolutions = [];
  11130. var subbands = [];
  11131. for (var r = 0; r <= decompositionLevelsCount; r++) {
  11132. var blocksDimensions = getBlocksDimensions(context, component, r);
  11133. var resolution = {};
  11134. var scale = 1 << (decompositionLevelsCount - r);
  11135. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  11136. resolution.try0 = Math.ceil(component.tcy0 / scale);
  11137. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  11138. resolution.try1 = Math.ceil(component.tcy1 / scale);
  11139. resolution.resLevel = r;
  11140. buildPrecincts(context, resolution, blocksDimensions);
  11141. resolutions.push(resolution);
  11142. var subband;
  11143. if (r === 0) {
  11144. // one sub-band (LL) with last decomposition
  11145. subband = {};
  11146. subband.type = 'LL';
  11147. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  11148. subband.tby0 = Math.ceil(component.tcy0 / scale);
  11149. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  11150. subband.tby1 = Math.ceil(component.tcy1 / scale);
  11151. subband.resolution = resolution;
  11152. buildCodeblocks(context, subband, blocksDimensions);
  11153. subbands.push(subband);
  11154. resolution.subbands = [subband];
  11155. } else {
  11156. var bscale = 1 << (decompositionLevelsCount - r + 1);
  11157. var resolutionSubbands = [];
  11158. // three sub-bands (HL, LH and HH) with rest of decompositions
  11159. subband = {};
  11160. subband.type = 'HL';
  11161. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11162. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  11163. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11164. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  11165. subband.resolution = resolution;
  11166. buildCodeblocks(context, subband, blocksDimensions);
  11167. subbands.push(subband);
  11168. resolutionSubbands.push(subband);
  11169. subband = {};
  11170. subband.type = 'LH';
  11171. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  11172. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11173. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  11174. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11175. subband.resolution = resolution;
  11176. buildCodeblocks(context, subband, blocksDimensions);
  11177. subbands.push(subband);
  11178. resolutionSubbands.push(subband);
  11179. subband = {};
  11180. subband.type = 'HH';
  11181. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11182. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11183. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11184. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11185. subband.resolution = resolution;
  11186. buildCodeblocks(context, subband, blocksDimensions);
  11187. subbands.push(subband);
  11188. resolutionSubbands.push(subband);
  11189. resolution.subbands = resolutionSubbands;
  11190. }
  11191. }
  11192. component.resolutions = resolutions;
  11193. component.subbands = subbands;
  11194. }
  11195. // Generate the packets sequence
  11196. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  11197. switch (progressionOrder) {
  11198. case 0:
  11199. tile.packetsIterator =
  11200. new LayerResolutionComponentPositionIterator(context);
  11201. break;
  11202. case 1:
  11203. tile.packetsIterator =
  11204. new ResolutionLayerComponentPositionIterator(context);
  11205. break;
  11206. case 2:
  11207. tile.packetsIterator =
  11208. new ResolutionPositionComponentLayerIterator(context);
  11209. break;
  11210. case 3:
  11211. tile.packetsIterator =
  11212. new PositionComponentResolutionLayerIterator(context);
  11213. break;
  11214. case 4:
  11215. tile.packetsIterator =
  11216. new ComponentPositionResolutionLayerIterator(context);
  11217. break;
  11218. default:
  11219. throw new Error('JPX Error: Unsupported progression order ' +
  11220. progressionOrder);
  11221. }
  11222. }
  11223. function parseTilePackets(context, data, offset, dataLength) {
  11224. var position = 0;
  11225. var buffer, bufferSize = 0, skipNextBit = false;
  11226. function readBits(count) {
  11227. while (bufferSize < count) {
  11228. var b = data[offset + position];
  11229. position++;
  11230. if (skipNextBit) {
  11231. buffer = (buffer << 7) | b;
  11232. bufferSize += 7;
  11233. skipNextBit = false;
  11234. } else {
  11235. buffer = (buffer << 8) | b;
  11236. bufferSize += 8;
  11237. }
  11238. if (b === 0xFF) {
  11239. skipNextBit = true;
  11240. }
  11241. }
  11242. bufferSize -= count;
  11243. return (buffer >>> bufferSize) & ((1 << count) - 1);
  11244. }
  11245. function skipMarkerIfEqual(value) {
  11246. if (data[offset + position - 1] === 0xFF &&
  11247. data[offset + position] === value) {
  11248. skipBytes(1);
  11249. return true;
  11250. } else if (data[offset + position] === 0xFF &&
  11251. data[offset + position + 1] === value) {
  11252. skipBytes(2);
  11253. return true;
  11254. }
  11255. return false;
  11256. }
  11257. function skipBytes(count) {
  11258. position += count;
  11259. }
  11260. function alignToByte() {
  11261. bufferSize = 0;
  11262. if (skipNextBit) {
  11263. position++;
  11264. skipNextBit = false;
  11265. }
  11266. }
  11267. function readCodingpasses() {
  11268. if (readBits(1) === 0) {
  11269. return 1;
  11270. }
  11271. if (readBits(1) === 0) {
  11272. return 2;
  11273. }
  11274. var value = readBits(2);
  11275. if (value < 3) {
  11276. return value + 3;
  11277. }
  11278. value = readBits(5);
  11279. if (value < 31) {
  11280. return value + 6;
  11281. }
  11282. value = readBits(7);
  11283. return value + 37;
  11284. }
  11285. var tileIndex = context.currentTile.index;
  11286. var tile = context.tiles[tileIndex];
  11287. var sopMarkerUsed = context.COD.sopMarkerUsed;
  11288. var ephMarkerUsed = context.COD.ephMarkerUsed;
  11289. var packetsIterator = tile.packetsIterator;
  11290. while (position < dataLength) {
  11291. alignToByte();
  11292. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  11293. // Skip also marker segment length and packet sequence ID
  11294. skipBytes(4);
  11295. }
  11296. var packet = packetsIterator.nextPacket();
  11297. if (!readBits(1)) {
  11298. continue;
  11299. }
  11300. var layerNumber = packet.layerNumber;
  11301. var queue = [], codeblock;
  11302. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  11303. codeblock = packet.codeblocks[i];
  11304. var precinct = codeblock.precinct;
  11305. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  11306. var codeblockRow = codeblock.cby - precinct.cbyMin;
  11307. var codeblockIncluded = false;
  11308. var firstTimeInclusion = false;
  11309. var valueReady;
  11310. if (codeblock['included'] !== undefined) {
  11311. codeblockIncluded = !!readBits(1);
  11312. } else {
  11313. // reading inclusion tree
  11314. precinct = codeblock.precinct;
  11315. var inclusionTree, zeroBitPlanesTree;
  11316. if (precinct['inclusionTree'] !== undefined) {
  11317. inclusionTree = precinct.inclusionTree;
  11318. } else {
  11319. // building inclusion and zero bit-planes trees
  11320. var width = precinct.cbxMax - precinct.cbxMin + 1;
  11321. var height = precinct.cbyMax - precinct.cbyMin + 1;
  11322. inclusionTree = new InclusionTree(width, height, layerNumber);
  11323. zeroBitPlanesTree = new TagTree(width, height);
  11324. precinct.inclusionTree = inclusionTree;
  11325. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  11326. }
  11327. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  11328. while (true) {
  11329. if (readBits(1)) {
  11330. valueReady = !inclusionTree.nextLevel();
  11331. if (valueReady) {
  11332. codeblock.included = true;
  11333. codeblockIncluded = firstTimeInclusion = true;
  11334. break;
  11335. }
  11336. } else {
  11337. inclusionTree.incrementValue(layerNumber);
  11338. break;
  11339. }
  11340. }
  11341. }
  11342. }
  11343. if (!codeblockIncluded) {
  11344. continue;
  11345. }
  11346. if (firstTimeInclusion) {
  11347. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  11348. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  11349. while (true) {
  11350. if (readBits(1)) {
  11351. valueReady = !zeroBitPlanesTree.nextLevel();
  11352. if (valueReady) {
  11353. break;
  11354. }
  11355. } else {
  11356. zeroBitPlanesTree.incrementValue();
  11357. }
  11358. }
  11359. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  11360. }
  11361. var codingpasses = readCodingpasses();
  11362. while (readBits(1)) {
  11363. codeblock.Lblock++;
  11364. }
  11365. var codingpassesLog2 = log2(codingpasses);
  11366. // rounding down log2
  11367. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  11368. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  11369. var codedDataLength = readBits(bits);
  11370. queue.push({
  11371. codeblock: codeblock,
  11372. codingpasses: codingpasses,
  11373. dataLength: codedDataLength
  11374. });
  11375. }
  11376. alignToByte();
  11377. if (ephMarkerUsed) {
  11378. skipMarkerIfEqual(0x92);
  11379. }
  11380. while (queue.length > 0) {
  11381. var packetItem = queue.shift();
  11382. codeblock = packetItem.codeblock;
  11383. if (codeblock['data'] === undefined) {
  11384. codeblock.data = [];
  11385. }
  11386. codeblock.data.push({
  11387. data: data,
  11388. start: offset + position,
  11389. end: offset + position + packetItem.dataLength,
  11390. codingpasses: packetItem.codingpasses
  11391. });
  11392. position += packetItem.dataLength;
  11393. }
  11394. }
  11395. return position;
  11396. }
  11397. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  11398. delta, mb, reversible, segmentationSymbolUsed) {
  11399. var x0 = subband.tbx0;
  11400. var y0 = subband.tby0;
  11401. var width = subband.tbx1 - subband.tbx0;
  11402. var codeblocks = subband.codeblocks;
  11403. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  11404. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  11405. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  11406. var codeblock = codeblocks[i];
  11407. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  11408. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  11409. if (blockWidth === 0 || blockHeight === 0) {
  11410. continue;
  11411. }
  11412. if (codeblock['data'] === undefined) {
  11413. continue;
  11414. }
  11415. var bitModel, currentCodingpassType;
  11416. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  11417. codeblock.zeroBitPlanes, mb);
  11418. currentCodingpassType = 2; // first bit plane starts from cleanup
  11419. // collect data
  11420. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  11421. var j, jj, dataItem;
  11422. for (j = 0, jj = data.length; j < jj; j++) {
  11423. dataItem = data[j];
  11424. totalLength += dataItem.end - dataItem.start;
  11425. codingpasses += dataItem.codingpasses;
  11426. }
  11427. var encodedData = new Uint8Array(totalLength);
  11428. var position = 0;
  11429. for (j = 0, jj = data.length; j < jj; j++) {
  11430. dataItem = data[j];
  11431. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  11432. encodedData.set(chunk, position);
  11433. position += chunk.length;
  11434. }
  11435. // decoding the item
  11436. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  11437. bitModel.setDecoder(decoder);
  11438. for (j = 0; j < codingpasses; j++) {
  11439. switch (currentCodingpassType) {
  11440. case 0:
  11441. bitModel.runSignificancePropogationPass();
  11442. break;
  11443. case 1:
  11444. bitModel.runMagnitudeRefinementPass();
  11445. break;
  11446. case 2:
  11447. bitModel.runCleanupPass();
  11448. if (segmentationSymbolUsed) {
  11449. bitModel.checkSegmentationSymbol();
  11450. }
  11451. break;
  11452. }
  11453. currentCodingpassType = (currentCodingpassType + 1) % 3;
  11454. }
  11455. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  11456. var sign = bitModel.coefficentsSign;
  11457. var magnitude = bitModel.coefficentsMagnitude;
  11458. var bitsDecoded = bitModel.bitsDecoded;
  11459. var magnitudeCorrection = reversible ? 0 : 0.5;
  11460. var k, n, nb;
  11461. position = 0;
  11462. // Do the interleaving of Section F.3.3 here, so we do not need
  11463. // to copy later. LL level is not interleaved, just copied.
  11464. var interleave = (subband.type !== 'LL');
  11465. for (j = 0; j < blockHeight; j++) {
  11466. var row = (offset / width) | 0; // row in the non-interleaved subband
  11467. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  11468. for (k = 0; k < blockWidth; k++) {
  11469. n = magnitude[position];
  11470. if (n !== 0) {
  11471. n = (n + magnitudeCorrection) * delta;
  11472. if (sign[position] !== 0) {
  11473. n = -n;
  11474. }
  11475. nb = bitsDecoded[position];
  11476. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  11477. if (reversible && (nb >= mb)) {
  11478. coefficients[pos] = n;
  11479. } else {
  11480. coefficients[pos] = n * (1 << (mb - nb));
  11481. }
  11482. }
  11483. offset++;
  11484. position++;
  11485. }
  11486. offset += width - blockWidth;
  11487. }
  11488. }
  11489. }
  11490. function transformTile(context, tile, c) {
  11491. var component = tile.components[c];
  11492. var codingStyleParameters = component.codingStyleParameters;
  11493. var quantizationParameters = component.quantizationParameters;
  11494. var decompositionLevelsCount =
  11495. codingStyleParameters.decompositionLevelsCount;
  11496. var spqcds = quantizationParameters.SPqcds;
  11497. var scalarExpounded = quantizationParameters.scalarExpounded;
  11498. var guardBits = quantizationParameters.guardBits;
  11499. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  11500. var precision = context.components[c].precision;
  11501. var reversible = codingStyleParameters.reversibleTransformation;
  11502. var transform = (reversible ? new ReversibleTransform() :
  11503. new IrreversibleTransform());
  11504. var subbandCoefficients = [];
  11505. var b = 0;
  11506. for (var i = 0; i <= decompositionLevelsCount; i++) {
  11507. var resolution = component.resolutions[i];
  11508. var width = resolution.trx1 - resolution.trx0;
  11509. var height = resolution.try1 - resolution.try0;
  11510. // Allocate space for the whole sublevel.
  11511. var coefficients = new Float32Array(width * height);
  11512. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  11513. var mu, epsilon;
  11514. if (!scalarExpounded) {
  11515. // formula E-5
  11516. mu = spqcds[0].mu;
  11517. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  11518. } else {
  11519. mu = spqcds[b].mu;
  11520. epsilon = spqcds[b].epsilon;
  11521. b++;
  11522. }
  11523. var subband = resolution.subbands[j];
  11524. var gainLog2 = SubbandsGainLog2[subband.type];
  11525. // calulate quantization coefficient (Section E.1.1.1)
  11526. var delta = (reversible ? 1 :
  11527. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  11528. var mb = (guardBits + epsilon - 1);
  11529. // In the first resolution level, copyCoefficients will fill the
  11530. // whole array with coefficients. In the succeding passes,
  11531. // copyCoefficients will consecutively fill in the values that belong
  11532. // to the interleaved positions of the HL, LH, and HH coefficients.
  11533. // The LL coefficients will then be interleaved in Transform.iterate().
  11534. copyCoefficients(coefficients, width, height, subband, delta, mb,
  11535. reversible, segmentationSymbolUsed);
  11536. }
  11537. subbandCoefficients.push({
  11538. width: width,
  11539. height: height,
  11540. items: coefficients
  11541. });
  11542. }
  11543. var result = transform.calculate(subbandCoefficients,
  11544. component.tcx0, component.tcy0);
  11545. return {
  11546. left: component.tcx0,
  11547. top: component.tcy0,
  11548. width: result.width,
  11549. height: result.height,
  11550. items: result.items
  11551. };
  11552. }
  11553. function transformComponents(context) {
  11554. var siz = context.SIZ;
  11555. var components = context.components;
  11556. var componentsCount = siz.Csiz;
  11557. var resultImages = [];
  11558. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  11559. var tile = context.tiles[i];
  11560. var transformedTiles = [];
  11561. var c;
  11562. for (c = 0; c < componentsCount; c++) {
  11563. transformedTiles[c] = transformTile(context, tile, c);
  11564. }
  11565. var tile0 = transformedTiles[0];
  11566. var out = new Uint8Array(tile0.items.length * componentsCount);
  11567. var result = {
  11568. left: tile0.left,
  11569. top: tile0.top,
  11570. width: tile0.width,
  11571. height: tile0.height,
  11572. items: out
  11573. };
  11574. // Section G.2.2 Inverse multi component transform
  11575. var shift, offset, max, min, maxK;
  11576. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  11577. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  11578. var fourComponents = componentsCount === 4;
  11579. var y0items = transformedTiles[0].items;
  11580. var y1items = transformedTiles[1].items;
  11581. var y2items = transformedTiles[2].items;
  11582. var y3items = fourComponents ? transformedTiles[3].items : null;
  11583. // HACK: The multiple component transform formulas below assume that
  11584. // all components have the same precision. With this in mind, we
  11585. // compute shift and offset only once.
  11586. shift = components[0].precision - 8;
  11587. offset = (128 << shift) + 0.5;
  11588. max = 255 * (1 << shift);
  11589. maxK = max * 0.5;
  11590. min = -maxK;
  11591. var component0 = tile.components[0];
  11592. var alpha01 = componentsCount - 3;
  11593. jj = y0items.length;
  11594. if (!component0.codingStyleParameters.reversibleTransformation) {
  11595. // inverse irreversible multiple component transform
  11596. for (j = 0; j < jj; j++, pos += alpha01) {
  11597. y0 = y0items[j] + offset;
  11598. y1 = y1items[j];
  11599. y2 = y2items[j];
  11600. r = y0 + 1.402 * y2;
  11601. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  11602. b = y0 + 1.772 * y1;
  11603. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11604. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11605. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11606. }
  11607. } else {
  11608. // inverse reversible multiple component transform
  11609. for (j = 0; j < jj; j++, pos += alpha01) {
  11610. y0 = y0items[j] + offset;
  11611. y1 = y1items[j];
  11612. y2 = y2items[j];
  11613. g = y0 - ((y2 + y1) >> 2);
  11614. r = g + y2;
  11615. b = g + y1;
  11616. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11617. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11618. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11619. }
  11620. }
  11621. if (fourComponents) {
  11622. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  11623. k = y3items[j];
  11624. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  11625. }
  11626. }
  11627. } else { // no multi-component transform
  11628. for (c = 0; c < componentsCount; c++) {
  11629. var items = transformedTiles[c].items;
  11630. shift = components[c].precision - 8;
  11631. offset = (128 << shift) + 0.5;
  11632. max = (127.5 * (1 << shift));
  11633. min = -max;
  11634. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  11635. val = items[j];
  11636. out[pos] = val <= min ? 0 :
  11637. val >= max ? 255 : (val + offset) >> shift;
  11638. pos += componentsCount;
  11639. }
  11640. }
  11641. }
  11642. resultImages.push(result);
  11643. }
  11644. return resultImages;
  11645. }
  11646. function initializeTile(context, tileIndex) {
  11647. var siz = context.SIZ;
  11648. var componentsCount = siz.Csiz;
  11649. var tile = context.tiles[tileIndex];
  11650. for (var c = 0; c < componentsCount; c++) {
  11651. var component = tile.components[c];
  11652. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  11653. context.currentTile.QCC[c] : context.currentTile.QCD);
  11654. component.quantizationParameters = qcdOrQcc;
  11655. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  11656. context.currentTile.COC[c] : context.currentTile.COD);
  11657. component.codingStyleParameters = codOrCoc;
  11658. }
  11659. tile.codingStyleDefaultParameters = context.currentTile.COD;
  11660. }
  11661. // Section B.10.2 Tag trees
  11662. var TagTree = (function TagTreeClosure() {
  11663. function TagTree(width, height) {
  11664. var levelsLength = log2(Math.max(width, height)) + 1;
  11665. this.levels = [];
  11666. for (var i = 0; i < levelsLength; i++) {
  11667. var level = {
  11668. width: width,
  11669. height: height,
  11670. items: []
  11671. };
  11672. this.levels.push(level);
  11673. width = Math.ceil(width / 2);
  11674. height = Math.ceil(height / 2);
  11675. }
  11676. }
  11677. TagTree.prototype = {
  11678. reset: function TagTree_reset(i, j) {
  11679. var currentLevel = 0, value = 0, level;
  11680. while (currentLevel < this.levels.length) {
  11681. level = this.levels[currentLevel];
  11682. var index = i + j * level.width;
  11683. if (level.items[index] !== undefined) {
  11684. value = level.items[index];
  11685. break;
  11686. }
  11687. level.index = index;
  11688. i >>= 1;
  11689. j >>= 1;
  11690. currentLevel++;
  11691. }
  11692. currentLevel--;
  11693. level = this.levels[currentLevel];
  11694. level.items[level.index] = value;
  11695. this.currentLevel = currentLevel;
  11696. delete this.value;
  11697. },
  11698. incrementValue: function TagTree_incrementValue() {
  11699. var level = this.levels[this.currentLevel];
  11700. level.items[level.index]++;
  11701. },
  11702. nextLevel: function TagTree_nextLevel() {
  11703. var currentLevel = this.currentLevel;
  11704. var level = this.levels[currentLevel];
  11705. var value = level.items[level.index];
  11706. currentLevel--;
  11707. if (currentLevel < 0) {
  11708. this.value = value;
  11709. return false;
  11710. }
  11711. this.currentLevel = currentLevel;
  11712. level = this.levels[currentLevel];
  11713. level.items[level.index] = value;
  11714. return true;
  11715. }
  11716. };
  11717. return TagTree;
  11718. })();
  11719. var InclusionTree = (function InclusionTreeClosure() {
  11720. function InclusionTree(width, height, defaultValue) {
  11721. var levelsLength = log2(Math.max(width, height)) + 1;
  11722. this.levels = [];
  11723. for (var i = 0; i < levelsLength; i++) {
  11724. var items = new Uint8Array(width * height);
  11725. for (var j = 0, jj = items.length; j < jj; j++) {
  11726. items[j] = defaultValue;
  11727. }
  11728. var level = {
  11729. width: width,
  11730. height: height,
  11731. items: items
  11732. };
  11733. this.levels.push(level);
  11734. width = Math.ceil(width / 2);
  11735. height = Math.ceil(height / 2);
  11736. }
  11737. }
  11738. InclusionTree.prototype = {
  11739. reset: function InclusionTree_reset(i, j, stopValue) {
  11740. var currentLevel = 0;
  11741. while (currentLevel < this.levels.length) {
  11742. var level = this.levels[currentLevel];
  11743. var index = i + j * level.width;
  11744. level.index = index;
  11745. var value = level.items[index];
  11746. if (value === 0xFF) {
  11747. break;
  11748. }
  11749. if (value > stopValue) {
  11750. this.currentLevel = currentLevel;
  11751. // already know about this one, propagating the value to top levels
  11752. this.propagateValues();
  11753. return false;
  11754. }
  11755. i >>= 1;
  11756. j >>= 1;
  11757. currentLevel++;
  11758. }
  11759. this.currentLevel = currentLevel - 1;
  11760. return true;
  11761. },
  11762. incrementValue: function InclusionTree_incrementValue(stopValue) {
  11763. var level = this.levels[this.currentLevel];
  11764. level.items[level.index] = stopValue + 1;
  11765. this.propagateValues();
  11766. },
  11767. propagateValues: function InclusionTree_propagateValues() {
  11768. var levelIndex = this.currentLevel;
  11769. var level = this.levels[levelIndex];
  11770. var currentValue = level.items[level.index];
  11771. while (--levelIndex >= 0) {
  11772. level = this.levels[levelIndex];
  11773. level.items[level.index] = currentValue;
  11774. }
  11775. },
  11776. nextLevel: function InclusionTree_nextLevel() {
  11777. var currentLevel = this.currentLevel;
  11778. var level = this.levels[currentLevel];
  11779. var value = level.items[level.index];
  11780. level.items[level.index] = 0xFF;
  11781. currentLevel--;
  11782. if (currentLevel < 0) {
  11783. return false;
  11784. }
  11785. this.currentLevel = currentLevel;
  11786. level = this.levels[currentLevel];
  11787. level.items[level.index] = value;
  11788. return true;
  11789. }
  11790. };
  11791. return InclusionTree;
  11792. })();
  11793. // Section D. Coefficient bit modeling
  11794. var BitModel = (function BitModelClosure() {
  11795. var UNIFORM_CONTEXT = 17;
  11796. var RUNLENGTH_CONTEXT = 18;
  11797. // Table D-1
  11798. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  11799. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  11800. var LLAndLHContextsLabel = new Uint8Array([
  11801. 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,
  11802. 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,
  11803. 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
  11804. ]);
  11805. var HLContextLabel = new Uint8Array([
  11806. 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,
  11807. 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,
  11808. 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
  11809. ]);
  11810. var HHContextLabel = new Uint8Array([
  11811. 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,
  11812. 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,
  11813. 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
  11814. ]);
  11815. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  11816. this.width = width;
  11817. this.height = height;
  11818. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  11819. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  11820. var coefficientCount = width * height;
  11821. // coefficients outside the encoding region treated as insignificant
  11822. // add border state cells for significanceState
  11823. this.neighborsSignificance = new Uint8Array(coefficientCount);
  11824. this.coefficentsSign = new Uint8Array(coefficientCount);
  11825. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  11826. mb > 6 ? new Uint16Array(coefficientCount) :
  11827. new Uint8Array(coefficientCount);
  11828. this.processingFlags = new Uint8Array(coefficientCount);
  11829. var bitsDecoded = new Uint8Array(coefficientCount);
  11830. if (zeroBitPlanes !== 0) {
  11831. for (var i = 0; i < coefficientCount; i++) {
  11832. bitsDecoded[i] = zeroBitPlanes;
  11833. }
  11834. }
  11835. this.bitsDecoded = bitsDecoded;
  11836. this.reset();
  11837. }
  11838. BitModel.prototype = {
  11839. setDecoder: function BitModel_setDecoder(decoder) {
  11840. this.decoder = decoder;
  11841. },
  11842. reset: function BitModel_reset() {
  11843. // We have 17 contexts that are accessed via context labels,
  11844. // plus the uniform and runlength context.
  11845. this.contexts = new Int8Array(19);
  11846. // Contexts are packed into 1 byte:
  11847. // highest 7 bits carry the index, lowest bit carries mps
  11848. this.contexts[0] = (4 << 1) | 0;
  11849. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  11850. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  11851. },
  11852. setNeighborsSignificance:
  11853. function BitModel_setNeighborsSignificance(row, column, index) {
  11854. var neighborsSignificance = this.neighborsSignificance;
  11855. var width = this.width, height = this.height;
  11856. var left = (column > 0);
  11857. var right = (column + 1 < width);
  11858. var i;
  11859. if (row > 0) {
  11860. i = index - width;
  11861. if (left) {
  11862. neighborsSignificance[i - 1] += 0x10;
  11863. }
  11864. if (right) {
  11865. neighborsSignificance[i + 1] += 0x10;
  11866. }
  11867. neighborsSignificance[i] += 0x04;
  11868. }
  11869. if (row + 1 < height) {
  11870. i = index + width;
  11871. if (left) {
  11872. neighborsSignificance[i - 1] += 0x10;
  11873. }
  11874. if (right) {
  11875. neighborsSignificance[i + 1] += 0x10;
  11876. }
  11877. neighborsSignificance[i] += 0x04;
  11878. }
  11879. if (left) {
  11880. neighborsSignificance[index - 1] += 0x01;
  11881. }
  11882. if (right) {
  11883. neighborsSignificance[index + 1] += 0x01;
  11884. }
  11885. neighborsSignificance[index] |= 0x80;
  11886. },
  11887. runSignificancePropogationPass:
  11888. function BitModel_runSignificancePropogationPass() {
  11889. var decoder = this.decoder;
  11890. var width = this.width, height = this.height;
  11891. var coefficentsMagnitude = this.coefficentsMagnitude;
  11892. var coefficentsSign = this.coefficentsSign;
  11893. var neighborsSignificance = this.neighborsSignificance;
  11894. var processingFlags = this.processingFlags;
  11895. var contexts = this.contexts;
  11896. var labels = this.contextLabelTable;
  11897. var bitsDecoded = this.bitsDecoded;
  11898. var processedInverseMask = ~1;
  11899. var processedMask = 1;
  11900. var firstMagnitudeBitMask = 2;
  11901. for (var i0 = 0; i0 < height; i0 += 4) {
  11902. for (var j = 0; j < width; j++) {
  11903. var index = i0 * width + j;
  11904. for (var i1 = 0; i1 < 4; i1++, index += width) {
  11905. var i = i0 + i1;
  11906. if (i >= height) {
  11907. break;
  11908. }
  11909. // clear processed flag first
  11910. processingFlags[index] &= processedInverseMask;
  11911. if (coefficentsMagnitude[index] ||
  11912. !neighborsSignificance[index]) {
  11913. continue;
  11914. }
  11915. var contextLabel = labels[neighborsSignificance[index]];
  11916. var decision = decoder.readBit(contexts, contextLabel);
  11917. if (decision) {
  11918. var sign = this.decodeSignBit(i, j, index);
  11919. coefficentsSign[index] = sign;
  11920. coefficentsMagnitude[index] = 1;
  11921. this.setNeighborsSignificance(i, j, index);
  11922. processingFlags[index] |= firstMagnitudeBitMask;
  11923. }
  11924. bitsDecoded[index]++;
  11925. processingFlags[index] |= processedMask;
  11926. }
  11927. }
  11928. }
  11929. },
  11930. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  11931. var width = this.width, height = this.height;
  11932. var coefficentsMagnitude = this.coefficentsMagnitude;
  11933. var coefficentsSign = this.coefficentsSign;
  11934. var contribution, sign0, sign1, significance1;
  11935. var contextLabel, decoded;
  11936. // calculate horizontal contribution
  11937. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  11938. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  11939. sign1 = coefficentsSign[index + 1];
  11940. if (significance1) {
  11941. sign0 = coefficentsSign[index - 1];
  11942. contribution = 1 - sign1 - sign0;
  11943. } else {
  11944. contribution = 1 - sign1 - sign1;
  11945. }
  11946. } else if (significance1) {
  11947. sign0 = coefficentsSign[index - 1];
  11948. contribution = 1 - sign0 - sign0;
  11949. } else {
  11950. contribution = 0;
  11951. }
  11952. var horizontalContribution = 3 * contribution;
  11953. // calculate vertical contribution and combine with the horizontal
  11954. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  11955. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  11956. sign1 = coefficentsSign[index + width];
  11957. if (significance1) {
  11958. sign0 = coefficentsSign[index - width];
  11959. contribution = 1 - sign1 - sign0 + horizontalContribution;
  11960. } else {
  11961. contribution = 1 - sign1 - sign1 + horizontalContribution;
  11962. }
  11963. } else if (significance1) {
  11964. sign0 = coefficentsSign[index - width];
  11965. contribution = 1 - sign0 - sign0 + horizontalContribution;
  11966. } else {
  11967. contribution = horizontalContribution;
  11968. }
  11969. if (contribution >= 0) {
  11970. contextLabel = 9 + contribution;
  11971. decoded = this.decoder.readBit(this.contexts, contextLabel);
  11972. } else {
  11973. contextLabel = 9 - contribution;
  11974. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  11975. }
  11976. return decoded;
  11977. },
  11978. runMagnitudeRefinementPass:
  11979. function BitModel_runMagnitudeRefinementPass() {
  11980. var decoder = this.decoder;
  11981. var width = this.width, height = this.height;
  11982. var coefficentsMagnitude = this.coefficentsMagnitude;
  11983. var neighborsSignificance = this.neighborsSignificance;
  11984. var contexts = this.contexts;
  11985. var bitsDecoded = this.bitsDecoded;
  11986. var processingFlags = this.processingFlags;
  11987. var processedMask = 1;
  11988. var firstMagnitudeBitMask = 2;
  11989. var length = width * height;
  11990. var width4 = width * 4;
  11991. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  11992. indexNext = Math.min(length, index0 + width4);
  11993. for (var j = 0; j < width; j++) {
  11994. for (var index = index0 + j; index < indexNext; index += width) {
  11995. // significant but not those that have just become
  11996. if (!coefficentsMagnitude[index] ||
  11997. (processingFlags[index] & processedMask) !== 0) {
  11998. continue;
  11999. }
  12000. var contextLabel = 16;
  12001. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  12002. processingFlags[index] ^= firstMagnitudeBitMask;
  12003. // first refinement
  12004. var significance = neighborsSignificance[index] & 127;
  12005. contextLabel = significance === 0 ? 15 : 14;
  12006. }
  12007. var bit = decoder.readBit(contexts, contextLabel);
  12008. coefficentsMagnitude[index] =
  12009. (coefficentsMagnitude[index] << 1) | bit;
  12010. bitsDecoded[index]++;
  12011. processingFlags[index] |= processedMask;
  12012. }
  12013. }
  12014. }
  12015. },
  12016. runCleanupPass: function BitModel_runCleanupPass() {
  12017. var decoder = this.decoder;
  12018. var width = this.width, height = this.height;
  12019. var neighborsSignificance = this.neighborsSignificance;
  12020. var coefficentsMagnitude = this.coefficentsMagnitude;
  12021. var coefficentsSign = this.coefficentsSign;
  12022. var contexts = this.contexts;
  12023. var labels = this.contextLabelTable;
  12024. var bitsDecoded = this.bitsDecoded;
  12025. var processingFlags = this.processingFlags;
  12026. var processedMask = 1;
  12027. var firstMagnitudeBitMask = 2;
  12028. var oneRowDown = width;
  12029. var twoRowsDown = width * 2;
  12030. var threeRowsDown = width * 3;
  12031. var iNext;
  12032. for (var i0 = 0; i0 < height; i0 = iNext) {
  12033. iNext = Math.min(i0 + 4, height);
  12034. var indexBase = i0 * width;
  12035. var checkAllEmpty = i0 + 3 < height;
  12036. for (var j = 0; j < width; j++) {
  12037. var index0 = indexBase + j;
  12038. // using the property: labels[neighborsSignificance[index]] === 0
  12039. // when neighborsSignificance[index] === 0
  12040. var allEmpty = (checkAllEmpty &&
  12041. processingFlags[index0] === 0 &&
  12042. processingFlags[index0 + oneRowDown] === 0 &&
  12043. processingFlags[index0 + twoRowsDown] === 0 &&
  12044. processingFlags[index0 + threeRowsDown] === 0 &&
  12045. neighborsSignificance[index0] === 0 &&
  12046. neighborsSignificance[index0 + oneRowDown] === 0 &&
  12047. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  12048. neighborsSignificance[index0 + threeRowsDown] === 0);
  12049. var i1 = 0, index = index0;
  12050. var i = i0, sign;
  12051. if (allEmpty) {
  12052. var hasSignificantCoefficent =
  12053. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  12054. if (!hasSignificantCoefficent) {
  12055. bitsDecoded[index0]++;
  12056. bitsDecoded[index0 + oneRowDown]++;
  12057. bitsDecoded[index0 + twoRowsDown]++;
  12058. bitsDecoded[index0 + threeRowsDown]++;
  12059. continue; // next column
  12060. }
  12061. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  12062. decoder.readBit(contexts, UNIFORM_CONTEXT);
  12063. if (i1 !== 0) {
  12064. i = i0 + i1;
  12065. index += i1 * width;
  12066. }
  12067. sign = this.decodeSignBit(i, j, index);
  12068. coefficentsSign[index] = sign;
  12069. coefficentsMagnitude[index] = 1;
  12070. this.setNeighborsSignificance(i, j, index);
  12071. processingFlags[index] |= firstMagnitudeBitMask;
  12072. index = index0;
  12073. for (var i2 = i0; i2 <= i; i2++, index += width) {
  12074. bitsDecoded[index]++;
  12075. }
  12076. i1++;
  12077. }
  12078. for (i = i0 + i1; i < iNext; i++, index += width) {
  12079. if (coefficentsMagnitude[index] ||
  12080. (processingFlags[index] & processedMask) !== 0) {
  12081. continue;
  12082. }
  12083. var contextLabel = labels[neighborsSignificance[index]];
  12084. var decision = decoder.readBit(contexts, contextLabel);
  12085. if (decision === 1) {
  12086. sign = this.decodeSignBit(i, j, index);
  12087. coefficentsSign[index] = sign;
  12088. coefficentsMagnitude[index] = 1;
  12089. this.setNeighborsSignificance(i, j, index);
  12090. processingFlags[index] |= firstMagnitudeBitMask;
  12091. }
  12092. bitsDecoded[index]++;
  12093. }
  12094. }
  12095. }
  12096. },
  12097. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  12098. var decoder = this.decoder;
  12099. var contexts = this.contexts;
  12100. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  12101. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  12102. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  12103. decoder.readBit(contexts, UNIFORM_CONTEXT);
  12104. if (symbol !== 0xA) {
  12105. throw new Error('JPX Error: Invalid segmentation symbol');
  12106. }
  12107. }
  12108. };
  12109. return BitModel;
  12110. })();
  12111. // Section F, Discrete wavelet transformation
  12112. var Transform = (function TransformClosure() {
  12113. function Transform() {}
  12114. Transform.prototype.calculate =
  12115. function transformCalculate(subbands, u0, v0) {
  12116. var ll = subbands[0];
  12117. for (var i = 1, ii = subbands.length; i < ii; i++) {
  12118. ll = this.iterate(ll, subbands[i], u0, v0);
  12119. }
  12120. return ll;
  12121. };
  12122. Transform.prototype.extend = function extend(buffer, offset, size) {
  12123. // Section F.3.7 extending... using max extension of 4
  12124. var i1 = offset - 1, j1 = offset + 1;
  12125. var i2 = offset + size - 2, j2 = offset + size;
  12126. buffer[i1--] = buffer[j1++];
  12127. buffer[j2++] = buffer[i2--];
  12128. buffer[i1--] = buffer[j1++];
  12129. buffer[j2++] = buffer[i2--];
  12130. buffer[i1--] = buffer[j1++];
  12131. buffer[j2++] = buffer[i2--];
  12132. buffer[i1] = buffer[j1];
  12133. buffer[j2] = buffer[i2];
  12134. };
  12135. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  12136. u0, v0) {
  12137. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  12138. var width = hl_lh_hh.width;
  12139. var height = hl_lh_hh.height;
  12140. var items = hl_lh_hh.items;
  12141. var i, j, k, l, u, v;
  12142. // Interleave LL according to Section F.3.3
  12143. for (k = 0, i = 0; i < llHeight; i++) {
  12144. l = i * 2 * width;
  12145. for (j = 0; j < llWidth; j++, k++, l += 2) {
  12146. items[l] = llItems[k];
  12147. }
  12148. }
  12149. // The LL band is not needed anymore.
  12150. llItems = ll.items = null;
  12151. var bufferPadding = 4;
  12152. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  12153. // Section F.3.4 HOR_SR
  12154. if (width === 1) {
  12155. // if width = 1, when u0 even keep items as is, when odd divide by 2
  12156. if ((u0 & 1) !== 0) {
  12157. for (v = 0, k = 0; v < height; v++, k += width) {
  12158. items[k] *= 0.5;
  12159. }
  12160. }
  12161. } else {
  12162. for (v = 0, k = 0; v < height; v++, k += width) {
  12163. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  12164. this.extend(rowBuffer, bufferPadding, width);
  12165. this.filter(rowBuffer, bufferPadding, width);
  12166. items.set(
  12167. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  12168. k);
  12169. }
  12170. }
  12171. // Accesses to the items array can take long, because it may not fit into
  12172. // CPU cache and has to be fetched from main memory. Since subsequent
  12173. // accesses to the items array are not local when reading columns, we
  12174. // have a cache miss every time. To reduce cache misses, get up to
  12175. // 'numBuffers' items at a time and store them into the individual
  12176. // buffers. The colBuffers should be small enough to fit into CPU cache.
  12177. var numBuffers = 16;
  12178. var colBuffers = [];
  12179. for (i = 0; i < numBuffers; i++) {
  12180. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  12181. }
  12182. var b, currentBuffer = 0;
  12183. ll = bufferPadding + height;
  12184. // Section F.3.5 VER_SR
  12185. if (height === 1) {
  12186. // if height = 1, when v0 even keep items as is, when odd divide by 2
  12187. if ((v0 & 1) !== 0) {
  12188. for (u = 0; u < width; u++) {
  12189. items[u] *= 0.5;
  12190. }
  12191. }
  12192. } else {
  12193. for (u = 0; u < width; u++) {
  12194. // if we ran out of buffers, copy several image columns at once
  12195. if (currentBuffer === 0) {
  12196. numBuffers = Math.min(width - u, numBuffers);
  12197. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  12198. for (b = 0; b < numBuffers; b++) {
  12199. colBuffers[b][l] = items[k + b];
  12200. }
  12201. }
  12202. currentBuffer = numBuffers;
  12203. }
  12204. currentBuffer--;
  12205. var buffer = colBuffers[currentBuffer];
  12206. this.extend(buffer, bufferPadding, height);
  12207. this.filter(buffer, bufferPadding, height);
  12208. // If this is last buffer in this group of buffers, flush all buffers.
  12209. if (currentBuffer === 0) {
  12210. k = u - numBuffers + 1;
  12211. for (l = bufferPadding; l < ll; k += width, l++) {
  12212. for (b = 0; b < numBuffers; b++) {
  12213. items[k + b] = colBuffers[b][l];
  12214. }
  12215. }
  12216. }
  12217. }
  12218. }
  12219. return {
  12220. width: width,
  12221. height: height,
  12222. items: items
  12223. };
  12224. };
  12225. return Transform;
  12226. })();
  12227. // Section 3.8.2 Irreversible 9-7 filter
  12228. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  12229. function IrreversibleTransform() {
  12230. Transform.call(this);
  12231. }
  12232. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  12233. IrreversibleTransform.prototype.filter =
  12234. function irreversibleTransformFilter(x, offset, length) {
  12235. var len = length >> 1;
  12236. offset = offset | 0;
  12237. var j, n, current, next;
  12238. var alpha = -1.586134342059924;
  12239. var beta = -0.052980118572961;
  12240. var gamma = 0.882911075530934;
  12241. var delta = 0.443506852043971;
  12242. var K = 1.230174104914001;
  12243. var K_ = 1 / K;
  12244. // step 1 is combined with step 3
  12245. // step 2
  12246. j = offset - 3;
  12247. for (n = len + 4; n--; j += 2) {
  12248. x[j] *= K_;
  12249. }
  12250. // step 1 & 3
  12251. j = offset - 2;
  12252. current = delta * x[j -1];
  12253. for (n = len + 3; n--; j += 2) {
  12254. next = delta * x[j + 1];
  12255. x[j] = K * x[j] - current - next;
  12256. if (n--) {
  12257. j += 2;
  12258. current = delta * x[j + 1];
  12259. x[j] = K * x[j] - current - next;
  12260. } else {
  12261. break;
  12262. }
  12263. }
  12264. // step 4
  12265. j = offset - 1;
  12266. current = gamma * x[j - 1];
  12267. for (n = len + 2; n--; j += 2) {
  12268. next = gamma * x[j + 1];
  12269. x[j] -= current + next;
  12270. if (n--) {
  12271. j += 2;
  12272. current = gamma * x[j + 1];
  12273. x[j] -= current + next;
  12274. } else {
  12275. break;
  12276. }
  12277. }
  12278. // step 5
  12279. j = offset;
  12280. current = beta * x[j - 1];
  12281. for (n = len + 1; n--; j += 2) {
  12282. next = beta * x[j + 1];
  12283. x[j] -= current + next;
  12284. if (n--) {
  12285. j += 2;
  12286. current = beta * x[j + 1];
  12287. x[j] -= current + next;
  12288. } else {
  12289. break;
  12290. }
  12291. }
  12292. // step 6
  12293. if (len !== 0) {
  12294. j = offset + 1;
  12295. current = alpha * x[j - 1];
  12296. for (n = len; n--; j += 2) {
  12297. next = alpha * x[j + 1];
  12298. x[j] -= current + next;
  12299. if (n--) {
  12300. j += 2;
  12301. current = alpha * x[j + 1];
  12302. x[j] -= current + next;
  12303. } else {
  12304. break;
  12305. }
  12306. }
  12307. }
  12308. };
  12309. return IrreversibleTransform;
  12310. })();
  12311. // Section 3.8.1 Reversible 5-3 filter
  12312. var ReversibleTransform = (function ReversibleTransformClosure() {
  12313. function ReversibleTransform() {
  12314. Transform.call(this);
  12315. }
  12316. ReversibleTransform.prototype = Object.create(Transform.prototype);
  12317. ReversibleTransform.prototype.filter =
  12318. function reversibleTransformFilter(x, offset, length) {
  12319. var len = length >> 1;
  12320. offset = offset | 0;
  12321. var j, n;
  12322. for (j = offset, n = len + 1; n--; j += 2) {
  12323. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  12324. }
  12325. for (j = offset + 1, n = len; n--; j += 2) {
  12326. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  12327. }
  12328. };
  12329. return ReversibleTransform;
  12330. })();
  12331. return JpxImage;
  12332. })();
  12333. exports.JpxImage = JpxImage;
  12334. }));
  12335. (function (root, factory) {
  12336. {
  12337. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  12338. }
  12339. }(this, function (exports, sharedUtil) {
  12340. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  12341. // The Metrics object contains glyph widths (in glyph space units).
  12342. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  12343. // space unit corresponds to 1/1000th of text space unit.
  12344. var getMetrics = getLookupTableFactory(function (t) {
  12345. t['Courier'] = 600;
  12346. t['Courier-Bold'] = 600;
  12347. t['Courier-BoldOblique'] = 600;
  12348. t['Courier-Oblique'] = 600;
  12349. t['Helvetica'] = getLookupTableFactory(function (t) {
  12350. t['space'] = 278;
  12351. t['exclam'] = 278;
  12352. t['quotedbl'] = 355;
  12353. t['numbersign'] = 556;
  12354. t['dollar'] = 556;
  12355. t['percent'] = 889;
  12356. t['ampersand'] = 667;
  12357. t['quoteright'] = 222;
  12358. t['parenleft'] = 333;
  12359. t['parenright'] = 333;
  12360. t['asterisk'] = 389;
  12361. t['plus'] = 584;
  12362. t['comma'] = 278;
  12363. t['hyphen'] = 333;
  12364. t['period'] = 278;
  12365. t['slash'] = 278;
  12366. t['zero'] = 556;
  12367. t['one'] = 556;
  12368. t['two'] = 556;
  12369. t['three'] = 556;
  12370. t['four'] = 556;
  12371. t['five'] = 556;
  12372. t['six'] = 556;
  12373. t['seven'] = 556;
  12374. t['eight'] = 556;
  12375. t['nine'] = 556;
  12376. t['colon'] = 278;
  12377. t['semicolon'] = 278;
  12378. t['less'] = 584;
  12379. t['equal'] = 584;
  12380. t['greater'] = 584;
  12381. t['question'] = 556;
  12382. t['at'] = 1015;
  12383. t['A'] = 667;
  12384. t['B'] = 667;
  12385. t['C'] = 722;
  12386. t['D'] = 722;
  12387. t['E'] = 667;
  12388. t['F'] = 611;
  12389. t['G'] = 778;
  12390. t['H'] = 722;
  12391. t['I'] = 278;
  12392. t['J'] = 500;
  12393. t['K'] = 667;
  12394. t['L'] = 556;
  12395. t['M'] = 833;
  12396. t['N'] = 722;
  12397. t['O'] = 778;
  12398. t['P'] = 667;
  12399. t['Q'] = 778;
  12400. t['R'] = 722;
  12401. t['S'] = 667;
  12402. t['T'] = 611;
  12403. t['U'] = 722;
  12404. t['V'] = 667;
  12405. t['W'] = 944;
  12406. t['X'] = 667;
  12407. t['Y'] = 667;
  12408. t['Z'] = 611;
  12409. t['bracketleft'] = 278;
  12410. t['backslash'] = 278;
  12411. t['bracketright'] = 278;
  12412. t['asciicircum'] = 469;
  12413. t['underscore'] = 556;
  12414. t['quoteleft'] = 222;
  12415. t['a'] = 556;
  12416. t['b'] = 556;
  12417. t['c'] = 500;
  12418. t['d'] = 556;
  12419. t['e'] = 556;
  12420. t['f'] = 278;
  12421. t['g'] = 556;
  12422. t['h'] = 556;
  12423. t['i'] = 222;
  12424. t['j'] = 222;
  12425. t['k'] = 500;
  12426. t['l'] = 222;
  12427. t['m'] = 833;
  12428. t['n'] = 556;
  12429. t['o'] = 556;
  12430. t['p'] = 556;
  12431. t['q'] = 556;
  12432. t['r'] = 333;
  12433. t['s'] = 500;
  12434. t['t'] = 278;
  12435. t['u'] = 556;
  12436. t['v'] = 500;
  12437. t['w'] = 722;
  12438. t['x'] = 500;
  12439. t['y'] = 500;
  12440. t['z'] = 500;
  12441. t['braceleft'] = 334;
  12442. t['bar'] = 260;
  12443. t['braceright'] = 334;
  12444. t['asciitilde'] = 584;
  12445. t['exclamdown'] = 333;
  12446. t['cent'] = 556;
  12447. t['sterling'] = 556;
  12448. t['fraction'] = 167;
  12449. t['yen'] = 556;
  12450. t['florin'] = 556;
  12451. t['section'] = 556;
  12452. t['currency'] = 556;
  12453. t['quotesingle'] = 191;
  12454. t['quotedblleft'] = 333;
  12455. t['guillemotleft'] = 556;
  12456. t['guilsinglleft'] = 333;
  12457. t['guilsinglright'] = 333;
  12458. t['fi'] = 500;
  12459. t['fl'] = 500;
  12460. t['endash'] = 556;
  12461. t['dagger'] = 556;
  12462. t['daggerdbl'] = 556;
  12463. t['periodcentered'] = 278;
  12464. t['paragraph'] = 537;
  12465. t['bullet'] = 350;
  12466. t['quotesinglbase'] = 222;
  12467. t['quotedblbase'] = 333;
  12468. t['quotedblright'] = 333;
  12469. t['guillemotright'] = 556;
  12470. t['ellipsis'] = 1000;
  12471. t['perthousand'] = 1000;
  12472. t['questiondown'] = 611;
  12473. t['grave'] = 333;
  12474. t['acute'] = 333;
  12475. t['circumflex'] = 333;
  12476. t['tilde'] = 333;
  12477. t['macron'] = 333;
  12478. t['breve'] = 333;
  12479. t['dotaccent'] = 333;
  12480. t['dieresis'] = 333;
  12481. t['ring'] = 333;
  12482. t['cedilla'] = 333;
  12483. t['hungarumlaut'] = 333;
  12484. t['ogonek'] = 333;
  12485. t['caron'] = 333;
  12486. t['emdash'] = 1000;
  12487. t['AE'] = 1000;
  12488. t['ordfeminine'] = 370;
  12489. t['Lslash'] = 556;
  12490. t['Oslash'] = 778;
  12491. t['OE'] = 1000;
  12492. t['ordmasculine'] = 365;
  12493. t['ae'] = 889;
  12494. t['dotlessi'] = 278;
  12495. t['lslash'] = 222;
  12496. t['oslash'] = 611;
  12497. t['oe'] = 944;
  12498. t['germandbls'] = 611;
  12499. t['Idieresis'] = 278;
  12500. t['eacute'] = 556;
  12501. t['abreve'] = 556;
  12502. t['uhungarumlaut'] = 556;
  12503. t['ecaron'] = 556;
  12504. t['Ydieresis'] = 667;
  12505. t['divide'] = 584;
  12506. t['Yacute'] = 667;
  12507. t['Acircumflex'] = 667;
  12508. t['aacute'] = 556;
  12509. t['Ucircumflex'] = 722;
  12510. t['yacute'] = 500;
  12511. t['scommaaccent'] = 500;
  12512. t['ecircumflex'] = 556;
  12513. t['Uring'] = 722;
  12514. t['Udieresis'] = 722;
  12515. t['aogonek'] = 556;
  12516. t['Uacute'] = 722;
  12517. t['uogonek'] = 556;
  12518. t['Edieresis'] = 667;
  12519. t['Dcroat'] = 722;
  12520. t['commaaccent'] = 250;
  12521. t['copyright'] = 737;
  12522. t['Emacron'] = 667;
  12523. t['ccaron'] = 500;
  12524. t['aring'] = 556;
  12525. t['Ncommaaccent'] = 722;
  12526. t['lacute'] = 222;
  12527. t['agrave'] = 556;
  12528. t['Tcommaaccent'] = 611;
  12529. t['Cacute'] = 722;
  12530. t['atilde'] = 556;
  12531. t['Edotaccent'] = 667;
  12532. t['scaron'] = 500;
  12533. t['scedilla'] = 500;
  12534. t['iacute'] = 278;
  12535. t['lozenge'] = 471;
  12536. t['Rcaron'] = 722;
  12537. t['Gcommaaccent'] = 778;
  12538. t['ucircumflex'] = 556;
  12539. t['acircumflex'] = 556;
  12540. t['Amacron'] = 667;
  12541. t['rcaron'] = 333;
  12542. t['ccedilla'] = 500;
  12543. t['Zdotaccent'] = 611;
  12544. t['Thorn'] = 667;
  12545. t['Omacron'] = 778;
  12546. t['Racute'] = 722;
  12547. t['Sacute'] = 667;
  12548. t['dcaron'] = 643;
  12549. t['Umacron'] = 722;
  12550. t['uring'] = 556;
  12551. t['threesuperior'] = 333;
  12552. t['Ograve'] = 778;
  12553. t['Agrave'] = 667;
  12554. t['Abreve'] = 667;
  12555. t['multiply'] = 584;
  12556. t['uacute'] = 556;
  12557. t['Tcaron'] = 611;
  12558. t['partialdiff'] = 476;
  12559. t['ydieresis'] = 500;
  12560. t['Nacute'] = 722;
  12561. t['icircumflex'] = 278;
  12562. t['Ecircumflex'] = 667;
  12563. t['adieresis'] = 556;
  12564. t['edieresis'] = 556;
  12565. t['cacute'] = 500;
  12566. t['nacute'] = 556;
  12567. t['umacron'] = 556;
  12568. t['Ncaron'] = 722;
  12569. t['Iacute'] = 278;
  12570. t['plusminus'] = 584;
  12571. t['brokenbar'] = 260;
  12572. t['registered'] = 737;
  12573. t['Gbreve'] = 778;
  12574. t['Idotaccent'] = 278;
  12575. t['summation'] = 600;
  12576. t['Egrave'] = 667;
  12577. t['racute'] = 333;
  12578. t['omacron'] = 556;
  12579. t['Zacute'] = 611;
  12580. t['Zcaron'] = 611;
  12581. t['greaterequal'] = 549;
  12582. t['Eth'] = 722;
  12583. t['Ccedilla'] = 722;
  12584. t['lcommaaccent'] = 222;
  12585. t['tcaron'] = 317;
  12586. t['eogonek'] = 556;
  12587. t['Uogonek'] = 722;
  12588. t['Aacute'] = 667;
  12589. t['Adieresis'] = 667;
  12590. t['egrave'] = 556;
  12591. t['zacute'] = 500;
  12592. t['iogonek'] = 222;
  12593. t['Oacute'] = 778;
  12594. t['oacute'] = 556;
  12595. t['amacron'] = 556;
  12596. t['sacute'] = 500;
  12597. t['idieresis'] = 278;
  12598. t['Ocircumflex'] = 778;
  12599. t['Ugrave'] = 722;
  12600. t['Delta'] = 612;
  12601. t['thorn'] = 556;
  12602. t['twosuperior'] = 333;
  12603. t['Odieresis'] = 778;
  12604. t['mu'] = 556;
  12605. t['igrave'] = 278;
  12606. t['ohungarumlaut'] = 556;
  12607. t['Eogonek'] = 667;
  12608. t['dcroat'] = 556;
  12609. t['threequarters'] = 834;
  12610. t['Scedilla'] = 667;
  12611. t['lcaron'] = 299;
  12612. t['Kcommaaccent'] = 667;
  12613. t['Lacute'] = 556;
  12614. t['trademark'] = 1000;
  12615. t['edotaccent'] = 556;
  12616. t['Igrave'] = 278;
  12617. t['Imacron'] = 278;
  12618. t['Lcaron'] = 556;
  12619. t['onehalf'] = 834;
  12620. t['lessequal'] = 549;
  12621. t['ocircumflex'] = 556;
  12622. t['ntilde'] = 556;
  12623. t['Uhungarumlaut'] = 722;
  12624. t['Eacute'] = 667;
  12625. t['emacron'] = 556;
  12626. t['gbreve'] = 556;
  12627. t['onequarter'] = 834;
  12628. t['Scaron'] = 667;
  12629. t['Scommaaccent'] = 667;
  12630. t['Ohungarumlaut'] = 778;
  12631. t['degree'] = 400;
  12632. t['ograve'] = 556;
  12633. t['Ccaron'] = 722;
  12634. t['ugrave'] = 556;
  12635. t['radical'] = 453;
  12636. t['Dcaron'] = 722;
  12637. t['rcommaaccent'] = 333;
  12638. t['Ntilde'] = 722;
  12639. t['otilde'] = 556;
  12640. t['Rcommaaccent'] = 722;
  12641. t['Lcommaaccent'] = 556;
  12642. t['Atilde'] = 667;
  12643. t['Aogonek'] = 667;
  12644. t['Aring'] = 667;
  12645. t['Otilde'] = 778;
  12646. t['zdotaccent'] = 500;
  12647. t['Ecaron'] = 667;
  12648. t['Iogonek'] = 278;
  12649. t['kcommaaccent'] = 500;
  12650. t['minus'] = 584;
  12651. t['Icircumflex'] = 278;
  12652. t['ncaron'] = 556;
  12653. t['tcommaaccent'] = 278;
  12654. t['logicalnot'] = 584;
  12655. t['odieresis'] = 556;
  12656. t['udieresis'] = 556;
  12657. t['notequal'] = 549;
  12658. t['gcommaaccent'] = 556;
  12659. t['eth'] = 556;
  12660. t['zcaron'] = 500;
  12661. t['ncommaaccent'] = 556;
  12662. t['onesuperior'] = 333;
  12663. t['imacron'] = 278;
  12664. t['Euro'] = 556;
  12665. });
  12666. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  12667. t['space'] = 278;
  12668. t['exclam'] = 333;
  12669. t['quotedbl'] = 474;
  12670. t['numbersign'] = 556;
  12671. t['dollar'] = 556;
  12672. t['percent'] = 889;
  12673. t['ampersand'] = 722;
  12674. t['quoteright'] = 278;
  12675. t['parenleft'] = 333;
  12676. t['parenright'] = 333;
  12677. t['asterisk'] = 389;
  12678. t['plus'] = 584;
  12679. t['comma'] = 278;
  12680. t['hyphen'] = 333;
  12681. t['period'] = 278;
  12682. t['slash'] = 278;
  12683. t['zero'] = 556;
  12684. t['one'] = 556;
  12685. t['two'] = 556;
  12686. t['three'] = 556;
  12687. t['four'] = 556;
  12688. t['five'] = 556;
  12689. t['six'] = 556;
  12690. t['seven'] = 556;
  12691. t['eight'] = 556;
  12692. t['nine'] = 556;
  12693. t['colon'] = 333;
  12694. t['semicolon'] = 333;
  12695. t['less'] = 584;
  12696. t['equal'] = 584;
  12697. t['greater'] = 584;
  12698. t['question'] = 611;
  12699. t['at'] = 975;
  12700. t['A'] = 722;
  12701. t['B'] = 722;
  12702. t['C'] = 722;
  12703. t['D'] = 722;
  12704. t['E'] = 667;
  12705. t['F'] = 611;
  12706. t['G'] = 778;
  12707. t['H'] = 722;
  12708. t['I'] = 278;
  12709. t['J'] = 556;
  12710. t['K'] = 722;
  12711. t['L'] = 611;
  12712. t['M'] = 833;
  12713. t['N'] = 722;
  12714. t['O'] = 778;
  12715. t['P'] = 667;
  12716. t['Q'] = 778;
  12717. t['R'] = 722;
  12718. t['S'] = 667;
  12719. t['T'] = 611;
  12720. t['U'] = 722;
  12721. t['V'] = 667;
  12722. t['W'] = 944;
  12723. t['X'] = 667;
  12724. t['Y'] = 667;
  12725. t['Z'] = 611;
  12726. t['bracketleft'] = 333;
  12727. t['backslash'] = 278;
  12728. t['bracketright'] = 333;
  12729. t['asciicircum'] = 584;
  12730. t['underscore'] = 556;
  12731. t['quoteleft'] = 278;
  12732. t['a'] = 556;
  12733. t['b'] = 611;
  12734. t['c'] = 556;
  12735. t['d'] = 611;
  12736. t['e'] = 556;
  12737. t['f'] = 333;
  12738. t['g'] = 611;
  12739. t['h'] = 611;
  12740. t['i'] = 278;
  12741. t['j'] = 278;
  12742. t['k'] = 556;
  12743. t['l'] = 278;
  12744. t['m'] = 889;
  12745. t['n'] = 611;
  12746. t['o'] = 611;
  12747. t['p'] = 611;
  12748. t['q'] = 611;
  12749. t['r'] = 389;
  12750. t['s'] = 556;
  12751. t['t'] = 333;
  12752. t['u'] = 611;
  12753. t['v'] = 556;
  12754. t['w'] = 778;
  12755. t['x'] = 556;
  12756. t['y'] = 556;
  12757. t['z'] = 500;
  12758. t['braceleft'] = 389;
  12759. t['bar'] = 280;
  12760. t['braceright'] = 389;
  12761. t['asciitilde'] = 584;
  12762. t['exclamdown'] = 333;
  12763. t['cent'] = 556;
  12764. t['sterling'] = 556;
  12765. t['fraction'] = 167;
  12766. t['yen'] = 556;
  12767. t['florin'] = 556;
  12768. t['section'] = 556;
  12769. t['currency'] = 556;
  12770. t['quotesingle'] = 238;
  12771. t['quotedblleft'] = 500;
  12772. t['guillemotleft'] = 556;
  12773. t['guilsinglleft'] = 333;
  12774. t['guilsinglright'] = 333;
  12775. t['fi'] = 611;
  12776. t['fl'] = 611;
  12777. t['endash'] = 556;
  12778. t['dagger'] = 556;
  12779. t['daggerdbl'] = 556;
  12780. t['periodcentered'] = 278;
  12781. t['paragraph'] = 556;
  12782. t['bullet'] = 350;
  12783. t['quotesinglbase'] = 278;
  12784. t['quotedblbase'] = 500;
  12785. t['quotedblright'] = 500;
  12786. t['guillemotright'] = 556;
  12787. t['ellipsis'] = 1000;
  12788. t['perthousand'] = 1000;
  12789. t['questiondown'] = 611;
  12790. t['grave'] = 333;
  12791. t['acute'] = 333;
  12792. t['circumflex'] = 333;
  12793. t['tilde'] = 333;
  12794. t['macron'] = 333;
  12795. t['breve'] = 333;
  12796. t['dotaccent'] = 333;
  12797. t['dieresis'] = 333;
  12798. t['ring'] = 333;
  12799. t['cedilla'] = 333;
  12800. t['hungarumlaut'] = 333;
  12801. t['ogonek'] = 333;
  12802. t['caron'] = 333;
  12803. t['emdash'] = 1000;
  12804. t['AE'] = 1000;
  12805. t['ordfeminine'] = 370;
  12806. t['Lslash'] = 611;
  12807. t['Oslash'] = 778;
  12808. t['OE'] = 1000;
  12809. t['ordmasculine'] = 365;
  12810. t['ae'] = 889;
  12811. t['dotlessi'] = 278;
  12812. t['lslash'] = 278;
  12813. t['oslash'] = 611;
  12814. t['oe'] = 944;
  12815. t['germandbls'] = 611;
  12816. t['Idieresis'] = 278;
  12817. t['eacute'] = 556;
  12818. t['abreve'] = 556;
  12819. t['uhungarumlaut'] = 611;
  12820. t['ecaron'] = 556;
  12821. t['Ydieresis'] = 667;
  12822. t['divide'] = 584;
  12823. t['Yacute'] = 667;
  12824. t['Acircumflex'] = 722;
  12825. t['aacute'] = 556;
  12826. t['Ucircumflex'] = 722;
  12827. t['yacute'] = 556;
  12828. t['scommaaccent'] = 556;
  12829. t['ecircumflex'] = 556;
  12830. t['Uring'] = 722;
  12831. t['Udieresis'] = 722;
  12832. t['aogonek'] = 556;
  12833. t['Uacute'] = 722;
  12834. t['uogonek'] = 611;
  12835. t['Edieresis'] = 667;
  12836. t['Dcroat'] = 722;
  12837. t['commaaccent'] = 250;
  12838. t['copyright'] = 737;
  12839. t['Emacron'] = 667;
  12840. t['ccaron'] = 556;
  12841. t['aring'] = 556;
  12842. t['Ncommaaccent'] = 722;
  12843. t['lacute'] = 278;
  12844. t['agrave'] = 556;
  12845. t['Tcommaaccent'] = 611;
  12846. t['Cacute'] = 722;
  12847. t['atilde'] = 556;
  12848. t['Edotaccent'] = 667;
  12849. t['scaron'] = 556;
  12850. t['scedilla'] = 556;
  12851. t['iacute'] = 278;
  12852. t['lozenge'] = 494;
  12853. t['Rcaron'] = 722;
  12854. t['Gcommaaccent'] = 778;
  12855. t['ucircumflex'] = 611;
  12856. t['acircumflex'] = 556;
  12857. t['Amacron'] = 722;
  12858. t['rcaron'] = 389;
  12859. t['ccedilla'] = 556;
  12860. t['Zdotaccent'] = 611;
  12861. t['Thorn'] = 667;
  12862. t['Omacron'] = 778;
  12863. t['Racute'] = 722;
  12864. t['Sacute'] = 667;
  12865. t['dcaron'] = 743;
  12866. t['Umacron'] = 722;
  12867. t['uring'] = 611;
  12868. t['threesuperior'] = 333;
  12869. t['Ograve'] = 778;
  12870. t['Agrave'] = 722;
  12871. t['Abreve'] = 722;
  12872. t['multiply'] = 584;
  12873. t['uacute'] = 611;
  12874. t['Tcaron'] = 611;
  12875. t['partialdiff'] = 494;
  12876. t['ydieresis'] = 556;
  12877. t['Nacute'] = 722;
  12878. t['icircumflex'] = 278;
  12879. t['Ecircumflex'] = 667;
  12880. t['adieresis'] = 556;
  12881. t['edieresis'] = 556;
  12882. t['cacute'] = 556;
  12883. t['nacute'] = 611;
  12884. t['umacron'] = 611;
  12885. t['Ncaron'] = 722;
  12886. t['Iacute'] = 278;
  12887. t['plusminus'] = 584;
  12888. t['brokenbar'] = 280;
  12889. t['registered'] = 737;
  12890. t['Gbreve'] = 778;
  12891. t['Idotaccent'] = 278;
  12892. t['summation'] = 600;
  12893. t['Egrave'] = 667;
  12894. t['racute'] = 389;
  12895. t['omacron'] = 611;
  12896. t['Zacute'] = 611;
  12897. t['Zcaron'] = 611;
  12898. t['greaterequal'] = 549;
  12899. t['Eth'] = 722;
  12900. t['Ccedilla'] = 722;
  12901. t['lcommaaccent'] = 278;
  12902. t['tcaron'] = 389;
  12903. t['eogonek'] = 556;
  12904. t['Uogonek'] = 722;
  12905. t['Aacute'] = 722;
  12906. t['Adieresis'] = 722;
  12907. t['egrave'] = 556;
  12908. t['zacute'] = 500;
  12909. t['iogonek'] = 278;
  12910. t['Oacute'] = 778;
  12911. t['oacute'] = 611;
  12912. t['amacron'] = 556;
  12913. t['sacute'] = 556;
  12914. t['idieresis'] = 278;
  12915. t['Ocircumflex'] = 778;
  12916. t['Ugrave'] = 722;
  12917. t['Delta'] = 612;
  12918. t['thorn'] = 611;
  12919. t['twosuperior'] = 333;
  12920. t['Odieresis'] = 778;
  12921. t['mu'] = 611;
  12922. t['igrave'] = 278;
  12923. t['ohungarumlaut'] = 611;
  12924. t['Eogonek'] = 667;
  12925. t['dcroat'] = 611;
  12926. t['threequarters'] = 834;
  12927. t['Scedilla'] = 667;
  12928. t['lcaron'] = 400;
  12929. t['Kcommaaccent'] = 722;
  12930. t['Lacute'] = 611;
  12931. t['trademark'] = 1000;
  12932. t['edotaccent'] = 556;
  12933. t['Igrave'] = 278;
  12934. t['Imacron'] = 278;
  12935. t['Lcaron'] = 611;
  12936. t['onehalf'] = 834;
  12937. t['lessequal'] = 549;
  12938. t['ocircumflex'] = 611;
  12939. t['ntilde'] = 611;
  12940. t['Uhungarumlaut'] = 722;
  12941. t['Eacute'] = 667;
  12942. t['emacron'] = 556;
  12943. t['gbreve'] = 611;
  12944. t['onequarter'] = 834;
  12945. t['Scaron'] = 667;
  12946. t['Scommaaccent'] = 667;
  12947. t['Ohungarumlaut'] = 778;
  12948. t['degree'] = 400;
  12949. t['ograve'] = 611;
  12950. t['Ccaron'] = 722;
  12951. t['ugrave'] = 611;
  12952. t['radical'] = 549;
  12953. t['Dcaron'] = 722;
  12954. t['rcommaaccent'] = 389;
  12955. t['Ntilde'] = 722;
  12956. t['otilde'] = 611;
  12957. t['Rcommaaccent'] = 722;
  12958. t['Lcommaaccent'] = 611;
  12959. t['Atilde'] = 722;
  12960. t['Aogonek'] = 722;
  12961. t['Aring'] = 722;
  12962. t['Otilde'] = 778;
  12963. t['zdotaccent'] = 500;
  12964. t['Ecaron'] = 667;
  12965. t['Iogonek'] = 278;
  12966. t['kcommaaccent'] = 556;
  12967. t['minus'] = 584;
  12968. t['Icircumflex'] = 278;
  12969. t['ncaron'] = 611;
  12970. t['tcommaaccent'] = 333;
  12971. t['logicalnot'] = 584;
  12972. t['odieresis'] = 611;
  12973. t['udieresis'] = 611;
  12974. t['notequal'] = 549;
  12975. t['gcommaaccent'] = 611;
  12976. t['eth'] = 611;
  12977. t['zcaron'] = 500;
  12978. t['ncommaaccent'] = 611;
  12979. t['onesuperior'] = 333;
  12980. t['imacron'] = 278;
  12981. t['Euro'] = 556;
  12982. });
  12983. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  12984. t['space'] = 278;
  12985. t['exclam'] = 333;
  12986. t['quotedbl'] = 474;
  12987. t['numbersign'] = 556;
  12988. t['dollar'] = 556;
  12989. t['percent'] = 889;
  12990. t['ampersand'] = 722;
  12991. t['quoteright'] = 278;
  12992. t['parenleft'] = 333;
  12993. t['parenright'] = 333;
  12994. t['asterisk'] = 389;
  12995. t['plus'] = 584;
  12996. t['comma'] = 278;
  12997. t['hyphen'] = 333;
  12998. t['period'] = 278;
  12999. t['slash'] = 278;
  13000. t['zero'] = 556;
  13001. t['one'] = 556;
  13002. t['two'] = 556;
  13003. t['three'] = 556;
  13004. t['four'] = 556;
  13005. t['five'] = 556;
  13006. t['six'] = 556;
  13007. t['seven'] = 556;
  13008. t['eight'] = 556;
  13009. t['nine'] = 556;
  13010. t['colon'] = 333;
  13011. t['semicolon'] = 333;
  13012. t['less'] = 584;
  13013. t['equal'] = 584;
  13014. t['greater'] = 584;
  13015. t['question'] = 611;
  13016. t['at'] = 975;
  13017. t['A'] = 722;
  13018. t['B'] = 722;
  13019. t['C'] = 722;
  13020. t['D'] = 722;
  13021. t['E'] = 667;
  13022. t['F'] = 611;
  13023. t['G'] = 778;
  13024. t['H'] = 722;
  13025. t['I'] = 278;
  13026. t['J'] = 556;
  13027. t['K'] = 722;
  13028. t['L'] = 611;
  13029. t['M'] = 833;
  13030. t['N'] = 722;
  13031. t['O'] = 778;
  13032. t['P'] = 667;
  13033. t['Q'] = 778;
  13034. t['R'] = 722;
  13035. t['S'] = 667;
  13036. t['T'] = 611;
  13037. t['U'] = 722;
  13038. t['V'] = 667;
  13039. t['W'] = 944;
  13040. t['X'] = 667;
  13041. t['Y'] = 667;
  13042. t['Z'] = 611;
  13043. t['bracketleft'] = 333;
  13044. t['backslash'] = 278;
  13045. t['bracketright'] = 333;
  13046. t['asciicircum'] = 584;
  13047. t['underscore'] = 556;
  13048. t['quoteleft'] = 278;
  13049. t['a'] = 556;
  13050. t['b'] = 611;
  13051. t['c'] = 556;
  13052. t['d'] = 611;
  13053. t['e'] = 556;
  13054. t['f'] = 333;
  13055. t['g'] = 611;
  13056. t['h'] = 611;
  13057. t['i'] = 278;
  13058. t['j'] = 278;
  13059. t['k'] = 556;
  13060. t['l'] = 278;
  13061. t['m'] = 889;
  13062. t['n'] = 611;
  13063. t['o'] = 611;
  13064. t['p'] = 611;
  13065. t['q'] = 611;
  13066. t['r'] = 389;
  13067. t['s'] = 556;
  13068. t['t'] = 333;
  13069. t['u'] = 611;
  13070. t['v'] = 556;
  13071. t['w'] = 778;
  13072. t['x'] = 556;
  13073. t['y'] = 556;
  13074. t['z'] = 500;
  13075. t['braceleft'] = 389;
  13076. t['bar'] = 280;
  13077. t['braceright'] = 389;
  13078. t['asciitilde'] = 584;
  13079. t['exclamdown'] = 333;
  13080. t['cent'] = 556;
  13081. t['sterling'] = 556;
  13082. t['fraction'] = 167;
  13083. t['yen'] = 556;
  13084. t['florin'] = 556;
  13085. t['section'] = 556;
  13086. t['currency'] = 556;
  13087. t['quotesingle'] = 238;
  13088. t['quotedblleft'] = 500;
  13089. t['guillemotleft'] = 556;
  13090. t['guilsinglleft'] = 333;
  13091. t['guilsinglright'] = 333;
  13092. t['fi'] = 611;
  13093. t['fl'] = 611;
  13094. t['endash'] = 556;
  13095. t['dagger'] = 556;
  13096. t['daggerdbl'] = 556;
  13097. t['periodcentered'] = 278;
  13098. t['paragraph'] = 556;
  13099. t['bullet'] = 350;
  13100. t['quotesinglbase'] = 278;
  13101. t['quotedblbase'] = 500;
  13102. t['quotedblright'] = 500;
  13103. t['guillemotright'] = 556;
  13104. t['ellipsis'] = 1000;
  13105. t['perthousand'] = 1000;
  13106. t['questiondown'] = 611;
  13107. t['grave'] = 333;
  13108. t['acute'] = 333;
  13109. t['circumflex'] = 333;
  13110. t['tilde'] = 333;
  13111. t['macron'] = 333;
  13112. t['breve'] = 333;
  13113. t['dotaccent'] = 333;
  13114. t['dieresis'] = 333;
  13115. t['ring'] = 333;
  13116. t['cedilla'] = 333;
  13117. t['hungarumlaut'] = 333;
  13118. t['ogonek'] = 333;
  13119. t['caron'] = 333;
  13120. t['emdash'] = 1000;
  13121. t['AE'] = 1000;
  13122. t['ordfeminine'] = 370;
  13123. t['Lslash'] = 611;
  13124. t['Oslash'] = 778;
  13125. t['OE'] = 1000;
  13126. t['ordmasculine'] = 365;
  13127. t['ae'] = 889;
  13128. t['dotlessi'] = 278;
  13129. t['lslash'] = 278;
  13130. t['oslash'] = 611;
  13131. t['oe'] = 944;
  13132. t['germandbls'] = 611;
  13133. t['Idieresis'] = 278;
  13134. t['eacute'] = 556;
  13135. t['abreve'] = 556;
  13136. t['uhungarumlaut'] = 611;
  13137. t['ecaron'] = 556;
  13138. t['Ydieresis'] = 667;
  13139. t['divide'] = 584;
  13140. t['Yacute'] = 667;
  13141. t['Acircumflex'] = 722;
  13142. t['aacute'] = 556;
  13143. t['Ucircumflex'] = 722;
  13144. t['yacute'] = 556;
  13145. t['scommaaccent'] = 556;
  13146. t['ecircumflex'] = 556;
  13147. t['Uring'] = 722;
  13148. t['Udieresis'] = 722;
  13149. t['aogonek'] = 556;
  13150. t['Uacute'] = 722;
  13151. t['uogonek'] = 611;
  13152. t['Edieresis'] = 667;
  13153. t['Dcroat'] = 722;
  13154. t['commaaccent'] = 250;
  13155. t['copyright'] = 737;
  13156. t['Emacron'] = 667;
  13157. t['ccaron'] = 556;
  13158. t['aring'] = 556;
  13159. t['Ncommaaccent'] = 722;
  13160. t['lacute'] = 278;
  13161. t['agrave'] = 556;
  13162. t['Tcommaaccent'] = 611;
  13163. t['Cacute'] = 722;
  13164. t['atilde'] = 556;
  13165. t['Edotaccent'] = 667;
  13166. t['scaron'] = 556;
  13167. t['scedilla'] = 556;
  13168. t['iacute'] = 278;
  13169. t['lozenge'] = 494;
  13170. t['Rcaron'] = 722;
  13171. t['Gcommaaccent'] = 778;
  13172. t['ucircumflex'] = 611;
  13173. t['acircumflex'] = 556;
  13174. t['Amacron'] = 722;
  13175. t['rcaron'] = 389;
  13176. t['ccedilla'] = 556;
  13177. t['Zdotaccent'] = 611;
  13178. t['Thorn'] = 667;
  13179. t['Omacron'] = 778;
  13180. t['Racute'] = 722;
  13181. t['Sacute'] = 667;
  13182. t['dcaron'] = 743;
  13183. t['Umacron'] = 722;
  13184. t['uring'] = 611;
  13185. t['threesuperior'] = 333;
  13186. t['Ograve'] = 778;
  13187. t['Agrave'] = 722;
  13188. t['Abreve'] = 722;
  13189. t['multiply'] = 584;
  13190. t['uacute'] = 611;
  13191. t['Tcaron'] = 611;
  13192. t['partialdiff'] = 494;
  13193. t['ydieresis'] = 556;
  13194. t['Nacute'] = 722;
  13195. t['icircumflex'] = 278;
  13196. t['Ecircumflex'] = 667;
  13197. t['adieresis'] = 556;
  13198. t['edieresis'] = 556;
  13199. t['cacute'] = 556;
  13200. t['nacute'] = 611;
  13201. t['umacron'] = 611;
  13202. t['Ncaron'] = 722;
  13203. t['Iacute'] = 278;
  13204. t['plusminus'] = 584;
  13205. t['brokenbar'] = 280;
  13206. t['registered'] = 737;
  13207. t['Gbreve'] = 778;
  13208. t['Idotaccent'] = 278;
  13209. t['summation'] = 600;
  13210. t['Egrave'] = 667;
  13211. t['racute'] = 389;
  13212. t['omacron'] = 611;
  13213. t['Zacute'] = 611;
  13214. t['Zcaron'] = 611;
  13215. t['greaterequal'] = 549;
  13216. t['Eth'] = 722;
  13217. t['Ccedilla'] = 722;
  13218. t['lcommaaccent'] = 278;
  13219. t['tcaron'] = 389;
  13220. t['eogonek'] = 556;
  13221. t['Uogonek'] = 722;
  13222. t['Aacute'] = 722;
  13223. t['Adieresis'] = 722;
  13224. t['egrave'] = 556;
  13225. t['zacute'] = 500;
  13226. t['iogonek'] = 278;
  13227. t['Oacute'] = 778;
  13228. t['oacute'] = 611;
  13229. t['amacron'] = 556;
  13230. t['sacute'] = 556;
  13231. t['idieresis'] = 278;
  13232. t['Ocircumflex'] = 778;
  13233. t['Ugrave'] = 722;
  13234. t['Delta'] = 612;
  13235. t['thorn'] = 611;
  13236. t['twosuperior'] = 333;
  13237. t['Odieresis'] = 778;
  13238. t['mu'] = 611;
  13239. t['igrave'] = 278;
  13240. t['ohungarumlaut'] = 611;
  13241. t['Eogonek'] = 667;
  13242. t['dcroat'] = 611;
  13243. t['threequarters'] = 834;
  13244. t['Scedilla'] = 667;
  13245. t['lcaron'] = 400;
  13246. t['Kcommaaccent'] = 722;
  13247. t['Lacute'] = 611;
  13248. t['trademark'] = 1000;
  13249. t['edotaccent'] = 556;
  13250. t['Igrave'] = 278;
  13251. t['Imacron'] = 278;
  13252. t['Lcaron'] = 611;
  13253. t['onehalf'] = 834;
  13254. t['lessequal'] = 549;
  13255. t['ocircumflex'] = 611;
  13256. t['ntilde'] = 611;
  13257. t['Uhungarumlaut'] = 722;
  13258. t['Eacute'] = 667;
  13259. t['emacron'] = 556;
  13260. t['gbreve'] = 611;
  13261. t['onequarter'] = 834;
  13262. t['Scaron'] = 667;
  13263. t['Scommaaccent'] = 667;
  13264. t['Ohungarumlaut'] = 778;
  13265. t['degree'] = 400;
  13266. t['ograve'] = 611;
  13267. t['Ccaron'] = 722;
  13268. t['ugrave'] = 611;
  13269. t['radical'] = 549;
  13270. t['Dcaron'] = 722;
  13271. t['rcommaaccent'] = 389;
  13272. t['Ntilde'] = 722;
  13273. t['otilde'] = 611;
  13274. t['Rcommaaccent'] = 722;
  13275. t['Lcommaaccent'] = 611;
  13276. t['Atilde'] = 722;
  13277. t['Aogonek'] = 722;
  13278. t['Aring'] = 722;
  13279. t['Otilde'] = 778;
  13280. t['zdotaccent'] = 500;
  13281. t['Ecaron'] = 667;
  13282. t['Iogonek'] = 278;
  13283. t['kcommaaccent'] = 556;
  13284. t['minus'] = 584;
  13285. t['Icircumflex'] = 278;
  13286. t['ncaron'] = 611;
  13287. t['tcommaaccent'] = 333;
  13288. t['logicalnot'] = 584;
  13289. t['odieresis'] = 611;
  13290. t['udieresis'] = 611;
  13291. t['notequal'] = 549;
  13292. t['gcommaaccent'] = 611;
  13293. t['eth'] = 611;
  13294. t['zcaron'] = 500;
  13295. t['ncommaaccent'] = 611;
  13296. t['onesuperior'] = 333;
  13297. t['imacron'] = 278;
  13298. t['Euro'] = 556;
  13299. });
  13300. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  13301. t['space'] = 278;
  13302. t['exclam'] = 278;
  13303. t['quotedbl'] = 355;
  13304. t['numbersign'] = 556;
  13305. t['dollar'] = 556;
  13306. t['percent'] = 889;
  13307. t['ampersand'] = 667;
  13308. t['quoteright'] = 222;
  13309. t['parenleft'] = 333;
  13310. t['parenright'] = 333;
  13311. t['asterisk'] = 389;
  13312. t['plus'] = 584;
  13313. t['comma'] = 278;
  13314. t['hyphen'] = 333;
  13315. t['period'] = 278;
  13316. t['slash'] = 278;
  13317. t['zero'] = 556;
  13318. t['one'] = 556;
  13319. t['two'] = 556;
  13320. t['three'] = 556;
  13321. t['four'] = 556;
  13322. t['five'] = 556;
  13323. t['six'] = 556;
  13324. t['seven'] = 556;
  13325. t['eight'] = 556;
  13326. t['nine'] = 556;
  13327. t['colon'] = 278;
  13328. t['semicolon'] = 278;
  13329. t['less'] = 584;
  13330. t['equal'] = 584;
  13331. t['greater'] = 584;
  13332. t['question'] = 556;
  13333. t['at'] = 1015;
  13334. t['A'] = 667;
  13335. t['B'] = 667;
  13336. t['C'] = 722;
  13337. t['D'] = 722;
  13338. t['E'] = 667;
  13339. t['F'] = 611;
  13340. t['G'] = 778;
  13341. t['H'] = 722;
  13342. t['I'] = 278;
  13343. t['J'] = 500;
  13344. t['K'] = 667;
  13345. t['L'] = 556;
  13346. t['M'] = 833;
  13347. t['N'] = 722;
  13348. t['O'] = 778;
  13349. t['P'] = 667;
  13350. t['Q'] = 778;
  13351. t['R'] = 722;
  13352. t['S'] = 667;
  13353. t['T'] = 611;
  13354. t['U'] = 722;
  13355. t['V'] = 667;
  13356. t['W'] = 944;
  13357. t['X'] = 667;
  13358. t['Y'] = 667;
  13359. t['Z'] = 611;
  13360. t['bracketleft'] = 278;
  13361. t['backslash'] = 278;
  13362. t['bracketright'] = 278;
  13363. t['asciicircum'] = 469;
  13364. t['underscore'] = 556;
  13365. t['quoteleft'] = 222;
  13366. t['a'] = 556;
  13367. t['b'] = 556;
  13368. t['c'] = 500;
  13369. t['d'] = 556;
  13370. t['e'] = 556;
  13371. t['f'] = 278;
  13372. t['g'] = 556;
  13373. t['h'] = 556;
  13374. t['i'] = 222;
  13375. t['j'] = 222;
  13376. t['k'] = 500;
  13377. t['l'] = 222;
  13378. t['m'] = 833;
  13379. t['n'] = 556;
  13380. t['o'] = 556;
  13381. t['p'] = 556;
  13382. t['q'] = 556;
  13383. t['r'] = 333;
  13384. t['s'] = 500;
  13385. t['t'] = 278;
  13386. t['u'] = 556;
  13387. t['v'] = 500;
  13388. t['w'] = 722;
  13389. t['x'] = 500;
  13390. t['y'] = 500;
  13391. t['z'] = 500;
  13392. t['braceleft'] = 334;
  13393. t['bar'] = 260;
  13394. t['braceright'] = 334;
  13395. t['asciitilde'] = 584;
  13396. t['exclamdown'] = 333;
  13397. t['cent'] = 556;
  13398. t['sterling'] = 556;
  13399. t['fraction'] = 167;
  13400. t['yen'] = 556;
  13401. t['florin'] = 556;
  13402. t['section'] = 556;
  13403. t['currency'] = 556;
  13404. t['quotesingle'] = 191;
  13405. t['quotedblleft'] = 333;
  13406. t['guillemotleft'] = 556;
  13407. t['guilsinglleft'] = 333;
  13408. t['guilsinglright'] = 333;
  13409. t['fi'] = 500;
  13410. t['fl'] = 500;
  13411. t['endash'] = 556;
  13412. t['dagger'] = 556;
  13413. t['daggerdbl'] = 556;
  13414. t['periodcentered'] = 278;
  13415. t['paragraph'] = 537;
  13416. t['bullet'] = 350;
  13417. t['quotesinglbase'] = 222;
  13418. t['quotedblbase'] = 333;
  13419. t['quotedblright'] = 333;
  13420. t['guillemotright'] = 556;
  13421. t['ellipsis'] = 1000;
  13422. t['perthousand'] = 1000;
  13423. t['questiondown'] = 611;
  13424. t['grave'] = 333;
  13425. t['acute'] = 333;
  13426. t['circumflex'] = 333;
  13427. t['tilde'] = 333;
  13428. t['macron'] = 333;
  13429. t['breve'] = 333;
  13430. t['dotaccent'] = 333;
  13431. t['dieresis'] = 333;
  13432. t['ring'] = 333;
  13433. t['cedilla'] = 333;
  13434. t['hungarumlaut'] = 333;
  13435. t['ogonek'] = 333;
  13436. t['caron'] = 333;
  13437. t['emdash'] = 1000;
  13438. t['AE'] = 1000;
  13439. t['ordfeminine'] = 370;
  13440. t['Lslash'] = 556;
  13441. t['Oslash'] = 778;
  13442. t['OE'] = 1000;
  13443. t['ordmasculine'] = 365;
  13444. t['ae'] = 889;
  13445. t['dotlessi'] = 278;
  13446. t['lslash'] = 222;
  13447. t['oslash'] = 611;
  13448. t['oe'] = 944;
  13449. t['germandbls'] = 611;
  13450. t['Idieresis'] = 278;
  13451. t['eacute'] = 556;
  13452. t['abreve'] = 556;
  13453. t['uhungarumlaut'] = 556;
  13454. t['ecaron'] = 556;
  13455. t['Ydieresis'] = 667;
  13456. t['divide'] = 584;
  13457. t['Yacute'] = 667;
  13458. t['Acircumflex'] = 667;
  13459. t['aacute'] = 556;
  13460. t['Ucircumflex'] = 722;
  13461. t['yacute'] = 500;
  13462. t['scommaaccent'] = 500;
  13463. t['ecircumflex'] = 556;
  13464. t['Uring'] = 722;
  13465. t['Udieresis'] = 722;
  13466. t['aogonek'] = 556;
  13467. t['Uacute'] = 722;
  13468. t['uogonek'] = 556;
  13469. t['Edieresis'] = 667;
  13470. t['Dcroat'] = 722;
  13471. t['commaaccent'] = 250;
  13472. t['copyright'] = 737;
  13473. t['Emacron'] = 667;
  13474. t['ccaron'] = 500;
  13475. t['aring'] = 556;
  13476. t['Ncommaaccent'] = 722;
  13477. t['lacute'] = 222;
  13478. t['agrave'] = 556;
  13479. t['Tcommaaccent'] = 611;
  13480. t['Cacute'] = 722;
  13481. t['atilde'] = 556;
  13482. t['Edotaccent'] = 667;
  13483. t['scaron'] = 500;
  13484. t['scedilla'] = 500;
  13485. t['iacute'] = 278;
  13486. t['lozenge'] = 471;
  13487. t['Rcaron'] = 722;
  13488. t['Gcommaaccent'] = 778;
  13489. t['ucircumflex'] = 556;
  13490. t['acircumflex'] = 556;
  13491. t['Amacron'] = 667;
  13492. t['rcaron'] = 333;
  13493. t['ccedilla'] = 500;
  13494. t['Zdotaccent'] = 611;
  13495. t['Thorn'] = 667;
  13496. t['Omacron'] = 778;
  13497. t['Racute'] = 722;
  13498. t['Sacute'] = 667;
  13499. t['dcaron'] = 643;
  13500. t['Umacron'] = 722;
  13501. t['uring'] = 556;
  13502. t['threesuperior'] = 333;
  13503. t['Ograve'] = 778;
  13504. t['Agrave'] = 667;
  13505. t['Abreve'] = 667;
  13506. t['multiply'] = 584;
  13507. t['uacute'] = 556;
  13508. t['Tcaron'] = 611;
  13509. t['partialdiff'] = 476;
  13510. t['ydieresis'] = 500;
  13511. t['Nacute'] = 722;
  13512. t['icircumflex'] = 278;
  13513. t['Ecircumflex'] = 667;
  13514. t['adieresis'] = 556;
  13515. t['edieresis'] = 556;
  13516. t['cacute'] = 500;
  13517. t['nacute'] = 556;
  13518. t['umacron'] = 556;
  13519. t['Ncaron'] = 722;
  13520. t['Iacute'] = 278;
  13521. t['plusminus'] = 584;
  13522. t['brokenbar'] = 260;
  13523. t['registered'] = 737;
  13524. t['Gbreve'] = 778;
  13525. t['Idotaccent'] = 278;
  13526. t['summation'] = 600;
  13527. t['Egrave'] = 667;
  13528. t['racute'] = 333;
  13529. t['omacron'] = 556;
  13530. t['Zacute'] = 611;
  13531. t['Zcaron'] = 611;
  13532. t['greaterequal'] = 549;
  13533. t['Eth'] = 722;
  13534. t['Ccedilla'] = 722;
  13535. t['lcommaaccent'] = 222;
  13536. t['tcaron'] = 317;
  13537. t['eogonek'] = 556;
  13538. t['Uogonek'] = 722;
  13539. t['Aacute'] = 667;
  13540. t['Adieresis'] = 667;
  13541. t['egrave'] = 556;
  13542. t['zacute'] = 500;
  13543. t['iogonek'] = 222;
  13544. t['Oacute'] = 778;
  13545. t['oacute'] = 556;
  13546. t['amacron'] = 556;
  13547. t['sacute'] = 500;
  13548. t['idieresis'] = 278;
  13549. t['Ocircumflex'] = 778;
  13550. t['Ugrave'] = 722;
  13551. t['Delta'] = 612;
  13552. t['thorn'] = 556;
  13553. t['twosuperior'] = 333;
  13554. t['Odieresis'] = 778;
  13555. t['mu'] = 556;
  13556. t['igrave'] = 278;
  13557. t['ohungarumlaut'] = 556;
  13558. t['Eogonek'] = 667;
  13559. t['dcroat'] = 556;
  13560. t['threequarters'] = 834;
  13561. t['Scedilla'] = 667;
  13562. t['lcaron'] = 299;
  13563. t['Kcommaaccent'] = 667;
  13564. t['Lacute'] = 556;
  13565. t['trademark'] = 1000;
  13566. t['edotaccent'] = 556;
  13567. t['Igrave'] = 278;
  13568. t['Imacron'] = 278;
  13569. t['Lcaron'] = 556;
  13570. t['onehalf'] = 834;
  13571. t['lessequal'] = 549;
  13572. t['ocircumflex'] = 556;
  13573. t['ntilde'] = 556;
  13574. t['Uhungarumlaut'] = 722;
  13575. t['Eacute'] = 667;
  13576. t['emacron'] = 556;
  13577. t['gbreve'] = 556;
  13578. t['onequarter'] = 834;
  13579. t['Scaron'] = 667;
  13580. t['Scommaaccent'] = 667;
  13581. t['Ohungarumlaut'] = 778;
  13582. t['degree'] = 400;
  13583. t['ograve'] = 556;
  13584. t['Ccaron'] = 722;
  13585. t['ugrave'] = 556;
  13586. t['radical'] = 453;
  13587. t['Dcaron'] = 722;
  13588. t['rcommaaccent'] = 333;
  13589. t['Ntilde'] = 722;
  13590. t['otilde'] = 556;
  13591. t['Rcommaaccent'] = 722;
  13592. t['Lcommaaccent'] = 556;
  13593. t['Atilde'] = 667;
  13594. t['Aogonek'] = 667;
  13595. t['Aring'] = 667;
  13596. t['Otilde'] = 778;
  13597. t['zdotaccent'] = 500;
  13598. t['Ecaron'] = 667;
  13599. t['Iogonek'] = 278;
  13600. t['kcommaaccent'] = 500;
  13601. t['minus'] = 584;
  13602. t['Icircumflex'] = 278;
  13603. t['ncaron'] = 556;
  13604. t['tcommaaccent'] = 278;
  13605. t['logicalnot'] = 584;
  13606. t['odieresis'] = 556;
  13607. t['udieresis'] = 556;
  13608. t['notequal'] = 549;
  13609. t['gcommaaccent'] = 556;
  13610. t['eth'] = 556;
  13611. t['zcaron'] = 500;
  13612. t['ncommaaccent'] = 556;
  13613. t['onesuperior'] = 333;
  13614. t['imacron'] = 278;
  13615. t['Euro'] = 556;
  13616. });
  13617. t['Symbol'] = getLookupTableFactory(function (t) {
  13618. t['space'] = 250;
  13619. t['exclam'] = 333;
  13620. t['universal'] = 713;
  13621. t['numbersign'] = 500;
  13622. t['existential'] = 549;
  13623. t['percent'] = 833;
  13624. t['ampersand'] = 778;
  13625. t['suchthat'] = 439;
  13626. t['parenleft'] = 333;
  13627. t['parenright'] = 333;
  13628. t['asteriskmath'] = 500;
  13629. t['plus'] = 549;
  13630. t['comma'] = 250;
  13631. t['minus'] = 549;
  13632. t['period'] = 250;
  13633. t['slash'] = 278;
  13634. t['zero'] = 500;
  13635. t['one'] = 500;
  13636. t['two'] = 500;
  13637. t['three'] = 500;
  13638. t['four'] = 500;
  13639. t['five'] = 500;
  13640. t['six'] = 500;
  13641. t['seven'] = 500;
  13642. t['eight'] = 500;
  13643. t['nine'] = 500;
  13644. t['colon'] = 278;
  13645. t['semicolon'] = 278;
  13646. t['less'] = 549;
  13647. t['equal'] = 549;
  13648. t['greater'] = 549;
  13649. t['question'] = 444;
  13650. t['congruent'] = 549;
  13651. t['Alpha'] = 722;
  13652. t['Beta'] = 667;
  13653. t['Chi'] = 722;
  13654. t['Delta'] = 612;
  13655. t['Epsilon'] = 611;
  13656. t['Phi'] = 763;
  13657. t['Gamma'] = 603;
  13658. t['Eta'] = 722;
  13659. t['Iota'] = 333;
  13660. t['theta1'] = 631;
  13661. t['Kappa'] = 722;
  13662. t['Lambda'] = 686;
  13663. t['Mu'] = 889;
  13664. t['Nu'] = 722;
  13665. t['Omicron'] = 722;
  13666. t['Pi'] = 768;
  13667. t['Theta'] = 741;
  13668. t['Rho'] = 556;
  13669. t['Sigma'] = 592;
  13670. t['Tau'] = 611;
  13671. t['Upsilon'] = 690;
  13672. t['sigma1'] = 439;
  13673. t['Omega'] = 768;
  13674. t['Xi'] = 645;
  13675. t['Psi'] = 795;
  13676. t['Zeta'] = 611;
  13677. t['bracketleft'] = 333;
  13678. t['therefore'] = 863;
  13679. t['bracketright'] = 333;
  13680. t['perpendicular'] = 658;
  13681. t['underscore'] = 500;
  13682. t['radicalex'] = 500;
  13683. t['alpha'] = 631;
  13684. t['beta'] = 549;
  13685. t['chi'] = 549;
  13686. t['delta'] = 494;
  13687. t['epsilon'] = 439;
  13688. t['phi'] = 521;
  13689. t['gamma'] = 411;
  13690. t['eta'] = 603;
  13691. t['iota'] = 329;
  13692. t['phi1'] = 603;
  13693. t['kappa'] = 549;
  13694. t['lambda'] = 549;
  13695. t['mu'] = 576;
  13696. t['nu'] = 521;
  13697. t['omicron'] = 549;
  13698. t['pi'] = 549;
  13699. t['theta'] = 521;
  13700. t['rho'] = 549;
  13701. t['sigma'] = 603;
  13702. t['tau'] = 439;
  13703. t['upsilon'] = 576;
  13704. t['omega1'] = 713;
  13705. t['omega'] = 686;
  13706. t['xi'] = 493;
  13707. t['psi'] = 686;
  13708. t['zeta'] = 494;
  13709. t['braceleft'] = 480;
  13710. t['bar'] = 200;
  13711. t['braceright'] = 480;
  13712. t['similar'] = 549;
  13713. t['Euro'] = 750;
  13714. t['Upsilon1'] = 620;
  13715. t['minute'] = 247;
  13716. t['lessequal'] = 549;
  13717. t['fraction'] = 167;
  13718. t['infinity'] = 713;
  13719. t['florin'] = 500;
  13720. t['club'] = 753;
  13721. t['diamond'] = 753;
  13722. t['heart'] = 753;
  13723. t['spade'] = 753;
  13724. t['arrowboth'] = 1042;
  13725. t['arrowleft'] = 987;
  13726. t['arrowup'] = 603;
  13727. t['arrowright'] = 987;
  13728. t['arrowdown'] = 603;
  13729. t['degree'] = 400;
  13730. t['plusminus'] = 549;
  13731. t['second'] = 411;
  13732. t['greaterequal'] = 549;
  13733. t['multiply'] = 549;
  13734. t['proportional'] = 713;
  13735. t['partialdiff'] = 494;
  13736. t['bullet'] = 460;
  13737. t['divide'] = 549;
  13738. t['notequal'] = 549;
  13739. t['equivalence'] = 549;
  13740. t['approxequal'] = 549;
  13741. t['ellipsis'] = 1000;
  13742. t['arrowvertex'] = 603;
  13743. t['arrowhorizex'] = 1000;
  13744. t['carriagereturn'] = 658;
  13745. t['aleph'] = 823;
  13746. t['Ifraktur'] = 686;
  13747. t['Rfraktur'] = 795;
  13748. t['weierstrass'] = 987;
  13749. t['circlemultiply'] = 768;
  13750. t['circleplus'] = 768;
  13751. t['emptyset'] = 823;
  13752. t['intersection'] = 768;
  13753. t['union'] = 768;
  13754. t['propersuperset'] = 713;
  13755. t['reflexsuperset'] = 713;
  13756. t['notsubset'] = 713;
  13757. t['propersubset'] = 713;
  13758. t['reflexsubset'] = 713;
  13759. t['element'] = 713;
  13760. t['notelement'] = 713;
  13761. t['angle'] = 768;
  13762. t['gradient'] = 713;
  13763. t['registerserif'] = 790;
  13764. t['copyrightserif'] = 790;
  13765. t['trademarkserif'] = 890;
  13766. t['product'] = 823;
  13767. t['radical'] = 549;
  13768. t['dotmath'] = 250;
  13769. t['logicalnot'] = 713;
  13770. t['logicaland'] = 603;
  13771. t['logicalor'] = 603;
  13772. t['arrowdblboth'] = 1042;
  13773. t['arrowdblleft'] = 987;
  13774. t['arrowdblup'] = 603;
  13775. t['arrowdblright'] = 987;
  13776. t['arrowdbldown'] = 603;
  13777. t['lozenge'] = 494;
  13778. t['angleleft'] = 329;
  13779. t['registersans'] = 790;
  13780. t['copyrightsans'] = 790;
  13781. t['trademarksans'] = 786;
  13782. t['summation'] = 713;
  13783. t['parenlefttp'] = 384;
  13784. t['parenleftex'] = 384;
  13785. t['parenleftbt'] = 384;
  13786. t['bracketlefttp'] = 384;
  13787. t['bracketleftex'] = 384;
  13788. t['bracketleftbt'] = 384;
  13789. t['bracelefttp'] = 494;
  13790. t['braceleftmid'] = 494;
  13791. t['braceleftbt'] = 494;
  13792. t['braceex'] = 494;
  13793. t['angleright'] = 329;
  13794. t['integral'] = 274;
  13795. t['integraltp'] = 686;
  13796. t['integralex'] = 686;
  13797. t['integralbt'] = 686;
  13798. t['parenrighttp'] = 384;
  13799. t['parenrightex'] = 384;
  13800. t['parenrightbt'] = 384;
  13801. t['bracketrighttp'] = 384;
  13802. t['bracketrightex'] = 384;
  13803. t['bracketrightbt'] = 384;
  13804. t['bracerighttp'] = 494;
  13805. t['bracerightmid'] = 494;
  13806. t['bracerightbt'] = 494;
  13807. t['apple'] = 790;
  13808. });
  13809. t['Times-Roman'] = getLookupTableFactory(function (t) {
  13810. t['space'] = 250;
  13811. t['exclam'] = 333;
  13812. t['quotedbl'] = 408;
  13813. t['numbersign'] = 500;
  13814. t['dollar'] = 500;
  13815. t['percent'] = 833;
  13816. t['ampersand'] = 778;
  13817. t['quoteright'] = 333;
  13818. t['parenleft'] = 333;
  13819. t['parenright'] = 333;
  13820. t['asterisk'] = 500;
  13821. t['plus'] = 564;
  13822. t['comma'] = 250;
  13823. t['hyphen'] = 333;
  13824. t['period'] = 250;
  13825. t['slash'] = 278;
  13826. t['zero'] = 500;
  13827. t['one'] = 500;
  13828. t['two'] = 500;
  13829. t['three'] = 500;
  13830. t['four'] = 500;
  13831. t['five'] = 500;
  13832. t['six'] = 500;
  13833. t['seven'] = 500;
  13834. t['eight'] = 500;
  13835. t['nine'] = 500;
  13836. t['colon'] = 278;
  13837. t['semicolon'] = 278;
  13838. t['less'] = 564;
  13839. t['equal'] = 564;
  13840. t['greater'] = 564;
  13841. t['question'] = 444;
  13842. t['at'] = 921;
  13843. t['A'] = 722;
  13844. t['B'] = 667;
  13845. t['C'] = 667;
  13846. t['D'] = 722;
  13847. t['E'] = 611;
  13848. t['F'] = 556;
  13849. t['G'] = 722;
  13850. t['H'] = 722;
  13851. t['I'] = 333;
  13852. t['J'] = 389;
  13853. t['K'] = 722;
  13854. t['L'] = 611;
  13855. t['M'] = 889;
  13856. t['N'] = 722;
  13857. t['O'] = 722;
  13858. t['P'] = 556;
  13859. t['Q'] = 722;
  13860. t['R'] = 667;
  13861. t['S'] = 556;
  13862. t['T'] = 611;
  13863. t['U'] = 722;
  13864. t['V'] = 722;
  13865. t['W'] = 944;
  13866. t['X'] = 722;
  13867. t['Y'] = 722;
  13868. t['Z'] = 611;
  13869. t['bracketleft'] = 333;
  13870. t['backslash'] = 278;
  13871. t['bracketright'] = 333;
  13872. t['asciicircum'] = 469;
  13873. t['underscore'] = 500;
  13874. t['quoteleft'] = 333;
  13875. t['a'] = 444;
  13876. t['b'] = 500;
  13877. t['c'] = 444;
  13878. t['d'] = 500;
  13879. t['e'] = 444;
  13880. t['f'] = 333;
  13881. t['g'] = 500;
  13882. t['h'] = 500;
  13883. t['i'] = 278;
  13884. t['j'] = 278;
  13885. t['k'] = 500;
  13886. t['l'] = 278;
  13887. t['m'] = 778;
  13888. t['n'] = 500;
  13889. t['o'] = 500;
  13890. t['p'] = 500;
  13891. t['q'] = 500;
  13892. t['r'] = 333;
  13893. t['s'] = 389;
  13894. t['t'] = 278;
  13895. t['u'] = 500;
  13896. t['v'] = 500;
  13897. t['w'] = 722;
  13898. t['x'] = 500;
  13899. t['y'] = 500;
  13900. t['z'] = 444;
  13901. t['braceleft'] = 480;
  13902. t['bar'] = 200;
  13903. t['braceright'] = 480;
  13904. t['asciitilde'] = 541;
  13905. t['exclamdown'] = 333;
  13906. t['cent'] = 500;
  13907. t['sterling'] = 500;
  13908. t['fraction'] = 167;
  13909. t['yen'] = 500;
  13910. t['florin'] = 500;
  13911. t['section'] = 500;
  13912. t['currency'] = 500;
  13913. t['quotesingle'] = 180;
  13914. t['quotedblleft'] = 444;
  13915. t['guillemotleft'] = 500;
  13916. t['guilsinglleft'] = 333;
  13917. t['guilsinglright'] = 333;
  13918. t['fi'] = 556;
  13919. t['fl'] = 556;
  13920. t['endash'] = 500;
  13921. t['dagger'] = 500;
  13922. t['daggerdbl'] = 500;
  13923. t['periodcentered'] = 250;
  13924. t['paragraph'] = 453;
  13925. t['bullet'] = 350;
  13926. t['quotesinglbase'] = 333;
  13927. t['quotedblbase'] = 444;
  13928. t['quotedblright'] = 444;
  13929. t['guillemotright'] = 500;
  13930. t['ellipsis'] = 1000;
  13931. t['perthousand'] = 1000;
  13932. t['questiondown'] = 444;
  13933. t['grave'] = 333;
  13934. t['acute'] = 333;
  13935. t['circumflex'] = 333;
  13936. t['tilde'] = 333;
  13937. t['macron'] = 333;
  13938. t['breve'] = 333;
  13939. t['dotaccent'] = 333;
  13940. t['dieresis'] = 333;
  13941. t['ring'] = 333;
  13942. t['cedilla'] = 333;
  13943. t['hungarumlaut'] = 333;
  13944. t['ogonek'] = 333;
  13945. t['caron'] = 333;
  13946. t['emdash'] = 1000;
  13947. t['AE'] = 889;
  13948. t['ordfeminine'] = 276;
  13949. t['Lslash'] = 611;
  13950. t['Oslash'] = 722;
  13951. t['OE'] = 889;
  13952. t['ordmasculine'] = 310;
  13953. t['ae'] = 667;
  13954. t['dotlessi'] = 278;
  13955. t['lslash'] = 278;
  13956. t['oslash'] = 500;
  13957. t['oe'] = 722;
  13958. t['germandbls'] = 500;
  13959. t['Idieresis'] = 333;
  13960. t['eacute'] = 444;
  13961. t['abreve'] = 444;
  13962. t['uhungarumlaut'] = 500;
  13963. t['ecaron'] = 444;
  13964. t['Ydieresis'] = 722;
  13965. t['divide'] = 564;
  13966. t['Yacute'] = 722;
  13967. t['Acircumflex'] = 722;
  13968. t['aacute'] = 444;
  13969. t['Ucircumflex'] = 722;
  13970. t['yacute'] = 500;
  13971. t['scommaaccent'] = 389;
  13972. t['ecircumflex'] = 444;
  13973. t['Uring'] = 722;
  13974. t['Udieresis'] = 722;
  13975. t['aogonek'] = 444;
  13976. t['Uacute'] = 722;
  13977. t['uogonek'] = 500;
  13978. t['Edieresis'] = 611;
  13979. t['Dcroat'] = 722;
  13980. t['commaaccent'] = 250;
  13981. t['copyright'] = 760;
  13982. t['Emacron'] = 611;
  13983. t['ccaron'] = 444;
  13984. t['aring'] = 444;
  13985. t['Ncommaaccent'] = 722;
  13986. t['lacute'] = 278;
  13987. t['agrave'] = 444;
  13988. t['Tcommaaccent'] = 611;
  13989. t['Cacute'] = 667;
  13990. t['atilde'] = 444;
  13991. t['Edotaccent'] = 611;
  13992. t['scaron'] = 389;
  13993. t['scedilla'] = 389;
  13994. t['iacute'] = 278;
  13995. t['lozenge'] = 471;
  13996. t['Rcaron'] = 667;
  13997. t['Gcommaaccent'] = 722;
  13998. t['ucircumflex'] = 500;
  13999. t['acircumflex'] = 444;
  14000. t['Amacron'] = 722;
  14001. t['rcaron'] = 333;
  14002. t['ccedilla'] = 444;
  14003. t['Zdotaccent'] = 611;
  14004. t['Thorn'] = 556;
  14005. t['Omacron'] = 722;
  14006. t['Racute'] = 667;
  14007. t['Sacute'] = 556;
  14008. t['dcaron'] = 588;
  14009. t['Umacron'] = 722;
  14010. t['uring'] = 500;
  14011. t['threesuperior'] = 300;
  14012. t['Ograve'] = 722;
  14013. t['Agrave'] = 722;
  14014. t['Abreve'] = 722;
  14015. t['multiply'] = 564;
  14016. t['uacute'] = 500;
  14017. t['Tcaron'] = 611;
  14018. t['partialdiff'] = 476;
  14019. t['ydieresis'] = 500;
  14020. t['Nacute'] = 722;
  14021. t['icircumflex'] = 278;
  14022. t['Ecircumflex'] = 611;
  14023. t['adieresis'] = 444;
  14024. t['edieresis'] = 444;
  14025. t['cacute'] = 444;
  14026. t['nacute'] = 500;
  14027. t['umacron'] = 500;
  14028. t['Ncaron'] = 722;
  14029. t['Iacute'] = 333;
  14030. t['plusminus'] = 564;
  14031. t['brokenbar'] = 200;
  14032. t['registered'] = 760;
  14033. t['Gbreve'] = 722;
  14034. t['Idotaccent'] = 333;
  14035. t['summation'] = 600;
  14036. t['Egrave'] = 611;
  14037. t['racute'] = 333;
  14038. t['omacron'] = 500;
  14039. t['Zacute'] = 611;
  14040. t['Zcaron'] = 611;
  14041. t['greaterequal'] = 549;
  14042. t['Eth'] = 722;
  14043. t['Ccedilla'] = 667;
  14044. t['lcommaaccent'] = 278;
  14045. t['tcaron'] = 326;
  14046. t['eogonek'] = 444;
  14047. t['Uogonek'] = 722;
  14048. t['Aacute'] = 722;
  14049. t['Adieresis'] = 722;
  14050. t['egrave'] = 444;
  14051. t['zacute'] = 444;
  14052. t['iogonek'] = 278;
  14053. t['Oacute'] = 722;
  14054. t['oacute'] = 500;
  14055. t['amacron'] = 444;
  14056. t['sacute'] = 389;
  14057. t['idieresis'] = 278;
  14058. t['Ocircumflex'] = 722;
  14059. t['Ugrave'] = 722;
  14060. t['Delta'] = 612;
  14061. t['thorn'] = 500;
  14062. t['twosuperior'] = 300;
  14063. t['Odieresis'] = 722;
  14064. t['mu'] = 500;
  14065. t['igrave'] = 278;
  14066. t['ohungarumlaut'] = 500;
  14067. t['Eogonek'] = 611;
  14068. t['dcroat'] = 500;
  14069. t['threequarters'] = 750;
  14070. t['Scedilla'] = 556;
  14071. t['lcaron'] = 344;
  14072. t['Kcommaaccent'] = 722;
  14073. t['Lacute'] = 611;
  14074. t['trademark'] = 980;
  14075. t['edotaccent'] = 444;
  14076. t['Igrave'] = 333;
  14077. t['Imacron'] = 333;
  14078. t['Lcaron'] = 611;
  14079. t['onehalf'] = 750;
  14080. t['lessequal'] = 549;
  14081. t['ocircumflex'] = 500;
  14082. t['ntilde'] = 500;
  14083. t['Uhungarumlaut'] = 722;
  14084. t['Eacute'] = 611;
  14085. t['emacron'] = 444;
  14086. t['gbreve'] = 500;
  14087. t['onequarter'] = 750;
  14088. t['Scaron'] = 556;
  14089. t['Scommaaccent'] = 556;
  14090. t['Ohungarumlaut'] = 722;
  14091. t['degree'] = 400;
  14092. t['ograve'] = 500;
  14093. t['Ccaron'] = 667;
  14094. t['ugrave'] = 500;
  14095. t['radical'] = 453;
  14096. t['Dcaron'] = 722;
  14097. t['rcommaaccent'] = 333;
  14098. t['Ntilde'] = 722;
  14099. t['otilde'] = 500;
  14100. t['Rcommaaccent'] = 667;
  14101. t['Lcommaaccent'] = 611;
  14102. t['Atilde'] = 722;
  14103. t['Aogonek'] = 722;
  14104. t['Aring'] = 722;
  14105. t['Otilde'] = 722;
  14106. t['zdotaccent'] = 444;
  14107. t['Ecaron'] = 611;
  14108. t['Iogonek'] = 333;
  14109. t['kcommaaccent'] = 500;
  14110. t['minus'] = 564;
  14111. t['Icircumflex'] = 333;
  14112. t['ncaron'] = 500;
  14113. t['tcommaaccent'] = 278;
  14114. t['logicalnot'] = 564;
  14115. t['odieresis'] = 500;
  14116. t['udieresis'] = 500;
  14117. t['notequal'] = 549;
  14118. t['gcommaaccent'] = 500;
  14119. t['eth'] = 500;
  14120. t['zcaron'] = 444;
  14121. t['ncommaaccent'] = 500;
  14122. t['onesuperior'] = 300;
  14123. t['imacron'] = 278;
  14124. t['Euro'] = 500;
  14125. });
  14126. t['Times-Bold'] = getLookupTableFactory(function (t) {
  14127. t['space'] = 250;
  14128. t['exclam'] = 333;
  14129. t['quotedbl'] = 555;
  14130. t['numbersign'] = 500;
  14131. t['dollar'] = 500;
  14132. t['percent'] = 1000;
  14133. t['ampersand'] = 833;
  14134. t['quoteright'] = 333;
  14135. t['parenleft'] = 333;
  14136. t['parenright'] = 333;
  14137. t['asterisk'] = 500;
  14138. t['plus'] = 570;
  14139. t['comma'] = 250;
  14140. t['hyphen'] = 333;
  14141. t['period'] = 250;
  14142. t['slash'] = 278;
  14143. t['zero'] = 500;
  14144. t['one'] = 500;
  14145. t['two'] = 500;
  14146. t['three'] = 500;
  14147. t['four'] = 500;
  14148. t['five'] = 500;
  14149. t['six'] = 500;
  14150. t['seven'] = 500;
  14151. t['eight'] = 500;
  14152. t['nine'] = 500;
  14153. t['colon'] = 333;
  14154. t['semicolon'] = 333;
  14155. t['less'] = 570;
  14156. t['equal'] = 570;
  14157. t['greater'] = 570;
  14158. t['question'] = 500;
  14159. t['at'] = 930;
  14160. t['A'] = 722;
  14161. t['B'] = 667;
  14162. t['C'] = 722;
  14163. t['D'] = 722;
  14164. t['E'] = 667;
  14165. t['F'] = 611;
  14166. t['G'] = 778;
  14167. t['H'] = 778;
  14168. t['I'] = 389;
  14169. t['J'] = 500;
  14170. t['K'] = 778;
  14171. t['L'] = 667;
  14172. t['M'] = 944;
  14173. t['N'] = 722;
  14174. t['O'] = 778;
  14175. t['P'] = 611;
  14176. t['Q'] = 778;
  14177. t['R'] = 722;
  14178. t['S'] = 556;
  14179. t['T'] = 667;
  14180. t['U'] = 722;
  14181. t['V'] = 722;
  14182. t['W'] = 1000;
  14183. t['X'] = 722;
  14184. t['Y'] = 722;
  14185. t['Z'] = 667;
  14186. t['bracketleft'] = 333;
  14187. t['backslash'] = 278;
  14188. t['bracketright'] = 333;
  14189. t['asciicircum'] = 581;
  14190. t['underscore'] = 500;
  14191. t['quoteleft'] = 333;
  14192. t['a'] = 500;
  14193. t['b'] = 556;
  14194. t['c'] = 444;
  14195. t['d'] = 556;
  14196. t['e'] = 444;
  14197. t['f'] = 333;
  14198. t['g'] = 500;
  14199. t['h'] = 556;
  14200. t['i'] = 278;
  14201. t['j'] = 333;
  14202. t['k'] = 556;
  14203. t['l'] = 278;
  14204. t['m'] = 833;
  14205. t['n'] = 556;
  14206. t['o'] = 500;
  14207. t['p'] = 556;
  14208. t['q'] = 556;
  14209. t['r'] = 444;
  14210. t['s'] = 389;
  14211. t['t'] = 333;
  14212. t['u'] = 556;
  14213. t['v'] = 500;
  14214. t['w'] = 722;
  14215. t['x'] = 500;
  14216. t['y'] = 500;
  14217. t['z'] = 444;
  14218. t['braceleft'] = 394;
  14219. t['bar'] = 220;
  14220. t['braceright'] = 394;
  14221. t['asciitilde'] = 520;
  14222. t['exclamdown'] = 333;
  14223. t['cent'] = 500;
  14224. t['sterling'] = 500;
  14225. t['fraction'] = 167;
  14226. t['yen'] = 500;
  14227. t['florin'] = 500;
  14228. t['section'] = 500;
  14229. t['currency'] = 500;
  14230. t['quotesingle'] = 278;
  14231. t['quotedblleft'] = 500;
  14232. t['guillemotleft'] = 500;
  14233. t['guilsinglleft'] = 333;
  14234. t['guilsinglright'] = 333;
  14235. t['fi'] = 556;
  14236. t['fl'] = 556;
  14237. t['endash'] = 500;
  14238. t['dagger'] = 500;
  14239. t['daggerdbl'] = 500;
  14240. t['periodcentered'] = 250;
  14241. t['paragraph'] = 540;
  14242. t['bullet'] = 350;
  14243. t['quotesinglbase'] = 333;
  14244. t['quotedblbase'] = 500;
  14245. t['quotedblright'] = 500;
  14246. t['guillemotright'] = 500;
  14247. t['ellipsis'] = 1000;
  14248. t['perthousand'] = 1000;
  14249. t['questiondown'] = 500;
  14250. t['grave'] = 333;
  14251. t['acute'] = 333;
  14252. t['circumflex'] = 333;
  14253. t['tilde'] = 333;
  14254. t['macron'] = 333;
  14255. t['breve'] = 333;
  14256. t['dotaccent'] = 333;
  14257. t['dieresis'] = 333;
  14258. t['ring'] = 333;
  14259. t['cedilla'] = 333;
  14260. t['hungarumlaut'] = 333;
  14261. t['ogonek'] = 333;
  14262. t['caron'] = 333;
  14263. t['emdash'] = 1000;
  14264. t['AE'] = 1000;
  14265. t['ordfeminine'] = 300;
  14266. t['Lslash'] = 667;
  14267. t['Oslash'] = 778;
  14268. t['OE'] = 1000;
  14269. t['ordmasculine'] = 330;
  14270. t['ae'] = 722;
  14271. t['dotlessi'] = 278;
  14272. t['lslash'] = 278;
  14273. t['oslash'] = 500;
  14274. t['oe'] = 722;
  14275. t['germandbls'] = 556;
  14276. t['Idieresis'] = 389;
  14277. t['eacute'] = 444;
  14278. t['abreve'] = 500;
  14279. t['uhungarumlaut'] = 556;
  14280. t['ecaron'] = 444;
  14281. t['Ydieresis'] = 722;
  14282. t['divide'] = 570;
  14283. t['Yacute'] = 722;
  14284. t['Acircumflex'] = 722;
  14285. t['aacute'] = 500;
  14286. t['Ucircumflex'] = 722;
  14287. t['yacute'] = 500;
  14288. t['scommaaccent'] = 389;
  14289. t['ecircumflex'] = 444;
  14290. t['Uring'] = 722;
  14291. t['Udieresis'] = 722;
  14292. t['aogonek'] = 500;
  14293. t['Uacute'] = 722;
  14294. t['uogonek'] = 556;
  14295. t['Edieresis'] = 667;
  14296. t['Dcroat'] = 722;
  14297. t['commaaccent'] = 250;
  14298. t['copyright'] = 747;
  14299. t['Emacron'] = 667;
  14300. t['ccaron'] = 444;
  14301. t['aring'] = 500;
  14302. t['Ncommaaccent'] = 722;
  14303. t['lacute'] = 278;
  14304. t['agrave'] = 500;
  14305. t['Tcommaaccent'] = 667;
  14306. t['Cacute'] = 722;
  14307. t['atilde'] = 500;
  14308. t['Edotaccent'] = 667;
  14309. t['scaron'] = 389;
  14310. t['scedilla'] = 389;
  14311. t['iacute'] = 278;
  14312. t['lozenge'] = 494;
  14313. t['Rcaron'] = 722;
  14314. t['Gcommaaccent'] = 778;
  14315. t['ucircumflex'] = 556;
  14316. t['acircumflex'] = 500;
  14317. t['Amacron'] = 722;
  14318. t['rcaron'] = 444;
  14319. t['ccedilla'] = 444;
  14320. t['Zdotaccent'] = 667;
  14321. t['Thorn'] = 611;
  14322. t['Omacron'] = 778;
  14323. t['Racute'] = 722;
  14324. t['Sacute'] = 556;
  14325. t['dcaron'] = 672;
  14326. t['Umacron'] = 722;
  14327. t['uring'] = 556;
  14328. t['threesuperior'] = 300;
  14329. t['Ograve'] = 778;
  14330. t['Agrave'] = 722;
  14331. t['Abreve'] = 722;
  14332. t['multiply'] = 570;
  14333. t['uacute'] = 556;
  14334. t['Tcaron'] = 667;
  14335. t['partialdiff'] = 494;
  14336. t['ydieresis'] = 500;
  14337. t['Nacute'] = 722;
  14338. t['icircumflex'] = 278;
  14339. t['Ecircumflex'] = 667;
  14340. t['adieresis'] = 500;
  14341. t['edieresis'] = 444;
  14342. t['cacute'] = 444;
  14343. t['nacute'] = 556;
  14344. t['umacron'] = 556;
  14345. t['Ncaron'] = 722;
  14346. t['Iacute'] = 389;
  14347. t['plusminus'] = 570;
  14348. t['brokenbar'] = 220;
  14349. t['registered'] = 747;
  14350. t['Gbreve'] = 778;
  14351. t['Idotaccent'] = 389;
  14352. t['summation'] = 600;
  14353. t['Egrave'] = 667;
  14354. t['racute'] = 444;
  14355. t['omacron'] = 500;
  14356. t['Zacute'] = 667;
  14357. t['Zcaron'] = 667;
  14358. t['greaterequal'] = 549;
  14359. t['Eth'] = 722;
  14360. t['Ccedilla'] = 722;
  14361. t['lcommaaccent'] = 278;
  14362. t['tcaron'] = 416;
  14363. t['eogonek'] = 444;
  14364. t['Uogonek'] = 722;
  14365. t['Aacute'] = 722;
  14366. t['Adieresis'] = 722;
  14367. t['egrave'] = 444;
  14368. t['zacute'] = 444;
  14369. t['iogonek'] = 278;
  14370. t['Oacute'] = 778;
  14371. t['oacute'] = 500;
  14372. t['amacron'] = 500;
  14373. t['sacute'] = 389;
  14374. t['idieresis'] = 278;
  14375. t['Ocircumflex'] = 778;
  14376. t['Ugrave'] = 722;
  14377. t['Delta'] = 612;
  14378. t['thorn'] = 556;
  14379. t['twosuperior'] = 300;
  14380. t['Odieresis'] = 778;
  14381. t['mu'] = 556;
  14382. t['igrave'] = 278;
  14383. t['ohungarumlaut'] = 500;
  14384. t['Eogonek'] = 667;
  14385. t['dcroat'] = 556;
  14386. t['threequarters'] = 750;
  14387. t['Scedilla'] = 556;
  14388. t['lcaron'] = 394;
  14389. t['Kcommaaccent'] = 778;
  14390. t['Lacute'] = 667;
  14391. t['trademark'] = 1000;
  14392. t['edotaccent'] = 444;
  14393. t['Igrave'] = 389;
  14394. t['Imacron'] = 389;
  14395. t['Lcaron'] = 667;
  14396. t['onehalf'] = 750;
  14397. t['lessequal'] = 549;
  14398. t['ocircumflex'] = 500;
  14399. t['ntilde'] = 556;
  14400. t['Uhungarumlaut'] = 722;
  14401. t['Eacute'] = 667;
  14402. t['emacron'] = 444;
  14403. t['gbreve'] = 500;
  14404. t['onequarter'] = 750;
  14405. t['Scaron'] = 556;
  14406. t['Scommaaccent'] = 556;
  14407. t['Ohungarumlaut'] = 778;
  14408. t['degree'] = 400;
  14409. t['ograve'] = 500;
  14410. t['Ccaron'] = 722;
  14411. t['ugrave'] = 556;
  14412. t['radical'] = 549;
  14413. t['Dcaron'] = 722;
  14414. t['rcommaaccent'] = 444;
  14415. t['Ntilde'] = 722;
  14416. t['otilde'] = 500;
  14417. t['Rcommaaccent'] = 722;
  14418. t['Lcommaaccent'] = 667;
  14419. t['Atilde'] = 722;
  14420. t['Aogonek'] = 722;
  14421. t['Aring'] = 722;
  14422. t['Otilde'] = 778;
  14423. t['zdotaccent'] = 444;
  14424. t['Ecaron'] = 667;
  14425. t['Iogonek'] = 389;
  14426. t['kcommaaccent'] = 556;
  14427. t['minus'] = 570;
  14428. t['Icircumflex'] = 389;
  14429. t['ncaron'] = 556;
  14430. t['tcommaaccent'] = 333;
  14431. t['logicalnot'] = 570;
  14432. t['odieresis'] = 500;
  14433. t['udieresis'] = 556;
  14434. t['notequal'] = 549;
  14435. t['gcommaaccent'] = 500;
  14436. t['eth'] = 500;
  14437. t['zcaron'] = 444;
  14438. t['ncommaaccent'] = 556;
  14439. t['onesuperior'] = 300;
  14440. t['imacron'] = 278;
  14441. t['Euro'] = 500;
  14442. });
  14443. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  14444. t['space'] = 250;
  14445. t['exclam'] = 389;
  14446. t['quotedbl'] = 555;
  14447. t['numbersign'] = 500;
  14448. t['dollar'] = 500;
  14449. t['percent'] = 833;
  14450. t['ampersand'] = 778;
  14451. t['quoteright'] = 333;
  14452. t['parenleft'] = 333;
  14453. t['parenright'] = 333;
  14454. t['asterisk'] = 500;
  14455. t['plus'] = 570;
  14456. t['comma'] = 250;
  14457. t['hyphen'] = 333;
  14458. t['period'] = 250;
  14459. t['slash'] = 278;
  14460. t['zero'] = 500;
  14461. t['one'] = 500;
  14462. t['two'] = 500;
  14463. t['three'] = 500;
  14464. t['four'] = 500;
  14465. t['five'] = 500;
  14466. t['six'] = 500;
  14467. t['seven'] = 500;
  14468. t['eight'] = 500;
  14469. t['nine'] = 500;
  14470. t['colon'] = 333;
  14471. t['semicolon'] = 333;
  14472. t['less'] = 570;
  14473. t['equal'] = 570;
  14474. t['greater'] = 570;
  14475. t['question'] = 500;
  14476. t['at'] = 832;
  14477. t['A'] = 667;
  14478. t['B'] = 667;
  14479. t['C'] = 667;
  14480. t['D'] = 722;
  14481. t['E'] = 667;
  14482. t['F'] = 667;
  14483. t['G'] = 722;
  14484. t['H'] = 778;
  14485. t['I'] = 389;
  14486. t['J'] = 500;
  14487. t['K'] = 667;
  14488. t['L'] = 611;
  14489. t['M'] = 889;
  14490. t['N'] = 722;
  14491. t['O'] = 722;
  14492. t['P'] = 611;
  14493. t['Q'] = 722;
  14494. t['R'] = 667;
  14495. t['S'] = 556;
  14496. t['T'] = 611;
  14497. t['U'] = 722;
  14498. t['V'] = 667;
  14499. t['W'] = 889;
  14500. t['X'] = 667;
  14501. t['Y'] = 611;
  14502. t['Z'] = 611;
  14503. t['bracketleft'] = 333;
  14504. t['backslash'] = 278;
  14505. t['bracketright'] = 333;
  14506. t['asciicircum'] = 570;
  14507. t['underscore'] = 500;
  14508. t['quoteleft'] = 333;
  14509. t['a'] = 500;
  14510. t['b'] = 500;
  14511. t['c'] = 444;
  14512. t['d'] = 500;
  14513. t['e'] = 444;
  14514. t['f'] = 333;
  14515. t['g'] = 500;
  14516. t['h'] = 556;
  14517. t['i'] = 278;
  14518. t['j'] = 278;
  14519. t['k'] = 500;
  14520. t['l'] = 278;
  14521. t['m'] = 778;
  14522. t['n'] = 556;
  14523. t['o'] = 500;
  14524. t['p'] = 500;
  14525. t['q'] = 500;
  14526. t['r'] = 389;
  14527. t['s'] = 389;
  14528. t['t'] = 278;
  14529. t['u'] = 556;
  14530. t['v'] = 444;
  14531. t['w'] = 667;
  14532. t['x'] = 500;
  14533. t['y'] = 444;
  14534. t['z'] = 389;
  14535. t['braceleft'] = 348;
  14536. t['bar'] = 220;
  14537. t['braceright'] = 348;
  14538. t['asciitilde'] = 570;
  14539. t['exclamdown'] = 389;
  14540. t['cent'] = 500;
  14541. t['sterling'] = 500;
  14542. t['fraction'] = 167;
  14543. t['yen'] = 500;
  14544. t['florin'] = 500;
  14545. t['section'] = 500;
  14546. t['currency'] = 500;
  14547. t['quotesingle'] = 278;
  14548. t['quotedblleft'] = 500;
  14549. t['guillemotleft'] = 500;
  14550. t['guilsinglleft'] = 333;
  14551. t['guilsinglright'] = 333;
  14552. t['fi'] = 556;
  14553. t['fl'] = 556;
  14554. t['endash'] = 500;
  14555. t['dagger'] = 500;
  14556. t['daggerdbl'] = 500;
  14557. t['periodcentered'] = 250;
  14558. t['paragraph'] = 500;
  14559. t['bullet'] = 350;
  14560. t['quotesinglbase'] = 333;
  14561. t['quotedblbase'] = 500;
  14562. t['quotedblright'] = 500;
  14563. t['guillemotright'] = 500;
  14564. t['ellipsis'] = 1000;
  14565. t['perthousand'] = 1000;
  14566. t['questiondown'] = 500;
  14567. t['grave'] = 333;
  14568. t['acute'] = 333;
  14569. t['circumflex'] = 333;
  14570. t['tilde'] = 333;
  14571. t['macron'] = 333;
  14572. t['breve'] = 333;
  14573. t['dotaccent'] = 333;
  14574. t['dieresis'] = 333;
  14575. t['ring'] = 333;
  14576. t['cedilla'] = 333;
  14577. t['hungarumlaut'] = 333;
  14578. t['ogonek'] = 333;
  14579. t['caron'] = 333;
  14580. t['emdash'] = 1000;
  14581. t['AE'] = 944;
  14582. t['ordfeminine'] = 266;
  14583. t['Lslash'] = 611;
  14584. t['Oslash'] = 722;
  14585. t['OE'] = 944;
  14586. t['ordmasculine'] = 300;
  14587. t['ae'] = 722;
  14588. t['dotlessi'] = 278;
  14589. t['lslash'] = 278;
  14590. t['oslash'] = 500;
  14591. t['oe'] = 722;
  14592. t['germandbls'] = 500;
  14593. t['Idieresis'] = 389;
  14594. t['eacute'] = 444;
  14595. t['abreve'] = 500;
  14596. t['uhungarumlaut'] = 556;
  14597. t['ecaron'] = 444;
  14598. t['Ydieresis'] = 611;
  14599. t['divide'] = 570;
  14600. t['Yacute'] = 611;
  14601. t['Acircumflex'] = 667;
  14602. t['aacute'] = 500;
  14603. t['Ucircumflex'] = 722;
  14604. t['yacute'] = 444;
  14605. t['scommaaccent'] = 389;
  14606. t['ecircumflex'] = 444;
  14607. t['Uring'] = 722;
  14608. t['Udieresis'] = 722;
  14609. t['aogonek'] = 500;
  14610. t['Uacute'] = 722;
  14611. t['uogonek'] = 556;
  14612. t['Edieresis'] = 667;
  14613. t['Dcroat'] = 722;
  14614. t['commaaccent'] = 250;
  14615. t['copyright'] = 747;
  14616. t['Emacron'] = 667;
  14617. t['ccaron'] = 444;
  14618. t['aring'] = 500;
  14619. t['Ncommaaccent'] = 722;
  14620. t['lacute'] = 278;
  14621. t['agrave'] = 500;
  14622. t['Tcommaaccent'] = 611;
  14623. t['Cacute'] = 667;
  14624. t['atilde'] = 500;
  14625. t['Edotaccent'] = 667;
  14626. t['scaron'] = 389;
  14627. t['scedilla'] = 389;
  14628. t['iacute'] = 278;
  14629. t['lozenge'] = 494;
  14630. t['Rcaron'] = 667;
  14631. t['Gcommaaccent'] = 722;
  14632. t['ucircumflex'] = 556;
  14633. t['acircumflex'] = 500;
  14634. t['Amacron'] = 667;
  14635. t['rcaron'] = 389;
  14636. t['ccedilla'] = 444;
  14637. t['Zdotaccent'] = 611;
  14638. t['Thorn'] = 611;
  14639. t['Omacron'] = 722;
  14640. t['Racute'] = 667;
  14641. t['Sacute'] = 556;
  14642. t['dcaron'] = 608;
  14643. t['Umacron'] = 722;
  14644. t['uring'] = 556;
  14645. t['threesuperior'] = 300;
  14646. t['Ograve'] = 722;
  14647. t['Agrave'] = 667;
  14648. t['Abreve'] = 667;
  14649. t['multiply'] = 570;
  14650. t['uacute'] = 556;
  14651. t['Tcaron'] = 611;
  14652. t['partialdiff'] = 494;
  14653. t['ydieresis'] = 444;
  14654. t['Nacute'] = 722;
  14655. t['icircumflex'] = 278;
  14656. t['Ecircumflex'] = 667;
  14657. t['adieresis'] = 500;
  14658. t['edieresis'] = 444;
  14659. t['cacute'] = 444;
  14660. t['nacute'] = 556;
  14661. t['umacron'] = 556;
  14662. t['Ncaron'] = 722;
  14663. t['Iacute'] = 389;
  14664. t['plusminus'] = 570;
  14665. t['brokenbar'] = 220;
  14666. t['registered'] = 747;
  14667. t['Gbreve'] = 722;
  14668. t['Idotaccent'] = 389;
  14669. t['summation'] = 600;
  14670. t['Egrave'] = 667;
  14671. t['racute'] = 389;
  14672. t['omacron'] = 500;
  14673. t['Zacute'] = 611;
  14674. t['Zcaron'] = 611;
  14675. t['greaterequal'] = 549;
  14676. t['Eth'] = 722;
  14677. t['Ccedilla'] = 667;
  14678. t['lcommaaccent'] = 278;
  14679. t['tcaron'] = 366;
  14680. t['eogonek'] = 444;
  14681. t['Uogonek'] = 722;
  14682. t['Aacute'] = 667;
  14683. t['Adieresis'] = 667;
  14684. t['egrave'] = 444;
  14685. t['zacute'] = 389;
  14686. t['iogonek'] = 278;
  14687. t['Oacute'] = 722;
  14688. t['oacute'] = 500;
  14689. t['amacron'] = 500;
  14690. t['sacute'] = 389;
  14691. t['idieresis'] = 278;
  14692. t['Ocircumflex'] = 722;
  14693. t['Ugrave'] = 722;
  14694. t['Delta'] = 612;
  14695. t['thorn'] = 500;
  14696. t['twosuperior'] = 300;
  14697. t['Odieresis'] = 722;
  14698. t['mu'] = 576;
  14699. t['igrave'] = 278;
  14700. t['ohungarumlaut'] = 500;
  14701. t['Eogonek'] = 667;
  14702. t['dcroat'] = 500;
  14703. t['threequarters'] = 750;
  14704. t['Scedilla'] = 556;
  14705. t['lcaron'] = 382;
  14706. t['Kcommaaccent'] = 667;
  14707. t['Lacute'] = 611;
  14708. t['trademark'] = 1000;
  14709. t['edotaccent'] = 444;
  14710. t['Igrave'] = 389;
  14711. t['Imacron'] = 389;
  14712. t['Lcaron'] = 611;
  14713. t['onehalf'] = 750;
  14714. t['lessequal'] = 549;
  14715. t['ocircumflex'] = 500;
  14716. t['ntilde'] = 556;
  14717. t['Uhungarumlaut'] = 722;
  14718. t['Eacute'] = 667;
  14719. t['emacron'] = 444;
  14720. t['gbreve'] = 500;
  14721. t['onequarter'] = 750;
  14722. t['Scaron'] = 556;
  14723. t['Scommaaccent'] = 556;
  14724. t['Ohungarumlaut'] = 722;
  14725. t['degree'] = 400;
  14726. t['ograve'] = 500;
  14727. t['Ccaron'] = 667;
  14728. t['ugrave'] = 556;
  14729. t['radical'] = 549;
  14730. t['Dcaron'] = 722;
  14731. t['rcommaaccent'] = 389;
  14732. t['Ntilde'] = 722;
  14733. t['otilde'] = 500;
  14734. t['Rcommaaccent'] = 667;
  14735. t['Lcommaaccent'] = 611;
  14736. t['Atilde'] = 667;
  14737. t['Aogonek'] = 667;
  14738. t['Aring'] = 667;
  14739. t['Otilde'] = 722;
  14740. t['zdotaccent'] = 389;
  14741. t['Ecaron'] = 667;
  14742. t['Iogonek'] = 389;
  14743. t['kcommaaccent'] = 500;
  14744. t['minus'] = 606;
  14745. t['Icircumflex'] = 389;
  14746. t['ncaron'] = 556;
  14747. t['tcommaaccent'] = 278;
  14748. t['logicalnot'] = 606;
  14749. t['odieresis'] = 500;
  14750. t['udieresis'] = 556;
  14751. t['notequal'] = 549;
  14752. t['gcommaaccent'] = 500;
  14753. t['eth'] = 500;
  14754. t['zcaron'] = 389;
  14755. t['ncommaaccent'] = 556;
  14756. t['onesuperior'] = 300;
  14757. t['imacron'] = 278;
  14758. t['Euro'] = 500;
  14759. });
  14760. t['Times-Italic'] = getLookupTableFactory(function (t) {
  14761. t['space'] = 250;
  14762. t['exclam'] = 333;
  14763. t['quotedbl'] = 420;
  14764. t['numbersign'] = 500;
  14765. t['dollar'] = 500;
  14766. t['percent'] = 833;
  14767. t['ampersand'] = 778;
  14768. t['quoteright'] = 333;
  14769. t['parenleft'] = 333;
  14770. t['parenright'] = 333;
  14771. t['asterisk'] = 500;
  14772. t['plus'] = 675;
  14773. t['comma'] = 250;
  14774. t['hyphen'] = 333;
  14775. t['period'] = 250;
  14776. t['slash'] = 278;
  14777. t['zero'] = 500;
  14778. t['one'] = 500;
  14779. t['two'] = 500;
  14780. t['three'] = 500;
  14781. t['four'] = 500;
  14782. t['five'] = 500;
  14783. t['six'] = 500;
  14784. t['seven'] = 500;
  14785. t['eight'] = 500;
  14786. t['nine'] = 500;
  14787. t['colon'] = 333;
  14788. t['semicolon'] = 333;
  14789. t['less'] = 675;
  14790. t['equal'] = 675;
  14791. t['greater'] = 675;
  14792. t['question'] = 500;
  14793. t['at'] = 920;
  14794. t['A'] = 611;
  14795. t['B'] = 611;
  14796. t['C'] = 667;
  14797. t['D'] = 722;
  14798. t['E'] = 611;
  14799. t['F'] = 611;
  14800. t['G'] = 722;
  14801. t['H'] = 722;
  14802. t['I'] = 333;
  14803. t['J'] = 444;
  14804. t['K'] = 667;
  14805. t['L'] = 556;
  14806. t['M'] = 833;
  14807. t['N'] = 667;
  14808. t['O'] = 722;
  14809. t['P'] = 611;
  14810. t['Q'] = 722;
  14811. t['R'] = 611;
  14812. t['S'] = 500;
  14813. t['T'] = 556;
  14814. t['U'] = 722;
  14815. t['V'] = 611;
  14816. t['W'] = 833;
  14817. t['X'] = 611;
  14818. t['Y'] = 556;
  14819. t['Z'] = 556;
  14820. t['bracketleft'] = 389;
  14821. t['backslash'] = 278;
  14822. t['bracketright'] = 389;
  14823. t['asciicircum'] = 422;
  14824. t['underscore'] = 500;
  14825. t['quoteleft'] = 333;
  14826. t['a'] = 500;
  14827. t['b'] = 500;
  14828. t['c'] = 444;
  14829. t['d'] = 500;
  14830. t['e'] = 444;
  14831. t['f'] = 278;
  14832. t['g'] = 500;
  14833. t['h'] = 500;
  14834. t['i'] = 278;
  14835. t['j'] = 278;
  14836. t['k'] = 444;
  14837. t['l'] = 278;
  14838. t['m'] = 722;
  14839. t['n'] = 500;
  14840. t['o'] = 500;
  14841. t['p'] = 500;
  14842. t['q'] = 500;
  14843. t['r'] = 389;
  14844. t['s'] = 389;
  14845. t['t'] = 278;
  14846. t['u'] = 500;
  14847. t['v'] = 444;
  14848. t['w'] = 667;
  14849. t['x'] = 444;
  14850. t['y'] = 444;
  14851. t['z'] = 389;
  14852. t['braceleft'] = 400;
  14853. t['bar'] = 275;
  14854. t['braceright'] = 400;
  14855. t['asciitilde'] = 541;
  14856. t['exclamdown'] = 389;
  14857. t['cent'] = 500;
  14858. t['sterling'] = 500;
  14859. t['fraction'] = 167;
  14860. t['yen'] = 500;
  14861. t['florin'] = 500;
  14862. t['section'] = 500;
  14863. t['currency'] = 500;
  14864. t['quotesingle'] = 214;
  14865. t['quotedblleft'] = 556;
  14866. t['guillemotleft'] = 500;
  14867. t['guilsinglleft'] = 333;
  14868. t['guilsinglright'] = 333;
  14869. t['fi'] = 500;
  14870. t['fl'] = 500;
  14871. t['endash'] = 500;
  14872. t['dagger'] = 500;
  14873. t['daggerdbl'] = 500;
  14874. t['periodcentered'] = 250;
  14875. t['paragraph'] = 523;
  14876. t['bullet'] = 350;
  14877. t['quotesinglbase'] = 333;
  14878. t['quotedblbase'] = 556;
  14879. t['quotedblright'] = 556;
  14880. t['guillemotright'] = 500;
  14881. t['ellipsis'] = 889;
  14882. t['perthousand'] = 1000;
  14883. t['questiondown'] = 500;
  14884. t['grave'] = 333;
  14885. t['acute'] = 333;
  14886. t['circumflex'] = 333;
  14887. t['tilde'] = 333;
  14888. t['macron'] = 333;
  14889. t['breve'] = 333;
  14890. t['dotaccent'] = 333;
  14891. t['dieresis'] = 333;
  14892. t['ring'] = 333;
  14893. t['cedilla'] = 333;
  14894. t['hungarumlaut'] = 333;
  14895. t['ogonek'] = 333;
  14896. t['caron'] = 333;
  14897. t['emdash'] = 889;
  14898. t['AE'] = 889;
  14899. t['ordfeminine'] = 276;
  14900. t['Lslash'] = 556;
  14901. t['Oslash'] = 722;
  14902. t['OE'] = 944;
  14903. t['ordmasculine'] = 310;
  14904. t['ae'] = 667;
  14905. t['dotlessi'] = 278;
  14906. t['lslash'] = 278;
  14907. t['oslash'] = 500;
  14908. t['oe'] = 667;
  14909. t['germandbls'] = 500;
  14910. t['Idieresis'] = 333;
  14911. t['eacute'] = 444;
  14912. t['abreve'] = 500;
  14913. t['uhungarumlaut'] = 500;
  14914. t['ecaron'] = 444;
  14915. t['Ydieresis'] = 556;
  14916. t['divide'] = 675;
  14917. t['Yacute'] = 556;
  14918. t['Acircumflex'] = 611;
  14919. t['aacute'] = 500;
  14920. t['Ucircumflex'] = 722;
  14921. t['yacute'] = 444;
  14922. t['scommaaccent'] = 389;
  14923. t['ecircumflex'] = 444;
  14924. t['Uring'] = 722;
  14925. t['Udieresis'] = 722;
  14926. t['aogonek'] = 500;
  14927. t['Uacute'] = 722;
  14928. t['uogonek'] = 500;
  14929. t['Edieresis'] = 611;
  14930. t['Dcroat'] = 722;
  14931. t['commaaccent'] = 250;
  14932. t['copyright'] = 760;
  14933. t['Emacron'] = 611;
  14934. t['ccaron'] = 444;
  14935. t['aring'] = 500;
  14936. t['Ncommaaccent'] = 667;
  14937. t['lacute'] = 278;
  14938. t['agrave'] = 500;
  14939. t['Tcommaaccent'] = 556;
  14940. t['Cacute'] = 667;
  14941. t['atilde'] = 500;
  14942. t['Edotaccent'] = 611;
  14943. t['scaron'] = 389;
  14944. t['scedilla'] = 389;
  14945. t['iacute'] = 278;
  14946. t['lozenge'] = 471;
  14947. t['Rcaron'] = 611;
  14948. t['Gcommaaccent'] = 722;
  14949. t['ucircumflex'] = 500;
  14950. t['acircumflex'] = 500;
  14951. t['Amacron'] = 611;
  14952. t['rcaron'] = 389;
  14953. t['ccedilla'] = 444;
  14954. t['Zdotaccent'] = 556;
  14955. t['Thorn'] = 611;
  14956. t['Omacron'] = 722;
  14957. t['Racute'] = 611;
  14958. t['Sacute'] = 500;
  14959. t['dcaron'] = 544;
  14960. t['Umacron'] = 722;
  14961. t['uring'] = 500;
  14962. t['threesuperior'] = 300;
  14963. t['Ograve'] = 722;
  14964. t['Agrave'] = 611;
  14965. t['Abreve'] = 611;
  14966. t['multiply'] = 675;
  14967. t['uacute'] = 500;
  14968. t['Tcaron'] = 556;
  14969. t['partialdiff'] = 476;
  14970. t['ydieresis'] = 444;
  14971. t['Nacute'] = 667;
  14972. t['icircumflex'] = 278;
  14973. t['Ecircumflex'] = 611;
  14974. t['adieresis'] = 500;
  14975. t['edieresis'] = 444;
  14976. t['cacute'] = 444;
  14977. t['nacute'] = 500;
  14978. t['umacron'] = 500;
  14979. t['Ncaron'] = 667;
  14980. t['Iacute'] = 333;
  14981. t['plusminus'] = 675;
  14982. t['brokenbar'] = 275;
  14983. t['registered'] = 760;
  14984. t['Gbreve'] = 722;
  14985. t['Idotaccent'] = 333;
  14986. t['summation'] = 600;
  14987. t['Egrave'] = 611;
  14988. t['racute'] = 389;
  14989. t['omacron'] = 500;
  14990. t['Zacute'] = 556;
  14991. t['Zcaron'] = 556;
  14992. t['greaterequal'] = 549;
  14993. t['Eth'] = 722;
  14994. t['Ccedilla'] = 667;
  14995. t['lcommaaccent'] = 278;
  14996. t['tcaron'] = 300;
  14997. t['eogonek'] = 444;
  14998. t['Uogonek'] = 722;
  14999. t['Aacute'] = 611;
  15000. t['Adieresis'] = 611;
  15001. t['egrave'] = 444;
  15002. t['zacute'] = 389;
  15003. t['iogonek'] = 278;
  15004. t['Oacute'] = 722;
  15005. t['oacute'] = 500;
  15006. t['amacron'] = 500;
  15007. t['sacute'] = 389;
  15008. t['idieresis'] = 278;
  15009. t['Ocircumflex'] = 722;
  15010. t['Ugrave'] = 722;
  15011. t['Delta'] = 612;
  15012. t['thorn'] = 500;
  15013. t['twosuperior'] = 300;
  15014. t['Odieresis'] = 722;
  15015. t['mu'] = 500;
  15016. t['igrave'] = 278;
  15017. t['ohungarumlaut'] = 500;
  15018. t['Eogonek'] = 611;
  15019. t['dcroat'] = 500;
  15020. t['threequarters'] = 750;
  15021. t['Scedilla'] = 500;
  15022. t['lcaron'] = 300;
  15023. t['Kcommaaccent'] = 667;
  15024. t['Lacute'] = 556;
  15025. t['trademark'] = 980;
  15026. t['edotaccent'] = 444;
  15027. t['Igrave'] = 333;
  15028. t['Imacron'] = 333;
  15029. t['Lcaron'] = 611;
  15030. t['onehalf'] = 750;
  15031. t['lessequal'] = 549;
  15032. t['ocircumflex'] = 500;
  15033. t['ntilde'] = 500;
  15034. t['Uhungarumlaut'] = 722;
  15035. t['Eacute'] = 611;
  15036. t['emacron'] = 444;
  15037. t['gbreve'] = 500;
  15038. t['onequarter'] = 750;
  15039. t['Scaron'] = 500;
  15040. t['Scommaaccent'] = 500;
  15041. t['Ohungarumlaut'] = 722;
  15042. t['degree'] = 400;
  15043. t['ograve'] = 500;
  15044. t['Ccaron'] = 667;
  15045. t['ugrave'] = 500;
  15046. t['radical'] = 453;
  15047. t['Dcaron'] = 722;
  15048. t['rcommaaccent'] = 389;
  15049. t['Ntilde'] = 667;
  15050. t['otilde'] = 500;
  15051. t['Rcommaaccent'] = 611;
  15052. t['Lcommaaccent'] = 556;
  15053. t['Atilde'] = 611;
  15054. t['Aogonek'] = 611;
  15055. t['Aring'] = 611;
  15056. t['Otilde'] = 722;
  15057. t['zdotaccent'] = 389;
  15058. t['Ecaron'] = 611;
  15059. t['Iogonek'] = 333;
  15060. t['kcommaaccent'] = 444;
  15061. t['minus'] = 675;
  15062. t['Icircumflex'] = 333;
  15063. t['ncaron'] = 500;
  15064. t['tcommaaccent'] = 278;
  15065. t['logicalnot'] = 675;
  15066. t['odieresis'] = 500;
  15067. t['udieresis'] = 500;
  15068. t['notequal'] = 549;
  15069. t['gcommaaccent'] = 500;
  15070. t['eth'] = 500;
  15071. t['zcaron'] = 389;
  15072. t['ncommaaccent'] = 500;
  15073. t['onesuperior'] = 300;
  15074. t['imacron'] = 278;
  15075. t['Euro'] = 500;
  15076. });
  15077. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  15078. t['space'] = 278;
  15079. t['a1'] = 974;
  15080. t['a2'] = 961;
  15081. t['a202'] = 974;
  15082. t['a3'] = 980;
  15083. t['a4'] = 719;
  15084. t['a5'] = 789;
  15085. t['a119'] = 790;
  15086. t['a118'] = 791;
  15087. t['a117'] = 690;
  15088. t['a11'] = 960;
  15089. t['a12'] = 939;
  15090. t['a13'] = 549;
  15091. t['a14'] = 855;
  15092. t['a15'] = 911;
  15093. t['a16'] = 933;
  15094. t['a105'] = 911;
  15095. t['a17'] = 945;
  15096. t['a18'] = 974;
  15097. t['a19'] = 755;
  15098. t['a20'] = 846;
  15099. t['a21'] = 762;
  15100. t['a22'] = 761;
  15101. t['a23'] = 571;
  15102. t['a24'] = 677;
  15103. t['a25'] = 763;
  15104. t['a26'] = 760;
  15105. t['a27'] = 759;
  15106. t['a28'] = 754;
  15107. t['a6'] = 494;
  15108. t['a7'] = 552;
  15109. t['a8'] = 537;
  15110. t['a9'] = 577;
  15111. t['a10'] = 692;
  15112. t['a29'] = 786;
  15113. t['a30'] = 788;
  15114. t['a31'] = 788;
  15115. t['a32'] = 790;
  15116. t['a33'] = 793;
  15117. t['a34'] = 794;
  15118. t['a35'] = 816;
  15119. t['a36'] = 823;
  15120. t['a37'] = 789;
  15121. t['a38'] = 841;
  15122. t['a39'] = 823;
  15123. t['a40'] = 833;
  15124. t['a41'] = 816;
  15125. t['a42'] = 831;
  15126. t['a43'] = 923;
  15127. t['a44'] = 744;
  15128. t['a45'] = 723;
  15129. t['a46'] = 749;
  15130. t['a47'] = 790;
  15131. t['a48'] = 792;
  15132. t['a49'] = 695;
  15133. t['a50'] = 776;
  15134. t['a51'] = 768;
  15135. t['a52'] = 792;
  15136. t['a53'] = 759;
  15137. t['a54'] = 707;
  15138. t['a55'] = 708;
  15139. t['a56'] = 682;
  15140. t['a57'] = 701;
  15141. t['a58'] = 826;
  15142. t['a59'] = 815;
  15143. t['a60'] = 789;
  15144. t['a61'] = 789;
  15145. t['a62'] = 707;
  15146. t['a63'] = 687;
  15147. t['a64'] = 696;
  15148. t['a65'] = 689;
  15149. t['a66'] = 786;
  15150. t['a67'] = 787;
  15151. t['a68'] = 713;
  15152. t['a69'] = 791;
  15153. t['a70'] = 785;
  15154. t['a71'] = 791;
  15155. t['a72'] = 873;
  15156. t['a73'] = 761;
  15157. t['a74'] = 762;
  15158. t['a203'] = 762;
  15159. t['a75'] = 759;
  15160. t['a204'] = 759;
  15161. t['a76'] = 892;
  15162. t['a77'] = 892;
  15163. t['a78'] = 788;
  15164. t['a79'] = 784;
  15165. t['a81'] = 438;
  15166. t['a82'] = 138;
  15167. t['a83'] = 277;
  15168. t['a84'] = 415;
  15169. t['a97'] = 392;
  15170. t['a98'] = 392;
  15171. t['a99'] = 668;
  15172. t['a100'] = 668;
  15173. t['a89'] = 390;
  15174. t['a90'] = 390;
  15175. t['a93'] = 317;
  15176. t['a94'] = 317;
  15177. t['a91'] = 276;
  15178. t['a92'] = 276;
  15179. t['a205'] = 509;
  15180. t['a85'] = 509;
  15181. t['a206'] = 410;
  15182. t['a86'] = 410;
  15183. t['a87'] = 234;
  15184. t['a88'] = 234;
  15185. t['a95'] = 334;
  15186. t['a96'] = 334;
  15187. t['a101'] = 732;
  15188. t['a102'] = 544;
  15189. t['a103'] = 544;
  15190. t['a104'] = 910;
  15191. t['a106'] = 667;
  15192. t['a107'] = 760;
  15193. t['a108'] = 760;
  15194. t['a112'] = 776;
  15195. t['a111'] = 595;
  15196. t['a110'] = 694;
  15197. t['a109'] = 626;
  15198. t['a120'] = 788;
  15199. t['a121'] = 788;
  15200. t['a122'] = 788;
  15201. t['a123'] = 788;
  15202. t['a124'] = 788;
  15203. t['a125'] = 788;
  15204. t['a126'] = 788;
  15205. t['a127'] = 788;
  15206. t['a128'] = 788;
  15207. t['a129'] = 788;
  15208. t['a130'] = 788;
  15209. t['a131'] = 788;
  15210. t['a132'] = 788;
  15211. t['a133'] = 788;
  15212. t['a134'] = 788;
  15213. t['a135'] = 788;
  15214. t['a136'] = 788;
  15215. t['a137'] = 788;
  15216. t['a138'] = 788;
  15217. t['a139'] = 788;
  15218. t['a140'] = 788;
  15219. t['a141'] = 788;
  15220. t['a142'] = 788;
  15221. t['a143'] = 788;
  15222. t['a144'] = 788;
  15223. t['a145'] = 788;
  15224. t['a146'] = 788;
  15225. t['a147'] = 788;
  15226. t['a148'] = 788;
  15227. t['a149'] = 788;
  15228. t['a150'] = 788;
  15229. t['a151'] = 788;
  15230. t['a152'] = 788;
  15231. t['a153'] = 788;
  15232. t['a154'] = 788;
  15233. t['a155'] = 788;
  15234. t['a156'] = 788;
  15235. t['a157'] = 788;
  15236. t['a158'] = 788;
  15237. t['a159'] = 788;
  15238. t['a160'] = 894;
  15239. t['a161'] = 838;
  15240. t['a163'] = 1016;
  15241. t['a164'] = 458;
  15242. t['a196'] = 748;
  15243. t['a165'] = 924;
  15244. t['a192'] = 748;
  15245. t['a166'] = 918;
  15246. t['a167'] = 927;
  15247. t['a168'] = 928;
  15248. t['a169'] = 928;
  15249. t['a170'] = 834;
  15250. t['a171'] = 873;
  15251. t['a172'] = 828;
  15252. t['a173'] = 924;
  15253. t['a162'] = 924;
  15254. t['a174'] = 917;
  15255. t['a175'] = 930;
  15256. t['a176'] = 931;
  15257. t['a177'] = 463;
  15258. t['a178'] = 883;
  15259. t['a179'] = 836;
  15260. t['a193'] = 836;
  15261. t['a180'] = 867;
  15262. t['a199'] = 867;
  15263. t['a181'] = 696;
  15264. t['a200'] = 696;
  15265. t['a182'] = 874;
  15266. t['a201'] = 874;
  15267. t['a183'] = 760;
  15268. t['a184'] = 946;
  15269. t['a197'] = 771;
  15270. t['a185'] = 865;
  15271. t['a194'] = 771;
  15272. t['a198'] = 888;
  15273. t['a186'] = 967;
  15274. t['a195'] = 888;
  15275. t['a187'] = 831;
  15276. t['a188'] = 873;
  15277. t['a189'] = 927;
  15278. t['a190'] = 970;
  15279. t['a191'] = 918;
  15280. });
  15281. });
  15282. exports.getMetrics = getMetrics;
  15283. }));
  15284. (function (root, factory) {
  15285. {
  15286. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  15287. }
  15288. }(this, function (exports, sharedUtil) {
  15289. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  15290. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  15291. // Workaround for missing math precison in JS.
  15292. var MASK_HIGH = 0xffff0000;
  15293. var MASK_LOW = 0xffff;
  15294. function MurmurHash3_64 (seed) {
  15295. var SEED = 0xc3d2e1f0;
  15296. this.h1 = seed ? seed & 0xffffffff : SEED;
  15297. this.h2 = seed ? seed & 0xffffffff : SEED;
  15298. }
  15299. var alwaysUseUint32ArrayView = false;
  15300. // old webkits have issues with non-aligned arrays
  15301. try {
  15302. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  15303. } catch (e) {
  15304. alwaysUseUint32ArrayView = true;
  15305. }
  15306. MurmurHash3_64.prototype = {
  15307. update: function MurmurHash3_64_update(input) {
  15308. var useUint32ArrayView = alwaysUseUint32ArrayView;
  15309. var i;
  15310. if (typeof input === 'string') {
  15311. var data = new Uint8Array(input.length * 2);
  15312. var length = 0;
  15313. for (i = 0; i < input.length; i++) {
  15314. var code = input.charCodeAt(i);
  15315. if (code <= 0xff) {
  15316. data[length++] = code;
  15317. }
  15318. else {
  15319. data[length++] = code >>> 8;
  15320. data[length++] = code & 0xff;
  15321. }
  15322. }
  15323. } else if (input instanceof Uint8Array) {
  15324. data = input;
  15325. length = data.length;
  15326. } else if (typeof input === 'object' && ('length' in input)) {
  15327. // processing regular arrays as well, e.g. for IE9
  15328. data = input;
  15329. length = data.length;
  15330. useUint32ArrayView = true;
  15331. } else {
  15332. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  15333. 'Input must be a string or array.');
  15334. }
  15335. var blockCounts = length >> 2;
  15336. var tailLength = length - blockCounts * 4;
  15337. // we don't care about endianness here
  15338. var dataUint32 = useUint32ArrayView ?
  15339. new Uint32ArrayView(data, blockCounts) :
  15340. new Uint32Array(data.buffer, 0, blockCounts);
  15341. var k1 = 0;
  15342. var k2 = 0;
  15343. var h1 = this.h1;
  15344. var h2 = this.h2;
  15345. var C1 = 0xcc9e2d51;
  15346. var C2 = 0x1b873593;
  15347. var C1_LOW = C1 & MASK_LOW;
  15348. var C2_LOW = C2 & MASK_LOW;
  15349. for (i = 0; i < blockCounts; i++) {
  15350. if (i & 1) {
  15351. k1 = dataUint32[i];
  15352. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15353. k1 = k1 << 15 | k1 >>> 17;
  15354. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15355. h1 ^= k1;
  15356. h1 = h1 << 13 | h1 >>> 19;
  15357. h1 = h1 * 5 + 0xe6546b64;
  15358. } else {
  15359. k2 = dataUint32[i];
  15360. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  15361. k2 = k2 << 15 | k2 >>> 17;
  15362. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  15363. h2 ^= k2;
  15364. h2 = h2 << 13 | h2 >>> 19;
  15365. h2 = h2 * 5 + 0xe6546b64;
  15366. }
  15367. }
  15368. k1 = 0;
  15369. switch (tailLength) {
  15370. case 3:
  15371. k1 ^= data[blockCounts * 4 + 2] << 16;
  15372. /* falls through */
  15373. case 2:
  15374. k1 ^= data[blockCounts * 4 + 1] << 8;
  15375. /* falls through */
  15376. case 1:
  15377. k1 ^= data[blockCounts * 4];
  15378. /* falls through */
  15379. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15380. k1 = k1 << 15 | k1 >>> 17;
  15381. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15382. if (blockCounts & 1) {
  15383. h1 ^= k1;
  15384. } else {
  15385. h2 ^= k1;
  15386. }
  15387. }
  15388. this.h1 = h1;
  15389. this.h2 = h2;
  15390. return this;
  15391. },
  15392. hexdigest: function MurmurHash3_64_hexdigest () {
  15393. var h1 = this.h1;
  15394. var h2 = this.h2;
  15395. h1 ^= h2 >>> 1;
  15396. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15397. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15398. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15399. h1 ^= h2 >>> 1;
  15400. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15401. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15402. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15403. h1 ^= h2 >>> 1;
  15404. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15405. var hex = (arr[i] >>> 0).toString(16);
  15406. while (hex.length < 8) {
  15407. hex = '0' + hex;
  15408. }
  15409. str += hex;
  15410. }
  15411. return str;
  15412. }
  15413. };
  15414. return MurmurHash3_64;
  15415. })();
  15416. exports.MurmurHash3_64 = MurmurHash3_64;
  15417. }));
  15418. (function (root, factory) {
  15419. {
  15420. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15421. }
  15422. }(this, function (exports, sharedUtil) {
  15423. var isArray = sharedUtil.isArray;
  15424. var Name = (function NameClosure() {
  15425. function Name(name) {
  15426. this.name = name;
  15427. }
  15428. Name.prototype = {};
  15429. var nameCache = Object.create(null);
  15430. Name.get = function Name_get(name) {
  15431. var nameValue = nameCache[name];
  15432. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15433. };
  15434. return Name;
  15435. })();
  15436. var Cmd = (function CmdClosure() {
  15437. function Cmd(cmd) {
  15438. this.cmd = cmd;
  15439. }
  15440. Cmd.prototype = {};
  15441. var cmdCache = Object.create(null);
  15442. Cmd.get = function Cmd_get(cmd) {
  15443. var cmdValue = cmdCache[cmd];
  15444. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15445. };
  15446. return Cmd;
  15447. })();
  15448. var Dict = (function DictClosure() {
  15449. var nonSerializable = function nonSerializableClosure() {
  15450. return nonSerializable; // creating closure on some variable
  15451. };
  15452. // xref is optional
  15453. function Dict(xref) {
  15454. // Map should only be used internally, use functions below to access.
  15455. this.map = Object.create(null);
  15456. this.xref = xref;
  15457. this.objId = null;
  15458. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15459. }
  15460. Dict.prototype = {
  15461. assignXref: function Dict_assignXref(newXref) {
  15462. this.xref = newXref;
  15463. },
  15464. // automatically dereferences Ref objects
  15465. get: function Dict_get(key1, key2, key3) {
  15466. var value;
  15467. var xref = this.xref;
  15468. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15469. typeof key2 === 'undefined') {
  15470. return xref ? xref.fetchIfRef(value) : value;
  15471. }
  15472. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15473. typeof key3 === 'undefined') {
  15474. return xref ? xref.fetchIfRef(value) : value;
  15475. }
  15476. value = this.map[key3] || null;
  15477. return xref ? xref.fetchIfRef(value) : value;
  15478. },
  15479. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15480. getAsync: function Dict_getAsync(key1, key2, key3) {
  15481. var value;
  15482. var xref = this.xref;
  15483. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15484. typeof key2 === 'undefined') {
  15485. if (xref) {
  15486. return xref.fetchIfRefAsync(value);
  15487. }
  15488. return Promise.resolve(value);
  15489. }
  15490. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15491. typeof key3 === 'undefined') {
  15492. if (xref) {
  15493. return xref.fetchIfRefAsync(value);
  15494. }
  15495. return Promise.resolve(value);
  15496. }
  15497. value = this.map[key3] || null;
  15498. if (xref) {
  15499. return xref.fetchIfRefAsync(value);
  15500. }
  15501. return Promise.resolve(value);
  15502. },
  15503. // Same as get(), but dereferences all elements if the result is an Array.
  15504. getArray: function Dict_getArray(key1, key2, key3) {
  15505. var value = this.get(key1, key2, key3);
  15506. var xref = this.xref;
  15507. if (!isArray(value) || !xref) {
  15508. return value;
  15509. }
  15510. value = value.slice(); // Ensure that we don't modify the Dict data.
  15511. for (var i = 0, ii = value.length; i < ii; i++) {
  15512. if (!isRef(value[i])) {
  15513. continue;
  15514. }
  15515. value[i] = xref.fetch(value[i]);
  15516. }
  15517. return value;
  15518. },
  15519. // no dereferencing
  15520. getRaw: function Dict_getRaw(key) {
  15521. return this.map[key];
  15522. },
  15523. getKeys: function Dict_getKeys() {
  15524. return Object.keys(this.map);
  15525. },
  15526. set: function Dict_set(key, value) {
  15527. this.map[key] = value;
  15528. },
  15529. has: function Dict_has(key) {
  15530. return key in this.map;
  15531. },
  15532. forEach: function Dict_forEach(callback) {
  15533. for (var key in this.map) {
  15534. callback(key, this.get(key));
  15535. }
  15536. }
  15537. };
  15538. Dict.empty = new Dict(null);
  15539. Dict.merge = function Dict_merge(xref, dictArray) {
  15540. var mergedDict = new Dict(xref);
  15541. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15542. var dict = dictArray[i];
  15543. if (!isDict(dict)) {
  15544. continue;
  15545. }
  15546. for (var keyName in dict.map) {
  15547. if (mergedDict.map[keyName]) {
  15548. continue;
  15549. }
  15550. mergedDict.map[keyName] = dict.map[keyName];
  15551. }
  15552. }
  15553. return mergedDict;
  15554. };
  15555. return Dict;
  15556. })();
  15557. var Ref = (function RefClosure() {
  15558. function Ref(num, gen) {
  15559. this.num = num;
  15560. this.gen = gen;
  15561. }
  15562. Ref.prototype = {
  15563. toString: function Ref_toString() {
  15564. // This function is hot, so we make the string as compact as possible.
  15565. // |this.gen| is almost always zero, so we treat that case specially.
  15566. var str = this.num + 'R';
  15567. if (this.gen !== 0) {
  15568. str += this.gen;
  15569. }
  15570. return str;
  15571. }
  15572. };
  15573. return Ref;
  15574. })();
  15575. // The reference is identified by number and generation.
  15576. // This structure stores only one instance of the reference.
  15577. var RefSet = (function RefSetClosure() {
  15578. function RefSet() {
  15579. this.dict = Object.create(null);
  15580. }
  15581. RefSet.prototype = {
  15582. has: function RefSet_has(ref) {
  15583. return ref.toString() in this.dict;
  15584. },
  15585. put: function RefSet_put(ref) {
  15586. this.dict[ref.toString()] = true;
  15587. },
  15588. remove: function RefSet_remove(ref) {
  15589. delete this.dict[ref.toString()];
  15590. }
  15591. };
  15592. return RefSet;
  15593. })();
  15594. var RefSetCache = (function RefSetCacheClosure() {
  15595. function RefSetCache() {
  15596. this.dict = Object.create(null);
  15597. }
  15598. RefSetCache.prototype = {
  15599. get: function RefSetCache_get(ref) {
  15600. return this.dict[ref.toString()];
  15601. },
  15602. has: function RefSetCache_has(ref) {
  15603. return ref.toString() in this.dict;
  15604. },
  15605. put: function RefSetCache_put(ref, obj) {
  15606. this.dict[ref.toString()] = obj;
  15607. },
  15608. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15609. this.dict[ref.toString()] = this.get(aliasRef);
  15610. },
  15611. forEach: function RefSetCache_forEach(fn, thisArg) {
  15612. for (var i in this.dict) {
  15613. fn.call(thisArg, this.dict[i]);
  15614. }
  15615. },
  15616. clear: function RefSetCache_clear() {
  15617. this.dict = Object.create(null);
  15618. }
  15619. };
  15620. return RefSetCache;
  15621. })();
  15622. function isName(v) {
  15623. return v instanceof Name;
  15624. }
  15625. function isCmd(v, cmd) {
  15626. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15627. }
  15628. function isDict(v, type) {
  15629. if (!(v instanceof Dict)) {
  15630. return false;
  15631. }
  15632. if (!type) {
  15633. return true;
  15634. }
  15635. var dictType = v.get('Type');
  15636. return isName(dictType) && dictType.name === type;
  15637. }
  15638. function isRef(v) {
  15639. return v instanceof Ref;
  15640. }
  15641. function isStream(v) {
  15642. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15643. }
  15644. exports.Cmd = Cmd;
  15645. exports.Dict = Dict;
  15646. exports.Name = Name;
  15647. exports.Ref = Ref;
  15648. exports.RefSet = RefSet;
  15649. exports.RefSetCache = RefSetCache;
  15650. exports.isCmd = isCmd;
  15651. exports.isDict = isDict;
  15652. exports.isName = isName;
  15653. exports.isRef = isRef;
  15654. exports.isStream = isStream;
  15655. }));
  15656. (function (root, factory) {
  15657. {
  15658. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  15659. }
  15660. }(this, function (exports, sharedUtil) {
  15661. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15662. /**
  15663. * Hold a map of decoded fonts and of the standard fourteen Type1
  15664. * fonts and their acronyms.
  15665. */
  15666. var getStdFontMap = getLookupTableFactory(function (t) {
  15667. t['ArialNarrow'] = 'Helvetica';
  15668. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  15669. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  15670. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  15671. t['ArialBlack'] = 'Helvetica';
  15672. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  15673. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  15674. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  15675. t['Arial'] = 'Helvetica';
  15676. t['Arial-Bold'] = 'Helvetica-Bold';
  15677. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  15678. t['Arial-Italic'] = 'Helvetica-Oblique';
  15679. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  15680. t['Arial-BoldMT'] = 'Helvetica-Bold';
  15681. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  15682. t['ArialMT'] = 'Helvetica';
  15683. t['Courier-Bold'] = 'Courier-Bold';
  15684. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  15685. t['Courier-Italic'] = 'Courier-Oblique';
  15686. t['CourierNew'] = 'Courier';
  15687. t['CourierNew-Bold'] = 'Courier-Bold';
  15688. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  15689. t['CourierNew-Italic'] = 'Courier-Oblique';
  15690. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  15691. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  15692. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  15693. t['CourierNewPSMT'] = 'Courier';
  15694. t['Helvetica'] = 'Helvetica';
  15695. t['Helvetica-Bold'] = 'Helvetica-Bold';
  15696. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  15697. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  15698. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  15699. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  15700. t['Symbol-Bold'] = 'Symbol';
  15701. t['Symbol-BoldItalic'] = 'Symbol';
  15702. t['Symbol-Italic'] = 'Symbol';
  15703. t['TimesNewRoman'] = 'Times-Roman';
  15704. t['TimesNewRoman-Bold'] = 'Times-Bold';
  15705. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  15706. t['TimesNewRoman-Italic'] = 'Times-Italic';
  15707. t['TimesNewRomanPS'] = 'Times-Roman';
  15708. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  15709. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  15710. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  15711. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  15712. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  15713. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  15714. t['TimesNewRomanPSMT'] = 'Times-Roman';
  15715. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  15716. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  15717. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  15718. });
  15719. /**
  15720. * Holds the map of the non-standard fonts that might be included as
  15721. * a standard fonts without glyph data.
  15722. */
  15723. var getNonStdFontMap = getLookupTableFactory(function (t) {
  15724. t['CenturyGothic'] = 'Helvetica';
  15725. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  15726. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  15727. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  15728. t['ComicSansMS'] = 'Comic Sans MS';
  15729. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  15730. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  15731. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  15732. t['LucidaConsole'] = 'Courier';
  15733. t['LucidaConsole-Bold'] = 'Courier-Bold';
  15734. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  15735. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  15736. t['MS-Gothic'] = 'MS Gothic';
  15737. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  15738. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  15739. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  15740. t['MS-Mincho'] = 'MS Mincho';
  15741. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  15742. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  15743. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  15744. t['MS-PGothic'] = 'MS PGothic';
  15745. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  15746. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  15747. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  15748. t['MS-PMincho'] = 'MS PMincho';
  15749. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  15750. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  15751. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  15752. t['Wingdings'] = 'ZapfDingbats';
  15753. });
  15754. var getSerifFonts = getLookupTableFactory(function (t) {
  15755. t['Adobe Jenson'] = true;
  15756. t['Adobe Text'] = true;
  15757. t['Albertus'] = true;
  15758. t['Aldus'] = true;
  15759. t['Alexandria'] = true;
  15760. t['Algerian'] = true;
  15761. t['American Typewriter'] = true;
  15762. t['Antiqua'] = true;
  15763. t['Apex'] = true;
  15764. t['Arno'] = true;
  15765. t['Aster'] = true;
  15766. t['Aurora'] = true;
  15767. t['Baskerville'] = true;
  15768. t['Bell'] = true;
  15769. t['Bembo'] = true;
  15770. t['Bembo Schoolbook'] = true;
  15771. t['Benguiat'] = true;
  15772. t['Berkeley Old Style'] = true;
  15773. t['Bernhard Modern'] = true;
  15774. t['Berthold City'] = true;
  15775. t['Bodoni'] = true;
  15776. t['Bauer Bodoni'] = true;
  15777. t['Book Antiqua'] = true;
  15778. t['Bookman'] = true;
  15779. t['Bordeaux Roman'] = true;
  15780. t['Californian FB'] = true;
  15781. t['Calisto'] = true;
  15782. t['Calvert'] = true;
  15783. t['Capitals'] = true;
  15784. t['Cambria'] = true;
  15785. t['Cartier'] = true;
  15786. t['Caslon'] = true;
  15787. t['Catull'] = true;
  15788. t['Centaur'] = true;
  15789. t['Century Old Style'] = true;
  15790. t['Century Schoolbook'] = true;
  15791. t['Chaparral'] = true;
  15792. t['Charis SIL'] = true;
  15793. t['Cheltenham'] = true;
  15794. t['Cholla Slab'] = true;
  15795. t['Clarendon'] = true;
  15796. t['Clearface'] = true;
  15797. t['Cochin'] = true;
  15798. t['Colonna'] = true;
  15799. t['Computer Modern'] = true;
  15800. t['Concrete Roman'] = true;
  15801. t['Constantia'] = true;
  15802. t['Cooper Black'] = true;
  15803. t['Corona'] = true;
  15804. t['Ecotype'] = true;
  15805. t['Egyptienne'] = true;
  15806. t['Elephant'] = true;
  15807. t['Excelsior'] = true;
  15808. t['Fairfield'] = true;
  15809. t['FF Scala'] = true;
  15810. t['Folkard'] = true;
  15811. t['Footlight'] = true;
  15812. t['FreeSerif'] = true;
  15813. t['Friz Quadrata'] = true;
  15814. t['Garamond'] = true;
  15815. t['Gentium'] = true;
  15816. t['Georgia'] = true;
  15817. t['Gloucester'] = true;
  15818. t['Goudy Old Style'] = true;
  15819. t['Goudy Schoolbook'] = true;
  15820. t['Goudy Pro Font'] = true;
  15821. t['Granjon'] = true;
  15822. t['Guardian Egyptian'] = true;
  15823. t['Heather'] = true;
  15824. t['Hercules'] = true;
  15825. t['High Tower Text'] = true;
  15826. t['Hiroshige'] = true;
  15827. t['Hoefler Text'] = true;
  15828. t['Humana Serif'] = true;
  15829. t['Imprint'] = true;
  15830. t['Ionic No. 5'] = true;
  15831. t['Janson'] = true;
  15832. t['Joanna'] = true;
  15833. t['Korinna'] = true;
  15834. t['Lexicon'] = true;
  15835. t['Liberation Serif'] = true;
  15836. t['Linux Libertine'] = true;
  15837. t['Literaturnaya'] = true;
  15838. t['Lucida'] = true;
  15839. t['Lucida Bright'] = true;
  15840. t['Melior'] = true;
  15841. t['Memphis'] = true;
  15842. t['Miller'] = true;
  15843. t['Minion'] = true;
  15844. t['Modern'] = true;
  15845. t['Mona Lisa'] = true;
  15846. t['Mrs Eaves'] = true;
  15847. t['MS Serif'] = true;
  15848. t['Museo Slab'] = true;
  15849. t['New York'] = true;
  15850. t['Nimbus Roman'] = true;
  15851. t['NPS Rawlinson Roadway'] = true;
  15852. t['Palatino'] = true;
  15853. t['Perpetua'] = true;
  15854. t['Plantin'] = true;
  15855. t['Plantin Schoolbook'] = true;
  15856. t['Playbill'] = true;
  15857. t['Poor Richard'] = true;
  15858. t['Rawlinson Roadway'] = true;
  15859. t['Renault'] = true;
  15860. t['Requiem'] = true;
  15861. t['Rockwell'] = true;
  15862. t['Roman'] = true;
  15863. t['Rotis Serif'] = true;
  15864. t['Sabon'] = true;
  15865. t['Scala'] = true;
  15866. t['Seagull'] = true;
  15867. t['Sistina'] = true;
  15868. t['Souvenir'] = true;
  15869. t['STIX'] = true;
  15870. t['Stone Informal'] = true;
  15871. t['Stone Serif'] = true;
  15872. t['Sylfaen'] = true;
  15873. t['Times'] = true;
  15874. t['Trajan'] = true;
  15875. t['Trinité'] = true;
  15876. t['Trump Mediaeval'] = true;
  15877. t['Utopia'] = true;
  15878. t['Vale Type'] = true;
  15879. t['Bitstream Vera'] = true;
  15880. t['Vera Serif'] = true;
  15881. t['Versailles'] = true;
  15882. t['Wanted'] = true;
  15883. t['Weiss'] = true;
  15884. t['Wide Latin'] = true;
  15885. t['Windsor'] = true;
  15886. t['XITS'] = true;
  15887. });
  15888. var getSymbolsFonts = getLookupTableFactory(function (t) {
  15889. t['Dingbats'] = true;
  15890. t['Symbol'] = true;
  15891. t['ZapfDingbats'] = true;
  15892. });
  15893. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  15894. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  15895. // for all glyphs, but common for some set of the standard fonts.
  15896. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  15897. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  15898. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  15899. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  15900. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  15901. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  15902. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  15903. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  15904. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  15905. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  15906. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  15907. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  15908. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  15909. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  15910. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  15911. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  15912. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  15913. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  15914. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  15915. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  15916. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  15917. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  15918. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  15919. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  15920. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  15921. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  15922. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  15923. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  15924. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  15925. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  15926. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  15927. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  15928. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  15929. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  15930. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  15931. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  15932. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  15933. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  15934. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  15935. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  15936. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  15937. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  15938. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  15939. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  15940. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  15941. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  15942. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  15943. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  15944. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  15945. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  15946. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  15947. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  15948. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  15949. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  15950. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  15951. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  15952. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  15953. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  15954. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  15955. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  15956. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  15957. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  15958. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  15959. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  15960. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  15961. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  15962. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  15963. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  15964. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  15965. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  15966. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  15967. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  15968. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  15969. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  15970. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  15971. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  15972. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  15973. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  15974. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  15975. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  15976. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  15977. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  15978. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  15979. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  15980. t[3416] = 8377;
  15981. });
  15982. // The glyph map for ArialBlack differs slightly from the glyph map used for
  15983. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  15984. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  15985. var getSupplementalGlyphMapForArialBlack =
  15986. getLookupTableFactory(function (t) {
  15987. t[227] = 322; t[264] = 261; t[291] = 346;
  15988. });
  15989. exports.getStdFontMap = getStdFontMap;
  15990. exports.getNonStdFontMap = getNonStdFontMap;
  15991. exports.getSerifFonts = getSerifFonts;
  15992. exports.getSymbolsFonts = getSymbolsFonts;
  15993. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  15994. exports.getSupplementalGlyphMapForArialBlack =
  15995. getSupplementalGlyphMapForArialBlack;
  15996. }));
  15997. (function (root, factory) {
  15998. {
  15999. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  16000. }
  16001. }(this, function (exports, sharedUtil) {
  16002. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  16003. // Some characters, e.g. copyrightserif, are mapped to the private use area
  16004. // and might not be displayed using standard fonts. Mapping/hacking well-known
  16005. // chars to the similar equivalents in the normal characters range.
  16006. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  16007. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  16008. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  16009. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  16010. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  16011. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  16012. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  16013. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  16014. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  16015. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  16016. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  16017. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  16018. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  16019. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  16020. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  16021. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  16022. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  16023. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  16024. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  16025. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  16026. t[63724] = 0x239C; // parenleftex (0xF8EC)
  16027. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  16028. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  16029. t[63735] = 0x239F; // parenrightex (0xF8F7)
  16030. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  16031. });
  16032. function mapSpecialUnicodeValues(code) {
  16033. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  16034. return 0;
  16035. } else if (code >= 0xF600 && code <= 0xF8FF) {
  16036. return (getSpecialPUASymbols()[code] || code);
  16037. }
  16038. return code;
  16039. }
  16040. var UnicodeRanges = [
  16041. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  16042. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  16043. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  16044. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  16045. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  16046. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  16047. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  16048. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  16049. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  16050. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  16051. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  16052. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  16053. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  16054. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  16055. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  16056. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  16057. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  16058. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  16059. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  16060. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  16061. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  16062. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  16063. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  16064. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  16065. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  16066. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  16067. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  16068. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  16069. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  16070. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  16071. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  16072. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  16073. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  16074. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  16075. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  16076. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  16077. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  16078. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  16079. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  16080. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  16081. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  16082. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  16083. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  16084. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  16085. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  16086. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  16087. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  16088. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  16089. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  16090. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  16091. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  16092. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  16093. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  16094. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  16095. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  16096. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  16097. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  16098. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  16099. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  16100. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  16101. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  16102. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  16103. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  16104. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  16105. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  16106. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  16107. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  16108. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  16109. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  16110. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  16111. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  16112. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  16113. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  16114. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  16115. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  16116. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  16117. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  16118. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  16119. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  16120. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  16121. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  16122. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  16123. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  16124. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  16125. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  16126. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  16127. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  16128. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  16129. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  16130. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  16131. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  16132. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  16133. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  16134. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  16135. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  16136. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  16137. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  16138. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  16139. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  16140. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  16141. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  16142. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  16143. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  16144. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  16145. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  16146. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  16147. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  16148. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  16149. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  16150. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  16151. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  16152. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  16153. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  16154. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  16155. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  16156. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  16157. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  16158. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  16159. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  16160. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  16161. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  16162. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  16163. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  16164. ];
  16165. function getUnicodeRangeFor(value) {
  16166. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  16167. var range = UnicodeRanges[i];
  16168. if (value >= range.begin && value < range.end) {
  16169. return i;
  16170. }
  16171. }
  16172. return -1;
  16173. }
  16174. function isRTLRangeFor(value) {
  16175. var range = UnicodeRanges[13];
  16176. if (value >= range.begin && value < range.end) {
  16177. return true;
  16178. }
  16179. range = UnicodeRanges[11];
  16180. if (value >= range.begin && value < range.end) {
  16181. return true;
  16182. }
  16183. return false;
  16184. }
  16185. // The normalization table is obtained by filtering the Unicode characters
  16186. // database with <compat> entries.
  16187. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  16188. t['\u00A8'] = '\u0020\u0308';
  16189. t['\u00AF'] = '\u0020\u0304';
  16190. t['\u00B4'] = '\u0020\u0301';
  16191. t['\u00B5'] = '\u03BC';
  16192. t['\u00B8'] = '\u0020\u0327';
  16193. t['\u0132'] = '\u0049\u004A';
  16194. t['\u0133'] = '\u0069\u006A';
  16195. t['\u013F'] = '\u004C\u00B7';
  16196. t['\u0140'] = '\u006C\u00B7';
  16197. t['\u0149'] = '\u02BC\u006E';
  16198. t['\u017F'] = '\u0073';
  16199. t['\u01C4'] = '\u0044\u017D';
  16200. t['\u01C5'] = '\u0044\u017E';
  16201. t['\u01C6'] = '\u0064\u017E';
  16202. t['\u01C7'] = '\u004C\u004A';
  16203. t['\u01C8'] = '\u004C\u006A';
  16204. t['\u01C9'] = '\u006C\u006A';
  16205. t['\u01CA'] = '\u004E\u004A';
  16206. t['\u01CB'] = '\u004E\u006A';
  16207. t['\u01CC'] = '\u006E\u006A';
  16208. t['\u01F1'] = '\u0044\u005A';
  16209. t['\u01F2'] = '\u0044\u007A';
  16210. t['\u01F3'] = '\u0064\u007A';
  16211. t['\u02D8'] = '\u0020\u0306';
  16212. t['\u02D9'] = '\u0020\u0307';
  16213. t['\u02DA'] = '\u0020\u030A';
  16214. t['\u02DB'] = '\u0020\u0328';
  16215. t['\u02DC'] = '\u0020\u0303';
  16216. t['\u02DD'] = '\u0020\u030B';
  16217. t['\u037A'] = '\u0020\u0345';
  16218. t['\u0384'] = '\u0020\u0301';
  16219. t['\u03D0'] = '\u03B2';
  16220. t['\u03D1'] = '\u03B8';
  16221. t['\u03D2'] = '\u03A5';
  16222. t['\u03D5'] = '\u03C6';
  16223. t['\u03D6'] = '\u03C0';
  16224. t['\u03F0'] = '\u03BA';
  16225. t['\u03F1'] = '\u03C1';
  16226. t['\u03F2'] = '\u03C2';
  16227. t['\u03F4'] = '\u0398';
  16228. t['\u03F5'] = '\u03B5';
  16229. t['\u03F9'] = '\u03A3';
  16230. t['\u0587'] = '\u0565\u0582';
  16231. t['\u0675'] = '\u0627\u0674';
  16232. t['\u0676'] = '\u0648\u0674';
  16233. t['\u0677'] = '\u06C7\u0674';
  16234. t['\u0678'] = '\u064A\u0674';
  16235. t['\u0E33'] = '\u0E4D\u0E32';
  16236. t['\u0EB3'] = '\u0ECD\u0EB2';
  16237. t['\u0EDC'] = '\u0EAB\u0E99';
  16238. t['\u0EDD'] = '\u0EAB\u0EA1';
  16239. t['\u0F77'] = '\u0FB2\u0F81';
  16240. t['\u0F79'] = '\u0FB3\u0F81';
  16241. t['\u1E9A'] = '\u0061\u02BE';
  16242. t['\u1FBD'] = '\u0020\u0313';
  16243. t['\u1FBF'] = '\u0020\u0313';
  16244. t['\u1FC0'] = '\u0020\u0342';
  16245. t['\u1FFE'] = '\u0020\u0314';
  16246. t['\u2002'] = '\u0020';
  16247. t['\u2003'] = '\u0020';
  16248. t['\u2004'] = '\u0020';
  16249. t['\u2005'] = '\u0020';
  16250. t['\u2006'] = '\u0020';
  16251. t['\u2008'] = '\u0020';
  16252. t['\u2009'] = '\u0020';
  16253. t['\u200A'] = '\u0020';
  16254. t['\u2017'] = '\u0020\u0333';
  16255. t['\u2024'] = '\u002E';
  16256. t['\u2025'] = '\u002E\u002E';
  16257. t['\u2026'] = '\u002E\u002E\u002E';
  16258. t['\u2033'] = '\u2032\u2032';
  16259. t['\u2034'] = '\u2032\u2032\u2032';
  16260. t['\u2036'] = '\u2035\u2035';
  16261. t['\u2037'] = '\u2035\u2035\u2035';
  16262. t['\u203C'] = '\u0021\u0021';
  16263. t['\u203E'] = '\u0020\u0305';
  16264. t['\u2047'] = '\u003F\u003F';
  16265. t['\u2048'] = '\u003F\u0021';
  16266. t['\u2049'] = '\u0021\u003F';
  16267. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  16268. t['\u205F'] = '\u0020';
  16269. t['\u20A8'] = '\u0052\u0073';
  16270. t['\u2100'] = '\u0061\u002F\u0063';
  16271. t['\u2101'] = '\u0061\u002F\u0073';
  16272. t['\u2103'] = '\u00B0\u0043';
  16273. t['\u2105'] = '\u0063\u002F\u006F';
  16274. t['\u2106'] = '\u0063\u002F\u0075';
  16275. t['\u2107'] = '\u0190';
  16276. t['\u2109'] = '\u00B0\u0046';
  16277. t['\u2116'] = '\u004E\u006F';
  16278. t['\u2121'] = '\u0054\u0045\u004C';
  16279. t['\u2135'] = '\u05D0';
  16280. t['\u2136'] = '\u05D1';
  16281. t['\u2137'] = '\u05D2';
  16282. t['\u2138'] = '\u05D3';
  16283. t['\u213B'] = '\u0046\u0041\u0058';
  16284. t['\u2160'] = '\u0049';
  16285. t['\u2161'] = '\u0049\u0049';
  16286. t['\u2162'] = '\u0049\u0049\u0049';
  16287. t['\u2163'] = '\u0049\u0056';
  16288. t['\u2164'] = '\u0056';
  16289. t['\u2165'] = '\u0056\u0049';
  16290. t['\u2166'] = '\u0056\u0049\u0049';
  16291. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  16292. t['\u2168'] = '\u0049\u0058';
  16293. t['\u2169'] = '\u0058';
  16294. t['\u216A'] = '\u0058\u0049';
  16295. t['\u216B'] = '\u0058\u0049\u0049';
  16296. t['\u216C'] = '\u004C';
  16297. t['\u216D'] = '\u0043';
  16298. t['\u216E'] = '\u0044';
  16299. t['\u216F'] = '\u004D';
  16300. t['\u2170'] = '\u0069';
  16301. t['\u2171'] = '\u0069\u0069';
  16302. t['\u2172'] = '\u0069\u0069\u0069';
  16303. t['\u2173'] = '\u0069\u0076';
  16304. t['\u2174'] = '\u0076';
  16305. t['\u2175'] = '\u0076\u0069';
  16306. t['\u2176'] = '\u0076\u0069\u0069';
  16307. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  16308. t['\u2178'] = '\u0069\u0078';
  16309. t['\u2179'] = '\u0078';
  16310. t['\u217A'] = '\u0078\u0069';
  16311. t['\u217B'] = '\u0078\u0069\u0069';
  16312. t['\u217C'] = '\u006C';
  16313. t['\u217D'] = '\u0063';
  16314. t['\u217E'] = '\u0064';
  16315. t['\u217F'] = '\u006D';
  16316. t['\u222C'] = '\u222B\u222B';
  16317. t['\u222D'] = '\u222B\u222B\u222B';
  16318. t['\u222F'] = '\u222E\u222E';
  16319. t['\u2230'] = '\u222E\u222E\u222E';
  16320. t['\u2474'] = '\u0028\u0031\u0029';
  16321. t['\u2475'] = '\u0028\u0032\u0029';
  16322. t['\u2476'] = '\u0028\u0033\u0029';
  16323. t['\u2477'] = '\u0028\u0034\u0029';
  16324. t['\u2478'] = '\u0028\u0035\u0029';
  16325. t['\u2479'] = '\u0028\u0036\u0029';
  16326. t['\u247A'] = '\u0028\u0037\u0029';
  16327. t['\u247B'] = '\u0028\u0038\u0029';
  16328. t['\u247C'] = '\u0028\u0039\u0029';
  16329. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  16330. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  16331. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  16332. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  16333. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  16334. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  16335. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  16336. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  16337. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  16338. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  16339. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  16340. t['\u2488'] = '\u0031\u002E';
  16341. t['\u2489'] = '\u0032\u002E';
  16342. t['\u248A'] = '\u0033\u002E';
  16343. t['\u248B'] = '\u0034\u002E';
  16344. t['\u248C'] = '\u0035\u002E';
  16345. t['\u248D'] = '\u0036\u002E';
  16346. t['\u248E'] = '\u0037\u002E';
  16347. t['\u248F'] = '\u0038\u002E';
  16348. t['\u2490'] = '\u0039\u002E';
  16349. t['\u2491'] = '\u0031\u0030\u002E';
  16350. t['\u2492'] = '\u0031\u0031\u002E';
  16351. t['\u2493'] = '\u0031\u0032\u002E';
  16352. t['\u2494'] = '\u0031\u0033\u002E';
  16353. t['\u2495'] = '\u0031\u0034\u002E';
  16354. t['\u2496'] = '\u0031\u0035\u002E';
  16355. t['\u2497'] = '\u0031\u0036\u002E';
  16356. t['\u2498'] = '\u0031\u0037\u002E';
  16357. t['\u2499'] = '\u0031\u0038\u002E';
  16358. t['\u249A'] = '\u0031\u0039\u002E';
  16359. t['\u249B'] = '\u0032\u0030\u002E';
  16360. t['\u249C'] = '\u0028\u0061\u0029';
  16361. t['\u249D'] = '\u0028\u0062\u0029';
  16362. t['\u249E'] = '\u0028\u0063\u0029';
  16363. t['\u249F'] = '\u0028\u0064\u0029';
  16364. t['\u24A0'] = '\u0028\u0065\u0029';
  16365. t['\u24A1'] = '\u0028\u0066\u0029';
  16366. t['\u24A2'] = '\u0028\u0067\u0029';
  16367. t['\u24A3'] = '\u0028\u0068\u0029';
  16368. t['\u24A4'] = '\u0028\u0069\u0029';
  16369. t['\u24A5'] = '\u0028\u006A\u0029';
  16370. t['\u24A6'] = '\u0028\u006B\u0029';
  16371. t['\u24A7'] = '\u0028\u006C\u0029';
  16372. t['\u24A8'] = '\u0028\u006D\u0029';
  16373. t['\u24A9'] = '\u0028\u006E\u0029';
  16374. t['\u24AA'] = '\u0028\u006F\u0029';
  16375. t['\u24AB'] = '\u0028\u0070\u0029';
  16376. t['\u24AC'] = '\u0028\u0071\u0029';
  16377. t['\u24AD'] = '\u0028\u0072\u0029';
  16378. t['\u24AE'] = '\u0028\u0073\u0029';
  16379. t['\u24AF'] = '\u0028\u0074\u0029';
  16380. t['\u24B0'] = '\u0028\u0075\u0029';
  16381. t['\u24B1'] = '\u0028\u0076\u0029';
  16382. t['\u24B2'] = '\u0028\u0077\u0029';
  16383. t['\u24B3'] = '\u0028\u0078\u0029';
  16384. t['\u24B4'] = '\u0028\u0079\u0029';
  16385. t['\u24B5'] = '\u0028\u007A\u0029';
  16386. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  16387. t['\u2A74'] = '\u003A\u003A\u003D';
  16388. t['\u2A75'] = '\u003D\u003D';
  16389. t['\u2A76'] = '\u003D\u003D\u003D';
  16390. t['\u2E9F'] = '\u6BCD';
  16391. t['\u2EF3'] = '\u9F9F';
  16392. t['\u2F00'] = '\u4E00';
  16393. t['\u2F01'] = '\u4E28';
  16394. t['\u2F02'] = '\u4E36';
  16395. t['\u2F03'] = '\u4E3F';
  16396. t['\u2F04'] = '\u4E59';
  16397. t['\u2F05'] = '\u4E85';
  16398. t['\u2F06'] = '\u4E8C';
  16399. t['\u2F07'] = '\u4EA0';
  16400. t['\u2F08'] = '\u4EBA';
  16401. t['\u2F09'] = '\u513F';
  16402. t['\u2F0A'] = '\u5165';
  16403. t['\u2F0B'] = '\u516B';
  16404. t['\u2F0C'] = '\u5182';
  16405. t['\u2F0D'] = '\u5196';
  16406. t['\u2F0E'] = '\u51AB';
  16407. t['\u2F0F'] = '\u51E0';
  16408. t['\u2F10'] = '\u51F5';
  16409. t['\u2F11'] = '\u5200';
  16410. t['\u2F12'] = '\u529B';
  16411. t['\u2F13'] = '\u52F9';
  16412. t['\u2F14'] = '\u5315';
  16413. t['\u2F15'] = '\u531A';
  16414. t['\u2F16'] = '\u5338';
  16415. t['\u2F17'] = '\u5341';
  16416. t['\u2F18'] = '\u535C';
  16417. t['\u2F19'] = '\u5369';
  16418. t['\u2F1A'] = '\u5382';
  16419. t['\u2F1B'] = '\u53B6';
  16420. t['\u2F1C'] = '\u53C8';
  16421. t['\u2F1D'] = '\u53E3';
  16422. t['\u2F1E'] = '\u56D7';
  16423. t['\u2F1F'] = '\u571F';
  16424. t['\u2F20'] = '\u58EB';
  16425. t['\u2F21'] = '\u5902';
  16426. t['\u2F22'] = '\u590A';
  16427. t['\u2F23'] = '\u5915';
  16428. t['\u2F24'] = '\u5927';
  16429. t['\u2F25'] = '\u5973';
  16430. t['\u2F26'] = '\u5B50';
  16431. t['\u2F27'] = '\u5B80';
  16432. t['\u2F28'] = '\u5BF8';
  16433. t['\u2F29'] = '\u5C0F';
  16434. t['\u2F2A'] = '\u5C22';
  16435. t['\u2F2B'] = '\u5C38';
  16436. t['\u2F2C'] = '\u5C6E';
  16437. t['\u2F2D'] = '\u5C71';
  16438. t['\u2F2E'] = '\u5DDB';
  16439. t['\u2F2F'] = '\u5DE5';
  16440. t['\u2F30'] = '\u5DF1';
  16441. t['\u2F31'] = '\u5DFE';
  16442. t['\u2F32'] = '\u5E72';
  16443. t['\u2F33'] = '\u5E7A';
  16444. t['\u2F34'] = '\u5E7F';
  16445. t['\u2F35'] = '\u5EF4';
  16446. t['\u2F36'] = '\u5EFE';
  16447. t['\u2F37'] = '\u5F0B';
  16448. t['\u2F38'] = '\u5F13';
  16449. t['\u2F39'] = '\u5F50';
  16450. t['\u2F3A'] = '\u5F61';
  16451. t['\u2F3B'] = '\u5F73';
  16452. t['\u2F3C'] = '\u5FC3';
  16453. t['\u2F3D'] = '\u6208';
  16454. t['\u2F3E'] = '\u6236';
  16455. t['\u2F3F'] = '\u624B';
  16456. t['\u2F40'] = '\u652F';
  16457. t['\u2F41'] = '\u6534';
  16458. t['\u2F42'] = '\u6587';
  16459. t['\u2F43'] = '\u6597';
  16460. t['\u2F44'] = '\u65A4';
  16461. t['\u2F45'] = '\u65B9';
  16462. t['\u2F46'] = '\u65E0';
  16463. t['\u2F47'] = '\u65E5';
  16464. t['\u2F48'] = '\u66F0';
  16465. t['\u2F49'] = '\u6708';
  16466. t['\u2F4A'] = '\u6728';
  16467. t['\u2F4B'] = '\u6B20';
  16468. t['\u2F4C'] = '\u6B62';
  16469. t['\u2F4D'] = '\u6B79';
  16470. t['\u2F4E'] = '\u6BB3';
  16471. t['\u2F4F'] = '\u6BCB';
  16472. t['\u2F50'] = '\u6BD4';
  16473. t['\u2F51'] = '\u6BDB';
  16474. t['\u2F52'] = '\u6C0F';
  16475. t['\u2F53'] = '\u6C14';
  16476. t['\u2F54'] = '\u6C34';
  16477. t['\u2F55'] = '\u706B';
  16478. t['\u2F56'] = '\u722A';
  16479. t['\u2F57'] = '\u7236';
  16480. t['\u2F58'] = '\u723B';
  16481. t['\u2F59'] = '\u723F';
  16482. t['\u2F5A'] = '\u7247';
  16483. t['\u2F5B'] = '\u7259';
  16484. t['\u2F5C'] = '\u725B';
  16485. t['\u2F5D'] = '\u72AC';
  16486. t['\u2F5E'] = '\u7384';
  16487. t['\u2F5F'] = '\u7389';
  16488. t['\u2F60'] = '\u74DC';
  16489. t['\u2F61'] = '\u74E6';
  16490. t['\u2F62'] = '\u7518';
  16491. t['\u2F63'] = '\u751F';
  16492. t['\u2F64'] = '\u7528';
  16493. t['\u2F65'] = '\u7530';
  16494. t['\u2F66'] = '\u758B';
  16495. t['\u2F67'] = '\u7592';
  16496. t['\u2F68'] = '\u7676';
  16497. t['\u2F69'] = '\u767D';
  16498. t['\u2F6A'] = '\u76AE';
  16499. t['\u2F6B'] = '\u76BF';
  16500. t['\u2F6C'] = '\u76EE';
  16501. t['\u2F6D'] = '\u77DB';
  16502. t['\u2F6E'] = '\u77E2';
  16503. t['\u2F6F'] = '\u77F3';
  16504. t['\u2F70'] = '\u793A';
  16505. t['\u2F71'] = '\u79B8';
  16506. t['\u2F72'] = '\u79BE';
  16507. t['\u2F73'] = '\u7A74';
  16508. t['\u2F74'] = '\u7ACB';
  16509. t['\u2F75'] = '\u7AF9';
  16510. t['\u2F76'] = '\u7C73';
  16511. t['\u2F77'] = '\u7CF8';
  16512. t['\u2F78'] = '\u7F36';
  16513. t['\u2F79'] = '\u7F51';
  16514. t['\u2F7A'] = '\u7F8A';
  16515. t['\u2F7B'] = '\u7FBD';
  16516. t['\u2F7C'] = '\u8001';
  16517. t['\u2F7D'] = '\u800C';
  16518. t['\u2F7E'] = '\u8012';
  16519. t['\u2F7F'] = '\u8033';
  16520. t['\u2F80'] = '\u807F';
  16521. t['\u2F81'] = '\u8089';
  16522. t['\u2F82'] = '\u81E3';
  16523. t['\u2F83'] = '\u81EA';
  16524. t['\u2F84'] = '\u81F3';
  16525. t['\u2F85'] = '\u81FC';
  16526. t['\u2F86'] = '\u820C';
  16527. t['\u2F87'] = '\u821B';
  16528. t['\u2F88'] = '\u821F';
  16529. t['\u2F89'] = '\u826E';
  16530. t['\u2F8A'] = '\u8272';
  16531. t['\u2F8B'] = '\u8278';
  16532. t['\u2F8C'] = '\u864D';
  16533. t['\u2F8D'] = '\u866B';
  16534. t['\u2F8E'] = '\u8840';
  16535. t['\u2F8F'] = '\u884C';
  16536. t['\u2F90'] = '\u8863';
  16537. t['\u2F91'] = '\u897E';
  16538. t['\u2F92'] = '\u898B';
  16539. t['\u2F93'] = '\u89D2';
  16540. t['\u2F94'] = '\u8A00';
  16541. t['\u2F95'] = '\u8C37';
  16542. t['\u2F96'] = '\u8C46';
  16543. t['\u2F97'] = '\u8C55';
  16544. t['\u2F98'] = '\u8C78';
  16545. t['\u2F99'] = '\u8C9D';
  16546. t['\u2F9A'] = '\u8D64';
  16547. t['\u2F9B'] = '\u8D70';
  16548. t['\u2F9C'] = '\u8DB3';
  16549. t['\u2F9D'] = '\u8EAB';
  16550. t['\u2F9E'] = '\u8ECA';
  16551. t['\u2F9F'] = '\u8F9B';
  16552. t['\u2FA0'] = '\u8FB0';
  16553. t['\u2FA1'] = '\u8FB5';
  16554. t['\u2FA2'] = '\u9091';
  16555. t['\u2FA3'] = '\u9149';
  16556. t['\u2FA4'] = '\u91C6';
  16557. t['\u2FA5'] = '\u91CC';
  16558. t['\u2FA6'] = '\u91D1';
  16559. t['\u2FA7'] = '\u9577';
  16560. t['\u2FA8'] = '\u9580';
  16561. t['\u2FA9'] = '\u961C';
  16562. t['\u2FAA'] = '\u96B6';
  16563. t['\u2FAB'] = '\u96B9';
  16564. t['\u2FAC'] = '\u96E8';
  16565. t['\u2FAD'] = '\u9751';
  16566. t['\u2FAE'] = '\u975E';
  16567. t['\u2FAF'] = '\u9762';
  16568. t['\u2FB0'] = '\u9769';
  16569. t['\u2FB1'] = '\u97CB';
  16570. t['\u2FB2'] = '\u97ED';
  16571. t['\u2FB3'] = '\u97F3';
  16572. t['\u2FB4'] = '\u9801';
  16573. t['\u2FB5'] = '\u98A8';
  16574. t['\u2FB6'] = '\u98DB';
  16575. t['\u2FB7'] = '\u98DF';
  16576. t['\u2FB8'] = '\u9996';
  16577. t['\u2FB9'] = '\u9999';
  16578. t['\u2FBA'] = '\u99AC';
  16579. t['\u2FBB'] = '\u9AA8';
  16580. t['\u2FBC'] = '\u9AD8';
  16581. t['\u2FBD'] = '\u9ADF';
  16582. t['\u2FBE'] = '\u9B25';
  16583. t['\u2FBF'] = '\u9B2F';
  16584. t['\u2FC0'] = '\u9B32';
  16585. t['\u2FC1'] = '\u9B3C';
  16586. t['\u2FC2'] = '\u9B5A';
  16587. t['\u2FC3'] = '\u9CE5';
  16588. t['\u2FC4'] = '\u9E75';
  16589. t['\u2FC5'] = '\u9E7F';
  16590. t['\u2FC6'] = '\u9EA5';
  16591. t['\u2FC7'] = '\u9EBB';
  16592. t['\u2FC8'] = '\u9EC3';
  16593. t['\u2FC9'] = '\u9ECD';
  16594. t['\u2FCA'] = '\u9ED1';
  16595. t['\u2FCB'] = '\u9EF9';
  16596. t['\u2FCC'] = '\u9EFD';
  16597. t['\u2FCD'] = '\u9F0E';
  16598. t['\u2FCE'] = '\u9F13';
  16599. t['\u2FCF'] = '\u9F20';
  16600. t['\u2FD0'] = '\u9F3B';
  16601. t['\u2FD1'] = '\u9F4A';
  16602. t['\u2FD2'] = '\u9F52';
  16603. t['\u2FD3'] = '\u9F8D';
  16604. t['\u2FD4'] = '\u9F9C';
  16605. t['\u2FD5'] = '\u9FA0';
  16606. t['\u3036'] = '\u3012';
  16607. t['\u3038'] = '\u5341';
  16608. t['\u3039'] = '\u5344';
  16609. t['\u303A'] = '\u5345';
  16610. t['\u309B'] = '\u0020\u3099';
  16611. t['\u309C'] = '\u0020\u309A';
  16612. t['\u3131'] = '\u1100';
  16613. t['\u3132'] = '\u1101';
  16614. t['\u3133'] = '\u11AA';
  16615. t['\u3134'] = '\u1102';
  16616. t['\u3135'] = '\u11AC';
  16617. t['\u3136'] = '\u11AD';
  16618. t['\u3137'] = '\u1103';
  16619. t['\u3138'] = '\u1104';
  16620. t['\u3139'] = '\u1105';
  16621. t['\u313A'] = '\u11B0';
  16622. t['\u313B'] = '\u11B1';
  16623. t['\u313C'] = '\u11B2';
  16624. t['\u313D'] = '\u11B3';
  16625. t['\u313E'] = '\u11B4';
  16626. t['\u313F'] = '\u11B5';
  16627. t['\u3140'] = '\u111A';
  16628. t['\u3141'] = '\u1106';
  16629. t['\u3142'] = '\u1107';
  16630. t['\u3143'] = '\u1108';
  16631. t['\u3144'] = '\u1121';
  16632. t['\u3145'] = '\u1109';
  16633. t['\u3146'] = '\u110A';
  16634. t['\u3147'] = '\u110B';
  16635. t['\u3148'] = '\u110C';
  16636. t['\u3149'] = '\u110D';
  16637. t['\u314A'] = '\u110E';
  16638. t['\u314B'] = '\u110F';
  16639. t['\u314C'] = '\u1110';
  16640. t['\u314D'] = '\u1111';
  16641. t['\u314E'] = '\u1112';
  16642. t['\u314F'] = '\u1161';
  16643. t['\u3150'] = '\u1162';
  16644. t['\u3151'] = '\u1163';
  16645. t['\u3152'] = '\u1164';
  16646. t['\u3153'] = '\u1165';
  16647. t['\u3154'] = '\u1166';
  16648. t['\u3155'] = '\u1167';
  16649. t['\u3156'] = '\u1168';
  16650. t['\u3157'] = '\u1169';
  16651. t['\u3158'] = '\u116A';
  16652. t['\u3159'] = '\u116B';
  16653. t['\u315A'] = '\u116C';
  16654. t['\u315B'] = '\u116D';
  16655. t['\u315C'] = '\u116E';
  16656. t['\u315D'] = '\u116F';
  16657. t['\u315E'] = '\u1170';
  16658. t['\u315F'] = '\u1171';
  16659. t['\u3160'] = '\u1172';
  16660. t['\u3161'] = '\u1173';
  16661. t['\u3162'] = '\u1174';
  16662. t['\u3163'] = '\u1175';
  16663. t['\u3164'] = '\u1160';
  16664. t['\u3165'] = '\u1114';
  16665. t['\u3166'] = '\u1115';
  16666. t['\u3167'] = '\u11C7';
  16667. t['\u3168'] = '\u11C8';
  16668. t['\u3169'] = '\u11CC';
  16669. t['\u316A'] = '\u11CE';
  16670. t['\u316B'] = '\u11D3';
  16671. t['\u316C'] = '\u11D7';
  16672. t['\u316D'] = '\u11D9';
  16673. t['\u316E'] = '\u111C';
  16674. t['\u316F'] = '\u11DD';
  16675. t['\u3170'] = '\u11DF';
  16676. t['\u3171'] = '\u111D';
  16677. t['\u3172'] = '\u111E';
  16678. t['\u3173'] = '\u1120';
  16679. t['\u3174'] = '\u1122';
  16680. t['\u3175'] = '\u1123';
  16681. t['\u3176'] = '\u1127';
  16682. t['\u3177'] = '\u1129';
  16683. t['\u3178'] = '\u112B';
  16684. t['\u3179'] = '\u112C';
  16685. t['\u317A'] = '\u112D';
  16686. t['\u317B'] = '\u112E';
  16687. t['\u317C'] = '\u112F';
  16688. t['\u317D'] = '\u1132';
  16689. t['\u317E'] = '\u1136';
  16690. t['\u317F'] = '\u1140';
  16691. t['\u3180'] = '\u1147';
  16692. t['\u3181'] = '\u114C';
  16693. t['\u3182'] = '\u11F1';
  16694. t['\u3183'] = '\u11F2';
  16695. t['\u3184'] = '\u1157';
  16696. t['\u3185'] = '\u1158';
  16697. t['\u3186'] = '\u1159';
  16698. t['\u3187'] = '\u1184';
  16699. t['\u3188'] = '\u1185';
  16700. t['\u3189'] = '\u1188';
  16701. t['\u318A'] = '\u1191';
  16702. t['\u318B'] = '\u1192';
  16703. t['\u318C'] = '\u1194';
  16704. t['\u318D'] = '\u119E';
  16705. t['\u318E'] = '\u11A1';
  16706. t['\u3200'] = '\u0028\u1100\u0029';
  16707. t['\u3201'] = '\u0028\u1102\u0029';
  16708. t['\u3202'] = '\u0028\u1103\u0029';
  16709. t['\u3203'] = '\u0028\u1105\u0029';
  16710. t['\u3204'] = '\u0028\u1106\u0029';
  16711. t['\u3205'] = '\u0028\u1107\u0029';
  16712. t['\u3206'] = '\u0028\u1109\u0029';
  16713. t['\u3207'] = '\u0028\u110B\u0029';
  16714. t['\u3208'] = '\u0028\u110C\u0029';
  16715. t['\u3209'] = '\u0028\u110E\u0029';
  16716. t['\u320A'] = '\u0028\u110F\u0029';
  16717. t['\u320B'] = '\u0028\u1110\u0029';
  16718. t['\u320C'] = '\u0028\u1111\u0029';
  16719. t['\u320D'] = '\u0028\u1112\u0029';
  16720. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  16721. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  16722. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  16723. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  16724. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  16725. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  16726. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  16727. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  16728. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  16729. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  16730. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  16731. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  16732. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  16733. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  16734. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  16735. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  16736. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  16737. t['\u3220'] = '\u0028\u4E00\u0029';
  16738. t['\u3221'] = '\u0028\u4E8C\u0029';
  16739. t['\u3222'] = '\u0028\u4E09\u0029';
  16740. t['\u3223'] = '\u0028\u56DB\u0029';
  16741. t['\u3224'] = '\u0028\u4E94\u0029';
  16742. t['\u3225'] = '\u0028\u516D\u0029';
  16743. t['\u3226'] = '\u0028\u4E03\u0029';
  16744. t['\u3227'] = '\u0028\u516B\u0029';
  16745. t['\u3228'] = '\u0028\u4E5D\u0029';
  16746. t['\u3229'] = '\u0028\u5341\u0029';
  16747. t['\u322A'] = '\u0028\u6708\u0029';
  16748. t['\u322B'] = '\u0028\u706B\u0029';
  16749. t['\u322C'] = '\u0028\u6C34\u0029';
  16750. t['\u322D'] = '\u0028\u6728\u0029';
  16751. t['\u322E'] = '\u0028\u91D1\u0029';
  16752. t['\u322F'] = '\u0028\u571F\u0029';
  16753. t['\u3230'] = '\u0028\u65E5\u0029';
  16754. t['\u3231'] = '\u0028\u682A\u0029';
  16755. t['\u3232'] = '\u0028\u6709\u0029';
  16756. t['\u3233'] = '\u0028\u793E\u0029';
  16757. t['\u3234'] = '\u0028\u540D\u0029';
  16758. t['\u3235'] = '\u0028\u7279\u0029';
  16759. t['\u3236'] = '\u0028\u8CA1\u0029';
  16760. t['\u3237'] = '\u0028\u795D\u0029';
  16761. t['\u3238'] = '\u0028\u52B4\u0029';
  16762. t['\u3239'] = '\u0028\u4EE3\u0029';
  16763. t['\u323A'] = '\u0028\u547C\u0029';
  16764. t['\u323B'] = '\u0028\u5B66\u0029';
  16765. t['\u323C'] = '\u0028\u76E3\u0029';
  16766. t['\u323D'] = '\u0028\u4F01\u0029';
  16767. t['\u323E'] = '\u0028\u8CC7\u0029';
  16768. t['\u323F'] = '\u0028\u5354\u0029';
  16769. t['\u3240'] = '\u0028\u796D\u0029';
  16770. t['\u3241'] = '\u0028\u4F11\u0029';
  16771. t['\u3242'] = '\u0028\u81EA\u0029';
  16772. t['\u3243'] = '\u0028\u81F3\u0029';
  16773. t['\u32C0'] = '\u0031\u6708';
  16774. t['\u32C1'] = '\u0032\u6708';
  16775. t['\u32C2'] = '\u0033\u6708';
  16776. t['\u32C3'] = '\u0034\u6708';
  16777. t['\u32C4'] = '\u0035\u6708';
  16778. t['\u32C5'] = '\u0036\u6708';
  16779. t['\u32C6'] = '\u0037\u6708';
  16780. t['\u32C7'] = '\u0038\u6708';
  16781. t['\u32C8'] = '\u0039\u6708';
  16782. t['\u32C9'] = '\u0031\u0030\u6708';
  16783. t['\u32CA'] = '\u0031\u0031\u6708';
  16784. t['\u32CB'] = '\u0031\u0032\u6708';
  16785. t['\u3358'] = '\u0030\u70B9';
  16786. t['\u3359'] = '\u0031\u70B9';
  16787. t['\u335A'] = '\u0032\u70B9';
  16788. t['\u335B'] = '\u0033\u70B9';
  16789. t['\u335C'] = '\u0034\u70B9';
  16790. t['\u335D'] = '\u0035\u70B9';
  16791. t['\u335E'] = '\u0036\u70B9';
  16792. t['\u335F'] = '\u0037\u70B9';
  16793. t['\u3360'] = '\u0038\u70B9';
  16794. t['\u3361'] = '\u0039\u70B9';
  16795. t['\u3362'] = '\u0031\u0030\u70B9';
  16796. t['\u3363'] = '\u0031\u0031\u70B9';
  16797. t['\u3364'] = '\u0031\u0032\u70B9';
  16798. t['\u3365'] = '\u0031\u0033\u70B9';
  16799. t['\u3366'] = '\u0031\u0034\u70B9';
  16800. t['\u3367'] = '\u0031\u0035\u70B9';
  16801. t['\u3368'] = '\u0031\u0036\u70B9';
  16802. t['\u3369'] = '\u0031\u0037\u70B9';
  16803. t['\u336A'] = '\u0031\u0038\u70B9';
  16804. t['\u336B'] = '\u0031\u0039\u70B9';
  16805. t['\u336C'] = '\u0032\u0030\u70B9';
  16806. t['\u336D'] = '\u0032\u0031\u70B9';
  16807. t['\u336E'] = '\u0032\u0032\u70B9';
  16808. t['\u336F'] = '\u0032\u0033\u70B9';
  16809. t['\u3370'] = '\u0032\u0034\u70B9';
  16810. t['\u33E0'] = '\u0031\u65E5';
  16811. t['\u33E1'] = '\u0032\u65E5';
  16812. t['\u33E2'] = '\u0033\u65E5';
  16813. t['\u33E3'] = '\u0034\u65E5';
  16814. t['\u33E4'] = '\u0035\u65E5';
  16815. t['\u33E5'] = '\u0036\u65E5';
  16816. t['\u33E6'] = '\u0037\u65E5';
  16817. t['\u33E7'] = '\u0038\u65E5';
  16818. t['\u33E8'] = '\u0039\u65E5';
  16819. t['\u33E9'] = '\u0031\u0030\u65E5';
  16820. t['\u33EA'] = '\u0031\u0031\u65E5';
  16821. t['\u33EB'] = '\u0031\u0032\u65E5';
  16822. t['\u33EC'] = '\u0031\u0033\u65E5';
  16823. t['\u33ED'] = '\u0031\u0034\u65E5';
  16824. t['\u33EE'] = '\u0031\u0035\u65E5';
  16825. t['\u33EF'] = '\u0031\u0036\u65E5';
  16826. t['\u33F0'] = '\u0031\u0037\u65E5';
  16827. t['\u33F1'] = '\u0031\u0038\u65E5';
  16828. t['\u33F2'] = '\u0031\u0039\u65E5';
  16829. t['\u33F3'] = '\u0032\u0030\u65E5';
  16830. t['\u33F4'] = '\u0032\u0031\u65E5';
  16831. t['\u33F5'] = '\u0032\u0032\u65E5';
  16832. t['\u33F6'] = '\u0032\u0033\u65E5';
  16833. t['\u33F7'] = '\u0032\u0034\u65E5';
  16834. t['\u33F8'] = '\u0032\u0035\u65E5';
  16835. t['\u33F9'] = '\u0032\u0036\u65E5';
  16836. t['\u33FA'] = '\u0032\u0037\u65E5';
  16837. t['\u33FB'] = '\u0032\u0038\u65E5';
  16838. t['\u33FC'] = '\u0032\u0039\u65E5';
  16839. t['\u33FD'] = '\u0033\u0030\u65E5';
  16840. t['\u33FE'] = '\u0033\u0031\u65E5';
  16841. t['\uFB00'] = '\u0066\u0066';
  16842. t['\uFB01'] = '\u0066\u0069';
  16843. t['\uFB02'] = '\u0066\u006C';
  16844. t['\uFB03'] = '\u0066\u0066\u0069';
  16845. t['\uFB04'] = '\u0066\u0066\u006C';
  16846. t['\uFB05'] = '\u017F\u0074';
  16847. t['\uFB06'] = '\u0073\u0074';
  16848. t['\uFB13'] = '\u0574\u0576';
  16849. t['\uFB14'] = '\u0574\u0565';
  16850. t['\uFB15'] = '\u0574\u056B';
  16851. t['\uFB16'] = '\u057E\u0576';
  16852. t['\uFB17'] = '\u0574\u056D';
  16853. t['\uFB4F'] = '\u05D0\u05DC';
  16854. t['\uFB50'] = '\u0671';
  16855. t['\uFB51'] = '\u0671';
  16856. t['\uFB52'] = '\u067B';
  16857. t['\uFB53'] = '\u067B';
  16858. t['\uFB54'] = '\u067B';
  16859. t['\uFB55'] = '\u067B';
  16860. t['\uFB56'] = '\u067E';
  16861. t['\uFB57'] = '\u067E';
  16862. t['\uFB58'] = '\u067E';
  16863. t['\uFB59'] = '\u067E';
  16864. t['\uFB5A'] = '\u0680';
  16865. t['\uFB5B'] = '\u0680';
  16866. t['\uFB5C'] = '\u0680';
  16867. t['\uFB5D'] = '\u0680';
  16868. t['\uFB5E'] = '\u067A';
  16869. t['\uFB5F'] = '\u067A';
  16870. t['\uFB60'] = '\u067A';
  16871. t['\uFB61'] = '\u067A';
  16872. t['\uFB62'] = '\u067F';
  16873. t['\uFB63'] = '\u067F';
  16874. t['\uFB64'] = '\u067F';
  16875. t['\uFB65'] = '\u067F';
  16876. t['\uFB66'] = '\u0679';
  16877. t['\uFB67'] = '\u0679';
  16878. t['\uFB68'] = '\u0679';
  16879. t['\uFB69'] = '\u0679';
  16880. t['\uFB6A'] = '\u06A4';
  16881. t['\uFB6B'] = '\u06A4';
  16882. t['\uFB6C'] = '\u06A4';
  16883. t['\uFB6D'] = '\u06A4';
  16884. t['\uFB6E'] = '\u06A6';
  16885. t['\uFB6F'] = '\u06A6';
  16886. t['\uFB70'] = '\u06A6';
  16887. t['\uFB71'] = '\u06A6';
  16888. t['\uFB72'] = '\u0684';
  16889. t['\uFB73'] = '\u0684';
  16890. t['\uFB74'] = '\u0684';
  16891. t['\uFB75'] = '\u0684';
  16892. t['\uFB76'] = '\u0683';
  16893. t['\uFB77'] = '\u0683';
  16894. t['\uFB78'] = '\u0683';
  16895. t['\uFB79'] = '\u0683';
  16896. t['\uFB7A'] = '\u0686';
  16897. t['\uFB7B'] = '\u0686';
  16898. t['\uFB7C'] = '\u0686';
  16899. t['\uFB7D'] = '\u0686';
  16900. t['\uFB7E'] = '\u0687';
  16901. t['\uFB7F'] = '\u0687';
  16902. t['\uFB80'] = '\u0687';
  16903. t['\uFB81'] = '\u0687';
  16904. t['\uFB82'] = '\u068D';
  16905. t['\uFB83'] = '\u068D';
  16906. t['\uFB84'] = '\u068C';
  16907. t['\uFB85'] = '\u068C';
  16908. t['\uFB86'] = '\u068E';
  16909. t['\uFB87'] = '\u068E';
  16910. t['\uFB88'] = '\u0688';
  16911. t['\uFB89'] = '\u0688';
  16912. t['\uFB8A'] = '\u0698';
  16913. t['\uFB8B'] = '\u0698';
  16914. t['\uFB8C'] = '\u0691';
  16915. t['\uFB8D'] = '\u0691';
  16916. t['\uFB8E'] = '\u06A9';
  16917. t['\uFB8F'] = '\u06A9';
  16918. t['\uFB90'] = '\u06A9';
  16919. t['\uFB91'] = '\u06A9';
  16920. t['\uFB92'] = '\u06AF';
  16921. t['\uFB93'] = '\u06AF';
  16922. t['\uFB94'] = '\u06AF';
  16923. t['\uFB95'] = '\u06AF';
  16924. t['\uFB96'] = '\u06B3';
  16925. t['\uFB97'] = '\u06B3';
  16926. t['\uFB98'] = '\u06B3';
  16927. t['\uFB99'] = '\u06B3';
  16928. t['\uFB9A'] = '\u06B1';
  16929. t['\uFB9B'] = '\u06B1';
  16930. t['\uFB9C'] = '\u06B1';
  16931. t['\uFB9D'] = '\u06B1';
  16932. t['\uFB9E'] = '\u06BA';
  16933. t['\uFB9F'] = '\u06BA';
  16934. t['\uFBA0'] = '\u06BB';
  16935. t['\uFBA1'] = '\u06BB';
  16936. t['\uFBA2'] = '\u06BB';
  16937. t['\uFBA3'] = '\u06BB';
  16938. t['\uFBA4'] = '\u06C0';
  16939. t['\uFBA5'] = '\u06C0';
  16940. t['\uFBA6'] = '\u06C1';
  16941. t['\uFBA7'] = '\u06C1';
  16942. t['\uFBA8'] = '\u06C1';
  16943. t['\uFBA9'] = '\u06C1';
  16944. t['\uFBAA'] = '\u06BE';
  16945. t['\uFBAB'] = '\u06BE';
  16946. t['\uFBAC'] = '\u06BE';
  16947. t['\uFBAD'] = '\u06BE';
  16948. t['\uFBAE'] = '\u06D2';
  16949. t['\uFBAF'] = '\u06D2';
  16950. t['\uFBB0'] = '\u06D3';
  16951. t['\uFBB1'] = '\u06D3';
  16952. t['\uFBD3'] = '\u06AD';
  16953. t['\uFBD4'] = '\u06AD';
  16954. t['\uFBD5'] = '\u06AD';
  16955. t['\uFBD6'] = '\u06AD';
  16956. t['\uFBD7'] = '\u06C7';
  16957. t['\uFBD8'] = '\u06C7';
  16958. t['\uFBD9'] = '\u06C6';
  16959. t['\uFBDA'] = '\u06C6';
  16960. t['\uFBDB'] = '\u06C8';
  16961. t['\uFBDC'] = '\u06C8';
  16962. t['\uFBDD'] = '\u0677';
  16963. t['\uFBDE'] = '\u06CB';
  16964. t['\uFBDF'] = '\u06CB';
  16965. t['\uFBE0'] = '\u06C5';
  16966. t['\uFBE1'] = '\u06C5';
  16967. t['\uFBE2'] = '\u06C9';
  16968. t['\uFBE3'] = '\u06C9';
  16969. t['\uFBE4'] = '\u06D0';
  16970. t['\uFBE5'] = '\u06D0';
  16971. t['\uFBE6'] = '\u06D0';
  16972. t['\uFBE7'] = '\u06D0';
  16973. t['\uFBE8'] = '\u0649';
  16974. t['\uFBE9'] = '\u0649';
  16975. t['\uFBEA'] = '\u0626\u0627';
  16976. t['\uFBEB'] = '\u0626\u0627';
  16977. t['\uFBEC'] = '\u0626\u06D5';
  16978. t['\uFBED'] = '\u0626\u06D5';
  16979. t['\uFBEE'] = '\u0626\u0648';
  16980. t['\uFBEF'] = '\u0626\u0648';
  16981. t['\uFBF0'] = '\u0626\u06C7';
  16982. t['\uFBF1'] = '\u0626\u06C7';
  16983. t['\uFBF2'] = '\u0626\u06C6';
  16984. t['\uFBF3'] = '\u0626\u06C6';
  16985. t['\uFBF4'] = '\u0626\u06C8';
  16986. t['\uFBF5'] = '\u0626\u06C8';
  16987. t['\uFBF6'] = '\u0626\u06D0';
  16988. t['\uFBF7'] = '\u0626\u06D0';
  16989. t['\uFBF8'] = '\u0626\u06D0';
  16990. t['\uFBF9'] = '\u0626\u0649';
  16991. t['\uFBFA'] = '\u0626\u0649';
  16992. t['\uFBFB'] = '\u0626\u0649';
  16993. t['\uFBFC'] = '\u06CC';
  16994. t['\uFBFD'] = '\u06CC';
  16995. t['\uFBFE'] = '\u06CC';
  16996. t['\uFBFF'] = '\u06CC';
  16997. t['\uFC00'] = '\u0626\u062C';
  16998. t['\uFC01'] = '\u0626\u062D';
  16999. t['\uFC02'] = '\u0626\u0645';
  17000. t['\uFC03'] = '\u0626\u0649';
  17001. t['\uFC04'] = '\u0626\u064A';
  17002. t['\uFC05'] = '\u0628\u062C';
  17003. t['\uFC06'] = '\u0628\u062D';
  17004. t['\uFC07'] = '\u0628\u062E';
  17005. t['\uFC08'] = '\u0628\u0645';
  17006. t['\uFC09'] = '\u0628\u0649';
  17007. t['\uFC0A'] = '\u0628\u064A';
  17008. t['\uFC0B'] = '\u062A\u062C';
  17009. t['\uFC0C'] = '\u062A\u062D';
  17010. t['\uFC0D'] = '\u062A\u062E';
  17011. t['\uFC0E'] = '\u062A\u0645';
  17012. t['\uFC0F'] = '\u062A\u0649';
  17013. t['\uFC10'] = '\u062A\u064A';
  17014. t['\uFC11'] = '\u062B\u062C';
  17015. t['\uFC12'] = '\u062B\u0645';
  17016. t['\uFC13'] = '\u062B\u0649';
  17017. t['\uFC14'] = '\u062B\u064A';
  17018. t['\uFC15'] = '\u062C\u062D';
  17019. t['\uFC16'] = '\u062C\u0645';
  17020. t['\uFC17'] = '\u062D\u062C';
  17021. t['\uFC18'] = '\u062D\u0645';
  17022. t['\uFC19'] = '\u062E\u062C';
  17023. t['\uFC1A'] = '\u062E\u062D';
  17024. t['\uFC1B'] = '\u062E\u0645';
  17025. t['\uFC1C'] = '\u0633\u062C';
  17026. t['\uFC1D'] = '\u0633\u062D';
  17027. t['\uFC1E'] = '\u0633\u062E';
  17028. t['\uFC1F'] = '\u0633\u0645';
  17029. t['\uFC20'] = '\u0635\u062D';
  17030. t['\uFC21'] = '\u0635\u0645';
  17031. t['\uFC22'] = '\u0636\u062C';
  17032. t['\uFC23'] = '\u0636\u062D';
  17033. t['\uFC24'] = '\u0636\u062E';
  17034. t['\uFC25'] = '\u0636\u0645';
  17035. t['\uFC26'] = '\u0637\u062D';
  17036. t['\uFC27'] = '\u0637\u0645';
  17037. t['\uFC28'] = '\u0638\u0645';
  17038. t['\uFC29'] = '\u0639\u062C';
  17039. t['\uFC2A'] = '\u0639\u0645';
  17040. t['\uFC2B'] = '\u063A\u062C';
  17041. t['\uFC2C'] = '\u063A\u0645';
  17042. t['\uFC2D'] = '\u0641\u062C';
  17043. t['\uFC2E'] = '\u0641\u062D';
  17044. t['\uFC2F'] = '\u0641\u062E';
  17045. t['\uFC30'] = '\u0641\u0645';
  17046. t['\uFC31'] = '\u0641\u0649';
  17047. t['\uFC32'] = '\u0641\u064A';
  17048. t['\uFC33'] = '\u0642\u062D';
  17049. t['\uFC34'] = '\u0642\u0645';
  17050. t['\uFC35'] = '\u0642\u0649';
  17051. t['\uFC36'] = '\u0642\u064A';
  17052. t['\uFC37'] = '\u0643\u0627';
  17053. t['\uFC38'] = '\u0643\u062C';
  17054. t['\uFC39'] = '\u0643\u062D';
  17055. t['\uFC3A'] = '\u0643\u062E';
  17056. t['\uFC3B'] = '\u0643\u0644';
  17057. t['\uFC3C'] = '\u0643\u0645';
  17058. t['\uFC3D'] = '\u0643\u0649';
  17059. t['\uFC3E'] = '\u0643\u064A';
  17060. t['\uFC3F'] = '\u0644\u062C';
  17061. t['\uFC40'] = '\u0644\u062D';
  17062. t['\uFC41'] = '\u0644\u062E';
  17063. t['\uFC42'] = '\u0644\u0645';
  17064. t['\uFC43'] = '\u0644\u0649';
  17065. t['\uFC44'] = '\u0644\u064A';
  17066. t['\uFC45'] = '\u0645\u062C';
  17067. t['\uFC46'] = '\u0645\u062D';
  17068. t['\uFC47'] = '\u0645\u062E';
  17069. t['\uFC48'] = '\u0645\u0645';
  17070. t['\uFC49'] = '\u0645\u0649';
  17071. t['\uFC4A'] = '\u0645\u064A';
  17072. t['\uFC4B'] = '\u0646\u062C';
  17073. t['\uFC4C'] = '\u0646\u062D';
  17074. t['\uFC4D'] = '\u0646\u062E';
  17075. t['\uFC4E'] = '\u0646\u0645';
  17076. t['\uFC4F'] = '\u0646\u0649';
  17077. t['\uFC50'] = '\u0646\u064A';
  17078. t['\uFC51'] = '\u0647\u062C';
  17079. t['\uFC52'] = '\u0647\u0645';
  17080. t['\uFC53'] = '\u0647\u0649';
  17081. t['\uFC54'] = '\u0647\u064A';
  17082. t['\uFC55'] = '\u064A\u062C';
  17083. t['\uFC56'] = '\u064A\u062D';
  17084. t['\uFC57'] = '\u064A\u062E';
  17085. t['\uFC58'] = '\u064A\u0645';
  17086. t['\uFC59'] = '\u064A\u0649';
  17087. t['\uFC5A'] = '\u064A\u064A';
  17088. t['\uFC5B'] = '\u0630\u0670';
  17089. t['\uFC5C'] = '\u0631\u0670';
  17090. t['\uFC5D'] = '\u0649\u0670';
  17091. t['\uFC5E'] = '\u0020\u064C\u0651';
  17092. t['\uFC5F'] = '\u0020\u064D\u0651';
  17093. t['\uFC60'] = '\u0020\u064E\u0651';
  17094. t['\uFC61'] = '\u0020\u064F\u0651';
  17095. t['\uFC62'] = '\u0020\u0650\u0651';
  17096. t['\uFC63'] = '\u0020\u0651\u0670';
  17097. t['\uFC64'] = '\u0626\u0631';
  17098. t['\uFC65'] = '\u0626\u0632';
  17099. t['\uFC66'] = '\u0626\u0645';
  17100. t['\uFC67'] = '\u0626\u0646';
  17101. t['\uFC68'] = '\u0626\u0649';
  17102. t['\uFC69'] = '\u0626\u064A';
  17103. t['\uFC6A'] = '\u0628\u0631';
  17104. t['\uFC6B'] = '\u0628\u0632';
  17105. t['\uFC6C'] = '\u0628\u0645';
  17106. t['\uFC6D'] = '\u0628\u0646';
  17107. t['\uFC6E'] = '\u0628\u0649';
  17108. t['\uFC6F'] = '\u0628\u064A';
  17109. t['\uFC70'] = '\u062A\u0631';
  17110. t['\uFC71'] = '\u062A\u0632';
  17111. t['\uFC72'] = '\u062A\u0645';
  17112. t['\uFC73'] = '\u062A\u0646';
  17113. t['\uFC74'] = '\u062A\u0649';
  17114. t['\uFC75'] = '\u062A\u064A';
  17115. t['\uFC76'] = '\u062B\u0631';
  17116. t['\uFC77'] = '\u062B\u0632';
  17117. t['\uFC78'] = '\u062B\u0645';
  17118. t['\uFC79'] = '\u062B\u0646';
  17119. t['\uFC7A'] = '\u062B\u0649';
  17120. t['\uFC7B'] = '\u062B\u064A';
  17121. t['\uFC7C'] = '\u0641\u0649';
  17122. t['\uFC7D'] = '\u0641\u064A';
  17123. t['\uFC7E'] = '\u0642\u0649';
  17124. t['\uFC7F'] = '\u0642\u064A';
  17125. t['\uFC80'] = '\u0643\u0627';
  17126. t['\uFC81'] = '\u0643\u0644';
  17127. t['\uFC82'] = '\u0643\u0645';
  17128. t['\uFC83'] = '\u0643\u0649';
  17129. t['\uFC84'] = '\u0643\u064A';
  17130. t['\uFC85'] = '\u0644\u0645';
  17131. t['\uFC86'] = '\u0644\u0649';
  17132. t['\uFC87'] = '\u0644\u064A';
  17133. t['\uFC88'] = '\u0645\u0627';
  17134. t['\uFC89'] = '\u0645\u0645';
  17135. t['\uFC8A'] = '\u0646\u0631';
  17136. t['\uFC8B'] = '\u0646\u0632';
  17137. t['\uFC8C'] = '\u0646\u0645';
  17138. t['\uFC8D'] = '\u0646\u0646';
  17139. t['\uFC8E'] = '\u0646\u0649';
  17140. t['\uFC8F'] = '\u0646\u064A';
  17141. t['\uFC90'] = '\u0649\u0670';
  17142. t['\uFC91'] = '\u064A\u0631';
  17143. t['\uFC92'] = '\u064A\u0632';
  17144. t['\uFC93'] = '\u064A\u0645';
  17145. t['\uFC94'] = '\u064A\u0646';
  17146. t['\uFC95'] = '\u064A\u0649';
  17147. t['\uFC96'] = '\u064A\u064A';
  17148. t['\uFC97'] = '\u0626\u062C';
  17149. t['\uFC98'] = '\u0626\u062D';
  17150. t['\uFC99'] = '\u0626\u062E';
  17151. t['\uFC9A'] = '\u0626\u0645';
  17152. t['\uFC9B'] = '\u0626\u0647';
  17153. t['\uFC9C'] = '\u0628\u062C';
  17154. t['\uFC9D'] = '\u0628\u062D';
  17155. t['\uFC9E'] = '\u0628\u062E';
  17156. t['\uFC9F'] = '\u0628\u0645';
  17157. t['\uFCA0'] = '\u0628\u0647';
  17158. t['\uFCA1'] = '\u062A\u062C';
  17159. t['\uFCA2'] = '\u062A\u062D';
  17160. t['\uFCA3'] = '\u062A\u062E';
  17161. t['\uFCA4'] = '\u062A\u0645';
  17162. t['\uFCA5'] = '\u062A\u0647';
  17163. t['\uFCA6'] = '\u062B\u0645';
  17164. t['\uFCA7'] = '\u062C\u062D';
  17165. t['\uFCA8'] = '\u062C\u0645';
  17166. t['\uFCA9'] = '\u062D\u062C';
  17167. t['\uFCAA'] = '\u062D\u0645';
  17168. t['\uFCAB'] = '\u062E\u062C';
  17169. t['\uFCAC'] = '\u062E\u0645';
  17170. t['\uFCAD'] = '\u0633\u062C';
  17171. t['\uFCAE'] = '\u0633\u062D';
  17172. t['\uFCAF'] = '\u0633\u062E';
  17173. t['\uFCB0'] = '\u0633\u0645';
  17174. t['\uFCB1'] = '\u0635\u062D';
  17175. t['\uFCB2'] = '\u0635\u062E';
  17176. t['\uFCB3'] = '\u0635\u0645';
  17177. t['\uFCB4'] = '\u0636\u062C';
  17178. t['\uFCB5'] = '\u0636\u062D';
  17179. t['\uFCB6'] = '\u0636\u062E';
  17180. t['\uFCB7'] = '\u0636\u0645';
  17181. t['\uFCB8'] = '\u0637\u062D';
  17182. t['\uFCB9'] = '\u0638\u0645';
  17183. t['\uFCBA'] = '\u0639\u062C';
  17184. t['\uFCBB'] = '\u0639\u0645';
  17185. t['\uFCBC'] = '\u063A\u062C';
  17186. t['\uFCBD'] = '\u063A\u0645';
  17187. t['\uFCBE'] = '\u0641\u062C';
  17188. t['\uFCBF'] = '\u0641\u062D';
  17189. t['\uFCC0'] = '\u0641\u062E';
  17190. t['\uFCC1'] = '\u0641\u0645';
  17191. t['\uFCC2'] = '\u0642\u062D';
  17192. t['\uFCC3'] = '\u0642\u0645';
  17193. t['\uFCC4'] = '\u0643\u062C';
  17194. t['\uFCC5'] = '\u0643\u062D';
  17195. t['\uFCC6'] = '\u0643\u062E';
  17196. t['\uFCC7'] = '\u0643\u0644';
  17197. t['\uFCC8'] = '\u0643\u0645';
  17198. t['\uFCC9'] = '\u0644\u062C';
  17199. t['\uFCCA'] = '\u0644\u062D';
  17200. t['\uFCCB'] = '\u0644\u062E';
  17201. t['\uFCCC'] = '\u0644\u0645';
  17202. t['\uFCCD'] = '\u0644\u0647';
  17203. t['\uFCCE'] = '\u0645\u062C';
  17204. t['\uFCCF'] = '\u0645\u062D';
  17205. t['\uFCD0'] = '\u0645\u062E';
  17206. t['\uFCD1'] = '\u0645\u0645';
  17207. t['\uFCD2'] = '\u0646\u062C';
  17208. t['\uFCD3'] = '\u0646\u062D';
  17209. t['\uFCD4'] = '\u0646\u062E';
  17210. t['\uFCD5'] = '\u0646\u0645';
  17211. t['\uFCD6'] = '\u0646\u0647';
  17212. t['\uFCD7'] = '\u0647\u062C';
  17213. t['\uFCD8'] = '\u0647\u0645';
  17214. t['\uFCD9'] = '\u0647\u0670';
  17215. t['\uFCDA'] = '\u064A\u062C';
  17216. t['\uFCDB'] = '\u064A\u062D';
  17217. t['\uFCDC'] = '\u064A\u062E';
  17218. t['\uFCDD'] = '\u064A\u0645';
  17219. t['\uFCDE'] = '\u064A\u0647';
  17220. t['\uFCDF'] = '\u0626\u0645';
  17221. t['\uFCE0'] = '\u0626\u0647';
  17222. t['\uFCE1'] = '\u0628\u0645';
  17223. t['\uFCE2'] = '\u0628\u0647';
  17224. t['\uFCE3'] = '\u062A\u0645';
  17225. t['\uFCE4'] = '\u062A\u0647';
  17226. t['\uFCE5'] = '\u062B\u0645';
  17227. t['\uFCE6'] = '\u062B\u0647';
  17228. t['\uFCE7'] = '\u0633\u0645';
  17229. t['\uFCE8'] = '\u0633\u0647';
  17230. t['\uFCE9'] = '\u0634\u0645';
  17231. t['\uFCEA'] = '\u0634\u0647';
  17232. t['\uFCEB'] = '\u0643\u0644';
  17233. t['\uFCEC'] = '\u0643\u0645';
  17234. t['\uFCED'] = '\u0644\u0645';
  17235. t['\uFCEE'] = '\u0646\u0645';
  17236. t['\uFCEF'] = '\u0646\u0647';
  17237. t['\uFCF0'] = '\u064A\u0645';
  17238. t['\uFCF1'] = '\u064A\u0647';
  17239. t['\uFCF2'] = '\u0640\u064E\u0651';
  17240. t['\uFCF3'] = '\u0640\u064F\u0651';
  17241. t['\uFCF4'] = '\u0640\u0650\u0651';
  17242. t['\uFCF5'] = '\u0637\u0649';
  17243. t['\uFCF6'] = '\u0637\u064A';
  17244. t['\uFCF7'] = '\u0639\u0649';
  17245. t['\uFCF8'] = '\u0639\u064A';
  17246. t['\uFCF9'] = '\u063A\u0649';
  17247. t['\uFCFA'] = '\u063A\u064A';
  17248. t['\uFCFB'] = '\u0633\u0649';
  17249. t['\uFCFC'] = '\u0633\u064A';
  17250. t['\uFCFD'] = '\u0634\u0649';
  17251. t['\uFCFE'] = '\u0634\u064A';
  17252. t['\uFCFF'] = '\u062D\u0649';
  17253. t['\uFD00'] = '\u062D\u064A';
  17254. t['\uFD01'] = '\u062C\u0649';
  17255. t['\uFD02'] = '\u062C\u064A';
  17256. t['\uFD03'] = '\u062E\u0649';
  17257. t['\uFD04'] = '\u062E\u064A';
  17258. t['\uFD05'] = '\u0635\u0649';
  17259. t['\uFD06'] = '\u0635\u064A';
  17260. t['\uFD07'] = '\u0636\u0649';
  17261. t['\uFD08'] = '\u0636\u064A';
  17262. t['\uFD09'] = '\u0634\u062C';
  17263. t['\uFD0A'] = '\u0634\u062D';
  17264. t['\uFD0B'] = '\u0634\u062E';
  17265. t['\uFD0C'] = '\u0634\u0645';
  17266. t['\uFD0D'] = '\u0634\u0631';
  17267. t['\uFD0E'] = '\u0633\u0631';
  17268. t['\uFD0F'] = '\u0635\u0631';
  17269. t['\uFD10'] = '\u0636\u0631';
  17270. t['\uFD11'] = '\u0637\u0649';
  17271. t['\uFD12'] = '\u0637\u064A';
  17272. t['\uFD13'] = '\u0639\u0649';
  17273. t['\uFD14'] = '\u0639\u064A';
  17274. t['\uFD15'] = '\u063A\u0649';
  17275. t['\uFD16'] = '\u063A\u064A';
  17276. t['\uFD17'] = '\u0633\u0649';
  17277. t['\uFD18'] = '\u0633\u064A';
  17278. t['\uFD19'] = '\u0634\u0649';
  17279. t['\uFD1A'] = '\u0634\u064A';
  17280. t['\uFD1B'] = '\u062D\u0649';
  17281. t['\uFD1C'] = '\u062D\u064A';
  17282. t['\uFD1D'] = '\u062C\u0649';
  17283. t['\uFD1E'] = '\u062C\u064A';
  17284. t['\uFD1F'] = '\u062E\u0649';
  17285. t['\uFD20'] = '\u062E\u064A';
  17286. t['\uFD21'] = '\u0635\u0649';
  17287. t['\uFD22'] = '\u0635\u064A';
  17288. t['\uFD23'] = '\u0636\u0649';
  17289. t['\uFD24'] = '\u0636\u064A';
  17290. t['\uFD25'] = '\u0634\u062C';
  17291. t['\uFD26'] = '\u0634\u062D';
  17292. t['\uFD27'] = '\u0634\u062E';
  17293. t['\uFD28'] = '\u0634\u0645';
  17294. t['\uFD29'] = '\u0634\u0631';
  17295. t['\uFD2A'] = '\u0633\u0631';
  17296. t['\uFD2B'] = '\u0635\u0631';
  17297. t['\uFD2C'] = '\u0636\u0631';
  17298. t['\uFD2D'] = '\u0634\u062C';
  17299. t['\uFD2E'] = '\u0634\u062D';
  17300. t['\uFD2F'] = '\u0634\u062E';
  17301. t['\uFD30'] = '\u0634\u0645';
  17302. t['\uFD31'] = '\u0633\u0647';
  17303. t['\uFD32'] = '\u0634\u0647';
  17304. t['\uFD33'] = '\u0637\u0645';
  17305. t['\uFD34'] = '\u0633\u062C';
  17306. t['\uFD35'] = '\u0633\u062D';
  17307. t['\uFD36'] = '\u0633\u062E';
  17308. t['\uFD37'] = '\u0634\u062C';
  17309. t['\uFD38'] = '\u0634\u062D';
  17310. t['\uFD39'] = '\u0634\u062E';
  17311. t['\uFD3A'] = '\u0637\u0645';
  17312. t['\uFD3B'] = '\u0638\u0645';
  17313. t['\uFD3C'] = '\u0627\u064B';
  17314. t['\uFD3D'] = '\u0627\u064B';
  17315. t['\uFD50'] = '\u062A\u062C\u0645';
  17316. t['\uFD51'] = '\u062A\u062D\u062C';
  17317. t['\uFD52'] = '\u062A\u062D\u062C';
  17318. t['\uFD53'] = '\u062A\u062D\u0645';
  17319. t['\uFD54'] = '\u062A\u062E\u0645';
  17320. t['\uFD55'] = '\u062A\u0645\u062C';
  17321. t['\uFD56'] = '\u062A\u0645\u062D';
  17322. t['\uFD57'] = '\u062A\u0645\u062E';
  17323. t['\uFD58'] = '\u062C\u0645\u062D';
  17324. t['\uFD59'] = '\u062C\u0645\u062D';
  17325. t['\uFD5A'] = '\u062D\u0645\u064A';
  17326. t['\uFD5B'] = '\u062D\u0645\u0649';
  17327. t['\uFD5C'] = '\u0633\u062D\u062C';
  17328. t['\uFD5D'] = '\u0633\u062C\u062D';
  17329. t['\uFD5E'] = '\u0633\u062C\u0649';
  17330. t['\uFD5F'] = '\u0633\u0645\u062D';
  17331. t['\uFD60'] = '\u0633\u0645\u062D';
  17332. t['\uFD61'] = '\u0633\u0645\u062C';
  17333. t['\uFD62'] = '\u0633\u0645\u0645';
  17334. t['\uFD63'] = '\u0633\u0645\u0645';
  17335. t['\uFD64'] = '\u0635\u062D\u062D';
  17336. t['\uFD65'] = '\u0635\u062D\u062D';
  17337. t['\uFD66'] = '\u0635\u0645\u0645';
  17338. t['\uFD67'] = '\u0634\u062D\u0645';
  17339. t['\uFD68'] = '\u0634\u062D\u0645';
  17340. t['\uFD69'] = '\u0634\u062C\u064A';
  17341. t['\uFD6A'] = '\u0634\u0645\u062E';
  17342. t['\uFD6B'] = '\u0634\u0645\u062E';
  17343. t['\uFD6C'] = '\u0634\u0645\u0645';
  17344. t['\uFD6D'] = '\u0634\u0645\u0645';
  17345. t['\uFD6E'] = '\u0636\u062D\u0649';
  17346. t['\uFD6F'] = '\u0636\u062E\u0645';
  17347. t['\uFD70'] = '\u0636\u062E\u0645';
  17348. t['\uFD71'] = '\u0637\u0645\u062D';
  17349. t['\uFD72'] = '\u0637\u0645\u062D';
  17350. t['\uFD73'] = '\u0637\u0645\u0645';
  17351. t['\uFD74'] = '\u0637\u0645\u064A';
  17352. t['\uFD75'] = '\u0639\u062C\u0645';
  17353. t['\uFD76'] = '\u0639\u0645\u0645';
  17354. t['\uFD77'] = '\u0639\u0645\u0645';
  17355. t['\uFD78'] = '\u0639\u0645\u0649';
  17356. t['\uFD79'] = '\u063A\u0645\u0645';
  17357. t['\uFD7A'] = '\u063A\u0645\u064A';
  17358. t['\uFD7B'] = '\u063A\u0645\u0649';
  17359. t['\uFD7C'] = '\u0641\u062E\u0645';
  17360. t['\uFD7D'] = '\u0641\u062E\u0645';
  17361. t['\uFD7E'] = '\u0642\u0645\u062D';
  17362. t['\uFD7F'] = '\u0642\u0645\u0645';
  17363. t['\uFD80'] = '\u0644\u062D\u0645';
  17364. t['\uFD81'] = '\u0644\u062D\u064A';
  17365. t['\uFD82'] = '\u0644\u062D\u0649';
  17366. t['\uFD83'] = '\u0644\u062C\u062C';
  17367. t['\uFD84'] = '\u0644\u062C\u062C';
  17368. t['\uFD85'] = '\u0644\u062E\u0645';
  17369. t['\uFD86'] = '\u0644\u062E\u0645';
  17370. t['\uFD87'] = '\u0644\u0645\u062D';
  17371. t['\uFD88'] = '\u0644\u0645\u062D';
  17372. t['\uFD89'] = '\u0645\u062D\u062C';
  17373. t['\uFD8A'] = '\u0645\u062D\u0645';
  17374. t['\uFD8B'] = '\u0645\u062D\u064A';
  17375. t['\uFD8C'] = '\u0645\u062C\u062D';
  17376. t['\uFD8D'] = '\u0645\u062C\u0645';
  17377. t['\uFD8E'] = '\u0645\u062E\u062C';
  17378. t['\uFD8F'] = '\u0645\u062E\u0645';
  17379. t['\uFD92'] = '\u0645\u062C\u062E';
  17380. t['\uFD93'] = '\u0647\u0645\u062C';
  17381. t['\uFD94'] = '\u0647\u0645\u0645';
  17382. t['\uFD95'] = '\u0646\u062D\u0645';
  17383. t['\uFD96'] = '\u0646\u062D\u0649';
  17384. t['\uFD97'] = '\u0646\u062C\u0645';
  17385. t['\uFD98'] = '\u0646\u062C\u0645';
  17386. t['\uFD99'] = '\u0646\u062C\u0649';
  17387. t['\uFD9A'] = '\u0646\u0645\u064A';
  17388. t['\uFD9B'] = '\u0646\u0645\u0649';
  17389. t['\uFD9C'] = '\u064A\u0645\u0645';
  17390. t['\uFD9D'] = '\u064A\u0645\u0645';
  17391. t['\uFD9E'] = '\u0628\u062E\u064A';
  17392. t['\uFD9F'] = '\u062A\u062C\u064A';
  17393. t['\uFDA0'] = '\u062A\u062C\u0649';
  17394. t['\uFDA1'] = '\u062A\u062E\u064A';
  17395. t['\uFDA2'] = '\u062A\u062E\u0649';
  17396. t['\uFDA3'] = '\u062A\u0645\u064A';
  17397. t['\uFDA4'] = '\u062A\u0645\u0649';
  17398. t['\uFDA5'] = '\u062C\u0645\u064A';
  17399. t['\uFDA6'] = '\u062C\u062D\u0649';
  17400. t['\uFDA7'] = '\u062C\u0645\u0649';
  17401. t['\uFDA8'] = '\u0633\u062E\u0649';
  17402. t['\uFDA9'] = '\u0635\u062D\u064A';
  17403. t['\uFDAA'] = '\u0634\u062D\u064A';
  17404. t['\uFDAB'] = '\u0636\u062D\u064A';
  17405. t['\uFDAC'] = '\u0644\u062C\u064A';
  17406. t['\uFDAD'] = '\u0644\u0645\u064A';
  17407. t['\uFDAE'] = '\u064A\u062D\u064A';
  17408. t['\uFDAF'] = '\u064A\u062C\u064A';
  17409. t['\uFDB0'] = '\u064A\u0645\u064A';
  17410. t['\uFDB1'] = '\u0645\u0645\u064A';
  17411. t['\uFDB2'] = '\u0642\u0645\u064A';
  17412. t['\uFDB3'] = '\u0646\u062D\u064A';
  17413. t['\uFDB4'] = '\u0642\u0645\u062D';
  17414. t['\uFDB5'] = '\u0644\u062D\u0645';
  17415. t['\uFDB6'] = '\u0639\u0645\u064A';
  17416. t['\uFDB7'] = '\u0643\u0645\u064A';
  17417. t['\uFDB8'] = '\u0646\u062C\u062D';
  17418. t['\uFDB9'] = '\u0645\u062E\u064A';
  17419. t['\uFDBA'] = '\u0644\u062C\u0645';
  17420. t['\uFDBB'] = '\u0643\u0645\u0645';
  17421. t['\uFDBC'] = '\u0644\u062C\u0645';
  17422. t['\uFDBD'] = '\u0646\u062C\u062D';
  17423. t['\uFDBE'] = '\u062C\u062D\u064A';
  17424. t['\uFDBF'] = '\u062D\u062C\u064A';
  17425. t['\uFDC0'] = '\u0645\u062C\u064A';
  17426. t['\uFDC1'] = '\u0641\u0645\u064A';
  17427. t['\uFDC2'] = '\u0628\u062D\u064A';
  17428. t['\uFDC3'] = '\u0643\u0645\u0645';
  17429. t['\uFDC4'] = '\u0639\u062C\u0645';
  17430. t['\uFDC5'] = '\u0635\u0645\u0645';
  17431. t['\uFDC6'] = '\u0633\u062E\u064A';
  17432. t['\uFDC7'] = '\u0646\u062C\u064A';
  17433. t['\uFE49'] = '\u203E';
  17434. t['\uFE4A'] = '\u203E';
  17435. t['\uFE4B'] = '\u203E';
  17436. t['\uFE4C'] = '\u203E';
  17437. t['\uFE4D'] = '\u005F';
  17438. t['\uFE4E'] = '\u005F';
  17439. t['\uFE4F'] = '\u005F';
  17440. t['\uFE80'] = '\u0621';
  17441. t['\uFE81'] = '\u0622';
  17442. t['\uFE82'] = '\u0622';
  17443. t['\uFE83'] = '\u0623';
  17444. t['\uFE84'] = '\u0623';
  17445. t['\uFE85'] = '\u0624';
  17446. t['\uFE86'] = '\u0624';
  17447. t['\uFE87'] = '\u0625';
  17448. t['\uFE88'] = '\u0625';
  17449. t['\uFE89'] = '\u0626';
  17450. t['\uFE8A'] = '\u0626';
  17451. t['\uFE8B'] = '\u0626';
  17452. t['\uFE8C'] = '\u0626';
  17453. t['\uFE8D'] = '\u0627';
  17454. t['\uFE8E'] = '\u0627';
  17455. t['\uFE8F'] = '\u0628';
  17456. t['\uFE90'] = '\u0628';
  17457. t['\uFE91'] = '\u0628';
  17458. t['\uFE92'] = '\u0628';
  17459. t['\uFE93'] = '\u0629';
  17460. t['\uFE94'] = '\u0629';
  17461. t['\uFE95'] = '\u062A';
  17462. t['\uFE96'] = '\u062A';
  17463. t['\uFE97'] = '\u062A';
  17464. t['\uFE98'] = '\u062A';
  17465. t['\uFE99'] = '\u062B';
  17466. t['\uFE9A'] = '\u062B';
  17467. t['\uFE9B'] = '\u062B';
  17468. t['\uFE9C'] = '\u062B';
  17469. t['\uFE9D'] = '\u062C';
  17470. t['\uFE9E'] = '\u062C';
  17471. t['\uFE9F'] = '\u062C';
  17472. t['\uFEA0'] = '\u062C';
  17473. t['\uFEA1'] = '\u062D';
  17474. t['\uFEA2'] = '\u062D';
  17475. t['\uFEA3'] = '\u062D';
  17476. t['\uFEA4'] = '\u062D';
  17477. t['\uFEA5'] = '\u062E';
  17478. t['\uFEA6'] = '\u062E';
  17479. t['\uFEA7'] = '\u062E';
  17480. t['\uFEA8'] = '\u062E';
  17481. t['\uFEA9'] = '\u062F';
  17482. t['\uFEAA'] = '\u062F';
  17483. t['\uFEAB'] = '\u0630';
  17484. t['\uFEAC'] = '\u0630';
  17485. t['\uFEAD'] = '\u0631';
  17486. t['\uFEAE'] = '\u0631';
  17487. t['\uFEAF'] = '\u0632';
  17488. t['\uFEB0'] = '\u0632';
  17489. t['\uFEB1'] = '\u0633';
  17490. t['\uFEB2'] = '\u0633';
  17491. t['\uFEB3'] = '\u0633';
  17492. t['\uFEB4'] = '\u0633';
  17493. t['\uFEB5'] = '\u0634';
  17494. t['\uFEB6'] = '\u0634';
  17495. t['\uFEB7'] = '\u0634';
  17496. t['\uFEB8'] = '\u0634';
  17497. t['\uFEB9'] = '\u0635';
  17498. t['\uFEBA'] = '\u0635';
  17499. t['\uFEBB'] = '\u0635';
  17500. t['\uFEBC'] = '\u0635';
  17501. t['\uFEBD'] = '\u0636';
  17502. t['\uFEBE'] = '\u0636';
  17503. t['\uFEBF'] = '\u0636';
  17504. t['\uFEC0'] = '\u0636';
  17505. t['\uFEC1'] = '\u0637';
  17506. t['\uFEC2'] = '\u0637';
  17507. t['\uFEC3'] = '\u0637';
  17508. t['\uFEC4'] = '\u0637';
  17509. t['\uFEC5'] = '\u0638';
  17510. t['\uFEC6'] = '\u0638';
  17511. t['\uFEC7'] = '\u0638';
  17512. t['\uFEC8'] = '\u0638';
  17513. t['\uFEC9'] = '\u0639';
  17514. t['\uFECA'] = '\u0639';
  17515. t['\uFECB'] = '\u0639';
  17516. t['\uFECC'] = '\u0639';
  17517. t['\uFECD'] = '\u063A';
  17518. t['\uFECE'] = '\u063A';
  17519. t['\uFECF'] = '\u063A';
  17520. t['\uFED0'] = '\u063A';
  17521. t['\uFED1'] = '\u0641';
  17522. t['\uFED2'] = '\u0641';
  17523. t['\uFED3'] = '\u0641';
  17524. t['\uFED4'] = '\u0641';
  17525. t['\uFED5'] = '\u0642';
  17526. t['\uFED6'] = '\u0642';
  17527. t['\uFED7'] = '\u0642';
  17528. t['\uFED8'] = '\u0642';
  17529. t['\uFED9'] = '\u0643';
  17530. t['\uFEDA'] = '\u0643';
  17531. t['\uFEDB'] = '\u0643';
  17532. t['\uFEDC'] = '\u0643';
  17533. t['\uFEDD'] = '\u0644';
  17534. t['\uFEDE'] = '\u0644';
  17535. t['\uFEDF'] = '\u0644';
  17536. t['\uFEE0'] = '\u0644';
  17537. t['\uFEE1'] = '\u0645';
  17538. t['\uFEE2'] = '\u0645';
  17539. t['\uFEE3'] = '\u0645';
  17540. t['\uFEE4'] = '\u0645';
  17541. t['\uFEE5'] = '\u0646';
  17542. t['\uFEE6'] = '\u0646';
  17543. t['\uFEE7'] = '\u0646';
  17544. t['\uFEE8'] = '\u0646';
  17545. t['\uFEE9'] = '\u0647';
  17546. t['\uFEEA'] = '\u0647';
  17547. t['\uFEEB'] = '\u0647';
  17548. t['\uFEEC'] = '\u0647';
  17549. t['\uFEED'] = '\u0648';
  17550. t['\uFEEE'] = '\u0648';
  17551. t['\uFEEF'] = '\u0649';
  17552. t['\uFEF0'] = '\u0649';
  17553. t['\uFEF1'] = '\u064A';
  17554. t['\uFEF2'] = '\u064A';
  17555. t['\uFEF3'] = '\u064A';
  17556. t['\uFEF4'] = '\u064A';
  17557. t['\uFEF5'] = '\u0644\u0622';
  17558. t['\uFEF6'] = '\u0644\u0622';
  17559. t['\uFEF7'] = '\u0644\u0623';
  17560. t['\uFEF8'] = '\u0644\u0623';
  17561. t['\uFEF9'] = '\u0644\u0625';
  17562. t['\uFEFA'] = '\u0644\u0625';
  17563. t['\uFEFB'] = '\u0644\u0627';
  17564. t['\uFEFC'] = '\u0644\u0627';
  17565. });
  17566. function reverseIfRtl(chars) {
  17567. var charsLength = chars.length;
  17568. //reverse an arabic ligature
  17569. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  17570. return chars;
  17571. }
  17572. var s = '';
  17573. for (var ii = charsLength - 1; ii >= 0; ii--) {
  17574. s += chars[ii];
  17575. }
  17576. return s;
  17577. }
  17578. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  17579. exports.reverseIfRtl = reverseIfRtl;
  17580. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  17581. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  17582. }));
  17583. (function (root, factory) {
  17584. {
  17585. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  17586. root.pdfjsDisplayDOMUtils);
  17587. }
  17588. }(this, function (exports, sharedUtil, displayDOMUtils) {
  17589. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  17590. var AnnotationType = sharedUtil.AnnotationType;
  17591. var Util = sharedUtil.Util;
  17592. var addLinkAttributes = sharedUtil.addLinkAttributes;
  17593. var warn = sharedUtil.warn;
  17594. var CustomStyle = displayDOMUtils.CustomStyle;
  17595. /**
  17596. * @typedef {Object} AnnotationElementParameters
  17597. * @property {Object} data
  17598. * @property {HTMLDivElement} layer
  17599. * @property {PDFPage} page
  17600. * @property {PageViewport} viewport
  17601. * @property {IPDFLinkService} linkService
  17602. */
  17603. /**
  17604. * @class
  17605. * @alias AnnotationElementFactory
  17606. */
  17607. function AnnotationElementFactory() {}
  17608. AnnotationElementFactory.prototype =
  17609. /** @lends AnnotationElementFactory.prototype */ {
  17610. /**
  17611. * @param {AnnotationElementParameters} parameters
  17612. * @returns {AnnotationElement}
  17613. */
  17614. create: function AnnotationElementFactory_create(parameters) {
  17615. var subtype = parameters.data.annotationType;
  17616. switch (subtype) {
  17617. case AnnotationType.LINK:
  17618. return new LinkAnnotationElement(parameters);
  17619. case AnnotationType.TEXT:
  17620. return new TextAnnotationElement(parameters);
  17621. case AnnotationType.WIDGET:
  17622. return new WidgetAnnotationElement(parameters);
  17623. case AnnotationType.POPUP:
  17624. return new PopupAnnotationElement(parameters);
  17625. case AnnotationType.HIGHLIGHT:
  17626. return new HighlightAnnotationElement(parameters);
  17627. case AnnotationType.UNDERLINE:
  17628. return new UnderlineAnnotationElement(parameters);
  17629. case AnnotationType.SQUIGGLY:
  17630. return new SquigglyAnnotationElement(parameters);
  17631. case AnnotationType.STRIKEOUT:
  17632. return new StrikeOutAnnotationElement(parameters);
  17633. default:
  17634. return new AnnotationElement(parameters);
  17635. }
  17636. }
  17637. };
  17638. /**
  17639. * @class
  17640. * @alias AnnotationElement
  17641. */
  17642. var AnnotationElement = (function AnnotationElementClosure() {
  17643. function AnnotationElement(parameters, isRenderable) {
  17644. this.isRenderable = isRenderable || false;
  17645. this.data = parameters.data;
  17646. this.layer = parameters.layer;
  17647. this.page = parameters.page;
  17648. this.viewport = parameters.viewport;
  17649. this.linkService = parameters.linkService;
  17650. if (isRenderable) {
  17651. this.container = this._createContainer();
  17652. }
  17653. }
  17654. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  17655. /**
  17656. * Create an empty container for the annotation's HTML element.
  17657. *
  17658. * @private
  17659. * @memberof AnnotationElement
  17660. * @returns {HTMLSectionElement}
  17661. */
  17662. _createContainer: function AnnotationElement_createContainer() {
  17663. var data = this.data, page = this.page, viewport = this.viewport;
  17664. var container = document.createElement('section');
  17665. var width = data.rect[2] - data.rect[0];
  17666. var height = data.rect[3] - data.rect[1];
  17667. container.setAttribute('data-annotation-id', data.id);
  17668. // Do *not* modify `data.rect`, since that will corrupt the annotation
  17669. // position on subsequent calls to `_createContainer` (see issue 6804).
  17670. var rect = Util.normalizeRect([
  17671. data.rect[0],
  17672. page.view[3] - data.rect[1] + page.view[1],
  17673. data.rect[2],
  17674. page.view[3] - data.rect[3] + page.view[1]
  17675. ]);
  17676. CustomStyle.setProp('transform', container,
  17677. 'matrix(' + viewport.transform.join(',') + ')');
  17678. CustomStyle.setProp('transformOrigin', container,
  17679. -rect[0] + 'px ' + -rect[1] + 'px');
  17680. if (data.borderStyle.width > 0) {
  17681. container.style.borderWidth = data.borderStyle.width + 'px';
  17682. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  17683. // Underline styles only have a bottom border, so we do not need
  17684. // to adjust for all borders. This yields a similar result as
  17685. // Adobe Acrobat/Reader.
  17686. width = width - 2 * data.borderStyle.width;
  17687. height = height - 2 * data.borderStyle.width;
  17688. }
  17689. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  17690. var verticalRadius = data.borderStyle.verticalCornerRadius;
  17691. if (horizontalRadius > 0 || verticalRadius > 0) {
  17692. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  17693. CustomStyle.setProp('borderRadius', container, radius);
  17694. }
  17695. switch (data.borderStyle.style) {
  17696. case AnnotationBorderStyleType.SOLID:
  17697. container.style.borderStyle = 'solid';
  17698. break;
  17699. case AnnotationBorderStyleType.DASHED:
  17700. container.style.borderStyle = 'dashed';
  17701. break;
  17702. case AnnotationBorderStyleType.BEVELED:
  17703. warn('Unimplemented border style: beveled');
  17704. break;
  17705. case AnnotationBorderStyleType.INSET:
  17706. warn('Unimplemented border style: inset');
  17707. break;
  17708. case AnnotationBorderStyleType.UNDERLINE:
  17709. container.style.borderBottomStyle = 'solid';
  17710. break;
  17711. default:
  17712. break;
  17713. }
  17714. if (data.color) {
  17715. container.style.borderColor =
  17716. Util.makeCssRgb(data.color[0] | 0,
  17717. data.color[1] | 0,
  17718. data.color[2] | 0);
  17719. } else {
  17720. // Transparent (invisible) border, so do not draw it at all.
  17721. container.style.borderWidth = 0;
  17722. }
  17723. }
  17724. container.style.left = rect[0] + 'px';
  17725. container.style.top = rect[1] + 'px';
  17726. container.style.width = width + 'px';
  17727. container.style.height = height + 'px';
  17728. return container;
  17729. },
  17730. /**
  17731. * Render the annotation's HTML element in the empty container.
  17732. *
  17733. * @public
  17734. * @memberof AnnotationElement
  17735. */
  17736. render: function AnnotationElement_render() {
  17737. throw new Error('Abstract method AnnotationElement.render called');
  17738. }
  17739. };
  17740. return AnnotationElement;
  17741. })();
  17742. /**
  17743. * @class
  17744. * @alias LinkAnnotationElement
  17745. */
  17746. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  17747. function LinkAnnotationElement(parameters) {
  17748. AnnotationElement.call(this, parameters, true);
  17749. }
  17750. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  17751. /**
  17752. * Render the link annotation's HTML element in the empty container.
  17753. *
  17754. * @public
  17755. * @memberof LinkAnnotationElement
  17756. * @returns {HTMLSectionElement}
  17757. */
  17758. render: function LinkAnnotationElement_render() {
  17759. this.container.className = 'linkAnnotation';
  17760. var link = document.createElement('a');
  17761. addLinkAttributes(link, { url: this.data.url });
  17762. if (!this.data.url) {
  17763. if (this.data.action) {
  17764. this._bindNamedAction(link, this.data.action);
  17765. } else {
  17766. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  17767. }
  17768. }
  17769. this.container.appendChild(link);
  17770. return this.container;
  17771. },
  17772. /**
  17773. * Bind internal links to the link element.
  17774. *
  17775. * @private
  17776. * @param {Object} link
  17777. * @param {Object} destination
  17778. * @memberof LinkAnnotationElement
  17779. */
  17780. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  17781. var self = this;
  17782. link.href = this.linkService.getDestinationHash(destination);
  17783. link.onclick = function() {
  17784. if (destination) {
  17785. self.linkService.navigateTo(destination);
  17786. }
  17787. return false;
  17788. };
  17789. if (destination) {
  17790. link.className = 'internalLink';
  17791. }
  17792. },
  17793. /**
  17794. * Bind named actions to the link element.
  17795. *
  17796. * @private
  17797. * @param {Object} link
  17798. * @param {Object} action
  17799. * @memberof LinkAnnotationElement
  17800. */
  17801. _bindNamedAction:
  17802. function LinkAnnotationElement_bindNamedAction(link, action) {
  17803. var self = this;
  17804. link.href = this.linkService.getAnchorUrl('');
  17805. link.onclick = function() {
  17806. self.linkService.executeNamedAction(action);
  17807. return false;
  17808. };
  17809. link.className = 'internalLink';
  17810. }
  17811. });
  17812. return LinkAnnotationElement;
  17813. })();
  17814. /**
  17815. * @class
  17816. * @alias TextAnnotationElement
  17817. */
  17818. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  17819. function TextAnnotationElement(parameters) {
  17820. var isRenderable = !!(parameters.data.hasPopup ||
  17821. parameters.data.title || parameters.data.contents);
  17822. AnnotationElement.call(this, parameters, isRenderable);
  17823. }
  17824. Util.inherit(TextAnnotationElement, AnnotationElement, {
  17825. /**
  17826. * Render the text annotation's HTML element in the empty container.
  17827. *
  17828. * @public
  17829. * @memberof TextAnnotationElement
  17830. * @returns {HTMLSectionElement}
  17831. */
  17832. render: function TextAnnotationElement_render() {
  17833. this.container.className = 'textAnnotation';
  17834. var image = document.createElement('img');
  17835. image.style.height = this.container.style.height;
  17836. image.style.width = this.container.style.width;
  17837. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  17838. this.data.name.toLowerCase() + '.svg';
  17839. image.alt = '[{{type}} Annotation]';
  17840. image.dataset.l10nId = 'text_annotation_type';
  17841. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  17842. if (!this.data.hasPopup) {
  17843. var popupElement = new PopupElement({
  17844. container: this.container,
  17845. trigger: image,
  17846. color: this.data.color,
  17847. title: this.data.title,
  17848. contents: this.data.contents,
  17849. hideWrapper: true
  17850. });
  17851. var popup = popupElement.render();
  17852. // Position the popup next to the Text annotation's container.
  17853. popup.style.left = image.style.width;
  17854. this.container.appendChild(popup);
  17855. }
  17856. this.container.appendChild(image);
  17857. return this.container;
  17858. }
  17859. });
  17860. return TextAnnotationElement;
  17861. })();
  17862. /**
  17863. * @class
  17864. * @alias WidgetAnnotationElement
  17865. */
  17866. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  17867. function WidgetAnnotationElement(parameters) {
  17868. var isRenderable = !parameters.data.hasAppearance &&
  17869. !!parameters.data.fieldValue;
  17870. AnnotationElement.call(this, parameters, isRenderable);
  17871. }
  17872. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  17873. /**
  17874. * Render the widget annotation's HTML element in the empty container.
  17875. *
  17876. * @public
  17877. * @memberof WidgetAnnotationElement
  17878. * @returns {HTMLSectionElement}
  17879. */
  17880. render: function WidgetAnnotationElement_render() {
  17881. var content = document.createElement('div');
  17882. content.textContent = this.data.fieldValue;
  17883. var textAlignment = this.data.textAlignment;
  17884. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  17885. content.style.verticalAlign = 'middle';
  17886. content.style.display = 'table-cell';
  17887. var font = (this.data.fontRefName ?
  17888. this.page.commonObjs.getData(this.data.fontRefName) : null);
  17889. this._setTextStyle(content, font);
  17890. this.container.appendChild(content);
  17891. return this.container;
  17892. },
  17893. /**
  17894. * Apply text styles to the text in the element.
  17895. *
  17896. * @private
  17897. * @param {HTMLDivElement} element
  17898. * @param {Object} font
  17899. * @memberof WidgetAnnotationElement
  17900. */
  17901. _setTextStyle:
  17902. function WidgetAnnotationElement_setTextStyle(element, font) {
  17903. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  17904. var style = element.style;
  17905. style.fontSize = this.data.fontSize + 'px';
  17906. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  17907. if (!font) {
  17908. return;
  17909. }
  17910. style.fontWeight = (font.black ?
  17911. (font.bold ? '900' : 'bold') :
  17912. (font.bold ? 'bold' : 'normal'));
  17913. style.fontStyle = (font.italic ? 'italic' : 'normal');
  17914. // Use a reasonable default font if the font doesn't specify a fallback.
  17915. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  17916. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  17917. style.fontFamily = fontFamily + fallbackName;
  17918. }
  17919. });
  17920. return WidgetAnnotationElement;
  17921. })();
  17922. /**
  17923. * @class
  17924. * @alias PopupAnnotationElement
  17925. */
  17926. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  17927. function PopupAnnotationElement(parameters) {
  17928. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  17929. AnnotationElement.call(this, parameters, isRenderable);
  17930. }
  17931. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  17932. /**
  17933. * Render the popup annotation's HTML element in the empty container.
  17934. *
  17935. * @public
  17936. * @memberof PopupAnnotationElement
  17937. * @returns {HTMLSectionElement}
  17938. */
  17939. render: function PopupAnnotationElement_render() {
  17940. this.container.className = 'popupAnnotation';
  17941. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  17942. var parentElement = this.layer.querySelector(selector);
  17943. if (!parentElement) {
  17944. return this.container;
  17945. }
  17946. var popup = new PopupElement({
  17947. container: this.container,
  17948. trigger: parentElement,
  17949. color: this.data.color,
  17950. title: this.data.title,
  17951. contents: this.data.contents
  17952. });
  17953. // Position the popup next to the parent annotation's container.
  17954. // PDF viewers ignore a popup annotation's rectangle.
  17955. var parentLeft = parseFloat(parentElement.style.left);
  17956. var parentWidth = parseFloat(parentElement.style.width);
  17957. CustomStyle.setProp('transformOrigin', this.container,
  17958. -(parentLeft + parentWidth) + 'px -' +
  17959. parentElement.style.top);
  17960. this.container.style.left = (parentLeft + parentWidth) + 'px';
  17961. this.container.appendChild(popup.render());
  17962. return this.container;
  17963. }
  17964. });
  17965. return PopupAnnotationElement;
  17966. })();
  17967. /**
  17968. * @class
  17969. * @alias PopupElement
  17970. */
  17971. var PopupElement = (function PopupElementClosure() {
  17972. var BACKGROUND_ENLIGHT = 0.7;
  17973. function PopupElement(parameters) {
  17974. this.container = parameters.container;
  17975. this.trigger = parameters.trigger;
  17976. this.color = parameters.color;
  17977. this.title = parameters.title;
  17978. this.contents = parameters.contents;
  17979. this.hideWrapper = parameters.hideWrapper || false;
  17980. this.pinned = false;
  17981. }
  17982. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  17983. /**
  17984. * Render the popup's HTML element.
  17985. *
  17986. * @public
  17987. * @memberof PopupElement
  17988. * @returns {HTMLSectionElement}
  17989. */
  17990. render: function PopupElement_render() {
  17991. var wrapper = document.createElement('div');
  17992. wrapper.className = 'popupWrapper';
  17993. // For Popup annotations we hide the entire section because it contains
  17994. // only the popup. However, for Text annotations without a separate Popup
  17995. // annotation, we cannot hide the entire container as the image would
  17996. // disappear too. In that special case, hiding the wrapper suffices.
  17997. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  17998. this.hideElement.setAttribute('hidden', true);
  17999. var popup = document.createElement('div');
  18000. popup.className = 'popup';
  18001. var color = this.color;
  18002. if (color) {
  18003. // Enlighten the color.
  18004. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  18005. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  18006. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  18007. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  18008. }
  18009. var contents = this._formatContents(this.contents);
  18010. var title = document.createElement('h1');
  18011. title.textContent = this.title;
  18012. // Attach the event listeners to the trigger element.
  18013. this.trigger.addEventListener('click', this._toggle.bind(this));
  18014. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  18015. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  18016. popup.addEventListener('click', this._hide.bind(this, true));
  18017. popup.appendChild(title);
  18018. popup.appendChild(contents);
  18019. wrapper.appendChild(popup);
  18020. return wrapper;
  18021. },
  18022. /**
  18023. * Format the contents of the popup by adding newlines where necessary.
  18024. *
  18025. * @private
  18026. * @param {string} contents
  18027. * @memberof PopupElement
  18028. * @returns {HTMLParagraphElement}
  18029. */
  18030. _formatContents: function PopupElement_formatContents(contents) {
  18031. var p = document.createElement('p');
  18032. var lines = contents.split(/(?:\r\n?|\n)/);
  18033. for (var i = 0, ii = lines.length; i < ii; ++i) {
  18034. var line = lines[i];
  18035. p.appendChild(document.createTextNode(line));
  18036. if (i < (ii - 1)) {
  18037. p.appendChild(document.createElement('br'));
  18038. }
  18039. }
  18040. return p;
  18041. },
  18042. /**
  18043. * Toggle the visibility of the popup.
  18044. *
  18045. * @private
  18046. * @memberof PopupElement
  18047. */
  18048. _toggle: function PopupElement_toggle() {
  18049. if (this.pinned) {
  18050. this._hide(true);
  18051. } else {
  18052. this._show(true);
  18053. }
  18054. },
  18055. /**
  18056. * Show the popup.
  18057. *
  18058. * @private
  18059. * @param {boolean} pin
  18060. * @memberof PopupElement
  18061. */
  18062. _show: function PopupElement_show(pin) {
  18063. if (pin) {
  18064. this.pinned = true;
  18065. }
  18066. if (this.hideElement.hasAttribute('hidden')) {
  18067. this.hideElement.removeAttribute('hidden');
  18068. this.container.style.zIndex += 1;
  18069. }
  18070. },
  18071. /**
  18072. * Hide the popup.
  18073. *
  18074. * @private
  18075. * @param {boolean} unpin
  18076. * @memberof PopupElement
  18077. */
  18078. _hide: function PopupElement_hide(unpin) {
  18079. if (unpin) {
  18080. this.pinned = false;
  18081. }
  18082. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  18083. this.hideElement.setAttribute('hidden', true);
  18084. this.container.style.zIndex -= 1;
  18085. }
  18086. }
  18087. };
  18088. return PopupElement;
  18089. })();
  18090. /**
  18091. * @class
  18092. * @alias HighlightAnnotationElement
  18093. */
  18094. var HighlightAnnotationElement = (
  18095. function HighlightAnnotationElementClosure() {
  18096. function HighlightAnnotationElement(parameters) {
  18097. var isRenderable = parameters.data.hasPopup;
  18098. AnnotationElement.call(this, parameters, isRenderable);
  18099. }
  18100. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  18101. /**
  18102. * Render the highlight annotation's HTML element in the empty container.
  18103. *
  18104. * @public
  18105. * @memberof HighlightAnnotationElement
  18106. * @returns {HTMLSectionElement}
  18107. */
  18108. render: function HighlightAnnotationElement_render() {
  18109. this.container.className = 'highlightAnnotation';
  18110. return this.container;
  18111. }
  18112. });
  18113. return HighlightAnnotationElement;
  18114. })();
  18115. /**
  18116. * @class
  18117. * @alias UnderlineAnnotationElement
  18118. */
  18119. var UnderlineAnnotationElement = (
  18120. function UnderlineAnnotationElementClosure() {
  18121. function UnderlineAnnotationElement(parameters) {
  18122. var isRenderable = parameters.data.hasPopup;
  18123. AnnotationElement.call(this, parameters, isRenderable);
  18124. }
  18125. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  18126. /**
  18127. * Render the underline annotation's HTML element in the empty container.
  18128. *
  18129. * @public
  18130. * @memberof UnderlineAnnotationElement
  18131. * @returns {HTMLSectionElement}
  18132. */
  18133. render: function UnderlineAnnotationElement_render() {
  18134. this.container.className = 'underlineAnnotation';
  18135. return this.container;
  18136. }
  18137. });
  18138. return UnderlineAnnotationElement;
  18139. })();
  18140. /**
  18141. * @class
  18142. * @alias SquigglyAnnotationElement
  18143. */
  18144. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  18145. function SquigglyAnnotationElement(parameters) {
  18146. var isRenderable = parameters.data.hasPopup;
  18147. AnnotationElement.call(this, parameters, isRenderable);
  18148. }
  18149. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  18150. /**
  18151. * Render the squiggly annotation's HTML element in the empty container.
  18152. *
  18153. * @public
  18154. * @memberof SquigglyAnnotationElement
  18155. * @returns {HTMLSectionElement}
  18156. */
  18157. render: function SquigglyAnnotationElement_render() {
  18158. this.container.className = 'squigglyAnnotation';
  18159. return this.container;
  18160. }
  18161. });
  18162. return SquigglyAnnotationElement;
  18163. })();
  18164. /**
  18165. * @class
  18166. * @alias StrikeOutAnnotationElement
  18167. */
  18168. var StrikeOutAnnotationElement = (
  18169. function StrikeOutAnnotationElementClosure() {
  18170. function StrikeOutAnnotationElement(parameters) {
  18171. var isRenderable = parameters.data.hasPopup;
  18172. AnnotationElement.call(this, parameters, isRenderable);
  18173. }
  18174. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  18175. /**
  18176. * Render the strikeout annotation's HTML element in the empty container.
  18177. *
  18178. * @public
  18179. * @memberof StrikeOutAnnotationElement
  18180. * @returns {HTMLSectionElement}
  18181. */
  18182. render: function StrikeOutAnnotationElement_render() {
  18183. this.container.className = 'strikeoutAnnotation';
  18184. return this.container;
  18185. }
  18186. });
  18187. return StrikeOutAnnotationElement;
  18188. })();
  18189. /**
  18190. * @typedef {Object} AnnotationLayerParameters
  18191. * @property {PageViewport} viewport
  18192. * @property {HTMLDivElement} div
  18193. * @property {Array} annotations
  18194. * @property {PDFPage} page
  18195. * @property {IPDFLinkService} linkService
  18196. */
  18197. /**
  18198. * @class
  18199. * @alias AnnotationLayer
  18200. */
  18201. var AnnotationLayer = (function AnnotationLayerClosure() {
  18202. return {
  18203. /**
  18204. * Render a new annotation layer with all annotation elements.
  18205. *
  18206. * @public
  18207. * @param {AnnotationLayerParameters} parameters
  18208. * @memberof AnnotationLayer
  18209. */
  18210. render: function AnnotationLayer_render(parameters) {
  18211. var annotationElementFactory = new AnnotationElementFactory();
  18212. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  18213. var data = parameters.annotations[i];
  18214. if (!data) {
  18215. continue;
  18216. }
  18217. var properties = {
  18218. data: data,
  18219. layer: parameters.div,
  18220. page: parameters.page,
  18221. viewport: parameters.viewport,
  18222. linkService: parameters.linkService
  18223. };
  18224. var element = annotationElementFactory.create(properties);
  18225. if (element.isRenderable) {
  18226. parameters.div.appendChild(element.render());
  18227. }
  18228. }
  18229. },
  18230. /**
  18231. * Update the annotation elements on existing annotation layer.
  18232. *
  18233. * @public
  18234. * @param {AnnotationLayerParameters} parameters
  18235. * @memberof AnnotationLayer
  18236. */
  18237. update: function AnnotationLayer_update(parameters) {
  18238. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  18239. var data = parameters.annotations[i];
  18240. var element = parameters.div.querySelector(
  18241. '[data-annotation-id="' + data.id + '"]');
  18242. if (element) {
  18243. CustomStyle.setProp('transform', element,
  18244. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  18245. }
  18246. }
  18247. parameters.div.removeAttribute('hidden');
  18248. }
  18249. };
  18250. })();
  18251. PDFJS.AnnotationLayer = AnnotationLayer;
  18252. exports.AnnotationLayer = AnnotationLayer;
  18253. }));
  18254. (function (root, factory) {
  18255. {
  18256. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  18257. root.pdfjsSharedGlobal);
  18258. }
  18259. }(this, function (exports, sharedUtil, sharedGlobal) {
  18260. var assert = sharedUtil.assert;
  18261. var bytesToString = sharedUtil.bytesToString;
  18262. var string32 = sharedUtil.string32;
  18263. var shadow = sharedUtil.shadow;
  18264. var warn = sharedUtil.warn;
  18265. var PDFJS = sharedGlobal.PDFJS;
  18266. var globalScope = sharedGlobal.globalScope;
  18267. var isWorker = sharedGlobal.isWorker;
  18268. function FontLoader(docId) {
  18269. this.docId = docId;
  18270. this.styleElement = null;
  18271. this.nativeFontFaces = [];
  18272. this.loadTestFontId = 0;
  18273. this.loadingContext = {
  18274. requests: [],
  18275. nextRequestId: 0
  18276. };
  18277. }
  18278. FontLoader.prototype = {
  18279. insertRule: function fontLoaderInsertRule(rule) {
  18280. var styleElement = this.styleElement;
  18281. if (!styleElement) {
  18282. styleElement = this.styleElement = document.createElement('style');
  18283. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  18284. document.documentElement.getElementsByTagName('head')[0].appendChild(
  18285. styleElement);
  18286. }
  18287. var styleSheet = styleElement.sheet;
  18288. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  18289. },
  18290. clear: function fontLoaderClear() {
  18291. var styleElement = this.styleElement;
  18292. if (styleElement) {
  18293. styleElement.parentNode.removeChild(styleElement);
  18294. styleElement = this.styleElement = null;
  18295. }
  18296. this.nativeFontFaces.forEach(function(nativeFontFace) {
  18297. document.fonts.delete(nativeFontFace);
  18298. });
  18299. this.nativeFontFaces.length = 0;
  18300. },
  18301. get loadTestFont() {
  18302. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  18303. // height.
  18304. return shadow(this, 'loadTestFont', atob(
  18305. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  18306. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  18307. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  18308. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  18309. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  18310. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  18311. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  18312. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  18313. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  18314. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  18315. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  18316. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  18317. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  18318. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18319. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18320. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18321. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  18322. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  18323. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  18324. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  18325. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  18326. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  18327. ));
  18328. },
  18329. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  18330. this.nativeFontFaces.push(nativeFontFace);
  18331. document.fonts.add(nativeFontFace);
  18332. },
  18333. bind: function fontLoaderBind(fonts, callback) {
  18334. assert(!isWorker, 'bind() shall be called from main thread');
  18335. var rules = [];
  18336. var fontsToLoad = [];
  18337. var fontLoadPromises = [];
  18338. var getNativeFontPromise = function(nativeFontFace) {
  18339. // Return a promise that is always fulfilled, even when the font fails to
  18340. // load.
  18341. return nativeFontFace.loaded.catch(function(e) {
  18342. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  18343. });
  18344. };
  18345. for (var i = 0, ii = fonts.length; i < ii; i++) {
  18346. var font = fonts[i];
  18347. // Add the font to the DOM only once or skip if the font
  18348. // is already loaded.
  18349. if (font.attached || font.loading === false) {
  18350. continue;
  18351. }
  18352. font.attached = true;
  18353. if (FontLoader.isFontLoadingAPISupported) {
  18354. var nativeFontFace = font.createNativeFontFace();
  18355. if (nativeFontFace) {
  18356. this.addNativeFontFace(nativeFontFace);
  18357. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  18358. }
  18359. } else {
  18360. var rule = font.createFontFaceRule();
  18361. if (rule) {
  18362. this.insertRule(rule);
  18363. rules.push(rule);
  18364. fontsToLoad.push(font);
  18365. }
  18366. }
  18367. }
  18368. var request = this.queueLoadingCallback(callback);
  18369. if (FontLoader.isFontLoadingAPISupported) {
  18370. Promise.all(fontLoadPromises).then(function() {
  18371. request.complete();
  18372. });
  18373. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  18374. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  18375. } else {
  18376. request.complete();
  18377. }
  18378. },
  18379. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  18380. function LoadLoader_completeRequest() {
  18381. assert(!request.end, 'completeRequest() cannot be called twice');
  18382. request.end = Date.now();
  18383. // sending all completed requests in order how they were queued
  18384. while (context.requests.length > 0 && context.requests[0].end) {
  18385. var otherRequest = context.requests.shift();
  18386. setTimeout(otherRequest.callback, 0);
  18387. }
  18388. }
  18389. var context = this.loadingContext;
  18390. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  18391. var request = {
  18392. id: requestId,
  18393. complete: LoadLoader_completeRequest,
  18394. callback: callback,
  18395. started: Date.now()
  18396. };
  18397. context.requests.push(request);
  18398. return request;
  18399. },
  18400. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  18401. fonts,
  18402. request) {
  18403. /** Hack begin */
  18404. // There's currently no event when a font has finished downloading so the
  18405. // following code is a dirty hack to 'guess' when a font is
  18406. // ready. It's assumed fonts are loaded in order, so add a known test
  18407. // font after the desired fonts and then test for the loading of that
  18408. // test font.
  18409. function int32(data, offset) {
  18410. return (data.charCodeAt(offset) << 24) |
  18411. (data.charCodeAt(offset + 1) << 16) |
  18412. (data.charCodeAt(offset + 2) << 8) |
  18413. (data.charCodeAt(offset + 3) & 0xff);
  18414. }
  18415. function spliceString(s, offset, remove, insert) {
  18416. var chunk1 = s.substr(0, offset);
  18417. var chunk2 = s.substr(offset + remove);
  18418. return chunk1 + insert + chunk2;
  18419. }
  18420. var i, ii;
  18421. var canvas = document.createElement('canvas');
  18422. canvas.width = 1;
  18423. canvas.height = 1;
  18424. var ctx = canvas.getContext('2d');
  18425. var called = 0;
  18426. function isFontReady(name, callback) {
  18427. called++;
  18428. // With setTimeout clamping this gives the font ~100ms to load.
  18429. if(called > 30) {
  18430. warn('Load test font never loaded.');
  18431. callback();
  18432. return;
  18433. }
  18434. ctx.font = '30px ' + name;
  18435. ctx.fillText('.', 0, 20);
  18436. var imageData = ctx.getImageData(0, 0, 1, 1);
  18437. if (imageData.data[3] > 0) {
  18438. callback();
  18439. return;
  18440. }
  18441. setTimeout(isFontReady.bind(null, name, callback));
  18442. }
  18443. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  18444. // Chromium seems to cache fonts based on a hash of the actual font data,
  18445. // so the font must be modified for each load test else it will appear to
  18446. // be loaded already.
  18447. // TODO: This could maybe be made faster by avoiding the btoa of the full
  18448. // font by splitting it in chunks before hand and padding the font id.
  18449. var data = this.loadTestFont;
  18450. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  18451. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  18452. loadTestFontId);
  18453. // CFF checksum is important for IE, adjusting it
  18454. var CFF_CHECKSUM_OFFSET = 16;
  18455. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  18456. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  18457. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  18458. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  18459. }
  18460. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  18461. checksum = (checksum - XXXX_VALUE +
  18462. int32(loadTestFontId + 'XXX', i)) | 0;
  18463. }
  18464. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  18465. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  18466. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  18467. url + '}';
  18468. this.insertRule(rule);
  18469. var names = [];
  18470. for (i = 0, ii = fonts.length; i < ii; i++) {
  18471. names.push(fonts[i].loadedName);
  18472. }
  18473. names.push(loadTestFontId);
  18474. var div = document.createElement('div');
  18475. div.setAttribute('style',
  18476. 'visibility: hidden;' +
  18477. 'width: 10px; height: 10px;' +
  18478. 'position: absolute; top: 0px; left: 0px;');
  18479. for (i = 0, ii = names.length; i < ii; ++i) {
  18480. var span = document.createElement('span');
  18481. span.textContent = 'Hi';
  18482. span.style.fontFamily = names[i];
  18483. div.appendChild(span);
  18484. }
  18485. document.body.appendChild(div);
  18486. isFontReady(loadTestFontId, function() {
  18487. document.body.removeChild(div);
  18488. request.complete();
  18489. });
  18490. /** Hack end */
  18491. }
  18492. };
  18493. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  18494. typeof document !== 'undefined' && !!document.fonts);
  18495. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  18496. get: function () {
  18497. var supported = false;
  18498. // User agent string sniffing is bad, but there is no reliable way to tell
  18499. // if font is fully loaded and ready to be used with canvas.
  18500. var userAgent = window.navigator.userAgent;
  18501. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  18502. if (m && m[1] >= 14) {
  18503. supported = true;
  18504. }
  18505. // TODO other browsers
  18506. if (userAgent === 'node') {
  18507. supported = true;
  18508. }
  18509. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  18510. },
  18511. enumerable: true,
  18512. configurable: true
  18513. });
  18514. var FontFaceObject = (function FontFaceObjectClosure() {
  18515. function FontFaceObject(translatedData) {
  18516. this.compiledGlyphs = Object.create(null);
  18517. // importing translated data
  18518. for (var i in translatedData) {
  18519. this[i] = translatedData[i];
  18520. }
  18521. }
  18522. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  18523. get: function () {
  18524. var evalSupport = false;
  18525. if (PDFJS.isEvalSupported) {
  18526. try {
  18527. /* jshint evil: true */
  18528. new Function('');
  18529. evalSupport = true;
  18530. } catch (e) {}
  18531. }
  18532. return shadow(this, 'isEvalSupported', evalSupport);
  18533. },
  18534. enumerable: true,
  18535. configurable: true
  18536. });
  18537. FontFaceObject.prototype = {
  18538. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  18539. if (!this.data) {
  18540. return null;
  18541. }
  18542. if (PDFJS.disableFontFace) {
  18543. this.disableFontFace = true;
  18544. return null;
  18545. }
  18546. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  18547. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  18548. globalScope['FontInspector'].enabled) {
  18549. globalScope['FontInspector'].fontAdded(this);
  18550. }
  18551. return nativeFontFace;
  18552. },
  18553. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  18554. if (!this.data) {
  18555. return null;
  18556. }
  18557. if (PDFJS.disableFontFace) {
  18558. this.disableFontFace = true;
  18559. return null;
  18560. }
  18561. var data = bytesToString(new Uint8Array(this.data));
  18562. var fontName = this.loadedName;
  18563. // Add the font-face rule to the document
  18564. var url = ('url(data:' + this.mimetype + ';base64,' +
  18565. window.btoa(data) + ');');
  18566. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  18567. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  18568. globalScope['FontInspector'].enabled) {
  18569. globalScope['FontInspector'].fontAdded(this, url);
  18570. }
  18571. return rule;
  18572. },
  18573. getPathGenerator:
  18574. function FontFaceObject_getPathGenerator(objs, character) {
  18575. if (!(character in this.compiledGlyphs)) {
  18576. var cmds = objs.get(this.loadedName + '_path_' + character);
  18577. var current, i, len;
  18578. // If we can, compile cmds into JS for MAXIMUM SPEED
  18579. if (FontFaceObject.isEvalSupported) {
  18580. var args, js = '';
  18581. for (i = 0, len = cmds.length; i < len; i++) {
  18582. current = cmds[i];
  18583. if (current.args !== undefined) {
  18584. args = current.args.join(',');
  18585. } else {
  18586. args = '';
  18587. }
  18588. js += 'c.' + current.cmd + '(' + args + ');\n';
  18589. }
  18590. /* jshint -W054 */
  18591. this.compiledGlyphs[character] = new Function('c', 'size', js);
  18592. } else {
  18593. // But fall back on using Function.prototype.apply() if we're
  18594. // blocked from using eval() for whatever reason (like CSP policies)
  18595. this.compiledGlyphs[character] = function(c, size) {
  18596. for (i = 0, len = cmds.length; i < len; i++) {
  18597. current = cmds[i];
  18598. if (current.cmd === 'scale') {
  18599. current.args = [size, -size];
  18600. }
  18601. c[current.cmd].apply(c, current.args);
  18602. }
  18603. };
  18604. }
  18605. }
  18606. return this.compiledGlyphs[character];
  18607. }
  18608. };
  18609. return FontFaceObject;
  18610. })();
  18611. exports.FontFaceObject = FontFaceObject;
  18612. exports.FontLoader = FontLoader;
  18613. }));
  18614. (function (root, factory) {
  18615. {
  18616. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  18617. }
  18618. }(this, function (exports, sharedUtil) {
  18619. var error = sharedUtil.error;
  18620. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  18621. function fixMetadata(meta) {
  18622. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  18623. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  18624. function(code, d1, d2, d3) {
  18625. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  18626. });
  18627. var chars = '';
  18628. for (var i = 0; i < bytes.length; i += 2) {
  18629. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  18630. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  18631. code !== 38 && false ? String.fromCharCode(code) :
  18632. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  18633. }
  18634. return '>' + chars;
  18635. });
  18636. }
  18637. function Metadata(meta) {
  18638. if (typeof meta === 'string') {
  18639. // Ghostscript produces invalid metadata
  18640. meta = fixMetadata(meta);
  18641. var parser = new DOMParser();
  18642. meta = parser.parseFromString(meta, 'application/xml');
  18643. } else if (!(meta instanceof Document)) {
  18644. error('Metadata: Invalid metadata object');
  18645. }
  18646. this.metaDocument = meta;
  18647. this.metadata = Object.create(null);
  18648. this.parse();
  18649. }
  18650. Metadata.prototype = {
  18651. parse: function Metadata_parse() {
  18652. var doc = this.metaDocument;
  18653. var rdf = doc.documentElement;
  18654. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  18655. rdf = rdf.firstChild;
  18656. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  18657. rdf = rdf.nextSibling;
  18658. }
  18659. }
  18660. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  18661. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  18662. return;
  18663. }
  18664. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  18665. for (i = 0, length = children.length; i < length; i++) {
  18666. desc = children[i];
  18667. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  18668. continue;
  18669. }
  18670. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  18671. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  18672. entry = desc.childNodes[ii];
  18673. name = entry.nodeName.toLowerCase();
  18674. this.metadata[name] = entry.textContent.trim();
  18675. }
  18676. }
  18677. }
  18678. },
  18679. get: function Metadata_get(name) {
  18680. return this.metadata[name] || null;
  18681. },
  18682. has: function Metadata_has(name) {
  18683. return typeof this.metadata[name] !== 'undefined';
  18684. }
  18685. };
  18686. return Metadata;
  18687. })();
  18688. exports.Metadata = Metadata;
  18689. }));
  18690. (function (root, factory) {
  18691. {
  18692. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  18693. }
  18694. }(this, function (exports, sharedUtil) {
  18695. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  18696. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  18697. var ImageKind = sharedUtil.ImageKind;
  18698. var OPS = sharedUtil.OPS;
  18699. var Util = sharedUtil.Util;
  18700. var isNum = sharedUtil.isNum;
  18701. var isArray = sharedUtil.isArray;
  18702. var warn = sharedUtil.warn;
  18703. var SVG_DEFAULTS = {
  18704. fontStyle: 'normal',
  18705. fontWeight: 'normal',
  18706. fillColor: '#000000'
  18707. };
  18708. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  18709. var PNG_HEADER =
  18710. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  18711. var CHUNK_WRAPPER_SIZE = 12;
  18712. var crcTable = new Int32Array(256);
  18713. for (var i = 0; i < 256; i++) {
  18714. var c = i;
  18715. for (var h = 0; h < 8; h++) {
  18716. if (c & 1) {
  18717. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  18718. } else {
  18719. c = (c >> 1) & 0x7fffffff;
  18720. }
  18721. }
  18722. crcTable[i] = c;
  18723. }
  18724. function crc32(data, start, end) {
  18725. var crc = -1;
  18726. for (var i = start; i < end; i++) {
  18727. var a = (crc ^ data[i]) & 0xff;
  18728. var b = crcTable[a];
  18729. crc = (crc >>> 8) ^ b;
  18730. }
  18731. return crc ^ -1;
  18732. }
  18733. function writePngChunk(type, body, data, offset) {
  18734. var p = offset;
  18735. var len = body.length;
  18736. data[p] = len >> 24 & 0xff;
  18737. data[p + 1] = len >> 16 & 0xff;
  18738. data[p + 2] = len >> 8 & 0xff;
  18739. data[p + 3] = len & 0xff;
  18740. p += 4;
  18741. data[p] = type.charCodeAt(0) & 0xff;
  18742. data[p + 1] = type.charCodeAt(1) & 0xff;
  18743. data[p + 2] = type.charCodeAt(2) & 0xff;
  18744. data[p + 3] = type.charCodeAt(3) & 0xff;
  18745. p += 4;
  18746. data.set(body, p);
  18747. p += body.length;
  18748. var crc = crc32(data, offset + 4, p);
  18749. data[p] = crc >> 24 & 0xff;
  18750. data[p + 1] = crc >> 16 & 0xff;
  18751. data[p + 2] = crc >> 8 & 0xff;
  18752. data[p + 3] = crc & 0xff;
  18753. }
  18754. function adler32(data, start, end) {
  18755. var a = 1;
  18756. var b = 0;
  18757. for (var i = start; i < end; ++i) {
  18758. a = (a + (data[i] & 0xff)) % 65521;
  18759. b = (b + a) % 65521;
  18760. }
  18761. return (b << 16) | a;
  18762. }
  18763. function encode(imgData, kind) {
  18764. var width = imgData.width;
  18765. var height = imgData.height;
  18766. var bitDepth, colorType, lineSize;
  18767. var bytes = imgData.data;
  18768. switch (kind) {
  18769. case ImageKind.GRAYSCALE_1BPP:
  18770. colorType = 0;
  18771. bitDepth = 1;
  18772. lineSize = (width + 7) >> 3;
  18773. break;
  18774. case ImageKind.RGB_24BPP:
  18775. colorType = 2;
  18776. bitDepth = 8;
  18777. lineSize = width * 3;
  18778. break;
  18779. case ImageKind.RGBA_32BPP:
  18780. colorType = 6;
  18781. bitDepth = 8;
  18782. lineSize = width * 4;
  18783. break;
  18784. default:
  18785. throw new Error('invalid format');
  18786. }
  18787. // prefix every row with predictor 0
  18788. var literals = new Uint8Array((1 + lineSize) * height);
  18789. var offsetLiterals = 0, offsetBytes = 0;
  18790. var y, i;
  18791. for (y = 0; y < height; ++y) {
  18792. literals[offsetLiterals++] = 0; // no prediction
  18793. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  18794. offsetLiterals);
  18795. offsetBytes += lineSize;
  18796. offsetLiterals += lineSize;
  18797. }
  18798. if (kind === ImageKind.GRAYSCALE_1BPP) {
  18799. // inverting for B/W
  18800. offsetLiterals = 0;
  18801. for (y = 0; y < height; y++) {
  18802. offsetLiterals++; // skipping predictor
  18803. for (i = 0; i < lineSize; i++) {
  18804. literals[offsetLiterals++] ^= 0xFF;
  18805. }
  18806. }
  18807. }
  18808. var ihdr = new Uint8Array([
  18809. width >> 24 & 0xff,
  18810. width >> 16 & 0xff,
  18811. width >> 8 & 0xff,
  18812. width & 0xff,
  18813. height >> 24 & 0xff,
  18814. height >> 16 & 0xff,
  18815. height >> 8 & 0xff,
  18816. height & 0xff,
  18817. bitDepth, // bit depth
  18818. colorType, // color type
  18819. 0x00, // compression method
  18820. 0x00, // filter method
  18821. 0x00 // interlace method
  18822. ]);
  18823. var len = literals.length;
  18824. var maxBlockLength = 0xFFFF;
  18825. var deflateBlocks = Math.ceil(len / maxBlockLength);
  18826. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  18827. var pi = 0;
  18828. idat[pi++] = 0x78; // compression method and flags
  18829. idat[pi++] = 0x9c; // flags
  18830. var pos = 0;
  18831. while (len > maxBlockLength) {
  18832. // writing non-final DEFLATE blocks type 0 and length of 65535
  18833. idat[pi++] = 0x00;
  18834. idat[pi++] = 0xff;
  18835. idat[pi++] = 0xff;
  18836. idat[pi++] = 0x00;
  18837. idat[pi++] = 0x00;
  18838. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  18839. pi += maxBlockLength;
  18840. pos += maxBlockLength;
  18841. len -= maxBlockLength;
  18842. }
  18843. // writing non-final DEFLATE blocks type 0
  18844. idat[pi++] = 0x01;
  18845. idat[pi++] = len & 0xff;
  18846. idat[pi++] = len >> 8 & 0xff;
  18847. idat[pi++] = (~len & 0xffff) & 0xff;
  18848. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  18849. idat.set(literals.subarray(pos), pi);
  18850. pi += literals.length - pos;
  18851. var adler = adler32(literals, 0, literals.length); // checksum
  18852. idat[pi++] = adler >> 24 & 0xff;
  18853. idat[pi++] = adler >> 16 & 0xff;
  18854. idat[pi++] = adler >> 8 & 0xff;
  18855. idat[pi++] = adler & 0xff;
  18856. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  18857. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  18858. ihdr.length + idat.length;
  18859. var data = new Uint8Array(pngLength);
  18860. var offset = 0;
  18861. data.set(PNG_HEADER, offset);
  18862. offset += PNG_HEADER.length;
  18863. writePngChunk('IHDR', ihdr, data, offset);
  18864. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  18865. writePngChunk('IDATA', idat, data, offset);
  18866. offset += CHUNK_WRAPPER_SIZE + idat.length;
  18867. writePngChunk('IEND', new Uint8Array(0), data, offset);
  18868. return PDFJS.createObjectURL(data, 'image/png');
  18869. }
  18870. return function convertImgDataToPng(imgData) {
  18871. var kind = (imgData.kind === undefined ?
  18872. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  18873. return encode(imgData, kind);
  18874. };
  18875. })();
  18876. var SVGExtraState = (function SVGExtraStateClosure() {
  18877. function SVGExtraState() {
  18878. this.fontSizeScale = 1;
  18879. this.fontWeight = SVG_DEFAULTS.fontWeight;
  18880. this.fontSize = 0;
  18881. this.textMatrix = IDENTITY_MATRIX;
  18882. this.fontMatrix = FONT_IDENTITY_MATRIX;
  18883. this.leading = 0;
  18884. // Current point (in user coordinates)
  18885. this.x = 0;
  18886. this.y = 0;
  18887. // Start of text line (in text coordinates)
  18888. this.lineX = 0;
  18889. this.lineY = 0;
  18890. // Character and word spacing
  18891. this.charSpacing = 0;
  18892. this.wordSpacing = 0;
  18893. this.textHScale = 1;
  18894. this.textRise = 0;
  18895. // Default foreground and background colors
  18896. this.fillColor = SVG_DEFAULTS.fillColor;
  18897. this.strokeColor = '#000000';
  18898. this.fillAlpha = 1;
  18899. this.strokeAlpha = 1;
  18900. this.lineWidth = 1;
  18901. this.lineJoin = '';
  18902. this.lineCap = '';
  18903. this.miterLimit = 0;
  18904. this.dashArray = [];
  18905. this.dashPhase = 0;
  18906. this.dependencies = [];
  18907. // Clipping
  18908. this.clipId = '';
  18909. this.pendingClip = false;
  18910. this.maskId = '';
  18911. }
  18912. SVGExtraState.prototype = {
  18913. clone: function SVGExtraState_clone() {
  18914. return Object.create(this);
  18915. },
  18916. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  18917. this.x = x;
  18918. this.y = y;
  18919. }
  18920. };
  18921. return SVGExtraState;
  18922. })();
  18923. var SVGGraphics = (function SVGGraphicsClosure() {
  18924. function createScratchSVG(width, height) {
  18925. var NS = 'http://www.w3.org/2000/svg';
  18926. var svg = document.createElementNS(NS, 'svg:svg');
  18927. svg.setAttributeNS(null, 'version', '1.1');
  18928. svg.setAttributeNS(null, 'width', width + 'px');
  18929. svg.setAttributeNS(null, 'height', height + 'px');
  18930. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  18931. return svg;
  18932. }
  18933. function opListToTree(opList) {
  18934. var opTree = [];
  18935. var tmp = [];
  18936. var opListLen = opList.length;
  18937. for (var x = 0; x < opListLen; x++) {
  18938. if (opList[x].fn === 'save') {
  18939. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  18940. tmp.push(opTree);
  18941. opTree = opTree[opTree.length - 1].items;
  18942. continue;
  18943. }
  18944. if(opList[x].fn === 'restore') {
  18945. opTree = tmp.pop();
  18946. } else {
  18947. opTree.push(opList[x]);
  18948. }
  18949. }
  18950. return opTree;
  18951. }
  18952. /**
  18953. * Formats float number.
  18954. * @param value {number} number to format.
  18955. * @returns {string}
  18956. */
  18957. function pf(value) {
  18958. if (value === (value | 0)) { // integer number
  18959. return value.toString();
  18960. }
  18961. var s = value.toFixed(10);
  18962. var i = s.length - 1;
  18963. if (s[i] !== '0') {
  18964. return s;
  18965. }
  18966. // removing trailing zeros
  18967. do {
  18968. i--;
  18969. } while (s[i] === '0');
  18970. return s.substr(0, s[i] === '.' ? i : i + 1);
  18971. }
  18972. /**
  18973. * Formats transform matrix. The standard rotation, scale and translate
  18974. * matrices are replaced by their shorter forms, and for identity matrix
  18975. * returns empty string to save the memory.
  18976. * @param m {Array} matrix to format.
  18977. * @returns {string}
  18978. */
  18979. function pm(m) {
  18980. if (m[4] === 0 && m[5] === 0) {
  18981. if (m[1] === 0 && m[2] === 0) {
  18982. if (m[0] === 1 && m[3] === 1) {
  18983. return '';
  18984. }
  18985. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  18986. }
  18987. if (m[0] === m[3] && m[1] === -m[2]) {
  18988. var a = Math.acos(m[0]) * 180 / Math.PI;
  18989. return 'rotate(' + pf(a) + ')';
  18990. }
  18991. } else {
  18992. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  18993. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  18994. }
  18995. }
  18996. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  18997. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  18998. }
  18999. function SVGGraphics(commonObjs, objs) {
  19000. this.current = new SVGExtraState();
  19001. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  19002. this.transformStack = [];
  19003. this.extraStack = [];
  19004. this.commonObjs = commonObjs;
  19005. this.objs = objs;
  19006. this.pendingEOFill = false;
  19007. this.embedFonts = false;
  19008. this.embeddedFonts = Object.create(null);
  19009. this.cssStyle = null;
  19010. }
  19011. var NS = 'http://www.w3.org/2000/svg';
  19012. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  19013. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  19014. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  19015. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  19016. var clipCount = 0;
  19017. var maskCount = 0;
  19018. SVGGraphics.prototype = {
  19019. save: function SVGGraphics_save() {
  19020. this.transformStack.push(this.transformMatrix);
  19021. var old = this.current;
  19022. this.extraStack.push(old);
  19023. this.current = old.clone();
  19024. },
  19025. restore: function SVGGraphics_restore() {
  19026. this.transformMatrix = this.transformStack.pop();
  19027. this.current = this.extraStack.pop();
  19028. this.tgrp = document.createElementNS(NS, 'svg:g');
  19029. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19030. this.pgrp.appendChild(this.tgrp);
  19031. },
  19032. group: function SVGGraphics_group(items) {
  19033. this.save();
  19034. this.executeOpTree(items);
  19035. this.restore();
  19036. },
  19037. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  19038. var fnArray = operatorList.fnArray;
  19039. var fnArrayLen = fnArray.length;
  19040. var argsArray = operatorList.argsArray;
  19041. var self = this;
  19042. for (var i = 0; i < fnArrayLen; i++) {
  19043. if (OPS.dependency === fnArray[i]) {
  19044. var deps = argsArray[i];
  19045. for (var n = 0, nn = deps.length; n < nn; n++) {
  19046. var obj = deps[n];
  19047. var common = obj.substring(0, 2) === 'g_';
  19048. var promise;
  19049. if (common) {
  19050. promise = new Promise(function(resolve) {
  19051. self.commonObjs.get(obj, resolve);
  19052. });
  19053. } else {
  19054. promise = new Promise(function(resolve) {
  19055. self.objs.get(obj, resolve);
  19056. });
  19057. }
  19058. this.current.dependencies.push(promise);
  19059. }
  19060. }
  19061. }
  19062. return Promise.all(this.current.dependencies);
  19063. },
  19064. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19065. var transformMatrix = [a, b, c, d, e, f];
  19066. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  19067. transformMatrix);
  19068. this.tgrp = document.createElementNS(NS, 'svg:g');
  19069. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19070. },
  19071. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19072. this.svg = createScratchSVG(viewport.width, viewport.height);
  19073. this.viewport = viewport;
  19074. return this.loadDependencies(operatorList).then(function () {
  19075. this.transformMatrix = IDENTITY_MATRIX;
  19076. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19077. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19078. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19079. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19080. this.defs = document.createElementNS(NS, 'svg:defs');
  19081. this.pgrp.appendChild(this.defs);
  19082. this.pgrp.appendChild(this.tgrp);
  19083. this.svg.appendChild(this.pgrp);
  19084. var opTree = this.convertOpList(operatorList);
  19085. this.executeOpTree(opTree);
  19086. return this.svg;
  19087. }.bind(this));
  19088. },
  19089. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19090. var argsArray = operatorList.argsArray;
  19091. var fnArray = operatorList.fnArray;
  19092. var fnArrayLen = fnArray.length;
  19093. var REVOPS = [];
  19094. var opList = [];
  19095. for (var op in OPS) {
  19096. REVOPS[OPS[op]] = op;
  19097. }
  19098. for (var x = 0; x < fnArrayLen; x++) {
  19099. var fnId = fnArray[x];
  19100. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19101. }
  19102. return opListToTree(opList);
  19103. },
  19104. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19105. var opTreeLen = opTree.length;
  19106. for(var x = 0; x < opTreeLen; x++) {
  19107. var fn = opTree[x].fn;
  19108. var fnId = opTree[x].fnId;
  19109. var args = opTree[x].args;
  19110. switch (fnId | 0) {
  19111. case OPS.beginText:
  19112. this.beginText();
  19113. break;
  19114. case OPS.setLeading:
  19115. this.setLeading(args);
  19116. break;
  19117. case OPS.setLeadingMoveText:
  19118. this.setLeadingMoveText(args[0], args[1]);
  19119. break;
  19120. case OPS.setFont:
  19121. this.setFont(args);
  19122. break;
  19123. case OPS.showText:
  19124. this.showText(args[0]);
  19125. break;
  19126. case OPS.showSpacedText:
  19127. this.showText(args[0]);
  19128. break;
  19129. case OPS.endText:
  19130. this.endText();
  19131. break;
  19132. case OPS.moveText:
  19133. this.moveText(args[0], args[1]);
  19134. break;
  19135. case OPS.setCharSpacing:
  19136. this.setCharSpacing(args[0]);
  19137. break;
  19138. case OPS.setWordSpacing:
  19139. this.setWordSpacing(args[0]);
  19140. break;
  19141. case OPS.setHScale:
  19142. this.setHScale(args[0]);
  19143. break;
  19144. case OPS.setTextMatrix:
  19145. this.setTextMatrix(args[0], args[1], args[2],
  19146. args[3], args[4], args[5]);
  19147. break;
  19148. case OPS.setLineWidth:
  19149. this.setLineWidth(args[0]);
  19150. break;
  19151. case OPS.setLineJoin:
  19152. this.setLineJoin(args[0]);
  19153. break;
  19154. case OPS.setLineCap:
  19155. this.setLineCap(args[0]);
  19156. break;
  19157. case OPS.setMiterLimit:
  19158. this.setMiterLimit(args[0]);
  19159. break;
  19160. case OPS.setFillRGBColor:
  19161. this.setFillRGBColor(args[0], args[1], args[2]);
  19162. break;
  19163. case OPS.setStrokeRGBColor:
  19164. this.setStrokeRGBColor(args[0], args[1], args[2]);
  19165. break;
  19166. case OPS.setDash:
  19167. this.setDash(args[0], args[1]);
  19168. break;
  19169. case OPS.setGState:
  19170. this.setGState(args[0]);
  19171. break;
  19172. case OPS.fill:
  19173. this.fill();
  19174. break;
  19175. case OPS.eoFill:
  19176. this.eoFill();
  19177. break;
  19178. case OPS.stroke:
  19179. this.stroke();
  19180. break;
  19181. case OPS.fillStroke:
  19182. this.fillStroke();
  19183. break;
  19184. case OPS.eoFillStroke:
  19185. this.eoFillStroke();
  19186. break;
  19187. case OPS.clip:
  19188. this.clip('nonzero');
  19189. break;
  19190. case OPS.eoClip:
  19191. this.clip('evenodd');
  19192. break;
  19193. case OPS.paintSolidColorImageMask:
  19194. this.paintSolidColorImageMask();
  19195. break;
  19196. case OPS.paintJpegXObject:
  19197. this.paintJpegXObject(args[0], args[1], args[2]);
  19198. break;
  19199. case OPS.paintImageXObject:
  19200. this.paintImageXObject(args[0]);
  19201. break;
  19202. case OPS.paintInlineImageXObject:
  19203. this.paintInlineImageXObject(args[0]);
  19204. break;
  19205. case OPS.paintImageMaskXObject:
  19206. this.paintImageMaskXObject(args[0]);
  19207. break;
  19208. case OPS.paintFormXObjectBegin:
  19209. this.paintFormXObjectBegin(args[0], args[1]);
  19210. break;
  19211. case OPS.paintFormXObjectEnd:
  19212. this.paintFormXObjectEnd();
  19213. break;
  19214. case OPS.closePath:
  19215. this.closePath();
  19216. break;
  19217. case OPS.closeStroke:
  19218. this.closeStroke();
  19219. break;
  19220. case OPS.closeFillStroke:
  19221. this.closeFillStroke();
  19222. break;
  19223. case OPS.nextLine:
  19224. this.nextLine();
  19225. break;
  19226. case OPS.transform:
  19227. this.transform(args[0], args[1], args[2], args[3],
  19228. args[4], args[5]);
  19229. break;
  19230. case OPS.constructPath:
  19231. this.constructPath(args[0], args[1]);
  19232. break;
  19233. case OPS.endPath:
  19234. this.endPath();
  19235. break;
  19236. case 92:
  19237. this.group(opTree[x].items);
  19238. break;
  19239. default:
  19240. warn('Unimplemented method '+ fn);
  19241. break;
  19242. }
  19243. }
  19244. },
  19245. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  19246. this.current.wordSpacing = wordSpacing;
  19247. },
  19248. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  19249. this.current.charSpacing = charSpacing;
  19250. },
  19251. nextLine: function SVGGraphics_nextLine() {
  19252. this.moveText(0, this.current.leading);
  19253. },
  19254. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  19255. var current = this.current;
  19256. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  19257. this.current.x = this.current.lineX = 0;
  19258. this.current.y = this.current.lineY = 0;
  19259. current.xcoords = [];
  19260. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19261. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19262. current.tspan.setAttributeNS(null, 'font-size',
  19263. pf(current.fontSize) + 'px');
  19264. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19265. current.txtElement = document.createElementNS(NS, 'svg:text');
  19266. current.txtElement.appendChild(current.tspan);
  19267. },
  19268. beginText: function SVGGraphics_beginText() {
  19269. this.current.x = this.current.lineX = 0;
  19270. this.current.y = this.current.lineY = 0;
  19271. this.current.textMatrix = IDENTITY_MATRIX;
  19272. this.current.lineMatrix = IDENTITY_MATRIX;
  19273. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  19274. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  19275. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  19276. this.current.xcoords = [];
  19277. },
  19278. moveText: function SVGGraphics_moveText(x, y) {
  19279. var current = this.current;
  19280. this.current.x = this.current.lineX += x;
  19281. this.current.y = this.current.lineY += y;
  19282. current.xcoords = [];
  19283. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19284. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19285. current.tspan.setAttributeNS(null, 'font-size',
  19286. pf(current.fontSize) + 'px');
  19287. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19288. },
  19289. showText: function SVGGraphics_showText(glyphs) {
  19290. var current = this.current;
  19291. var font = current.font;
  19292. var fontSize = current.fontSize;
  19293. if (fontSize === 0) {
  19294. return;
  19295. }
  19296. var charSpacing = current.charSpacing;
  19297. var wordSpacing = current.wordSpacing;
  19298. var fontDirection = current.fontDirection;
  19299. var textHScale = current.textHScale * fontDirection;
  19300. var glyphsLength = glyphs.length;
  19301. var vertical = font.vertical;
  19302. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  19303. var x = 0, i;
  19304. for (i = 0; i < glyphsLength; ++i) {
  19305. var glyph = glyphs[i];
  19306. if (glyph === null) {
  19307. // word break
  19308. x += fontDirection * wordSpacing;
  19309. continue;
  19310. } else if (isNum(glyph)) {
  19311. x += -glyph * fontSize * 0.001;
  19312. continue;
  19313. }
  19314. current.xcoords.push(current.x + x * textHScale);
  19315. var width = glyph.width;
  19316. var character = glyph.fontChar;
  19317. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  19318. x += charWidth;
  19319. current.tspan.textContent += character;
  19320. }
  19321. if (vertical) {
  19322. current.y -= x * textHScale;
  19323. } else {
  19324. current.x += x * textHScale;
  19325. }
  19326. current.tspan.setAttributeNS(null, 'x',
  19327. current.xcoords.map(pf).join(' '));
  19328. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19329. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19330. current.tspan.setAttributeNS(null, 'font-size',
  19331. pf(current.fontSize) + 'px');
  19332. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  19333. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  19334. }
  19335. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  19336. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  19337. }
  19338. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  19339. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  19340. }
  19341. current.txtElement.setAttributeNS(null, 'transform',
  19342. pm(current.textMatrix) +
  19343. ' scale(1, -1)' );
  19344. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  19345. current.txtElement.appendChild(current.tspan);
  19346. current.txtgrp.appendChild(current.txtElement);
  19347. this.tgrp.appendChild(current.txtElement);
  19348. },
  19349. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  19350. this.setLeading(-y);
  19351. this.moveText(x, y);
  19352. },
  19353. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  19354. if (!this.cssStyle) {
  19355. this.cssStyle = document.createElementNS(NS, 'svg:style');
  19356. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  19357. this.defs.appendChild(this.cssStyle);
  19358. }
  19359. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  19360. this.cssStyle.textContent +=
  19361. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  19362. ' src: url(' + url + '); }\n';
  19363. },
  19364. setFont: function SVGGraphics_setFont(details) {
  19365. var current = this.current;
  19366. var fontObj = this.commonObjs.get(details[0]);
  19367. var size = details[1];
  19368. this.current.font = fontObj;
  19369. if (this.embedFonts && fontObj.data &&
  19370. !this.embeddedFonts[fontObj.loadedName]) {
  19371. this.addFontStyle(fontObj);
  19372. this.embeddedFonts[fontObj.loadedName] = fontObj;
  19373. }
  19374. current.fontMatrix = (fontObj.fontMatrix ?
  19375. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  19376. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  19377. (fontObj.bold ? 'bold' : 'normal');
  19378. var italic = fontObj.italic ? 'italic' : 'normal';
  19379. if (size < 0) {
  19380. size = -size;
  19381. current.fontDirection = -1;
  19382. } else {
  19383. current.fontDirection = 1;
  19384. }
  19385. current.fontSize = size;
  19386. current.fontFamily = fontObj.loadedName;
  19387. current.fontWeight = bold;
  19388. current.fontStyle = italic;
  19389. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19390. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19391. current.xcoords = [];
  19392. },
  19393. endText: function SVGGraphics_endText() {
  19394. if (this.current.pendingClip) {
  19395. this.cgrp.appendChild(this.tgrp);
  19396. this.pgrp.appendChild(this.cgrp);
  19397. } else {
  19398. this.pgrp.appendChild(this.tgrp);
  19399. }
  19400. this.tgrp = document.createElementNS(NS, 'svg:g');
  19401. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19402. },
  19403. // Path properties
  19404. setLineWidth: function SVGGraphics_setLineWidth(width) {
  19405. this.current.lineWidth = width;
  19406. },
  19407. setLineCap: function SVGGraphics_setLineCap(style) {
  19408. this.current.lineCap = LINE_CAP_STYLES[style];
  19409. },
  19410. setLineJoin: function SVGGraphics_setLineJoin(style) {
  19411. this.current.lineJoin = LINE_JOIN_STYLES[style];
  19412. },
  19413. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  19414. this.current.miterLimit = limit;
  19415. },
  19416. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  19417. var color = Util.makeCssRgb(r, g, b);
  19418. this.current.strokeColor = color;
  19419. },
  19420. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  19421. var color = Util.makeCssRgb(r, g, b);
  19422. this.current.fillColor = color;
  19423. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  19424. this.current.xcoords = [];
  19425. },
  19426. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  19427. this.current.dashArray = dashArray;
  19428. this.current.dashPhase = dashPhase;
  19429. },
  19430. constructPath: function SVGGraphics_constructPath(ops, args) {
  19431. var current = this.current;
  19432. var x = current.x, y = current.y;
  19433. current.path = document.createElementNS(NS, 'svg:path');
  19434. var d = [];
  19435. var opLength = ops.length;
  19436. for (var i = 0, j = 0; i < opLength; i++) {
  19437. switch (ops[i] | 0) {
  19438. case OPS.rectangle:
  19439. x = args[j++];
  19440. y = args[j++];
  19441. var width = args[j++];
  19442. var height = args[j++];
  19443. var xw = x + width;
  19444. var yh = y + height;
  19445. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  19446. 'L', pf(x), pf(yh), 'Z');
  19447. break;
  19448. case OPS.moveTo:
  19449. x = args[j++];
  19450. y = args[j++];
  19451. d.push('M', pf(x), pf(y));
  19452. break;
  19453. case OPS.lineTo:
  19454. x = args[j++];
  19455. y = args[j++];
  19456. d.push('L', pf(x) , pf(y));
  19457. break;
  19458. case OPS.curveTo:
  19459. x = args[j + 4];
  19460. y = args[j + 5];
  19461. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  19462. pf(args[j + 3]), pf(x), pf(y));
  19463. j += 6;
  19464. break;
  19465. case OPS.curveTo2:
  19466. x = args[j + 2];
  19467. y = args[j + 3];
  19468. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  19469. pf(args[j + 2]), pf(args[j + 3]));
  19470. j += 4;
  19471. break;
  19472. case OPS.curveTo3:
  19473. x = args[j + 2];
  19474. y = args[j + 3];
  19475. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  19476. pf(x), pf(y));
  19477. j += 4;
  19478. break;
  19479. case OPS.closePath:
  19480. d.push('Z');
  19481. break;
  19482. }
  19483. }
  19484. current.path.setAttributeNS(null, 'd', d.join(' '));
  19485. current.path.setAttributeNS(null, 'stroke-miterlimit',
  19486. pf(current.miterLimit));
  19487. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  19488. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  19489. current.path.setAttributeNS(null, 'stroke-width',
  19490. pf(current.lineWidth) + 'px');
  19491. current.path.setAttributeNS(null, 'stroke-dasharray',
  19492. current.dashArray.map(pf).join(' '));
  19493. current.path.setAttributeNS(null, 'stroke-dashoffset',
  19494. pf(current.dashPhase) + 'px');
  19495. current.path.setAttributeNS(null, 'fill', 'none');
  19496. this.tgrp.appendChild(current.path);
  19497. if (current.pendingClip) {
  19498. this.cgrp.appendChild(this.tgrp);
  19499. this.pgrp.appendChild(this.cgrp);
  19500. } else {
  19501. this.pgrp.appendChild(this.tgrp);
  19502. }
  19503. // Saving a reference in current.element so that it can be addressed
  19504. // in 'fill' and 'stroke'
  19505. current.element = current.path;
  19506. current.setCurrentPoint(x, y);
  19507. },
  19508. endPath: function SVGGraphics_endPath() {
  19509. var current = this.current;
  19510. if (current.pendingClip) {
  19511. this.cgrp.appendChild(this.tgrp);
  19512. this.pgrp.appendChild(this.cgrp);
  19513. } else {
  19514. this.pgrp.appendChild(this.tgrp);
  19515. }
  19516. this.tgrp = document.createElementNS(NS, 'svg:g');
  19517. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19518. },
  19519. clip: function SVGGraphics_clip(type) {
  19520. var current = this.current;
  19521. // Add current path to clipping path
  19522. current.clipId = 'clippath' + clipCount;
  19523. clipCount++;
  19524. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  19525. this.clippath.setAttributeNS(null, 'id', current.clipId);
  19526. var clipElement = current.element.cloneNode();
  19527. if (type === 'evenodd') {
  19528. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  19529. } else {
  19530. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  19531. }
  19532. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19533. this.clippath.appendChild(clipElement);
  19534. this.defs.appendChild(this.clippath);
  19535. // Create a new group with that attribute
  19536. current.pendingClip = true;
  19537. this.cgrp = document.createElementNS(NS, 'svg:g');
  19538. this.cgrp.setAttributeNS(null, 'clip-path',
  19539. 'url(#' + current.clipId + ')');
  19540. this.pgrp.appendChild(this.cgrp);
  19541. },
  19542. closePath: function SVGGraphics_closePath() {
  19543. var current = this.current;
  19544. var d = current.path.getAttributeNS(null, 'd');
  19545. d += 'Z';
  19546. current.path.setAttributeNS(null, 'd', d);
  19547. },
  19548. setLeading: function SVGGraphics_setLeading(leading) {
  19549. this.current.leading = -leading;
  19550. },
  19551. setTextRise: function SVGGraphics_setTextRise(textRise) {
  19552. this.current.textRise = textRise;
  19553. },
  19554. setHScale: function SVGGraphics_setHScale(scale) {
  19555. this.current.textHScale = scale / 100;
  19556. },
  19557. setGState: function SVGGraphics_setGState(states) {
  19558. for (var i = 0, ii = states.length; i < ii; i++) {
  19559. var state = states[i];
  19560. var key = state[0];
  19561. var value = state[1];
  19562. switch (key) {
  19563. case 'LW':
  19564. this.setLineWidth(value);
  19565. break;
  19566. case 'LC':
  19567. this.setLineCap(value);
  19568. break;
  19569. case 'LJ':
  19570. this.setLineJoin(value);
  19571. break;
  19572. case 'ML':
  19573. this.setMiterLimit(value);
  19574. break;
  19575. case 'D':
  19576. this.setDash(value[0], value[1]);
  19577. break;
  19578. case 'RI':
  19579. break;
  19580. case 'FL':
  19581. break;
  19582. case 'Font':
  19583. this.setFont(value);
  19584. break;
  19585. case 'CA':
  19586. break;
  19587. case 'ca':
  19588. break;
  19589. case 'BM':
  19590. break;
  19591. case 'SMask':
  19592. break;
  19593. }
  19594. }
  19595. },
  19596. fill: function SVGGraphics_fill() {
  19597. var current = this.current;
  19598. current.element.setAttributeNS(null, 'fill', current.fillColor);
  19599. },
  19600. stroke: function SVGGraphics_stroke() {
  19601. var current = this.current;
  19602. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  19603. current.element.setAttributeNS(null, 'fill', 'none');
  19604. },
  19605. eoFill: function SVGGraphics_eoFill() {
  19606. var current = this.current;
  19607. current.element.setAttributeNS(null, 'fill', current.fillColor);
  19608. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  19609. },
  19610. fillStroke: function SVGGraphics_fillStroke() {
  19611. // Order is important since stroke wants fill to be none.
  19612. // First stroke, then if fill needed, it will be overwritten.
  19613. this.stroke();
  19614. this.fill();
  19615. },
  19616. eoFillStroke: function SVGGraphics_eoFillStroke() {
  19617. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  19618. this.fillStroke();
  19619. },
  19620. closeStroke: function SVGGraphics_closeStroke() {
  19621. this.closePath();
  19622. this.stroke();
  19623. },
  19624. closeFillStroke: function SVGGraphics_closeFillStroke() {
  19625. this.closePath();
  19626. this.fillStroke();
  19627. },
  19628. paintSolidColorImageMask:
  19629. function SVGGraphics_paintSolidColorImageMask() {
  19630. var current = this.current;
  19631. var rect = document.createElementNS(NS, 'svg:rect');
  19632. rect.setAttributeNS(null, 'x', '0');
  19633. rect.setAttributeNS(null, 'y', '0');
  19634. rect.setAttributeNS(null, 'width', '1px');
  19635. rect.setAttributeNS(null, 'height', '1px');
  19636. rect.setAttributeNS(null, 'fill', current.fillColor);
  19637. this.tgrp.appendChild(rect);
  19638. },
  19639. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  19640. var current = this.current;
  19641. var imgObj = this.objs.get(objId);
  19642. var imgEl = document.createElementNS(NS, 'svg:image');
  19643. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  19644. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  19645. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  19646. imgEl.setAttributeNS(null, 'x', '0');
  19647. imgEl.setAttributeNS(null, 'y', pf(-h));
  19648. imgEl.setAttributeNS(null, 'transform',
  19649. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  19650. this.tgrp.appendChild(imgEl);
  19651. if (current.pendingClip) {
  19652. this.cgrp.appendChild(this.tgrp);
  19653. this.pgrp.appendChild(this.cgrp);
  19654. } else {
  19655. this.pgrp.appendChild(this.tgrp);
  19656. }
  19657. },
  19658. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  19659. var imgData = this.objs.get(objId);
  19660. if (!imgData) {
  19661. warn('Dependent image isn\'t ready yet');
  19662. return;
  19663. }
  19664. this.paintInlineImageXObject(imgData);
  19665. },
  19666. paintInlineImageXObject:
  19667. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  19668. var current = this.current;
  19669. var width = imgData.width;
  19670. var height = imgData.height;
  19671. var imgSrc = convertImgDataToPng(imgData);
  19672. var cliprect = document.createElementNS(NS, 'svg:rect');
  19673. cliprect.setAttributeNS(null, 'x', '0');
  19674. cliprect.setAttributeNS(null, 'y', '0');
  19675. cliprect.setAttributeNS(null, 'width', pf(width));
  19676. cliprect.setAttributeNS(null, 'height', pf(height));
  19677. current.element = cliprect;
  19678. this.clip('nonzero');
  19679. var imgEl = document.createElementNS(NS, 'svg:image');
  19680. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  19681. imgEl.setAttributeNS(null, 'x', '0');
  19682. imgEl.setAttributeNS(null, 'y', pf(-height));
  19683. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  19684. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  19685. imgEl.setAttributeNS(null, 'transform',
  19686. 'scale(' + pf(1 / width) + ' ' +
  19687. pf(-1 / height) + ')');
  19688. if (mask) {
  19689. mask.appendChild(imgEl);
  19690. } else {
  19691. this.tgrp.appendChild(imgEl);
  19692. }
  19693. if (current.pendingClip) {
  19694. this.cgrp.appendChild(this.tgrp);
  19695. this.pgrp.appendChild(this.cgrp);
  19696. } else {
  19697. this.pgrp.appendChild(this.tgrp);
  19698. }
  19699. },
  19700. paintImageMaskXObject:
  19701. function SVGGraphics_paintImageMaskXObject(imgData) {
  19702. var current = this.current;
  19703. var width = imgData.width;
  19704. var height = imgData.height;
  19705. var fillColor = current.fillColor;
  19706. current.maskId = 'mask' + maskCount++;
  19707. var mask = document.createElementNS(NS, 'svg:mask');
  19708. mask.setAttributeNS(null, 'id', current.maskId);
  19709. var rect = document.createElementNS(NS, 'svg:rect');
  19710. rect.setAttributeNS(null, 'x', '0');
  19711. rect.setAttributeNS(null, 'y', '0');
  19712. rect.setAttributeNS(null, 'width', pf(width));
  19713. rect.setAttributeNS(null, 'height', pf(height));
  19714. rect.setAttributeNS(null, 'fill', fillColor);
  19715. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  19716. this.defs.appendChild(mask);
  19717. this.tgrp.appendChild(rect);
  19718. this.paintInlineImageXObject(imgData, mask);
  19719. },
  19720. paintFormXObjectBegin:
  19721. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  19722. this.save();
  19723. if (isArray(matrix) && matrix.length === 6) {
  19724. this.transform(matrix[0], matrix[1], matrix[2],
  19725. matrix[3], matrix[4], matrix[5]);
  19726. }
  19727. if (isArray(bbox) && bbox.length === 4) {
  19728. var width = bbox[2] - bbox[0];
  19729. var height = bbox[3] - bbox[1];
  19730. var cliprect = document.createElementNS(NS, 'svg:rect');
  19731. cliprect.setAttributeNS(null, 'x', bbox[0]);
  19732. cliprect.setAttributeNS(null, 'y', bbox[1]);
  19733. cliprect.setAttributeNS(null, 'width', pf(width));
  19734. cliprect.setAttributeNS(null, 'height', pf(height));
  19735. this.current.element = cliprect;
  19736. this.clip('nonzero');
  19737. this.endPath();
  19738. }
  19739. },
  19740. paintFormXObjectEnd:
  19741. function SVGGraphics_paintFormXObjectEnd() {
  19742. this.restore();
  19743. }
  19744. };
  19745. return SVGGraphics;
  19746. })();
  19747. PDFJS.SVGGraphics = SVGGraphics;
  19748. exports.SVGGraphics = SVGGraphics;
  19749. }));
  19750. (function (root, factory) {
  19751. {
  19752. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  19753. root.pdfjsDisplayDOMUtils, root.pdfjsSharedGlobal);
  19754. }
  19755. }(this, function (exports, sharedUtil, displayDOMUtils, sharedGlobal) {
  19756. var Util = sharedUtil.Util;
  19757. var createPromiseCapability = sharedUtil.createPromiseCapability;
  19758. var CustomStyle = displayDOMUtils.CustomStyle;
  19759. var PDFJS = sharedGlobal.PDFJS;
  19760. /**
  19761. * Text layer render parameters.
  19762. *
  19763. * @typedef {Object} TextLayerRenderParameters
  19764. * @property {TextContent} textContent - Text content to render (the object is
  19765. * returned by the page's getTextContent() method).
  19766. * @property {HTMLElement} container - HTML element that will contain text runs.
  19767. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  19768. * layout the text runs.
  19769. * @property {Array} textDivs - (optional) HTML elements that are correspond
  19770. * the text items of the textContent input. This is output and shall be
  19771. * initially be set to empty array.
  19772. * @property {number} timeout - (optional) Delay in milliseconds before
  19773. * rendering of the text runs occurs.
  19774. */
  19775. var renderTextLayer = (function renderTextLayerClosure() {
  19776. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  19777. var NonWhitespaceRegexp = /\S/;
  19778. function isAllWhitespace(str) {
  19779. return !NonWhitespaceRegexp.test(str);
  19780. }
  19781. function appendText(textDivs, viewport, geom, styles) {
  19782. var style = styles[geom.fontName];
  19783. var textDiv = document.createElement('div');
  19784. textDivs.push(textDiv);
  19785. if (isAllWhitespace(geom.str)) {
  19786. textDiv.dataset.isWhitespace = true;
  19787. return;
  19788. }
  19789. var tx = Util.transform(viewport.transform, geom.transform);
  19790. var angle = Math.atan2(tx[1], tx[0]);
  19791. if (style.vertical) {
  19792. angle += Math.PI / 2;
  19793. }
  19794. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  19795. var fontAscent = fontHeight;
  19796. if (style.ascent) {
  19797. fontAscent = style.ascent * fontAscent;
  19798. } else if (style.descent) {
  19799. fontAscent = (1 + style.descent) * fontAscent;
  19800. }
  19801. var left;
  19802. var top;
  19803. if (angle === 0) {
  19804. left = tx[4];
  19805. top = tx[5] - fontAscent;
  19806. } else {
  19807. left = tx[4] + (fontAscent * Math.sin(angle));
  19808. top = tx[5] - (fontAscent * Math.cos(angle));
  19809. }
  19810. textDiv.style.left = left + 'px';
  19811. textDiv.style.top = top + 'px';
  19812. textDiv.style.fontSize = fontHeight + 'px';
  19813. textDiv.style.fontFamily = style.fontFamily;
  19814. textDiv.textContent = geom.str;
  19815. // |fontName| is only used by the Font Inspector. This test will succeed
  19816. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  19817. // not worth the effort to do a more accurate test.
  19818. if (PDFJS.pdfBug) {
  19819. textDiv.dataset.fontName = geom.fontName;
  19820. }
  19821. // Storing into dataset will convert number into string.
  19822. if (angle !== 0) {
  19823. textDiv.dataset.angle = angle * (180 / Math.PI);
  19824. }
  19825. // We don't bother scaling single-char text divs, because it has very
  19826. // little effect on text highlighting. This makes scrolling on docs with
  19827. // lots of such divs a lot faster.
  19828. if (geom.str.length > 1) {
  19829. if (style.vertical) {
  19830. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  19831. } else {
  19832. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  19833. }
  19834. }
  19835. }
  19836. function render(task) {
  19837. if (task._canceled) {
  19838. return;
  19839. }
  19840. var textLayerFrag = task._container;
  19841. var textDivs = task._textDivs;
  19842. var capability = task._capability;
  19843. var textDivsLength = textDivs.length;
  19844. // No point in rendering many divs as it would make the browser
  19845. // unusable even after the divs are rendered.
  19846. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  19847. capability.resolve();
  19848. return;
  19849. }
  19850. var canvas = document.createElement('canvas');
  19851. var ctx = canvas.getContext('2d', {alpha: false});
  19852. var lastFontSize;
  19853. var lastFontFamily;
  19854. for (var i = 0; i < textDivsLength; i++) {
  19855. var textDiv = textDivs[i];
  19856. if (textDiv.dataset.isWhitespace !== undefined) {
  19857. continue;
  19858. }
  19859. var fontSize = textDiv.style.fontSize;
  19860. var fontFamily = textDiv.style.fontFamily;
  19861. // Only build font string and set to context if different from last.
  19862. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  19863. ctx.font = fontSize + ' ' + fontFamily;
  19864. lastFontSize = fontSize;
  19865. lastFontFamily = fontFamily;
  19866. }
  19867. var width = ctx.measureText(textDiv.textContent).width;
  19868. if (width > 0) {
  19869. textLayerFrag.appendChild(textDiv);
  19870. var transform;
  19871. if (textDiv.dataset.canvasWidth !== undefined) {
  19872. // Dataset values come of type string.
  19873. var textScale = textDiv.dataset.canvasWidth / width;
  19874. transform = 'scaleX(' + textScale + ')';
  19875. } else {
  19876. transform = '';
  19877. }
  19878. var rotation = textDiv.dataset.angle;
  19879. if (rotation) {
  19880. transform = 'rotate(' + rotation + 'deg) ' + transform;
  19881. }
  19882. if (transform) {
  19883. CustomStyle.setProp('transform' , textDiv, transform);
  19884. }
  19885. }
  19886. }
  19887. capability.resolve();
  19888. }
  19889. /**
  19890. * Text layer rendering task.
  19891. *
  19892. * @param {TextContent} textContent
  19893. * @param {HTMLElement} container
  19894. * @param {PDFJS.PageViewport} viewport
  19895. * @param {Array} textDivs
  19896. * @private
  19897. */
  19898. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  19899. this._textContent = textContent;
  19900. this._container = container;
  19901. this._viewport = viewport;
  19902. textDivs = textDivs || [];
  19903. this._textDivs = textDivs;
  19904. this._canceled = false;
  19905. this._capability = createPromiseCapability();
  19906. this._renderTimer = null;
  19907. }
  19908. TextLayerRenderTask.prototype = {
  19909. get promise() {
  19910. return this._capability.promise;
  19911. },
  19912. cancel: function TextLayer_cancel() {
  19913. this._canceled = true;
  19914. if (this._renderTimer !== null) {
  19915. clearTimeout(this._renderTimer);
  19916. this._renderTimer = null;
  19917. }
  19918. this._capability.reject('canceled');
  19919. },
  19920. _render: function TextLayer_render(timeout) {
  19921. var textItems = this._textContent.items;
  19922. var styles = this._textContent.styles;
  19923. var textDivs = this._textDivs;
  19924. var viewport = this._viewport;
  19925. for (var i = 0, len = textItems.length; i < len; i++) {
  19926. appendText(textDivs, viewport, textItems[i], styles);
  19927. }
  19928. if (!timeout) { // Render right away
  19929. render(this);
  19930. } else { // Schedule
  19931. var self = this;
  19932. this._renderTimer = setTimeout(function() {
  19933. render(self);
  19934. self._renderTimer = null;
  19935. }, timeout);
  19936. }
  19937. }
  19938. };
  19939. /**
  19940. * Starts rendering of the text layer.
  19941. *
  19942. * @param {TextLayerRenderParameters} renderParameters
  19943. * @returns {TextLayerRenderTask}
  19944. */
  19945. function renderTextLayer(renderParameters) {
  19946. var task = new TextLayerRenderTask(renderParameters.textContent,
  19947. renderParameters.container,
  19948. renderParameters.viewport,
  19949. renderParameters.textDivs);
  19950. task._render(renderParameters.timeout);
  19951. return task;
  19952. }
  19953. return renderTextLayer;
  19954. })();
  19955. PDFJS.renderTextLayer = renderTextLayer;
  19956. exports.renderTextLayer = renderTextLayer;
  19957. }));
  19958. (function (root, factory) {
  19959. {
  19960. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  19961. }
  19962. }(this, function (exports, sharedUtil) {
  19963. var shadow = sharedUtil.shadow;
  19964. var WebGLUtils = (function WebGLUtilsClosure() {
  19965. function loadShader(gl, code, shaderType) {
  19966. var shader = gl.createShader(shaderType);
  19967. gl.shaderSource(shader, code);
  19968. gl.compileShader(shader);
  19969. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  19970. if (!compiled) {
  19971. var errorMsg = gl.getShaderInfoLog(shader);
  19972. throw new Error('Error during shader compilation: ' + errorMsg);
  19973. }
  19974. return shader;
  19975. }
  19976. function createVertexShader(gl, code) {
  19977. return loadShader(gl, code, gl.VERTEX_SHADER);
  19978. }
  19979. function createFragmentShader(gl, code) {
  19980. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  19981. }
  19982. function createProgram(gl, shaders) {
  19983. var program = gl.createProgram();
  19984. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  19985. gl.attachShader(program, shaders[i]);
  19986. }
  19987. gl.linkProgram(program);
  19988. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  19989. if (!linked) {
  19990. var errorMsg = gl.getProgramInfoLog(program);
  19991. throw new Error('Error during program linking: ' + errorMsg);
  19992. }
  19993. return program;
  19994. }
  19995. function createTexture(gl, image, textureId) {
  19996. gl.activeTexture(textureId);
  19997. var texture = gl.createTexture();
  19998. gl.bindTexture(gl.TEXTURE_2D, texture);
  19999. // Set the parameters so we can render any size image.
  20000. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  20001. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  20002. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  20003. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  20004. // Upload the image into the texture.
  20005. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  20006. return texture;
  20007. }
  20008. var currentGL, currentCanvas;
  20009. function generateGL() {
  20010. if (currentGL) {
  20011. return;
  20012. }
  20013. currentCanvas = document.createElement('canvas');
  20014. currentGL = currentCanvas.getContext('webgl',
  20015. { premultipliedalpha: false });
  20016. }
  20017. var smaskVertexShaderCode = '\
  20018. attribute vec2 a_position; \
  20019. attribute vec2 a_texCoord; \
  20020. \
  20021. uniform vec2 u_resolution; \
  20022. \
  20023. varying vec2 v_texCoord; \
  20024. \
  20025. void main() { \
  20026. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  20027. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  20028. \
  20029. v_texCoord = a_texCoord; \
  20030. } ';
  20031. var smaskFragmentShaderCode = '\
  20032. precision mediump float; \
  20033. \
  20034. uniform vec4 u_backdrop; \
  20035. uniform int u_subtype; \
  20036. uniform sampler2D u_image; \
  20037. uniform sampler2D u_mask; \
  20038. \
  20039. varying vec2 v_texCoord; \
  20040. \
  20041. void main() { \
  20042. vec4 imageColor = texture2D(u_image, v_texCoord); \
  20043. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  20044. if (u_backdrop.a > 0.0) { \
  20045. maskColor.rgb = maskColor.rgb * maskColor.a + \
  20046. u_backdrop.rgb * (1.0 - maskColor.a); \
  20047. } \
  20048. float lum; \
  20049. if (u_subtype == 0) { \
  20050. lum = maskColor.a; \
  20051. } else { \
  20052. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  20053. maskColor.b * 0.11; \
  20054. } \
  20055. imageColor.a *= lum; \
  20056. imageColor.rgb *= imageColor.a; \
  20057. gl_FragColor = imageColor; \
  20058. } ';
  20059. var smaskCache = null;
  20060. function initSmaskGL() {
  20061. var canvas, gl;
  20062. generateGL();
  20063. canvas = currentCanvas;
  20064. currentCanvas = null;
  20065. gl = currentGL;
  20066. currentGL = null;
  20067. // setup a GLSL program
  20068. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  20069. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  20070. var program = createProgram(gl, [vertexShader, fragmentShader]);
  20071. gl.useProgram(program);
  20072. var cache = {};
  20073. cache.gl = gl;
  20074. cache.canvas = canvas;
  20075. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  20076. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  20077. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  20078. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  20079. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  20080. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  20081. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  20082. // provide texture coordinates for the rectangle.
  20083. var texCoordBuffer = gl.createBuffer();
  20084. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  20085. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  20086. 0.0, 0.0,
  20087. 1.0, 0.0,
  20088. 0.0, 1.0,
  20089. 0.0, 1.0,
  20090. 1.0, 0.0,
  20091. 1.0, 1.0]), gl.STATIC_DRAW);
  20092. gl.enableVertexAttribArray(texCoordLocation);
  20093. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  20094. gl.uniform1i(texLayerLocation, 0);
  20095. gl.uniform1i(texMaskLocation, 1);
  20096. smaskCache = cache;
  20097. }
  20098. function composeSMask(layer, mask, properties) {
  20099. var width = layer.width, height = layer.height;
  20100. if (!smaskCache) {
  20101. initSmaskGL();
  20102. }
  20103. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  20104. canvas.width = width;
  20105. canvas.height = height;
  20106. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  20107. gl.uniform2f(cache.resolutionLocation, width, height);
  20108. if (properties.backdrop) {
  20109. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  20110. properties.backdrop[1], properties.backdrop[2], 1);
  20111. } else {
  20112. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  20113. }
  20114. gl.uniform1i(cache.subtypeLocation,
  20115. properties.subtype === 'Luminosity' ? 1 : 0);
  20116. // Create a textures
  20117. var texture = createTexture(gl, layer, gl.TEXTURE0);
  20118. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  20119. // Create a buffer and put a single clipspace rectangle in
  20120. // it (2 triangles)
  20121. var buffer = gl.createBuffer();
  20122. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  20123. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  20124. 0, 0,
  20125. width, 0,
  20126. 0, height,
  20127. 0, height,
  20128. width, 0,
  20129. width, height]), gl.STATIC_DRAW);
  20130. gl.enableVertexAttribArray(cache.positionLocation);
  20131. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  20132. // draw
  20133. gl.clearColor(0, 0, 0, 0);
  20134. gl.enable(gl.BLEND);
  20135. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  20136. gl.clear(gl.COLOR_BUFFER_BIT);
  20137. gl.drawArrays(gl.TRIANGLES, 0, 6);
  20138. gl.flush();
  20139. gl.deleteTexture(texture);
  20140. gl.deleteTexture(maskTexture);
  20141. gl.deleteBuffer(buffer);
  20142. return canvas;
  20143. }
  20144. var figuresVertexShaderCode = '\
  20145. attribute vec2 a_position; \
  20146. attribute vec3 a_color; \
  20147. \
  20148. uniform vec2 u_resolution; \
  20149. uniform vec2 u_scale; \
  20150. uniform vec2 u_offset; \
  20151. \
  20152. varying vec4 v_color; \
  20153. \
  20154. void main() { \
  20155. vec2 position = (a_position + u_offset) * u_scale; \
  20156. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  20157. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  20158. \
  20159. v_color = vec4(a_color / 255.0, 1.0); \
  20160. } ';
  20161. var figuresFragmentShaderCode = '\
  20162. precision mediump float; \
  20163. \
  20164. varying vec4 v_color; \
  20165. \
  20166. void main() { \
  20167. gl_FragColor = v_color; \
  20168. } ';
  20169. var figuresCache = null;
  20170. function initFiguresGL() {
  20171. var canvas, gl;
  20172. generateGL();
  20173. canvas = currentCanvas;
  20174. currentCanvas = null;
  20175. gl = currentGL;
  20176. currentGL = null;
  20177. // setup a GLSL program
  20178. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  20179. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  20180. var program = createProgram(gl, [vertexShader, fragmentShader]);
  20181. gl.useProgram(program);
  20182. var cache = {};
  20183. cache.gl = gl;
  20184. cache.canvas = canvas;
  20185. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  20186. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  20187. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  20188. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  20189. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  20190. figuresCache = cache;
  20191. }
  20192. function drawFigures(width, height, backgroundColor, figures, context) {
  20193. if (!figuresCache) {
  20194. initFiguresGL();
  20195. }
  20196. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  20197. canvas.width = width;
  20198. canvas.height = height;
  20199. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  20200. gl.uniform2f(cache.resolutionLocation, width, height);
  20201. // count triangle points
  20202. var count = 0;
  20203. var i, ii, rows;
  20204. for (i = 0, ii = figures.length; i < ii; i++) {
  20205. switch (figures[i].type) {
  20206. case 'lattice':
  20207. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  20208. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  20209. break;
  20210. case 'triangles':
  20211. count += figures[i].coords.length;
  20212. break;
  20213. }
  20214. }
  20215. // transfer data
  20216. var coords = new Float32Array(count * 2);
  20217. var colors = new Uint8Array(count * 3);
  20218. var coordsMap = context.coords, colorsMap = context.colors;
  20219. var pIndex = 0, cIndex = 0;
  20220. for (i = 0, ii = figures.length; i < ii; i++) {
  20221. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  20222. switch (figure.type) {
  20223. case 'lattice':
  20224. var cols = figure.verticesPerRow;
  20225. rows = (ps.length / cols) | 0;
  20226. for (var row = 1; row < rows; row++) {
  20227. var offset = row * cols + 1;
  20228. for (var col = 1; col < cols; col++, offset++) {
  20229. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  20230. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  20231. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  20232. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  20233. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  20234. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  20235. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  20236. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  20237. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  20238. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  20239. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  20240. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  20241. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  20242. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  20243. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  20244. coords[pIndex + 6] = coords[pIndex + 2];
  20245. coords[pIndex + 7] = coords[pIndex + 3];
  20246. coords[pIndex + 8] = coords[pIndex + 4];
  20247. coords[pIndex + 9] = coords[pIndex + 5];
  20248. coords[pIndex + 10] = coordsMap[ps[offset]];
  20249. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  20250. colors[cIndex + 9] = colors[cIndex + 3];
  20251. colors[cIndex + 10] = colors[cIndex + 4];
  20252. colors[cIndex + 11] = colors[cIndex + 5];
  20253. colors[cIndex + 12] = colors[cIndex + 6];
  20254. colors[cIndex + 13] = colors[cIndex + 7];
  20255. colors[cIndex + 14] = colors[cIndex + 8];
  20256. colors[cIndex + 15] = colorsMap[cs[offset]];
  20257. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  20258. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  20259. pIndex += 12;
  20260. cIndex += 18;
  20261. }
  20262. }
  20263. break;
  20264. case 'triangles':
  20265. for (var j = 0, jj = ps.length; j < jj; j++) {
  20266. coords[pIndex] = coordsMap[ps[j]];
  20267. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  20268. colors[cIndex] = colorsMap[cs[j]];
  20269. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  20270. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  20271. pIndex += 2;
  20272. cIndex += 3;
  20273. }
  20274. break;
  20275. }
  20276. }
  20277. // draw
  20278. if (backgroundColor) {
  20279. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  20280. backgroundColor[2] / 255, 1.0);
  20281. } else {
  20282. gl.clearColor(0, 0, 0, 0);
  20283. }
  20284. gl.clear(gl.COLOR_BUFFER_BIT);
  20285. var coordsBuffer = gl.createBuffer();
  20286. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  20287. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  20288. gl.enableVertexAttribArray(cache.positionLocation);
  20289. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  20290. var colorsBuffer = gl.createBuffer();
  20291. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  20292. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  20293. gl.enableVertexAttribArray(cache.colorLocation);
  20294. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  20295. 0, 0);
  20296. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  20297. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  20298. gl.drawArrays(gl.TRIANGLES, 0, count);
  20299. gl.flush();
  20300. gl.deleteBuffer(coordsBuffer);
  20301. gl.deleteBuffer(colorsBuffer);
  20302. return canvas;
  20303. }
  20304. function cleanup() {
  20305. if (smaskCache && smaskCache.canvas) {
  20306. smaskCache.canvas.width = 0;
  20307. smaskCache.canvas.height = 0;
  20308. }
  20309. if (figuresCache && figuresCache.canvas) {
  20310. figuresCache.canvas.width = 0;
  20311. figuresCache.canvas.height = 0;
  20312. }
  20313. smaskCache = null;
  20314. figuresCache = null;
  20315. }
  20316. return {
  20317. get isEnabled() {
  20318. if (PDFJS.disableWebGL) {
  20319. return false;
  20320. }
  20321. var enabled = false;
  20322. try {
  20323. generateGL();
  20324. enabled = !!currentGL;
  20325. } catch (e) { }
  20326. return shadow(this, 'isEnabled', enabled);
  20327. },
  20328. composeSMask: composeSMask,
  20329. drawFigures: drawFigures,
  20330. clear: cleanup
  20331. };
  20332. })();
  20333. exports.WebGLUtils = WebGLUtils;
  20334. }));
  20335. (function (root, factory) {
  20336. {
  20337. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20338. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20339. root.pdfjsCoreJpx);
  20340. }
  20341. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20342. coreJpx) {
  20343. var Util = sharedUtil.Util;
  20344. var error = sharedUtil.error;
  20345. var info = sharedUtil.info;
  20346. var isArray = sharedUtil.isArray;
  20347. var shadow = sharedUtil.shadow;
  20348. var warn = sharedUtil.warn;
  20349. var Dict = corePrimitives.Dict;
  20350. var Jbig2Image = coreJbig2.Jbig2Image;
  20351. var JpegImage = coreJpg.JpegImage;
  20352. var JpxImage = coreJpx.JpxImage;
  20353. var coreParser; // see _setCoreParser below
  20354. var EOF; // = coreParser.EOF;
  20355. var Lexer; // = coreParser.Lexer;
  20356. var coreColorSpace; // see _setCoreColorSpace below
  20357. var ColorSpace; // = coreColorSpace.ColorSpace;
  20358. var Stream = (function StreamClosure() {
  20359. function Stream(arrayBuffer, start, length, dict) {
  20360. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20361. arrayBuffer : new Uint8Array(arrayBuffer));
  20362. this.start = start || 0;
  20363. this.pos = this.start;
  20364. this.end = (start + length) || this.bytes.length;
  20365. this.dict = dict;
  20366. }
  20367. // required methods for a stream. if a particular stream does not
  20368. // implement these, an error should be thrown
  20369. Stream.prototype = {
  20370. get length() {
  20371. return this.end - this.start;
  20372. },
  20373. get isEmpty() {
  20374. return this.length === 0;
  20375. },
  20376. getByte: function Stream_getByte() {
  20377. if (this.pos >= this.end) {
  20378. return -1;
  20379. }
  20380. return this.bytes[this.pos++];
  20381. },
  20382. getUint16: function Stream_getUint16() {
  20383. var b0 = this.getByte();
  20384. var b1 = this.getByte();
  20385. if (b0 === -1 || b1 === -1) {
  20386. return -1;
  20387. }
  20388. return (b0 << 8) + b1;
  20389. },
  20390. getInt32: function Stream_getInt32() {
  20391. var b0 = this.getByte();
  20392. var b1 = this.getByte();
  20393. var b2 = this.getByte();
  20394. var b3 = this.getByte();
  20395. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20396. },
  20397. // returns subarray of original buffer
  20398. // should only be read
  20399. getBytes: function Stream_getBytes(length) {
  20400. var bytes = this.bytes;
  20401. var pos = this.pos;
  20402. var strEnd = this.end;
  20403. if (!length) {
  20404. return bytes.subarray(pos, strEnd);
  20405. }
  20406. var end = pos + length;
  20407. if (end > strEnd) {
  20408. end = strEnd;
  20409. }
  20410. this.pos = end;
  20411. return bytes.subarray(pos, end);
  20412. },
  20413. peekByte: function Stream_peekByte() {
  20414. var peekedByte = this.getByte();
  20415. this.pos--;
  20416. return peekedByte;
  20417. },
  20418. peekBytes: function Stream_peekBytes(length) {
  20419. var bytes = this.getBytes(length);
  20420. this.pos -= bytes.length;
  20421. return bytes;
  20422. },
  20423. skip: function Stream_skip(n) {
  20424. if (!n) {
  20425. n = 1;
  20426. }
  20427. this.pos += n;
  20428. },
  20429. reset: function Stream_reset() {
  20430. this.pos = this.start;
  20431. },
  20432. moveStart: function Stream_moveStart() {
  20433. this.start = this.pos;
  20434. },
  20435. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20436. return new Stream(this.bytes.buffer, start, length, dict);
  20437. },
  20438. isStream: true
  20439. };
  20440. return Stream;
  20441. })();
  20442. var StringStream = (function StringStreamClosure() {
  20443. function StringStream(str) {
  20444. var length = str.length;
  20445. var bytes = new Uint8Array(length);
  20446. for (var n = 0; n < length; ++n) {
  20447. bytes[n] = str.charCodeAt(n);
  20448. }
  20449. Stream.call(this, bytes);
  20450. }
  20451. StringStream.prototype = Stream.prototype;
  20452. return StringStream;
  20453. })();
  20454. // super class for the decoding streams
  20455. var DecodeStream = (function DecodeStreamClosure() {
  20456. // Lots of DecodeStreams are created whose buffers are never used. For these
  20457. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20458. // having special cases that would be required if we used |null| for an empty
  20459. // buffer.
  20460. var emptyBuffer = new Uint8Array(0);
  20461. function DecodeStream(maybeMinBufferLength) {
  20462. this.pos = 0;
  20463. this.bufferLength = 0;
  20464. this.eof = false;
  20465. this.buffer = emptyBuffer;
  20466. this.minBufferLength = 512;
  20467. if (maybeMinBufferLength) {
  20468. // Compute the first power of two that is as big as maybeMinBufferLength.
  20469. while (this.minBufferLength < maybeMinBufferLength) {
  20470. this.minBufferLength *= 2;
  20471. }
  20472. }
  20473. }
  20474. DecodeStream.prototype = {
  20475. get isEmpty() {
  20476. while (!this.eof && this.bufferLength === 0) {
  20477. this.readBlock();
  20478. }
  20479. return this.bufferLength === 0;
  20480. },
  20481. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20482. var buffer = this.buffer;
  20483. if (requested <= buffer.byteLength) {
  20484. return buffer;
  20485. }
  20486. var size = this.minBufferLength;
  20487. while (size < requested) {
  20488. size *= 2;
  20489. }
  20490. var buffer2 = new Uint8Array(size);
  20491. buffer2.set(buffer);
  20492. return (this.buffer = buffer2);
  20493. },
  20494. getByte: function DecodeStream_getByte() {
  20495. var pos = this.pos;
  20496. while (this.bufferLength <= pos) {
  20497. if (this.eof) {
  20498. return -1;
  20499. }
  20500. this.readBlock();
  20501. }
  20502. return this.buffer[this.pos++];
  20503. },
  20504. getUint16: function DecodeStream_getUint16() {
  20505. var b0 = this.getByte();
  20506. var b1 = this.getByte();
  20507. if (b0 === -1 || b1 === -1) {
  20508. return -1;
  20509. }
  20510. return (b0 << 8) + b1;
  20511. },
  20512. getInt32: function DecodeStream_getInt32() {
  20513. var b0 = this.getByte();
  20514. var b1 = this.getByte();
  20515. var b2 = this.getByte();
  20516. var b3 = this.getByte();
  20517. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20518. },
  20519. getBytes: function DecodeStream_getBytes(length) {
  20520. var end, pos = this.pos;
  20521. if (length) {
  20522. this.ensureBuffer(pos + length);
  20523. end = pos + length;
  20524. while (!this.eof && this.bufferLength < end) {
  20525. this.readBlock();
  20526. }
  20527. var bufEnd = this.bufferLength;
  20528. if (end > bufEnd) {
  20529. end = bufEnd;
  20530. }
  20531. } else {
  20532. while (!this.eof) {
  20533. this.readBlock();
  20534. }
  20535. end = this.bufferLength;
  20536. }
  20537. this.pos = end;
  20538. return this.buffer.subarray(pos, end);
  20539. },
  20540. peekByte: function DecodeStream_peekByte() {
  20541. var peekedByte = this.getByte();
  20542. this.pos--;
  20543. return peekedByte;
  20544. },
  20545. peekBytes: function DecodeStream_peekBytes(length) {
  20546. var bytes = this.getBytes(length);
  20547. this.pos -= bytes.length;
  20548. return bytes;
  20549. },
  20550. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20551. var end = start + length;
  20552. while (this.bufferLength <= end && !this.eof) {
  20553. this.readBlock();
  20554. }
  20555. return new Stream(this.buffer, start, length, dict);
  20556. },
  20557. skip: function DecodeStream_skip(n) {
  20558. if (!n) {
  20559. n = 1;
  20560. }
  20561. this.pos += n;
  20562. },
  20563. reset: function DecodeStream_reset() {
  20564. this.pos = 0;
  20565. },
  20566. getBaseStreams: function DecodeStream_getBaseStreams() {
  20567. if (this.str && this.str.getBaseStreams) {
  20568. return this.str.getBaseStreams();
  20569. }
  20570. return [];
  20571. }
  20572. };
  20573. return DecodeStream;
  20574. })();
  20575. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20576. function StreamsSequenceStream(streams) {
  20577. this.streams = streams;
  20578. DecodeStream.call(this, /* maybeLength = */ null);
  20579. }
  20580. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20581. StreamsSequenceStream.prototype.readBlock =
  20582. function streamSequenceStreamReadBlock() {
  20583. var streams = this.streams;
  20584. if (streams.length === 0) {
  20585. this.eof = true;
  20586. return;
  20587. }
  20588. var stream = streams.shift();
  20589. var chunk = stream.getBytes();
  20590. var bufferLength = this.bufferLength;
  20591. var newLength = bufferLength + chunk.length;
  20592. var buffer = this.ensureBuffer(newLength);
  20593. buffer.set(chunk, bufferLength);
  20594. this.bufferLength = newLength;
  20595. };
  20596. StreamsSequenceStream.prototype.getBaseStreams =
  20597. function StreamsSequenceStream_getBaseStreams() {
  20598. var baseStreams = [];
  20599. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20600. var stream = this.streams[i];
  20601. if (stream.getBaseStreams) {
  20602. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20603. }
  20604. }
  20605. return baseStreams;
  20606. };
  20607. return StreamsSequenceStream;
  20608. })();
  20609. var FlateStream = (function FlateStreamClosure() {
  20610. var codeLenCodeMap = new Int32Array([
  20611. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20612. ]);
  20613. var lengthDecode = new Int32Array([
  20614. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20615. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20616. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20617. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20618. ]);
  20619. var distDecode = new Int32Array([
  20620. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20621. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20622. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20623. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20624. ]);
  20625. var fixedLitCodeTab = [new Int32Array([
  20626. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20627. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20628. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20629. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20630. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20631. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20632. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20633. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20634. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20635. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20636. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20637. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20638. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20639. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20640. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20641. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20642. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20643. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20644. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20645. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20646. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20647. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20648. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20649. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20650. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20651. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20652. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20653. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20654. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20655. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20656. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20657. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20658. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20659. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20660. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20661. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20662. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20663. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20664. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20665. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20666. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20667. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20668. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20669. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20670. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20671. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20672. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20673. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20674. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20675. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20676. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20677. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20678. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20679. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20680. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20681. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20682. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20683. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20684. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20685. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20686. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20687. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20688. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20689. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20690. ]), 9];
  20691. var fixedDistCodeTab = [new Int32Array([
  20692. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20693. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20694. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20695. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  20696. ]), 5];
  20697. function FlateStream(str, maybeLength) {
  20698. this.str = str;
  20699. this.dict = str.dict;
  20700. var cmf = str.getByte();
  20701. var flg = str.getByte();
  20702. if (cmf === -1 || flg === -1) {
  20703. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  20704. }
  20705. if ((cmf & 0x0f) !== 0x08) {
  20706. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  20707. }
  20708. if ((((cmf << 8) + flg) % 31) !== 0) {
  20709. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  20710. }
  20711. if (flg & 0x20) {
  20712. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  20713. }
  20714. this.codeSize = 0;
  20715. this.codeBuf = 0;
  20716. DecodeStream.call(this, maybeLength);
  20717. }
  20718. FlateStream.prototype = Object.create(DecodeStream.prototype);
  20719. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  20720. var str = this.str;
  20721. var codeSize = this.codeSize;
  20722. var codeBuf = this.codeBuf;
  20723. var b;
  20724. while (codeSize < bits) {
  20725. if ((b = str.getByte()) === -1) {
  20726. error('Bad encoding in flate stream');
  20727. }
  20728. codeBuf |= b << codeSize;
  20729. codeSize += 8;
  20730. }
  20731. b = codeBuf & ((1 << bits) - 1);
  20732. this.codeBuf = codeBuf >> bits;
  20733. this.codeSize = codeSize -= bits;
  20734. return b;
  20735. };
  20736. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  20737. var str = this.str;
  20738. var codes = table[0];
  20739. var maxLen = table[1];
  20740. var codeSize = this.codeSize;
  20741. var codeBuf = this.codeBuf;
  20742. var b;
  20743. while (codeSize < maxLen) {
  20744. if ((b = str.getByte()) === -1) {
  20745. // premature end of stream. code might however still be valid.
  20746. // codeSize < codeLen check below guards against incomplete codeVal.
  20747. break;
  20748. }
  20749. codeBuf |= (b << codeSize);
  20750. codeSize += 8;
  20751. }
  20752. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  20753. var codeLen = code >> 16;
  20754. var codeVal = code & 0xffff;
  20755. if (codeLen < 1 || codeSize < codeLen) {
  20756. error('Bad encoding in flate stream');
  20757. }
  20758. this.codeBuf = (codeBuf >> codeLen);
  20759. this.codeSize = (codeSize - codeLen);
  20760. return codeVal;
  20761. };
  20762. FlateStream.prototype.generateHuffmanTable =
  20763. function flateStreamGenerateHuffmanTable(lengths) {
  20764. var n = lengths.length;
  20765. // find max code length
  20766. var maxLen = 0;
  20767. var i;
  20768. for (i = 0; i < n; ++i) {
  20769. if (lengths[i] > maxLen) {
  20770. maxLen = lengths[i];
  20771. }
  20772. }
  20773. // build the table
  20774. var size = 1 << maxLen;
  20775. var codes = new Int32Array(size);
  20776. for (var len = 1, code = 0, skip = 2;
  20777. len <= maxLen;
  20778. ++len, code <<= 1, skip <<= 1) {
  20779. for (var val = 0; val < n; ++val) {
  20780. if (lengths[val] === len) {
  20781. // bit-reverse the code
  20782. var code2 = 0;
  20783. var t = code;
  20784. for (i = 0; i < len; ++i) {
  20785. code2 = (code2 << 1) | (t & 1);
  20786. t >>= 1;
  20787. }
  20788. // fill the table entries
  20789. for (i = code2; i < size; i += skip) {
  20790. codes[i] = (len << 16) | val;
  20791. }
  20792. ++code;
  20793. }
  20794. }
  20795. }
  20796. return [codes, maxLen];
  20797. };
  20798. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  20799. var buffer, len;
  20800. var str = this.str;
  20801. // read block header
  20802. var hdr = this.getBits(3);
  20803. if (hdr & 1) {
  20804. this.eof = true;
  20805. }
  20806. hdr >>= 1;
  20807. if (hdr === 0) { // uncompressed block
  20808. var b;
  20809. if ((b = str.getByte()) === -1) {
  20810. error('Bad block header in flate stream');
  20811. }
  20812. var blockLen = b;
  20813. if ((b = str.getByte()) === -1) {
  20814. error('Bad block header in flate stream');
  20815. }
  20816. blockLen |= (b << 8);
  20817. if ((b = str.getByte()) === -1) {
  20818. error('Bad block header in flate stream');
  20819. }
  20820. var check = b;
  20821. if ((b = str.getByte()) === -1) {
  20822. error('Bad block header in flate stream');
  20823. }
  20824. check |= (b << 8);
  20825. if (check !== (~blockLen & 0xffff) &&
  20826. (blockLen !== 0 || check !== 0)) {
  20827. // Ignoring error for bad "empty" block (see issue 1277)
  20828. error('Bad uncompressed block length in flate stream');
  20829. }
  20830. this.codeBuf = 0;
  20831. this.codeSize = 0;
  20832. var bufferLength = this.bufferLength;
  20833. buffer = this.ensureBuffer(bufferLength + blockLen);
  20834. var end = bufferLength + blockLen;
  20835. this.bufferLength = end;
  20836. if (blockLen === 0) {
  20837. if (str.peekByte() === -1) {
  20838. this.eof = true;
  20839. }
  20840. } else {
  20841. for (var n = bufferLength; n < end; ++n) {
  20842. if ((b = str.getByte()) === -1) {
  20843. this.eof = true;
  20844. break;
  20845. }
  20846. buffer[n] = b;
  20847. }
  20848. }
  20849. return;
  20850. }
  20851. var litCodeTable;
  20852. var distCodeTable;
  20853. if (hdr === 1) { // compressed block, fixed codes
  20854. litCodeTable = fixedLitCodeTab;
  20855. distCodeTable = fixedDistCodeTab;
  20856. } else if (hdr === 2) { // compressed block, dynamic codes
  20857. var numLitCodes = this.getBits(5) + 257;
  20858. var numDistCodes = this.getBits(5) + 1;
  20859. var numCodeLenCodes = this.getBits(4) + 4;
  20860. // build the code lengths code table
  20861. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  20862. var i;
  20863. for (i = 0; i < numCodeLenCodes; ++i) {
  20864. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  20865. }
  20866. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  20867. // build the literal and distance code tables
  20868. len = 0;
  20869. i = 0;
  20870. var codes = numLitCodes + numDistCodes;
  20871. var codeLengths = new Uint8Array(codes);
  20872. var bitsLength, bitsOffset, what;
  20873. while (i < codes) {
  20874. var code = this.getCode(codeLenCodeTab);
  20875. if (code === 16) {
  20876. bitsLength = 2; bitsOffset = 3; what = len;
  20877. } else if (code === 17) {
  20878. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  20879. } else if (code === 18) {
  20880. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  20881. } else {
  20882. codeLengths[i++] = len = code;
  20883. continue;
  20884. }
  20885. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  20886. while (repeatLength-- > 0) {
  20887. codeLengths[i++] = what;
  20888. }
  20889. }
  20890. litCodeTable =
  20891. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  20892. distCodeTable =
  20893. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  20894. } else {
  20895. error('Unknown block type in flate stream');
  20896. }
  20897. buffer = this.buffer;
  20898. var limit = buffer ? buffer.length : 0;
  20899. var pos = this.bufferLength;
  20900. while (true) {
  20901. var code1 = this.getCode(litCodeTable);
  20902. if (code1 < 256) {
  20903. if (pos + 1 >= limit) {
  20904. buffer = this.ensureBuffer(pos + 1);
  20905. limit = buffer.length;
  20906. }
  20907. buffer[pos++] = code1;
  20908. continue;
  20909. }
  20910. if (code1 === 256) {
  20911. this.bufferLength = pos;
  20912. return;
  20913. }
  20914. code1 -= 257;
  20915. code1 = lengthDecode[code1];
  20916. var code2 = code1 >> 16;
  20917. if (code2 > 0) {
  20918. code2 = this.getBits(code2);
  20919. }
  20920. len = (code1 & 0xffff) + code2;
  20921. code1 = this.getCode(distCodeTable);
  20922. code1 = distDecode[code1];
  20923. code2 = code1 >> 16;
  20924. if (code2 > 0) {
  20925. code2 = this.getBits(code2);
  20926. }
  20927. var dist = (code1 & 0xffff) + code2;
  20928. if (pos + len >= limit) {
  20929. buffer = this.ensureBuffer(pos + len);
  20930. limit = buffer.length;
  20931. }
  20932. for (var k = 0; k < len; ++k, ++pos) {
  20933. buffer[pos] = buffer[pos - dist];
  20934. }
  20935. }
  20936. };
  20937. return FlateStream;
  20938. })();
  20939. var PredictorStream = (function PredictorStreamClosure() {
  20940. function PredictorStream(str, maybeLength, params) {
  20941. var predictor = this.predictor = params.get('Predictor') || 1;
  20942. if (predictor <= 1) {
  20943. return str; // no prediction
  20944. }
  20945. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  20946. error('Unsupported predictor: ' + predictor);
  20947. }
  20948. if (predictor === 2) {
  20949. this.readBlock = this.readBlockTiff;
  20950. } else {
  20951. this.readBlock = this.readBlockPng;
  20952. }
  20953. this.str = str;
  20954. this.dict = str.dict;
  20955. var colors = this.colors = params.get('Colors') || 1;
  20956. var bits = this.bits = params.get('BitsPerComponent') || 8;
  20957. var columns = this.columns = params.get('Columns') || 1;
  20958. this.pixBytes = (colors * bits + 7) >> 3;
  20959. this.rowBytes = (columns * colors * bits + 7) >> 3;
  20960. DecodeStream.call(this, maybeLength);
  20961. return this;
  20962. }
  20963. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  20964. PredictorStream.prototype.readBlockTiff =
  20965. function predictorStreamReadBlockTiff() {
  20966. var rowBytes = this.rowBytes;
  20967. var bufferLength = this.bufferLength;
  20968. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  20969. var bits = this.bits;
  20970. var colors = this.colors;
  20971. var rawBytes = this.str.getBytes(rowBytes);
  20972. this.eof = !rawBytes.length;
  20973. if (this.eof) {
  20974. return;
  20975. }
  20976. var inbuf = 0, outbuf = 0;
  20977. var inbits = 0, outbits = 0;
  20978. var pos = bufferLength;
  20979. var i;
  20980. if (bits === 1) {
  20981. for (i = 0; i < rowBytes; ++i) {
  20982. var c = rawBytes[i];
  20983. inbuf = (inbuf << 8) | c;
  20984. // bitwise addition is exclusive or
  20985. // first shift inbuf and then add
  20986. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  20987. // truncate inbuf (assumes colors < 16)
  20988. inbuf &= 0xFFFF;
  20989. }
  20990. } else if (bits === 8) {
  20991. for (i = 0; i < colors; ++i) {
  20992. buffer[pos++] = rawBytes[i];
  20993. }
  20994. for (; i < rowBytes; ++i) {
  20995. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  20996. pos++;
  20997. }
  20998. } else {
  20999. var compArray = new Uint8Array(colors + 1);
  21000. var bitMask = (1 << bits) - 1;
  21001. var j = 0, k = bufferLength;
  21002. var columns = this.columns;
  21003. for (i = 0; i < columns; ++i) {
  21004. for (var kk = 0; kk < colors; ++kk) {
  21005. if (inbits < bits) {
  21006. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21007. inbits += 8;
  21008. }
  21009. compArray[kk] = (compArray[kk] +
  21010. (inbuf >> (inbits - bits))) & bitMask;
  21011. inbits -= bits;
  21012. outbuf = (outbuf << bits) | compArray[kk];
  21013. outbits += bits;
  21014. if (outbits >= 8) {
  21015. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21016. outbits -= 8;
  21017. }
  21018. }
  21019. }
  21020. if (outbits > 0) {
  21021. buffer[k++] = (outbuf << (8 - outbits)) +
  21022. (inbuf & ((1 << (8 - outbits)) - 1));
  21023. }
  21024. }
  21025. this.bufferLength += rowBytes;
  21026. };
  21027. PredictorStream.prototype.readBlockPng =
  21028. function predictorStreamReadBlockPng() {
  21029. var rowBytes = this.rowBytes;
  21030. var pixBytes = this.pixBytes;
  21031. var predictor = this.str.getByte();
  21032. var rawBytes = this.str.getBytes(rowBytes);
  21033. this.eof = !rawBytes.length;
  21034. if (this.eof) {
  21035. return;
  21036. }
  21037. var bufferLength = this.bufferLength;
  21038. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21039. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21040. if (prevRow.length === 0) {
  21041. prevRow = new Uint8Array(rowBytes);
  21042. }
  21043. var i, j = bufferLength, up, c;
  21044. switch (predictor) {
  21045. case 0:
  21046. for (i = 0; i < rowBytes; ++i) {
  21047. buffer[j++] = rawBytes[i];
  21048. }
  21049. break;
  21050. case 1:
  21051. for (i = 0; i < pixBytes; ++i) {
  21052. buffer[j++] = rawBytes[i];
  21053. }
  21054. for (; i < rowBytes; ++i) {
  21055. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21056. j++;
  21057. }
  21058. break;
  21059. case 2:
  21060. for (i = 0; i < rowBytes; ++i) {
  21061. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21062. }
  21063. break;
  21064. case 3:
  21065. for (i = 0; i < pixBytes; ++i) {
  21066. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21067. }
  21068. for (; i < rowBytes; ++i) {
  21069. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21070. rawBytes[i]) & 0xFF;
  21071. j++;
  21072. }
  21073. break;
  21074. case 4:
  21075. // we need to save the up left pixels values. the simplest way
  21076. // is to create a new buffer
  21077. for (i = 0; i < pixBytes; ++i) {
  21078. up = prevRow[i];
  21079. c = rawBytes[i];
  21080. buffer[j++] = up + c;
  21081. }
  21082. for (; i < rowBytes; ++i) {
  21083. up = prevRow[i];
  21084. var upLeft = prevRow[i - pixBytes];
  21085. var left = buffer[j - pixBytes];
  21086. var p = left + up - upLeft;
  21087. var pa = p - left;
  21088. if (pa < 0) {
  21089. pa = -pa;
  21090. }
  21091. var pb = p - up;
  21092. if (pb < 0) {
  21093. pb = -pb;
  21094. }
  21095. var pc = p - upLeft;
  21096. if (pc < 0) {
  21097. pc = -pc;
  21098. }
  21099. c = rawBytes[i];
  21100. if (pa <= pb && pa <= pc) {
  21101. buffer[j++] = left + c;
  21102. } else if (pb <= pc) {
  21103. buffer[j++] = up + c;
  21104. } else {
  21105. buffer[j++] = upLeft + c;
  21106. }
  21107. }
  21108. break;
  21109. default:
  21110. error('Unsupported predictor: ' + predictor);
  21111. }
  21112. this.bufferLength += rowBytes;
  21113. };
  21114. return PredictorStream;
  21115. })();
  21116. /**
  21117. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21118. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21119. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21120. * a library to decode these images and the stream behaves like all the other
  21121. * DecodeStreams.
  21122. */
  21123. var JpegStream = (function JpegStreamClosure() {
  21124. function JpegStream(stream, maybeLength, dict, xref) {
  21125. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21126. // Note: this seems to mainly affect inline images.
  21127. var ch;
  21128. while ((ch = stream.getByte()) !== -1) {
  21129. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21130. stream.skip(-1); // Reset the stream position to the SOI.
  21131. break;
  21132. }
  21133. }
  21134. this.stream = stream;
  21135. this.maybeLength = maybeLength;
  21136. this.dict = dict;
  21137. DecodeStream.call(this, maybeLength);
  21138. }
  21139. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21140. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21141. get: function JpegStream_bytes() {
  21142. // If this.maybeLength is null, we'll get the entire stream.
  21143. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21144. },
  21145. configurable: true
  21146. });
  21147. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21148. if (this.bufferLength) {
  21149. return;
  21150. }
  21151. try {
  21152. var jpegImage = new JpegImage();
  21153. // checking if values needs to be transformed before conversion
  21154. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  21155. var decodeArr = this.dict.get('Decode');
  21156. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21157. var decodeArrLength = decodeArr.length;
  21158. var transform = new Int32Array(decodeArrLength);
  21159. var transformNeeded = false;
  21160. var maxValue = (1 << bitsPerComponent) - 1;
  21161. for (var i = 0; i < decodeArrLength; i += 2) {
  21162. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21163. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21164. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21165. transformNeeded = true;
  21166. }
  21167. }
  21168. if (transformNeeded) {
  21169. jpegImage.decodeTransform = transform;
  21170. }
  21171. }
  21172. jpegImage.parse(this.bytes);
  21173. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21174. this.forceRGB);
  21175. this.buffer = data;
  21176. this.bufferLength = data.length;
  21177. this.eof = true;
  21178. } catch (e) {
  21179. error('JPEG error: ' + e);
  21180. }
  21181. };
  21182. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21183. this.ensureBuffer();
  21184. return this.buffer;
  21185. };
  21186. JpegStream.prototype.getIR = function JpegStream_getIR() {
  21187. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  21188. };
  21189. /**
  21190. * Checks if the image can be decoded and displayed by the browser without any
  21191. * further processing such as color space conversions.
  21192. */
  21193. JpegStream.prototype.isNativelySupported =
  21194. function JpegStream_isNativelySupported(xref, res) {
  21195. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  21196. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  21197. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  21198. };
  21199. /**
  21200. * Checks if the image can be decoded by the browser.
  21201. */
  21202. JpegStream.prototype.isNativelyDecodable =
  21203. function JpegStream_isNativelyDecodable(xref, res) {
  21204. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  21205. return (cs.numComps === 1 || cs.numComps === 3) &&
  21206. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  21207. };
  21208. return JpegStream;
  21209. })();
  21210. /**
  21211. * For JPEG 2000's we use a library to decode these images and
  21212. * the stream behaves like all the other DecodeStreams.
  21213. */
  21214. var JpxStream = (function JpxStreamClosure() {
  21215. function JpxStream(stream, maybeLength, dict) {
  21216. this.stream = stream;
  21217. this.maybeLength = maybeLength;
  21218. this.dict = dict;
  21219. DecodeStream.call(this, maybeLength);
  21220. }
  21221. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21222. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21223. get: function JpxStream_bytes() {
  21224. // If this.maybeLength is null, we'll get the entire stream.
  21225. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21226. },
  21227. configurable: true
  21228. });
  21229. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21230. if (this.bufferLength) {
  21231. return;
  21232. }
  21233. var jpxImage = new JpxImage();
  21234. jpxImage.parse(this.bytes);
  21235. var width = jpxImage.width;
  21236. var height = jpxImage.height;
  21237. var componentsCount = jpxImage.componentsCount;
  21238. var tileCount = jpxImage.tiles.length;
  21239. if (tileCount === 1) {
  21240. this.buffer = jpxImage.tiles[0].items;
  21241. } else {
  21242. var data = new Uint8Array(width * height * componentsCount);
  21243. for (var k = 0; k < tileCount; k++) {
  21244. var tileComponents = jpxImage.tiles[k];
  21245. var tileWidth = tileComponents.width;
  21246. var tileHeight = tileComponents.height;
  21247. var tileLeft = tileComponents.left;
  21248. var tileTop = tileComponents.top;
  21249. var src = tileComponents.items;
  21250. var srcPosition = 0;
  21251. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21252. var imgRowSize = width * componentsCount;
  21253. var tileRowSize = tileWidth * componentsCount;
  21254. for (var j = 0; j < tileHeight; j++) {
  21255. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21256. data.set(rowBytes, dataPosition);
  21257. srcPosition += tileRowSize;
  21258. dataPosition += imgRowSize;
  21259. }
  21260. }
  21261. this.buffer = data;
  21262. }
  21263. this.bufferLength = this.buffer.length;
  21264. this.eof = true;
  21265. };
  21266. return JpxStream;
  21267. })();
  21268. /**
  21269. * For JBIG2's we use a library to decode these images and
  21270. * the stream behaves like all the other DecodeStreams.
  21271. */
  21272. var Jbig2Stream = (function Jbig2StreamClosure() {
  21273. function Jbig2Stream(stream, maybeLength, dict) {
  21274. this.stream = stream;
  21275. this.maybeLength = maybeLength;
  21276. this.dict = dict;
  21277. DecodeStream.call(this, maybeLength);
  21278. }
  21279. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21280. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21281. get: function Jbig2Stream_bytes() {
  21282. // If this.maybeLength is null, we'll get the entire stream.
  21283. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21284. },
  21285. configurable: true
  21286. });
  21287. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21288. if (this.bufferLength) {
  21289. return;
  21290. }
  21291. var jbig2Image = new Jbig2Image();
  21292. var chunks = [], xref = this.dict.xref;
  21293. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  21294. // According to the PDF specification, DecodeParms can be either
  21295. // a dictionary, or an array whose elements are dictionaries.
  21296. if (isArray(decodeParams)) {
  21297. if (decodeParams.length > 1) {
  21298. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21299. 'not supported.');
  21300. }
  21301. decodeParams = xref.fetchIfRef(decodeParams[0]);
  21302. }
  21303. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21304. var globalsStream = decodeParams.get('JBIG2Globals');
  21305. var globals = globalsStream.getBytes();
  21306. chunks.push({data: globals, start: 0, end: globals.length});
  21307. }
  21308. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21309. var data = jbig2Image.parseChunks(chunks);
  21310. var dataLength = data.length;
  21311. // JBIG2 had black as 1 and white as 0, inverting the colors
  21312. for (var i = 0; i < dataLength; i++) {
  21313. data[i] ^= 0xFF;
  21314. }
  21315. this.buffer = data;
  21316. this.bufferLength = dataLength;
  21317. this.eof = true;
  21318. };
  21319. return Jbig2Stream;
  21320. })();
  21321. var DecryptStream = (function DecryptStreamClosure() {
  21322. function DecryptStream(str, maybeLength, decrypt) {
  21323. this.str = str;
  21324. this.dict = str.dict;
  21325. this.decrypt = decrypt;
  21326. this.nextChunk = null;
  21327. this.initialized = false;
  21328. DecodeStream.call(this, maybeLength);
  21329. }
  21330. var chunkSize = 512;
  21331. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21332. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21333. var chunk;
  21334. if (this.initialized) {
  21335. chunk = this.nextChunk;
  21336. } else {
  21337. chunk = this.str.getBytes(chunkSize);
  21338. this.initialized = true;
  21339. }
  21340. if (!chunk || chunk.length === 0) {
  21341. this.eof = true;
  21342. return;
  21343. }
  21344. this.nextChunk = this.str.getBytes(chunkSize);
  21345. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21346. var decrypt = this.decrypt;
  21347. chunk = decrypt(chunk, !hasMoreData);
  21348. var bufferLength = this.bufferLength;
  21349. var i, n = chunk.length;
  21350. var buffer = this.ensureBuffer(bufferLength + n);
  21351. for (i = 0; i < n; i++) {
  21352. buffer[bufferLength++] = chunk[i];
  21353. }
  21354. this.bufferLength = bufferLength;
  21355. };
  21356. return DecryptStream;
  21357. })();
  21358. var Ascii85Stream = (function Ascii85StreamClosure() {
  21359. function Ascii85Stream(str, maybeLength) {
  21360. this.str = str;
  21361. this.dict = str.dict;
  21362. this.input = new Uint8Array(5);
  21363. // Most streams increase in size when decoded, but Ascii85 streams
  21364. // typically shrink by ~20%.
  21365. if (maybeLength) {
  21366. maybeLength = 0.8 * maybeLength;
  21367. }
  21368. DecodeStream.call(this, maybeLength);
  21369. }
  21370. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21371. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21372. var TILDA_CHAR = 0x7E; // '~'
  21373. var Z_LOWER_CHAR = 0x7A; // 'z'
  21374. var EOF = -1;
  21375. var str = this.str;
  21376. var c = str.getByte();
  21377. while (Lexer.isSpace(c)) {
  21378. c = str.getByte();
  21379. }
  21380. if (c === EOF || c === TILDA_CHAR) {
  21381. this.eof = true;
  21382. return;
  21383. }
  21384. var bufferLength = this.bufferLength, buffer;
  21385. var i;
  21386. // special code for z
  21387. if (c === Z_LOWER_CHAR) {
  21388. buffer = this.ensureBuffer(bufferLength + 4);
  21389. for (i = 0; i < 4; ++i) {
  21390. buffer[bufferLength + i] = 0;
  21391. }
  21392. this.bufferLength += 4;
  21393. } else {
  21394. var input = this.input;
  21395. input[0] = c;
  21396. for (i = 1; i < 5; ++i) {
  21397. c = str.getByte();
  21398. while (Lexer.isSpace(c)) {
  21399. c = str.getByte();
  21400. }
  21401. input[i] = c;
  21402. if (c === EOF || c === TILDA_CHAR) {
  21403. break;
  21404. }
  21405. }
  21406. buffer = this.ensureBuffer(bufferLength + i - 1);
  21407. this.bufferLength += i - 1;
  21408. // partial ending;
  21409. if (i < 5) {
  21410. for (; i < 5; ++i) {
  21411. input[i] = 0x21 + 84;
  21412. }
  21413. this.eof = true;
  21414. }
  21415. var t = 0;
  21416. for (i = 0; i < 5; ++i) {
  21417. t = t * 85 + (input[i] - 0x21);
  21418. }
  21419. for (i = 3; i >= 0; --i) {
  21420. buffer[bufferLength + i] = t & 0xFF;
  21421. t >>= 8;
  21422. }
  21423. }
  21424. };
  21425. return Ascii85Stream;
  21426. })();
  21427. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21428. function AsciiHexStream(str, maybeLength) {
  21429. this.str = str;
  21430. this.dict = str.dict;
  21431. this.firstDigit = -1;
  21432. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21433. // by 50%.
  21434. if (maybeLength) {
  21435. maybeLength = 0.5 * maybeLength;
  21436. }
  21437. DecodeStream.call(this, maybeLength);
  21438. }
  21439. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21440. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21441. var UPSTREAM_BLOCK_SIZE = 8000;
  21442. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21443. if (!bytes.length) {
  21444. this.eof = true;
  21445. return;
  21446. }
  21447. var maxDecodeLength = (bytes.length + 1) >> 1;
  21448. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21449. var bufferLength = this.bufferLength;
  21450. var firstDigit = this.firstDigit;
  21451. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21452. var ch = bytes[i], digit;
  21453. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21454. digit = ch & 0x0F;
  21455. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21456. // 'A'-'Z', 'a'-'z'
  21457. digit = (ch & 0x0F) + 9;
  21458. } else if (ch === 0x3E) { // '>'
  21459. this.eof = true;
  21460. break;
  21461. } else { // probably whitespace
  21462. continue; // ignoring
  21463. }
  21464. if (firstDigit < 0) {
  21465. firstDigit = digit;
  21466. } else {
  21467. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21468. firstDigit = -1;
  21469. }
  21470. }
  21471. if (firstDigit >= 0 && this.eof) {
  21472. // incomplete byte
  21473. buffer[bufferLength++] = (firstDigit << 4);
  21474. firstDigit = -1;
  21475. }
  21476. this.firstDigit = firstDigit;
  21477. this.bufferLength = bufferLength;
  21478. };
  21479. return AsciiHexStream;
  21480. })();
  21481. var RunLengthStream = (function RunLengthStreamClosure() {
  21482. function RunLengthStream(str, maybeLength) {
  21483. this.str = str;
  21484. this.dict = str.dict;
  21485. DecodeStream.call(this, maybeLength);
  21486. }
  21487. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21488. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21489. // The repeatHeader has following format. The first byte defines type of run
  21490. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21491. // (in addition to the second byte from the header), n = 129 through 255 -
  21492. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21493. var repeatHeader = this.str.getBytes(2);
  21494. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21495. this.eof = true;
  21496. return;
  21497. }
  21498. var buffer;
  21499. var bufferLength = this.bufferLength;
  21500. var n = repeatHeader[0];
  21501. if (n < 128) {
  21502. // copy n bytes
  21503. buffer = this.ensureBuffer(bufferLength + n + 1);
  21504. buffer[bufferLength++] = repeatHeader[1];
  21505. if (n > 0) {
  21506. var source = this.str.getBytes(n);
  21507. buffer.set(source, bufferLength);
  21508. bufferLength += n;
  21509. }
  21510. } else {
  21511. n = 257 - n;
  21512. var b = repeatHeader[1];
  21513. buffer = this.ensureBuffer(bufferLength + n + 1);
  21514. for (var i = 0; i < n; i++) {
  21515. buffer[bufferLength++] = b;
  21516. }
  21517. }
  21518. this.bufferLength = bufferLength;
  21519. };
  21520. return RunLengthStream;
  21521. })();
  21522. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21523. var ccittEOL = -2;
  21524. var twoDimPass = 0;
  21525. var twoDimHoriz = 1;
  21526. var twoDimVert0 = 2;
  21527. var twoDimVertR1 = 3;
  21528. var twoDimVertL1 = 4;
  21529. var twoDimVertR2 = 5;
  21530. var twoDimVertL2 = 6;
  21531. var twoDimVertR3 = 7;
  21532. var twoDimVertL3 = 8;
  21533. var twoDimTable = [
  21534. [-1, -1], [-1, -1], // 000000x
  21535. [7, twoDimVertL3], // 0000010
  21536. [7, twoDimVertR3], // 0000011
  21537. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21538. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21539. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21540. [4, twoDimPass], [4, twoDimPass],
  21541. [4, twoDimPass], [4, twoDimPass],
  21542. [4, twoDimPass], [4, twoDimPass],
  21543. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21544. [3, twoDimHoriz], [3, twoDimHoriz],
  21545. [3, twoDimHoriz], [3, twoDimHoriz],
  21546. [3, twoDimHoriz], [3, twoDimHoriz],
  21547. [3, twoDimHoriz], [3, twoDimHoriz],
  21548. [3, twoDimHoriz], [3, twoDimHoriz],
  21549. [3, twoDimHoriz], [3, twoDimHoriz],
  21550. [3, twoDimHoriz], [3, twoDimHoriz],
  21551. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21552. [3, twoDimVertL1], [3, twoDimVertL1],
  21553. [3, twoDimVertL1], [3, twoDimVertL1],
  21554. [3, twoDimVertL1], [3, twoDimVertL1],
  21555. [3, twoDimVertL1], [3, twoDimVertL1],
  21556. [3, twoDimVertL1], [3, twoDimVertL1],
  21557. [3, twoDimVertL1], [3, twoDimVertL1],
  21558. [3, twoDimVertL1], [3, twoDimVertL1],
  21559. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21560. [3, twoDimVertR1], [3, twoDimVertR1],
  21561. [3, twoDimVertR1], [3, twoDimVertR1],
  21562. [3, twoDimVertR1], [3, twoDimVertR1],
  21563. [3, twoDimVertR1], [3, twoDimVertR1],
  21564. [3, twoDimVertR1], [3, twoDimVertR1],
  21565. [3, twoDimVertR1], [3, twoDimVertR1],
  21566. [3, twoDimVertR1], [3, twoDimVertR1],
  21567. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21568. [1, twoDimVert0], [1, twoDimVert0],
  21569. [1, twoDimVert0], [1, twoDimVert0],
  21570. [1, twoDimVert0], [1, twoDimVert0],
  21571. [1, twoDimVert0], [1, twoDimVert0],
  21572. [1, twoDimVert0], [1, twoDimVert0],
  21573. [1, twoDimVert0], [1, twoDimVert0],
  21574. [1, twoDimVert0], [1, twoDimVert0],
  21575. [1, twoDimVert0], [1, twoDimVert0],
  21576. [1, twoDimVert0], [1, twoDimVert0],
  21577. [1, twoDimVert0], [1, twoDimVert0],
  21578. [1, twoDimVert0], [1, twoDimVert0],
  21579. [1, twoDimVert0], [1, twoDimVert0],
  21580. [1, twoDimVert0], [1, twoDimVert0],
  21581. [1, twoDimVert0], [1, twoDimVert0],
  21582. [1, twoDimVert0], [1, twoDimVert0],
  21583. [1, twoDimVert0], [1, twoDimVert0],
  21584. [1, twoDimVert0], [1, twoDimVert0],
  21585. [1, twoDimVert0], [1, twoDimVert0],
  21586. [1, twoDimVert0], [1, twoDimVert0],
  21587. [1, twoDimVert0], [1, twoDimVert0],
  21588. [1, twoDimVert0], [1, twoDimVert0],
  21589. [1, twoDimVert0], [1, twoDimVert0],
  21590. [1, twoDimVert0], [1, twoDimVert0],
  21591. [1, twoDimVert0], [1, twoDimVert0],
  21592. [1, twoDimVert0], [1, twoDimVert0],
  21593. [1, twoDimVert0], [1, twoDimVert0],
  21594. [1, twoDimVert0], [1, twoDimVert0],
  21595. [1, twoDimVert0], [1, twoDimVert0],
  21596. [1, twoDimVert0], [1, twoDimVert0],
  21597. [1, twoDimVert0], [1, twoDimVert0],
  21598. [1, twoDimVert0], [1, twoDimVert0]
  21599. ];
  21600. var whiteTable1 = [
  21601. [-1, -1], // 00000
  21602. [12, ccittEOL], // 00001
  21603. [-1, -1], [-1, -1], // 0001x
  21604. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21605. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21606. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21607. [11, 1792], [11, 1792], // 1000x
  21608. [12, 1984], // 10010
  21609. [12, 2048], // 10011
  21610. [12, 2112], // 10100
  21611. [12, 2176], // 10101
  21612. [12, 2240], // 10110
  21613. [12, 2304], // 10111
  21614. [11, 1856], [11, 1856], // 1100x
  21615. [11, 1920], [11, 1920], // 1101x
  21616. [12, 2368], // 11100
  21617. [12, 2432], // 11101
  21618. [12, 2496], // 11110
  21619. [12, 2560] // 11111
  21620. ];
  21621. var whiteTable2 = [
  21622. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21623. [8, 29], [8, 29], // 00000010x
  21624. [8, 30], [8, 30], // 00000011x
  21625. [8, 45], [8, 45], // 00000100x
  21626. [8, 46], [8, 46], // 00000101x
  21627. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21628. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21629. [8, 47], [8, 47], // 00001010x
  21630. [8, 48], [8, 48], // 00001011x
  21631. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21632. [6, 13], [6, 13], [6, 13], [6, 13],
  21633. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21634. [8, 33], [8, 33], // 00010010x
  21635. [8, 34], [8, 34], // 00010011x
  21636. [8, 35], [8, 35], // 00010100x
  21637. [8, 36], [8, 36], // 00010101x
  21638. [8, 37], [8, 37], // 00010110x
  21639. [8, 38], [8, 38], // 00010111x
  21640. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21641. [8, 31], [8, 31], // 00011010x
  21642. [8, 32], [8, 32], // 00011011x
  21643. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21644. [6, 1], [6, 1], [6, 1], [6, 1],
  21645. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21646. [6, 12], [6, 12], [6, 12], [6, 12],
  21647. [8, 53], [8, 53], // 00100100x
  21648. [8, 54], [8, 54], // 00100101x
  21649. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21650. [8, 39], [8, 39], // 00101000x
  21651. [8, 40], [8, 40], // 00101001x
  21652. [8, 41], [8, 41], // 00101010x
  21653. [8, 42], [8, 42], // 00101011x
  21654. [8, 43], [8, 43], // 00101100x
  21655. [8, 44], [8, 44], // 00101101x
  21656. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21657. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21658. [8, 61], [8, 61], // 00110010x
  21659. [8, 62], [8, 62], // 00110011x
  21660. [8, 63], [8, 63], // 00110100x
  21661. [8, 0], [8, 0], // 00110101x
  21662. [8, 320], [8, 320], // 00110110x
  21663. [8, 384], [8, 384], // 00110111x
  21664. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21665. [5, 10], [5, 10], [5, 10], [5, 10],
  21666. [5, 10], [5, 10], [5, 10], [5, 10],
  21667. [5, 10], [5, 10], [5, 10], [5, 10],
  21668. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21669. [5, 11], [5, 11], [5, 11], [5, 11],
  21670. [5, 11], [5, 11], [5, 11], [5, 11],
  21671. [5, 11], [5, 11], [5, 11], [5, 11],
  21672. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21673. [8, 59], [8, 59], // 01001010x
  21674. [8, 60], [8, 60], // 01001011x
  21675. [9, 1472], // 010011000
  21676. [9, 1536], // 010011001
  21677. [9, 1600], // 010011010
  21678. [9, 1728], // 010011011
  21679. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21680. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21681. [8, 49], [8, 49], // 01010010x
  21682. [8, 50], [8, 50], // 01010011x
  21683. [8, 51], [8, 51], // 01010100x
  21684. [8, 52], [8, 52], // 01010101x
  21685. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21686. [8, 55], [8, 55], // 01011000x
  21687. [8, 56], [8, 56], // 01011001x
  21688. [8, 57], [8, 57], // 01011010x
  21689. [8, 58], [8, 58], // 01011011x
  21690. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21691. [6, 192], [6, 192], [6, 192], [6, 192],
  21692. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21693. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21694. [8, 448], [8, 448], // 01100100x
  21695. [8, 512], [8, 512], // 01100101x
  21696. [9, 704], // 011001100
  21697. [9, 768], // 011001101
  21698. [8, 640], [8, 640], // 01100111x
  21699. [8, 576], [8, 576], // 01101000x
  21700. [9, 832], // 011010010
  21701. [9, 896], // 011010011
  21702. [9, 960], // 011010100
  21703. [9, 1024], // 011010101
  21704. [9, 1088], // 011010110
  21705. [9, 1152], // 011010111
  21706. [9, 1216], // 011011000
  21707. [9, 1280], // 011011001
  21708. [9, 1344], // 011011010
  21709. [9, 1408], // 011011011
  21710. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  21711. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  21712. [4, 2], [4, 2], [4, 2], [4, 2],
  21713. [4, 2], [4, 2], [4, 2], [4, 2],
  21714. [4, 2], [4, 2], [4, 2], [4, 2],
  21715. [4, 2], [4, 2], [4, 2], [4, 2],
  21716. [4, 2], [4, 2], [4, 2], [4, 2],
  21717. [4, 2], [4, 2], [4, 2], [4, 2],
  21718. [4, 2], [4, 2], [4, 2], [4, 2],
  21719. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  21720. [4, 3], [4, 3], [4, 3], [4, 3],
  21721. [4, 3], [4, 3], [4, 3], [4, 3],
  21722. [4, 3], [4, 3], [4, 3], [4, 3],
  21723. [4, 3], [4, 3], [4, 3], [4, 3],
  21724. [4, 3], [4, 3], [4, 3], [4, 3],
  21725. [4, 3], [4, 3], [4, 3], [4, 3],
  21726. [4, 3], [4, 3], [4, 3], [4, 3],
  21727. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  21728. [5, 128], [5, 128], [5, 128], [5, 128],
  21729. [5, 128], [5, 128], [5, 128], [5, 128],
  21730. [5, 128], [5, 128], [5, 128], [5, 128],
  21731. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  21732. [5, 8], [5, 8], [5, 8], [5, 8],
  21733. [5, 8], [5, 8], [5, 8], [5, 8],
  21734. [5, 8], [5, 8], [5, 8], [5, 8],
  21735. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  21736. [5, 9], [5, 9], [5, 9], [5, 9],
  21737. [5, 9], [5, 9], [5, 9], [5, 9],
  21738. [5, 9], [5, 9], [5, 9], [5, 9],
  21739. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  21740. [6, 16], [6, 16], [6, 16], [6, 16],
  21741. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  21742. [6, 17], [6, 17], [6, 17], [6, 17],
  21743. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  21744. [4, 4], [4, 4], [4, 4], [4, 4],
  21745. [4, 4], [4, 4], [4, 4], [4, 4],
  21746. [4, 4], [4, 4], [4, 4], [4, 4],
  21747. [4, 4], [4, 4], [4, 4], [4, 4],
  21748. [4, 4], [4, 4], [4, 4], [4, 4],
  21749. [4, 4], [4, 4], [4, 4], [4, 4],
  21750. [4, 4], [4, 4], [4, 4], [4, 4],
  21751. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  21752. [4, 5], [4, 5], [4, 5], [4, 5],
  21753. [4, 5], [4, 5], [4, 5], [4, 5],
  21754. [4, 5], [4, 5], [4, 5], [4, 5],
  21755. [4, 5], [4, 5], [4, 5], [4, 5],
  21756. [4, 5], [4, 5], [4, 5], [4, 5],
  21757. [4, 5], [4, 5], [4, 5], [4, 5],
  21758. [4, 5], [4, 5], [4, 5], [4, 5],
  21759. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  21760. [6, 14], [6, 14], [6, 14], [6, 14],
  21761. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  21762. [6, 15], [6, 15], [6, 15], [6, 15],
  21763. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  21764. [5, 64], [5, 64], [5, 64], [5, 64],
  21765. [5, 64], [5, 64], [5, 64], [5, 64],
  21766. [5, 64], [5, 64], [5, 64], [5, 64],
  21767. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  21768. [4, 6], [4, 6], [4, 6], [4, 6],
  21769. [4, 6], [4, 6], [4, 6], [4, 6],
  21770. [4, 6], [4, 6], [4, 6], [4, 6],
  21771. [4, 6], [4, 6], [4, 6], [4, 6],
  21772. [4, 6], [4, 6], [4, 6], [4, 6],
  21773. [4, 6], [4, 6], [4, 6], [4, 6],
  21774. [4, 6], [4, 6], [4, 6], [4, 6],
  21775. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  21776. [4, 7], [4, 7], [4, 7], [4, 7],
  21777. [4, 7], [4, 7], [4, 7], [4, 7],
  21778. [4, 7], [4, 7], [4, 7], [4, 7],
  21779. [4, 7], [4, 7], [4, 7], [4, 7],
  21780. [4, 7], [4, 7], [4, 7], [4, 7],
  21781. [4, 7], [4, 7], [4, 7], [4, 7],
  21782. [4, 7], [4, 7], [4, 7], [4, 7]
  21783. ];
  21784. var blackTable1 = [
  21785. [-1, -1], [-1, -1], // 000000000000x
  21786. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  21787. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  21788. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  21789. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  21790. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  21791. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  21792. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  21793. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  21794. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  21795. [12, 1984], [12, 1984], // 000000010010x
  21796. [12, 2048], [12, 2048], // 000000010011x
  21797. [12, 2112], [12, 2112], // 000000010100x
  21798. [12, 2176], [12, 2176], // 000000010101x
  21799. [12, 2240], [12, 2240], // 000000010110x
  21800. [12, 2304], [12, 2304], // 000000010111x
  21801. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  21802. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  21803. [12, 2368], [12, 2368], // 000000011100x
  21804. [12, 2432], [12, 2432], // 000000011101x
  21805. [12, 2496], [12, 2496], // 000000011110x
  21806. [12, 2560], [12, 2560], // 000000011111x
  21807. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  21808. [10, 18], [10, 18], [10, 18], [10, 18],
  21809. [12, 52], [12, 52], // 000000100100x
  21810. [13, 640], // 0000001001010
  21811. [13, 704], // 0000001001011
  21812. [13, 768], // 0000001001100
  21813. [13, 832], // 0000001001101
  21814. [12, 55], [12, 55], // 000000100111x
  21815. [12, 56], [12, 56], // 000000101000x
  21816. [13, 1280], // 0000001010010
  21817. [13, 1344], // 0000001010011
  21818. [13, 1408], // 0000001010100
  21819. [13, 1472], // 0000001010101
  21820. [12, 59], [12, 59], // 000000101011x
  21821. [12, 60], [12, 60], // 000000101100x
  21822. [13, 1536], // 0000001011010
  21823. [13, 1600], // 0000001011011
  21824. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  21825. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  21826. [13, 1664], // 0000001100100
  21827. [13, 1728], // 0000001100101
  21828. [12, 320], [12, 320], // 000000110011x
  21829. [12, 384], [12, 384], // 000000110100x
  21830. [12, 448], [12, 448], // 000000110101x
  21831. [13, 512], // 0000001101100
  21832. [13, 576], // 0000001101101
  21833. [12, 53], [12, 53], // 000000110111x
  21834. [12, 54], [12, 54], // 000000111000x
  21835. [13, 896], // 0000001110010
  21836. [13, 960], // 0000001110011
  21837. [13, 1024], // 0000001110100
  21838. [13, 1088], // 0000001110101
  21839. [13, 1152], // 0000001110110
  21840. [13, 1216], // 0000001110111
  21841. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  21842. [10, 64], [10, 64], [10, 64], [10, 64]
  21843. ];
  21844. var blackTable2 = [
  21845. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  21846. [8, 13], [8, 13], [8, 13], [8, 13],
  21847. [8, 13], [8, 13], [8, 13], [8, 13],
  21848. [8, 13], [8, 13], [8, 13], [8, 13],
  21849. [11, 23], [11, 23], // 00000101000x
  21850. [12, 50], // 000001010010
  21851. [12, 51], // 000001010011
  21852. [12, 44], // 000001010100
  21853. [12, 45], // 000001010101
  21854. [12, 46], // 000001010110
  21855. [12, 47], // 000001010111
  21856. [12, 57], // 000001011000
  21857. [12, 58], // 000001011001
  21858. [12, 61], // 000001011010
  21859. [12, 256], // 000001011011
  21860. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  21861. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  21862. [12, 48], // 000001100100
  21863. [12, 49], // 000001100101
  21864. [12, 62], // 000001100110
  21865. [12, 63], // 000001100111
  21866. [12, 30], // 000001101000
  21867. [12, 31], // 000001101001
  21868. [12, 32], // 000001101010
  21869. [12, 33], // 000001101011
  21870. [12, 40], // 000001101100
  21871. [12, 41], // 000001101101
  21872. [11, 22], [11, 22], // 00000110111x
  21873. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  21874. [8, 14], [8, 14], [8, 14], [8, 14],
  21875. [8, 14], [8, 14], [8, 14], [8, 14],
  21876. [8, 14], [8, 14], [8, 14], [8, 14],
  21877. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  21878. [7, 10], [7, 10], [7, 10], [7, 10],
  21879. [7, 10], [7, 10], [7, 10], [7, 10],
  21880. [7, 10], [7, 10], [7, 10], [7, 10],
  21881. [7, 10], [7, 10], [7, 10], [7, 10],
  21882. [7, 10], [7, 10], [7, 10], [7, 10],
  21883. [7, 10], [7, 10], [7, 10], [7, 10],
  21884. [7, 10], [7, 10], [7, 10], [7, 10],
  21885. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  21886. [7, 11], [7, 11], [7, 11], [7, 11],
  21887. [7, 11], [7, 11], [7, 11], [7, 11],
  21888. [7, 11], [7, 11], [7, 11], [7, 11],
  21889. [7, 11], [7, 11], [7, 11], [7, 11],
  21890. [7, 11], [7, 11], [7, 11], [7, 11],
  21891. [7, 11], [7, 11], [7, 11], [7, 11],
  21892. [7, 11], [7, 11], [7, 11], [7, 11],
  21893. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  21894. [9, 15], [9, 15], [9, 15], [9, 15],
  21895. [12, 128], // 000011001000
  21896. [12, 192], // 000011001001
  21897. [12, 26], // 000011001010
  21898. [12, 27], // 000011001011
  21899. [12, 28], // 000011001100
  21900. [12, 29], // 000011001101
  21901. [11, 19], [11, 19], // 00001100111x
  21902. [11, 20], [11, 20], // 00001101000x
  21903. [12, 34], // 000011010010
  21904. [12, 35], // 000011010011
  21905. [12, 36], // 000011010100
  21906. [12, 37], // 000011010101
  21907. [12, 38], // 000011010110
  21908. [12, 39], // 000011010111
  21909. [11, 21], [11, 21], // 00001101100x
  21910. [12, 42], // 000011011010
  21911. [12, 43], // 000011011011
  21912. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  21913. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  21914. [7, 12], [7, 12], [7, 12], [7, 12],
  21915. [7, 12], [7, 12], [7, 12], [7, 12],
  21916. [7, 12], [7, 12], [7, 12], [7, 12],
  21917. [7, 12], [7, 12], [7, 12], [7, 12],
  21918. [7, 12], [7, 12], [7, 12], [7, 12],
  21919. [7, 12], [7, 12], [7, 12], [7, 12],
  21920. [7, 12], [7, 12], [7, 12], [7, 12]
  21921. ];
  21922. var blackTable3 = [
  21923. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  21924. [6, 9], // 000100
  21925. [6, 8], // 000101
  21926. [5, 7], [5, 7], // 00011x
  21927. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  21928. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  21929. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  21930. [3, 1], [3, 1], [3, 1], [3, 1],
  21931. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  21932. [3, 4], [3, 4], [3, 4], [3, 4],
  21933. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  21934. [2, 3], [2, 3], [2, 3], [2, 3],
  21935. [2, 3], [2, 3], [2, 3], [2, 3],
  21936. [2, 3], [2, 3], [2, 3], [2, 3],
  21937. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  21938. [2, 2], [2, 2], [2, 2], [2, 2],
  21939. [2, 2], [2, 2], [2, 2], [2, 2],
  21940. [2, 2], [2, 2], [2, 2], [2, 2]
  21941. ];
  21942. function CCITTFaxStream(str, maybeLength, params) {
  21943. this.str = str;
  21944. this.dict = str.dict;
  21945. params = params || Dict.empty;
  21946. this.encoding = params.get('K') || 0;
  21947. this.eoline = params.get('EndOfLine') || false;
  21948. this.byteAlign = params.get('EncodedByteAlign') || false;
  21949. this.columns = params.get('Columns') || 1728;
  21950. this.rows = params.get('Rows') || 0;
  21951. var eoblock = params.get('EndOfBlock');
  21952. if (eoblock === null || eoblock === undefined) {
  21953. eoblock = true;
  21954. }
  21955. this.eoblock = eoblock;
  21956. this.black = params.get('BlackIs1') || false;
  21957. this.codingLine = new Uint32Array(this.columns + 1);
  21958. this.refLine = new Uint32Array(this.columns + 2);
  21959. this.codingLine[0] = this.columns;
  21960. this.codingPos = 0;
  21961. this.row = 0;
  21962. this.nextLine2D = this.encoding < 0;
  21963. this.inputBits = 0;
  21964. this.inputBuf = 0;
  21965. this.outputBits = 0;
  21966. var code1;
  21967. while ((code1 = this.lookBits(12)) === 0) {
  21968. this.eatBits(1);
  21969. }
  21970. if (code1 === 1) {
  21971. this.eatBits(12);
  21972. }
  21973. if (this.encoding > 0) {
  21974. this.nextLine2D = !this.lookBits(1);
  21975. this.eatBits(1);
  21976. }
  21977. DecodeStream.call(this, maybeLength);
  21978. }
  21979. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  21980. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  21981. while (!this.eof) {
  21982. var c = this.lookChar();
  21983. this.ensureBuffer(this.bufferLength + 1);
  21984. this.buffer[this.bufferLength++] = c;
  21985. }
  21986. };
  21987. CCITTFaxStream.prototype.addPixels =
  21988. function ccittFaxStreamAddPixels(a1, blackPixels) {
  21989. var codingLine = this.codingLine;
  21990. var codingPos = this.codingPos;
  21991. if (a1 > codingLine[codingPos]) {
  21992. if (a1 > this.columns) {
  21993. info('row is wrong length');
  21994. this.err = true;
  21995. a1 = this.columns;
  21996. }
  21997. if ((codingPos & 1) ^ blackPixels) {
  21998. ++codingPos;
  21999. }
  22000. codingLine[codingPos] = a1;
  22001. }
  22002. this.codingPos = codingPos;
  22003. };
  22004. CCITTFaxStream.prototype.addPixelsNeg =
  22005. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22006. var codingLine = this.codingLine;
  22007. var codingPos = this.codingPos;
  22008. if (a1 > codingLine[codingPos]) {
  22009. if (a1 > this.columns) {
  22010. info('row is wrong length');
  22011. this.err = true;
  22012. a1 = this.columns;
  22013. }
  22014. if ((codingPos & 1) ^ blackPixels) {
  22015. ++codingPos;
  22016. }
  22017. codingLine[codingPos] = a1;
  22018. } else if (a1 < codingLine[codingPos]) {
  22019. if (a1 < 0) {
  22020. info('invalid code');
  22021. this.err = true;
  22022. a1 = 0;
  22023. }
  22024. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22025. --codingPos;
  22026. }
  22027. codingLine[codingPos] = a1;
  22028. }
  22029. this.codingPos = codingPos;
  22030. };
  22031. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22032. var refLine = this.refLine;
  22033. var codingLine = this.codingLine;
  22034. var columns = this.columns;
  22035. var refPos, blackPixels, bits, i;
  22036. if (this.outputBits === 0) {
  22037. if (this.eof) {
  22038. return null;
  22039. }
  22040. this.err = false;
  22041. var code1, code2, code3;
  22042. if (this.nextLine2D) {
  22043. for (i = 0; codingLine[i] < columns; ++i) {
  22044. refLine[i] = codingLine[i];
  22045. }
  22046. refLine[i++] = columns;
  22047. refLine[i] = columns;
  22048. codingLine[0] = 0;
  22049. this.codingPos = 0;
  22050. refPos = 0;
  22051. blackPixels = 0;
  22052. while (codingLine[this.codingPos] < columns) {
  22053. code1 = this.getTwoDimCode();
  22054. switch (code1) {
  22055. case twoDimPass:
  22056. this.addPixels(refLine[refPos + 1], blackPixels);
  22057. if (refLine[refPos + 1] < columns) {
  22058. refPos += 2;
  22059. }
  22060. break;
  22061. case twoDimHoriz:
  22062. code1 = code2 = 0;
  22063. if (blackPixels) {
  22064. do {
  22065. code1 += (code3 = this.getBlackCode());
  22066. } while (code3 >= 64);
  22067. do {
  22068. code2 += (code3 = this.getWhiteCode());
  22069. } while (code3 >= 64);
  22070. } else {
  22071. do {
  22072. code1 += (code3 = this.getWhiteCode());
  22073. } while (code3 >= 64);
  22074. do {
  22075. code2 += (code3 = this.getBlackCode());
  22076. } while (code3 >= 64);
  22077. }
  22078. this.addPixels(codingLine[this.codingPos] +
  22079. code1, blackPixels);
  22080. if (codingLine[this.codingPos] < columns) {
  22081. this.addPixels(codingLine[this.codingPos] + code2,
  22082. blackPixels ^ 1);
  22083. }
  22084. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22085. refLine[refPos] < columns) {
  22086. refPos += 2;
  22087. }
  22088. break;
  22089. case twoDimVertR3:
  22090. this.addPixels(refLine[refPos] + 3, blackPixels);
  22091. blackPixels ^= 1;
  22092. if (codingLine[this.codingPos] < columns) {
  22093. ++refPos;
  22094. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22095. refLine[refPos] < columns) {
  22096. refPos += 2;
  22097. }
  22098. }
  22099. break;
  22100. case twoDimVertR2:
  22101. this.addPixels(refLine[refPos] + 2, blackPixels);
  22102. blackPixels ^= 1;
  22103. if (codingLine[this.codingPos] < columns) {
  22104. ++refPos;
  22105. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22106. refLine[refPos] < columns) {
  22107. refPos += 2;
  22108. }
  22109. }
  22110. break;
  22111. case twoDimVertR1:
  22112. this.addPixels(refLine[refPos] + 1, blackPixels);
  22113. blackPixels ^= 1;
  22114. if (codingLine[this.codingPos] < columns) {
  22115. ++refPos;
  22116. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22117. refLine[refPos] < columns) {
  22118. refPos += 2;
  22119. }
  22120. }
  22121. break;
  22122. case twoDimVert0:
  22123. this.addPixels(refLine[refPos], blackPixels);
  22124. blackPixels ^= 1;
  22125. if (codingLine[this.codingPos] < columns) {
  22126. ++refPos;
  22127. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22128. refLine[refPos] < columns) {
  22129. refPos += 2;
  22130. }
  22131. }
  22132. break;
  22133. case twoDimVertL3:
  22134. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22135. blackPixels ^= 1;
  22136. if (codingLine[this.codingPos] < columns) {
  22137. if (refPos > 0) {
  22138. --refPos;
  22139. } else {
  22140. ++refPos;
  22141. }
  22142. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22143. refLine[refPos] < columns) {
  22144. refPos += 2;
  22145. }
  22146. }
  22147. break;
  22148. case twoDimVertL2:
  22149. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22150. blackPixels ^= 1;
  22151. if (codingLine[this.codingPos] < columns) {
  22152. if (refPos > 0) {
  22153. --refPos;
  22154. } else {
  22155. ++refPos;
  22156. }
  22157. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22158. refLine[refPos] < columns) {
  22159. refPos += 2;
  22160. }
  22161. }
  22162. break;
  22163. case twoDimVertL1:
  22164. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22165. blackPixels ^= 1;
  22166. if (codingLine[this.codingPos] < columns) {
  22167. if (refPos > 0) {
  22168. --refPos;
  22169. } else {
  22170. ++refPos;
  22171. }
  22172. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22173. refLine[refPos] < columns) {
  22174. refPos += 2;
  22175. }
  22176. }
  22177. break;
  22178. case EOF:
  22179. this.addPixels(columns, 0);
  22180. this.eof = true;
  22181. break;
  22182. default:
  22183. info('bad 2d code');
  22184. this.addPixels(columns, 0);
  22185. this.err = true;
  22186. }
  22187. }
  22188. } else {
  22189. codingLine[0] = 0;
  22190. this.codingPos = 0;
  22191. blackPixels = 0;
  22192. while (codingLine[this.codingPos] < columns) {
  22193. code1 = 0;
  22194. if (blackPixels) {
  22195. do {
  22196. code1 += (code3 = this.getBlackCode());
  22197. } while (code3 >= 64);
  22198. } else {
  22199. do {
  22200. code1 += (code3 = this.getWhiteCode());
  22201. } while (code3 >= 64);
  22202. }
  22203. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22204. blackPixels ^= 1;
  22205. }
  22206. }
  22207. var gotEOL = false;
  22208. if (this.byteAlign) {
  22209. this.inputBits &= ~7;
  22210. }
  22211. if (!this.eoblock && this.row === this.rows - 1) {
  22212. this.eof = true;
  22213. } else {
  22214. code1 = this.lookBits(12);
  22215. if (this.eoline) {
  22216. while (code1 !== EOF && code1 !== 1) {
  22217. this.eatBits(1);
  22218. code1 = this.lookBits(12);
  22219. }
  22220. } else {
  22221. while (code1 === 0) {
  22222. this.eatBits(1);
  22223. code1 = this.lookBits(12);
  22224. }
  22225. }
  22226. if (code1 === 1) {
  22227. this.eatBits(12);
  22228. gotEOL = true;
  22229. } else if (code1 === EOF) {
  22230. this.eof = true;
  22231. }
  22232. }
  22233. if (!this.eof && this.encoding > 0) {
  22234. this.nextLine2D = !this.lookBits(1);
  22235. this.eatBits(1);
  22236. }
  22237. if (this.eoblock && gotEOL && this.byteAlign) {
  22238. code1 = this.lookBits(12);
  22239. if (code1 === 1) {
  22240. this.eatBits(12);
  22241. if (this.encoding > 0) {
  22242. this.lookBits(1);
  22243. this.eatBits(1);
  22244. }
  22245. if (this.encoding >= 0) {
  22246. for (i = 0; i < 4; ++i) {
  22247. code1 = this.lookBits(12);
  22248. if (code1 !== 1) {
  22249. info('bad rtc code: ' + code1);
  22250. }
  22251. this.eatBits(12);
  22252. if (this.encoding > 0) {
  22253. this.lookBits(1);
  22254. this.eatBits(1);
  22255. }
  22256. }
  22257. }
  22258. this.eof = true;
  22259. }
  22260. } else if (this.err && this.eoline) {
  22261. while (true) {
  22262. code1 = this.lookBits(13);
  22263. if (code1 === EOF) {
  22264. this.eof = true;
  22265. return null;
  22266. }
  22267. if ((code1 >> 1) === 1) {
  22268. break;
  22269. }
  22270. this.eatBits(1);
  22271. }
  22272. this.eatBits(12);
  22273. if (this.encoding > 0) {
  22274. this.eatBits(1);
  22275. this.nextLine2D = !(code1 & 1);
  22276. }
  22277. }
  22278. if (codingLine[0] > 0) {
  22279. this.outputBits = codingLine[this.codingPos = 0];
  22280. } else {
  22281. this.outputBits = codingLine[this.codingPos = 1];
  22282. }
  22283. this.row++;
  22284. }
  22285. var c;
  22286. if (this.outputBits >= 8) {
  22287. c = (this.codingPos & 1) ? 0 : 0xFF;
  22288. this.outputBits -= 8;
  22289. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22290. this.codingPos++;
  22291. this.outputBits = (codingLine[this.codingPos] -
  22292. codingLine[this.codingPos - 1]);
  22293. }
  22294. } else {
  22295. bits = 8;
  22296. c = 0;
  22297. do {
  22298. if (this.outputBits > bits) {
  22299. c <<= bits;
  22300. if (!(this.codingPos & 1)) {
  22301. c |= 0xFF >> (8 - bits);
  22302. }
  22303. this.outputBits -= bits;
  22304. bits = 0;
  22305. } else {
  22306. c <<= this.outputBits;
  22307. if (!(this.codingPos & 1)) {
  22308. c |= 0xFF >> (8 - this.outputBits);
  22309. }
  22310. bits -= this.outputBits;
  22311. this.outputBits = 0;
  22312. if (codingLine[this.codingPos] < columns) {
  22313. this.codingPos++;
  22314. this.outputBits = (codingLine[this.codingPos] -
  22315. codingLine[this.codingPos - 1]);
  22316. } else if (bits > 0) {
  22317. c <<= bits;
  22318. bits = 0;
  22319. }
  22320. }
  22321. } while (bits);
  22322. }
  22323. if (this.black) {
  22324. c ^= 0xFF;
  22325. }
  22326. return c;
  22327. };
  22328. // This functions returns the code found from the table.
  22329. // The start and end parameters set the boundaries for searching the table.
  22330. // The limit parameter is optional. Function returns an array with three
  22331. // values. The first array element indicates whether a valid code is being
  22332. // returned. The second array element is the actual code. The third array
  22333. // element indicates whether EOF was reached.
  22334. CCITTFaxStream.prototype.findTableCode =
  22335. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22336. var limitValue = limit || 0;
  22337. for (var i = start; i <= end; ++i) {
  22338. var code = this.lookBits(i);
  22339. if (code === EOF) {
  22340. return [true, 1, false];
  22341. }
  22342. if (i < end) {
  22343. code <<= end - i;
  22344. }
  22345. if (!limitValue || code >= limitValue) {
  22346. var p = table[code - limitValue];
  22347. if (p[0] === i) {
  22348. this.eatBits(i);
  22349. return [true, p[1], true];
  22350. }
  22351. }
  22352. }
  22353. return [false, 0, false];
  22354. };
  22355. CCITTFaxStream.prototype.getTwoDimCode =
  22356. function ccittFaxStreamGetTwoDimCode() {
  22357. var code = 0;
  22358. var p;
  22359. if (this.eoblock) {
  22360. code = this.lookBits(7);
  22361. p = twoDimTable[code];
  22362. if (p && p[0] > 0) {
  22363. this.eatBits(p[0]);
  22364. return p[1];
  22365. }
  22366. } else {
  22367. var result = this.findTableCode(1, 7, twoDimTable);
  22368. if (result[0] && result[2]) {
  22369. return result[1];
  22370. }
  22371. }
  22372. info('Bad two dim code');
  22373. return EOF;
  22374. };
  22375. CCITTFaxStream.prototype.getWhiteCode =
  22376. function ccittFaxStreamGetWhiteCode() {
  22377. var code = 0;
  22378. var p;
  22379. if (this.eoblock) {
  22380. code = this.lookBits(12);
  22381. if (code === EOF) {
  22382. return 1;
  22383. }
  22384. if ((code >> 5) === 0) {
  22385. p = whiteTable1[code];
  22386. } else {
  22387. p = whiteTable2[code >> 3];
  22388. }
  22389. if (p[0] > 0) {
  22390. this.eatBits(p[0]);
  22391. return p[1];
  22392. }
  22393. } else {
  22394. var result = this.findTableCode(1, 9, whiteTable2);
  22395. if (result[0]) {
  22396. return result[1];
  22397. }
  22398. result = this.findTableCode(11, 12, whiteTable1);
  22399. if (result[0]) {
  22400. return result[1];
  22401. }
  22402. }
  22403. info('bad white code');
  22404. this.eatBits(1);
  22405. return 1;
  22406. };
  22407. CCITTFaxStream.prototype.getBlackCode =
  22408. function ccittFaxStreamGetBlackCode() {
  22409. var code, p;
  22410. if (this.eoblock) {
  22411. code = this.lookBits(13);
  22412. if (code === EOF) {
  22413. return 1;
  22414. }
  22415. if ((code >> 7) === 0) {
  22416. p = blackTable1[code];
  22417. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22418. p = blackTable2[(code >> 1) - 64];
  22419. } else {
  22420. p = blackTable3[code >> 7];
  22421. }
  22422. if (p[0] > 0) {
  22423. this.eatBits(p[0]);
  22424. return p[1];
  22425. }
  22426. } else {
  22427. var result = this.findTableCode(2, 6, blackTable3);
  22428. if (result[0]) {
  22429. return result[1];
  22430. }
  22431. result = this.findTableCode(7, 12, blackTable2, 64);
  22432. if (result[0]) {
  22433. return result[1];
  22434. }
  22435. result = this.findTableCode(10, 13, blackTable1);
  22436. if (result[0]) {
  22437. return result[1];
  22438. }
  22439. }
  22440. info('bad black code');
  22441. this.eatBits(1);
  22442. return 1;
  22443. };
  22444. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22445. var c;
  22446. while (this.inputBits < n) {
  22447. if ((c = this.str.getByte()) === -1) {
  22448. if (this.inputBits === 0) {
  22449. return EOF;
  22450. }
  22451. return ((this.inputBuf << (n - this.inputBits)) &
  22452. (0xFFFF >> (16 - n)));
  22453. }
  22454. this.inputBuf = (this.inputBuf << 8) + c;
  22455. this.inputBits += 8;
  22456. }
  22457. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22458. };
  22459. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22460. if ((this.inputBits -= n) < 0) {
  22461. this.inputBits = 0;
  22462. }
  22463. };
  22464. return CCITTFaxStream;
  22465. })();
  22466. var LZWStream = (function LZWStreamClosure() {
  22467. function LZWStream(str, maybeLength, earlyChange) {
  22468. this.str = str;
  22469. this.dict = str.dict;
  22470. this.cachedData = 0;
  22471. this.bitsCached = 0;
  22472. var maxLzwDictionarySize = 4096;
  22473. var lzwState = {
  22474. earlyChange: earlyChange,
  22475. codeLength: 9,
  22476. nextCode: 258,
  22477. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22478. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22479. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22480. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22481. currentSequenceLength: 0
  22482. };
  22483. for (var i = 0; i < 256; ++i) {
  22484. lzwState.dictionaryValues[i] = i;
  22485. lzwState.dictionaryLengths[i] = 1;
  22486. }
  22487. this.lzwState = lzwState;
  22488. DecodeStream.call(this, maybeLength);
  22489. }
  22490. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22491. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22492. var bitsCached = this.bitsCached;
  22493. var cachedData = this.cachedData;
  22494. while (bitsCached < n) {
  22495. var c = this.str.getByte();
  22496. if (c === -1) {
  22497. this.eof = true;
  22498. return null;
  22499. }
  22500. cachedData = (cachedData << 8) | c;
  22501. bitsCached += 8;
  22502. }
  22503. this.bitsCached = (bitsCached -= n);
  22504. this.cachedData = cachedData;
  22505. this.lastCode = null;
  22506. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22507. };
  22508. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22509. var blockSize = 512;
  22510. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22511. var i, j, q;
  22512. var lzwState = this.lzwState;
  22513. if (!lzwState) {
  22514. return; // eof was found
  22515. }
  22516. var earlyChange = lzwState.earlyChange;
  22517. var nextCode = lzwState.nextCode;
  22518. var dictionaryValues = lzwState.dictionaryValues;
  22519. var dictionaryLengths = lzwState.dictionaryLengths;
  22520. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22521. var codeLength = lzwState.codeLength;
  22522. var prevCode = lzwState.prevCode;
  22523. var currentSequence = lzwState.currentSequence;
  22524. var currentSequenceLength = lzwState.currentSequenceLength;
  22525. var decodedLength = 0;
  22526. var currentBufferLength = this.bufferLength;
  22527. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22528. for (i = 0; i < blockSize; i++) {
  22529. var code = this.readBits(codeLength);
  22530. var hasPrev = currentSequenceLength > 0;
  22531. if (code < 256) {
  22532. currentSequence[0] = code;
  22533. currentSequenceLength = 1;
  22534. } else if (code >= 258) {
  22535. if (code < nextCode) {
  22536. currentSequenceLength = dictionaryLengths[code];
  22537. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22538. currentSequence[j] = dictionaryValues[q];
  22539. q = dictionaryPrevCodes[q];
  22540. }
  22541. } else {
  22542. currentSequence[currentSequenceLength++] = currentSequence[0];
  22543. }
  22544. } else if (code === 256) {
  22545. codeLength = 9;
  22546. nextCode = 258;
  22547. currentSequenceLength = 0;
  22548. continue;
  22549. } else {
  22550. this.eof = true;
  22551. delete this.lzwState;
  22552. break;
  22553. }
  22554. if (hasPrev) {
  22555. dictionaryPrevCodes[nextCode] = prevCode;
  22556. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22557. dictionaryValues[nextCode] = currentSequence[0];
  22558. nextCode++;
  22559. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22560. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22561. 0.6931471805599453 + 1, 12) | 0;
  22562. }
  22563. prevCode = code;
  22564. decodedLength += currentSequenceLength;
  22565. if (estimatedDecodedSize < decodedLength) {
  22566. do {
  22567. estimatedDecodedSize += decodedSizeDelta;
  22568. } while (estimatedDecodedSize < decodedLength);
  22569. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22570. }
  22571. for (j = 0; j < currentSequenceLength; j++) {
  22572. buffer[currentBufferLength++] = currentSequence[j];
  22573. }
  22574. }
  22575. lzwState.nextCode = nextCode;
  22576. lzwState.codeLength = codeLength;
  22577. lzwState.prevCode = prevCode;
  22578. lzwState.currentSequenceLength = currentSequenceLength;
  22579. this.bufferLength = currentBufferLength;
  22580. };
  22581. return LZWStream;
  22582. })();
  22583. var NullStream = (function NullStreamClosure() {
  22584. function NullStream() {
  22585. Stream.call(this, new Uint8Array(0));
  22586. }
  22587. NullStream.prototype = Stream.prototype;
  22588. return NullStream;
  22589. })();
  22590. // TODO refactor to remove dependency on parser.js
  22591. function _setCoreParser(coreParser_) {
  22592. coreParser = coreParser_;
  22593. EOF = coreParser_.EOF;
  22594. Lexer = coreParser_.Lexer;
  22595. }
  22596. exports._setCoreParser = _setCoreParser;
  22597. // TODO refactor to remove dependency on colorspace.js
  22598. function _setCoreColorSpace(coreColorSpace_) {
  22599. coreColorSpace = coreColorSpace_;
  22600. ColorSpace = coreColorSpace_.ColorSpace;
  22601. }
  22602. exports._setCoreColorSpace = _setCoreColorSpace;
  22603. exports.Ascii85Stream = Ascii85Stream;
  22604. exports.AsciiHexStream = AsciiHexStream;
  22605. exports.CCITTFaxStream = CCITTFaxStream;
  22606. exports.DecryptStream = DecryptStream;
  22607. exports.DecodeStream = DecodeStream;
  22608. exports.FlateStream = FlateStream;
  22609. exports.Jbig2Stream = Jbig2Stream;
  22610. exports.JpegStream = JpegStream;
  22611. exports.JpxStream = JpxStream;
  22612. exports.NullStream = NullStream;
  22613. exports.PredictorStream = PredictorStream;
  22614. exports.RunLengthStream = RunLengthStream;
  22615. exports.Stream = Stream;
  22616. exports.StreamsSequenceStream = StreamsSequenceStream;
  22617. exports.StringStream = StringStream;
  22618. exports.LZWStream = LZWStream;
  22619. }));
  22620. (function (root, factory) {
  22621. {
  22622. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  22623. root.pdfjsDisplayWebGL);
  22624. }
  22625. }(this, function (exports, sharedUtil, displayWebGL) {
  22626. var Util = sharedUtil.Util;
  22627. var info = sharedUtil.info;
  22628. var isArray = sharedUtil.isArray;
  22629. var error = sharedUtil.error;
  22630. var WebGLUtils = displayWebGL.WebGLUtils;
  22631. var ShadingIRs = {};
  22632. ShadingIRs.RadialAxial = {
  22633. fromIR: function RadialAxial_fromIR(raw) {
  22634. var type = raw[1];
  22635. var colorStops = raw[2];
  22636. var p0 = raw[3];
  22637. var p1 = raw[4];
  22638. var r0 = raw[5];
  22639. var r1 = raw[6];
  22640. return {
  22641. type: 'Pattern',
  22642. getPattern: function RadialAxial_getPattern(ctx) {
  22643. var grad;
  22644. if (type === 'axial') {
  22645. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  22646. } else if (type === 'radial') {
  22647. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  22648. }
  22649. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  22650. var c = colorStops[i];
  22651. grad.addColorStop(c[0], c[1]);
  22652. }
  22653. return grad;
  22654. }
  22655. };
  22656. }
  22657. };
  22658. var createMeshCanvas = (function createMeshCanvasClosure() {
  22659. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  22660. // Very basic Gouraud-shaded triangle rasterization algorithm.
  22661. var coords = context.coords, colors = context.colors;
  22662. var bytes = data.data, rowSize = data.width * 4;
  22663. var tmp;
  22664. if (coords[p1 + 1] > coords[p2 + 1]) {
  22665. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  22666. }
  22667. if (coords[p2 + 1] > coords[p3 + 1]) {
  22668. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  22669. }
  22670. if (coords[p1 + 1] > coords[p2 + 1]) {
  22671. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  22672. }
  22673. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  22674. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  22675. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  22676. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  22677. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  22678. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  22679. if (y1 >= y3) {
  22680. return;
  22681. }
  22682. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  22683. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  22684. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  22685. var minY = Math.round(y1), maxY = Math.round(y3);
  22686. var xa, car, cag, cab;
  22687. var xb, cbr, cbg, cbb;
  22688. var k;
  22689. for (var y = minY; y <= maxY; y++) {
  22690. if (y < y2) {
  22691. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  22692. xa = x1 - (x1 - x2) * k;
  22693. car = c1r - (c1r - c2r) * k;
  22694. cag = c1g - (c1g - c2g) * k;
  22695. cab = c1b - (c1b - c2b) * k;
  22696. } else {
  22697. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  22698. xa = x2 - (x2 - x3) * k;
  22699. car = c2r - (c2r - c3r) * k;
  22700. cag = c2g - (c2g - c3g) * k;
  22701. cab = c2b - (c2b - c3b) * k;
  22702. }
  22703. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  22704. xb = x1 - (x1 - x3) * k;
  22705. cbr = c1r - (c1r - c3r) * k;
  22706. cbg = c1g - (c1g - c3g) * k;
  22707. cbb = c1b - (c1b - c3b) * k;
  22708. var x1_ = Math.round(Math.min(xa, xb));
  22709. var x2_ = Math.round(Math.max(xa, xb));
  22710. var j = rowSize * y + x1_ * 4;
  22711. for (var x = x1_; x <= x2_; x++) {
  22712. k = (xa - x) / (xa - xb);
  22713. k = k < 0 ? 0 : k > 1 ? 1 : k;
  22714. bytes[j++] = (car - (car - cbr) * k) | 0;
  22715. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  22716. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  22717. bytes[j++] = 255;
  22718. }
  22719. }
  22720. }
  22721. function drawFigure(data, figure, context) {
  22722. var ps = figure.coords;
  22723. var cs = figure.colors;
  22724. var i, ii;
  22725. switch (figure.type) {
  22726. case 'lattice':
  22727. var verticesPerRow = figure.verticesPerRow;
  22728. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  22729. var cols = verticesPerRow - 1;
  22730. for (i = 0; i < rows; i++) {
  22731. var q = i * verticesPerRow;
  22732. for (var j = 0; j < cols; j++, q++) {
  22733. drawTriangle(data, context,
  22734. ps[q], ps[q + 1], ps[q + verticesPerRow],
  22735. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  22736. drawTriangle(data, context,
  22737. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  22738. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  22739. }
  22740. }
  22741. break;
  22742. case 'triangles':
  22743. for (i = 0, ii = ps.length; i < ii; i += 3) {
  22744. drawTriangle(data, context,
  22745. ps[i], ps[i + 1], ps[i + 2],
  22746. cs[i], cs[i + 1], cs[i + 2]);
  22747. }
  22748. break;
  22749. default:
  22750. error('illigal figure');
  22751. break;
  22752. }
  22753. }
  22754. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  22755. backgroundColor, cachedCanvases) {
  22756. // we will increase scale on some weird factor to let antialiasing take
  22757. // care of "rough" edges
  22758. var EXPECTED_SCALE = 1.1;
  22759. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  22760. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  22761. var offsetX = Math.floor(bounds[0]);
  22762. var offsetY = Math.floor(bounds[1]);
  22763. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  22764. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  22765. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  22766. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  22767. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  22768. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  22769. var scaleX = boundsWidth / width;
  22770. var scaleY = boundsHeight / height;
  22771. var context = {
  22772. coords: coords,
  22773. colors: colors,
  22774. offsetX: -offsetX,
  22775. offsetY: -offsetY,
  22776. scaleX: 1 / scaleX,
  22777. scaleY: 1 / scaleY
  22778. };
  22779. var canvas, tmpCanvas, i, ii;
  22780. if (WebGLUtils.isEnabled) {
  22781. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  22782. figures, context);
  22783. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  22784. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  22785. tmpCanvas.context.drawImage(canvas, 0, 0);
  22786. canvas = tmpCanvas.canvas;
  22787. } else {
  22788. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  22789. var tmpCtx = tmpCanvas.context;
  22790. var data = tmpCtx.createImageData(width, height);
  22791. if (backgroundColor) {
  22792. var bytes = data.data;
  22793. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  22794. bytes[i] = backgroundColor[0];
  22795. bytes[i + 1] = backgroundColor[1];
  22796. bytes[i + 2] = backgroundColor[2];
  22797. bytes[i + 3] = 255;
  22798. }
  22799. }
  22800. for (i = 0; i < figures.length; i++) {
  22801. drawFigure(data, figures[i], context);
  22802. }
  22803. tmpCtx.putImageData(data, 0, 0);
  22804. canvas = tmpCanvas.canvas;
  22805. }
  22806. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  22807. scaleX: scaleX, scaleY: scaleY};
  22808. }
  22809. return createMeshCanvas;
  22810. })();
  22811. ShadingIRs.Mesh = {
  22812. fromIR: function Mesh_fromIR(raw) {
  22813. //var type = raw[1];
  22814. var coords = raw[2];
  22815. var colors = raw[3];
  22816. var figures = raw[4];
  22817. var bounds = raw[5];
  22818. var matrix = raw[6];
  22819. //var bbox = raw[7];
  22820. var background = raw[8];
  22821. return {
  22822. type: 'Pattern',
  22823. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  22824. var scale;
  22825. if (shadingFill) {
  22826. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  22827. } else {
  22828. // Obtain scale from matrix and current transformation matrix.
  22829. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  22830. if (matrix) {
  22831. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  22832. scale = [scale[0] * matrixScale[0],
  22833. scale[1] * matrixScale[1]];
  22834. }
  22835. }
  22836. // Rasterizing on the main thread since sending/queue large canvases
  22837. // might cause OOM.
  22838. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  22839. colors, figures, shadingFill ? null : background,
  22840. owner.cachedCanvases);
  22841. if (!shadingFill) {
  22842. ctx.setTransform.apply(ctx, owner.baseTransform);
  22843. if (matrix) {
  22844. ctx.transform.apply(ctx, matrix);
  22845. }
  22846. }
  22847. ctx.translate(temporaryPatternCanvas.offsetX,
  22848. temporaryPatternCanvas.offsetY);
  22849. ctx.scale(temporaryPatternCanvas.scaleX,
  22850. temporaryPatternCanvas.scaleY);
  22851. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  22852. }
  22853. };
  22854. }
  22855. };
  22856. ShadingIRs.Dummy = {
  22857. fromIR: function Dummy_fromIR() {
  22858. return {
  22859. type: 'Pattern',
  22860. getPattern: function Dummy_fromIR_getPattern() {
  22861. return 'hotpink';
  22862. }
  22863. };
  22864. }
  22865. };
  22866. function getShadingPatternFromIR(raw) {
  22867. var shadingIR = ShadingIRs[raw[0]];
  22868. if (!shadingIR) {
  22869. error('Unknown IR type: ' + raw[0]);
  22870. }
  22871. return shadingIR.fromIR(raw);
  22872. }
  22873. var TilingPattern = (function TilingPatternClosure() {
  22874. var PaintType = {
  22875. COLORED: 1,
  22876. UNCOLORED: 2
  22877. };
  22878. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  22879. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  22880. this.operatorList = IR[2];
  22881. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  22882. this.bbox = IR[4];
  22883. this.xstep = IR[5];
  22884. this.ystep = IR[6];
  22885. this.paintType = IR[7];
  22886. this.tilingType = IR[8];
  22887. this.color = color;
  22888. this.canvasGraphicsFactory = canvasGraphicsFactory;
  22889. this.baseTransform = baseTransform;
  22890. this.type = 'Pattern';
  22891. this.ctx = ctx;
  22892. }
  22893. TilingPattern.prototype = {
  22894. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  22895. var operatorList = this.operatorList;
  22896. var bbox = this.bbox;
  22897. var xstep = this.xstep;
  22898. var ystep = this.ystep;
  22899. var paintType = this.paintType;
  22900. var tilingType = this.tilingType;
  22901. var color = this.color;
  22902. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  22903. info('TilingType: ' + tilingType);
  22904. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  22905. var topLeft = [x0, y0];
  22906. // we want the canvas to be as large as the step size
  22907. var botRight = [x0 + xstep, y0 + ystep];
  22908. var width = botRight[0] - topLeft[0];
  22909. var height = botRight[1] - topLeft[1];
  22910. // Obtain scale from matrix and current transformation matrix.
  22911. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  22912. var curMatrixScale = Util.singularValueDecompose2dScale(
  22913. this.baseTransform);
  22914. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  22915. matrixScale[1] * curMatrixScale[1]];
  22916. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  22917. // Use width and height values that are as close as possible to the end
  22918. // result when the pattern is used. Too low value makes the pattern look
  22919. // blurry. Too large value makes it look too crispy.
  22920. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  22921. MAX_PATTERN_SIZE);
  22922. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  22923. MAX_PATTERN_SIZE);
  22924. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  22925. width, height, true);
  22926. var tmpCtx = tmpCanvas.context;
  22927. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  22928. graphics.groupLevel = owner.groupLevel;
  22929. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  22930. this.setScale(width, height, xstep, ystep);
  22931. this.transformToScale(graphics);
  22932. // transform coordinates to pattern space
  22933. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  22934. graphics.transform.apply(graphics, tmpTranslate);
  22935. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  22936. graphics.executeOperatorList(operatorList);
  22937. return tmpCanvas.canvas;
  22938. },
  22939. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  22940. this.scale = [width / xstep, height / ystep];
  22941. },
  22942. transformToScale: function TilingPattern_transformToScale(graphics) {
  22943. var scale = this.scale;
  22944. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  22945. graphics.transform.apply(graphics, tmpScale);
  22946. },
  22947. scaleToContext: function TilingPattern_scaleToContext() {
  22948. var scale = this.scale;
  22949. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  22950. },
  22951. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  22952. if (bbox && isArray(bbox) && bbox.length === 4) {
  22953. var bboxWidth = x1 - x0;
  22954. var bboxHeight = y1 - y0;
  22955. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  22956. graphics.clip();
  22957. graphics.endPath();
  22958. }
  22959. },
  22960. setFillAndStrokeStyleToContext:
  22961. function setFillAndStrokeStyleToContext(context, paintType, color) {
  22962. switch (paintType) {
  22963. case PaintType.COLORED:
  22964. var ctx = this.ctx;
  22965. context.fillStyle = ctx.fillStyle;
  22966. context.strokeStyle = ctx.strokeStyle;
  22967. break;
  22968. case PaintType.UNCOLORED:
  22969. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  22970. context.fillStyle = cssColor;
  22971. context.strokeStyle = cssColor;
  22972. break;
  22973. default:
  22974. error('Unsupported paint type: ' + paintType);
  22975. }
  22976. },
  22977. getPattern: function TilingPattern_getPattern(ctx, owner) {
  22978. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  22979. ctx = this.ctx;
  22980. ctx.setTransform.apply(ctx, this.baseTransform);
  22981. ctx.transform.apply(ctx, this.matrix);
  22982. this.scaleToContext();
  22983. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  22984. }
  22985. };
  22986. return TilingPattern;
  22987. })();
  22988. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  22989. exports.TilingPattern = TilingPattern;
  22990. }));
  22991. (function (root, factory) {
  22992. {
  22993. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  22994. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  22995. }
  22996. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  22997. var PasswordException = sharedUtil.PasswordException;
  22998. var PasswordResponses = sharedUtil.PasswordResponses;
  22999. var bytesToString = sharedUtil.bytesToString;
  23000. var error = sharedUtil.error;
  23001. var isInt = sharedUtil.isInt;
  23002. var stringToBytes = sharedUtil.stringToBytes;
  23003. var utf8StringToString = sharedUtil.utf8StringToString;
  23004. var warn = sharedUtil.warn;
  23005. var Name = corePrimitives.Name;
  23006. var isName = corePrimitives.isName;
  23007. var isDict = corePrimitives.isDict;
  23008. var DecryptStream = coreStream.DecryptStream;
  23009. var ARCFourCipher = (function ARCFourCipherClosure() {
  23010. function ARCFourCipher(key) {
  23011. this.a = 0;
  23012. this.b = 0;
  23013. var s = new Uint8Array(256);
  23014. var i, j = 0, tmp, keyLength = key.length;
  23015. for (i = 0; i < 256; ++i) {
  23016. s[i] = i;
  23017. }
  23018. for (i = 0; i < 256; ++i) {
  23019. tmp = s[i];
  23020. j = (j + tmp + key[i % keyLength]) & 0xFF;
  23021. s[i] = s[j];
  23022. s[j] = tmp;
  23023. }
  23024. this.s = s;
  23025. }
  23026. ARCFourCipher.prototype = {
  23027. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  23028. var i, n = data.length, tmp, tmp2;
  23029. var a = this.a, b = this.b, s = this.s;
  23030. var output = new Uint8Array(n);
  23031. for (i = 0; i < n; ++i) {
  23032. a = (a + 1) & 0xFF;
  23033. tmp = s[a];
  23034. b = (b + tmp) & 0xFF;
  23035. tmp2 = s[b];
  23036. s[a] = tmp2;
  23037. s[b] = tmp;
  23038. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  23039. }
  23040. this.a = a;
  23041. this.b = b;
  23042. return output;
  23043. }
  23044. };
  23045. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  23046. return ARCFourCipher;
  23047. })();
  23048. var calculateMD5 = (function calculateMD5Closure() {
  23049. var r = new Uint8Array([
  23050. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23051. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23052. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23053. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23054. var k = new Int32Array([
  23055. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23056. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23057. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23058. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23059. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23060. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23061. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23062. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23063. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23064. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23065. -145523070, -1120210379, 718787259, -343485551]);
  23066. function hash(data, offset, length) {
  23067. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23068. // pre-processing
  23069. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23070. var padded = new Uint8Array(paddedLength);
  23071. var i, j, n;
  23072. for (i = 0; i < length; ++i) {
  23073. padded[i] = data[offset++];
  23074. }
  23075. padded[i++] = 0x80;
  23076. n = paddedLength - 8;
  23077. while (i < n) {
  23078. padded[i++] = 0;
  23079. }
  23080. padded[i++] = (length << 3) & 0xFF;
  23081. padded[i++] = (length >> 5) & 0xFF;
  23082. padded[i++] = (length >> 13) & 0xFF;
  23083. padded[i++] = (length >> 21) & 0xFF;
  23084. padded[i++] = (length >>> 29) & 0xFF;
  23085. padded[i++] = 0;
  23086. padded[i++] = 0;
  23087. padded[i++] = 0;
  23088. var w = new Int32Array(16);
  23089. for (i = 0; i < paddedLength;) {
  23090. for (j = 0; j < 16; ++j, i += 4) {
  23091. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23092. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23093. }
  23094. var a = h0, b = h1, c = h2, d = h3, f, g;
  23095. for (j = 0; j < 64; ++j) {
  23096. if (j < 16) {
  23097. f = (b & c) | ((~b) & d);
  23098. g = j;
  23099. } else if (j < 32) {
  23100. f = (d & b) | ((~d) & c);
  23101. g = (5 * j + 1) & 15;
  23102. } else if (j < 48) {
  23103. f = b ^ c ^ d;
  23104. g = (3 * j + 5) & 15;
  23105. } else {
  23106. f = c ^ (b | (~d));
  23107. g = (7 * j) & 15;
  23108. }
  23109. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23110. d = c;
  23111. c = b;
  23112. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23113. a = tmp;
  23114. }
  23115. h0 = (h0 + a) | 0;
  23116. h1 = (h1 + b) | 0;
  23117. h2 = (h2 + c) | 0;
  23118. h3 = (h3 + d) | 0;
  23119. }
  23120. return new Uint8Array([
  23121. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23122. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23123. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23124. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23125. ]);
  23126. }
  23127. return hash;
  23128. })();
  23129. var Word64 = (function Word64Closure() {
  23130. function Word64(highInteger, lowInteger) {
  23131. this.high = highInteger | 0;
  23132. this.low = lowInteger | 0;
  23133. }
  23134. Word64.prototype = {
  23135. and: function Word64_and(word) {
  23136. this.high &= word.high;
  23137. this.low &= word.low;
  23138. },
  23139. xor: function Word64_xor(word) {
  23140. this.high ^= word.high;
  23141. this.low ^= word.low;
  23142. },
  23143. or: function Word64_or(word) {
  23144. this.high |= word.high;
  23145. this.low |= word.low;
  23146. },
  23147. shiftRight: function Word64_shiftRight(places) {
  23148. if (places >= 32) {
  23149. this.low = (this.high >>> (places - 32)) | 0;
  23150. this.high = 0;
  23151. } else {
  23152. this.low = (this.low >>> places) | (this.high << (32 - places));
  23153. this.high = (this.high >>> places) | 0;
  23154. }
  23155. },
  23156. shiftLeft: function Word64_shiftLeft(places) {
  23157. if (places >= 32) {
  23158. this.high = this.low << (places - 32);
  23159. this.low = 0;
  23160. } else {
  23161. this.high = (this.high << places) | (this.low >>> (32 - places));
  23162. this.low = this.low << places;
  23163. }
  23164. },
  23165. rotateRight: function Word64_rotateRight(places) {
  23166. var low, high;
  23167. if (places & 32) {
  23168. high = this.low;
  23169. low = this.high;
  23170. } else {
  23171. low = this.low;
  23172. high = this.high;
  23173. }
  23174. places &= 31;
  23175. this.low = (low >>> places) | (high << (32 - places));
  23176. this.high = (high >>> places) | (low << (32 - places));
  23177. },
  23178. not: function Word64_not() {
  23179. this.high = ~this.high;
  23180. this.low = ~this.low;
  23181. },
  23182. add: function Word64_add(word) {
  23183. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  23184. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  23185. if (lowAdd > 0xFFFFFFFF) {
  23186. highAdd += 1;
  23187. }
  23188. this.low = lowAdd | 0;
  23189. this.high = highAdd | 0;
  23190. },
  23191. copyTo: function Word64_copyTo(bytes, offset) {
  23192. bytes[offset] = (this.high >>> 24) & 0xFF;
  23193. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  23194. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  23195. bytes[offset + 3] = this.high & 0xFF;
  23196. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  23197. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  23198. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  23199. bytes[offset + 7] = this.low & 0xFF;
  23200. },
  23201. assign: function Word64_assign(word) {
  23202. this.high = word.high;
  23203. this.low = word.low;
  23204. }
  23205. };
  23206. return Word64;
  23207. })();
  23208. var calculateSHA256 = (function calculateSHA256Closure() {
  23209. function rotr(x, n) {
  23210. return (x >>> n) | (x << 32 - n);
  23211. }
  23212. function ch(x, y, z) {
  23213. return (x & y) ^ (~x & z);
  23214. }
  23215. function maj(x, y, z) {
  23216. return (x & y) ^ (x & z) ^ (y & z);
  23217. }
  23218. function sigma(x) {
  23219. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  23220. }
  23221. function sigmaPrime(x) {
  23222. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  23223. }
  23224. function littleSigma(x) {
  23225. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  23226. }
  23227. function littleSigmaPrime(x) {
  23228. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  23229. }
  23230. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  23231. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  23232. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  23233. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  23234. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  23235. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  23236. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  23237. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  23238. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  23239. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  23240. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  23241. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  23242. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  23243. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  23244. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  23245. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  23246. function hash(data, offset, length) {
  23247. // initial hash values
  23248. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  23249. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  23250. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  23251. // pre-processing
  23252. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  23253. var padded = new Uint8Array(paddedLength);
  23254. var i, j, n;
  23255. for (i = 0; i < length; ++i) {
  23256. padded[i] = data[offset++];
  23257. }
  23258. padded[i++] = 0x80;
  23259. n = paddedLength - 8;
  23260. while (i < n) {
  23261. padded[i++] = 0;
  23262. }
  23263. padded[i++] = 0;
  23264. padded[i++] = 0;
  23265. padded[i++] = 0;
  23266. padded[i++] = (length >>> 29) & 0xFF;
  23267. padded[i++] = (length >> 21) & 0xFF;
  23268. padded[i++] = (length >> 13) & 0xFF;
  23269. padded[i++] = (length >> 5) & 0xFF;
  23270. padded[i++] = (length << 3) & 0xFF;
  23271. var w = new Uint32Array(64);
  23272. // for each 512 bit block
  23273. for (i = 0; i < paddedLength;) {
  23274. for (j = 0; j < 16; ++j) {
  23275. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  23276. (padded[i + 2] << 8) | (padded[i + 3]));
  23277. i += 4;
  23278. }
  23279. for (j = 16; j < 64; ++j) {
  23280. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  23281. littleSigma(w[j - 15]) + w[j - 16] | 0;
  23282. }
  23283. var a = h0, b = h1, c = h2, d = h3, e = h4,
  23284. f = h5, g = h6, h = h7, t1, t2;
  23285. for (j = 0; j < 64; ++j) {
  23286. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  23287. t2 = sigma(a) + maj(a, b, c);
  23288. h = g;
  23289. g = f;
  23290. f = e;
  23291. e = (d + t1) | 0;
  23292. d = c;
  23293. c = b;
  23294. b = a;
  23295. a = (t1 + t2) | 0;
  23296. }
  23297. h0 = (h0 + a) | 0;
  23298. h1 = (h1 + b) | 0;
  23299. h2 = (h2 + c) | 0;
  23300. h3 = (h3 + d) | 0;
  23301. h4 = (h4 + e) | 0;
  23302. h5 = (h5 + f) | 0;
  23303. h6 = (h6 + g) | 0;
  23304. h7 = (h7 + h) | 0;
  23305. }
  23306. return new Uint8Array([
  23307. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  23308. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  23309. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  23310. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  23311. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  23312. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  23313. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  23314. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  23315. ]);
  23316. }
  23317. return hash;
  23318. })();
  23319. var calculateSHA512 = (function calculateSHA512Closure() {
  23320. function ch(result, x, y, z, tmp) {
  23321. result.assign(x);
  23322. result.and(y);
  23323. tmp.assign(x);
  23324. tmp.not();
  23325. tmp.and(z);
  23326. result.xor(tmp);
  23327. }
  23328. function maj(result, x, y, z, tmp) {
  23329. result.assign(x);
  23330. result.and(y);
  23331. tmp.assign(x);
  23332. tmp.and(z);
  23333. result.xor(tmp);
  23334. tmp.assign(y);
  23335. tmp.and(z);
  23336. result.xor(tmp);
  23337. }
  23338. function sigma(result, x, tmp) {
  23339. result.assign(x);
  23340. result.rotateRight(28);
  23341. tmp.assign(x);
  23342. tmp.rotateRight(34);
  23343. result.xor(tmp);
  23344. tmp.assign(x);
  23345. tmp.rotateRight(39);
  23346. result.xor(tmp);
  23347. }
  23348. function sigmaPrime(result, x, tmp) {
  23349. result.assign(x);
  23350. result.rotateRight(14);
  23351. tmp.assign(x);
  23352. tmp.rotateRight(18);
  23353. result.xor(tmp);
  23354. tmp.assign(x);
  23355. tmp.rotateRight(41);
  23356. result.xor(tmp);
  23357. }
  23358. function littleSigma(result, x, tmp) {
  23359. result.assign(x);
  23360. result.rotateRight(1);
  23361. tmp.assign(x);
  23362. tmp.rotateRight(8);
  23363. result.xor(tmp);
  23364. tmp.assign(x);
  23365. tmp.shiftRight(7);
  23366. result.xor(tmp);
  23367. }
  23368. function littleSigmaPrime(result, x, tmp) {
  23369. result.assign(x);
  23370. result.rotateRight(19);
  23371. tmp.assign(x);
  23372. tmp.rotateRight(61);
  23373. result.xor(tmp);
  23374. tmp.assign(x);
  23375. tmp.shiftRight(6);
  23376. result.xor(tmp);
  23377. }
  23378. var k = [
  23379. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  23380. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  23381. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  23382. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  23383. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  23384. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  23385. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  23386. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  23387. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  23388. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  23389. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  23390. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  23391. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  23392. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  23393. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  23394. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  23395. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  23396. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  23397. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  23398. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  23399. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  23400. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  23401. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  23402. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  23403. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  23404. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  23405. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  23406. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  23407. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  23408. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  23409. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  23410. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  23411. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  23412. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  23413. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  23414. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  23415. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  23416. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  23417. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  23418. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  23419. function hash(data, offset, length, mode384) {
  23420. mode384 = !!mode384;
  23421. // initial hash values
  23422. var h0, h1, h2, h3, h4, h5, h6, h7;
  23423. if (!mode384) {
  23424. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  23425. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  23426. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  23427. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  23428. h4 = new Word64(0x510e527f, 0xade682d1);
  23429. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  23430. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  23431. h7 = new Word64(0x5be0cd19, 0x137e2179);
  23432. }
  23433. else {
  23434. // SHA384 is exactly the same
  23435. // except with different starting values and a trimmed result
  23436. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  23437. h1 = new Word64(0x629a292a, 0x367cd507);
  23438. h2 = new Word64(0x9159015a, 0x3070dd17);
  23439. h3 = new Word64(0x152fecd8, 0xf70e5939);
  23440. h4 = new Word64(0x67332667, 0xffc00b31);
  23441. h5 = new Word64(0x8eb44a87, 0x68581511);
  23442. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  23443. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  23444. }
  23445. // pre-processing
  23446. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  23447. var padded = new Uint8Array(paddedLength);
  23448. var i, j, n;
  23449. for (i = 0; i < length; ++i) {
  23450. padded[i] = data[offset++];
  23451. }
  23452. padded[i++] = 0x80;
  23453. n = paddedLength - 16;
  23454. while (i < n) {
  23455. padded[i++] = 0;
  23456. }
  23457. padded[i++] = 0;
  23458. padded[i++] = 0;
  23459. padded[i++] = 0;
  23460. padded[i++] = 0;
  23461. padded[i++] = 0;
  23462. padded[i++] = 0;
  23463. padded[i++] = 0;
  23464. padded[i++] = 0;
  23465. padded[i++] = 0;
  23466. padded[i++] = 0;
  23467. padded[i++] = 0;
  23468. padded[i++] = (length >>> 29) & 0xFF;
  23469. padded[i++] = (length >> 21) & 0xFF;
  23470. padded[i++] = (length >> 13) & 0xFF;
  23471. padded[i++] = (length >> 5) & 0xFF;
  23472. padded[i++] = (length << 3) & 0xFF;
  23473. var w = new Array(80);
  23474. for (i = 0; i < 80; i++) {
  23475. w[i] = new Word64(0, 0);
  23476. }
  23477. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  23478. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  23479. var g = new Word64(0, 0), h = new Word64(0, 0);
  23480. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  23481. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  23482. // for each 1024 bit block
  23483. for (i = 0; i < paddedLength;) {
  23484. for (j = 0; j < 16; ++j) {
  23485. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  23486. (padded[i + 2] << 8) | (padded[i + 3]);
  23487. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  23488. (padded[i + 6]) << 8 | (padded[i + 7]);
  23489. i += 8;
  23490. }
  23491. for (j = 16; j < 80; ++j) {
  23492. tmp3 = w[j];
  23493. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  23494. tmp3.add(w[j - 7]);
  23495. littleSigma(tmp1, w[j - 15], tmp2);
  23496. tmp3.add(tmp1);
  23497. tmp3.add(w[j - 16]);
  23498. }
  23499. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  23500. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  23501. for (j = 0; j < 80; ++j) {
  23502. t1.assign(h);
  23503. sigmaPrime(tmp1, e, tmp2);
  23504. t1.add(tmp1);
  23505. ch(tmp1, e, f, g, tmp2);
  23506. t1.add(tmp1);
  23507. t1.add(k[j]);
  23508. t1.add(w[j]);
  23509. sigma(t2, a, tmp2);
  23510. maj(tmp1, a, b, c, tmp2);
  23511. t2.add(tmp1);
  23512. tmp3 = h;
  23513. h = g;
  23514. g = f;
  23515. f = e;
  23516. d.add(t1);
  23517. e = d;
  23518. d = c;
  23519. c = b;
  23520. b = a;
  23521. tmp3.assign(t1);
  23522. tmp3.add(t2);
  23523. a = tmp3;
  23524. }
  23525. h0.add(a);
  23526. h1.add(b);
  23527. h2.add(c);
  23528. h3.add(d);
  23529. h4.add(e);
  23530. h5.add(f);
  23531. h6.add(g);
  23532. h7.add(h);
  23533. }
  23534. var result;
  23535. if (!mode384) {
  23536. result = new Uint8Array(64);
  23537. h0.copyTo(result,0);
  23538. h1.copyTo(result,8);
  23539. h2.copyTo(result,16);
  23540. h3.copyTo(result,24);
  23541. h4.copyTo(result,32);
  23542. h5.copyTo(result,40);
  23543. h6.copyTo(result,48);
  23544. h7.copyTo(result,56);
  23545. }
  23546. else {
  23547. result = new Uint8Array(48);
  23548. h0.copyTo(result,0);
  23549. h1.copyTo(result,8);
  23550. h2.copyTo(result,16);
  23551. h3.copyTo(result,24);
  23552. h4.copyTo(result,32);
  23553. h5.copyTo(result,40);
  23554. }
  23555. return result;
  23556. }
  23557. return hash;
  23558. })();
  23559. var calculateSHA384 = (function calculateSHA384Closure() {
  23560. function hash(data, offset, length) {
  23561. return calculateSHA512(data, offset, length, true);
  23562. }
  23563. return hash;
  23564. })();
  23565. var NullCipher = (function NullCipherClosure() {
  23566. function NullCipher() {
  23567. }
  23568. NullCipher.prototype = {
  23569. decryptBlock: function NullCipher_decryptBlock(data) {
  23570. return data;
  23571. }
  23572. };
  23573. return NullCipher;
  23574. })();
  23575. var AES128Cipher = (function AES128CipherClosure() {
  23576. var rcon = new Uint8Array([
  23577. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23578. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23579. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23580. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23581. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  23582. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  23583. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  23584. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  23585. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  23586. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  23587. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  23588. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  23589. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  23590. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  23591. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  23592. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  23593. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  23594. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23595. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23596. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23597. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23598. 0x74, 0xe8, 0xcb, 0x8d]);
  23599. var s = new Uint8Array([
  23600. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  23601. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  23602. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  23603. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  23604. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  23605. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  23606. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  23607. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  23608. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  23609. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  23610. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  23611. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  23612. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  23613. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  23614. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  23615. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  23616. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  23617. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  23618. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  23619. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  23620. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  23621. 0xb0, 0x54, 0xbb, 0x16]);
  23622. var inv_s = new Uint8Array([
  23623. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  23624. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  23625. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  23626. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  23627. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  23628. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  23629. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  23630. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  23631. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  23632. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  23633. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  23634. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  23635. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  23636. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  23637. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  23638. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  23639. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  23640. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  23641. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  23642. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  23643. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  23644. 0x55, 0x21, 0x0c, 0x7d]);
  23645. var mixCol = new Uint8Array(256);
  23646. for (var i = 0; i < 256; i++) {
  23647. if (i < 128) {
  23648. mixCol[i] = i << 1;
  23649. } else {
  23650. mixCol[i] = (i << 1) ^ 0x1b;
  23651. }
  23652. }
  23653. var mix = new Uint32Array([
  23654. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  23655. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  23656. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  23657. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  23658. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  23659. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  23660. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  23661. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  23662. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  23663. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  23664. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  23665. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  23666. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  23667. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  23668. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  23669. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  23670. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  23671. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  23672. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  23673. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  23674. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  23675. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  23676. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  23677. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  23678. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  23679. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  23680. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  23681. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  23682. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  23683. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  23684. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  23685. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  23686. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  23687. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  23688. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  23689. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  23690. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  23691. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  23692. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  23693. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  23694. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  23695. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  23696. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  23697. function expandKey128(cipherKey) {
  23698. var b = 176, result = new Uint8Array(b);
  23699. result.set(cipherKey);
  23700. for (var j = 16, i = 1; j < b; ++i) {
  23701. // RotWord
  23702. var t1 = result[j - 3], t2 = result[j - 2],
  23703. t3 = result[j - 1], t4 = result[j - 4];
  23704. // SubWord
  23705. t1 = s[t1];
  23706. t2 = s[t2];
  23707. t3 = s[t3];
  23708. t4 = s[t4];
  23709. // Rcon
  23710. t1 = t1 ^ rcon[i];
  23711. for (var n = 0; n < 4; ++n) {
  23712. result[j] = (t1 ^= result[j - 16]);
  23713. j++;
  23714. result[j] = (t2 ^= result[j - 16]);
  23715. j++;
  23716. result[j] = (t3 ^= result[j - 16]);
  23717. j++;
  23718. result[j] = (t4 ^= result[j - 16]);
  23719. j++;
  23720. }
  23721. }
  23722. return result;
  23723. }
  23724. function decrypt128(input, key) {
  23725. var state = new Uint8Array(16);
  23726. state.set(input);
  23727. var i, j, k;
  23728. var t, u, v;
  23729. // AddRoundKey
  23730. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23731. state[j] ^= key[k];
  23732. }
  23733. for (i = 9; i >= 1; --i) {
  23734. // InvShiftRows
  23735. t = state[13];
  23736. state[13] = state[9];
  23737. state[9] = state[5];
  23738. state[5] = state[1];
  23739. state[1] = t;
  23740. t = state[14];
  23741. u = state[10];
  23742. state[14] = state[6];
  23743. state[10] = state[2];
  23744. state[6] = t;
  23745. state[2] = u;
  23746. t = state[15];
  23747. u = state[11];
  23748. v = state[7];
  23749. state[15] = state[3];
  23750. state[11] = t;
  23751. state[7] = u;
  23752. state[3] = v;
  23753. // InvSubBytes
  23754. for (j = 0; j < 16; ++j) {
  23755. state[j] = inv_s[state[j]];
  23756. }
  23757. // AddRoundKey
  23758. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23759. state[j] ^= key[k];
  23760. }
  23761. // InvMixColumns
  23762. for (j = 0; j < 16; j += 4) {
  23763. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  23764. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  23765. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  23766. (s3 >>> 24) ^ (s3 << 8));
  23767. state[j] = (t >>> 24) & 0xFF;
  23768. state[j + 1] = (t >> 16) & 0xFF;
  23769. state[j + 2] = (t >> 8) & 0xFF;
  23770. state[j + 3] = t & 0xFF;
  23771. }
  23772. }
  23773. // InvShiftRows
  23774. t = state[13];
  23775. state[13] = state[9];
  23776. state[9] = state[5];
  23777. state[5] = state[1];
  23778. state[1] = t;
  23779. t = state[14];
  23780. u = state[10];
  23781. state[14] = state[6];
  23782. state[10] = state[2];
  23783. state[6] = t;
  23784. state[2] = u;
  23785. t = state[15];
  23786. u = state[11];
  23787. v = state[7];
  23788. state[15] = state[3];
  23789. state[11] = t;
  23790. state[7] = u;
  23791. state[3] = v;
  23792. for (j = 0; j < 16; ++j) {
  23793. // InvSubBytes
  23794. state[j] = inv_s[state[j]];
  23795. // AddRoundKey
  23796. state[j] ^= key[j];
  23797. }
  23798. return state;
  23799. }
  23800. function encrypt128(input, key) {
  23801. var t, u, v, k;
  23802. var state = new Uint8Array(16);
  23803. state.set(input);
  23804. for (j = 0; j < 16; ++j) {
  23805. // AddRoundKey
  23806. state[j] ^= key[j];
  23807. }
  23808. for (i = 1; i < 10; i++) {
  23809. //SubBytes
  23810. for (j = 0; j < 16; ++j) {
  23811. state[j] = s[state[j]];
  23812. }
  23813. //ShiftRows
  23814. v = state[1];
  23815. state[1] = state[5];
  23816. state[5] = state[9];
  23817. state[9] = state[13];
  23818. state[13] = v;
  23819. v = state[2];
  23820. u = state[6];
  23821. state[2] = state[10];
  23822. state[6] = state[14];
  23823. state[10] = v;
  23824. state[14] = u;
  23825. v = state[3];
  23826. u = state[7];
  23827. t = state[11];
  23828. state[3] = state[15];
  23829. state[7] = v;
  23830. state[11] = u;
  23831. state[15] = t;
  23832. //MixColumns
  23833. for (var j = 0; j < 16; j += 4) {
  23834. var s0 = state[j + 0], s1 = state[j + 1];
  23835. var s2 = state[j + 2], s3 = state[j + 3];
  23836. t = s0 ^ s1 ^ s2 ^ s3;
  23837. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  23838. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  23839. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  23840. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  23841. }
  23842. //AddRoundKey
  23843. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23844. state[j] ^= key[k];
  23845. }
  23846. }
  23847. //SubBytes
  23848. for (j = 0; j < 16; ++j) {
  23849. state[j] = s[state[j]];
  23850. }
  23851. //ShiftRows
  23852. v = state[1];
  23853. state[1] = state[5];
  23854. state[5] = state[9];
  23855. state[9] = state[13];
  23856. state[13] = v;
  23857. v = state[2];
  23858. u = state[6];
  23859. state[2] = state[10];
  23860. state[6] = state[14];
  23861. state[10] = v;
  23862. state[14] = u;
  23863. v = state[3];
  23864. u = state[7];
  23865. t = state[11];
  23866. state[3] = state[15];
  23867. state[7] = v;
  23868. state[11] = u;
  23869. state[15] = t;
  23870. //AddRoundKey
  23871. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23872. state[j] ^= key[k];
  23873. }
  23874. return state;
  23875. }
  23876. function AES128Cipher(key) {
  23877. this.key = expandKey128(key);
  23878. this.buffer = new Uint8Array(16);
  23879. this.bufferPosition = 0;
  23880. }
  23881. function decryptBlock2(data, finalize) {
  23882. var i, j, ii, sourceLength = data.length,
  23883. buffer = this.buffer, bufferLength = this.bufferPosition,
  23884. result = [], iv = this.iv;
  23885. for (i = 0; i < sourceLength; ++i) {
  23886. buffer[bufferLength] = data[i];
  23887. ++bufferLength;
  23888. if (bufferLength < 16) {
  23889. continue;
  23890. }
  23891. // buffer is full, decrypting
  23892. var plain = decrypt128(buffer, this.key);
  23893. // xor-ing the IV vector to get plain text
  23894. for (j = 0; j < 16; ++j) {
  23895. plain[j] ^= iv[j];
  23896. }
  23897. iv = buffer;
  23898. result.push(plain);
  23899. buffer = new Uint8Array(16);
  23900. bufferLength = 0;
  23901. }
  23902. // saving incomplete buffer
  23903. this.buffer = buffer;
  23904. this.bufferLength = bufferLength;
  23905. this.iv = iv;
  23906. if (result.length === 0) {
  23907. return new Uint8Array([]);
  23908. }
  23909. // combining plain text blocks into one
  23910. var outputLength = 16 * result.length;
  23911. if (finalize) {
  23912. // undo a padding that is described in RFC 2898
  23913. var lastBlock = result[result.length - 1];
  23914. var psLen = lastBlock[15];
  23915. if (psLen <= 16) {
  23916. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  23917. if (lastBlock[i] !== psLen) {
  23918. // Invalid padding, assume that the block has no padding.
  23919. psLen = 0;
  23920. break;
  23921. }
  23922. }
  23923. outputLength -= psLen;
  23924. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  23925. }
  23926. }
  23927. var output = new Uint8Array(outputLength);
  23928. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  23929. output.set(result[i], j);
  23930. }
  23931. return output;
  23932. }
  23933. AES128Cipher.prototype = {
  23934. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  23935. var i, sourceLength = data.length;
  23936. var buffer = this.buffer, bufferLength = this.bufferPosition;
  23937. // waiting for IV values -- they are at the start of the stream
  23938. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  23939. buffer[bufferLength] = data[i];
  23940. }
  23941. if (bufferLength < 16) {
  23942. // need more data
  23943. this.bufferLength = bufferLength;
  23944. return new Uint8Array([]);
  23945. }
  23946. this.iv = buffer;
  23947. this.buffer = new Uint8Array(16);
  23948. this.bufferLength = 0;
  23949. // starting decryption
  23950. this.decryptBlock = decryptBlock2;
  23951. return this.decryptBlock(data.subarray(16), finalize);
  23952. },
  23953. encrypt: function AES128Cipher_encrypt(data, iv) {
  23954. var i, j, ii, sourceLength = data.length,
  23955. buffer = this.buffer, bufferLength = this.bufferPosition,
  23956. result = [];
  23957. if (!iv) {
  23958. iv = new Uint8Array(16);
  23959. }
  23960. for (i = 0; i < sourceLength; ++i) {
  23961. buffer[bufferLength] = data[i];
  23962. ++bufferLength;
  23963. if (bufferLength < 16) {
  23964. continue;
  23965. }
  23966. for (j = 0; j < 16; ++j) {
  23967. buffer[j] ^= iv[j];
  23968. }
  23969. // buffer is full, encrypting
  23970. var cipher = encrypt128(buffer, this.key);
  23971. iv = cipher;
  23972. result.push(cipher);
  23973. buffer = new Uint8Array(16);
  23974. bufferLength = 0;
  23975. }
  23976. // saving incomplete buffer
  23977. this.buffer = buffer;
  23978. this.bufferLength = bufferLength;
  23979. this.iv = iv;
  23980. if (result.length === 0) {
  23981. return new Uint8Array([]);
  23982. }
  23983. // combining plain text blocks into one
  23984. var outputLength = 16 * result.length;
  23985. var output = new Uint8Array(outputLength);
  23986. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  23987. output.set(result[i], j);
  23988. }
  23989. return output;
  23990. }
  23991. };
  23992. return AES128Cipher;
  23993. })();
  23994. var AES256Cipher = (function AES256CipherClosure() {
  23995. var rcon = new Uint8Array([
  23996. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23997. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23998. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23999. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24000. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24001. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24002. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24003. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24004. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24005. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24006. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24007. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24008. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24009. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24010. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24011. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24012. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24013. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24014. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24015. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24016. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24017. 0x74, 0xe8, 0xcb, 0x8d]);
  24018. var s = new Uint8Array([
  24019. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24020. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24021. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24022. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24023. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24024. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24025. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24026. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24027. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24028. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24029. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24030. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24031. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24032. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24033. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24034. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24035. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24036. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24037. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24038. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24039. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24040. 0xb0, 0x54, 0xbb, 0x16]);
  24041. var inv_s = new Uint8Array([
  24042. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24043. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24044. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24045. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24046. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24047. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24048. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24049. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24050. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24051. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24052. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24053. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24054. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24055. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24056. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24057. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24058. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24059. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24060. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24061. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24062. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24063. 0x55, 0x21, 0x0c, 0x7d]);
  24064. var mixCol = new Uint8Array(256);
  24065. for (var i = 0; i < 256; i++) {
  24066. if (i < 128) {
  24067. mixCol[i] = i << 1;
  24068. } else {
  24069. mixCol[i] = (i << 1) ^ 0x1b;
  24070. }
  24071. }
  24072. var mix = new Uint32Array([
  24073. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24074. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24075. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24076. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24077. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24078. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24079. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24080. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24081. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24082. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24083. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24084. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24085. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24086. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24087. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24088. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24089. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24090. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24091. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24092. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24093. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24094. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24095. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24096. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24097. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24098. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24099. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24100. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24101. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24102. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24103. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24104. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24105. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24106. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24107. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24108. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24109. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24110. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24111. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24112. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24113. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24114. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24115. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24116. function expandKey256(cipherKey) {
  24117. var b = 240, result = new Uint8Array(b);
  24118. var r = 1;
  24119. result.set(cipherKey);
  24120. for (var j = 32, i = 1; j < b; ++i) {
  24121. if (j % 32 === 16) {
  24122. t1 = s[t1];
  24123. t2 = s[t2];
  24124. t3 = s[t3];
  24125. t4 = s[t4];
  24126. } else if (j % 32 === 0) {
  24127. // RotWord
  24128. var t1 = result[j - 3], t2 = result[j - 2],
  24129. t3 = result[j - 1], t4 = result[j - 4];
  24130. // SubWord
  24131. t1 = s[t1];
  24132. t2 = s[t2];
  24133. t3 = s[t3];
  24134. t4 = s[t4];
  24135. // Rcon
  24136. t1 = t1 ^ r;
  24137. if ((r <<= 1) >= 256) {
  24138. r = (r ^ 0x1b) & 0xFF;
  24139. }
  24140. }
  24141. for (var n = 0; n < 4; ++n) {
  24142. result[j] = (t1 ^= result[j - 32]);
  24143. j++;
  24144. result[j] = (t2 ^= result[j - 32]);
  24145. j++;
  24146. result[j] = (t3 ^= result[j - 32]);
  24147. j++;
  24148. result[j] = (t4 ^= result[j - 32]);
  24149. j++;
  24150. }
  24151. }
  24152. return result;
  24153. }
  24154. function decrypt256(input, key) {
  24155. var state = new Uint8Array(16);
  24156. state.set(input);
  24157. var i, j, k;
  24158. var t, u, v;
  24159. // AddRoundKey
  24160. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24161. state[j] ^= key[k];
  24162. }
  24163. for (i = 13; i >= 1; --i) {
  24164. // InvShiftRows
  24165. t = state[13];
  24166. state[13] = state[9];
  24167. state[9] = state[5];
  24168. state[5] = state[1];
  24169. state[1] = t;
  24170. t = state[14];
  24171. u = state[10];
  24172. state[14] = state[6];
  24173. state[10] = state[2];
  24174. state[6] = t;
  24175. state[2] = u;
  24176. t = state[15];
  24177. u = state[11];
  24178. v = state[7];
  24179. state[15] = state[3];
  24180. state[11] = t;
  24181. state[7] = u;
  24182. state[3] = v;
  24183. // InvSubBytes
  24184. for (j = 0; j < 16; ++j) {
  24185. state[j] = inv_s[state[j]];
  24186. }
  24187. // AddRoundKey
  24188. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24189. state[j] ^= key[k];
  24190. }
  24191. // InvMixColumns
  24192. for (j = 0; j < 16; j += 4) {
  24193. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24194. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24195. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24196. (s3 >>> 24) ^ (s3 << 8));
  24197. state[j] = (t >>> 24) & 0xFF;
  24198. state[j + 1] = (t >> 16) & 0xFF;
  24199. state[j + 2] = (t >> 8) & 0xFF;
  24200. state[j + 3] = t & 0xFF;
  24201. }
  24202. }
  24203. // InvShiftRows
  24204. t = state[13];
  24205. state[13] = state[9];
  24206. state[9] = state[5];
  24207. state[5] = state[1];
  24208. state[1] = t;
  24209. t = state[14];
  24210. u = state[10];
  24211. state[14] = state[6];
  24212. state[10] = state[2];
  24213. state[6] = t;
  24214. state[2] = u;
  24215. t = state[15];
  24216. u = state[11];
  24217. v = state[7];
  24218. state[15] = state[3];
  24219. state[11] = t;
  24220. state[7] = u;
  24221. state[3] = v;
  24222. for (j = 0; j < 16; ++j) {
  24223. // InvSubBytes
  24224. state[j] = inv_s[state[j]];
  24225. // AddRoundKey
  24226. state[j] ^= key[j];
  24227. }
  24228. return state;
  24229. }
  24230. function encrypt256(input, key) {
  24231. var t, u, v, k;
  24232. var state = new Uint8Array(16);
  24233. state.set(input);
  24234. for (j = 0; j < 16; ++j) {
  24235. // AddRoundKey
  24236. state[j] ^= key[j];
  24237. }
  24238. for (i = 1; i < 14; i++) {
  24239. //SubBytes
  24240. for (j = 0; j < 16; ++j) {
  24241. state[j] = s[state[j]];
  24242. }
  24243. //ShiftRows
  24244. v = state[1];
  24245. state[1] = state[5];
  24246. state[5] = state[9];
  24247. state[9] = state[13];
  24248. state[13] = v;
  24249. v = state[2];
  24250. u = state[6];
  24251. state[2] = state[10];
  24252. state[6] = state[14];
  24253. state[10] = v;
  24254. state[14] = u;
  24255. v = state[3];
  24256. u = state[7];
  24257. t = state[11];
  24258. state[3] = state[15];
  24259. state[7] = v;
  24260. state[11] = u;
  24261. state[15] = t;
  24262. //MixColumns
  24263. for (var j = 0; j < 16; j += 4) {
  24264. var s0 = state[j + 0], s1 = state[j + 1];
  24265. var s2 = state[j + 2], s3 = state[j + 3];
  24266. t = s0 ^ s1 ^ s2 ^ s3;
  24267. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24268. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24269. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24270. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24271. }
  24272. //AddRoundKey
  24273. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24274. state[j] ^= key[k];
  24275. }
  24276. }
  24277. //SubBytes
  24278. for (j = 0; j < 16; ++j) {
  24279. state[j] = s[state[j]];
  24280. }
  24281. //ShiftRows
  24282. v = state[1];
  24283. state[1] = state[5];
  24284. state[5] = state[9];
  24285. state[9] = state[13];
  24286. state[13] = v;
  24287. v = state[2];
  24288. u = state[6];
  24289. state[2] = state[10];
  24290. state[6] = state[14];
  24291. state[10] = v;
  24292. state[14] = u;
  24293. v = state[3];
  24294. u = state[7];
  24295. t = state[11];
  24296. state[3] = state[15];
  24297. state[7] = v;
  24298. state[11] = u;
  24299. state[15] = t;
  24300. //AddRoundKey
  24301. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24302. state[j] ^= key[k];
  24303. }
  24304. return state;
  24305. }
  24306. function AES256Cipher(key) {
  24307. this.key = expandKey256(key);
  24308. this.buffer = new Uint8Array(16);
  24309. this.bufferPosition = 0;
  24310. }
  24311. function decryptBlock2(data, finalize) {
  24312. var i, j, ii, sourceLength = data.length,
  24313. buffer = this.buffer, bufferLength = this.bufferPosition,
  24314. result = [], iv = this.iv;
  24315. for (i = 0; i < sourceLength; ++i) {
  24316. buffer[bufferLength] = data[i];
  24317. ++bufferLength;
  24318. if (bufferLength < 16) {
  24319. continue;
  24320. }
  24321. // buffer is full, decrypting
  24322. var plain = decrypt256(buffer, this.key);
  24323. // xor-ing the IV vector to get plain text
  24324. for (j = 0; j < 16; ++j) {
  24325. plain[j] ^= iv[j];
  24326. }
  24327. iv = buffer;
  24328. result.push(plain);
  24329. buffer = new Uint8Array(16);
  24330. bufferLength = 0;
  24331. }
  24332. // saving incomplete buffer
  24333. this.buffer = buffer;
  24334. this.bufferLength = bufferLength;
  24335. this.iv = iv;
  24336. if (result.length === 0) {
  24337. return new Uint8Array([]);
  24338. }
  24339. // combining plain text blocks into one
  24340. var outputLength = 16 * result.length;
  24341. if (finalize) {
  24342. // undo a padding that is described in RFC 2898
  24343. var lastBlock = result[result.length - 1];
  24344. var psLen = lastBlock[15];
  24345. if (psLen <= 16) {
  24346. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24347. if (lastBlock[i] !== psLen) {
  24348. // Invalid padding, assume that the block has no padding.
  24349. psLen = 0;
  24350. break;
  24351. }
  24352. }
  24353. outputLength -= psLen;
  24354. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24355. }
  24356. }
  24357. var output = new Uint8Array(outputLength);
  24358. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24359. output.set(result[i], j);
  24360. }
  24361. return output;
  24362. }
  24363. AES256Cipher.prototype = {
  24364. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  24365. var i, sourceLength = data.length;
  24366. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24367. // if not supplied an IV wait for IV values
  24368. // they are at the start of the stream
  24369. if (iv) {
  24370. this.iv = iv;
  24371. } else {
  24372. for (i = 0; bufferLength < 16 &&
  24373. i < sourceLength; ++i, ++bufferLength) {
  24374. buffer[bufferLength] = data[i];
  24375. }
  24376. if (bufferLength < 16) {
  24377. //need more data
  24378. this.bufferLength = bufferLength;
  24379. return new Uint8Array([]);
  24380. }
  24381. this.iv = buffer;
  24382. data = data.subarray(16);
  24383. }
  24384. this.buffer = new Uint8Array(16);
  24385. this.bufferLength = 0;
  24386. // starting decryption
  24387. this.decryptBlock = decryptBlock2;
  24388. return this.decryptBlock(data, finalize);
  24389. },
  24390. encrypt: function AES256Cipher_encrypt(data, iv) {
  24391. var i, j, ii, sourceLength = data.length,
  24392. buffer = this.buffer, bufferLength = this.bufferPosition,
  24393. result = [];
  24394. if (!iv) {
  24395. iv = new Uint8Array(16);
  24396. }
  24397. for (i = 0; i < sourceLength; ++i) {
  24398. buffer[bufferLength] = data[i];
  24399. ++bufferLength;
  24400. if (bufferLength < 16) {
  24401. continue;
  24402. }
  24403. for (j = 0; j < 16; ++j) {
  24404. buffer[j] ^= iv[j];
  24405. }
  24406. // buffer is full, encrypting
  24407. var cipher = encrypt256(buffer, this.key);
  24408. this.iv = cipher;
  24409. result.push(cipher);
  24410. buffer = new Uint8Array(16);
  24411. bufferLength = 0;
  24412. }
  24413. // saving incomplete buffer
  24414. this.buffer = buffer;
  24415. this.bufferLength = bufferLength;
  24416. this.iv = iv;
  24417. if (result.length === 0) {
  24418. return new Uint8Array([]);
  24419. }
  24420. // combining plain text blocks into one
  24421. var outputLength = 16 * result.length;
  24422. var output = new Uint8Array(outputLength);
  24423. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24424. output.set(result[i], j);
  24425. }
  24426. return output;
  24427. }
  24428. };
  24429. return AES256Cipher;
  24430. })();
  24431. var PDF17 = (function PDF17Closure() {
  24432. function compareByteArrays(array1, array2) {
  24433. if (array1.length !== array2.length) {
  24434. return false;
  24435. }
  24436. for (var i = 0; i < array1.length; i++) {
  24437. if (array1[i] !== array2[i]) {
  24438. return false;
  24439. }
  24440. }
  24441. return true;
  24442. }
  24443. function PDF17() {
  24444. }
  24445. PDF17.prototype = {
  24446. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  24447. ownerValidationSalt,
  24448. userBytes,
  24449. ownerPassword) {
  24450. var hashData = new Uint8Array(password.length + 56);
  24451. hashData.set(password, 0);
  24452. hashData.set(ownerValidationSalt, password.length);
  24453. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24454. var result = calculateSHA256(hashData, 0, hashData.length);
  24455. return compareByteArrays(result, ownerPassword);
  24456. },
  24457. checkUserPassword: function PDF17_checkUserPassword(password,
  24458. userValidationSalt,
  24459. userPassword) {
  24460. var hashData = new Uint8Array(password.length + 8);
  24461. hashData.set(password, 0);
  24462. hashData.set(userValidationSalt, password.length);
  24463. var result = calculateSHA256(hashData, 0, hashData.length);
  24464. return compareByteArrays(result, userPassword);
  24465. },
  24466. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  24467. ownerEncryption) {
  24468. var hashData = new Uint8Array(password.length + 56);
  24469. hashData.set(password, 0);
  24470. hashData.set(ownerKeySalt, password.length);
  24471. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24472. var key = calculateSHA256(hashData, 0, hashData.length);
  24473. var cipher = new AES256Cipher(key);
  24474. return cipher.decryptBlock(ownerEncryption,
  24475. false,
  24476. new Uint8Array(16));
  24477. },
  24478. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  24479. userEncryption) {
  24480. var hashData = new Uint8Array(password.length + 8);
  24481. hashData.set(password, 0);
  24482. hashData.set(userKeySalt, password.length);
  24483. //key is the decryption key for the UE string
  24484. var key = calculateSHA256(hashData, 0, hashData.length);
  24485. var cipher = new AES256Cipher(key);
  24486. return cipher.decryptBlock(userEncryption,
  24487. false,
  24488. new Uint8Array(16));
  24489. }
  24490. };
  24491. return PDF17;
  24492. })();
  24493. var PDF20 = (function PDF20Closure() {
  24494. function concatArrays(array1, array2) {
  24495. var t = new Uint8Array(array1.length + array2.length);
  24496. t.set(array1, 0);
  24497. t.set(array2, array1.length);
  24498. return t;
  24499. }
  24500. function calculatePDF20Hash(password, input, userBytes) {
  24501. //This refers to Algorithm 2.B as defined in ISO 32000-2
  24502. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  24503. var e = [0];
  24504. var i = 0;
  24505. while (i < 64 || e[e.length - 1] > i - 32) {
  24506. var arrayLength = password.length + k.length + userBytes.length;
  24507. var k1 = new Uint8Array(arrayLength * 64);
  24508. var array = concatArrays(password, k);
  24509. array = concatArrays(array, userBytes);
  24510. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  24511. k1.set(array, pos);
  24512. }
  24513. //AES128 CBC NO PADDING with
  24514. //first 16 bytes of k as the key and the second 16 as the iv.
  24515. var cipher = new AES128Cipher(k.subarray(0, 16));
  24516. e = cipher.encrypt(k1, k.subarray(16, 32));
  24517. //Now we have to take the first 16 bytes of an unsigned
  24518. //big endian integer... and compute the remainder
  24519. //modulo 3.... That is a fairly large number and
  24520. //JavaScript isn't going to handle that well...
  24521. //So we're using a trick that allows us to perform
  24522. //modulo math byte by byte
  24523. var remainder = 0;
  24524. for (var z = 0; z < 16; z++) {
  24525. remainder *= (256 % 3);
  24526. remainder %= 3;
  24527. remainder += ((e[z] >>> 0) % 3);
  24528. remainder %= 3;
  24529. }
  24530. if (remainder === 0) {
  24531. k = calculateSHA256(e, 0, e.length);
  24532. }
  24533. else if (remainder === 1) {
  24534. k = calculateSHA384(e, 0, e.length);
  24535. }
  24536. else if (remainder === 2) {
  24537. k = calculateSHA512(e, 0, e.length);
  24538. }
  24539. i++;
  24540. }
  24541. return k.subarray(0, 32);
  24542. }
  24543. function PDF20() {
  24544. }
  24545. function compareByteArrays(array1, array2) {
  24546. if (array1.length !== array2.length) {
  24547. return false;
  24548. }
  24549. for (var i = 0; i < array1.length; i++) {
  24550. if (array1[i] !== array2[i]) {
  24551. return false;
  24552. }
  24553. }
  24554. return true;
  24555. }
  24556. PDF20.prototype = {
  24557. hash: function PDF20_hash(password, concatBytes, userBytes) {
  24558. return calculatePDF20Hash(password, concatBytes, userBytes);
  24559. },
  24560. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  24561. ownerValidationSalt,
  24562. userBytes,
  24563. ownerPassword) {
  24564. var hashData = new Uint8Array(password.length + 56);
  24565. hashData.set(password, 0);
  24566. hashData.set(ownerValidationSalt, password.length);
  24567. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24568. var result = calculatePDF20Hash(password, hashData, userBytes);
  24569. return compareByteArrays(result, ownerPassword);
  24570. },
  24571. checkUserPassword: function PDF20_checkUserPassword(password,
  24572. userValidationSalt,
  24573. userPassword) {
  24574. var hashData = new Uint8Array(password.length + 8);
  24575. hashData.set(password, 0);
  24576. hashData.set(userValidationSalt, password.length);
  24577. var result = calculatePDF20Hash(password, hashData, []);
  24578. return compareByteArrays(result, userPassword);
  24579. },
  24580. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  24581. ownerEncryption) {
  24582. var hashData = new Uint8Array(password.length + 56);
  24583. hashData.set(password, 0);
  24584. hashData.set(ownerKeySalt, password.length);
  24585. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24586. var key = calculatePDF20Hash(password, hashData, userBytes);
  24587. var cipher = new AES256Cipher(key);
  24588. return cipher.decryptBlock(ownerEncryption,
  24589. false,
  24590. new Uint8Array(16));
  24591. },
  24592. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  24593. userEncryption) {
  24594. var hashData = new Uint8Array(password.length + 8);
  24595. hashData.set(password, 0);
  24596. hashData.set(userKeySalt, password.length);
  24597. //key is the decryption key for the UE string
  24598. var key = calculatePDF20Hash(password, hashData, []);
  24599. var cipher = new AES256Cipher(key);
  24600. return cipher.decryptBlock(userEncryption,
  24601. false,
  24602. new Uint8Array(16));
  24603. }
  24604. };
  24605. return PDF20;
  24606. })();
  24607. var CipherTransform = (function CipherTransformClosure() {
  24608. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  24609. this.stringCipherConstructor = stringCipherConstructor;
  24610. this.streamCipherConstructor = streamCipherConstructor;
  24611. }
  24612. CipherTransform.prototype = {
  24613. createStream: function CipherTransform_createStream(stream, length) {
  24614. var cipher = new this.streamCipherConstructor();
  24615. return new DecryptStream(stream, length,
  24616. function cipherTransformDecryptStream(data, finalize) {
  24617. return cipher.decryptBlock(data, finalize);
  24618. }
  24619. );
  24620. },
  24621. decryptString: function CipherTransform_decryptString(s) {
  24622. var cipher = new this.stringCipherConstructor();
  24623. var data = stringToBytes(s);
  24624. data = cipher.decryptBlock(data, true);
  24625. return bytesToString(data);
  24626. }
  24627. };
  24628. return CipherTransform;
  24629. })();
  24630. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  24631. var defaultPasswordBytes = new Uint8Array([
  24632. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  24633. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  24634. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  24635. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  24636. function createEncryptionKey20(revision, password, ownerPassword,
  24637. ownerValidationSalt, ownerKeySalt, uBytes,
  24638. userPassword, userValidationSalt, userKeySalt,
  24639. ownerEncryption, userEncryption, perms) {
  24640. if (password) {
  24641. var passwordLength = Math.min(127, password.length);
  24642. password = password.subarray(0, passwordLength);
  24643. } else {
  24644. password = [];
  24645. }
  24646. var pdfAlgorithm;
  24647. if (revision === 6) {
  24648. pdfAlgorithm = new PDF20();
  24649. } else {
  24650. pdfAlgorithm = new PDF17();
  24651. }
  24652. if (pdfAlgorithm) {
  24653. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  24654. userPassword)) {
  24655. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  24656. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  24657. ownerValidationSalt,
  24658. uBytes,
  24659. ownerPassword)) {
  24660. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  24661. ownerEncryption);
  24662. }
  24663. }
  24664. return null;
  24665. }
  24666. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  24667. flags, revision, keyLength, encryptMetadata) {
  24668. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  24669. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  24670. if (password) {
  24671. n = Math.min(32, password.length);
  24672. for (; i < n; ++i) {
  24673. hashData[i] = password[i];
  24674. }
  24675. }
  24676. j = 0;
  24677. while (i < 32) {
  24678. hashData[i++] = defaultPasswordBytes[j++];
  24679. }
  24680. // as now the padded password in the hashData[0..i]
  24681. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  24682. hashData[i++] = ownerPassword[j];
  24683. }
  24684. hashData[i++] = flags & 0xFF;
  24685. hashData[i++] = (flags >> 8) & 0xFF;
  24686. hashData[i++] = (flags >> 16) & 0xFF;
  24687. hashData[i++] = (flags >>> 24) & 0xFF;
  24688. for (j = 0, n = fileId.length; j < n; ++j) {
  24689. hashData[i++] = fileId[j];
  24690. }
  24691. if (revision >= 4 && !encryptMetadata) {
  24692. hashData[i++] = 0xFF;
  24693. hashData[i++] = 0xFF;
  24694. hashData[i++] = 0xFF;
  24695. hashData[i++] = 0xFF;
  24696. }
  24697. var hash = calculateMD5(hashData, 0, i);
  24698. var keyLengthInBytes = keyLength >> 3;
  24699. if (revision >= 3) {
  24700. for (j = 0; j < 50; ++j) {
  24701. hash = calculateMD5(hash, 0, keyLengthInBytes);
  24702. }
  24703. }
  24704. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  24705. var cipher, checkData;
  24706. if (revision >= 3) {
  24707. for (i = 0; i < 32; ++i) {
  24708. hashData[i] = defaultPasswordBytes[i];
  24709. }
  24710. for (j = 0, n = fileId.length; j < n; ++j) {
  24711. hashData[i++] = fileId[j];
  24712. }
  24713. cipher = new ARCFourCipher(encryptionKey);
  24714. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  24715. n = encryptionKey.length;
  24716. var derivedKey = new Uint8Array(n), k;
  24717. for (j = 1; j <= 19; ++j) {
  24718. for (k = 0; k < n; ++k) {
  24719. derivedKey[k] = encryptionKey[k] ^ j;
  24720. }
  24721. cipher = new ARCFourCipher(derivedKey);
  24722. checkData = cipher.encryptBlock(checkData);
  24723. }
  24724. for (j = 0, n = checkData.length; j < n; ++j) {
  24725. if (userPassword[j] !== checkData[j]) {
  24726. return null;
  24727. }
  24728. }
  24729. } else {
  24730. cipher = new ARCFourCipher(encryptionKey);
  24731. checkData = cipher.encryptBlock(defaultPasswordBytes);
  24732. for (j = 0, n = checkData.length; j < n; ++j) {
  24733. if (userPassword[j] !== checkData[j]) {
  24734. return null;
  24735. }
  24736. }
  24737. }
  24738. return encryptionKey;
  24739. }
  24740. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  24741. var hashData = new Uint8Array(32), i = 0, j, n;
  24742. n = Math.min(32, password.length);
  24743. for (; i < n; ++i) {
  24744. hashData[i] = password[i];
  24745. }
  24746. j = 0;
  24747. while (i < 32) {
  24748. hashData[i++] = defaultPasswordBytes[j++];
  24749. }
  24750. var hash = calculateMD5(hashData, 0, i);
  24751. var keyLengthInBytes = keyLength >> 3;
  24752. if (revision >= 3) {
  24753. for (j = 0; j < 50; ++j) {
  24754. hash = calculateMD5(hash, 0, hash.length);
  24755. }
  24756. }
  24757. var cipher, userPassword;
  24758. if (revision >= 3) {
  24759. userPassword = ownerPassword;
  24760. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  24761. for (j = 19; j >= 0; j--) {
  24762. for (k = 0; k < keyLengthInBytes; ++k) {
  24763. derivedKey[k] = hash[k] ^ j;
  24764. }
  24765. cipher = new ARCFourCipher(derivedKey);
  24766. userPassword = cipher.encryptBlock(userPassword);
  24767. }
  24768. } else {
  24769. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  24770. userPassword = cipher.encryptBlock(ownerPassword);
  24771. }
  24772. return userPassword;
  24773. }
  24774. var identityName = Name.get('Identity');
  24775. function CipherTransformFactory(dict, fileId, password) {
  24776. var filter = dict.get('Filter');
  24777. if (!isName(filter) || filter.name !== 'Standard') {
  24778. error('unknown encryption method');
  24779. }
  24780. this.dict = dict;
  24781. var algorithm = dict.get('V');
  24782. if (!isInt(algorithm) ||
  24783. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  24784. algorithm !== 5)) {
  24785. error('unsupported encryption algorithm');
  24786. }
  24787. this.algorithm = algorithm;
  24788. var keyLength = dict.get('Length');
  24789. if (!keyLength) {
  24790. // Spec asks to rely on encryption dictionary's Length entry, however
  24791. // some PDFs don't have it. Trying to recover.
  24792. if (algorithm <= 3) {
  24793. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  24794. keyLength = 40;
  24795. } else {
  24796. // Trying to find default handler -- it usually has Length.
  24797. var cfDict = dict.get('CF');
  24798. var streamCryptoName = dict.get('StmF');
  24799. if (isDict(cfDict) && isName(streamCryptoName)) {
  24800. var handlerDict = cfDict.get(streamCryptoName.name);
  24801. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  24802. if (keyLength < 40) {
  24803. // Sometimes it's incorrect value of bits, generators specify bytes.
  24804. keyLength <<= 3;
  24805. }
  24806. }
  24807. }
  24808. }
  24809. if (!isInt(keyLength) ||
  24810. keyLength < 40 || (keyLength % 8) !== 0) {
  24811. error('invalid key length');
  24812. }
  24813. // prepare keys
  24814. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  24815. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  24816. var flags = dict.get('P');
  24817. var revision = dict.get('R');
  24818. // meaningful when V is 4 or 5
  24819. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  24820. dict.get('EncryptMetadata') !== false);
  24821. this.encryptMetadata = encryptMetadata;
  24822. var fileIdBytes = stringToBytes(fileId);
  24823. var passwordBytes;
  24824. if (password) {
  24825. if (revision === 6) {
  24826. try {
  24827. password = utf8StringToString(password);
  24828. } catch (ex) {
  24829. warn('CipherTransformFactory: ' +
  24830. 'Unable to convert UTF8 encoded password.');
  24831. }
  24832. }
  24833. passwordBytes = stringToBytes(password);
  24834. }
  24835. var encryptionKey;
  24836. if (algorithm !== 5) {
  24837. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  24838. ownerPassword, userPassword, flags,
  24839. revision, keyLength, encryptMetadata);
  24840. }
  24841. else {
  24842. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  24843. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  24844. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  24845. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  24846. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  24847. var ownerEncryption = stringToBytes(dict.get('OE'));
  24848. var userEncryption = stringToBytes(dict.get('UE'));
  24849. var perms = stringToBytes(dict.get('Perms'));
  24850. encryptionKey =
  24851. createEncryptionKey20(revision, passwordBytes,
  24852. ownerPassword, ownerValidationSalt,
  24853. ownerKeySalt, uBytes,
  24854. userPassword, userValidationSalt,
  24855. userKeySalt, ownerEncryption,
  24856. userEncryption, perms);
  24857. }
  24858. if (!encryptionKey && !password) {
  24859. throw new PasswordException('No password given',
  24860. PasswordResponses.NEED_PASSWORD);
  24861. } else if (!encryptionKey && password) {
  24862. // Attempting use the password as an owner password
  24863. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  24864. revision, keyLength);
  24865. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  24866. ownerPassword, userPassword, flags,
  24867. revision, keyLength, encryptMetadata);
  24868. }
  24869. if (!encryptionKey) {
  24870. throw new PasswordException('Incorrect Password',
  24871. PasswordResponses.INCORRECT_PASSWORD);
  24872. }
  24873. this.encryptionKey = encryptionKey;
  24874. if (algorithm >= 4) {
  24875. this.cf = dict.get('CF');
  24876. this.stmf = dict.get('StmF') || identityName;
  24877. this.strf = dict.get('StrF') || identityName;
  24878. this.eff = dict.get('EFF') || this.stmf;
  24879. }
  24880. }
  24881. function buildObjectKey(num, gen, encryptionKey, isAes) {
  24882. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  24883. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  24884. key[i] = encryptionKey[i];
  24885. }
  24886. key[i++] = num & 0xFF;
  24887. key[i++] = (num >> 8) & 0xFF;
  24888. key[i++] = (num >> 16) & 0xFF;
  24889. key[i++] = gen & 0xFF;
  24890. key[i++] = (gen >> 8) & 0xFF;
  24891. if (isAes) {
  24892. key[i++] = 0x73;
  24893. key[i++] = 0x41;
  24894. key[i++] = 0x6C;
  24895. key[i++] = 0x54;
  24896. }
  24897. var hash = calculateMD5(key, 0, i);
  24898. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  24899. }
  24900. function buildCipherConstructor(cf, name, num, gen, key) {
  24901. var cryptFilter = cf.get(name.name);
  24902. var cfm;
  24903. if (cryptFilter !== null && cryptFilter !== undefined) {
  24904. cfm = cryptFilter.get('CFM');
  24905. }
  24906. if (!cfm || cfm.name === 'None') {
  24907. return function cipherTransformFactoryBuildCipherConstructorNone() {
  24908. return new NullCipher();
  24909. };
  24910. }
  24911. if ('V2' === cfm.name) {
  24912. return function cipherTransformFactoryBuildCipherConstructorV2() {
  24913. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  24914. };
  24915. }
  24916. if ('AESV2' === cfm.name) {
  24917. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  24918. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  24919. };
  24920. }
  24921. if ('AESV3' === cfm.name) {
  24922. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  24923. return new AES256Cipher(key);
  24924. };
  24925. }
  24926. error('Unknown crypto method');
  24927. }
  24928. CipherTransformFactory.prototype = {
  24929. createCipherTransform:
  24930. function CipherTransformFactory_createCipherTransform(num, gen) {
  24931. if (this.algorithm === 4 || this.algorithm === 5) {
  24932. return new CipherTransform(
  24933. buildCipherConstructor(this.cf, this.stmf,
  24934. num, gen, this.encryptionKey),
  24935. buildCipherConstructor(this.cf, this.strf,
  24936. num, gen, this.encryptionKey));
  24937. }
  24938. // algorithms 1 and 2
  24939. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  24940. var cipherConstructor = function buildCipherCipherConstructor() {
  24941. return new ARCFourCipher(key);
  24942. };
  24943. return new CipherTransform(cipherConstructor, cipherConstructor);
  24944. }
  24945. };
  24946. return CipherTransformFactory;
  24947. })();
  24948. exports.AES128Cipher = AES128Cipher;
  24949. exports.AES256Cipher = AES256Cipher;
  24950. exports.ARCFourCipher = ARCFourCipher;
  24951. exports.CipherTransformFactory = CipherTransformFactory;
  24952. exports.PDF17 = PDF17;
  24953. exports.PDF20 = PDF20;
  24954. exports.calculateMD5 = calculateMD5;
  24955. exports.calculateSHA256 = calculateSHA256;
  24956. exports.calculateSHA384 = calculateSHA384;
  24957. exports.calculateSHA512 = calculateSHA512;
  24958. }));
  24959. (function (root, factory) {
  24960. {
  24961. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  24962. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings);
  24963. }
  24964. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  24965. coreEncodings) {
  24966. var Util = sharedUtil.Util;
  24967. var bytesToString = sharedUtil.bytesToString;
  24968. var error = sharedUtil.error;
  24969. var Stream = coreStream.Stream;
  24970. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  24971. var StandardEncoding = coreEncodings.StandardEncoding;
  24972. var coreFonts; // see _setCoreFonts below
  24973. var CFFParser; // = coreFonts.CFFParser;
  24974. var FontRendererFactory = (function FontRendererFactoryClosure() {
  24975. function getLong(data, offset) {
  24976. return (data[offset] << 24) | (data[offset + 1] << 16) |
  24977. (data[offset + 2] << 8) | data[offset + 3];
  24978. }
  24979. function getUshort(data, offset) {
  24980. return (data[offset] << 8) | data[offset + 1];
  24981. }
  24982. function parseCmap(data, start, end) {
  24983. var offset = (getUshort(data, start + 2) === 1 ?
  24984. getLong(data, start + 8) : getLong(data, start + 16));
  24985. var format = getUshort(data, start + offset);
  24986. var length, ranges, p, i;
  24987. if (format === 4) {
  24988. length = getUshort(data, start + offset + 2);
  24989. var segCount = getUshort(data, start + offset + 6) >> 1;
  24990. p = start + offset + 14;
  24991. ranges = [];
  24992. for (i = 0; i < segCount; i++, p += 2) {
  24993. ranges[i] = {end: getUshort(data, p)};
  24994. }
  24995. p += 2;
  24996. for (i = 0; i < segCount; i++, p += 2) {
  24997. ranges[i].start = getUshort(data, p);
  24998. }
  24999. for (i = 0; i < segCount; i++, p += 2) {
  25000. ranges[i].idDelta = getUshort(data, p);
  25001. }
  25002. for (i = 0; i < segCount; i++, p += 2) {
  25003. var idOffset = getUshort(data, p);
  25004. if (idOffset === 0) {
  25005. continue;
  25006. }
  25007. ranges[i].ids = [];
  25008. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25009. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25010. idOffset += 2;
  25011. }
  25012. }
  25013. return ranges;
  25014. } else if (format === 12) {
  25015. length = getLong(data, start + offset + 4);
  25016. var groups = getLong(data, start + offset + 12);
  25017. p = start + offset + 16;
  25018. ranges = [];
  25019. for (i = 0; i < groups; i++) {
  25020. ranges.push({
  25021. start: getLong(data, p),
  25022. end: getLong(data, p + 4),
  25023. idDelta: getLong(data, p + 8) - getLong(data, p)
  25024. });
  25025. p += 12;
  25026. }
  25027. return ranges;
  25028. }
  25029. error('not supported cmap: ' + format);
  25030. }
  25031. function parseCff(data, start, end) {
  25032. var properties = {};
  25033. var parser = new CFFParser(new Stream(data, start, end - start),
  25034. properties);
  25035. var cff = parser.parse();
  25036. return {
  25037. glyphs: cff.charStrings.objects,
  25038. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25039. cff.topDict.privateDict.subrsIndex.objects),
  25040. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25041. };
  25042. }
  25043. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25044. var itemSize, itemDecode;
  25045. if (isGlyphLocationsLong) {
  25046. itemSize = 4;
  25047. itemDecode = function fontItemDecodeLong(data, offset) {
  25048. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25049. (data[offset + 2] << 8) | data[offset + 3];
  25050. };
  25051. } else {
  25052. itemSize = 2;
  25053. itemDecode = function fontItemDecode(data, offset) {
  25054. return (data[offset] << 9) | (data[offset + 1] << 1);
  25055. };
  25056. }
  25057. var glyphs = [];
  25058. var startOffset = itemDecode(loca, 0);
  25059. for (var j = itemSize; j < loca.length; j += itemSize) {
  25060. var endOffset = itemDecode(loca, j);
  25061. glyphs.push(glyf.subarray(startOffset, endOffset));
  25062. startOffset = endOffset;
  25063. }
  25064. return glyphs;
  25065. }
  25066. function lookupCmap(ranges, unicode) {
  25067. var code = unicode.charCodeAt(0);
  25068. var l = 0, r = ranges.length - 1;
  25069. while (l < r) {
  25070. var c = (l + r + 1) >> 1;
  25071. if (code < ranges[c].start) {
  25072. r = c - 1;
  25073. } else {
  25074. l = c;
  25075. }
  25076. }
  25077. if (ranges[l].start <= code && code <= ranges[l].end) {
  25078. return (ranges[l].idDelta + (ranges[l].ids ?
  25079. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25080. }
  25081. return 0;
  25082. }
  25083. function compileGlyf(code, cmds, font) {
  25084. function moveTo(x, y) {
  25085. cmds.push({cmd: 'moveTo', args: [x, y]});
  25086. }
  25087. function lineTo(x, y) {
  25088. cmds.push({cmd: 'lineTo', args: [x, y]});
  25089. }
  25090. function quadraticCurveTo(xa, ya, x, y) {
  25091. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25092. }
  25093. var i = 0;
  25094. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25095. var flags;
  25096. var x = 0, y = 0;
  25097. i += 10;
  25098. if (numberOfContours < 0) {
  25099. // composite glyph
  25100. do {
  25101. flags = (code[i] << 8) | code[i + 1];
  25102. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25103. i += 4;
  25104. var arg1, arg2;
  25105. if ((flags & 0x01)) {
  25106. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25107. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25108. i += 4;
  25109. } else {
  25110. arg1 = code[i++]; arg2 = code[i++];
  25111. }
  25112. if ((flags & 0x02)) {
  25113. x = arg1;
  25114. y = arg2;
  25115. } else {
  25116. x = 0; y = 0; // TODO "they are points" ?
  25117. }
  25118. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25119. if ((flags & 0x08)) {
  25120. scaleX =
  25121. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25122. i += 2;
  25123. } else if ((flags & 0x40)) {
  25124. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25125. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25126. i += 4;
  25127. } else if ((flags & 0x80)) {
  25128. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25129. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25130. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25131. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25132. i += 8;
  25133. }
  25134. var subglyph = font.glyphs[glyphIndex];
  25135. if (subglyph) {
  25136. cmds.push({cmd: 'save'});
  25137. cmds.push({cmd: 'transform',
  25138. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25139. compileGlyf(subglyph, cmds, font);
  25140. cmds.push({cmd: 'restore'});
  25141. }
  25142. } while ((flags & 0x20));
  25143. } else {
  25144. // simple glyph
  25145. var endPtsOfContours = [];
  25146. var j, jj;
  25147. for (j = 0; j < numberOfContours; j++) {
  25148. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25149. i += 2;
  25150. }
  25151. var instructionLength = (code[i] << 8) | code[i + 1];
  25152. i += 2 + instructionLength; // skipping the instructions
  25153. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25154. var points = [];
  25155. while (points.length < numberOfPoints) {
  25156. flags = code[i++];
  25157. var repeat = 1;
  25158. if ((flags & 0x08)) {
  25159. repeat += code[i++];
  25160. }
  25161. while (repeat-- > 0) {
  25162. points.push({flags: flags});
  25163. }
  25164. }
  25165. for (j = 0; j < numberOfPoints; j++) {
  25166. switch (points[j].flags & 0x12) {
  25167. case 0x00:
  25168. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25169. i += 2;
  25170. break;
  25171. case 0x02:
  25172. x -= code[i++];
  25173. break;
  25174. case 0x12:
  25175. x += code[i++];
  25176. break;
  25177. }
  25178. points[j].x = x;
  25179. }
  25180. for (j = 0; j < numberOfPoints; j++) {
  25181. switch (points[j].flags & 0x24) {
  25182. case 0x00:
  25183. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25184. i += 2;
  25185. break;
  25186. case 0x04:
  25187. y -= code[i++];
  25188. break;
  25189. case 0x24:
  25190. y += code[i++];
  25191. break;
  25192. }
  25193. points[j].y = y;
  25194. }
  25195. var startPoint = 0;
  25196. for (i = 0; i < numberOfContours; i++) {
  25197. var endPoint = endPtsOfContours[i];
  25198. // contours might have implicit points, which is located in the middle
  25199. // between two neighboring off-curve points
  25200. var contour = points.slice(startPoint, endPoint + 1);
  25201. if ((contour[0].flags & 1)) {
  25202. contour.push(contour[0]); // using start point at the contour end
  25203. } else if ((contour[contour.length - 1].flags & 1)) {
  25204. // first is off-curve point, trying to use one from the end
  25205. contour.unshift(contour[contour.length - 1]);
  25206. } else {
  25207. // start and end are off-curve points, creating implicit one
  25208. var p = {
  25209. flags: 1,
  25210. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25211. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25212. };
  25213. contour.unshift(p);
  25214. contour.push(p);
  25215. }
  25216. moveTo(contour[0].x, contour[0].y);
  25217. for (j = 1, jj = contour.length; j < jj; j++) {
  25218. if ((contour[j].flags & 1)) {
  25219. lineTo(contour[j].x, contour[j].y);
  25220. } else if ((contour[j + 1].flags & 1)){
  25221. quadraticCurveTo(contour[j].x, contour[j].y,
  25222. contour[j + 1].x, contour[j + 1].y);
  25223. j++;
  25224. } else {
  25225. quadraticCurveTo(contour[j].x, contour[j].y,
  25226. (contour[j].x + contour[j + 1].x) / 2,
  25227. (contour[j].y + contour[j + 1].y) / 2);
  25228. }
  25229. }
  25230. startPoint = endPoint + 1;
  25231. }
  25232. }
  25233. }
  25234. function compileCharString(code, cmds, font) {
  25235. var stack = [];
  25236. var x = 0, y = 0;
  25237. var stems = 0;
  25238. function moveTo(x, y) {
  25239. cmds.push({cmd: 'moveTo', args: [x, y]});
  25240. }
  25241. function lineTo(x, y) {
  25242. cmds.push({cmd: 'lineTo', args: [x, y]});
  25243. }
  25244. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25245. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  25246. }
  25247. function parse(code) {
  25248. var i = 0;
  25249. while (i < code.length) {
  25250. var stackClean = false;
  25251. var v = code[i++];
  25252. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25253. switch (v) {
  25254. case 1: // hstem
  25255. stems += stack.length >> 1;
  25256. stackClean = true;
  25257. break;
  25258. case 3: // vstem
  25259. stems += stack.length >> 1;
  25260. stackClean = true;
  25261. break;
  25262. case 4: // vmoveto
  25263. y += stack.pop();
  25264. moveTo(x, y);
  25265. stackClean = true;
  25266. break;
  25267. case 5: // rlineto
  25268. while (stack.length > 0) {
  25269. x += stack.shift();
  25270. y += stack.shift();
  25271. lineTo(x, y);
  25272. }
  25273. break;
  25274. case 6: // hlineto
  25275. while (stack.length > 0) {
  25276. x += stack.shift();
  25277. lineTo(x, y);
  25278. if (stack.length === 0) {
  25279. break;
  25280. }
  25281. y += stack.shift();
  25282. lineTo(x, y);
  25283. }
  25284. break;
  25285. case 7: // vlineto
  25286. while (stack.length > 0) {
  25287. y += stack.shift();
  25288. lineTo(x, y);
  25289. if (stack.length === 0) {
  25290. break;
  25291. }
  25292. x += stack.shift();
  25293. lineTo(x, y);
  25294. }
  25295. break;
  25296. case 8: // rrcurveto
  25297. while (stack.length > 0) {
  25298. xa = x + stack.shift(); ya = y + stack.shift();
  25299. xb = xa + stack.shift(); yb = ya + stack.shift();
  25300. x = xb + stack.shift(); y = yb + stack.shift();
  25301. bezierCurveTo(xa, ya, xb, yb, x, y);
  25302. }
  25303. break;
  25304. case 10: // callsubr
  25305. n = stack.pop() + font.subrsBias;
  25306. subrCode = font.subrs[n];
  25307. if (subrCode) {
  25308. parse(subrCode);
  25309. }
  25310. break;
  25311. case 11: // return
  25312. return;
  25313. case 12:
  25314. v = code[i++];
  25315. switch (v) {
  25316. case 34: // flex
  25317. xa = x + stack.shift();
  25318. xb = xa + stack.shift(); y1 = y + stack.shift();
  25319. x = xb + stack.shift();
  25320. bezierCurveTo(xa, y, xb, y1, x, y1);
  25321. xa = x + stack.shift();
  25322. xb = xa + stack.shift();
  25323. x = xb + stack.shift();
  25324. bezierCurveTo(xa, y1, xb, y, x, y);
  25325. break;
  25326. case 35: // flex
  25327. xa = x + stack.shift(); ya = y + stack.shift();
  25328. xb = xa + stack.shift(); yb = ya + stack.shift();
  25329. x = xb + stack.shift(); y = yb + stack.shift();
  25330. bezierCurveTo(xa, ya, xb, yb, x, y);
  25331. xa = x + stack.shift(); ya = y + stack.shift();
  25332. xb = xa + stack.shift(); yb = ya + stack.shift();
  25333. x = xb + stack.shift(); y = yb + stack.shift();
  25334. bezierCurveTo(xa, ya, xb, yb, x, y);
  25335. stack.pop(); // fd
  25336. break;
  25337. case 36: // hflex1
  25338. xa = x + stack.shift(); y1 = y + stack.shift();
  25339. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25340. x = xb + stack.shift();
  25341. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25342. xa = x + stack.shift();
  25343. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25344. x = xb + stack.shift();
  25345. bezierCurveTo(xa, y2, xb, y3, x, y);
  25346. break;
  25347. case 37: // flex1
  25348. var x0 = x, y0 = y;
  25349. xa = x + stack.shift(); ya = y + stack.shift();
  25350. xb = xa + stack.shift(); yb = ya + stack.shift();
  25351. x = xb + stack.shift(); y = yb + stack.shift();
  25352. bezierCurveTo(xa, ya, xb, yb, x, y);
  25353. xa = x + stack.shift(); ya = y + stack.shift();
  25354. xb = xa + stack.shift(); yb = ya + stack.shift();
  25355. x = xb; y = yb;
  25356. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25357. x += stack.shift();
  25358. } else {
  25359. y += stack.shift();
  25360. }
  25361. bezierCurveTo(xa, ya, xb, yb, x, y);
  25362. break;
  25363. default:
  25364. error('unknown operator: 12 ' + v);
  25365. }
  25366. break;
  25367. case 14: // endchar
  25368. if (stack.length >= 4) {
  25369. var achar = stack.pop();
  25370. var bchar = stack.pop();
  25371. y = stack.pop();
  25372. x = stack.pop();
  25373. cmds.push({cmd: 'save'});
  25374. cmds.push({cmd: 'translate', args: [x, y]});
  25375. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25376. font.glyphNameMap[StandardEncoding[achar]]));
  25377. compileCharString(font.glyphs[gid], cmds, font);
  25378. cmds.push({cmd: 'restore'});
  25379. gid = lookupCmap(font.cmap, String.fromCharCode(
  25380. font.glyphNameMap[StandardEncoding[bchar]]));
  25381. compileCharString(font.glyphs[gid], cmds, font);
  25382. }
  25383. return;
  25384. case 18: // hstemhm
  25385. stems += stack.length >> 1;
  25386. stackClean = true;
  25387. break;
  25388. case 19: // hintmask
  25389. stems += stack.length >> 1;
  25390. i += (stems + 7) >> 3;
  25391. stackClean = true;
  25392. break;
  25393. case 20: // cntrmask
  25394. stems += stack.length >> 1;
  25395. i += (stems + 7) >> 3;
  25396. stackClean = true;
  25397. break;
  25398. case 21: // rmoveto
  25399. y += stack.pop();
  25400. x += stack.pop();
  25401. moveTo(x, y);
  25402. stackClean = true;
  25403. break;
  25404. case 22: // hmoveto
  25405. x += stack.pop();
  25406. moveTo(x, y);
  25407. stackClean = true;
  25408. break;
  25409. case 23: // vstemhm
  25410. stems += stack.length >> 1;
  25411. stackClean = true;
  25412. break;
  25413. case 24: // rcurveline
  25414. while (stack.length > 2) {
  25415. xa = x + stack.shift(); ya = y + stack.shift();
  25416. xb = xa + stack.shift(); yb = ya + stack.shift();
  25417. x = xb + stack.shift(); y = yb + stack.shift();
  25418. bezierCurveTo(xa, ya, xb, yb, x, y);
  25419. }
  25420. x += stack.shift();
  25421. y += stack.shift();
  25422. lineTo(x, y);
  25423. break;
  25424. case 25: // rlinecurve
  25425. while (stack.length > 6) {
  25426. x += stack.shift();
  25427. y += stack.shift();
  25428. lineTo(x, y);
  25429. }
  25430. xa = x + stack.shift(); ya = y + stack.shift();
  25431. xb = xa + stack.shift(); yb = ya + stack.shift();
  25432. x = xb + stack.shift(); y = yb + stack.shift();
  25433. bezierCurveTo(xa, ya, xb, yb, x, y);
  25434. break;
  25435. case 26: // vvcurveto
  25436. if (stack.length % 2) {
  25437. x += stack.shift();
  25438. }
  25439. while (stack.length > 0) {
  25440. xa = x; ya = y + stack.shift();
  25441. xb = xa + stack.shift(); yb = ya + stack.shift();
  25442. x = xb; y = yb + stack.shift();
  25443. bezierCurveTo(xa, ya, xb, yb, x, y);
  25444. }
  25445. break;
  25446. case 27: // hhcurveto
  25447. if (stack.length % 2) {
  25448. y += stack.shift();
  25449. }
  25450. while (stack.length > 0) {
  25451. xa = x + stack.shift(); ya = y;
  25452. xb = xa + stack.shift(); yb = ya + stack.shift();
  25453. x = xb + stack.shift(); y = yb;
  25454. bezierCurveTo(xa, ya, xb, yb, x, y);
  25455. }
  25456. break;
  25457. case 28:
  25458. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25459. i += 2;
  25460. break;
  25461. case 29: // callgsubr
  25462. n = stack.pop() + font.gsubrsBias;
  25463. subrCode = font.gsubrs[n];
  25464. if (subrCode) {
  25465. parse(subrCode);
  25466. }
  25467. break;
  25468. case 30: // vhcurveto
  25469. while (stack.length > 0) {
  25470. xa = x; ya = y + stack.shift();
  25471. xb = xa + stack.shift(); yb = ya + stack.shift();
  25472. x = xb + stack.shift();
  25473. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25474. bezierCurveTo(xa, ya, xb, yb, x, y);
  25475. if (stack.length === 0) {
  25476. break;
  25477. }
  25478. xa = x + stack.shift(); ya = y;
  25479. xb = xa + stack.shift(); yb = ya + stack.shift();
  25480. y = yb + stack.shift();
  25481. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25482. bezierCurveTo(xa, ya, xb, yb, x, y);
  25483. }
  25484. break;
  25485. case 31: // hvcurveto
  25486. while (stack.length > 0) {
  25487. xa = x + stack.shift(); ya = y;
  25488. xb = xa + stack.shift(); yb = ya + stack.shift();
  25489. y = yb + stack.shift();
  25490. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25491. bezierCurveTo(xa, ya, xb, yb, x, y);
  25492. if (stack.length === 0) {
  25493. break;
  25494. }
  25495. xa = x; ya = y + stack.shift();
  25496. xb = xa + stack.shift(); yb = ya + stack.shift();
  25497. x = xb + stack.shift();
  25498. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25499. bezierCurveTo(xa, ya, xb, yb, x, y);
  25500. }
  25501. break;
  25502. default:
  25503. if (v < 32) {
  25504. error('unknown operator: ' + v);
  25505. }
  25506. if (v < 247) {
  25507. stack.push(v - 139);
  25508. } else if (v < 251) {
  25509. stack.push((v - 247) * 256 + code[i++] + 108);
  25510. } else if (v < 255) {
  25511. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25512. } else {
  25513. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25514. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25515. i += 4;
  25516. }
  25517. break;
  25518. }
  25519. if (stackClean) {
  25520. stack.length = 0;
  25521. }
  25522. }
  25523. }
  25524. parse(code);
  25525. }
  25526. var noop = '';
  25527. function CompiledFont(fontMatrix) {
  25528. this.compiledGlyphs = Object.create(null);
  25529. this.fontMatrix = fontMatrix;
  25530. }
  25531. CompiledFont.prototype = {
  25532. getPathJs: function (unicode) {
  25533. var gid = lookupCmap(this.cmap, unicode);
  25534. var fn = this.compiledGlyphs[gid];
  25535. if (!fn) {
  25536. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25537. }
  25538. return fn;
  25539. },
  25540. compileGlyph: function (code) {
  25541. if (!code || code.length === 0 || code[0] === 14) {
  25542. return noop;
  25543. }
  25544. var cmds = [];
  25545. cmds.push({cmd: 'save'});
  25546. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  25547. cmds.push({cmd: 'scale', args: ['size', '-size']});
  25548. this.compileGlyphImpl(code, cmds);
  25549. cmds.push({cmd: 'restore'});
  25550. return cmds;
  25551. },
  25552. compileGlyphImpl: function () {
  25553. error('Children classes should implement this.');
  25554. },
  25555. hasBuiltPath: function (unicode) {
  25556. var gid = lookupCmap(this.cmap, unicode);
  25557. return gid in this.compiledGlyphs;
  25558. }
  25559. };
  25560. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25561. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25562. CompiledFont.call(this, fontMatrix);
  25563. this.glyphs = glyphs;
  25564. this.cmap = cmap;
  25565. this.compiledGlyphs = [];
  25566. }
  25567. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25568. compileGlyphImpl: function (code, cmds) {
  25569. compileGlyf(code, cmds, this);
  25570. }
  25571. });
  25572. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25573. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25574. CompiledFont.call(this, fontMatrix);
  25575. this.glyphs = cffInfo.glyphs;
  25576. this.gsubrs = cffInfo.gsubrs || [];
  25577. this.subrs = cffInfo.subrs || [];
  25578. this.cmap = cmap;
  25579. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  25580. this.compiledGlyphs = [];
  25581. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25582. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25583. this.subrsBias = (this.subrs.length < 1240 ?
  25584. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25585. }
  25586. Util.inherit(Type2Compiled, CompiledFont, {
  25587. compileGlyphImpl: function (code, cmds) {
  25588. compileCharString(code, cmds, this);
  25589. }
  25590. });
  25591. return {
  25592. create: function FontRendererFactory_create(font) {
  25593. var data = new Uint8Array(font.data);
  25594. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25595. var numTables = getUshort(data, 4);
  25596. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25597. var tag = bytesToString(data.subarray(p, p + 4));
  25598. var offset = getLong(data, p + 8);
  25599. var length = getLong(data, p + 12);
  25600. switch (tag) {
  25601. case 'cmap':
  25602. cmap = parseCmap(data, offset, offset + length);
  25603. break;
  25604. case 'glyf':
  25605. glyf = data.subarray(offset, offset + length);
  25606. break;
  25607. case 'loca':
  25608. loca = data.subarray(offset, offset + length);
  25609. break;
  25610. case 'head':
  25611. unitsPerEm = getUshort(data, offset + 18);
  25612. indexToLocFormat = getUshort(data, offset + 50);
  25613. break;
  25614. case 'CFF ':
  25615. cff = parseCff(data, offset, offset + length);
  25616. break;
  25617. }
  25618. }
  25619. if (glyf) {
  25620. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25621. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25622. return new TrueTypeCompiled(
  25623. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25624. } else {
  25625. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25626. }
  25627. }
  25628. };
  25629. })();
  25630. // TODO refactor to remove cyclic dependency on fonts.js
  25631. function _setCoreFonts(coreFonts_) {
  25632. coreFonts = coreFonts_;
  25633. CFFParser = coreFonts_.CFFParser;
  25634. }
  25635. exports._setCoreFonts = _setCoreFonts;
  25636. exports.FontRendererFactory = FontRendererFactory;
  25637. }));
  25638. (function (root, factory) {
  25639. {
  25640. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  25641. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  25642. }
  25643. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  25644. var MissingDataException = sharedUtil.MissingDataException;
  25645. var StreamType = sharedUtil.StreamType;
  25646. var assert = sharedUtil.assert;
  25647. var error = sharedUtil.error;
  25648. var info = sharedUtil.info;
  25649. var isArray = sharedUtil.isArray;
  25650. var isInt = sharedUtil.isInt;
  25651. var isNum = sharedUtil.isNum;
  25652. var isString = sharedUtil.isString;
  25653. var warn = sharedUtil.warn;
  25654. var Cmd = corePrimitives.Cmd;
  25655. var Dict = corePrimitives.Dict;
  25656. var Name = corePrimitives.Name;
  25657. var Ref = corePrimitives.Ref;
  25658. var isCmd = corePrimitives.isCmd;
  25659. var isDict = corePrimitives.isDict;
  25660. var isName = corePrimitives.isName;
  25661. var Ascii85Stream = coreStream.Ascii85Stream;
  25662. var AsciiHexStream = coreStream.AsciiHexStream;
  25663. var CCITTFaxStream = coreStream.CCITTFaxStream;
  25664. var FlateStream = coreStream.FlateStream;
  25665. var Jbig2Stream = coreStream.Jbig2Stream;
  25666. var JpegStream = coreStream.JpegStream;
  25667. var JpxStream = coreStream.JpxStream;
  25668. var LZWStream = coreStream.LZWStream;
  25669. var NullStream = coreStream.NullStream;
  25670. var PredictorStream = coreStream.PredictorStream;
  25671. var RunLengthStream = coreStream.RunLengthStream;
  25672. var EOF = {};
  25673. function isEOF(v) {
  25674. return (v === EOF);
  25675. }
  25676. var MAX_LENGTH_TO_CACHE = 1000;
  25677. var Parser = (function ParserClosure() {
  25678. function Parser(lexer, allowStreams, xref) {
  25679. this.lexer = lexer;
  25680. this.allowStreams = allowStreams;
  25681. this.xref = xref;
  25682. this.imageCache = Object.create(null);
  25683. this.refill();
  25684. }
  25685. Parser.prototype = {
  25686. refill: function Parser_refill() {
  25687. this.buf1 = this.lexer.getObj();
  25688. this.buf2 = this.lexer.getObj();
  25689. },
  25690. shift: function Parser_shift() {
  25691. if (isCmd(this.buf2, 'ID')) {
  25692. this.buf1 = this.buf2;
  25693. this.buf2 = null;
  25694. } else {
  25695. this.buf1 = this.buf2;
  25696. this.buf2 = this.lexer.getObj();
  25697. }
  25698. },
  25699. tryShift: function Parser_tryShift() {
  25700. try {
  25701. this.shift();
  25702. return true;
  25703. } catch (e) {
  25704. if (e instanceof MissingDataException) {
  25705. throw e;
  25706. }
  25707. // Upon failure, the caller should reset this.lexer.pos to a known good
  25708. // state and call this.shift() twice to reset the buffers.
  25709. return false;
  25710. }
  25711. },
  25712. getObj: function Parser_getObj(cipherTransform) {
  25713. var buf1 = this.buf1;
  25714. this.shift();
  25715. if (buf1 instanceof Cmd) {
  25716. switch (buf1.cmd) {
  25717. case 'BI': // inline image
  25718. return this.makeInlineImage(cipherTransform);
  25719. case '[': // array
  25720. var array = [];
  25721. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  25722. array.push(this.getObj(cipherTransform));
  25723. }
  25724. if (isEOF(this.buf1)) {
  25725. error('End of file inside array');
  25726. }
  25727. this.shift();
  25728. return array;
  25729. case '<<': // dictionary or stream
  25730. var dict = new Dict(this.xref);
  25731. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  25732. if (!isName(this.buf1)) {
  25733. info('Malformed dictionary: key must be a name object');
  25734. this.shift();
  25735. continue;
  25736. }
  25737. var key = this.buf1.name;
  25738. this.shift();
  25739. if (isEOF(this.buf1)) {
  25740. break;
  25741. }
  25742. dict.set(key, this.getObj(cipherTransform));
  25743. }
  25744. if (isEOF(this.buf1)) {
  25745. error('End of file inside dictionary');
  25746. }
  25747. // Stream objects are not allowed inside content streams or
  25748. // object streams.
  25749. if (isCmd(this.buf2, 'stream')) {
  25750. return (this.allowStreams ?
  25751. this.makeStream(dict, cipherTransform) : dict);
  25752. }
  25753. this.shift();
  25754. return dict;
  25755. default: // simple object
  25756. return buf1;
  25757. }
  25758. }
  25759. if (isInt(buf1)) { // indirect reference or integer
  25760. var num = buf1;
  25761. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  25762. var ref = new Ref(num, this.buf1);
  25763. this.shift();
  25764. this.shift();
  25765. return ref;
  25766. }
  25767. return num;
  25768. }
  25769. if (isString(buf1)) { // string
  25770. var str = buf1;
  25771. if (cipherTransform) {
  25772. str = cipherTransform.decryptString(str);
  25773. }
  25774. return str;
  25775. }
  25776. // simple object
  25777. return buf1;
  25778. },
  25779. /**
  25780. * Find the end of the stream by searching for the /EI\s/.
  25781. * @returns {number} The inline stream length.
  25782. */
  25783. findDefaultInlineStreamEnd:
  25784. function Parser_findDefaultInlineStreamEnd(stream) {
  25785. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  25786. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  25787. while ((ch = stream.getByte()) !== -1) {
  25788. if (state === 0) {
  25789. state = (ch === E) ? 1 : 0;
  25790. } else if (state === 1) {
  25791. state = (ch === I) ? 2 : 0;
  25792. } else {
  25793. assert(state === 2);
  25794. if (ch === SPACE || ch === LF || ch === CR) {
  25795. // Let's check the next five bytes are ASCII... just be sure.
  25796. n = 5;
  25797. followingBytes = stream.peekBytes(n);
  25798. for (i = 0; i < n; i++) {
  25799. ch = followingBytes[i];
  25800. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  25801. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  25802. // it's binary stuff. Resetting the state.
  25803. state = 0;
  25804. break;
  25805. }
  25806. }
  25807. if (state === 2) {
  25808. break; // Finished!
  25809. }
  25810. } else {
  25811. state = 0;
  25812. }
  25813. }
  25814. }
  25815. return ((stream.pos - 4) - startPos);
  25816. },
  25817. /**
  25818. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  25819. * @returns {number} The inline stream length.
  25820. */
  25821. findDCTDecodeInlineStreamEnd:
  25822. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  25823. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  25824. while ((b = stream.getByte()) !== -1) {
  25825. if (b !== 0xFF) { // Not a valid marker.
  25826. continue;
  25827. }
  25828. switch (stream.getByte()) {
  25829. case 0x00: // Byte stuffing.
  25830. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  25831. break;
  25832. case 0xFF: // Fill byte.
  25833. // Avoid skipping a valid marker, resetting the stream position.
  25834. stream.skip(-1);
  25835. break;
  25836. case 0xD9: // EOI
  25837. foundEOI = true;
  25838. break;
  25839. case 0xC0: // SOF0
  25840. case 0xC1: // SOF1
  25841. case 0xC2: // SOF2
  25842. case 0xC3: // SOF3
  25843. case 0xC5: // SOF5
  25844. case 0xC6: // SOF6
  25845. case 0xC7: // SOF7
  25846. case 0xC9: // SOF9
  25847. case 0xCA: // SOF10
  25848. case 0xCB: // SOF11
  25849. case 0xCD: // SOF13
  25850. case 0xCE: // SOF14
  25851. case 0xCF: // SOF15
  25852. case 0xC4: // DHT
  25853. case 0xCC: // DAC
  25854. case 0xDA: // SOS
  25855. case 0xDB: // DQT
  25856. case 0xDC: // DNL
  25857. case 0xDD: // DRI
  25858. case 0xDE: // DHP
  25859. case 0xDF: // EXP
  25860. case 0xE0: // APP0
  25861. case 0xE1: // APP1
  25862. case 0xE2: // APP2
  25863. case 0xE3: // APP3
  25864. case 0xE4: // APP4
  25865. case 0xE5: // APP5
  25866. case 0xE6: // APP6
  25867. case 0xE7: // APP7
  25868. case 0xE8: // APP8
  25869. case 0xE9: // APP9
  25870. case 0xEA: // APP10
  25871. case 0xEB: // APP11
  25872. case 0xEC: // APP12
  25873. case 0xED: // APP13
  25874. case 0xEE: // APP14
  25875. case 0xEF: // APP15
  25876. case 0xFE: // COM
  25877. // The marker should be followed by the length of the segment.
  25878. markerLength = stream.getUint16();
  25879. if (markerLength > 2) {
  25880. // |markerLength| contains the byte length of the marker segment,
  25881. // including its own length (2 bytes) and excluding the marker.
  25882. stream.skip(markerLength - 2); // Jump to the next marker.
  25883. } else {
  25884. // The marker length is invalid, resetting the stream position.
  25885. stream.skip(-2);
  25886. }
  25887. break;
  25888. }
  25889. if (foundEOI) {
  25890. break;
  25891. }
  25892. }
  25893. length = stream.pos - startPos;
  25894. if (b === -1) {
  25895. warn('Inline DCTDecode image stream: ' +
  25896. 'EOI marker not found, searching for /EI/ instead.');
  25897. stream.skip(-length); // Reset the stream position.
  25898. return this.findDefaultInlineStreamEnd(stream);
  25899. }
  25900. this.inlineStreamSkipEI(stream);
  25901. return length;
  25902. },
  25903. /**
  25904. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  25905. * @returns {number} The inline stream length.
  25906. */
  25907. findASCII85DecodeInlineStreamEnd:
  25908. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  25909. var TILDE = 0x7E, GT = 0x3E;
  25910. var startPos = stream.pos, ch, length;
  25911. while ((ch = stream.getByte()) !== -1) {
  25912. if (ch === TILDE && stream.peekByte() === GT) {
  25913. stream.skip();
  25914. break;
  25915. }
  25916. }
  25917. length = stream.pos - startPos;
  25918. if (ch === -1) {
  25919. warn('Inline ASCII85Decode image stream: ' +
  25920. 'EOD marker not found, searching for /EI/ instead.');
  25921. stream.skip(-length); // Reset the stream position.
  25922. return this.findDefaultInlineStreamEnd(stream);
  25923. }
  25924. this.inlineStreamSkipEI(stream);
  25925. return length;
  25926. },
  25927. /**
  25928. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  25929. * @returns {number} The inline stream length.
  25930. */
  25931. findASCIIHexDecodeInlineStreamEnd:
  25932. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  25933. var GT = 0x3E;
  25934. var startPos = stream.pos, ch, length;
  25935. while ((ch = stream.getByte()) !== -1) {
  25936. if (ch === GT) {
  25937. break;
  25938. }
  25939. }
  25940. length = stream.pos - startPos;
  25941. if (ch === -1) {
  25942. warn('Inline ASCIIHexDecode image stream: ' +
  25943. 'EOD marker not found, searching for /EI/ instead.');
  25944. stream.skip(-length); // Reset the stream position.
  25945. return this.findDefaultInlineStreamEnd(stream);
  25946. }
  25947. this.inlineStreamSkipEI(stream);
  25948. return length;
  25949. },
  25950. /**
  25951. * Skip over the /EI/ for streams where we search for an EOD marker.
  25952. */
  25953. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  25954. var E = 0x45, I = 0x49;
  25955. var state = 0, ch;
  25956. while ((ch = stream.getByte()) !== -1) {
  25957. if (state === 0) {
  25958. state = (ch === E) ? 1 : 0;
  25959. } else if (state === 1) {
  25960. state = (ch === I) ? 2 : 0;
  25961. } else if (state === 2) {
  25962. break;
  25963. }
  25964. }
  25965. },
  25966. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  25967. var lexer = this.lexer;
  25968. var stream = lexer.stream;
  25969. // Parse dictionary.
  25970. var dict = new Dict(this.xref);
  25971. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  25972. if (!isName(this.buf1)) {
  25973. error('Dictionary key must be a name object');
  25974. }
  25975. var key = this.buf1.name;
  25976. this.shift();
  25977. if (isEOF(this.buf1)) {
  25978. break;
  25979. }
  25980. dict.set(key, this.getObj(cipherTransform));
  25981. }
  25982. // Extract the name of the first (i.e. the current) image filter.
  25983. var filter = dict.get('Filter', 'F'), filterName;
  25984. if (isName(filter)) {
  25985. filterName = filter.name;
  25986. } else if (isArray(filter) && isName(filter[0])) {
  25987. filterName = filter[0].name;
  25988. }
  25989. // Parse image stream.
  25990. var startPos = stream.pos, length, i, ii;
  25991. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  25992. length = this.findDCTDecodeInlineStreamEnd(stream);
  25993. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  25994. length = this.findASCII85DecodeInlineStreamEnd(stream);
  25995. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  25996. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  25997. } else {
  25998. length = this.findDefaultInlineStreamEnd(stream);
  25999. }
  26000. var imageStream = stream.makeSubStream(startPos, length, dict);
  26001. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  26002. // adler32 checksum.
  26003. var adler32;
  26004. if (length < MAX_LENGTH_TO_CACHE) {
  26005. var imageBytes = imageStream.getBytes();
  26006. imageStream.reset();
  26007. var a = 1;
  26008. var b = 0;
  26009. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  26010. // No modulo required in the loop if imageBytes.length < 5552.
  26011. a += imageBytes[i] & 0xff;
  26012. b += a;
  26013. }
  26014. adler32 = ((b % 65521) << 16) | (a % 65521);
  26015. if (this.imageCache.adler32 === adler32) {
  26016. this.buf2 = Cmd.get('EI');
  26017. this.shift();
  26018. this.imageCache[adler32].reset();
  26019. return this.imageCache[adler32];
  26020. }
  26021. }
  26022. if (cipherTransform) {
  26023. imageStream = cipherTransform.createStream(imageStream, length);
  26024. }
  26025. imageStream = this.filter(imageStream, dict, length);
  26026. imageStream.dict = dict;
  26027. if (adler32 !== undefined) {
  26028. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  26029. this.imageCache[adler32] = imageStream;
  26030. }
  26031. this.buf2 = Cmd.get('EI');
  26032. this.shift();
  26033. return imageStream;
  26034. },
  26035. makeStream: function Parser_makeStream(dict, cipherTransform) {
  26036. var lexer = this.lexer;
  26037. var stream = lexer.stream;
  26038. // get stream start position
  26039. lexer.skipToNextLine();
  26040. var pos = stream.pos - 1;
  26041. // get length
  26042. var length = dict.get('Length');
  26043. if (!isInt(length)) {
  26044. info('Bad ' + length + ' attribute in stream');
  26045. length = 0;
  26046. }
  26047. // skip over the stream data
  26048. stream.pos = pos + length;
  26049. lexer.nextChar();
  26050. // Shift '>>' and check whether the new object marks the end of the stream
  26051. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26052. this.shift(); // 'stream'
  26053. } else {
  26054. // bad stream length, scanning for endstream
  26055. stream.pos = pos;
  26056. var SCAN_BLOCK_SIZE = 2048;
  26057. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26058. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26059. 0x61, 0x6D];
  26060. var skipped = 0, found = false, i, j;
  26061. while (stream.pos < stream.end) {
  26062. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26063. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26064. if (scanLength <= 0) {
  26065. break;
  26066. }
  26067. found = false;
  26068. i = 0;
  26069. while (i < scanLength) {
  26070. j = 0;
  26071. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  26072. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  26073. j++;
  26074. }
  26075. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26076. found = true;
  26077. break;
  26078. }
  26079. i++;
  26080. }
  26081. if (found) {
  26082. skipped += i;
  26083. stream.pos += i;
  26084. break;
  26085. }
  26086. skipped += scanLength;
  26087. stream.pos += scanLength;
  26088. }
  26089. if (!found) {
  26090. error('Missing endstream');
  26091. }
  26092. length = skipped;
  26093. lexer.nextChar();
  26094. this.shift();
  26095. this.shift();
  26096. }
  26097. this.shift(); // 'endstream'
  26098. stream = stream.makeSubStream(pos, length, dict);
  26099. if (cipherTransform) {
  26100. stream = cipherTransform.createStream(stream, length);
  26101. }
  26102. stream = this.filter(stream, dict, length);
  26103. stream.dict = dict;
  26104. return stream;
  26105. },
  26106. filter: function Parser_filter(stream, dict, length) {
  26107. var filter = dict.get('Filter', 'F');
  26108. var params = dict.get('DecodeParms', 'DP');
  26109. if (isName(filter)) {
  26110. return this.makeFilter(stream, filter.name, length, params);
  26111. }
  26112. var maybeLength = length;
  26113. if (isArray(filter)) {
  26114. var filterArray = filter;
  26115. var paramsArray = params;
  26116. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26117. filter = filterArray[i];
  26118. if (!isName(filter)) {
  26119. error('Bad filter name: ' + filter);
  26120. }
  26121. params = null;
  26122. if (isArray(paramsArray) && (i in paramsArray)) {
  26123. params = paramsArray[i];
  26124. }
  26125. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26126. // after the first stream the length variable is invalid
  26127. maybeLength = null;
  26128. }
  26129. }
  26130. return stream;
  26131. },
  26132. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26133. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26134. warn('Empty "' + name + '" stream.');
  26135. return new NullStream(stream);
  26136. }
  26137. try {
  26138. if (params && this.xref) {
  26139. params = this.xref.fetchIfRef(params);
  26140. }
  26141. var xrefStreamStats = this.xref.stats.streamTypes;
  26142. if (name === 'FlateDecode' || name === 'Fl') {
  26143. xrefStreamStats[StreamType.FLATE] = true;
  26144. if (params) {
  26145. return new PredictorStream(new FlateStream(stream, maybeLength),
  26146. maybeLength, params);
  26147. }
  26148. return new FlateStream(stream, maybeLength);
  26149. }
  26150. if (name === 'LZWDecode' || name === 'LZW') {
  26151. xrefStreamStats[StreamType.LZW] = true;
  26152. var earlyChange = 1;
  26153. if (params) {
  26154. if (params.has('EarlyChange')) {
  26155. earlyChange = params.get('EarlyChange');
  26156. }
  26157. return new PredictorStream(
  26158. new LZWStream(stream, maybeLength, earlyChange),
  26159. maybeLength, params);
  26160. }
  26161. return new LZWStream(stream, maybeLength, earlyChange);
  26162. }
  26163. if (name === 'DCTDecode' || name === 'DCT') {
  26164. xrefStreamStats[StreamType.DCT] = true;
  26165. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26166. }
  26167. if (name === 'JPXDecode' || name === 'JPX') {
  26168. xrefStreamStats[StreamType.JPX] = true;
  26169. return new JpxStream(stream, maybeLength, stream.dict);
  26170. }
  26171. if (name === 'ASCII85Decode' || name === 'A85') {
  26172. xrefStreamStats[StreamType.A85] = true;
  26173. return new Ascii85Stream(stream, maybeLength);
  26174. }
  26175. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26176. xrefStreamStats[StreamType.AHX] = true;
  26177. return new AsciiHexStream(stream, maybeLength);
  26178. }
  26179. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26180. xrefStreamStats[StreamType.CCF] = true;
  26181. return new CCITTFaxStream(stream, maybeLength, params);
  26182. }
  26183. if (name === 'RunLengthDecode' || name === 'RL') {
  26184. xrefStreamStats[StreamType.RL] = true;
  26185. return new RunLengthStream(stream, maybeLength);
  26186. }
  26187. if (name === 'JBIG2Decode') {
  26188. xrefStreamStats[StreamType.JBIG] = true;
  26189. return new Jbig2Stream(stream, maybeLength, stream.dict);
  26190. }
  26191. warn('filter "' + name + '" not supported yet');
  26192. return stream;
  26193. } catch (ex) {
  26194. if (ex instanceof MissingDataException) {
  26195. throw ex;
  26196. }
  26197. warn('Invalid stream: \"' + ex + '\"');
  26198. return new NullStream(stream);
  26199. }
  26200. }
  26201. };
  26202. return Parser;
  26203. })();
  26204. var Lexer = (function LexerClosure() {
  26205. function Lexer(stream, knownCommands) {
  26206. this.stream = stream;
  26207. this.nextChar();
  26208. // While lexing, we build up many strings one char at a time. Using += for
  26209. // this can result in lots of garbage strings. It's better to build an
  26210. // array of single-char strings and then join() them together at the end.
  26211. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  26212. // purpose uses less memory than using a new array for each string.
  26213. this.strBuf = [];
  26214. // The PDFs might have "glued" commands with other commands, operands or
  26215. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  26216. // commands and their prefixes. The prefixes are built the following way:
  26217. // if there a command that is a prefix of the other valid command or
  26218. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  26219. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  26220. // other commands or literals as a prefix. The knowCommands is optional.
  26221. this.knownCommands = knownCommands;
  26222. }
  26223. Lexer.isSpace = function Lexer_isSpace(ch) {
  26224. // Space is one of the following characters: SPACE, TAB, CR or LF.
  26225. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  26226. };
  26227. // A '1' in this array means the character is white space. A '1' or
  26228. // '2' means the character ends a name or command.
  26229. var specialChars = [
  26230. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  26231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  26232. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  26233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  26234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  26235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  26236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  26237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  26238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  26239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  26240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  26241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  26242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  26243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  26244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  26245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  26246. ];
  26247. function toHexDigit(ch) {
  26248. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  26249. return ch & 0x0F;
  26250. }
  26251. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  26252. // 'A'-'F', 'a'-'f'
  26253. return (ch & 0x0F) + 9;
  26254. }
  26255. return -1;
  26256. }
  26257. Lexer.prototype = {
  26258. nextChar: function Lexer_nextChar() {
  26259. return (this.currentChar = this.stream.getByte());
  26260. },
  26261. peekChar: function Lexer_peekChar() {
  26262. return this.stream.peekByte();
  26263. },
  26264. getNumber: function Lexer_getNumber() {
  26265. var ch = this.currentChar;
  26266. var eNotation = false;
  26267. var divideBy = 0; // different from 0 if it's a floating point value
  26268. var sign = 1;
  26269. if (ch === 0x2D) { // '-'
  26270. sign = -1;
  26271. ch = this.nextChar();
  26272. if (ch === 0x2D) { // '-'
  26273. // Ignore double negative (this is consistent with Adobe Reader).
  26274. ch = this.nextChar();
  26275. }
  26276. } else if (ch === 0x2B) { // '+'
  26277. ch = this.nextChar();
  26278. }
  26279. if (ch === 0x2E) { // '.'
  26280. divideBy = 10;
  26281. ch = this.nextChar();
  26282. }
  26283. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26284. error('Invalid number: ' + String.fromCharCode(ch));
  26285. return 0;
  26286. }
  26287. var baseValue = ch - 0x30; // '0'
  26288. var powerValue = 0;
  26289. var powerValueSign = 1;
  26290. while ((ch = this.nextChar()) >= 0) {
  26291. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  26292. var currentDigit = ch - 0x30; // '0'
  26293. if (eNotation) { // We are after an 'e' or 'E'
  26294. powerValue = powerValue * 10 + currentDigit;
  26295. } else {
  26296. if (divideBy !== 0) { // We are after a point
  26297. divideBy *= 10;
  26298. }
  26299. baseValue = baseValue * 10 + currentDigit;
  26300. }
  26301. } else if (ch === 0x2E) { // '.'
  26302. if (divideBy === 0) {
  26303. divideBy = 1;
  26304. } else {
  26305. // A number can have only one '.'
  26306. break;
  26307. }
  26308. } else if (ch === 0x2D) { // '-'
  26309. // ignore minus signs in the middle of numbers to match
  26310. // Adobe's behavior
  26311. warn('Badly formated number');
  26312. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  26313. // 'E' can be either a scientific notation or the beginning of a new
  26314. // operator
  26315. ch = this.peekChar();
  26316. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  26317. powerValueSign = (ch === 0x2D) ? -1 : 1;
  26318. this.nextChar(); // Consume the sign character
  26319. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26320. // The 'E' must be the beginning of a new operator
  26321. break;
  26322. }
  26323. eNotation = true;
  26324. } else {
  26325. // the last character doesn't belong to us
  26326. break;
  26327. }
  26328. }
  26329. if (divideBy !== 0) {
  26330. baseValue /= divideBy;
  26331. }
  26332. if (eNotation) {
  26333. baseValue *= Math.pow(10, powerValueSign * powerValue);
  26334. }
  26335. return sign * baseValue;
  26336. },
  26337. getString: function Lexer_getString() {
  26338. var numParen = 1;
  26339. var done = false;
  26340. var strBuf = this.strBuf;
  26341. strBuf.length = 0;
  26342. var ch = this.nextChar();
  26343. while (true) {
  26344. var charBuffered = false;
  26345. switch (ch | 0) {
  26346. case -1:
  26347. warn('Unterminated string');
  26348. done = true;
  26349. break;
  26350. case 0x28: // '('
  26351. ++numParen;
  26352. strBuf.push('(');
  26353. break;
  26354. case 0x29: // ')'
  26355. if (--numParen === 0) {
  26356. this.nextChar(); // consume strings ')'
  26357. done = true;
  26358. } else {
  26359. strBuf.push(')');
  26360. }
  26361. break;
  26362. case 0x5C: // '\\'
  26363. ch = this.nextChar();
  26364. switch (ch) {
  26365. case -1:
  26366. warn('Unterminated string');
  26367. done = true;
  26368. break;
  26369. case 0x6E: // 'n'
  26370. strBuf.push('\n');
  26371. break;
  26372. case 0x72: // 'r'
  26373. strBuf.push('\r');
  26374. break;
  26375. case 0x74: // 't'
  26376. strBuf.push('\t');
  26377. break;
  26378. case 0x62: // 'b'
  26379. strBuf.push('\b');
  26380. break;
  26381. case 0x66: // 'f'
  26382. strBuf.push('\f');
  26383. break;
  26384. case 0x5C: // '\'
  26385. case 0x28: // '('
  26386. case 0x29: // ')'
  26387. strBuf.push(String.fromCharCode(ch));
  26388. break;
  26389. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  26390. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  26391. var x = ch & 0x0F;
  26392. ch = this.nextChar();
  26393. charBuffered = true;
  26394. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26395. x = (x << 3) + (ch & 0x0F);
  26396. ch = this.nextChar();
  26397. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26398. charBuffered = false;
  26399. x = (x << 3) + (ch & 0x0F);
  26400. }
  26401. }
  26402. strBuf.push(String.fromCharCode(x));
  26403. break;
  26404. case 0x0D: // CR
  26405. if (this.peekChar() === 0x0A) { // LF
  26406. this.nextChar();
  26407. }
  26408. break;
  26409. case 0x0A: // LF
  26410. break;
  26411. default:
  26412. strBuf.push(String.fromCharCode(ch));
  26413. break;
  26414. }
  26415. break;
  26416. default:
  26417. strBuf.push(String.fromCharCode(ch));
  26418. break;
  26419. }
  26420. if (done) {
  26421. break;
  26422. }
  26423. if (!charBuffered) {
  26424. ch = this.nextChar();
  26425. }
  26426. }
  26427. return strBuf.join('');
  26428. },
  26429. getName: function Lexer_getName() {
  26430. var ch, previousCh;
  26431. var strBuf = this.strBuf;
  26432. strBuf.length = 0;
  26433. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26434. if (ch === 0x23) { // '#'
  26435. ch = this.nextChar();
  26436. if (specialChars[ch]) {
  26437. warn('Lexer_getName: ' +
  26438. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  26439. strBuf.push('#');
  26440. break;
  26441. }
  26442. var x = toHexDigit(ch);
  26443. if (x !== -1) {
  26444. previousCh = ch;
  26445. ch = this.nextChar();
  26446. var x2 = toHexDigit(ch);
  26447. if (x2 === -1) {
  26448. warn('Lexer_getName: Illegal digit (' +
  26449. String.fromCharCode(ch) +') in hexadecimal number.');
  26450. strBuf.push('#', String.fromCharCode(previousCh));
  26451. if (specialChars[ch]) {
  26452. break;
  26453. }
  26454. strBuf.push(String.fromCharCode(ch));
  26455. continue;
  26456. }
  26457. strBuf.push(String.fromCharCode((x << 4) | x2));
  26458. } else {
  26459. strBuf.push('#', String.fromCharCode(ch));
  26460. }
  26461. } else {
  26462. strBuf.push(String.fromCharCode(ch));
  26463. }
  26464. }
  26465. if (strBuf.length > 127) {
  26466. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  26467. }
  26468. return Name.get(strBuf.join(''));
  26469. },
  26470. getHexString: function Lexer_getHexString() {
  26471. var strBuf = this.strBuf;
  26472. strBuf.length = 0;
  26473. var ch = this.currentChar;
  26474. var isFirstHex = true;
  26475. var firstDigit;
  26476. var secondDigit;
  26477. while (true) {
  26478. if (ch < 0) {
  26479. warn('Unterminated hex string');
  26480. break;
  26481. } else if (ch === 0x3E) { // '>'
  26482. this.nextChar();
  26483. break;
  26484. } else if (specialChars[ch] === 1) {
  26485. ch = this.nextChar();
  26486. continue;
  26487. } else {
  26488. if (isFirstHex) {
  26489. firstDigit = toHexDigit(ch);
  26490. if (firstDigit === -1) {
  26491. warn('Ignoring invalid character "' + ch + '" in hex string');
  26492. ch = this.nextChar();
  26493. continue;
  26494. }
  26495. } else {
  26496. secondDigit = toHexDigit(ch);
  26497. if (secondDigit === -1) {
  26498. warn('Ignoring invalid character "' + ch + '" in hex string');
  26499. ch = this.nextChar();
  26500. continue;
  26501. }
  26502. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  26503. }
  26504. isFirstHex = !isFirstHex;
  26505. ch = this.nextChar();
  26506. }
  26507. }
  26508. return strBuf.join('');
  26509. },
  26510. getObj: function Lexer_getObj() {
  26511. // skip whitespace and comments
  26512. var comment = false;
  26513. var ch = this.currentChar;
  26514. while (true) {
  26515. if (ch < 0) {
  26516. return EOF;
  26517. }
  26518. if (comment) {
  26519. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  26520. comment = false;
  26521. }
  26522. } else if (ch === 0x25) { // '%'
  26523. comment = true;
  26524. } else if (specialChars[ch] !== 1) {
  26525. break;
  26526. }
  26527. ch = this.nextChar();
  26528. }
  26529. // start reading token
  26530. switch (ch | 0) {
  26531. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  26532. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  26533. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  26534. return this.getNumber();
  26535. case 0x28: // '('
  26536. return this.getString();
  26537. case 0x2F: // '/'
  26538. return this.getName();
  26539. // array punctuation
  26540. case 0x5B: // '['
  26541. this.nextChar();
  26542. return Cmd.get('[');
  26543. case 0x5D: // ']'
  26544. this.nextChar();
  26545. return Cmd.get(']');
  26546. // hex string or dict punctuation
  26547. case 0x3C: // '<'
  26548. ch = this.nextChar();
  26549. if (ch === 0x3C) {
  26550. // dict punctuation
  26551. this.nextChar();
  26552. return Cmd.get('<<');
  26553. }
  26554. return this.getHexString();
  26555. // dict punctuation
  26556. case 0x3E: // '>'
  26557. ch = this.nextChar();
  26558. if (ch === 0x3E) {
  26559. this.nextChar();
  26560. return Cmd.get('>>');
  26561. }
  26562. return Cmd.get('>');
  26563. case 0x7B: // '{'
  26564. this.nextChar();
  26565. return Cmd.get('{');
  26566. case 0x7D: // '}'
  26567. this.nextChar();
  26568. return Cmd.get('}');
  26569. case 0x29: // ')'
  26570. error('Illegal character: ' + ch);
  26571. break;
  26572. }
  26573. // command
  26574. var str = String.fromCharCode(ch);
  26575. var knownCommands = this.knownCommands;
  26576. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26577. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26578. // stop if known command is found and next character does not make
  26579. // the str a command
  26580. var possibleCommand = str + String.fromCharCode(ch);
  26581. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  26582. break;
  26583. }
  26584. if (str.length === 128) {
  26585. error('Command token too long: ' + str.length);
  26586. }
  26587. str = possibleCommand;
  26588. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26589. }
  26590. if (str === 'true') {
  26591. return true;
  26592. }
  26593. if (str === 'false') {
  26594. return false;
  26595. }
  26596. if (str === 'null') {
  26597. return null;
  26598. }
  26599. return Cmd.get(str);
  26600. },
  26601. skipToNextLine: function Lexer_skipToNextLine() {
  26602. var ch = this.currentChar;
  26603. while (ch >= 0) {
  26604. if (ch === 0x0D) { // CR
  26605. ch = this.nextChar();
  26606. if (ch === 0x0A) { // LF
  26607. this.nextChar();
  26608. }
  26609. break;
  26610. } else if (ch === 0x0A) { // LF
  26611. this.nextChar();
  26612. break;
  26613. }
  26614. ch = this.nextChar();
  26615. }
  26616. }
  26617. };
  26618. return Lexer;
  26619. })();
  26620. var Linearization = {
  26621. create: function LinearizationCreate(stream) {
  26622. function getInt(name, allowZeroValue) {
  26623. var obj = linDict.get(name);
  26624. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  26625. return obj;
  26626. }
  26627. throw new Error('The "' + name + '" parameter in the linearization ' +
  26628. 'dictionary is invalid.');
  26629. }
  26630. function getHints() {
  26631. var hints = linDict.get('H'), hintsLength, item;
  26632. if (isArray(hints) &&
  26633. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  26634. for (var index = 0; index < hintsLength; index++) {
  26635. if (!(isInt(item = hints[index]) && item > 0)) {
  26636. throw new Error('Hint (' + index +
  26637. ') in the linearization dictionary is invalid.');
  26638. }
  26639. }
  26640. return hints;
  26641. }
  26642. throw new Error('Hint array in the linearization dictionary is invalid.');
  26643. }
  26644. var parser = new Parser(new Lexer(stream), false, null);
  26645. var obj1 = parser.getObj();
  26646. var obj2 = parser.getObj();
  26647. var obj3 = parser.getObj();
  26648. var linDict = parser.getObj();
  26649. var obj, length;
  26650. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  26651. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  26652. return null; // No valid linearization dictionary found.
  26653. } else if ((length = getInt('L')) !== stream.length) {
  26654. throw new Error('The "L" parameter in the linearization dictionary ' +
  26655. 'does not equal the stream length.');
  26656. }
  26657. return {
  26658. length: length,
  26659. hints: getHints(),
  26660. objectNumberFirst: getInt('O'),
  26661. endFirst: getInt('E'),
  26662. numPages: getInt('N'),
  26663. mainXRefEntriesOffset: getInt('T'),
  26664. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  26665. };
  26666. }
  26667. };
  26668. exports.EOF = EOF;
  26669. exports.Lexer = Lexer;
  26670. exports.Linearization = Linearization;
  26671. exports.Parser = Parser;
  26672. exports.isEOF = isEOF;
  26673. // TODO refactor to remove dependency on stream.js
  26674. coreStream._setCoreParser(exports);
  26675. }));
  26676. (function (root, factory) {
  26677. {
  26678. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  26679. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  26680. }
  26681. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  26682. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26683. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  26684. var ImageKind = sharedUtil.ImageKind;
  26685. var OPS = sharedUtil.OPS;
  26686. var TextRenderingMode = sharedUtil.TextRenderingMode;
  26687. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  26688. var Util = sharedUtil.Util;
  26689. var assert = sharedUtil.assert;
  26690. var info = sharedUtil.info;
  26691. var isNum = sharedUtil.isNum;
  26692. var isArray = sharedUtil.isArray;
  26693. var error = sharedUtil.error;
  26694. var shadow = sharedUtil.shadow;
  26695. var warn = sharedUtil.warn;
  26696. var TilingPattern = displayPatternHelper.TilingPattern;
  26697. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  26698. var WebGLUtils = displayWebGL.WebGLUtils;
  26699. // <canvas> contexts store most of the state we need natively.
  26700. // However, PDF needs a bit more state, which we store here.
  26701. // Minimal font size that would be used during canvas fillText operations.
  26702. var MIN_FONT_SIZE = 16;
  26703. // Maximum font size that would be used during canvas fillText operations.
  26704. var MAX_FONT_SIZE = 100;
  26705. var MAX_GROUP_SIZE = 4096;
  26706. // Heuristic value used when enforcing minimum line widths.
  26707. var MIN_WIDTH_FACTOR = 0.65;
  26708. var COMPILE_TYPE3_GLYPHS = true;
  26709. var MAX_SIZE_TO_COMPILE = 1000;
  26710. var FULL_CHUNK_HEIGHT = 16;
  26711. function createScratchCanvas(width, height) {
  26712. var canvas = document.createElement('canvas');
  26713. canvas.width = width;
  26714. canvas.height = height;
  26715. return canvas;
  26716. }
  26717. function addContextCurrentTransform(ctx) {
  26718. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  26719. if (!ctx.mozCurrentTransform) {
  26720. ctx._originalSave = ctx.save;
  26721. ctx._originalRestore = ctx.restore;
  26722. ctx._originalRotate = ctx.rotate;
  26723. ctx._originalScale = ctx.scale;
  26724. ctx._originalTranslate = ctx.translate;
  26725. ctx._originalTransform = ctx.transform;
  26726. ctx._originalSetTransform = ctx.setTransform;
  26727. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  26728. ctx._transformStack = [];
  26729. Object.defineProperty(ctx, 'mozCurrentTransform', {
  26730. get: function getCurrentTransform() {
  26731. return this._transformMatrix;
  26732. }
  26733. });
  26734. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  26735. get: function getCurrentTransformInverse() {
  26736. // Calculation done using WolframAlpha:
  26737. // http://www.wolframalpha.com/input/?
  26738. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  26739. var m = this._transformMatrix;
  26740. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  26741. var ad_bc = a * d - b * c;
  26742. var bc_ad = b * c - a * d;
  26743. return [
  26744. d / ad_bc,
  26745. b / bc_ad,
  26746. c / bc_ad,
  26747. a / ad_bc,
  26748. (d * e - c * f) / bc_ad,
  26749. (b * e - a * f) / ad_bc
  26750. ];
  26751. }
  26752. });
  26753. ctx.save = function ctxSave() {
  26754. var old = this._transformMatrix;
  26755. this._transformStack.push(old);
  26756. this._transformMatrix = old.slice(0, 6);
  26757. this._originalSave();
  26758. };
  26759. ctx.restore = function ctxRestore() {
  26760. var prev = this._transformStack.pop();
  26761. if (prev) {
  26762. this._transformMatrix = prev;
  26763. this._originalRestore();
  26764. }
  26765. };
  26766. ctx.translate = function ctxTranslate(x, y) {
  26767. var m = this._transformMatrix;
  26768. m[4] = m[0] * x + m[2] * y + m[4];
  26769. m[5] = m[1] * x + m[3] * y + m[5];
  26770. this._originalTranslate(x, y);
  26771. };
  26772. ctx.scale = function ctxScale(x, y) {
  26773. var m = this._transformMatrix;
  26774. m[0] = m[0] * x;
  26775. m[1] = m[1] * x;
  26776. m[2] = m[2] * y;
  26777. m[3] = m[3] * y;
  26778. this._originalScale(x, y);
  26779. };
  26780. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  26781. var m = this._transformMatrix;
  26782. this._transformMatrix = [
  26783. m[0] * a + m[2] * b,
  26784. m[1] * a + m[3] * b,
  26785. m[0] * c + m[2] * d,
  26786. m[1] * c + m[3] * d,
  26787. m[0] * e + m[2] * f + m[4],
  26788. m[1] * e + m[3] * f + m[5]
  26789. ];
  26790. ctx._originalTransform(a, b, c, d, e, f);
  26791. };
  26792. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  26793. this._transformMatrix = [a, b, c, d, e, f];
  26794. ctx._originalSetTransform(a, b, c, d, e, f);
  26795. };
  26796. ctx.rotate = function ctxRotate(angle) {
  26797. var cosValue = Math.cos(angle);
  26798. var sinValue = Math.sin(angle);
  26799. var m = this._transformMatrix;
  26800. this._transformMatrix = [
  26801. m[0] * cosValue + m[2] * sinValue,
  26802. m[1] * cosValue + m[3] * sinValue,
  26803. m[0] * (-sinValue) + m[2] * cosValue,
  26804. m[1] * (-sinValue) + m[3] * cosValue,
  26805. m[4],
  26806. m[5]
  26807. ];
  26808. this._originalRotate(angle);
  26809. };
  26810. }
  26811. }
  26812. var CachedCanvases = (function CachedCanvasesClosure() {
  26813. function CachedCanvases() {
  26814. this.cache = Object.create(null);
  26815. }
  26816. CachedCanvases.prototype = {
  26817. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  26818. trackTransform) {
  26819. var canvasEntry;
  26820. if (this.cache[id] !== undefined) {
  26821. canvasEntry = this.cache[id];
  26822. canvasEntry.canvas.width = width;
  26823. canvasEntry.canvas.height = height;
  26824. // reset canvas transform for emulated mozCurrentTransform, if needed
  26825. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  26826. } else {
  26827. var canvas = createScratchCanvas(width, height);
  26828. var ctx = canvas.getContext('2d');
  26829. if (trackTransform) {
  26830. addContextCurrentTransform(ctx);
  26831. }
  26832. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  26833. }
  26834. return canvasEntry;
  26835. },
  26836. clear: function () {
  26837. for (var id in this.cache) {
  26838. var canvasEntry = this.cache[id];
  26839. // Zeroing the width and height causes Firefox to release graphics
  26840. // resources immediately, which can greatly reduce memory consumption.
  26841. canvasEntry.canvas.width = 0;
  26842. canvasEntry.canvas.height = 0;
  26843. delete this.cache[id];
  26844. }
  26845. }
  26846. };
  26847. return CachedCanvases;
  26848. })();
  26849. function compileType3Glyph(imgData) {
  26850. var POINT_TO_PROCESS_LIMIT = 1000;
  26851. var width = imgData.width, height = imgData.height;
  26852. var i, j, j0, width1 = width + 1;
  26853. var points = new Uint8Array(width1 * (height + 1));
  26854. var POINT_TYPES =
  26855. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  26856. // decodes bit-packed mask data
  26857. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  26858. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  26859. for (i = 0, ii = data0.length; i < ii; i++) {
  26860. var mask = 128, elem = data0[i];
  26861. while (mask > 0) {
  26862. data[pos++] = (elem & mask) ? 0 : 255;
  26863. mask >>= 1;
  26864. }
  26865. }
  26866. // finding iteresting points: every point is located between mask pixels,
  26867. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  26868. // will have flags assigned based on neighboring mask pixels:
  26869. // 4 | 8
  26870. // --P--
  26871. // 2 | 1
  26872. // We are interested only in points with the flags:
  26873. // - outside corners: 1, 2, 4, 8;
  26874. // - inside corners: 7, 11, 13, 14;
  26875. // - and, intersections: 5, 10.
  26876. var count = 0;
  26877. pos = 0;
  26878. if (data[pos] !== 0) {
  26879. points[0] = 1;
  26880. ++count;
  26881. }
  26882. for (j = 1; j < width; j++) {
  26883. if (data[pos] !== data[pos + 1]) {
  26884. points[j] = data[pos] ? 2 : 1;
  26885. ++count;
  26886. }
  26887. pos++;
  26888. }
  26889. if (data[pos] !== 0) {
  26890. points[j] = 2;
  26891. ++count;
  26892. }
  26893. for (i = 1; i < height; i++) {
  26894. pos = i * lineSize;
  26895. j0 = i * width1;
  26896. if (data[pos - lineSize] !== data[pos]) {
  26897. points[j0] = data[pos] ? 1 : 8;
  26898. ++count;
  26899. }
  26900. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  26901. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  26902. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  26903. for (j = 1; j < width; j++) {
  26904. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  26905. (data[pos - lineSize + 1] ? 8 : 0);
  26906. if (POINT_TYPES[sum]) {
  26907. points[j0 + j] = POINT_TYPES[sum];
  26908. ++count;
  26909. }
  26910. pos++;
  26911. }
  26912. if (data[pos - lineSize] !== data[pos]) {
  26913. points[j0 + j] = data[pos] ? 2 : 4;
  26914. ++count;
  26915. }
  26916. if (count > POINT_TO_PROCESS_LIMIT) {
  26917. return null;
  26918. }
  26919. }
  26920. pos = lineSize * (height - 1);
  26921. j0 = i * width1;
  26922. if (data[pos] !== 0) {
  26923. points[j0] = 8;
  26924. ++count;
  26925. }
  26926. for (j = 1; j < width; j++) {
  26927. if (data[pos] !== data[pos + 1]) {
  26928. points[j0 + j] = data[pos] ? 4 : 8;
  26929. ++count;
  26930. }
  26931. pos++;
  26932. }
  26933. if (data[pos] !== 0) {
  26934. points[j0 + j] = 4;
  26935. ++count;
  26936. }
  26937. if (count > POINT_TO_PROCESS_LIMIT) {
  26938. return null;
  26939. }
  26940. // building outlines
  26941. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  26942. var outlines = [];
  26943. for (i = 0; count && i <= height; i++) {
  26944. var p = i * width1;
  26945. var end = p + width;
  26946. while (p < end && !points[p]) {
  26947. p++;
  26948. }
  26949. if (p === end) {
  26950. continue;
  26951. }
  26952. var coords = [p % width1, i];
  26953. var type = points[p], p0 = p, pp;
  26954. do {
  26955. var step = steps[type];
  26956. do {
  26957. p += step;
  26958. } while (!points[p]);
  26959. pp = points[p];
  26960. if (pp !== 5 && pp !== 10) {
  26961. // set new direction
  26962. type = pp;
  26963. // delete mark
  26964. points[p] = 0;
  26965. } else { // type is 5 or 10, ie, a crossing
  26966. // set new direction
  26967. type = pp & ((0x33 * type) >> 4);
  26968. // set new type for "future hit"
  26969. points[p] &= (type >> 2 | type << 2);
  26970. }
  26971. coords.push(p % width1);
  26972. coords.push((p / width1) | 0);
  26973. --count;
  26974. } while (p0 !== p);
  26975. outlines.push(coords);
  26976. --i;
  26977. }
  26978. var drawOutline = function(c) {
  26979. c.save();
  26980. // the path shall be painted in [0..1]x[0..1] space
  26981. c.scale(1 / width, -1 / height);
  26982. c.translate(0, -height);
  26983. c.beginPath();
  26984. for (var i = 0, ii = outlines.length; i < ii; i++) {
  26985. var o = outlines[i];
  26986. c.moveTo(o[0], o[1]);
  26987. for (var j = 2, jj = o.length; j < jj; j += 2) {
  26988. c.lineTo(o[j], o[j+1]);
  26989. }
  26990. }
  26991. c.fill();
  26992. c.beginPath();
  26993. c.restore();
  26994. };
  26995. return drawOutline;
  26996. }
  26997. var CanvasExtraState = (function CanvasExtraStateClosure() {
  26998. function CanvasExtraState(old) {
  26999. // Are soft masks and alpha values shapes or opacities?
  27000. this.alphaIsShape = false;
  27001. this.fontSize = 0;
  27002. this.fontSizeScale = 1;
  27003. this.textMatrix = IDENTITY_MATRIX;
  27004. this.textMatrixScale = 1;
  27005. this.fontMatrix = FONT_IDENTITY_MATRIX;
  27006. this.leading = 0;
  27007. // Current point (in user coordinates)
  27008. this.x = 0;
  27009. this.y = 0;
  27010. // Start of text line (in text coordinates)
  27011. this.lineX = 0;
  27012. this.lineY = 0;
  27013. // Character and word spacing
  27014. this.charSpacing = 0;
  27015. this.wordSpacing = 0;
  27016. this.textHScale = 1;
  27017. this.textRenderingMode = TextRenderingMode.FILL;
  27018. this.textRise = 0;
  27019. // Default fore and background colors
  27020. this.fillColor = '#000000';
  27021. this.strokeColor = '#000000';
  27022. this.patternFill = false;
  27023. // Note: fill alpha applies to all non-stroking operations
  27024. this.fillAlpha = 1;
  27025. this.strokeAlpha = 1;
  27026. this.lineWidth = 1;
  27027. this.activeSMask = null; // nonclonable field (see the save method below)
  27028. this.old = old;
  27029. }
  27030. CanvasExtraState.prototype = {
  27031. clone: function CanvasExtraState_clone() {
  27032. return Object.create(this);
  27033. },
  27034. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  27035. this.x = x;
  27036. this.y = y;
  27037. }
  27038. };
  27039. return CanvasExtraState;
  27040. })();
  27041. var CanvasGraphics = (function CanvasGraphicsClosure() {
  27042. // Defines the time the executeOperatorList is going to be executing
  27043. // before it stops and shedules a continue of execution.
  27044. var EXECUTION_TIME = 15;
  27045. // Defines the number of steps before checking the execution time
  27046. var EXECUTION_STEPS = 10;
  27047. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  27048. this.ctx = canvasCtx;
  27049. this.current = new CanvasExtraState();
  27050. this.stateStack = [];
  27051. this.pendingClip = null;
  27052. this.pendingEOFill = false;
  27053. this.res = null;
  27054. this.xobjs = null;
  27055. this.commonObjs = commonObjs;
  27056. this.objs = objs;
  27057. this.imageLayer = imageLayer;
  27058. this.groupStack = [];
  27059. this.processingType3 = null;
  27060. // Patterns are painted relative to the initial page/form transform, see pdf
  27061. // spec 8.7.2 NOTE 1.
  27062. this.baseTransform = null;
  27063. this.baseTransformStack = [];
  27064. this.groupLevel = 0;
  27065. this.smaskStack = [];
  27066. this.smaskCounter = 0;
  27067. this.tempSMask = null;
  27068. this.cachedCanvases = new CachedCanvases();
  27069. if (canvasCtx) {
  27070. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  27071. // the transformation must already be set in canvasCtx._transformMatrix.
  27072. addContextCurrentTransform(canvasCtx);
  27073. }
  27074. this.cachedGetSinglePixelWidth = null;
  27075. }
  27076. function putBinaryImageData(ctx, imgData) {
  27077. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  27078. ctx.putImageData(imgData, 0, 0);
  27079. return;
  27080. }
  27081. // Put the image data to the canvas in chunks, rather than putting the
  27082. // whole image at once. This saves JS memory, because the ImageData object
  27083. // is smaller. It also possibly saves C++ memory within the implementation
  27084. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  27085. // the data passed to putImageData()). |n| shouldn't be too small, however,
  27086. // because too many putImageData() calls will slow things down.
  27087. //
  27088. // Note: as written, if the last chunk is partial, the putImageData() call
  27089. // will (conceptually) put pixels past the bounds of the canvas. But
  27090. // that's ok; any such pixels are ignored.
  27091. var height = imgData.height, width = imgData.width;
  27092. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  27093. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  27094. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  27095. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  27096. var srcPos = 0, destPos;
  27097. var src = imgData.data;
  27098. var dest = chunkImgData.data;
  27099. var i, j, thisChunkHeight, elemsInThisChunk;
  27100. // There are multiple forms in which the pixel data can be passed, and
  27101. // imgData.kind tells us which one this is.
  27102. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  27103. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  27104. var srcLength = src.byteLength;
  27105. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  27106. new Uint32ArrayView(dest);
  27107. var dest32DataLength = dest32.length;
  27108. var fullSrcDiff = (width + 7) >> 3;
  27109. var white = 0xFFFFFFFF;
  27110. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  27111. 0xFF000000 : 0x000000FF;
  27112. for (i = 0; i < totalChunks; i++) {
  27113. thisChunkHeight =
  27114. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  27115. destPos = 0;
  27116. for (j = 0; j < thisChunkHeight; j++) {
  27117. var srcDiff = srcLength - srcPos;
  27118. var k = 0;
  27119. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  27120. var kEndUnrolled = kEnd & ~7;
  27121. var mask = 0;
  27122. var srcByte = 0;
  27123. for (; k < kEndUnrolled; k += 8) {
  27124. srcByte = src[srcPos++];
  27125. dest32[destPos++] = (srcByte & 128) ? white : black;
  27126. dest32[destPos++] = (srcByte & 64) ? white : black;
  27127. dest32[destPos++] = (srcByte & 32) ? white : black;
  27128. dest32[destPos++] = (srcByte & 16) ? white : black;
  27129. dest32[destPos++] = (srcByte & 8) ? white : black;
  27130. dest32[destPos++] = (srcByte & 4) ? white : black;
  27131. dest32[destPos++] = (srcByte & 2) ? white : black;
  27132. dest32[destPos++] = (srcByte & 1) ? white : black;
  27133. }
  27134. for (; k < kEnd; k++) {
  27135. if (mask === 0) {
  27136. srcByte = src[srcPos++];
  27137. mask = 128;
  27138. }
  27139. dest32[destPos++] = (srcByte & mask) ? white : black;
  27140. mask >>= 1;
  27141. }
  27142. }
  27143. // We ran out of input. Make all remaining pixels transparent.
  27144. while (destPos < dest32DataLength) {
  27145. dest32[destPos++] = 0;
  27146. }
  27147. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27148. }
  27149. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  27150. // RGBA, 32-bits per pixel.
  27151. j = 0;
  27152. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  27153. for (i = 0; i < fullChunks; i++) {
  27154. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  27155. srcPos += elemsInThisChunk;
  27156. ctx.putImageData(chunkImgData, 0, j);
  27157. j += FULL_CHUNK_HEIGHT;
  27158. }
  27159. if (i < totalChunks) {
  27160. elemsInThisChunk = width * partialChunkHeight * 4;
  27161. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  27162. ctx.putImageData(chunkImgData, 0, j);
  27163. }
  27164. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  27165. // RGB, 24-bits per pixel.
  27166. thisChunkHeight = FULL_CHUNK_HEIGHT;
  27167. elemsInThisChunk = width * thisChunkHeight;
  27168. for (i = 0; i < totalChunks; i++) {
  27169. if (i >= fullChunks) {
  27170. thisChunkHeight = partialChunkHeight;
  27171. elemsInThisChunk = width * thisChunkHeight;
  27172. }
  27173. destPos = 0;
  27174. for (j = elemsInThisChunk; j--;) {
  27175. dest[destPos++] = src[srcPos++];
  27176. dest[destPos++] = src[srcPos++];
  27177. dest[destPos++] = src[srcPos++];
  27178. dest[destPos++] = 255;
  27179. }
  27180. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27181. }
  27182. } else {
  27183. error('bad image kind: ' + imgData.kind);
  27184. }
  27185. }
  27186. function putBinaryImageMask(ctx, imgData) {
  27187. var height = imgData.height, width = imgData.width;
  27188. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  27189. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  27190. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  27191. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  27192. var srcPos = 0;
  27193. var src = imgData.data;
  27194. var dest = chunkImgData.data;
  27195. for (var i = 0; i < totalChunks; i++) {
  27196. var thisChunkHeight =
  27197. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  27198. // Expand the mask so it can be used by the canvas. Any required
  27199. // inversion has already been handled.
  27200. var destPos = 3; // alpha component offset
  27201. for (var j = 0; j < thisChunkHeight; j++) {
  27202. var mask = 0;
  27203. for (var k = 0; k < width; k++) {
  27204. if (!mask) {
  27205. var elem = src[srcPos++];
  27206. mask = 128;
  27207. }
  27208. dest[destPos] = (elem & mask) ? 0 : 255;
  27209. destPos += 4;
  27210. mask >>= 1;
  27211. }
  27212. }
  27213. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27214. }
  27215. }
  27216. function copyCtxState(sourceCtx, destCtx) {
  27217. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  27218. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  27219. 'globalCompositeOperation', 'font'];
  27220. for (var i = 0, ii = properties.length; i < ii; i++) {
  27221. var property = properties[i];
  27222. if (sourceCtx[property] !== undefined) {
  27223. destCtx[property] = sourceCtx[property];
  27224. }
  27225. }
  27226. if (sourceCtx.setLineDash !== undefined) {
  27227. destCtx.setLineDash(sourceCtx.getLineDash());
  27228. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  27229. } else if (sourceCtx.mozDashOffset !== undefined) {
  27230. destCtx.mozDash = sourceCtx.mozDash;
  27231. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  27232. }
  27233. }
  27234. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  27235. var length = bytes.length;
  27236. for (var i = 3; i < length; i += 4) {
  27237. var alpha = bytes[i];
  27238. if (alpha === 0) {
  27239. bytes[i - 3] = r0;
  27240. bytes[i - 2] = g0;
  27241. bytes[i - 1] = b0;
  27242. } else if (alpha < 255) {
  27243. var alpha_ = 255 - alpha;
  27244. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  27245. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  27246. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  27247. }
  27248. }
  27249. }
  27250. function composeSMaskAlpha(maskData, layerData, transferMap) {
  27251. var length = maskData.length;
  27252. var scale = 1 / 255;
  27253. for (var i = 3; i < length; i += 4) {
  27254. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  27255. layerData[i] = (layerData[i] * alpha * scale) | 0;
  27256. }
  27257. }
  27258. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  27259. var length = maskData.length;
  27260. for (var i = 3; i < length; i += 4) {
  27261. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  27262. (maskData[i - 2] * 152) + // * 0.59 ....
  27263. (maskData[i - 1] * 28); // * 0.11 ....
  27264. layerData[i] = transferMap ?
  27265. (layerData[i] * transferMap[y >> 8]) >> 8 :
  27266. (layerData[i] * y) >> 16;
  27267. }
  27268. }
  27269. function genericComposeSMask(maskCtx, layerCtx, width, height,
  27270. subtype, backdrop, transferMap) {
  27271. var hasBackdrop = !!backdrop;
  27272. var r0 = hasBackdrop ? backdrop[0] : 0;
  27273. var g0 = hasBackdrop ? backdrop[1] : 0;
  27274. var b0 = hasBackdrop ? backdrop[2] : 0;
  27275. var composeFn;
  27276. if (subtype === 'Luminosity') {
  27277. composeFn = composeSMaskLuminosity;
  27278. } else {
  27279. composeFn = composeSMaskAlpha;
  27280. }
  27281. // processing image in chunks to save memory
  27282. var PIXELS_TO_PROCESS = 1048576;
  27283. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  27284. for (var row = 0; row < height; row += chunkSize) {
  27285. var chunkHeight = Math.min(chunkSize, height - row);
  27286. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  27287. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  27288. if (hasBackdrop) {
  27289. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  27290. }
  27291. composeFn(maskData.data, layerData.data, transferMap);
  27292. maskCtx.putImageData(layerData, 0, row);
  27293. }
  27294. }
  27295. function composeSMask(ctx, smask, layerCtx) {
  27296. var mask = smask.canvas;
  27297. var maskCtx = smask.context;
  27298. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  27299. smask.offsetX, smask.offsetY);
  27300. var backdrop = smask.backdrop || null;
  27301. if (!smask.transferMap && WebGLUtils.isEnabled) {
  27302. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  27303. {subtype: smask.subtype, backdrop: backdrop});
  27304. ctx.setTransform(1, 0, 0, 1, 0, 0);
  27305. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  27306. return;
  27307. }
  27308. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  27309. smask.subtype, backdrop, smask.transferMap);
  27310. ctx.drawImage(mask, 0, 0);
  27311. }
  27312. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  27313. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  27314. var NORMAL_CLIP = {};
  27315. var EO_CLIP = {};
  27316. CanvasGraphics.prototype = {
  27317. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  27318. transparency) {
  27319. // For pdfs that use blend modes we have to clear the canvas else certain
  27320. // blend modes can look wrong since we'd be blending with a white
  27321. // backdrop. The problem with a transparent backdrop though is we then
  27322. // don't get sub pixel anti aliasing on text, creating temporary
  27323. // transparent canvas when we have blend modes.
  27324. var width = this.ctx.canvas.width;
  27325. var height = this.ctx.canvas.height;
  27326. this.ctx.save();
  27327. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  27328. this.ctx.fillRect(0, 0, width, height);
  27329. this.ctx.restore();
  27330. if (transparency) {
  27331. var transparentCanvas = this.cachedCanvases.getCanvas(
  27332. 'transparent', width, height, true);
  27333. this.compositeCtx = this.ctx;
  27334. this.transparentCanvas = transparentCanvas.canvas;
  27335. this.ctx = transparentCanvas.context;
  27336. this.ctx.save();
  27337. // The transform can be applied before rendering, transferring it to
  27338. // the new canvas.
  27339. this.ctx.transform.apply(this.ctx,
  27340. this.compositeCtx.mozCurrentTransform);
  27341. }
  27342. this.ctx.save();
  27343. if (transform) {
  27344. this.ctx.transform.apply(this.ctx, transform);
  27345. }
  27346. this.ctx.transform.apply(this.ctx, viewport.transform);
  27347. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  27348. if (this.imageLayer) {
  27349. this.imageLayer.beginLayout();
  27350. }
  27351. },
  27352. executeOperatorList: function CanvasGraphics_executeOperatorList(
  27353. operatorList,
  27354. executionStartIdx, continueCallback,
  27355. stepper) {
  27356. var argsArray = operatorList.argsArray;
  27357. var fnArray = operatorList.fnArray;
  27358. var i = executionStartIdx || 0;
  27359. var argsArrayLen = argsArray.length;
  27360. // Sometimes the OperatorList to execute is empty.
  27361. if (argsArrayLen === i) {
  27362. return i;
  27363. }
  27364. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  27365. typeof continueCallback === 'function');
  27366. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  27367. var steps = 0;
  27368. var commonObjs = this.commonObjs;
  27369. var objs = this.objs;
  27370. var fnId;
  27371. while (true) {
  27372. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  27373. stepper.breakIt(i, continueCallback);
  27374. return i;
  27375. }
  27376. fnId = fnArray[i];
  27377. if (fnId !== OPS.dependency) {
  27378. this[fnId].apply(this, argsArray[i]);
  27379. } else {
  27380. var deps = argsArray[i];
  27381. for (var n = 0, nn = deps.length; n < nn; n++) {
  27382. var depObjId = deps[n];
  27383. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  27384. var objsPool = common ? commonObjs : objs;
  27385. // If the promise isn't resolved yet, add the continueCallback
  27386. // to the promise and bail out.
  27387. if (!objsPool.isResolved(depObjId)) {
  27388. objsPool.get(depObjId, continueCallback);
  27389. return i;
  27390. }
  27391. }
  27392. }
  27393. i++;
  27394. // If the entire operatorList was executed, stop as were done.
  27395. if (i === argsArrayLen) {
  27396. return i;
  27397. }
  27398. // If the execution took longer then a certain amount of time and
  27399. // `continueCallback` is specified, interrupt the execution.
  27400. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  27401. if (Date.now() > endTime) {
  27402. continueCallback();
  27403. return i;
  27404. }
  27405. steps = 0;
  27406. }
  27407. // If the operatorList isn't executed completely yet OR the execution
  27408. // time was short enough, do another execution round.
  27409. }
  27410. },
  27411. endDrawing: function CanvasGraphics_endDrawing() {
  27412. this.ctx.restore();
  27413. if (this.transparentCanvas) {
  27414. this.ctx = this.compositeCtx;
  27415. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  27416. this.transparentCanvas = null;
  27417. }
  27418. this.cachedCanvases.clear();
  27419. WebGLUtils.clear();
  27420. if (this.imageLayer) {
  27421. this.imageLayer.endLayout();
  27422. }
  27423. },
  27424. // Graphics state
  27425. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  27426. this.current.lineWidth = width;
  27427. this.ctx.lineWidth = width;
  27428. },
  27429. setLineCap: function CanvasGraphics_setLineCap(style) {
  27430. this.ctx.lineCap = LINE_CAP_STYLES[style];
  27431. },
  27432. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  27433. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  27434. },
  27435. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  27436. this.ctx.miterLimit = limit;
  27437. },
  27438. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  27439. var ctx = this.ctx;
  27440. if (ctx.setLineDash !== undefined) {
  27441. ctx.setLineDash(dashArray);
  27442. ctx.lineDashOffset = dashPhase;
  27443. } else {
  27444. ctx.mozDash = dashArray;
  27445. ctx.mozDashOffset = dashPhase;
  27446. }
  27447. },
  27448. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  27449. // Maybe if we one day fully support color spaces this will be important
  27450. // for now we can ignore.
  27451. // TODO set rendering intent?
  27452. },
  27453. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  27454. // There's no way to control this with canvas, but we can safely ignore.
  27455. // TODO set flatness?
  27456. },
  27457. setGState: function CanvasGraphics_setGState(states) {
  27458. for (var i = 0, ii = states.length; i < ii; i++) {
  27459. var state = states[i];
  27460. var key = state[0];
  27461. var value = state[1];
  27462. switch (key) {
  27463. case 'LW':
  27464. this.setLineWidth(value);
  27465. break;
  27466. case 'LC':
  27467. this.setLineCap(value);
  27468. break;
  27469. case 'LJ':
  27470. this.setLineJoin(value);
  27471. break;
  27472. case 'ML':
  27473. this.setMiterLimit(value);
  27474. break;
  27475. case 'D':
  27476. this.setDash(value[0], value[1]);
  27477. break;
  27478. case 'RI':
  27479. this.setRenderingIntent(value);
  27480. break;
  27481. case 'FL':
  27482. this.setFlatness(value);
  27483. break;
  27484. case 'Font':
  27485. this.setFont(value[0], value[1]);
  27486. break;
  27487. case 'CA':
  27488. this.current.strokeAlpha = state[1];
  27489. break;
  27490. case 'ca':
  27491. this.current.fillAlpha = state[1];
  27492. this.ctx.globalAlpha = state[1];
  27493. break;
  27494. case 'BM':
  27495. if (value && value.name && (value.name !== 'Normal')) {
  27496. var mode = value.name.replace(/([A-Z])/g,
  27497. function(c) {
  27498. return '-' + c.toLowerCase();
  27499. }
  27500. ).substring(1);
  27501. this.ctx.globalCompositeOperation = mode;
  27502. if (this.ctx.globalCompositeOperation !== mode) {
  27503. warn('globalCompositeOperation "' + mode +
  27504. '" is not supported');
  27505. }
  27506. } else {
  27507. this.ctx.globalCompositeOperation = 'source-over';
  27508. }
  27509. break;
  27510. case 'SMask':
  27511. if (this.current.activeSMask) {
  27512. this.endSMaskGroup();
  27513. }
  27514. this.current.activeSMask = value ? this.tempSMask : null;
  27515. if (this.current.activeSMask) {
  27516. this.beginSMaskGroup();
  27517. }
  27518. this.tempSMask = null;
  27519. break;
  27520. }
  27521. }
  27522. },
  27523. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  27524. var activeSMask = this.current.activeSMask;
  27525. var drawnWidth = activeSMask.canvas.width;
  27526. var drawnHeight = activeSMask.canvas.height;
  27527. var cacheId = 'smaskGroupAt' + this.groupLevel;
  27528. var scratchCanvas = this.cachedCanvases.getCanvas(
  27529. cacheId, drawnWidth, drawnHeight, true);
  27530. var currentCtx = this.ctx;
  27531. var currentTransform = currentCtx.mozCurrentTransform;
  27532. this.ctx.save();
  27533. var groupCtx = scratchCanvas.context;
  27534. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  27535. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  27536. groupCtx.transform.apply(groupCtx, currentTransform);
  27537. copyCtxState(currentCtx, groupCtx);
  27538. this.ctx = groupCtx;
  27539. this.setGState([
  27540. ['BM', 'Normal'],
  27541. ['ca', 1],
  27542. ['CA', 1]
  27543. ]);
  27544. this.groupStack.push(currentCtx);
  27545. this.groupLevel++;
  27546. },
  27547. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  27548. var groupCtx = this.ctx;
  27549. this.groupLevel--;
  27550. this.ctx = this.groupStack.pop();
  27551. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  27552. this.ctx.restore();
  27553. copyCtxState(groupCtx, this.ctx);
  27554. },
  27555. save: function CanvasGraphics_save() {
  27556. this.ctx.save();
  27557. var old = this.current;
  27558. this.stateStack.push(old);
  27559. this.current = old.clone();
  27560. this.current.activeSMask = null;
  27561. },
  27562. restore: function CanvasGraphics_restore() {
  27563. if (this.stateStack.length !== 0) {
  27564. if (this.current.activeSMask !== null) {
  27565. this.endSMaskGroup();
  27566. }
  27567. this.current = this.stateStack.pop();
  27568. this.ctx.restore();
  27569. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  27570. this.pendingClip = null;
  27571. this.cachedGetSinglePixelWidth = null;
  27572. }
  27573. },
  27574. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  27575. this.ctx.transform(a, b, c, d, e, f);
  27576. this.cachedGetSinglePixelWidth = null;
  27577. },
  27578. // Path
  27579. constructPath: function CanvasGraphics_constructPath(ops, args) {
  27580. var ctx = this.ctx;
  27581. var current = this.current;
  27582. var x = current.x, y = current.y;
  27583. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  27584. switch (ops[i] | 0) {
  27585. case OPS.rectangle:
  27586. x = args[j++];
  27587. y = args[j++];
  27588. var width = args[j++];
  27589. var height = args[j++];
  27590. if (width === 0) {
  27591. width = this.getSinglePixelWidth();
  27592. }
  27593. if (height === 0) {
  27594. height = this.getSinglePixelWidth();
  27595. }
  27596. var xw = x + width;
  27597. var yh = y + height;
  27598. this.ctx.moveTo(x, y);
  27599. this.ctx.lineTo(xw, y);
  27600. this.ctx.lineTo(xw, yh);
  27601. this.ctx.lineTo(x, yh);
  27602. this.ctx.lineTo(x, y);
  27603. this.ctx.closePath();
  27604. break;
  27605. case OPS.moveTo:
  27606. x = args[j++];
  27607. y = args[j++];
  27608. ctx.moveTo(x, y);
  27609. break;
  27610. case OPS.lineTo:
  27611. x = args[j++];
  27612. y = args[j++];
  27613. ctx.lineTo(x, y);
  27614. break;
  27615. case OPS.curveTo:
  27616. x = args[j + 4];
  27617. y = args[j + 5];
  27618. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  27619. x, y);
  27620. j += 6;
  27621. break;
  27622. case OPS.curveTo2:
  27623. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  27624. args[j + 2], args[j + 3]);
  27625. x = args[j + 2];
  27626. y = args[j + 3];
  27627. j += 4;
  27628. break;
  27629. case OPS.curveTo3:
  27630. x = args[j + 2];
  27631. y = args[j + 3];
  27632. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  27633. j += 4;
  27634. break;
  27635. case OPS.closePath:
  27636. ctx.closePath();
  27637. break;
  27638. }
  27639. }
  27640. current.setCurrentPoint(x, y);
  27641. },
  27642. closePath: function CanvasGraphics_closePath() {
  27643. this.ctx.closePath();
  27644. },
  27645. stroke: function CanvasGraphics_stroke(consumePath) {
  27646. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  27647. var ctx = this.ctx;
  27648. var strokeColor = this.current.strokeColor;
  27649. // Prevent drawing too thin lines by enforcing a minimum line width.
  27650. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  27651. this.current.lineWidth);
  27652. // For stroke we want to temporarily change the global alpha to the
  27653. // stroking alpha.
  27654. ctx.globalAlpha = this.current.strokeAlpha;
  27655. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  27656. strokeColor.type === 'Pattern') {
  27657. // for patterns, we transform to pattern space, calculate
  27658. // the pattern, call stroke, and restore to user space
  27659. ctx.save();
  27660. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  27661. ctx.stroke();
  27662. ctx.restore();
  27663. } else {
  27664. ctx.stroke();
  27665. }
  27666. if (consumePath) {
  27667. this.consumePath();
  27668. }
  27669. // Restore the global alpha to the fill alpha
  27670. ctx.globalAlpha = this.current.fillAlpha;
  27671. },
  27672. closeStroke: function CanvasGraphics_closeStroke() {
  27673. this.closePath();
  27674. this.stroke();
  27675. },
  27676. fill: function CanvasGraphics_fill(consumePath) {
  27677. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  27678. var ctx = this.ctx;
  27679. var fillColor = this.current.fillColor;
  27680. var isPatternFill = this.current.patternFill;
  27681. var needRestore = false;
  27682. if (isPatternFill) {
  27683. ctx.save();
  27684. if (this.baseTransform) {
  27685. ctx.setTransform.apply(ctx, this.baseTransform);
  27686. }
  27687. ctx.fillStyle = fillColor.getPattern(ctx, this);
  27688. needRestore = true;
  27689. }
  27690. if (this.pendingEOFill) {
  27691. if (ctx.mozFillRule !== undefined) {
  27692. ctx.mozFillRule = 'evenodd';
  27693. ctx.fill();
  27694. ctx.mozFillRule = 'nonzero';
  27695. } else {
  27696. ctx.fill('evenodd');
  27697. }
  27698. this.pendingEOFill = false;
  27699. } else {
  27700. ctx.fill();
  27701. }
  27702. if (needRestore) {
  27703. ctx.restore();
  27704. }
  27705. if (consumePath) {
  27706. this.consumePath();
  27707. }
  27708. },
  27709. eoFill: function CanvasGraphics_eoFill() {
  27710. this.pendingEOFill = true;
  27711. this.fill();
  27712. },
  27713. fillStroke: function CanvasGraphics_fillStroke() {
  27714. this.fill(false);
  27715. this.stroke(false);
  27716. this.consumePath();
  27717. },
  27718. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  27719. this.pendingEOFill = true;
  27720. this.fillStroke();
  27721. },
  27722. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  27723. this.closePath();
  27724. this.fillStroke();
  27725. },
  27726. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  27727. this.pendingEOFill = true;
  27728. this.closePath();
  27729. this.fillStroke();
  27730. },
  27731. endPath: function CanvasGraphics_endPath() {
  27732. this.consumePath();
  27733. },
  27734. // Clipping
  27735. clip: function CanvasGraphics_clip() {
  27736. this.pendingClip = NORMAL_CLIP;
  27737. },
  27738. eoClip: function CanvasGraphics_eoClip() {
  27739. this.pendingClip = EO_CLIP;
  27740. },
  27741. // Text
  27742. beginText: function CanvasGraphics_beginText() {
  27743. this.current.textMatrix = IDENTITY_MATRIX;
  27744. this.current.textMatrixScale = 1;
  27745. this.current.x = this.current.lineX = 0;
  27746. this.current.y = this.current.lineY = 0;
  27747. },
  27748. endText: function CanvasGraphics_endText() {
  27749. var paths = this.pendingTextPaths;
  27750. var ctx = this.ctx;
  27751. if (paths === undefined) {
  27752. ctx.beginPath();
  27753. return;
  27754. }
  27755. ctx.save();
  27756. ctx.beginPath();
  27757. for (var i = 0; i < paths.length; i++) {
  27758. var path = paths[i];
  27759. ctx.setTransform.apply(ctx, path.transform);
  27760. ctx.translate(path.x, path.y);
  27761. path.addToPath(ctx, path.fontSize);
  27762. }
  27763. ctx.restore();
  27764. ctx.clip();
  27765. ctx.beginPath();
  27766. delete this.pendingTextPaths;
  27767. },
  27768. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  27769. this.current.charSpacing = spacing;
  27770. },
  27771. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  27772. this.current.wordSpacing = spacing;
  27773. },
  27774. setHScale: function CanvasGraphics_setHScale(scale) {
  27775. this.current.textHScale = scale / 100;
  27776. },
  27777. setLeading: function CanvasGraphics_setLeading(leading) {
  27778. this.current.leading = -leading;
  27779. },
  27780. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  27781. var fontObj = this.commonObjs.get(fontRefName);
  27782. var current = this.current;
  27783. if (!fontObj) {
  27784. error('Can\'t find font for ' + fontRefName);
  27785. }
  27786. current.fontMatrix = (fontObj.fontMatrix ?
  27787. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  27788. // A valid matrix needs all main diagonal elements to be non-zero
  27789. // This also ensures we bypass FF bugzilla bug #719844.
  27790. if (current.fontMatrix[0] === 0 ||
  27791. current.fontMatrix[3] === 0) {
  27792. warn('Invalid font matrix for font ' + fontRefName);
  27793. }
  27794. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  27795. // and in some docs this can be negative (inverted x-y axes).
  27796. if (size < 0) {
  27797. size = -size;
  27798. current.fontDirection = -1;
  27799. } else {
  27800. current.fontDirection = 1;
  27801. }
  27802. this.current.font = fontObj;
  27803. this.current.fontSize = size;
  27804. if (fontObj.isType3Font) {
  27805. return; // we don't need ctx.font for Type3 fonts
  27806. }
  27807. var name = fontObj.loadedName || 'sans-serif';
  27808. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  27809. (fontObj.bold ? 'bold' : 'normal');
  27810. var italic = fontObj.italic ? 'italic' : 'normal';
  27811. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  27812. // Some font backends cannot handle fonts below certain size.
  27813. // Keeping the font at minimal size and using the fontSizeScale to change
  27814. // the current transformation matrix before the fillText/strokeText.
  27815. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  27816. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  27817. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  27818. this.current.fontSizeScale = size / browserFontSize;
  27819. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  27820. this.ctx.font = rule;
  27821. },
  27822. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  27823. this.current.textRenderingMode = mode;
  27824. },
  27825. setTextRise: function CanvasGraphics_setTextRise(rise) {
  27826. this.current.textRise = rise;
  27827. },
  27828. moveText: function CanvasGraphics_moveText(x, y) {
  27829. this.current.x = this.current.lineX += x;
  27830. this.current.y = this.current.lineY += y;
  27831. },
  27832. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  27833. this.setLeading(-y);
  27834. this.moveText(x, y);
  27835. },
  27836. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  27837. this.current.textMatrix = [a, b, c, d, e, f];
  27838. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  27839. this.current.x = this.current.lineX = 0;
  27840. this.current.y = this.current.lineY = 0;
  27841. },
  27842. nextLine: function CanvasGraphics_nextLine() {
  27843. this.moveText(0, this.current.leading);
  27844. },
  27845. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  27846. var ctx = this.ctx;
  27847. var current = this.current;
  27848. var font = current.font;
  27849. var textRenderingMode = current.textRenderingMode;
  27850. var fontSize = current.fontSize / current.fontSizeScale;
  27851. var fillStrokeMode = textRenderingMode &
  27852. TextRenderingMode.FILL_STROKE_MASK;
  27853. var isAddToPathSet = !!(textRenderingMode &
  27854. TextRenderingMode.ADD_TO_PATH_FLAG);
  27855. var addToPath;
  27856. if (font.disableFontFace || isAddToPathSet) {
  27857. addToPath = font.getPathGenerator(this.commonObjs, character);
  27858. }
  27859. if (font.disableFontFace) {
  27860. ctx.save();
  27861. ctx.translate(x, y);
  27862. ctx.beginPath();
  27863. addToPath(ctx, fontSize);
  27864. if (fillStrokeMode === TextRenderingMode.FILL ||
  27865. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27866. ctx.fill();
  27867. }
  27868. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27869. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27870. ctx.stroke();
  27871. }
  27872. ctx.restore();
  27873. } else {
  27874. if (fillStrokeMode === TextRenderingMode.FILL ||
  27875. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27876. ctx.fillText(character, x, y);
  27877. }
  27878. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27879. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27880. ctx.strokeText(character, x, y);
  27881. }
  27882. }
  27883. if (isAddToPathSet) {
  27884. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  27885. paths.push({
  27886. transform: ctx.mozCurrentTransform,
  27887. x: x,
  27888. y: y,
  27889. fontSize: fontSize,
  27890. addToPath: addToPath
  27891. });
  27892. }
  27893. },
  27894. get isFontSubpixelAAEnabled() {
  27895. // Checks if anti-aliasing is enabled when scaled text is painted.
  27896. // On Windows GDI scaled fonts looks bad.
  27897. var ctx = document.createElement('canvas').getContext('2d');
  27898. ctx.scale(1.5, 1);
  27899. ctx.fillText('I', 0, 10);
  27900. var data = ctx.getImageData(0, 0, 10, 10).data;
  27901. var enabled = false;
  27902. for (var i = 3; i < data.length; i += 4) {
  27903. if (data[i] > 0 && data[i] < 255) {
  27904. enabled = true;
  27905. break;
  27906. }
  27907. }
  27908. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  27909. },
  27910. showText: function CanvasGraphics_showText(glyphs) {
  27911. var current = this.current;
  27912. var font = current.font;
  27913. if (font.isType3Font) {
  27914. return this.showType3Text(glyphs);
  27915. }
  27916. var fontSize = current.fontSize;
  27917. if (fontSize === 0) {
  27918. return;
  27919. }
  27920. var ctx = this.ctx;
  27921. var fontSizeScale = current.fontSizeScale;
  27922. var charSpacing = current.charSpacing;
  27923. var wordSpacing = current.wordSpacing;
  27924. var fontDirection = current.fontDirection;
  27925. var textHScale = current.textHScale * fontDirection;
  27926. var glyphsLength = glyphs.length;
  27927. var vertical = font.vertical;
  27928. var spacingDir = vertical ? 1 : -1;
  27929. var defaultVMetrics = font.defaultVMetrics;
  27930. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  27931. var simpleFillText =
  27932. current.textRenderingMode === TextRenderingMode.FILL &&
  27933. !font.disableFontFace;
  27934. ctx.save();
  27935. ctx.transform.apply(ctx, current.textMatrix);
  27936. ctx.translate(current.x, current.y + current.textRise);
  27937. if (current.patternFill) {
  27938. // TODO: Some shading patterns are not applied correctly to text,
  27939. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  27940. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  27941. }
  27942. if (fontDirection > 0) {
  27943. ctx.scale(textHScale, -1);
  27944. } else {
  27945. ctx.scale(textHScale, 1);
  27946. }
  27947. var lineWidth = current.lineWidth;
  27948. var scale = current.textMatrixScale;
  27949. if (scale === 0 || lineWidth === 0) {
  27950. var fillStrokeMode = current.textRenderingMode &
  27951. TextRenderingMode.FILL_STROKE_MASK;
  27952. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27953. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27954. this.cachedGetSinglePixelWidth = null;
  27955. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  27956. }
  27957. } else {
  27958. lineWidth /= scale;
  27959. }
  27960. if (fontSizeScale !== 1.0) {
  27961. ctx.scale(fontSizeScale, fontSizeScale);
  27962. lineWidth /= fontSizeScale;
  27963. }
  27964. ctx.lineWidth = lineWidth;
  27965. var x = 0, i;
  27966. for (i = 0; i < glyphsLength; ++i) {
  27967. var glyph = glyphs[i];
  27968. if (isNum(glyph)) {
  27969. x += spacingDir * glyph * fontSize / 1000;
  27970. continue;
  27971. }
  27972. var restoreNeeded = false;
  27973. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  27974. var character = glyph.fontChar;
  27975. var accent = glyph.accent;
  27976. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  27977. var width = glyph.width;
  27978. if (vertical) {
  27979. var vmetric, vx, vy;
  27980. vmetric = glyph.vmetric || defaultVMetrics;
  27981. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  27982. vx = -vx * widthAdvanceScale;
  27983. vy = vmetric[2] * widthAdvanceScale;
  27984. width = vmetric ? -vmetric[0] : width;
  27985. scaledX = vx / fontSizeScale;
  27986. scaledY = (x + vy) / fontSizeScale;
  27987. } else {
  27988. scaledX = x / fontSizeScale;
  27989. scaledY = 0;
  27990. }
  27991. if (font.remeasure && width > 0) {
  27992. // Some standard fonts may not have the exact width: rescale per
  27993. // character if measured width is greater than expected glyph width
  27994. // and subpixel-aa is enabled, otherwise just center the glyph.
  27995. var measuredWidth = ctx.measureText(character).width * 1000 /
  27996. fontSize * fontSizeScale;
  27997. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  27998. var characterScaleX = width / measuredWidth;
  27999. restoreNeeded = true;
  28000. ctx.save();
  28001. ctx.scale(characterScaleX, 1);
  28002. scaledX /= characterScaleX;
  28003. } else if (width !== measuredWidth) {
  28004. scaledX += (width - measuredWidth) / 2000 *
  28005. fontSize / fontSizeScale;
  28006. }
  28007. }
  28008. if (simpleFillText && !accent) {
  28009. // common case
  28010. ctx.fillText(character, scaledX, scaledY);
  28011. } else {
  28012. this.paintChar(character, scaledX, scaledY);
  28013. if (accent) {
  28014. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  28015. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  28016. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  28017. }
  28018. }
  28019. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  28020. x += charWidth;
  28021. if (restoreNeeded) {
  28022. ctx.restore();
  28023. }
  28024. }
  28025. if (vertical) {
  28026. current.y -= x * textHScale;
  28027. } else {
  28028. current.x += x * textHScale;
  28029. }
  28030. ctx.restore();
  28031. },
  28032. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  28033. // Type3 fonts - each glyph is a "mini-PDF"
  28034. var ctx = this.ctx;
  28035. var current = this.current;
  28036. var font = current.font;
  28037. var fontSize = current.fontSize;
  28038. var fontDirection = current.fontDirection;
  28039. var spacingDir = font.vertical ? 1 : -1;
  28040. var charSpacing = current.charSpacing;
  28041. var wordSpacing = current.wordSpacing;
  28042. var textHScale = current.textHScale * fontDirection;
  28043. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  28044. var glyphsLength = glyphs.length;
  28045. var isTextInvisible =
  28046. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  28047. var i, glyph, width, spacingLength;
  28048. if (isTextInvisible || fontSize === 0) {
  28049. return;
  28050. }
  28051. this.cachedGetSinglePixelWidth = null;
  28052. ctx.save();
  28053. ctx.transform.apply(ctx, current.textMatrix);
  28054. ctx.translate(current.x, current.y);
  28055. ctx.scale(textHScale, fontDirection);
  28056. for (i = 0; i < glyphsLength; ++i) {
  28057. glyph = glyphs[i];
  28058. if (isNum(glyph)) {
  28059. spacingLength = spacingDir * glyph * fontSize / 1000;
  28060. this.ctx.translate(spacingLength, 0);
  28061. current.x += spacingLength * textHScale;
  28062. continue;
  28063. }
  28064. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  28065. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  28066. if (!operatorList) {
  28067. warn('Type3 character \"' + glyph.operatorListId +
  28068. '\" is not available');
  28069. continue;
  28070. }
  28071. this.processingType3 = glyph;
  28072. this.save();
  28073. ctx.scale(fontSize, fontSize);
  28074. ctx.transform.apply(ctx, fontMatrix);
  28075. this.executeOperatorList(operatorList);
  28076. this.restore();
  28077. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  28078. width = transformed[0] * fontSize + spacing;
  28079. ctx.translate(width, 0);
  28080. current.x += width * textHScale;
  28081. }
  28082. ctx.restore();
  28083. this.processingType3 = null;
  28084. },
  28085. // Type3 fonts
  28086. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  28087. // We can safely ignore this since the width should be the same
  28088. // as the width in the Widths array.
  28089. },
  28090. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  28091. yWidth,
  28092. llx,
  28093. lly,
  28094. urx,
  28095. ury) {
  28096. // TODO According to the spec we're also suppose to ignore any operators
  28097. // that set color or include images while processing this type3 font.
  28098. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  28099. this.clip();
  28100. this.endPath();
  28101. },
  28102. // Color
  28103. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  28104. var pattern;
  28105. if (IR[0] === 'TilingPattern') {
  28106. var color = IR[1];
  28107. var baseTransform = this.baseTransform ||
  28108. this.ctx.mozCurrentTransform.slice();
  28109. var self = this;
  28110. var canvasGraphicsFactory = {
  28111. createCanvasGraphics: function (ctx) {
  28112. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  28113. }
  28114. };
  28115. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  28116. baseTransform);
  28117. } else {
  28118. pattern = getShadingPatternFromIR(IR);
  28119. }
  28120. return pattern;
  28121. },
  28122. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  28123. this.current.strokeColor = this.getColorN_Pattern(arguments);
  28124. },
  28125. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  28126. this.current.fillColor = this.getColorN_Pattern(arguments);
  28127. this.current.patternFill = true;
  28128. },
  28129. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  28130. var color = Util.makeCssRgb(r, g, b);
  28131. this.ctx.strokeStyle = color;
  28132. this.current.strokeColor = color;
  28133. },
  28134. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  28135. var color = Util.makeCssRgb(r, g, b);
  28136. this.ctx.fillStyle = color;
  28137. this.current.fillColor = color;
  28138. this.current.patternFill = false;
  28139. },
  28140. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  28141. var ctx = this.ctx;
  28142. this.save();
  28143. var pattern = getShadingPatternFromIR(patternIR);
  28144. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  28145. var inv = ctx.mozCurrentTransformInverse;
  28146. if (inv) {
  28147. var canvas = ctx.canvas;
  28148. var width = canvas.width;
  28149. var height = canvas.height;
  28150. var bl = Util.applyTransform([0, 0], inv);
  28151. var br = Util.applyTransform([0, height], inv);
  28152. var ul = Util.applyTransform([width, 0], inv);
  28153. var ur = Util.applyTransform([width, height], inv);
  28154. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  28155. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  28156. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  28157. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  28158. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  28159. } else {
  28160. // HACK to draw the gradient onto an infinite rectangle.
  28161. // PDF gradients are drawn across the entire image while
  28162. // Canvas only allows gradients to be drawn in a rectangle
  28163. // The following bug should allow us to remove this.
  28164. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  28165. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  28166. }
  28167. this.restore();
  28168. },
  28169. // Images
  28170. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  28171. error('Should not call beginInlineImage');
  28172. },
  28173. beginImageData: function CanvasGraphics_beginImageData() {
  28174. error('Should not call beginImageData');
  28175. },
  28176. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  28177. bbox) {
  28178. this.save();
  28179. this.baseTransformStack.push(this.baseTransform);
  28180. if (isArray(matrix) && 6 === matrix.length) {
  28181. this.transform.apply(this, matrix);
  28182. }
  28183. this.baseTransform = this.ctx.mozCurrentTransform;
  28184. if (isArray(bbox) && 4 === bbox.length) {
  28185. var width = bbox[2] - bbox[0];
  28186. var height = bbox[3] - bbox[1];
  28187. this.ctx.rect(bbox[0], bbox[1], width, height);
  28188. this.clip();
  28189. this.endPath();
  28190. }
  28191. },
  28192. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  28193. this.restore();
  28194. this.baseTransform = this.baseTransformStack.pop();
  28195. },
  28196. beginGroup: function CanvasGraphics_beginGroup(group) {
  28197. this.save();
  28198. var currentCtx = this.ctx;
  28199. // TODO non-isolated groups - according to Rik at adobe non-isolated
  28200. // group results aren't usually that different and they even have tools
  28201. // that ignore this setting. Notes from Rik on implmenting:
  28202. // - When you encounter an transparency group, create a new canvas with
  28203. // the dimensions of the bbox
  28204. // - copy the content from the previous canvas to the new canvas
  28205. // - draw as usual
  28206. // - remove the backdrop alpha:
  28207. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  28208. // value of your transparency group and 'alphaBackdrop' the alpha of the
  28209. // backdrop
  28210. // - remove background color:
  28211. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  28212. if (!group.isolated) {
  28213. info('TODO: Support non-isolated groups.');
  28214. }
  28215. // TODO knockout - supposedly possible with the clever use of compositing
  28216. // modes.
  28217. if (group.knockout) {
  28218. warn('Knockout groups not supported.');
  28219. }
  28220. var currentTransform = currentCtx.mozCurrentTransform;
  28221. if (group.matrix) {
  28222. currentCtx.transform.apply(currentCtx, group.matrix);
  28223. }
  28224. assert(group.bbox, 'Bounding box is required.');
  28225. // Based on the current transform figure out how big the bounding box
  28226. // will actually be.
  28227. var bounds = Util.getAxialAlignedBoundingBox(
  28228. group.bbox,
  28229. currentCtx.mozCurrentTransform);
  28230. // Clip the bounding box to the current canvas.
  28231. var canvasBounds = [0,
  28232. 0,
  28233. currentCtx.canvas.width,
  28234. currentCtx.canvas.height];
  28235. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  28236. // Use ceil in case we're between sizes so we don't create canvas that is
  28237. // too small and make the canvas at least 1x1 pixels.
  28238. var offsetX = Math.floor(bounds[0]);
  28239. var offsetY = Math.floor(bounds[1]);
  28240. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  28241. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  28242. var scaleX = 1, scaleY = 1;
  28243. if (drawnWidth > MAX_GROUP_SIZE) {
  28244. scaleX = drawnWidth / MAX_GROUP_SIZE;
  28245. drawnWidth = MAX_GROUP_SIZE;
  28246. }
  28247. if (drawnHeight > MAX_GROUP_SIZE) {
  28248. scaleY = drawnHeight / MAX_GROUP_SIZE;
  28249. drawnHeight = MAX_GROUP_SIZE;
  28250. }
  28251. var cacheId = 'groupAt' + this.groupLevel;
  28252. if (group.smask) {
  28253. // Using two cache entries is case if masks are used one after another.
  28254. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  28255. }
  28256. var scratchCanvas = this.cachedCanvases.getCanvas(
  28257. cacheId, drawnWidth, drawnHeight, true);
  28258. var groupCtx = scratchCanvas.context;
  28259. // Since we created a new canvas that is just the size of the bounding box
  28260. // we have to translate the group ctx.
  28261. groupCtx.scale(1 / scaleX, 1 / scaleY);
  28262. groupCtx.translate(-offsetX, -offsetY);
  28263. groupCtx.transform.apply(groupCtx, currentTransform);
  28264. if (group.smask) {
  28265. // Saving state and cached mask to be used in setGState.
  28266. this.smaskStack.push({
  28267. canvas: scratchCanvas.canvas,
  28268. context: groupCtx,
  28269. offsetX: offsetX,
  28270. offsetY: offsetY,
  28271. scaleX: scaleX,
  28272. scaleY: scaleY,
  28273. subtype: group.smask.subtype,
  28274. backdrop: group.smask.backdrop,
  28275. transferMap: group.smask.transferMap || null
  28276. });
  28277. } else {
  28278. // Setup the current ctx so when the group is popped we draw it at the
  28279. // right location.
  28280. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  28281. currentCtx.translate(offsetX, offsetY);
  28282. currentCtx.scale(scaleX, scaleY);
  28283. }
  28284. // The transparency group inherits all off the current graphics state
  28285. // except the blend mode, soft mask, and alpha constants.
  28286. copyCtxState(currentCtx, groupCtx);
  28287. this.ctx = groupCtx;
  28288. this.setGState([
  28289. ['BM', 'Normal'],
  28290. ['ca', 1],
  28291. ['CA', 1]
  28292. ]);
  28293. this.groupStack.push(currentCtx);
  28294. this.groupLevel++;
  28295. },
  28296. endGroup: function CanvasGraphics_endGroup(group) {
  28297. this.groupLevel--;
  28298. var groupCtx = this.ctx;
  28299. this.ctx = this.groupStack.pop();
  28300. // Turn off image smoothing to avoid sub pixel interpolation which can
  28301. // look kind of blurry for some pdfs.
  28302. if (this.ctx.imageSmoothingEnabled !== undefined) {
  28303. this.ctx.imageSmoothingEnabled = false;
  28304. } else {
  28305. this.ctx.mozImageSmoothingEnabled = false;
  28306. }
  28307. if (group.smask) {
  28308. this.tempSMask = this.smaskStack.pop();
  28309. } else {
  28310. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  28311. }
  28312. this.restore();
  28313. },
  28314. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  28315. this.save();
  28316. this.current = new CanvasExtraState();
  28317. if (this.baseTransform) {
  28318. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  28319. }
  28320. },
  28321. endAnnotations: function CanvasGraphics_endAnnotations() {
  28322. this.restore();
  28323. },
  28324. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  28325. matrix) {
  28326. this.save();
  28327. if (isArray(rect) && 4 === rect.length) {
  28328. var width = rect[2] - rect[0];
  28329. var height = rect[3] - rect[1];
  28330. this.ctx.rect(rect[0], rect[1], width, height);
  28331. this.clip();
  28332. this.endPath();
  28333. }
  28334. this.transform.apply(this, transform);
  28335. this.transform.apply(this, matrix);
  28336. },
  28337. endAnnotation: function CanvasGraphics_endAnnotation() {
  28338. this.restore();
  28339. },
  28340. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  28341. var domImage = this.objs.get(objId);
  28342. if (!domImage) {
  28343. warn('Dependent image isn\'t ready yet');
  28344. return;
  28345. }
  28346. this.save();
  28347. var ctx = this.ctx;
  28348. // scale the image to the unit square
  28349. ctx.scale(1 / w, -1 / h);
  28350. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  28351. 0, -h, w, h);
  28352. if (this.imageLayer) {
  28353. var currentTransform = ctx.mozCurrentTransformInverse;
  28354. var position = this.getCanvasPosition(0, 0);
  28355. this.imageLayer.appendImage({
  28356. objId: objId,
  28357. left: position[0],
  28358. top: position[1],
  28359. width: w / currentTransform[0],
  28360. height: h / currentTransform[3]
  28361. });
  28362. }
  28363. this.restore();
  28364. },
  28365. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  28366. var ctx = this.ctx;
  28367. var width = img.width, height = img.height;
  28368. var fillColor = this.current.fillColor;
  28369. var isPatternFill = this.current.patternFill;
  28370. var glyph = this.processingType3;
  28371. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  28372. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  28373. glyph.compiled =
  28374. compileType3Glyph({data: img.data, width: width, height: height});
  28375. } else {
  28376. glyph.compiled = null;
  28377. }
  28378. }
  28379. if (glyph && glyph.compiled) {
  28380. glyph.compiled(ctx);
  28381. return;
  28382. }
  28383. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28384. width, height);
  28385. var maskCtx = maskCanvas.context;
  28386. maskCtx.save();
  28387. putBinaryImageMask(maskCtx, img);
  28388. maskCtx.globalCompositeOperation = 'source-in';
  28389. maskCtx.fillStyle = isPatternFill ?
  28390. fillColor.getPattern(maskCtx, this) : fillColor;
  28391. maskCtx.fillRect(0, 0, width, height);
  28392. maskCtx.restore();
  28393. this.paintInlineImageXObject(maskCanvas.canvas);
  28394. },
  28395. paintImageMaskXObjectRepeat:
  28396. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  28397. scaleY, positions) {
  28398. var width = imgData.width;
  28399. var height = imgData.height;
  28400. var fillColor = this.current.fillColor;
  28401. var isPatternFill = this.current.patternFill;
  28402. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28403. width, height);
  28404. var maskCtx = maskCanvas.context;
  28405. maskCtx.save();
  28406. putBinaryImageMask(maskCtx, imgData);
  28407. maskCtx.globalCompositeOperation = 'source-in';
  28408. maskCtx.fillStyle = isPatternFill ?
  28409. fillColor.getPattern(maskCtx, this) : fillColor;
  28410. maskCtx.fillRect(0, 0, width, height);
  28411. maskCtx.restore();
  28412. var ctx = this.ctx;
  28413. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  28414. ctx.save();
  28415. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  28416. ctx.scale(1, -1);
  28417. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  28418. 0, -1, 1, 1);
  28419. ctx.restore();
  28420. }
  28421. },
  28422. paintImageMaskXObjectGroup:
  28423. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  28424. var ctx = this.ctx;
  28425. var fillColor = this.current.fillColor;
  28426. var isPatternFill = this.current.patternFill;
  28427. for (var i = 0, ii = images.length; i < ii; i++) {
  28428. var image = images[i];
  28429. var width = image.width, height = image.height;
  28430. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28431. width, height);
  28432. var maskCtx = maskCanvas.context;
  28433. maskCtx.save();
  28434. putBinaryImageMask(maskCtx, image);
  28435. maskCtx.globalCompositeOperation = 'source-in';
  28436. maskCtx.fillStyle = isPatternFill ?
  28437. fillColor.getPattern(maskCtx, this) : fillColor;
  28438. maskCtx.fillRect(0, 0, width, height);
  28439. maskCtx.restore();
  28440. ctx.save();
  28441. ctx.transform.apply(ctx, image.transform);
  28442. ctx.scale(1, -1);
  28443. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  28444. 0, -1, 1, 1);
  28445. ctx.restore();
  28446. }
  28447. },
  28448. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  28449. var imgData = this.objs.get(objId);
  28450. if (!imgData) {
  28451. warn('Dependent image isn\'t ready yet');
  28452. return;
  28453. }
  28454. this.paintInlineImageXObject(imgData);
  28455. },
  28456. paintImageXObjectRepeat:
  28457. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  28458. positions) {
  28459. var imgData = this.objs.get(objId);
  28460. if (!imgData) {
  28461. warn('Dependent image isn\'t ready yet');
  28462. return;
  28463. }
  28464. var width = imgData.width;
  28465. var height = imgData.height;
  28466. var map = [];
  28467. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  28468. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  28469. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  28470. }
  28471. this.paintInlineImageXObjectGroup(imgData, map);
  28472. },
  28473. paintInlineImageXObject:
  28474. function CanvasGraphics_paintInlineImageXObject(imgData) {
  28475. var width = imgData.width;
  28476. var height = imgData.height;
  28477. var ctx = this.ctx;
  28478. this.save();
  28479. // scale the image to the unit square
  28480. ctx.scale(1 / width, -1 / height);
  28481. var currentTransform = ctx.mozCurrentTransformInverse;
  28482. var a = currentTransform[0], b = currentTransform[1];
  28483. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  28484. var c = currentTransform[2], d = currentTransform[3];
  28485. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  28486. var imgToPaint, tmpCanvas;
  28487. // instanceof HTMLElement does not work in jsdom node.js module
  28488. if (imgData instanceof HTMLElement || !imgData.data) {
  28489. imgToPaint = imgData;
  28490. } else {
  28491. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  28492. width, height);
  28493. var tmpCtx = tmpCanvas.context;
  28494. putBinaryImageData(tmpCtx, imgData);
  28495. imgToPaint = tmpCanvas.canvas;
  28496. }
  28497. var paintWidth = width, paintHeight = height;
  28498. var tmpCanvasId = 'prescale1';
  28499. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  28500. // pixels during drawImage operation, painting on the temporary canvas(es)
  28501. // that are twice smaller in size
  28502. while ((widthScale > 2 && paintWidth > 1) ||
  28503. (heightScale > 2 && paintHeight > 1)) {
  28504. var newWidth = paintWidth, newHeight = paintHeight;
  28505. if (widthScale > 2 && paintWidth > 1) {
  28506. newWidth = Math.ceil(paintWidth / 2);
  28507. widthScale /= paintWidth / newWidth;
  28508. }
  28509. if (heightScale > 2 && paintHeight > 1) {
  28510. newHeight = Math.ceil(paintHeight / 2);
  28511. heightScale /= paintHeight / newHeight;
  28512. }
  28513. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  28514. newWidth, newHeight);
  28515. tmpCtx = tmpCanvas.context;
  28516. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  28517. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  28518. 0, 0, newWidth, newHeight);
  28519. imgToPaint = tmpCanvas.canvas;
  28520. paintWidth = newWidth;
  28521. paintHeight = newHeight;
  28522. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  28523. }
  28524. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  28525. 0, -height, width, height);
  28526. if (this.imageLayer) {
  28527. var position = this.getCanvasPosition(0, -height);
  28528. this.imageLayer.appendImage({
  28529. imgData: imgData,
  28530. left: position[0],
  28531. top: position[1],
  28532. width: width / currentTransform[0],
  28533. height: height / currentTransform[3]
  28534. });
  28535. }
  28536. this.restore();
  28537. },
  28538. paintInlineImageXObjectGroup:
  28539. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  28540. var ctx = this.ctx;
  28541. var w = imgData.width;
  28542. var h = imgData.height;
  28543. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  28544. var tmpCtx = tmpCanvas.context;
  28545. putBinaryImageData(tmpCtx, imgData);
  28546. for (var i = 0, ii = map.length; i < ii; i++) {
  28547. var entry = map[i];
  28548. ctx.save();
  28549. ctx.transform.apply(ctx, entry.transform);
  28550. ctx.scale(1, -1);
  28551. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  28552. 0, -1, 1, 1);
  28553. if (this.imageLayer) {
  28554. var position = this.getCanvasPosition(entry.x, entry.y);
  28555. this.imageLayer.appendImage({
  28556. imgData: imgData,
  28557. left: position[0],
  28558. top: position[1],
  28559. width: w,
  28560. height: h
  28561. });
  28562. }
  28563. ctx.restore();
  28564. }
  28565. },
  28566. paintSolidColorImageMask:
  28567. function CanvasGraphics_paintSolidColorImageMask() {
  28568. this.ctx.fillRect(0, 0, 1, 1);
  28569. },
  28570. paintXObject: function CanvasGraphics_paintXObject() {
  28571. warn('Unsupported \'paintXObject\' command.');
  28572. },
  28573. // Marked content
  28574. markPoint: function CanvasGraphics_markPoint(tag) {
  28575. // TODO Marked content.
  28576. },
  28577. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  28578. // TODO Marked content.
  28579. },
  28580. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  28581. // TODO Marked content.
  28582. },
  28583. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  28584. tag, properties) {
  28585. // TODO Marked content.
  28586. },
  28587. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  28588. // TODO Marked content.
  28589. },
  28590. // Compatibility
  28591. beginCompat: function CanvasGraphics_beginCompat() {
  28592. // TODO ignore undefined operators (should we do that anyway?)
  28593. },
  28594. endCompat: function CanvasGraphics_endCompat() {
  28595. // TODO stop ignoring undefined operators
  28596. },
  28597. // Helper functions
  28598. consumePath: function CanvasGraphics_consumePath() {
  28599. var ctx = this.ctx;
  28600. if (this.pendingClip) {
  28601. if (this.pendingClip === EO_CLIP) {
  28602. if (ctx.mozFillRule !== undefined) {
  28603. ctx.mozFillRule = 'evenodd';
  28604. ctx.clip();
  28605. ctx.mozFillRule = 'nonzero';
  28606. } else {
  28607. ctx.clip('evenodd');
  28608. }
  28609. } else {
  28610. ctx.clip();
  28611. }
  28612. this.pendingClip = null;
  28613. }
  28614. ctx.beginPath();
  28615. },
  28616. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  28617. if (this.cachedGetSinglePixelWidth === null) {
  28618. var inverse = this.ctx.mozCurrentTransformInverse;
  28619. // max of the current horizontal and vertical scale
  28620. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  28621. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  28622. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  28623. }
  28624. return this.cachedGetSinglePixelWidth;
  28625. },
  28626. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  28627. var transform = this.ctx.mozCurrentTransform;
  28628. return [
  28629. transform[0] * x + transform[2] * y + transform[4],
  28630. transform[1] * x + transform[3] * y + transform[5]
  28631. ];
  28632. }
  28633. };
  28634. for (var op in OPS) {
  28635. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  28636. }
  28637. return CanvasGraphics;
  28638. })();
  28639. exports.CanvasGraphics = CanvasGraphics;
  28640. exports.createScratchCanvas = createScratchCanvas;
  28641. }));
  28642. (function (root, factory) {
  28643. {
  28644. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  28645. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  28646. }
  28647. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  28648. var Util = sharedUtil.Util;
  28649. var assert = sharedUtil.assert;
  28650. var error = sharedUtil.error;
  28651. var isInt = sharedUtil.isInt;
  28652. var isString = sharedUtil.isString;
  28653. var warn = sharedUtil.warn;
  28654. var isName = corePrimitives.isName;
  28655. var isCmd = corePrimitives.isCmd;
  28656. var isStream = corePrimitives.isStream;
  28657. var StringStream = coreStream.StringStream;
  28658. var Lexer = coreParser.Lexer;
  28659. var isEOF = coreParser.isEOF;
  28660. var BUILT_IN_CMAPS = [
  28661. // << Start unicode maps.
  28662. 'Adobe-GB1-UCS2',
  28663. 'Adobe-CNS1-UCS2',
  28664. 'Adobe-Japan1-UCS2',
  28665. 'Adobe-Korea1-UCS2',
  28666. // >> End unicode maps.
  28667. '78-EUC-H',
  28668. '78-EUC-V',
  28669. '78-H',
  28670. '78-RKSJ-H',
  28671. '78-RKSJ-V',
  28672. '78-V',
  28673. '78ms-RKSJ-H',
  28674. '78ms-RKSJ-V',
  28675. '83pv-RKSJ-H',
  28676. '90ms-RKSJ-H',
  28677. '90ms-RKSJ-V',
  28678. '90msp-RKSJ-H',
  28679. '90msp-RKSJ-V',
  28680. '90pv-RKSJ-H',
  28681. '90pv-RKSJ-V',
  28682. 'Add-H',
  28683. 'Add-RKSJ-H',
  28684. 'Add-RKSJ-V',
  28685. 'Add-V',
  28686. 'Adobe-CNS1-0',
  28687. 'Adobe-CNS1-1',
  28688. 'Adobe-CNS1-2',
  28689. 'Adobe-CNS1-3',
  28690. 'Adobe-CNS1-4',
  28691. 'Adobe-CNS1-5',
  28692. 'Adobe-CNS1-6',
  28693. 'Adobe-GB1-0',
  28694. 'Adobe-GB1-1',
  28695. 'Adobe-GB1-2',
  28696. 'Adobe-GB1-3',
  28697. 'Adobe-GB1-4',
  28698. 'Adobe-GB1-5',
  28699. 'Adobe-Japan1-0',
  28700. 'Adobe-Japan1-1',
  28701. 'Adobe-Japan1-2',
  28702. 'Adobe-Japan1-3',
  28703. 'Adobe-Japan1-4',
  28704. 'Adobe-Japan1-5',
  28705. 'Adobe-Japan1-6',
  28706. 'Adobe-Korea1-0',
  28707. 'Adobe-Korea1-1',
  28708. 'Adobe-Korea1-2',
  28709. 'B5-H',
  28710. 'B5-V',
  28711. 'B5pc-H',
  28712. 'B5pc-V',
  28713. 'CNS-EUC-H',
  28714. 'CNS-EUC-V',
  28715. 'CNS1-H',
  28716. 'CNS1-V',
  28717. 'CNS2-H',
  28718. 'CNS2-V',
  28719. 'ETHK-B5-H',
  28720. 'ETHK-B5-V',
  28721. 'ETen-B5-H',
  28722. 'ETen-B5-V',
  28723. 'ETenms-B5-H',
  28724. 'ETenms-B5-V',
  28725. 'EUC-H',
  28726. 'EUC-V',
  28727. 'Ext-H',
  28728. 'Ext-RKSJ-H',
  28729. 'Ext-RKSJ-V',
  28730. 'Ext-V',
  28731. 'GB-EUC-H',
  28732. 'GB-EUC-V',
  28733. 'GB-H',
  28734. 'GB-V',
  28735. 'GBK-EUC-H',
  28736. 'GBK-EUC-V',
  28737. 'GBK2K-H',
  28738. 'GBK2K-V',
  28739. 'GBKp-EUC-H',
  28740. 'GBKp-EUC-V',
  28741. 'GBT-EUC-H',
  28742. 'GBT-EUC-V',
  28743. 'GBT-H',
  28744. 'GBT-V',
  28745. 'GBTpc-EUC-H',
  28746. 'GBTpc-EUC-V',
  28747. 'GBpc-EUC-H',
  28748. 'GBpc-EUC-V',
  28749. 'H',
  28750. 'HKdla-B5-H',
  28751. 'HKdla-B5-V',
  28752. 'HKdlb-B5-H',
  28753. 'HKdlb-B5-V',
  28754. 'HKgccs-B5-H',
  28755. 'HKgccs-B5-V',
  28756. 'HKm314-B5-H',
  28757. 'HKm314-B5-V',
  28758. 'HKm471-B5-H',
  28759. 'HKm471-B5-V',
  28760. 'HKscs-B5-H',
  28761. 'HKscs-B5-V',
  28762. 'Hankaku',
  28763. 'Hiragana',
  28764. 'KSC-EUC-H',
  28765. 'KSC-EUC-V',
  28766. 'KSC-H',
  28767. 'KSC-Johab-H',
  28768. 'KSC-Johab-V',
  28769. 'KSC-V',
  28770. 'KSCms-UHC-H',
  28771. 'KSCms-UHC-HW-H',
  28772. 'KSCms-UHC-HW-V',
  28773. 'KSCms-UHC-V',
  28774. 'KSCpc-EUC-H',
  28775. 'KSCpc-EUC-V',
  28776. 'Katakana',
  28777. 'NWP-H',
  28778. 'NWP-V',
  28779. 'RKSJ-H',
  28780. 'RKSJ-V',
  28781. 'Roman',
  28782. 'UniCNS-UCS2-H',
  28783. 'UniCNS-UCS2-V',
  28784. 'UniCNS-UTF16-H',
  28785. 'UniCNS-UTF16-V',
  28786. 'UniCNS-UTF32-H',
  28787. 'UniCNS-UTF32-V',
  28788. 'UniCNS-UTF8-H',
  28789. 'UniCNS-UTF8-V',
  28790. 'UniGB-UCS2-H',
  28791. 'UniGB-UCS2-V',
  28792. 'UniGB-UTF16-H',
  28793. 'UniGB-UTF16-V',
  28794. 'UniGB-UTF32-H',
  28795. 'UniGB-UTF32-V',
  28796. 'UniGB-UTF8-H',
  28797. 'UniGB-UTF8-V',
  28798. 'UniJIS-UCS2-H',
  28799. 'UniJIS-UCS2-HW-H',
  28800. 'UniJIS-UCS2-HW-V',
  28801. 'UniJIS-UCS2-V',
  28802. 'UniJIS-UTF16-H',
  28803. 'UniJIS-UTF16-V',
  28804. 'UniJIS-UTF32-H',
  28805. 'UniJIS-UTF32-V',
  28806. 'UniJIS-UTF8-H',
  28807. 'UniJIS-UTF8-V',
  28808. 'UniJIS2004-UTF16-H',
  28809. 'UniJIS2004-UTF16-V',
  28810. 'UniJIS2004-UTF32-H',
  28811. 'UniJIS2004-UTF32-V',
  28812. 'UniJIS2004-UTF8-H',
  28813. 'UniJIS2004-UTF8-V',
  28814. 'UniJISPro-UCS2-HW-V',
  28815. 'UniJISPro-UCS2-V',
  28816. 'UniJISPro-UTF8-V',
  28817. 'UniJISX0213-UTF32-H',
  28818. 'UniJISX0213-UTF32-V',
  28819. 'UniJISX02132004-UTF32-H',
  28820. 'UniJISX02132004-UTF32-V',
  28821. 'UniKS-UCS2-H',
  28822. 'UniKS-UCS2-V',
  28823. 'UniKS-UTF16-H',
  28824. 'UniKS-UTF16-V',
  28825. 'UniKS-UTF32-H',
  28826. 'UniKS-UTF32-V',
  28827. 'UniKS-UTF8-H',
  28828. 'UniKS-UTF8-V',
  28829. 'V',
  28830. 'WP-Symbol'];
  28831. // CMap, not to be confused with TrueType's cmap.
  28832. var CMap = (function CMapClosure() {
  28833. function CMap(builtInCMap) {
  28834. // Codespace ranges are stored as follows:
  28835. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  28836. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  28837. this.codespaceRanges = [[], [], [], []];
  28838. this.numCodespaceRanges = 0;
  28839. // Map entries have one of two forms.
  28840. // - cid chars are 16-bit unsigned integers, stored as integers.
  28841. // - bf chars are variable-length byte sequences, stored as strings, with
  28842. // one byte per character.
  28843. this._map = [];
  28844. this.name = '';
  28845. this.vertical = false;
  28846. this.useCMap = null;
  28847. this.builtInCMap = builtInCMap;
  28848. }
  28849. CMap.prototype = {
  28850. addCodespaceRange: function(n, low, high) {
  28851. this.codespaceRanges[n - 1].push(low, high);
  28852. this.numCodespaceRanges++;
  28853. },
  28854. mapCidRange: function(low, high, dstLow) {
  28855. while (low <= high) {
  28856. this._map[low++] = dstLow++;
  28857. }
  28858. },
  28859. mapBfRange: function(low, high, dstLow) {
  28860. var lastByte = dstLow.length - 1;
  28861. while (low <= high) {
  28862. this._map[low++] = dstLow;
  28863. // Only the last byte has to be incremented.
  28864. dstLow = dstLow.substr(0, lastByte) +
  28865. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  28866. }
  28867. },
  28868. mapBfRangeToArray: function(low, high, array) {
  28869. var i = 0, ii = array.length;
  28870. while (low <= high && i < ii) {
  28871. this._map[low] = array[i++];
  28872. ++low;
  28873. }
  28874. },
  28875. // This is used for both bf and cid chars.
  28876. mapOne: function(src, dst) {
  28877. this._map[src] = dst;
  28878. },
  28879. lookup: function(code) {
  28880. return this._map[code];
  28881. },
  28882. contains: function(code) {
  28883. return this._map[code] !== undefined;
  28884. },
  28885. forEach: function(callback) {
  28886. // Most maps have fewer than 65536 entries, and for those we use normal
  28887. // array iteration. But really sparse tables are possible -- e.g. with
  28888. // indices in the *billions*. For such tables we use for..in, which isn't
  28889. // ideal because it stringifies the indices for all present elements, but
  28890. // it does avoid iterating over every undefined entry.
  28891. var map = this._map;
  28892. var length = map.length;
  28893. var i;
  28894. if (length <= 0x10000) {
  28895. for (i = 0; i < length; i++) {
  28896. if (map[i] !== undefined) {
  28897. callback(i, map[i]);
  28898. }
  28899. }
  28900. } else {
  28901. for (i in this._map) {
  28902. callback(i, map[i]);
  28903. }
  28904. }
  28905. },
  28906. charCodeOf: function(value) {
  28907. return this._map.indexOf(value);
  28908. },
  28909. getMap: function() {
  28910. return this._map;
  28911. },
  28912. readCharCode: function(str, offset, out) {
  28913. var c = 0;
  28914. var codespaceRanges = this.codespaceRanges;
  28915. var codespaceRangesLen = this.codespaceRanges.length;
  28916. // 9.7.6.2 CMap Mapping
  28917. // The code length is at most 4.
  28918. for (var n = 0; n < codespaceRangesLen; n++) {
  28919. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  28920. // Check each codespace range to see if it falls within.
  28921. var codespaceRange = codespaceRanges[n];
  28922. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  28923. var low = codespaceRange[k++];
  28924. var high = codespaceRange[k++];
  28925. if (c >= low && c <= high) {
  28926. out.charcode = c;
  28927. out.length = n + 1;
  28928. return;
  28929. }
  28930. }
  28931. }
  28932. out.charcode = 0;
  28933. out.length = 1;
  28934. },
  28935. get length() {
  28936. return this._map.length;
  28937. },
  28938. get isIdentityCMap() {
  28939. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  28940. return false;
  28941. }
  28942. if (this._map.length !== 0x10000) {
  28943. return false;
  28944. }
  28945. for (var i = 0; i < 0x10000; i++) {
  28946. if (this._map[i] !== i) {
  28947. return false;
  28948. }
  28949. }
  28950. return true;
  28951. }
  28952. };
  28953. return CMap;
  28954. })();
  28955. // A special case of CMap, where the _map array implicitly has a length of
  28956. // 65536 and each element is equal to its index.
  28957. var IdentityCMap = (function IdentityCMapClosure() {
  28958. function IdentityCMap(vertical, n) {
  28959. CMap.call(this);
  28960. this.vertical = vertical;
  28961. this.addCodespaceRange(n, 0, 0xffff);
  28962. }
  28963. Util.inherit(IdentityCMap, CMap, {});
  28964. IdentityCMap.prototype = {
  28965. addCodespaceRange: CMap.prototype.addCodespaceRange,
  28966. mapCidRange: function(low, high, dstLow) {
  28967. error('should not call mapCidRange');
  28968. },
  28969. mapBfRange: function(low, high, dstLow) {
  28970. error('should not call mapBfRange');
  28971. },
  28972. mapBfRangeToArray: function(low, high, array) {
  28973. error('should not call mapBfRangeToArray');
  28974. },
  28975. mapOne: function(src, dst) {
  28976. error('should not call mapCidOne');
  28977. },
  28978. lookup: function(code) {
  28979. return (isInt(code) && code <= 0xffff) ? code : undefined;
  28980. },
  28981. contains: function(code) {
  28982. return isInt(code) && code <= 0xffff;
  28983. },
  28984. forEach: function(callback) {
  28985. for (var i = 0; i <= 0xffff; i++) {
  28986. callback(i, i);
  28987. }
  28988. },
  28989. charCodeOf: function(value) {
  28990. return (isInt(value) && value <= 0xffff) ? value : -1;
  28991. },
  28992. getMap: function() {
  28993. // Sometimes identity maps must be instantiated, but it's rare.
  28994. var map = new Array(0x10000);
  28995. for (var i = 0; i <= 0xffff; i++) {
  28996. map[i] = i;
  28997. }
  28998. return map;
  28999. },
  29000. readCharCode: CMap.prototype.readCharCode,
  29001. get length() {
  29002. return 0x10000;
  29003. },
  29004. get isIdentityCMap() {
  29005. error('should not access .isIdentityCMap');
  29006. }
  29007. };
  29008. return IdentityCMap;
  29009. })();
  29010. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  29011. function fetchBinaryData(url) {
  29012. var nonBinaryRequest = PDFJS.disableWorker;
  29013. var request = new XMLHttpRequest();
  29014. request.open('GET', url, false);
  29015. if (!nonBinaryRequest) {
  29016. try {
  29017. request.responseType = 'arraybuffer';
  29018. nonBinaryRequest = request.responseType !== 'arraybuffer';
  29019. } catch (e) {
  29020. nonBinaryRequest = true;
  29021. }
  29022. }
  29023. if (nonBinaryRequest && request.overrideMimeType) {
  29024. request.overrideMimeType('text/plain; charset=x-user-defined');
  29025. }
  29026. request.send(null);
  29027. if (nonBinaryRequest ? !request.responseText : !request.response) {
  29028. error('Unable to get binary cMap at: ' + url);
  29029. }
  29030. if (nonBinaryRequest) {
  29031. var data = Array.prototype.map.call(request.responseText, function (ch) {
  29032. return ch.charCodeAt(0) & 255;
  29033. });
  29034. return new Uint8Array(data);
  29035. }
  29036. return new Uint8Array(request.response);
  29037. }
  29038. function hexToInt(a, size) {
  29039. var n = 0;
  29040. for (var i = 0; i <= size; i++) {
  29041. n = (n << 8) | a[i];
  29042. }
  29043. return n >>> 0;
  29044. }
  29045. function hexToStr(a, size) {
  29046. // This code is hot. Special-case some common values to avoid creating an
  29047. // object with subarray().
  29048. if (size === 1) {
  29049. return String.fromCharCode(a[0], a[1]);
  29050. }
  29051. if (size === 3) {
  29052. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29053. }
  29054. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29055. }
  29056. function addHex(a, b, size) {
  29057. var c = 0;
  29058. for (var i = size; i >= 0; i--) {
  29059. c += a[i] + b[i];
  29060. a[i] = c & 255;
  29061. c >>= 8;
  29062. }
  29063. }
  29064. function incHex(a, size) {
  29065. var c = 1;
  29066. for (var i = size; i >= 0 && c > 0; i--) {
  29067. c += a[i];
  29068. a[i] = c & 255;
  29069. c >>= 8;
  29070. }
  29071. }
  29072. var MAX_NUM_SIZE = 16;
  29073. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29074. function BinaryCMapStream(data) {
  29075. this.buffer = data;
  29076. this.pos = 0;
  29077. this.end = data.length;
  29078. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29079. }
  29080. BinaryCMapStream.prototype = {
  29081. readByte: function () {
  29082. if (this.pos >= this.end) {
  29083. return -1;
  29084. }
  29085. return this.buffer[this.pos++];
  29086. },
  29087. readNumber: function () {
  29088. var n = 0;
  29089. var last;
  29090. do {
  29091. var b = this.readByte();
  29092. if (b < 0) {
  29093. error('unexpected EOF in bcmap');
  29094. }
  29095. last = !(b & 0x80);
  29096. n = (n << 7) | (b & 0x7F);
  29097. } while (!last);
  29098. return n;
  29099. },
  29100. readSigned: function () {
  29101. var n = this.readNumber();
  29102. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29103. },
  29104. readHex: function (num, size) {
  29105. num.set(this.buffer.subarray(this.pos,
  29106. this.pos + size + 1));
  29107. this.pos += size + 1;
  29108. },
  29109. readHexNumber: function (num, size) {
  29110. var last;
  29111. var stack = this.tmpBuf, sp = 0;
  29112. do {
  29113. var b = this.readByte();
  29114. if (b < 0) {
  29115. error('unexpected EOF in bcmap');
  29116. }
  29117. last = !(b & 0x80);
  29118. stack[sp++] = b & 0x7F;
  29119. } while (!last);
  29120. var i = size, buffer = 0, bufferSize = 0;
  29121. while (i >= 0) {
  29122. while (bufferSize < 8 && stack.length > 0) {
  29123. buffer = (stack[--sp] << bufferSize) | buffer;
  29124. bufferSize += 7;
  29125. }
  29126. num[i] = buffer & 255;
  29127. i--;
  29128. buffer >>= 8;
  29129. bufferSize -= 8;
  29130. }
  29131. },
  29132. readHexSigned: function (num, size) {
  29133. this.readHexNumber(num, size);
  29134. var sign = num[size] & 1 ? 255 : 0;
  29135. var c = 0;
  29136. for (var i = 0; i <= size; i++) {
  29137. c = ((c & 1) << 8) | num[i];
  29138. num[i] = (c >> 1) ^ sign;
  29139. }
  29140. },
  29141. readString: function () {
  29142. var len = this.readNumber();
  29143. var s = '';
  29144. for (var i = 0; i < len; i++) {
  29145. s += String.fromCharCode(this.readNumber());
  29146. }
  29147. return s;
  29148. }
  29149. };
  29150. function processBinaryCMap(url, cMap, extend) {
  29151. var data = fetchBinaryData(url);
  29152. var stream = new BinaryCMapStream(data);
  29153. var header = stream.readByte();
  29154. cMap.vertical = !!(header & 1);
  29155. var useCMap = null;
  29156. var start = new Uint8Array(MAX_NUM_SIZE);
  29157. var end = new Uint8Array(MAX_NUM_SIZE);
  29158. var char = new Uint8Array(MAX_NUM_SIZE);
  29159. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29160. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29161. var code;
  29162. var b;
  29163. while ((b = stream.readByte()) >= 0) {
  29164. var type = b >> 5;
  29165. if (type === 7) { // metadata, e.g. comment or usecmap
  29166. switch (b & 0x1F) {
  29167. case 0:
  29168. stream.readString(); // skipping comment
  29169. break;
  29170. case 1:
  29171. useCMap = stream.readString();
  29172. break;
  29173. }
  29174. continue;
  29175. }
  29176. var sequence = !!(b & 0x10);
  29177. var dataSize = b & 15;
  29178. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29179. var ucs2DataSize = 1;
  29180. var subitemsCount = stream.readNumber();
  29181. var i;
  29182. switch (type) {
  29183. case 0: // codespacerange
  29184. stream.readHex(start, dataSize);
  29185. stream.readHexNumber(end, dataSize);
  29186. addHex(end, start, dataSize);
  29187. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29188. hexToInt(end, dataSize));
  29189. for (i = 1; i < subitemsCount; i++) {
  29190. incHex(end, dataSize);
  29191. stream.readHexNumber(start, dataSize);
  29192. addHex(start, end, dataSize);
  29193. stream.readHexNumber(end, dataSize);
  29194. addHex(end, start, dataSize);
  29195. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29196. hexToInt(end, dataSize));
  29197. }
  29198. break;
  29199. case 1: // notdefrange
  29200. stream.readHex(start, dataSize);
  29201. stream.readHexNumber(end, dataSize);
  29202. addHex(end, start, dataSize);
  29203. code = stream.readNumber();
  29204. // undefined range, skipping
  29205. for (i = 1; i < subitemsCount; i++) {
  29206. incHex(end, dataSize);
  29207. stream.readHexNumber(start, dataSize);
  29208. addHex(start, end, dataSize);
  29209. stream.readHexNumber(end, dataSize);
  29210. addHex(end, start, dataSize);
  29211. code = stream.readNumber();
  29212. // nop
  29213. }
  29214. break;
  29215. case 2: // cidchar
  29216. stream.readHex(char, dataSize);
  29217. code = stream.readNumber();
  29218. cMap.mapOne(hexToInt(char, dataSize), code);
  29219. for (i = 1; i < subitemsCount; i++) {
  29220. incHex(char, dataSize);
  29221. if (!sequence) {
  29222. stream.readHexNumber(tmp, dataSize);
  29223. addHex(char, tmp, dataSize);
  29224. }
  29225. code = stream.readSigned() + (code + 1);
  29226. cMap.mapOne(hexToInt(char, dataSize), code);
  29227. }
  29228. break;
  29229. case 3: // cidrange
  29230. stream.readHex(start, dataSize);
  29231. stream.readHexNumber(end, dataSize);
  29232. addHex(end, start, dataSize);
  29233. code = stream.readNumber();
  29234. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29235. code);
  29236. for (i = 1; i < subitemsCount; i++) {
  29237. incHex(end, dataSize);
  29238. if (!sequence) {
  29239. stream.readHexNumber(start, dataSize);
  29240. addHex(start, end, dataSize);
  29241. } else {
  29242. start.set(end);
  29243. }
  29244. stream.readHexNumber(end, dataSize);
  29245. addHex(end, start, dataSize);
  29246. code = stream.readNumber();
  29247. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29248. code);
  29249. }
  29250. break;
  29251. case 4: // bfchar
  29252. stream.readHex(char, ucs2DataSize);
  29253. stream.readHex(charCode, dataSize);
  29254. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29255. hexToStr(charCode, dataSize));
  29256. for (i = 1; i < subitemsCount; i++) {
  29257. incHex(char, ucs2DataSize);
  29258. if (!sequence) {
  29259. stream.readHexNumber(tmp, ucs2DataSize);
  29260. addHex(char, tmp, ucs2DataSize);
  29261. }
  29262. incHex(charCode, dataSize);
  29263. stream.readHexSigned(tmp, dataSize);
  29264. addHex(charCode, tmp, dataSize);
  29265. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29266. hexToStr(charCode, dataSize));
  29267. }
  29268. break;
  29269. case 5: // bfrange
  29270. stream.readHex(start, ucs2DataSize);
  29271. stream.readHexNumber(end, ucs2DataSize);
  29272. addHex(end, start, ucs2DataSize);
  29273. stream.readHex(charCode, dataSize);
  29274. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29275. hexToInt(end, ucs2DataSize),
  29276. hexToStr(charCode, dataSize));
  29277. for (i = 1; i < subitemsCount; i++) {
  29278. incHex(end, ucs2DataSize);
  29279. if (!sequence) {
  29280. stream.readHexNumber(start, ucs2DataSize);
  29281. addHex(start, end, ucs2DataSize);
  29282. } else {
  29283. start.set(end);
  29284. }
  29285. stream.readHexNumber(end, ucs2DataSize);
  29286. addHex(end, start, ucs2DataSize);
  29287. stream.readHex(charCode, dataSize);
  29288. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29289. hexToInt(end, ucs2DataSize),
  29290. hexToStr(charCode, dataSize));
  29291. }
  29292. break;
  29293. default:
  29294. error('Unknown type: ' + type);
  29295. break;
  29296. }
  29297. }
  29298. if (useCMap) {
  29299. extend(useCMap);
  29300. }
  29301. return cMap;
  29302. }
  29303. function BinaryCMapReader() {}
  29304. BinaryCMapReader.prototype = {
  29305. read: processBinaryCMap
  29306. };
  29307. return BinaryCMapReader;
  29308. })();
  29309. var CMapFactory = (function CMapFactoryClosure() {
  29310. function strToInt(str) {
  29311. var a = 0;
  29312. for (var i = 0; i < str.length; i++) {
  29313. a = (a << 8) | str.charCodeAt(i);
  29314. }
  29315. return a >>> 0;
  29316. }
  29317. function expectString(obj) {
  29318. if (!isString(obj)) {
  29319. error('Malformed CMap: expected string.');
  29320. }
  29321. }
  29322. function expectInt(obj) {
  29323. if (!isInt(obj)) {
  29324. error('Malformed CMap: expected int.');
  29325. }
  29326. }
  29327. function parseBfChar(cMap, lexer) {
  29328. while (true) {
  29329. var obj = lexer.getObj();
  29330. if (isEOF(obj)) {
  29331. break;
  29332. }
  29333. if (isCmd(obj, 'endbfchar')) {
  29334. return;
  29335. }
  29336. expectString(obj);
  29337. var src = strToInt(obj);
  29338. obj = lexer.getObj();
  29339. // TODO are /dstName used?
  29340. expectString(obj);
  29341. var dst = obj;
  29342. cMap.mapOne(src, dst);
  29343. }
  29344. }
  29345. function parseBfRange(cMap, lexer) {
  29346. while (true) {
  29347. var obj = lexer.getObj();
  29348. if (isEOF(obj)) {
  29349. break;
  29350. }
  29351. if (isCmd(obj, 'endbfrange')) {
  29352. return;
  29353. }
  29354. expectString(obj);
  29355. var low = strToInt(obj);
  29356. obj = lexer.getObj();
  29357. expectString(obj);
  29358. var high = strToInt(obj);
  29359. obj = lexer.getObj();
  29360. if (isInt(obj) || isString(obj)) {
  29361. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  29362. cMap.mapBfRange(low, high, dstLow);
  29363. } else if (isCmd(obj, '[')) {
  29364. obj = lexer.getObj();
  29365. var array = [];
  29366. while (!isCmd(obj, ']') && !isEOF(obj)) {
  29367. array.push(obj);
  29368. obj = lexer.getObj();
  29369. }
  29370. cMap.mapBfRangeToArray(low, high, array);
  29371. } else {
  29372. break;
  29373. }
  29374. }
  29375. error('Invalid bf range.');
  29376. }
  29377. function parseCidChar(cMap, lexer) {
  29378. while (true) {
  29379. var obj = lexer.getObj();
  29380. if (isEOF(obj)) {
  29381. break;
  29382. }
  29383. if (isCmd(obj, 'endcidchar')) {
  29384. return;
  29385. }
  29386. expectString(obj);
  29387. var src = strToInt(obj);
  29388. obj = lexer.getObj();
  29389. expectInt(obj);
  29390. var dst = obj;
  29391. cMap.mapOne(src, dst);
  29392. }
  29393. }
  29394. function parseCidRange(cMap, lexer) {
  29395. while (true) {
  29396. var obj = lexer.getObj();
  29397. if (isEOF(obj)) {
  29398. break;
  29399. }
  29400. if (isCmd(obj, 'endcidrange')) {
  29401. return;
  29402. }
  29403. expectString(obj);
  29404. var low = strToInt(obj);
  29405. obj = lexer.getObj();
  29406. expectString(obj);
  29407. var high = strToInt(obj);
  29408. obj = lexer.getObj();
  29409. expectInt(obj);
  29410. var dstLow = obj;
  29411. cMap.mapCidRange(low, high, dstLow);
  29412. }
  29413. }
  29414. function parseCodespaceRange(cMap, lexer) {
  29415. while (true) {
  29416. var obj = lexer.getObj();
  29417. if (isEOF(obj)) {
  29418. break;
  29419. }
  29420. if (isCmd(obj, 'endcodespacerange')) {
  29421. return;
  29422. }
  29423. if (!isString(obj)) {
  29424. break;
  29425. }
  29426. var low = strToInt(obj);
  29427. obj = lexer.getObj();
  29428. if (!isString(obj)) {
  29429. break;
  29430. }
  29431. var high = strToInt(obj);
  29432. cMap.addCodespaceRange(obj.length, low, high);
  29433. }
  29434. error('Invalid codespace range.');
  29435. }
  29436. function parseWMode(cMap, lexer) {
  29437. var obj = lexer.getObj();
  29438. if (isInt(obj)) {
  29439. cMap.vertical = !!obj;
  29440. }
  29441. }
  29442. function parseCMapName(cMap, lexer) {
  29443. var obj = lexer.getObj();
  29444. if (isName(obj) && isString(obj.name)) {
  29445. cMap.name = obj.name;
  29446. }
  29447. }
  29448. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  29449. var previous;
  29450. var embededUseCMap;
  29451. objLoop: while (true) {
  29452. var obj = lexer.getObj();
  29453. if (isEOF(obj)) {
  29454. break;
  29455. } else if (isName(obj)) {
  29456. if (obj.name === 'WMode') {
  29457. parseWMode(cMap, lexer);
  29458. } else if (obj.name === 'CMapName') {
  29459. parseCMapName(cMap, lexer);
  29460. }
  29461. previous = obj;
  29462. } else if (isCmd(obj)) {
  29463. switch (obj.cmd) {
  29464. case 'endcmap':
  29465. break objLoop;
  29466. case 'usecmap':
  29467. if (isName(previous)) {
  29468. embededUseCMap = previous.name;
  29469. }
  29470. break;
  29471. case 'begincodespacerange':
  29472. parseCodespaceRange(cMap, lexer);
  29473. break;
  29474. case 'beginbfchar':
  29475. parseBfChar(cMap, lexer);
  29476. break;
  29477. case 'begincidchar':
  29478. parseCidChar(cMap, lexer);
  29479. break;
  29480. case 'beginbfrange':
  29481. parseBfRange(cMap, lexer);
  29482. break;
  29483. case 'begincidrange':
  29484. parseCidRange(cMap, lexer);
  29485. break;
  29486. }
  29487. }
  29488. }
  29489. if (!useCMap && embededUseCMap) {
  29490. // Load the usecmap definition from the file only if there wasn't one
  29491. // specified.
  29492. useCMap = embededUseCMap;
  29493. }
  29494. if (useCMap) {
  29495. extendCMap(cMap, builtInCMapParams, useCMap);
  29496. }
  29497. }
  29498. function extendCMap(cMap, builtInCMapParams, useCMap) {
  29499. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  29500. // If there aren't any code space ranges defined clone all the parent ones
  29501. // into this cMap.
  29502. if (cMap.numCodespaceRanges === 0) {
  29503. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  29504. for (var i = 0; i < useCodespaceRanges.length; i++) {
  29505. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  29506. }
  29507. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  29508. }
  29509. // Merge the map into the current one, making sure not to override
  29510. // any previously defined entries.
  29511. cMap.useCMap.forEach(function(key, value) {
  29512. if (!cMap.contains(key)) {
  29513. cMap.mapOne(key, cMap.useCMap.lookup(key));
  29514. }
  29515. });
  29516. }
  29517. function parseBinaryCMap(name, builtInCMapParams) {
  29518. var url = builtInCMapParams.url + name + '.bcmap';
  29519. var cMap = new CMap(true);
  29520. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  29521. extendCMap(cMap, builtInCMapParams, useCMap);
  29522. });
  29523. return cMap;
  29524. }
  29525. function createBuiltInCMap(name, builtInCMapParams) {
  29526. if (name === 'Identity-H') {
  29527. return new IdentityCMap(false, 2);
  29528. } else if (name === 'Identity-V') {
  29529. return new IdentityCMap(true, 2);
  29530. }
  29531. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  29532. error('Unknown cMap name: ' + name);
  29533. }
  29534. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  29535. if (builtInCMapParams.packed) {
  29536. return parseBinaryCMap(name, builtInCMapParams);
  29537. }
  29538. var request = new XMLHttpRequest();
  29539. var url = builtInCMapParams.url + name;
  29540. request.open('GET', url, false);
  29541. request.send(null);
  29542. if (!request.responseText) {
  29543. error('Unable to get cMap at: ' + url);
  29544. }
  29545. var cMap = new CMap(true);
  29546. var lexer = new Lexer(new StringStream(request.responseText));
  29547. parseCMap(cMap, lexer, builtInCMapParams, null);
  29548. return cMap;
  29549. }
  29550. return {
  29551. create: function (encoding, builtInCMapParams, useCMap) {
  29552. if (isName(encoding)) {
  29553. return createBuiltInCMap(encoding.name, builtInCMapParams);
  29554. } else if (isStream(encoding)) {
  29555. var cMap = new CMap();
  29556. var lexer = new Lexer(encoding);
  29557. try {
  29558. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  29559. } catch (e) {
  29560. warn('Invalid CMap data. ' + e);
  29561. }
  29562. if (cMap.isIdentityCMap) {
  29563. return createBuiltInCMap(cMap.name, builtInCMapParams);
  29564. }
  29565. return cMap;
  29566. }
  29567. error('Encoding required.');
  29568. }
  29569. };
  29570. })();
  29571. exports.CMap = CMap;
  29572. exports.CMapFactory = CMapFactory;
  29573. exports.IdentityCMap = IdentityCMap;
  29574. }));
  29575. (function (root, factory) {
  29576. {
  29577. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29578. root.pdfjsCoreParser);
  29579. }
  29580. }(this, function (exports, sharedUtil, coreParser) {
  29581. var error = sharedUtil.error;
  29582. var EOF = coreParser.EOF;
  29583. var Lexer = coreParser.Lexer;
  29584. var PostScriptParser = (function PostScriptParserClosure() {
  29585. function PostScriptParser(lexer) {
  29586. this.lexer = lexer;
  29587. this.operators = [];
  29588. this.token = null;
  29589. this.prev = null;
  29590. }
  29591. PostScriptParser.prototype = {
  29592. nextToken: function PostScriptParser_nextToken() {
  29593. this.prev = this.token;
  29594. this.token = this.lexer.getToken();
  29595. },
  29596. accept: function PostScriptParser_accept(type) {
  29597. if (this.token.type === type) {
  29598. this.nextToken();
  29599. return true;
  29600. }
  29601. return false;
  29602. },
  29603. expect: function PostScriptParser_expect(type) {
  29604. if (this.accept(type)) {
  29605. return true;
  29606. }
  29607. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29608. type + '.');
  29609. },
  29610. parse: function PostScriptParser_parse() {
  29611. this.nextToken();
  29612. this.expect(PostScriptTokenTypes.LBRACE);
  29613. this.parseBlock();
  29614. this.expect(PostScriptTokenTypes.RBRACE);
  29615. return this.operators;
  29616. },
  29617. parseBlock: function PostScriptParser_parseBlock() {
  29618. while (true) {
  29619. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29620. this.operators.push(this.prev.value);
  29621. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29622. this.operators.push(this.prev.value);
  29623. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29624. this.parseCondition();
  29625. } else {
  29626. return;
  29627. }
  29628. }
  29629. },
  29630. parseCondition: function PostScriptParser_parseCondition() {
  29631. // Add two place holders that will be updated later
  29632. var conditionLocation = this.operators.length;
  29633. this.operators.push(null, null);
  29634. this.parseBlock();
  29635. this.expect(PostScriptTokenTypes.RBRACE);
  29636. if (this.accept(PostScriptTokenTypes.IF)) {
  29637. // The true block is right after the 'if' so it just falls through on
  29638. // true else it jumps and skips the true block.
  29639. this.operators[conditionLocation] = this.operators.length;
  29640. this.operators[conditionLocation + 1] = 'jz';
  29641. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29642. var jumpLocation = this.operators.length;
  29643. this.operators.push(null, null);
  29644. var endOfTrue = this.operators.length;
  29645. this.parseBlock();
  29646. this.expect(PostScriptTokenTypes.RBRACE);
  29647. this.expect(PostScriptTokenTypes.IFELSE);
  29648. // The jump is added at the end of the true block to skip the false
  29649. // block.
  29650. this.operators[jumpLocation] = this.operators.length;
  29651. this.operators[jumpLocation + 1] = 'j';
  29652. this.operators[conditionLocation] = endOfTrue;
  29653. this.operators[conditionLocation + 1] = 'jz';
  29654. } else {
  29655. error('PS Function: error parsing conditional.');
  29656. }
  29657. }
  29658. };
  29659. return PostScriptParser;
  29660. })();
  29661. var PostScriptTokenTypes = {
  29662. LBRACE: 0,
  29663. RBRACE: 1,
  29664. NUMBER: 2,
  29665. OPERATOR: 3,
  29666. IF: 4,
  29667. IFELSE: 5
  29668. };
  29669. var PostScriptToken = (function PostScriptTokenClosure() {
  29670. function PostScriptToken(type, value) {
  29671. this.type = type;
  29672. this.value = value;
  29673. }
  29674. var opCache = Object.create(null);
  29675. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29676. var opValue = opCache[op];
  29677. if (opValue) {
  29678. return opValue;
  29679. }
  29680. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29681. };
  29682. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29683. '{');
  29684. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29685. '}');
  29686. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29687. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29688. 'IFELSE');
  29689. return PostScriptToken;
  29690. })();
  29691. var PostScriptLexer = (function PostScriptLexerClosure() {
  29692. function PostScriptLexer(stream) {
  29693. this.stream = stream;
  29694. this.nextChar();
  29695. this.strBuf = [];
  29696. }
  29697. PostScriptLexer.prototype = {
  29698. nextChar: function PostScriptLexer_nextChar() {
  29699. return (this.currentChar = this.stream.getByte());
  29700. },
  29701. getToken: function PostScriptLexer_getToken() {
  29702. var comment = false;
  29703. var ch = this.currentChar;
  29704. // skip comments
  29705. while (true) {
  29706. if (ch < 0) {
  29707. return EOF;
  29708. }
  29709. if (comment) {
  29710. if (ch === 0x0A || ch === 0x0D) {
  29711. comment = false;
  29712. }
  29713. } else if (ch === 0x25) { // '%'
  29714. comment = true;
  29715. } else if (!Lexer.isSpace(ch)) {
  29716. break;
  29717. }
  29718. ch = this.nextChar();
  29719. }
  29720. switch (ch | 0) {
  29721. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29722. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29723. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29724. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29725. this.getNumber());
  29726. case 0x7B: // '{'
  29727. this.nextChar();
  29728. return PostScriptToken.LBRACE;
  29729. case 0x7D: // '}'
  29730. this.nextChar();
  29731. return PostScriptToken.RBRACE;
  29732. }
  29733. // operator
  29734. var strBuf = this.strBuf;
  29735. strBuf.length = 0;
  29736. strBuf[0] = String.fromCharCode(ch);
  29737. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29738. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29739. strBuf.push(String.fromCharCode(ch));
  29740. }
  29741. var str = strBuf.join('');
  29742. switch (str.toLowerCase()) {
  29743. case 'if':
  29744. return PostScriptToken.IF;
  29745. case 'ifelse':
  29746. return PostScriptToken.IFELSE;
  29747. default:
  29748. return PostScriptToken.getOperator(str);
  29749. }
  29750. },
  29751. getNumber: function PostScriptLexer_getNumber() {
  29752. var ch = this.currentChar;
  29753. var strBuf = this.strBuf;
  29754. strBuf.length = 0;
  29755. strBuf[0] = String.fromCharCode(ch);
  29756. while ((ch = this.nextChar()) >= 0) {
  29757. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29758. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29759. strBuf.push(String.fromCharCode(ch));
  29760. } else {
  29761. break;
  29762. }
  29763. }
  29764. var value = parseFloat(strBuf.join(''));
  29765. if (isNaN(value)) {
  29766. error('Invalid floating point number: ' + value);
  29767. }
  29768. return value;
  29769. }
  29770. };
  29771. return PostScriptLexer;
  29772. })();
  29773. exports.PostScriptLexer = PostScriptLexer;
  29774. exports.PostScriptParser = PostScriptParser;
  29775. }));
  29776. (function (root, factory) {
  29777. {
  29778. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  29779. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  29780. root.pdfjsDisplayMetadata, root.pdfjsSharedGlobal);
  29781. }
  29782. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  29783. displayMetadata, sharedGlobal, amdRequire) {
  29784. var InvalidPDFException = sharedUtil.InvalidPDFException;
  29785. var MessageHandler = sharedUtil.MessageHandler;
  29786. var MissingPDFException = sharedUtil.MissingPDFException;
  29787. var PasswordResponses = sharedUtil.PasswordResponses;
  29788. var PasswordException = sharedUtil.PasswordException;
  29789. var StatTimer = sharedUtil.StatTimer;
  29790. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  29791. var UnknownErrorException = sharedUtil.UnknownErrorException;
  29792. var Util = sharedUtil.Util;
  29793. var createPromiseCapability = sharedUtil.createPromiseCapability;
  29794. var combineUrl = sharedUtil.combineUrl;
  29795. var error = sharedUtil.error;
  29796. var deprecated = sharedUtil.deprecated;
  29797. var info = sharedUtil.info;
  29798. var isArrayBuffer = sharedUtil.isArrayBuffer;
  29799. var isSameOrigin = sharedUtil.isSameOrigin;
  29800. var loadJpegStream = sharedUtil.loadJpegStream;
  29801. var stringToBytes = sharedUtil.stringToBytes;
  29802. var warn = sharedUtil.warn;
  29803. var FontFaceObject = displayFontLoader.FontFaceObject;
  29804. var FontLoader = displayFontLoader.FontLoader;
  29805. var CanvasGraphics = displayCanvas.CanvasGraphics;
  29806. var createScratchCanvas = displayCanvas.createScratchCanvas;
  29807. var Metadata = displayMetadata.Metadata;
  29808. var PDFJS = sharedGlobal.PDFJS;
  29809. var globalScope = sharedGlobal.globalScope;
  29810. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  29811. /**
  29812. * The maximum allowed image size in total pixels e.g. width * height. Images
  29813. * above this value will not be drawn. Use -1 for no limit.
  29814. * @var {number}
  29815. */
  29816. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  29817. -1 : PDFJS.maxImageSize);
  29818. /**
  29819. * The url of where the predefined Adobe CMaps are located. Include trailing
  29820. * slash.
  29821. * @var {string}
  29822. */
  29823. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  29824. /**
  29825. * Specifies if CMaps are binary packed.
  29826. * @var {boolean}
  29827. */
  29828. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  29829. /**
  29830. * By default fonts are converted to OpenType fonts and loaded via font face
  29831. * rules. If disabled, the font will be rendered using a built in font renderer
  29832. * that constructs the glyphs with primitive path commands.
  29833. * @var {boolean}
  29834. */
  29835. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  29836. false : PDFJS.disableFontFace);
  29837. /**
  29838. * Path for image resources, mainly for annotation icons. Include trailing
  29839. * slash.
  29840. * @var {string}
  29841. */
  29842. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  29843. '' : PDFJS.imageResourcesPath);
  29844. /**
  29845. * Disable the web worker and run all code on the main thread. This will happen
  29846. * automatically if the browser doesn't support workers or sending typed arrays
  29847. * to workers.
  29848. * @var {boolean}
  29849. */
  29850. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  29851. false : PDFJS.disableWorker);
  29852. /**
  29853. * Path and filename of the worker file. Required when the worker is enabled in
  29854. * development mode. If unspecified in the production build, the worker will be
  29855. * loaded based on the location of the pdf.js file. It is recommended that
  29856. * the workerSrc is set in a custom application to prevent issues caused by
  29857. * third-party frameworks and libraries.
  29858. * @var {string}
  29859. */
  29860. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  29861. /**
  29862. * Disable range request loading of PDF files. When enabled and if the server
  29863. * supports partial content requests then the PDF will be fetched in chunks.
  29864. * Enabled (false) by default.
  29865. * @var {boolean}
  29866. */
  29867. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  29868. false : PDFJS.disableRange);
  29869. /**
  29870. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  29871. * in chunks. This default behavior can be disabled.
  29872. * @var {boolean}
  29873. */
  29874. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  29875. false : PDFJS.disableStream);
  29876. /**
  29877. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  29878. * will automatically keep fetching more data even if it isn't needed to display
  29879. * the current page. This default behavior can be disabled.
  29880. *
  29881. * NOTE: It is also necessary to disable streaming, see above,
  29882. * in order for disabling of pre-fetching to work correctly.
  29883. * @var {boolean}
  29884. */
  29885. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  29886. false : PDFJS.disableAutoFetch);
  29887. /**
  29888. * Enables special hooks for debugging PDF.js.
  29889. * @var {boolean}
  29890. */
  29891. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  29892. /**
  29893. * Enables transfer usage in postMessage for ArrayBuffers.
  29894. * @var {boolean}
  29895. */
  29896. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  29897. true : PDFJS.postMessageTransfers);
  29898. /**
  29899. * Disables URL.createObjectURL usage.
  29900. * @var {boolean}
  29901. */
  29902. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  29903. false : PDFJS.disableCreateObjectURL);
  29904. /**
  29905. * Disables WebGL usage.
  29906. * @var {boolean}
  29907. */
  29908. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  29909. true : PDFJS.disableWebGL);
  29910. /**
  29911. * Disables fullscreen support, and by extension Presentation Mode,
  29912. * in browsers which support the fullscreen API.
  29913. * @var {boolean}
  29914. */
  29915. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  29916. false : PDFJS.disableFullscreen);
  29917. /**
  29918. * Enables CSS only zooming.
  29919. * @var {boolean}
  29920. */
  29921. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  29922. false : PDFJS.useOnlyCssZoom);
  29923. /**
  29924. * Controls the logging level.
  29925. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  29926. * - errors
  29927. * - warnings [default]
  29928. * - infos
  29929. * @var {number}
  29930. */
  29931. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  29932. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  29933. /**
  29934. * The maximum supported canvas size in total pixels e.g. width * height.
  29935. * The default value is 4096 * 4096. Use -1 for no limit.
  29936. * @var {number}
  29937. */
  29938. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  29939. 16777216 : PDFJS.maxCanvasPixels);
  29940. /**
  29941. * (Deprecated) Opens external links in a new window if enabled.
  29942. * The default behavior opens external links in the PDF.js window.
  29943. *
  29944. * NOTE: This property has been deprecated, please use
  29945. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  29946. * @var {boolean}
  29947. */
  29948. PDFJS.openExternalLinksInNewWindow = (
  29949. PDFJS.openExternalLinksInNewWindow === undefined ?
  29950. false : PDFJS.openExternalLinksInNewWindow);
  29951. /**
  29952. * Specifies the |target| attribute for external links.
  29953. * The constants from PDFJS.LinkTarget should be used:
  29954. * - NONE [default]
  29955. * - SELF
  29956. * - BLANK
  29957. * - PARENT
  29958. * - TOP
  29959. * @var {number}
  29960. */
  29961. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  29962. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  29963. /**
  29964. * Specifies the |rel| attribute for external links. Defaults to stripping
  29965. * the referrer.
  29966. * @var {string}
  29967. */
  29968. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  29969. 'noreferrer' : PDFJS.externalLinkRel);
  29970. /**
  29971. * Determines if we can eval strings as JS. Primarily used to improve
  29972. * performance for font rendering.
  29973. * @var {boolean}
  29974. */
  29975. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  29976. true : PDFJS.isEvalSupported);
  29977. /**
  29978. * Document initialization / loading parameters object.
  29979. *
  29980. * @typedef {Object} DocumentInitParameters
  29981. * @property {string} url - The URL of the PDF.
  29982. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  29983. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  29984. * use atob() to convert it to a binary string first.
  29985. * @property {Object} httpHeaders - Basic authentication headers.
  29986. * @property {boolean} withCredentials - Indicates whether or not cross-site
  29987. * Access-Control requests should be made using credentials such as cookies
  29988. * or authorization headers. The default is false.
  29989. * @property {string} password - For decrypting password-protected PDFs.
  29990. * @property {TypedArray} initialData - A typed array with the first portion or
  29991. * all of the pdf data. Used by the extension since some data is already
  29992. * loaded before the switch to range requests.
  29993. * @property {number} length - The PDF file length. It's used for progress
  29994. * reports and range requests operations.
  29995. * @property {PDFDataRangeTransport} range
  29996. * @property {number} rangeChunkSize - Optional parameter to specify
  29997. * maximum number of bytes fetched per range request. The default value is
  29998. * 2^16 = 65536.
  29999. * @property {PDFWorker} worker - The worker that will be used for the loading
  30000. * and parsing of the PDF data.
  30001. */
  30002. /**
  30003. * @typedef {Object} PDFDocumentStats
  30004. * @property {Array} streamTypes - Used stream types in the document (an item
  30005. * is set to true if specific stream ID was used in the document).
  30006. * @property {Array} fontTypes - Used font type in the document (an item is set
  30007. * to true if specific font ID was used in the document).
  30008. */
  30009. /**
  30010. * This is the main entry point for loading a PDF and interacting with it.
  30011. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  30012. * is used, which means it must follow the same origin rules that any XHR does
  30013. * e.g. No cross domain requests without CORS.
  30014. *
  30015. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  30016. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  30017. * already populated with data or parameter object.
  30018. *
  30019. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  30020. * if you want to manually serve range requests for data in the PDF.
  30021. *
  30022. * @param {function} passwordCallback (deprecated) It is used to request a
  30023. * password if wrong or no password was provided. The callback receives two
  30024. * parameters: function that needs to be called with new password and reason
  30025. * (see {PasswordResponses}).
  30026. *
  30027. * @param {function} progressCallback (deprecated) It is used to be able to
  30028. * monitor the loading progress of the PDF file (necessary to implement e.g.
  30029. * a loading bar). The callback receives an {Object} with the properties:
  30030. * {number} loaded and {number} total.
  30031. *
  30032. * @return {PDFDocumentLoadingTask}
  30033. */
  30034. PDFJS.getDocument = function getDocument(src,
  30035. pdfDataRangeTransport,
  30036. passwordCallback,
  30037. progressCallback) {
  30038. var task = new PDFDocumentLoadingTask();
  30039. // Support of the obsolete arguments (for compatibility with API v1.0)
  30040. if (arguments.length > 1) {
  30041. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  30042. 'passwordCallback or progressCallback argument');
  30043. }
  30044. if (pdfDataRangeTransport) {
  30045. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  30046. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  30047. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  30048. pdfDataRangeTransport.length = src.length;
  30049. pdfDataRangeTransport.initialData = src.initialData;
  30050. if (!pdfDataRangeTransport.abort) {
  30051. pdfDataRangeTransport.abort = function () {};
  30052. }
  30053. }
  30054. src = Object.create(src);
  30055. src.range = pdfDataRangeTransport;
  30056. }
  30057. task.onPassword = passwordCallback || null;
  30058. task.onProgress = progressCallback || null;
  30059. var source;
  30060. if (typeof src === 'string') {
  30061. source = { url: src };
  30062. } else if (isArrayBuffer(src)) {
  30063. source = { data: src };
  30064. } else if (src instanceof PDFDataRangeTransport) {
  30065. source = { range: src };
  30066. } else {
  30067. if (typeof src !== 'object') {
  30068. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  30069. 'string or a parameter object');
  30070. }
  30071. if (!src.url && !src.data && !src.range) {
  30072. error('Invalid parameter object: need either .data, .range or .url');
  30073. }
  30074. source = src;
  30075. }
  30076. var params = {};
  30077. var rangeTransport = null;
  30078. var worker = null;
  30079. for (var key in source) {
  30080. if (key === 'url' && typeof window !== 'undefined') {
  30081. // The full path is required in the 'url' field.
  30082. params[key] = combineUrl(window.location.href, source[key]);
  30083. continue;
  30084. } else if (key === 'range') {
  30085. rangeTransport = source[key];
  30086. continue;
  30087. } else if (key === 'worker') {
  30088. worker = source[key];
  30089. continue;
  30090. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  30091. // Converting string or array-like data to Uint8Array.
  30092. var pdfBytes = source[key];
  30093. if (typeof pdfBytes === 'string') {
  30094. params[key] = stringToBytes(pdfBytes);
  30095. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  30096. !isNaN(pdfBytes.length)) {
  30097. params[key] = new Uint8Array(pdfBytes);
  30098. } else if (isArrayBuffer(pdfBytes)) {
  30099. params[key] = new Uint8Array(pdfBytes);
  30100. } else {
  30101. error('Invalid PDF binary data: either typed array, string or ' +
  30102. 'array-like object is expected in the data property.');
  30103. }
  30104. continue;
  30105. }
  30106. params[key] = source[key];
  30107. }
  30108. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  30109. if (!worker) {
  30110. // Worker was not provided -- creating and owning our own.
  30111. worker = new PDFWorker();
  30112. task._worker = worker;
  30113. }
  30114. var docId = task.docId;
  30115. worker.promise.then(function () {
  30116. if (task.destroyed) {
  30117. throw new Error('Loading aborted');
  30118. }
  30119. return _fetchDocument(worker, params, rangeTransport, docId).then(
  30120. function (workerId) {
  30121. if (task.destroyed) {
  30122. throw new Error('Loading aborted');
  30123. }
  30124. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  30125. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  30126. task._transport = transport;
  30127. messageHandler.send('Ready', null);
  30128. });
  30129. }).catch(task._capability.reject);
  30130. return task;
  30131. };
  30132. /**
  30133. * Starts fetching of specified PDF document/data.
  30134. * @param {PDFWorker} worker
  30135. * @param {Object} source
  30136. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  30137. * @param {string} docId Unique document id, used as MessageHandler id.
  30138. * @returns {Promise} The promise, which is resolved when worker id of
  30139. * MessageHandler is known.
  30140. * @private
  30141. */
  30142. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  30143. if (worker.destroyed) {
  30144. return Promise.reject(new Error('Worker was destroyed'));
  30145. }
  30146. source.disableAutoFetch = PDFJS.disableAutoFetch;
  30147. source.disableStream = PDFJS.disableStream;
  30148. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  30149. if (pdfDataRangeTransport) {
  30150. source.length = pdfDataRangeTransport.length;
  30151. source.initialData = pdfDataRangeTransport.initialData;
  30152. }
  30153. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  30154. docId: docId,
  30155. source: source,
  30156. disableRange: PDFJS.disableRange,
  30157. maxImageSize: PDFJS.maxImageSize,
  30158. cMapUrl: PDFJS.cMapUrl,
  30159. cMapPacked: PDFJS.cMapPacked,
  30160. disableFontFace: PDFJS.disableFontFace,
  30161. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  30162. verbosity: PDFJS.verbosity
  30163. }).then(function (workerId) {
  30164. if (worker.destroyed) {
  30165. throw new Error('Worker was destroyed');
  30166. }
  30167. return workerId;
  30168. });
  30169. }
  30170. /**
  30171. * PDF document loading operation.
  30172. * @class
  30173. * @alias PDFDocumentLoadingTask
  30174. */
  30175. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  30176. var nextDocumentId = 0;
  30177. /** @constructs PDFDocumentLoadingTask */
  30178. function PDFDocumentLoadingTask() {
  30179. this._capability = createPromiseCapability();
  30180. this._transport = null;
  30181. this._worker = null;
  30182. /**
  30183. * Unique document loading task id -- used in MessageHandlers.
  30184. * @type {string}
  30185. */
  30186. this.docId = 'd' + (nextDocumentId++);
  30187. /**
  30188. * Shows if loading task is destroyed.
  30189. * @type {boolean}
  30190. */
  30191. this.destroyed = false;
  30192. /**
  30193. * Callback to request a password if wrong or no password was provided.
  30194. * The callback receives two parameters: function that needs to be called
  30195. * with new password and reason (see {PasswordResponses}).
  30196. */
  30197. this.onPassword = null;
  30198. /**
  30199. * Callback to be able to monitor the loading progress of the PDF file
  30200. * (necessary to implement e.g. a loading bar). The callback receives
  30201. * an {Object} with the properties: {number} loaded and {number} total.
  30202. */
  30203. this.onProgress = null;
  30204. /**
  30205. * Callback to when unsupported feature is used. The callback receives
  30206. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  30207. */
  30208. this.onUnsupportedFeature = null;
  30209. }
  30210. PDFDocumentLoadingTask.prototype =
  30211. /** @lends PDFDocumentLoadingTask.prototype */ {
  30212. /**
  30213. * @return {Promise}
  30214. */
  30215. get promise() {
  30216. return this._capability.promise;
  30217. },
  30218. /**
  30219. * Aborts all network requests and destroys worker.
  30220. * @return {Promise} A promise that is resolved after destruction activity
  30221. * is completed.
  30222. */
  30223. destroy: function () {
  30224. this.destroyed = true;
  30225. var transportDestroyed = !this._transport ? Promise.resolve() :
  30226. this._transport.destroy();
  30227. return transportDestroyed.then(function () {
  30228. this._transport = null;
  30229. if (this._worker) {
  30230. this._worker.destroy();
  30231. this._worker = null;
  30232. }
  30233. }.bind(this));
  30234. },
  30235. /**
  30236. * Registers callbacks to indicate the document loading completion.
  30237. *
  30238. * @param {function} onFulfilled The callback for the loading completion.
  30239. * @param {function} onRejected The callback for the loading failure.
  30240. * @return {Promise} A promise that is resolved after the onFulfilled or
  30241. * onRejected callback.
  30242. */
  30243. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  30244. return this.promise.then.apply(this.promise, arguments);
  30245. }
  30246. };
  30247. return PDFDocumentLoadingTask;
  30248. })();
  30249. /**
  30250. * Abstract class to support range requests file loading.
  30251. * @class
  30252. * @alias PDFJS.PDFDataRangeTransport
  30253. * @param {number} length
  30254. * @param {Uint8Array} initialData
  30255. */
  30256. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  30257. function PDFDataRangeTransport(length, initialData) {
  30258. this.length = length;
  30259. this.initialData = initialData;
  30260. this._rangeListeners = [];
  30261. this._progressListeners = [];
  30262. this._progressiveReadListeners = [];
  30263. this._readyCapability = createPromiseCapability();
  30264. }
  30265. PDFDataRangeTransport.prototype =
  30266. /** @lends PDFDataRangeTransport.prototype */ {
  30267. addRangeListener:
  30268. function PDFDataRangeTransport_addRangeListener(listener) {
  30269. this._rangeListeners.push(listener);
  30270. },
  30271. addProgressListener:
  30272. function PDFDataRangeTransport_addProgressListener(listener) {
  30273. this._progressListeners.push(listener);
  30274. },
  30275. addProgressiveReadListener:
  30276. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  30277. this._progressiveReadListeners.push(listener);
  30278. },
  30279. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  30280. var listeners = this._rangeListeners;
  30281. for (var i = 0, n = listeners.length; i < n; ++i) {
  30282. listeners[i](begin, chunk);
  30283. }
  30284. },
  30285. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  30286. this._readyCapability.promise.then(function () {
  30287. var listeners = this._progressListeners;
  30288. for (var i = 0, n = listeners.length; i < n; ++i) {
  30289. listeners[i](loaded);
  30290. }
  30291. }.bind(this));
  30292. },
  30293. onDataProgressiveRead:
  30294. function PDFDataRangeTransport_onDataProgress(chunk) {
  30295. this._readyCapability.promise.then(function () {
  30296. var listeners = this._progressiveReadListeners;
  30297. for (var i = 0, n = listeners.length; i < n; ++i) {
  30298. listeners[i](chunk);
  30299. }
  30300. }.bind(this));
  30301. },
  30302. transportReady: function PDFDataRangeTransport_transportReady() {
  30303. this._readyCapability.resolve();
  30304. },
  30305. requestDataRange:
  30306. function PDFDataRangeTransport_requestDataRange(begin, end) {
  30307. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  30308. },
  30309. abort: function PDFDataRangeTransport_abort() {
  30310. }
  30311. };
  30312. return PDFDataRangeTransport;
  30313. })();
  30314. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  30315. /**
  30316. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  30317. * properties that can be read synchronously.
  30318. * @class
  30319. * @alias PDFDocumentProxy
  30320. */
  30321. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  30322. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  30323. this.pdfInfo = pdfInfo;
  30324. this.transport = transport;
  30325. this.loadingTask = loadingTask;
  30326. }
  30327. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  30328. /**
  30329. * @return {number} Total number of pages the PDF contains.
  30330. */
  30331. get numPages() {
  30332. return this.pdfInfo.numPages;
  30333. },
  30334. /**
  30335. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  30336. * unique.
  30337. */
  30338. get fingerprint() {
  30339. return this.pdfInfo.fingerprint;
  30340. },
  30341. /**
  30342. * @param {number} pageNumber The page number to get. The first page is 1.
  30343. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  30344. * object.
  30345. */
  30346. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  30347. return this.transport.getPage(pageNumber);
  30348. },
  30349. /**
  30350. * @param {{num: number, gen: number}} ref The page reference. Must have
  30351. * the 'num' and 'gen' properties.
  30352. * @return {Promise} A promise that is resolved with the page index that is
  30353. * associated with the reference.
  30354. */
  30355. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  30356. return this.transport.getPageIndex(ref);
  30357. },
  30358. /**
  30359. * @return {Promise} A promise that is resolved with a lookup table for
  30360. * mapping named destinations to reference numbers.
  30361. *
  30362. * This can be slow for large documents: use getDestination instead
  30363. */
  30364. getDestinations: function PDFDocumentProxy_getDestinations() {
  30365. return this.transport.getDestinations();
  30366. },
  30367. /**
  30368. * @param {string} id The named destination to get.
  30369. * @return {Promise} A promise that is resolved with all information
  30370. * of the given named destination.
  30371. */
  30372. getDestination: function PDFDocumentProxy_getDestination(id) {
  30373. return this.transport.getDestination(id);
  30374. },
  30375. /**
  30376. * @return {Promise} A promise that is resolved with:
  30377. * an Array containing the pageLabels that correspond to the pageIndexes,
  30378. * or `null` when no pageLabels are present in the PDF file.
  30379. */
  30380. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  30381. return this.transport.getPageLabels();
  30382. },
  30383. /**
  30384. * @return {Promise} A promise that is resolved with a lookup table for
  30385. * mapping named attachments to their content.
  30386. */
  30387. getAttachments: function PDFDocumentProxy_getAttachments() {
  30388. return this.transport.getAttachments();
  30389. },
  30390. /**
  30391. * @return {Promise} A promise that is resolved with an array of all the
  30392. * JavaScript strings in the name tree.
  30393. */
  30394. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  30395. return this.transport.getJavaScript();
  30396. },
  30397. /**
  30398. * @return {Promise} A promise that is resolved with an {Array} that is a
  30399. * tree outline (if it has one) of the PDF. The tree is in the format of:
  30400. * [
  30401. * {
  30402. * title: string,
  30403. * bold: boolean,
  30404. * italic: boolean,
  30405. * color: rgb Uint8Array,
  30406. * dest: dest obj,
  30407. * url: string,
  30408. * items: array of more items like this
  30409. * },
  30410. * ...
  30411. * ].
  30412. */
  30413. getOutline: function PDFDocumentProxy_getOutline() {
  30414. return this.transport.getOutline();
  30415. },
  30416. /**
  30417. * @return {Promise} A promise that is resolved with an {Object} that has
  30418. * info and metadata properties. Info is an {Object} filled with anything
  30419. * available in the information dictionary and similarly metadata is a
  30420. * {Metadata} object with information from the metadata section of the PDF.
  30421. */
  30422. getMetadata: function PDFDocumentProxy_getMetadata() {
  30423. return this.transport.getMetadata();
  30424. },
  30425. /**
  30426. * @return {Promise} A promise that is resolved with a TypedArray that has
  30427. * the raw data from the PDF.
  30428. */
  30429. getData: function PDFDocumentProxy_getData() {
  30430. return this.transport.getData();
  30431. },
  30432. /**
  30433. * @return {Promise} A promise that is resolved when the document's data
  30434. * is loaded. It is resolved with an {Object} that contains the length
  30435. * property that indicates size of the PDF data in bytes.
  30436. */
  30437. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  30438. return this.transport.downloadInfoCapability.promise;
  30439. },
  30440. /**
  30441. * @return {Promise} A promise this is resolved with current stats about
  30442. * document structures (see {@link PDFDocumentStats}).
  30443. */
  30444. getStats: function PDFDocumentProxy_getStats() {
  30445. return this.transport.getStats();
  30446. },
  30447. /**
  30448. * Cleans up resources allocated by the document, e.g. created @font-face.
  30449. */
  30450. cleanup: function PDFDocumentProxy_cleanup() {
  30451. this.transport.startCleanup();
  30452. },
  30453. /**
  30454. * Destroys current document instance and terminates worker.
  30455. */
  30456. destroy: function PDFDocumentProxy_destroy() {
  30457. return this.loadingTask.destroy();
  30458. }
  30459. };
  30460. return PDFDocumentProxy;
  30461. })();
  30462. /**
  30463. * Page getTextContent parameters.
  30464. *
  30465. * @typedef {Object} getTextContentParameters
  30466. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  30467. * whitespace with standard spaces (0x20). The default value is `false`.
  30468. */
  30469. /**
  30470. * Page text content.
  30471. *
  30472. * @typedef {Object} TextContent
  30473. * @property {array} items - array of {@link TextItem}
  30474. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  30475. * name.
  30476. */
  30477. /**
  30478. * Page text content part.
  30479. *
  30480. * @typedef {Object} TextItem
  30481. * @property {string} str - text content.
  30482. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  30483. * @property {array} transform - transformation matrix.
  30484. * @property {number} width - width in device space.
  30485. * @property {number} height - height in device space.
  30486. * @property {string} fontName - font name used by pdf.js for converted font.
  30487. */
  30488. /**
  30489. * Text style.
  30490. *
  30491. * @typedef {Object} TextStyle
  30492. * @property {number} ascent - font ascent.
  30493. * @property {number} descent - font descent.
  30494. * @property {boolean} vertical - text is in vertical mode.
  30495. * @property {string} fontFamily - possible font family
  30496. */
  30497. /**
  30498. * Page annotation parameters.
  30499. *
  30500. * @typedef {Object} GetAnnotationsParameters
  30501. * @param {string} intent - Determines the annotations that will be fetched,
  30502. * can be either 'display' (viewable annotations) or 'print'
  30503. * (printable annotations).
  30504. * If the parameter is omitted, all annotations are fetched.
  30505. */
  30506. /**
  30507. * Page render parameters.
  30508. *
  30509. * @typedef {Object} RenderParameters
  30510. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  30511. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  30512. * calling of PDFPage.getViewport method.
  30513. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  30514. * (default value is 'display').
  30515. * @property {Array} transform - (optional) Additional transform, applied
  30516. * just before viewport transform.
  30517. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  30518. * endLayout and appendImage functions.
  30519. * @property {function} continueCallback - (deprecated) A function that will be
  30520. * called each time the rendering is paused. To continue
  30521. * rendering call the function that is the first argument
  30522. * to the callback.
  30523. */
  30524. /**
  30525. * PDF page operator list.
  30526. *
  30527. * @typedef {Object} PDFOperatorList
  30528. * @property {Array} fnArray - Array containing the operator functions.
  30529. * @property {Array} argsArray - Array containing the arguments of the
  30530. * functions.
  30531. */
  30532. /**
  30533. * Proxy to a PDFPage in the worker thread.
  30534. * @class
  30535. * @alias PDFPageProxy
  30536. */
  30537. var PDFPageProxy = (function PDFPageProxyClosure() {
  30538. function PDFPageProxy(pageIndex, pageInfo, transport) {
  30539. this.pageIndex = pageIndex;
  30540. this.pageInfo = pageInfo;
  30541. this.transport = transport;
  30542. this.stats = new StatTimer();
  30543. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  30544. this.commonObjs = transport.commonObjs;
  30545. this.objs = new PDFObjects();
  30546. this.cleanupAfterRender = false;
  30547. this.pendingCleanup = false;
  30548. this.intentStates = Object.create(null);
  30549. this.destroyed = false;
  30550. }
  30551. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  30552. /**
  30553. * @return {number} Page number of the page. First page is 1.
  30554. */
  30555. get pageNumber() {
  30556. return this.pageIndex + 1;
  30557. },
  30558. /**
  30559. * @return {number} The number of degrees the page is rotated clockwise.
  30560. */
  30561. get rotate() {
  30562. return this.pageInfo.rotate;
  30563. },
  30564. /**
  30565. * @return {Object} The reference that points to this page. It has 'num' and
  30566. * 'gen' properties.
  30567. */
  30568. get ref() {
  30569. return this.pageInfo.ref;
  30570. },
  30571. /**
  30572. * @return {Array} An array of the visible portion of the PDF page in the
  30573. * user space units - [x1, y1, x2, y2].
  30574. */
  30575. get view() {
  30576. return this.pageInfo.view;
  30577. },
  30578. /**
  30579. * @param {number} scale The desired scale of the viewport.
  30580. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  30581. * defaults to the page rotation.
  30582. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  30583. * along with transforms required for rendering.
  30584. */
  30585. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  30586. if (arguments.length < 2) {
  30587. rotate = this.rotate;
  30588. }
  30589. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  30590. },
  30591. /**
  30592. * @param {GetAnnotationsParameters} params - Annotation parameters.
  30593. * @return {Promise} A promise that is resolved with an {Array} of the
  30594. * annotation objects.
  30595. */
  30596. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  30597. var intent = (params && params.intent) || null;
  30598. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  30599. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  30600. intent);
  30601. this.annotationsIntent = intent;
  30602. }
  30603. return this.annotationsPromise;
  30604. },
  30605. /**
  30606. * Begins the process of rendering a page to the desired context.
  30607. * @param {RenderParameters} params Page render parameters.
  30608. * @return {RenderTask} An object that contains the promise, which
  30609. * is resolved when the page finishes rendering.
  30610. */
  30611. render: function PDFPageProxy_render(params) {
  30612. var stats = this.stats;
  30613. stats.time('Overall');
  30614. // If there was a pending destroy cancel it so no cleanup happens during
  30615. // this call to render.
  30616. this.pendingCleanup = false;
  30617. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  30618. if (!this.intentStates[renderingIntent]) {
  30619. this.intentStates[renderingIntent] = Object.create(null);
  30620. }
  30621. var intentState = this.intentStates[renderingIntent];
  30622. // If there's no displayReadyCapability yet, then the operatorList
  30623. // was never requested before. Make the request and create the promise.
  30624. if (!intentState.displayReadyCapability) {
  30625. intentState.receivingOperatorList = true;
  30626. intentState.displayReadyCapability = createPromiseCapability();
  30627. intentState.operatorList = {
  30628. fnArray: [],
  30629. argsArray: [],
  30630. lastChunk: false
  30631. };
  30632. this.stats.time('Page Request');
  30633. this.transport.messageHandler.send('RenderPageRequest', {
  30634. pageIndex: this.pageNumber - 1,
  30635. intent: renderingIntent
  30636. });
  30637. }
  30638. var internalRenderTask = new InternalRenderTask(complete, params,
  30639. this.objs,
  30640. this.commonObjs,
  30641. intentState.operatorList,
  30642. this.pageNumber);
  30643. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  30644. if (!intentState.renderTasks) {
  30645. intentState.renderTasks = [];
  30646. }
  30647. intentState.renderTasks.push(internalRenderTask);
  30648. var renderTask = internalRenderTask.task;
  30649. // Obsolete parameter support
  30650. if (params.continueCallback) {
  30651. deprecated('render is used with continueCallback parameter');
  30652. renderTask.onContinue = params.continueCallback;
  30653. }
  30654. var self = this;
  30655. intentState.displayReadyCapability.promise.then(
  30656. function pageDisplayReadyPromise(transparency) {
  30657. if (self.pendingCleanup) {
  30658. complete();
  30659. return;
  30660. }
  30661. stats.time('Rendering');
  30662. internalRenderTask.initalizeGraphics(transparency);
  30663. internalRenderTask.operatorListChanged();
  30664. },
  30665. function pageDisplayReadPromiseError(reason) {
  30666. complete(reason);
  30667. }
  30668. );
  30669. function complete(error) {
  30670. var i = intentState.renderTasks.indexOf(internalRenderTask);
  30671. if (i >= 0) {
  30672. intentState.renderTasks.splice(i, 1);
  30673. }
  30674. if (self.cleanupAfterRender) {
  30675. self.pendingCleanup = true;
  30676. }
  30677. self._tryCleanup();
  30678. if (error) {
  30679. internalRenderTask.capability.reject(error);
  30680. } else {
  30681. internalRenderTask.capability.resolve();
  30682. }
  30683. stats.timeEnd('Rendering');
  30684. stats.timeEnd('Overall');
  30685. }
  30686. return renderTask;
  30687. },
  30688. /**
  30689. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  30690. * object that represents page's operator list.
  30691. */
  30692. getOperatorList: function PDFPageProxy_getOperatorList() {
  30693. function operatorListChanged() {
  30694. if (intentState.operatorList.lastChunk) {
  30695. intentState.opListReadCapability.resolve(intentState.operatorList);
  30696. var i = intentState.renderTasks.indexOf(opListTask);
  30697. if (i >= 0) {
  30698. intentState.renderTasks.splice(i, 1);
  30699. }
  30700. }
  30701. }
  30702. var renderingIntent = 'oplist';
  30703. if (!this.intentStates[renderingIntent]) {
  30704. this.intentStates[renderingIntent] = Object.create(null);
  30705. }
  30706. var intentState = this.intentStates[renderingIntent];
  30707. var opListTask;
  30708. if (!intentState.opListReadCapability) {
  30709. opListTask = {};
  30710. opListTask.operatorListChanged = operatorListChanged;
  30711. intentState.receivingOperatorList = true;
  30712. intentState.opListReadCapability = createPromiseCapability();
  30713. intentState.renderTasks = [];
  30714. intentState.renderTasks.push(opListTask);
  30715. intentState.operatorList = {
  30716. fnArray: [],
  30717. argsArray: [],
  30718. lastChunk: false
  30719. };
  30720. this.transport.messageHandler.send('RenderPageRequest', {
  30721. pageIndex: this.pageIndex,
  30722. intent: renderingIntent
  30723. });
  30724. }
  30725. return intentState.opListReadCapability.promise;
  30726. },
  30727. /**
  30728. * @param {getTextContentParameters} params - getTextContent parameters.
  30729. * @return {Promise} That is resolved a {@link TextContent}
  30730. * object that represent the page text content.
  30731. */
  30732. getTextContent: function PDFPageProxy_getTextContent(params) {
  30733. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  30734. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  30735. pageIndex: this.pageNumber - 1,
  30736. normalizeWhitespace: normalizeWhitespace,
  30737. });
  30738. },
  30739. /**
  30740. * Destroys page object.
  30741. */
  30742. _destroy: function PDFPageProxy_destroy() {
  30743. this.destroyed = true;
  30744. this.transport.pageCache[this.pageIndex] = null;
  30745. var waitOn = [];
  30746. Object.keys(this.intentStates).forEach(function(intent) {
  30747. if (intent === 'oplist') {
  30748. // Avoid errors below, since the renderTasks are just stubs.
  30749. return;
  30750. }
  30751. var intentState = this.intentStates[intent];
  30752. intentState.renderTasks.forEach(function(renderTask) {
  30753. var renderCompleted = renderTask.capability.promise.
  30754. catch(function () {}); // ignoring failures
  30755. waitOn.push(renderCompleted);
  30756. renderTask.cancel();
  30757. });
  30758. }, this);
  30759. this.objs.clear();
  30760. this.annotationsPromise = null;
  30761. this.pendingCleanup = false;
  30762. return Promise.all(waitOn);
  30763. },
  30764. /**
  30765. * Cleans up resources allocated by the page. (deprecated)
  30766. */
  30767. destroy: function() {
  30768. deprecated('page destroy method, use cleanup() instead');
  30769. this.cleanup();
  30770. },
  30771. /**
  30772. * Cleans up resources allocated by the page.
  30773. */
  30774. cleanup: function PDFPageProxy_cleanup() {
  30775. this.pendingCleanup = true;
  30776. this._tryCleanup();
  30777. },
  30778. /**
  30779. * For internal use only. Attempts to clean up if rendering is in a state
  30780. * where that's possible.
  30781. * @ignore
  30782. */
  30783. _tryCleanup: function PDFPageProxy_tryCleanup() {
  30784. if (!this.pendingCleanup ||
  30785. Object.keys(this.intentStates).some(function(intent) {
  30786. var intentState = this.intentStates[intent];
  30787. return (intentState.renderTasks.length !== 0 ||
  30788. intentState.receivingOperatorList);
  30789. }, this)) {
  30790. return;
  30791. }
  30792. Object.keys(this.intentStates).forEach(function(intent) {
  30793. delete this.intentStates[intent];
  30794. }, this);
  30795. this.objs.clear();
  30796. this.annotationsPromise = null;
  30797. this.pendingCleanup = false;
  30798. },
  30799. /**
  30800. * For internal use only.
  30801. * @ignore
  30802. */
  30803. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  30804. intent) {
  30805. var intentState = this.intentStates[intent];
  30806. // TODO Refactor RenderPageRequest to separate rendering
  30807. // and operator list logic
  30808. if (intentState.displayReadyCapability) {
  30809. intentState.displayReadyCapability.resolve(transparency);
  30810. }
  30811. },
  30812. /**
  30813. * For internal use only.
  30814. * @ignore
  30815. */
  30816. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  30817. intent) {
  30818. var intentState = this.intentStates[intent];
  30819. var i, ii;
  30820. // Add the new chunk to the current operator list.
  30821. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  30822. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  30823. intentState.operatorList.argsArray.push(
  30824. operatorListChunk.argsArray[i]);
  30825. }
  30826. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  30827. // Notify all the rendering tasks there are more operators to be consumed.
  30828. for (i = 0; i < intentState.renderTasks.length; i++) {
  30829. intentState.renderTasks[i].operatorListChanged();
  30830. }
  30831. if (operatorListChunk.lastChunk) {
  30832. intentState.receivingOperatorList = false;
  30833. this._tryCleanup();
  30834. }
  30835. }
  30836. };
  30837. return PDFPageProxy;
  30838. })();
  30839. /**
  30840. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  30841. * WorkerTransport for them. If creation of a web worker is not possible,
  30842. * a "fake" worker will be used instead.
  30843. * @class
  30844. */
  30845. var PDFWorker = (function PDFWorkerClosure() {
  30846. var nextFakeWorkerId = 0;
  30847. function getWorkerSrc() {
  30848. if (PDFJS.workerSrc) {
  30849. return PDFJS.workerSrc;
  30850. }
  30851. if (pdfjsFilePath) {
  30852. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  30853. }
  30854. error('No PDFJS.workerSrc specified');
  30855. }
  30856. // Loads worker code into main thread.
  30857. function setupFakeWorkerGlobal() {
  30858. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  30859. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  30860. // In the developer build load worker_loader which in turn loads all the
  30861. // other files and resolves the promise. In production only the
  30862. // pdf.worker.js file is needed.
  30863. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  30864. }
  30865. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  30866. }
  30867. function createCDNWrapper(url) {
  30868. // We will rely on blob URL's property to specify origin.
  30869. // We want this function to fail in case if createObjectURL or Blob do not
  30870. // exist or fail for some reason -- our Worker creation will fail anyway.
  30871. var wrapper = 'importScripts(\'' + url + '\');';
  30872. return URL.createObjectURL(new Blob([wrapper]));
  30873. }
  30874. function PDFWorker(name) {
  30875. this.name = name;
  30876. this.destroyed = false;
  30877. this._readyCapability = createPromiseCapability();
  30878. this._port = null;
  30879. this._webWorker = null;
  30880. this._messageHandler = null;
  30881. this._initialize();
  30882. }
  30883. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  30884. get promise() {
  30885. return this._readyCapability.promise;
  30886. },
  30887. get port() {
  30888. return this._port;
  30889. },
  30890. get messageHandler() {
  30891. return this._messageHandler;
  30892. },
  30893. _initialize: function PDFWorker_initialize() {
  30894. // If worker support isn't disabled explicit and the browser has worker
  30895. // support, create a new web worker and test if it/the browser fulfills
  30896. // all requirements to run parts of pdf.js in a web worker.
  30897. // Right now, the requirement is, that an Uint8Array is still an
  30898. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  30899. // Either workers are disabled, not supported or have thrown an exception.
  30900. // Thus, we fallback to a faked worker.
  30901. this._setupFakeWorker();
  30902. },
  30903. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  30904. if (!globalScope.PDFJS.disableWorker) {
  30905. warn('Setting up fake worker.');
  30906. globalScope.PDFJS.disableWorker = true;
  30907. }
  30908. setupFakeWorkerGlobal().then(function () {
  30909. if (this.destroyed) {
  30910. this._readyCapability.reject(new Error('Worker was destroyed'));
  30911. return;
  30912. }
  30913. // If we don't use a worker, just post/sendMessage to the main thread.
  30914. var port = {
  30915. _listeners: [],
  30916. postMessage: function (obj) {
  30917. var e = {data: obj};
  30918. this._listeners.forEach(function (listener) {
  30919. listener.call(this, e);
  30920. }, this);
  30921. },
  30922. addEventListener: function (name, listener) {
  30923. this._listeners.push(listener);
  30924. },
  30925. removeEventListener: function (name, listener) {
  30926. var i = this._listeners.indexOf(listener);
  30927. this._listeners.splice(i, 1);
  30928. },
  30929. terminate: function () {}
  30930. };
  30931. this._port = port;
  30932. // All fake workers use the same port, making id unique.
  30933. var id = 'fake' + (nextFakeWorkerId++);
  30934. // If the main thread is our worker, setup the handling for the
  30935. // messages -- the main thread sends to it self.
  30936. var workerHandler = new MessageHandler(id + '_worker', id, port);
  30937. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  30938. var messageHandler = new MessageHandler(id, id + '_worker', port);
  30939. this._messageHandler = messageHandler;
  30940. this._readyCapability.resolve();
  30941. }.bind(this));
  30942. },
  30943. /**
  30944. * Destroys the worker instance.
  30945. */
  30946. destroy: function PDFWorker_destroy() {
  30947. this.destroyed = true;
  30948. if (this._webWorker) {
  30949. // We need to terminate only web worker created resource.
  30950. this._webWorker.terminate();
  30951. this._webWorker = null;
  30952. }
  30953. this._port = null;
  30954. if (this._messageHandler) {
  30955. this._messageHandler.destroy();
  30956. this._messageHandler = null;
  30957. }
  30958. }
  30959. };
  30960. return PDFWorker;
  30961. })();
  30962. PDFJS.PDFWorker = PDFWorker;
  30963. /**
  30964. * For internal use only.
  30965. * @ignore
  30966. */
  30967. var WorkerTransport = (function WorkerTransportClosure() {
  30968. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  30969. this.messageHandler = messageHandler;
  30970. this.loadingTask = loadingTask;
  30971. this.pdfDataRangeTransport = pdfDataRangeTransport;
  30972. this.commonObjs = new PDFObjects();
  30973. this.fontLoader = new FontLoader(loadingTask.docId);
  30974. this.destroyed = false;
  30975. this.destroyCapability = null;
  30976. this.pageCache = [];
  30977. this.pagePromises = [];
  30978. this.downloadInfoCapability = createPromiseCapability();
  30979. this.setupMessageHandler();
  30980. }
  30981. WorkerTransport.prototype = {
  30982. destroy: function WorkerTransport_destroy() {
  30983. if (this.destroyCapability) {
  30984. return this.destroyCapability.promise;
  30985. }
  30986. this.destroyed = true;
  30987. this.destroyCapability = createPromiseCapability();
  30988. var waitOn = [];
  30989. // We need to wait for all renderings to be completed, e.g.
  30990. // timeout/rAF can take a long time.
  30991. this.pageCache.forEach(function (page) {
  30992. if (page) {
  30993. waitOn.push(page._destroy());
  30994. }
  30995. });
  30996. this.pageCache = [];
  30997. this.pagePromises = [];
  30998. var self = this;
  30999. // We also need to wait for the worker to finish its long running tasks.
  31000. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  31001. waitOn.push(terminated);
  31002. Promise.all(waitOn).then(function () {
  31003. self.fontLoader.clear();
  31004. if (self.pdfDataRangeTransport) {
  31005. self.pdfDataRangeTransport.abort();
  31006. self.pdfDataRangeTransport = null;
  31007. }
  31008. if (self.messageHandler) {
  31009. self.messageHandler.destroy();
  31010. self.messageHandler = null;
  31011. }
  31012. self.destroyCapability.resolve();
  31013. }, this.destroyCapability.reject);
  31014. return this.destroyCapability.promise;
  31015. },
  31016. setupMessageHandler:
  31017. function WorkerTransport_setupMessageHandler() {
  31018. var messageHandler = this.messageHandler;
  31019. function updatePassword(password) {
  31020. messageHandler.send('UpdatePassword', password);
  31021. }
  31022. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  31023. if (pdfDataRangeTransport) {
  31024. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  31025. messageHandler.send('OnDataRange', {
  31026. begin: begin,
  31027. chunk: chunk
  31028. });
  31029. });
  31030. pdfDataRangeTransport.addProgressListener(function(loaded) {
  31031. messageHandler.send('OnDataProgress', {
  31032. loaded: loaded
  31033. });
  31034. });
  31035. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  31036. messageHandler.send('OnDataRange', {
  31037. chunk: chunk
  31038. });
  31039. });
  31040. messageHandler.on('RequestDataRange',
  31041. function transportDataRange(data) {
  31042. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  31043. }, this);
  31044. }
  31045. messageHandler.on('GetDoc', function transportDoc(data) {
  31046. var pdfInfo = data.pdfInfo;
  31047. this.numPages = data.pdfInfo.numPages;
  31048. var loadingTask = this.loadingTask;
  31049. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  31050. this.pdfDocument = pdfDocument;
  31051. loadingTask._capability.resolve(pdfDocument);
  31052. }, this);
  31053. messageHandler.on('NeedPassword',
  31054. function transportNeedPassword(exception) {
  31055. var loadingTask = this.loadingTask;
  31056. if (loadingTask.onPassword) {
  31057. return loadingTask.onPassword(updatePassword,
  31058. PasswordResponses.NEED_PASSWORD);
  31059. }
  31060. loadingTask._capability.reject(
  31061. new PasswordException(exception.message, exception.code));
  31062. }, this);
  31063. messageHandler.on('IncorrectPassword',
  31064. function transportIncorrectPassword(exception) {
  31065. var loadingTask = this.loadingTask;
  31066. if (loadingTask.onPassword) {
  31067. return loadingTask.onPassword(updatePassword,
  31068. PasswordResponses.INCORRECT_PASSWORD);
  31069. }
  31070. loadingTask._capability.reject(
  31071. new PasswordException(exception.message, exception.code));
  31072. }, this);
  31073. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  31074. this.loadingTask._capability.reject(
  31075. new InvalidPDFException(exception.message));
  31076. }, this);
  31077. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  31078. this.loadingTask._capability.reject(
  31079. new MissingPDFException(exception.message));
  31080. }, this);
  31081. messageHandler.on('UnexpectedResponse',
  31082. function transportUnexpectedResponse(exception) {
  31083. this.loadingTask._capability.reject(
  31084. new UnexpectedResponseException(exception.message, exception.status));
  31085. }, this);
  31086. messageHandler.on('UnknownError',
  31087. function transportUnknownError(exception) {
  31088. this.loadingTask._capability.reject(
  31089. new UnknownErrorException(exception.message, exception.details));
  31090. }, this);
  31091. messageHandler.on('DataLoaded', function transportPage(data) {
  31092. this.downloadInfoCapability.resolve(data);
  31093. }, this);
  31094. messageHandler.on('PDFManagerReady', function transportPage(data) {
  31095. if (this.pdfDataRangeTransport) {
  31096. this.pdfDataRangeTransport.transportReady();
  31097. }
  31098. }, this);
  31099. messageHandler.on('StartRenderPage', function transportRender(data) {
  31100. if (this.destroyed) {
  31101. return; // Ignore any pending requests if the worker was terminated.
  31102. }
  31103. var page = this.pageCache[data.pageIndex];
  31104. page.stats.timeEnd('Page Request');
  31105. page._startRenderPage(data.transparency, data.intent);
  31106. }, this);
  31107. messageHandler.on('RenderPageChunk', function transportRender(data) {
  31108. if (this.destroyed) {
  31109. return; // Ignore any pending requests if the worker was terminated.
  31110. }
  31111. var page = this.pageCache[data.pageIndex];
  31112. page._renderPageChunk(data.operatorList, data.intent);
  31113. }, this);
  31114. messageHandler.on('commonobj', function transportObj(data) {
  31115. if (this.destroyed) {
  31116. return; // Ignore any pending requests if the worker was terminated.
  31117. }
  31118. var id = data[0];
  31119. var type = data[1];
  31120. if (this.commonObjs.hasData(id)) {
  31121. return;
  31122. }
  31123. switch (type) {
  31124. case 'Font':
  31125. var exportedData = data[2];
  31126. var font;
  31127. if ('error' in exportedData) {
  31128. var error = exportedData.error;
  31129. warn('Error during font loading: ' + error);
  31130. this.commonObjs.resolve(id, error);
  31131. break;
  31132. } else {
  31133. font = new FontFaceObject(exportedData);
  31134. }
  31135. this.fontLoader.bind(
  31136. [font],
  31137. function fontReady(fontObjs) {
  31138. this.commonObjs.resolve(id, font);
  31139. }.bind(this)
  31140. );
  31141. break;
  31142. case 'FontPath':
  31143. this.commonObjs.resolve(id, data[2]);
  31144. break;
  31145. default:
  31146. error('Got unknown common object type ' + type);
  31147. }
  31148. }, this);
  31149. messageHandler.on('obj', function transportObj(data) {
  31150. if (this.destroyed) {
  31151. return; // Ignore any pending requests if the worker was terminated.
  31152. }
  31153. var id = data[0];
  31154. var pageIndex = data[1];
  31155. var type = data[2];
  31156. var pageProxy = this.pageCache[pageIndex];
  31157. var imageData;
  31158. if (pageProxy.objs.hasData(id)) {
  31159. return;
  31160. }
  31161. switch (type) {
  31162. case 'JpegStream':
  31163. imageData = data[3];
  31164. loadJpegStream(id, imageData, pageProxy.objs);
  31165. break;
  31166. case 'Image':
  31167. imageData = data[3];
  31168. pageProxy.objs.resolve(id, imageData);
  31169. // heuristics that will allow not to store large data
  31170. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  31171. if (imageData && 'data' in imageData &&
  31172. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  31173. pageProxy.cleanupAfterRender = true;
  31174. }
  31175. break;
  31176. default:
  31177. error('Got unknown object type ' + type);
  31178. }
  31179. }, this);
  31180. messageHandler.on('DocProgress', function transportDocProgress(data) {
  31181. if (this.destroyed) {
  31182. return; // Ignore any pending requests if the worker was terminated.
  31183. }
  31184. var loadingTask = this.loadingTask;
  31185. if (loadingTask.onProgress) {
  31186. loadingTask.onProgress({
  31187. loaded: data.loaded,
  31188. total: data.total
  31189. });
  31190. }
  31191. }, this);
  31192. messageHandler.on('PageError', function transportError(data) {
  31193. if (this.destroyed) {
  31194. return; // Ignore any pending requests if the worker was terminated.
  31195. }
  31196. var page = this.pageCache[data.pageNum - 1];
  31197. var intentState = page.intentStates[data.intent];
  31198. if (intentState.displayReadyCapability) {
  31199. intentState.displayReadyCapability.reject(data.error);
  31200. } else {
  31201. error(data.error);
  31202. }
  31203. }, this);
  31204. messageHandler.on('UnsupportedFeature',
  31205. function transportUnsupportedFeature(data) {
  31206. if (this.destroyed) {
  31207. return; // Ignore any pending requests if the worker was terminated.
  31208. }
  31209. var featureId = data.featureId;
  31210. var loadingTask = this.loadingTask;
  31211. if (loadingTask.onUnsupportedFeature) {
  31212. loadingTask.onUnsupportedFeature(featureId);
  31213. }
  31214. PDFJS.UnsupportedManager.notify(featureId);
  31215. }, this);
  31216. messageHandler.on('JpegDecode', function(data) {
  31217. if (this.destroyed) {
  31218. return Promise.reject('Worker was terminated');
  31219. }
  31220. var imageUrl = data[0];
  31221. var components = data[1];
  31222. if (components !== 3 && components !== 1) {
  31223. return Promise.reject(
  31224. new Error('Only 3 components or 1 component can be returned'));
  31225. }
  31226. return new Promise(function (resolve, reject) {
  31227. var img = new Image();
  31228. img.onload = function () {
  31229. var width = img.width;
  31230. var height = img.height;
  31231. var size = width * height;
  31232. var rgbaLength = size * 4;
  31233. var buf = new Uint8Array(size * components);
  31234. var tmpCanvas = createScratchCanvas(width, height);
  31235. var tmpCtx = tmpCanvas.getContext('2d');
  31236. tmpCtx.drawImage(img, 0, 0);
  31237. var data = tmpCtx.getImageData(0, 0, width, height).data;
  31238. var i, j;
  31239. if (components === 3) {
  31240. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  31241. buf[j] = data[i];
  31242. buf[j + 1] = data[i + 1];
  31243. buf[j + 2] = data[i + 2];
  31244. }
  31245. } else if (components === 1) {
  31246. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  31247. buf[j] = data[i];
  31248. }
  31249. }
  31250. resolve({ data: buf, width: width, height: height});
  31251. };
  31252. img.onerror = function () {
  31253. reject(new Error('JpegDecode failed to load image'));
  31254. };
  31255. img.src = imageUrl;
  31256. });
  31257. }, this);
  31258. },
  31259. getData: function WorkerTransport_getData() {
  31260. return this.messageHandler.sendWithPromise('GetData', null);
  31261. },
  31262. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  31263. if (pageNumber <= 0 || pageNumber > this.numPages ||
  31264. (pageNumber|0) !== pageNumber) {
  31265. return Promise.reject(new Error('Invalid page request'));
  31266. }
  31267. var pageIndex = pageNumber - 1;
  31268. if (pageIndex in this.pagePromises) {
  31269. return this.pagePromises[pageIndex];
  31270. }
  31271. var promise = this.messageHandler.sendWithPromise('GetPage', {
  31272. pageIndex: pageIndex
  31273. }).then(function (pageInfo) {
  31274. if (this.destroyed) {
  31275. throw new Error('Transport destroyed');
  31276. }
  31277. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  31278. this.pageCache[pageIndex] = page;
  31279. return page;
  31280. }.bind(this));
  31281. this.pagePromises[pageIndex] = promise;
  31282. return promise;
  31283. },
  31284. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  31285. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  31286. },
  31287. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  31288. return this.messageHandler.sendWithPromise('GetAnnotations', {
  31289. pageIndex: pageIndex,
  31290. intent: intent,
  31291. });
  31292. },
  31293. getDestinations: function WorkerTransport_getDestinations() {
  31294. return this.messageHandler.sendWithPromise('GetDestinations', null);
  31295. },
  31296. getDestination: function WorkerTransport_getDestination(id) {
  31297. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  31298. },
  31299. getPageLabels: function WorkerTransport_getPageLabels() {
  31300. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  31301. },
  31302. getAttachments: function WorkerTransport_getAttachments() {
  31303. return this.messageHandler.sendWithPromise('GetAttachments', null);
  31304. },
  31305. getJavaScript: function WorkerTransport_getJavaScript() {
  31306. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  31307. },
  31308. getOutline: function WorkerTransport_getOutline() {
  31309. return this.messageHandler.sendWithPromise('GetOutline', null);
  31310. },
  31311. getMetadata: function WorkerTransport_getMetadata() {
  31312. return this.messageHandler.sendWithPromise('GetMetadata', null).
  31313. then(function transportMetadata(results) {
  31314. return {
  31315. info: results[0],
  31316. metadata: (results[1] ? new Metadata(results[1]) : null)
  31317. };
  31318. });
  31319. },
  31320. getStats: function WorkerTransport_getStats() {
  31321. return this.messageHandler.sendWithPromise('GetStats', null);
  31322. },
  31323. startCleanup: function WorkerTransport_startCleanup() {
  31324. this.messageHandler.sendWithPromise('Cleanup', null).
  31325. then(function endCleanup() {
  31326. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  31327. var page = this.pageCache[i];
  31328. if (page) {
  31329. page.cleanup();
  31330. }
  31331. }
  31332. this.commonObjs.clear();
  31333. this.fontLoader.clear();
  31334. }.bind(this));
  31335. }
  31336. };
  31337. return WorkerTransport;
  31338. })();
  31339. /**
  31340. * A PDF document and page is built of many objects. E.g. there are objects
  31341. * for fonts, images, rendering code and such. These objects might get processed
  31342. * inside of a worker. The `PDFObjects` implements some basic functions to
  31343. * manage these objects.
  31344. * @ignore
  31345. */
  31346. var PDFObjects = (function PDFObjectsClosure() {
  31347. function PDFObjects() {
  31348. this.objs = Object.create(null);
  31349. }
  31350. PDFObjects.prototype = {
  31351. /**
  31352. * Internal function.
  31353. * Ensures there is an object defined for `objId`.
  31354. */
  31355. ensureObj: function PDFObjects_ensureObj(objId) {
  31356. if (this.objs[objId]) {
  31357. return this.objs[objId];
  31358. }
  31359. var obj = {
  31360. capability: createPromiseCapability(),
  31361. data: null,
  31362. resolved: false
  31363. };
  31364. this.objs[objId] = obj;
  31365. return obj;
  31366. },
  31367. /**
  31368. * If called *without* callback, this returns the data of `objId` but the
  31369. * object needs to be resolved. If it isn't, this function throws.
  31370. *
  31371. * If called *with* a callback, the callback is called with the data of the
  31372. * object once the object is resolved. That means, if you call this
  31373. * function and the object is already resolved, the callback gets called
  31374. * right away.
  31375. */
  31376. get: function PDFObjects_get(objId, callback) {
  31377. // If there is a callback, then the get can be async and the object is
  31378. // not required to be resolved right now
  31379. if (callback) {
  31380. this.ensureObj(objId).capability.promise.then(callback);
  31381. return null;
  31382. }
  31383. // If there isn't a callback, the user expects to get the resolved data
  31384. // directly.
  31385. var obj = this.objs[objId];
  31386. // If there isn't an object yet or the object isn't resolved, then the
  31387. // data isn't ready yet!
  31388. if (!obj || !obj.resolved) {
  31389. error('Requesting object that isn\'t resolved yet ' + objId);
  31390. }
  31391. return obj.data;
  31392. },
  31393. /**
  31394. * Resolves the object `objId` with optional `data`.
  31395. */
  31396. resolve: function PDFObjects_resolve(objId, data) {
  31397. var obj = this.ensureObj(objId);
  31398. obj.resolved = true;
  31399. obj.data = data;
  31400. obj.capability.resolve(data);
  31401. },
  31402. isResolved: function PDFObjects_isResolved(objId) {
  31403. var objs = this.objs;
  31404. if (!objs[objId]) {
  31405. return false;
  31406. } else {
  31407. return objs[objId].resolved;
  31408. }
  31409. },
  31410. hasData: function PDFObjects_hasData(objId) {
  31411. return this.isResolved(objId);
  31412. },
  31413. /**
  31414. * Returns the data of `objId` if object exists, null otherwise.
  31415. */
  31416. getData: function PDFObjects_getData(objId) {
  31417. var objs = this.objs;
  31418. if (!objs[objId] || !objs[objId].resolved) {
  31419. return null;
  31420. } else {
  31421. return objs[objId].data;
  31422. }
  31423. },
  31424. clear: function PDFObjects_clear() {
  31425. this.objs = Object.create(null);
  31426. }
  31427. };
  31428. return PDFObjects;
  31429. })();
  31430. /**
  31431. * Allows controlling of the rendering tasks.
  31432. * @class
  31433. * @alias RenderTask
  31434. */
  31435. var RenderTask = (function RenderTaskClosure() {
  31436. function RenderTask(internalRenderTask) {
  31437. this._internalRenderTask = internalRenderTask;
  31438. /**
  31439. * Callback for incremental rendering -- a function that will be called
  31440. * each time the rendering is paused. To continue rendering call the
  31441. * function that is the first argument to the callback.
  31442. * @type {function}
  31443. */
  31444. this.onContinue = null;
  31445. }
  31446. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  31447. /**
  31448. * Promise for rendering task completion.
  31449. * @return {Promise}
  31450. */
  31451. get promise() {
  31452. return this._internalRenderTask.capability.promise;
  31453. },
  31454. /**
  31455. * Cancels the rendering task. If the task is currently rendering it will
  31456. * not be cancelled until graphics pauses with a timeout. The promise that
  31457. * this object extends will resolved when cancelled.
  31458. */
  31459. cancel: function RenderTask_cancel() {
  31460. this._internalRenderTask.cancel();
  31461. },
  31462. /**
  31463. * Registers callbacks to indicate the rendering task completion.
  31464. *
  31465. * @param {function} onFulfilled The callback for the rendering completion.
  31466. * @param {function} onRejected The callback for the rendering failure.
  31467. * @return {Promise} A promise that is resolved after the onFulfilled or
  31468. * onRejected callback.
  31469. */
  31470. then: function RenderTask_then(onFulfilled, onRejected) {
  31471. return this.promise.then.apply(this.promise, arguments);
  31472. }
  31473. };
  31474. return RenderTask;
  31475. })();
  31476. /**
  31477. * For internal use only.
  31478. * @ignore
  31479. */
  31480. var InternalRenderTask = (function InternalRenderTaskClosure() {
  31481. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  31482. pageNumber) {
  31483. this.callback = callback;
  31484. this.params = params;
  31485. this.objs = objs;
  31486. this.commonObjs = commonObjs;
  31487. this.operatorListIdx = null;
  31488. this.operatorList = operatorList;
  31489. this.pageNumber = pageNumber;
  31490. this.running = false;
  31491. this.graphicsReadyCallback = null;
  31492. this.graphicsReady = false;
  31493. this.useRequestAnimationFrame = false;
  31494. this.cancelled = false;
  31495. this.capability = createPromiseCapability();
  31496. this.task = new RenderTask(this);
  31497. // caching this-bound methods
  31498. this._continueBound = this._continue.bind(this);
  31499. this._scheduleNextBound = this._scheduleNext.bind(this);
  31500. this._nextBound = this._next.bind(this);
  31501. }
  31502. InternalRenderTask.prototype = {
  31503. initalizeGraphics:
  31504. function InternalRenderTask_initalizeGraphics(transparency) {
  31505. if (this.cancelled) {
  31506. return;
  31507. }
  31508. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  31509. globalScope.StepperManager.enabled) {
  31510. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  31511. this.stepper.init(this.operatorList);
  31512. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  31513. }
  31514. var params = this.params;
  31515. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  31516. this.objs, params.imageLayer);
  31517. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  31518. this.operatorListIdx = 0;
  31519. this.graphicsReady = true;
  31520. if (this.graphicsReadyCallback) {
  31521. this.graphicsReadyCallback();
  31522. }
  31523. },
  31524. cancel: function InternalRenderTask_cancel() {
  31525. this.running = false;
  31526. this.cancelled = true;
  31527. this.callback('cancelled');
  31528. },
  31529. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  31530. if (!this.graphicsReady) {
  31531. if (!this.graphicsReadyCallback) {
  31532. this.graphicsReadyCallback = this._continueBound;
  31533. }
  31534. return;
  31535. }
  31536. if (this.stepper) {
  31537. this.stepper.updateOperatorList(this.operatorList);
  31538. }
  31539. if (this.running) {
  31540. return;
  31541. }
  31542. this._continue();
  31543. },
  31544. _continue: function InternalRenderTask__continue() {
  31545. this.running = true;
  31546. if (this.cancelled) {
  31547. return;
  31548. }
  31549. if (this.task.onContinue) {
  31550. this.task.onContinue.call(this.task, this._scheduleNextBound);
  31551. } else {
  31552. this._scheduleNext();
  31553. }
  31554. },
  31555. _scheduleNext: function InternalRenderTask__scheduleNext() {
  31556. if (this.useRequestAnimationFrame) {
  31557. window.requestAnimationFrame(this._nextBound);
  31558. } else {
  31559. Promise.resolve(undefined).then(this._nextBound);
  31560. }
  31561. },
  31562. _next: function InternalRenderTask__next() {
  31563. if (this.cancelled) {
  31564. return;
  31565. }
  31566. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  31567. this.operatorListIdx,
  31568. this._continueBound,
  31569. this.stepper);
  31570. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  31571. this.running = false;
  31572. if (this.operatorList.lastChunk) {
  31573. this.gfx.endDrawing();
  31574. this.callback();
  31575. }
  31576. }
  31577. }
  31578. };
  31579. return InternalRenderTask;
  31580. })();
  31581. /**
  31582. * (Deprecated) Global observer of unsupported feature usages. Use
  31583. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  31584. */
  31585. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  31586. var listeners = [];
  31587. return {
  31588. listen: function (cb) {
  31589. deprecated('Global UnsupportedManager.listen is used: ' +
  31590. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  31591. listeners.push(cb);
  31592. },
  31593. notify: function (featureId) {
  31594. for (var i = 0, ii = listeners.length; i < ii; i++) {
  31595. listeners[i](featureId);
  31596. }
  31597. }
  31598. };
  31599. })();
  31600. exports.getDocument = PDFJS.getDocument;
  31601. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  31602. exports.PDFDocumentProxy = PDFDocumentProxy;
  31603. exports.PDFPageProxy = PDFPageProxy;
  31604. }));
  31605. (function (root, factory) {
  31606. {
  31607. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  31608. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  31609. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  31610. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  31611. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
  31612. }
  31613. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  31614. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer,
  31615. coreEncodings, coreStandardFonts, coreUnicode) {
  31616. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  31617. var FontType = sharedUtil.FontType;
  31618. var Util = sharedUtil.Util;
  31619. var assert = sharedUtil.assert;
  31620. var bytesToString = sharedUtil.bytesToString;
  31621. var error = sharedUtil.error;
  31622. var info = sharedUtil.info;
  31623. var isArray = sharedUtil.isArray;
  31624. var isInt = sharedUtil.isInt;
  31625. var isNum = sharedUtil.isNum;
  31626. var readUint32 = sharedUtil.readUint32;
  31627. var shadow = sharedUtil.shadow;
  31628. var stringToBytes = sharedUtil.stringToBytes;
  31629. var string32 = sharedUtil.string32;
  31630. var warn = sharedUtil.warn;
  31631. var Name = corePrimitives.Name;
  31632. var Stream = coreStream.Stream;
  31633. var Lexer = coreParser.Lexer;
  31634. var CMapFactory = coreCMap.CMapFactory;
  31635. var IdentityCMap = coreCMap.IdentityCMap;
  31636. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  31637. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  31638. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  31639. var ExpertCharset = coreCharsets.ExpertCharset;
  31640. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  31641. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  31642. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  31643. var StandardEncoding = coreEncodings.StandardEncoding;
  31644. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  31645. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  31646. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  31647. var ExpertEncoding = coreEncodings.ExpertEncoding;
  31648. var getEncoding = coreEncodings.getEncoding;
  31649. var getStdFontMap = coreStandardFonts.getStdFontMap;
  31650. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  31651. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  31652. var getSupplementalGlyphMapForArialBlack =
  31653. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  31654. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  31655. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  31656. // Unicode Private Use Area
  31657. var PRIVATE_USE_OFFSET_START = 0xE000;
  31658. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  31659. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  31660. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  31661. // except for Type 3 fonts
  31662. var PDF_GLYPH_SPACE_UNITS = 1000;
  31663. // Hinting is currently disabled due to unknown problems on windows
  31664. // in tracemonkey and various other pdfs with type1 fonts.
  31665. var HINTING_ENABLED = false;
  31666. // Accented charactars are not displayed properly on windows, using this flag
  31667. // to control analysis of seac charstrings.
  31668. var SEAC_ANALYSIS_ENABLED = false;
  31669. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  31670. var MAX_SUBR_NESTING = 10;
  31671. var FontFlags = {
  31672. FixedPitch: 1,
  31673. Serif: 2,
  31674. Symbolic: 4,
  31675. Script: 8,
  31676. Nonsymbolic: 32,
  31677. Italic: 64,
  31678. AllCap: 65536,
  31679. SmallCap: 131072,
  31680. ForceBold: 262144
  31681. };
  31682. var MacStandardGlyphOrdering = [
  31683. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  31684. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  31685. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  31686. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  31687. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  31688. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  31689. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  31690. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  31691. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  31692. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  31693. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  31694. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  31695. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  31696. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  31697. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  31698. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  31699. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  31700. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  31701. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  31702. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  31703. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  31704. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  31705. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  31706. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  31707. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  31708. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  31709. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  31710. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  31711. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  31712. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  31713. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  31714. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  31715. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  31716. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  31717. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  31718. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  31719. function adjustWidths(properties) {
  31720. if (!properties.fontMatrix) {
  31721. return;
  31722. }
  31723. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  31724. return;
  31725. }
  31726. // adjusting width to fontMatrix scale
  31727. var scale = 0.001 / properties.fontMatrix[0];
  31728. var glyphsWidths = properties.widths;
  31729. for (var glyph in glyphsWidths) {
  31730. glyphsWidths[glyph] *= scale;
  31731. }
  31732. properties.defaultWidth *= scale;
  31733. }
  31734. function getFontType(type, subtype) {
  31735. switch (type) {
  31736. case 'Type1':
  31737. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  31738. case 'CIDFontType0':
  31739. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  31740. FontType.CIDFONTTYPE0;
  31741. case 'OpenType':
  31742. return FontType.OPENTYPE;
  31743. case 'TrueType':
  31744. return FontType.TRUETYPE;
  31745. case 'CIDFontType2':
  31746. return FontType.CIDFONTTYPE2;
  31747. case 'MMType1':
  31748. return FontType.MMTYPE1;
  31749. case 'Type0':
  31750. return FontType.TYPE0;
  31751. default:
  31752. return FontType.UNKNOWN;
  31753. }
  31754. }
  31755. var Glyph = (function GlyphClosure() {
  31756. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  31757. isSpace) {
  31758. this.fontChar = fontChar;
  31759. this.unicode = unicode;
  31760. this.accent = accent;
  31761. this.width = width;
  31762. this.vmetric = vmetric;
  31763. this.operatorListId = operatorListId;
  31764. this.isSpace = isSpace;
  31765. }
  31766. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  31767. vmetric, operatorListId, isSpace) {
  31768. return this.fontChar === fontChar &&
  31769. this.unicode === unicode &&
  31770. this.accent === accent &&
  31771. this.width === width &&
  31772. this.vmetric === vmetric &&
  31773. this.operatorListId === operatorListId &&
  31774. this.isSpace === isSpace;
  31775. };
  31776. return Glyph;
  31777. })();
  31778. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  31779. function ToUnicodeMap(cmap) {
  31780. // The elements of this._map can be integers or strings, depending on how
  31781. // |cmap| was created.
  31782. this._map = cmap;
  31783. }
  31784. ToUnicodeMap.prototype = {
  31785. get length() {
  31786. return this._map.length;
  31787. },
  31788. forEach: function(callback) {
  31789. for (var charCode in this._map) {
  31790. callback(charCode, this._map[charCode].charCodeAt(0));
  31791. }
  31792. },
  31793. has: function(i) {
  31794. return this._map[i] !== undefined;
  31795. },
  31796. get: function(i) {
  31797. return this._map[i];
  31798. },
  31799. charCodeOf: function(v) {
  31800. return this._map.indexOf(v);
  31801. }
  31802. };
  31803. return ToUnicodeMap;
  31804. })();
  31805. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  31806. function IdentityToUnicodeMap(firstChar, lastChar) {
  31807. this.firstChar = firstChar;
  31808. this.lastChar = lastChar;
  31809. }
  31810. IdentityToUnicodeMap.prototype = {
  31811. get length() {
  31812. return (this.lastChar + 1) - this.firstChar;
  31813. },
  31814. forEach: function (callback) {
  31815. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  31816. callback(i, i);
  31817. }
  31818. },
  31819. has: function (i) {
  31820. return this.firstChar <= i && i <= this.lastChar;
  31821. },
  31822. get: function (i) {
  31823. if (this.firstChar <= i && i <= this.lastChar) {
  31824. return String.fromCharCode(i);
  31825. }
  31826. return undefined;
  31827. },
  31828. charCodeOf: function (v) {
  31829. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  31830. }
  31831. };
  31832. return IdentityToUnicodeMap;
  31833. })();
  31834. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  31835. function writeInt16(dest, offset, num) {
  31836. dest[offset] = (num >> 8) & 0xFF;
  31837. dest[offset + 1] = num & 0xFF;
  31838. }
  31839. function writeInt32(dest, offset, num) {
  31840. dest[offset] = (num >> 24) & 0xFF;
  31841. dest[offset + 1] = (num >> 16) & 0xFF;
  31842. dest[offset + 2] = (num >> 8) & 0xFF;
  31843. dest[offset + 3] = num & 0xFF;
  31844. }
  31845. function writeData(dest, offset, data) {
  31846. var i, ii;
  31847. if (data instanceof Uint8Array) {
  31848. dest.set(data, offset);
  31849. } else if (typeof data === 'string') {
  31850. for (i = 0, ii = data.length; i < ii; i++) {
  31851. dest[offset++] = data.charCodeAt(i) & 0xFF;
  31852. }
  31853. } else {
  31854. // treating everything else as array
  31855. for (i = 0, ii = data.length; i < ii; i++) {
  31856. dest[offset++] = data[i] & 0xFF;
  31857. }
  31858. }
  31859. }
  31860. function OpenTypeFileBuilder(sfnt) {
  31861. this.sfnt = sfnt;
  31862. this.tables = Object.create(null);
  31863. }
  31864. OpenTypeFileBuilder.getSearchParams =
  31865. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  31866. var maxPower2 = 1, log2 = 0;
  31867. while ((maxPower2 ^ entriesCount) > maxPower2) {
  31868. maxPower2 <<= 1;
  31869. log2++;
  31870. }
  31871. var searchRange = maxPower2 * entrySize;
  31872. return {
  31873. range: searchRange,
  31874. entry: log2,
  31875. rangeShift: entrySize * entriesCount - searchRange
  31876. };
  31877. };
  31878. var OTF_HEADER_SIZE = 12;
  31879. var OTF_TABLE_ENTRY_SIZE = 16;
  31880. OpenTypeFileBuilder.prototype = {
  31881. toArray: function OpenTypeFileBuilder_toArray() {
  31882. var sfnt = this.sfnt;
  31883. // Tables needs to be written by ascendant alphabetic order
  31884. var tables = this.tables;
  31885. var tablesNames = Object.keys(tables);
  31886. tablesNames.sort();
  31887. var numTables = tablesNames.length;
  31888. var i, j, jj, table, tableName;
  31889. // layout the tables data
  31890. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  31891. var tableOffsets = [offset];
  31892. for (i = 0; i < numTables; i++) {
  31893. table = tables[tablesNames[i]];
  31894. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  31895. offset += paddedLength;
  31896. tableOffsets.push(offset);
  31897. }
  31898. var file = new Uint8Array(offset);
  31899. // write the table data first (mostly for checksum)
  31900. for (i = 0; i < numTables; i++) {
  31901. table = tables[tablesNames[i]];
  31902. writeData(file, tableOffsets[i], table);
  31903. }
  31904. // sfnt version (4 bytes)
  31905. if (sfnt === 'true') {
  31906. // Windows hates the Mac TrueType sfnt version number
  31907. sfnt = string32(0x00010000);
  31908. }
  31909. file[0] = sfnt.charCodeAt(0) & 0xFF;
  31910. file[1] = sfnt.charCodeAt(1) & 0xFF;
  31911. file[2] = sfnt.charCodeAt(2) & 0xFF;
  31912. file[3] = sfnt.charCodeAt(3) & 0xFF;
  31913. // numTables (2 bytes)
  31914. writeInt16(file, 4, numTables);
  31915. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  31916. // searchRange (2 bytes)
  31917. writeInt16(file, 6, searchParams.range);
  31918. // entrySelector (2 bytes)
  31919. writeInt16(file, 8, searchParams.entry);
  31920. // rangeShift (2 bytes)
  31921. writeInt16(file, 10, searchParams.rangeShift);
  31922. offset = OTF_HEADER_SIZE;
  31923. // writing table entries
  31924. for (i = 0; i < numTables; i++) {
  31925. tableName = tablesNames[i];
  31926. file[offset] = tableName.charCodeAt(0) & 0xFF;
  31927. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  31928. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  31929. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  31930. // checksum
  31931. var checksum = 0;
  31932. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  31933. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  31934. (file[j + 2] << 8) + file[j + 3];
  31935. checksum = (checksum + quad) | 0;
  31936. }
  31937. writeInt32(file, offset + 4, checksum);
  31938. // offset
  31939. writeInt32(file, offset + 8, tableOffsets[i]);
  31940. // length
  31941. writeInt32(file, offset + 12, tables[tableName].length);
  31942. offset += OTF_TABLE_ENTRY_SIZE;
  31943. }
  31944. return file;
  31945. },
  31946. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  31947. if (tag in this.tables) {
  31948. throw new Error('Table ' + tag + ' already exists');
  31949. }
  31950. this.tables[tag] = data;
  31951. }
  31952. };
  31953. return OpenTypeFileBuilder;
  31954. })();
  31955. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  31956. // issues when they are painted on the canvas, e.g. complex-script shaping or
  31957. // control/whitespace characters. The ranges are listed in pairs: the first item
  31958. // is a code of the first problematic code, the second one is the next
  31959. // non-problematic code. The ranges must be in sorted order.
  31960. var ProblematicCharRanges = new Int32Array([
  31961. // Control characters.
  31962. 0x0000, 0x0020,
  31963. 0x007F, 0x00A1,
  31964. 0x00AD, 0x00AE,
  31965. // Chars that is used in complex-script shaping.
  31966. 0x0600, 0x0780,
  31967. 0x08A0, 0x10A0,
  31968. 0x1780, 0x1800,
  31969. // General punctuation chars.
  31970. 0x2000, 0x2010,
  31971. 0x2011, 0x2012,
  31972. 0x2028, 0x2030,
  31973. 0x205F, 0x2070,
  31974. 0x25CC, 0x25CD,
  31975. // Chars that is used in complex-script shaping.
  31976. 0xAA60, 0xAA80,
  31977. // Specials Unicode block.
  31978. 0xFFF0, 0x10000
  31979. ]);
  31980. /**
  31981. * 'Font' is the class the outside world should use, it encapsulate all the font
  31982. * decoding logics whatever type it is (assuming the font type is supported).
  31983. *
  31984. * For example to read a Type1 font and to attach it to the document:
  31985. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  31986. * type1Font.bind();
  31987. */
  31988. var Font = (function FontClosure() {
  31989. function Font(name, file, properties) {
  31990. var charCode, glyphName, fontChar;
  31991. this.name = name;
  31992. this.loadedName = properties.loadedName;
  31993. this.isType3Font = properties.isType3Font;
  31994. this.sizes = [];
  31995. this.glyphCache = Object.create(null);
  31996. var names = name.split('+');
  31997. names = names.length > 1 ? names[1] : names[0];
  31998. names = names.split(/[-,_]/g)[0];
  31999. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  32000. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  32001. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  32002. var type = properties.type;
  32003. var subtype = properties.subtype;
  32004. this.type = type;
  32005. this.fallbackName = (this.isMonospace ? 'monospace' :
  32006. (this.isSerifFont ? 'serif' : 'sans-serif'));
  32007. this.differences = properties.differences;
  32008. this.widths = properties.widths;
  32009. this.defaultWidth = properties.defaultWidth;
  32010. this.composite = properties.composite;
  32011. this.wideChars = properties.wideChars;
  32012. this.cMap = properties.cMap;
  32013. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  32014. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  32015. this.fontMatrix = properties.fontMatrix;
  32016. this.bbox = properties.bbox;
  32017. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  32018. this.toFontChar = [];
  32019. if (properties.type === 'Type3') {
  32020. for (charCode = 0; charCode < 256; charCode++) {
  32021. this.toFontChar[charCode] = (this.differences[charCode] ||
  32022. properties.defaultEncoding[charCode]);
  32023. }
  32024. this.fontType = FontType.TYPE3;
  32025. return;
  32026. }
  32027. this.cidEncoding = properties.cidEncoding;
  32028. this.vertical = properties.vertical;
  32029. if (this.vertical) {
  32030. this.vmetrics = properties.vmetrics;
  32031. this.defaultVMetrics = properties.defaultVMetrics;
  32032. }
  32033. var glyphsUnicodeMap;
  32034. if (!file || file.isEmpty) {
  32035. if (file) {
  32036. // Some bad PDF generators will include empty font files,
  32037. // attempting to recover by assuming that no file exists.
  32038. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  32039. }
  32040. this.missingFile = true;
  32041. // The file data is not specified. Trying to fix the font name
  32042. // to be used with the canvas.font.
  32043. var fontName = name.replace(/[,_]/g, '-');
  32044. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  32045. var isStandardFont = !!stdFontMap[fontName] ||
  32046. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32047. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32048. this.bold = (fontName.search(/bold/gi) !== -1);
  32049. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32050. (fontName.search(/italic/gi) !== -1));
  32051. // Use 'name' instead of 'fontName' here because the original
  32052. // name ArialBlack for example will be replaced by Helvetica.
  32053. this.black = (name.search(/Black/g) !== -1);
  32054. // if at least one width is present, remeasure all chars when exists
  32055. this.remeasure = Object.keys(this.widths).length > 0;
  32056. if (isStandardFont && type === 'CIDFontType2' &&
  32057. properties.cidEncoding.indexOf('Identity-') === 0) {
  32058. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  32059. // Standard fonts might be embedded as CID font without glyph mapping.
  32060. // Building one based on GlyphMapForStandardFonts.
  32061. var map = [];
  32062. for (charCode in GlyphMapForStandardFonts) {
  32063. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32064. }
  32065. if (/ArialBlack/i.test(name)) {
  32066. var SupplementalGlyphMapForArialBlack =
  32067. getSupplementalGlyphMapForArialBlack();
  32068. for (charCode in SupplementalGlyphMapForArialBlack) {
  32069. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32070. }
  32071. }
  32072. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32073. if (!isIdentityUnicode) {
  32074. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32075. map[+charCode] = unicodeCharCode;
  32076. });
  32077. }
  32078. this.toFontChar = map;
  32079. this.toUnicode = new ToUnicodeMap(map);
  32080. } else if (/Symbol/i.test(fontName)) {
  32081. var symbols = SymbolSetEncoding;
  32082. glyphsUnicodeMap = getGlyphsUnicode();
  32083. for (charCode in symbols) {
  32084. fontChar = glyphsUnicodeMap[symbols[charCode]];
  32085. if (!fontChar) {
  32086. continue;
  32087. }
  32088. this.toFontChar[charCode] = fontChar;
  32089. }
  32090. for (charCode in properties.differences) {
  32091. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  32092. if (!fontChar) {
  32093. continue;
  32094. }
  32095. this.toFontChar[charCode] = fontChar;
  32096. }
  32097. } else if (/Dingbats/i.test(fontName)) {
  32098. glyphsUnicodeMap = getDingbatsGlyphsUnicode();
  32099. if (/Wingdings/i.test(name)) {
  32100. warn('Wingdings font without embedded font file, ' +
  32101. 'falling back to the ZapfDingbats encoding.');
  32102. }
  32103. var dingbats = ZapfDingbatsEncoding;
  32104. for (charCode in dingbats) {
  32105. fontChar = glyphsUnicodeMap[dingbats[charCode]];
  32106. if (!fontChar) {
  32107. continue;
  32108. }
  32109. this.toFontChar[charCode] = fontChar;
  32110. }
  32111. for (charCode in properties.differences) {
  32112. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  32113. if (!fontChar) {
  32114. continue;
  32115. }
  32116. this.toFontChar[charCode] = fontChar;
  32117. }
  32118. } else if (isStandardFont) {
  32119. this.toFontChar = [];
  32120. glyphsUnicodeMap = getGlyphsUnicode();
  32121. for (charCode in properties.defaultEncoding) {
  32122. glyphName = (properties.differences[charCode] ||
  32123. properties.defaultEncoding[charCode]);
  32124. this.toFontChar[charCode] = glyphsUnicodeMap[glyphName];
  32125. }
  32126. } else {
  32127. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  32128. glyphsUnicodeMap = getGlyphsUnicode();
  32129. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32130. if (notCidFont) {
  32131. glyphName = (properties.differences[charCode] ||
  32132. properties.defaultEncoding[charCode]);
  32133. unicodeCharCode = (glyphsUnicodeMap[glyphName] || unicodeCharCode);
  32134. }
  32135. this.toFontChar[charCode] = unicodeCharCode;
  32136. }.bind(this));
  32137. }
  32138. this.loadedName = fontName.split('-')[0];
  32139. this.loading = false;
  32140. this.fontType = getFontType(type, subtype);
  32141. return;
  32142. }
  32143. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32144. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32145. // Some TrueType fonts by mistake claim Type1C
  32146. if (isTrueTypeFile(file)) {
  32147. subtype = 'TrueType';
  32148. } else {
  32149. type = 'Type1';
  32150. }
  32151. }
  32152. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32153. type = 'CIDFontType0';
  32154. }
  32155. if (subtype === 'OpenType') {
  32156. type = 'OpenType';
  32157. }
  32158. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32159. if (type === 'CIDFontType0') {
  32160. if (isType1File(file)) {
  32161. subtype = 'CIDFontType0';
  32162. } else if (isOpenTypeFile(file)) {
  32163. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  32164. type = subtype = 'OpenType';
  32165. } else {
  32166. subtype = 'CIDFontType0C';
  32167. }
  32168. }
  32169. var data;
  32170. switch (type) {
  32171. case 'MMType1':
  32172. info('MMType1 font (' + name + '), falling back to Type1.');
  32173. /* falls through */
  32174. case 'Type1':
  32175. case 'CIDFontType0':
  32176. this.mimetype = 'font/opentype';
  32177. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32178. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32179. adjustWidths(properties);
  32180. // Wrap the CFF data inside an OTF font file
  32181. data = this.convert(name, cff, properties);
  32182. break;
  32183. case 'OpenType':
  32184. case 'TrueType':
  32185. case 'CIDFontType2':
  32186. this.mimetype = 'font/opentype';
  32187. // Repair the TrueType file. It is can be damaged in the point of
  32188. // view of the sanitizer
  32189. data = this.checkAndRepair(name, file, properties);
  32190. if (this.isOpenType) {
  32191. adjustWidths(properties);
  32192. type = 'OpenType';
  32193. }
  32194. break;
  32195. default:
  32196. error('Font ' + type + ' is not supported');
  32197. break;
  32198. }
  32199. this.data = data;
  32200. this.fontType = getFontType(type, subtype);
  32201. // Transfer some properties again that could change during font conversion
  32202. this.fontMatrix = properties.fontMatrix;
  32203. this.widths = properties.widths;
  32204. this.defaultWidth = properties.defaultWidth;
  32205. this.encoding = properties.baseEncoding;
  32206. this.seacMap = properties.seacMap;
  32207. this.loading = true;
  32208. }
  32209. Font.getFontID = (function () {
  32210. var ID = 1;
  32211. return function Font_getFontID() {
  32212. return String(ID++);
  32213. };
  32214. })();
  32215. function int16(b0, b1) {
  32216. return (b0 << 8) + b1;
  32217. }
  32218. function int32(b0, b1, b2, b3) {
  32219. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32220. }
  32221. function string16(value) {
  32222. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32223. }
  32224. function safeString16(value) {
  32225. // clamp value to the 16-bit int range
  32226. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32227. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32228. }
  32229. function isTrueTypeFile(file) {
  32230. var header = file.peekBytes(4);
  32231. return readUint32(header, 0) === 0x00010000;
  32232. }
  32233. function isOpenTypeFile(file) {
  32234. var header = file.peekBytes(4);
  32235. return bytesToString(header) === 'OTTO';
  32236. }
  32237. function isType1File(file) {
  32238. var header = file.peekBytes(2);
  32239. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32240. if (header[0] === 0x25 && header[1] === 0x21) {
  32241. return true;
  32242. }
  32243. // ... obviously some fonts violate that part of the specification,
  32244. // please refer to the comment in |Type1Font| below.
  32245. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32246. return true;
  32247. }
  32248. return false;
  32249. }
  32250. /**
  32251. * Helper function for |adjustMapping|.
  32252. * @return {boolean}
  32253. */
  32254. function isProblematicUnicodeLocation(code) {
  32255. // Using binary search to find a range start.
  32256. var i = 0, j = ProblematicCharRanges.length - 1;
  32257. while (i < j) {
  32258. var c = (i + j + 1) >> 1;
  32259. if (code < ProblematicCharRanges[c]) {
  32260. j = c - 1;
  32261. } else {
  32262. i = c;
  32263. }
  32264. }
  32265. // Even index means code in problematic range.
  32266. return !(i & 1);
  32267. }
  32268. /**
  32269. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32270. * with their unicode value. It also moves char codes that are in known
  32271. * problematic locations.
  32272. * @return {Object} Two properties:
  32273. * 'toFontChar' - maps original char codes(the value that will be read
  32274. * from commands such as show text) to the char codes that will be used in the
  32275. * font that we build
  32276. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32277. */
  32278. function adjustMapping(charCodeToGlyphId, properties) {
  32279. var toUnicode = properties.toUnicode;
  32280. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32281. var isIdentityUnicode =
  32282. properties.toUnicode instanceof IdentityToUnicodeMap;
  32283. var newMap = Object.create(null);
  32284. var toFontChar = [];
  32285. var usedFontCharCodes = [];
  32286. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32287. for (var originalCharCode in charCodeToGlyphId) {
  32288. originalCharCode |= 0;
  32289. var glyphId = charCodeToGlyphId[originalCharCode];
  32290. var fontCharCode = originalCharCode;
  32291. // First try to map the value to a unicode position if a non identity map
  32292. // was created.
  32293. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32294. var unicode = toUnicode.get(fontCharCode);
  32295. // TODO: Try to map ligatures to the correct spot.
  32296. if (unicode.length === 1) {
  32297. fontCharCode = unicode.charCodeAt(0);
  32298. }
  32299. }
  32300. // Try to move control characters, special characters and already mapped
  32301. // characters to the private use area since they will not be drawn by
  32302. // canvas if left in their current position. Also, move characters if the
  32303. // font was symbolic and there is only an identity unicode map since the
  32304. // characters probably aren't in the correct position (fixes an issue
  32305. // with firefox and thuluthfont).
  32306. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32307. isProblematicUnicodeLocation(fontCharCode) ||
  32308. (isSymbolic && isIdentityUnicode)) &&
  32309. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32310. // Loop to try and find a free spot in the private use area.
  32311. do {
  32312. fontCharCode = nextAvailableFontCharCode++;
  32313. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32314. fontCharCode = 0xF020;
  32315. nextAvailableFontCharCode = fontCharCode + 1;
  32316. }
  32317. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32318. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32319. }
  32320. newMap[fontCharCode] = glyphId;
  32321. toFontChar[originalCharCode] = fontCharCode;
  32322. usedFontCharCodes[fontCharCode] = true;
  32323. }
  32324. return {
  32325. toFontChar: toFontChar,
  32326. charCodeToGlyphId: newMap,
  32327. nextAvailableFontCharCode: nextAvailableFontCharCode
  32328. };
  32329. }
  32330. function getRanges(glyphs, numGlyphs) {
  32331. // Array.sort() sorts by characters, not numerically, so convert to an
  32332. // array of characters.
  32333. var codes = [];
  32334. for (var charCode in glyphs) {
  32335. // Remove an invalid glyph ID mappings to make OTS happy.
  32336. if (glyphs[charCode] >= numGlyphs) {
  32337. continue;
  32338. }
  32339. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32340. }
  32341. codes.sort(function fontGetRangesSort(a, b) {
  32342. return a.fontCharCode - b.fontCharCode;
  32343. });
  32344. // Split the sorted codes into ranges.
  32345. var ranges = [];
  32346. var length = codes.length;
  32347. for (var n = 0; n < length; ) {
  32348. var start = codes[n].fontCharCode;
  32349. var codeIndices = [codes[n].glyphId];
  32350. ++n;
  32351. var end = start;
  32352. while (n < length && end + 1 === codes[n].fontCharCode) {
  32353. codeIndices.push(codes[n].glyphId);
  32354. ++end;
  32355. ++n;
  32356. if (end === 0xFFFF) {
  32357. break;
  32358. }
  32359. }
  32360. ranges.push([start, end, codeIndices]);
  32361. }
  32362. return ranges;
  32363. }
  32364. function createCmapTable(glyphs, numGlyphs) {
  32365. var ranges = getRanges(glyphs, numGlyphs);
  32366. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32367. var cmap = '\x00\x00' + // version
  32368. string16(numTables) + // numTables
  32369. '\x00\x03' + // platformID
  32370. '\x00\x01' + // encodingID
  32371. string32(4 + numTables * 8); // start of the table record
  32372. var i, ii, j, jj;
  32373. for (i = ranges.length - 1; i >= 0; --i) {
  32374. if (ranges[i][0] <= 0xFFFF) { break; }
  32375. }
  32376. var bmpLength = i + 1;
  32377. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32378. ranges[i][1] = 0xFFFE;
  32379. }
  32380. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32381. var segCount = bmpLength + trailingRangesCount;
  32382. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32383. // Fill up the 4 parallel arrays describing the segments.
  32384. var startCount = '';
  32385. var endCount = '';
  32386. var idDeltas = '';
  32387. var idRangeOffsets = '';
  32388. var glyphsIds = '';
  32389. var bias = 0;
  32390. var range, start, end, codes;
  32391. for (i = 0, ii = bmpLength; i < ii; i++) {
  32392. range = ranges[i];
  32393. start = range[0];
  32394. end = range[1];
  32395. startCount += string16(start);
  32396. endCount += string16(end);
  32397. codes = range[2];
  32398. var contiguous = true;
  32399. for (j = 1, jj = codes.length; j < jj; ++j) {
  32400. if (codes[j] !== codes[j - 1] + 1) {
  32401. contiguous = false;
  32402. break;
  32403. }
  32404. }
  32405. if (!contiguous) {
  32406. var offset = (segCount - i) * 2 + bias * 2;
  32407. bias += (end - start + 1);
  32408. idDeltas += string16(0);
  32409. idRangeOffsets += string16(offset);
  32410. for (j = 0, jj = codes.length; j < jj; ++j) {
  32411. glyphsIds += string16(codes[j]);
  32412. }
  32413. } else {
  32414. var startCode = codes[0];
  32415. idDeltas += string16((startCode - start) & 0xFFFF);
  32416. idRangeOffsets += string16(0);
  32417. }
  32418. }
  32419. if (trailingRangesCount > 0) {
  32420. endCount += '\xFF\xFF';
  32421. startCount += '\xFF\xFF';
  32422. idDeltas += '\x00\x01';
  32423. idRangeOffsets += '\x00\x00';
  32424. }
  32425. var format314 = '\x00\x00' + // language
  32426. string16(2 * segCount) +
  32427. string16(searchParams.range) +
  32428. string16(searchParams.entry) +
  32429. string16(searchParams.rangeShift) +
  32430. endCount + '\x00\x00' + startCount +
  32431. idDeltas + idRangeOffsets + glyphsIds;
  32432. var format31012 = '';
  32433. var header31012 = '';
  32434. if (numTables > 1) {
  32435. cmap += '\x00\x03' + // platformID
  32436. '\x00\x0A' + // encodingID
  32437. string32(4 + numTables * 8 +
  32438. 4 + format314.length); // start of the table record
  32439. format31012 = '';
  32440. for (i = 0, ii = ranges.length; i < ii; i++) {
  32441. range = ranges[i];
  32442. start = range[0];
  32443. codes = range[2];
  32444. var code = codes[0];
  32445. for (j = 1, jj = codes.length; j < jj; ++j) {
  32446. if (codes[j] !== codes[j - 1] + 1) {
  32447. end = range[0] + j - 1;
  32448. format31012 += string32(start) + // startCharCode
  32449. string32(end) + // endCharCode
  32450. string32(code); // startGlyphID
  32451. start = end + 1;
  32452. code = codes[j];
  32453. }
  32454. }
  32455. format31012 += string32(start) + // startCharCode
  32456. string32(range[1]) + // endCharCode
  32457. string32(code); // startGlyphID
  32458. }
  32459. header31012 = '\x00\x0C' + // format
  32460. '\x00\x00' + // reserved
  32461. string32(format31012.length + 16) + // length
  32462. '\x00\x00\x00\x00' + // language
  32463. string32(format31012.length / 12); // nGroups
  32464. }
  32465. return cmap + '\x00\x04' + // format
  32466. string16(format314.length + 4) + // length
  32467. format314 + header31012 + format31012;
  32468. }
  32469. function validateOS2Table(os2) {
  32470. var stream = new Stream(os2.data);
  32471. var version = stream.getUint16();
  32472. // TODO verify all OS/2 tables fields, but currently we validate only those
  32473. // that give us issues
  32474. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32475. var selection = stream.getUint16();
  32476. if (version < 4 && (selection & 0x0300)) {
  32477. return false;
  32478. }
  32479. var firstChar = stream.getUint16();
  32480. var lastChar = stream.getUint16();
  32481. if (firstChar > lastChar) {
  32482. return false;
  32483. }
  32484. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32485. var usWinAscent = stream.getUint16();
  32486. if (usWinAscent === 0) { // makes font unreadable by windows
  32487. return false;
  32488. }
  32489. // OS/2 appears to be valid, resetting some fields
  32490. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32491. return true;
  32492. }
  32493. function createOS2Table(properties, charstrings, override) {
  32494. override = override || {
  32495. unitsPerEm: 0,
  32496. yMax: 0,
  32497. yMin: 0,
  32498. ascent: 0,
  32499. descent: 0
  32500. };
  32501. var ulUnicodeRange1 = 0;
  32502. var ulUnicodeRange2 = 0;
  32503. var ulUnicodeRange3 = 0;
  32504. var ulUnicodeRange4 = 0;
  32505. var firstCharIndex = null;
  32506. var lastCharIndex = 0;
  32507. if (charstrings) {
  32508. for (var code in charstrings) {
  32509. code |= 0;
  32510. if (firstCharIndex > code || !firstCharIndex) {
  32511. firstCharIndex = code;
  32512. }
  32513. if (lastCharIndex < code) {
  32514. lastCharIndex = code;
  32515. }
  32516. var position = getUnicodeRangeFor(code);
  32517. if (position < 32) {
  32518. ulUnicodeRange1 |= 1 << position;
  32519. } else if (position < 64) {
  32520. ulUnicodeRange2 |= 1 << position - 32;
  32521. } else if (position < 96) {
  32522. ulUnicodeRange3 |= 1 << position - 64;
  32523. } else if (position < 123) {
  32524. ulUnicodeRange4 |= 1 << position - 96;
  32525. } else {
  32526. error('Unicode ranges Bits > 123 are reserved for internal usage');
  32527. }
  32528. }
  32529. } else {
  32530. // TODO
  32531. firstCharIndex = 0;
  32532. lastCharIndex = 255;
  32533. }
  32534. var bbox = properties.bbox || [0, 0, 0, 0];
  32535. var unitsPerEm = (override.unitsPerEm ||
  32536. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  32537. // if the font units differ to the PDF glyph space units
  32538. // then scale up the values
  32539. var scale = (properties.ascentScaled ? 1.0 :
  32540. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  32541. var typoAscent = (override.ascent ||
  32542. Math.round(scale * (properties.ascent || bbox[3])));
  32543. var typoDescent = (override.descent ||
  32544. Math.round(scale * (properties.descent || bbox[1])));
  32545. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  32546. typoDescent = -typoDescent; // fixing incorrect descent
  32547. }
  32548. var winAscent = override.yMax || typoAscent;
  32549. var winDescent = -override.yMin || -typoDescent;
  32550. return '\x00\x03' + // version
  32551. '\x02\x24' + // xAvgCharWidth
  32552. '\x01\xF4' + // usWeightClass
  32553. '\x00\x05' + // usWidthClass
  32554. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  32555. '\x02\x8A' + // ySubscriptXSize
  32556. '\x02\xBB' + // ySubscriptYSize
  32557. '\x00\x00' + // ySubscriptXOffset
  32558. '\x00\x8C' + // ySubscriptYOffset
  32559. '\x02\x8A' + // ySuperScriptXSize
  32560. '\x02\xBB' + // ySuperScriptYSize
  32561. '\x00\x00' + // ySuperScriptXOffset
  32562. '\x01\xDF' + // ySuperScriptYOffset
  32563. '\x00\x31' + // yStrikeOutSize
  32564. '\x01\x02' + // yStrikeOutPosition
  32565. '\x00\x00' + // sFamilyClass
  32566. '\x00\x00\x06' +
  32567. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  32568. '\x00\x00\x00\x00\x00\x00' + // Panose
  32569. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  32570. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  32571. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  32572. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  32573. '\x2A\x32\x31\x2A' + // achVendID
  32574. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  32575. string16(firstCharIndex ||
  32576. properties.firstChar) + // usFirstCharIndex
  32577. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  32578. string16(typoAscent) + // sTypoAscender
  32579. string16(typoDescent) + // sTypoDescender
  32580. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  32581. string16(winAscent) + // usWinAscent
  32582. string16(winDescent) + // usWinDescent
  32583. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  32584. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  32585. string16(properties.xHeight) + // sxHeight
  32586. string16(properties.capHeight) + // sCapHeight
  32587. string16(0) + // usDefaultChar
  32588. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  32589. '\x00\x03'; // usMaxContext
  32590. }
  32591. function createPostTable(properties) {
  32592. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  32593. return ('\x00\x03\x00\x00' + // Version number
  32594. string32(angle) + // italicAngle
  32595. '\x00\x00' + // underlinePosition
  32596. '\x00\x00' + // underlineThickness
  32597. string32(properties.fixedPitch) + // isFixedPitch
  32598. '\x00\x00\x00\x00' + // minMemType42
  32599. '\x00\x00\x00\x00' + // maxMemType42
  32600. '\x00\x00\x00\x00' + // minMemType1
  32601. '\x00\x00\x00\x00'); // maxMemType1
  32602. }
  32603. function createNameTable(name, proto) {
  32604. if (!proto) {
  32605. proto = [[], []]; // no strings and unicode strings
  32606. }
  32607. var strings = [
  32608. proto[0][0] || 'Original licence', // 0.Copyright
  32609. proto[0][1] || name, // 1.Font family
  32610. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  32611. proto[0][3] || 'uniqueID', // 3.Unique ID
  32612. proto[0][4] || name, // 4.Full font name
  32613. proto[0][5] || 'Version 0.11', // 5.Version
  32614. proto[0][6] || '', // 6.Postscript name
  32615. proto[0][7] || 'Unknown', // 7.Trademark
  32616. proto[0][8] || 'Unknown', // 8.Manufacturer
  32617. proto[0][9] || 'Unknown' // 9.Designer
  32618. ];
  32619. // Mac want 1-byte per character strings while Windows want
  32620. // 2-bytes per character, so duplicate the names table
  32621. var stringsUnicode = [];
  32622. var i, ii, j, jj, str;
  32623. for (i = 0, ii = strings.length; i < ii; i++) {
  32624. str = proto[1][i] || strings[i];
  32625. var strBufUnicode = [];
  32626. for (j = 0, jj = str.length; j < jj; j++) {
  32627. strBufUnicode.push(string16(str.charCodeAt(j)));
  32628. }
  32629. stringsUnicode.push(strBufUnicode.join(''));
  32630. }
  32631. var names = [strings, stringsUnicode];
  32632. var platforms = ['\x00\x01', '\x00\x03'];
  32633. var encodings = ['\x00\x00', '\x00\x01'];
  32634. var languages = ['\x00\x00', '\x04\x09'];
  32635. var namesRecordCount = strings.length * platforms.length;
  32636. var nameTable =
  32637. '\x00\x00' + // format
  32638. string16(namesRecordCount) + // Number of names Record
  32639. string16(namesRecordCount * 12 + 6); // Storage
  32640. // Build the name records field
  32641. var strOffset = 0;
  32642. for (i = 0, ii = platforms.length; i < ii; i++) {
  32643. var strs = names[i];
  32644. for (j = 0, jj = strs.length; j < jj; j++) {
  32645. str = strs[j];
  32646. var nameRecord =
  32647. platforms[i] + // platform ID
  32648. encodings[i] + // encoding ID
  32649. languages[i] + // language ID
  32650. string16(j) + // name ID
  32651. string16(str.length) +
  32652. string16(strOffset);
  32653. nameTable += nameRecord;
  32654. strOffset += str.length;
  32655. }
  32656. }
  32657. nameTable += strings.join('') + stringsUnicode.join('');
  32658. return nameTable;
  32659. }
  32660. Font.prototype = {
  32661. name: null,
  32662. font: null,
  32663. mimetype: null,
  32664. encoding: null,
  32665. get renderer() {
  32666. var renderer = FontRendererFactory.create(this);
  32667. return shadow(this, 'renderer', renderer);
  32668. },
  32669. exportData: function Font_exportData() {
  32670. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  32671. var data = {};
  32672. for (var i in this) {
  32673. if (this.hasOwnProperty(i)) {
  32674. data[i] = this[i];
  32675. }
  32676. }
  32677. return data;
  32678. },
  32679. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  32680. function readTableEntry(file) {
  32681. var tag = bytesToString(file.getBytes(4));
  32682. var checksum = file.getInt32();
  32683. var offset = file.getInt32() >>> 0;
  32684. var length = file.getInt32() >>> 0;
  32685. // Read the table associated data
  32686. var previousPosition = file.pos;
  32687. file.pos = file.start ? file.start : 0;
  32688. file.skip(offset);
  32689. var data = file.getBytes(length);
  32690. file.pos = previousPosition;
  32691. if (tag === 'head') {
  32692. // clearing checksum adjustment
  32693. data[8] = data[9] = data[10] = data[11] = 0;
  32694. data[17] |= 0x20; //Set font optimized for cleartype flag
  32695. }
  32696. return {
  32697. tag: tag,
  32698. checksum: checksum,
  32699. length: length,
  32700. offset: offset,
  32701. data: data
  32702. };
  32703. }
  32704. function readOpenTypeHeader(ttf) {
  32705. return {
  32706. version: bytesToString(ttf.getBytes(4)),
  32707. numTables: ttf.getUint16(),
  32708. searchRange: ttf.getUint16(),
  32709. entrySelector: ttf.getUint16(),
  32710. rangeShift: ttf.getUint16()
  32711. };
  32712. }
  32713. /**
  32714. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  32715. * PDF spec
  32716. */
  32717. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  32718. if (!cmap) {
  32719. warn('No cmap table available.');
  32720. return {
  32721. platformId: -1,
  32722. encodingId: -1,
  32723. mappings: [],
  32724. hasShortCmap: false
  32725. };
  32726. }
  32727. var segment;
  32728. var start = (font.start ? font.start : 0) + cmap.offset;
  32729. font.pos = start;
  32730. var version = font.getUint16();
  32731. var numTables = font.getUint16();
  32732. var potentialTable;
  32733. var canBreak = false;
  32734. // There's an order of preference in terms of which cmap subtable to
  32735. // use:
  32736. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  32737. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  32738. // The following takes advantage of the fact that the tables are sorted
  32739. // to work.
  32740. for (var i = 0; i < numTables; i++) {
  32741. var platformId = font.getUint16();
  32742. var encodingId = font.getUint16();
  32743. var offset = font.getInt32() >>> 0;
  32744. var useTable = false;
  32745. if (platformId === 0 && encodingId === 0) {
  32746. useTable = true;
  32747. // Continue the loop since there still may be a higher priority
  32748. // table.
  32749. } else if (platformId === 1 && encodingId === 0) {
  32750. useTable = true;
  32751. // Continue the loop since there still may be a higher priority
  32752. // table.
  32753. } else if (platformId === 3 && encodingId === 1 &&
  32754. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  32755. useTable = true;
  32756. if (!isSymbolicFont) {
  32757. canBreak = true;
  32758. }
  32759. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  32760. useTable = true;
  32761. canBreak = true;
  32762. }
  32763. if (useTable) {
  32764. potentialTable = {
  32765. platformId: platformId,
  32766. encodingId: encodingId,
  32767. offset: offset
  32768. };
  32769. }
  32770. if (canBreak) {
  32771. break;
  32772. }
  32773. }
  32774. if (potentialTable) {
  32775. font.pos = start + potentialTable.offset;
  32776. }
  32777. if (!potentialTable || font.peekByte() === -1) {
  32778. warn('Could not find a preferred cmap table.');
  32779. return {
  32780. platformId: -1,
  32781. encodingId: -1,
  32782. mappings: [],
  32783. hasShortCmap: false
  32784. };
  32785. }
  32786. var format = font.getUint16();
  32787. var length = font.getUint16();
  32788. var language = font.getUint16();
  32789. var hasShortCmap = false;
  32790. var mappings = [];
  32791. var j, glyphId;
  32792. // TODO(mack): refactor this cmap subtable reading logic out
  32793. if (format === 0) {
  32794. for (j = 0; j < 256; j++) {
  32795. var index = font.getByte();
  32796. if (!index) {
  32797. continue;
  32798. }
  32799. mappings.push({
  32800. charCode: j,
  32801. glyphId: index
  32802. });
  32803. }
  32804. hasShortCmap = true;
  32805. } else if (format === 4) {
  32806. // re-creating the table in format 4 since the encoding
  32807. // might be changed
  32808. var segCount = (font.getUint16() >> 1);
  32809. font.getBytes(6); // skipping range fields
  32810. var segIndex, segments = [];
  32811. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32812. segments.push({ end: font.getUint16() });
  32813. }
  32814. font.getUint16();
  32815. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32816. segments[segIndex].start = font.getUint16();
  32817. }
  32818. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32819. segments[segIndex].delta = font.getUint16();
  32820. }
  32821. var offsetsCount = 0;
  32822. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32823. segment = segments[segIndex];
  32824. var rangeOffset = font.getUint16();
  32825. if (!rangeOffset) {
  32826. segment.offsetIndex = -1;
  32827. continue;
  32828. }
  32829. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  32830. segment.offsetIndex = offsetIndex;
  32831. offsetsCount = Math.max(offsetsCount, offsetIndex +
  32832. segment.end - segment.start + 1);
  32833. }
  32834. var offsets = [];
  32835. for (j = 0; j < offsetsCount; j++) {
  32836. offsets.push(font.getUint16());
  32837. }
  32838. for (segIndex = 0; segIndex < segCount; segIndex++) {
  32839. segment = segments[segIndex];
  32840. start = segment.start;
  32841. var end = segment.end;
  32842. var delta = segment.delta;
  32843. offsetIndex = segment.offsetIndex;
  32844. for (j = start; j <= end; j++) {
  32845. if (j === 0xFFFF) {
  32846. continue;
  32847. }
  32848. glyphId = (offsetIndex < 0 ?
  32849. j : offsets[offsetIndex + j - start]);
  32850. glyphId = (glyphId + delta) & 0xFFFF;
  32851. if (glyphId === 0) {
  32852. continue;
  32853. }
  32854. mappings.push({
  32855. charCode: j,
  32856. glyphId: glyphId
  32857. });
  32858. }
  32859. }
  32860. } else if (format === 6) {
  32861. // Format 6 is a 2-bytes dense mapping, which means the font data
  32862. // lives glue together even if they are pretty far in the unicode
  32863. // table. (This looks weird, so I can have missed something), this
  32864. // works on Linux but seems to fails on Mac so let's rewrite the
  32865. // cmap table to a 3-1-4 style
  32866. var firstCode = font.getUint16();
  32867. var entryCount = font.getUint16();
  32868. for (j = 0; j < entryCount; j++) {
  32869. glyphId = font.getUint16();
  32870. var charCode = firstCode + j;
  32871. mappings.push({
  32872. charCode: charCode,
  32873. glyphId: glyphId
  32874. });
  32875. }
  32876. } else {
  32877. warn('cmap table has unsupported format: ' + format);
  32878. return {
  32879. platformId: -1,
  32880. encodingId: -1,
  32881. mappings: [],
  32882. hasShortCmap: false
  32883. };
  32884. }
  32885. // removing duplicate entries
  32886. mappings.sort(function (a, b) {
  32887. return a.charCode - b.charCode;
  32888. });
  32889. for (i = 1; i < mappings.length; i++) {
  32890. if (mappings[i - 1].charCode === mappings[i].charCode) {
  32891. mappings.splice(i, 1);
  32892. i--;
  32893. }
  32894. }
  32895. return {
  32896. platformId: potentialTable.platformId,
  32897. encodingId: potentialTable.encodingId,
  32898. mappings: mappings,
  32899. hasShortCmap: hasShortCmap
  32900. };
  32901. }
  32902. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  32903. if (!header) {
  32904. if (metrics) {
  32905. metrics.data = null;
  32906. }
  32907. return;
  32908. }
  32909. font.pos = (font.start ? font.start : 0) + header.offset;
  32910. font.pos += header.length - 2;
  32911. var numOfMetrics = font.getUint16();
  32912. if (numOfMetrics > numGlyphs) {
  32913. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  32914. 'greater than the numGlyphs (' + numGlyphs + ')');
  32915. // Reduce numOfMetrics if it is greater than numGlyphs
  32916. numOfMetrics = numGlyphs;
  32917. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  32918. header.data[35] = numOfMetrics & 0x00ff;
  32919. }
  32920. var numOfSidebearings = numGlyphs - numOfMetrics;
  32921. var numMissing = numOfSidebearings -
  32922. ((metrics.length - numOfMetrics * 4) >> 1);
  32923. if (numMissing > 0) {
  32924. // For each missing glyph, we set both the width and lsb to 0 (zero).
  32925. // Since we need to add two properties for each glyph, this explains
  32926. // the use of |numMissing * 2| when initializing the typed array.
  32927. var entries = new Uint8Array(metrics.length + numMissing * 2);
  32928. entries.set(metrics.data);
  32929. metrics.data = entries;
  32930. }
  32931. }
  32932. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  32933. hintsValid) {
  32934. if (sourceEnd - sourceStart <= 12) {
  32935. // glyph with data less than 12 is invalid one
  32936. return 0;
  32937. }
  32938. var glyf = source.subarray(sourceStart, sourceEnd);
  32939. var contoursCount = (glyf[0] << 8) | glyf[1];
  32940. if (contoursCount & 0x8000) {
  32941. // complex glyph, writing as is
  32942. dest.set(glyf, destStart);
  32943. return glyf.length;
  32944. }
  32945. var i, j = 10, flagsCount = 0;
  32946. for (i = 0; i < contoursCount; i++) {
  32947. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  32948. flagsCount = endPoint + 1;
  32949. j += 2;
  32950. }
  32951. // skipping instructions
  32952. var instructionsStart = j;
  32953. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  32954. j += 2 + instructionsLength;
  32955. var instructionsEnd = j;
  32956. // validating flags
  32957. var coordinatesLength = 0;
  32958. for (i = 0; i < flagsCount; i++) {
  32959. var flag = glyf[j++];
  32960. if (flag & 0xC0) {
  32961. // reserved flags must be zero, cleaning up
  32962. glyf[j - 1] = flag & 0x3F;
  32963. }
  32964. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  32965. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  32966. coordinatesLength += xyLength;
  32967. if (flag & 8) {
  32968. var repeat = glyf[j++];
  32969. i += repeat;
  32970. coordinatesLength += repeat * xyLength;
  32971. }
  32972. }
  32973. // glyph without coordinates will be rejected
  32974. if (coordinatesLength === 0) {
  32975. return 0;
  32976. }
  32977. var glyphDataLength = j + coordinatesLength;
  32978. if (glyphDataLength > glyf.length) {
  32979. // not enough data for coordinates
  32980. return 0;
  32981. }
  32982. if (!hintsValid && instructionsLength > 0) {
  32983. dest.set(glyf.subarray(0, instructionsStart), destStart);
  32984. dest.set([0, 0], destStart + instructionsStart);
  32985. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  32986. destStart + instructionsStart + 2);
  32987. glyphDataLength -= instructionsLength;
  32988. if (glyf.length - glyphDataLength > 3) {
  32989. glyphDataLength = (glyphDataLength + 3) & ~3;
  32990. }
  32991. return glyphDataLength;
  32992. }
  32993. if (glyf.length - glyphDataLength > 3) {
  32994. // truncating and aligning to 4 bytes the long glyph data
  32995. glyphDataLength = (glyphDataLength + 3) & ~3;
  32996. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  32997. return glyphDataLength;
  32998. }
  32999. // glyph data is fine
  33000. dest.set(glyf, destStart);
  33001. return glyf.length;
  33002. }
  33003. function sanitizeHead(head, numGlyphs, locaLength) {
  33004. var data = head.data;
  33005. // Validate version:
  33006. // Should always be 0x00010000
  33007. var version = int32(data[0], data[1], data[2], data[3]);
  33008. if (version >> 16 !== 1) {
  33009. info('Attempting to fix invalid version in head table: ' + version);
  33010. data[0] = 0;
  33011. data[1] = 1;
  33012. data[2] = 0;
  33013. data[3] = 0;
  33014. }
  33015. var indexToLocFormat = int16(data[50], data[51]);
  33016. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  33017. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  33018. indexToLocFormat);
  33019. // The value of indexToLocFormat should be 0 if the loca table
  33020. // consists of short offsets, and should be 1 if the loca table
  33021. // consists of long offsets.
  33022. //
  33023. // The number of entries in the loca table should be numGlyphs + 1.
  33024. //
  33025. // Using this information, we can work backwards to deduce if the
  33026. // size of each offset in the loca table, and thus figure out the
  33027. // appropriate value for indexToLocFormat.
  33028. var numGlyphsPlusOne = numGlyphs + 1;
  33029. if (locaLength === numGlyphsPlusOne << 1) {
  33030. // 0x0000 indicates the loca table consists of short offsets
  33031. data[50] = 0;
  33032. data[51] = 0;
  33033. } else if (locaLength === numGlyphsPlusOne << 2) {
  33034. // 0x0001 indicates the loca table consists of long offsets
  33035. data[50] = 0;
  33036. data[51] = 1;
  33037. } else {
  33038. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  33039. }
  33040. }
  33041. }
  33042. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  33043. isGlyphLocationsLong, hintsValid,
  33044. dupFirstEntry) {
  33045. var itemSize, itemDecode, itemEncode;
  33046. if (isGlyphLocationsLong) {
  33047. itemSize = 4;
  33048. itemDecode = function fontItemDecodeLong(data, offset) {
  33049. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33050. (data[offset + 2] << 8) | data[offset + 3];
  33051. };
  33052. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33053. data[offset] = (value >>> 24) & 0xFF;
  33054. data[offset + 1] = (value >> 16) & 0xFF;
  33055. data[offset + 2] = (value >> 8) & 0xFF;
  33056. data[offset + 3] = value & 0xFF;
  33057. };
  33058. } else {
  33059. itemSize = 2;
  33060. itemDecode = function fontItemDecode(data, offset) {
  33061. return (data[offset] << 9) | (data[offset + 1] << 1);
  33062. };
  33063. itemEncode = function fontItemEncode(data, offset, value) {
  33064. data[offset] = (value >> 9) & 0xFF;
  33065. data[offset + 1] = (value >> 1) & 0xFF;
  33066. };
  33067. }
  33068. var locaData = loca.data;
  33069. var locaDataSize = itemSize * (1 + numGlyphs);
  33070. // is loca.data too short or long?
  33071. if (locaData.length !== locaDataSize) {
  33072. locaData = new Uint8Array(locaDataSize);
  33073. locaData.set(loca.data.subarray(0, locaDataSize));
  33074. loca.data = locaData;
  33075. }
  33076. // removing the invalid glyphs
  33077. var oldGlyfData = glyf.data;
  33078. var oldGlyfDataLength = oldGlyfData.length;
  33079. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33080. var startOffset = itemDecode(locaData, 0);
  33081. var writeOffset = 0;
  33082. var missingGlyphData = Object.create(null);
  33083. itemEncode(locaData, 0, writeOffset);
  33084. var i, j;
  33085. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33086. var endOffset = itemDecode(locaData, j);
  33087. if (endOffset > oldGlyfDataLength &&
  33088. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33089. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33090. // the glyf table size, which makes last glyph out of range.
  33091. endOffset = oldGlyfDataLength;
  33092. }
  33093. if (endOffset > oldGlyfDataLength) {
  33094. // glyph end offset points outside glyf data, rejecting the glyph
  33095. itemEncode(locaData, j, writeOffset);
  33096. startOffset = endOffset;
  33097. continue;
  33098. }
  33099. if (startOffset === endOffset) {
  33100. missingGlyphData[i] = true;
  33101. }
  33102. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33103. newGlyfData, writeOffset, hintsValid);
  33104. writeOffset += newLength;
  33105. itemEncode(locaData, j, writeOffset);
  33106. startOffset = endOffset;
  33107. }
  33108. if (writeOffset === 0) {
  33109. // glyf table cannot be empty -- redoing the glyf and loca tables
  33110. // to have single glyph with one point
  33111. var simpleGlyph = new Uint8Array(
  33112. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33113. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33114. itemEncode(locaData, j, simpleGlyph.length);
  33115. }
  33116. glyf.data = simpleGlyph;
  33117. return missingGlyphData;
  33118. }
  33119. if (dupFirstEntry) {
  33120. var firstEntryLength = itemDecode(locaData, itemSize);
  33121. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33122. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33123. } else {
  33124. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33125. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33126. }
  33127. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33128. itemEncode(loca.data, locaData.length - itemSize,
  33129. writeOffset + firstEntryLength);
  33130. } else {
  33131. glyf.data = newGlyfData.subarray(0, writeOffset);
  33132. }
  33133. return missingGlyphData;
  33134. }
  33135. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33136. var start = (font.start ? font.start : 0) + post.offset;
  33137. font.pos = start;
  33138. var length = post.length, end = start + length;
  33139. var version = font.getInt32();
  33140. // skip rest to the tables
  33141. font.getBytes(28);
  33142. var glyphNames;
  33143. var valid = true;
  33144. var i;
  33145. switch (version) {
  33146. case 0x00010000:
  33147. glyphNames = MacStandardGlyphOrdering;
  33148. break;
  33149. case 0x00020000:
  33150. var numGlyphs = font.getUint16();
  33151. if (numGlyphs !== maxpNumGlyphs) {
  33152. valid = false;
  33153. break;
  33154. }
  33155. var glyphNameIndexes = [];
  33156. for (i = 0; i < numGlyphs; ++i) {
  33157. var index = font.getUint16();
  33158. if (index >= 32768) {
  33159. valid = false;
  33160. break;
  33161. }
  33162. glyphNameIndexes.push(index);
  33163. }
  33164. if (!valid) {
  33165. break;
  33166. }
  33167. var customNames = [];
  33168. var strBuf = [];
  33169. while (font.pos < end) {
  33170. var stringLength = font.getByte();
  33171. strBuf.length = stringLength;
  33172. for (i = 0; i < stringLength; ++i) {
  33173. strBuf[i] = String.fromCharCode(font.getByte());
  33174. }
  33175. customNames.push(strBuf.join(''));
  33176. }
  33177. glyphNames = [];
  33178. for (i = 0; i < numGlyphs; ++i) {
  33179. var j = glyphNameIndexes[i];
  33180. if (j < 258) {
  33181. glyphNames.push(MacStandardGlyphOrdering[j]);
  33182. continue;
  33183. }
  33184. glyphNames.push(customNames[j - 258]);
  33185. }
  33186. break;
  33187. case 0x00030000:
  33188. break;
  33189. default:
  33190. warn('Unknown/unsupported post table version ' + version);
  33191. valid = false;
  33192. if (properties.defaultEncoding) {
  33193. glyphNames = properties.defaultEncoding;
  33194. }
  33195. break;
  33196. }
  33197. properties.glyphNames = glyphNames;
  33198. return valid;
  33199. }
  33200. function readNameTable(nameTable) {
  33201. var start = (font.start ? font.start : 0) + nameTable.offset;
  33202. font.pos = start;
  33203. var names = [[], []];
  33204. var length = nameTable.length, end = start + length;
  33205. var format = font.getUint16();
  33206. var FORMAT_0_HEADER_LENGTH = 6;
  33207. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33208. // unsupported name table format or table "too" small
  33209. return names;
  33210. }
  33211. var numRecords = font.getUint16();
  33212. var stringsStart = font.getUint16();
  33213. var records = [];
  33214. var NAME_RECORD_LENGTH = 12;
  33215. var i, ii;
  33216. for (i = 0; i < numRecords &&
  33217. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33218. var r = {
  33219. platform: font.getUint16(),
  33220. encoding: font.getUint16(),
  33221. language: font.getUint16(),
  33222. name: font.getUint16(),
  33223. length: font.getUint16(),
  33224. offset: font.getUint16()
  33225. };
  33226. // using only Macintosh and Windows platform/encoding names
  33227. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33228. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33229. records.push(r);
  33230. }
  33231. }
  33232. for (i = 0, ii = records.length; i < ii; i++) {
  33233. var record = records[i];
  33234. var pos = start + stringsStart + record.offset;
  33235. if (pos + record.length > end) {
  33236. continue; // outside of name table, ignoring
  33237. }
  33238. font.pos = pos;
  33239. var nameIndex = record.name;
  33240. if (record.encoding) {
  33241. // unicode
  33242. var str = '';
  33243. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33244. str += String.fromCharCode(font.getUint16());
  33245. }
  33246. names[1][nameIndex] = str;
  33247. } else {
  33248. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33249. }
  33250. }
  33251. return names;
  33252. }
  33253. var TTOpsStackDeltas = [
  33254. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33255. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33256. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33257. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33258. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33259. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33260. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33261. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33262. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33263. // 0xC0-DF == -1 and 0xE0-FF == -2
  33264. function sanitizeTTProgram(table, ttContext) {
  33265. var data = table.data;
  33266. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33267. var stack = [];
  33268. var callstack = [];
  33269. var functionsCalled = [];
  33270. var tooComplexToFollowFunctions =
  33271. ttContext.tooComplexToFollowFunctions;
  33272. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33273. for (var ii = data.length; i < ii;) {
  33274. var op = data[i++];
  33275. // The TrueType instruction set docs can be found at
  33276. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33277. if (op === 0x40) { // NPUSHB - pushes n bytes
  33278. n = data[i++];
  33279. if (inFDEF || inELSE) {
  33280. i += n;
  33281. } else {
  33282. for (j = 0; j < n; j++) {
  33283. stack.push(data[i++]);
  33284. }
  33285. }
  33286. } else if (op === 0x41) { // NPUSHW - pushes n words
  33287. n = data[i++];
  33288. if (inFDEF || inELSE) {
  33289. i += n * 2;
  33290. } else {
  33291. for (j = 0; j < n; j++) {
  33292. b = data[i++];
  33293. stack.push((b << 8) | data[i++]);
  33294. }
  33295. }
  33296. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33297. n = op - 0xB0 + 1;
  33298. if (inFDEF || inELSE) {
  33299. i += n;
  33300. } else {
  33301. for (j = 0; j < n; j++) {
  33302. stack.push(data[i++]);
  33303. }
  33304. }
  33305. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33306. n = op - 0xB8 + 1;
  33307. if (inFDEF || inELSE) {
  33308. i += n * 2;
  33309. } else {
  33310. for (j = 0; j < n; j++) {
  33311. b = data[i++];
  33312. stack.push((b << 8) | data[i++]);
  33313. }
  33314. }
  33315. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33316. if (!inFDEF && !inELSE) {
  33317. // collecting inforamtion about which functions are used
  33318. funcId = stack[stack.length - 1];
  33319. ttContext.functionsUsed[funcId] = true;
  33320. if (funcId in ttContext.functionsStackDeltas) {
  33321. stack.length += ttContext.functionsStackDeltas[funcId];
  33322. } else if (funcId in ttContext.functionsDefined &&
  33323. functionsCalled.indexOf(funcId) < 0) {
  33324. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33325. functionsCalled.push(funcId);
  33326. pc = ttContext.functionsDefined[funcId];
  33327. if (!pc) {
  33328. warn('TT: CALL non-existent function');
  33329. ttContext.hintsValid = false;
  33330. return;
  33331. }
  33332. data = pc.data;
  33333. i = pc.i;
  33334. }
  33335. }
  33336. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33337. if (inFDEF || inELSE) {
  33338. warn('TT: nested FDEFs not allowed');
  33339. tooComplexToFollowFunctions = true;
  33340. }
  33341. inFDEF = true;
  33342. // collecting inforamtion about which functions are defined
  33343. lastDeff = i;
  33344. funcId = stack.pop();
  33345. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33346. } else if (op === 0x2D) { // ENDF - end of function
  33347. if (inFDEF) {
  33348. inFDEF = false;
  33349. lastEndf = i;
  33350. } else {
  33351. pc = callstack.pop();
  33352. if (!pc) {
  33353. warn('TT: ENDF bad stack');
  33354. ttContext.hintsValid = false;
  33355. return;
  33356. }
  33357. funcId = functionsCalled.pop();
  33358. data = pc.data;
  33359. i = pc.i;
  33360. ttContext.functionsStackDeltas[funcId] =
  33361. stack.length - pc.stackTop;
  33362. }
  33363. } else if (op === 0x89) { // IDEF - instruction definition
  33364. if (inFDEF || inELSE) {
  33365. warn('TT: nested IDEFs not allowed');
  33366. tooComplexToFollowFunctions = true;
  33367. }
  33368. inFDEF = true;
  33369. // recording it as a function to track ENDF
  33370. lastDeff = i;
  33371. } else if (op === 0x58) { // IF
  33372. ++ifLevel;
  33373. } else if (op === 0x1B) { // ELSE
  33374. inELSE = ifLevel;
  33375. } else if (op === 0x59) { // EIF
  33376. if (inELSE === ifLevel) {
  33377. inELSE = 0;
  33378. }
  33379. --ifLevel;
  33380. } else if (op === 0x1C) { // JMPR
  33381. if (!inFDEF && !inELSE) {
  33382. var offset = stack[stack.length - 1];
  33383. // only jumping forward to prevent infinite loop
  33384. if (offset > 0) {
  33385. i += offset - 1;
  33386. }
  33387. }
  33388. }
  33389. // Adjusting stack not extactly, but just enough to get function id
  33390. if (!inFDEF && !inELSE) {
  33391. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33392. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33393. if (op >= 0x71 && op <= 0x75) {
  33394. n = stack.pop();
  33395. if (n === n) {
  33396. stackDelta = -n * 2;
  33397. }
  33398. }
  33399. while (stackDelta < 0 && stack.length > 0) {
  33400. stack.pop();
  33401. stackDelta++;
  33402. }
  33403. while (stackDelta > 0) {
  33404. stack.push(NaN); // pushing any number into stack
  33405. stackDelta--;
  33406. }
  33407. }
  33408. }
  33409. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33410. var content = [data];
  33411. if (i > data.length) {
  33412. content.push(new Uint8Array(i - data.length));
  33413. }
  33414. if (lastDeff > lastEndf) {
  33415. warn('TT: complementing a missing function tail');
  33416. // new function definition started, but not finished
  33417. // complete function by [CLEAR, ENDF]
  33418. content.push(new Uint8Array([0x22, 0x2D]));
  33419. }
  33420. foldTTTable(table, content);
  33421. }
  33422. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33423. if (ttContext.tooComplexToFollowFunctions) {
  33424. return;
  33425. }
  33426. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33427. warn('TT: more functions defined than expected');
  33428. ttContext.hintsValid = false;
  33429. return;
  33430. }
  33431. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33432. if (j > maxFunctionDefs) {
  33433. warn('TT: invalid function id: ' + j);
  33434. ttContext.hintsValid = false;
  33435. return;
  33436. }
  33437. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33438. warn('TT: undefined function: ' + j);
  33439. ttContext.hintsValid = false;
  33440. return;
  33441. }
  33442. }
  33443. }
  33444. function foldTTTable(table, content) {
  33445. if (content.length > 1) {
  33446. // concatenating the content items
  33447. var newLength = 0;
  33448. var j, jj;
  33449. for (j = 0, jj = content.length; j < jj; j++) {
  33450. newLength += content[j].length;
  33451. }
  33452. newLength = (newLength + 3) & ~3;
  33453. var result = new Uint8Array(newLength);
  33454. var pos = 0;
  33455. for (j = 0, jj = content.length; j < jj; j++) {
  33456. result.set(content[j], pos);
  33457. pos += content[j].length;
  33458. }
  33459. table.data = result;
  33460. table.length = newLength;
  33461. }
  33462. }
  33463. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33464. var ttContext = {
  33465. functionsDefined: [],
  33466. functionsUsed: [],
  33467. functionsStackDeltas: [],
  33468. tooComplexToFollowFunctions: false,
  33469. hintsValid: true
  33470. };
  33471. if (fpgm) {
  33472. sanitizeTTProgram(fpgm, ttContext);
  33473. }
  33474. if (prep) {
  33475. sanitizeTTProgram(prep, ttContext);
  33476. }
  33477. if (fpgm) {
  33478. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33479. }
  33480. if (cvt && (cvt.length & 1)) {
  33481. var cvtData = new Uint8Array(cvt.length + 1);
  33482. cvtData.set(cvt.data);
  33483. cvt.data = cvtData;
  33484. }
  33485. return ttContext.hintsValid;
  33486. }
  33487. // The following steps modify the original font data, making copy
  33488. font = new Stream(new Uint8Array(font.getBytes()));
  33489. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33490. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33491. var header = readOpenTypeHeader(font);
  33492. var numTables = header.numTables;
  33493. var cff, cffFile;
  33494. var tables = Object.create(null);
  33495. tables['OS/2'] = null;
  33496. tables['cmap'] = null;
  33497. tables['head'] = null;
  33498. tables['hhea'] = null;
  33499. tables['hmtx'] = null;
  33500. tables['maxp'] = null;
  33501. tables['name'] = null;
  33502. tables['post'] = null;
  33503. var table;
  33504. for (var i = 0; i < numTables; i++) {
  33505. table = readTableEntry(font);
  33506. if (VALID_TABLES.indexOf(table.tag) < 0) {
  33507. continue; // skipping table if it's not a required or optional table
  33508. }
  33509. if (table.length === 0) {
  33510. continue; // skipping empty tables
  33511. }
  33512. tables[table.tag] = table;
  33513. }
  33514. var isTrueType = !tables['CFF '];
  33515. if (!isTrueType) {
  33516. // OpenType font
  33517. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  33518. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  33519. !tables['post']) {
  33520. // no major tables: throwing everything at CFFFont
  33521. cffFile = new Stream(tables['CFF '].data);
  33522. cff = new CFFFont(cffFile, properties);
  33523. adjustWidths(properties);
  33524. return this.convert(name, cff, properties);
  33525. }
  33526. delete tables['glyf'];
  33527. delete tables['loca'];
  33528. delete tables['fpgm'];
  33529. delete tables['prep'];
  33530. delete tables['cvt '];
  33531. this.isOpenType = true;
  33532. } else {
  33533. if (!tables['loca']) {
  33534. error('Required "loca" table is not found');
  33535. }
  33536. if (!tables['glyf']) {
  33537. warn('Required "glyf" table is not found -- trying to recover.');
  33538. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  33539. tables['glyf'] = {
  33540. tag: 'glyf',
  33541. data: new Uint8Array(0),
  33542. };
  33543. }
  33544. this.isOpenType = false;
  33545. }
  33546. if (!tables['maxp']) {
  33547. error('Required "maxp" table is not found');
  33548. }
  33549. font.pos = (font.start || 0) + tables['maxp'].offset;
  33550. var version = font.getInt32();
  33551. var numGlyphs = font.getUint16();
  33552. var maxFunctionDefs = 0;
  33553. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  33554. // maxZones can be invalid
  33555. font.pos += 8;
  33556. var maxZones = font.getUint16();
  33557. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  33558. tables['maxp'].data[14] = 0;
  33559. tables['maxp'].data[15] = 2;
  33560. }
  33561. font.pos += 4;
  33562. maxFunctionDefs = font.getUint16();
  33563. }
  33564. var dupFirstEntry = false;
  33565. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  33566. properties.toUnicode.get(0) > '\u0000') {
  33567. // oracle's defect (see 3427), duplicating first entry
  33568. dupFirstEntry = true;
  33569. numGlyphs++;
  33570. tables['maxp'].data[4] = numGlyphs >> 8;
  33571. tables['maxp'].data[5] = numGlyphs & 255;
  33572. }
  33573. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  33574. tables['cvt '], maxFunctionDefs);
  33575. if (!hintsValid) {
  33576. delete tables['fpgm'];
  33577. delete tables['prep'];
  33578. delete tables['cvt '];
  33579. }
  33580. // Ensure the hmtx table contains the advance width and
  33581. // sidebearings information for numGlyphs in the maxp table
  33582. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  33583. if (!tables['head']) {
  33584. error('Required "head" table is not found');
  33585. }
  33586. sanitizeHead(tables['head'], numGlyphs,
  33587. isTrueType ? tables['loca'].length : 0);
  33588. var missingGlyphs = Object.create(null);
  33589. if (isTrueType) {
  33590. var isGlyphLocationsLong = int16(tables['head'].data[50],
  33591. tables['head'].data[51]);
  33592. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  33593. numGlyphs, isGlyphLocationsLong,
  33594. hintsValid, dupFirstEntry);
  33595. }
  33596. if (!tables['hhea']) {
  33597. error('Required "hhea" table is not found');
  33598. }
  33599. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  33600. // Sometimes it's 0. That needs to be fixed
  33601. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  33602. tables['hhea'].data[10] = 0xFF;
  33603. tables['hhea'].data[11] = 0xFF;
  33604. }
  33605. // Extract some more font properties from the OpenType head and
  33606. // hhea tables; yMin and descent value are always negative.
  33607. var metricsOverride = {
  33608. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  33609. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  33610. yMin: int16(tables['head'].data[38], tables['head'].data[39]) - 0x10000,
  33611. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  33612. descent: int16(tables['hhea'].data[6], tables['hhea'].data[7]) - 0x10000
  33613. };
  33614. // PDF FontDescriptor metrics lie -- using data from actual font.
  33615. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  33616. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  33617. // The 'post' table has glyphs names.
  33618. if (tables['post']) {
  33619. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  33620. if (!valid) {
  33621. tables['post'] = null;
  33622. }
  33623. }
  33624. var charCodeToGlyphId = [], charCode;
  33625. var toUnicode = properties.toUnicode, widths = properties.widths;
  33626. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  33627. toUnicode.length === 0x10000);
  33628. // Helper function to try to skip mapping of empty glyphs.
  33629. // Note: In some cases, just relying on the glyph data doesn't work,
  33630. // hence we also use a few heuristics to fix various PDF files.
  33631. function hasGlyph(glyphId, charCode, widthCode) {
  33632. if (!missingGlyphs[glyphId]) {
  33633. return true;
  33634. }
  33635. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  33636. return true;
  33637. }
  33638. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  33639. return true;
  33640. }
  33641. return false;
  33642. }
  33643. if (properties.type === 'CIDFontType2') {
  33644. var cidToGidMap = properties.cidToGidMap || [];
  33645. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  33646. properties.cMap.forEach(function(charCode, cid) {
  33647. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  33648. var glyphId = -1;
  33649. if (isCidToGidMapEmpty) {
  33650. glyphId = charCode;
  33651. } else if (cidToGidMap[cid] !== undefined) {
  33652. glyphId = cidToGidMap[cid];
  33653. }
  33654. if (glyphId >= 0 && glyphId < numGlyphs &&
  33655. hasGlyph(glyphId, charCode, cid)) {
  33656. charCodeToGlyphId[charCode] = glyphId;
  33657. }
  33658. });
  33659. if (dupFirstEntry) {
  33660. charCodeToGlyphId[0] = numGlyphs - 1;
  33661. }
  33662. } else {
  33663. // Most of the following logic in this code branch is based on the
  33664. // 9.6.6.4 of the PDF spec.
  33665. var hasEncoding =
  33666. properties.differences.length > 0 || !!properties.baseEncodingName;
  33667. var cmapTable =
  33668. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  33669. var cmapPlatformId = cmapTable.platformId;
  33670. var cmapEncodingId = cmapTable.encodingId;
  33671. var cmapMappings = cmapTable.mappings;
  33672. var cmapMappingsLength = cmapMappings.length;
  33673. // The spec seems to imply that if the font is symbolic the encoding
  33674. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  33675. // where the the font is symbolic and it has an encoding.
  33676. if (hasEncoding &&
  33677. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  33678. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  33679. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  33680. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  33681. // When no preferred cmap table was found and |baseEncodingName| is
  33682. // one of the predefined encodings, we seem to obtain a better
  33683. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  33684. // TODO: Note that this is a hack which should be removed as soon as
  33685. // we have proper support for more exotic cmap tables.
  33686. var baseEncoding = [];
  33687. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  33688. properties.baseEncodingName === 'WinAnsiEncoding') {
  33689. baseEncoding = getEncoding(properties.baseEncodingName);
  33690. }
  33691. var glyphsUnicodeMap = getGlyphsUnicode();
  33692. for (charCode = 0; charCode < 256; charCode++) {
  33693. var glyphName;
  33694. if (this.differences && charCode in this.differences) {
  33695. glyphName = this.differences[charCode];
  33696. } else if (charCode in baseEncoding &&
  33697. baseEncoding[charCode] !== '') {
  33698. glyphName = baseEncoding[charCode];
  33699. } else {
  33700. glyphName = StandardEncoding[charCode];
  33701. }
  33702. if (!glyphName) {
  33703. continue;
  33704. }
  33705. var unicodeOrCharCode, isUnicode = false;
  33706. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  33707. unicodeOrCharCode = glyphsUnicodeMap[glyphName];
  33708. isUnicode = true;
  33709. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  33710. // TODO: the encoding needs to be updated with mac os table.
  33711. unicodeOrCharCode = MacRomanEncoding.indexOf(glyphName);
  33712. }
  33713. var found = false;
  33714. for (i = 0; i < cmapMappingsLength; ++i) {
  33715. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  33716. continue;
  33717. }
  33718. var code = isUnicode ? charCode : unicodeOrCharCode;
  33719. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  33720. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  33721. found = true;
  33722. break;
  33723. }
  33724. }
  33725. if (!found && properties.glyphNames) {
  33726. // Try to map using the post table.
  33727. var glyphId = properties.glyphNames.indexOf(glyphName);
  33728. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  33729. charCodeToGlyphId[charCode] = glyphId;
  33730. found = true;
  33731. }
  33732. }
  33733. if (!found) {
  33734. charCodeToGlyphId[charCode] = 0; // notdef
  33735. }
  33736. }
  33737. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  33738. // Default Unicode semantics, use the charcodes as is.
  33739. for (i = 0; i < cmapMappingsLength; ++i) {
  33740. charCodeToGlyphId[cmapMappings[i].charCode] =
  33741. cmapMappings[i].glyphId;
  33742. }
  33743. } else {
  33744. // For (3, 0) cmap tables:
  33745. // The charcode key being stored in charCodeToGlyphId is the lower
  33746. // byte of the two-byte charcodes of the cmap table since according to
  33747. // the spec: 'each byte from the string shall be prepended with the
  33748. // high byte of the range [of charcodes in the cmap table], to form
  33749. // a two-byte character, which shall be used to select the
  33750. // associated glyph description from the subtable'.
  33751. //
  33752. // For (1, 0) cmap tables:
  33753. // 'single bytes from the string shall be used to look up the
  33754. // associated glyph descriptions from the subtable'. This means
  33755. // charcodes in the cmap will be single bytes, so no-op since
  33756. // glyph.charCode & 0xFF === glyph.charCode
  33757. for (i = 0; i < cmapMappingsLength; ++i) {
  33758. charCode = cmapMappings[i].charCode & 0xFF;
  33759. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  33760. }
  33761. }
  33762. }
  33763. if (charCodeToGlyphId.length === 0) {
  33764. // defines at least one glyph
  33765. charCodeToGlyphId[0] = 0;
  33766. }
  33767. // Converting glyphs and ids into font's cmap table
  33768. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  33769. this.toFontChar = newMapping.toFontChar;
  33770. tables['cmap'] = {
  33771. tag: 'cmap',
  33772. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  33773. };
  33774. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  33775. tables['OS/2'] = {
  33776. tag: 'OS/2',
  33777. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  33778. metricsOverride)
  33779. };
  33780. }
  33781. // Rewrite the 'post' table if needed
  33782. if (!tables['post']) {
  33783. tables['post'] = {
  33784. tag: 'post',
  33785. data: createPostTable(properties)
  33786. };
  33787. }
  33788. if (!isTrueType) {
  33789. try {
  33790. // Trying to repair CFF file
  33791. cffFile = new Stream(tables['CFF '].data);
  33792. var parser = new CFFParser(cffFile, properties);
  33793. cff = parser.parse();
  33794. var compiler = new CFFCompiler(cff);
  33795. tables['CFF '].data = compiler.compile();
  33796. } catch (e) {
  33797. warn('Failed to compile font ' + properties.loadedName);
  33798. }
  33799. }
  33800. // Re-creating 'name' table
  33801. if (!tables['name']) {
  33802. tables['name'] = {
  33803. tag: 'name',
  33804. data: createNameTable(this.name)
  33805. };
  33806. } else {
  33807. // ... using existing 'name' table as prototype
  33808. var namePrototype = readNameTable(tables['name']);
  33809. tables['name'].data = createNameTable(name, namePrototype);
  33810. }
  33811. var builder = new OpenTypeFileBuilder(header.version);
  33812. for (var tableTag in tables) {
  33813. builder.addTable(tableTag, tables[tableTag].data);
  33814. }
  33815. return builder.toArray();
  33816. },
  33817. convert: function Font_convert(fontName, font, properties) {
  33818. // TODO: Check the charstring widths to determine this.
  33819. properties.fixedPitch = false;
  33820. var mapping = font.getGlyphMapping(properties);
  33821. var newMapping = adjustMapping(mapping, properties);
  33822. this.toFontChar = newMapping.toFontChar;
  33823. var numGlyphs = font.numGlyphs;
  33824. function getCharCodes(charCodeToGlyphId, glyphId) {
  33825. var charCodes = null;
  33826. for (var charCode in charCodeToGlyphId) {
  33827. if (glyphId === charCodeToGlyphId[charCode]) {
  33828. if (!charCodes) {
  33829. charCodes = [];
  33830. }
  33831. charCodes.push(charCode | 0);
  33832. }
  33833. }
  33834. return charCodes;
  33835. }
  33836. function createCharCode(charCodeToGlyphId, glyphId) {
  33837. for (var charCode in charCodeToGlyphId) {
  33838. if (glyphId === charCodeToGlyphId[charCode]) {
  33839. return charCode | 0;
  33840. }
  33841. }
  33842. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  33843. glyphId;
  33844. return newMapping.nextAvailableFontCharCode++;
  33845. }
  33846. var seacs = font.seacs;
  33847. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  33848. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  33849. var charset = font.getCharset();
  33850. var seacMap = Object.create(null);
  33851. for (var glyphId in seacs) {
  33852. glyphId |= 0;
  33853. var seac = seacs[glyphId];
  33854. var baseGlyphName = StandardEncoding[seac[2]];
  33855. var accentGlyphName = StandardEncoding[seac[3]];
  33856. var baseGlyphId = charset.indexOf(baseGlyphName);
  33857. var accentGlyphId = charset.indexOf(accentGlyphName);
  33858. if (baseGlyphId < 0 || accentGlyphId < 0) {
  33859. continue;
  33860. }
  33861. var accentOffset = {
  33862. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  33863. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  33864. };
  33865. var charCodes = getCharCodes(mapping, glyphId);
  33866. if (!charCodes) {
  33867. // There's no point in mapping it if the char code was never mapped
  33868. // to begin with.
  33869. continue;
  33870. }
  33871. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  33872. var charCode = charCodes[i];
  33873. // Find a fontCharCode that maps to the base and accent glyphs.
  33874. // If one doesn't exists, create it.
  33875. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  33876. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  33877. baseGlyphId);
  33878. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  33879. accentGlyphId);
  33880. seacMap[charCode] = {
  33881. baseFontCharCode: baseFontCharCode,
  33882. accentFontCharCode: accentFontCharCode,
  33883. accentOffset: accentOffset
  33884. };
  33885. }
  33886. }
  33887. properties.seacMap = seacMap;
  33888. }
  33889. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  33890. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  33891. // PostScript Font Program
  33892. builder.addTable('CFF ', font.data);
  33893. // OS/2 and Windows Specific metrics
  33894. builder.addTable('OS/2', createOS2Table(properties,
  33895. newMapping.charCodeToGlyphId));
  33896. // Character to glyphs mapping
  33897. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  33898. numGlyphs));
  33899. // Font header
  33900. builder.addTable('head',
  33901. '\x00\x01\x00\x00' + // Version number
  33902. '\x00\x00\x10\x00' + // fontRevision
  33903. '\x00\x00\x00\x00' + // checksumAdjustement
  33904. '\x5F\x0F\x3C\xF5' + // magicNumber
  33905. '\x00\x00' + // Flags
  33906. safeString16(unitsPerEm) + // unitsPerEM
  33907. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  33908. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  33909. '\x00\x00' + // xMin
  33910. safeString16(properties.descent) + // yMin
  33911. '\x0F\xFF' + // xMax
  33912. safeString16(properties.ascent) + // yMax
  33913. string16(properties.italicAngle ? 2 : 0) + // macStyle
  33914. '\x00\x11' + // lowestRecPPEM
  33915. '\x00\x00' + // fontDirectionHint
  33916. '\x00\x00' + // indexToLocFormat
  33917. '\x00\x00'); // glyphDataFormat
  33918. // Horizontal header
  33919. builder.addTable('hhea',
  33920. '\x00\x01\x00\x00' + // Version number
  33921. safeString16(properties.ascent) + // Typographic Ascent
  33922. safeString16(properties.descent) + // Typographic Descent
  33923. '\x00\x00' + // Line Gap
  33924. '\xFF\xFF' + // advanceWidthMax
  33925. '\x00\x00' + // minLeftSidebearing
  33926. '\x00\x00' + // minRightSidebearing
  33927. '\x00\x00' + // xMaxExtent
  33928. safeString16(properties.capHeight) + // caretSlopeRise
  33929. safeString16(Math.tan(properties.italicAngle) *
  33930. properties.xHeight) + // caretSlopeRun
  33931. '\x00\x00' + // caretOffset
  33932. '\x00\x00' + // -reserved-
  33933. '\x00\x00' + // -reserved-
  33934. '\x00\x00' + // -reserved-
  33935. '\x00\x00' + // -reserved-
  33936. '\x00\x00' + // metricDataFormat
  33937. string16(numGlyphs)); // Number of HMetrics
  33938. // Horizontal metrics
  33939. builder.addTable('hmtx', (function fontFieldsHmtx() {
  33940. var charstrings = font.charstrings;
  33941. var cffWidths = font.cff ? font.cff.widths : null;
  33942. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  33943. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  33944. var width = 0;
  33945. if (charstrings) {
  33946. var charstring = charstrings[i - 1];
  33947. width = 'width' in charstring ? charstring.width : 0;
  33948. } else if (cffWidths) {
  33949. width = Math.ceil(cffWidths[i] || 0);
  33950. }
  33951. hmtx += string16(width) + string16(0);
  33952. }
  33953. return hmtx;
  33954. })());
  33955. // Maximum profile
  33956. builder.addTable('maxp',
  33957. '\x00\x00\x50\x00' + // Version number
  33958. string16(numGlyphs)); // Num of glyphs
  33959. // Naming tables
  33960. builder.addTable('name', createNameTable(fontName));
  33961. // PostScript informations
  33962. builder.addTable('post', createPostTable(properties));
  33963. return builder.toArray();
  33964. },
  33965. /**
  33966. * Builds a char code to unicode map based on section 9.10 of the spec.
  33967. * @param {Object} properties Font properties object.
  33968. * @return {Object} A ToUnicodeMap object.
  33969. */
  33970. buildToUnicode: function Font_buildToUnicode(properties) {
  33971. // Section 9.10.2 Mapping Character Codes to Unicode Values
  33972. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  33973. return properties.toUnicode;
  33974. }
  33975. // According to the spec if the font is a simple font we should only map
  33976. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  33977. // the differences array only contains adobe standard or symbol set names,
  33978. // in pratice it seems better to always try to create a toUnicode
  33979. // map based of the default encoding.
  33980. var toUnicode, charcode;
  33981. if (!properties.composite /* is simple font */) {
  33982. toUnicode = [];
  33983. var encoding = properties.defaultEncoding.slice();
  33984. var baseEncodingName = properties.baseEncodingName;
  33985. // Merge in the differences array.
  33986. var differences = properties.differences;
  33987. for (charcode in differences) {
  33988. encoding[charcode] = differences[charcode];
  33989. }
  33990. var glyphsUnicodeMap = getGlyphsUnicode();
  33991. for (charcode in encoding) {
  33992. // a) Map the character code to a character name.
  33993. var glyphName = encoding[charcode];
  33994. // b) Look up the character name in the Adobe Glyph List (see the
  33995. // Bibliography) to obtain the corresponding Unicode value.
  33996. if (glyphName === '') {
  33997. continue;
  33998. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  33999. // (undocumented) c) Few heuristics to recognize unknown glyphs
  34000. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  34001. var code = 0;
  34002. switch (glyphName[0]) {
  34003. case 'G': // Gxx glyph
  34004. if (glyphName.length === 3) {
  34005. code = parseInt(glyphName.substr(1), 16);
  34006. }
  34007. break;
  34008. case 'g': // g00xx glyph
  34009. if (glyphName.length === 5) {
  34010. code = parseInt(glyphName.substr(1), 16);
  34011. }
  34012. break;
  34013. case 'C': // Cddd glyph
  34014. case 'c': // cddd glyph
  34015. if (glyphName.length >= 3) {
  34016. code = +glyphName.substr(1);
  34017. }
  34018. break;
  34019. }
  34020. if (code) {
  34021. // If |baseEncodingName| is one the predefined encodings,
  34022. // and |code| equals |charcode|, using the glyph defined in the
  34023. // baseEncoding seems to yield a better |toUnicode| mapping
  34024. // (fixes issue 5070).
  34025. if (baseEncodingName && code === +charcode) {
  34026. var baseEncoding = getEncoding(baseEncodingName);
  34027. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  34028. toUnicode[charcode] =
  34029. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  34030. continue;
  34031. }
  34032. }
  34033. toUnicode[charcode] = String.fromCharCode(code);
  34034. }
  34035. continue;
  34036. }
  34037. toUnicode[charcode] =
  34038. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  34039. }
  34040. return new ToUnicodeMap(toUnicode);
  34041. }
  34042. // If the font is a composite font that uses one of the predefined CMaps
  34043. // listed in Table 118 (except Identity–H and Identity–V) or whose
  34044. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  34045. // Adobe-Korea1 character collection:
  34046. if (properties.composite && (
  34047. (properties.cMap.builtInCMap &&
  34048. !(properties.cMap instanceof IdentityCMap)) ||
  34049. (properties.cidSystemInfo.registry === 'Adobe' &&
  34050. (properties.cidSystemInfo.ordering === 'GB1' ||
  34051. properties.cidSystemInfo.ordering === 'CNS1' ||
  34052. properties.cidSystemInfo.ordering === 'Japan1' ||
  34053. properties.cidSystemInfo.ordering === 'Korea1')))) {
  34054. // Then:
  34055. // a) Map the character code to a character identifier (CID) according
  34056. // to the font’s CMap.
  34057. // b) Obtain the registry and ordering of the character collection used
  34058. // by the font’s CMap (for example, Adobe and Japan1) from its
  34059. // CIDSystemInfo dictionary.
  34060. var registry = properties.cidSystemInfo.registry;
  34061. var ordering = properties.cidSystemInfo.ordering;
  34062. // c) Construct a second CMap name by concatenating the registry and
  34063. // ordering obtained in step (b) in the format registry–ordering–UCS2
  34064. // (for example, Adobe–Japan1–UCS2).
  34065. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  34066. // d) Obtain the CMap with the name constructed in step (c) (available
  34067. // from the ASN Web site; see the Bibliography).
  34068. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  34069. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  34070. var cMap = properties.cMap;
  34071. toUnicode = [];
  34072. cMap.forEach(function(charcode, cid) {
  34073. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34074. // e) Map the CID obtained in step (a) according to the CMap obtained
  34075. // in step (d), producing a Unicode value.
  34076. var ucs2 = ucs2CMap.lookup(cid);
  34077. if (ucs2) {
  34078. toUnicode[charcode] =
  34079. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  34080. ucs2.charCodeAt(1));
  34081. }
  34082. });
  34083. return new ToUnicodeMap(toUnicode);
  34084. }
  34085. // The viewer's choice, just use an identity map.
  34086. return new IdentityToUnicodeMap(properties.firstChar,
  34087. properties.lastChar);
  34088. },
  34089. get spaceWidth() {
  34090. if ('_shadowWidth' in this) {
  34091. return this._shadowWidth;
  34092. }
  34093. // trying to estimate space character width
  34094. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34095. var width;
  34096. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34097. var glyphName = possibleSpaceReplacements[i];
  34098. // if possible, getting width by glyph name
  34099. if (glyphName in this.widths) {
  34100. width = this.widths[glyphName];
  34101. break;
  34102. }
  34103. var glyphsUnicodeMap = getGlyphsUnicode();
  34104. var glyphUnicode = glyphsUnicodeMap[glyphName];
  34105. // finding the charcode via unicodeToCID map
  34106. var charcode = 0;
  34107. if (this.composite) {
  34108. if (this.cMap.contains(glyphUnicode)) {
  34109. charcode = this.cMap.lookup(glyphUnicode);
  34110. }
  34111. }
  34112. // ... via toUnicode map
  34113. if (!charcode && this.toUnicode) {
  34114. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34115. }
  34116. // setting it to unicode if negative or undefined
  34117. if (charcode <= 0) {
  34118. charcode = glyphUnicode;
  34119. }
  34120. // trying to get width via charcode
  34121. width = this.widths[charcode];
  34122. if (width) {
  34123. break; // the non-zero width found
  34124. }
  34125. }
  34126. width = width || this.defaultWidth;
  34127. // Do not shadow the property here. See discussion:
  34128. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34129. this._shadowWidth = width;
  34130. return width;
  34131. },
  34132. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34133. var fontCharCode, width, operatorListId;
  34134. var widthCode = charcode;
  34135. if (this.cMap && this.cMap.contains(charcode)) {
  34136. widthCode = this.cMap.lookup(charcode);
  34137. }
  34138. width = this.widths[widthCode];
  34139. width = isNum(width) ? width : this.defaultWidth;
  34140. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34141. var unicode = this.toUnicode.get(charcode) || charcode;
  34142. if (typeof unicode === 'number') {
  34143. unicode = String.fromCharCode(unicode);
  34144. }
  34145. // First try the toFontChar map, if it's not there then try falling
  34146. // back to the char code.
  34147. fontCharCode = this.toFontChar[charcode] || charcode;
  34148. if (this.missingFile) {
  34149. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34150. }
  34151. if (this.isType3Font) {
  34152. // Font char code in this case is actually a glyph name.
  34153. operatorListId = fontCharCode;
  34154. }
  34155. var accent = null;
  34156. if (this.seacMap && this.seacMap[charcode]) {
  34157. var seac = this.seacMap[charcode];
  34158. fontCharCode = seac.baseFontCharCode;
  34159. accent = {
  34160. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34161. offset: seac.accentOffset
  34162. };
  34163. }
  34164. var fontChar = String.fromCharCode(fontCharCode);
  34165. var glyph = this.glyphCache[charcode];
  34166. if (!glyph ||
  34167. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34168. operatorListId, isSpace)) {
  34169. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34170. operatorListId, isSpace);
  34171. this.glyphCache[charcode] = glyph;
  34172. }
  34173. return glyph;
  34174. },
  34175. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34176. var charsCache = this.charsCache;
  34177. var glyphs, glyph, charcode;
  34178. // if we translated this string before, just grab it from the cache
  34179. if (charsCache) {
  34180. glyphs = charsCache[chars];
  34181. if (glyphs) {
  34182. return glyphs;
  34183. }
  34184. }
  34185. // lazily create the translation cache
  34186. if (!charsCache) {
  34187. charsCache = this.charsCache = Object.create(null);
  34188. }
  34189. glyphs = [];
  34190. var charsCacheKey = chars;
  34191. var i = 0, ii;
  34192. if (this.cMap) {
  34193. // composite fonts have multi-byte strings convert the string from
  34194. // single-byte to multi-byte
  34195. var c = Object.create(null);
  34196. while (i < chars.length) {
  34197. this.cMap.readCharCode(chars, i, c);
  34198. charcode = c.charcode;
  34199. var length = c.length;
  34200. i += length;
  34201. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34202. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34203. glyph = this.charToGlyph(charcode, isSpace);
  34204. glyphs.push(glyph);
  34205. }
  34206. } else {
  34207. for (i = 0, ii = chars.length; i < ii; ++i) {
  34208. charcode = chars.charCodeAt(i);
  34209. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34210. glyphs.push(glyph);
  34211. }
  34212. }
  34213. // Enter the translated string into the cache
  34214. return (charsCache[charsCacheKey] = glyphs);
  34215. }
  34216. };
  34217. return Font;
  34218. })();
  34219. var ErrorFont = (function ErrorFontClosure() {
  34220. function ErrorFont(error) {
  34221. this.error = error;
  34222. this.loadedName = 'g_font_error';
  34223. this.loading = false;
  34224. }
  34225. ErrorFont.prototype = {
  34226. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34227. return [];
  34228. },
  34229. exportData: function ErrorFont_exportData() {
  34230. return {error: this.error};
  34231. }
  34232. };
  34233. return ErrorFont;
  34234. })();
  34235. /**
  34236. * Shared logic for building a char code to glyph id mapping for Type1 and
  34237. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34238. * @param {Object} properties Font properties object.
  34239. * @param {Object} builtInEncoding The encoding contained within the actual font
  34240. * data.
  34241. * @param {Array} Array of glyph names where the index is the glyph ID.
  34242. * @returns {Object} A char code to glyph ID map.
  34243. */
  34244. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34245. var charCodeToGlyphId = Object.create(null);
  34246. var glyphId, charCode, baseEncoding;
  34247. if (properties.baseEncodingName) {
  34248. // If a valid base encoding name was used, the mapping is initialized with
  34249. // that.
  34250. baseEncoding = getEncoding(properties.baseEncodingName);
  34251. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34252. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34253. if (glyphId >= 0) {
  34254. charCodeToGlyphId[charCode] = glyphId;
  34255. } else {
  34256. charCodeToGlyphId[charCode] = 0; // notdef
  34257. }
  34258. }
  34259. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34260. // For a symbolic font the encoding should be the fonts built-in
  34261. // encoding.
  34262. for (charCode in builtInEncoding) {
  34263. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34264. }
  34265. } else {
  34266. // For non-symbolic fonts that don't have a base encoding the standard
  34267. // encoding should be used.
  34268. baseEncoding = StandardEncoding;
  34269. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34270. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34271. if (glyphId >= 0) {
  34272. charCodeToGlyphId[charCode] = glyphId;
  34273. } else {
  34274. charCodeToGlyphId[charCode] = 0; // notdef
  34275. }
  34276. }
  34277. }
  34278. // Lastly, merge in the differences.
  34279. var differences = properties.differences;
  34280. if (differences) {
  34281. for (charCode in differences) {
  34282. var glyphName = differences[charCode];
  34283. glyphId = glyphNames.indexOf(glyphName);
  34284. if (glyphId >= 0) {
  34285. charCodeToGlyphId[charCode] = glyphId;
  34286. } else {
  34287. charCodeToGlyphId[charCode] = 0; // notdef
  34288. }
  34289. }
  34290. }
  34291. return charCodeToGlyphId;
  34292. }
  34293. /*
  34294. * CharStrings are encoded following the the CharString Encoding sequence
  34295. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  34296. * The value in a byte indicates a command, a number, or subsequent bytes
  34297. * that are to be interpreted in a special way.
  34298. *
  34299. * CharString Number Encoding:
  34300. * A CharString byte containing the values from 32 through 255 inclusive
  34301. * indicate an integer. These values are decoded in four ranges.
  34302. *
  34303. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  34304. * indicate the integer v - 139. Thus, the integer values from -107 through
  34305. * 107 inclusive may be encoded in single byte.
  34306. *
  34307. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  34308. * indicates an integer involving the next byte, w, according to the formula:
  34309. * [(v - 247) x 256] + w + 108
  34310. *
  34311. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  34312. * indicates an integer involving the next byte, w, according to the formula:
  34313. * -[(v - 251) * 256] - w - 108
  34314. *
  34315. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  34316. * are a two complement signed integer. The first of these bytes contains the
  34317. * highest order bits, the second byte contains the next higher order bits
  34318. * and the fourth byte contain the lowest order bits.
  34319. *
  34320. *
  34321. * CharString Command Encoding:
  34322. * CharStrings commands are encoded in 1 or 2 bytes.
  34323. *
  34324. * Single byte commands are encoded in 1 byte that contains a value between
  34325. * 0 and 31 inclusive.
  34326. * If a command byte contains the value 12, then the value in the next byte
  34327. * indicates a command. This "escape" mechanism allows many extra commands
  34328. * to be encoded and this encoding technique helps to minimize the length of
  34329. * the charStrings.
  34330. */
  34331. var Type1CharString = (function Type1CharStringClosure() {
  34332. var COMMAND_MAP = {
  34333. 'hstem': [1],
  34334. 'vstem': [3],
  34335. 'vmoveto': [4],
  34336. 'rlineto': [5],
  34337. 'hlineto': [6],
  34338. 'vlineto': [7],
  34339. 'rrcurveto': [8],
  34340. 'callsubr': [10],
  34341. 'flex': [12, 35],
  34342. 'drop' : [12, 18],
  34343. 'endchar': [14],
  34344. 'rmoveto': [21],
  34345. 'hmoveto': [22],
  34346. 'vhcurveto': [30],
  34347. 'hvcurveto': [31]
  34348. };
  34349. function Type1CharString() {
  34350. this.width = 0;
  34351. this.lsb = 0;
  34352. this.flexing = false;
  34353. this.output = [];
  34354. this.stack = [];
  34355. }
  34356. Type1CharString.prototype = {
  34357. convert: function Type1CharString_convert(encoded, subrs) {
  34358. var count = encoded.length;
  34359. var error = false;
  34360. var wx, sbx, subrNumber;
  34361. for (var i = 0; i < count; i++) {
  34362. var value = encoded[i];
  34363. if (value < 32) {
  34364. if (value === 12) {
  34365. value = (value << 8) + encoded[++i];
  34366. }
  34367. switch (value) {
  34368. case 1: // hstem
  34369. if (!HINTING_ENABLED) {
  34370. this.stack = [];
  34371. break;
  34372. }
  34373. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34374. break;
  34375. case 3: // vstem
  34376. if (!HINTING_ENABLED) {
  34377. this.stack = [];
  34378. break;
  34379. }
  34380. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34381. break;
  34382. case 4: // vmoveto
  34383. if (this.flexing) {
  34384. if (this.stack.length < 1) {
  34385. error = true;
  34386. break;
  34387. }
  34388. // Add the dx for flex and but also swap the values so they are
  34389. // the right order.
  34390. var dy = this.stack.pop();
  34391. this.stack.push(0, dy);
  34392. break;
  34393. }
  34394. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  34395. break;
  34396. case 5: // rlineto
  34397. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  34398. break;
  34399. case 6: // hlineto
  34400. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  34401. break;
  34402. case 7: // vlineto
  34403. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  34404. break;
  34405. case 8: // rrcurveto
  34406. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  34407. break;
  34408. case 9: // closepath
  34409. // closepath is a Type1 command that does not take argument and is
  34410. // useless in Type2 and it can simply be ignored.
  34411. this.stack = [];
  34412. break;
  34413. case 10: // callsubr
  34414. if (this.stack.length < 1) {
  34415. error = true;
  34416. break;
  34417. }
  34418. subrNumber = this.stack.pop();
  34419. error = this.convert(subrs[subrNumber], subrs);
  34420. break;
  34421. case 11: // return
  34422. return error;
  34423. case 13: // hsbw
  34424. if (this.stack.length < 2) {
  34425. error = true;
  34426. break;
  34427. }
  34428. // To convert to type2 we have to move the width value to the
  34429. // first part of the charstring and then use hmoveto with lsb.
  34430. wx = this.stack.pop();
  34431. sbx = this.stack.pop();
  34432. this.lsb = sbx;
  34433. this.width = wx;
  34434. this.stack.push(wx, sbx);
  34435. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  34436. break;
  34437. case 14: // endchar
  34438. this.output.push(COMMAND_MAP.endchar[0]);
  34439. break;
  34440. case 21: // rmoveto
  34441. if (this.flexing) {
  34442. break;
  34443. }
  34444. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  34445. break;
  34446. case 22: // hmoveto
  34447. if (this.flexing) {
  34448. // Add the dy for flex.
  34449. this.stack.push(0);
  34450. break;
  34451. }
  34452. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  34453. break;
  34454. case 30: // vhcurveto
  34455. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  34456. break;
  34457. case 31: // hvcurveto
  34458. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  34459. break;
  34460. case (12 << 8) + 0: // dotsection
  34461. // dotsection is a Type1 command to specify some hinting feature
  34462. // for dots that do not take a parameter and it can safely be
  34463. // ignored for Type2.
  34464. this.stack = [];
  34465. break;
  34466. case (12 << 8) + 1: // vstem3
  34467. if (!HINTING_ENABLED) {
  34468. this.stack = [];
  34469. break;
  34470. }
  34471. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  34472. // multiple parameters, so instead of returning [vh]stem3 take a
  34473. // shortcut and return [vhstem] instead.
  34474. error = this.executeCommand(2, COMMAND_MAP.vstem);
  34475. break;
  34476. case (12 << 8) + 2: // hstem3
  34477. if (!HINTING_ENABLED) {
  34478. this.stack = [];
  34479. break;
  34480. }
  34481. // See vstem3.
  34482. error = this.executeCommand(2, COMMAND_MAP.hstem);
  34483. break;
  34484. case (12 << 8) + 6: // seac
  34485. // seac is like type 2's special endchar but it doesn't use the
  34486. // first argument asb, so remove it.
  34487. if (SEAC_ANALYSIS_ENABLED) {
  34488. this.seac = this.stack.splice(-4, 4);
  34489. error = this.executeCommand(0, COMMAND_MAP.endchar);
  34490. } else {
  34491. error = this.executeCommand(4, COMMAND_MAP.endchar);
  34492. }
  34493. break;
  34494. case (12 << 8) + 7: // sbw
  34495. if (this.stack.length < 4) {
  34496. error = true;
  34497. break;
  34498. }
  34499. // To convert to type2 we have to move the width value to the
  34500. // first part of the charstring and then use rmoveto with
  34501. // (dx, dy). The height argument will not be used for vmtx and
  34502. // vhea tables reconstruction -- ignoring it.
  34503. var wy = this.stack.pop();
  34504. wx = this.stack.pop();
  34505. var sby = this.stack.pop();
  34506. sbx = this.stack.pop();
  34507. this.lsb = sbx;
  34508. this.width = wx;
  34509. this.stack.push(wx, sbx, sby);
  34510. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  34511. break;
  34512. case (12 << 8) + 12: // div
  34513. if (this.stack.length < 2) {
  34514. error = true;
  34515. break;
  34516. }
  34517. var num2 = this.stack.pop();
  34518. var num1 = this.stack.pop();
  34519. this.stack.push(num1 / num2);
  34520. break;
  34521. case (12 << 8) + 16: // callothersubr
  34522. if (this.stack.length < 2) {
  34523. error = true;
  34524. break;
  34525. }
  34526. subrNumber = this.stack.pop();
  34527. var numArgs = this.stack.pop();
  34528. if (subrNumber === 0 && numArgs === 3) {
  34529. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  34530. this.stack.push(
  34531. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  34532. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  34533. flexArgs[4], // bcp2x
  34534. flexArgs[5], // bcp2y
  34535. flexArgs[6], // p2x
  34536. flexArgs[7], // p2y
  34537. flexArgs[8], // bcp3x
  34538. flexArgs[9], // bcp3y
  34539. flexArgs[10], // bcp4x
  34540. flexArgs[11], // bcp4y
  34541. flexArgs[12], // p3x
  34542. flexArgs[13], // p3y
  34543. flexArgs[14] // flexDepth
  34544. // 15 = finalx unused by flex
  34545. // 16 = finaly unused by flex
  34546. );
  34547. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  34548. this.flexing = false;
  34549. this.stack.push(flexArgs[15], flexArgs[16]);
  34550. } else if (subrNumber === 1 && numArgs === 0) {
  34551. this.flexing = true;
  34552. }
  34553. break;
  34554. case (12 << 8) + 17: // pop
  34555. // Ignore this since it is only used with othersubr.
  34556. break;
  34557. case (12 << 8) + 33: // setcurrentpoint
  34558. // Ignore for now.
  34559. this.stack = [];
  34560. break;
  34561. default:
  34562. warn('Unknown type 1 charstring command of "' + value + '"');
  34563. break;
  34564. }
  34565. if (error) {
  34566. break;
  34567. }
  34568. continue;
  34569. } else if (value <= 246) {
  34570. value = value - 139;
  34571. } else if (value <= 250) {
  34572. value = ((value - 247) * 256) + encoded[++i] + 108;
  34573. } else if (value <= 254) {
  34574. value = -((value - 251) * 256) - encoded[++i] - 108;
  34575. } else {
  34576. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  34577. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  34578. }
  34579. this.stack.push(value);
  34580. }
  34581. return error;
  34582. },
  34583. executeCommand: function(howManyArgs, command, keepStack) {
  34584. var stackLength = this.stack.length;
  34585. if (howManyArgs > stackLength) {
  34586. return true;
  34587. }
  34588. var start = stackLength - howManyArgs;
  34589. for (var i = start; i < stackLength; i++) {
  34590. var value = this.stack[i];
  34591. if (value === (value | 0)) { // int
  34592. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  34593. } else { // fixed point
  34594. value = (65536 * value) | 0;
  34595. this.output.push(255,
  34596. (value >> 24) & 0xFF,
  34597. (value >> 16) & 0xFF,
  34598. (value >> 8) & 0xFF,
  34599. value & 0xFF);
  34600. }
  34601. }
  34602. this.output.push.apply(this.output, command);
  34603. if (keepStack) {
  34604. this.stack.splice(start, howManyArgs);
  34605. } else {
  34606. this.stack.length = 0;
  34607. }
  34608. return false;
  34609. }
  34610. };
  34611. return Type1CharString;
  34612. })();
  34613. /*
  34614. * Type1Parser encapsulate the needed code for parsing a Type1 font
  34615. * program. Some of its logic depends on the Type2 charstrings
  34616. * structure.
  34617. * Note: this doesn't really parse the font since that would require evaluation
  34618. * of PostScript, but it is possible in most cases to extract what we need
  34619. * without a full parse.
  34620. */
  34621. var Type1Parser = (function Type1ParserClosure() {
  34622. /*
  34623. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  34624. * of Plaintext Bytes. The function took a key as a parameter which can be
  34625. * for decrypting the eexec block of for decoding charStrings.
  34626. */
  34627. var EEXEC_ENCRYPT_KEY = 55665;
  34628. var CHAR_STRS_ENCRYPT_KEY = 4330;
  34629. function isHexDigit(code) {
  34630. return code >= 48 && code <= 57 || // '0'-'9'
  34631. code >= 65 && code <= 70 || // 'A'-'F'
  34632. code >= 97 && code <= 102; // 'a'-'f'
  34633. }
  34634. function decrypt(data, key, discardNumber) {
  34635. if (discardNumber >= data.length) {
  34636. return new Uint8Array(0);
  34637. }
  34638. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  34639. for (i = 0; i < discardNumber; i++) {
  34640. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  34641. }
  34642. var count = data.length - discardNumber;
  34643. var decrypted = new Uint8Array(count);
  34644. for (i = discardNumber, j = 0; j < count; i++, j++) {
  34645. var value = data[i];
  34646. decrypted[j] = value ^ (r >> 8);
  34647. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34648. }
  34649. return decrypted;
  34650. }
  34651. function decryptAscii(data, key, discardNumber) {
  34652. var r = key | 0, c1 = 52845, c2 = 22719;
  34653. var count = data.length, maybeLength = count >>> 1;
  34654. var decrypted = new Uint8Array(maybeLength);
  34655. var i, j;
  34656. for (i = 0, j = 0; i < count; i++) {
  34657. var digit1 = data[i];
  34658. if (!isHexDigit(digit1)) {
  34659. continue;
  34660. }
  34661. i++;
  34662. var digit2;
  34663. while (i < count && !isHexDigit(digit2 = data[i])) {
  34664. i++;
  34665. }
  34666. if (i < count) {
  34667. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  34668. decrypted[j++] = value ^ (r >> 8);
  34669. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  34670. }
  34671. }
  34672. return Array.prototype.slice.call(decrypted, discardNumber, j);
  34673. }
  34674. function isSpecial(c) {
  34675. return c === 0x2F || // '/'
  34676. c === 0x5B || c === 0x5D || // '[', ']'
  34677. c === 0x7B || c === 0x7D || // '{', '}'
  34678. c === 0x28 || c === 0x29; // '(', ')'
  34679. }
  34680. function Type1Parser(stream, encrypted) {
  34681. if (encrypted) {
  34682. var data = stream.getBytes();
  34683. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  34684. isHexDigit(data[2]) && isHexDigit(data[3]));
  34685. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  34686. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  34687. }
  34688. this.stream = stream;
  34689. this.nextChar();
  34690. }
  34691. Type1Parser.prototype = {
  34692. readNumberArray: function Type1Parser_readNumberArray() {
  34693. this.getToken(); // read '[' or '{' (arrays can start with either)
  34694. var array = [];
  34695. while (true) {
  34696. var token = this.getToken();
  34697. if (token === null || token === ']' || token === '}') {
  34698. break;
  34699. }
  34700. array.push(parseFloat(token || 0));
  34701. }
  34702. return array;
  34703. },
  34704. readNumber: function Type1Parser_readNumber() {
  34705. var token = this.getToken();
  34706. return parseFloat(token || 0);
  34707. },
  34708. readInt: function Type1Parser_readInt() {
  34709. // Use '| 0' to prevent setting a double into length such as the double
  34710. // does not flow into the loop variable.
  34711. var token = this.getToken();
  34712. return parseInt(token || 0, 10) | 0;
  34713. },
  34714. readBoolean: function Type1Parser_readBoolean() {
  34715. var token = this.getToken();
  34716. // Use 1 and 0 since that's what type2 charstrings use.
  34717. return token === 'true' ? 1 : 0;
  34718. },
  34719. nextChar : function Type1_nextChar() {
  34720. return (this.currentChar = this.stream.getByte());
  34721. },
  34722. getToken: function Type1Parser_getToken() {
  34723. // Eat whitespace and comments.
  34724. var comment = false;
  34725. var ch = this.currentChar;
  34726. while (true) {
  34727. if (ch === -1) {
  34728. return null;
  34729. }
  34730. if (comment) {
  34731. if (ch === 0x0A || ch === 0x0D) {
  34732. comment = false;
  34733. }
  34734. } else if (ch === 0x25) { // '%'
  34735. comment = true;
  34736. } else if (!Lexer.isSpace(ch)) {
  34737. break;
  34738. }
  34739. ch = this.nextChar();
  34740. }
  34741. if (isSpecial(ch)) {
  34742. this.nextChar();
  34743. return String.fromCharCode(ch);
  34744. }
  34745. var token = '';
  34746. do {
  34747. token += String.fromCharCode(ch);
  34748. ch = this.nextChar();
  34749. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  34750. return token;
  34751. },
  34752. /*
  34753. * Returns an object containing a Subrs array and a CharStrings
  34754. * array extracted from and eexec encrypted block of data
  34755. */
  34756. extractFontProgram: function Type1Parser_extractFontProgram() {
  34757. var stream = this.stream;
  34758. var subrs = [], charstrings = [];
  34759. var privateData = Object.create(null);
  34760. privateData['lenIV'] = 4;
  34761. var program = {
  34762. subrs: [],
  34763. charstrings: [],
  34764. properties: {
  34765. 'privateData': privateData
  34766. }
  34767. };
  34768. var token, length, data, lenIV, encoded;
  34769. while ((token = this.getToken()) !== null) {
  34770. if (token !== '/') {
  34771. continue;
  34772. }
  34773. token = this.getToken();
  34774. switch (token) {
  34775. case 'CharStrings':
  34776. // The number immediately following CharStrings must be greater or
  34777. // equal to the number of CharStrings.
  34778. this.getToken();
  34779. this.getToken(); // read in 'dict'
  34780. this.getToken(); // read in 'dup'
  34781. this.getToken(); // read in 'begin'
  34782. while(true) {
  34783. token = this.getToken();
  34784. if (token === null || token === 'end') {
  34785. break;
  34786. }
  34787. if (token !== '/') {
  34788. continue;
  34789. }
  34790. var glyph = this.getToken();
  34791. length = this.readInt();
  34792. this.getToken(); // read in 'RD' or '-|'
  34793. data = stream.makeSubStream(stream.pos, length);
  34794. lenIV = program.properties.privateData['lenIV'];
  34795. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  34796. // Skip past the required space and binary data.
  34797. stream.skip(length);
  34798. this.nextChar();
  34799. token = this.getToken(); // read in 'ND' or '|-'
  34800. if (token === 'noaccess') {
  34801. this.getToken(); // read in 'def'
  34802. }
  34803. charstrings.push({
  34804. glyph: glyph,
  34805. encoded: encoded
  34806. });
  34807. }
  34808. break;
  34809. case 'Subrs':
  34810. var num = this.readInt();
  34811. this.getToken(); // read in 'array'
  34812. while ((token = this.getToken()) === 'dup') {
  34813. var index = this.readInt();
  34814. length = this.readInt();
  34815. this.getToken(); // read in 'RD' or '-|'
  34816. data = stream.makeSubStream(stream.pos, length);
  34817. lenIV = program.properties.privateData['lenIV'];
  34818. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  34819. // Skip past the required space and binary data.
  34820. stream.skip(length);
  34821. this.nextChar();
  34822. token = this.getToken(); // read in 'NP' or '|'
  34823. if (token === 'noaccess') {
  34824. this.getToken(); // read in 'put'
  34825. }
  34826. subrs[index] = encoded;
  34827. }
  34828. break;
  34829. case 'BlueValues':
  34830. case 'OtherBlues':
  34831. case 'FamilyBlues':
  34832. case 'FamilyOtherBlues':
  34833. var blueArray = this.readNumberArray();
  34834. // *Blue* values may contain invalid data: disables reading of
  34835. // those values when hinting is disabled.
  34836. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  34837. HINTING_ENABLED) {
  34838. program.properties.privateData[token] = blueArray;
  34839. }
  34840. break;
  34841. case 'StemSnapH':
  34842. case 'StemSnapV':
  34843. program.properties.privateData[token] = this.readNumberArray();
  34844. break;
  34845. case 'StdHW':
  34846. case 'StdVW':
  34847. program.properties.privateData[token] =
  34848. this.readNumberArray()[0];
  34849. break;
  34850. case 'BlueShift':
  34851. case 'lenIV':
  34852. case 'BlueFuzz':
  34853. case 'BlueScale':
  34854. case 'LanguageGroup':
  34855. case 'ExpansionFactor':
  34856. program.properties.privateData[token] = this.readNumber();
  34857. break;
  34858. case 'ForceBold':
  34859. program.properties.privateData[token] = this.readBoolean();
  34860. break;
  34861. }
  34862. }
  34863. for (var i = 0; i < charstrings.length; i++) {
  34864. glyph = charstrings[i].glyph;
  34865. encoded = charstrings[i].encoded;
  34866. var charString = new Type1CharString();
  34867. var error = charString.convert(encoded, subrs);
  34868. var output = charString.output;
  34869. if (error) {
  34870. // It seems when FreeType encounters an error while evaluating a glyph
  34871. // that it completely ignores the glyph so we'll mimic that behaviour
  34872. // here and put an endchar to make the validator happy.
  34873. output = [14];
  34874. }
  34875. program.charstrings.push({
  34876. glyphName: glyph,
  34877. charstring: output,
  34878. width: charString.width,
  34879. lsb: charString.lsb,
  34880. seac: charString.seac
  34881. });
  34882. }
  34883. return program;
  34884. },
  34885. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  34886. var token;
  34887. while ((token = this.getToken()) !== null) {
  34888. if (token !== '/') {
  34889. continue;
  34890. }
  34891. token = this.getToken();
  34892. switch (token) {
  34893. case 'FontMatrix':
  34894. var matrix = this.readNumberArray();
  34895. properties.fontMatrix = matrix;
  34896. break;
  34897. case 'Encoding':
  34898. var encodingArg = this.getToken();
  34899. var encoding;
  34900. if (!/^\d+$/.test(encodingArg)) {
  34901. // encoding name is specified
  34902. encoding = getEncoding(encodingArg);
  34903. } else {
  34904. encoding = [];
  34905. var size = parseInt(encodingArg, 10) | 0;
  34906. this.getToken(); // read in 'array'
  34907. for (var j = 0; j < size; j++) {
  34908. token = this.getToken();
  34909. // skipping till first dup or def (e.g. ignoring for statement)
  34910. while (token !== 'dup' && token !== 'def') {
  34911. token = this.getToken();
  34912. if (token === null) {
  34913. return; // invalid header
  34914. }
  34915. }
  34916. if (token === 'def') {
  34917. break; // read all array data
  34918. }
  34919. var index = this.readInt();
  34920. this.getToken(); // read in '/'
  34921. var glyph = this.getToken();
  34922. encoding[index] = glyph;
  34923. this.getToken(); // read the in 'put'
  34924. }
  34925. }
  34926. properties.builtInEncoding = encoding;
  34927. break;
  34928. case 'FontBBox':
  34929. var fontBBox = this.readNumberArray();
  34930. // adjusting ascent/descent
  34931. properties.ascent = fontBBox[3];
  34932. properties.descent = fontBBox[1];
  34933. properties.ascentScaled = true;
  34934. break;
  34935. }
  34936. }
  34937. }
  34938. };
  34939. return Type1Parser;
  34940. })();
  34941. /**
  34942. * The CFF class takes a Type1 file and wrap it into a
  34943. * 'Compact Font Format' which itself embed Type2 charstrings.
  34944. */
  34945. var CFFStandardStrings = [
  34946. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  34947. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  34948. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  34949. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  34950. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  34951. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  34952. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  34953. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  34954. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  34955. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  34956. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  34957. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  34958. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  34959. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  34960. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  34961. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  34962. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  34963. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  34964. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  34965. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  34966. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  34967. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  34968. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  34969. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  34970. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  34971. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  34972. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  34973. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  34974. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  34975. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  34976. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  34977. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  34978. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  34979. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  34980. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  34981. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  34982. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  34983. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  34984. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  34985. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  34986. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  34987. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  34988. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  34989. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  34990. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  34991. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  34992. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  34993. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  34994. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  34995. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  34996. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  34997. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  34998. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  34999. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  35000. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  35001. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  35002. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  35003. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  35004. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  35005. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  35006. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  35007. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  35008. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  35009. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  35010. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  35011. ];
  35012. // Type1Font is also a CIDFontType0.
  35013. var Type1Font = function Type1Font(name, file, properties) {
  35014. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  35015. // Also, length1 and length2 might be off by 6 bytes as well.
  35016. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  35017. var PFB_HEADER_SIZE = 6;
  35018. var headerBlockLength = properties.length1;
  35019. var eexecBlockLength = properties.length2;
  35020. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  35021. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  35022. if (pfbHeaderPresent) {
  35023. file.skip(PFB_HEADER_SIZE);
  35024. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35025. (pfbHeader[3] << 8) | pfbHeader[2];
  35026. }
  35027. // Get the data block containing glyphs and subrs informations
  35028. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  35029. var headerBlockParser = new Type1Parser(headerBlock);
  35030. headerBlockParser.extractFontHeader(properties);
  35031. if (pfbHeaderPresent) {
  35032. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  35033. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  35034. (pfbHeader[3] << 8) | pfbHeader[2];
  35035. }
  35036. // Decrypt the data blocks and retrieve it's content
  35037. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  35038. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  35039. var data = eexecBlockParser.extractFontProgram();
  35040. for (var info in data.properties) {
  35041. properties[info] = data.properties[info];
  35042. }
  35043. var charstrings = data.charstrings;
  35044. var type2Charstrings = this.getType2Charstrings(charstrings);
  35045. var subrs = this.getType2Subrs(data.subrs);
  35046. this.charstrings = charstrings;
  35047. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  35048. subrs, properties);
  35049. this.seacs = this.getSeacs(data.charstrings);
  35050. };
  35051. Type1Font.prototype = {
  35052. get numGlyphs() {
  35053. return this.charstrings.length + 1;
  35054. },
  35055. getCharset: function Type1Font_getCharset() {
  35056. var charset = ['.notdef'];
  35057. var charstrings = this.charstrings;
  35058. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35059. charset.push(charstrings[glyphId].glyphName);
  35060. }
  35061. return charset;
  35062. },
  35063. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  35064. var charstrings = this.charstrings;
  35065. var glyphNames = ['.notdef'], glyphId;
  35066. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  35067. glyphNames.push(charstrings[glyphId].glyphName);
  35068. }
  35069. var encoding = properties.builtInEncoding;
  35070. if (encoding) {
  35071. var builtInEncoding = Object.create(null);
  35072. for (var charCode in encoding) {
  35073. glyphId = glyphNames.indexOf(encoding[charCode]);
  35074. if (glyphId >= 0) {
  35075. builtInEncoding[charCode] = glyphId;
  35076. }
  35077. }
  35078. }
  35079. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  35080. },
  35081. getSeacs: function Type1Font_getSeacs(charstrings) {
  35082. var i, ii;
  35083. var seacMap = [];
  35084. for (i = 0, ii = charstrings.length; i < ii; i++) {
  35085. var charstring = charstrings[i];
  35086. if (charstring.seac) {
  35087. // Offset by 1 for .notdef
  35088. seacMap[i + 1] = charstring.seac;
  35089. }
  35090. }
  35091. return seacMap;
  35092. },
  35093. getType2Charstrings: function Type1Font_getType2Charstrings(
  35094. type1Charstrings) {
  35095. var type2Charstrings = [];
  35096. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  35097. type2Charstrings.push(type1Charstrings[i].charstring);
  35098. }
  35099. return type2Charstrings;
  35100. },
  35101. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  35102. var bias = 0;
  35103. var count = type1Subrs.length;
  35104. if (count < 1133) {
  35105. bias = 107;
  35106. } else if (count < 33769) {
  35107. bias = 1131;
  35108. } else {
  35109. bias = 32768;
  35110. }
  35111. // Add a bunch of empty subrs to deal with the Type2 bias
  35112. var type2Subrs = [];
  35113. var i;
  35114. for (i = 0; i < bias; i++) {
  35115. type2Subrs.push([0x0B]);
  35116. }
  35117. for (i = 0; i < count; i++) {
  35118. type2Subrs.push(type1Subrs[i]);
  35119. }
  35120. return type2Subrs;
  35121. },
  35122. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  35123. var cff = new CFF();
  35124. cff.header = new CFFHeader(1, 0, 4, 4);
  35125. cff.names = [name];
  35126. var topDict = new CFFTopDict();
  35127. // CFF strings IDs 0...390 are predefined names, so refering
  35128. // to entries in our own String INDEX starts at SID 391.
  35129. topDict.setByName('version', 391);
  35130. topDict.setByName('Notice', 392);
  35131. topDict.setByName('FullName', 393);
  35132. topDict.setByName('FamilyName', 394);
  35133. topDict.setByName('Weight', 395);
  35134. topDict.setByName('Encoding', null); // placeholder
  35135. topDict.setByName('FontMatrix', properties.fontMatrix);
  35136. topDict.setByName('FontBBox', properties.bbox);
  35137. topDict.setByName('charset', null); // placeholder
  35138. topDict.setByName('CharStrings', null); // placeholder
  35139. topDict.setByName('Private', null); // placeholder
  35140. cff.topDict = topDict;
  35141. var strings = new CFFStrings();
  35142. strings.add('Version 0.11'); // Version
  35143. strings.add('See original notice'); // Notice
  35144. strings.add(name); // FullName
  35145. strings.add(name); // FamilyName
  35146. strings.add('Medium'); // Weight
  35147. cff.strings = strings;
  35148. cff.globalSubrIndex = new CFFIndex();
  35149. var count = glyphs.length;
  35150. var charsetArray = [0];
  35151. var i, ii;
  35152. for (i = 0; i < count; i++) {
  35153. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  35154. // TODO: Insert the string and correctly map it. Previously it was
  35155. // thought mapping names that aren't in the standard strings to .notdef
  35156. // was fine, however in issue818 when mapping them all to .notdef the
  35157. // adieresis glyph no longer worked.
  35158. if (index === -1) {
  35159. index = 0;
  35160. }
  35161. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  35162. }
  35163. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  35164. var charStringsIndex = new CFFIndex();
  35165. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  35166. for (i = 0; i < count; i++) {
  35167. charStringsIndex.add(glyphs[i]);
  35168. }
  35169. cff.charStrings = charStringsIndex;
  35170. var privateDict = new CFFPrivateDict();
  35171. privateDict.setByName('Subrs', null); // placeholder
  35172. var fields = [
  35173. 'BlueValues',
  35174. 'OtherBlues',
  35175. 'FamilyBlues',
  35176. 'FamilyOtherBlues',
  35177. 'StemSnapH',
  35178. 'StemSnapV',
  35179. 'BlueShift',
  35180. 'BlueFuzz',
  35181. 'BlueScale',
  35182. 'LanguageGroup',
  35183. 'ExpansionFactor',
  35184. 'ForceBold',
  35185. 'StdHW',
  35186. 'StdVW'
  35187. ];
  35188. for (i = 0, ii = fields.length; i < ii; i++) {
  35189. var field = fields[i];
  35190. if (!(field in properties.privateData)) {
  35191. continue;
  35192. }
  35193. var value = properties.privateData[field];
  35194. if (isArray(value)) {
  35195. // All of the private dictionary array data in CFF must be stored as
  35196. // "delta-encoded" numbers.
  35197. for (var j = value.length - 1; j > 0; j--) {
  35198. value[j] -= value[j - 1]; // ... difference from previous value
  35199. }
  35200. }
  35201. privateDict.setByName(field, value);
  35202. }
  35203. cff.topDict.privateDict = privateDict;
  35204. var subrIndex = new CFFIndex();
  35205. for (i = 0, ii = subrs.length; i < ii; i++) {
  35206. subrIndex.add(subrs[i]);
  35207. }
  35208. privateDict.subrsIndex = subrIndex;
  35209. var compiler = new CFFCompiler(cff);
  35210. return compiler.compile();
  35211. }
  35212. };
  35213. var CFFFont = (function CFFFontClosure() {
  35214. function CFFFont(file, properties) {
  35215. this.properties = properties;
  35216. var parser = new CFFParser(file, properties);
  35217. this.cff = parser.parse();
  35218. var compiler = new CFFCompiler(this.cff);
  35219. this.seacs = this.cff.seacs;
  35220. try {
  35221. this.data = compiler.compile();
  35222. } catch (e) {
  35223. warn('Failed to compile font ' + properties.loadedName);
  35224. // There may have just been an issue with the compiler, set the data
  35225. // anyway and hope the font loaded.
  35226. this.data = file;
  35227. }
  35228. }
  35229. CFFFont.prototype = {
  35230. get numGlyphs() {
  35231. return this.cff.charStrings.count;
  35232. },
  35233. getCharset: function CFFFont_getCharset() {
  35234. return this.cff.charset.charset;
  35235. },
  35236. getGlyphMapping: function CFFFont_getGlyphMapping() {
  35237. var cff = this.cff;
  35238. var properties = this.properties;
  35239. var charsets = cff.charset.charset;
  35240. var charCodeToGlyphId;
  35241. var glyphId;
  35242. if (properties.composite) {
  35243. charCodeToGlyphId = Object.create(null);
  35244. if (cff.isCIDFont) {
  35245. // If the font is actually a CID font then we should use the charset
  35246. // to map CIDs to GIDs.
  35247. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  35248. var cid = charsets[glyphId];
  35249. var charCode = properties.cMap.charCodeOf(cid);
  35250. charCodeToGlyphId[charCode] = glyphId;
  35251. }
  35252. } else {
  35253. // If it is NOT actually a CID font then CIDs should be mapped
  35254. // directly to GIDs.
  35255. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  35256. charCodeToGlyphId[glyphId] = glyphId;
  35257. }
  35258. }
  35259. return charCodeToGlyphId;
  35260. }
  35261. var encoding = cff.encoding ? cff.encoding.encoding : null;
  35262. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  35263. return charCodeToGlyphId;
  35264. }
  35265. };
  35266. return CFFFont;
  35267. })();
  35268. var CFFParser = (function CFFParserClosure() {
  35269. var CharstringValidationData = [
  35270. null,
  35271. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  35272. null,
  35273. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  35274. { id: 'vmoveto', min: 1, stackClearing: true },
  35275. { id: 'rlineto', min: 2, resetStack: true },
  35276. { id: 'hlineto', min: 1, resetStack: true },
  35277. { id: 'vlineto', min: 1, resetStack: true },
  35278. { id: 'rrcurveto', min: 6, resetStack: true },
  35279. null,
  35280. { id: 'callsubr', min: 1, undefStack: true },
  35281. { id: 'return', min: 0, undefStack: true },
  35282. null, // 12
  35283. null,
  35284. { id: 'endchar', min: 0, stackClearing: true },
  35285. null,
  35286. null,
  35287. null,
  35288. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  35289. { id: 'hintmask', min: 0, stackClearing: true },
  35290. { id: 'cntrmask', min: 0, stackClearing: true },
  35291. { id: 'rmoveto', min: 2, stackClearing: true },
  35292. { id: 'hmoveto', min: 1, stackClearing: true },
  35293. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  35294. { id: 'rcurveline', min: 8, resetStack: true },
  35295. { id: 'rlinecurve', min: 8, resetStack: true },
  35296. { id: 'vvcurveto', min: 4, resetStack: true },
  35297. { id: 'hhcurveto', min: 4, resetStack: true },
  35298. null, // shortint
  35299. { id: 'callgsubr', min: 1, undefStack: true },
  35300. { id: 'vhcurveto', min: 4, resetStack: true },
  35301. { id: 'hvcurveto', min: 4, resetStack: true }
  35302. ];
  35303. var CharstringValidationData12 = [
  35304. null,
  35305. null,
  35306. null,
  35307. { id: 'and', min: 2, stackDelta: -1 },
  35308. { id: 'or', min: 2, stackDelta: -1 },
  35309. { id: 'not', min: 1, stackDelta: 0 },
  35310. null,
  35311. null,
  35312. null,
  35313. { id: 'abs', min: 1, stackDelta: 0 },
  35314. { id: 'add', min: 2, stackDelta: -1,
  35315. stackFn: function stack_div(stack, index) {
  35316. stack[index - 2] = stack[index - 2] + stack[index - 1];
  35317. }
  35318. },
  35319. { id: 'sub', min: 2, stackDelta: -1,
  35320. stackFn: function stack_div(stack, index) {
  35321. stack[index - 2] = stack[index - 2] - stack[index - 1];
  35322. }
  35323. },
  35324. { id: 'div', min: 2, stackDelta: -1,
  35325. stackFn: function stack_div(stack, index) {
  35326. stack[index - 2] = stack[index - 2] / stack[index - 1];
  35327. }
  35328. },
  35329. null,
  35330. { id: 'neg', min: 1, stackDelta: 0,
  35331. stackFn: function stack_div(stack, index) {
  35332. stack[index - 1] = -stack[index - 1];
  35333. }
  35334. },
  35335. { id: 'eq', min: 2, stackDelta: -1 },
  35336. null,
  35337. null,
  35338. { id: 'drop', min: 1, stackDelta: -1 },
  35339. null,
  35340. { id: 'put', min: 2, stackDelta: -2 },
  35341. { id: 'get', min: 1, stackDelta: 0 },
  35342. { id: 'ifelse', min: 4, stackDelta: -3 },
  35343. { id: 'random', min: 0, stackDelta: 1 },
  35344. { id: 'mul', min: 2, stackDelta: -1,
  35345. stackFn: function stack_div(stack, index) {
  35346. stack[index - 2] = stack[index - 2] * stack[index - 1];
  35347. }
  35348. },
  35349. null,
  35350. { id: 'sqrt', min: 1, stackDelta: 0 },
  35351. { id: 'dup', min: 1, stackDelta: 1 },
  35352. { id: 'exch', min: 2, stackDelta: 0 },
  35353. { id: 'index', min: 2, stackDelta: 0 },
  35354. { id: 'roll', min: 3, stackDelta: -2 },
  35355. null,
  35356. null,
  35357. null,
  35358. { id: 'hflex', min: 7, resetStack: true },
  35359. { id: 'flex', min: 13, resetStack: true },
  35360. { id: 'hflex1', min: 9, resetStack: true },
  35361. { id: 'flex1', min: 11, resetStack: true }
  35362. ];
  35363. function CFFParser(file, properties) {
  35364. this.bytes = file.getBytes();
  35365. this.properties = properties;
  35366. }
  35367. CFFParser.prototype = {
  35368. parse: function CFFParser_parse() {
  35369. var properties = this.properties;
  35370. var cff = new CFF();
  35371. this.cff = cff;
  35372. // The first five sections must be in order, all the others are reached
  35373. // via offsets contained in one of the below.
  35374. var header = this.parseHeader();
  35375. var nameIndex = this.parseIndex(header.endPos);
  35376. var topDictIndex = this.parseIndex(nameIndex.endPos);
  35377. var stringIndex = this.parseIndex(topDictIndex.endPos);
  35378. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  35379. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  35380. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  35381. cff.header = header.obj;
  35382. cff.names = this.parseNameIndex(nameIndex.obj);
  35383. cff.strings = this.parseStringIndex(stringIndex.obj);
  35384. cff.topDict = topDict;
  35385. cff.globalSubrIndex = globalSubrIndex.obj;
  35386. this.parsePrivateDict(cff.topDict);
  35387. cff.isCIDFont = topDict.hasName('ROS');
  35388. var charStringOffset = topDict.getByName('CharStrings');
  35389. var charStringIndex = this.parseIndex(charStringOffset).obj;
  35390. var fontMatrix = topDict.getByName('FontMatrix');
  35391. if (fontMatrix) {
  35392. properties.fontMatrix = fontMatrix;
  35393. }
  35394. var fontBBox = topDict.getByName('FontBBox');
  35395. if (fontBBox) {
  35396. // adjusting ascent/descent
  35397. properties.ascent = fontBBox[3];
  35398. properties.descent = fontBBox[1];
  35399. properties.ascentScaled = true;
  35400. }
  35401. var charset, encoding;
  35402. if (cff.isCIDFont) {
  35403. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  35404. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  35405. var dictRaw = fdArrayIndex.get(i);
  35406. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  35407. cff.strings);
  35408. this.parsePrivateDict(fontDict);
  35409. cff.fdArray.push(fontDict);
  35410. }
  35411. // cid fonts don't have an encoding
  35412. encoding = null;
  35413. charset = this.parseCharsets(topDict.getByName('charset'),
  35414. charStringIndex.count, cff.strings, true);
  35415. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  35416. charStringIndex.count);
  35417. } else {
  35418. charset = this.parseCharsets(topDict.getByName('charset'),
  35419. charStringIndex.count, cff.strings, false);
  35420. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  35421. properties,
  35422. cff.strings, charset.charset);
  35423. }
  35424. cff.charset = charset;
  35425. cff.encoding = encoding;
  35426. var charStringsAndSeacs = this.parseCharStrings(
  35427. charStringIndex,
  35428. topDict.privateDict.subrsIndex,
  35429. globalSubrIndex.obj,
  35430. cff.fdSelect,
  35431. cff.fdArray);
  35432. cff.charStrings = charStringsAndSeacs.charStrings;
  35433. cff.seacs = charStringsAndSeacs.seacs;
  35434. cff.widths = charStringsAndSeacs.widths;
  35435. return cff;
  35436. },
  35437. parseHeader: function CFFParser_parseHeader() {
  35438. var bytes = this.bytes;
  35439. var bytesLength = bytes.length;
  35440. var offset = 0;
  35441. // Prevent an infinite loop, by checking that the offset is within the
  35442. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  35443. while (offset < bytesLength && bytes[offset] !== 1) {
  35444. ++offset;
  35445. }
  35446. if (offset >= bytesLength) {
  35447. error('Invalid CFF header');
  35448. } else if (offset !== 0) {
  35449. info('cff data is shifted');
  35450. bytes = bytes.subarray(offset);
  35451. this.bytes = bytes;
  35452. }
  35453. var major = bytes[0];
  35454. var minor = bytes[1];
  35455. var hdrSize = bytes[2];
  35456. var offSize = bytes[3];
  35457. var header = new CFFHeader(major, minor, hdrSize, offSize);
  35458. return { obj: header, endPos: hdrSize };
  35459. },
  35460. parseDict: function CFFParser_parseDict(dict) {
  35461. var pos = 0;
  35462. function parseOperand() {
  35463. var value = dict[pos++];
  35464. if (value === 30) {
  35465. return parseFloatOperand(pos);
  35466. } else if (value === 28) {
  35467. value = dict[pos++];
  35468. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  35469. return value;
  35470. } else if (value === 29) {
  35471. value = dict[pos++];
  35472. value = (value << 8) | dict[pos++];
  35473. value = (value << 8) | dict[pos++];
  35474. value = (value << 8) | dict[pos++];
  35475. return value;
  35476. } else if (value >= 32 && value <= 246) {
  35477. return value - 139;
  35478. } else if (value >= 247 && value <= 250) {
  35479. return ((value - 247) * 256) + dict[pos++] + 108;
  35480. } else if (value >= 251 && value <= 254) {
  35481. return -((value - 251) * 256) - dict[pos++] - 108;
  35482. } else {
  35483. error('255 is not a valid DICT command');
  35484. }
  35485. return -1;
  35486. }
  35487. function parseFloatOperand() {
  35488. var str = '';
  35489. var eof = 15;
  35490. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  35491. '9', '.', 'E', 'E-', null, '-'];
  35492. var length = dict.length;
  35493. while (pos < length) {
  35494. var b = dict[pos++];
  35495. var b1 = b >> 4;
  35496. var b2 = b & 15;
  35497. if (b1 === eof) {
  35498. break;
  35499. }
  35500. str += lookup[b1];
  35501. if (b2 === eof) {
  35502. break;
  35503. }
  35504. str += lookup[b2];
  35505. }
  35506. return parseFloat(str);
  35507. }
  35508. var operands = [];
  35509. var entries = [];
  35510. pos = 0;
  35511. var end = dict.length;
  35512. while (pos < end) {
  35513. var b = dict[pos];
  35514. if (b <= 21) {
  35515. if (b === 12) {
  35516. b = (b << 8) | dict[++pos];
  35517. }
  35518. entries.push([b, operands]);
  35519. operands = [];
  35520. ++pos;
  35521. } else {
  35522. operands.push(parseOperand());
  35523. }
  35524. }
  35525. return entries;
  35526. },
  35527. parseIndex: function CFFParser_parseIndex(pos) {
  35528. var cffIndex = new CFFIndex();
  35529. var bytes = this.bytes;
  35530. var count = (bytes[pos++] << 8) | bytes[pos++];
  35531. var offsets = [];
  35532. var end = pos;
  35533. var i, ii;
  35534. if (count !== 0) {
  35535. var offsetSize = bytes[pos++];
  35536. // add 1 for offset to determine size of last object
  35537. var startPos = pos + ((count + 1) * offsetSize) - 1;
  35538. for (i = 0, ii = count + 1; i < ii; ++i) {
  35539. var offset = 0;
  35540. for (var j = 0; j < offsetSize; ++j) {
  35541. offset <<= 8;
  35542. offset += bytes[pos++];
  35543. }
  35544. offsets.push(startPos + offset);
  35545. }
  35546. end = offsets[count];
  35547. }
  35548. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  35549. var offsetStart = offsets[i];
  35550. var offsetEnd = offsets[i + 1];
  35551. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  35552. }
  35553. return {obj: cffIndex, endPos: end};
  35554. },
  35555. parseNameIndex: function CFFParser_parseNameIndex(index) {
  35556. var names = [];
  35557. for (var i = 0, ii = index.count; i < ii; ++i) {
  35558. var name = index.get(i);
  35559. // OTS doesn't allow names to be over 127 characters.
  35560. var length = Math.min(name.length, 127);
  35561. var data = [];
  35562. // OTS also only permits certain characters in the name.
  35563. for (var j = 0; j < length; ++j) {
  35564. var c = name[j];
  35565. if (j === 0 && c === 0) {
  35566. data[j] = c;
  35567. continue;
  35568. }
  35569. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  35570. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  35571. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  35572. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  35573. data[j] = 95;
  35574. continue;
  35575. }
  35576. data[j] = c;
  35577. }
  35578. names.push(bytesToString(data));
  35579. }
  35580. return names;
  35581. },
  35582. parseStringIndex: function CFFParser_parseStringIndex(index) {
  35583. var strings = new CFFStrings();
  35584. for (var i = 0, ii = index.count; i < ii; ++i) {
  35585. var data = index.get(i);
  35586. strings.add(bytesToString(data));
  35587. }
  35588. return strings;
  35589. },
  35590. createDict: function CFFParser_createDict(Type, dict, strings) {
  35591. var cffDict = new Type(strings);
  35592. for (var i = 0, ii = dict.length; i < ii; ++i) {
  35593. var pair = dict[i];
  35594. var key = pair[0];
  35595. var value = pair[1];
  35596. cffDict.setByKey(key, value);
  35597. }
  35598. return cffDict;
  35599. },
  35600. parseCharString: function CFFParser_parseCharString(state, data,
  35601. localSubrIndex,
  35602. globalSubrIndex) {
  35603. if (state.callDepth > MAX_SUBR_NESTING) {
  35604. return false;
  35605. }
  35606. var stackSize = state.stackSize;
  35607. var stack = state.stack;
  35608. var length = data.length;
  35609. for (var j = 0; j < length;) {
  35610. var value = data[j++];
  35611. var validationCommand = null;
  35612. if (value === 12) {
  35613. var q = data[j++];
  35614. if (q === 0) {
  35615. // The CFF specification state that the 'dotsection' command
  35616. // (12, 0) is deprecated and treated as a no-op, but all Type2
  35617. // charstrings processors should support them. Unfortunately
  35618. // the font sanitizer don't. As a workaround the sequence (12, 0)
  35619. // is replaced by a useless (0, hmoveto).
  35620. data[j - 2] = 139;
  35621. data[j - 1] = 22;
  35622. stackSize = 0;
  35623. } else {
  35624. validationCommand = CharstringValidationData12[q];
  35625. }
  35626. } else if (value === 28) { // number (16 bit)
  35627. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  35628. j += 2;
  35629. stackSize++;
  35630. } else if (value === 14) {
  35631. if (stackSize >= 4) {
  35632. stackSize -= 4;
  35633. if (SEAC_ANALYSIS_ENABLED) {
  35634. state.seac = stack.slice(stackSize, stackSize + 4);
  35635. return false;
  35636. }
  35637. }
  35638. validationCommand = CharstringValidationData[value];
  35639. } else if (value >= 32 && value <= 246) { // number
  35640. stack[stackSize] = value - 139;
  35641. stackSize++;
  35642. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  35643. stack[stackSize] = (value < 251 ?
  35644. ((value - 247) << 8) + data[j] + 108 :
  35645. -((value - 251) << 8) - data[j] - 108);
  35646. j++;
  35647. stackSize++;
  35648. } else if (value === 255) { // number (32 bit)
  35649. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  35650. (data[j + 2] << 8) | data[j + 3]) / 65536;
  35651. j += 4;
  35652. stackSize++;
  35653. } else if (value === 19 || value === 20) {
  35654. state.hints += stackSize >> 1;
  35655. // skipping right amount of hints flag data
  35656. j += (state.hints + 7) >> 3;
  35657. stackSize %= 2;
  35658. validationCommand = CharstringValidationData[value];
  35659. } else if (value === 10 || value === 29) {
  35660. var subrsIndex;
  35661. if (value === 10) {
  35662. subrsIndex = localSubrIndex;
  35663. } else {
  35664. subrsIndex = globalSubrIndex;
  35665. }
  35666. if (!subrsIndex) {
  35667. validationCommand = CharstringValidationData[value];
  35668. warn('Missing subrsIndex for ' + validationCommand.id);
  35669. return false;
  35670. }
  35671. var bias = 32768;
  35672. if (subrsIndex.count < 1240) {
  35673. bias = 107;
  35674. } else if (subrsIndex.count < 33900) {
  35675. bias = 1131;
  35676. }
  35677. var subrNumber = stack[--stackSize] + bias;
  35678. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  35679. validationCommand = CharstringValidationData[value];
  35680. warn('Out of bounds subrIndex for ' + validationCommand.id);
  35681. return false;
  35682. }
  35683. state.stackSize = stackSize;
  35684. state.callDepth++;
  35685. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  35686. localSubrIndex, globalSubrIndex);
  35687. if (!valid) {
  35688. return false;
  35689. }
  35690. state.callDepth--;
  35691. stackSize = state.stackSize;
  35692. continue;
  35693. } else if (value === 11) {
  35694. state.stackSize = stackSize;
  35695. return true;
  35696. } else {
  35697. validationCommand = CharstringValidationData[value];
  35698. }
  35699. if (validationCommand) {
  35700. if (validationCommand.stem) {
  35701. state.hints += stackSize >> 1;
  35702. }
  35703. if ('min' in validationCommand) {
  35704. if (!state.undefStack && stackSize < validationCommand.min) {
  35705. warn('Not enough parameters for ' + validationCommand.id +
  35706. '; actual: ' + stackSize +
  35707. ', expected: ' + validationCommand.min);
  35708. return false;
  35709. }
  35710. }
  35711. if (state.firstStackClearing && validationCommand.stackClearing) {
  35712. state.firstStackClearing = false;
  35713. // the optional character width can be found before the first
  35714. // stack-clearing command arguments
  35715. stackSize -= validationCommand.min;
  35716. if (stackSize >= 2 && validationCommand.stem) {
  35717. // there are even amount of arguments for stem commands
  35718. stackSize %= 2;
  35719. } else if (stackSize > 1) {
  35720. warn('Found too many parameters for stack-clearing command');
  35721. }
  35722. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  35723. state.width = stack[stackSize - 1];
  35724. }
  35725. }
  35726. if ('stackDelta' in validationCommand) {
  35727. if ('stackFn' in validationCommand) {
  35728. validationCommand.stackFn(stack, stackSize);
  35729. }
  35730. stackSize += validationCommand.stackDelta;
  35731. } else if (validationCommand.stackClearing) {
  35732. stackSize = 0;
  35733. } else if (validationCommand.resetStack) {
  35734. stackSize = 0;
  35735. state.undefStack = false;
  35736. } else if (validationCommand.undefStack) {
  35737. stackSize = 0;
  35738. state.undefStack = true;
  35739. state.firstStackClearing = false;
  35740. }
  35741. }
  35742. }
  35743. state.stackSize = stackSize;
  35744. return true;
  35745. },
  35746. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  35747. localSubrIndex,
  35748. globalSubrIndex,
  35749. fdSelect,
  35750. fdArray) {
  35751. var seacs = [];
  35752. var widths = [];
  35753. var count = charStrings.count;
  35754. for (var i = 0; i < count; i++) {
  35755. var charstring = charStrings.get(i);
  35756. var state = {
  35757. callDepth: 0,
  35758. stackSize: 0,
  35759. stack: [],
  35760. undefStack: true,
  35761. hints: 0,
  35762. firstStackClearing: true,
  35763. seac: null,
  35764. width: null
  35765. };
  35766. var valid = true;
  35767. var localSubrToUse = null;
  35768. if (fdSelect && fdArray.length) {
  35769. var fdIndex = fdSelect.getFDIndex(i);
  35770. if (fdIndex === -1) {
  35771. warn('Glyph index is not in fd select.');
  35772. valid = false;
  35773. }
  35774. if (fdIndex >= fdArray.length) {
  35775. warn('Invalid fd index for glyph index.');
  35776. valid = false;
  35777. }
  35778. if (valid) {
  35779. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  35780. }
  35781. } else if (localSubrIndex) {
  35782. localSubrToUse = localSubrIndex;
  35783. }
  35784. if (valid) {
  35785. valid = this.parseCharString(state, charstring, localSubrToUse,
  35786. globalSubrIndex);
  35787. }
  35788. if (state.width !== null) {
  35789. widths[i] = state.width;
  35790. }
  35791. if (state.seac !== null) {
  35792. seacs[i] = state.seac;
  35793. }
  35794. if (!valid) {
  35795. // resetting invalid charstring to single 'endchar'
  35796. charStrings.set(i, new Uint8Array([14]));
  35797. }
  35798. }
  35799. return { charStrings: charStrings, seacs: seacs, widths: widths };
  35800. },
  35801. emptyPrivateDictionary:
  35802. function CFFParser_emptyPrivateDictionary(parentDict) {
  35803. var privateDict = this.createDict(CFFPrivateDict, [],
  35804. parentDict.strings);
  35805. parentDict.setByKey(18, [0, 0]);
  35806. parentDict.privateDict = privateDict;
  35807. },
  35808. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  35809. // no private dict, do nothing
  35810. if (!parentDict.hasName('Private')) {
  35811. this.emptyPrivateDictionary(parentDict);
  35812. return;
  35813. }
  35814. var privateOffset = parentDict.getByName('Private');
  35815. // make sure the params are formatted correctly
  35816. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  35817. parentDict.removeByName('Private');
  35818. return;
  35819. }
  35820. var size = privateOffset[0];
  35821. var offset = privateOffset[1];
  35822. // remove empty dicts or ones that refer to invalid location
  35823. if (size === 0 || offset >= this.bytes.length) {
  35824. this.emptyPrivateDictionary(parentDict);
  35825. return;
  35826. }
  35827. var privateDictEnd = offset + size;
  35828. var dictData = this.bytes.subarray(offset, privateDictEnd);
  35829. var dict = this.parseDict(dictData);
  35830. var privateDict = this.createDict(CFFPrivateDict, dict,
  35831. parentDict.strings);
  35832. parentDict.privateDict = privateDict;
  35833. // Parse the Subrs index also since it's relative to the private dict.
  35834. if (!privateDict.getByName('Subrs')) {
  35835. return;
  35836. }
  35837. var subrsOffset = privateDict.getByName('Subrs');
  35838. var relativeOffset = offset + subrsOffset;
  35839. // Validate the offset.
  35840. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  35841. this.emptyPrivateDictionary(parentDict);
  35842. return;
  35843. }
  35844. var subrsIndex = this.parseIndex(relativeOffset);
  35845. privateDict.subrsIndex = subrsIndex.obj;
  35846. },
  35847. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  35848. if (pos === 0) {
  35849. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  35850. ISOAdobeCharset);
  35851. } else if (pos === 1) {
  35852. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  35853. ExpertCharset);
  35854. } else if (pos === 2) {
  35855. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  35856. ExpertSubsetCharset);
  35857. }
  35858. var bytes = this.bytes;
  35859. var start = pos;
  35860. var format = bytes[pos++];
  35861. var charset = ['.notdef'];
  35862. var id, count, i;
  35863. // subtract 1 for the .notdef glyph
  35864. length -= 1;
  35865. switch (format) {
  35866. case 0:
  35867. for (i = 0; i < length; i++) {
  35868. id = (bytes[pos++] << 8) | bytes[pos++];
  35869. charset.push(cid ? id : strings.get(id));
  35870. }
  35871. break;
  35872. case 1:
  35873. while (charset.length <= length) {
  35874. id = (bytes[pos++] << 8) | bytes[pos++];
  35875. count = bytes[pos++];
  35876. for (i = 0; i <= count; i++) {
  35877. charset.push(cid ? id++ : strings.get(id++));
  35878. }
  35879. }
  35880. break;
  35881. case 2:
  35882. while (charset.length <= length) {
  35883. id = (bytes[pos++] << 8) | bytes[pos++];
  35884. count = (bytes[pos++] << 8) | bytes[pos++];
  35885. for (i = 0; i <= count; i++) {
  35886. charset.push(cid ? id++ : strings.get(id++));
  35887. }
  35888. }
  35889. break;
  35890. default:
  35891. error('Unknown charset format');
  35892. }
  35893. // Raw won't be needed if we actually compile the charset.
  35894. var end = pos;
  35895. var raw = bytes.subarray(start, end);
  35896. return new CFFCharset(false, format, charset, raw);
  35897. },
  35898. parseEncoding: function CFFParser_parseEncoding(pos,
  35899. properties,
  35900. strings,
  35901. charset) {
  35902. var encoding = Object.create(null);
  35903. var bytes = this.bytes;
  35904. var predefined = false;
  35905. var hasSupplement = false;
  35906. var format, i, ii;
  35907. var raw = null;
  35908. function readSupplement() {
  35909. var supplementsCount = bytes[pos++];
  35910. for (i = 0; i < supplementsCount; i++) {
  35911. var code = bytes[pos++];
  35912. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  35913. encoding[code] = charset.indexOf(strings.get(sid));
  35914. }
  35915. }
  35916. if (pos === 0 || pos === 1) {
  35917. predefined = true;
  35918. format = pos;
  35919. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  35920. for (i = 0, ii = charset.length; i < ii; i++) {
  35921. var index = baseEncoding.indexOf(charset[i]);
  35922. if (index !== -1) {
  35923. encoding[index] = i;
  35924. }
  35925. }
  35926. } else {
  35927. var dataStart = pos;
  35928. format = bytes[pos++];
  35929. switch (format & 0x7f) {
  35930. case 0:
  35931. var glyphsCount = bytes[pos++];
  35932. for (i = 1; i <= glyphsCount; i++) {
  35933. encoding[bytes[pos++]] = i;
  35934. }
  35935. break;
  35936. case 1:
  35937. var rangesCount = bytes[pos++];
  35938. var gid = 1;
  35939. for (i = 0; i < rangesCount; i++) {
  35940. var start = bytes[pos++];
  35941. var left = bytes[pos++];
  35942. for (var j = start; j <= start + left; j++) {
  35943. encoding[j] = gid++;
  35944. }
  35945. }
  35946. break;
  35947. default:
  35948. error('Unknow encoding format: ' + format + ' in CFF');
  35949. break;
  35950. }
  35951. var dataEnd = pos;
  35952. if (format & 0x80) {
  35953. // The font sanitizer does not support CFF encoding with a
  35954. // supplement, since the encoding is not really used to map
  35955. // between gid to glyph, let's overwrite what is declared in
  35956. // the top dictionary to let the sanitizer think the font use
  35957. // StandardEncoding, that's a lie but that's ok.
  35958. bytes[dataStart] &= 0x7f;
  35959. readSupplement();
  35960. hasSupplement = true;
  35961. }
  35962. raw = bytes.subarray(dataStart, dataEnd);
  35963. }
  35964. format = format & 0x7f;
  35965. return new CFFEncoding(predefined, format, encoding, raw);
  35966. },
  35967. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  35968. var start = pos;
  35969. var bytes = this.bytes;
  35970. var format = bytes[pos++];
  35971. var fdSelect = [];
  35972. var i;
  35973. switch (format) {
  35974. case 0:
  35975. for (i = 0; i < length; ++i) {
  35976. var id = bytes[pos++];
  35977. fdSelect.push(id);
  35978. }
  35979. break;
  35980. case 3:
  35981. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  35982. for (i = 0; i < rangesCount; ++i) {
  35983. var first = (bytes[pos++] << 8) | bytes[pos++];
  35984. var fdIndex = bytes[pos++];
  35985. var next = (bytes[pos] << 8) | bytes[pos + 1];
  35986. for (var j = first; j < next; ++j) {
  35987. fdSelect.push(fdIndex);
  35988. }
  35989. }
  35990. // Advance past the sentinel(next).
  35991. pos += 2;
  35992. break;
  35993. default:
  35994. error('Unknown fdselect format ' + format);
  35995. break;
  35996. }
  35997. var end = pos;
  35998. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  35999. }
  36000. };
  36001. return CFFParser;
  36002. })();
  36003. // Compact Font Format
  36004. var CFF = (function CFFClosure() {
  36005. function CFF() {
  36006. this.header = null;
  36007. this.names = [];
  36008. this.topDict = null;
  36009. this.strings = new CFFStrings();
  36010. this.globalSubrIndex = null;
  36011. // The following could really be per font, but since we only have one font
  36012. // store them here.
  36013. this.encoding = null;
  36014. this.charset = null;
  36015. this.charStrings = null;
  36016. this.fdArray = [];
  36017. this.fdSelect = null;
  36018. this.isCIDFont = false;
  36019. }
  36020. return CFF;
  36021. })();
  36022. var CFFHeader = (function CFFHeaderClosure() {
  36023. function CFFHeader(major, minor, hdrSize, offSize) {
  36024. this.major = major;
  36025. this.minor = minor;
  36026. this.hdrSize = hdrSize;
  36027. this.offSize = offSize;
  36028. }
  36029. return CFFHeader;
  36030. })();
  36031. var CFFStrings = (function CFFStringsClosure() {
  36032. function CFFStrings() {
  36033. this.strings = [];
  36034. }
  36035. CFFStrings.prototype = {
  36036. get: function CFFStrings_get(index) {
  36037. if (index >= 0 && index <= 390) {
  36038. return CFFStandardStrings[index];
  36039. }
  36040. if (index - 391 <= this.strings.length) {
  36041. return this.strings[index - 391];
  36042. }
  36043. return CFFStandardStrings[0];
  36044. },
  36045. add: function CFFStrings_add(value) {
  36046. this.strings.push(value);
  36047. },
  36048. get count() {
  36049. return this.strings.length;
  36050. }
  36051. };
  36052. return CFFStrings;
  36053. })();
  36054. var CFFIndex = (function CFFIndexClosure() {
  36055. function CFFIndex() {
  36056. this.objects = [];
  36057. this.length = 0;
  36058. }
  36059. CFFIndex.prototype = {
  36060. add: function CFFIndex_add(data) {
  36061. this.length += data.length;
  36062. this.objects.push(data);
  36063. },
  36064. set: function CFFIndex_set(index, data) {
  36065. this.length += data.length - this.objects[index].length;
  36066. this.objects[index] = data;
  36067. },
  36068. get: function CFFIndex_get(index) {
  36069. return this.objects[index];
  36070. },
  36071. get count() {
  36072. return this.objects.length;
  36073. }
  36074. };
  36075. return CFFIndex;
  36076. })();
  36077. var CFFDict = (function CFFDictClosure() {
  36078. function CFFDict(tables, strings) {
  36079. this.keyToNameMap = tables.keyToNameMap;
  36080. this.nameToKeyMap = tables.nameToKeyMap;
  36081. this.defaults = tables.defaults;
  36082. this.types = tables.types;
  36083. this.opcodes = tables.opcodes;
  36084. this.order = tables.order;
  36085. this.strings = strings;
  36086. this.values = Object.create(null);
  36087. }
  36088. CFFDict.prototype = {
  36089. // value should always be an array
  36090. setByKey: function CFFDict_setByKey(key, value) {
  36091. if (!(key in this.keyToNameMap)) {
  36092. return false;
  36093. }
  36094. // ignore empty values
  36095. if (value.length === 0) {
  36096. return true;
  36097. }
  36098. var type = this.types[key];
  36099. // remove the array wrapping these types of values
  36100. if (type === 'num' || type === 'sid' || type === 'offset') {
  36101. value = value[0];
  36102. }
  36103. this.values[key] = value;
  36104. return true;
  36105. },
  36106. setByName: function CFFDict_setByName(name, value) {
  36107. if (!(name in this.nameToKeyMap)) {
  36108. error('Invalid dictionary name "' + name + '"');
  36109. }
  36110. this.values[this.nameToKeyMap[name]] = value;
  36111. },
  36112. hasName: function CFFDict_hasName(name) {
  36113. return this.nameToKeyMap[name] in this.values;
  36114. },
  36115. getByName: function CFFDict_getByName(name) {
  36116. if (!(name in this.nameToKeyMap)) {
  36117. error('Invalid dictionary name "' + name + '"');
  36118. }
  36119. var key = this.nameToKeyMap[name];
  36120. if (!(key in this.values)) {
  36121. return this.defaults[key];
  36122. }
  36123. return this.values[key];
  36124. },
  36125. removeByName: function CFFDict_removeByName(name) {
  36126. delete this.values[this.nameToKeyMap[name]];
  36127. }
  36128. };
  36129. CFFDict.createTables = function CFFDict_createTables(layout) {
  36130. var tables = {
  36131. keyToNameMap: {},
  36132. nameToKeyMap: {},
  36133. defaults: {},
  36134. types: {},
  36135. opcodes: {},
  36136. order: []
  36137. };
  36138. for (var i = 0, ii = layout.length; i < ii; ++i) {
  36139. var entry = layout[i];
  36140. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  36141. tables.keyToNameMap[key] = entry[1];
  36142. tables.nameToKeyMap[entry[1]] = key;
  36143. tables.types[key] = entry[2];
  36144. tables.defaults[key] = entry[3];
  36145. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  36146. tables.order.push(key);
  36147. }
  36148. return tables;
  36149. };
  36150. return CFFDict;
  36151. })();
  36152. var CFFTopDict = (function CFFTopDictClosure() {
  36153. var layout = [
  36154. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  36155. [[12, 20], 'SyntheticBase', 'num', null],
  36156. [0, 'version', 'sid', null],
  36157. [1, 'Notice', 'sid', null],
  36158. [[12, 0], 'Copyright', 'sid', null],
  36159. [2, 'FullName', 'sid', null],
  36160. [3, 'FamilyName', 'sid', null],
  36161. [4, 'Weight', 'sid', null],
  36162. [[12, 1], 'isFixedPitch', 'num', 0],
  36163. [[12, 2], 'ItalicAngle', 'num', 0],
  36164. [[12, 3], 'UnderlinePosition', 'num', -100],
  36165. [[12, 4], 'UnderlineThickness', 'num', 50],
  36166. [[12, 5], 'PaintType', 'num', 0],
  36167. [[12, 6], 'CharstringType', 'num', 2],
  36168. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  36169. [0.001, 0, 0, 0.001, 0, 0]],
  36170. [13, 'UniqueID', 'num', null],
  36171. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  36172. [[12, 8], 'StrokeWidth', 'num', 0],
  36173. [14, 'XUID', 'array', null],
  36174. [15, 'charset', 'offset', 0],
  36175. [16, 'Encoding', 'offset', 0],
  36176. [17, 'CharStrings', 'offset', 0],
  36177. [18, 'Private', ['offset', 'offset'], null],
  36178. [[12, 21], 'PostScript', 'sid', null],
  36179. [[12, 22], 'BaseFontName', 'sid', null],
  36180. [[12, 23], 'BaseFontBlend', 'delta', null],
  36181. [[12, 31], 'CIDFontVersion', 'num', 0],
  36182. [[12, 32], 'CIDFontRevision', 'num', 0],
  36183. [[12, 33], 'CIDFontType', 'num', 0],
  36184. [[12, 34], 'CIDCount', 'num', 8720],
  36185. [[12, 35], 'UIDBase', 'num', null],
  36186. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  36187. // before FDArray.
  36188. [[12, 37], 'FDSelect', 'offset', null],
  36189. [[12, 36], 'FDArray', 'offset', null],
  36190. [[12, 38], 'FontName', 'sid', null]
  36191. ];
  36192. var tables = null;
  36193. function CFFTopDict(strings) {
  36194. if (tables === null) {
  36195. tables = CFFDict.createTables(layout);
  36196. }
  36197. CFFDict.call(this, tables, strings);
  36198. this.privateDict = null;
  36199. }
  36200. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  36201. return CFFTopDict;
  36202. })();
  36203. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  36204. var layout = [
  36205. [6, 'BlueValues', 'delta', null],
  36206. [7, 'OtherBlues', 'delta', null],
  36207. [8, 'FamilyBlues', 'delta', null],
  36208. [9, 'FamilyOtherBlues', 'delta', null],
  36209. [[12, 9], 'BlueScale', 'num', 0.039625],
  36210. [[12, 10], 'BlueShift', 'num', 7],
  36211. [[12, 11], 'BlueFuzz', 'num', 1],
  36212. [10, 'StdHW', 'num', null],
  36213. [11, 'StdVW', 'num', null],
  36214. [[12, 12], 'StemSnapH', 'delta', null],
  36215. [[12, 13], 'StemSnapV', 'delta', null],
  36216. [[12, 14], 'ForceBold', 'num', 0],
  36217. [[12, 17], 'LanguageGroup', 'num', 0],
  36218. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  36219. [[12, 19], 'initialRandomSeed', 'num', 0],
  36220. [20, 'defaultWidthX', 'num', 0],
  36221. [21, 'nominalWidthX', 'num', 0],
  36222. [19, 'Subrs', 'offset', null]
  36223. ];
  36224. var tables = null;
  36225. function CFFPrivateDict(strings) {
  36226. if (tables === null) {
  36227. tables = CFFDict.createTables(layout);
  36228. }
  36229. CFFDict.call(this, tables, strings);
  36230. this.subrsIndex = null;
  36231. }
  36232. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  36233. return CFFPrivateDict;
  36234. })();
  36235. var CFFCharsetPredefinedTypes = {
  36236. ISO_ADOBE: 0,
  36237. EXPERT: 1,
  36238. EXPERT_SUBSET: 2
  36239. };
  36240. var CFFCharset = (function CFFCharsetClosure() {
  36241. function CFFCharset(predefined, format, charset, raw) {
  36242. this.predefined = predefined;
  36243. this.format = format;
  36244. this.charset = charset;
  36245. this.raw = raw;
  36246. }
  36247. return CFFCharset;
  36248. })();
  36249. var CFFEncoding = (function CFFEncodingClosure() {
  36250. function CFFEncoding(predefined, format, encoding, raw) {
  36251. this.predefined = predefined;
  36252. this.format = format;
  36253. this.encoding = encoding;
  36254. this.raw = raw;
  36255. }
  36256. return CFFEncoding;
  36257. })();
  36258. var CFFFDSelect = (function CFFFDSelectClosure() {
  36259. function CFFFDSelect(fdSelect, raw) {
  36260. this.fdSelect = fdSelect;
  36261. this.raw = raw;
  36262. }
  36263. CFFFDSelect.prototype = {
  36264. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  36265. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  36266. return -1;
  36267. }
  36268. return this.fdSelect[glyphIndex];
  36269. }
  36270. };
  36271. return CFFFDSelect;
  36272. })();
  36273. // Helper class to keep track of where an offset is within the data and helps
  36274. // filling in that offset once it's known.
  36275. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  36276. function CFFOffsetTracker() {
  36277. this.offsets = Object.create(null);
  36278. }
  36279. CFFOffsetTracker.prototype = {
  36280. isTracking: function CFFOffsetTracker_isTracking(key) {
  36281. return key in this.offsets;
  36282. },
  36283. track: function CFFOffsetTracker_track(key, location) {
  36284. if (key in this.offsets) {
  36285. error('Already tracking location of ' + key);
  36286. }
  36287. this.offsets[key] = location;
  36288. },
  36289. offset: function CFFOffsetTracker_offset(value) {
  36290. for (var key in this.offsets) {
  36291. this.offsets[key] += value;
  36292. }
  36293. },
  36294. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  36295. values,
  36296. output) {
  36297. if (!(key in this.offsets)) {
  36298. error('Not tracking location of ' + key);
  36299. }
  36300. var data = output.data;
  36301. var dataOffset = this.offsets[key];
  36302. var size = 5;
  36303. for (var i = 0, ii = values.length; i < ii; ++i) {
  36304. var offset0 = i * size + dataOffset;
  36305. var offset1 = offset0 + 1;
  36306. var offset2 = offset0 + 2;
  36307. var offset3 = offset0 + 3;
  36308. var offset4 = offset0 + 4;
  36309. // It's easy to screw up offsets so perform this sanity check.
  36310. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  36311. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  36312. error('writing to an offset that is not empty');
  36313. }
  36314. var value = values[i];
  36315. data[offset0] = 0x1d;
  36316. data[offset1] = (value >> 24) & 0xFF;
  36317. data[offset2] = (value >> 16) & 0xFF;
  36318. data[offset3] = (value >> 8) & 0xFF;
  36319. data[offset4] = value & 0xFF;
  36320. }
  36321. }
  36322. };
  36323. return CFFOffsetTracker;
  36324. })();
  36325. // Takes a CFF and converts it to the binary representation.
  36326. var CFFCompiler = (function CFFCompilerClosure() {
  36327. function CFFCompiler(cff) {
  36328. this.cff = cff;
  36329. }
  36330. CFFCompiler.prototype = {
  36331. compile: function CFFCompiler_compile() {
  36332. var cff = this.cff;
  36333. var output = {
  36334. data: [],
  36335. length: 0,
  36336. add: function CFFCompiler_add(data) {
  36337. this.data = this.data.concat(data);
  36338. this.length = this.data.length;
  36339. }
  36340. };
  36341. // Compile the five entries that must be in order.
  36342. var header = this.compileHeader(cff.header);
  36343. output.add(header);
  36344. var nameIndex = this.compileNameIndex(cff.names);
  36345. output.add(nameIndex);
  36346. if (cff.isCIDFont) {
  36347. // The spec is unclear on how font matrices should relate to each other
  36348. // when there is one in the main top dict and the sub top dicts.
  36349. // Windows handles this differently than linux and osx so we have to
  36350. // normalize to work on all.
  36351. // Rules based off of some mailing list discussions:
  36352. // - If main font has a matrix and subfont doesn't, use the main matrix.
  36353. // - If no main font matrix and there is a subfont matrix, use the
  36354. // subfont matrix.
  36355. // - If both have matrices, concat together.
  36356. // - If neither have matrices, use default.
  36357. // To make this work on all platforms we move the top matrix into each
  36358. // sub top dict and concat if necessary.
  36359. if (cff.topDict.hasName('FontMatrix')) {
  36360. var base = cff.topDict.getByName('FontMatrix');
  36361. cff.topDict.removeByName('FontMatrix');
  36362. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  36363. var subDict = cff.fdArray[i];
  36364. var matrix = base.slice(0);
  36365. if (subDict.hasName('FontMatrix')) {
  36366. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  36367. }
  36368. subDict.setByName('FontMatrix', matrix);
  36369. }
  36370. }
  36371. }
  36372. var compiled = this.compileTopDicts([cff.topDict],
  36373. output.length,
  36374. cff.isCIDFont);
  36375. output.add(compiled.output);
  36376. var topDictTracker = compiled.trackers[0];
  36377. var stringIndex = this.compileStringIndex(cff.strings.strings);
  36378. output.add(stringIndex);
  36379. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  36380. output.add(globalSubrIndex);
  36381. // Now start on the other entries that have no specfic order.
  36382. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  36383. if (cff.encoding.predefined) {
  36384. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  36385. output);
  36386. } else {
  36387. var encoding = this.compileEncoding(cff.encoding);
  36388. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  36389. output.add(encoding);
  36390. }
  36391. }
  36392. if (cff.charset && cff.topDict.hasName('charset')) {
  36393. if (cff.charset.predefined) {
  36394. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  36395. output);
  36396. } else {
  36397. var charset = this.compileCharset(cff.charset);
  36398. topDictTracker.setEntryLocation('charset', [output.length], output);
  36399. output.add(charset);
  36400. }
  36401. }
  36402. var charStrings = this.compileCharStrings(cff.charStrings);
  36403. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  36404. output.add(charStrings);
  36405. if (cff.isCIDFont) {
  36406. // For some reason FDSelect must be in front of FDArray on windows. OSX
  36407. // and linux don't seem to care.
  36408. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  36409. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  36410. output.add(fdSelect);
  36411. // It is unclear if the sub font dictionary can have CID related
  36412. // dictionary keys, but the sanitizer doesn't like them so remove them.
  36413. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  36414. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  36415. output.add(compiled.output);
  36416. var fontDictTrackers = compiled.trackers;
  36417. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  36418. }
  36419. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  36420. // If the font data ends with INDEX whose object data is zero-length,
  36421. // the sanitizer will bail out. Add a dummy byte to avoid that.
  36422. output.add([0]);
  36423. return output.data;
  36424. },
  36425. encodeNumber: function CFFCompiler_encodeNumber(value) {
  36426. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  36427. return this.encodeInteger(value);
  36428. } else {
  36429. return this.encodeFloat(value);
  36430. }
  36431. },
  36432. encodeFloat: function CFFCompiler_encodeFloat(num) {
  36433. var value = num.toString();
  36434. // rounding inaccurate doubles
  36435. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  36436. if (m) {
  36437. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  36438. value = (Math.round(num * epsilon) / epsilon).toString();
  36439. }
  36440. var nibbles = '';
  36441. var i, ii;
  36442. for (i = 0, ii = value.length; i < ii; ++i) {
  36443. var a = value[i];
  36444. if (a === 'e') {
  36445. nibbles += value[++i] === '-' ? 'c' : 'b';
  36446. } else if (a === '.') {
  36447. nibbles += 'a';
  36448. } else if (a === '-') {
  36449. nibbles += 'e';
  36450. } else {
  36451. nibbles += a;
  36452. }
  36453. }
  36454. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  36455. var out = [30];
  36456. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  36457. out.push(parseInt(nibbles.substr(i, 2), 16));
  36458. }
  36459. return out;
  36460. },
  36461. encodeInteger: function CFFCompiler_encodeInteger(value) {
  36462. var code;
  36463. if (value >= -107 && value <= 107) {
  36464. code = [value + 139];
  36465. } else if (value >= 108 && value <= 1131) {
  36466. value = [value - 108];
  36467. code = [(value >> 8) + 247, value & 0xFF];
  36468. } else if (value >= -1131 && value <= -108) {
  36469. value = -value - 108;
  36470. code = [(value >> 8) + 251, value & 0xFF];
  36471. } else if (value >= -32768 && value <= 32767) {
  36472. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  36473. } else {
  36474. code = [0x1d,
  36475. (value >> 24) & 0xFF,
  36476. (value >> 16) & 0xFF,
  36477. (value >> 8) & 0xFF,
  36478. value & 0xFF];
  36479. }
  36480. return code;
  36481. },
  36482. compileHeader: function CFFCompiler_compileHeader(header) {
  36483. return [
  36484. header.major,
  36485. header.minor,
  36486. header.hdrSize,
  36487. header.offSize
  36488. ];
  36489. },
  36490. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  36491. var nameIndex = new CFFIndex();
  36492. for (var i = 0, ii = names.length; i < ii; ++i) {
  36493. nameIndex.add(stringToBytes(names[i]));
  36494. }
  36495. return this.compileIndex(nameIndex);
  36496. },
  36497. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  36498. length,
  36499. removeCidKeys) {
  36500. var fontDictTrackers = [];
  36501. var fdArrayIndex = new CFFIndex();
  36502. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36503. var fontDict = dicts[i];
  36504. if (removeCidKeys) {
  36505. fontDict.removeByName('CIDFontVersion');
  36506. fontDict.removeByName('CIDFontRevision');
  36507. fontDict.removeByName('CIDFontType');
  36508. fontDict.removeByName('CIDCount');
  36509. fontDict.removeByName('UIDBase');
  36510. }
  36511. var fontDictTracker = new CFFOffsetTracker();
  36512. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  36513. fontDictTrackers.push(fontDictTracker);
  36514. fdArrayIndex.add(fontDictData);
  36515. fontDictTracker.offset(length);
  36516. }
  36517. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  36518. return {
  36519. trackers: fontDictTrackers,
  36520. output: fdArrayIndex
  36521. };
  36522. },
  36523. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  36524. trackers,
  36525. output) {
  36526. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  36527. var fontDict = dicts[i];
  36528. assert(fontDict.privateDict && fontDict.hasName('Private'),
  36529. 'There must be an private dictionary.');
  36530. var privateDict = fontDict.privateDict;
  36531. var privateDictTracker = new CFFOffsetTracker();
  36532. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  36533. var outputLength = output.length;
  36534. privateDictTracker.offset(outputLength);
  36535. if (!privateDictData.length) {
  36536. // The private dictionary was empty, set the output length to zero to
  36537. // ensure the offset length isn't out of bounds in the eyes of the
  36538. // sanitizer.
  36539. outputLength = 0;
  36540. }
  36541. trackers[i].setEntryLocation('Private',
  36542. [privateDictData.length, outputLength],
  36543. output);
  36544. output.add(privateDictData);
  36545. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  36546. var subrs = this.compileIndex(privateDict.subrsIndex);
  36547. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  36548. output);
  36549. output.add(subrs);
  36550. }
  36551. }
  36552. },
  36553. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  36554. var out = [];
  36555. // The dictionary keys must be in a certain order.
  36556. var order = dict.order;
  36557. for (var i = 0; i < order.length; ++i) {
  36558. var key = order[i];
  36559. if (!(key in dict.values)) {
  36560. continue;
  36561. }
  36562. var values = dict.values[key];
  36563. var types = dict.types[key];
  36564. if (!isArray(types)) {
  36565. types = [types];
  36566. }
  36567. if (!isArray(values)) {
  36568. values = [values];
  36569. }
  36570. // Remove any empty dict values.
  36571. if (values.length === 0) {
  36572. continue;
  36573. }
  36574. for (var j = 0, jj = types.length; j < jj; ++j) {
  36575. var type = types[j];
  36576. var value = values[j];
  36577. switch (type) {
  36578. case 'num':
  36579. case 'sid':
  36580. out = out.concat(this.encodeNumber(value));
  36581. break;
  36582. case 'offset':
  36583. // For offsets we just insert a 32bit integer so we don't have to
  36584. // deal with figuring out the length of the offset when it gets
  36585. // replaced later on by the compiler.
  36586. var name = dict.keyToNameMap[key];
  36587. // Some offsets have the offset and the length, so just record the
  36588. // position of the first one.
  36589. if (!offsetTracker.isTracking(name)) {
  36590. offsetTracker.track(name, out.length);
  36591. }
  36592. out = out.concat([0x1d, 0, 0, 0, 0]);
  36593. break;
  36594. case 'array':
  36595. case 'delta':
  36596. out = out.concat(this.encodeNumber(value));
  36597. for (var k = 1, kk = values.length; k < kk; ++k) {
  36598. out = out.concat(this.encodeNumber(values[k]));
  36599. }
  36600. break;
  36601. default:
  36602. error('Unknown data type of ' + type);
  36603. break;
  36604. }
  36605. }
  36606. out = out.concat(dict.opcodes[key]);
  36607. }
  36608. return out;
  36609. },
  36610. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  36611. var stringIndex = new CFFIndex();
  36612. for (var i = 0, ii = strings.length; i < ii; ++i) {
  36613. stringIndex.add(stringToBytes(strings[i]));
  36614. }
  36615. return this.compileIndex(stringIndex);
  36616. },
  36617. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  36618. var globalSubrIndex = this.cff.globalSubrIndex;
  36619. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  36620. },
  36621. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  36622. return this.compileIndex(charStrings);
  36623. },
  36624. compileCharset: function CFFCompiler_compileCharset(charset) {
  36625. return this.compileTypedArray(charset.raw);
  36626. },
  36627. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  36628. return this.compileTypedArray(encoding.raw);
  36629. },
  36630. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  36631. return this.compileTypedArray(fdSelect);
  36632. },
  36633. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  36634. var out = [];
  36635. for (var i = 0, ii = data.length; i < ii; ++i) {
  36636. out[i] = data[i];
  36637. }
  36638. return out;
  36639. },
  36640. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  36641. trackers = trackers || [];
  36642. var objects = index.objects;
  36643. // First 2 bytes contains the number of objects contained into this index
  36644. var count = objects.length;
  36645. // If there is no object, just create an index. This technically
  36646. // should just be [0, 0] but OTS has an issue with that.
  36647. if (count === 0) {
  36648. return [0, 0, 0];
  36649. }
  36650. var data = [(count >> 8) & 0xFF, count & 0xff];
  36651. var lastOffset = 1, i;
  36652. for (i = 0; i < count; ++i) {
  36653. lastOffset += objects[i].length;
  36654. }
  36655. var offsetSize;
  36656. if (lastOffset < 0x100) {
  36657. offsetSize = 1;
  36658. } else if (lastOffset < 0x10000) {
  36659. offsetSize = 2;
  36660. } else if (lastOffset < 0x1000000) {
  36661. offsetSize = 3;
  36662. } else {
  36663. offsetSize = 4;
  36664. }
  36665. // Next byte contains the offset size use to reference object in the file
  36666. data.push(offsetSize);
  36667. // Add another offset after this one because we need a new offset
  36668. var relativeOffset = 1;
  36669. for (i = 0; i < count + 1; i++) {
  36670. if (offsetSize === 1) {
  36671. data.push(relativeOffset & 0xFF);
  36672. } else if (offsetSize === 2) {
  36673. data.push((relativeOffset >> 8) & 0xFF,
  36674. relativeOffset & 0xFF);
  36675. } else if (offsetSize === 3) {
  36676. data.push((relativeOffset >> 16) & 0xFF,
  36677. (relativeOffset >> 8) & 0xFF,
  36678. relativeOffset & 0xFF);
  36679. } else {
  36680. data.push((relativeOffset >>> 24) & 0xFF,
  36681. (relativeOffset >> 16) & 0xFF,
  36682. (relativeOffset >> 8) & 0xFF,
  36683. relativeOffset & 0xFF);
  36684. }
  36685. if (objects[i]) {
  36686. relativeOffset += objects[i].length;
  36687. }
  36688. }
  36689. for (i = 0; i < count; i++) {
  36690. // Notify the tracker where the object will be offset in the data.
  36691. if (trackers[i]) {
  36692. trackers[i].offset(data.length);
  36693. }
  36694. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  36695. data.push(objects[i][j]);
  36696. }
  36697. }
  36698. return data;
  36699. }
  36700. };
  36701. return CFFCompiler;
  36702. })();
  36703. function _enableSeacAnalysis(enabled) {
  36704. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  36705. }
  36706. // Workaround for seac on Windows.
  36707. (function checkSeacSupport() {
  36708. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  36709. SEAC_ANALYSIS_ENABLED = true;
  36710. }
  36711. })();
  36712. // Workaround for Private Use Area characters in Chrome on Windows
  36713. // http://code.google.com/p/chromium/issues/detail?id=122465
  36714. // https://github.com/mozilla/pdf.js/issues/1689
  36715. (function checkChromeWindows() {
  36716. if (typeof navigator !== 'undefined' &&
  36717. /Windows.*Chrome/.test(navigator.userAgent)) {
  36718. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  36719. }
  36720. })();
  36721. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  36722. exports.CFFCompiler = CFFCompiler;
  36723. exports.CFFIndex = CFFIndex;
  36724. exports.CFFParser = CFFParser;
  36725. exports.CFFStrings = CFFStrings;
  36726. exports.ErrorFont = ErrorFont;
  36727. exports.FontFlags = FontFlags;
  36728. exports.Font = Font;
  36729. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  36730. exports.ToUnicodeMap = ToUnicodeMap;
  36731. exports.Type1Parser = Type1Parser;
  36732. exports.getFontType = getFontType;
  36733. exports._enableSeacAnalysis = _enableSeacAnalysis;
  36734. // TODO refactor to remove cyclic dependency on font_renderer.js
  36735. coreFontRenderer._setCoreFonts(exports);
  36736. }));
  36737. (function (root, factory) {
  36738. {
  36739. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  36740. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  36741. }
  36742. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  36743. var error = sharedUtil.error;
  36744. var info = sharedUtil.info;
  36745. var isArray = sharedUtil.isArray;
  36746. var isBool = sharedUtil.isBool;
  36747. var isDict = corePrimitives.isDict;
  36748. var isStream = corePrimitives.isStream;
  36749. var PostScriptLexer = corePsParser.PostScriptLexer;
  36750. var PostScriptParser = corePsParser.PostScriptParser;
  36751. var PDFFunction = (function PDFFunctionClosure() {
  36752. var CONSTRUCT_SAMPLED = 0;
  36753. var CONSTRUCT_INTERPOLATED = 2;
  36754. var CONSTRUCT_STICHED = 3;
  36755. var CONSTRUCT_POSTSCRIPT = 4;
  36756. return {
  36757. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  36758. str) {
  36759. var i, ii;
  36760. var length = 1;
  36761. for (i = 0, ii = size.length; i < ii; i++) {
  36762. length *= size[i];
  36763. }
  36764. length *= outputSize;
  36765. var array = new Array(length);
  36766. var codeSize = 0;
  36767. var codeBuf = 0;
  36768. // 32 is a valid bps so shifting won't work
  36769. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  36770. var strBytes = str.getBytes((length * bps + 7) / 8);
  36771. var strIdx = 0;
  36772. for (i = 0; i < length; i++) {
  36773. while (codeSize < bps) {
  36774. codeBuf <<= 8;
  36775. codeBuf |= strBytes[strIdx++];
  36776. codeSize += 8;
  36777. }
  36778. codeSize -= bps;
  36779. array[i] = (codeBuf >> codeSize) * sampleMul;
  36780. codeBuf &= (1 << codeSize) - 1;
  36781. }
  36782. return array;
  36783. },
  36784. getIR: function PDFFunction_getIR(xref, fn) {
  36785. var dict = fn.dict;
  36786. if (!dict) {
  36787. dict = fn;
  36788. }
  36789. var types = [this.constructSampled,
  36790. null,
  36791. this.constructInterpolated,
  36792. this.constructStiched,
  36793. this.constructPostScript];
  36794. var typeNum = dict.get('FunctionType');
  36795. var typeFn = types[typeNum];
  36796. if (!typeFn) {
  36797. error('Unknown type of function');
  36798. }
  36799. return typeFn.call(this, fn, dict, xref);
  36800. },
  36801. fromIR: function PDFFunction_fromIR(IR) {
  36802. var type = IR[0];
  36803. switch (type) {
  36804. case CONSTRUCT_SAMPLED:
  36805. return this.constructSampledFromIR(IR);
  36806. case CONSTRUCT_INTERPOLATED:
  36807. return this.constructInterpolatedFromIR(IR);
  36808. case CONSTRUCT_STICHED:
  36809. return this.constructStichedFromIR(IR);
  36810. //case CONSTRUCT_POSTSCRIPT:
  36811. default:
  36812. return this.constructPostScriptFromIR(IR);
  36813. }
  36814. },
  36815. parse: function PDFFunction_parse(xref, fn) {
  36816. var IR = this.getIR(xref, fn);
  36817. return this.fromIR(IR);
  36818. },
  36819. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  36820. if (!isArray(fnObj)) {
  36821. // not an array -- parsing as regular function
  36822. return this.parse(xref, fnObj);
  36823. }
  36824. var fnArray = [];
  36825. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  36826. var obj = xref.fetchIfRef(fnObj[j]);
  36827. fnArray.push(PDFFunction.parse(xref, obj));
  36828. }
  36829. return function (src, srcOffset, dest, destOffset) {
  36830. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  36831. fnArray[i](src, srcOffset, dest, destOffset + i);
  36832. }
  36833. };
  36834. },
  36835. constructSampled: function PDFFunction_constructSampled(str, dict) {
  36836. function toMultiArray(arr) {
  36837. var inputLength = arr.length;
  36838. var out = [];
  36839. var index = 0;
  36840. for (var i = 0; i < inputLength; i += 2) {
  36841. out[index] = [arr[i], arr[i + 1]];
  36842. ++index;
  36843. }
  36844. return out;
  36845. }
  36846. var domain = dict.get('Domain');
  36847. var range = dict.get('Range');
  36848. if (!domain || !range) {
  36849. error('No domain or range');
  36850. }
  36851. var inputSize = domain.length / 2;
  36852. var outputSize = range.length / 2;
  36853. domain = toMultiArray(domain);
  36854. range = toMultiArray(range);
  36855. var size = dict.get('Size');
  36856. var bps = dict.get('BitsPerSample');
  36857. var order = dict.get('Order') || 1;
  36858. if (order !== 1) {
  36859. // No description how cubic spline interpolation works in PDF32000:2008
  36860. // As in poppler, ignoring order, linear interpolation may work as good
  36861. info('No support for cubic spline interpolation: ' + order);
  36862. }
  36863. var encode = dict.get('Encode');
  36864. if (!encode) {
  36865. encode = [];
  36866. for (var i = 0; i < inputSize; ++i) {
  36867. encode.push(0);
  36868. encode.push(size[i] - 1);
  36869. }
  36870. }
  36871. encode = toMultiArray(encode);
  36872. var decode = dict.get('Decode');
  36873. if (!decode) {
  36874. decode = range;
  36875. } else {
  36876. decode = toMultiArray(decode);
  36877. }
  36878. var samples = this.getSampleArray(size, outputSize, bps, str);
  36879. return [
  36880. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  36881. outputSize, Math.pow(2, bps) - 1, range
  36882. ];
  36883. },
  36884. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  36885. // See chapter 3, page 109 of the PDF reference
  36886. function interpolate(x, xmin, xmax, ymin, ymax) {
  36887. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  36888. }
  36889. return function constructSampledFromIRResult(src, srcOffset,
  36890. dest, destOffset) {
  36891. // See chapter 3, page 110 of the PDF reference.
  36892. var m = IR[1];
  36893. var domain = IR[2];
  36894. var encode = IR[3];
  36895. var decode = IR[4];
  36896. var samples = IR[5];
  36897. var size = IR[6];
  36898. var n = IR[7];
  36899. //var mask = IR[8];
  36900. var range = IR[9];
  36901. // Building the cube vertices: its part and sample index
  36902. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  36903. var cubeVertices = 1 << m;
  36904. var cubeN = new Float64Array(cubeVertices);
  36905. var cubeVertex = new Uint32Array(cubeVertices);
  36906. var i, j;
  36907. for (j = 0; j < cubeVertices; j++) {
  36908. cubeN[j] = 1;
  36909. }
  36910. var k = n, pos = 1;
  36911. // Map x_i to y_j for 0 <= i < m using the sampled function.
  36912. for (i = 0; i < m; ++i) {
  36913. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  36914. var domain_2i = domain[i][0];
  36915. var domain_2i_1 = domain[i][1];
  36916. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  36917. domain_2i_1);
  36918. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  36919. // Encode_2i, Encode_2i+1)
  36920. var e = interpolate(xi, domain_2i, domain_2i_1,
  36921. encode[i][0], encode[i][1]);
  36922. // e_i' = min(max(e_i, 0), Size_i - 1)
  36923. var size_i = size[i];
  36924. e = Math.min(Math.max(e, 0), size_i - 1);
  36925. // Adjusting the cube: N and vertex sample index
  36926. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  36927. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  36928. var n1 = e - e0; // (e - e0) / (e1 - e0);
  36929. var offset0 = e0 * k;
  36930. var offset1 = offset0 + k; // e1 * k
  36931. for (j = 0; j < cubeVertices; j++) {
  36932. if (j & pos) {
  36933. cubeN[j] *= n1;
  36934. cubeVertex[j] += offset1;
  36935. } else {
  36936. cubeN[j] *= n0;
  36937. cubeVertex[j] += offset0;
  36938. }
  36939. }
  36940. k *= size_i;
  36941. pos <<= 1;
  36942. }
  36943. for (j = 0; j < n; ++j) {
  36944. // Sum all cube vertices' samples portions
  36945. var rj = 0;
  36946. for (i = 0; i < cubeVertices; i++) {
  36947. rj += samples[cubeVertex[i] + j] * cubeN[i];
  36948. }
  36949. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  36950. // Decode_2j, Decode_2j+1)
  36951. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  36952. // y_j = min(max(r_j, range_2j), range_2j+1)
  36953. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  36954. range[j][1]);
  36955. }
  36956. };
  36957. },
  36958. constructInterpolated: function PDFFunction_constructInterpolated(str,
  36959. dict) {
  36960. var c0 = dict.get('C0') || [0];
  36961. var c1 = dict.get('C1') || [1];
  36962. var n = dict.get('N');
  36963. if (!isArray(c0) || !isArray(c1)) {
  36964. error('Illegal dictionary for interpolated function');
  36965. }
  36966. var length = c0.length;
  36967. var diff = [];
  36968. for (var i = 0; i < length; ++i) {
  36969. diff.push(c1[i] - c0[i]);
  36970. }
  36971. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  36972. },
  36973. constructInterpolatedFromIR:
  36974. function PDFFunction_constructInterpolatedFromIR(IR) {
  36975. var c0 = IR[1];
  36976. var diff = IR[2];
  36977. var n = IR[3];
  36978. var length = diff.length;
  36979. return function constructInterpolatedFromIRResult(src, srcOffset,
  36980. dest, destOffset) {
  36981. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  36982. for (var j = 0; j < length; ++j) {
  36983. dest[destOffset + j] = c0[j] + (x * diff[j]);
  36984. }
  36985. };
  36986. },
  36987. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  36988. var domain = dict.get('Domain');
  36989. if (!domain) {
  36990. error('No domain');
  36991. }
  36992. var inputSize = domain.length / 2;
  36993. if (inputSize !== 1) {
  36994. error('Bad domain for stiched function');
  36995. }
  36996. var fnRefs = dict.get('Functions');
  36997. var fns = [];
  36998. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  36999. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  37000. }
  37001. var bounds = dict.get('Bounds');
  37002. var encode = dict.get('Encode');
  37003. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  37004. },
  37005. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  37006. var domain = IR[1];
  37007. var bounds = IR[2];
  37008. var encode = IR[3];
  37009. var fnsIR = IR[4];
  37010. var fns = [];
  37011. var tmpBuf = new Float32Array(1);
  37012. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  37013. fns.push(PDFFunction.fromIR(fnsIR[i]));
  37014. }
  37015. return function constructStichedFromIRResult(src, srcOffset,
  37016. dest, destOffset) {
  37017. var clip = function constructStichedFromIRClip(v, min, max) {
  37018. if (v > max) {
  37019. v = max;
  37020. } else if (v < min) {
  37021. v = min;
  37022. }
  37023. return v;
  37024. };
  37025. // clip to domain
  37026. var v = clip(src[srcOffset], domain[0], domain[1]);
  37027. // calulate which bound the value is in
  37028. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  37029. if (v < bounds[i]) {
  37030. break;
  37031. }
  37032. }
  37033. // encode value into domain of function
  37034. var dmin = domain[0];
  37035. if (i > 0) {
  37036. dmin = bounds[i - 1];
  37037. }
  37038. var dmax = domain[1];
  37039. if (i < bounds.length) {
  37040. dmax = bounds[i];
  37041. }
  37042. var rmin = encode[2 * i];
  37043. var rmax = encode[2 * i + 1];
  37044. // Prevent the value from becoming NaN as a result
  37045. // of division by zero (fixes issue6113.pdf).
  37046. tmpBuf[0] = dmin === dmax ? rmin :
  37047. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  37048. // call the appropriate function
  37049. fns[i](tmpBuf, 0, dest, destOffset);
  37050. };
  37051. },
  37052. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  37053. xref) {
  37054. var domain = dict.get('Domain');
  37055. var range = dict.get('Range');
  37056. if (!domain) {
  37057. error('No domain.');
  37058. }
  37059. if (!range) {
  37060. error('No range.');
  37061. }
  37062. var lexer = new PostScriptLexer(fn);
  37063. var parser = new PostScriptParser(lexer);
  37064. var code = parser.parse();
  37065. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  37066. },
  37067. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  37068. IR) {
  37069. var domain = IR[1];
  37070. var range = IR[2];
  37071. var code = IR[3];
  37072. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  37073. if (compiled) {
  37074. // Compiled function consists of simple expressions such as addition,
  37075. // subtraction, Math.max, and also contains 'var' and 'return'
  37076. // statements. See the generation in the PostScriptCompiler below.
  37077. /*jshint -W054 */
  37078. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  37079. }
  37080. info('Unable to compile PS function');
  37081. var numOutputs = range.length >> 1;
  37082. var numInputs = domain.length >> 1;
  37083. var evaluator = new PostScriptEvaluator(code);
  37084. // Cache the values for a big speed up, the cache size is limited though
  37085. // since the number of possible values can be huge from a PS function.
  37086. var cache = Object.create(null);
  37087. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  37088. // seen in our tests.
  37089. var MAX_CACHE_SIZE = 2048 * 4;
  37090. var cache_available = MAX_CACHE_SIZE;
  37091. var tmpBuf = new Float32Array(numInputs);
  37092. return function constructPostScriptFromIRResult(src, srcOffset,
  37093. dest, destOffset) {
  37094. var i, value;
  37095. var key = '';
  37096. var input = tmpBuf;
  37097. for (i = 0; i < numInputs; i++) {
  37098. value = src[srcOffset + i];
  37099. input[i] = value;
  37100. key += value + '_';
  37101. }
  37102. var cachedValue = cache[key];
  37103. if (cachedValue !== undefined) {
  37104. dest.set(cachedValue, destOffset);
  37105. return;
  37106. }
  37107. var output = new Float32Array(numOutputs);
  37108. var stack = evaluator.execute(input);
  37109. var stackIndex = stack.length - numOutputs;
  37110. for (i = 0; i < numOutputs; i++) {
  37111. value = stack[stackIndex + i];
  37112. var bound = range[i * 2];
  37113. if (value < bound) {
  37114. value = bound;
  37115. } else {
  37116. bound = range[i * 2 +1];
  37117. if (value > bound) {
  37118. value = bound;
  37119. }
  37120. }
  37121. output[i] = value;
  37122. }
  37123. if (cache_available > 0) {
  37124. cache_available--;
  37125. cache[key] = output;
  37126. }
  37127. dest.set(output, destOffset);
  37128. };
  37129. }
  37130. };
  37131. })();
  37132. function isPDFFunction(v) {
  37133. var fnDict;
  37134. if (typeof v !== 'object') {
  37135. return false;
  37136. } else if (isDict(v)) {
  37137. fnDict = v;
  37138. } else if (isStream(v)) {
  37139. fnDict = v.dict;
  37140. } else {
  37141. return false;
  37142. }
  37143. return fnDict.has('FunctionType');
  37144. }
  37145. var PostScriptStack = (function PostScriptStackClosure() {
  37146. var MAX_STACK_SIZE = 100;
  37147. function PostScriptStack(initialStack) {
  37148. this.stack = !initialStack ? [] :
  37149. Array.prototype.slice.call(initialStack, 0);
  37150. }
  37151. PostScriptStack.prototype = {
  37152. push: function PostScriptStack_push(value) {
  37153. if (this.stack.length >= MAX_STACK_SIZE) {
  37154. error('PostScript function stack overflow.');
  37155. }
  37156. this.stack.push(value);
  37157. },
  37158. pop: function PostScriptStack_pop() {
  37159. if (this.stack.length <= 0) {
  37160. error('PostScript function stack underflow.');
  37161. }
  37162. return this.stack.pop();
  37163. },
  37164. copy: function PostScriptStack_copy(n) {
  37165. if (this.stack.length + n >= MAX_STACK_SIZE) {
  37166. error('PostScript function stack overflow.');
  37167. }
  37168. var stack = this.stack;
  37169. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  37170. stack.push(stack[i]);
  37171. }
  37172. },
  37173. index: function PostScriptStack_index(n) {
  37174. this.push(this.stack[this.stack.length - n - 1]);
  37175. },
  37176. // rotate the last n stack elements p times
  37177. roll: function PostScriptStack_roll(n, p) {
  37178. var stack = this.stack;
  37179. var l = stack.length - n;
  37180. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  37181. for (i = l, j = r; i < j; i++, j--) {
  37182. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37183. }
  37184. for (i = l, j = c - 1; i < j; i++, j--) {
  37185. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37186. }
  37187. for (i = c, j = r; i < j; i++, j--) {
  37188. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  37189. }
  37190. }
  37191. };
  37192. return PostScriptStack;
  37193. })();
  37194. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  37195. function PostScriptEvaluator(operators) {
  37196. this.operators = operators;
  37197. }
  37198. PostScriptEvaluator.prototype = {
  37199. execute: function PostScriptEvaluator_execute(initialStack) {
  37200. var stack = new PostScriptStack(initialStack);
  37201. var counter = 0;
  37202. var operators = this.operators;
  37203. var length = operators.length;
  37204. var operator, a, b;
  37205. while (counter < length) {
  37206. operator = operators[counter++];
  37207. if (typeof operator === 'number') {
  37208. // Operator is really an operand and should be pushed to the stack.
  37209. stack.push(operator);
  37210. continue;
  37211. }
  37212. switch (operator) {
  37213. // non standard ps operators
  37214. case 'jz': // jump if false
  37215. b = stack.pop();
  37216. a = stack.pop();
  37217. if (!a) {
  37218. counter = b;
  37219. }
  37220. break;
  37221. case 'j': // jump
  37222. a = stack.pop();
  37223. counter = a;
  37224. break;
  37225. // all ps operators in alphabetical order (excluding if/ifelse)
  37226. case 'abs':
  37227. a = stack.pop();
  37228. stack.push(Math.abs(a));
  37229. break;
  37230. case 'add':
  37231. b = stack.pop();
  37232. a = stack.pop();
  37233. stack.push(a + b);
  37234. break;
  37235. case 'and':
  37236. b = stack.pop();
  37237. a = stack.pop();
  37238. if (isBool(a) && isBool(b)) {
  37239. stack.push(a && b);
  37240. } else {
  37241. stack.push(a & b);
  37242. }
  37243. break;
  37244. case 'atan':
  37245. a = stack.pop();
  37246. stack.push(Math.atan(a));
  37247. break;
  37248. case 'bitshift':
  37249. b = stack.pop();
  37250. a = stack.pop();
  37251. if (a > 0) {
  37252. stack.push(a << b);
  37253. } else {
  37254. stack.push(a >> b);
  37255. }
  37256. break;
  37257. case 'ceiling':
  37258. a = stack.pop();
  37259. stack.push(Math.ceil(a));
  37260. break;
  37261. case 'copy':
  37262. a = stack.pop();
  37263. stack.copy(a);
  37264. break;
  37265. case 'cos':
  37266. a = stack.pop();
  37267. stack.push(Math.cos(a));
  37268. break;
  37269. case 'cvi':
  37270. a = stack.pop() | 0;
  37271. stack.push(a);
  37272. break;
  37273. case 'cvr':
  37274. // noop
  37275. break;
  37276. case 'div':
  37277. b = stack.pop();
  37278. a = stack.pop();
  37279. stack.push(a / b);
  37280. break;
  37281. case 'dup':
  37282. stack.copy(1);
  37283. break;
  37284. case 'eq':
  37285. b = stack.pop();
  37286. a = stack.pop();
  37287. stack.push(a === b);
  37288. break;
  37289. case 'exch':
  37290. stack.roll(2, 1);
  37291. break;
  37292. case 'exp':
  37293. b = stack.pop();
  37294. a = stack.pop();
  37295. stack.push(Math.pow(a, b));
  37296. break;
  37297. case 'false':
  37298. stack.push(false);
  37299. break;
  37300. case 'floor':
  37301. a = stack.pop();
  37302. stack.push(Math.floor(a));
  37303. break;
  37304. case 'ge':
  37305. b = stack.pop();
  37306. a = stack.pop();
  37307. stack.push(a >= b);
  37308. break;
  37309. case 'gt':
  37310. b = stack.pop();
  37311. a = stack.pop();
  37312. stack.push(a > b);
  37313. break;
  37314. case 'idiv':
  37315. b = stack.pop();
  37316. a = stack.pop();
  37317. stack.push((a / b) | 0);
  37318. break;
  37319. case 'index':
  37320. a = stack.pop();
  37321. stack.index(a);
  37322. break;
  37323. case 'le':
  37324. b = stack.pop();
  37325. a = stack.pop();
  37326. stack.push(a <= b);
  37327. break;
  37328. case 'ln':
  37329. a = stack.pop();
  37330. stack.push(Math.log(a));
  37331. break;
  37332. case 'log':
  37333. a = stack.pop();
  37334. stack.push(Math.log(a) / Math.LN10);
  37335. break;
  37336. case 'lt':
  37337. b = stack.pop();
  37338. a = stack.pop();
  37339. stack.push(a < b);
  37340. break;
  37341. case 'mod':
  37342. b = stack.pop();
  37343. a = stack.pop();
  37344. stack.push(a % b);
  37345. break;
  37346. case 'mul':
  37347. b = stack.pop();
  37348. a = stack.pop();
  37349. stack.push(a * b);
  37350. break;
  37351. case 'ne':
  37352. b = stack.pop();
  37353. a = stack.pop();
  37354. stack.push(a !== b);
  37355. break;
  37356. case 'neg':
  37357. a = stack.pop();
  37358. stack.push(-a);
  37359. break;
  37360. case 'not':
  37361. a = stack.pop();
  37362. if (isBool(a)) {
  37363. stack.push(!a);
  37364. } else {
  37365. stack.push(~a);
  37366. }
  37367. break;
  37368. case 'or':
  37369. b = stack.pop();
  37370. a = stack.pop();
  37371. if (isBool(a) && isBool(b)) {
  37372. stack.push(a || b);
  37373. } else {
  37374. stack.push(a | b);
  37375. }
  37376. break;
  37377. case 'pop':
  37378. stack.pop();
  37379. break;
  37380. case 'roll':
  37381. b = stack.pop();
  37382. a = stack.pop();
  37383. stack.roll(a, b);
  37384. break;
  37385. case 'round':
  37386. a = stack.pop();
  37387. stack.push(Math.round(a));
  37388. break;
  37389. case 'sin':
  37390. a = stack.pop();
  37391. stack.push(Math.sin(a));
  37392. break;
  37393. case 'sqrt':
  37394. a = stack.pop();
  37395. stack.push(Math.sqrt(a));
  37396. break;
  37397. case 'sub':
  37398. b = stack.pop();
  37399. a = stack.pop();
  37400. stack.push(a - b);
  37401. break;
  37402. case 'true':
  37403. stack.push(true);
  37404. break;
  37405. case 'truncate':
  37406. a = stack.pop();
  37407. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  37408. stack.push(a);
  37409. break;
  37410. case 'xor':
  37411. b = stack.pop();
  37412. a = stack.pop();
  37413. if (isBool(a) && isBool(b)) {
  37414. stack.push(a !== b);
  37415. } else {
  37416. stack.push(a ^ b);
  37417. }
  37418. break;
  37419. default:
  37420. error('Unknown operator ' + operator);
  37421. break;
  37422. }
  37423. }
  37424. return stack.stack;
  37425. }
  37426. };
  37427. return PostScriptEvaluator;
  37428. })();
  37429. // Most of the PDFs functions consist of simple operations such as:
  37430. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  37431. //
  37432. // We can compile most of such programs, and at the same moment, we can
  37433. // optimize some expressions using basic math properties. Keeping track of
  37434. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  37435. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  37436. function AstNode(type) {
  37437. this.type = type;
  37438. }
  37439. AstNode.prototype.visit = function (visitor) {
  37440. throw new Error('abstract method');
  37441. };
  37442. function AstArgument(index, min, max) {
  37443. AstNode.call(this, 'args');
  37444. this.index = index;
  37445. this.min = min;
  37446. this.max = max;
  37447. }
  37448. AstArgument.prototype = Object.create(AstNode.prototype);
  37449. AstArgument.prototype.visit = function (visitor) {
  37450. visitor.visitArgument(this);
  37451. };
  37452. function AstLiteral(number) {
  37453. AstNode.call(this, 'literal');
  37454. this.number = number;
  37455. this.min = number;
  37456. this.max = number;
  37457. }
  37458. AstLiteral.prototype = Object.create(AstNode.prototype);
  37459. AstLiteral.prototype.visit = function (visitor) {
  37460. visitor.visitLiteral(this);
  37461. };
  37462. function AstBinaryOperation(op, arg1, arg2, min, max) {
  37463. AstNode.call(this, 'binary');
  37464. this.op = op;
  37465. this.arg1 = arg1;
  37466. this.arg2 = arg2;
  37467. this.min = min;
  37468. this.max = max;
  37469. }
  37470. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  37471. AstBinaryOperation.prototype.visit = function (visitor) {
  37472. visitor.visitBinaryOperation(this);
  37473. };
  37474. function AstMin(arg, max) {
  37475. AstNode.call(this, 'max');
  37476. this.arg = arg;
  37477. this.min = arg.min;
  37478. this.max = max;
  37479. }
  37480. AstMin.prototype = Object.create(AstNode.prototype);
  37481. AstMin.prototype.visit = function (visitor) {
  37482. visitor.visitMin(this);
  37483. };
  37484. function AstVariable(index, min, max) {
  37485. AstNode.call(this, 'var');
  37486. this.index = index;
  37487. this.min = min;
  37488. this.max = max;
  37489. }
  37490. AstVariable.prototype = Object.create(AstNode.prototype);
  37491. AstVariable.prototype.visit = function (visitor) {
  37492. visitor.visitVariable(this);
  37493. };
  37494. function AstVariableDefinition(variable, arg) {
  37495. AstNode.call(this, 'definition');
  37496. this.variable = variable;
  37497. this.arg = arg;
  37498. }
  37499. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  37500. AstVariableDefinition.prototype.visit = function (visitor) {
  37501. visitor.visitVariableDefinition(this);
  37502. };
  37503. function ExpressionBuilderVisitor() {
  37504. this.parts = [];
  37505. }
  37506. ExpressionBuilderVisitor.prototype = {
  37507. visitArgument: function (arg) {
  37508. this.parts.push('Math.max(', arg.min, ', Math.min(',
  37509. arg.max, ', src[srcOffset + ', arg.index, ']))');
  37510. },
  37511. visitVariable: function (variable) {
  37512. this.parts.push('v', variable.index);
  37513. },
  37514. visitLiteral: function (literal) {
  37515. this.parts.push(literal.number);
  37516. },
  37517. visitBinaryOperation: function (operation) {
  37518. this.parts.push('(');
  37519. operation.arg1.visit(this);
  37520. this.parts.push(' ', operation.op, ' ');
  37521. operation.arg2.visit(this);
  37522. this.parts.push(')');
  37523. },
  37524. visitVariableDefinition: function (definition) {
  37525. this.parts.push('var ');
  37526. definition.variable.visit(this);
  37527. this.parts.push(' = ');
  37528. definition.arg.visit(this);
  37529. this.parts.push(';');
  37530. },
  37531. visitMin: function (max) {
  37532. this.parts.push('Math.min(');
  37533. max.arg.visit(this);
  37534. this.parts.push(', ', max.max, ')');
  37535. },
  37536. toString: function () {
  37537. return this.parts.join('');
  37538. }
  37539. };
  37540. function buildAddOperation(num1, num2) {
  37541. if (num2.type === 'literal' && num2.number === 0) {
  37542. // optimization: second operand is 0
  37543. return num1;
  37544. }
  37545. if (num1.type === 'literal' && num1.number === 0) {
  37546. // optimization: first operand is 0
  37547. return num2;
  37548. }
  37549. if (num2.type === 'literal' && num1.type === 'literal') {
  37550. // optimization: operands operand are literals
  37551. return new AstLiteral(num1.number + num2.number);
  37552. }
  37553. return new AstBinaryOperation('+', num1, num2,
  37554. num1.min + num2.min, num1.max + num2.max);
  37555. }
  37556. function buildMulOperation(num1, num2) {
  37557. if (num2.type === 'literal') {
  37558. // optimization: second operands is a literal...
  37559. if (num2.number === 0) {
  37560. return new AstLiteral(0); // and it's 0
  37561. } else if (num2.number === 1) {
  37562. return num1; // and it's 1
  37563. } else if (num1.type === 'literal') {
  37564. // ... and first operands is a literal too
  37565. return new AstLiteral(num1.number * num2.number);
  37566. }
  37567. }
  37568. if (num1.type === 'literal') {
  37569. // optimization: first operands is a literal...
  37570. if (num1.number === 0) {
  37571. return new AstLiteral(0); // and it's 0
  37572. } else if (num1.number === 1) {
  37573. return num2; // and it's 1
  37574. }
  37575. }
  37576. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  37577. num1.max * num2.min, num1.max * num2.max);
  37578. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  37579. num1.max * num2.min, num1.max * num2.max);
  37580. return new AstBinaryOperation('*', num1, num2, min, max);
  37581. }
  37582. function buildSubOperation(num1, num2) {
  37583. if (num2.type === 'literal') {
  37584. // optimization: second operands is a literal...
  37585. if (num2.number === 0) {
  37586. return num1; // ... and it's 0
  37587. } else if (num1.type === 'literal') {
  37588. // ... and first operands is a literal too
  37589. return new AstLiteral(num1.number - num2.number);
  37590. }
  37591. }
  37592. if (num2.type === 'binary' && num2.op === '-' &&
  37593. num1.type === 'literal' && num1.number === 1 &&
  37594. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  37595. // optimization for case: 1 - (1 - x)
  37596. return num2.arg2;
  37597. }
  37598. return new AstBinaryOperation('-', num1, num2,
  37599. num1.min - num2.max, num1.max - num2.min);
  37600. }
  37601. function buildMinOperation(num1, max) {
  37602. if (num1.min >= max) {
  37603. // optimization: num1 min value is not less than required max
  37604. return new AstLiteral(max); // just returning max
  37605. } else if (num1.max <= max) {
  37606. // optimization: num1 max value is not greater than required max
  37607. return num1; // just returning an argument
  37608. }
  37609. return new AstMin(num1, max);
  37610. }
  37611. function PostScriptCompiler() {}
  37612. PostScriptCompiler.prototype = {
  37613. compile: function PostScriptCompiler_compile(code, domain, range) {
  37614. var stack = [];
  37615. var i, ii;
  37616. var instructions = [];
  37617. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  37618. var lastRegister = 0;
  37619. var n, j;
  37620. var num1, num2, ast1, ast2, tmpVar, item;
  37621. for (i = 0; i < inputSize; i++) {
  37622. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  37623. }
  37624. for (i = 0, ii = code.length; i < ii; i++) {
  37625. item = code[i];
  37626. if (typeof item === 'number') {
  37627. stack.push(new AstLiteral(item));
  37628. continue;
  37629. }
  37630. switch (item) {
  37631. case 'add':
  37632. if (stack.length < 2) {
  37633. return null;
  37634. }
  37635. num2 = stack.pop();
  37636. num1 = stack.pop();
  37637. stack.push(buildAddOperation(num1, num2));
  37638. break;
  37639. case 'cvr':
  37640. if (stack.length < 1) {
  37641. return null;
  37642. }
  37643. break;
  37644. case 'mul':
  37645. if (stack.length < 2) {
  37646. return null;
  37647. }
  37648. num2 = stack.pop();
  37649. num1 = stack.pop();
  37650. stack.push(buildMulOperation(num1, num2));
  37651. break;
  37652. case 'sub':
  37653. if (stack.length < 2) {
  37654. return null;
  37655. }
  37656. num2 = stack.pop();
  37657. num1 = stack.pop();
  37658. stack.push(buildSubOperation(num1, num2));
  37659. break;
  37660. case 'exch':
  37661. if (stack.length < 2) {
  37662. return null;
  37663. }
  37664. ast1 = stack.pop(); ast2 = stack.pop();
  37665. stack.push(ast1, ast2);
  37666. break;
  37667. case 'pop':
  37668. if (stack.length < 1) {
  37669. return null;
  37670. }
  37671. stack.pop();
  37672. break;
  37673. case 'index':
  37674. if (stack.length < 1) {
  37675. return null;
  37676. }
  37677. num1 = stack.pop();
  37678. if (num1.type !== 'literal') {
  37679. return null;
  37680. }
  37681. n = num1.number;
  37682. if (n < 0 || (n|0) !== n || stack.length < n) {
  37683. return null;
  37684. }
  37685. ast1 = stack[stack.length - n - 1];
  37686. if (ast1.type === 'literal' || ast1.type === 'var') {
  37687. stack.push(ast1);
  37688. break;
  37689. }
  37690. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37691. stack[stack.length - n - 1] = tmpVar;
  37692. stack.push(tmpVar);
  37693. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37694. break;
  37695. case 'dup':
  37696. if (stack.length < 1) {
  37697. return null;
  37698. }
  37699. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  37700. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  37701. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  37702. // special case of the commands sequence for the min operation
  37703. num1 = stack.pop();
  37704. stack.push(buildMinOperation(num1, code[i + 1]));
  37705. i += 6;
  37706. break;
  37707. }
  37708. ast1 = stack[stack.length - 1];
  37709. if (ast1.type === 'literal' || ast1.type === 'var') {
  37710. // we don't have to save into intermediate variable a literal or
  37711. // variable.
  37712. stack.push(ast1);
  37713. break;
  37714. }
  37715. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  37716. stack[stack.length - 1] = tmpVar;
  37717. stack.push(tmpVar);
  37718. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  37719. break;
  37720. case 'roll':
  37721. if (stack.length < 2) {
  37722. return null;
  37723. }
  37724. num2 = stack.pop();
  37725. num1 = stack.pop();
  37726. if (num2.type !== 'literal' || num1.type !== 'literal') {
  37727. // both roll operands must be numbers
  37728. return null;
  37729. }
  37730. j = num2.number;
  37731. n = num1.number;
  37732. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  37733. // ... and integers
  37734. return null;
  37735. }
  37736. j = ((j % n) + n) % n;
  37737. if (j === 0) {
  37738. break; // just skipping -- there are nothing to rotate
  37739. }
  37740. Array.prototype.push.apply(stack,
  37741. stack.splice(stack.length - n, n - j));
  37742. break;
  37743. default:
  37744. return null; // unsupported operator
  37745. }
  37746. }
  37747. if (stack.length !== outputSize) {
  37748. return null;
  37749. }
  37750. var result = [];
  37751. instructions.forEach(function (instruction) {
  37752. var statementBuilder = new ExpressionBuilderVisitor();
  37753. instruction.visit(statementBuilder);
  37754. result.push(statementBuilder.toString());
  37755. });
  37756. stack.forEach(function (expr, i) {
  37757. var statementBuilder = new ExpressionBuilderVisitor();
  37758. expr.visit(statementBuilder);
  37759. var min = range[i * 2], max = range[i * 2 + 1];
  37760. var out = [statementBuilder.toString()];
  37761. if (min > expr.min) {
  37762. out.unshift('Math.max(', min, ', ');
  37763. out.push(')');
  37764. }
  37765. if (max < expr.max) {
  37766. out.unshift('Math.min(', max, ', ');
  37767. out.push(')');
  37768. }
  37769. out.unshift('dest[destOffset + ', i, '] = ');
  37770. out.push(';');
  37771. result.push(out.join(''));
  37772. });
  37773. return result.join('\n');
  37774. }
  37775. };
  37776. return PostScriptCompiler;
  37777. })();
  37778. exports.isPDFFunction = isPDFFunction;
  37779. exports.PDFFunction = PDFFunction;
  37780. exports.PostScriptEvaluator = PostScriptEvaluator;
  37781. exports.PostScriptCompiler = PostScriptCompiler;
  37782. }));
  37783. (function (root, factory) {
  37784. {
  37785. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  37786. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  37787. }
  37788. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  37789. coreStream) {
  37790. var error = sharedUtil.error;
  37791. var info = sharedUtil.info;
  37792. var isArray = sharedUtil.isArray;
  37793. var isString = sharedUtil.isString;
  37794. var shadow = sharedUtil.shadow;
  37795. var warn = sharedUtil.warn;
  37796. var isDict = corePrimitives.isDict;
  37797. var isName = corePrimitives.isName;
  37798. var isStream = corePrimitives.isStream;
  37799. var PDFFunction = coreFunction.PDFFunction;
  37800. var coreImage; // see _setCoreImage below
  37801. var PDFImage; // = coreImage.PDFImage;
  37802. var ColorSpace = (function ColorSpaceClosure() {
  37803. // Constructor should define this.numComps, this.defaultColor, this.name
  37804. function ColorSpace() {
  37805. error('should not call ColorSpace constructor');
  37806. }
  37807. ColorSpace.prototype = {
  37808. /**
  37809. * Converts the color value to the RGB color. The color components are
  37810. * located in the src array starting from the srcOffset. Returns the array
  37811. * of the rgb components, each value ranging from [0,255].
  37812. */
  37813. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  37814. var rgb = new Uint8Array(3);
  37815. this.getRgbItem(src, srcOffset, rgb, 0);
  37816. return rgb;
  37817. },
  37818. /**
  37819. * Converts the color value to the RGB color, similar to the getRgb method.
  37820. * The result placed into the dest array starting from the destOffset.
  37821. */
  37822. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  37823. dest, destOffset) {
  37824. error('Should not call ColorSpace.getRgbItem');
  37825. },
  37826. /**
  37827. * Converts the specified number of the color values to the RGB colors.
  37828. * The colors are located in the src array starting from the srcOffset.
  37829. * The result is placed into the dest array starting from the destOffset.
  37830. * The src array items shall be in [0,2^bits) range, the dest array items
  37831. * will be in [0,255] range. alpha01 indicates how many alpha components
  37832. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  37833. * array).
  37834. */
  37835. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  37836. dest, destOffset, bits,
  37837. alpha01) {
  37838. error('Should not call ColorSpace.getRgbBuffer');
  37839. },
  37840. /**
  37841. * Determines the number of bytes required to store the result of the
  37842. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  37843. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  37844. */
  37845. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  37846. alpha01) {
  37847. error('Should not call ColorSpace.getOutputLength');
  37848. },
  37849. /**
  37850. * Returns true if source data will be equal the result/output data.
  37851. */
  37852. isPassthrough: function ColorSpace_isPassthrough(bits) {
  37853. return false;
  37854. },
  37855. /**
  37856. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  37857. * how many alpha components there are in the dest array; it will be either
  37858. * 0 (RGB array) or 1 (RGBA array).
  37859. */
  37860. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  37861. originalHeight, width, height,
  37862. actualHeight, bpc, comps, alpha01) {
  37863. var count = originalWidth * originalHeight;
  37864. var rgbBuf = null;
  37865. var numComponentColors = 1 << bpc;
  37866. var needsResizing = originalHeight !== height || originalWidth !== width;
  37867. var i, ii;
  37868. if (this.isPassthrough(bpc)) {
  37869. rgbBuf = comps;
  37870. } else if (this.numComps === 1 && count > numComponentColors &&
  37871. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  37872. // Optimization: create a color map when there is just one component and
  37873. // we are converting more colors than the size of the color map. We
  37874. // don't build the map if the colorspace is gray or rgb since those
  37875. // methods are faster than building a map. This mainly offers big speed
  37876. // ups for indexed and alternate colorspaces.
  37877. //
  37878. // TODO it may be worth while to cache the color map. While running
  37879. // testing I never hit a cache so I will leave that out for now (perhaps
  37880. // we are reparsing colorspaces too much?).
  37881. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  37882. new Uint16Array(numComponentColors);
  37883. var key;
  37884. for (i = 0; i < numComponentColors; i++) {
  37885. allColors[i] = i;
  37886. }
  37887. var colorMap = new Uint8Array(numComponentColors * 3);
  37888. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  37889. /* alpha01 = */ 0);
  37890. var destPos, rgbPos;
  37891. if (!needsResizing) {
  37892. // Fill in the RGB values directly into |dest|.
  37893. destPos = 0;
  37894. for (i = 0; i < count; ++i) {
  37895. key = comps[i] * 3;
  37896. dest[destPos++] = colorMap[key];
  37897. dest[destPos++] = colorMap[key + 1];
  37898. dest[destPos++] = colorMap[key + 2];
  37899. destPos += alpha01;
  37900. }
  37901. } else {
  37902. rgbBuf = new Uint8Array(count * 3);
  37903. rgbPos = 0;
  37904. for (i = 0; i < count; ++i) {
  37905. key = comps[i] * 3;
  37906. rgbBuf[rgbPos++] = colorMap[key];
  37907. rgbBuf[rgbPos++] = colorMap[key + 1];
  37908. rgbBuf[rgbPos++] = colorMap[key + 2];
  37909. }
  37910. }
  37911. } else {
  37912. if (!needsResizing) {
  37913. // Fill in the RGB values directly into |dest|.
  37914. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  37915. alpha01);
  37916. } else {
  37917. rgbBuf = new Uint8Array(count * 3);
  37918. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  37919. /* alpha01 = */ 0);
  37920. }
  37921. }
  37922. if (rgbBuf) {
  37923. if (needsResizing) {
  37924. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  37925. height, dest, alpha01);
  37926. } else {
  37927. rgbPos = 0;
  37928. destPos = 0;
  37929. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  37930. dest[destPos++] = rgbBuf[rgbPos++];
  37931. dest[destPos++] = rgbBuf[rgbPos++];
  37932. dest[destPos++] = rgbBuf[rgbPos++];
  37933. destPos += alpha01;
  37934. }
  37935. }
  37936. }
  37937. },
  37938. /**
  37939. * True if the colorspace has components in the default range of [0, 1].
  37940. * This should be true for all colorspaces except for lab color spaces
  37941. * which are [0,100], [-128, 127], [-128, 127].
  37942. */
  37943. usesZeroToOneRange: true
  37944. };
  37945. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  37946. var IR = ColorSpace.parseToIR(cs, xref, res);
  37947. if (IR instanceof AlternateCS) {
  37948. return IR;
  37949. }
  37950. return ColorSpace.fromIR(IR);
  37951. };
  37952. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  37953. var name = isArray(IR) ? IR[0] : IR;
  37954. var whitePoint, blackPoint, gamma;
  37955. switch (name) {
  37956. case 'DeviceGrayCS':
  37957. return this.singletons.gray;
  37958. case 'DeviceRgbCS':
  37959. return this.singletons.rgb;
  37960. case 'DeviceCmykCS':
  37961. return this.singletons.cmyk;
  37962. case 'CalGrayCS':
  37963. whitePoint = IR[1];
  37964. blackPoint = IR[2];
  37965. gamma = IR[3];
  37966. return new CalGrayCS(whitePoint, blackPoint, gamma);
  37967. case 'CalRGBCS':
  37968. whitePoint = IR[1];
  37969. blackPoint = IR[2];
  37970. gamma = IR[3];
  37971. var matrix = IR[4];
  37972. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  37973. case 'PatternCS':
  37974. var basePatternCS = IR[1];
  37975. if (basePatternCS) {
  37976. basePatternCS = ColorSpace.fromIR(basePatternCS);
  37977. }
  37978. return new PatternCS(basePatternCS);
  37979. case 'IndexedCS':
  37980. var baseIndexedCS = IR[1];
  37981. var hiVal = IR[2];
  37982. var lookup = IR[3];
  37983. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  37984. case 'AlternateCS':
  37985. var numComps = IR[1];
  37986. var alt = IR[2];
  37987. var tintFnIR = IR[3];
  37988. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  37989. PDFFunction.fromIR(tintFnIR));
  37990. case 'LabCS':
  37991. whitePoint = IR[1];
  37992. blackPoint = IR[2];
  37993. var range = IR[3];
  37994. return new LabCS(whitePoint, blackPoint, range);
  37995. default:
  37996. error('Unknown name ' + name);
  37997. }
  37998. return null;
  37999. };
  38000. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38001. if (isName(cs)) {
  38002. var colorSpaces = res.get('ColorSpace');
  38003. if (isDict(colorSpaces)) {
  38004. var refcs = colorSpaces.get(cs.name);
  38005. if (refcs) {
  38006. cs = refcs;
  38007. }
  38008. }
  38009. }
  38010. cs = xref.fetchIfRef(cs);
  38011. var mode;
  38012. if (isName(cs)) {
  38013. mode = cs.name;
  38014. this.mode = mode;
  38015. switch (mode) {
  38016. case 'DeviceGray':
  38017. case 'G':
  38018. return 'DeviceGrayCS';
  38019. case 'DeviceRGB':
  38020. case 'RGB':
  38021. return 'DeviceRgbCS';
  38022. case 'DeviceCMYK':
  38023. case 'CMYK':
  38024. return 'DeviceCmykCS';
  38025. case 'Pattern':
  38026. return ['PatternCS', null];
  38027. default:
  38028. error('unrecognized colorspace ' + mode);
  38029. }
  38030. } else if (isArray(cs)) {
  38031. mode = xref.fetchIfRef(cs[0]).name;
  38032. this.mode = mode;
  38033. var numComps, params, alt, whitePoint, blackPoint, gamma;
  38034. switch (mode) {
  38035. case 'DeviceGray':
  38036. case 'G':
  38037. return 'DeviceGrayCS';
  38038. case 'DeviceRGB':
  38039. case 'RGB':
  38040. return 'DeviceRgbCS';
  38041. case 'DeviceCMYK':
  38042. case 'CMYK':
  38043. return 'DeviceCmykCS';
  38044. case 'CalGray':
  38045. params = xref.fetchIfRef(cs[1]);
  38046. whitePoint = params.get('WhitePoint');
  38047. blackPoint = params.get('BlackPoint');
  38048. gamma = params.get('Gamma');
  38049. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38050. case 'CalRGB':
  38051. params = xref.fetchIfRef(cs[1]);
  38052. whitePoint = params.get('WhitePoint');
  38053. blackPoint = params.get('BlackPoint');
  38054. gamma = params.get('Gamma');
  38055. var matrix = params.get('Matrix');
  38056. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38057. case 'ICCBased':
  38058. var stream = xref.fetchIfRef(cs[1]);
  38059. var dict = stream.dict;
  38060. numComps = dict.get('N');
  38061. alt = dict.get('Alternate');
  38062. if (alt) {
  38063. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38064. // Parse the /Alternate CS to ensure that the number of components
  38065. // are correct, and also (indirectly) that it is not a PatternCS.
  38066. var altCS = ColorSpace.fromIR(altIR);
  38067. if (altCS.numComps === numComps) {
  38068. return altIR;
  38069. }
  38070. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38071. }
  38072. if (numComps === 1) {
  38073. return 'DeviceGrayCS';
  38074. } else if (numComps === 3) {
  38075. return 'DeviceRgbCS';
  38076. } else if (numComps === 4) {
  38077. return 'DeviceCmykCS';
  38078. }
  38079. break;
  38080. case 'Pattern':
  38081. var basePatternCS = cs[1] || null;
  38082. if (basePatternCS) {
  38083. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38084. }
  38085. return ['PatternCS', basePatternCS];
  38086. case 'Indexed':
  38087. case 'I':
  38088. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38089. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38090. var lookup = xref.fetchIfRef(cs[3]);
  38091. if (isStream(lookup)) {
  38092. lookup = lookup.getBytes();
  38093. }
  38094. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38095. case 'Separation':
  38096. case 'DeviceN':
  38097. var name = xref.fetchIfRef(cs[1]);
  38098. numComps = 1;
  38099. if (isName(name)) {
  38100. numComps = 1;
  38101. } else if (isArray(name)) {
  38102. numComps = name.length;
  38103. }
  38104. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38105. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38106. return ['AlternateCS', numComps, alt, tintFnIR];
  38107. case 'Lab':
  38108. params = xref.fetchIfRef(cs[1]);
  38109. whitePoint = params.get('WhitePoint');
  38110. blackPoint = params.get('BlackPoint');
  38111. var range = params.get('Range');
  38112. return ['LabCS', whitePoint, blackPoint, range];
  38113. default:
  38114. error('unimplemented color space object "' + mode + '"');
  38115. }
  38116. } else {
  38117. error('unrecognized color space object: "' + cs + '"');
  38118. }
  38119. return null;
  38120. };
  38121. /**
  38122. * Checks if a decode map matches the default decode map for a color space.
  38123. * This handles the general decode maps where there are two values per
  38124. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38125. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38126. * slightly different.
  38127. * @param {Array} decode Decode map (usually from an image).
  38128. * @param {Number} n Number of components the color space has.
  38129. */
  38130. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38131. if (!isArray(decode)) {
  38132. return true;
  38133. }
  38134. if (n * 2 !== decode.length) {
  38135. warn('The decode map is not the correct length');
  38136. return true;
  38137. }
  38138. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38139. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38140. return false;
  38141. }
  38142. }
  38143. return true;
  38144. };
  38145. ColorSpace.singletons = {
  38146. get gray() {
  38147. return shadow(this, 'gray', new DeviceGrayCS());
  38148. },
  38149. get rgb() {
  38150. return shadow(this, 'rgb', new DeviceRgbCS());
  38151. },
  38152. get cmyk() {
  38153. return shadow(this, 'cmyk', new DeviceCmykCS());
  38154. }
  38155. };
  38156. return ColorSpace;
  38157. })();
  38158. /**
  38159. * Alternate color space handles both Separation and DeviceN color spaces. A
  38160. * Separation color space is actually just a DeviceN with one color component.
  38161. * Both color spaces use a tinting function to convert colors to a base color
  38162. * space.
  38163. */
  38164. var AlternateCS = (function AlternateCSClosure() {
  38165. function AlternateCS(numComps, base, tintFn) {
  38166. this.name = 'Alternate';
  38167. this.numComps = numComps;
  38168. this.defaultColor = new Float32Array(numComps);
  38169. for (var i = 0; i < numComps; ++i) {
  38170. this.defaultColor[i] = 1;
  38171. }
  38172. this.base = base;
  38173. this.tintFn = tintFn;
  38174. this.tmpBuf = new Float32Array(base.numComps);
  38175. }
  38176. AlternateCS.prototype = {
  38177. getRgb: ColorSpace.prototype.getRgb,
  38178. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38179. dest, destOffset) {
  38180. var tmpBuf = this.tmpBuf;
  38181. this.tintFn(src, srcOffset, tmpBuf, 0);
  38182. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38183. },
  38184. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38185. dest, destOffset, bits,
  38186. alpha01) {
  38187. var tintFn = this.tintFn;
  38188. var base = this.base;
  38189. var scale = 1 / ((1 << bits) - 1);
  38190. var baseNumComps = base.numComps;
  38191. var usesZeroToOneRange = base.usesZeroToOneRange;
  38192. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38193. alpha01 === 0;
  38194. var pos = isPassthrough ? destOffset : 0;
  38195. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38196. var numComps = this.numComps;
  38197. var scaled = new Float32Array(numComps);
  38198. var tinted = new Float32Array(baseNumComps);
  38199. var i, j;
  38200. if (usesZeroToOneRange) {
  38201. for (i = 0; i < count; i++) {
  38202. for (j = 0; j < numComps; j++) {
  38203. scaled[j] = src[srcOffset++] * scale;
  38204. }
  38205. tintFn(scaled, 0, tinted, 0);
  38206. for (j = 0; j < baseNumComps; j++) {
  38207. baseBuf[pos++] = tinted[j] * 255;
  38208. }
  38209. }
  38210. } else {
  38211. for (i = 0; i < count; i++) {
  38212. for (j = 0; j < numComps; j++) {
  38213. scaled[j] = src[srcOffset++] * scale;
  38214. }
  38215. tintFn(scaled, 0, tinted, 0);
  38216. base.getRgbItem(tinted, 0, baseBuf, pos);
  38217. pos += baseNumComps;
  38218. }
  38219. }
  38220. if (!isPassthrough) {
  38221. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38222. }
  38223. },
  38224. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38225. alpha01) {
  38226. return this.base.getOutputLength(inputLength *
  38227. this.base.numComps / this.numComps,
  38228. alpha01);
  38229. },
  38230. isPassthrough: ColorSpace.prototype.isPassthrough,
  38231. fillRgb: ColorSpace.prototype.fillRgb,
  38232. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38233. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38234. },
  38235. usesZeroToOneRange: true
  38236. };
  38237. return AlternateCS;
  38238. })();
  38239. var PatternCS = (function PatternCSClosure() {
  38240. function PatternCS(baseCS) {
  38241. this.name = 'Pattern';
  38242. this.base = baseCS;
  38243. }
  38244. PatternCS.prototype = {};
  38245. return PatternCS;
  38246. })();
  38247. var IndexedCS = (function IndexedCSClosure() {
  38248. function IndexedCS(base, highVal, lookup) {
  38249. this.name = 'Indexed';
  38250. this.numComps = 1;
  38251. this.defaultColor = new Uint8Array([0]);
  38252. this.base = base;
  38253. this.highVal = highVal;
  38254. var baseNumComps = base.numComps;
  38255. var length = baseNumComps * highVal;
  38256. var lookupArray;
  38257. if (isStream(lookup)) {
  38258. lookupArray = new Uint8Array(length);
  38259. var bytes = lookup.getBytes(length);
  38260. lookupArray.set(bytes);
  38261. } else if (isString(lookup)) {
  38262. lookupArray = new Uint8Array(length);
  38263. for (var i = 0; i < length; ++i) {
  38264. lookupArray[i] = lookup.charCodeAt(i);
  38265. }
  38266. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38267. lookupArray = lookup;
  38268. } else {
  38269. error('Unrecognized lookup table: ' + lookup);
  38270. }
  38271. this.lookup = lookupArray;
  38272. }
  38273. IndexedCS.prototype = {
  38274. getRgb: ColorSpace.prototype.getRgb,
  38275. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38276. dest, destOffset) {
  38277. var numComps = this.base.numComps;
  38278. var start = src[srcOffset] * numComps;
  38279. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38280. },
  38281. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38282. dest, destOffset, bits,
  38283. alpha01) {
  38284. var base = this.base;
  38285. var numComps = base.numComps;
  38286. var outputDelta = base.getOutputLength(numComps, alpha01);
  38287. var lookup = this.lookup;
  38288. for (var i = 0; i < count; ++i) {
  38289. var lookupPos = src[srcOffset++] * numComps;
  38290. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38291. destOffset += outputDelta;
  38292. }
  38293. },
  38294. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38295. return this.base.getOutputLength(inputLength * this.base.numComps,
  38296. alpha01);
  38297. },
  38298. isPassthrough: ColorSpace.prototype.isPassthrough,
  38299. fillRgb: ColorSpace.prototype.fillRgb,
  38300. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38301. // indexed color maps shouldn't be changed
  38302. return true;
  38303. },
  38304. usesZeroToOneRange: true
  38305. };
  38306. return IndexedCS;
  38307. })();
  38308. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38309. function DeviceGrayCS() {
  38310. this.name = 'DeviceGray';
  38311. this.numComps = 1;
  38312. this.defaultColor = new Float32Array([0]);
  38313. }
  38314. DeviceGrayCS.prototype = {
  38315. getRgb: ColorSpace.prototype.getRgb,
  38316. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38317. dest, destOffset) {
  38318. var c = (src[srcOffset] * 255) | 0;
  38319. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38320. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38321. },
  38322. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38323. dest, destOffset, bits,
  38324. alpha01) {
  38325. var scale = 255 / ((1 << bits) - 1);
  38326. var j = srcOffset, q = destOffset;
  38327. for (var i = 0; i < count; ++i) {
  38328. var c = (scale * src[j++]) | 0;
  38329. dest[q++] = c;
  38330. dest[q++] = c;
  38331. dest[q++] = c;
  38332. q += alpha01;
  38333. }
  38334. },
  38335. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38336. alpha01) {
  38337. return inputLength * (3 + alpha01);
  38338. },
  38339. isPassthrough: ColorSpace.prototype.isPassthrough,
  38340. fillRgb: ColorSpace.prototype.fillRgb,
  38341. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38342. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38343. },
  38344. usesZeroToOneRange: true
  38345. };
  38346. return DeviceGrayCS;
  38347. })();
  38348. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38349. function DeviceRgbCS() {
  38350. this.name = 'DeviceRGB';
  38351. this.numComps = 3;
  38352. this.defaultColor = new Float32Array([0, 0, 0]);
  38353. }
  38354. DeviceRgbCS.prototype = {
  38355. getRgb: ColorSpace.prototype.getRgb,
  38356. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38357. dest, destOffset) {
  38358. var r = (src[srcOffset] * 255) | 0;
  38359. var g = (src[srcOffset + 1] * 255) | 0;
  38360. var b = (src[srcOffset + 2] * 255) | 0;
  38361. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38362. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38363. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38364. },
  38365. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38366. dest, destOffset, bits,
  38367. alpha01) {
  38368. if (bits === 8 && alpha01 === 0) {
  38369. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38370. return;
  38371. }
  38372. var scale = 255 / ((1 << bits) - 1);
  38373. var j = srcOffset, q = destOffset;
  38374. for (var i = 0; i < count; ++i) {
  38375. dest[q++] = (scale * src[j++]) | 0;
  38376. dest[q++] = (scale * src[j++]) | 0;
  38377. dest[q++] = (scale * src[j++]) | 0;
  38378. q += alpha01;
  38379. }
  38380. },
  38381. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38382. alpha01) {
  38383. return (inputLength * (3 + alpha01) / 3) | 0;
  38384. },
  38385. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38386. return bits === 8;
  38387. },
  38388. fillRgb: ColorSpace.prototype.fillRgb,
  38389. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38390. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38391. },
  38392. usesZeroToOneRange: true
  38393. };
  38394. return DeviceRgbCS;
  38395. })();
  38396. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38397. // The coefficients below was found using numerical analysis: the method of
  38398. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38399. // where color_value is the tabular value from the table of sampled RGB colors
  38400. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38401. // CMYK color conversion using the estimation below:
  38402. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38403. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38404. var c = src[srcOffset + 0] * srcScale;
  38405. var m = src[srcOffset + 1] * srcScale;
  38406. var y = src[srcOffset + 2] * srcScale;
  38407. var k = src[srcOffset + 3] * srcScale;
  38408. var r =
  38409. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38410. 18.82290502165302 * y + 212.25662451639585 * k +
  38411. -285.2331026137004) +
  38412. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38413. -17.873870861415444 * k - 5.497006427196366) +
  38414. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38415. 17.5119270841813) +
  38416. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38417. var g =
  38418. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38419. 6.871425592049007 * y + 31.159100130055922 * k +
  38420. -79.2970844816548) +
  38421. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38422. 131.35250912493976 * k - 190.9453302588951) +
  38423. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38424. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38425. var b =
  38426. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38427. 30.89978309703729 * y - 0.23883238689178934 * k +
  38428. -14.183576799673286) +
  38429. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38430. 50.606957656360734 * k - 112.23884253719248) +
  38431. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38432. -193.58209356861505) +
  38433. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38434. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38435. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38436. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38437. }
  38438. function DeviceCmykCS() {
  38439. this.name = 'DeviceCMYK';
  38440. this.numComps = 4;
  38441. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38442. }
  38443. DeviceCmykCS.prototype = {
  38444. getRgb: ColorSpace.prototype.getRgb,
  38445. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38446. dest, destOffset) {
  38447. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38448. },
  38449. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38450. dest, destOffset, bits,
  38451. alpha01) {
  38452. var scale = 1 / ((1 << bits) - 1);
  38453. for (var i = 0; i < count; i++) {
  38454. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38455. srcOffset += 4;
  38456. destOffset += 3 + alpha01;
  38457. }
  38458. },
  38459. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38460. alpha01) {
  38461. return (inputLength / 4 * (3 + alpha01)) | 0;
  38462. },
  38463. isPassthrough: ColorSpace.prototype.isPassthrough,
  38464. fillRgb: ColorSpace.prototype.fillRgb,
  38465. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38466. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38467. },
  38468. usesZeroToOneRange: true
  38469. };
  38470. return DeviceCmykCS;
  38471. })();
  38472. //
  38473. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38474. //
  38475. var CalGrayCS = (function CalGrayCSClosure() {
  38476. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38477. this.name = 'CalGray';
  38478. this.numComps = 1;
  38479. this.defaultColor = new Float32Array([0]);
  38480. if (!whitePoint) {
  38481. error('WhitePoint missing - required for color space CalGray');
  38482. }
  38483. blackPoint = blackPoint || [0, 0, 0];
  38484. gamma = gamma || 1;
  38485. // Translate arguments to spec variables.
  38486. this.XW = whitePoint[0];
  38487. this.YW = whitePoint[1];
  38488. this.ZW = whitePoint[2];
  38489. this.XB = blackPoint[0];
  38490. this.YB = blackPoint[1];
  38491. this.ZB = blackPoint[2];
  38492. this.G = gamma;
  38493. // Validate variables as per spec.
  38494. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38495. error('Invalid WhitePoint components for ' + this.name +
  38496. ', no fallback available');
  38497. }
  38498. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38499. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38500. this.XB = this.YB = this.ZB = 0;
  38501. }
  38502. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38503. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38504. ', ZB: ' + this.ZB + ', only default values are supported.');
  38505. }
  38506. if (this.G < 1) {
  38507. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38508. ', falling back to default');
  38509. this.G = 1;
  38510. }
  38511. }
  38512. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38513. // A represents a gray component of a calibrated gray space.
  38514. // A <---> AG in the spec
  38515. var A = src[srcOffset] * scale;
  38516. var AG = Math.pow(A, cs.G);
  38517. // Computes L as per spec. ( = cs.YW * AG )
  38518. // Except if other than default BlackPoint values are used.
  38519. var L = cs.YW * AG;
  38520. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38521. // Convert values to rgb range [0, 255].
  38522. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38523. dest[destOffset] = val;
  38524. dest[destOffset + 1] = val;
  38525. dest[destOffset + 2] = val;
  38526. }
  38527. CalGrayCS.prototype = {
  38528. getRgb: ColorSpace.prototype.getRgb,
  38529. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38530. dest, destOffset) {
  38531. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38532. },
  38533. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38534. dest, destOffset, bits,
  38535. alpha01) {
  38536. var scale = 1 / ((1 << bits) - 1);
  38537. for (var i = 0; i < count; ++i) {
  38538. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38539. srcOffset += 1;
  38540. destOffset += 3 + alpha01;
  38541. }
  38542. },
  38543. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38544. return inputLength * (3 + alpha01);
  38545. },
  38546. isPassthrough: ColorSpace.prototype.isPassthrough,
  38547. fillRgb: ColorSpace.prototype.fillRgb,
  38548. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38549. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38550. },
  38551. usesZeroToOneRange: true
  38552. };
  38553. return CalGrayCS;
  38554. })();
  38555. //
  38556. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38557. //
  38558. var CalRGBCS = (function CalRGBCSClosure() {
  38559. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38560. // matrices.
  38561. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38562. 0.8951, 0.2664, -0.1614,
  38563. -0.7502, 1.7135, 0.0367,
  38564. 0.0389, -0.0685, 1.0296]);
  38565. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38566. 0.9869929, -0.1470543, 0.1599627,
  38567. 0.4323053, 0.5183603, 0.0492912,
  38568. -0.0085287, 0.0400428, 0.9684867]);
  38569. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38570. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38571. 3.2404542, -1.5371385, -0.4985314,
  38572. -0.9692660, 1.8760108, 0.0415560,
  38573. 0.0556434, -0.2040259, 1.0572252]);
  38574. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38575. var tempNormalizeMatrix = new Float32Array(3);
  38576. var tempConvertMatrix1 = new Float32Array(3);
  38577. var tempConvertMatrix2 = new Float32Array(3);
  38578. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38579. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38580. this.name = 'CalRGB';
  38581. this.numComps = 3;
  38582. this.defaultColor = new Float32Array(3);
  38583. if (!whitePoint) {
  38584. error('WhitePoint missing - required for color space CalRGB');
  38585. }
  38586. blackPoint = blackPoint || new Float32Array(3);
  38587. gamma = gamma || new Float32Array([1, 1, 1]);
  38588. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38589. // Translate arguments to spec variables.
  38590. var XW = whitePoint[0];
  38591. var YW = whitePoint[1];
  38592. var ZW = whitePoint[2];
  38593. this.whitePoint = whitePoint;
  38594. var XB = blackPoint[0];
  38595. var YB = blackPoint[1];
  38596. var ZB = blackPoint[2];
  38597. this.blackPoint = blackPoint;
  38598. this.GR = gamma[0];
  38599. this.GG = gamma[1];
  38600. this.GB = gamma[2];
  38601. this.MXA = matrix[0];
  38602. this.MYA = matrix[1];
  38603. this.MZA = matrix[2];
  38604. this.MXB = matrix[3];
  38605. this.MYB = matrix[4];
  38606. this.MZB = matrix[5];
  38607. this.MXC = matrix[6];
  38608. this.MYC = matrix[7];
  38609. this.MZC = matrix[8];
  38610. // Validate variables as per spec.
  38611. if (XW < 0 || ZW < 0 || YW !== 1) {
  38612. error('Invalid WhitePoint components for ' + this.name +
  38613. ', no fallback available');
  38614. }
  38615. if (XB < 0 || YB < 0 || ZB < 0) {
  38616. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38617. ', ' + ZB + '], falling back to default');
  38618. this.blackPoint = new Float32Array(3);
  38619. }
  38620. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38621. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38622. '] for ' + this.name + ', falling back to default');
  38623. this.GR = this.GG = this.GB = 1;
  38624. }
  38625. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38626. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38627. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  38628. info('Invalid Matrix for ' + this.name + ' [' +
  38629. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  38630. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  38631. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  38632. '], falling back to default');
  38633. this.MXA = this.MYB = this.MZC = 1;
  38634. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  38635. }
  38636. }
  38637. function matrixProduct(a, b, result) {
  38638. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  38639. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  38640. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  38641. }
  38642. function convertToFlat(sourceWhitePoint, LMS, result) {
  38643. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  38644. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  38645. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  38646. }
  38647. function convertToD65(sourceWhitePoint, LMS, result) {
  38648. var D65X = 0.95047;
  38649. var D65Y = 1;
  38650. var D65Z = 1.08883;
  38651. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  38652. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  38653. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  38654. }
  38655. function sRGBTransferFunction(color) {
  38656. // See http://en.wikipedia.org/wiki/SRGB.
  38657. if (color <= 0.0031308){
  38658. return adjustToRange(0, 1, 12.92 * color);
  38659. }
  38660. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  38661. }
  38662. function adjustToRange(min, max, value) {
  38663. return Math.max(min, Math.min(max, value));
  38664. }
  38665. function decodeL(L) {
  38666. if (L < 0) {
  38667. return -decodeL(-L);
  38668. }
  38669. if (L > 8.0) {
  38670. return Math.pow(((L + 16) / 116), 3);
  38671. }
  38672. return L * DECODE_L_CONSTANT;
  38673. }
  38674. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  38675. // In case the blackPoint is already the default blackPoint then there is
  38676. // no need to do compensation.
  38677. if (sourceBlackPoint[0] === 0 &&
  38678. sourceBlackPoint[1] === 0 &&
  38679. sourceBlackPoint[2] === 0) {
  38680. result[0] = XYZ_Flat[0];
  38681. result[1] = XYZ_Flat[1];
  38682. result[2] = XYZ_Flat[2];
  38683. return;
  38684. }
  38685. // For the blackPoint calculation details, please see
  38686. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38687. // AdobeBPC.pdf.
  38688. // The destination blackPoint is the default blackPoint [0, 0, 0].
  38689. var zeroDecodeL = decodeL(0);
  38690. var X_DST = zeroDecodeL;
  38691. var X_SRC = decodeL(sourceBlackPoint[0]);
  38692. var Y_DST = zeroDecodeL;
  38693. var Y_SRC = decodeL(sourceBlackPoint[1]);
  38694. var Z_DST = zeroDecodeL;
  38695. var Z_SRC = decodeL(sourceBlackPoint[2]);
  38696. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  38697. var X_Offset = 1 - X_Scale;
  38698. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  38699. var Y_Offset = 1 - Y_Scale;
  38700. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  38701. var Z_Offset = 1 - Z_Scale;
  38702. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  38703. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  38704. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  38705. }
  38706. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  38707. // In case the whitePoint is already flat then there is no need to do
  38708. // normalization.
  38709. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  38710. result[0] = XYZ_In[0];
  38711. result[1] = XYZ_In[1];
  38712. result[2] = XYZ_In[2];
  38713. return;
  38714. }
  38715. var LMS = result;
  38716. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38717. var LMS_Flat = tempNormalizeMatrix;
  38718. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  38719. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  38720. }
  38721. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  38722. var LMS = result;
  38723. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38724. var LMS_D65 = tempNormalizeMatrix;
  38725. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  38726. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  38727. }
  38728. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38729. // A, B and C represent a red, green and blue components of a calibrated
  38730. // rgb space.
  38731. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  38732. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  38733. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  38734. // A <---> AGR in the spec
  38735. // B <---> BGG in the spec
  38736. // C <---> CGB in the spec
  38737. var AGR = Math.pow(A, cs.GR);
  38738. var BGG = Math.pow(B, cs.GG);
  38739. var CGB = Math.pow(C, cs.GB);
  38740. // Computes intermediate variables L, M, N as per spec.
  38741. // To decode X, Y, Z values map L, M, N directly to them.
  38742. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  38743. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  38744. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  38745. // The following calculations are based on this document:
  38746. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38747. // AdobeBPC.pdf.
  38748. var XYZ = tempConvertMatrix1;
  38749. XYZ[0] = X;
  38750. XYZ[1] = Y;
  38751. XYZ[2] = Z;
  38752. var XYZ_Flat = tempConvertMatrix2;
  38753. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  38754. var XYZ_Black = tempConvertMatrix1;
  38755. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  38756. var XYZ_D65 = tempConvertMatrix2;
  38757. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  38758. var SRGB = tempConvertMatrix1;
  38759. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  38760. var sR = sRGBTransferFunction(SRGB[0]);
  38761. var sG = sRGBTransferFunction(SRGB[1]);
  38762. var sB = sRGBTransferFunction(SRGB[2]);
  38763. // Convert the values to rgb range [0, 255].
  38764. dest[destOffset] = Math.round(sR * 255);
  38765. dest[destOffset + 1] = Math.round(sG * 255);
  38766. dest[destOffset + 2] = Math.round(sB * 255);
  38767. }
  38768. CalRGBCS.prototype = {
  38769. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  38770. var rgb = new Uint8Array(3);
  38771. this.getRgbItem(src, srcOffset, rgb, 0);
  38772. return rgb;
  38773. },
  38774. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  38775. dest, destOffset) {
  38776. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38777. },
  38778. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  38779. dest, destOffset, bits,
  38780. alpha01) {
  38781. var scale = 1 / ((1 << bits) - 1);
  38782. for (var i = 0; i < count; ++i) {
  38783. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38784. srcOffset += 3;
  38785. destOffset += 3 + alpha01;
  38786. }
  38787. },
  38788. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  38789. return (inputLength * (3 + alpha01) / 3) | 0;
  38790. },
  38791. isPassthrough: ColorSpace.prototype.isPassthrough,
  38792. fillRgb: ColorSpace.prototype.fillRgb,
  38793. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  38794. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38795. },
  38796. usesZeroToOneRange: true
  38797. };
  38798. return CalRGBCS;
  38799. })();
  38800. //
  38801. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  38802. //
  38803. var LabCS = (function LabCSClosure() {
  38804. function LabCS(whitePoint, blackPoint, range) {
  38805. this.name = 'Lab';
  38806. this.numComps = 3;
  38807. this.defaultColor = new Float32Array([0, 0, 0]);
  38808. if (!whitePoint) {
  38809. error('WhitePoint missing - required for color space Lab');
  38810. }
  38811. blackPoint = blackPoint || [0, 0, 0];
  38812. range = range || [-100, 100, -100, 100];
  38813. // Translate args to spec variables
  38814. this.XW = whitePoint[0];
  38815. this.YW = whitePoint[1];
  38816. this.ZW = whitePoint[2];
  38817. this.amin = range[0];
  38818. this.amax = range[1];
  38819. this.bmin = range[2];
  38820. this.bmax = range[3];
  38821. // These are here just for completeness - the spec doesn't offer any
  38822. // formulas that use BlackPoint in Lab
  38823. this.XB = blackPoint[0];
  38824. this.YB = blackPoint[1];
  38825. this.ZB = blackPoint[2];
  38826. // Validate vars as per spec
  38827. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38828. error('Invalid WhitePoint components, no fallback available');
  38829. }
  38830. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38831. info('Invalid BlackPoint, falling back to default');
  38832. this.XB = this.YB = this.ZB = 0;
  38833. }
  38834. if (this.amin > this.amax || this.bmin > this.bmax) {
  38835. info('Invalid Range, falling back to defaults');
  38836. this.amin = -100;
  38837. this.amax = 100;
  38838. this.bmin = -100;
  38839. this.bmax = 100;
  38840. }
  38841. }
  38842. // Function g(x) from spec
  38843. function fn_g(x) {
  38844. if (x >= 6 / 29) {
  38845. return x * x * x;
  38846. } else {
  38847. return (108 / 841) * (x - 4 / 29);
  38848. }
  38849. }
  38850. function decode(value, high1, low2, high2) {
  38851. return low2 + (value) * (high2 - low2) / (high1);
  38852. }
  38853. // If decoding is needed maxVal should be 2^bits per component - 1.
  38854. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  38855. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  38856. // not the usual [0, 1]. If a command like setFillColor is used the src
  38857. // values will already be within the correct range. However, if we are
  38858. // converting an image we have to map the values to the correct range given
  38859. // above.
  38860. // Ls,as,bs <---> L*,a*,b* in the spec
  38861. var Ls = src[srcOffset];
  38862. var as = src[srcOffset + 1];
  38863. var bs = src[srcOffset + 2];
  38864. if (maxVal !== false) {
  38865. Ls = decode(Ls, maxVal, 0, 100);
  38866. as = decode(as, maxVal, cs.amin, cs.amax);
  38867. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  38868. }
  38869. // Adjust limits of 'as' and 'bs'
  38870. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  38871. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  38872. // Computes intermediate variables X,Y,Z as per spec
  38873. var M = (Ls + 16) / 116;
  38874. var L = M + (as / 500);
  38875. var N = M - (bs / 200);
  38876. var X = cs.XW * fn_g(L);
  38877. var Y = cs.YW * fn_g(M);
  38878. var Z = cs.ZW * fn_g(N);
  38879. var r, g, b;
  38880. // Using different conversions for D50 and D65 white points,
  38881. // per http://www.color.org/srgb.pdf
  38882. if (cs.ZW < 1) {
  38883. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  38884. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  38885. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  38886. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  38887. } else {
  38888. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  38889. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  38890. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  38891. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  38892. }
  38893. // clamp color values to [0,1] range then convert to [0,255] range.
  38894. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  38895. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  38896. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  38897. }
  38898. LabCS.prototype = {
  38899. getRgb: ColorSpace.prototype.getRgb,
  38900. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  38901. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  38902. },
  38903. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  38904. dest, destOffset, bits,
  38905. alpha01) {
  38906. var maxVal = (1 << bits) - 1;
  38907. for (var i = 0; i < count; i++) {
  38908. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  38909. srcOffset += 3;
  38910. destOffset += 3 + alpha01;
  38911. }
  38912. },
  38913. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  38914. return (inputLength * (3 + alpha01) / 3) | 0;
  38915. },
  38916. isPassthrough: ColorSpace.prototype.isPassthrough,
  38917. fillRgb: ColorSpace.prototype.fillRgb,
  38918. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  38919. // XXX: Decoding is handled with the lab conversion because of the strange
  38920. // ranges that are used.
  38921. return true;
  38922. },
  38923. usesZeroToOneRange: false
  38924. };
  38925. return LabCS;
  38926. })();
  38927. // TODO refactor to remove dependency on image.js
  38928. function _setCoreImage(coreImage_) {
  38929. coreImage = coreImage_;
  38930. PDFImage = coreImage_.PDFImage;
  38931. }
  38932. exports._setCoreImage = _setCoreImage;
  38933. exports.ColorSpace = ColorSpace;
  38934. // TODO refactor to remove dependency on colorspace.js
  38935. coreStream._setCoreColorSpace(exports);
  38936. }));
  38937. (function (root, factory) {
  38938. {
  38939. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  38940. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  38941. root.pdfjsCoreJpx);
  38942. }
  38943. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  38944. coreStream, coreJpx) {
  38945. var ImageKind = sharedUtil.ImageKind;
  38946. var assert = sharedUtil.assert;
  38947. var error = sharedUtil.error;
  38948. var info = sharedUtil.info;
  38949. var isArray = sharedUtil.isArray;
  38950. var warn = sharedUtil.warn;
  38951. var Name = corePrimitives.Name;
  38952. var isStream = corePrimitives.isStream;
  38953. var ColorSpace = coreColorSpace.ColorSpace;
  38954. var DecodeStream = coreStream.DecodeStream;
  38955. var Stream = coreStream.Stream;
  38956. var JpegStream = coreStream.JpegStream;
  38957. var JpxImage = coreJpx.JpxImage;
  38958. var PDFImage = (function PDFImageClosure() {
  38959. /**
  38960. * Decode the image in the main thread if it supported. Resovles the promise
  38961. * when the image data is ready.
  38962. */
  38963. function handleImageData(handler, xref, res, image) {
  38964. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  38965. // For natively supported jpegs send them to the main thread for decoding.
  38966. var dict = image.dict;
  38967. var colorSpace = dict.get('ColorSpace', 'CS');
  38968. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  38969. var numComps = colorSpace.numComps;
  38970. var decodePromise = handler.sendWithPromise('JpegDecode',
  38971. [image.getIR(), numComps]);
  38972. return decodePromise.then(function (message) {
  38973. var data = message.data;
  38974. return new Stream(data, 0, data.length, image.dict);
  38975. });
  38976. } else {
  38977. return Promise.resolve(image);
  38978. }
  38979. }
  38980. /**
  38981. * Decode and clamp a value. The formula is different from the spec because we
  38982. * don't decode to float range [0,1], we decode it in the [0,max] range.
  38983. */
  38984. function decodeAndClamp(value, addend, coefficient, max) {
  38985. value = addend + value * coefficient;
  38986. // Clamp the value to the range
  38987. return (value < 0 ? 0 : (value > max ? max : value));
  38988. }
  38989. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  38990. this.image = image;
  38991. var dict = image.dict;
  38992. if (dict.has('Filter')) {
  38993. var filter = dict.get('Filter').name;
  38994. if (filter === 'JPXDecode') {
  38995. var jpxImage = new JpxImage();
  38996. jpxImage.parseImageProperties(image.stream);
  38997. image.stream.reset();
  38998. image.bitsPerComponent = jpxImage.bitsPerComponent;
  38999. image.numComps = jpxImage.componentsCount;
  39000. } else if (filter === 'JBIG2Decode') {
  39001. image.bitsPerComponent = 1;
  39002. image.numComps = 1;
  39003. }
  39004. }
  39005. // TODO cache rendered images?
  39006. this.width = dict.get('Width', 'W');
  39007. this.height = dict.get('Height', 'H');
  39008. if (this.width < 1 || this.height < 1) {
  39009. error('Invalid image width: ' + this.width + ' or height: ' +
  39010. this.height);
  39011. }
  39012. this.interpolate = dict.get('Interpolate', 'I') || false;
  39013. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39014. this.matte = dict.get('Matte') || false;
  39015. var bitsPerComponent = image.bitsPerComponent;
  39016. if (!bitsPerComponent) {
  39017. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39018. if (!bitsPerComponent) {
  39019. if (this.imageMask) {
  39020. bitsPerComponent = 1;
  39021. } else {
  39022. error('Bits per component missing in image: ' + this.imageMask);
  39023. }
  39024. }
  39025. }
  39026. this.bpc = bitsPerComponent;
  39027. if (!this.imageMask) {
  39028. var colorSpace = dict.get('ColorSpace', 'CS');
  39029. if (!colorSpace) {
  39030. info('JPX images (which do not require color spaces)');
  39031. switch (image.numComps) {
  39032. case 1:
  39033. colorSpace = Name.get('DeviceGray');
  39034. break;
  39035. case 3:
  39036. colorSpace = Name.get('DeviceRGB');
  39037. break;
  39038. case 4:
  39039. colorSpace = Name.get('DeviceCMYK');
  39040. break;
  39041. default:
  39042. error('JPX images with ' + this.numComps +
  39043. ' color components not supported.');
  39044. }
  39045. }
  39046. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39047. this.numComps = this.colorSpace.numComps;
  39048. }
  39049. this.decode = dict.get('Decode', 'D');
  39050. this.needsDecode = false;
  39051. if (this.decode &&
  39052. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39053. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39054. this.needsDecode = true;
  39055. // Do some preprocessing to avoid more math.
  39056. var max = (1 << bitsPerComponent) - 1;
  39057. this.decodeCoefficients = [];
  39058. this.decodeAddends = [];
  39059. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39060. var dmin = this.decode[i];
  39061. var dmax = this.decode[i + 1];
  39062. this.decodeCoefficients[j] = dmax - dmin;
  39063. this.decodeAddends[j] = max * dmin;
  39064. }
  39065. }
  39066. if (smask) {
  39067. this.smask = new PDFImage(xref, res, smask, false);
  39068. } else if (mask) {
  39069. if (isStream(mask)) {
  39070. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39071. if (!imageMask) {
  39072. warn('Ignoring /Mask in image without /ImageMask.');
  39073. } else {
  39074. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39075. }
  39076. } else {
  39077. // Color key mask (just an array).
  39078. this.mask = mask;
  39079. }
  39080. }
  39081. }
  39082. /**
  39083. * Handles processing of image data and returns the Promise that is resolved
  39084. * with a PDFImage when the image is ready to be used.
  39085. */
  39086. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39087. res, image, inline) {
  39088. var imagePromise = handleImageData(handler, xref, res, image);
  39089. var smaskPromise;
  39090. var maskPromise;
  39091. var smask = image.dict.get('SMask');
  39092. var mask = image.dict.get('Mask');
  39093. if (smask) {
  39094. smaskPromise = handleImageData(handler, xref, res, smask);
  39095. maskPromise = Promise.resolve(null);
  39096. } else {
  39097. smaskPromise = Promise.resolve(null);
  39098. if (mask) {
  39099. if (isStream(mask)) {
  39100. maskPromise = handleImageData(handler, xref, res, mask);
  39101. } else if (isArray(mask)) {
  39102. maskPromise = Promise.resolve(mask);
  39103. } else {
  39104. warn('Unsupported mask format.');
  39105. maskPromise = Promise.resolve(null);
  39106. }
  39107. } else {
  39108. maskPromise = Promise.resolve(null);
  39109. }
  39110. }
  39111. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39112. function(results) {
  39113. var imageData = results[0];
  39114. var smaskData = results[1];
  39115. var maskData = results[2];
  39116. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39117. });
  39118. };
  39119. /**
  39120. * Resize an image using the nearest neighbor algorithm. Currently only
  39121. * supports one and three component images.
  39122. * @param {TypedArray} pixels The original image with one component.
  39123. * @param {Number} bpc Number of bits per component.
  39124. * @param {Number} components Number of color components, 1 or 3 is supported.
  39125. * @param {Number} w1 Original width.
  39126. * @param {Number} h1 Original height.
  39127. * @param {Number} w2 New width.
  39128. * @param {Number} h2 New height.
  39129. * @param {TypedArray} dest (Optional) The destination buffer.
  39130. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39131. * @return {TypedArray} Resized image data.
  39132. */
  39133. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39134. w1, h1, w2, h2, dest, alpha01) {
  39135. if (components !== 1 && components !== 3) {
  39136. error('Unsupported component count for resizing.');
  39137. }
  39138. var length = w2 * h2 * components;
  39139. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39140. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39141. var xRatio = w1 / w2;
  39142. var yRatio = h1 / h2;
  39143. var i, j, py, newIndex = 0, oldIndex;
  39144. var xScaled = new Uint16Array(w2);
  39145. var w1Scanline = w1 * components;
  39146. if (alpha01 !== 1) {
  39147. alpha01 = 0;
  39148. }
  39149. for (j = 0; j < w2; j++) {
  39150. xScaled[j] = Math.floor(j * xRatio) * components;
  39151. }
  39152. if (components === 1) {
  39153. for (i = 0; i < h2; i++) {
  39154. py = Math.floor(i * yRatio) * w1Scanline;
  39155. for (j = 0; j < w2; j++) {
  39156. oldIndex = py + xScaled[j];
  39157. temp[newIndex++] = pixels[oldIndex];
  39158. }
  39159. }
  39160. } else if (components === 3) {
  39161. for (i = 0; i < h2; i++) {
  39162. py = Math.floor(i * yRatio) * w1Scanline;
  39163. for (j = 0; j < w2; j++) {
  39164. oldIndex = py + xScaled[j];
  39165. temp[newIndex++] = pixels[oldIndex++];
  39166. temp[newIndex++] = pixels[oldIndex++];
  39167. temp[newIndex++] = pixels[oldIndex++];
  39168. newIndex += alpha01;
  39169. }
  39170. }
  39171. }
  39172. return temp;
  39173. };
  39174. PDFImage.createMask =
  39175. function PDFImage_createMask(imgArray, width, height,
  39176. imageIsFromDecodeStream, inverseDecode) {
  39177. // |imgArray| might not contain full data for every pixel of the mask, so
  39178. // we need to distinguish between |computedLength| and |actualLength|.
  39179. // In particular, if inverseDecode is true, then the array we return must
  39180. // have a length of |computedLength|.
  39181. var computedLength = ((width + 7) >> 3) * height;
  39182. var actualLength = imgArray.byteLength;
  39183. var haveFullData = computedLength === actualLength;
  39184. var data, i;
  39185. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39186. // imgArray came from a DecodeStream and its data is in an appropriate
  39187. // form, so we can just transfer it.
  39188. data = imgArray;
  39189. } else if (!inverseDecode) {
  39190. data = new Uint8Array(actualLength);
  39191. data.set(imgArray);
  39192. } else {
  39193. data = new Uint8Array(computedLength);
  39194. data.set(imgArray);
  39195. for (i = actualLength; i < computedLength; i++) {
  39196. data[i] = 0xff;
  39197. }
  39198. }
  39199. // If necessary, invert the original mask data (but not any extra we might
  39200. // have added above). It's safe to modify the array -- whether it's the
  39201. // original or a copy, we're about to transfer it anyway, so nothing else
  39202. // in this thread can be relying on its contents.
  39203. if (inverseDecode) {
  39204. for (i = 0; i < actualLength; i++) {
  39205. data[i] = ~data[i];
  39206. }
  39207. }
  39208. return {data: data, width: width, height: height};
  39209. };
  39210. PDFImage.prototype = {
  39211. get drawWidth() {
  39212. return Math.max(this.width,
  39213. this.smask && this.smask.width || 0,
  39214. this.mask && this.mask.width || 0);
  39215. },
  39216. get drawHeight() {
  39217. return Math.max(this.height,
  39218. this.smask && this.smask.height || 0,
  39219. this.mask && this.mask.height || 0);
  39220. },
  39221. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39222. var bpc = this.bpc;
  39223. var numComps = this.numComps;
  39224. var decodeAddends = this.decodeAddends;
  39225. var decodeCoefficients = this.decodeCoefficients;
  39226. var max = (1 << bpc) - 1;
  39227. var i, ii;
  39228. if (bpc === 1) {
  39229. // If the buffer needed decode that means it just needs to be inverted.
  39230. for (i = 0, ii = buffer.length; i < ii; i++) {
  39231. buffer[i] = +!(buffer[i]);
  39232. }
  39233. return;
  39234. }
  39235. var index = 0;
  39236. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39237. for (var j = 0; j < numComps; j++) {
  39238. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39239. decodeCoefficients[j], max);
  39240. index++;
  39241. }
  39242. }
  39243. },
  39244. getComponents: function PDFImage_getComponents(buffer) {
  39245. var bpc = this.bpc;
  39246. // This image doesn't require any extra work.
  39247. if (bpc === 8) {
  39248. return buffer;
  39249. }
  39250. var width = this.width;
  39251. var height = this.height;
  39252. var numComps = this.numComps;
  39253. var length = width * height * numComps;
  39254. var bufferPos = 0;
  39255. var output = (bpc <= 8 ? new Uint8Array(length) :
  39256. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39257. var rowComps = width * numComps;
  39258. var max = (1 << bpc) - 1;
  39259. var i = 0, ii, buf;
  39260. if (bpc === 1) {
  39261. // Optimization for reading 1 bpc images.
  39262. var mask, loop1End, loop2End;
  39263. for (var j = 0; j < height; j++) {
  39264. loop1End = i + (rowComps & ~7);
  39265. loop2End = i + rowComps;
  39266. // unroll loop for all full bytes
  39267. while (i < loop1End) {
  39268. buf = buffer[bufferPos++];
  39269. output[i] = (buf >> 7) & 1;
  39270. output[i + 1] = (buf >> 6) & 1;
  39271. output[i + 2] = (buf >> 5) & 1;
  39272. output[i + 3] = (buf >> 4) & 1;
  39273. output[i + 4] = (buf >> 3) & 1;
  39274. output[i + 5] = (buf >> 2) & 1;
  39275. output[i + 6] = (buf >> 1) & 1;
  39276. output[i + 7] = buf & 1;
  39277. i += 8;
  39278. }
  39279. // handle remaing bits
  39280. if (i < loop2End) {
  39281. buf = buffer[bufferPos++];
  39282. mask = 128;
  39283. while (i < loop2End) {
  39284. output[i++] = +!!(buf & mask);
  39285. mask >>= 1;
  39286. }
  39287. }
  39288. }
  39289. } else {
  39290. // The general case that handles all other bpc values.
  39291. var bits = 0;
  39292. buf = 0;
  39293. for (i = 0, ii = length; i < ii; ++i) {
  39294. if (i % rowComps === 0) {
  39295. buf = 0;
  39296. bits = 0;
  39297. }
  39298. while (bits < bpc) {
  39299. buf = (buf << 8) | buffer[bufferPos++];
  39300. bits += 8;
  39301. }
  39302. var remainingBits = bits - bpc;
  39303. var value = buf >> remainingBits;
  39304. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39305. buf = buf & ((1 << remainingBits) - 1);
  39306. bits = remainingBits;
  39307. }
  39308. }
  39309. return output;
  39310. },
  39311. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39312. actualHeight, image) {
  39313. var smask = this.smask;
  39314. var mask = this.mask;
  39315. var alphaBuf, sw, sh, i, ii, j;
  39316. if (smask) {
  39317. sw = smask.width;
  39318. sh = smask.height;
  39319. alphaBuf = new Uint8Array(sw * sh);
  39320. smask.fillGrayBuffer(alphaBuf);
  39321. if (sw !== width || sh !== height) {
  39322. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39323. height);
  39324. }
  39325. } else if (mask) {
  39326. if (mask instanceof PDFImage) {
  39327. sw = mask.width;
  39328. sh = mask.height;
  39329. alphaBuf = new Uint8Array(sw * sh);
  39330. mask.numComps = 1;
  39331. mask.fillGrayBuffer(alphaBuf);
  39332. // Need to invert values in rgbaBuf
  39333. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39334. alphaBuf[i] = 255 - alphaBuf[i];
  39335. }
  39336. if (sw !== width || sh !== height) {
  39337. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39338. height);
  39339. }
  39340. } else if (isArray(mask)) {
  39341. // Color key mask: if any of the compontents are outside the range
  39342. // then they should be painted.
  39343. alphaBuf = new Uint8Array(width * height);
  39344. var numComps = this.numComps;
  39345. for (i = 0, ii = width * height; i < ii; ++i) {
  39346. var opacity = 0;
  39347. var imageOffset = i * numComps;
  39348. for (j = 0; j < numComps; ++j) {
  39349. var color = image[imageOffset + j];
  39350. var maskOffset = j * 2;
  39351. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39352. opacity = 255;
  39353. break;
  39354. }
  39355. }
  39356. alphaBuf[i] = opacity;
  39357. }
  39358. } else {
  39359. error('Unknown mask format.');
  39360. }
  39361. }
  39362. if (alphaBuf) {
  39363. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39364. rgbaBuf[j] = alphaBuf[i];
  39365. }
  39366. } else {
  39367. // No mask.
  39368. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39369. rgbaBuf[j] = 255;
  39370. }
  39371. }
  39372. },
  39373. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39374. var matte = this.smask && this.smask.matte;
  39375. if (!matte) {
  39376. return;
  39377. }
  39378. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39379. var matteR = matteRgb[0];
  39380. var matteG = matteRgb[1];
  39381. var matteB = matteRgb[2];
  39382. var length = width * height * 4;
  39383. var r, g, b;
  39384. for (var i = 0; i < length; i += 4) {
  39385. var alpha = buffer[i + 3];
  39386. if (alpha === 0) {
  39387. // according formula we have to get Infinity in all components
  39388. // making it white (typical paper color) should be okay
  39389. buffer[i] = 255;
  39390. buffer[i + 1] = 255;
  39391. buffer[i + 2] = 255;
  39392. continue;
  39393. }
  39394. var k = 255 / alpha;
  39395. r = (buffer[i] - matteR) * k + matteR;
  39396. g = (buffer[i + 1] - matteG) * k + matteG;
  39397. b = (buffer[i + 2] - matteB) * k + matteB;
  39398. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39399. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39400. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39401. }
  39402. },
  39403. createImageData: function PDFImage_createImageData(forceRGBA) {
  39404. var drawWidth = this.drawWidth;
  39405. var drawHeight = this.drawHeight;
  39406. var imgData = { // other fields are filled in below
  39407. width: drawWidth,
  39408. height: drawHeight
  39409. };
  39410. var numComps = this.numComps;
  39411. var originalWidth = this.width;
  39412. var originalHeight = this.height;
  39413. var bpc = this.bpc;
  39414. // Rows start at byte boundary.
  39415. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39416. var imgArray;
  39417. if (!forceRGBA) {
  39418. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39419. // without any complications, we pass a same-sized copy to the main
  39420. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39421. // of memory for many scanned documents. It's also much faster.
  39422. //
  39423. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39424. // complications, we avoid expanding by 1.333x to RGBA form.
  39425. var kind;
  39426. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39427. kind = ImageKind.GRAYSCALE_1BPP;
  39428. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39429. !this.needsDecode) {
  39430. kind = ImageKind.RGB_24BPP;
  39431. }
  39432. if (kind && !this.smask && !this.mask &&
  39433. drawWidth === originalWidth && drawHeight === originalHeight) {
  39434. imgData.kind = kind;
  39435. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39436. // If imgArray came from a DecodeStream, we're safe to transfer it
  39437. // (and thus detach its underlying buffer) because it will constitute
  39438. // the entire DecodeStream's data. But if it came from a Stream, we
  39439. // need to copy it because it'll only be a portion of the Stream's
  39440. // data, and the rest will be read later on.
  39441. if (this.image instanceof DecodeStream) {
  39442. imgData.data = imgArray;
  39443. } else {
  39444. var newArray = new Uint8Array(imgArray.length);
  39445. newArray.set(imgArray);
  39446. imgData.data = newArray;
  39447. }
  39448. if (this.needsDecode) {
  39449. // Invert the buffer (which must be grayscale if we reached here).
  39450. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39451. var buffer = imgData.data;
  39452. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39453. buffer[i] ^= 0xff;
  39454. }
  39455. }
  39456. return imgData;
  39457. }
  39458. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39459. (this.colorSpace.name === 'DeviceGray' ||
  39460. this.colorSpace.name === 'DeviceRGB' ||
  39461. this.colorSpace.name === 'DeviceCMYK')) {
  39462. imgData.kind = ImageKind.RGB_24BPP;
  39463. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39464. drawWidth, drawHeight, true);
  39465. return imgData;
  39466. }
  39467. }
  39468. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39469. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39470. var actualHeight = 0 | (imgArray.length / rowBytes *
  39471. drawHeight / originalHeight);
  39472. var comps = this.getComponents(imgArray);
  39473. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39474. // more compact RGB_24BPP form if allowable.
  39475. var alpha01, maybeUndoPreblend;
  39476. if (!forceRGBA && !this.smask && !this.mask) {
  39477. imgData.kind = ImageKind.RGB_24BPP;
  39478. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39479. alpha01 = 0;
  39480. maybeUndoPreblend = false;
  39481. } else {
  39482. imgData.kind = ImageKind.RGBA_32BPP;
  39483. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39484. alpha01 = 1;
  39485. maybeUndoPreblend = true;
  39486. // Color key masking (opacity) must be performed before decoding.
  39487. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39488. comps);
  39489. }
  39490. if (this.needsDecode) {
  39491. this.decodeBuffer(comps);
  39492. }
  39493. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39494. drawWidth, drawHeight, actualHeight, bpc, comps,
  39495. alpha01);
  39496. if (maybeUndoPreblend) {
  39497. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39498. }
  39499. return imgData;
  39500. },
  39501. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39502. var numComps = this.numComps;
  39503. if (numComps !== 1) {
  39504. error('Reading gray scale from a color image: ' + numComps);
  39505. }
  39506. var width = this.width;
  39507. var height = this.height;
  39508. var bpc = this.bpc;
  39509. // rows start at byte boundary
  39510. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39511. var imgArray = this.getImageBytes(height * rowBytes);
  39512. var comps = this.getComponents(imgArray);
  39513. var i, length;
  39514. if (bpc === 1) {
  39515. // inline decoding (= inversion) for 1 bpc images
  39516. length = width * height;
  39517. if (this.needsDecode) {
  39518. // invert and scale to {0, 255}
  39519. for (i = 0; i < length; ++i) {
  39520. buffer[i] = (comps[i] - 1) & 255;
  39521. }
  39522. } else {
  39523. // scale to {0, 255}
  39524. for (i = 0; i < length; ++i) {
  39525. buffer[i] = (-comps[i]) & 255;
  39526. }
  39527. }
  39528. return;
  39529. }
  39530. if (this.needsDecode) {
  39531. this.decodeBuffer(comps);
  39532. }
  39533. length = width * height;
  39534. // we aren't using a colorspace so we need to scale the value
  39535. var scale = 255 / ((1 << bpc) - 1);
  39536. for (i = 0; i < length; ++i) {
  39537. buffer[i] = (scale * comps[i]) | 0;
  39538. }
  39539. },
  39540. getImageBytes: function PDFImage_getImageBytes(length,
  39541. drawWidth, drawHeight,
  39542. forceRGB) {
  39543. this.image.reset();
  39544. this.image.drawWidth = drawWidth || this.width;
  39545. this.image.drawHeight = drawHeight || this.height;
  39546. this.image.forceRGB = !!forceRGB;
  39547. return this.image.getBytes(length);
  39548. }
  39549. };
  39550. return PDFImage;
  39551. })();
  39552. exports.PDFImage = PDFImage;
  39553. // TODO refactor to remove dependency on colorspace.js
  39554. coreColorSpace._setCoreImage(exports);
  39555. }));
  39556. (function (root, factory) {
  39557. {
  39558. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  39559. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  39560. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  39561. }
  39562. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  39563. coreChunkedStream, coreColorSpace) {
  39564. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39565. var MissingDataException = sharedUtil.MissingDataException;
  39566. var XRefParseException = sharedUtil.XRefParseException;
  39567. var assert = sharedUtil.assert;
  39568. var bytesToString = sharedUtil.bytesToString;
  39569. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39570. var error = sharedUtil.error;
  39571. var info = sharedUtil.info;
  39572. var isArray = sharedUtil.isArray;
  39573. var isInt = sharedUtil.isInt;
  39574. var isString = sharedUtil.isString;
  39575. var shadow = sharedUtil.shadow;
  39576. var stringToPDFString = sharedUtil.stringToPDFString;
  39577. var stringToUTF8String = sharedUtil.stringToUTF8String;
  39578. var warn = sharedUtil.warn;
  39579. var isValidUrl = sharedUtil.isValidUrl;
  39580. var Util = sharedUtil.Util;
  39581. var Ref = corePrimitives.Ref;
  39582. var RefSet = corePrimitives.RefSet;
  39583. var RefSetCache = corePrimitives.RefSetCache;
  39584. var isName = corePrimitives.isName;
  39585. var isCmd = corePrimitives.isCmd;
  39586. var isDict = corePrimitives.isDict;
  39587. var isRef = corePrimitives.isRef;
  39588. var isStream = corePrimitives.isStream;
  39589. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  39590. var Lexer = coreParser.Lexer;
  39591. var Parser = coreParser.Parser;
  39592. var ChunkedStream = coreChunkedStream.ChunkedStream;
  39593. var ColorSpace = coreColorSpace.ColorSpace;
  39594. var Catalog = (function CatalogClosure() {
  39595. function Catalog(pdfManager, xref, pageFactory) {
  39596. this.pdfManager = pdfManager;
  39597. this.xref = xref;
  39598. this.catDict = xref.getCatalogObj();
  39599. this.fontCache = new RefSetCache();
  39600. assert(isDict(this.catDict),
  39601. 'catalog object is not a dictionary');
  39602. // TODO refactor to move getPage() to the PDFDocument.
  39603. this.pageFactory = pageFactory;
  39604. this.pagePromises = [];
  39605. }
  39606. Catalog.prototype = {
  39607. get metadata() {
  39608. var streamRef = this.catDict.getRaw('Metadata');
  39609. if (!isRef(streamRef)) {
  39610. return shadow(this, 'metadata', null);
  39611. }
  39612. var encryptMetadata = (!this.xref.encrypt ? false :
  39613. this.xref.encrypt.encryptMetadata);
  39614. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  39615. var metadata;
  39616. if (stream && isDict(stream.dict)) {
  39617. var type = stream.dict.get('Type');
  39618. var subtype = stream.dict.get('Subtype');
  39619. if (isName(type) && isName(subtype) &&
  39620. type.name === 'Metadata' && subtype.name === 'XML') {
  39621. // XXX: This should examine the charset the XML document defines,
  39622. // however since there are currently no real means to decode
  39623. // arbitrary charsets, let's just hope that the author of the PDF
  39624. // was reasonable enough to stick with the XML default charset,
  39625. // which is UTF-8.
  39626. try {
  39627. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  39628. } catch (e) {
  39629. info('Skipping invalid metadata.');
  39630. }
  39631. }
  39632. }
  39633. return shadow(this, 'metadata', metadata);
  39634. },
  39635. get toplevelPagesDict() {
  39636. var pagesObj = this.catDict.get('Pages');
  39637. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  39638. // shadow the prototype getter
  39639. return shadow(this, 'toplevelPagesDict', pagesObj);
  39640. },
  39641. get documentOutline() {
  39642. var obj = null;
  39643. try {
  39644. obj = this.readDocumentOutline();
  39645. } catch (ex) {
  39646. if (ex instanceof MissingDataException) {
  39647. throw ex;
  39648. }
  39649. warn('Unable to read document outline');
  39650. }
  39651. return shadow(this, 'documentOutline', obj);
  39652. },
  39653. readDocumentOutline: function Catalog_readDocumentOutline() {
  39654. var obj = this.catDict.get('Outlines');
  39655. if (!isDict(obj)) {
  39656. return null;
  39657. }
  39658. obj = obj.getRaw('First');
  39659. if (!isRef(obj)) {
  39660. return null;
  39661. }
  39662. var root = { items: [] };
  39663. var queue = [{obj: obj, parent: root}];
  39664. // To avoid recursion, keep track of the already processed items.
  39665. var processed = new RefSet();
  39666. processed.put(obj);
  39667. var xref = this.xref, blackColor = new Uint8Array(3);
  39668. while (queue.length > 0) {
  39669. var i = queue.shift();
  39670. var outlineDict = xref.fetchIfRef(i.obj);
  39671. if (outlineDict === null) {
  39672. continue;
  39673. }
  39674. assert(outlineDict.has('Title'), 'Invalid outline item');
  39675. var actionDict = outlineDict.get('A'), dest = null, url = null;
  39676. if (actionDict) {
  39677. var destEntry = actionDict.get('D');
  39678. if (destEntry) {
  39679. dest = destEntry;
  39680. } else {
  39681. var uriEntry = actionDict.get('URI');
  39682. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  39683. url = uriEntry;
  39684. }
  39685. }
  39686. } else if (outlineDict.has('Dest')) {
  39687. dest = outlineDict.getRaw('Dest');
  39688. if (isName(dest)) {
  39689. dest = dest.name;
  39690. }
  39691. }
  39692. var title = outlineDict.get('Title');
  39693. var flags = outlineDict.get('F') || 0;
  39694. var color = outlineDict.get('C'), rgbColor = blackColor;
  39695. // We only need to parse the color when it's valid, and non-default.
  39696. if (isArray(color) && color.length === 3 &&
  39697. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  39698. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  39699. }
  39700. var outlineItem = {
  39701. dest: dest,
  39702. url: url,
  39703. title: stringToPDFString(title),
  39704. color: rgbColor,
  39705. count: outlineDict.get('Count'),
  39706. bold: !!(flags & 2),
  39707. italic: !!(flags & 1),
  39708. items: []
  39709. };
  39710. i.parent.items.push(outlineItem);
  39711. obj = outlineDict.getRaw('First');
  39712. if (isRef(obj) && !processed.has(obj)) {
  39713. queue.push({obj: obj, parent: outlineItem});
  39714. processed.put(obj);
  39715. }
  39716. obj = outlineDict.getRaw('Next');
  39717. if (isRef(obj) && !processed.has(obj)) {
  39718. queue.push({obj: obj, parent: i.parent});
  39719. processed.put(obj);
  39720. }
  39721. }
  39722. return (root.items.length > 0 ? root.items : null);
  39723. },
  39724. get numPages() {
  39725. var obj = this.toplevelPagesDict.get('Count');
  39726. assert(
  39727. isInt(obj),
  39728. 'page count in top level pages object is not an integer'
  39729. );
  39730. // shadow the prototype getter
  39731. return shadow(this, 'num', obj);
  39732. },
  39733. get destinations() {
  39734. function fetchDestination(dest) {
  39735. return isDict(dest) ? dest.get('D') : dest;
  39736. }
  39737. var xref = this.xref;
  39738. var dests = {}, nameTreeRef, nameDictionaryRef;
  39739. var obj = this.catDict.get('Names');
  39740. if (obj && obj.has('Dests')) {
  39741. nameTreeRef = obj.getRaw('Dests');
  39742. } else if (this.catDict.has('Dests')) {
  39743. nameDictionaryRef = this.catDict.get('Dests');
  39744. }
  39745. if (nameDictionaryRef) {
  39746. // reading simple destination dictionary
  39747. obj = nameDictionaryRef;
  39748. obj.forEach(function catalogForEach(key, value) {
  39749. if (!value) {
  39750. return;
  39751. }
  39752. dests[key] = fetchDestination(value);
  39753. });
  39754. }
  39755. if (nameTreeRef) {
  39756. var nameTree = new NameTree(nameTreeRef, xref);
  39757. var names = nameTree.getAll();
  39758. for (var name in names) {
  39759. dests[name] = fetchDestination(names[name]);
  39760. }
  39761. }
  39762. return shadow(this, 'destinations', dests);
  39763. },
  39764. getDestination: function Catalog_getDestination(destinationId) {
  39765. function fetchDestination(dest) {
  39766. return isDict(dest) ? dest.get('D') : dest;
  39767. }
  39768. var xref = this.xref;
  39769. var dest = null, nameTreeRef, nameDictionaryRef;
  39770. var obj = this.catDict.get('Names');
  39771. if (obj && obj.has('Dests')) {
  39772. nameTreeRef = obj.getRaw('Dests');
  39773. } else if (this.catDict.has('Dests')) {
  39774. nameDictionaryRef = this.catDict.get('Dests');
  39775. }
  39776. if (nameDictionaryRef) { // Simple destination dictionary.
  39777. var value = nameDictionaryRef.get(destinationId);
  39778. if (value) {
  39779. dest = fetchDestination(value);
  39780. }
  39781. }
  39782. if (nameTreeRef) {
  39783. var nameTree = new NameTree(nameTreeRef, xref);
  39784. dest = fetchDestination(nameTree.get(destinationId));
  39785. }
  39786. return dest;
  39787. },
  39788. get pageLabels() {
  39789. var obj = null;
  39790. try {
  39791. obj = this.readPageLabels();
  39792. } catch (ex) {
  39793. if (ex instanceof MissingDataException) {
  39794. throw ex;
  39795. }
  39796. warn('Unable to read page labels.');
  39797. }
  39798. return shadow(this, 'pageLabels', obj);
  39799. },
  39800. readPageLabels: function Catalog_readPageLabels() {
  39801. var obj = this.catDict.getRaw('PageLabels');
  39802. if (!obj) {
  39803. return null;
  39804. }
  39805. var pageLabels = new Array(this.numPages);
  39806. var style = null;
  39807. var prefix = '';
  39808. var start = 1;
  39809. var numberTree = new NumberTree(obj, this.xref);
  39810. var nums = numberTree.getAll();
  39811. var currentLabel = '', currentIndex = 1;
  39812. for (var i = 0, ii = this.numPages; i < ii; i++) {
  39813. if (i in nums) {
  39814. var labelDict = nums[i];
  39815. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  39816. var type = labelDict.get('Type');
  39817. assert(!type || (isName(type) && type.name === 'PageLabel'),
  39818. 'Invalid type in PageLabel dictionary.');
  39819. var s = labelDict.get('S');
  39820. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  39821. style = (s ? s.name : null);
  39822. prefix = labelDict.get('P') || '';
  39823. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  39824. start = labelDict.get('St') || 1;
  39825. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  39826. currentIndex = start;
  39827. }
  39828. switch (style) {
  39829. case 'D':
  39830. currentLabel = currentIndex;
  39831. break;
  39832. case 'R':
  39833. case 'r':
  39834. currentLabel = Util.toRoman(currentIndex, style === 'r');
  39835. break;
  39836. case 'A':
  39837. case 'a':
  39838. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  39839. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  39840. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  39841. var letterIndex = currentIndex - 1;
  39842. var character = String.fromCharCode(baseCharCode +
  39843. (letterIndex % LIMIT));
  39844. var charBuf = [];
  39845. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  39846. charBuf.push(character);
  39847. }
  39848. currentLabel = charBuf.join('');
  39849. break;
  39850. default:
  39851. assert(!style,
  39852. 'Invalid style "' + style + '" in PageLabel dictionary.');
  39853. }
  39854. pageLabels[i] = prefix + currentLabel;
  39855. currentLabel = '';
  39856. currentIndex++;
  39857. }
  39858. return pageLabels;
  39859. },
  39860. get attachments() {
  39861. var xref = this.xref;
  39862. var attachments = null, nameTreeRef;
  39863. var obj = this.catDict.get('Names');
  39864. if (obj) {
  39865. nameTreeRef = obj.getRaw('EmbeddedFiles');
  39866. }
  39867. if (nameTreeRef) {
  39868. var nameTree = new NameTree(nameTreeRef, xref);
  39869. var names = nameTree.getAll();
  39870. for (var name in names) {
  39871. var fs = new FileSpec(names[name], xref);
  39872. if (!attachments) {
  39873. attachments = Object.create(null);
  39874. }
  39875. attachments[stringToPDFString(name)] = fs.serializable;
  39876. }
  39877. }
  39878. return shadow(this, 'attachments', attachments);
  39879. },
  39880. get javaScript() {
  39881. var xref = this.xref;
  39882. var obj = this.catDict.get('Names');
  39883. var javaScript = [];
  39884. function appendIfJavaScriptDict(jsDict) {
  39885. var type = jsDict.get('S');
  39886. if (!isName(type) || type.name !== 'JavaScript') {
  39887. return;
  39888. }
  39889. var js = jsDict.get('JS');
  39890. if (isStream(js)) {
  39891. js = bytesToString(js.getBytes());
  39892. } else if (!isString(js)) {
  39893. return;
  39894. }
  39895. javaScript.push(stringToPDFString(js));
  39896. }
  39897. if (obj && obj.has('JavaScript')) {
  39898. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  39899. var names = nameTree.getAll();
  39900. for (var name in names) {
  39901. // We don't really use the JavaScript right now. This code is
  39902. // defensive so we don't cause errors on document load.
  39903. var jsDict = names[name];
  39904. if (isDict(jsDict)) {
  39905. appendIfJavaScriptDict(jsDict);
  39906. }
  39907. }
  39908. }
  39909. // Append OpenAction actions to javaScript array
  39910. var openactionDict = this.catDict.get('OpenAction');
  39911. if (isDict(openactionDict, 'Action')) {
  39912. var actionType = openactionDict.get('S');
  39913. if (isName(actionType) && actionType.name === 'Named') {
  39914. // The named Print action is not a part of the PDF 1.7 specification,
  39915. // but is supported by many PDF readers/writers (including Adobe's).
  39916. var action = openactionDict.get('N');
  39917. if (isName(action) && action.name === 'Print') {
  39918. javaScript.push('print({});');
  39919. }
  39920. } else {
  39921. appendIfJavaScriptDict(openactionDict);
  39922. }
  39923. }
  39924. return shadow(this, 'javaScript', javaScript);
  39925. },
  39926. cleanup: function Catalog_cleanup() {
  39927. var promises = [];
  39928. this.fontCache.forEach(function (promise) {
  39929. promises.push(promise);
  39930. });
  39931. return Promise.all(promises).then(function (translatedFonts) {
  39932. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  39933. var font = translatedFonts[i].dict;
  39934. delete font.translated;
  39935. }
  39936. this.fontCache.clear();
  39937. }.bind(this));
  39938. },
  39939. getPage: function Catalog_getPage(pageIndex) {
  39940. if (!(pageIndex in this.pagePromises)) {
  39941. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  39942. function (a) {
  39943. var dict = a[0];
  39944. var ref = a[1];
  39945. return this.pageFactory.createPage(pageIndex, dict, ref,
  39946. this.fontCache);
  39947. }.bind(this)
  39948. );
  39949. }
  39950. return this.pagePromises[pageIndex];
  39951. },
  39952. getPageDict: function Catalog_getPageDict(pageIndex) {
  39953. var capability = createPromiseCapability();
  39954. var nodesToVisit = [this.catDict.getRaw('Pages')];
  39955. var currentPageIndex = 0;
  39956. var xref = this.xref;
  39957. var checkAllKids = false;
  39958. function next() {
  39959. while (nodesToVisit.length) {
  39960. var currentNode = nodesToVisit.pop();
  39961. if (isRef(currentNode)) {
  39962. xref.fetchAsync(currentNode).then(function (obj) {
  39963. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  39964. if (pageIndex === currentPageIndex) {
  39965. capability.resolve([obj, currentNode]);
  39966. } else {
  39967. currentPageIndex++;
  39968. next();
  39969. }
  39970. return;
  39971. }
  39972. nodesToVisit.push(obj);
  39973. next();
  39974. }, capability.reject);
  39975. return;
  39976. }
  39977. // Must be a child page dictionary.
  39978. assert(
  39979. isDict(currentNode),
  39980. 'page dictionary kid reference points to wrong type of object'
  39981. );
  39982. var count = currentNode.get('Count');
  39983. // If the current node doesn't have any children, avoid getting stuck
  39984. // in an empty node further down in the tree (see issue5644.pdf).
  39985. if (count === 0) {
  39986. checkAllKids = true;
  39987. }
  39988. // Skip nodes where the page can't be.
  39989. if (currentPageIndex + count <= pageIndex) {
  39990. currentPageIndex += count;
  39991. continue;
  39992. }
  39993. var kids = currentNode.get('Kids');
  39994. assert(isArray(kids), 'page dictionary kids object is not an array');
  39995. if (!checkAllKids && count === kids.length) {
  39996. // Nodes that don't have the page have been skipped and this is the
  39997. // bottom of the tree which means the page requested must be a
  39998. // descendant of this pages node. Ideally we would just resolve the
  39999. // promise with the page ref here, but there is the case where more
  40000. // pages nodes could link to single a page (see issue 3666 pdf). To
  40001. // handle this push it back on the queue so if it is a pages node it
  40002. // will be descended into.
  40003. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  40004. currentPageIndex = pageIndex;
  40005. continue;
  40006. } else {
  40007. for (var last = kids.length - 1; last >= 0; last--) {
  40008. nodesToVisit.push(kids[last]);
  40009. }
  40010. }
  40011. }
  40012. capability.reject('Page index ' + pageIndex + ' not found.');
  40013. }
  40014. next();
  40015. return capability.promise;
  40016. },
  40017. getPageIndex: function Catalog_getPageIndex(ref) {
  40018. // The page tree nodes have the count of all the leaves below them. To get
  40019. // how many pages are before we just have to walk up the tree and keep
  40020. // adding the count of siblings to the left of the node.
  40021. var xref = this.xref;
  40022. function pagesBeforeRef(kidRef) {
  40023. var total = 0;
  40024. var parentRef;
  40025. return xref.fetchAsync(kidRef).then(function (node) {
  40026. if (!node) {
  40027. return null;
  40028. }
  40029. parentRef = node.getRaw('Parent');
  40030. return node.getAsync('Parent');
  40031. }).then(function (parent) {
  40032. if (!parent) {
  40033. return null;
  40034. }
  40035. return parent.getAsync('Kids');
  40036. }).then(function (kids) {
  40037. if (!kids) {
  40038. return null;
  40039. }
  40040. var kidPromises = [];
  40041. var found = false;
  40042. for (var i = 0; i < kids.length; i++) {
  40043. var kid = kids[i];
  40044. assert(isRef(kid), 'kids must be a ref');
  40045. if (kid.num === kidRef.num) {
  40046. found = true;
  40047. break;
  40048. }
  40049. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  40050. if (kid.has('Count')) {
  40051. var count = kid.get('Count');
  40052. total += count;
  40053. } else { // page leaf node
  40054. total++;
  40055. }
  40056. }));
  40057. }
  40058. if (!found) {
  40059. error('kid ref not found in parents kids');
  40060. }
  40061. return Promise.all(kidPromises).then(function () {
  40062. return [total, parentRef];
  40063. });
  40064. });
  40065. }
  40066. var total = 0;
  40067. function next(ref) {
  40068. return pagesBeforeRef(ref).then(function (args) {
  40069. if (!args) {
  40070. return total;
  40071. }
  40072. var count = args[0];
  40073. var parentRef = args[1];
  40074. total += count;
  40075. return next(parentRef);
  40076. });
  40077. }
  40078. return next(ref);
  40079. }
  40080. };
  40081. return Catalog;
  40082. })();
  40083. var XRef = (function XRefClosure() {
  40084. function XRef(stream, password) {
  40085. this.stream = stream;
  40086. this.entries = [];
  40087. this.xrefstms = Object.create(null);
  40088. // prepare the XRef cache
  40089. this.cache = [];
  40090. this.password = password;
  40091. this.stats = {
  40092. streamTypes: [],
  40093. fontTypes: []
  40094. };
  40095. }
  40096. XRef.prototype = {
  40097. setStartXRef: function XRef_setStartXRef(startXRef) {
  40098. // Store the starting positions of xref tables as we process them
  40099. // so we can recover from missing data errors
  40100. this.startXRefQueue = [startXRef];
  40101. },
  40102. parse: function XRef_parse(recoveryMode) {
  40103. var trailerDict;
  40104. if (!recoveryMode) {
  40105. trailerDict = this.readXRef();
  40106. } else {
  40107. warn('Indexing all PDF objects');
  40108. trailerDict = this.indexObjects();
  40109. }
  40110. trailerDict.assignXref(this);
  40111. this.trailer = trailerDict;
  40112. var encrypt = trailerDict.get('Encrypt');
  40113. if (encrypt) {
  40114. var ids = trailerDict.get('ID');
  40115. var fileId = (ids && ids.length) ? ids[0] : '';
  40116. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  40117. this.password);
  40118. }
  40119. // get the root dictionary (catalog) object
  40120. if (!(this.root = trailerDict.get('Root'))) {
  40121. error('Invalid root reference');
  40122. }
  40123. },
  40124. processXRefTable: function XRef_processXRefTable(parser) {
  40125. if (!('tableState' in this)) {
  40126. // Stores state of the table as we process it so we can resume
  40127. // from middle of table in case of missing data error
  40128. this.tableState = {
  40129. entryNum: 0,
  40130. streamPos: parser.lexer.stream.pos,
  40131. parserBuf1: parser.buf1,
  40132. parserBuf2: parser.buf2
  40133. };
  40134. }
  40135. var obj = this.readXRefTable(parser);
  40136. // Sanity check
  40137. if (!isCmd(obj, 'trailer')) {
  40138. error('Invalid XRef table: could not find trailer dictionary');
  40139. }
  40140. // Read trailer dictionary, e.g.
  40141. // trailer
  40142. // << /Size 22
  40143. // /Root 20R
  40144. // /Info 10R
  40145. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  40146. // >>
  40147. // The parser goes through the entire stream << ... >> and provides
  40148. // a getter interface for the key-value table
  40149. var dict = parser.getObj();
  40150. // The pdflib PDF generator can generate a nested trailer dictionary
  40151. if (!isDict(dict) && dict.dict) {
  40152. dict = dict.dict;
  40153. }
  40154. if (!isDict(dict)) {
  40155. error('Invalid XRef table: could not parse trailer dictionary');
  40156. }
  40157. delete this.tableState;
  40158. return dict;
  40159. },
  40160. readXRefTable: function XRef_readXRefTable(parser) {
  40161. // Example of cross-reference table:
  40162. // xref
  40163. // 0 1 <-- subsection header (first obj #, obj count)
  40164. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  40165. // 23 2 <-- subsection header ... and so on ...
  40166. // 0000025518 00002 n
  40167. // 0000025635 00000 n
  40168. // trailer
  40169. // ...
  40170. var stream = parser.lexer.stream;
  40171. var tableState = this.tableState;
  40172. stream.pos = tableState.streamPos;
  40173. parser.buf1 = tableState.parserBuf1;
  40174. parser.buf2 = tableState.parserBuf2;
  40175. // Outer loop is over subsection headers
  40176. var obj;
  40177. while (true) {
  40178. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  40179. if (isCmd(obj = parser.getObj(), 'trailer')) {
  40180. break;
  40181. }
  40182. tableState.firstEntryNum = obj;
  40183. tableState.entryCount = parser.getObj();
  40184. }
  40185. var first = tableState.firstEntryNum;
  40186. var count = tableState.entryCount;
  40187. if (!isInt(first) || !isInt(count)) {
  40188. error('Invalid XRef table: wrong types in subsection header');
  40189. }
  40190. // Inner loop is over objects themselves
  40191. for (var i = tableState.entryNum; i < count; i++) {
  40192. tableState.streamPos = stream.pos;
  40193. tableState.entryNum = i;
  40194. tableState.parserBuf1 = parser.buf1;
  40195. tableState.parserBuf2 = parser.buf2;
  40196. var entry = {};
  40197. entry.offset = parser.getObj();
  40198. entry.gen = parser.getObj();
  40199. var type = parser.getObj();
  40200. if (isCmd(type, 'f')) {
  40201. entry.free = true;
  40202. } else if (isCmd(type, 'n')) {
  40203. entry.uncompressed = true;
  40204. }
  40205. // Validate entry obj
  40206. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  40207. !(entry.free || entry.uncompressed)) {
  40208. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  40209. }
  40210. if (!this.entries[i + first]) {
  40211. this.entries[i + first] = entry;
  40212. }
  40213. }
  40214. tableState.entryNum = 0;
  40215. tableState.streamPos = stream.pos;
  40216. tableState.parserBuf1 = parser.buf1;
  40217. tableState.parserBuf2 = parser.buf2;
  40218. delete tableState.firstEntryNum;
  40219. delete tableState.entryCount;
  40220. }
  40221. // Per issue 3248: hp scanners generate bad XRef
  40222. if (first === 1 && this.entries[1] && this.entries[1].free) {
  40223. // shifting the entries
  40224. this.entries.shift();
  40225. }
  40226. // Sanity check: as per spec, first object must be free
  40227. if (this.entries[0] && !this.entries[0].free) {
  40228. error('Invalid XRef table: unexpected first object');
  40229. }
  40230. return obj;
  40231. },
  40232. processXRefStream: function XRef_processXRefStream(stream) {
  40233. if (!('streamState' in this)) {
  40234. // Stores state of the stream as we process it so we can resume
  40235. // from middle of stream in case of missing data error
  40236. var streamParameters = stream.dict;
  40237. var byteWidths = streamParameters.get('W');
  40238. var range = streamParameters.get('Index');
  40239. if (!range) {
  40240. range = [0, streamParameters.get('Size')];
  40241. }
  40242. this.streamState = {
  40243. entryRanges: range,
  40244. byteWidths: byteWidths,
  40245. entryNum: 0,
  40246. streamPos: stream.pos
  40247. };
  40248. }
  40249. this.readXRefStream(stream);
  40250. delete this.streamState;
  40251. return stream.dict;
  40252. },
  40253. readXRefStream: function XRef_readXRefStream(stream) {
  40254. var i, j;
  40255. var streamState = this.streamState;
  40256. stream.pos = streamState.streamPos;
  40257. var byteWidths = streamState.byteWidths;
  40258. var typeFieldWidth = byteWidths[0];
  40259. var offsetFieldWidth = byteWidths[1];
  40260. var generationFieldWidth = byteWidths[2];
  40261. var entryRanges = streamState.entryRanges;
  40262. while (entryRanges.length > 0) {
  40263. var first = entryRanges[0];
  40264. var n = entryRanges[1];
  40265. if (!isInt(first) || !isInt(n)) {
  40266. error('Invalid XRef range fields: ' + first + ', ' + n);
  40267. }
  40268. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  40269. !isInt(generationFieldWidth)) {
  40270. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  40271. }
  40272. for (i = streamState.entryNum; i < n; ++i) {
  40273. streamState.entryNum = i;
  40274. streamState.streamPos = stream.pos;
  40275. var type = 0, offset = 0, generation = 0;
  40276. for (j = 0; j < typeFieldWidth; ++j) {
  40277. type = (type << 8) | stream.getByte();
  40278. }
  40279. // if type field is absent, its default value is 1
  40280. if (typeFieldWidth === 0) {
  40281. type = 1;
  40282. }
  40283. for (j = 0; j < offsetFieldWidth; ++j) {
  40284. offset = (offset << 8) | stream.getByte();
  40285. }
  40286. for (j = 0; j < generationFieldWidth; ++j) {
  40287. generation = (generation << 8) | stream.getByte();
  40288. }
  40289. var entry = {};
  40290. entry.offset = offset;
  40291. entry.gen = generation;
  40292. switch (type) {
  40293. case 0:
  40294. entry.free = true;
  40295. break;
  40296. case 1:
  40297. entry.uncompressed = true;
  40298. break;
  40299. case 2:
  40300. break;
  40301. default:
  40302. error('Invalid XRef entry type: ' + type);
  40303. }
  40304. if (!this.entries[first + i]) {
  40305. this.entries[first + i] = entry;
  40306. }
  40307. }
  40308. streamState.entryNum = 0;
  40309. streamState.streamPos = stream.pos;
  40310. entryRanges.splice(0, 2);
  40311. }
  40312. },
  40313. indexObjects: function XRef_indexObjects() {
  40314. // Simple scan through the PDF content to find objects,
  40315. // trailers and XRef streams.
  40316. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  40317. var PERCENT = 0x25, LT = 0x3C;
  40318. function readToken(data, offset) {
  40319. var token = '', ch = data[offset];
  40320. while (ch !== LF && ch !== CR && ch !== LT) {
  40321. if (++offset >= data.length) {
  40322. break;
  40323. }
  40324. token += String.fromCharCode(ch);
  40325. ch = data[offset];
  40326. }
  40327. return token;
  40328. }
  40329. function skipUntil(data, offset, what) {
  40330. var length = what.length, dataLength = data.length;
  40331. var skipped = 0;
  40332. // finding byte sequence
  40333. while (offset < dataLength) {
  40334. var i = 0;
  40335. while (i < length && data[offset + i] === what[i]) {
  40336. ++i;
  40337. }
  40338. if (i >= length) {
  40339. break; // sequence found
  40340. }
  40341. offset++;
  40342. skipped++;
  40343. }
  40344. return skipped;
  40345. }
  40346. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  40347. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  40348. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  40349. 101, 102]);
  40350. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  40351. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  40352. // Clear out any existing entries, since they may be bogus.
  40353. this.entries.length = 0;
  40354. var stream = this.stream;
  40355. stream.pos = 0;
  40356. var buffer = stream.getBytes();
  40357. var position = stream.start, length = buffer.length;
  40358. var trailers = [], xrefStms = [];
  40359. while (position < length) {
  40360. var ch = buffer[position];
  40361. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  40362. ++position;
  40363. continue;
  40364. }
  40365. if (ch === PERCENT) { // %-comment
  40366. do {
  40367. ++position;
  40368. if (position >= length) {
  40369. break;
  40370. }
  40371. ch = buffer[position];
  40372. } while (ch !== LF && ch !== CR);
  40373. continue;
  40374. }
  40375. var token = readToken(buffer, position);
  40376. var m;
  40377. if (token.indexOf('xref') === 0 &&
  40378. (token.length === 4 || /\s/.test(token[4]))) {
  40379. position += skipUntil(buffer, position, trailerBytes);
  40380. trailers.push(position);
  40381. position += skipUntil(buffer, position, startxrefBytes);
  40382. } else if ((m = objRegExp.exec(token))) {
  40383. if (typeof this.entries[m[1]] === 'undefined') {
  40384. this.entries[m[1]] = {
  40385. offset: position - stream.start,
  40386. gen: m[2] | 0,
  40387. uncompressed: true
  40388. };
  40389. }
  40390. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  40391. var content = buffer.subarray(position, position + contentLength);
  40392. // checking XRef stream suspect
  40393. // (it shall have '/XRef' and next char is not a letter)
  40394. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  40395. if (xrefTagOffset < contentLength &&
  40396. content[xrefTagOffset + 5] < 64) {
  40397. xrefStms.push(position - stream.start);
  40398. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  40399. }
  40400. position += contentLength;
  40401. } else if (token.indexOf('trailer') === 0 &&
  40402. (token.length === 7 || /\s/.test(token[7]))) {
  40403. trailers.push(position);
  40404. position += skipUntil(buffer, position, startxrefBytes);
  40405. } else {
  40406. position += token.length + 1;
  40407. }
  40408. }
  40409. // reading XRef streams
  40410. var i, ii;
  40411. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  40412. this.startXRefQueue.push(xrefStms[i]);
  40413. this.readXRef(/* recoveryMode */ true);
  40414. }
  40415. // finding main trailer
  40416. var dict;
  40417. for (i = 0, ii = trailers.length; i < ii; ++i) {
  40418. stream.pos = trailers[i];
  40419. var parser = new Parser(new Lexer(stream), true, this);
  40420. var obj = parser.getObj();
  40421. if (!isCmd(obj, 'trailer')) {
  40422. continue;
  40423. }
  40424. // read the trailer dictionary
  40425. if (!isDict(dict = parser.getObj())) {
  40426. continue;
  40427. }
  40428. // taking the first one with 'ID'
  40429. if (dict.has('ID')) {
  40430. return dict;
  40431. }
  40432. }
  40433. // no tailer with 'ID', taking last one (if exists)
  40434. if (dict) {
  40435. return dict;
  40436. }
  40437. // nothing helps
  40438. // calling error() would reject worker with an UnknownErrorException.
  40439. throw new InvalidPDFException('Invalid PDF structure');
  40440. },
  40441. readXRef: function XRef_readXRef(recoveryMode) {
  40442. var stream = this.stream;
  40443. try {
  40444. while (this.startXRefQueue.length) {
  40445. var startXRef = this.startXRefQueue[0];
  40446. stream.pos = startXRef + stream.start;
  40447. var parser = new Parser(new Lexer(stream), true, this);
  40448. var obj = parser.getObj();
  40449. var dict;
  40450. // Get dictionary
  40451. if (isCmd(obj, 'xref')) {
  40452. // Parse end-of-file XRef
  40453. dict = this.processXRefTable(parser);
  40454. if (!this.topDict) {
  40455. this.topDict = dict;
  40456. }
  40457. // Recursively get other XRefs 'XRefStm', if any
  40458. obj = dict.get('XRefStm');
  40459. if (isInt(obj)) {
  40460. var pos = obj;
  40461. // ignore previously loaded xref streams
  40462. // (possible infinite recursion)
  40463. if (!(pos in this.xrefstms)) {
  40464. this.xrefstms[pos] = 1;
  40465. this.startXRefQueue.push(pos);
  40466. }
  40467. }
  40468. } else if (isInt(obj)) {
  40469. // Parse in-stream XRef
  40470. if (!isInt(parser.getObj()) ||
  40471. !isCmd(parser.getObj(), 'obj') ||
  40472. !isStream(obj = parser.getObj())) {
  40473. error('Invalid XRef stream');
  40474. }
  40475. dict = this.processXRefStream(obj);
  40476. if (!this.topDict) {
  40477. this.topDict = dict;
  40478. }
  40479. if (!dict) {
  40480. error('Failed to read XRef stream');
  40481. }
  40482. } else {
  40483. error('Invalid XRef stream header');
  40484. }
  40485. // Recursively get previous dictionary, if any
  40486. obj = dict.get('Prev');
  40487. if (isInt(obj)) {
  40488. this.startXRefQueue.push(obj);
  40489. } else if (isRef(obj)) {
  40490. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  40491. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  40492. this.startXRefQueue.push(obj.num);
  40493. }
  40494. this.startXRefQueue.shift();
  40495. }
  40496. return this.topDict;
  40497. } catch (e) {
  40498. if (e instanceof MissingDataException) {
  40499. throw e;
  40500. }
  40501. info('(while reading XRef): ' + e);
  40502. }
  40503. if (recoveryMode) {
  40504. return;
  40505. }
  40506. throw new XRefParseException();
  40507. },
  40508. getEntry: function XRef_getEntry(i) {
  40509. var xrefEntry = this.entries[i];
  40510. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  40511. return xrefEntry;
  40512. }
  40513. return null;
  40514. },
  40515. fetchIfRef: function XRef_fetchIfRef(obj) {
  40516. if (!isRef(obj)) {
  40517. return obj;
  40518. }
  40519. return this.fetch(obj);
  40520. },
  40521. fetch: function XRef_fetch(ref, suppressEncryption) {
  40522. assert(isRef(ref), 'ref object is not a reference');
  40523. var num = ref.num;
  40524. if (num in this.cache) {
  40525. var cacheEntry = this.cache[num];
  40526. return cacheEntry;
  40527. }
  40528. var xrefEntry = this.getEntry(num);
  40529. // the referenced entry can be free
  40530. if (xrefEntry === null) {
  40531. return (this.cache[num] = null);
  40532. }
  40533. if (xrefEntry.uncompressed) {
  40534. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  40535. } else {
  40536. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  40537. }
  40538. if (isDict(xrefEntry)){
  40539. xrefEntry.objId = ref.toString();
  40540. } else if (isStream(xrefEntry)) {
  40541. xrefEntry.dict.objId = ref.toString();
  40542. }
  40543. return xrefEntry;
  40544. },
  40545. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  40546. suppressEncryption) {
  40547. var gen = ref.gen;
  40548. var num = ref.num;
  40549. if (xrefEntry.gen !== gen) {
  40550. error('inconsistent generation in XRef');
  40551. }
  40552. var stream = this.stream.makeSubStream(xrefEntry.offset +
  40553. this.stream.start);
  40554. var parser = new Parser(new Lexer(stream), true, this);
  40555. var obj1 = parser.getObj();
  40556. var obj2 = parser.getObj();
  40557. var obj3 = parser.getObj();
  40558. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  40559. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  40560. !isCmd(obj3)) {
  40561. error('bad XRef entry');
  40562. }
  40563. if (!isCmd(obj3, 'obj')) {
  40564. // some bad PDFs use "obj1234" and really mean 1234
  40565. if (obj3.cmd.indexOf('obj') === 0) {
  40566. num = parseInt(obj3.cmd.substring(3), 10);
  40567. if (!isNaN(num)) {
  40568. return num;
  40569. }
  40570. }
  40571. error('bad XRef entry');
  40572. }
  40573. if (this.encrypt && !suppressEncryption) {
  40574. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  40575. } else {
  40576. xrefEntry = parser.getObj();
  40577. }
  40578. if (!isStream(xrefEntry)) {
  40579. this.cache[num] = xrefEntry;
  40580. }
  40581. return xrefEntry;
  40582. },
  40583. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  40584. suppressEncryption) {
  40585. var tableOffset = xrefEntry.offset;
  40586. var stream = this.fetch(new Ref(tableOffset, 0));
  40587. if (!isStream(stream)) {
  40588. error('bad ObjStm stream');
  40589. }
  40590. var first = stream.dict.get('First');
  40591. var n = stream.dict.get('N');
  40592. if (!isInt(first) || !isInt(n)) {
  40593. error('invalid first and n parameters for ObjStm stream');
  40594. }
  40595. var parser = new Parser(new Lexer(stream), false, this);
  40596. parser.allowStreams = true;
  40597. var i, entries = [], num, nums = [];
  40598. // read the object numbers to populate cache
  40599. for (i = 0; i < n; ++i) {
  40600. num = parser.getObj();
  40601. if (!isInt(num)) {
  40602. error('invalid object number in the ObjStm stream: ' + num);
  40603. }
  40604. nums.push(num);
  40605. var offset = parser.getObj();
  40606. if (!isInt(offset)) {
  40607. error('invalid object offset in the ObjStm stream: ' + offset);
  40608. }
  40609. }
  40610. // read stream objects for cache
  40611. for (i = 0; i < n; ++i) {
  40612. entries.push(parser.getObj());
  40613. num = nums[i];
  40614. var entry = this.entries[num];
  40615. if (entry && entry.offset === tableOffset && entry.gen === i) {
  40616. this.cache[num] = entries[i];
  40617. }
  40618. }
  40619. xrefEntry = entries[xrefEntry.gen];
  40620. if (xrefEntry === undefined) {
  40621. error('bad XRef entry for compressed object');
  40622. }
  40623. return xrefEntry;
  40624. },
  40625. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  40626. if (!isRef(obj)) {
  40627. return Promise.resolve(obj);
  40628. }
  40629. return this.fetchAsync(obj);
  40630. },
  40631. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  40632. var streamManager = this.stream.manager;
  40633. var xref = this;
  40634. return new Promise(function tryFetch(resolve, reject) {
  40635. try {
  40636. resolve(xref.fetch(ref, suppressEncryption));
  40637. } catch (e) {
  40638. if (e instanceof MissingDataException) {
  40639. streamManager.requestRange(e.begin, e.end).then(function () {
  40640. tryFetch(resolve, reject);
  40641. }, reject);
  40642. return;
  40643. }
  40644. reject(e);
  40645. }
  40646. });
  40647. },
  40648. getCatalogObj: function XRef_getCatalogObj() {
  40649. return this.root;
  40650. }
  40651. };
  40652. return XRef;
  40653. })();
  40654. /**
  40655. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  40656. * see the specification (7.9.6 and 7.9.7) for additional details.
  40657. * TODO: implement all the Dict functions and make this more efficient.
  40658. */
  40659. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  40660. function NameOrNumberTree(root, xref) {
  40661. throw new Error('Cannot initialize NameOrNumberTree.');
  40662. }
  40663. NameOrNumberTree.prototype = {
  40664. getAll: function NameOrNumberTree_getAll() {
  40665. var dict = Object.create(null);
  40666. if (!this.root) {
  40667. return dict;
  40668. }
  40669. var xref = this.xref;
  40670. // Reading Name/Number tree.
  40671. var processed = new RefSet();
  40672. processed.put(this.root);
  40673. var queue = [this.root];
  40674. while (queue.length > 0) {
  40675. var i, n;
  40676. var obj = xref.fetchIfRef(queue.shift());
  40677. if (!isDict(obj)) {
  40678. continue;
  40679. }
  40680. if (obj.has('Kids')) {
  40681. var kids = obj.get('Kids');
  40682. for (i = 0, n = kids.length; i < n; i++) {
  40683. var kid = kids[i];
  40684. assert(!processed.has(kid),
  40685. 'Duplicate entry in "' + this._type + '" tree.');
  40686. queue.push(kid);
  40687. processed.put(kid);
  40688. }
  40689. continue;
  40690. }
  40691. var entries = obj.get(this._type);
  40692. if (isArray(entries)) {
  40693. for (i = 0, n = entries.length; i < n; i += 2) {
  40694. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  40695. }
  40696. }
  40697. }
  40698. return dict;
  40699. },
  40700. get: function NameOrNumberTree_get(key) {
  40701. if (!this.root) {
  40702. return null;
  40703. }
  40704. var xref = this.xref;
  40705. var kidsOrEntries = xref.fetchIfRef(this.root);
  40706. var loopCount = 0;
  40707. var MAX_LEVELS = 10;
  40708. var l, r, m;
  40709. // Perform a binary search to quickly find the entry that
  40710. // contains the key we are looking for.
  40711. while (kidsOrEntries.has('Kids')) {
  40712. if (++loopCount > MAX_LEVELS) {
  40713. warn('Search depth limit reached for "' + this._type + '" tree.');
  40714. return null;
  40715. }
  40716. var kids = kidsOrEntries.get('Kids');
  40717. if (!isArray(kids)) {
  40718. return null;
  40719. }
  40720. l = 0;
  40721. r = kids.length - 1;
  40722. while (l <= r) {
  40723. m = (l + r) >> 1;
  40724. var kid = xref.fetchIfRef(kids[m]);
  40725. var limits = kid.get('Limits');
  40726. if (key < xref.fetchIfRef(limits[0])) {
  40727. r = m - 1;
  40728. } else if (key > xref.fetchIfRef(limits[1])) {
  40729. l = m + 1;
  40730. } else {
  40731. kidsOrEntries = xref.fetchIfRef(kids[m]);
  40732. break;
  40733. }
  40734. }
  40735. if (l > r) {
  40736. return null;
  40737. }
  40738. }
  40739. // If we get here, then we have found the right entry. Now go through the
  40740. // entries in the dictionary until we find the key we're looking for.
  40741. var entries = kidsOrEntries.get(this._type);
  40742. if (isArray(entries)) {
  40743. // Perform a binary search to reduce the lookup time.
  40744. l = 0;
  40745. r = entries.length - 2;
  40746. while (l <= r) {
  40747. // Check only even indices (0, 2, 4, ...) because the
  40748. // odd indices contain the actual data.
  40749. m = (l + r) & ~1;
  40750. var currentKey = xref.fetchIfRef(entries[m]);
  40751. if (key < currentKey) {
  40752. r = m - 2;
  40753. } else if (key > currentKey) {
  40754. l = m + 2;
  40755. } else {
  40756. return xref.fetchIfRef(entries[m + 1]);
  40757. }
  40758. }
  40759. }
  40760. return null;
  40761. }
  40762. };
  40763. return NameOrNumberTree;
  40764. })();
  40765. var NameTree = (function NameTreeClosure() {
  40766. function NameTree(root, xref) {
  40767. this.root = root;
  40768. this.xref = xref;
  40769. this._type = 'Names';
  40770. }
  40771. Util.inherit(NameTree, NameOrNumberTree, {});
  40772. return NameTree;
  40773. })();
  40774. var NumberTree = (function NumberTreeClosure() {
  40775. function NumberTree(root, xref) {
  40776. this.root = root;
  40777. this.xref = xref;
  40778. this._type = 'Nums';
  40779. }
  40780. Util.inherit(NumberTree, NameOrNumberTree, {});
  40781. return NumberTree;
  40782. })();
  40783. /**
  40784. * "A PDF file can refer to the contents of another file by using a File
  40785. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  40786. * NOTE: Only embedded files are supported (as part of the attachments support)
  40787. * TODO: support the 'URL' file system (with caching if !/V), portable
  40788. * collections attributes and related files (/RF)
  40789. */
  40790. var FileSpec = (function FileSpecClosure() {
  40791. function FileSpec(root, xref) {
  40792. if (!root || !isDict(root)) {
  40793. return;
  40794. }
  40795. this.xref = xref;
  40796. this.root = root;
  40797. if (root.has('FS')) {
  40798. this.fs = root.get('FS');
  40799. }
  40800. this.description = root.has('Desc') ?
  40801. stringToPDFString(root.get('Desc')) :
  40802. '';
  40803. if (root.has('RF')) {
  40804. warn('Related file specifications are not supported');
  40805. }
  40806. this.contentAvailable = true;
  40807. if (!root.has('EF')) {
  40808. this.contentAvailable = false;
  40809. warn('Non-embedded file specifications are not supported');
  40810. }
  40811. }
  40812. function pickPlatformItem(dict) {
  40813. // Look for the filename in this order:
  40814. // UF, F, Unix, Mac, DOS
  40815. if (dict.has('UF')) {
  40816. return dict.get('UF');
  40817. } else if (dict.has('F')) {
  40818. return dict.get('F');
  40819. } else if (dict.has('Unix')) {
  40820. return dict.get('Unix');
  40821. } else if (dict.has('Mac')) {
  40822. return dict.get('Mac');
  40823. } else if (dict.has('DOS')) {
  40824. return dict.get('DOS');
  40825. } else {
  40826. return null;
  40827. }
  40828. }
  40829. FileSpec.prototype = {
  40830. get filename() {
  40831. if (!this._filename && this.root) {
  40832. var filename = pickPlatformItem(this.root) || 'unnamed';
  40833. this._filename = stringToPDFString(filename).
  40834. replace(/\\\\/g, '\\').
  40835. replace(/\\\//g, '/').
  40836. replace(/\\/g, '/');
  40837. }
  40838. return this._filename;
  40839. },
  40840. get content() {
  40841. if (!this.contentAvailable) {
  40842. return null;
  40843. }
  40844. if (!this.contentRef && this.root) {
  40845. this.contentRef = pickPlatformItem(this.root.get('EF'));
  40846. }
  40847. var content = null;
  40848. if (this.contentRef) {
  40849. var xref = this.xref;
  40850. var fileObj = xref.fetchIfRef(this.contentRef);
  40851. if (fileObj && isStream(fileObj)) {
  40852. content = fileObj.getBytes();
  40853. } else {
  40854. warn('Embedded file specification points to non-existing/invalid ' +
  40855. 'content');
  40856. }
  40857. } else {
  40858. warn('Embedded file specification does not have a content');
  40859. }
  40860. return content;
  40861. },
  40862. get serializable() {
  40863. return {
  40864. filename: this.filename,
  40865. content: this.content
  40866. };
  40867. }
  40868. };
  40869. return FileSpec;
  40870. })();
  40871. /**
  40872. * A helper for loading missing data in object graphs. It traverses the graph
  40873. * depth first and queues up any objects that have missing data. Once it has
  40874. * has traversed as many objects that are available it attempts to bundle the
  40875. * missing data requests and then resume from the nodes that weren't ready.
  40876. *
  40877. * NOTE: It provides protection from circular references by keeping track of
  40878. * of loaded references. However, you must be careful not to load any graphs
  40879. * that have references to the catalog or other pages since that will cause the
  40880. * entire PDF document object graph to be traversed.
  40881. */
  40882. var ObjectLoader = (function() {
  40883. function mayHaveChildren(value) {
  40884. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  40885. }
  40886. function addChildren(node, nodesToVisit) {
  40887. var value;
  40888. if (isDict(node) || isStream(node)) {
  40889. var map;
  40890. if (isDict(node)) {
  40891. map = node.map;
  40892. } else {
  40893. map = node.dict.map;
  40894. }
  40895. for (var key in map) {
  40896. value = map[key];
  40897. if (mayHaveChildren(value)) {
  40898. nodesToVisit.push(value);
  40899. }
  40900. }
  40901. } else if (isArray(node)) {
  40902. for (var i = 0, ii = node.length; i < ii; i++) {
  40903. value = node[i];
  40904. if (mayHaveChildren(value)) {
  40905. nodesToVisit.push(value);
  40906. }
  40907. }
  40908. }
  40909. }
  40910. function ObjectLoader(obj, keys, xref) {
  40911. this.obj = obj;
  40912. this.keys = keys;
  40913. this.xref = xref;
  40914. this.refSet = null;
  40915. this.capability = null;
  40916. }
  40917. ObjectLoader.prototype = {
  40918. load: function ObjectLoader_load() {
  40919. var keys = this.keys;
  40920. this.capability = createPromiseCapability();
  40921. // Don't walk the graph if all the data is already loaded.
  40922. if (!(this.xref.stream instanceof ChunkedStream) ||
  40923. this.xref.stream.getMissingChunks().length === 0) {
  40924. this.capability.resolve();
  40925. return this.capability.promise;
  40926. }
  40927. this.refSet = new RefSet();
  40928. // Setup the initial nodes to visit.
  40929. var nodesToVisit = [];
  40930. for (var i = 0; i < keys.length; i++) {
  40931. nodesToVisit.push(this.obj[keys[i]]);
  40932. }
  40933. this._walk(nodesToVisit);
  40934. return this.capability.promise;
  40935. },
  40936. _walk: function ObjectLoader_walk(nodesToVisit) {
  40937. var nodesToRevisit = [];
  40938. var pendingRequests = [];
  40939. // DFS walk of the object graph.
  40940. while (nodesToVisit.length) {
  40941. var currentNode = nodesToVisit.pop();
  40942. // Only references or chunked streams can cause missing data exceptions.
  40943. if (isRef(currentNode)) {
  40944. // Skip nodes that have already been visited.
  40945. if (this.refSet.has(currentNode)) {
  40946. continue;
  40947. }
  40948. try {
  40949. var ref = currentNode;
  40950. this.refSet.put(ref);
  40951. currentNode = this.xref.fetch(currentNode);
  40952. } catch (e) {
  40953. if (!(e instanceof MissingDataException)) {
  40954. throw e;
  40955. }
  40956. nodesToRevisit.push(currentNode);
  40957. pendingRequests.push({ begin: e.begin, end: e.end });
  40958. }
  40959. }
  40960. if (currentNode && currentNode.getBaseStreams) {
  40961. var baseStreams = currentNode.getBaseStreams();
  40962. var foundMissingData = false;
  40963. for (var i = 0; i < baseStreams.length; i++) {
  40964. var stream = baseStreams[i];
  40965. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  40966. foundMissingData = true;
  40967. pendingRequests.push({
  40968. begin: stream.start,
  40969. end: stream.end
  40970. });
  40971. }
  40972. }
  40973. if (foundMissingData) {
  40974. nodesToRevisit.push(currentNode);
  40975. }
  40976. }
  40977. addChildren(currentNode, nodesToVisit);
  40978. }
  40979. if (pendingRequests.length) {
  40980. this.xref.stream.manager.requestRanges(pendingRequests).then(
  40981. function pendingRequestCallback() {
  40982. nodesToVisit = nodesToRevisit;
  40983. for (var i = 0; i < nodesToRevisit.length; i++) {
  40984. var node = nodesToRevisit[i];
  40985. // Remove any reference nodes from the currrent refset so they
  40986. // aren't skipped when we revist them.
  40987. if (isRef(node)) {
  40988. this.refSet.remove(node);
  40989. }
  40990. }
  40991. this._walk(nodesToVisit);
  40992. }.bind(this), this.capability.reject);
  40993. return;
  40994. }
  40995. // Everything is loaded.
  40996. this.refSet = null;
  40997. this.capability.resolve();
  40998. }
  40999. };
  41000. return ObjectLoader;
  41001. })();
  41002. exports.Catalog = Catalog;
  41003. exports.ObjectLoader = ObjectLoader;
  41004. exports.XRef = XRef;
  41005. }));
  41006. (function (root, factory) {
  41007. {
  41008. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41009. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41010. root.pdfjsCoreColorSpace);
  41011. }
  41012. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41013. coreColorSpace) {
  41014. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41015. var MissingDataException = sharedUtil.MissingDataException;
  41016. var Util = sharedUtil.Util;
  41017. var assert = sharedUtil.assert;
  41018. var error = sharedUtil.error;
  41019. var info = sharedUtil.info;
  41020. var warn = sharedUtil.warn;
  41021. var isStream = corePrimitives.isStream;
  41022. var PDFFunction = coreFunction.PDFFunction;
  41023. var ColorSpace = coreColorSpace.ColorSpace;
  41024. var ShadingType = {
  41025. FUNCTION_BASED: 1,
  41026. AXIAL: 2,
  41027. RADIAL: 3,
  41028. FREE_FORM_MESH: 4,
  41029. LATTICE_FORM_MESH: 5,
  41030. COONS_PATCH_MESH: 6,
  41031. TENSOR_PATCH_MESH: 7
  41032. };
  41033. var Pattern = (function PatternClosure() {
  41034. // Constructor should define this.getPattern
  41035. function Pattern() {
  41036. error('should not call Pattern constructor');
  41037. }
  41038. Pattern.prototype = {
  41039. // Input: current Canvas context
  41040. // Output: the appropriate fillStyle or strokeStyle
  41041. getPattern: function Pattern_getPattern(ctx) {
  41042. error('Should not call Pattern.getStyle: ' + ctx);
  41043. }
  41044. };
  41045. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41046. res, handler) {
  41047. var dict = isStream(shading) ? shading.dict : shading;
  41048. var type = dict.get('ShadingType');
  41049. try {
  41050. switch (type) {
  41051. case ShadingType.AXIAL:
  41052. case ShadingType.RADIAL:
  41053. // Both radial and axial shadings are handled by RadialAxial shading.
  41054. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41055. case ShadingType.FREE_FORM_MESH:
  41056. case ShadingType.LATTICE_FORM_MESH:
  41057. case ShadingType.COONS_PATCH_MESH:
  41058. case ShadingType.TENSOR_PATCH_MESH:
  41059. return new Shadings.Mesh(shading, matrix, xref, res);
  41060. default:
  41061. throw new Error('Unsupported ShadingType: ' + type);
  41062. }
  41063. } catch (ex) {
  41064. if (ex instanceof MissingDataException) {
  41065. throw ex;
  41066. }
  41067. handler.send('UnsupportedFeature',
  41068. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41069. warn(ex);
  41070. return new Shadings.Dummy();
  41071. }
  41072. };
  41073. return Pattern;
  41074. })();
  41075. var Shadings = {};
  41076. // A small number to offset the first/last color stops so we can insert ones to
  41077. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41078. Shadings.SMALL_NUMBER = 1e-6;
  41079. // Radial and axial shading have very similar implementations
  41080. // If needed, the implementations can be broken into two classes
  41081. Shadings.RadialAxial = (function RadialAxialClosure() {
  41082. function RadialAxial(dict, matrix, xref, res) {
  41083. this.matrix = matrix;
  41084. this.coordsArr = dict.get('Coords');
  41085. this.shadingType = dict.get('ShadingType');
  41086. this.type = 'Pattern';
  41087. var cs = dict.get('ColorSpace', 'CS');
  41088. cs = ColorSpace.parse(cs, xref, res);
  41089. this.cs = cs;
  41090. var t0 = 0.0, t1 = 1.0;
  41091. if (dict.has('Domain')) {
  41092. var domainArr = dict.get('Domain');
  41093. t0 = domainArr[0];
  41094. t1 = domainArr[1];
  41095. }
  41096. var extendStart = false, extendEnd = false;
  41097. if (dict.has('Extend')) {
  41098. var extendArr = dict.get('Extend');
  41099. extendStart = extendArr[0];
  41100. extendEnd = extendArr[1];
  41101. }
  41102. if (this.shadingType === ShadingType.RADIAL &&
  41103. (!extendStart || !extendEnd)) {
  41104. // Radial gradient only currently works if either circle is fully within
  41105. // the other circle.
  41106. var x1 = this.coordsArr[0];
  41107. var y1 = this.coordsArr[1];
  41108. var r1 = this.coordsArr[2];
  41109. var x2 = this.coordsArr[3];
  41110. var y2 = this.coordsArr[4];
  41111. var r2 = this.coordsArr[5];
  41112. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  41113. if (r1 <= r2 + distance &&
  41114. r2 <= r1 + distance) {
  41115. warn('Unsupported radial gradient.');
  41116. }
  41117. }
  41118. this.extendStart = extendStart;
  41119. this.extendEnd = extendEnd;
  41120. var fnObj = dict.get('Function');
  41121. var fn = PDFFunction.parseArray(xref, fnObj);
  41122. // 10 samples seems good enough for now, but probably won't work
  41123. // if there are sharp color changes. Ideally, we would implement
  41124. // the spec faithfully and add lossless optimizations.
  41125. var diff = t1 - t0;
  41126. var step = diff / 10;
  41127. var colorStops = this.colorStops = [];
  41128. // Protect against bad domains so we don't end up in an infinte loop below.
  41129. if (t0 >= t1 || step <= 0) {
  41130. // Acrobat doesn't seem to handle these cases so we'll ignore for
  41131. // now.
  41132. info('Bad shading domain.');
  41133. return;
  41134. }
  41135. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  41136. var rgbColor;
  41137. for (var i = t0; i <= t1; i += step) {
  41138. ratio[0] = i;
  41139. fn(ratio, 0, color, 0);
  41140. rgbColor = cs.getRgb(color, 0);
  41141. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41142. colorStops.push([(i - t0) / diff, cssColor]);
  41143. }
  41144. var background = 'transparent';
  41145. if (dict.has('Background')) {
  41146. rgbColor = cs.getRgb(dict.get('Background'), 0);
  41147. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41148. }
  41149. if (!extendStart) {
  41150. // Insert a color stop at the front and offset the first real color stop
  41151. // so it doesn't conflict with the one we insert.
  41152. colorStops.unshift([0, background]);
  41153. colorStops[1][0] += Shadings.SMALL_NUMBER;
  41154. }
  41155. if (!extendEnd) {
  41156. // Same idea as above in extendStart but for the end.
  41157. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  41158. colorStops.push([1, background]);
  41159. }
  41160. this.colorStops = colorStops;
  41161. }
  41162. RadialAxial.prototype = {
  41163. getIR: function RadialAxial_getIR() {
  41164. var coordsArr = this.coordsArr;
  41165. var shadingType = this.shadingType;
  41166. var type, p0, p1, r0, r1;
  41167. if (shadingType === ShadingType.AXIAL) {
  41168. p0 = [coordsArr[0], coordsArr[1]];
  41169. p1 = [coordsArr[2], coordsArr[3]];
  41170. r0 = null;
  41171. r1 = null;
  41172. type = 'axial';
  41173. } else if (shadingType === ShadingType.RADIAL) {
  41174. p0 = [coordsArr[0], coordsArr[1]];
  41175. p1 = [coordsArr[3], coordsArr[4]];
  41176. r0 = coordsArr[2];
  41177. r1 = coordsArr[5];
  41178. type = 'radial';
  41179. } else {
  41180. error('getPattern type unknown: ' + shadingType);
  41181. }
  41182. var matrix = this.matrix;
  41183. if (matrix) {
  41184. p0 = Util.applyTransform(p0, matrix);
  41185. p1 = Util.applyTransform(p1, matrix);
  41186. if (shadingType === ShadingType.RADIAL) {
  41187. var scale = Util.singularValueDecompose2dScale(matrix);
  41188. r0 *= scale[0];
  41189. r1 *= scale[1];
  41190. }
  41191. }
  41192. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  41193. }
  41194. };
  41195. return RadialAxial;
  41196. })();
  41197. // All mesh shading. For now, they will be presented as set of the triangles
  41198. // to be drawn on the canvas and rgb color for each vertex.
  41199. Shadings.Mesh = (function MeshClosure() {
  41200. function MeshStreamReader(stream, context) {
  41201. this.stream = stream;
  41202. this.context = context;
  41203. this.buffer = 0;
  41204. this.bufferLength = 0;
  41205. var numComps = context.numComps;
  41206. this.tmpCompsBuf = new Float32Array(numComps);
  41207. var csNumComps = context.colorSpace.numComps;
  41208. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  41209. this.tmpCompsBuf;
  41210. }
  41211. MeshStreamReader.prototype = {
  41212. get hasData() {
  41213. if (this.stream.end) {
  41214. return this.stream.pos < this.stream.end;
  41215. }
  41216. if (this.bufferLength > 0) {
  41217. return true;
  41218. }
  41219. var nextByte = this.stream.getByte();
  41220. if (nextByte < 0) {
  41221. return false;
  41222. }
  41223. this.buffer = nextByte;
  41224. this.bufferLength = 8;
  41225. return true;
  41226. },
  41227. readBits: function MeshStreamReader_readBits(n) {
  41228. var buffer = this.buffer;
  41229. var bufferLength = this.bufferLength;
  41230. if (n === 32) {
  41231. if (bufferLength === 0) {
  41232. return ((this.stream.getByte() << 24) |
  41233. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  41234. this.stream.getByte()) >>> 0;
  41235. }
  41236. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  41237. (this.stream.getByte() << 8) | this.stream.getByte();
  41238. var nextByte = this.stream.getByte();
  41239. this.buffer = nextByte & ((1 << bufferLength) - 1);
  41240. return ((buffer << (8 - bufferLength)) |
  41241. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  41242. }
  41243. if (n === 8 && bufferLength === 0) {
  41244. return this.stream.getByte();
  41245. }
  41246. while (bufferLength < n) {
  41247. buffer = (buffer << 8) | this.stream.getByte();
  41248. bufferLength += 8;
  41249. }
  41250. bufferLength -= n;
  41251. this.bufferLength = bufferLength;
  41252. this.buffer = buffer & ((1 << bufferLength) - 1);
  41253. return buffer >> bufferLength;
  41254. },
  41255. align: function MeshStreamReader_align() {
  41256. this.buffer = 0;
  41257. this.bufferLength = 0;
  41258. },
  41259. readFlag: function MeshStreamReader_readFlag() {
  41260. return this.readBits(this.context.bitsPerFlag);
  41261. },
  41262. readCoordinate: function MeshStreamReader_readCoordinate() {
  41263. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  41264. var xi = this.readBits(bitsPerCoordinate);
  41265. var yi = this.readBits(bitsPerCoordinate);
  41266. var decode = this.context.decode;
  41267. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  41268. 2.3283064365386963e-10; // 2 ^ -32
  41269. return [
  41270. xi * scale * (decode[1] - decode[0]) + decode[0],
  41271. yi * scale * (decode[3] - decode[2]) + decode[2]
  41272. ];
  41273. },
  41274. readComponents: function MeshStreamReader_readComponents() {
  41275. var numComps = this.context.numComps;
  41276. var bitsPerComponent = this.context.bitsPerComponent;
  41277. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  41278. 2.3283064365386963e-10; // 2 ^ -32
  41279. var decode = this.context.decode;
  41280. var components = this.tmpCompsBuf;
  41281. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  41282. var ci = this.readBits(bitsPerComponent);
  41283. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  41284. }
  41285. var color = this.tmpCsCompsBuf;
  41286. if (this.context.colorFn) {
  41287. this.context.colorFn(components, 0, color, 0);
  41288. }
  41289. return this.context.colorSpace.getRgb(color, 0);
  41290. }
  41291. };
  41292. function decodeType4Shading(mesh, reader) {
  41293. var coords = mesh.coords;
  41294. var colors = mesh.colors;
  41295. var operators = [];
  41296. var ps = []; // not maintaining cs since that will match ps
  41297. var verticesLeft = 0; // assuming we have all data to start a new triangle
  41298. while (reader.hasData) {
  41299. var f = reader.readFlag();
  41300. var coord = reader.readCoordinate();
  41301. var color = reader.readComponents();
  41302. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  41303. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  41304. switch (f) {
  41305. case 0:
  41306. verticesLeft = 3;
  41307. break;
  41308. case 1:
  41309. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  41310. verticesLeft = 1;
  41311. break;
  41312. case 2:
  41313. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  41314. verticesLeft = 1;
  41315. break;
  41316. }
  41317. operators.push(f);
  41318. }
  41319. ps.push(coords.length);
  41320. coords.push(coord);
  41321. colors.push(color);
  41322. verticesLeft--;
  41323. reader.align();
  41324. }
  41325. mesh.figures.push({
  41326. type: 'triangles',
  41327. coords: new Int32Array(ps),
  41328. colors: new Int32Array(ps),
  41329. });
  41330. }
  41331. function decodeType5Shading(mesh, reader, verticesPerRow) {
  41332. var coords = mesh.coords;
  41333. var colors = mesh.colors;
  41334. var ps = []; // not maintaining cs since that will match ps
  41335. while (reader.hasData) {
  41336. var coord = reader.readCoordinate();
  41337. var color = reader.readComponents();
  41338. ps.push(coords.length);
  41339. coords.push(coord);
  41340. colors.push(color);
  41341. }
  41342. mesh.figures.push({
  41343. type: 'lattice',
  41344. coords: new Int32Array(ps),
  41345. colors: new Int32Array(ps),
  41346. verticesPerRow: verticesPerRow
  41347. });
  41348. }
  41349. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  41350. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  41351. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  41352. var getB = (function getBClosure() {
  41353. function buildB(count) {
  41354. var lut = [];
  41355. for (var i = 0; i <= count; i++) {
  41356. var t = i / count, t_ = 1 - t;
  41357. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  41358. 3 * t * t * t_, t * t * t]));
  41359. }
  41360. return lut;
  41361. }
  41362. var cache = [];
  41363. return function getB(count) {
  41364. if (!cache[count]) {
  41365. cache[count] = buildB(count);
  41366. }
  41367. return cache[count];
  41368. };
  41369. })();
  41370. function buildFigureFromPatch(mesh, index) {
  41371. var figure = mesh.figures[index];
  41372. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  41373. var coords = mesh.coords, colors = mesh.colors;
  41374. var pi = figure.coords;
  41375. var ci = figure.colors;
  41376. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  41377. coords[pi[12]][0], coords[pi[15]][0]);
  41378. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  41379. coords[pi[12]][1], coords[pi[15]][1]);
  41380. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  41381. coords[pi[12]][0], coords[pi[15]][0]);
  41382. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  41383. coords[pi[12]][1], coords[pi[15]][1]);
  41384. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  41385. (mesh.bounds[2] - mesh.bounds[0]));
  41386. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41387. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  41388. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  41389. (mesh.bounds[3] - mesh.bounds[1]));
  41390. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41391. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  41392. var verticesPerRow = splitXBy + 1;
  41393. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  41394. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  41395. var k = 0;
  41396. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  41397. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  41398. c2 = colors[ci[2]], c3 = colors[ci[3]];
  41399. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  41400. for (var row = 0; row <= splitYBy; row++) {
  41401. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  41402. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  41403. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  41404. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  41405. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  41406. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  41407. for (var col = 0; col <= splitXBy; col++, k++) {
  41408. if ((row === 0 || row === splitYBy) &&
  41409. (col === 0 || col === splitXBy)) {
  41410. continue;
  41411. }
  41412. var x = 0, y = 0;
  41413. var q = 0;
  41414. for (var i = 0; i <= 3; i++) {
  41415. for (var j = 0; j <= 3; j++, q++) {
  41416. var m = bRow[row][i] * bCol[col][j];
  41417. x += coords[pi[q]][0] * m;
  41418. y += coords[pi[q]][1] * m;
  41419. }
  41420. }
  41421. figureCoords[k] = coords.length;
  41422. coords.push([x, y]);
  41423. figureColors[k] = colors.length;
  41424. var newColor = new Uint8Array(3);
  41425. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  41426. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  41427. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  41428. colors.push(newColor);
  41429. }
  41430. }
  41431. figureCoords[0] = pi[0];
  41432. figureColors[0] = ci[0];
  41433. figureCoords[splitXBy] = pi[3];
  41434. figureColors[splitXBy] = ci[1];
  41435. figureCoords[verticesPerRow * splitYBy] = pi[12];
  41436. figureColors[verticesPerRow * splitYBy] = ci[2];
  41437. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  41438. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  41439. mesh.figures[index] = {
  41440. type: 'lattice',
  41441. coords: figureCoords,
  41442. colors: figureColors,
  41443. verticesPerRow: verticesPerRow
  41444. };
  41445. }
  41446. function decodeType6Shading(mesh, reader) {
  41447. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  41448. var coords = mesh.coords;
  41449. var colors = mesh.colors;
  41450. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41451. var cs = new Int32Array(4); // c00, c30, c03, c33
  41452. while (reader.hasData) {
  41453. var f = reader.readFlag();
  41454. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  41455. var i, ii;
  41456. var pi = coords.length;
  41457. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  41458. coords.push(reader.readCoordinate());
  41459. }
  41460. var ci = colors.length;
  41461. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41462. colors.push(reader.readComponents());
  41463. }
  41464. var tmp1, tmp2, tmp3, tmp4;
  41465. switch (f) {
  41466. case 0:
  41467. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41468. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  41469. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  41470. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41471. cs[2] = ci + 1; cs[3] = ci + 2;
  41472. cs[0] = ci; cs[1] = ci + 3;
  41473. break;
  41474. case 1:
  41475. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41476. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41477. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41478. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41479. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41480. tmp1 = cs[2]; tmp2 = cs[3];
  41481. cs[2] = tmp2; cs[3] = ci;
  41482. cs[0] = tmp1; cs[1] = ci + 1;
  41483. break;
  41484. case 2:
  41485. tmp1 = ps[15];
  41486. tmp2 = ps[11];
  41487. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41488. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41489. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41490. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41491. tmp1 = cs[3];
  41492. cs[2] = cs[1]; cs[3] = ci;
  41493. cs[0] = tmp1; cs[1] = ci + 1;
  41494. break;
  41495. case 3:
  41496. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41497. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41498. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  41499. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41500. cs[2] = cs[0]; cs[3] = ci;
  41501. cs[0] = cs[1]; cs[1] = ci + 1;
  41502. break;
  41503. }
  41504. // set p11, p12, p21, p22
  41505. ps[5] = coords.length;
  41506. coords.push([
  41507. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  41508. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  41509. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41510. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  41511. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  41512. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  41513. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41514. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  41515. ]);
  41516. ps[6] = coords.length;
  41517. coords.push([
  41518. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  41519. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  41520. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41521. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  41522. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  41523. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  41524. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41525. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  41526. ]);
  41527. ps[9] = coords.length;
  41528. coords.push([
  41529. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  41530. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  41531. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41532. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  41533. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  41534. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  41535. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41536. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  41537. ]);
  41538. ps[10] = coords.length;
  41539. coords.push([
  41540. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  41541. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  41542. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41543. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  41544. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  41545. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  41546. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41547. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  41548. ]);
  41549. mesh.figures.push({
  41550. type: 'patch',
  41551. coords: new Int32Array(ps), // making copies of ps and cs
  41552. colors: new Int32Array(cs)
  41553. });
  41554. }
  41555. }
  41556. function decodeType7Shading(mesh, reader) {
  41557. var coords = mesh.coords;
  41558. var colors = mesh.colors;
  41559. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41560. var cs = new Int32Array(4); // c00, c30, c03, c33
  41561. while (reader.hasData) {
  41562. var f = reader.readFlag();
  41563. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  41564. var i, ii;
  41565. var pi = coords.length;
  41566. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  41567. coords.push(reader.readCoordinate());
  41568. }
  41569. var ci = colors.length;
  41570. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41571. colors.push(reader.readComponents());
  41572. }
  41573. var tmp1, tmp2, tmp3, tmp4;
  41574. switch (f) {
  41575. case 0:
  41576. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41577. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  41578. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  41579. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41580. cs[2] = ci + 1; cs[3] = ci + 2;
  41581. cs[0] = ci; cs[1] = ci + 3;
  41582. break;
  41583. case 1:
  41584. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41585. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41586. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41587. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41588. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41589. tmp1 = cs[2]; tmp2 = cs[3];
  41590. cs[2] = tmp2; cs[3] = ci;
  41591. cs[0] = tmp1; cs[1] = ci + 1;
  41592. break;
  41593. case 2:
  41594. tmp1 = ps[15];
  41595. tmp2 = ps[11];
  41596. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41597. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41598. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41599. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41600. tmp1 = cs[3];
  41601. cs[2] = cs[1]; cs[3] = ci;
  41602. cs[0] = tmp1; cs[1] = ci + 1;
  41603. break;
  41604. case 3:
  41605. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41606. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41607. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41608. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41609. cs[2] = cs[0]; cs[3] = ci;
  41610. cs[0] = cs[1]; cs[1] = ci + 1;
  41611. break;
  41612. }
  41613. mesh.figures.push({
  41614. type: 'patch',
  41615. coords: new Int32Array(ps), // making copies of ps and cs
  41616. colors: new Int32Array(cs)
  41617. });
  41618. }
  41619. }
  41620. function updateBounds(mesh) {
  41621. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  41622. maxX = minX, maxY = minY;
  41623. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  41624. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  41625. minX = minX > x ? x : minX;
  41626. minY = minY > y ? y : minY;
  41627. maxX = maxX < x ? x : maxX;
  41628. maxY = maxY < y ? y : maxY;
  41629. }
  41630. mesh.bounds = [minX, minY, maxX, maxY];
  41631. }
  41632. function packData(mesh) {
  41633. var i, ii, j, jj;
  41634. var coords = mesh.coords;
  41635. var coordsPacked = new Float32Array(coords.length * 2);
  41636. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  41637. var xy = coords[i];
  41638. coordsPacked[j++] = xy[0];
  41639. coordsPacked[j++] = xy[1];
  41640. }
  41641. mesh.coords = coordsPacked;
  41642. var colors = mesh.colors;
  41643. var colorsPacked = new Uint8Array(colors.length * 3);
  41644. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  41645. var c = colors[i];
  41646. colorsPacked[j++] = c[0];
  41647. colorsPacked[j++] = c[1];
  41648. colorsPacked[j++] = c[2];
  41649. }
  41650. mesh.colors = colorsPacked;
  41651. var figures = mesh.figures;
  41652. for (i = 0, ii = figures.length; i < ii; i++) {
  41653. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  41654. for (j = 0, jj = ps.length; j < jj; j++) {
  41655. ps[j] *= 2;
  41656. cs[j] *= 3;
  41657. }
  41658. }
  41659. }
  41660. function Mesh(stream, matrix, xref, res) {
  41661. assert(isStream(stream), 'Mesh data is not a stream');
  41662. var dict = stream.dict;
  41663. this.matrix = matrix;
  41664. this.shadingType = dict.get('ShadingType');
  41665. this.type = 'Pattern';
  41666. this.bbox = dict.get('BBox');
  41667. var cs = dict.get('ColorSpace', 'CS');
  41668. cs = ColorSpace.parse(cs, xref, res);
  41669. this.cs = cs;
  41670. this.background = dict.has('Background') ?
  41671. cs.getRgb(dict.get('Background'), 0) : null;
  41672. var fnObj = dict.get('Function');
  41673. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  41674. this.coords = [];
  41675. this.colors = [];
  41676. this.figures = [];
  41677. var decodeContext = {
  41678. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  41679. bitsPerComponent: dict.get('BitsPerComponent'),
  41680. bitsPerFlag: dict.get('BitsPerFlag'),
  41681. decode: dict.get('Decode'),
  41682. colorFn: fn,
  41683. colorSpace: cs,
  41684. numComps: fn ? 1 : cs.numComps
  41685. };
  41686. var reader = new MeshStreamReader(stream, decodeContext);
  41687. var patchMesh = false;
  41688. switch (this.shadingType) {
  41689. case ShadingType.FREE_FORM_MESH:
  41690. decodeType4Shading(this, reader);
  41691. break;
  41692. case ShadingType.LATTICE_FORM_MESH:
  41693. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  41694. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  41695. decodeType5Shading(this, reader, verticesPerRow);
  41696. break;
  41697. case ShadingType.COONS_PATCH_MESH:
  41698. decodeType6Shading(this, reader);
  41699. patchMesh = true;
  41700. break;
  41701. case ShadingType.TENSOR_PATCH_MESH:
  41702. decodeType7Shading(this, reader);
  41703. patchMesh = true;
  41704. break;
  41705. default:
  41706. error('Unsupported mesh type.');
  41707. break;
  41708. }
  41709. if (patchMesh) {
  41710. // dirty bounds calculation for determining, how dense shall be triangles
  41711. updateBounds(this);
  41712. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  41713. buildFigureFromPatch(this, i);
  41714. }
  41715. }
  41716. // calculate bounds
  41717. updateBounds(this);
  41718. packData(this);
  41719. }
  41720. Mesh.prototype = {
  41721. getIR: function Mesh_getIR() {
  41722. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  41723. this.bounds, this.matrix, this.bbox, this.background];
  41724. }
  41725. };
  41726. return Mesh;
  41727. })();
  41728. Shadings.Dummy = (function DummyClosure() {
  41729. function Dummy() {
  41730. this.type = 'Pattern';
  41731. }
  41732. Dummy.prototype = {
  41733. getIR: function Dummy_getIR() {
  41734. return ['Dummy'];
  41735. }
  41736. };
  41737. return Dummy;
  41738. })();
  41739. function getTilingPatternIR(operatorList, dict, args) {
  41740. var matrix = dict.get('Matrix');
  41741. var bbox = dict.get('BBox');
  41742. var xstep = dict.get('XStep');
  41743. var ystep = dict.get('YStep');
  41744. var paintType = dict.get('PaintType');
  41745. var tilingType = dict.get('TilingType');
  41746. return [
  41747. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  41748. paintType, tilingType
  41749. ];
  41750. }
  41751. exports.Pattern = Pattern;
  41752. exports.getTilingPatternIR = getTilingPatternIR;
  41753. }));
  41754. (function (root, factory) {
  41755. {
  41756. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  41757. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  41758. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  41759. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  41760. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  41761. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  41762. root.pdfjsCoreUnicode);
  41763. }
  41764. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  41765. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  41766. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  41767. coreEncodings, coreStandardFonts, coreUnicode) {
  41768. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  41769. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  41770. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41771. var ImageKind = sharedUtil.ImageKind;
  41772. var OPS = sharedUtil.OPS;
  41773. var TextRenderingMode = sharedUtil.TextRenderingMode;
  41774. var Util = sharedUtil.Util;
  41775. var assert = sharedUtil.assert;
  41776. var createPromiseCapability = sharedUtil.createPromiseCapability;
  41777. var error = sharedUtil.error;
  41778. var info = sharedUtil.info;
  41779. var isArray = sharedUtil.isArray;
  41780. var isNum = sharedUtil.isNum;
  41781. var isString = sharedUtil.isString;
  41782. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  41783. var warn = sharedUtil.warn;
  41784. var Dict = corePrimitives.Dict;
  41785. var Name = corePrimitives.Name;
  41786. var isCmd = corePrimitives.isCmd;
  41787. var isDict = corePrimitives.isDict;
  41788. var isName = corePrimitives.isName;
  41789. var isRef = corePrimitives.isRef;
  41790. var isStream = corePrimitives.isStream;
  41791. var DecodeStream = coreStream.DecodeStream;
  41792. var JpegStream = coreStream.JpegStream;
  41793. var Lexer = coreParser.Lexer;
  41794. var Parser = coreParser.Parser;
  41795. var isEOF = coreParser.isEOF;
  41796. var PDFImage = coreImage.PDFImage;
  41797. var ColorSpace = coreColorSpace.ColorSpace;
  41798. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  41799. var ErrorFont = coreFonts.ErrorFont;
  41800. var FontFlags = coreFonts.FontFlags;
  41801. var Font = coreFonts.Font;
  41802. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  41803. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  41804. var getFontType = coreFonts.getFontType;
  41805. var isPDFFunction = coreFunction.isPDFFunction;
  41806. var PDFFunction = coreFunction.PDFFunction;
  41807. var Pattern = corePattern.Pattern;
  41808. var getTilingPatternIR = corePattern.getTilingPatternIR;
  41809. var CMapFactory = coreCMap.CMapFactory;
  41810. var IdentityCMap = coreCMap.IdentityCMap;
  41811. var getMetrics = coreMetrics.getMetrics;
  41812. var bidi = coreBidi.bidi;
  41813. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  41814. var StandardEncoding = coreEncodings.StandardEncoding;
  41815. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  41816. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  41817. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  41818. var getEncoding = coreEncodings.getEncoding;
  41819. var getStdFontMap = coreStandardFonts.getStdFontMap;
  41820. var getSerifFonts = coreStandardFonts.getSerifFonts;
  41821. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  41822. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  41823. var reverseIfRtl = coreUnicode.reverseIfRtl;
  41824. var PartialEvaluator = (function PartialEvaluatorClosure() {
  41825. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  41826. uniquePrefix, idCounters, fontCache) {
  41827. this.pdfManager = pdfManager;
  41828. this.xref = xref;
  41829. this.handler = handler;
  41830. this.pageIndex = pageIndex;
  41831. this.uniquePrefix = uniquePrefix;
  41832. this.idCounters = idCounters;
  41833. this.fontCache = fontCache;
  41834. }
  41835. // Trying to minimize Date.now() usage and check every 100 time
  41836. var TIME_SLOT_DURATION_MS = 20;
  41837. var CHECK_TIME_EVERY = 100;
  41838. function TimeSlotManager() {
  41839. this.reset();
  41840. }
  41841. TimeSlotManager.prototype = {
  41842. check: function TimeSlotManager_check() {
  41843. if (++this.checked < CHECK_TIME_EVERY) {
  41844. return false;
  41845. }
  41846. this.checked = 0;
  41847. return this.endTime <= Date.now();
  41848. },
  41849. reset: function TimeSlotManager_reset() {
  41850. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  41851. this.checked = 0;
  41852. }
  41853. };
  41854. var deferred = Promise.resolve();
  41855. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  41856. PartialEvaluator.prototype = {
  41857. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  41858. if (!isDict(resources)) {
  41859. return false;
  41860. }
  41861. var processed = Object.create(null);
  41862. if (resources.objId) {
  41863. processed[resources.objId] = true;
  41864. }
  41865. var nodes = [resources], xref = this.xref;
  41866. while (nodes.length) {
  41867. var key, i, ii;
  41868. var node = nodes.shift();
  41869. // First check the current resources for blend modes.
  41870. var graphicStates = node.get('ExtGState');
  41871. if (isDict(graphicStates)) {
  41872. var graphicStatesKeys = graphicStates.getKeys();
  41873. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  41874. key = graphicStatesKeys[i];
  41875. var graphicState = graphicStates.get(key);
  41876. var bm = graphicState.get('BM');
  41877. if (isName(bm) && bm.name !== 'Normal') {
  41878. return true;
  41879. }
  41880. }
  41881. }
  41882. // Descend into the XObjects to look for more resources and blend modes.
  41883. var xObjects = node.get('XObject');
  41884. if (!isDict(xObjects)) {
  41885. continue;
  41886. }
  41887. var xObjectsKeys = xObjects.getKeys();
  41888. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  41889. key = xObjectsKeys[i];
  41890. var xObject = xObjects.getRaw(key);
  41891. if (isRef(xObject)) {
  41892. if (processed[xObject.toString()]) {
  41893. // The XObject has already been processed, and by avoiding a
  41894. // redundant `xref.fetch` we can *significantly* reduce the load
  41895. // time for badly generated PDF files (fixes issue6961.pdf).
  41896. continue;
  41897. }
  41898. xObject = xref.fetch(xObject);
  41899. }
  41900. if (!isStream(xObject)) {
  41901. continue;
  41902. }
  41903. if (xObject.dict.objId) {
  41904. if (processed[xObject.dict.objId]) {
  41905. // stream has objId and is processed already
  41906. continue;
  41907. }
  41908. processed[xObject.dict.objId] = true;
  41909. }
  41910. var xResources = xObject.dict.get('Resources');
  41911. // Checking objId to detect an infinite loop.
  41912. if (isDict(xResources) &&
  41913. (!xResources.objId || !processed[xResources.objId])) {
  41914. nodes.push(xResources);
  41915. if (xResources.objId) {
  41916. processed[xResources.objId] = true;
  41917. }
  41918. }
  41919. }
  41920. }
  41921. return false;
  41922. },
  41923. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  41924. xobj, smask,
  41925. operatorList,
  41926. task,
  41927. initialState) {
  41928. var matrix = xobj.dict.getArray('Matrix');
  41929. var bbox = xobj.dict.getArray('BBox');
  41930. var group = xobj.dict.get('Group');
  41931. if (group) {
  41932. var groupOptions = {
  41933. matrix: matrix,
  41934. bbox: bbox,
  41935. smask: smask,
  41936. isolated: false,
  41937. knockout: false
  41938. };
  41939. var groupSubtype = group.get('S');
  41940. var colorSpace;
  41941. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  41942. groupOptions.isolated = (group.get('I') || false);
  41943. groupOptions.knockout = (group.get('K') || false);
  41944. colorSpace = (group.has('CS') ?
  41945. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  41946. }
  41947. if (smask && smask.backdrop) {
  41948. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  41949. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  41950. }
  41951. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  41952. }
  41953. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  41954. return this.getOperatorList(xobj, task,
  41955. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  41956. then(function () {
  41957. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  41958. if (group) {
  41959. operatorList.addOp(OPS.endGroup, [groupOptions]);
  41960. }
  41961. });
  41962. },
  41963. buildPaintImageXObject:
  41964. function PartialEvaluator_buildPaintImageXObject(resources, image,
  41965. inline, operatorList,
  41966. cacheKey, imageCache) {
  41967. var self = this;
  41968. var dict = image.dict;
  41969. var w = dict.get('Width', 'W');
  41970. var h = dict.get('Height', 'H');
  41971. if (!(w && isNum(w)) || !(h && isNum(h))) {
  41972. warn('Image dimensions are missing, or not numbers.');
  41973. return;
  41974. }
  41975. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  41976. warn('Image exceeded maximum allowed size and was removed.');
  41977. return;
  41978. }
  41979. var imageMask = (dict.get('ImageMask', 'IM') || false);
  41980. var imgData, args;
  41981. if (imageMask) {
  41982. // This depends on a tmpCanvas being filled with the
  41983. // current fillStyle, such that processing the pixel
  41984. // data can't be done here. Instead of creating a
  41985. // complete PDFImage, only read the information needed
  41986. // for later.
  41987. var width = dict.get('Width', 'W');
  41988. var height = dict.get('Height', 'H');
  41989. var bitStrideLength = (width + 7) >> 3;
  41990. var imgArray = image.getBytes(bitStrideLength * height);
  41991. var decode = dict.get('Decode', 'D');
  41992. var inverseDecode = (!!decode && decode[0] > 0);
  41993. imgData = PDFImage.createMask(imgArray, width, height,
  41994. image instanceof DecodeStream,
  41995. inverseDecode);
  41996. imgData.cached = true;
  41997. args = [imgData];
  41998. operatorList.addOp(OPS.paintImageMaskXObject, args);
  41999. if (cacheKey) {
  42000. imageCache[cacheKey] = {
  42001. fn: OPS.paintImageMaskXObject,
  42002. args: args
  42003. };
  42004. }
  42005. return;
  42006. }
  42007. var softMask = (dict.get('SMask', 'SM') || false);
  42008. var mask = (dict.get('Mask') || false);
  42009. var SMALL_IMAGE_DIMENSIONS = 200;
  42010. // Inlining small images into the queue as RGB data
  42011. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  42012. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  42013. var imageObj = new PDFImage(this.xref, resources, image,
  42014. inline, null, null);
  42015. // We force the use of RGBA_32BPP images here, because we can't handle
  42016. // any other kind.
  42017. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  42018. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  42019. return;
  42020. }
  42021. // If there is no imageMask, create the PDFImage and a lot
  42022. // of image processing can be done here.
  42023. var uniquePrefix = (this.uniquePrefix || '');
  42024. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  42025. operatorList.addDependency(objId);
  42026. args = [objId, w, h];
  42027. if (!softMask && !mask && image instanceof JpegStream &&
  42028. image.isNativelySupported(this.xref, resources)) {
  42029. // These JPEGs don't need any more processing so we can just send it.
  42030. operatorList.addOp(OPS.paintJpegXObject, args);
  42031. this.handler.send('obj',
  42032. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  42033. return;
  42034. }
  42035. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  42036. then(function(imageObj) {
  42037. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  42038. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  42039. [imgData.data.buffer]);
  42040. }).then(undefined, function (reason) {
  42041. warn('Unable to decode image: ' + reason);
  42042. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  42043. });
  42044. operatorList.addOp(OPS.paintImageXObject, args);
  42045. if (cacheKey) {
  42046. imageCache[cacheKey] = {
  42047. fn: OPS.paintImageXObject,
  42048. args: args
  42049. };
  42050. }
  42051. },
  42052. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  42053. operatorList, task,
  42054. stateManager) {
  42055. var smaskContent = smask.get('G');
  42056. var smaskOptions = {
  42057. subtype: smask.get('S').name,
  42058. backdrop: smask.get('BC')
  42059. };
  42060. // The SMask might have a alpha/luminosity value transfer function --
  42061. // we will build a map of integer values in range 0..255 to be fast.
  42062. var transferObj = smask.get('TR');
  42063. if (isPDFFunction(transferObj)) {
  42064. var transferFn = PDFFunction.parse(this.xref, transferObj);
  42065. var transferMap = new Uint8Array(256);
  42066. var tmp = new Float32Array(1);
  42067. for (var i = 0; i < 256; i++) {
  42068. tmp[0] = i / 255;
  42069. transferFn(tmp, 0, tmp, 0);
  42070. transferMap[i] = (tmp[0] * 255) | 0;
  42071. }
  42072. smaskOptions.transferMap = transferMap;
  42073. }
  42074. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  42075. operatorList, task, stateManager.state.clone());
  42076. },
  42077. handleTilingType:
  42078. function PartialEvaluator_handleTilingType(fn, args, resources,
  42079. pattern, patternDict,
  42080. operatorList, task) {
  42081. // Create an IR of the pattern code.
  42082. var tilingOpList = new OperatorList();
  42083. // Merge the available resources, to prevent issues when the patternDict
  42084. // is missing some /Resources entries (fixes issue6541.pdf).
  42085. var resourcesArray = [patternDict.get('Resources'), resources];
  42086. var patternResources = Dict.merge(this.xref, resourcesArray);
  42087. return this.getOperatorList(pattern, task, patternResources,
  42088. tilingOpList).then(function () {
  42089. // Add the dependencies to the parent operator list so they are
  42090. // resolved before sub operator list is executed synchronously.
  42091. operatorList.addDependencies(tilingOpList.dependencies);
  42092. operatorList.addOp(fn, getTilingPatternIR({
  42093. fnArray: tilingOpList.fnArray,
  42094. argsArray: tilingOpList.argsArray
  42095. }, patternDict, args));
  42096. });
  42097. },
  42098. handleSetFont:
  42099. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  42100. operatorList, task, state) {
  42101. // TODO(mack): Not needed?
  42102. var fontName;
  42103. if (fontArgs) {
  42104. fontArgs = fontArgs.slice();
  42105. fontName = fontArgs[0].name;
  42106. }
  42107. var self = this;
  42108. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  42109. function (translated) {
  42110. if (!translated.font.isType3Font) {
  42111. return translated;
  42112. }
  42113. return translated.loadType3Data(self, resources, operatorList, task).
  42114. then(function () {
  42115. return translated;
  42116. }, function (reason) {
  42117. // Error in the font data -- sending unsupported feature notification.
  42118. self.handler.send('UnsupportedFeature',
  42119. {featureId: UNSUPPORTED_FEATURES.font});
  42120. return new TranslatedFont('g_font_error',
  42121. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  42122. });
  42123. }).then(function (translated) {
  42124. state.font = translated.font;
  42125. translated.send(self.handler);
  42126. return translated.loadedName;
  42127. });
  42128. },
  42129. handleText: function PartialEvaluator_handleText(chars, state) {
  42130. var font = state.font;
  42131. var glyphs = font.charsToGlyphs(chars);
  42132. var isAddToPathSet = !!(state.textRenderingMode &
  42133. TextRenderingMode.ADD_TO_PATH_FLAG);
  42134. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  42135. var buildPath = function (fontChar) {
  42136. if (!font.renderer.hasBuiltPath(fontChar)) {
  42137. var path = font.renderer.getPathJs(fontChar);
  42138. this.handler.send('commonobj', [
  42139. font.loadedName + '_path_' + fontChar,
  42140. 'FontPath',
  42141. path
  42142. ]);
  42143. }
  42144. }.bind(this);
  42145. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  42146. var glyph = glyphs[i];
  42147. buildPath(glyph.fontChar);
  42148. // If the glyph has an accent we need to build a path for its
  42149. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  42150. var accent = glyph.accent;
  42151. if (accent && accent.fontChar) {
  42152. buildPath(accent.fontChar);
  42153. }
  42154. }
  42155. }
  42156. return glyphs;
  42157. },
  42158. setGState: function PartialEvaluator_setGState(resources, gState,
  42159. operatorList, task,
  42160. xref, stateManager) {
  42161. // This array holds the converted/processed state data.
  42162. var gStateObj = [];
  42163. var gStateKeys = gState.getKeys();
  42164. var self = this;
  42165. var promise = Promise.resolve();
  42166. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  42167. var key = gStateKeys[i];
  42168. var value = gState.get(key);
  42169. switch (key) {
  42170. case 'Type':
  42171. break;
  42172. case 'LW':
  42173. case 'LC':
  42174. case 'LJ':
  42175. case 'ML':
  42176. case 'D':
  42177. case 'RI':
  42178. case 'FL':
  42179. case 'CA':
  42180. case 'ca':
  42181. gStateObj.push([key, value]);
  42182. break;
  42183. case 'Font':
  42184. promise = promise.then(function () {
  42185. return self.handleSetFont(resources, null, value[0], operatorList,
  42186. task, stateManager.state).
  42187. then(function (loadedName) {
  42188. operatorList.addDependency(loadedName);
  42189. gStateObj.push([key, [loadedName, value[1]]]);
  42190. });
  42191. });
  42192. break;
  42193. case 'BM':
  42194. gStateObj.push([key, value]);
  42195. break;
  42196. case 'SMask':
  42197. if (isName(value) && value.name === 'None') {
  42198. gStateObj.push([key, false]);
  42199. break;
  42200. }
  42201. if (isDict(value)) {
  42202. promise = promise.then(function (dict) {
  42203. return self.handleSMask(dict, resources, operatorList,
  42204. task, stateManager);
  42205. }.bind(this, value));
  42206. gStateObj.push([key, true]);
  42207. } else {
  42208. warn('Unsupported SMask type');
  42209. }
  42210. break;
  42211. // Only generate info log messages for the following since
  42212. // they are unlikely to have a big impact on the rendering.
  42213. case 'OP':
  42214. case 'op':
  42215. case 'OPM':
  42216. case 'BG':
  42217. case 'BG2':
  42218. case 'UCR':
  42219. case 'UCR2':
  42220. case 'TR':
  42221. case 'TR2':
  42222. case 'HT':
  42223. case 'SM':
  42224. case 'SA':
  42225. case 'AIS':
  42226. case 'TK':
  42227. // TODO implement these operators.
  42228. info('graphic state operator ' + key);
  42229. break;
  42230. default:
  42231. info('Unknown graphic state operator ' + key);
  42232. break;
  42233. }
  42234. }
  42235. return promise.then(function () {
  42236. if (gStateObj.length > 0) {
  42237. operatorList.addOp(OPS.setGState, [gStateObj]);
  42238. }
  42239. });
  42240. },
  42241. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  42242. resources) {
  42243. function errorFont() {
  42244. return Promise.resolve(new TranslatedFont('g_font_error',
  42245. new ErrorFont('Font ' + fontName + ' is not available'), font));
  42246. }
  42247. var fontRef;
  42248. if (font) { // Loading by ref.
  42249. assert(isRef(font));
  42250. fontRef = font;
  42251. } else { // Loading by name.
  42252. var fontRes = resources.get('Font');
  42253. if (fontRes) {
  42254. fontRef = fontRes.getRaw(fontName);
  42255. } else {
  42256. warn('fontRes not available');
  42257. return errorFont();
  42258. }
  42259. }
  42260. if (!fontRef) {
  42261. warn('fontRef not available');
  42262. return errorFont();
  42263. }
  42264. if (this.fontCache.has(fontRef)) {
  42265. return this.fontCache.get(fontRef);
  42266. }
  42267. font = xref.fetchIfRef(fontRef);
  42268. if (!isDict(font)) {
  42269. return errorFont();
  42270. }
  42271. // We are holding font.translated references just for fontRef that are not
  42272. // dictionaries (Dict). See explanation below.
  42273. if (font.translated) {
  42274. return font.translated;
  42275. }
  42276. var fontCapability = createPromiseCapability();
  42277. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  42278. var descriptor = preEvaluatedFont.descriptor;
  42279. var fontID = fontRef.num + '_' + fontRef.gen;
  42280. if (isDict(descriptor)) {
  42281. if (!descriptor.fontAliases) {
  42282. descriptor.fontAliases = Object.create(null);
  42283. }
  42284. var fontAliases = descriptor.fontAliases;
  42285. var hash = preEvaluatedFont.hash;
  42286. if (fontAliases[hash]) {
  42287. var aliasFontRef = fontAliases[hash].aliasRef;
  42288. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  42289. this.fontCache.putAlias(fontRef, aliasFontRef);
  42290. return this.fontCache.get(fontRef);
  42291. }
  42292. }
  42293. if (!fontAliases[hash]) {
  42294. fontAliases[hash] = {
  42295. fontID: Font.getFontID()
  42296. };
  42297. }
  42298. fontAliases[hash].aliasRef = fontRef;
  42299. fontID = fontAliases[hash].fontID;
  42300. }
  42301. // Workaround for bad PDF generators that don't reference fonts
  42302. // properly, i.e. by not using an object identifier.
  42303. // Check if the fontRef is a Dict (as opposed to a standard object),
  42304. // in which case we don't cache the font and instead reference it by
  42305. // fontName in font.loadedName below.
  42306. var fontRefIsDict = isDict(fontRef);
  42307. if (!fontRefIsDict) {
  42308. this.fontCache.put(fontRef, fontCapability.promise);
  42309. }
  42310. // Keep track of each font we translated so the caller can
  42311. // load them asynchronously before calling display on a page.
  42312. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  42313. fontName.replace(/\W/g, '') : fontID);
  42314. font.translated = fontCapability.promise;
  42315. // TODO move promises into translate font
  42316. var translatedPromise;
  42317. try {
  42318. translatedPromise = Promise.resolve(
  42319. this.translateFont(preEvaluatedFont, xref));
  42320. } catch (e) {
  42321. translatedPromise = Promise.reject(e);
  42322. }
  42323. var self = this;
  42324. translatedPromise.then(function (translatedFont) {
  42325. if (translatedFont.fontType !== undefined) {
  42326. var xrefFontStats = xref.stats.fontTypes;
  42327. xrefFontStats[translatedFont.fontType] = true;
  42328. }
  42329. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42330. translatedFont, font));
  42331. }, function (reason) {
  42332. // TODO fontCapability.reject?
  42333. // Error in the font data -- sending unsupported feature notification.
  42334. self.handler.send('UnsupportedFeature',
  42335. {featureId: UNSUPPORTED_FEATURES.font});
  42336. try {
  42337. // error, but it's still nice to have font type reported
  42338. var descriptor = preEvaluatedFont.descriptor;
  42339. var fontFile3 = descriptor && descriptor.get('FontFile3');
  42340. var subtype = fontFile3 && fontFile3.get('Subtype');
  42341. var fontType = getFontType(preEvaluatedFont.type,
  42342. subtype && subtype.name);
  42343. var xrefFontStats = xref.stats.fontTypes;
  42344. xrefFontStats[fontType] = true;
  42345. } catch (ex) { }
  42346. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42347. new ErrorFont(reason instanceof Error ? reason.message : reason),
  42348. font));
  42349. });
  42350. return fontCapability.promise;
  42351. },
  42352. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  42353. var lastIndex = operatorList.length - 1;
  42354. if (!args) {
  42355. args = [];
  42356. }
  42357. if (lastIndex < 0 ||
  42358. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  42359. operatorList.addOp(OPS.constructPath, [[fn], args]);
  42360. } else {
  42361. var opArgs = operatorList.argsArray[lastIndex];
  42362. opArgs[0].push(fn);
  42363. Array.prototype.push.apply(opArgs[1], args);
  42364. }
  42365. },
  42366. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  42367. cs, patterns, resources, task, xref) {
  42368. // compile tiling patterns
  42369. var patternName = args[args.length - 1];
  42370. // SCN/scn applies patterns along with normal colors
  42371. var pattern;
  42372. if (isName(patternName) &&
  42373. (pattern = patterns.get(patternName.name))) {
  42374. var dict = (isStream(pattern) ? pattern.dict : pattern);
  42375. var typeNum = dict.get('PatternType');
  42376. if (typeNum === TILING_PATTERN) {
  42377. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  42378. return this.handleTilingType(fn, color, resources, pattern,
  42379. dict, operatorList, task);
  42380. } else if (typeNum === SHADING_PATTERN) {
  42381. var shading = dict.get('Shading');
  42382. var matrix = dict.get('Matrix');
  42383. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  42384. this.handler);
  42385. operatorList.addOp(fn, pattern.getIR());
  42386. return Promise.resolve();
  42387. } else {
  42388. return Promise.reject('Unknown PatternType: ' + typeNum);
  42389. }
  42390. }
  42391. // TODO shall we fail here?
  42392. operatorList.addOp(fn, args);
  42393. return Promise.resolve();
  42394. },
  42395. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  42396. task,
  42397. resources,
  42398. operatorList,
  42399. initialState) {
  42400. var self = this;
  42401. var xref = this.xref;
  42402. var imageCache = Object.create(null);
  42403. assert(operatorList);
  42404. resources = (resources || Dict.empty);
  42405. var xobjs = (resources.get('XObject') || Dict.empty);
  42406. var patterns = (resources.get('Pattern') || Dict.empty);
  42407. var stateManager = new StateManager(initialState || new EvalState());
  42408. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42409. var timeSlotManager = new TimeSlotManager();
  42410. return new Promise(function next(resolve, reject) {
  42411. task.ensureNotTerminated();
  42412. timeSlotManager.reset();
  42413. var stop, operation = {}, i, ii, cs;
  42414. while (!(stop = timeSlotManager.check())) {
  42415. // The arguments parsed by read() are used beyond this loop, so we
  42416. // cannot reuse the same array on each iteration. Therefore we pass
  42417. // in |null| as the initial value (see the comment on
  42418. // EvaluatorPreprocessor_read() for why).
  42419. operation.args = null;
  42420. if (!(preprocessor.read(operation))) {
  42421. break;
  42422. }
  42423. var args = operation.args;
  42424. var fn = operation.fn;
  42425. switch (fn | 0) {
  42426. case OPS.paintXObject:
  42427. if (args[0].code) {
  42428. break;
  42429. }
  42430. // eagerly compile XForm objects
  42431. var name = args[0].name;
  42432. if (!name) {
  42433. warn('XObject must be referred to by name.');
  42434. continue;
  42435. }
  42436. if (imageCache[name] !== undefined) {
  42437. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  42438. args = null;
  42439. continue;
  42440. }
  42441. var xobj = xobjs.get(name);
  42442. if (xobj) {
  42443. assert(isStream(xobj), 'XObject should be a stream');
  42444. var type = xobj.dict.get('Subtype');
  42445. assert(isName(type),
  42446. 'XObject should have a Name subtype');
  42447. if (type.name === 'Form') {
  42448. stateManager.save();
  42449. return self.buildFormXObject(resources, xobj, null,
  42450. operatorList, task,
  42451. stateManager.state.clone()).
  42452. then(function () {
  42453. stateManager.restore();
  42454. next(resolve, reject);
  42455. }, reject);
  42456. } else if (type.name === 'Image') {
  42457. self.buildPaintImageXObject(resources, xobj, false,
  42458. operatorList, name, imageCache);
  42459. args = null;
  42460. continue;
  42461. } else if (type.name === 'PS') {
  42462. // PostScript XObjects are unused when viewing documents.
  42463. // See section 4.7.1 of Adobe's PDF reference.
  42464. info('Ignored XObject subtype PS');
  42465. continue;
  42466. } else {
  42467. error('Unhandled XObject subtype ' + type.name);
  42468. }
  42469. }
  42470. break;
  42471. case OPS.setFont:
  42472. var fontSize = args[1];
  42473. // eagerly collect all fonts
  42474. return self.handleSetFont(resources, args, null, operatorList,
  42475. task, stateManager.state).
  42476. then(function (loadedName) {
  42477. operatorList.addDependency(loadedName);
  42478. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  42479. next(resolve, reject);
  42480. }, reject);
  42481. case OPS.endInlineImage:
  42482. var cacheKey = args[0].cacheKey;
  42483. if (cacheKey) {
  42484. var cacheEntry = imageCache[cacheKey];
  42485. if (cacheEntry !== undefined) {
  42486. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  42487. args = null;
  42488. continue;
  42489. }
  42490. }
  42491. self.buildPaintImageXObject(resources, args[0], true,
  42492. operatorList, cacheKey, imageCache);
  42493. args = null;
  42494. continue;
  42495. case OPS.showText:
  42496. args[0] = self.handleText(args[0], stateManager.state);
  42497. break;
  42498. case OPS.showSpacedText:
  42499. var arr = args[0];
  42500. var combinedGlyphs = [];
  42501. var arrLength = arr.length;
  42502. var state = stateManager.state;
  42503. for (i = 0; i < arrLength; ++i) {
  42504. var arrItem = arr[i];
  42505. if (isString(arrItem)) {
  42506. Array.prototype.push.apply(combinedGlyphs,
  42507. self.handleText(arrItem, state));
  42508. } else if (isNum(arrItem)) {
  42509. combinedGlyphs.push(arrItem);
  42510. }
  42511. }
  42512. args[0] = combinedGlyphs;
  42513. fn = OPS.showText;
  42514. break;
  42515. case OPS.nextLineShowText:
  42516. operatorList.addOp(OPS.nextLine);
  42517. args[0] = self.handleText(args[0], stateManager.state);
  42518. fn = OPS.showText;
  42519. break;
  42520. case OPS.nextLineSetSpacingShowText:
  42521. operatorList.addOp(OPS.nextLine);
  42522. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  42523. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  42524. args[0] = self.handleText(args[0], stateManager.state);
  42525. fn = OPS.showText;
  42526. break;
  42527. case OPS.setTextRenderingMode:
  42528. stateManager.state.textRenderingMode = args[0];
  42529. break;
  42530. case OPS.setFillColorSpace:
  42531. stateManager.state.fillColorSpace =
  42532. ColorSpace.parse(args[0], xref, resources);
  42533. continue;
  42534. case OPS.setStrokeColorSpace:
  42535. stateManager.state.strokeColorSpace =
  42536. ColorSpace.parse(args[0], xref, resources);
  42537. continue;
  42538. case OPS.setFillColor:
  42539. cs = stateManager.state.fillColorSpace;
  42540. args = cs.getRgb(args, 0);
  42541. fn = OPS.setFillRGBColor;
  42542. break;
  42543. case OPS.setStrokeColor:
  42544. cs = stateManager.state.strokeColorSpace;
  42545. args = cs.getRgb(args, 0);
  42546. fn = OPS.setStrokeRGBColor;
  42547. break;
  42548. case OPS.setFillGray:
  42549. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  42550. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42551. fn = OPS.setFillRGBColor;
  42552. break;
  42553. case OPS.setStrokeGray:
  42554. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  42555. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42556. fn = OPS.setStrokeRGBColor;
  42557. break;
  42558. case OPS.setFillCMYKColor:
  42559. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  42560. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42561. fn = OPS.setFillRGBColor;
  42562. break;
  42563. case OPS.setStrokeCMYKColor:
  42564. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  42565. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42566. fn = OPS.setStrokeRGBColor;
  42567. break;
  42568. case OPS.setFillRGBColor:
  42569. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  42570. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42571. break;
  42572. case OPS.setStrokeRGBColor:
  42573. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  42574. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42575. break;
  42576. case OPS.setFillColorN:
  42577. cs = stateManager.state.fillColorSpace;
  42578. if (cs.name === 'Pattern') {
  42579. return self.handleColorN(operatorList, OPS.setFillColorN,
  42580. args, cs, patterns, resources, task, xref).then(function() {
  42581. next(resolve, reject);
  42582. }, reject);
  42583. }
  42584. args = cs.getRgb(args, 0);
  42585. fn = OPS.setFillRGBColor;
  42586. break;
  42587. case OPS.setStrokeColorN:
  42588. cs = stateManager.state.strokeColorSpace;
  42589. if (cs.name === 'Pattern') {
  42590. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  42591. args, cs, patterns, resources, task, xref).then(function() {
  42592. next(resolve, reject);
  42593. }, reject);
  42594. }
  42595. args = cs.getRgb(args, 0);
  42596. fn = OPS.setStrokeRGBColor;
  42597. break;
  42598. case OPS.shadingFill:
  42599. var shadingRes = resources.get('Shading');
  42600. if (!shadingRes) {
  42601. error('No shading resource found');
  42602. }
  42603. var shading = shadingRes.get(args[0].name);
  42604. if (!shading) {
  42605. error('No shading object found');
  42606. }
  42607. var shadingFill = Pattern.parseShading(shading, null, xref,
  42608. resources, self.handler);
  42609. var patternIR = shadingFill.getIR();
  42610. args = [patternIR];
  42611. fn = OPS.shadingFill;
  42612. break;
  42613. case OPS.setGState:
  42614. var dictName = args[0];
  42615. var extGState = resources.get('ExtGState');
  42616. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42617. break;
  42618. }
  42619. var gState = extGState.get(dictName.name);
  42620. return self.setGState(resources, gState, operatorList, task,
  42621. xref, stateManager).then(function() {
  42622. next(resolve, reject);
  42623. }, reject);
  42624. case OPS.moveTo:
  42625. case OPS.lineTo:
  42626. case OPS.curveTo:
  42627. case OPS.curveTo2:
  42628. case OPS.curveTo3:
  42629. case OPS.closePath:
  42630. self.buildPath(operatorList, fn, args);
  42631. continue;
  42632. case OPS.rectangle:
  42633. self.buildPath(operatorList, fn, args);
  42634. continue;
  42635. case OPS.markPoint:
  42636. case OPS.markPointProps:
  42637. case OPS.beginMarkedContent:
  42638. case OPS.beginMarkedContentProps:
  42639. case OPS.endMarkedContent:
  42640. case OPS.beginCompat:
  42641. case OPS.endCompat:
  42642. // Ignore operators where the corresponding handlers are known to
  42643. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  42644. // serialization errors and is also a bit more efficient.
  42645. // We could also try to serialize all objects in a general way,
  42646. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  42647. // but doing so is meaningless without knowing the semantics.
  42648. continue;
  42649. default:
  42650. // Note: Ignore the operator if it has `Dict` arguments, since
  42651. // those are non-serializable, otherwise postMessage will throw
  42652. // "An object could not be cloned.".
  42653. if (args !== null) {
  42654. for (i = 0, ii = args.length; i < ii; i++) {
  42655. if (args[i] instanceof Dict) {
  42656. break;
  42657. }
  42658. }
  42659. if (i < ii) {
  42660. warn('getOperatorList - ignoring operator: ' + fn);
  42661. continue;
  42662. }
  42663. }
  42664. }
  42665. operatorList.addOp(fn, args);
  42666. }
  42667. if (stop) {
  42668. deferred.then(function () {
  42669. next(resolve, reject);
  42670. }, reject);
  42671. return;
  42672. }
  42673. // Some PDFs don't close all restores inside object/form.
  42674. // Closing those for them.
  42675. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  42676. operatorList.addOp(OPS.restore, []);
  42677. }
  42678. resolve();
  42679. });
  42680. },
  42681. getTextContent:
  42682. function PartialEvaluator_getTextContent(stream, task, resources,
  42683. stateManager,
  42684. normalizeWhitespace) {
  42685. stateManager = (stateManager || new StateManager(new TextState()));
  42686. var WhitespaceRegexp = /\s/g;
  42687. var textContent = {
  42688. items: [],
  42689. styles: Object.create(null)
  42690. };
  42691. var textContentItem = {
  42692. initialized: false,
  42693. str: [],
  42694. width: 0,
  42695. height: 0,
  42696. vertical: false,
  42697. lastAdvanceWidth: 0,
  42698. lastAdvanceHeight: 0,
  42699. textAdvanceScale: 0,
  42700. spaceWidth: 0,
  42701. fakeSpaceMin: Infinity,
  42702. fakeMultiSpaceMin: Infinity,
  42703. fakeMultiSpaceMax: -0,
  42704. textRunBreakAllowed: false,
  42705. transform: null,
  42706. fontName: null
  42707. };
  42708. var SPACE_FACTOR = 0.3;
  42709. var MULTI_SPACE_FACTOR = 1.5;
  42710. var MULTI_SPACE_FACTOR_MAX = 4;
  42711. var self = this;
  42712. var xref = this.xref;
  42713. resources = (xref.fetchIfRef(resources) || Dict.empty);
  42714. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  42715. var xobjs = null;
  42716. var xobjsCache = Object.create(null);
  42717. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42718. var textState;
  42719. function ensureTextContentItem() {
  42720. if (textContentItem.initialized) {
  42721. return textContentItem;
  42722. }
  42723. var font = textState.font;
  42724. if (!(font.loadedName in textContent.styles)) {
  42725. textContent.styles[font.loadedName] = {
  42726. fontFamily: font.fallbackName,
  42727. ascent: font.ascent,
  42728. descent: font.descent,
  42729. vertical: font.vertical
  42730. };
  42731. }
  42732. textContentItem.fontName = font.loadedName;
  42733. // 9.4.4 Text Space Details
  42734. var tsm = [textState.fontSize * textState.textHScale, 0,
  42735. 0, textState.fontSize,
  42736. 0, textState.textRise];
  42737. if (font.isType3Font &&
  42738. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  42739. textState.fontSize === 1) {
  42740. var glyphHeight = font.bbox[3] - font.bbox[1];
  42741. if (glyphHeight > 0) {
  42742. glyphHeight = glyphHeight * textState.fontMatrix[3];
  42743. tsm[3] *= glyphHeight;
  42744. }
  42745. }
  42746. var trm = Util.transform(textState.ctm,
  42747. Util.transform(textState.textMatrix, tsm));
  42748. textContentItem.transform = trm;
  42749. if (!font.vertical) {
  42750. textContentItem.width = 0;
  42751. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  42752. textContentItem.vertical = false;
  42753. } else {
  42754. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  42755. textContentItem.height = 0;
  42756. textContentItem.vertical = true;
  42757. }
  42758. var a = textState.textLineMatrix[0];
  42759. var b = textState.textLineMatrix[1];
  42760. var scaleLineX = Math.sqrt(a * a + b * b);
  42761. a = textState.ctm[0];
  42762. b = textState.ctm[1];
  42763. var scaleCtmX = Math.sqrt(a * a + b * b);
  42764. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  42765. textContentItem.lastAdvanceWidth = 0;
  42766. textContentItem.lastAdvanceHeight = 0;
  42767. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  42768. if (spaceWidth) {
  42769. textContentItem.spaceWidth = spaceWidth;
  42770. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  42771. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  42772. textContentItem.fakeMultiSpaceMax =
  42773. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  42774. // It's okay for monospace fonts to fake as much space as needed.
  42775. textContentItem.textRunBreakAllowed = !font.isMonospace;
  42776. } else {
  42777. textContentItem.spaceWidth = 0;
  42778. textContentItem.fakeSpaceMin = Infinity;
  42779. textContentItem.fakeMultiSpaceMin = Infinity;
  42780. textContentItem.fakeMultiSpaceMax = 0;
  42781. textContentItem.textRunBreakAllowed = false;
  42782. }
  42783. textContentItem.initialized = true;
  42784. return textContentItem;
  42785. }
  42786. function replaceWhitespace(str) {
  42787. // Replaces all whitespaces with standard spaces (0x20), to avoid
  42788. // alignment issues between the textLayer and the canvas if the text
  42789. // contains e.g. tabs (fixes issue6612.pdf).
  42790. var i = 0, ii = str.length, code;
  42791. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  42792. i++;
  42793. }
  42794. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  42795. }
  42796. function runBidiTransform(textChunk) {
  42797. var str = textChunk.str.join('');
  42798. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  42799. return {
  42800. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  42801. bidiResult.str),
  42802. dir: bidiResult.dir,
  42803. width: textChunk.width,
  42804. height: textChunk.height,
  42805. transform: textChunk.transform,
  42806. fontName: textChunk.fontName
  42807. };
  42808. }
  42809. function handleSetFont(fontName, fontRef) {
  42810. return self.loadFont(fontName, fontRef, xref, resources).
  42811. then(function (translated) {
  42812. textState.font = translated.font;
  42813. textState.fontMatrix = translated.font.fontMatrix ||
  42814. FONT_IDENTITY_MATRIX;
  42815. });
  42816. }
  42817. function buildTextContentItem(chars) {
  42818. var font = textState.font;
  42819. var textChunk = ensureTextContentItem();
  42820. var width = 0;
  42821. var height = 0;
  42822. var glyphs = font.charsToGlyphs(chars);
  42823. var defaultVMetrics = font.defaultVMetrics;
  42824. for (var i = 0; i < glyphs.length; i++) {
  42825. var glyph = glyphs[i];
  42826. var vMetricX = null;
  42827. var vMetricY = null;
  42828. var glyphWidth = null;
  42829. if (font.vertical) {
  42830. if (glyph.vmetric) {
  42831. glyphWidth = glyph.vmetric[0];
  42832. vMetricX = glyph.vmetric[1];
  42833. vMetricY = glyph.vmetric[2];
  42834. } else {
  42835. glyphWidth = glyph.width;
  42836. vMetricX = glyph.width * 0.5;
  42837. vMetricY = defaultVMetrics[2];
  42838. }
  42839. } else {
  42840. glyphWidth = glyph.width;
  42841. }
  42842. var glyphUnicode = glyph.unicode;
  42843. var NormalizedUnicodes = getNormalizedUnicodes();
  42844. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  42845. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  42846. }
  42847. glyphUnicode = reverseIfRtl(glyphUnicode);
  42848. // The following will calculate the x and y of the individual glyphs.
  42849. // if (font.vertical) {
  42850. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  42851. // textState.fontMatrix[0];
  42852. // tsm[5] -= vMetricY * textState.fontSize *
  42853. // textState.fontMatrix[0];
  42854. // }
  42855. // var trm = Util.transform(textState.textMatrix, tsm);
  42856. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  42857. // var x = pt[0];
  42858. // var y = pt[1];
  42859. var charSpacing = textState.charSpacing;
  42860. if (glyph.isSpace) {
  42861. var wordSpacing = textState.wordSpacing;
  42862. charSpacing += wordSpacing;
  42863. if (wordSpacing > 0) {
  42864. addFakeSpaces(wordSpacing, textChunk.str);
  42865. }
  42866. }
  42867. var tx = 0;
  42868. var ty = 0;
  42869. if (!font.vertical) {
  42870. var w0 = glyphWidth * textState.fontMatrix[0];
  42871. tx = (w0 * textState.fontSize + charSpacing) *
  42872. textState.textHScale;
  42873. width += tx;
  42874. } else {
  42875. var w1 = glyphWidth * textState.fontMatrix[0];
  42876. ty = w1 * textState.fontSize + charSpacing;
  42877. height += ty;
  42878. }
  42879. textState.translateTextMatrix(tx, ty);
  42880. textChunk.str.push(glyphUnicode);
  42881. }
  42882. if (!font.vertical) {
  42883. textChunk.lastAdvanceWidth = width;
  42884. textChunk.width += width * textChunk.textAdvanceScale;
  42885. } else {
  42886. textChunk.lastAdvanceHeight = height;
  42887. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  42888. }
  42889. return textChunk;
  42890. }
  42891. function addFakeSpaces(width, strBuf) {
  42892. if (width < textContentItem.fakeSpaceMin) {
  42893. return;
  42894. }
  42895. if (width < textContentItem.fakeMultiSpaceMin) {
  42896. strBuf.push(' ');
  42897. return;
  42898. }
  42899. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  42900. while (fakeSpaces-- > 0) {
  42901. strBuf.push(' ');
  42902. }
  42903. }
  42904. function flushTextContentItem() {
  42905. if (!textContentItem.initialized) {
  42906. return;
  42907. }
  42908. textContent.items.push(runBidiTransform(textContentItem));
  42909. textContentItem.initialized = false;
  42910. textContentItem.str.length = 0;
  42911. }
  42912. var timeSlotManager = new TimeSlotManager();
  42913. return new Promise(function next(resolve, reject) {
  42914. task.ensureNotTerminated();
  42915. timeSlotManager.reset();
  42916. var stop, operation = {}, args = [];
  42917. while (!(stop = timeSlotManager.check())) {
  42918. // The arguments parsed by read() are not used beyond this loop, so
  42919. // we can reuse the same array on every iteration, thus avoiding
  42920. // unnecessary allocations.
  42921. args.length = 0;
  42922. operation.args = args;
  42923. if (!(preprocessor.read(operation))) {
  42924. break;
  42925. }
  42926. textState = stateManager.state;
  42927. var fn = operation.fn;
  42928. args = operation.args;
  42929. var advance;
  42930. switch (fn | 0) {
  42931. case OPS.setFont:
  42932. flushTextContentItem();
  42933. textState.fontSize = args[1];
  42934. return handleSetFont(args[0].name).then(function() {
  42935. next(resolve, reject);
  42936. }, reject);
  42937. case OPS.setTextRise:
  42938. flushTextContentItem();
  42939. textState.textRise = args[0];
  42940. break;
  42941. case OPS.setHScale:
  42942. flushTextContentItem();
  42943. textState.textHScale = args[0] / 100;
  42944. break;
  42945. case OPS.setLeading:
  42946. flushTextContentItem();
  42947. textState.leading = args[0];
  42948. break;
  42949. case OPS.moveText:
  42950. // Optimization to treat same line movement as advance
  42951. var isSameTextLine = !textState.font ? false :
  42952. ((textState.font.vertical ? args[0] : args[1]) === 0);
  42953. advance = args[0] - args[1];
  42954. if (isSameTextLine && textContentItem.initialized &&
  42955. advance > 0 &&
  42956. advance <= textContentItem.fakeMultiSpaceMax) {
  42957. textState.translateTextLineMatrix(args[0], args[1]);
  42958. textContentItem.width +=
  42959. (args[0] - textContentItem.lastAdvanceWidth);
  42960. textContentItem.height +=
  42961. (args[1] - textContentItem.lastAdvanceHeight);
  42962. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  42963. (args[1] - textContentItem.lastAdvanceHeight);
  42964. addFakeSpaces(diff, textContentItem.str);
  42965. break;
  42966. }
  42967. flushTextContentItem();
  42968. textState.translateTextLineMatrix(args[0], args[1]);
  42969. textState.textMatrix = textState.textLineMatrix.slice();
  42970. break;
  42971. case OPS.setLeadingMoveText:
  42972. flushTextContentItem();
  42973. textState.leading = -args[1];
  42974. textState.translateTextLineMatrix(args[0], args[1]);
  42975. textState.textMatrix = textState.textLineMatrix.slice();
  42976. break;
  42977. case OPS.nextLine:
  42978. flushTextContentItem();
  42979. textState.carriageReturn();
  42980. break;
  42981. case OPS.setTextMatrix:
  42982. flushTextContentItem();
  42983. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  42984. args[4], args[5]);
  42985. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  42986. args[4], args[5]);
  42987. break;
  42988. case OPS.setCharSpacing:
  42989. textState.charSpacing = args[0];
  42990. break;
  42991. case OPS.setWordSpacing:
  42992. textState.wordSpacing = args[0];
  42993. break;
  42994. case OPS.beginText:
  42995. flushTextContentItem();
  42996. textState.textMatrix = IDENTITY_MATRIX.slice();
  42997. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  42998. break;
  42999. case OPS.showSpacedText:
  43000. var items = args[0];
  43001. var offset;
  43002. for (var j = 0, jj = items.length; j < jj; j++) {
  43003. if (typeof items[j] === 'string') {
  43004. buildTextContentItem(items[j]);
  43005. } else {
  43006. ensureTextContentItem();
  43007. // PDF Specification 5.3.2 states:
  43008. // The number is expressed in thousandths of a unit of text
  43009. // space.
  43010. // This amount is subtracted from the current horizontal or
  43011. // vertical coordinate, depending on the writing mode.
  43012. // In the default coordinate system, a positive adjustment
  43013. // has the effect of moving the next glyph painted either to
  43014. // the left or down by the given amount.
  43015. advance = items[j] * textState.fontSize / 1000;
  43016. var breakTextRun = false;
  43017. if (textState.font.vertical) {
  43018. offset = advance *
  43019. (textState.textHScale * textState.textMatrix[2] +
  43020. textState.textMatrix[3]);
  43021. textState.translateTextMatrix(0, advance);
  43022. breakTextRun = textContentItem.textRunBreakAllowed &&
  43023. advance > textContentItem.fakeMultiSpaceMax;
  43024. if (!breakTextRun) {
  43025. // Value needs to be added to height to paint down.
  43026. textContentItem.height += offset;
  43027. }
  43028. } else {
  43029. advance = -advance;
  43030. offset = advance * (
  43031. textState.textHScale * textState.textMatrix[0] +
  43032. textState.textMatrix[1]);
  43033. textState.translateTextMatrix(advance, 0);
  43034. breakTextRun = textContentItem.textRunBreakAllowed &&
  43035. advance > textContentItem.fakeMultiSpaceMax;
  43036. if (!breakTextRun) {
  43037. // Value needs to be subtracted from width to paint left.
  43038. textContentItem.width += offset;
  43039. }
  43040. }
  43041. if (breakTextRun) {
  43042. flushTextContentItem();
  43043. } else if (advance > 0) {
  43044. addFakeSpaces(advance, textContentItem.str);
  43045. }
  43046. }
  43047. }
  43048. break;
  43049. case OPS.showText:
  43050. buildTextContentItem(args[0]);
  43051. break;
  43052. case OPS.nextLineShowText:
  43053. flushTextContentItem();
  43054. textState.carriageReturn();
  43055. buildTextContentItem(args[0]);
  43056. break;
  43057. case OPS.nextLineSetSpacingShowText:
  43058. flushTextContentItem();
  43059. textState.wordSpacing = args[0];
  43060. textState.charSpacing = args[1];
  43061. textState.carriageReturn();
  43062. buildTextContentItem(args[2]);
  43063. break;
  43064. case OPS.paintXObject:
  43065. flushTextContentItem();
  43066. if (args[0].code) {
  43067. break;
  43068. }
  43069. if (!xobjs) {
  43070. xobjs = (resources.get('XObject') || Dict.empty);
  43071. }
  43072. var name = args[0].name;
  43073. if (xobjsCache.key === name) {
  43074. if (xobjsCache.texts) {
  43075. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  43076. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  43077. }
  43078. break;
  43079. }
  43080. var xobj = xobjs.get(name);
  43081. if (!xobj) {
  43082. break;
  43083. }
  43084. assert(isStream(xobj), 'XObject should be a stream');
  43085. var type = xobj.dict.get('Subtype');
  43086. assert(isName(type),
  43087. 'XObject should have a Name subtype');
  43088. if ('Form' !== type.name) {
  43089. xobjsCache.key = name;
  43090. xobjsCache.texts = null;
  43091. break;
  43092. }
  43093. stateManager.save();
  43094. var matrix = xobj.dict.get('Matrix');
  43095. if (isArray(matrix) && matrix.length === 6) {
  43096. stateManager.transform(matrix);
  43097. }
  43098. return self.getTextContent(xobj, task,
  43099. xobj.dict.get('Resources') || resources, stateManager,
  43100. normalizeWhitespace).then(function (formTextContent) {
  43101. Util.appendToArray(textContent.items, formTextContent.items);
  43102. Util.extendObj(textContent.styles, formTextContent.styles);
  43103. stateManager.restore();
  43104. xobjsCache.key = name;
  43105. xobjsCache.texts = formTextContent;
  43106. next(resolve, reject);
  43107. }, reject);
  43108. case OPS.setGState:
  43109. flushTextContentItem();
  43110. var dictName = args[0];
  43111. var extGState = resources.get('ExtGState');
  43112. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43113. break;
  43114. }
  43115. var gsStateMap = extGState.get(dictName.name);
  43116. var gsStateFont = null;
  43117. for (var key in gsStateMap) {
  43118. if (key === 'Font') {
  43119. assert(!gsStateFont);
  43120. gsStateFont = gsStateMap[key];
  43121. }
  43122. }
  43123. if (gsStateFont) {
  43124. textState.fontSize = gsStateFont[1];
  43125. return handleSetFont(gsStateFont[0]).then(function() {
  43126. next(resolve, reject);
  43127. }, reject);
  43128. }
  43129. break;
  43130. } // switch
  43131. } // while
  43132. if (stop) {
  43133. deferred.then(function () {
  43134. next(resolve, reject);
  43135. }, reject);
  43136. return;
  43137. }
  43138. flushTextContentItem();
  43139. resolve(textContent);
  43140. });
  43141. },
  43142. extractDataStructures: function
  43143. partialEvaluatorExtractDataStructures(dict, baseDict,
  43144. xref, properties) {
  43145. // 9.10.2
  43146. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  43147. if (toUnicode) {
  43148. properties.toUnicode = this.readToUnicode(toUnicode);
  43149. }
  43150. if (properties.composite) {
  43151. // CIDSystemInfo helps to match CID to glyphs
  43152. var cidSystemInfo = dict.get('CIDSystemInfo');
  43153. if (isDict(cidSystemInfo)) {
  43154. properties.cidSystemInfo = {
  43155. registry: cidSystemInfo.get('Registry'),
  43156. ordering: cidSystemInfo.get('Ordering'),
  43157. supplement: cidSystemInfo.get('Supplement')
  43158. };
  43159. }
  43160. var cidToGidMap = dict.get('CIDToGIDMap');
  43161. if (isStream(cidToGidMap)) {
  43162. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  43163. }
  43164. }
  43165. // Based on 9.6.6 of the spec the encoding can come from multiple places
  43166. // and depends on the font type. The base encoding and differences are
  43167. // read here, but the encoding that is actually used is chosen during
  43168. // glyph mapping in the font.
  43169. // TODO: Loading the built in encoding in the font would allow the
  43170. // differences to be merged in here not require us to hold on to it.
  43171. var differences = [];
  43172. var baseEncodingName = null;
  43173. var encoding;
  43174. if (dict.has('Encoding')) {
  43175. encoding = dict.get('Encoding');
  43176. if (isDict(encoding)) {
  43177. baseEncodingName = encoding.get('BaseEncoding');
  43178. baseEncodingName = (isName(baseEncodingName) ?
  43179. baseEncodingName.name : null);
  43180. // Load the differences between the base and original
  43181. if (encoding.has('Differences')) {
  43182. var diffEncoding = encoding.get('Differences');
  43183. var index = 0;
  43184. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  43185. var data = xref.fetchIfRef(diffEncoding[j]);
  43186. if (isNum(data)) {
  43187. index = data;
  43188. } else if (isName(data)) {
  43189. differences[index++] = data.name;
  43190. } else {
  43191. error('Invalid entry in \'Differences\' array: ' + data);
  43192. }
  43193. }
  43194. }
  43195. } else if (isName(encoding)) {
  43196. baseEncodingName = encoding.name;
  43197. } else {
  43198. error('Encoding is not a Name nor a Dict');
  43199. }
  43200. // According to table 114 if the encoding is a named encoding it must be
  43201. // one of these predefined encodings.
  43202. if ((baseEncodingName !== 'MacRomanEncoding' &&
  43203. baseEncodingName !== 'MacExpertEncoding' &&
  43204. baseEncodingName !== 'WinAnsiEncoding')) {
  43205. baseEncodingName = null;
  43206. }
  43207. }
  43208. if (baseEncodingName) {
  43209. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  43210. } else {
  43211. encoding = (properties.type === 'TrueType' ?
  43212. WinAnsiEncoding : StandardEncoding);
  43213. // The Symbolic attribute can be misused for regular fonts
  43214. // Heuristic: we have to check if the font is a standard one also
  43215. if (!!(properties.flags & FontFlags.Symbolic)) {
  43216. encoding = MacRomanEncoding;
  43217. if (!properties.file) {
  43218. if (/Symbol/i.test(properties.name)) {
  43219. encoding = SymbolSetEncoding;
  43220. } else if (/Dingbats/i.test(properties.name)) {
  43221. encoding = ZapfDingbatsEncoding;
  43222. }
  43223. }
  43224. }
  43225. properties.defaultEncoding = encoding;
  43226. }
  43227. properties.differences = differences;
  43228. properties.baseEncodingName = baseEncodingName;
  43229. properties.dict = dict;
  43230. },
  43231. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  43232. var cmap, cmapObj = toUnicode;
  43233. if (isName(cmapObj)) {
  43234. cmap = CMapFactory.create(cmapObj,
  43235. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43236. if (cmap instanceof IdentityCMap) {
  43237. return new IdentityToUnicodeMap(0, 0xFFFF);
  43238. }
  43239. return new ToUnicodeMap(cmap.getMap());
  43240. } else if (isStream(cmapObj)) {
  43241. cmap = CMapFactory.create(cmapObj,
  43242. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43243. if (cmap instanceof IdentityCMap) {
  43244. return new IdentityToUnicodeMap(0, 0xFFFF);
  43245. }
  43246. var map = new Array(cmap.length);
  43247. // Convert UTF-16BE
  43248. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  43249. // to iterate over all keys.
  43250. cmap.forEach(function(charCode, token) {
  43251. var str = [];
  43252. for (var k = 0; k < token.length; k += 2) {
  43253. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43254. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  43255. str.push(w1);
  43256. continue;
  43257. }
  43258. k += 2;
  43259. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43260. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  43261. }
  43262. map[charCode] = String.fromCharCode.apply(String, str);
  43263. });
  43264. return new ToUnicodeMap(map);
  43265. }
  43266. return null;
  43267. },
  43268. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  43269. // Extract the encoding from the CIDToGIDMap
  43270. var glyphsData = cidToGidStream.getBytes();
  43271. // Set encoding 0 to later verify the font has an encoding
  43272. var result = [];
  43273. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  43274. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  43275. if (glyphID === 0) {
  43276. continue;
  43277. }
  43278. var code = j >> 1;
  43279. result[code] = glyphID;
  43280. }
  43281. return result;
  43282. },
  43283. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  43284. descriptor,
  43285. properties) {
  43286. var glyphsWidths = [];
  43287. var defaultWidth = 0;
  43288. var glyphsVMetrics = [];
  43289. var defaultVMetrics;
  43290. var i, ii, j, jj, start, code, widths;
  43291. if (properties.composite) {
  43292. defaultWidth = dict.get('DW') || 1000;
  43293. widths = dict.get('W');
  43294. if (widths) {
  43295. for (i = 0, ii = widths.length; i < ii; i++) {
  43296. start = widths[i++];
  43297. code = xref.fetchIfRef(widths[i]);
  43298. if (isArray(code)) {
  43299. for (j = 0, jj = code.length; j < jj; j++) {
  43300. glyphsWidths[start++] = code[j];
  43301. }
  43302. } else {
  43303. var width = widths[++i];
  43304. for (j = start; j <= code; j++) {
  43305. glyphsWidths[j] = width;
  43306. }
  43307. }
  43308. }
  43309. }
  43310. if (properties.vertical) {
  43311. var vmetrics = (dict.get('DW2') || [880, -1000]);
  43312. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  43313. vmetrics = dict.get('W2');
  43314. if (vmetrics) {
  43315. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  43316. start = vmetrics[i++];
  43317. code = xref.fetchIfRef(vmetrics[i]);
  43318. if (isArray(code)) {
  43319. for (j = 0, jj = code.length; j < jj; j++) {
  43320. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  43321. }
  43322. } else {
  43323. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  43324. for (j = start; j <= code; j++) {
  43325. glyphsVMetrics[j] = vmetric;
  43326. }
  43327. }
  43328. }
  43329. }
  43330. }
  43331. } else {
  43332. var firstChar = properties.firstChar;
  43333. widths = dict.get('Widths');
  43334. if (widths) {
  43335. j = firstChar;
  43336. for (i = 0, ii = widths.length; i < ii; i++) {
  43337. glyphsWidths[j++] = widths[i];
  43338. }
  43339. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  43340. } else {
  43341. // Trying get the BaseFont metrics (see comment above).
  43342. var baseFontName = dict.get('BaseFont');
  43343. if (isName(baseFontName)) {
  43344. var metrics = this.getBaseFontMetrics(baseFontName.name);
  43345. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  43346. properties);
  43347. defaultWidth = metrics.defaultWidth;
  43348. }
  43349. }
  43350. }
  43351. // Heuristic: detection of monospace font by checking all non-zero widths
  43352. var isMonospace = true;
  43353. var firstWidth = defaultWidth;
  43354. for (var glyph in glyphsWidths) {
  43355. var glyphWidth = glyphsWidths[glyph];
  43356. if (!glyphWidth) {
  43357. continue;
  43358. }
  43359. if (!firstWidth) {
  43360. firstWidth = glyphWidth;
  43361. continue;
  43362. }
  43363. if (firstWidth !== glyphWidth) {
  43364. isMonospace = false;
  43365. break;
  43366. }
  43367. }
  43368. if (isMonospace) {
  43369. properties.flags |= FontFlags.FixedPitch;
  43370. }
  43371. properties.defaultWidth = defaultWidth;
  43372. properties.widths = glyphsWidths;
  43373. properties.defaultVMetrics = defaultVMetrics;
  43374. properties.vmetrics = glyphsVMetrics;
  43375. },
  43376. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  43377. // Simulating descriptor flags attribute
  43378. var fontNameWoStyle = baseFontName.split('-')[0];
  43379. return (fontNameWoStyle in getSerifFonts()) ||
  43380. (fontNameWoStyle.search(/serif/gi) !== -1);
  43381. },
  43382. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  43383. var defaultWidth = 0;
  43384. var widths = [];
  43385. var monospace = false;
  43386. var stdFontMap = getStdFontMap();
  43387. var lookupName = (stdFontMap[name] || name);
  43388. var Metrics = getMetrics();
  43389. if (!(lookupName in Metrics)) {
  43390. // Use default fonts for looking up font metrics if the passed
  43391. // font is not a base font
  43392. if (this.isSerifFont(name)) {
  43393. lookupName = 'Times-Roman';
  43394. } else {
  43395. lookupName = 'Helvetica';
  43396. }
  43397. }
  43398. var glyphWidths = Metrics[lookupName];
  43399. if (isNum(glyphWidths)) {
  43400. defaultWidth = glyphWidths;
  43401. monospace = true;
  43402. } else {
  43403. widths = glyphWidths(); // expand lazy widths array
  43404. }
  43405. return {
  43406. defaultWidth: defaultWidth,
  43407. monospace: monospace,
  43408. widths: widths
  43409. };
  43410. },
  43411. buildCharCodeToWidth:
  43412. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  43413. properties) {
  43414. var widths = Object.create(null);
  43415. var differences = properties.differences;
  43416. var encoding = properties.defaultEncoding;
  43417. for (var charCode = 0; charCode < 256; charCode++) {
  43418. if (charCode in differences &&
  43419. widthsByGlyphName[differences[charCode]]) {
  43420. widths[charCode] = widthsByGlyphName[differences[charCode]];
  43421. continue;
  43422. }
  43423. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  43424. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  43425. continue;
  43426. }
  43427. }
  43428. return widths;
  43429. },
  43430. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  43431. var baseDict = dict;
  43432. var type = dict.get('Subtype');
  43433. assert(isName(type), 'invalid font Subtype');
  43434. var composite = false;
  43435. var uint8array;
  43436. if (type.name === 'Type0') {
  43437. // If font is a composite
  43438. // - get the descendant font
  43439. // - set the type according to the descendant font
  43440. // - get the FontDescriptor from the descendant font
  43441. var df = dict.get('DescendantFonts');
  43442. if (!df) {
  43443. error('Descendant fonts are not specified');
  43444. }
  43445. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  43446. type = dict.get('Subtype');
  43447. assert(isName(type), 'invalid font Subtype');
  43448. composite = true;
  43449. }
  43450. var descriptor = dict.get('FontDescriptor');
  43451. if (descriptor) {
  43452. var hash = new MurmurHash3_64();
  43453. var encoding = baseDict.getRaw('Encoding');
  43454. if (isName(encoding)) {
  43455. hash.update(encoding.name);
  43456. } else if (isRef(encoding)) {
  43457. hash.update(encoding.num + '_' + encoding.gen);
  43458. } else if (isDict(encoding)) {
  43459. var keys = encoding.getKeys();
  43460. for (var i = 0, ii = keys.length; i < ii; i++) {
  43461. var entry = encoding.getRaw(keys[i]);
  43462. if (isName(entry)) {
  43463. hash.update(entry.name);
  43464. } else if (isRef(entry)) {
  43465. hash.update(entry.num + '_' + entry.gen);
  43466. } else if (isArray(entry)) { // 'Differences' entry.
  43467. // Ideally we should check the contents of the array, but to avoid
  43468. // parsing it here and then again in |extractDataStructures|,
  43469. // we only use the array length for now (fixes bug1157493.pdf).
  43470. hash.update(entry.length.toString());
  43471. }
  43472. }
  43473. }
  43474. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  43475. if (isStream(toUnicode)) {
  43476. var stream = toUnicode.str || toUnicode;
  43477. uint8array = stream.buffer ?
  43478. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  43479. new Uint8Array(stream.bytes.buffer,
  43480. stream.start, stream.end - stream.start);
  43481. hash.update(uint8array);
  43482. } else if (isName(toUnicode)) {
  43483. hash.update(toUnicode.name);
  43484. }
  43485. var widths = dict.get('Widths') || baseDict.get('Widths');
  43486. if (widths) {
  43487. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  43488. hash.update(uint8array);
  43489. }
  43490. }
  43491. return {
  43492. descriptor: descriptor,
  43493. dict: dict,
  43494. baseDict: baseDict,
  43495. composite: composite,
  43496. type: type.name,
  43497. hash: hash ? hash.hexdigest() : ''
  43498. };
  43499. },
  43500. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  43501. xref) {
  43502. var baseDict = preEvaluatedFont.baseDict;
  43503. var dict = preEvaluatedFont.dict;
  43504. var composite = preEvaluatedFont.composite;
  43505. var descriptor = preEvaluatedFont.descriptor;
  43506. var type = preEvaluatedFont.type;
  43507. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  43508. var properties;
  43509. if (!descriptor) {
  43510. if (type === 'Type3') {
  43511. // FontDescriptor is only required for Type3 fonts when the document
  43512. // is a tagged pdf. Create a barbebones one to get by.
  43513. descriptor = new Dict(null);
  43514. descriptor.set('FontName', Name.get(type));
  43515. descriptor.set('FontBBox', dict.get('FontBBox'));
  43516. } else {
  43517. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  43518. // FontDescriptor was not required.
  43519. // This case is here for compatibility.
  43520. var baseFontName = dict.get('BaseFont');
  43521. if (!isName(baseFontName)) {
  43522. error('Base font is not specified');
  43523. }
  43524. // Using base font name as a font name.
  43525. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  43526. var metrics = this.getBaseFontMetrics(baseFontName);
  43527. // Simulating descriptor flags attribute
  43528. var fontNameWoStyle = baseFontName.split('-')[0];
  43529. var flags =
  43530. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  43531. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  43532. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  43533. FontFlags.Nonsymbolic);
  43534. properties = {
  43535. type: type,
  43536. name: baseFontName,
  43537. widths: metrics.widths,
  43538. defaultWidth: metrics.defaultWidth,
  43539. flags: flags,
  43540. firstChar: 0,
  43541. lastChar: maxCharIndex
  43542. };
  43543. this.extractDataStructures(dict, dict, xref, properties);
  43544. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  43545. properties);
  43546. return new Font(baseFontName, null, properties);
  43547. }
  43548. }
  43549. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  43550. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  43551. // to ignore this rule when a variant of a standart font is used.
  43552. // TODO Fill the width array depending on which of the base font this is
  43553. // a variant.
  43554. var firstChar = (dict.get('FirstChar') || 0);
  43555. var lastChar = (dict.get('LastChar') || maxCharIndex);
  43556. var fontName = descriptor.get('FontName');
  43557. var baseFont = dict.get('BaseFont');
  43558. // Some bad PDFs have a string as the font name.
  43559. if (isString(fontName)) {
  43560. fontName = Name.get(fontName);
  43561. }
  43562. if (isString(baseFont)) {
  43563. baseFont = Name.get(baseFont);
  43564. }
  43565. if (type !== 'Type3') {
  43566. var fontNameStr = fontName && fontName.name;
  43567. var baseFontStr = baseFont && baseFont.name;
  43568. if (fontNameStr !== baseFontStr) {
  43569. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  43570. '" but should be the same as the Font\'s BaseFont "' +
  43571. baseFontStr + '"');
  43572. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  43573. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  43574. if (fontNameStr && baseFontStr &&
  43575. baseFontStr.indexOf(fontNameStr) === 0) {
  43576. fontName = baseFont;
  43577. }
  43578. }
  43579. }
  43580. fontName = (fontName || baseFont);
  43581. assert(isName(fontName), 'invalid font name');
  43582. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  43583. if (fontFile) {
  43584. if (fontFile.dict) {
  43585. var subtype = fontFile.dict.get('Subtype');
  43586. if (subtype) {
  43587. subtype = subtype.name;
  43588. }
  43589. var length1 = fontFile.dict.get('Length1');
  43590. var length2 = fontFile.dict.get('Length2');
  43591. }
  43592. }
  43593. properties = {
  43594. type: type,
  43595. name: fontName.name,
  43596. subtype: subtype,
  43597. file: fontFile,
  43598. length1: length1,
  43599. length2: length2,
  43600. loadedName: baseDict.loadedName,
  43601. composite: composite,
  43602. wideChars: composite,
  43603. fixedPitch: false,
  43604. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  43605. firstChar: firstChar || 0,
  43606. lastChar: (lastChar || maxCharIndex),
  43607. bbox: descriptor.get('FontBBox'),
  43608. ascent: descriptor.get('Ascent'),
  43609. descent: descriptor.get('Descent'),
  43610. xHeight: descriptor.get('XHeight'),
  43611. capHeight: descriptor.get('CapHeight'),
  43612. flags: descriptor.get('Flags'),
  43613. italicAngle: descriptor.get('ItalicAngle'),
  43614. coded: false
  43615. };
  43616. if (composite) {
  43617. var cidEncoding = baseDict.get('Encoding');
  43618. if (isName(cidEncoding)) {
  43619. properties.cidEncoding = cidEncoding.name;
  43620. }
  43621. properties.cMap = CMapFactory.create(cidEncoding,
  43622. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43623. properties.vertical = properties.cMap.vertical;
  43624. }
  43625. this.extractDataStructures(dict, baseDict, xref, properties);
  43626. this.extractWidths(dict, xref, descriptor, properties);
  43627. if (type === 'Type3') {
  43628. properties.isType3Font = true;
  43629. }
  43630. return new Font(fontName.name, fontFile, properties);
  43631. }
  43632. };
  43633. return PartialEvaluator;
  43634. })();
  43635. var TranslatedFont = (function TranslatedFontClosure() {
  43636. function TranslatedFont(loadedName, font, dict) {
  43637. this.loadedName = loadedName;
  43638. this.font = font;
  43639. this.dict = dict;
  43640. this.type3Loaded = null;
  43641. this.sent = false;
  43642. }
  43643. TranslatedFont.prototype = {
  43644. send: function (handler) {
  43645. if (this.sent) {
  43646. return;
  43647. }
  43648. var fontData = this.font.exportData();
  43649. handler.send('commonobj', [
  43650. this.loadedName,
  43651. 'Font',
  43652. fontData
  43653. ]);
  43654. this.sent = true;
  43655. },
  43656. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  43657. assert(this.font.isType3Font);
  43658. if (this.type3Loaded) {
  43659. return this.type3Loaded;
  43660. }
  43661. var translatedFont = this.font;
  43662. var loadCharProcsPromise = Promise.resolve();
  43663. var charProcs = this.dict.get('CharProcs');
  43664. var fontResources = this.dict.get('Resources') || resources;
  43665. var charProcKeys = charProcs.getKeys();
  43666. var charProcOperatorList = Object.create(null);
  43667. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  43668. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  43669. var glyphStream = charProcs.get(key);
  43670. var operatorList = new OperatorList();
  43671. return evaluator.getOperatorList(glyphStream, task, fontResources,
  43672. operatorList).then(function () {
  43673. charProcOperatorList[key] = operatorList.getIR();
  43674. // Add the dependencies to the parent operator list so they are
  43675. // resolved before sub operator list is executed synchronously.
  43676. parentOperatorList.addDependencies(operatorList.dependencies);
  43677. }, function (reason) {
  43678. warn('Type3 font resource \"' + key + '\" is not available');
  43679. var operatorList = new OperatorList();
  43680. charProcOperatorList[key] = operatorList.getIR();
  43681. });
  43682. }.bind(this, charProcKeys[i]));
  43683. }
  43684. this.type3Loaded = loadCharProcsPromise.then(function () {
  43685. translatedFont.charProcOperatorList = charProcOperatorList;
  43686. });
  43687. return this.type3Loaded;
  43688. }
  43689. };
  43690. return TranslatedFont;
  43691. })();
  43692. var OperatorList = (function OperatorListClosure() {
  43693. var CHUNK_SIZE = 1000;
  43694. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  43695. function getTransfers(queue) {
  43696. var transfers = [];
  43697. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43698. for (var i = 0, ii = queue.length; i < ii; i++) {
  43699. switch (fnArray[i]) {
  43700. case OPS.paintInlineImageXObject:
  43701. case OPS.paintInlineImageXObjectGroup:
  43702. case OPS.paintImageMaskXObject:
  43703. var arg = argsArray[i][0]; // first param in imgData
  43704. if (!arg.cached) {
  43705. transfers.push(arg.data.buffer);
  43706. }
  43707. break;
  43708. }
  43709. }
  43710. return transfers;
  43711. }
  43712. function OperatorList(intent, messageHandler, pageIndex) {
  43713. this.messageHandler = messageHandler;
  43714. this.fnArray = [];
  43715. this.argsArray = [];
  43716. this.dependencies = Object.create(null);
  43717. this._totalLength = 0;
  43718. this.pageIndex = pageIndex;
  43719. this.intent = intent;
  43720. }
  43721. OperatorList.prototype = {
  43722. get length() {
  43723. return this.argsArray.length;
  43724. },
  43725. /**
  43726. * @returns {number} The total length of the entire operator list,
  43727. * since `this.length === 0` after flushing.
  43728. */
  43729. get totalLength() {
  43730. return (this._totalLength + this.length);
  43731. },
  43732. addOp: function(fn, args) {
  43733. this.fnArray.push(fn);
  43734. this.argsArray.push(args);
  43735. if (this.messageHandler) {
  43736. if (this.fnArray.length >= CHUNK_SIZE) {
  43737. this.flush();
  43738. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  43739. (fn === OPS.restore || fn === OPS.endText)) {
  43740. // heuristic to flush on boundary of restore or endText
  43741. this.flush();
  43742. }
  43743. }
  43744. },
  43745. addDependency: function(dependency) {
  43746. if (dependency in this.dependencies) {
  43747. return;
  43748. }
  43749. this.dependencies[dependency] = true;
  43750. this.addOp(OPS.dependency, [dependency]);
  43751. },
  43752. addDependencies: function(dependencies) {
  43753. for (var key in dependencies) {
  43754. this.addDependency(key);
  43755. }
  43756. },
  43757. addOpList: function(opList) {
  43758. Util.extendObj(this.dependencies, opList.dependencies);
  43759. for (var i = 0, ii = opList.length; i < ii; i++) {
  43760. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  43761. }
  43762. },
  43763. getIR: function() {
  43764. return {
  43765. fnArray: this.fnArray,
  43766. argsArray: this.argsArray,
  43767. length: this.length
  43768. };
  43769. },
  43770. flush: function(lastChunk) {
  43771. if (this.intent !== 'oplist') {
  43772. new QueueOptimizer().optimize(this);
  43773. }
  43774. var transfers = getTransfers(this);
  43775. var length = this.length;
  43776. this._totalLength += length;
  43777. this.messageHandler.send('RenderPageChunk', {
  43778. operatorList: {
  43779. fnArray: this.fnArray,
  43780. argsArray: this.argsArray,
  43781. lastChunk: lastChunk,
  43782. length: length
  43783. },
  43784. pageIndex: this.pageIndex,
  43785. intent: this.intent
  43786. }, transfers);
  43787. this.dependencies = Object.create(null);
  43788. this.fnArray.length = 0;
  43789. this.argsArray.length = 0;
  43790. }
  43791. };
  43792. return OperatorList;
  43793. })();
  43794. var StateManager = (function StateManagerClosure() {
  43795. function StateManager(initialState) {
  43796. this.state = initialState;
  43797. this.stateStack = [];
  43798. }
  43799. StateManager.prototype = {
  43800. save: function () {
  43801. var old = this.state;
  43802. this.stateStack.push(this.state);
  43803. this.state = old.clone();
  43804. },
  43805. restore: function () {
  43806. var prev = this.stateStack.pop();
  43807. if (prev) {
  43808. this.state = prev;
  43809. }
  43810. },
  43811. transform: function (args) {
  43812. this.state.ctm = Util.transform(this.state.ctm, args);
  43813. }
  43814. };
  43815. return StateManager;
  43816. })();
  43817. var TextState = (function TextStateClosure() {
  43818. function TextState() {
  43819. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43820. this.fontSize = 0;
  43821. this.font = null;
  43822. this.fontMatrix = FONT_IDENTITY_MATRIX;
  43823. this.textMatrix = IDENTITY_MATRIX.slice();
  43824. this.textLineMatrix = IDENTITY_MATRIX.slice();
  43825. this.charSpacing = 0;
  43826. this.wordSpacing = 0;
  43827. this.leading = 0;
  43828. this.textHScale = 1;
  43829. this.textRise = 0;
  43830. }
  43831. TextState.prototype = {
  43832. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43833. var m = this.textMatrix;
  43834. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43835. },
  43836. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43837. var m = this.textLineMatrix;
  43838. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43839. },
  43840. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  43841. var m = this.textMatrix;
  43842. m[4] = m[0] * x + m[2] * y + m[4];
  43843. m[5] = m[1] * x + m[3] * y + m[5];
  43844. },
  43845. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  43846. var m = this.textLineMatrix;
  43847. m[4] = m[0] * x + m[2] * y + m[4];
  43848. m[5] = m[1] * x + m[3] * y + m[5];
  43849. },
  43850. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  43851. // 9.4.4 Text Space Details
  43852. var tsm = [this.fontSize * this.textHScale, 0,
  43853. 0, this.fontSize,
  43854. 0, this.textRise];
  43855. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  43856. },
  43857. carriageReturn: function TextState_carriageReturn() {
  43858. this.translateTextLineMatrix(0, -this.leading);
  43859. this.textMatrix = this.textLineMatrix.slice();
  43860. },
  43861. clone: function TextState_clone() {
  43862. var clone = Object.create(this);
  43863. clone.textMatrix = this.textMatrix.slice();
  43864. clone.textLineMatrix = this.textLineMatrix.slice();
  43865. clone.fontMatrix = this.fontMatrix.slice();
  43866. return clone;
  43867. }
  43868. };
  43869. return TextState;
  43870. })();
  43871. var EvalState = (function EvalStateClosure() {
  43872. function EvalState() {
  43873. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43874. this.font = null;
  43875. this.textRenderingMode = TextRenderingMode.FILL;
  43876. this.fillColorSpace = ColorSpace.singletons.gray;
  43877. this.strokeColorSpace = ColorSpace.singletons.gray;
  43878. }
  43879. EvalState.prototype = {
  43880. clone: function CanvasExtraState_clone() {
  43881. return Object.create(this);
  43882. },
  43883. };
  43884. return EvalState;
  43885. })();
  43886. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  43887. // Specifies properties for each command
  43888. //
  43889. // If variableArgs === true: [0, `numArgs`] expected
  43890. // If variableArgs === false: exactly `numArgs` expected
  43891. var getOPMap = getLookupTableFactory(function (t) {
  43892. // Graphic state
  43893. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  43894. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  43895. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  43896. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  43897. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  43898. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  43899. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  43900. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  43901. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  43902. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  43903. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  43904. // Path
  43905. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  43906. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  43907. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  43908. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  43909. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  43910. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  43911. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  43912. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  43913. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  43914. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  43915. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  43916. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  43917. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  43918. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  43919. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  43920. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  43921. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  43922. // Clipping
  43923. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  43924. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  43925. // Text
  43926. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  43927. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  43928. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  43929. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  43930. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  43931. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  43932. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  43933. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  43934. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  43935. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  43936. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  43937. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  43938. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  43939. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  43940. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  43941. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  43942. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  43943. variableArgs: false };
  43944. // Type3 fonts
  43945. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  43946. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  43947. variableArgs: false };
  43948. // Color
  43949. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  43950. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  43951. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  43952. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  43953. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  43954. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  43955. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  43956. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  43957. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  43958. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  43959. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  43960. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  43961. // Shading
  43962. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  43963. // Images
  43964. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  43965. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  43966. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  43967. // XObjects
  43968. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  43969. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  43970. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  43971. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  43972. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  43973. variableArgs: false };
  43974. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  43975. // Compatibility
  43976. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  43977. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  43978. // (reserved partial commands for the lexer)
  43979. t['BM'] = null;
  43980. t['BD'] = null;
  43981. t['true'] = null;
  43982. t['fa'] = null;
  43983. t['fal'] = null;
  43984. t['fals'] = null;
  43985. t['false'] = null;
  43986. t['nu'] = null;
  43987. t['nul'] = null;
  43988. t['null'] = null;
  43989. });
  43990. function EvaluatorPreprocessor(stream, xref, stateManager) {
  43991. this.opMap = getOPMap();
  43992. // TODO(mduan): pass array of knownCommands rather than this.opMap
  43993. // dictionary
  43994. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  43995. this.stateManager = stateManager;
  43996. this.nonProcessedArgs = [];
  43997. }
  43998. EvaluatorPreprocessor.prototype = {
  43999. get savedStatesDepth() {
  44000. return this.stateManager.stateStack.length;
  44001. },
  44002. // |operation| is an object with two fields:
  44003. //
  44004. // - |fn| is an out param.
  44005. //
  44006. // - |args| is an inout param. On entry, it should have one of two values.
  44007. //
  44008. // - An empty array. This indicates that the caller is providing the
  44009. // array in which the args will be stored in. The caller should use
  44010. // this value if it can reuse a single array for each call to read().
  44011. //
  44012. // - |null|. This indicates that the caller needs this function to create
  44013. // the array in which any args are stored in. If there are zero args,
  44014. // this function will leave |operation.args| as |null| (thus avoiding
  44015. // allocations that would occur if we used an empty array to represent
  44016. // zero arguments). Otherwise, it will replace |null| with a new array
  44017. // containing the arguments. The caller should use this value if it
  44018. // cannot reuse an array for each call to read().
  44019. //
  44020. // These two modes are present because this function is very hot and so
  44021. // avoiding allocations where possible is worthwhile.
  44022. //
  44023. read: function EvaluatorPreprocessor_read(operation) {
  44024. var args = operation.args;
  44025. while (true) {
  44026. var obj = this.parser.getObj();
  44027. if (isCmd(obj)) {
  44028. var cmd = obj.cmd;
  44029. // Check that the command is valid
  44030. var opSpec = this.opMap[cmd];
  44031. if (!opSpec) {
  44032. warn('Unknown command "' + cmd + '"');
  44033. continue;
  44034. }
  44035. var fn = opSpec.id;
  44036. var numArgs = opSpec.numArgs;
  44037. var argsLength = args !== null ? args.length : 0;
  44038. if (!opSpec.variableArgs) {
  44039. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  44040. if (argsLength !== numArgs) {
  44041. var nonProcessedArgs = this.nonProcessedArgs;
  44042. while (argsLength > numArgs) {
  44043. nonProcessedArgs.push(args.shift());
  44044. argsLength--;
  44045. }
  44046. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  44047. if (!args) {
  44048. args = [];
  44049. }
  44050. args.unshift(nonProcessedArgs.pop());
  44051. argsLength++;
  44052. }
  44053. }
  44054. if (argsLength < numArgs) {
  44055. // If we receive too few args, it's not possible to possible
  44056. // to execute the command, so skip the command
  44057. info('Command ' + fn + ': because expected ' +
  44058. numArgs + ' args, but received ' + argsLength +
  44059. ' args; skipping');
  44060. args = null;
  44061. continue;
  44062. }
  44063. } else if (argsLength > numArgs) {
  44064. info('Command ' + fn + ': expected [0,' + numArgs +
  44065. '] args, but received ' + argsLength + ' args');
  44066. }
  44067. // TODO figure out how to type-check vararg functions
  44068. this.preprocessCommand(fn, args);
  44069. operation.fn = fn;
  44070. operation.args = args;
  44071. return true;
  44072. } else {
  44073. if (isEOF(obj)) {
  44074. return false; // no more commands
  44075. }
  44076. // argument
  44077. if (obj !== null) {
  44078. if (!args) {
  44079. args = [];
  44080. }
  44081. args.push(obj);
  44082. assert(args.length <= 33, 'Too many arguments');
  44083. }
  44084. }
  44085. }
  44086. },
  44087. preprocessCommand:
  44088. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  44089. switch (fn | 0) {
  44090. case OPS.save:
  44091. this.stateManager.save();
  44092. break;
  44093. case OPS.restore:
  44094. this.stateManager.restore();
  44095. break;
  44096. case OPS.transform:
  44097. this.stateManager.transform(args);
  44098. break;
  44099. }
  44100. }
  44101. };
  44102. return EvaluatorPreprocessor;
  44103. })();
  44104. var QueueOptimizer = (function QueueOptimizerClosure() {
  44105. function addState(parentState, pattern, fn) {
  44106. var state = parentState;
  44107. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  44108. var item = pattern[i];
  44109. state = (state[item] || (state[item] = []));
  44110. }
  44111. state[pattern[pattern.length - 1]] = fn;
  44112. }
  44113. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44114. argsArray) {
  44115. // Handles special case of mainly LaTeX documents which use image masks to
  44116. // draw lines with the current fill style.
  44117. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  44118. // have been found at iFirstSave.
  44119. var iFirstPIMXO = iFirstSave + 2;
  44120. for (var i = 0; i < count; i++) {
  44121. var arg = argsArray[iFirstPIMXO + 4 * i];
  44122. var imageMask = arg.length === 1 && arg[0];
  44123. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  44124. (!imageMask.data.length ||
  44125. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  44126. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  44127. continue;
  44128. }
  44129. break;
  44130. }
  44131. return count - i;
  44132. }
  44133. var InitialState = [];
  44134. // This replaces (save, transform, paintInlineImageXObject, restore)+
  44135. // sequences with one |paintInlineImageXObjectGroup| operation.
  44136. addState(InitialState,
  44137. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  44138. function foundInlineImageGroup(context) {
  44139. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  44140. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  44141. var MAX_WIDTH = 1000;
  44142. var IMAGE_PADDING = 1;
  44143. var fnArray = context.fnArray, argsArray = context.argsArray;
  44144. var curr = context.iCurr;
  44145. var iFirstSave = curr - 3;
  44146. var iFirstTransform = curr - 2;
  44147. var iFirstPIIXO = curr - 1;
  44148. // Look for the quartets.
  44149. var i = iFirstSave + 4;
  44150. var ii = fnArray.length;
  44151. while (i + 3 < ii) {
  44152. if (fnArray[i] !== OPS.save ||
  44153. fnArray[i + 1] !== OPS.transform ||
  44154. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  44155. fnArray[i + 3] !== OPS.restore) {
  44156. break; // ops don't match
  44157. }
  44158. i += 4;
  44159. }
  44160. // At this point, i is the index of the first op past the last valid
  44161. // quartet.
  44162. var count = Math.min((i - iFirstSave) / 4,
  44163. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  44164. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  44165. return i;
  44166. }
  44167. // assuming that heights of those image is too small (~1 pixel)
  44168. // packing as much as possible by lines
  44169. var maxX = 0;
  44170. var map = [], maxLineHeight = 0;
  44171. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  44172. var q;
  44173. for (q = 0; q < count; q++) {
  44174. var transform = argsArray[iFirstTransform + (q << 2)];
  44175. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  44176. if (currentX + img.width > MAX_WIDTH) {
  44177. // starting new line
  44178. maxX = Math.max(maxX, currentX);
  44179. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  44180. currentX = 0;
  44181. maxLineHeight = 0;
  44182. }
  44183. map.push({
  44184. transform: transform,
  44185. x: currentX, y: currentY,
  44186. w: img.width, h: img.height
  44187. });
  44188. currentX += img.width + 2 * IMAGE_PADDING;
  44189. maxLineHeight = Math.max(maxLineHeight, img.height);
  44190. }
  44191. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  44192. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  44193. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  44194. var imgRowSize = imgWidth << 2;
  44195. for (q = 0; q < count; q++) {
  44196. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  44197. // Copy image by lines and extends pixels into padding.
  44198. var rowSize = map[q].w << 2;
  44199. var dataOffset = 0;
  44200. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  44201. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  44202. for (var k = 0, kk = map[q].h; k < kk; k++) {
  44203. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  44204. dataOffset += rowSize;
  44205. offset += imgRowSize;
  44206. }
  44207. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  44208. while (offset >= 0) {
  44209. data[offset - 4] = data[offset];
  44210. data[offset - 3] = data[offset + 1];
  44211. data[offset - 2] = data[offset + 2];
  44212. data[offset - 1] = data[offset + 3];
  44213. data[offset + rowSize] = data[offset + rowSize - 4];
  44214. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  44215. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  44216. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  44217. offset -= imgRowSize;
  44218. }
  44219. }
  44220. // Replace queue items.
  44221. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  44222. argsArray.splice(iFirstSave, count * 4,
  44223. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  44224. data: imgData }, map]);
  44225. return iFirstSave + 1;
  44226. });
  44227. // This replaces (save, transform, paintImageMaskXObject, restore)+
  44228. // sequences with one |paintImageMaskXObjectGroup| or one
  44229. // |paintImageMaskXObjectRepeat| operation.
  44230. addState(InitialState,
  44231. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  44232. function foundImageMaskGroup(context) {
  44233. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  44234. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  44235. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  44236. var fnArray = context.fnArray, argsArray = context.argsArray;
  44237. var curr = context.iCurr;
  44238. var iFirstSave = curr - 3;
  44239. var iFirstTransform = curr - 2;
  44240. var iFirstPIMXO = curr - 1;
  44241. // Look for the quartets.
  44242. var i = iFirstSave + 4;
  44243. var ii = fnArray.length;
  44244. while (i + 3 < ii) {
  44245. if (fnArray[i] !== OPS.save ||
  44246. fnArray[i + 1] !== OPS.transform ||
  44247. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  44248. fnArray[i + 3] !== OPS.restore) {
  44249. break; // ops don't match
  44250. }
  44251. i += 4;
  44252. }
  44253. // At this point, i is the index of the first op past the last valid
  44254. // quartet.
  44255. var count = (i - iFirstSave) / 4;
  44256. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44257. argsArray);
  44258. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  44259. return i;
  44260. }
  44261. var q;
  44262. var isSameImage = false;
  44263. var iTransform, transformArgs;
  44264. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  44265. if (argsArray[iFirstTransform][1] === 0 &&
  44266. argsArray[iFirstTransform][2] === 0) {
  44267. isSameImage = true;
  44268. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44269. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44270. iTransform = iFirstTransform + 4;
  44271. var iPIMXO = iFirstPIMXO + 4;
  44272. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  44273. transformArgs = argsArray[iTransform];
  44274. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  44275. transformArgs[0] !== firstTransformArg0 ||
  44276. transformArgs[1] !== 0 ||
  44277. transformArgs[2] !== 0 ||
  44278. transformArgs[3] !== firstTransformArg3) {
  44279. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  44280. isSameImage = false;
  44281. } else {
  44282. count = q;
  44283. }
  44284. break; // different image or transform
  44285. }
  44286. }
  44287. }
  44288. if (isSameImage) {
  44289. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  44290. var positions = new Float32Array(count * 2);
  44291. iTransform = iFirstTransform;
  44292. for (q = 0; q < count; q++, iTransform += 4) {
  44293. transformArgs = argsArray[iTransform];
  44294. positions[(q << 1)] = transformArgs[4];
  44295. positions[(q << 1) + 1] = transformArgs[5];
  44296. }
  44297. // Replace queue items.
  44298. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  44299. argsArray.splice(iFirstSave, count * 4,
  44300. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  44301. } else {
  44302. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  44303. var images = [];
  44304. for (q = 0; q < count; q++) {
  44305. transformArgs = argsArray[iFirstTransform + (q << 2)];
  44306. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  44307. images.push({ data: maskParams.data, width: maskParams.width,
  44308. height: maskParams.height,
  44309. transform: transformArgs });
  44310. }
  44311. // Replace queue items.
  44312. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  44313. argsArray.splice(iFirstSave, count * 4, [images]);
  44314. }
  44315. return iFirstSave + 1;
  44316. });
  44317. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  44318. // with one paintImageXObjectRepeat operation, if the |transform| and
  44319. // |paintImageXObjectRepeat| ops are appropriate.
  44320. addState(InitialState,
  44321. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  44322. function (context) {
  44323. var MIN_IMAGES_IN_BLOCK = 3;
  44324. var MAX_IMAGES_IN_BLOCK = 1000;
  44325. var fnArray = context.fnArray, argsArray = context.argsArray;
  44326. var curr = context.iCurr;
  44327. var iFirstSave = curr - 3;
  44328. var iFirstTransform = curr - 2;
  44329. var iFirstPIXO = curr - 1;
  44330. var iFirstRestore = curr;
  44331. if (argsArray[iFirstTransform][1] !== 0 ||
  44332. argsArray[iFirstTransform][2] !== 0) {
  44333. return iFirstRestore + 1; // transform has the wrong form
  44334. }
  44335. // Look for the quartets.
  44336. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  44337. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44338. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44339. var i = iFirstSave + 4;
  44340. var ii = fnArray.length;
  44341. while (i + 3 < ii) {
  44342. if (fnArray[i] !== OPS.save ||
  44343. fnArray[i + 1] !== OPS.transform ||
  44344. fnArray[i + 2] !== OPS.paintImageXObject ||
  44345. fnArray[i + 3] !== OPS.restore) {
  44346. break; // ops don't match
  44347. }
  44348. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  44349. argsArray[i + 1][1] !== 0 ||
  44350. argsArray[i + 1][2] !== 0 ||
  44351. argsArray[i + 1][3] !== firstTransformArg3) {
  44352. break; // transforms don't match
  44353. }
  44354. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  44355. break; // images don't match
  44356. }
  44357. i += 4;
  44358. }
  44359. // At this point, i is the index of the first op past the last valid
  44360. // quartet.
  44361. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  44362. if (count < MIN_IMAGES_IN_BLOCK) {
  44363. return i;
  44364. }
  44365. // Extract the (x,y) positions from all of the matching transforms.
  44366. var positions = new Float32Array(count * 2);
  44367. var iTransform = iFirstTransform;
  44368. for (var q = 0; q < count; q++, iTransform += 4) {
  44369. var transformArgs = argsArray[iTransform];
  44370. positions[(q << 1)] = transformArgs[4];
  44371. positions[(q << 1) + 1] = transformArgs[5];
  44372. }
  44373. // Replace queue items.
  44374. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  44375. positions];
  44376. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  44377. argsArray.splice(iFirstSave, count * 4, args);
  44378. return iFirstSave + 1;
  44379. });
  44380. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  44381. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  44382. // sequences, if the font for each one is the same.
  44383. addState(InitialState,
  44384. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  44385. function (context) {
  44386. var MIN_CHARS_IN_BLOCK = 3;
  44387. var MAX_CHARS_IN_BLOCK = 1000;
  44388. var fnArray = context.fnArray, argsArray = context.argsArray;
  44389. var curr = context.iCurr;
  44390. var iFirstBeginText = curr - 4;
  44391. var iFirstSetFont = curr - 3;
  44392. var iFirstSetTextMatrix = curr - 2;
  44393. var iFirstShowText = curr - 1;
  44394. var iFirstEndText = curr;
  44395. // Look for the quintets.
  44396. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  44397. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  44398. var i = iFirstBeginText + 5;
  44399. var ii = fnArray.length;
  44400. while (i + 4 < ii) {
  44401. if (fnArray[i] !== OPS.beginText ||
  44402. fnArray[i + 1] !== OPS.setFont ||
  44403. fnArray[i + 2] !== OPS.setTextMatrix ||
  44404. fnArray[i + 3] !== OPS.showText ||
  44405. fnArray[i + 4] !== OPS.endText) {
  44406. break; // ops don't match
  44407. }
  44408. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  44409. argsArray[i + 1][1] !== firstSetFontArg1) {
  44410. break; // fonts don't match
  44411. }
  44412. i += 5;
  44413. }
  44414. // At this point, i is the index of the first op past the last valid
  44415. // quintet.
  44416. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  44417. if (count < MIN_CHARS_IN_BLOCK) {
  44418. return i;
  44419. }
  44420. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  44421. // showText, endText), include that as well. (E.g. <something> might be
  44422. // |dependency|.)
  44423. var iFirst = iFirstBeginText;
  44424. if (iFirstBeginText >= 4 &&
  44425. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  44426. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  44427. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  44428. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  44429. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  44430. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  44431. count++;
  44432. iFirst -= 5;
  44433. }
  44434. // Remove (endText, beginText, setFont) trios.
  44435. var iEndText = iFirst + 4;
  44436. for (var q = 1; q < count; q++) {
  44437. fnArray.splice(iEndText, 3);
  44438. argsArray.splice(iEndText, 3);
  44439. iEndText += 2;
  44440. }
  44441. return iEndText + 1;
  44442. });
  44443. function QueueOptimizer() {}
  44444. QueueOptimizer.prototype = {
  44445. optimize: function QueueOptimizer_optimize(queue) {
  44446. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44447. var context = {
  44448. iCurr: 0,
  44449. fnArray: fnArray,
  44450. argsArray: argsArray
  44451. };
  44452. var state;
  44453. var i = 0, ii = fnArray.length;
  44454. while (i < ii) {
  44455. state = (state || InitialState)[fnArray[i]];
  44456. if (typeof state === 'function') { // we found some handler
  44457. context.iCurr = i;
  44458. // state() returns the index of the first non-matching op (if we
  44459. // didn't match) or the first op past the modified ops (if we did
  44460. // match and replace).
  44461. i = state(context);
  44462. state = undefined; // reset the state machine
  44463. ii = context.fnArray.length;
  44464. } else {
  44465. i++;
  44466. }
  44467. }
  44468. }
  44469. };
  44470. return QueueOptimizer;
  44471. })();
  44472. exports.OperatorList = OperatorList;
  44473. exports.PartialEvaluator = PartialEvaluator;
  44474. }));
  44475. (function (root, factory) {
  44476. {
  44477. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  44478. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  44479. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  44480. }
  44481. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  44482. coreColorSpace, coreObj, coreEvaluator) {
  44483. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  44484. var AnnotationFlag = sharedUtil.AnnotationFlag;
  44485. var AnnotationType = sharedUtil.AnnotationType;
  44486. var OPS = sharedUtil.OPS;
  44487. var Util = sharedUtil.Util;
  44488. var isArray = sharedUtil.isArray;
  44489. var isInt = sharedUtil.isInt;
  44490. var isValidUrl = sharedUtil.isValidUrl;
  44491. var stringToBytes = sharedUtil.stringToBytes;
  44492. var stringToPDFString = sharedUtil.stringToPDFString;
  44493. var stringToUTF8String = sharedUtil.stringToUTF8String;
  44494. var warn = sharedUtil.warn;
  44495. var Dict = corePrimitives.Dict;
  44496. var isDict = corePrimitives.isDict;
  44497. var isName = corePrimitives.isName;
  44498. var Stream = coreStream.Stream;
  44499. var ColorSpace = coreColorSpace.ColorSpace;
  44500. var ObjectLoader = coreObj.ObjectLoader;
  44501. var OperatorList = coreEvaluator.OperatorList;
  44502. /**
  44503. * @class
  44504. * @alias AnnotationFactory
  44505. */
  44506. function AnnotationFactory() {}
  44507. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  44508. /**
  44509. * @param {XRef} xref
  44510. * @param {Object} ref
  44511. * @returns {Annotation}
  44512. */
  44513. create: function AnnotationFactory_create(xref, ref) {
  44514. var dict = xref.fetchIfRef(ref);
  44515. if (!isDict(dict)) {
  44516. return;
  44517. }
  44518. // Determine the annotation's subtype.
  44519. var subtype = dict.get('Subtype');
  44520. subtype = isName(subtype) ? subtype.name : '';
  44521. // Return the right annotation object based on the subtype and field type.
  44522. var parameters = {
  44523. dict: dict,
  44524. ref: ref
  44525. };
  44526. switch (subtype) {
  44527. case 'Link':
  44528. return new LinkAnnotation(parameters);
  44529. case 'Text':
  44530. return new TextAnnotation(parameters);
  44531. case 'Widget':
  44532. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44533. if (isName(fieldType) && fieldType.name === 'Tx') {
  44534. return new TextWidgetAnnotation(parameters);
  44535. }
  44536. return new WidgetAnnotation(parameters);
  44537. case 'Popup':
  44538. return new PopupAnnotation(parameters);
  44539. case 'Highlight':
  44540. return new HighlightAnnotation(parameters);
  44541. case 'Underline':
  44542. return new UnderlineAnnotation(parameters);
  44543. case 'Squiggly':
  44544. return new SquigglyAnnotation(parameters);
  44545. case 'StrikeOut':
  44546. return new StrikeOutAnnotation(parameters);
  44547. default:
  44548. warn('Unimplemented annotation type "' + subtype + '", ' +
  44549. 'falling back to base annotation');
  44550. return new Annotation(parameters);
  44551. }
  44552. }
  44553. };
  44554. var Annotation = (function AnnotationClosure() {
  44555. // 12.5.5: Algorithm: Appearance streams
  44556. function getTransformMatrix(rect, bbox, matrix) {
  44557. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  44558. var minX = bounds[0];
  44559. var minY = bounds[1];
  44560. var maxX = bounds[2];
  44561. var maxY = bounds[3];
  44562. if (minX === maxX || minY === maxY) {
  44563. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  44564. // just apply the transform for rect
  44565. return [1, 0, 0, 1, rect[0], rect[1]];
  44566. }
  44567. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  44568. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  44569. return [
  44570. xRatio,
  44571. 0,
  44572. 0,
  44573. yRatio,
  44574. rect[0] - minX * xRatio,
  44575. rect[1] - minY * yRatio
  44576. ];
  44577. }
  44578. function getDefaultAppearance(dict) {
  44579. var appearanceState = dict.get('AP');
  44580. if (!isDict(appearanceState)) {
  44581. return;
  44582. }
  44583. var appearance;
  44584. var appearances = appearanceState.get('N');
  44585. if (isDict(appearances)) {
  44586. var as = dict.get('AS');
  44587. if (as && appearances.has(as.name)) {
  44588. appearance = appearances.get(as.name);
  44589. }
  44590. } else {
  44591. appearance = appearances;
  44592. }
  44593. return appearance;
  44594. }
  44595. function Annotation(params) {
  44596. var dict = params.dict;
  44597. this.setFlags(dict.get('F'));
  44598. this.setRectangle(dict.get('Rect'));
  44599. this.setColor(dict.get('C'));
  44600. this.setBorderStyle(dict);
  44601. this.appearance = getDefaultAppearance(dict);
  44602. // Expose public properties using a data object.
  44603. this.data = {};
  44604. this.data.id = params.ref.toString();
  44605. this.data.subtype = dict.get('Subtype').name;
  44606. this.data.annotationFlags = this.flags;
  44607. this.data.rect = this.rectangle;
  44608. this.data.color = this.color;
  44609. this.data.borderStyle = this.borderStyle;
  44610. this.data.hasAppearance = !!this.appearance;
  44611. }
  44612. Annotation.prototype = {
  44613. /**
  44614. * @return {boolean}
  44615. */
  44616. get viewable() {
  44617. if (this.flags) {
  44618. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44619. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  44620. !this.hasFlag(AnnotationFlag.NOVIEW);
  44621. }
  44622. return true;
  44623. },
  44624. /**
  44625. * @return {boolean}
  44626. */
  44627. get printable() {
  44628. if (this.flags) {
  44629. return this.hasFlag(AnnotationFlag.PRINT) &&
  44630. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44631. !this.hasFlag(AnnotationFlag.HIDDEN);
  44632. }
  44633. return false;
  44634. },
  44635. /**
  44636. * Set the flags.
  44637. *
  44638. * @public
  44639. * @memberof Annotation
  44640. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  44641. * characteristics
  44642. * @see {@link shared/util.js}
  44643. */
  44644. setFlags: function Annotation_setFlags(flags) {
  44645. if (isInt(flags)) {
  44646. this.flags = flags;
  44647. } else {
  44648. this.flags = 0;
  44649. }
  44650. },
  44651. /**
  44652. * Check if a provided flag is set.
  44653. *
  44654. * @public
  44655. * @memberof Annotation
  44656. * @param {number} flag - Hexadecimal representation for an annotation
  44657. * characteristic
  44658. * @return {boolean}
  44659. * @see {@link shared/util.js}
  44660. */
  44661. hasFlag: function Annotation_hasFlag(flag) {
  44662. if (this.flags) {
  44663. return (this.flags & flag) > 0;
  44664. }
  44665. return false;
  44666. },
  44667. /**
  44668. * Set the rectangle.
  44669. *
  44670. * @public
  44671. * @memberof Annotation
  44672. * @param {Array} rectangle - The rectangle array with exactly four entries
  44673. */
  44674. setRectangle: function Annotation_setRectangle(rectangle) {
  44675. if (isArray(rectangle) && rectangle.length === 4) {
  44676. this.rectangle = Util.normalizeRect(rectangle);
  44677. } else {
  44678. this.rectangle = [0, 0, 0, 0];
  44679. }
  44680. },
  44681. /**
  44682. * Set the color and take care of color space conversion.
  44683. *
  44684. * @public
  44685. * @memberof Annotation
  44686. * @param {Array} color - The color array containing either 0
  44687. * (transparent), 1 (grayscale), 3 (RGB) or
  44688. * 4 (CMYK) elements
  44689. */
  44690. setColor: function Annotation_setColor(color) {
  44691. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  44692. if (!isArray(color)) {
  44693. this.color = rgbColor;
  44694. return;
  44695. }
  44696. switch (color.length) {
  44697. case 0: // Transparent, which we indicate with a null value
  44698. this.color = null;
  44699. break;
  44700. case 1: // Convert grayscale to RGB
  44701. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  44702. this.color = rgbColor;
  44703. break;
  44704. case 3: // Convert RGB percentages to RGB
  44705. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  44706. this.color = rgbColor;
  44707. break;
  44708. case 4: // Convert CMYK to RGB
  44709. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  44710. this.color = rgbColor;
  44711. break;
  44712. default:
  44713. this.color = rgbColor;
  44714. break;
  44715. }
  44716. },
  44717. /**
  44718. * Set the border style (as AnnotationBorderStyle object).
  44719. *
  44720. * @public
  44721. * @memberof Annotation
  44722. * @param {Dict} borderStyle - The border style dictionary
  44723. */
  44724. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  44725. this.borderStyle = new AnnotationBorderStyle();
  44726. if (!isDict(borderStyle)) {
  44727. return;
  44728. }
  44729. if (borderStyle.has('BS')) {
  44730. var dict = borderStyle.get('BS');
  44731. var dictType;
  44732. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  44733. dictType.name === 'Border')) {
  44734. this.borderStyle.setWidth(dict.get('W'));
  44735. this.borderStyle.setStyle(dict.get('S'));
  44736. this.borderStyle.setDashArray(dict.get('D'));
  44737. }
  44738. } else if (borderStyle.has('Border')) {
  44739. var array = borderStyle.get('Border');
  44740. if (isArray(array) && array.length >= 3) {
  44741. this.borderStyle.setHorizontalCornerRadius(array[0]);
  44742. this.borderStyle.setVerticalCornerRadius(array[1]);
  44743. this.borderStyle.setWidth(array[2]);
  44744. if (array.length === 4) { // Dash array available
  44745. this.borderStyle.setDashArray(array[3]);
  44746. }
  44747. }
  44748. } else {
  44749. // There are no border entries in the dictionary. According to the
  44750. // specification, we should draw a solid border of width 1 in that
  44751. // case, but Adobe Reader did not implement that part of the
  44752. // specification and instead draws no border at all, so we do the same.
  44753. // See also https://github.com/mozilla/pdf.js/issues/6179.
  44754. this.borderStyle.setWidth(0);
  44755. }
  44756. },
  44757. loadResources: function Annotation_loadResources(keys) {
  44758. return new Promise(function (resolve, reject) {
  44759. this.appearance.dict.getAsync('Resources').then(function (resources) {
  44760. if (!resources) {
  44761. resolve();
  44762. return;
  44763. }
  44764. var objectLoader = new ObjectLoader(resources.map,
  44765. keys,
  44766. resources.xref);
  44767. objectLoader.load().then(function() {
  44768. resolve(resources);
  44769. }, reject);
  44770. }, reject);
  44771. }.bind(this));
  44772. },
  44773. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  44774. if (!this.appearance) {
  44775. return Promise.resolve(new OperatorList());
  44776. }
  44777. var data = this.data;
  44778. var appearanceDict = this.appearance.dict;
  44779. var resourcesPromise = this.loadResources([
  44780. 'ExtGState',
  44781. 'ColorSpace',
  44782. 'Pattern',
  44783. 'Shading',
  44784. 'XObject',
  44785. 'Font'
  44786. // ProcSet
  44787. // Properties
  44788. ]);
  44789. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  44790. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  44791. var transform = getTransformMatrix(data.rect, bbox, matrix);
  44792. var self = this;
  44793. return resourcesPromise.then(function(resources) {
  44794. var opList = new OperatorList();
  44795. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  44796. return evaluator.getOperatorList(self.appearance, task,
  44797. resources, opList).
  44798. then(function () {
  44799. opList.addOp(OPS.endAnnotation, []);
  44800. self.appearance.reset();
  44801. return opList;
  44802. });
  44803. });
  44804. }
  44805. };
  44806. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  44807. annotations, opList, partialEvaluator, task, intent) {
  44808. var annotationPromises = [];
  44809. for (var i = 0, n = annotations.length; i < n; ++i) {
  44810. if ((intent === 'display' && annotations[i].viewable) ||
  44811. (intent === 'print' && annotations[i].printable)) {
  44812. annotationPromises.push(
  44813. annotations[i].getOperatorList(partialEvaluator, task));
  44814. }
  44815. }
  44816. return Promise.all(annotationPromises).then(function(operatorLists) {
  44817. opList.addOp(OPS.beginAnnotations, []);
  44818. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  44819. opList.addOpList(operatorLists[i]);
  44820. }
  44821. opList.addOp(OPS.endAnnotations, []);
  44822. });
  44823. };
  44824. return Annotation;
  44825. })();
  44826. /**
  44827. * Contains all data regarding an annotation's border style.
  44828. *
  44829. * @class
  44830. */
  44831. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  44832. /**
  44833. * @constructor
  44834. * @private
  44835. */
  44836. function AnnotationBorderStyle() {
  44837. this.width = 1;
  44838. this.style = AnnotationBorderStyleType.SOLID;
  44839. this.dashArray = [3];
  44840. this.horizontalCornerRadius = 0;
  44841. this.verticalCornerRadius = 0;
  44842. }
  44843. AnnotationBorderStyle.prototype = {
  44844. /**
  44845. * Set the width.
  44846. *
  44847. * @public
  44848. * @memberof AnnotationBorderStyle
  44849. * @param {integer} width - The width
  44850. */
  44851. setWidth: function AnnotationBorderStyle_setWidth(width) {
  44852. if (width === (width | 0)) {
  44853. this.width = width;
  44854. }
  44855. },
  44856. /**
  44857. * Set the style.
  44858. *
  44859. * @public
  44860. * @memberof AnnotationBorderStyle
  44861. * @param {Object} style - The style object
  44862. * @see {@link shared/util.js}
  44863. */
  44864. setStyle: function AnnotationBorderStyle_setStyle(style) {
  44865. if (!style) {
  44866. return;
  44867. }
  44868. switch (style.name) {
  44869. case 'S':
  44870. this.style = AnnotationBorderStyleType.SOLID;
  44871. break;
  44872. case 'D':
  44873. this.style = AnnotationBorderStyleType.DASHED;
  44874. break;
  44875. case 'B':
  44876. this.style = AnnotationBorderStyleType.BEVELED;
  44877. break;
  44878. case 'I':
  44879. this.style = AnnotationBorderStyleType.INSET;
  44880. break;
  44881. case 'U':
  44882. this.style = AnnotationBorderStyleType.UNDERLINE;
  44883. break;
  44884. default:
  44885. break;
  44886. }
  44887. },
  44888. /**
  44889. * Set the dash array.
  44890. *
  44891. * @public
  44892. * @memberof AnnotationBorderStyle
  44893. * @param {Array} dashArray - The dash array with at least one element
  44894. */
  44895. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  44896. // We validate the dash array, but we do not use it because CSS does not
  44897. // allow us to change spacing of dashes. For more information, visit
  44898. // http://www.w3.org/TR/css3-background/#the-border-style.
  44899. if (isArray(dashArray) && dashArray.length > 0) {
  44900. // According to the PDF specification: the elements in a dashArray
  44901. // shall be numbers that are nonnegative and not all equal to zero.
  44902. var isValid = true;
  44903. var allZeros = true;
  44904. for (var i = 0, len = dashArray.length; i < len; i++) {
  44905. var element = dashArray[i];
  44906. var validNumber = (+element >= 0);
  44907. if (!validNumber) {
  44908. isValid = false;
  44909. break;
  44910. } else if (element > 0) {
  44911. allZeros = false;
  44912. }
  44913. }
  44914. if (isValid && !allZeros) {
  44915. this.dashArray = dashArray;
  44916. } else {
  44917. this.width = 0; // Adobe behavior when the array is invalid.
  44918. }
  44919. } else if (dashArray) {
  44920. this.width = 0; // Adobe behavior when the array is invalid.
  44921. }
  44922. },
  44923. /**
  44924. * Set the horizontal corner radius (from a Border dictionary).
  44925. *
  44926. * @public
  44927. * @memberof AnnotationBorderStyle
  44928. * @param {integer} radius - The horizontal corner radius
  44929. */
  44930. setHorizontalCornerRadius:
  44931. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  44932. if (radius === (radius | 0)) {
  44933. this.horizontalCornerRadius = radius;
  44934. }
  44935. },
  44936. /**
  44937. * Set the vertical corner radius (from a Border dictionary).
  44938. *
  44939. * @public
  44940. * @memberof AnnotationBorderStyle
  44941. * @param {integer} radius - The vertical corner radius
  44942. */
  44943. setVerticalCornerRadius:
  44944. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  44945. if (radius === (radius | 0)) {
  44946. this.verticalCornerRadius = radius;
  44947. }
  44948. }
  44949. };
  44950. return AnnotationBorderStyle;
  44951. })();
  44952. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  44953. function WidgetAnnotation(params) {
  44954. Annotation.call(this, params);
  44955. var dict = params.dict;
  44956. var data = this.data;
  44957. data.annotationType = AnnotationType.WIDGET;
  44958. data.fieldValue = stringToPDFString(
  44959. Util.getInheritableProperty(dict, 'V') || '');
  44960. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  44961. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  44962. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44963. data.fieldType = isName(fieldType) ? fieldType.name : '';
  44964. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  44965. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  44966. // Hide unsupported Widget signatures.
  44967. if (data.fieldType === 'Sig') {
  44968. warn('unimplemented annotation type: Widget signature');
  44969. this.setFlags(AnnotationFlag.HIDDEN);
  44970. }
  44971. // Building the full field name by collecting the field and
  44972. // its ancestors 'T' data and joining them using '.'.
  44973. var fieldName = [];
  44974. var namedItem = dict;
  44975. var ref = params.ref;
  44976. while (namedItem) {
  44977. var parent = namedItem.get('Parent');
  44978. var parentRef = namedItem.getRaw('Parent');
  44979. var name = namedItem.get('T');
  44980. if (name) {
  44981. fieldName.unshift(stringToPDFString(name));
  44982. } else if (parent && ref) {
  44983. // The field name is absent, that means more than one field
  44984. // with the same name may exist. Replacing the empty name
  44985. // with the '`' plus index in the parent's 'Kids' array.
  44986. // This is not in the PDF spec but necessary to id the
  44987. // the input controls.
  44988. var kids = parent.get('Kids');
  44989. var j, jj;
  44990. for (j = 0, jj = kids.length; j < jj; j++) {
  44991. var kidRef = kids[j];
  44992. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  44993. break;
  44994. }
  44995. }
  44996. fieldName.unshift('`' + j);
  44997. }
  44998. namedItem = parent;
  44999. ref = parentRef;
  45000. }
  45001. data.fullName = fieldName.join('.');
  45002. }
  45003. Util.inherit(WidgetAnnotation, Annotation, {});
  45004. return WidgetAnnotation;
  45005. })();
  45006. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  45007. function TextWidgetAnnotation(params) {
  45008. WidgetAnnotation.call(this, params);
  45009. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  45010. }
  45011. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  45012. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  45013. task) {
  45014. if (this.appearance) {
  45015. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  45016. }
  45017. var opList = new OperatorList();
  45018. var data = this.data;
  45019. // Even if there is an appearance stream, ignore it. This is the
  45020. // behaviour used by Adobe Reader.
  45021. if (!data.defaultAppearance) {
  45022. return Promise.resolve(opList);
  45023. }
  45024. var stream = new Stream(stringToBytes(data.defaultAppearance));
  45025. return evaluator.getOperatorList(stream, task,
  45026. this.fieldResources, opList).
  45027. then(function () {
  45028. return opList;
  45029. });
  45030. }
  45031. });
  45032. return TextWidgetAnnotation;
  45033. })();
  45034. var TextAnnotation = (function TextAnnotationClosure() {
  45035. var DEFAULT_ICON_SIZE = 22; // px
  45036. function TextAnnotation(parameters) {
  45037. Annotation.call(this, parameters);
  45038. this.data.annotationType = AnnotationType.TEXT;
  45039. var dict = parameters.dict;
  45040. if (this.data.hasAppearance) {
  45041. this.data.name = 'NoIcon';
  45042. } else {
  45043. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  45044. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  45045. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  45046. }
  45047. if (!dict.has('C')) {
  45048. // Fall back to the default background color.
  45049. this.data.color = null;
  45050. }
  45051. this.data.hasPopup = dict.has('Popup');
  45052. if (!this.data.hasPopup) {
  45053. // There is no associated Popup annotation, so the Text annotation
  45054. // must create its own popup.
  45055. this.data.title = stringToPDFString(dict.get('T') || '');
  45056. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  45057. }
  45058. }
  45059. Util.inherit(TextAnnotation, Annotation, {});
  45060. return TextAnnotation;
  45061. })();
  45062. var LinkAnnotation = (function LinkAnnotationClosure() {
  45063. function LinkAnnotation(params) {
  45064. Annotation.call(this, params);
  45065. var dict = params.dict;
  45066. var data = this.data;
  45067. data.annotationType = AnnotationType.LINK;
  45068. var action = dict.get('A');
  45069. if (action && isDict(action)) {
  45070. var linkType = action.get('S').name;
  45071. if (linkType === 'URI') {
  45072. var url = action.get('URI');
  45073. if (isName(url)) {
  45074. // Some bad PDFs do not put parentheses around relative URLs.
  45075. url = '/' + url.name;
  45076. } else if (url) {
  45077. url = addDefaultProtocolToUrl(url);
  45078. }
  45079. // TODO: pdf spec mentions urls can be relative to a Base
  45080. // entry in the dictionary.
  45081. if (!isValidUrl(url, false)) {
  45082. url = '';
  45083. }
  45084. // According to ISO 32000-1:2008, section 12.6.4.7,
  45085. // URI should to be encoded in 7-bit ASCII.
  45086. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  45087. try {
  45088. data.url = stringToUTF8String(url);
  45089. } catch (e) {
  45090. // Fall back to a simple copy.
  45091. data.url = url;
  45092. }
  45093. } else if (linkType === 'GoTo') {
  45094. data.dest = action.get('D');
  45095. } else if (linkType === 'GoToR') {
  45096. var urlDict = action.get('F');
  45097. if (isDict(urlDict)) {
  45098. // We assume that the 'url' is a Filspec dictionary
  45099. // and fetch the url without checking any further
  45100. url = urlDict.get('F') || '';
  45101. }
  45102. // TODO: pdf reference says that GoToR
  45103. // can also have 'NewWindow' attribute
  45104. if (!isValidUrl(url, false)) {
  45105. url = '';
  45106. }
  45107. data.url = url;
  45108. data.dest = action.get('D');
  45109. } else if (linkType === 'Named') {
  45110. data.action = action.get('N').name;
  45111. } else {
  45112. warn('unrecognized link type: ' + linkType);
  45113. }
  45114. } else if (dict.has('Dest')) {
  45115. // simple destination link
  45116. var dest = dict.get('Dest');
  45117. data.dest = isName(dest) ? dest.name : dest;
  45118. }
  45119. }
  45120. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  45121. function addDefaultProtocolToUrl(url) {
  45122. if (url && url.indexOf('www.') === 0) {
  45123. return ('http://' + url);
  45124. }
  45125. return url;
  45126. }
  45127. Util.inherit(LinkAnnotation, Annotation, {});
  45128. return LinkAnnotation;
  45129. })();
  45130. var PopupAnnotation = (function PopupAnnotationClosure() {
  45131. function PopupAnnotation(parameters) {
  45132. Annotation.call(this, parameters);
  45133. this.data.annotationType = AnnotationType.POPUP;
  45134. var dict = parameters.dict;
  45135. var parentItem = dict.get('Parent');
  45136. if (!parentItem) {
  45137. warn('Popup annotation has a missing or invalid parent annotation.');
  45138. return;
  45139. }
  45140. this.data.parentId = dict.getRaw('Parent').toString();
  45141. this.data.title = stringToPDFString(parentItem.get('T') || '');
  45142. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  45143. if (!parentItem.has('C')) {
  45144. // Fall back to the default background color.
  45145. this.data.color = null;
  45146. } else {
  45147. this.setColor(parentItem.get('C'));
  45148. this.data.color = this.color;
  45149. }
  45150. }
  45151. Util.inherit(PopupAnnotation, Annotation, {});
  45152. return PopupAnnotation;
  45153. })();
  45154. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  45155. function HighlightAnnotation(parameters) {
  45156. Annotation.call(this, parameters);
  45157. this.data.annotationType = AnnotationType.HIGHLIGHT;
  45158. this.data.hasPopup = parameters.dict.has('Popup');
  45159. // PDF viewers completely ignore any border styles.
  45160. this.data.borderStyle.setWidth(0);
  45161. }
  45162. Util.inherit(HighlightAnnotation, Annotation, {});
  45163. return HighlightAnnotation;
  45164. })();
  45165. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  45166. function UnderlineAnnotation(parameters) {
  45167. Annotation.call(this, parameters);
  45168. this.data.annotationType = AnnotationType.UNDERLINE;
  45169. this.data.hasPopup = parameters.dict.has('Popup');
  45170. // PDF viewers completely ignore any border styles.
  45171. this.data.borderStyle.setWidth(0);
  45172. }
  45173. Util.inherit(UnderlineAnnotation, Annotation, {});
  45174. return UnderlineAnnotation;
  45175. })();
  45176. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  45177. function SquigglyAnnotation(parameters) {
  45178. Annotation.call(this, parameters);
  45179. this.data.annotationType = AnnotationType.SQUIGGLY;
  45180. this.data.hasPopup = parameters.dict.has('Popup');
  45181. // PDF viewers completely ignore any border styles.
  45182. this.data.borderStyle.setWidth(0);
  45183. }
  45184. Util.inherit(SquigglyAnnotation, Annotation, {});
  45185. return SquigglyAnnotation;
  45186. })();
  45187. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  45188. function StrikeOutAnnotation(parameters) {
  45189. Annotation.call(this, parameters);
  45190. this.data.annotationType = AnnotationType.STRIKEOUT;
  45191. this.data.hasPopup = parameters.dict.has('Popup');
  45192. // PDF viewers completely ignore any border styles.
  45193. this.data.borderStyle.setWidth(0);
  45194. }
  45195. Util.inherit(StrikeOutAnnotation, Annotation, {});
  45196. return StrikeOutAnnotation;
  45197. })();
  45198. exports.Annotation = Annotation;
  45199. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  45200. exports.AnnotationFactory = AnnotationFactory;
  45201. }));
  45202. (function (root, factory) {
  45203. {
  45204. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  45205. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  45206. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  45207. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  45208. }
  45209. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  45210. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  45211. var MissingDataException = sharedUtil.MissingDataException;
  45212. var Util = sharedUtil.Util;
  45213. var assert = sharedUtil.assert;
  45214. var error = sharedUtil.error;
  45215. var info = sharedUtil.info;
  45216. var isArray = sharedUtil.isArray;
  45217. var isArrayBuffer = sharedUtil.isArrayBuffer;
  45218. var isString = sharedUtil.isString;
  45219. var shadow = sharedUtil.shadow;
  45220. var stringToBytes = sharedUtil.stringToBytes;
  45221. var stringToPDFString = sharedUtil.stringToPDFString;
  45222. var warn = sharedUtil.warn;
  45223. var Dict = corePrimitives.Dict;
  45224. var isDict = corePrimitives.isDict;
  45225. var isName = corePrimitives.isName;
  45226. var isStream = corePrimitives.isStream;
  45227. var NullStream = coreStream.NullStream;
  45228. var Stream = coreStream.Stream;
  45229. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  45230. var Catalog = coreObj.Catalog;
  45231. var ObjectLoader = coreObj.ObjectLoader;
  45232. var XRef = coreObj.XRef;
  45233. var Lexer = coreParser.Lexer;
  45234. var Linearization = coreParser.Linearization;
  45235. var calculateMD5 = coreCrypto.calculateMD5;
  45236. var OperatorList = coreEvaluator.OperatorList;
  45237. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  45238. var Annotation = coreAnnotation.Annotation;
  45239. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  45240. var Page = (function PageClosure() {
  45241. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  45242. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  45243. this.pdfManager = pdfManager;
  45244. this.pageIndex = pageIndex;
  45245. this.pageDict = pageDict;
  45246. this.xref = xref;
  45247. this.ref = ref;
  45248. this.fontCache = fontCache;
  45249. this.idCounters = {
  45250. obj: 0
  45251. };
  45252. this.resourcesPromise = null;
  45253. }
  45254. Page.prototype = {
  45255. getPageProp: function Page_getPageProp(key) {
  45256. return this.pageDict.get(key);
  45257. },
  45258. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  45259. var dict = this.pageDict, valueArray = null, loopCount = 0;
  45260. var MAX_LOOP_COUNT = 100;
  45261. // Always walk up the entire parent chain, to be able to find
  45262. // e.g. \Resources placed on multiple levels of the tree.
  45263. while (dict) {
  45264. var value = dict.get(key);
  45265. if (value) {
  45266. if (!valueArray) {
  45267. valueArray = [];
  45268. }
  45269. valueArray.push(value);
  45270. }
  45271. if (++loopCount > MAX_LOOP_COUNT) {
  45272. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  45273. break;
  45274. }
  45275. dict = dict.get('Parent');
  45276. }
  45277. if (!valueArray) {
  45278. return Dict.empty;
  45279. }
  45280. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  45281. loopCount > MAX_LOOP_COUNT) {
  45282. return valueArray[0];
  45283. }
  45284. return Dict.merge(this.xref, valueArray);
  45285. },
  45286. get content() {
  45287. return this.getPageProp('Contents');
  45288. },
  45289. get resources() {
  45290. // For robustness: The spec states that a \Resources entry has to be
  45291. // present, but can be empty. Some document omit it still, in this case
  45292. // we return an empty dictionary.
  45293. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  45294. },
  45295. get mediaBox() {
  45296. var obj = this.getInheritedPageProp('MediaBox');
  45297. // Reset invalid media box to letter size.
  45298. if (!isArray(obj) || obj.length !== 4) {
  45299. obj = LETTER_SIZE_MEDIABOX;
  45300. }
  45301. return shadow(this, 'mediaBox', obj);
  45302. },
  45303. get view() {
  45304. var mediaBox = this.mediaBox;
  45305. var cropBox = this.getInheritedPageProp('CropBox');
  45306. if (!isArray(cropBox) || cropBox.length !== 4) {
  45307. return shadow(this, 'view', mediaBox);
  45308. }
  45309. // From the spec, 6th ed., p.963:
  45310. // "The crop, bleed, trim, and art boxes should not ordinarily
  45311. // extend beyond the boundaries of the media box. If they do, they are
  45312. // effectively reduced to their intersection with the media box."
  45313. cropBox = Util.intersect(cropBox, mediaBox);
  45314. if (!cropBox) {
  45315. return shadow(this, 'view', mediaBox);
  45316. }
  45317. return shadow(this, 'view', cropBox);
  45318. },
  45319. get rotate() {
  45320. var rotate = this.getInheritedPageProp('Rotate') || 0;
  45321. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  45322. if (rotate % 90 !== 0) {
  45323. rotate = 0;
  45324. } else if (rotate >= 360) {
  45325. rotate = rotate % 360;
  45326. } else if (rotate < 0) {
  45327. // The spec doesn't cover negatives, assume its counterclockwise
  45328. // rotation. The following is the other implementation of modulo.
  45329. rotate = ((rotate % 360) + 360) % 360;
  45330. }
  45331. return shadow(this, 'rotate', rotate);
  45332. },
  45333. getContentStream: function Page_getContentStream() {
  45334. var content = this.content;
  45335. var stream;
  45336. if (isArray(content)) {
  45337. // fetching items
  45338. var xref = this.xref;
  45339. var i, n = content.length;
  45340. var streams = [];
  45341. for (i = 0; i < n; ++i) {
  45342. streams.push(xref.fetchIfRef(content[i]));
  45343. }
  45344. stream = new StreamsSequenceStream(streams);
  45345. } else if (isStream(content)) {
  45346. stream = content;
  45347. } else {
  45348. // replacing non-existent page content with empty one
  45349. stream = new NullStream();
  45350. }
  45351. return stream;
  45352. },
  45353. loadResources: function Page_loadResources(keys) {
  45354. if (!this.resourcesPromise) {
  45355. // TODO: add async getInheritedPageProp and remove this.
  45356. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  45357. }
  45358. return this.resourcesPromise.then(function resourceSuccess() {
  45359. var objectLoader = new ObjectLoader(this.resources.map,
  45360. keys,
  45361. this.xref);
  45362. return objectLoader.load();
  45363. }.bind(this));
  45364. },
  45365. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  45366. var self = this;
  45367. var pdfManager = this.pdfManager;
  45368. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45369. []);
  45370. var resourcesPromise = this.loadResources([
  45371. 'ExtGState',
  45372. 'ColorSpace',
  45373. 'Pattern',
  45374. 'Shading',
  45375. 'XObject',
  45376. 'Font'
  45377. // ProcSet
  45378. // Properties
  45379. ]);
  45380. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  45381. handler, this.pageIndex,
  45382. 'p' + this.pageIndex + '_',
  45383. this.idCounters,
  45384. this.fontCache);
  45385. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  45386. var pageListPromise = dataPromises.then(function(data) {
  45387. var contentStream = data[0];
  45388. var opList = new OperatorList(intent, handler, self.pageIndex);
  45389. handler.send('StartRenderPage', {
  45390. transparency: partialEvaluator.hasBlendModes(self.resources),
  45391. pageIndex: self.pageIndex,
  45392. intent: intent
  45393. });
  45394. return partialEvaluator.getOperatorList(contentStream, task,
  45395. self.resources, opList).then(function () {
  45396. return opList;
  45397. });
  45398. });
  45399. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  45400. return Promise.all([pageListPromise, annotationsPromise]).then(
  45401. function(datas) {
  45402. var pageOpList = datas[0];
  45403. var annotations = datas[1];
  45404. if (annotations.length === 0) {
  45405. pageOpList.flush(true);
  45406. return pageOpList;
  45407. }
  45408. var annotationsReadyPromise = Annotation.appendToOperatorList(
  45409. annotations, pageOpList, partialEvaluator, task, intent);
  45410. return annotationsReadyPromise.then(function () {
  45411. pageOpList.flush(true);
  45412. return pageOpList;
  45413. });
  45414. });
  45415. },
  45416. extractTextContent: function Page_extractTextContent(task,
  45417. normalizeWhitespace) {
  45418. var handler = {
  45419. on: function nullHandlerOn() {},
  45420. send: function nullHandlerSend() {}
  45421. };
  45422. var self = this;
  45423. var pdfManager = this.pdfManager;
  45424. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45425. []);
  45426. var resourcesPromise = this.loadResources([
  45427. 'ExtGState',
  45428. 'XObject',
  45429. 'Font'
  45430. ]);
  45431. var dataPromises = Promise.all([contentStreamPromise,
  45432. resourcesPromise]);
  45433. return dataPromises.then(function(data) {
  45434. var contentStream = data[0];
  45435. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  45436. handler, self.pageIndex,
  45437. 'p' + self.pageIndex + '_',
  45438. self.idCounters,
  45439. self.fontCache);
  45440. return partialEvaluator.getTextContent(contentStream,
  45441. task,
  45442. self.resources,
  45443. /* stateManager = */ null,
  45444. normalizeWhitespace);
  45445. });
  45446. },
  45447. getAnnotationsData: function Page_getAnnotationsData(intent) {
  45448. var annotations = this.annotations;
  45449. var annotationsData = [];
  45450. for (var i = 0, n = annotations.length; i < n; ++i) {
  45451. if (intent) {
  45452. if (!(intent === 'display' && annotations[i].viewable) &&
  45453. !(intent === 'print' && annotations[i].printable)) {
  45454. continue;
  45455. }
  45456. }
  45457. annotationsData.push(annotations[i].data);
  45458. }
  45459. return annotationsData;
  45460. },
  45461. get annotations() {
  45462. var annotations = [];
  45463. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  45464. var annotationFactory = new AnnotationFactory();
  45465. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  45466. var annotationRef = annotationRefs[i];
  45467. var annotation = annotationFactory.create(this.xref, annotationRef);
  45468. if (annotation) {
  45469. annotations.push(annotation);
  45470. }
  45471. }
  45472. return shadow(this, 'annotations', annotations);
  45473. }
  45474. };
  45475. return Page;
  45476. })();
  45477. /**
  45478. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  45479. * `PDFDoc`, this one doesn't have any job management code.
  45480. * Right now there exists one PDFDocument on the main thread + one object
  45481. * for each worker. If there is no worker support enabled, there are two
  45482. * `PDFDocument` objects on the main thread created.
  45483. */
  45484. var PDFDocument = (function PDFDocumentClosure() {
  45485. var FINGERPRINT_FIRST_BYTES = 1024;
  45486. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  45487. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  45488. function PDFDocument(pdfManager, arg, password) {
  45489. if (isStream(arg)) {
  45490. init.call(this, pdfManager, arg, password);
  45491. } else if (isArrayBuffer(arg)) {
  45492. init.call(this, pdfManager, new Stream(arg), password);
  45493. } else {
  45494. error('PDFDocument: Unknown argument type');
  45495. }
  45496. }
  45497. function init(pdfManager, stream, password) {
  45498. assert(stream.length > 0, 'stream must have data');
  45499. this.pdfManager = pdfManager;
  45500. this.stream = stream;
  45501. var xref = new XRef(this.stream, password, pdfManager);
  45502. this.xref = xref;
  45503. }
  45504. function find(stream, needle, limit, backwards) {
  45505. var pos = stream.pos;
  45506. var end = stream.end;
  45507. var strBuf = [];
  45508. if (pos + limit > end) {
  45509. limit = end - pos;
  45510. }
  45511. for (var n = 0; n < limit; ++n) {
  45512. strBuf.push(String.fromCharCode(stream.getByte()));
  45513. }
  45514. var str = strBuf.join('');
  45515. stream.pos = pos;
  45516. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  45517. if (index === -1) {
  45518. return false; /* not found */
  45519. }
  45520. stream.pos += index;
  45521. return true; /* found */
  45522. }
  45523. var DocumentInfoValidators = {
  45524. get entries() {
  45525. // Lazily build this since all the validation functions below are not
  45526. // defined until after this file loads.
  45527. return shadow(this, 'entries', {
  45528. Title: isString,
  45529. Author: isString,
  45530. Subject: isString,
  45531. Keywords: isString,
  45532. Creator: isString,
  45533. Producer: isString,
  45534. CreationDate: isString,
  45535. ModDate: isString,
  45536. Trapped: isName
  45537. });
  45538. }
  45539. };
  45540. PDFDocument.prototype = {
  45541. parse: function PDFDocument_parse(recoveryMode) {
  45542. this.setup(recoveryMode);
  45543. var version = this.catalog.catDict.get('Version');
  45544. if (isName(version)) {
  45545. this.pdfFormatVersion = version.name;
  45546. }
  45547. try {
  45548. // checking if AcroForm is present
  45549. this.acroForm = this.catalog.catDict.get('AcroForm');
  45550. if (this.acroForm) {
  45551. this.xfa = this.acroForm.get('XFA');
  45552. var fields = this.acroForm.get('Fields');
  45553. if ((!fields || !isArray(fields) || fields.length === 0) &&
  45554. !this.xfa) {
  45555. // no fields and no XFA -- not a form (?)
  45556. this.acroForm = null;
  45557. }
  45558. }
  45559. } catch (ex) {
  45560. info('Something wrong with AcroForm entry');
  45561. this.acroForm = null;
  45562. }
  45563. },
  45564. get linearization() {
  45565. var linearization = null;
  45566. if (this.stream.length) {
  45567. try {
  45568. linearization = Linearization.create(this.stream);
  45569. } catch (err) {
  45570. if (err instanceof MissingDataException) {
  45571. throw err;
  45572. }
  45573. info(err);
  45574. }
  45575. }
  45576. // shadow the prototype getter with a data property
  45577. return shadow(this, 'linearization', linearization);
  45578. },
  45579. get startXRef() {
  45580. var stream = this.stream;
  45581. var startXRef = 0;
  45582. var linearization = this.linearization;
  45583. if (linearization) {
  45584. // Find end of first obj.
  45585. stream.reset();
  45586. if (find(stream, 'endobj', 1024)) {
  45587. startXRef = stream.pos + 6;
  45588. }
  45589. } else {
  45590. // Find startxref by jumping backward from the end of the file.
  45591. var step = 1024;
  45592. var found = false, pos = stream.end;
  45593. while (!found && pos > 0) {
  45594. pos -= step - 'startxref'.length;
  45595. if (pos < 0) {
  45596. pos = 0;
  45597. }
  45598. stream.pos = pos;
  45599. found = find(stream, 'startxref', step, true);
  45600. }
  45601. if (found) {
  45602. stream.skip(9);
  45603. var ch;
  45604. do {
  45605. ch = stream.getByte();
  45606. } while (Lexer.isSpace(ch));
  45607. var str = '';
  45608. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  45609. str += String.fromCharCode(ch);
  45610. ch = stream.getByte();
  45611. }
  45612. startXRef = parseInt(str, 10);
  45613. if (isNaN(startXRef)) {
  45614. startXRef = 0;
  45615. }
  45616. }
  45617. }
  45618. // shadow the prototype getter with a data property
  45619. return shadow(this, 'startXRef', startXRef);
  45620. },
  45621. get mainXRefEntriesOffset() {
  45622. var mainXRefEntriesOffset = 0;
  45623. var linearization = this.linearization;
  45624. if (linearization) {
  45625. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  45626. }
  45627. // shadow the prototype getter with a data property
  45628. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  45629. },
  45630. // Find the header, remove leading garbage and setup the stream
  45631. // starting from the header.
  45632. checkHeader: function PDFDocument_checkHeader() {
  45633. var stream = this.stream;
  45634. stream.reset();
  45635. if (find(stream, '%PDF-', 1024)) {
  45636. // Found the header, trim off any garbage before it.
  45637. stream.moveStart();
  45638. // Reading file format version
  45639. var MAX_VERSION_LENGTH = 12;
  45640. var version = '', ch;
  45641. while ((ch = stream.getByte()) > 0x20) { // SPACE
  45642. if (version.length >= MAX_VERSION_LENGTH) {
  45643. break;
  45644. }
  45645. version += String.fromCharCode(ch);
  45646. }
  45647. if (!this.pdfFormatVersion) {
  45648. // removing "%PDF-"-prefix
  45649. this.pdfFormatVersion = version.substring(5);
  45650. }
  45651. return;
  45652. }
  45653. // May not be a PDF file, continue anyway.
  45654. },
  45655. parseStartXRef: function PDFDocument_parseStartXRef() {
  45656. var startXRef = this.startXRef;
  45657. this.xref.setStartXRef(startXRef);
  45658. },
  45659. setup: function PDFDocument_setup(recoveryMode) {
  45660. this.xref.parse(recoveryMode);
  45661. var self = this;
  45662. var pageFactory = {
  45663. createPage: function (pageIndex, dict, ref, fontCache) {
  45664. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  45665. fontCache);
  45666. }
  45667. };
  45668. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  45669. },
  45670. get numPages() {
  45671. var linearization = this.linearization;
  45672. var num = linearization ? linearization.numPages : this.catalog.numPages;
  45673. // shadow the prototype getter
  45674. return shadow(this, 'numPages', num);
  45675. },
  45676. get documentInfo() {
  45677. var docInfo = {
  45678. PDFFormatVersion: this.pdfFormatVersion,
  45679. IsAcroFormPresent: !!this.acroForm,
  45680. IsXFAPresent: !!this.xfa
  45681. };
  45682. var infoDict;
  45683. try {
  45684. infoDict = this.xref.trailer.get('Info');
  45685. } catch (err) {
  45686. info('The document information dictionary is invalid.');
  45687. }
  45688. if (infoDict) {
  45689. var validEntries = DocumentInfoValidators.entries;
  45690. // Only fill the document info with valid entries from the spec.
  45691. for (var key in validEntries) {
  45692. if (infoDict.has(key)) {
  45693. var value = infoDict.get(key);
  45694. // Make sure the value conforms to the spec.
  45695. if (validEntries[key](value)) {
  45696. docInfo[key] = (typeof value !== 'string' ?
  45697. value : stringToPDFString(value));
  45698. } else {
  45699. info('Bad value in document info for "' + key + '"');
  45700. }
  45701. }
  45702. }
  45703. }
  45704. return shadow(this, 'documentInfo', docInfo);
  45705. },
  45706. get fingerprint() {
  45707. var xref = this.xref, hash, fileID = '';
  45708. var idArray = xref.trailer.get('ID');
  45709. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  45710. idArray[0] !== EMPTY_FINGERPRINT) {
  45711. hash = stringToBytes(idArray[0]);
  45712. } else {
  45713. if (this.stream.ensureRange) {
  45714. this.stream.ensureRange(0,
  45715. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  45716. }
  45717. hash = calculateMD5(this.stream.bytes.subarray(0,
  45718. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  45719. }
  45720. for (var i = 0, n = hash.length; i < n; i++) {
  45721. var hex = hash[i].toString(16);
  45722. fileID += hex.length === 1 ? '0' + hex : hex;
  45723. }
  45724. return shadow(this, 'fingerprint', fileID);
  45725. },
  45726. getPage: function PDFDocument_getPage(pageIndex) {
  45727. return this.catalog.getPage(pageIndex);
  45728. },
  45729. cleanup: function PDFDocument_cleanup() {
  45730. return this.catalog.cleanup();
  45731. }
  45732. };
  45733. return PDFDocument;
  45734. })();
  45735. exports.Page = Page;
  45736. exports.PDFDocument = PDFDocument;
  45737. }));
  45738. (function (root, factory) {
  45739. {
  45740. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  45741. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  45742. root.pdfjsCoreDocument);
  45743. }
  45744. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  45745. coreDocument) {
  45746. var NotImplementedException = sharedUtil.NotImplementedException;
  45747. var MissingDataException = sharedUtil.MissingDataException;
  45748. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45749. var Util = sharedUtil.Util;
  45750. var Stream = coreStream.Stream;
  45751. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  45752. var PDFDocument = coreDocument.PDFDocument;
  45753. var BasePdfManager = (function BasePdfManagerClosure() {
  45754. function BasePdfManager() {
  45755. throw new Error('Cannot initialize BaseManagerManager');
  45756. }
  45757. BasePdfManager.prototype = {
  45758. get docId() {
  45759. return this._docId;
  45760. },
  45761. onLoadedStream: function BasePdfManager_onLoadedStream() {
  45762. throw new NotImplementedException();
  45763. },
  45764. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  45765. return this.ensure(this.pdfDocument, prop, args);
  45766. },
  45767. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  45768. return this.ensure(this.pdfDocument.xref, prop, args);
  45769. },
  45770. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  45771. return this.ensure(this.pdfDocument.catalog, prop, args);
  45772. },
  45773. getPage: function BasePdfManager_getPage(pageIndex) {
  45774. return this.pdfDocument.getPage(pageIndex);
  45775. },
  45776. cleanup: function BasePdfManager_cleanup() {
  45777. return this.pdfDocument.cleanup();
  45778. },
  45779. ensure: function BasePdfManager_ensure(obj, prop, args) {
  45780. return new NotImplementedException();
  45781. },
  45782. requestRange: function BasePdfManager_requestRange(begin, end) {
  45783. return new NotImplementedException();
  45784. },
  45785. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  45786. return new NotImplementedException();
  45787. },
  45788. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  45789. return new NotImplementedException();
  45790. },
  45791. updatePassword: function BasePdfManager_updatePassword(password) {
  45792. this.pdfDocument.xref.password = this.password = password;
  45793. if (this._passwordChangedCapability) {
  45794. this._passwordChangedCapability.resolve();
  45795. }
  45796. },
  45797. passwordChanged: function BasePdfManager_passwordChanged() {
  45798. this._passwordChangedCapability = createPromiseCapability();
  45799. return this._passwordChangedCapability.promise;
  45800. },
  45801. terminate: function BasePdfManager_terminate() {
  45802. return new NotImplementedException();
  45803. }
  45804. };
  45805. return BasePdfManager;
  45806. })();
  45807. var LocalPdfManager = (function LocalPdfManagerClosure() {
  45808. function LocalPdfManager(docId, data, password) {
  45809. this._docId = docId;
  45810. var stream = new Stream(data);
  45811. this.pdfDocument = new PDFDocument(this, stream, password);
  45812. this._loadedStreamCapability = createPromiseCapability();
  45813. this._loadedStreamCapability.resolve(stream);
  45814. }
  45815. Util.inherit(LocalPdfManager, BasePdfManager, {
  45816. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  45817. return new Promise(function (resolve, reject) {
  45818. try {
  45819. var value = obj[prop];
  45820. var result;
  45821. if (typeof value === 'function') {
  45822. result = value.apply(obj, args);
  45823. } else {
  45824. result = value;
  45825. }
  45826. resolve(result);
  45827. } catch (e) {
  45828. reject(e);
  45829. }
  45830. });
  45831. },
  45832. requestRange: function LocalPdfManager_requestRange(begin, end) {
  45833. return Promise.resolve();
  45834. },
  45835. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  45836. return;
  45837. },
  45838. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  45839. return this._loadedStreamCapability.promise;
  45840. },
  45841. terminate: function LocalPdfManager_terminate() {
  45842. return;
  45843. }
  45844. });
  45845. return LocalPdfManager;
  45846. })();
  45847. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  45848. function NetworkPdfManager(docId, args, msgHandler) {
  45849. this._docId = docId;
  45850. this.msgHandler = msgHandler;
  45851. var params = {
  45852. msgHandler: msgHandler,
  45853. httpHeaders: args.httpHeaders,
  45854. withCredentials: args.withCredentials,
  45855. chunkedViewerLoading: args.chunkedViewerLoading,
  45856. disableAutoFetch: args.disableAutoFetch,
  45857. initialData: args.initialData
  45858. };
  45859. this.streamManager = new ChunkedStreamManager(args.length,
  45860. args.rangeChunkSize,
  45861. args.url, params);
  45862. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  45863. args.password);
  45864. }
  45865. Util.inherit(NetworkPdfManager, BasePdfManager, {
  45866. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  45867. var pdfManager = this;
  45868. return new Promise(function (resolve, reject) {
  45869. function ensureHelper() {
  45870. try {
  45871. var result;
  45872. var value = obj[prop];
  45873. if (typeof value === 'function') {
  45874. result = value.apply(obj, args);
  45875. } else {
  45876. result = value;
  45877. }
  45878. resolve(result);
  45879. } catch(e) {
  45880. if (!(e instanceof MissingDataException)) {
  45881. reject(e);
  45882. return;
  45883. }
  45884. pdfManager.streamManager.requestRange(e.begin, e.end).
  45885. then(ensureHelper, reject);
  45886. }
  45887. }
  45888. ensureHelper();
  45889. });
  45890. },
  45891. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  45892. return this.streamManager.requestRange(begin, end);
  45893. },
  45894. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  45895. this.streamManager.requestAllChunks();
  45896. },
  45897. sendProgressiveData:
  45898. function NetworkPdfManager_sendProgressiveData(chunk) {
  45899. this.streamManager.onReceiveData({ chunk: chunk });
  45900. },
  45901. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  45902. return this.streamManager.onLoadedStream();
  45903. },
  45904. terminate: function NetworkPdfManager_terminate() {
  45905. this.streamManager.abort();
  45906. }
  45907. });
  45908. return NetworkPdfManager;
  45909. })();
  45910. exports.LocalPdfManager = LocalPdfManager;
  45911. exports.NetworkPdfManager = NetworkPdfManager;
  45912. }));
  45913. (function (root, factory) {
  45914. {
  45915. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  45916. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  45917. root.pdfjsSharedGlobal);
  45918. }
  45919. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  45920. sharedGlobal) {
  45921. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  45922. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45923. var MessageHandler = sharedUtil.MessageHandler;
  45924. var MissingPDFException = sharedUtil.MissingPDFException;
  45925. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  45926. var PasswordException = sharedUtil.PasswordException;
  45927. var PasswordResponses = sharedUtil.PasswordResponses;
  45928. var UnknownErrorException = sharedUtil.UnknownErrorException;
  45929. var XRefParseException = sharedUtil.XRefParseException;
  45930. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45931. var error = sharedUtil.error;
  45932. var info = sharedUtil.info;
  45933. var isInt = sharedUtil.isInt;
  45934. var warn = sharedUtil.warn;
  45935. var Ref = corePrimitives.Ref;
  45936. var LocalPdfManager = corePdfManager.LocalPdfManager;
  45937. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  45938. var globalScope = sharedGlobal.globalScope;
  45939. var PDFJS = sharedGlobal.PDFJS;
  45940. var WorkerTask = (function WorkerTaskClosure() {
  45941. function WorkerTask(name) {
  45942. this.name = name;
  45943. this.terminated = false;
  45944. this._capability = createPromiseCapability();
  45945. }
  45946. WorkerTask.prototype = {
  45947. get finished() {
  45948. return this._capability.promise;
  45949. },
  45950. finish: function () {
  45951. this._capability.resolve();
  45952. },
  45953. terminate: function () {
  45954. this.terminated = true;
  45955. },
  45956. ensureNotTerminated: function () {
  45957. if (this.terminated) {
  45958. throw new Error('Worker task was terminated');
  45959. }
  45960. }
  45961. };
  45962. return WorkerTask;
  45963. })();
  45964. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  45965. setup: function wphSetup(handler, port) {
  45966. var testMessageProcessed = false;
  45967. handler.on('test', function wphSetupTest(data) {
  45968. if (testMessageProcessed) {
  45969. return; // we already processed 'test' message once
  45970. }
  45971. testMessageProcessed = true;
  45972. // check if Uint8Array can be sent to worker
  45973. if (!(data instanceof Uint8Array)) {
  45974. handler.send('test', 'main', false);
  45975. return;
  45976. }
  45977. // making sure postMessage transfers are working
  45978. var supportTransfers = data[0] === 255;
  45979. handler.postMessageTransfers = supportTransfers;
  45980. // check if the response property is supported by xhr
  45981. var xhr = new XMLHttpRequest();
  45982. var responseExists = 'response' in xhr;
  45983. // check if the property is actually implemented
  45984. try {
  45985. var dummy = xhr.responseType;
  45986. } catch (e) {
  45987. responseExists = false;
  45988. }
  45989. if (!responseExists) {
  45990. handler.send('test', false);
  45991. return;
  45992. }
  45993. handler.send('test', {
  45994. supportTypedArray: true,
  45995. supportTransfers: supportTransfers
  45996. });
  45997. });
  45998. handler.on('GetDocRequest', function wphSetupDoc(data) {
  45999. return WorkerMessageHandler.createDocumentHandler(data, port);
  46000. });
  46001. },
  46002. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  46003. // This context is actually holds references on pdfManager and handler,
  46004. // until the latter is destroyed.
  46005. var pdfManager;
  46006. var terminated = false;
  46007. var cancelXHRs = null;
  46008. var WorkerTasks = [];
  46009. var docId = docParams.docId;
  46010. var workerHandlerName = docParams.docId + '_worker';
  46011. var handler = new MessageHandler(workerHandlerName, docId, port);
  46012. function ensureNotTerminated() {
  46013. if (terminated) {
  46014. throw new Error('Worker was terminated');
  46015. }
  46016. }
  46017. function startWorkerTask(task) {
  46018. WorkerTasks.push(task);
  46019. }
  46020. function finishWorkerTask(task) {
  46021. task.finish();
  46022. var i = WorkerTasks.indexOf(task);
  46023. WorkerTasks.splice(i, 1);
  46024. }
  46025. function loadDocument(recoveryMode) {
  46026. var loadDocumentCapability = createPromiseCapability();
  46027. var parseSuccess = function parseSuccess() {
  46028. var numPagesPromise = pdfManager.ensureDoc('numPages');
  46029. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  46030. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  46031. Promise.all([numPagesPromise, fingerprintPromise,
  46032. encryptedPromise]).then(function onDocReady(results) {
  46033. var doc = {
  46034. numPages: results[0],
  46035. fingerprint: results[1],
  46036. encrypted: !!results[2],
  46037. };
  46038. loadDocumentCapability.resolve(doc);
  46039. },
  46040. parseFailure);
  46041. };
  46042. var parseFailure = function parseFailure(e) {
  46043. loadDocumentCapability.reject(e);
  46044. };
  46045. pdfManager.ensureDoc('checkHeader', []).then(function() {
  46046. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  46047. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  46048. parseSuccess, parseFailure);
  46049. }, parseFailure);
  46050. }, parseFailure);
  46051. return loadDocumentCapability.promise;
  46052. }
  46053. function getPdfManager(data) {
  46054. var pdfManagerCapability = createPromiseCapability();
  46055. var pdfManager;
  46056. var source = data.source;
  46057. var disableRange = data.disableRange;
  46058. if (source.data) {
  46059. try {
  46060. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  46061. pdfManagerCapability.resolve(pdfManager);
  46062. } catch (ex) {
  46063. pdfManagerCapability.reject(ex);
  46064. }
  46065. return pdfManagerCapability.promise;
  46066. } else if (source.chunkedViewerLoading) {
  46067. try {
  46068. pdfManager = new NetworkPdfManager(docId, source, handler);
  46069. pdfManagerCapability.resolve(pdfManager);
  46070. } catch (ex) {
  46071. pdfManagerCapability.reject(ex);
  46072. }
  46073. return pdfManagerCapability.promise;
  46074. }
  46075. var networkManager = new NetworkManager(source.url, {
  46076. httpHeaders: source.httpHeaders,
  46077. withCredentials: source.withCredentials
  46078. });
  46079. var cachedChunks = [];
  46080. var fullRequestXhrId = networkManager.requestFull({
  46081. onHeadersReceived: function onHeadersReceived() {
  46082. if (disableRange) {
  46083. return;
  46084. }
  46085. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  46086. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  46087. return;
  46088. }
  46089. var contentEncoding =
  46090. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  46091. if (contentEncoding !== 'identity') {
  46092. return;
  46093. }
  46094. var length = fullRequestXhr.getResponseHeader('Content-Length');
  46095. length = parseInt(length, 10);
  46096. if (!isInt(length)) {
  46097. return;
  46098. }
  46099. source.length = length;
  46100. if (length <= 2 * source.rangeChunkSize) {
  46101. // The file size is smaller than the size of two chunks, so it does
  46102. // not make any sense to abort the request and retry with a range
  46103. // request.
  46104. return;
  46105. }
  46106. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  46107. // We can continue fetching when progressive loading is enabled,
  46108. // and we don't need the autoFetch feature.
  46109. source.disableAutoFetch = true;
  46110. } else {
  46111. // NOTE: by cancelling the full request, and then issuing range
  46112. // requests, there will be an issue for sites where you can only
  46113. // request the pdf once. However, if this is the case, then the
  46114. // server should not be returning that it can support range
  46115. // requests.
  46116. networkManager.abortRequest(fullRequestXhrId);
  46117. }
  46118. try {
  46119. pdfManager = new NetworkPdfManager(docId, source, handler);
  46120. pdfManagerCapability.resolve(pdfManager);
  46121. } catch (ex) {
  46122. pdfManagerCapability.reject(ex);
  46123. }
  46124. cancelXHRs = null;
  46125. },
  46126. onProgressiveData: source.disableStream ? null :
  46127. function onProgressiveData(chunk) {
  46128. if (!pdfManager) {
  46129. cachedChunks.push(chunk);
  46130. return;
  46131. }
  46132. pdfManager.sendProgressiveData(chunk);
  46133. },
  46134. onDone: function onDone(args) {
  46135. if (pdfManager) {
  46136. return; // already processed
  46137. }
  46138. var pdfFile;
  46139. if (args === null) {
  46140. // TODO add some streaming manager, e.g. for unknown length files.
  46141. // The data was returned in the onProgressiveData, combining...
  46142. var pdfFileLength = 0, pos = 0;
  46143. cachedChunks.forEach(function (chunk) {
  46144. pdfFileLength += chunk.byteLength;
  46145. });
  46146. if (source.length && pdfFileLength !== source.length) {
  46147. warn('reported HTTP length is different from actual');
  46148. }
  46149. var pdfFileArray = new Uint8Array(pdfFileLength);
  46150. cachedChunks.forEach(function (chunk) {
  46151. pdfFileArray.set(new Uint8Array(chunk), pos);
  46152. pos += chunk.byteLength;
  46153. });
  46154. pdfFile = pdfFileArray.buffer;
  46155. } else {
  46156. pdfFile = args.chunk;
  46157. }
  46158. // the data is array, instantiating directly from it
  46159. try {
  46160. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  46161. pdfManagerCapability.resolve(pdfManager);
  46162. } catch (ex) {
  46163. pdfManagerCapability.reject(ex);
  46164. }
  46165. cancelXHRs = null;
  46166. },
  46167. onError: function onError(status) {
  46168. var exception;
  46169. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  46170. exception = new MissingPDFException('Missing PDF "' +
  46171. source.url + '".');
  46172. handler.send('MissingPDF', exception);
  46173. } else {
  46174. exception = new UnexpectedResponseException(
  46175. 'Unexpected server response (' + status +
  46176. ') while retrieving PDF "' + source.url + '".', status);
  46177. handler.send('UnexpectedResponse', exception);
  46178. }
  46179. cancelXHRs = null;
  46180. },
  46181. onProgress: function onProgress(evt) {
  46182. handler.send('DocProgress', {
  46183. loaded: evt.loaded,
  46184. total: evt.lengthComputable ? evt.total : source.length
  46185. });
  46186. }
  46187. });
  46188. cancelXHRs = function () {
  46189. networkManager.abortRequest(fullRequestXhrId);
  46190. };
  46191. return pdfManagerCapability.promise;
  46192. }
  46193. var setupDoc = function(data) {
  46194. var onSuccess = function(doc) {
  46195. ensureNotTerminated();
  46196. handler.send('GetDoc', { pdfInfo: doc });
  46197. };
  46198. var onFailure = function(e) {
  46199. if (e instanceof PasswordException) {
  46200. if (e.code === PasswordResponses.NEED_PASSWORD) {
  46201. handler.send('NeedPassword', e);
  46202. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  46203. handler.send('IncorrectPassword', e);
  46204. }
  46205. } else if (e instanceof InvalidPDFException) {
  46206. handler.send('InvalidPDF', e);
  46207. } else if (e instanceof MissingPDFException) {
  46208. handler.send('MissingPDF', e);
  46209. } else if (e instanceof UnexpectedResponseException) {
  46210. handler.send('UnexpectedResponse', e);
  46211. } else {
  46212. handler.send('UnknownError',
  46213. new UnknownErrorException(e.message, e.toString()));
  46214. }
  46215. };
  46216. ensureNotTerminated();
  46217. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  46218. -1 : data.maxImageSize;
  46219. PDFJS.disableFontFace = data.disableFontFace;
  46220. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  46221. PDFJS.verbosity = data.verbosity;
  46222. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  46223. null : data.cMapUrl;
  46224. PDFJS.cMapPacked = data.cMapPacked === true;
  46225. getPdfManager(data).then(function (newPdfManager) {
  46226. if (terminated) {
  46227. // We were in a process of setting up the manager, but it got
  46228. // terminated in the middle.
  46229. newPdfManager.terminate();
  46230. throw new Error('Worker was terminated');
  46231. }
  46232. pdfManager = newPdfManager;
  46233. handler.send('PDFManagerReady', null);
  46234. pdfManager.onLoadedStream().then(function(stream) {
  46235. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  46236. });
  46237. }).then(function pdfManagerReady() {
  46238. ensureNotTerminated();
  46239. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  46240. ensureNotTerminated();
  46241. // Try again with recoveryMode == true
  46242. if (!(ex instanceof XRefParseException)) {
  46243. if (ex instanceof PasswordException) {
  46244. // after password exception prepare to receive a new password
  46245. // to repeat loading
  46246. pdfManager.passwordChanged().then(pdfManagerReady);
  46247. }
  46248. onFailure(ex);
  46249. return;
  46250. }
  46251. pdfManager.requestLoadedStream();
  46252. pdfManager.onLoadedStream().then(function() {
  46253. ensureNotTerminated();
  46254. loadDocument(true).then(onSuccess, onFailure);
  46255. });
  46256. }, onFailure);
  46257. }, onFailure);
  46258. };
  46259. handler.on('GetPage', function wphSetupGetPage(data) {
  46260. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46261. var rotatePromise = pdfManager.ensure(page, 'rotate');
  46262. var refPromise = pdfManager.ensure(page, 'ref');
  46263. var viewPromise = pdfManager.ensure(page, 'view');
  46264. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  46265. function(results) {
  46266. return {
  46267. rotate: results[0],
  46268. ref: results[1],
  46269. view: results[2]
  46270. };
  46271. });
  46272. });
  46273. });
  46274. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  46275. var ref = new Ref(data.ref.num, data.ref.gen);
  46276. var catalog = pdfManager.pdfDocument.catalog;
  46277. return catalog.getPageIndex(ref);
  46278. });
  46279. handler.on('GetDestinations',
  46280. function wphSetupGetDestinations(data) {
  46281. return pdfManager.ensureCatalog('destinations');
  46282. }
  46283. );
  46284. handler.on('GetDestination',
  46285. function wphSetupGetDestination(data) {
  46286. return pdfManager.ensureCatalog('getDestination', [data.id]);
  46287. }
  46288. );
  46289. handler.on('GetPageLabels',
  46290. function wphSetupGetPageLabels(data) {
  46291. return pdfManager.ensureCatalog('pageLabels');
  46292. }
  46293. );
  46294. handler.on('GetAttachments',
  46295. function wphSetupGetAttachments(data) {
  46296. return pdfManager.ensureCatalog('attachments');
  46297. }
  46298. );
  46299. handler.on('GetJavaScript',
  46300. function wphSetupGetJavaScript(data) {
  46301. return pdfManager.ensureCatalog('javaScript');
  46302. }
  46303. );
  46304. handler.on('GetOutline',
  46305. function wphSetupGetOutline(data) {
  46306. return pdfManager.ensureCatalog('documentOutline');
  46307. }
  46308. );
  46309. handler.on('GetMetadata',
  46310. function wphSetupGetMetadata(data) {
  46311. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  46312. pdfManager.ensureCatalog('metadata')]);
  46313. }
  46314. );
  46315. handler.on('GetData', function wphSetupGetData(data) {
  46316. pdfManager.requestLoadedStream();
  46317. return pdfManager.onLoadedStream().then(function(stream) {
  46318. return stream.bytes;
  46319. });
  46320. });
  46321. handler.on('GetStats',
  46322. function wphSetupGetStats(data) {
  46323. return pdfManager.pdfDocument.xref.stats;
  46324. }
  46325. );
  46326. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  46327. pdfManager.updatePassword(data);
  46328. });
  46329. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  46330. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46331. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  46332. });
  46333. });
  46334. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  46335. var pageIndex = data.pageIndex;
  46336. pdfManager.getPage(pageIndex).then(function(page) {
  46337. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  46338. startWorkerTask(task);
  46339. var pageNum = pageIndex + 1;
  46340. var start = Date.now();
  46341. // Pre compile the pdf page and fetch the fonts/images.
  46342. page.getOperatorList(handler, task, data.intent).then(
  46343. function(operatorList) {
  46344. finishWorkerTask(task);
  46345. info('page=' + pageNum + ' - getOperatorList: time=' +
  46346. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  46347. }, function(e) {
  46348. finishWorkerTask(task);
  46349. if (task.terminated) {
  46350. return; // ignoring errors from the terminated thread
  46351. }
  46352. // For compatibility with older behavior, generating unknown
  46353. // unsupported feature notification on errors.
  46354. handler.send('UnsupportedFeature',
  46355. {featureId: UNSUPPORTED_FEATURES.unknown});
  46356. var minimumStackMessage =
  46357. 'worker.js: while trying to getPage() and getOperatorList()';
  46358. var wrappedException;
  46359. // Turn the error into an obj that can be serialized
  46360. if (typeof e === 'string') {
  46361. wrappedException = {
  46362. message: e,
  46363. stack: minimumStackMessage
  46364. };
  46365. } else if (typeof e === 'object') {
  46366. wrappedException = {
  46367. message: e.message || e.toString(),
  46368. stack: e.stack || minimumStackMessage
  46369. };
  46370. } else {
  46371. wrappedException = {
  46372. message: 'Unknown exception type: ' + (typeof e),
  46373. stack: minimumStackMessage
  46374. };
  46375. }
  46376. handler.send('PageError', {
  46377. pageNum: pageNum,
  46378. error: wrappedException,
  46379. intent: data.intent
  46380. });
  46381. });
  46382. });
  46383. }, this);
  46384. handler.on('GetTextContent', function wphExtractText(data) {
  46385. var pageIndex = data.pageIndex;
  46386. var normalizeWhitespace = data.normalizeWhitespace;
  46387. return pdfManager.getPage(pageIndex).then(function(page) {
  46388. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  46389. startWorkerTask(task);
  46390. var pageNum = pageIndex + 1;
  46391. var start = Date.now();
  46392. return page.extractTextContent(task, normalizeWhitespace).then(
  46393. function(textContent) {
  46394. finishWorkerTask(task);
  46395. info('text indexing: page=' + pageNum + ' - time=' +
  46396. (Date.now() - start) + 'ms');
  46397. return textContent;
  46398. }, function (reason) {
  46399. finishWorkerTask(task);
  46400. if (task.terminated) {
  46401. return; // ignoring errors from the terminated thread
  46402. }
  46403. throw reason;
  46404. });
  46405. });
  46406. });
  46407. handler.on('Cleanup', function wphCleanup(data) {
  46408. return pdfManager.cleanup();
  46409. });
  46410. handler.on('Terminate', function wphTerminate(data) {
  46411. terminated = true;
  46412. if (pdfManager) {
  46413. pdfManager.terminate();
  46414. pdfManager = null;
  46415. }
  46416. if (cancelXHRs) {
  46417. cancelXHRs();
  46418. }
  46419. var waitOn = [];
  46420. WorkerTasks.forEach(function (task) {
  46421. waitOn.push(task.finished);
  46422. task.terminate();
  46423. });
  46424. return Promise.all(waitOn).then(function () {
  46425. // Notice that even if we destroying handler, resolved response promise
  46426. // must be sent back.
  46427. handler.destroy();
  46428. handler = null;
  46429. });
  46430. });
  46431. handler.on('Ready', function wphReady(data) {
  46432. setupDoc(docParams);
  46433. docParams = null; // we don't need docParams anymore -- saving memory.
  46434. });
  46435. return workerHandlerName;
  46436. }
  46437. };
  46438. function initializeWorker() {
  46439. if (!('console' in globalScope)) {
  46440. var consoleTimer = {};
  46441. var workerConsole = {
  46442. log: function log() {
  46443. var args = Array.prototype.slice.call(arguments);
  46444. globalScope.postMessage({
  46445. targetName: 'main',
  46446. action: 'console_log',
  46447. data: args
  46448. });
  46449. },
  46450. error: function error() {
  46451. var args = Array.prototype.slice.call(arguments);
  46452. globalScope.postMessage({
  46453. targetName: 'main',
  46454. action: 'console_error',
  46455. data: args
  46456. });
  46457. throw 'pdf.js execution error';
  46458. },
  46459. time: function time(name) {
  46460. consoleTimer[name] = Date.now();
  46461. },
  46462. timeEnd: function timeEnd(name) {
  46463. var time = consoleTimer[name];
  46464. if (!time) {
  46465. error('Unknown timer name ' + name);
  46466. }
  46467. this.log('Timer:', name, Date.now() - time);
  46468. }
  46469. };
  46470. globalScope.console = workerConsole;
  46471. }
  46472. var handler = new MessageHandler('worker', 'main', self);
  46473. WorkerMessageHandler.setup(handler, self);
  46474. handler.send('ready', null);
  46475. }
  46476. // Worker thread (and not node.js)?
  46477. if (typeof window === 'undefined' &&
  46478. !(typeof module !== 'undefined' && module.require)) {
  46479. initializeWorker();
  46480. }
  46481. exports.WorkerTask = WorkerTask;
  46482. exports.WorkerMessageHandler = WorkerMessageHandler;
  46483. }));
  46484. }).call(pdfjsLibs);
  46485. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  46486. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  46487. exports.PDFDataRangeTransport =
  46488. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  46489. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  46490. exports.AnnotationLayer =
  46491. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  46492. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  46493. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  46494. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  46495. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  46496. exports.UnexpectedResponseException =
  46497. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  46498. }));