pdf.combined.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177
  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.64';
  30. var pdfjsBuild = '2f145d8';
  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 === 3) {
  1500. return this._convertYccToRgb(data);
  1501. } else if (this.numComponents === 4) {
  1502. if (this._isColorConversionNeeded()) {
  1503. if (forceRGBoutput) {
  1504. return this._convertYcckToRgb(data);
  1505. } else {
  1506. return this._convertYcckToCmyk(data);
  1507. }
  1508. } else if (forceRGBoutput) {
  1509. return this._convertCmykToRgb(data);
  1510. }
  1511. }
  1512. return data;
  1513. }
  1514. };
  1515. return constructor;
  1516. })();
  1517. exports.JpegImage = JpegImage;
  1518. }));
  1519. var NetworkManager = (function NetworkManagerClosure() {
  1520. var OK_RESPONSE = 200;
  1521. var PARTIAL_CONTENT_RESPONSE = 206;
  1522. function NetworkManager(url, args) {
  1523. this.url = url;
  1524. args = args || {};
  1525. this.isHttp = /^https?:/i.test(url);
  1526. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  1527. this.withCredentials = args.withCredentials || false;
  1528. this.getXhr = args.getXhr ||
  1529. function NetworkManager_getXhr() {
  1530. return new XMLHttpRequest();
  1531. };
  1532. this.currXhrId = 0;
  1533. this.pendingRequests = Object.create(null);
  1534. this.loadedRequests = Object.create(null);
  1535. }
  1536. function getArrayBuffer(xhr) {
  1537. var data = xhr.response;
  1538. if (typeof data !== 'string') {
  1539. return data;
  1540. }
  1541. var length = data.length;
  1542. var array = new Uint8Array(length);
  1543. for (var i = 0; i < length; i++) {
  1544. array[i] = data.charCodeAt(i) & 0xFF;
  1545. }
  1546. return array.buffer;
  1547. }
  1548. var supportsMozChunked = (function supportsMozChunkedClosure() {
  1549. try {
  1550. var x = new XMLHttpRequest();
  1551. // Firefox 37- required .open() to be called before setting responseType.
  1552. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  1553. // Even though the URL is not visited, .open() could fail if the URL is
  1554. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  1555. // When this error occurs, this feature detection method will mistakenly
  1556. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  1557. x.open('GET', 'https://example.com');
  1558. x.responseType = 'moz-chunked-arraybuffer';
  1559. return x.responseType === 'moz-chunked-arraybuffer';
  1560. } catch (e) {
  1561. return false;
  1562. }
  1563. })();
  1564. NetworkManager.prototype = {
  1565. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  1566. var args = {
  1567. begin: begin,
  1568. end: end
  1569. };
  1570. for (var prop in listeners) {
  1571. args[prop] = listeners[prop];
  1572. }
  1573. return this.request(args);
  1574. },
  1575. requestFull: function NetworkManager_requestFull(listeners) {
  1576. return this.request(listeners);
  1577. },
  1578. request: function NetworkManager_request(args) {
  1579. var xhr = this.getXhr();
  1580. var xhrId = this.currXhrId++;
  1581. var pendingRequest = this.pendingRequests[xhrId] = {
  1582. xhr: xhr
  1583. };
  1584. xhr.open('GET', this.url);
  1585. xhr.withCredentials = this.withCredentials;
  1586. for (var property in this.httpHeaders) {
  1587. var value = this.httpHeaders[property];
  1588. if (typeof value === 'undefined') {
  1589. continue;
  1590. }
  1591. xhr.setRequestHeader(property, value);
  1592. }
  1593. if (this.isHttp && 'begin' in args && 'end' in args) {
  1594. var rangeStr = args.begin + '-' + (args.end - 1);
  1595. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  1596. pendingRequest.expectedStatus = 206;
  1597. } else {
  1598. pendingRequest.expectedStatus = 200;
  1599. }
  1600. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  1601. if (useMozChunkedLoading) {
  1602. xhr.responseType = 'moz-chunked-arraybuffer';
  1603. pendingRequest.onProgressiveData = args.onProgressiveData;
  1604. pendingRequest.mozChunked = true;
  1605. } else {
  1606. xhr.responseType = 'arraybuffer';
  1607. }
  1608. if (args.onError) {
  1609. xhr.onerror = function(evt) {
  1610. args.onError(xhr.status);
  1611. };
  1612. }
  1613. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  1614. xhr.onprogress = this.onProgress.bind(this, xhrId);
  1615. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  1616. pendingRequest.onDone = args.onDone;
  1617. pendingRequest.onError = args.onError;
  1618. pendingRequest.onProgress = args.onProgress;
  1619. xhr.send(null);
  1620. return xhrId;
  1621. },
  1622. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  1623. var pendingRequest = this.pendingRequests[xhrId];
  1624. if (!pendingRequest) {
  1625. // Maybe abortRequest was called...
  1626. return;
  1627. }
  1628. if (pendingRequest.mozChunked) {
  1629. var chunk = getArrayBuffer(pendingRequest.xhr);
  1630. pendingRequest.onProgressiveData(chunk);
  1631. }
  1632. var onProgress = pendingRequest.onProgress;
  1633. if (onProgress) {
  1634. onProgress(evt);
  1635. }
  1636. },
  1637. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  1638. var pendingRequest = this.pendingRequests[xhrId];
  1639. if (!pendingRequest) {
  1640. // Maybe abortRequest was called...
  1641. return;
  1642. }
  1643. var xhr = pendingRequest.xhr;
  1644. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  1645. pendingRequest.onHeadersReceived();
  1646. delete pendingRequest.onHeadersReceived;
  1647. }
  1648. if (xhr.readyState !== 4) {
  1649. return;
  1650. }
  1651. if (!(xhrId in this.pendingRequests)) {
  1652. // The XHR request might have been aborted in onHeadersReceived()
  1653. // callback, in which case we should abort request
  1654. return;
  1655. }
  1656. delete this.pendingRequests[xhrId];
  1657. // success status == 0 can be on ftp, file and other protocols
  1658. if (xhr.status === 0 && this.isHttp) {
  1659. if (pendingRequest.onError) {
  1660. pendingRequest.onError(xhr.status);
  1661. }
  1662. return;
  1663. }
  1664. var xhrStatus = xhr.status || OK_RESPONSE;
  1665. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  1666. // "A server MAY ignore the Range header". This means it's possible to
  1667. // get a 200 rather than a 206 response from a range request.
  1668. var ok_response_on_range_request =
  1669. xhrStatus === OK_RESPONSE &&
  1670. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  1671. if (!ok_response_on_range_request &&
  1672. xhrStatus !== pendingRequest.expectedStatus) {
  1673. if (pendingRequest.onError) {
  1674. pendingRequest.onError(xhr.status);
  1675. }
  1676. return;
  1677. }
  1678. this.loadedRequests[xhrId] = true;
  1679. var chunk = getArrayBuffer(xhr);
  1680. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  1681. var rangeHeader = xhr.getResponseHeader('Content-Range');
  1682. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  1683. var begin = parseInt(matches[1], 10);
  1684. pendingRequest.onDone({
  1685. begin: begin,
  1686. chunk: chunk
  1687. });
  1688. } else if (pendingRequest.onProgressiveData) {
  1689. pendingRequest.onDone(null);
  1690. } else if (chunk) {
  1691. pendingRequest.onDone({
  1692. begin: 0,
  1693. chunk: chunk
  1694. });
  1695. } else if (pendingRequest.onError) {
  1696. pendingRequest.onError(xhr.status);
  1697. }
  1698. },
  1699. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  1700. for (var xhrId in this.pendingRequests) {
  1701. return true;
  1702. }
  1703. return false;
  1704. },
  1705. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  1706. return this.pendingRequests[xhrId].xhr;
  1707. },
  1708. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  1709. return !!(this.pendingRequests[xhrId].onProgressiveData);
  1710. },
  1711. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  1712. return xhrId in this.pendingRequests;
  1713. },
  1714. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  1715. return xhrId in this.loadedRequests;
  1716. },
  1717. abortAllRequests: function NetworkManager_abortAllRequests() {
  1718. for (var xhrId in this.pendingRequests) {
  1719. this.abortRequest(xhrId | 0);
  1720. }
  1721. },
  1722. abortRequest: function NetworkManager_abortRequest(xhrId) {
  1723. var xhr = this.pendingRequests[xhrId].xhr;
  1724. delete this.pendingRequests[xhrId];
  1725. xhr.abort();
  1726. }
  1727. };
  1728. return NetworkManager;
  1729. })();
  1730. (function (root, factory) {
  1731. {
  1732. factory((root.pdfjsCoreNetwork = {}));
  1733. }
  1734. }(this, function (exports) {
  1735. exports.NetworkManager = NetworkManager;
  1736. }));
  1737. (function (root, factory) {
  1738. {
  1739. factory((root.pdfjsSharedGlobal = {}));
  1740. }
  1741. }(this, function (exports) {
  1742. var globalScope = (typeof window !== 'undefined') ? window :
  1743. (typeof global !== 'undefined') ? global :
  1744. (typeof self !== 'undefined') ? self : this;
  1745. var isWorker = (typeof window === 'undefined');
  1746. // The global PDFJS object exposes the API
  1747. // In production, it will be declared outside a global wrapper
  1748. // In development, it will be declared here
  1749. if (!globalScope.PDFJS) {
  1750. globalScope.PDFJS = {};
  1751. }
  1752. if (typeof pdfjsVersion !== 'undefined') {
  1753. globalScope.PDFJS.version = pdfjsVersion;
  1754. }
  1755. if (typeof pdfjsVersion !== 'undefined') {
  1756. globalScope.PDFJS.build = pdfjsBuild;
  1757. }
  1758. globalScope.PDFJS.pdfBug = false;
  1759. exports.globalScope = globalScope;
  1760. exports.isWorker = isWorker;
  1761. exports.PDFJS = globalScope.PDFJS;
  1762. }));
  1763. (function (root, factory) {
  1764. {
  1765. factory((root.pdfjsCoreBidi = {}), root.pdfjsSharedGlobal);
  1766. }
  1767. }(this, function (exports, sharedGlobal) {
  1768. var PDFJS = sharedGlobal.PDFJS;
  1769. var bidi = PDFJS.bidi = (function bidiClosure() {
  1770. // Character types for symbols from 0000 to 00FF.
  1771. var baseTypes = [
  1772. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  1773. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1774. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  1775. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  1776. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  1777. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1778. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  1779. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1780. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1781. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  1782. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1783. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  1784. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  1785. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  1786. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1787. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  1788. 'L', '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', 'L', 'L',
  1790. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  1791. ];
  1792. // Character types for symbols from 0600 to 06FF
  1793. var arabicTypes = [
  1794. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1795. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  1796. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1797. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1798. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1799. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1800. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1801. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1802. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  1803. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  1804. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1805. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1806. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', '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', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1812. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  1813. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  1814. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  1815. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  1816. ];
  1817. function isOdd(i) {
  1818. return (i & 1) !== 0;
  1819. }
  1820. function isEven(i) {
  1821. return (i & 1) === 0;
  1822. }
  1823. function findUnequal(arr, start, value) {
  1824. for (var j = start, jj = arr.length; j < jj; ++j) {
  1825. if (arr[j] !== value) {
  1826. return j;
  1827. }
  1828. }
  1829. return j;
  1830. }
  1831. function setValues(arr, start, end, value) {
  1832. for (var j = start; j < end; ++j) {
  1833. arr[j] = value;
  1834. }
  1835. }
  1836. function reverseValues(arr, start, end) {
  1837. for (var i = start, j = end - 1; i < j; ++i, --j) {
  1838. var temp = arr[i];
  1839. arr[i] = arr[j];
  1840. arr[j] = temp;
  1841. }
  1842. }
  1843. function createBidiText(str, isLTR, vertical) {
  1844. return {
  1845. str: str,
  1846. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  1847. };
  1848. }
  1849. // These are used in bidi(), which is called frequently. We re-use them on
  1850. // each call to avoid unnecessary allocations.
  1851. var chars = [];
  1852. var types = [];
  1853. function bidi(str, startLevel, vertical) {
  1854. var isLTR = true;
  1855. var strLength = str.length;
  1856. if (strLength === 0 || vertical) {
  1857. return createBidiText(str, isLTR, vertical);
  1858. }
  1859. // Get types and fill arrays
  1860. chars.length = strLength;
  1861. types.length = strLength;
  1862. var numBidi = 0;
  1863. var i, ii;
  1864. for (i = 0; i < strLength; ++i) {
  1865. chars[i] = str.charAt(i);
  1866. var charCode = str.charCodeAt(i);
  1867. var charType = 'L';
  1868. if (charCode <= 0x00ff) {
  1869. charType = baseTypes[charCode];
  1870. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  1871. charType = 'R';
  1872. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  1873. charType = arabicTypes[charCode & 0xff];
  1874. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  1875. charType = 'AL';
  1876. }
  1877. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  1878. numBidi++;
  1879. }
  1880. types[i] = charType;
  1881. }
  1882. // Detect the bidi method
  1883. // - If there are no rtl characters then no bidi needed
  1884. // - If less than 30% chars are rtl then string is primarily ltr
  1885. // - If more than 30% chars are rtl then string is primarily rtl
  1886. if (numBidi === 0) {
  1887. isLTR = true;
  1888. return createBidiText(str, isLTR);
  1889. }
  1890. if (startLevel === -1) {
  1891. if ((strLength / numBidi) < 0.3) {
  1892. isLTR = true;
  1893. startLevel = 0;
  1894. } else {
  1895. isLTR = false;
  1896. startLevel = 1;
  1897. }
  1898. }
  1899. var levels = [];
  1900. for (i = 0; i < strLength; ++i) {
  1901. levels[i] = startLevel;
  1902. }
  1903. /*
  1904. X1-X10: skip most of this, since we are NOT doing the embeddings.
  1905. */
  1906. var e = (isOdd(startLevel) ? 'R' : 'L');
  1907. var sor = e;
  1908. var eor = sor;
  1909. /*
  1910. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  1911. type of the NSM to the type of the previous character. If the NSM is at the
  1912. start of the level run, it will get the type of sor.
  1913. */
  1914. var lastType = sor;
  1915. for (i = 0; i < strLength; ++i) {
  1916. if (types[i] === 'NSM') {
  1917. types[i] = lastType;
  1918. } else {
  1919. lastType = types[i];
  1920. }
  1921. }
  1922. /*
  1923. W2. Search backwards from each instance of a European number until the
  1924. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  1925. the type of the European number to Arabic number.
  1926. */
  1927. lastType = sor;
  1928. var t;
  1929. for (i = 0; i < strLength; ++i) {
  1930. t = types[i];
  1931. if (t === 'EN') {
  1932. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  1933. } else if (t === 'R' || t === 'L' || t === 'AL') {
  1934. lastType = t;
  1935. }
  1936. }
  1937. /*
  1938. W3. Change all ALs to R.
  1939. */
  1940. for (i = 0; i < strLength; ++i) {
  1941. t = types[i];
  1942. if (t === 'AL') {
  1943. types[i] = 'R';
  1944. }
  1945. }
  1946. /*
  1947. W4. A single European separator between two European numbers changes to a
  1948. European number. A single common separator between two numbers of the same
  1949. type changes to that type:
  1950. */
  1951. for (i = 1; i < strLength - 1; ++i) {
  1952. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  1953. types[i] = 'EN';
  1954. }
  1955. if (types[i] === 'CS' &&
  1956. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  1957. types[i + 1] === types[i - 1]) {
  1958. types[i] = types[i - 1];
  1959. }
  1960. }
  1961. /*
  1962. W5. A sequence of European terminators adjacent to European numbers changes
  1963. to all European numbers:
  1964. */
  1965. for (i = 0; i < strLength; ++i) {
  1966. if (types[i] === 'EN') {
  1967. // do before
  1968. var j;
  1969. for (j = i - 1; j >= 0; --j) {
  1970. if (types[j] !== 'ET') {
  1971. break;
  1972. }
  1973. types[j] = 'EN';
  1974. }
  1975. // do after
  1976. for (j = i + 1; j < strLength; --j) {
  1977. if (types[j] !== 'ET') {
  1978. break;
  1979. }
  1980. types[j] = 'EN';
  1981. }
  1982. }
  1983. }
  1984. /*
  1985. W6. Otherwise, separators and terminators change to Other Neutral:
  1986. */
  1987. for (i = 0; i < strLength; ++i) {
  1988. t = types[i];
  1989. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  1990. types[i] = 'ON';
  1991. }
  1992. }
  1993. /*
  1994. W7. Search backwards from each instance of a European number until the
  1995. first strong type (R, L, or sor) is found. If an L is found, then change
  1996. the type of the European number to L.
  1997. */
  1998. lastType = sor;
  1999. for (i = 0; i < strLength; ++i) {
  2000. t = types[i];
  2001. if (t === 'EN') {
  2002. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  2003. } else if (t === 'R' || t === 'L') {
  2004. lastType = t;
  2005. }
  2006. }
  2007. /*
  2008. N1. A sequence of neutrals takes the direction of the surrounding strong
  2009. text if the text on both sides has the same direction. European and Arabic
  2010. numbers are treated as though they were R. Start-of-level-run (sor) and
  2011. end-of-level-run (eor) are used at level run boundaries.
  2012. */
  2013. for (i = 0; i < strLength; ++i) {
  2014. if (types[i] === 'ON') {
  2015. var end = findUnequal(types, i + 1, 'ON');
  2016. var before = sor;
  2017. if (i > 0) {
  2018. before = types[i - 1];
  2019. }
  2020. var after = eor;
  2021. if (end + 1 < strLength) {
  2022. after = types[end + 1];
  2023. }
  2024. if (before !== 'L') {
  2025. before = 'R';
  2026. }
  2027. if (after !== 'L') {
  2028. after = 'R';
  2029. }
  2030. if (before === after) {
  2031. setValues(types, i, end, before);
  2032. }
  2033. i = end - 1; // reset to end (-1 so next iteration is ok)
  2034. }
  2035. }
  2036. /*
  2037. N2. Any remaining neutrals take the embedding direction.
  2038. */
  2039. for (i = 0; i < strLength; ++i) {
  2040. if (types[i] === 'ON') {
  2041. types[i] = e;
  2042. }
  2043. }
  2044. /*
  2045. I1. For all characters with an even (left-to-right) embedding direction,
  2046. those of type R go up one level and those of type AN or EN go up two
  2047. levels.
  2048. I2. For all characters with an odd (right-to-left) embedding direction,
  2049. those of type L, EN or AN go up one level.
  2050. */
  2051. for (i = 0; i < strLength; ++i) {
  2052. t = types[i];
  2053. if (isEven(levels[i])) {
  2054. if (t === 'R') {
  2055. levels[i] += 1;
  2056. } else if (t === 'AN' || t === 'EN') {
  2057. levels[i] += 2;
  2058. }
  2059. } else { // isOdd
  2060. if (t === 'L' || t === 'AN' || t === 'EN') {
  2061. levels[i] += 1;
  2062. }
  2063. }
  2064. }
  2065. /*
  2066. L1. On each line, reset the embedding level of the following characters to
  2067. the paragraph embedding level:
  2068. segment separators,
  2069. paragraph separators,
  2070. any sequence of whitespace characters preceding a segment separator or
  2071. paragraph separator, and any sequence of white space characters at the end
  2072. of the line.
  2073. */
  2074. // don't bother as text is only single line
  2075. /*
  2076. L2. From the highest level found in the text to the lowest odd level on
  2077. each line, reverse any contiguous sequence of characters that are at that
  2078. level or higher.
  2079. */
  2080. // find highest level & lowest odd level
  2081. var highestLevel = -1;
  2082. var lowestOddLevel = 99;
  2083. var level;
  2084. for (i = 0, ii = levels.length; i < ii; ++i) {
  2085. level = levels[i];
  2086. if (highestLevel < level) {
  2087. highestLevel = level;
  2088. }
  2089. if (lowestOddLevel > level && isOdd(level)) {
  2090. lowestOddLevel = level;
  2091. }
  2092. }
  2093. // now reverse between those limits
  2094. for (level = highestLevel; level >= lowestOddLevel; --level) {
  2095. // find segments to reverse
  2096. var start = -1;
  2097. for (i = 0, ii = levels.length; i < ii; ++i) {
  2098. if (levels[i] < level) {
  2099. if (start >= 0) {
  2100. reverseValues(chars, start, i);
  2101. start = -1;
  2102. }
  2103. } else if (start < 0) {
  2104. start = i;
  2105. }
  2106. }
  2107. if (start >= 0) {
  2108. reverseValues(chars, start, levels.length);
  2109. }
  2110. }
  2111. /*
  2112. L3. Combining marks applied to a right-to-left base character will at this
  2113. point precede their base character. If the rendering engine expects them to
  2114. follow the base characters in the final display process, then the ordering
  2115. of the marks and the base character must be reversed.
  2116. */
  2117. // don't bother for now
  2118. /*
  2119. L4. A character that possesses the mirrored property as specified by
  2120. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  2121. directionality of that character is R.
  2122. */
  2123. // don't mirror as characters are already mirrored in the pdf
  2124. // Finally, return string
  2125. for (i = 0, ii = chars.length; i < ii; ++i) {
  2126. var ch = chars[i];
  2127. if (ch === '<' || ch === '>') {
  2128. chars[i] = '';
  2129. }
  2130. }
  2131. return createBidiText(chars.join(''), isLTR);
  2132. }
  2133. return bidi;
  2134. })();
  2135. exports.bidi = bidi;
  2136. }));
  2137. (function (root, factory) {
  2138. {
  2139. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedGlobal);
  2140. }
  2141. }(this, function (exports, sharedGlobal) {
  2142. var PDFJS = sharedGlobal.PDFJS;
  2143. /**
  2144. * Optimised CSS custom property getter/setter.
  2145. * @class
  2146. */
  2147. var CustomStyle = (function CustomStyleClosure() {
  2148. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  2149. // animate-css-transforms-firefox-webkit.html
  2150. // in some versions of IE9 it is critical that ms appear in this list
  2151. // before Moz
  2152. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  2153. var _cache = Object.create(null);
  2154. function CustomStyle() {}
  2155. CustomStyle.getProp = function get(propName, element) {
  2156. // check cache only when no element is given
  2157. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  2158. return _cache[propName];
  2159. }
  2160. element = element || document.documentElement;
  2161. var style = element.style, prefixed, uPropName;
  2162. // test standard property first
  2163. if (typeof style[propName] === 'string') {
  2164. return (_cache[propName] = propName);
  2165. }
  2166. // capitalize
  2167. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  2168. // test vendor specific properties
  2169. for (var i = 0, l = prefixes.length; i < l; i++) {
  2170. prefixed = prefixes[i] + uPropName;
  2171. if (typeof style[prefixed] === 'string') {
  2172. return (_cache[propName] = prefixed);
  2173. }
  2174. }
  2175. //if all fails then set to undefined
  2176. return (_cache[propName] = 'undefined');
  2177. };
  2178. CustomStyle.setProp = function set(propName, element, str) {
  2179. var prop = this.getProp(propName);
  2180. if (prop !== 'undefined') {
  2181. element.style[prop] = str;
  2182. }
  2183. };
  2184. return CustomStyle;
  2185. })();
  2186. PDFJS.CustomStyle = CustomStyle;
  2187. exports.CustomStyle = CustomStyle;
  2188. }));
  2189. (function (root, factory) {
  2190. {
  2191. factory((root.pdfjsSharedUtil = {}), root.pdfjsSharedGlobal);
  2192. }
  2193. }(this, function (exports, sharedGlobal) {
  2194. var PDFJS = sharedGlobal.PDFJS;
  2195. var globalScope = sharedGlobal.globalScope;
  2196. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  2197. var TextRenderingMode = {
  2198. FILL: 0,
  2199. STROKE: 1,
  2200. FILL_STROKE: 2,
  2201. INVISIBLE: 3,
  2202. FILL_ADD_TO_PATH: 4,
  2203. STROKE_ADD_TO_PATH: 5,
  2204. FILL_STROKE_ADD_TO_PATH: 6,
  2205. ADD_TO_PATH: 7,
  2206. FILL_STROKE_MASK: 3,
  2207. ADD_TO_PATH_FLAG: 4
  2208. };
  2209. var ImageKind = {
  2210. GRAYSCALE_1BPP: 1,
  2211. RGB_24BPP: 2,
  2212. RGBA_32BPP: 3
  2213. };
  2214. var AnnotationType = {
  2215. TEXT: 1,
  2216. LINK: 2,
  2217. FREETEXT: 3,
  2218. LINE: 4,
  2219. SQUARE: 5,
  2220. CIRCLE: 6,
  2221. POLYGON: 7,
  2222. POLYLINE: 8,
  2223. HIGHLIGHT: 9,
  2224. UNDERLINE: 10,
  2225. SQUIGGLY: 11,
  2226. STRIKEOUT: 12,
  2227. STAMP: 13,
  2228. CARET: 14,
  2229. INK: 15,
  2230. POPUP: 16,
  2231. FILEATTACHMENT: 17,
  2232. SOUND: 18,
  2233. MOVIE: 19,
  2234. WIDGET: 20,
  2235. SCREEN: 21,
  2236. PRINTERMARK: 22,
  2237. TRAPNET: 23,
  2238. WATERMARK: 24,
  2239. THREED: 25,
  2240. REDACT: 26
  2241. };
  2242. var AnnotationFlag = {
  2243. INVISIBLE: 0x01,
  2244. HIDDEN: 0x02,
  2245. PRINT: 0x04,
  2246. NOZOOM: 0x08,
  2247. NOROTATE: 0x10,
  2248. NOVIEW: 0x20,
  2249. READONLY: 0x40,
  2250. LOCKED: 0x80,
  2251. TOGGLENOVIEW: 0x100,
  2252. LOCKEDCONTENTS: 0x200
  2253. };
  2254. var AnnotationBorderStyleType = {
  2255. SOLID: 1,
  2256. DASHED: 2,
  2257. BEVELED: 3,
  2258. INSET: 4,
  2259. UNDERLINE: 5
  2260. };
  2261. var StreamType = {
  2262. UNKNOWN: 0,
  2263. FLATE: 1,
  2264. LZW: 2,
  2265. DCT: 3,
  2266. JPX: 4,
  2267. JBIG: 5,
  2268. A85: 6,
  2269. AHX: 7,
  2270. CCF: 8,
  2271. RL: 9
  2272. };
  2273. var FontType = {
  2274. UNKNOWN: 0,
  2275. TYPE1: 1,
  2276. TYPE1C: 2,
  2277. CIDFONTTYPE0: 3,
  2278. CIDFONTTYPE0C: 4,
  2279. TRUETYPE: 5,
  2280. CIDFONTTYPE2: 6,
  2281. TYPE3: 7,
  2282. OPENTYPE: 8,
  2283. TYPE0: 9,
  2284. MMTYPE1: 10
  2285. };
  2286. PDFJS.VERBOSITY_LEVELS = {
  2287. errors: 0,
  2288. warnings: 1,
  2289. infos: 5
  2290. };
  2291. // All the possible operations for an operator list.
  2292. var OPS = PDFJS.OPS = {
  2293. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2294. // 0's.
  2295. dependency: 1,
  2296. setLineWidth: 2,
  2297. setLineCap: 3,
  2298. setLineJoin: 4,
  2299. setMiterLimit: 5,
  2300. setDash: 6,
  2301. setRenderingIntent: 7,
  2302. setFlatness: 8,
  2303. setGState: 9,
  2304. save: 10,
  2305. restore: 11,
  2306. transform: 12,
  2307. moveTo: 13,
  2308. lineTo: 14,
  2309. curveTo: 15,
  2310. curveTo2: 16,
  2311. curveTo3: 17,
  2312. closePath: 18,
  2313. rectangle: 19,
  2314. stroke: 20,
  2315. closeStroke: 21,
  2316. fill: 22,
  2317. eoFill: 23,
  2318. fillStroke: 24,
  2319. eoFillStroke: 25,
  2320. closeFillStroke: 26,
  2321. closeEOFillStroke: 27,
  2322. endPath: 28,
  2323. clip: 29,
  2324. eoClip: 30,
  2325. beginText: 31,
  2326. endText: 32,
  2327. setCharSpacing: 33,
  2328. setWordSpacing: 34,
  2329. setHScale: 35,
  2330. setLeading: 36,
  2331. setFont: 37,
  2332. setTextRenderingMode: 38,
  2333. setTextRise: 39,
  2334. moveText: 40,
  2335. setLeadingMoveText: 41,
  2336. setTextMatrix: 42,
  2337. nextLine: 43,
  2338. showText: 44,
  2339. showSpacedText: 45,
  2340. nextLineShowText: 46,
  2341. nextLineSetSpacingShowText: 47,
  2342. setCharWidth: 48,
  2343. setCharWidthAndBounds: 49,
  2344. setStrokeColorSpace: 50,
  2345. setFillColorSpace: 51,
  2346. setStrokeColor: 52,
  2347. setStrokeColorN: 53,
  2348. setFillColor: 54,
  2349. setFillColorN: 55,
  2350. setStrokeGray: 56,
  2351. setFillGray: 57,
  2352. setStrokeRGBColor: 58,
  2353. setFillRGBColor: 59,
  2354. setStrokeCMYKColor: 60,
  2355. setFillCMYKColor: 61,
  2356. shadingFill: 62,
  2357. beginInlineImage: 63,
  2358. beginImageData: 64,
  2359. endInlineImage: 65,
  2360. paintXObject: 66,
  2361. markPoint: 67,
  2362. markPointProps: 68,
  2363. beginMarkedContent: 69,
  2364. beginMarkedContentProps: 70,
  2365. endMarkedContent: 71,
  2366. beginCompat: 72,
  2367. endCompat: 73,
  2368. paintFormXObjectBegin: 74,
  2369. paintFormXObjectEnd: 75,
  2370. beginGroup: 76,
  2371. endGroup: 77,
  2372. beginAnnotations: 78,
  2373. endAnnotations: 79,
  2374. beginAnnotation: 80,
  2375. endAnnotation: 81,
  2376. paintJpegXObject: 82,
  2377. paintImageMaskXObject: 83,
  2378. paintImageMaskXObjectGroup: 84,
  2379. paintImageXObject: 85,
  2380. paintInlineImageXObject: 86,
  2381. paintInlineImageXObjectGroup: 87,
  2382. paintImageXObjectRepeat: 88,
  2383. paintImageMaskXObjectRepeat: 89,
  2384. paintSolidColorImageMask: 90,
  2385. constructPath: 91
  2386. };
  2387. // A notice for devs. These are good for things that are helpful to devs, such
  2388. // as warning that Workers were disabled, which is important to devs but not
  2389. // end users.
  2390. function info(msg) {
  2391. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.infos) {
  2392. console.log('Info: ' + msg);
  2393. }
  2394. }
  2395. // Non-fatal warnings.
  2396. function warn(msg) {
  2397. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.warnings) {
  2398. console.log('Warning: ' + msg);
  2399. }
  2400. }
  2401. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2402. function deprecated(details) {
  2403. console.log('Deprecated API usage: ' + details);
  2404. }
  2405. // Fatal errors that should trigger the fallback UI and halt execution by
  2406. // throwing an exception.
  2407. function error(msg) {
  2408. if (PDFJS.verbosity >= PDFJS.VERBOSITY_LEVELS.errors) {
  2409. console.log('Error: ' + msg);
  2410. console.log(backtrace());
  2411. }
  2412. throw new Error(msg);
  2413. }
  2414. function backtrace() {
  2415. try {
  2416. throw new Error();
  2417. } catch (e) {
  2418. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2419. }
  2420. }
  2421. function assert(cond, msg) {
  2422. if (!cond) {
  2423. error(msg);
  2424. }
  2425. }
  2426. var UNSUPPORTED_FEATURES = PDFJS.UNSUPPORTED_FEATURES = {
  2427. unknown: 'unknown',
  2428. forms: 'forms',
  2429. javaScript: 'javaScript',
  2430. smask: 'smask',
  2431. shadingPattern: 'shadingPattern',
  2432. font: 'font'
  2433. };
  2434. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  2435. // absolute URL, it will be returned as is.
  2436. function combineUrl(baseUrl, url) {
  2437. if (!url) {
  2438. return baseUrl;
  2439. }
  2440. return new URL(url, baseUrl).href;
  2441. }
  2442. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2443. function isSameOrigin(baseUrl, otherUrl) {
  2444. try {
  2445. var base = new URL(baseUrl);
  2446. if (!base.origin || base.origin === 'null') {
  2447. return false; // non-HTTP url
  2448. }
  2449. } catch (e) {
  2450. return false;
  2451. }
  2452. var other = new URL(otherUrl, base);
  2453. return base.origin === other.origin;
  2454. }
  2455. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2456. function isValidUrl(url, allowRelative) {
  2457. if (!url) {
  2458. return false;
  2459. }
  2460. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2461. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2462. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2463. if (!protocol) {
  2464. return allowRelative;
  2465. }
  2466. protocol = protocol[0].toLowerCase();
  2467. switch (protocol) {
  2468. case 'http':
  2469. case 'https':
  2470. case 'ftp':
  2471. case 'mailto':
  2472. case 'tel':
  2473. return true;
  2474. default:
  2475. return false;
  2476. }
  2477. }
  2478. PDFJS.isValidUrl = isValidUrl;
  2479. /**
  2480. * Adds various attributes (href, title, target, rel) to hyperlinks.
  2481. * @param {HTMLLinkElement} link - The link element.
  2482. * @param {Object} params - An object with the properties:
  2483. * @param {string} params.url - An absolute URL.
  2484. */
  2485. function addLinkAttributes(link, params) {
  2486. var url = params && params.url;
  2487. link.href = link.title = (url ? removeNullCharacters(url) : '');
  2488. if (url) {
  2489. if (isExternalLinkTargetSet()) {
  2490. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  2491. }
  2492. // Strip referrer from the URL.
  2493. link.rel = PDFJS.externalLinkRel;
  2494. }
  2495. }
  2496. PDFJS.addLinkAttributes = addLinkAttributes;
  2497. function shadow(obj, prop, value) {
  2498. Object.defineProperty(obj, prop, { value: value,
  2499. enumerable: true,
  2500. configurable: true,
  2501. writable: false });
  2502. return value;
  2503. }
  2504. PDFJS.shadow = shadow;
  2505. function getLookupTableFactory(initializer) {
  2506. var lookup;
  2507. return function () {
  2508. if (initializer) {
  2509. lookup = Object.create(null);
  2510. initializer(lookup);
  2511. initializer = null;
  2512. }
  2513. return lookup;
  2514. };
  2515. }
  2516. var LinkTarget = PDFJS.LinkTarget = {
  2517. NONE: 0, // Default value.
  2518. SELF: 1,
  2519. BLANK: 2,
  2520. PARENT: 3,
  2521. TOP: 4,
  2522. };
  2523. var LinkTargetStringMap = [
  2524. '',
  2525. '_self',
  2526. '_blank',
  2527. '_parent',
  2528. '_top'
  2529. ];
  2530. function isExternalLinkTargetSet() {
  2531. if (PDFJS.openExternalLinksInNewWindow) {
  2532. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  2533. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  2534. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  2535. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  2536. }
  2537. // Reset the deprecated parameter, to suppress further warnings.
  2538. PDFJS.openExternalLinksInNewWindow = false;
  2539. }
  2540. switch (PDFJS.externalLinkTarget) {
  2541. case LinkTarget.NONE:
  2542. return false;
  2543. case LinkTarget.SELF:
  2544. case LinkTarget.BLANK:
  2545. case LinkTarget.PARENT:
  2546. case LinkTarget.TOP:
  2547. return true;
  2548. }
  2549. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  2550. // Reset the external link target, to suppress further warnings.
  2551. PDFJS.externalLinkTarget = LinkTarget.NONE;
  2552. return false;
  2553. }
  2554. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  2555. var PasswordResponses = PDFJS.PasswordResponses = {
  2556. NEED_PASSWORD: 1,
  2557. INCORRECT_PASSWORD: 2
  2558. };
  2559. var PasswordException = (function PasswordExceptionClosure() {
  2560. function PasswordException(msg, code) {
  2561. this.name = 'PasswordException';
  2562. this.message = msg;
  2563. this.code = code;
  2564. }
  2565. PasswordException.prototype = new Error();
  2566. PasswordException.constructor = PasswordException;
  2567. return PasswordException;
  2568. })();
  2569. PDFJS.PasswordException = PasswordException;
  2570. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2571. function UnknownErrorException(msg, details) {
  2572. this.name = 'UnknownErrorException';
  2573. this.message = msg;
  2574. this.details = details;
  2575. }
  2576. UnknownErrorException.prototype = new Error();
  2577. UnknownErrorException.constructor = UnknownErrorException;
  2578. return UnknownErrorException;
  2579. })();
  2580. PDFJS.UnknownErrorException = UnknownErrorException;
  2581. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2582. function InvalidPDFException(msg) {
  2583. this.name = 'InvalidPDFException';
  2584. this.message = msg;
  2585. }
  2586. InvalidPDFException.prototype = new Error();
  2587. InvalidPDFException.constructor = InvalidPDFException;
  2588. return InvalidPDFException;
  2589. })();
  2590. PDFJS.InvalidPDFException = InvalidPDFException;
  2591. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2592. function MissingPDFException(msg) {
  2593. this.name = 'MissingPDFException';
  2594. this.message = msg;
  2595. }
  2596. MissingPDFException.prototype = new Error();
  2597. MissingPDFException.constructor = MissingPDFException;
  2598. return MissingPDFException;
  2599. })();
  2600. PDFJS.MissingPDFException = MissingPDFException;
  2601. var UnexpectedResponseException =
  2602. (function UnexpectedResponseExceptionClosure() {
  2603. function UnexpectedResponseException(msg, status) {
  2604. this.name = 'UnexpectedResponseException';
  2605. this.message = msg;
  2606. this.status = status;
  2607. }
  2608. UnexpectedResponseException.prototype = new Error();
  2609. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2610. return UnexpectedResponseException;
  2611. })();
  2612. PDFJS.UnexpectedResponseException = UnexpectedResponseException;
  2613. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2614. function NotImplementedException(msg) {
  2615. this.message = msg;
  2616. }
  2617. NotImplementedException.prototype = new Error();
  2618. NotImplementedException.prototype.name = 'NotImplementedException';
  2619. NotImplementedException.constructor = NotImplementedException;
  2620. return NotImplementedException;
  2621. })();
  2622. var MissingDataException = (function MissingDataExceptionClosure() {
  2623. function MissingDataException(begin, end) {
  2624. this.begin = begin;
  2625. this.end = end;
  2626. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2627. }
  2628. MissingDataException.prototype = new Error();
  2629. MissingDataException.prototype.name = 'MissingDataException';
  2630. MissingDataException.constructor = MissingDataException;
  2631. return MissingDataException;
  2632. })();
  2633. var XRefParseException = (function XRefParseExceptionClosure() {
  2634. function XRefParseException(msg) {
  2635. this.message = msg;
  2636. }
  2637. XRefParseException.prototype = new Error();
  2638. XRefParseException.prototype.name = 'XRefParseException';
  2639. XRefParseException.constructor = XRefParseException;
  2640. return XRefParseException;
  2641. })();
  2642. var NullCharactersRegExp = /\x00/g;
  2643. function removeNullCharacters(str) {
  2644. if (typeof str !== 'string') {
  2645. warn('The argument for removeNullCharacters must be a string.');
  2646. return str;
  2647. }
  2648. return str.replace(NullCharactersRegExp, '');
  2649. }
  2650. PDFJS.removeNullCharacters = removeNullCharacters;
  2651. function bytesToString(bytes) {
  2652. assert(bytes !== null && typeof bytes === 'object' &&
  2653. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2654. var length = bytes.length;
  2655. var MAX_ARGUMENT_COUNT = 8192;
  2656. if (length < MAX_ARGUMENT_COUNT) {
  2657. return String.fromCharCode.apply(null, bytes);
  2658. }
  2659. var strBuf = [];
  2660. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2661. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2662. var chunk = bytes.subarray(i, chunkEnd);
  2663. strBuf.push(String.fromCharCode.apply(null, chunk));
  2664. }
  2665. return strBuf.join('');
  2666. }
  2667. function stringToBytes(str) {
  2668. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2669. var length = str.length;
  2670. var bytes = new Uint8Array(length);
  2671. for (var i = 0; i < length; ++i) {
  2672. bytes[i] = str.charCodeAt(i) & 0xFF;
  2673. }
  2674. return bytes;
  2675. }
  2676. function string32(value) {
  2677. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2678. (value >> 8) & 0xff, value & 0xff);
  2679. }
  2680. function log2(x) {
  2681. var n = 1, i = 0;
  2682. while (x > n) {
  2683. n <<= 1;
  2684. i++;
  2685. }
  2686. return i;
  2687. }
  2688. function readInt8(data, start) {
  2689. return (data[start] << 24) >> 24;
  2690. }
  2691. function readUint16(data, offset) {
  2692. return (data[offset] << 8) | data[offset + 1];
  2693. }
  2694. function readUint32(data, offset) {
  2695. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2696. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2697. }
  2698. // Lazy test the endianness of the platform
  2699. // NOTE: This will be 'true' for simulated TypedArrays
  2700. function isLittleEndian() {
  2701. var buffer8 = new Uint8Array(2);
  2702. buffer8[0] = 1;
  2703. var buffer16 = new Uint16Array(buffer8.buffer);
  2704. return (buffer16[0] === 1);
  2705. }
  2706. Object.defineProperty(PDFJS, 'isLittleEndian', {
  2707. configurable: true,
  2708. get: function PDFJS_isLittleEndian() {
  2709. return shadow(PDFJS, 'isLittleEndian', isLittleEndian());
  2710. }
  2711. });
  2712. // Lazy test if the userAgent support CanvasTypedArrays
  2713. function hasCanvasTypedArrays() {
  2714. var canvas = document.createElement('canvas');
  2715. canvas.width = canvas.height = 1;
  2716. var ctx = canvas.getContext('2d');
  2717. var imageData = ctx.createImageData(1, 1);
  2718. return (typeof imageData.data.buffer !== 'undefined');
  2719. }
  2720. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  2721. configurable: true,
  2722. get: function PDFJS_hasCanvasTypedArrays() {
  2723. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  2724. }
  2725. });
  2726. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2727. function Uint32ArrayView(buffer, length) {
  2728. this.buffer = buffer;
  2729. this.byteLength = buffer.length;
  2730. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2731. ensureUint32ArrayViewProps(this.length);
  2732. }
  2733. Uint32ArrayView.prototype = Object.create(null);
  2734. var uint32ArrayViewSetters = 0;
  2735. function createUint32ArrayProp(index) {
  2736. return {
  2737. get: function () {
  2738. var buffer = this.buffer, offset = index << 2;
  2739. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2740. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2741. },
  2742. set: function (value) {
  2743. var buffer = this.buffer, offset = index << 2;
  2744. buffer[offset] = value & 255;
  2745. buffer[offset + 1] = (value >> 8) & 255;
  2746. buffer[offset + 2] = (value >> 16) & 255;
  2747. buffer[offset + 3] = (value >>> 24) & 255;
  2748. }
  2749. };
  2750. }
  2751. function ensureUint32ArrayViewProps(length) {
  2752. while (uint32ArrayViewSetters < length) {
  2753. Object.defineProperty(Uint32ArrayView.prototype,
  2754. uint32ArrayViewSetters,
  2755. createUint32ArrayProp(uint32ArrayViewSetters));
  2756. uint32ArrayViewSetters++;
  2757. }
  2758. }
  2759. return Uint32ArrayView;
  2760. })();
  2761. exports.Uint32ArrayView = Uint32ArrayView;
  2762. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2763. var Util = PDFJS.Util = (function UtilClosure() {
  2764. function Util() {}
  2765. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2766. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2767. // creating many intermediate strings.
  2768. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2769. rgbBuf[1] = r;
  2770. rgbBuf[3] = g;
  2771. rgbBuf[5] = b;
  2772. return rgbBuf.join('');
  2773. };
  2774. // Concatenates two transformation matrices together and returns the result.
  2775. Util.transform = function Util_transform(m1, m2) {
  2776. return [
  2777. m1[0] * m2[0] + m1[2] * m2[1],
  2778. m1[1] * m2[0] + m1[3] * m2[1],
  2779. m1[0] * m2[2] + m1[2] * m2[3],
  2780. m1[1] * m2[2] + m1[3] * m2[3],
  2781. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2782. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2783. ];
  2784. };
  2785. // For 2d affine transforms
  2786. Util.applyTransform = function Util_applyTransform(p, m) {
  2787. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2788. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2789. return [xt, yt];
  2790. };
  2791. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2792. var d = m[0] * m[3] - m[1] * m[2];
  2793. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2794. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2795. return [xt, yt];
  2796. };
  2797. // Applies the transform to the rectangle and finds the minimum axially
  2798. // aligned bounding box.
  2799. Util.getAxialAlignedBoundingBox =
  2800. function Util_getAxialAlignedBoundingBox(r, m) {
  2801. var p1 = Util.applyTransform(r, m);
  2802. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2803. var p3 = Util.applyTransform([r[0], r[3]], m);
  2804. var p4 = Util.applyTransform([r[2], r[1]], m);
  2805. return [
  2806. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2807. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2808. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2809. Math.max(p1[1], p2[1], p3[1], p4[1])
  2810. ];
  2811. };
  2812. Util.inverseTransform = function Util_inverseTransform(m) {
  2813. var d = m[0] * m[3] - m[1] * m[2];
  2814. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2815. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2816. };
  2817. // Apply a generic 3d matrix M on a 3-vector v:
  2818. // | a b c | | X |
  2819. // | d e f | x | Y |
  2820. // | g h i | | Z |
  2821. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2822. // with v as [X,Y,Z]
  2823. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2824. return [
  2825. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2826. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2827. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2828. ];
  2829. };
  2830. // This calculation uses Singular Value Decomposition.
  2831. // The SVD can be represented with formula A = USV. We are interested in the
  2832. // matrix S here because it represents the scale values.
  2833. Util.singularValueDecompose2dScale =
  2834. function Util_singularValueDecompose2dScale(m) {
  2835. var transpose = [m[0], m[2], m[1], m[3]];
  2836. // Multiply matrix m with its transpose.
  2837. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2838. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2839. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2840. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2841. // Solve the second degree polynomial to get roots.
  2842. var first = (a + d) / 2;
  2843. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2844. var sx = first + second || 1;
  2845. var sy = first - second || 1;
  2846. // Scale values are the square roots of the eigenvalues.
  2847. return [Math.sqrt(sx), Math.sqrt(sy)];
  2848. };
  2849. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2850. // For coordinate systems whose origin lies in the bottom-left, this
  2851. // means normalization to (BL,TR) ordering. For systems with origin in the
  2852. // top-left, this means (TL,BR) ordering.
  2853. Util.normalizeRect = function Util_normalizeRect(rect) {
  2854. var r = rect.slice(0); // clone rect
  2855. if (rect[0] > rect[2]) {
  2856. r[0] = rect[2];
  2857. r[2] = rect[0];
  2858. }
  2859. if (rect[1] > rect[3]) {
  2860. r[1] = rect[3];
  2861. r[3] = rect[1];
  2862. }
  2863. return r;
  2864. };
  2865. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2866. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2867. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2868. Util.intersect = function Util_intersect(rect1, rect2) {
  2869. function compare(a, b) {
  2870. return a - b;
  2871. }
  2872. // Order points along the axes
  2873. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2874. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2875. result = [];
  2876. rect1 = Util.normalizeRect(rect1);
  2877. rect2 = Util.normalizeRect(rect2);
  2878. // X: first and second points belong to different rectangles?
  2879. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2880. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2881. // Intersection must be between second and third points
  2882. result[0] = orderedX[1];
  2883. result[2] = orderedX[2];
  2884. } else {
  2885. return false;
  2886. }
  2887. // Y: first and second points belong to different rectangles?
  2888. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2889. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2890. // Intersection must be between second and third points
  2891. result[1] = orderedY[1];
  2892. result[3] = orderedY[2];
  2893. } else {
  2894. return false;
  2895. }
  2896. return result;
  2897. };
  2898. Util.sign = function Util_sign(num) {
  2899. return num < 0 ? -1 : 1;
  2900. };
  2901. var ROMAN_NUMBER_MAP = [
  2902. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2903. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2904. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2905. ];
  2906. /**
  2907. * Converts positive integers to (upper case) Roman numerals.
  2908. * @param {integer} number - The number that should be converted.
  2909. * @param {boolean} lowerCase - Indicates if the result should be converted
  2910. * to lower case letters. The default is false.
  2911. * @return {string} The resulting Roman number.
  2912. */
  2913. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2914. assert(isInt(number) && number > 0,
  2915. 'The number should be a positive integer.');
  2916. var pos, romanBuf = [];
  2917. // Thousands
  2918. while (number >= 1000) {
  2919. number -= 1000;
  2920. romanBuf.push('M');
  2921. }
  2922. // Hundreds
  2923. pos = (number / 100) | 0;
  2924. number %= 100;
  2925. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2926. // Tens
  2927. pos = (number / 10) | 0;
  2928. number %= 10;
  2929. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2930. // Ones
  2931. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2932. var romanStr = romanBuf.join('');
  2933. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2934. };
  2935. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2936. Array.prototype.push.apply(arr1, arr2);
  2937. };
  2938. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2939. Array.prototype.unshift.apply(arr1, arr2);
  2940. };
  2941. Util.extendObj = function extendObj(obj1, obj2) {
  2942. for (var key in obj2) {
  2943. obj1[key] = obj2[key];
  2944. }
  2945. };
  2946. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2947. name) {
  2948. while (dict && !dict.has(name)) {
  2949. dict = dict.get('Parent');
  2950. }
  2951. if (!dict) {
  2952. return null;
  2953. }
  2954. return dict.get(name);
  2955. };
  2956. Util.inherit = function Util_inherit(sub, base, prototype) {
  2957. sub.prototype = Object.create(base.prototype);
  2958. sub.prototype.constructor = sub;
  2959. for (var prop in prototype) {
  2960. sub.prototype[prop] = prototype[prop];
  2961. }
  2962. };
  2963. Util.loadScript = function Util_loadScript(src, callback) {
  2964. var script = document.createElement('script');
  2965. var loaded = false;
  2966. script.setAttribute('src', src);
  2967. if (callback) {
  2968. script.onload = function() {
  2969. if (!loaded) {
  2970. callback();
  2971. }
  2972. loaded = true;
  2973. };
  2974. }
  2975. document.getElementsByTagName('head')[0].appendChild(script);
  2976. };
  2977. return Util;
  2978. })();
  2979. /**
  2980. * PDF page viewport created based on scale, rotation and offset.
  2981. * @class
  2982. * @alias PDFJS.PageViewport
  2983. */
  2984. var PageViewport = PDFJS.PageViewport = (function PageViewportClosure() {
  2985. /**
  2986. * @constructor
  2987. * @private
  2988. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  2989. * @param scale {number} scale of the viewport.
  2990. * @param rotation {number} rotations of the viewport in degrees.
  2991. * @param offsetX {number} offset X
  2992. * @param offsetY {number} offset Y
  2993. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  2994. */
  2995. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  2996. this.viewBox = viewBox;
  2997. this.scale = scale;
  2998. this.rotation = rotation;
  2999. this.offsetX = offsetX;
  3000. this.offsetY = offsetY;
  3001. // creating transform to convert pdf coordinate system to the normal
  3002. // canvas like coordinates taking in account scale and rotation
  3003. var centerX = (viewBox[2] + viewBox[0]) / 2;
  3004. var centerY = (viewBox[3] + viewBox[1]) / 2;
  3005. var rotateA, rotateB, rotateC, rotateD;
  3006. rotation = rotation % 360;
  3007. rotation = rotation < 0 ? rotation + 360 : rotation;
  3008. switch (rotation) {
  3009. case 180:
  3010. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  3011. break;
  3012. case 90:
  3013. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  3014. break;
  3015. case 270:
  3016. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  3017. break;
  3018. //case 0:
  3019. default:
  3020. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  3021. break;
  3022. }
  3023. if (dontFlip) {
  3024. rotateC = -rotateC; rotateD = -rotateD;
  3025. }
  3026. var offsetCanvasX, offsetCanvasY;
  3027. var width, height;
  3028. if (rotateA === 0) {
  3029. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  3030. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  3031. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  3032. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  3033. } else {
  3034. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  3035. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  3036. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  3037. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  3038. }
  3039. // creating transform for the following operations:
  3040. // translate(-centerX, -centerY), rotate and flip vertically,
  3041. // scale, and translate(offsetCanvasX, offsetCanvasY)
  3042. this.transform = [
  3043. rotateA * scale,
  3044. rotateB * scale,
  3045. rotateC * scale,
  3046. rotateD * scale,
  3047. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  3048. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  3049. ];
  3050. this.width = width;
  3051. this.height = height;
  3052. this.fontScale = scale;
  3053. }
  3054. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  3055. /**
  3056. * Clones viewport with additional properties.
  3057. * @param args {Object} (optional) If specified, may contain the 'scale' or
  3058. * 'rotation' properties to override the corresponding properties in
  3059. * the cloned viewport.
  3060. * @returns {PDFJS.PageViewport} Cloned viewport.
  3061. */
  3062. clone: function PageViewPort_clone(args) {
  3063. args = args || {};
  3064. var scale = 'scale' in args ? args.scale : this.scale;
  3065. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  3066. return new PageViewport(this.viewBox.slice(), scale, rotation,
  3067. this.offsetX, this.offsetY, args.dontFlip);
  3068. },
  3069. /**
  3070. * Converts PDF point to the viewport coordinates. For examples, useful for
  3071. * converting PDF location into canvas pixel coordinates.
  3072. * @param x {number} X coordinate.
  3073. * @param y {number} Y coordinate.
  3074. * @returns {Object} Object that contains 'x' and 'y' properties of the
  3075. * point in the viewport coordinate space.
  3076. * @see {@link convertToPdfPoint}
  3077. * @see {@link convertToViewportRectangle}
  3078. */
  3079. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  3080. return Util.applyTransform([x, y], this.transform);
  3081. },
  3082. /**
  3083. * Converts PDF rectangle to the viewport coordinates.
  3084. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  3085. * @returns {Array} Contains corresponding coordinates of the rectangle
  3086. * in the viewport coordinate space.
  3087. * @see {@link convertToViewportPoint}
  3088. */
  3089. convertToViewportRectangle:
  3090. function PageViewport_convertToViewportRectangle(rect) {
  3091. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  3092. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  3093. return [tl[0], tl[1], br[0], br[1]];
  3094. },
  3095. /**
  3096. * Converts viewport coordinates to the PDF location. For examples, useful
  3097. * for converting canvas pixel location into PDF one.
  3098. * @param x {number} X coordinate.
  3099. * @param y {number} Y coordinate.
  3100. * @returns {Object} Object that contains 'x' and 'y' properties of the
  3101. * point in the PDF coordinate space.
  3102. * @see {@link convertToViewportPoint}
  3103. */
  3104. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  3105. return Util.applyInverseTransform([x, y], this.transform);
  3106. }
  3107. };
  3108. return PageViewport;
  3109. })();
  3110. var PDFStringTranslateTable = [
  3111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  3112. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  3113. 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,
  3114. 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,
  3115. 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,
  3116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  3117. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  3118. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  3119. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  3120. ];
  3121. function stringToPDFString(str) {
  3122. var i, n = str.length, strBuf = [];
  3123. if (str[0] === '\xFE' && str[1] === '\xFF') {
  3124. // UTF16BE BOM
  3125. for (i = 2; i < n; i += 2) {
  3126. strBuf.push(String.fromCharCode(
  3127. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  3128. }
  3129. } else {
  3130. for (i = 0; i < n; ++i) {
  3131. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  3132. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  3133. }
  3134. }
  3135. return strBuf.join('');
  3136. }
  3137. function stringToUTF8String(str) {
  3138. return decodeURIComponent(escape(str));
  3139. }
  3140. function utf8StringToString(str) {
  3141. return unescape(encodeURIComponent(str));
  3142. }
  3143. function isEmptyObj(obj) {
  3144. for (var key in obj) {
  3145. return false;
  3146. }
  3147. return true;
  3148. }
  3149. function isBool(v) {
  3150. return typeof v === 'boolean';
  3151. }
  3152. function isInt(v) {
  3153. return typeof v === 'number' && ((v | 0) === v);
  3154. }
  3155. function isNum(v) {
  3156. return typeof v === 'number';
  3157. }
  3158. function isString(v) {
  3159. return typeof v === 'string';
  3160. }
  3161. function isArray(v) {
  3162. return v instanceof Array;
  3163. }
  3164. function isArrayBuffer(v) {
  3165. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  3166. }
  3167. /**
  3168. * Promise Capability object.
  3169. *
  3170. * @typedef {Object} PromiseCapability
  3171. * @property {Promise} promise - A promise object.
  3172. * @property {function} resolve - Fullfills the promise.
  3173. * @property {function} reject - Rejects the promise.
  3174. */
  3175. /**
  3176. * Creates a promise capability object.
  3177. * @alias PDFJS.createPromiseCapability
  3178. *
  3179. * @return {PromiseCapability} A capability object contains:
  3180. * - a Promise, resolve and reject methods.
  3181. */
  3182. function createPromiseCapability() {
  3183. var capability = {};
  3184. capability.promise = new Promise(function (resolve, reject) {
  3185. capability.resolve = resolve;
  3186. capability.reject = reject;
  3187. });
  3188. return capability;
  3189. }
  3190. PDFJS.createPromiseCapability = createPromiseCapability;
  3191. /**
  3192. * Polyfill for Promises:
  3193. * The following promise implementation tries to generally implement the
  3194. * Promise/A+ spec. Some notable differences from other promise libaries are:
  3195. * - There currently isn't a seperate deferred and promise object.
  3196. * - Unhandled rejections eventually show an error if they aren't handled.
  3197. *
  3198. * Based off of the work in:
  3199. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  3200. */
  3201. (function PromiseClosure() {
  3202. if (globalScope.Promise) {
  3203. // Promises existing in the DOM/Worker, checking presence of all/resolve
  3204. if (typeof globalScope.Promise.all !== 'function') {
  3205. globalScope.Promise.all = function (iterable) {
  3206. var count = 0, results = [], resolve, reject;
  3207. var promise = new globalScope.Promise(function (resolve_, reject_) {
  3208. resolve = resolve_;
  3209. reject = reject_;
  3210. });
  3211. iterable.forEach(function (p, i) {
  3212. count++;
  3213. p.then(function (result) {
  3214. results[i] = result;
  3215. count--;
  3216. if (count === 0) {
  3217. resolve(results);
  3218. }
  3219. }, reject);
  3220. });
  3221. if (count === 0) {
  3222. resolve(results);
  3223. }
  3224. return promise;
  3225. };
  3226. }
  3227. if (typeof globalScope.Promise.resolve !== 'function') {
  3228. globalScope.Promise.resolve = function (value) {
  3229. return new globalScope.Promise(function (resolve) { resolve(value); });
  3230. };
  3231. }
  3232. if (typeof globalScope.Promise.reject !== 'function') {
  3233. globalScope.Promise.reject = function (reason) {
  3234. return new globalScope.Promise(function (resolve, reject) {
  3235. reject(reason);
  3236. });
  3237. };
  3238. }
  3239. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  3240. globalScope.Promise.prototype.catch = function (onReject) {
  3241. return globalScope.Promise.prototype.then(undefined, onReject);
  3242. };
  3243. }
  3244. return;
  3245. }
  3246. var STATUS_PENDING = 0;
  3247. var STATUS_RESOLVED = 1;
  3248. var STATUS_REJECTED = 2;
  3249. // In an attempt to avoid silent exceptions, unhandled rejections are
  3250. // tracked and if they aren't handled in a certain amount of time an
  3251. // error is logged.
  3252. var REJECTION_TIMEOUT = 500;
  3253. var HandlerManager = {
  3254. handlers: [],
  3255. running: false,
  3256. unhandledRejections: [],
  3257. pendingRejectionCheck: false,
  3258. scheduleHandlers: function scheduleHandlers(promise) {
  3259. if (promise._status === STATUS_PENDING) {
  3260. return;
  3261. }
  3262. this.handlers = this.handlers.concat(promise._handlers);
  3263. promise._handlers = [];
  3264. if (this.running) {
  3265. return;
  3266. }
  3267. this.running = true;
  3268. setTimeout(this.runHandlers.bind(this), 0);
  3269. },
  3270. runHandlers: function runHandlers() {
  3271. var RUN_TIMEOUT = 1; // ms
  3272. var timeoutAt = Date.now() + RUN_TIMEOUT;
  3273. while (this.handlers.length > 0) {
  3274. var handler = this.handlers.shift();
  3275. var nextStatus = handler.thisPromise._status;
  3276. var nextValue = handler.thisPromise._value;
  3277. try {
  3278. if (nextStatus === STATUS_RESOLVED) {
  3279. if (typeof handler.onResolve === 'function') {
  3280. nextValue = handler.onResolve(nextValue);
  3281. }
  3282. } else if (typeof handler.onReject === 'function') {
  3283. nextValue = handler.onReject(nextValue);
  3284. nextStatus = STATUS_RESOLVED;
  3285. if (handler.thisPromise._unhandledRejection) {
  3286. this.removeUnhandeledRejection(handler.thisPromise);
  3287. }
  3288. }
  3289. } catch (ex) {
  3290. nextStatus = STATUS_REJECTED;
  3291. nextValue = ex;
  3292. }
  3293. handler.nextPromise._updateStatus(nextStatus, nextValue);
  3294. if (Date.now() >= timeoutAt) {
  3295. break;
  3296. }
  3297. }
  3298. if (this.handlers.length > 0) {
  3299. setTimeout(this.runHandlers.bind(this), 0);
  3300. return;
  3301. }
  3302. this.running = false;
  3303. },
  3304. addUnhandledRejection: function addUnhandledRejection(promise) {
  3305. this.unhandledRejections.push({
  3306. promise: promise,
  3307. time: Date.now()
  3308. });
  3309. this.scheduleRejectionCheck();
  3310. },
  3311. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  3312. promise._unhandledRejection = false;
  3313. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3314. if (this.unhandledRejections[i].promise === promise) {
  3315. this.unhandledRejections.splice(i);
  3316. i--;
  3317. }
  3318. }
  3319. },
  3320. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3321. if (this.pendingRejectionCheck) {
  3322. return;
  3323. }
  3324. this.pendingRejectionCheck = true;
  3325. setTimeout(function rejectionCheck() {
  3326. this.pendingRejectionCheck = false;
  3327. var now = Date.now();
  3328. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3329. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3330. var unhandled = this.unhandledRejections[i].promise._value;
  3331. var msg = 'Unhandled rejection: ' + unhandled;
  3332. if (unhandled.stack) {
  3333. msg += '\n' + unhandled.stack;
  3334. }
  3335. warn(msg);
  3336. this.unhandledRejections.splice(i);
  3337. i--;
  3338. }
  3339. }
  3340. if (this.unhandledRejections.length) {
  3341. this.scheduleRejectionCheck();
  3342. }
  3343. }.bind(this), REJECTION_TIMEOUT);
  3344. }
  3345. };
  3346. function Promise(resolver) {
  3347. this._status = STATUS_PENDING;
  3348. this._handlers = [];
  3349. try {
  3350. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3351. } catch (e) {
  3352. this._reject(e);
  3353. }
  3354. }
  3355. /**
  3356. * Builds a promise that is resolved when all the passed in promises are
  3357. * resolved.
  3358. * @param {array} array of data and/or promises to wait for.
  3359. * @return {Promise} New dependant promise.
  3360. */
  3361. Promise.all = function Promise_all(promises) {
  3362. var resolveAll, rejectAll;
  3363. var deferred = new Promise(function (resolve, reject) {
  3364. resolveAll = resolve;
  3365. rejectAll = reject;
  3366. });
  3367. var unresolved = promises.length;
  3368. var results = [];
  3369. if (unresolved === 0) {
  3370. resolveAll(results);
  3371. return deferred;
  3372. }
  3373. function reject(reason) {
  3374. if (deferred._status === STATUS_REJECTED) {
  3375. return;
  3376. }
  3377. results = [];
  3378. rejectAll(reason);
  3379. }
  3380. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3381. var promise = promises[i];
  3382. var resolve = (function(i) {
  3383. return function(value) {
  3384. if (deferred._status === STATUS_REJECTED) {
  3385. return;
  3386. }
  3387. results[i] = value;
  3388. unresolved--;
  3389. if (unresolved === 0) {
  3390. resolveAll(results);
  3391. }
  3392. };
  3393. })(i);
  3394. if (Promise.isPromise(promise)) {
  3395. promise.then(resolve, reject);
  3396. } else {
  3397. resolve(promise);
  3398. }
  3399. }
  3400. return deferred;
  3401. };
  3402. /**
  3403. * Checks if the value is likely a promise (has a 'then' function).
  3404. * @return {boolean} true if value is thenable
  3405. */
  3406. Promise.isPromise = function Promise_isPromise(value) {
  3407. return value && typeof value.then === 'function';
  3408. };
  3409. /**
  3410. * Creates resolved promise
  3411. * @param value resolve value
  3412. * @returns {Promise}
  3413. */
  3414. Promise.resolve = function Promise_resolve(value) {
  3415. return new Promise(function (resolve) { resolve(value); });
  3416. };
  3417. /**
  3418. * Creates rejected promise
  3419. * @param reason rejection value
  3420. * @returns {Promise}
  3421. */
  3422. Promise.reject = function Promise_reject(reason) {
  3423. return new Promise(function (resolve, reject) { reject(reason); });
  3424. };
  3425. Promise.prototype = {
  3426. _status: null,
  3427. _value: null,
  3428. _handlers: null,
  3429. _unhandledRejection: null,
  3430. _updateStatus: function Promise__updateStatus(status, value) {
  3431. if (this._status === STATUS_RESOLVED ||
  3432. this._status === STATUS_REJECTED) {
  3433. return;
  3434. }
  3435. if (status === STATUS_RESOLVED &&
  3436. Promise.isPromise(value)) {
  3437. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3438. this._updateStatus.bind(this, STATUS_REJECTED));
  3439. return;
  3440. }
  3441. this._status = status;
  3442. this._value = value;
  3443. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3444. this._unhandledRejection = true;
  3445. HandlerManager.addUnhandledRejection(this);
  3446. }
  3447. HandlerManager.scheduleHandlers(this);
  3448. },
  3449. _resolve: function Promise_resolve(value) {
  3450. this._updateStatus(STATUS_RESOLVED, value);
  3451. },
  3452. _reject: function Promise_reject(reason) {
  3453. this._updateStatus(STATUS_REJECTED, reason);
  3454. },
  3455. then: function Promise_then(onResolve, onReject) {
  3456. var nextPromise = new Promise(function (resolve, reject) {
  3457. this.resolve = resolve;
  3458. this.reject = reject;
  3459. });
  3460. this._handlers.push({
  3461. thisPromise: this,
  3462. onResolve: onResolve,
  3463. onReject: onReject,
  3464. nextPromise: nextPromise
  3465. });
  3466. HandlerManager.scheduleHandlers(this);
  3467. return nextPromise;
  3468. },
  3469. catch: function Promise_catch(onReject) {
  3470. return this.then(undefined, onReject);
  3471. }
  3472. };
  3473. globalScope.Promise = Promise;
  3474. })();
  3475. var StatTimer = (function StatTimerClosure() {
  3476. function rpad(str, pad, length) {
  3477. while (str.length < length) {
  3478. str += pad;
  3479. }
  3480. return str;
  3481. }
  3482. function StatTimer() {
  3483. this.started = Object.create(null);
  3484. this.times = [];
  3485. this.enabled = true;
  3486. }
  3487. StatTimer.prototype = {
  3488. time: function StatTimer_time(name) {
  3489. if (!this.enabled) {
  3490. return;
  3491. }
  3492. if (name in this.started) {
  3493. warn('Timer is already running for ' + name);
  3494. }
  3495. this.started[name] = Date.now();
  3496. },
  3497. timeEnd: function StatTimer_timeEnd(name) {
  3498. if (!this.enabled) {
  3499. return;
  3500. }
  3501. if (!(name in this.started)) {
  3502. warn('Timer has not been started for ' + name);
  3503. }
  3504. this.times.push({
  3505. 'name': name,
  3506. 'start': this.started[name],
  3507. 'end': Date.now()
  3508. });
  3509. // Remove timer from started so it can be called again.
  3510. delete this.started[name];
  3511. },
  3512. toString: function StatTimer_toString() {
  3513. var i, ii;
  3514. var times = this.times;
  3515. var out = '';
  3516. // Find the longest name for padding purposes.
  3517. var longest = 0;
  3518. for (i = 0, ii = times.length; i < ii; ++i) {
  3519. var name = times[i]['name'];
  3520. if (name.length > longest) {
  3521. longest = name.length;
  3522. }
  3523. }
  3524. for (i = 0, ii = times.length; i < ii; ++i) {
  3525. var span = times[i];
  3526. var duration = span.end - span.start;
  3527. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3528. }
  3529. return out;
  3530. }
  3531. };
  3532. return StatTimer;
  3533. })();
  3534. PDFJS.createBlob = function createBlob(data, contentType) {
  3535. if (typeof Blob !== 'undefined') {
  3536. return new Blob([data], { type: contentType });
  3537. }
  3538. // Blob builder is deprecated in FF14 and removed in FF18.
  3539. var bb = new MozBlobBuilder();
  3540. bb.append(data);
  3541. return bb.getBlob(contentType);
  3542. };
  3543. PDFJS.createObjectURL = (function createObjectURLClosure() {
  3544. // Blob/createObjectURL is not available, falling back to data schema.
  3545. var digits =
  3546. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3547. return function createObjectURL(data, contentType) {
  3548. if (!PDFJS.disableCreateObjectURL &&
  3549. typeof URL !== 'undefined' && URL.createObjectURL) {
  3550. var blob = PDFJS.createBlob(data, contentType);
  3551. return URL.createObjectURL(blob);
  3552. }
  3553. var buffer = 'data:' + contentType + ';base64,';
  3554. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3555. var b1 = data[i] & 0xFF;
  3556. var b2 = data[i + 1] & 0xFF;
  3557. var b3 = data[i + 2] & 0xFF;
  3558. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3559. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3560. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3561. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3562. }
  3563. return buffer;
  3564. };
  3565. })();
  3566. function MessageHandler(sourceName, targetName, comObj) {
  3567. this.sourceName = sourceName;
  3568. this.targetName = targetName;
  3569. this.comObj = comObj;
  3570. this.callbackIndex = 1;
  3571. this.postMessageTransfers = true;
  3572. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3573. var ah = this.actionHandler = Object.create(null);
  3574. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3575. var data = event.data;
  3576. if (data.targetName !== this.sourceName) {
  3577. return;
  3578. }
  3579. if (data.isReply) {
  3580. var callbackId = data.callbackId;
  3581. if (data.callbackId in callbacksCapabilities) {
  3582. var callback = callbacksCapabilities[callbackId];
  3583. delete callbacksCapabilities[callbackId];
  3584. if ('error' in data) {
  3585. callback.reject(data.error);
  3586. } else {
  3587. callback.resolve(data.data);
  3588. }
  3589. } else {
  3590. error('Cannot resolve callback ' + callbackId);
  3591. }
  3592. } else if (data.action in ah) {
  3593. var action = ah[data.action];
  3594. if (data.callbackId) {
  3595. var sourceName = this.sourceName;
  3596. var targetName = data.sourceName;
  3597. Promise.resolve().then(function () {
  3598. return action[0].call(action[1], data.data);
  3599. }).then(function (result) {
  3600. comObj.postMessage({
  3601. sourceName: sourceName,
  3602. targetName: targetName,
  3603. isReply: true,
  3604. callbackId: data.callbackId,
  3605. data: result
  3606. });
  3607. }, function (reason) {
  3608. if (reason instanceof Error) {
  3609. // Serialize error to avoid "DataCloneError"
  3610. reason = reason + '';
  3611. }
  3612. comObj.postMessage({
  3613. sourceName: sourceName,
  3614. targetName: targetName,
  3615. isReply: true,
  3616. callbackId: data.callbackId,
  3617. error: reason
  3618. });
  3619. });
  3620. } else {
  3621. action[0].call(action[1], data.data);
  3622. }
  3623. } else {
  3624. error('Unknown action from worker: ' + data.action);
  3625. }
  3626. }.bind(this);
  3627. comObj.addEventListener('message', this._onComObjOnMessage);
  3628. }
  3629. MessageHandler.prototype = {
  3630. on: function messageHandlerOn(actionName, handler, scope) {
  3631. var ah = this.actionHandler;
  3632. if (ah[actionName]) {
  3633. error('There is already an actionName called "' + actionName + '"');
  3634. }
  3635. ah[actionName] = [handler, scope];
  3636. },
  3637. /**
  3638. * Sends a message to the comObj to invoke the action with the supplied data.
  3639. * @param {String} actionName Action to call.
  3640. * @param {JSON} data JSON data to send.
  3641. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3642. */
  3643. send: function messageHandlerSend(actionName, data, transfers) {
  3644. var message = {
  3645. sourceName: this.sourceName,
  3646. targetName: this.targetName,
  3647. action: actionName,
  3648. data: data
  3649. };
  3650. this.postMessage(message, transfers);
  3651. },
  3652. /**
  3653. * Sends a message to the comObj to invoke the action with the supplied data.
  3654. * Expects that other side will callback with the response.
  3655. * @param {String} actionName Action to call.
  3656. * @param {JSON} data JSON data to send.
  3657. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3658. * @returns {Promise} Promise to be resolved with response data.
  3659. */
  3660. sendWithPromise:
  3661. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3662. var callbackId = this.callbackIndex++;
  3663. var message = {
  3664. sourceName: this.sourceName,
  3665. targetName: this.targetName,
  3666. action: actionName,
  3667. data: data,
  3668. callbackId: callbackId
  3669. };
  3670. var capability = createPromiseCapability();
  3671. this.callbacksCapabilities[callbackId] = capability;
  3672. try {
  3673. this.postMessage(message, transfers);
  3674. } catch (e) {
  3675. capability.reject(e);
  3676. }
  3677. return capability.promise;
  3678. },
  3679. /**
  3680. * Sends raw message to the comObj.
  3681. * @private
  3682. * @param message {Object} Raw message.
  3683. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3684. */
  3685. postMessage: function (message, transfers) {
  3686. if (transfers && this.postMessageTransfers) {
  3687. this.comObj.postMessage(message, transfers);
  3688. } else {
  3689. this.comObj.postMessage(message);
  3690. }
  3691. },
  3692. destroy: function () {
  3693. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3694. }
  3695. };
  3696. function loadJpegStream(id, imageUrl, objs) {
  3697. var img = new Image();
  3698. img.onload = (function loadJpegStream_onloadClosure() {
  3699. objs.resolve(id, img);
  3700. });
  3701. img.onerror = (function loadJpegStream_onerrorClosure() {
  3702. objs.resolve(id, null);
  3703. warn('Error during JPEG image loading');
  3704. });
  3705. img.src = imageUrl;
  3706. }
  3707. // Polyfill from https://github.com/Polymer/URL
  3708. /* Any copyright is dedicated to the Public Domain.
  3709. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3710. (function checkURLConstructor(scope) {
  3711. /* jshint ignore:start */
  3712. // feature detect for URL constructor
  3713. var hasWorkingUrl = false;
  3714. try {
  3715. if (typeof URL === 'function' &&
  3716. typeof URL.prototype === 'object' &&
  3717. ('origin' in URL.prototype)) {
  3718. var u = new URL('b', 'http://a');
  3719. u.pathname = 'c%20d';
  3720. hasWorkingUrl = u.href === 'http://a/c%20d';
  3721. }
  3722. } catch(e) { }
  3723. if (hasWorkingUrl)
  3724. return;
  3725. var relative = Object.create(null);
  3726. relative['ftp'] = 21;
  3727. relative['file'] = 0;
  3728. relative['gopher'] = 70;
  3729. relative['http'] = 80;
  3730. relative['https'] = 443;
  3731. relative['ws'] = 80;
  3732. relative['wss'] = 443;
  3733. var relativePathDotMapping = Object.create(null);
  3734. relativePathDotMapping['%2e'] = '.';
  3735. relativePathDotMapping['.%2e'] = '..';
  3736. relativePathDotMapping['%2e.'] = '..';
  3737. relativePathDotMapping['%2e%2e'] = '..';
  3738. function isRelativeScheme(scheme) {
  3739. return relative[scheme] !== undefined;
  3740. }
  3741. function invalid() {
  3742. clear.call(this);
  3743. this._isInvalid = true;
  3744. }
  3745. function IDNAToASCII(h) {
  3746. if ('' == h) {
  3747. invalid.call(this)
  3748. }
  3749. // XXX
  3750. return h.toLowerCase()
  3751. }
  3752. function percentEscape(c) {
  3753. var unicode = c.charCodeAt(0);
  3754. if (unicode > 0x20 &&
  3755. unicode < 0x7F &&
  3756. // " # < > ? `
  3757. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3758. ) {
  3759. return c;
  3760. }
  3761. return encodeURIComponent(c);
  3762. }
  3763. function percentEscapeQuery(c) {
  3764. // XXX This actually needs to encode c using encoding and then
  3765. // convert the bytes one-by-one.
  3766. var unicode = c.charCodeAt(0);
  3767. if (unicode > 0x20 &&
  3768. unicode < 0x7F &&
  3769. // " # < > ` (do not escape '?')
  3770. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3771. ) {
  3772. return c;
  3773. }
  3774. return encodeURIComponent(c);
  3775. }
  3776. var EOF = undefined,
  3777. ALPHA = /[a-zA-Z]/,
  3778. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3779. function parse(input, stateOverride, base) {
  3780. function err(message) {
  3781. errors.push(message)
  3782. }
  3783. var state = stateOverride || 'scheme start',
  3784. cursor = 0,
  3785. buffer = '',
  3786. seenAt = false,
  3787. seenBracket = false,
  3788. errors = [];
  3789. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3790. var c = input[cursor];
  3791. switch (state) {
  3792. case 'scheme start':
  3793. if (c && ALPHA.test(c)) {
  3794. buffer += c.toLowerCase(); // ASCII-safe
  3795. state = 'scheme';
  3796. } else if (!stateOverride) {
  3797. buffer = '';
  3798. state = 'no scheme';
  3799. continue;
  3800. } else {
  3801. err('Invalid scheme.');
  3802. break loop;
  3803. }
  3804. break;
  3805. case 'scheme':
  3806. if (c && ALPHANUMERIC.test(c)) {
  3807. buffer += c.toLowerCase(); // ASCII-safe
  3808. } else if (':' == c) {
  3809. this._scheme = buffer;
  3810. buffer = '';
  3811. if (stateOverride) {
  3812. break loop;
  3813. }
  3814. if (isRelativeScheme(this._scheme)) {
  3815. this._isRelative = true;
  3816. }
  3817. if ('file' == this._scheme) {
  3818. state = 'relative';
  3819. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3820. state = 'relative or authority';
  3821. } else if (this._isRelative) {
  3822. state = 'authority first slash';
  3823. } else {
  3824. state = 'scheme data';
  3825. }
  3826. } else if (!stateOverride) {
  3827. buffer = '';
  3828. cursor = 0;
  3829. state = 'no scheme';
  3830. continue;
  3831. } else if (EOF == c) {
  3832. break loop;
  3833. } else {
  3834. err('Code point not allowed in scheme: ' + c)
  3835. break loop;
  3836. }
  3837. break;
  3838. case 'scheme data':
  3839. if ('?' == c) {
  3840. this._query = '?';
  3841. state = 'query';
  3842. } else if ('#' == c) {
  3843. this._fragment = '#';
  3844. state = 'fragment';
  3845. } else {
  3846. // XXX error handling
  3847. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3848. this._schemeData += percentEscape(c);
  3849. }
  3850. }
  3851. break;
  3852. case 'no scheme':
  3853. if (!base || !(isRelativeScheme(base._scheme))) {
  3854. err('Missing scheme.');
  3855. invalid.call(this);
  3856. } else {
  3857. state = 'relative';
  3858. continue;
  3859. }
  3860. break;
  3861. case 'relative or authority':
  3862. if ('/' == c && '/' == input[cursor+1]) {
  3863. state = 'authority ignore slashes';
  3864. } else {
  3865. err('Expected /, got: ' + c);
  3866. state = 'relative';
  3867. continue
  3868. }
  3869. break;
  3870. case 'relative':
  3871. this._isRelative = true;
  3872. if ('file' != this._scheme)
  3873. this._scheme = base._scheme;
  3874. if (EOF == c) {
  3875. this._host = base._host;
  3876. this._port = base._port;
  3877. this._path = base._path.slice();
  3878. this._query = base._query;
  3879. this._username = base._username;
  3880. this._password = base._password;
  3881. break loop;
  3882. } else if ('/' == c || '\\' == c) {
  3883. if ('\\' == c)
  3884. err('\\ is an invalid code point.');
  3885. state = 'relative slash';
  3886. } else if ('?' == c) {
  3887. this._host = base._host;
  3888. this._port = base._port;
  3889. this._path = base._path.slice();
  3890. this._query = '?';
  3891. this._username = base._username;
  3892. this._password = base._password;
  3893. state = 'query';
  3894. } else if ('#' == c) {
  3895. this._host = base._host;
  3896. this._port = base._port;
  3897. this._path = base._path.slice();
  3898. this._query = base._query;
  3899. this._fragment = '#';
  3900. this._username = base._username;
  3901. this._password = base._password;
  3902. state = 'fragment';
  3903. } else {
  3904. var nextC = input[cursor+1]
  3905. var nextNextC = input[cursor+2]
  3906. if (
  3907. 'file' != this._scheme || !ALPHA.test(c) ||
  3908. (nextC != ':' && nextC != '|') ||
  3909. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3910. this._host = base._host;
  3911. this._port = base._port;
  3912. this._username = base._username;
  3913. this._password = base._password;
  3914. this._path = base._path.slice();
  3915. this._path.pop();
  3916. }
  3917. state = 'relative path';
  3918. continue;
  3919. }
  3920. break;
  3921. case 'relative slash':
  3922. if ('/' == c || '\\' == c) {
  3923. if ('\\' == c) {
  3924. err('\\ is an invalid code point.');
  3925. }
  3926. if ('file' == this._scheme) {
  3927. state = 'file host';
  3928. } else {
  3929. state = 'authority ignore slashes';
  3930. }
  3931. } else {
  3932. if ('file' != this._scheme) {
  3933. this._host = base._host;
  3934. this._port = base._port;
  3935. this._username = base._username;
  3936. this._password = base._password;
  3937. }
  3938. state = 'relative path';
  3939. continue;
  3940. }
  3941. break;
  3942. case 'authority first slash':
  3943. if ('/' == c) {
  3944. state = 'authority second slash';
  3945. } else {
  3946. err("Expected '/', got: " + c);
  3947. state = 'authority ignore slashes';
  3948. continue;
  3949. }
  3950. break;
  3951. case 'authority second slash':
  3952. state = 'authority ignore slashes';
  3953. if ('/' != c) {
  3954. err("Expected '/', got: " + c);
  3955. continue;
  3956. }
  3957. break;
  3958. case 'authority ignore slashes':
  3959. if ('/' != c && '\\' != c) {
  3960. state = 'authority';
  3961. continue;
  3962. } else {
  3963. err('Expected authority, got: ' + c);
  3964. }
  3965. break;
  3966. case 'authority':
  3967. if ('@' == c) {
  3968. if (seenAt) {
  3969. err('@ already seen.');
  3970. buffer += '%40';
  3971. }
  3972. seenAt = true;
  3973. for (var i = 0; i < buffer.length; i++) {
  3974. var cp = buffer[i];
  3975. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3976. err('Invalid whitespace in authority.');
  3977. continue;
  3978. }
  3979. // XXX check URL code points
  3980. if (':' == cp && null === this._password) {
  3981. this._password = '';
  3982. continue;
  3983. }
  3984. var tempC = percentEscape(cp);
  3985. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3986. }
  3987. buffer = '';
  3988. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3989. cursor -= buffer.length;
  3990. buffer = '';
  3991. state = 'host';
  3992. continue;
  3993. } else {
  3994. buffer += c;
  3995. }
  3996. break;
  3997. case 'file host':
  3998. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3999. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  4000. state = 'relative path';
  4001. } else if (buffer.length == 0) {
  4002. state = 'relative path start';
  4003. } else {
  4004. this._host = IDNAToASCII.call(this, buffer);
  4005. buffer = '';
  4006. state = 'relative path start';
  4007. }
  4008. continue;
  4009. } else if ('\t' == c || '\n' == c || '\r' == c) {
  4010. err('Invalid whitespace in file host.');
  4011. } else {
  4012. buffer += c;
  4013. }
  4014. break;
  4015. case 'host':
  4016. case 'hostname':
  4017. if (':' == c && !seenBracket) {
  4018. // XXX host parsing
  4019. this._host = IDNAToASCII.call(this, buffer);
  4020. buffer = '';
  4021. state = 'port';
  4022. if ('hostname' == stateOverride) {
  4023. break loop;
  4024. }
  4025. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  4026. this._host = IDNAToASCII.call(this, buffer);
  4027. buffer = '';
  4028. state = 'relative path start';
  4029. if (stateOverride) {
  4030. break loop;
  4031. }
  4032. continue;
  4033. } else if ('\t' != c && '\n' != c && '\r' != c) {
  4034. if ('[' == c) {
  4035. seenBracket = true;
  4036. } else if (']' == c) {
  4037. seenBracket = false;
  4038. }
  4039. buffer += c;
  4040. } else {
  4041. err('Invalid code point in host/hostname: ' + c);
  4042. }
  4043. break;
  4044. case 'port':
  4045. if (/[0-9]/.test(c)) {
  4046. buffer += c;
  4047. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  4048. if ('' != buffer) {
  4049. var temp = parseInt(buffer, 10);
  4050. if (temp != relative[this._scheme]) {
  4051. this._port = temp + '';
  4052. }
  4053. buffer = '';
  4054. }
  4055. if (stateOverride) {
  4056. break loop;
  4057. }
  4058. state = 'relative path start';
  4059. continue;
  4060. } else if ('\t' == c || '\n' == c || '\r' == c) {
  4061. err('Invalid code point in port: ' + c);
  4062. } else {
  4063. invalid.call(this);
  4064. }
  4065. break;
  4066. case 'relative path start':
  4067. if ('\\' == c)
  4068. err("'\\' not allowed in path.");
  4069. state = 'relative path';
  4070. if ('/' != c && '\\' != c) {
  4071. continue;
  4072. }
  4073. break;
  4074. case 'relative path':
  4075. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  4076. if ('\\' == c) {
  4077. err('\\ not allowed in relative path.');
  4078. }
  4079. var tmp;
  4080. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  4081. buffer = tmp;
  4082. }
  4083. if ('..' == buffer) {
  4084. this._path.pop();
  4085. if ('/' != c && '\\' != c) {
  4086. this._path.push('');
  4087. }
  4088. } else if ('.' == buffer && '/' != c && '\\' != c) {
  4089. this._path.push('');
  4090. } else if ('.' != buffer) {
  4091. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  4092. buffer = buffer[0] + ':';
  4093. }
  4094. this._path.push(buffer);
  4095. }
  4096. buffer = '';
  4097. if ('?' == c) {
  4098. this._query = '?';
  4099. state = 'query';
  4100. } else if ('#' == c) {
  4101. this._fragment = '#';
  4102. state = 'fragment';
  4103. }
  4104. } else if ('\t' != c && '\n' != c && '\r' != c) {
  4105. buffer += percentEscape(c);
  4106. }
  4107. break;
  4108. case 'query':
  4109. if (!stateOverride && '#' == c) {
  4110. this._fragment = '#';
  4111. state = 'fragment';
  4112. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  4113. this._query += percentEscapeQuery(c);
  4114. }
  4115. break;
  4116. case 'fragment':
  4117. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  4118. this._fragment += c;
  4119. }
  4120. break;
  4121. }
  4122. cursor++;
  4123. }
  4124. }
  4125. function clear() {
  4126. this._scheme = '';
  4127. this._schemeData = '';
  4128. this._username = '';
  4129. this._password = null;
  4130. this._host = '';
  4131. this._port = '';
  4132. this._path = [];
  4133. this._query = '';
  4134. this._fragment = '';
  4135. this._isInvalid = false;
  4136. this._isRelative = false;
  4137. }
  4138. // Does not process domain names or IP addresses.
  4139. // Does not handle encoding for the query parameter.
  4140. function jURL(url, base /* , encoding */) {
  4141. if (base !== undefined && !(base instanceof jURL))
  4142. base = new jURL(String(base));
  4143. this._url = url;
  4144. clear.call(this);
  4145. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  4146. // encoding = encoding || 'utf-8'
  4147. parse.call(this, input, null, base);
  4148. }
  4149. jURL.prototype = {
  4150. toString: function() {
  4151. return this.href;
  4152. },
  4153. get href() {
  4154. if (this._isInvalid)
  4155. return this._url;
  4156. var authority = '';
  4157. if ('' != this._username || null != this._password) {
  4158. authority = this._username +
  4159. (null != this._password ? ':' + this._password : '') + '@';
  4160. }
  4161. return this.protocol +
  4162. (this._isRelative ? '//' + authority + this.host : '') +
  4163. this.pathname + this._query + this._fragment;
  4164. },
  4165. set href(href) {
  4166. clear.call(this);
  4167. parse.call(this, href);
  4168. },
  4169. get protocol() {
  4170. return this._scheme + ':';
  4171. },
  4172. set protocol(protocol) {
  4173. if (this._isInvalid)
  4174. return;
  4175. parse.call(this, protocol + ':', 'scheme start');
  4176. },
  4177. get host() {
  4178. return this._isInvalid ? '' : this._port ?
  4179. this._host + ':' + this._port : this._host;
  4180. },
  4181. set host(host) {
  4182. if (this._isInvalid || !this._isRelative)
  4183. return;
  4184. parse.call(this, host, 'host');
  4185. },
  4186. get hostname() {
  4187. return this._host;
  4188. },
  4189. set hostname(hostname) {
  4190. if (this._isInvalid || !this._isRelative)
  4191. return;
  4192. parse.call(this, hostname, 'hostname');
  4193. },
  4194. get port() {
  4195. return this._port;
  4196. },
  4197. set port(port) {
  4198. if (this._isInvalid || !this._isRelative)
  4199. return;
  4200. parse.call(this, port, 'port');
  4201. },
  4202. get pathname() {
  4203. return this._isInvalid ? '' : this._isRelative ?
  4204. '/' + this._path.join('/') : this._schemeData;
  4205. },
  4206. set pathname(pathname) {
  4207. if (this._isInvalid || !this._isRelative)
  4208. return;
  4209. this._path = [];
  4210. parse.call(this, pathname, 'relative path start');
  4211. },
  4212. get search() {
  4213. return this._isInvalid || !this._query || '?' == this._query ?
  4214. '' : this._query;
  4215. },
  4216. set search(search) {
  4217. if (this._isInvalid || !this._isRelative)
  4218. return;
  4219. this._query = '?';
  4220. if ('?' == search[0])
  4221. search = search.slice(1);
  4222. parse.call(this, search, 'query');
  4223. },
  4224. get hash() {
  4225. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  4226. '' : this._fragment;
  4227. },
  4228. set hash(hash) {
  4229. if (this._isInvalid)
  4230. return;
  4231. this._fragment = '#';
  4232. if ('#' == hash[0])
  4233. hash = hash.slice(1);
  4234. parse.call(this, hash, 'fragment');
  4235. },
  4236. get origin() {
  4237. var host;
  4238. if (this._isInvalid || !this._scheme) {
  4239. return '';
  4240. }
  4241. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  4242. // Gecko throws error for "data://"
  4243. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  4244. // Gecko returns String("") for file: mailto:
  4245. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  4246. switch (this._scheme) {
  4247. case 'data':
  4248. case 'file':
  4249. case 'javascript':
  4250. case 'mailto':
  4251. return 'null';
  4252. }
  4253. host = this.host;
  4254. if (!host) {
  4255. return '';
  4256. }
  4257. return this._scheme + '://' + host;
  4258. }
  4259. };
  4260. // Copy over the static methods
  4261. var OriginalURL = scope.URL;
  4262. if (OriginalURL) {
  4263. jURL.createObjectURL = function(blob) {
  4264. // IE extension allows a second optional options argument.
  4265. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  4266. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  4267. };
  4268. jURL.revokeObjectURL = function(url) {
  4269. OriginalURL.revokeObjectURL(url);
  4270. };
  4271. }
  4272. scope.URL = jURL;
  4273. /* jshint ignore:end */
  4274. })(globalScope);
  4275. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  4276. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  4277. exports.OPS = OPS;
  4278. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  4279. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  4280. exports.AnnotationFlag = AnnotationFlag;
  4281. exports.AnnotationType = AnnotationType;
  4282. exports.FontType = FontType;
  4283. exports.ImageKind = ImageKind;
  4284. exports.InvalidPDFException = InvalidPDFException;
  4285. exports.LinkTarget = LinkTarget;
  4286. exports.LinkTargetStringMap = LinkTargetStringMap;
  4287. exports.MessageHandler = MessageHandler;
  4288. exports.MissingDataException = MissingDataException;
  4289. exports.MissingPDFException = MissingPDFException;
  4290. exports.NotImplementedException = NotImplementedException;
  4291. exports.PasswordException = PasswordException;
  4292. exports.PasswordResponses = PasswordResponses;
  4293. exports.StatTimer = StatTimer;
  4294. exports.StreamType = StreamType;
  4295. exports.TextRenderingMode = TextRenderingMode;
  4296. exports.UnexpectedResponseException = UnexpectedResponseException;
  4297. exports.UnknownErrorException = UnknownErrorException;
  4298. exports.Util = Util;
  4299. exports.XRefParseException = XRefParseException;
  4300. exports.assert = assert;
  4301. exports.bytesToString = bytesToString;
  4302. exports.combineUrl = combineUrl;
  4303. exports.createPromiseCapability = createPromiseCapability;
  4304. exports.deprecated = deprecated;
  4305. exports.error = error;
  4306. exports.getLookupTableFactory = getLookupTableFactory;
  4307. exports.info = info;
  4308. exports.isArray = isArray;
  4309. exports.isArrayBuffer = isArrayBuffer;
  4310. exports.isBool = isBool;
  4311. exports.isEmptyObj = isEmptyObj;
  4312. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  4313. exports.isInt = isInt;
  4314. exports.isNum = isNum;
  4315. exports.isString = isString;
  4316. exports.isSameOrigin = isSameOrigin;
  4317. exports.isValidUrl = isValidUrl;
  4318. exports.addLinkAttributes = addLinkAttributes;
  4319. exports.loadJpegStream = loadJpegStream;
  4320. exports.log2 = log2;
  4321. exports.readInt8 = readInt8;
  4322. exports.readUint16 = readUint16;
  4323. exports.readUint32 = readUint32;
  4324. exports.removeNullCharacters = removeNullCharacters;
  4325. exports.shadow = shadow;
  4326. exports.string32 = string32;
  4327. exports.stringToBytes = stringToBytes;
  4328. exports.stringToPDFString = stringToPDFString;
  4329. exports.stringToUTF8String = stringToUTF8String;
  4330. exports.utf8StringToString = utf8StringToString;
  4331. exports.warn = warn;
  4332. }));
  4333. (function (root, factory) {
  4334. {
  4335. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  4336. }
  4337. }(this, function (exports, sharedUtil) {
  4338. var MissingDataException = sharedUtil.MissingDataException;
  4339. var assert = sharedUtil.assert;
  4340. var createPromiseCapability = sharedUtil.createPromiseCapability;
  4341. var isInt = sharedUtil.isInt;
  4342. var isEmptyObj = sharedUtil.isEmptyObj;
  4343. var ChunkedStream = (function ChunkedStreamClosure() {
  4344. function ChunkedStream(length, chunkSize, manager) {
  4345. this.bytes = new Uint8Array(length);
  4346. this.start = 0;
  4347. this.pos = 0;
  4348. this.end = length;
  4349. this.chunkSize = chunkSize;
  4350. this.loadedChunks = [];
  4351. this.numChunksLoaded = 0;
  4352. this.numChunks = Math.ceil(length / chunkSize);
  4353. this.manager = manager;
  4354. this.progressiveDataLength = 0;
  4355. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  4356. }
  4357. // required methods for a stream. if a particular stream does not
  4358. // implement these, an error should be thrown
  4359. ChunkedStream.prototype = {
  4360. getMissingChunks: function ChunkedStream_getMissingChunks() {
  4361. var chunks = [];
  4362. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  4363. if (!this.loadedChunks[chunk]) {
  4364. chunks.push(chunk);
  4365. }
  4366. }
  4367. return chunks;
  4368. },
  4369. getBaseStreams: function ChunkedStream_getBaseStreams() {
  4370. return [this];
  4371. },
  4372. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  4373. return this.numChunksLoaded === this.numChunks;
  4374. },
  4375. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  4376. var end = begin + chunk.byteLength;
  4377. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  4378. // Using this.length is inaccurate here since this.start can be moved
  4379. // See ChunkedStream.moveStart()
  4380. var length = this.bytes.length;
  4381. assert(end % this.chunkSize === 0 || end === length,
  4382. 'Bad end offset: ' + end);
  4383. this.bytes.set(new Uint8Array(chunk), begin);
  4384. var chunkSize = this.chunkSize;
  4385. var beginChunk = Math.floor(begin / chunkSize);
  4386. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4387. var curChunk;
  4388. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4389. if (!this.loadedChunks[curChunk]) {
  4390. this.loadedChunks[curChunk] = true;
  4391. ++this.numChunksLoaded;
  4392. }
  4393. }
  4394. },
  4395. onReceiveProgressiveData:
  4396. function ChunkedStream_onReceiveProgressiveData(data) {
  4397. var position = this.progressiveDataLength;
  4398. var beginChunk = Math.floor(position / this.chunkSize);
  4399. this.bytes.set(new Uint8Array(data), position);
  4400. position += data.byteLength;
  4401. this.progressiveDataLength = position;
  4402. var endChunk = position >= this.end ? this.numChunks :
  4403. Math.floor(position / this.chunkSize);
  4404. var curChunk;
  4405. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  4406. if (!this.loadedChunks[curChunk]) {
  4407. this.loadedChunks[curChunk] = true;
  4408. ++this.numChunksLoaded;
  4409. }
  4410. }
  4411. },
  4412. ensureByte: function ChunkedStream_ensureByte(pos) {
  4413. var chunk = Math.floor(pos / this.chunkSize);
  4414. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  4415. return;
  4416. }
  4417. if (!this.loadedChunks[chunk]) {
  4418. throw new MissingDataException(pos, pos + 1);
  4419. }
  4420. this.lastSuccessfulEnsureByteChunk = chunk;
  4421. },
  4422. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  4423. if (begin >= end) {
  4424. return;
  4425. }
  4426. if (end <= this.progressiveDataLength) {
  4427. return;
  4428. }
  4429. var chunkSize = this.chunkSize;
  4430. var beginChunk = Math.floor(begin / chunkSize);
  4431. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  4432. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4433. if (!this.loadedChunks[chunk]) {
  4434. throw new MissingDataException(begin, end);
  4435. }
  4436. }
  4437. },
  4438. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  4439. var chunk, numChunks = this.numChunks;
  4440. for (var i = 0; i < numChunks; ++i) {
  4441. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  4442. if (!this.loadedChunks[chunk]) {
  4443. return chunk;
  4444. }
  4445. }
  4446. return null;
  4447. },
  4448. hasChunk: function ChunkedStream_hasChunk(chunk) {
  4449. return !!this.loadedChunks[chunk];
  4450. },
  4451. get length() {
  4452. return this.end - this.start;
  4453. },
  4454. get isEmpty() {
  4455. return this.length === 0;
  4456. },
  4457. getByte: function ChunkedStream_getByte() {
  4458. var pos = this.pos;
  4459. if (pos >= this.end) {
  4460. return -1;
  4461. }
  4462. this.ensureByte(pos);
  4463. return this.bytes[this.pos++];
  4464. },
  4465. getUint16: function ChunkedStream_getUint16() {
  4466. var b0 = this.getByte();
  4467. var b1 = this.getByte();
  4468. if (b0 === -1 || b1 === -1) {
  4469. return -1;
  4470. }
  4471. return (b0 << 8) + b1;
  4472. },
  4473. getInt32: function ChunkedStream_getInt32() {
  4474. var b0 = this.getByte();
  4475. var b1 = this.getByte();
  4476. var b2 = this.getByte();
  4477. var b3 = this.getByte();
  4478. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  4479. },
  4480. // returns subarray of original buffer
  4481. // should only be read
  4482. getBytes: function ChunkedStream_getBytes(length) {
  4483. var bytes = this.bytes;
  4484. var pos = this.pos;
  4485. var strEnd = this.end;
  4486. if (!length) {
  4487. this.ensureRange(pos, strEnd);
  4488. return bytes.subarray(pos, strEnd);
  4489. }
  4490. var end = pos + length;
  4491. if (end > strEnd) {
  4492. end = strEnd;
  4493. }
  4494. this.ensureRange(pos, end);
  4495. this.pos = end;
  4496. return bytes.subarray(pos, end);
  4497. },
  4498. peekByte: function ChunkedStream_peekByte() {
  4499. var peekedByte = this.getByte();
  4500. this.pos--;
  4501. return peekedByte;
  4502. },
  4503. peekBytes: function ChunkedStream_peekBytes(length) {
  4504. var bytes = this.getBytes(length);
  4505. this.pos -= bytes.length;
  4506. return bytes;
  4507. },
  4508. getByteRange: function ChunkedStream_getBytes(begin, end) {
  4509. this.ensureRange(begin, end);
  4510. return this.bytes.subarray(begin, end);
  4511. },
  4512. skip: function ChunkedStream_skip(n) {
  4513. if (!n) {
  4514. n = 1;
  4515. }
  4516. this.pos += n;
  4517. },
  4518. reset: function ChunkedStream_reset() {
  4519. this.pos = this.start;
  4520. },
  4521. moveStart: function ChunkedStream_moveStart() {
  4522. this.start = this.pos;
  4523. },
  4524. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  4525. this.ensureRange(start, start + length);
  4526. function ChunkedStreamSubstream() {}
  4527. ChunkedStreamSubstream.prototype = Object.create(this);
  4528. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  4529. var chunkSize = this.chunkSize;
  4530. var beginChunk = Math.floor(this.start / chunkSize);
  4531. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  4532. var missingChunks = [];
  4533. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4534. if (!this.loadedChunks[chunk]) {
  4535. missingChunks.push(chunk);
  4536. }
  4537. }
  4538. return missingChunks;
  4539. };
  4540. var subStream = new ChunkedStreamSubstream();
  4541. subStream.pos = subStream.start = start;
  4542. subStream.end = start + length || this.end;
  4543. subStream.dict = dict;
  4544. return subStream;
  4545. },
  4546. isStream: true
  4547. };
  4548. return ChunkedStream;
  4549. })();
  4550. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  4551. function ChunkedStreamManager(length, chunkSize, url, args) {
  4552. this.stream = new ChunkedStream(length, chunkSize, this);
  4553. this.length = length;
  4554. this.chunkSize = chunkSize;
  4555. this.url = url;
  4556. this.disableAutoFetch = args.disableAutoFetch;
  4557. var msgHandler = this.msgHandler = args.msgHandler;
  4558. if (args.chunkedViewerLoading) {
  4559. msgHandler.on('OnDataRange', this.onReceiveData.bind(this));
  4560. msgHandler.on('OnDataProgress', this.onProgress.bind(this));
  4561. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  4562. msgHandler.send('RequestDataRange', { begin: begin, end: end });
  4563. };
  4564. } else {
  4565. var getXhr = function getXhr() {
  4566. return new XMLHttpRequest();
  4567. };
  4568. this.networkManager = new NetworkManager(this.url, {
  4569. getXhr: getXhr,
  4570. httpHeaders: args.httpHeaders,
  4571. withCredentials: args.withCredentials
  4572. });
  4573. this.sendRequest = function ChunkedStreamManager_sendRequest(begin, end) {
  4574. this.networkManager.requestRange(begin, end, {
  4575. onDone: this.onReceiveData.bind(this),
  4576. onProgress: this.onProgress.bind(this)
  4577. });
  4578. };
  4579. }
  4580. this.currRequestId = 0;
  4581. this.chunksNeededByRequest = Object.create(null);
  4582. this.requestsByChunk = Object.create(null);
  4583. this.promisesByRequest = Object.create(null);
  4584. this.progressiveDataLength = 0;
  4585. this._loadedStreamCapability = createPromiseCapability();
  4586. if (args.initialData) {
  4587. this.onReceiveData({chunk: args.initialData});
  4588. }
  4589. }
  4590. ChunkedStreamManager.prototype = {
  4591. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  4592. return this._loadedStreamCapability.promise;
  4593. },
  4594. // Get all the chunks that are not yet loaded and groups them into
  4595. // contiguous ranges to load in as few requests as possible
  4596. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  4597. var missingChunks = this.stream.getMissingChunks();
  4598. this._requestChunks(missingChunks);
  4599. return this._loadedStreamCapability.promise;
  4600. },
  4601. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  4602. var requestId = this.currRequestId++;
  4603. var i, ii;
  4604. var chunksNeeded = Object.create(null);
  4605. this.chunksNeededByRequest[requestId] = chunksNeeded;
  4606. for (i = 0, ii = chunks.length; i < ii; i++) {
  4607. if (!this.stream.hasChunk(chunks[i])) {
  4608. chunksNeeded[chunks[i]] = true;
  4609. }
  4610. }
  4611. if (isEmptyObj(chunksNeeded)) {
  4612. return Promise.resolve();
  4613. }
  4614. var capability = createPromiseCapability();
  4615. this.promisesByRequest[requestId] = capability;
  4616. var chunksToRequest = [];
  4617. for (var chunk in chunksNeeded) {
  4618. chunk = chunk | 0;
  4619. if (!(chunk in this.requestsByChunk)) {
  4620. this.requestsByChunk[chunk] = [];
  4621. chunksToRequest.push(chunk);
  4622. }
  4623. this.requestsByChunk[chunk].push(requestId);
  4624. }
  4625. if (!chunksToRequest.length) {
  4626. return capability.promise;
  4627. }
  4628. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  4629. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  4630. var groupedChunk = groupedChunksToRequest[i];
  4631. var begin = groupedChunk.beginChunk * this.chunkSize;
  4632. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  4633. this.sendRequest(begin, end);
  4634. }
  4635. return capability.promise;
  4636. },
  4637. getStream: function ChunkedStreamManager_getStream() {
  4638. return this.stream;
  4639. },
  4640. // Loads any chunks in the requested range that are not yet loaded
  4641. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  4642. end = Math.min(end, this.length);
  4643. var beginChunk = this.getBeginChunk(begin);
  4644. var endChunk = this.getEndChunk(end);
  4645. var chunks = [];
  4646. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4647. chunks.push(chunk);
  4648. }
  4649. return this._requestChunks(chunks);
  4650. },
  4651. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  4652. ranges = ranges || [];
  4653. var chunksToRequest = [];
  4654. for (var i = 0; i < ranges.length; i++) {
  4655. var beginChunk = this.getBeginChunk(ranges[i].begin);
  4656. var endChunk = this.getEndChunk(ranges[i].end);
  4657. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  4658. if (chunksToRequest.indexOf(chunk) < 0) {
  4659. chunksToRequest.push(chunk);
  4660. }
  4661. }
  4662. }
  4663. chunksToRequest.sort(function(a, b) { return a - b; });
  4664. return this._requestChunks(chunksToRequest);
  4665. },
  4666. // Groups a sorted array of chunks into as few contiguous larger
  4667. // chunks as possible
  4668. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  4669. var groupedChunks = [];
  4670. var beginChunk = -1;
  4671. var prevChunk = -1;
  4672. for (var i = 0; i < chunks.length; ++i) {
  4673. var chunk = chunks[i];
  4674. if (beginChunk < 0) {
  4675. beginChunk = chunk;
  4676. }
  4677. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  4678. groupedChunks.push({ beginChunk: beginChunk,
  4679. endChunk: prevChunk + 1 });
  4680. beginChunk = chunk;
  4681. }
  4682. if (i + 1 === chunks.length) {
  4683. groupedChunks.push({ beginChunk: beginChunk,
  4684. endChunk: chunk + 1 });
  4685. }
  4686. prevChunk = chunk;
  4687. }
  4688. return groupedChunks;
  4689. },
  4690. onProgress: function ChunkedStreamManager_onProgress(args) {
  4691. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  4692. args.loaded);
  4693. this.msgHandler.send('DocProgress', {
  4694. loaded: bytesLoaded,
  4695. total: this.length
  4696. });
  4697. },
  4698. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  4699. var chunk = args.chunk;
  4700. var isProgressive = args.begin === undefined;
  4701. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  4702. var end = begin + chunk.byteLength;
  4703. var beginChunk = Math.floor(begin / this.chunkSize);
  4704. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  4705. Math.ceil(end / this.chunkSize);
  4706. if (isProgressive) {
  4707. this.stream.onReceiveProgressiveData(chunk);
  4708. this.progressiveDataLength = end;
  4709. } else {
  4710. this.stream.onReceiveData(begin, chunk);
  4711. }
  4712. if (this.stream.allChunksLoaded()) {
  4713. this._loadedStreamCapability.resolve(this.stream);
  4714. }
  4715. var loadedRequests = [];
  4716. var i, requestId;
  4717. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  4718. // The server might return more chunks than requested
  4719. var requestIds = this.requestsByChunk[chunk] || [];
  4720. delete this.requestsByChunk[chunk];
  4721. for (i = 0; i < requestIds.length; ++i) {
  4722. requestId = requestIds[i];
  4723. var chunksNeeded = this.chunksNeededByRequest[requestId];
  4724. if (chunk in chunksNeeded) {
  4725. delete chunksNeeded[chunk];
  4726. }
  4727. if (!isEmptyObj(chunksNeeded)) {
  4728. continue;
  4729. }
  4730. loadedRequests.push(requestId);
  4731. }
  4732. }
  4733. // If there are no pending requests, automatically fetch the next
  4734. // unfetched chunk of the PDF
  4735. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  4736. var nextEmptyChunk;
  4737. if (this.stream.numChunksLoaded === 1) {
  4738. // This is a special optimization so that after fetching the first
  4739. // chunk, rather than fetching the second chunk, we fetch the last
  4740. // chunk.
  4741. var lastChunk = this.stream.numChunks - 1;
  4742. if (!this.stream.hasChunk(lastChunk)) {
  4743. nextEmptyChunk = lastChunk;
  4744. }
  4745. } else {
  4746. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  4747. }
  4748. if (isInt(nextEmptyChunk)) {
  4749. this._requestChunks([nextEmptyChunk]);
  4750. }
  4751. }
  4752. for (i = 0; i < loadedRequests.length; ++i) {
  4753. requestId = loadedRequests[i];
  4754. var capability = this.promisesByRequest[requestId];
  4755. delete this.promisesByRequest[requestId];
  4756. capability.resolve();
  4757. }
  4758. this.msgHandler.send('DocProgress', {
  4759. loaded: this.stream.numChunksLoaded * this.chunkSize,
  4760. total: this.length
  4761. });
  4762. },
  4763. onError: function ChunkedStreamManager_onError(err) {
  4764. this._loadedStreamCapability.reject(err);
  4765. },
  4766. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  4767. var chunk = Math.floor(begin / this.chunkSize);
  4768. return chunk;
  4769. },
  4770. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  4771. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  4772. return chunk;
  4773. },
  4774. abort: function ChunkedStreamManager_abort() {
  4775. if (this.networkManager) {
  4776. this.networkManager.abortAllRequests();
  4777. }
  4778. for(var requestId in this.promisesByRequest) {
  4779. var capability = this.promisesByRequest[requestId];
  4780. capability.reject(new Error('Request was aborted'));
  4781. }
  4782. }
  4783. };
  4784. return ChunkedStreamManager;
  4785. })();
  4786. exports.ChunkedStream = ChunkedStream;
  4787. exports.ChunkedStreamManager = ChunkedStreamManager;
  4788. }));
  4789. (function (root, factory) {
  4790. {
  4791. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  4792. }
  4793. }(this, function (exports, sharedUtil) {
  4794. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  4795. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  4796. t['A'] = 0x0041;
  4797. t['AE'] = 0x00C6;
  4798. t['AEacute'] = 0x01FC;
  4799. t['AEmacron'] = 0x01E2;
  4800. t['AEsmall'] = 0xF7E6;
  4801. t['Aacute'] = 0x00C1;
  4802. t['Aacutesmall'] = 0xF7E1;
  4803. t['Abreve'] = 0x0102;
  4804. t['Abreveacute'] = 0x1EAE;
  4805. t['Abrevecyrillic'] = 0x04D0;
  4806. t['Abrevedotbelow'] = 0x1EB6;
  4807. t['Abrevegrave'] = 0x1EB0;
  4808. t['Abrevehookabove'] = 0x1EB2;
  4809. t['Abrevetilde'] = 0x1EB4;
  4810. t['Acaron'] = 0x01CD;
  4811. t['Acircle'] = 0x24B6;
  4812. t['Acircumflex'] = 0x00C2;
  4813. t['Acircumflexacute'] = 0x1EA4;
  4814. t['Acircumflexdotbelow'] = 0x1EAC;
  4815. t['Acircumflexgrave'] = 0x1EA6;
  4816. t['Acircumflexhookabove'] = 0x1EA8;
  4817. t['Acircumflexsmall'] = 0xF7E2;
  4818. t['Acircumflextilde'] = 0x1EAA;
  4819. t['Acute'] = 0xF6C9;
  4820. t['Acutesmall'] = 0xF7B4;
  4821. t['Acyrillic'] = 0x0410;
  4822. t['Adblgrave'] = 0x0200;
  4823. t['Adieresis'] = 0x00C4;
  4824. t['Adieresiscyrillic'] = 0x04D2;
  4825. t['Adieresismacron'] = 0x01DE;
  4826. t['Adieresissmall'] = 0xF7E4;
  4827. t['Adotbelow'] = 0x1EA0;
  4828. t['Adotmacron'] = 0x01E0;
  4829. t['Agrave'] = 0x00C0;
  4830. t['Agravesmall'] = 0xF7E0;
  4831. t['Ahookabove'] = 0x1EA2;
  4832. t['Aiecyrillic'] = 0x04D4;
  4833. t['Ainvertedbreve'] = 0x0202;
  4834. t['Alpha'] = 0x0391;
  4835. t['Alphatonos'] = 0x0386;
  4836. t['Amacron'] = 0x0100;
  4837. t['Amonospace'] = 0xFF21;
  4838. t['Aogonek'] = 0x0104;
  4839. t['Aring'] = 0x00C5;
  4840. t['Aringacute'] = 0x01FA;
  4841. t['Aringbelow'] = 0x1E00;
  4842. t['Aringsmall'] = 0xF7E5;
  4843. t['Asmall'] = 0xF761;
  4844. t['Atilde'] = 0x00C3;
  4845. t['Atildesmall'] = 0xF7E3;
  4846. t['Aybarmenian'] = 0x0531;
  4847. t['B'] = 0x0042;
  4848. t['Bcircle'] = 0x24B7;
  4849. t['Bdotaccent'] = 0x1E02;
  4850. t['Bdotbelow'] = 0x1E04;
  4851. t['Becyrillic'] = 0x0411;
  4852. t['Benarmenian'] = 0x0532;
  4853. t['Beta'] = 0x0392;
  4854. t['Bhook'] = 0x0181;
  4855. t['Blinebelow'] = 0x1E06;
  4856. t['Bmonospace'] = 0xFF22;
  4857. t['Brevesmall'] = 0xF6F4;
  4858. t['Bsmall'] = 0xF762;
  4859. t['Btopbar'] = 0x0182;
  4860. t['C'] = 0x0043;
  4861. t['Caarmenian'] = 0x053E;
  4862. t['Cacute'] = 0x0106;
  4863. t['Caron'] = 0xF6CA;
  4864. t['Caronsmall'] = 0xF6F5;
  4865. t['Ccaron'] = 0x010C;
  4866. t['Ccedilla'] = 0x00C7;
  4867. t['Ccedillaacute'] = 0x1E08;
  4868. t['Ccedillasmall'] = 0xF7E7;
  4869. t['Ccircle'] = 0x24B8;
  4870. t['Ccircumflex'] = 0x0108;
  4871. t['Cdot'] = 0x010A;
  4872. t['Cdotaccent'] = 0x010A;
  4873. t['Cedillasmall'] = 0xF7B8;
  4874. t['Chaarmenian'] = 0x0549;
  4875. t['Cheabkhasiancyrillic'] = 0x04BC;
  4876. t['Checyrillic'] = 0x0427;
  4877. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  4878. t['Chedescendercyrillic'] = 0x04B6;
  4879. t['Chedieresiscyrillic'] = 0x04F4;
  4880. t['Cheharmenian'] = 0x0543;
  4881. t['Chekhakassiancyrillic'] = 0x04CB;
  4882. t['Cheverticalstrokecyrillic'] = 0x04B8;
  4883. t['Chi'] = 0x03A7;
  4884. t['Chook'] = 0x0187;
  4885. t['Circumflexsmall'] = 0xF6F6;
  4886. t['Cmonospace'] = 0xFF23;
  4887. t['Coarmenian'] = 0x0551;
  4888. t['Csmall'] = 0xF763;
  4889. t['D'] = 0x0044;
  4890. t['DZ'] = 0x01F1;
  4891. t['DZcaron'] = 0x01C4;
  4892. t['Daarmenian'] = 0x0534;
  4893. t['Dafrican'] = 0x0189;
  4894. t['Dcaron'] = 0x010E;
  4895. t['Dcedilla'] = 0x1E10;
  4896. t['Dcircle'] = 0x24B9;
  4897. t['Dcircumflexbelow'] = 0x1E12;
  4898. t['Dcroat'] = 0x0110;
  4899. t['Ddotaccent'] = 0x1E0A;
  4900. t['Ddotbelow'] = 0x1E0C;
  4901. t['Decyrillic'] = 0x0414;
  4902. t['Deicoptic'] = 0x03EE;
  4903. t['Delta'] = 0x2206;
  4904. t['Deltagreek'] = 0x0394;
  4905. t['Dhook'] = 0x018A;
  4906. t['Dieresis'] = 0xF6CB;
  4907. t['DieresisAcute'] = 0xF6CC;
  4908. t['DieresisGrave'] = 0xF6CD;
  4909. t['Dieresissmall'] = 0xF7A8;
  4910. t['Digammagreek'] = 0x03DC;
  4911. t['Djecyrillic'] = 0x0402;
  4912. t['Dlinebelow'] = 0x1E0E;
  4913. t['Dmonospace'] = 0xFF24;
  4914. t['Dotaccentsmall'] = 0xF6F7;
  4915. t['Dslash'] = 0x0110;
  4916. t['Dsmall'] = 0xF764;
  4917. t['Dtopbar'] = 0x018B;
  4918. t['Dz'] = 0x01F2;
  4919. t['Dzcaron'] = 0x01C5;
  4920. t['Dzeabkhasiancyrillic'] = 0x04E0;
  4921. t['Dzecyrillic'] = 0x0405;
  4922. t['Dzhecyrillic'] = 0x040F;
  4923. t['E'] = 0x0045;
  4924. t['Eacute'] = 0x00C9;
  4925. t['Eacutesmall'] = 0xF7E9;
  4926. t['Ebreve'] = 0x0114;
  4927. t['Ecaron'] = 0x011A;
  4928. t['Ecedillabreve'] = 0x1E1C;
  4929. t['Echarmenian'] = 0x0535;
  4930. t['Ecircle'] = 0x24BA;
  4931. t['Ecircumflex'] = 0x00CA;
  4932. t['Ecircumflexacute'] = 0x1EBE;
  4933. t['Ecircumflexbelow'] = 0x1E18;
  4934. t['Ecircumflexdotbelow'] = 0x1EC6;
  4935. t['Ecircumflexgrave'] = 0x1EC0;
  4936. t['Ecircumflexhookabove'] = 0x1EC2;
  4937. t['Ecircumflexsmall'] = 0xF7EA;
  4938. t['Ecircumflextilde'] = 0x1EC4;
  4939. t['Ecyrillic'] = 0x0404;
  4940. t['Edblgrave'] = 0x0204;
  4941. t['Edieresis'] = 0x00CB;
  4942. t['Edieresissmall'] = 0xF7EB;
  4943. t['Edot'] = 0x0116;
  4944. t['Edotaccent'] = 0x0116;
  4945. t['Edotbelow'] = 0x1EB8;
  4946. t['Efcyrillic'] = 0x0424;
  4947. t['Egrave'] = 0x00C8;
  4948. t['Egravesmall'] = 0xF7E8;
  4949. t['Eharmenian'] = 0x0537;
  4950. t['Ehookabove'] = 0x1EBA;
  4951. t['Eightroman'] = 0x2167;
  4952. t['Einvertedbreve'] = 0x0206;
  4953. t['Eiotifiedcyrillic'] = 0x0464;
  4954. t['Elcyrillic'] = 0x041B;
  4955. t['Elevenroman'] = 0x216A;
  4956. t['Emacron'] = 0x0112;
  4957. t['Emacronacute'] = 0x1E16;
  4958. t['Emacrongrave'] = 0x1E14;
  4959. t['Emcyrillic'] = 0x041C;
  4960. t['Emonospace'] = 0xFF25;
  4961. t['Encyrillic'] = 0x041D;
  4962. t['Endescendercyrillic'] = 0x04A2;
  4963. t['Eng'] = 0x014A;
  4964. t['Enghecyrillic'] = 0x04A4;
  4965. t['Enhookcyrillic'] = 0x04C7;
  4966. t['Eogonek'] = 0x0118;
  4967. t['Eopen'] = 0x0190;
  4968. t['Epsilon'] = 0x0395;
  4969. t['Epsilontonos'] = 0x0388;
  4970. t['Ercyrillic'] = 0x0420;
  4971. t['Ereversed'] = 0x018E;
  4972. t['Ereversedcyrillic'] = 0x042D;
  4973. t['Escyrillic'] = 0x0421;
  4974. t['Esdescendercyrillic'] = 0x04AA;
  4975. t['Esh'] = 0x01A9;
  4976. t['Esmall'] = 0xF765;
  4977. t['Eta'] = 0x0397;
  4978. t['Etarmenian'] = 0x0538;
  4979. t['Etatonos'] = 0x0389;
  4980. t['Eth'] = 0x00D0;
  4981. t['Ethsmall'] = 0xF7F0;
  4982. t['Etilde'] = 0x1EBC;
  4983. t['Etildebelow'] = 0x1E1A;
  4984. t['Euro'] = 0x20AC;
  4985. t['Ezh'] = 0x01B7;
  4986. t['Ezhcaron'] = 0x01EE;
  4987. t['Ezhreversed'] = 0x01B8;
  4988. t['F'] = 0x0046;
  4989. t['Fcircle'] = 0x24BB;
  4990. t['Fdotaccent'] = 0x1E1E;
  4991. t['Feharmenian'] = 0x0556;
  4992. t['Feicoptic'] = 0x03E4;
  4993. t['Fhook'] = 0x0191;
  4994. t['Fitacyrillic'] = 0x0472;
  4995. t['Fiveroman'] = 0x2164;
  4996. t['Fmonospace'] = 0xFF26;
  4997. t['Fourroman'] = 0x2163;
  4998. t['Fsmall'] = 0xF766;
  4999. t['G'] = 0x0047;
  5000. t['GBsquare'] = 0x3387;
  5001. t['Gacute'] = 0x01F4;
  5002. t['Gamma'] = 0x0393;
  5003. t['Gammaafrican'] = 0x0194;
  5004. t['Gangiacoptic'] = 0x03EA;
  5005. t['Gbreve'] = 0x011E;
  5006. t['Gcaron'] = 0x01E6;
  5007. t['Gcedilla'] = 0x0122;
  5008. t['Gcircle'] = 0x24BC;
  5009. t['Gcircumflex'] = 0x011C;
  5010. t['Gcommaaccent'] = 0x0122;
  5011. t['Gdot'] = 0x0120;
  5012. t['Gdotaccent'] = 0x0120;
  5013. t['Gecyrillic'] = 0x0413;
  5014. t['Ghadarmenian'] = 0x0542;
  5015. t['Ghemiddlehookcyrillic'] = 0x0494;
  5016. t['Ghestrokecyrillic'] = 0x0492;
  5017. t['Gheupturncyrillic'] = 0x0490;
  5018. t['Ghook'] = 0x0193;
  5019. t['Gimarmenian'] = 0x0533;
  5020. t['Gjecyrillic'] = 0x0403;
  5021. t['Gmacron'] = 0x1E20;
  5022. t['Gmonospace'] = 0xFF27;
  5023. t['Grave'] = 0xF6CE;
  5024. t['Gravesmall'] = 0xF760;
  5025. t['Gsmall'] = 0xF767;
  5026. t['Gsmallhook'] = 0x029B;
  5027. t['Gstroke'] = 0x01E4;
  5028. t['H'] = 0x0048;
  5029. t['H18533'] = 0x25CF;
  5030. t['H18543'] = 0x25AA;
  5031. t['H18551'] = 0x25AB;
  5032. t['H22073'] = 0x25A1;
  5033. t['HPsquare'] = 0x33CB;
  5034. t['Haabkhasiancyrillic'] = 0x04A8;
  5035. t['Hadescendercyrillic'] = 0x04B2;
  5036. t['Hardsigncyrillic'] = 0x042A;
  5037. t['Hbar'] = 0x0126;
  5038. t['Hbrevebelow'] = 0x1E2A;
  5039. t['Hcedilla'] = 0x1E28;
  5040. t['Hcircle'] = 0x24BD;
  5041. t['Hcircumflex'] = 0x0124;
  5042. t['Hdieresis'] = 0x1E26;
  5043. t['Hdotaccent'] = 0x1E22;
  5044. t['Hdotbelow'] = 0x1E24;
  5045. t['Hmonospace'] = 0xFF28;
  5046. t['Hoarmenian'] = 0x0540;
  5047. t['Horicoptic'] = 0x03E8;
  5048. t['Hsmall'] = 0xF768;
  5049. t['Hungarumlaut'] = 0xF6CF;
  5050. t['Hungarumlautsmall'] = 0xF6F8;
  5051. t['Hzsquare'] = 0x3390;
  5052. t['I'] = 0x0049;
  5053. t['IAcyrillic'] = 0x042F;
  5054. t['IJ'] = 0x0132;
  5055. t['IUcyrillic'] = 0x042E;
  5056. t['Iacute'] = 0x00CD;
  5057. t['Iacutesmall'] = 0xF7ED;
  5058. t['Ibreve'] = 0x012C;
  5059. t['Icaron'] = 0x01CF;
  5060. t['Icircle'] = 0x24BE;
  5061. t['Icircumflex'] = 0x00CE;
  5062. t['Icircumflexsmall'] = 0xF7EE;
  5063. t['Icyrillic'] = 0x0406;
  5064. t['Idblgrave'] = 0x0208;
  5065. t['Idieresis'] = 0x00CF;
  5066. t['Idieresisacute'] = 0x1E2E;
  5067. t['Idieresiscyrillic'] = 0x04E4;
  5068. t['Idieresissmall'] = 0xF7EF;
  5069. t['Idot'] = 0x0130;
  5070. t['Idotaccent'] = 0x0130;
  5071. t['Idotbelow'] = 0x1ECA;
  5072. t['Iebrevecyrillic'] = 0x04D6;
  5073. t['Iecyrillic'] = 0x0415;
  5074. t['Ifraktur'] = 0x2111;
  5075. t['Igrave'] = 0x00CC;
  5076. t['Igravesmall'] = 0xF7EC;
  5077. t['Ihookabove'] = 0x1EC8;
  5078. t['Iicyrillic'] = 0x0418;
  5079. t['Iinvertedbreve'] = 0x020A;
  5080. t['Iishortcyrillic'] = 0x0419;
  5081. t['Imacron'] = 0x012A;
  5082. t['Imacroncyrillic'] = 0x04E2;
  5083. t['Imonospace'] = 0xFF29;
  5084. t['Iniarmenian'] = 0x053B;
  5085. t['Iocyrillic'] = 0x0401;
  5086. t['Iogonek'] = 0x012E;
  5087. t['Iota'] = 0x0399;
  5088. t['Iotaafrican'] = 0x0196;
  5089. t['Iotadieresis'] = 0x03AA;
  5090. t['Iotatonos'] = 0x038A;
  5091. t['Ismall'] = 0xF769;
  5092. t['Istroke'] = 0x0197;
  5093. t['Itilde'] = 0x0128;
  5094. t['Itildebelow'] = 0x1E2C;
  5095. t['Izhitsacyrillic'] = 0x0474;
  5096. t['Izhitsadblgravecyrillic'] = 0x0476;
  5097. t['J'] = 0x004A;
  5098. t['Jaarmenian'] = 0x0541;
  5099. t['Jcircle'] = 0x24BF;
  5100. t['Jcircumflex'] = 0x0134;
  5101. t['Jecyrillic'] = 0x0408;
  5102. t['Jheharmenian'] = 0x054B;
  5103. t['Jmonospace'] = 0xFF2A;
  5104. t['Jsmall'] = 0xF76A;
  5105. t['K'] = 0x004B;
  5106. t['KBsquare'] = 0x3385;
  5107. t['KKsquare'] = 0x33CD;
  5108. t['Kabashkircyrillic'] = 0x04A0;
  5109. t['Kacute'] = 0x1E30;
  5110. t['Kacyrillic'] = 0x041A;
  5111. t['Kadescendercyrillic'] = 0x049A;
  5112. t['Kahookcyrillic'] = 0x04C3;
  5113. t['Kappa'] = 0x039A;
  5114. t['Kastrokecyrillic'] = 0x049E;
  5115. t['Kaverticalstrokecyrillic'] = 0x049C;
  5116. t['Kcaron'] = 0x01E8;
  5117. t['Kcedilla'] = 0x0136;
  5118. t['Kcircle'] = 0x24C0;
  5119. t['Kcommaaccent'] = 0x0136;
  5120. t['Kdotbelow'] = 0x1E32;
  5121. t['Keharmenian'] = 0x0554;
  5122. t['Kenarmenian'] = 0x053F;
  5123. t['Khacyrillic'] = 0x0425;
  5124. t['Kheicoptic'] = 0x03E6;
  5125. t['Khook'] = 0x0198;
  5126. t['Kjecyrillic'] = 0x040C;
  5127. t['Klinebelow'] = 0x1E34;
  5128. t['Kmonospace'] = 0xFF2B;
  5129. t['Koppacyrillic'] = 0x0480;
  5130. t['Koppagreek'] = 0x03DE;
  5131. t['Ksicyrillic'] = 0x046E;
  5132. t['Ksmall'] = 0xF76B;
  5133. t['L'] = 0x004C;
  5134. t['LJ'] = 0x01C7;
  5135. t['LL'] = 0xF6BF;
  5136. t['Lacute'] = 0x0139;
  5137. t['Lambda'] = 0x039B;
  5138. t['Lcaron'] = 0x013D;
  5139. t['Lcedilla'] = 0x013B;
  5140. t['Lcircle'] = 0x24C1;
  5141. t['Lcircumflexbelow'] = 0x1E3C;
  5142. t['Lcommaaccent'] = 0x013B;
  5143. t['Ldot'] = 0x013F;
  5144. t['Ldotaccent'] = 0x013F;
  5145. t['Ldotbelow'] = 0x1E36;
  5146. t['Ldotbelowmacron'] = 0x1E38;
  5147. t['Liwnarmenian'] = 0x053C;
  5148. t['Lj'] = 0x01C8;
  5149. t['Ljecyrillic'] = 0x0409;
  5150. t['Llinebelow'] = 0x1E3A;
  5151. t['Lmonospace'] = 0xFF2C;
  5152. t['Lslash'] = 0x0141;
  5153. t['Lslashsmall'] = 0xF6F9;
  5154. t['Lsmall'] = 0xF76C;
  5155. t['M'] = 0x004D;
  5156. t['MBsquare'] = 0x3386;
  5157. t['Macron'] = 0xF6D0;
  5158. t['Macronsmall'] = 0xF7AF;
  5159. t['Macute'] = 0x1E3E;
  5160. t['Mcircle'] = 0x24C2;
  5161. t['Mdotaccent'] = 0x1E40;
  5162. t['Mdotbelow'] = 0x1E42;
  5163. t['Menarmenian'] = 0x0544;
  5164. t['Mmonospace'] = 0xFF2D;
  5165. t['Msmall'] = 0xF76D;
  5166. t['Mturned'] = 0x019C;
  5167. t['Mu'] = 0x039C;
  5168. t['N'] = 0x004E;
  5169. t['NJ'] = 0x01CA;
  5170. t['Nacute'] = 0x0143;
  5171. t['Ncaron'] = 0x0147;
  5172. t['Ncedilla'] = 0x0145;
  5173. t['Ncircle'] = 0x24C3;
  5174. t['Ncircumflexbelow'] = 0x1E4A;
  5175. t['Ncommaaccent'] = 0x0145;
  5176. t['Ndotaccent'] = 0x1E44;
  5177. t['Ndotbelow'] = 0x1E46;
  5178. t['Nhookleft'] = 0x019D;
  5179. t['Nineroman'] = 0x2168;
  5180. t['Nj'] = 0x01CB;
  5181. t['Njecyrillic'] = 0x040A;
  5182. t['Nlinebelow'] = 0x1E48;
  5183. t['Nmonospace'] = 0xFF2E;
  5184. t['Nowarmenian'] = 0x0546;
  5185. t['Nsmall'] = 0xF76E;
  5186. t['Ntilde'] = 0x00D1;
  5187. t['Ntildesmall'] = 0xF7F1;
  5188. t['Nu'] = 0x039D;
  5189. t['O'] = 0x004F;
  5190. t['OE'] = 0x0152;
  5191. t['OEsmall'] = 0xF6FA;
  5192. t['Oacute'] = 0x00D3;
  5193. t['Oacutesmall'] = 0xF7F3;
  5194. t['Obarredcyrillic'] = 0x04E8;
  5195. t['Obarreddieresiscyrillic'] = 0x04EA;
  5196. t['Obreve'] = 0x014E;
  5197. t['Ocaron'] = 0x01D1;
  5198. t['Ocenteredtilde'] = 0x019F;
  5199. t['Ocircle'] = 0x24C4;
  5200. t['Ocircumflex'] = 0x00D4;
  5201. t['Ocircumflexacute'] = 0x1ED0;
  5202. t['Ocircumflexdotbelow'] = 0x1ED8;
  5203. t['Ocircumflexgrave'] = 0x1ED2;
  5204. t['Ocircumflexhookabove'] = 0x1ED4;
  5205. t['Ocircumflexsmall'] = 0xF7F4;
  5206. t['Ocircumflextilde'] = 0x1ED6;
  5207. t['Ocyrillic'] = 0x041E;
  5208. t['Odblacute'] = 0x0150;
  5209. t['Odblgrave'] = 0x020C;
  5210. t['Odieresis'] = 0x00D6;
  5211. t['Odieresiscyrillic'] = 0x04E6;
  5212. t['Odieresissmall'] = 0xF7F6;
  5213. t['Odotbelow'] = 0x1ECC;
  5214. t['Ogoneksmall'] = 0xF6FB;
  5215. t['Ograve'] = 0x00D2;
  5216. t['Ogravesmall'] = 0xF7F2;
  5217. t['Oharmenian'] = 0x0555;
  5218. t['Ohm'] = 0x2126;
  5219. t['Ohookabove'] = 0x1ECE;
  5220. t['Ohorn'] = 0x01A0;
  5221. t['Ohornacute'] = 0x1EDA;
  5222. t['Ohorndotbelow'] = 0x1EE2;
  5223. t['Ohorngrave'] = 0x1EDC;
  5224. t['Ohornhookabove'] = 0x1EDE;
  5225. t['Ohorntilde'] = 0x1EE0;
  5226. t['Ohungarumlaut'] = 0x0150;
  5227. t['Oi'] = 0x01A2;
  5228. t['Oinvertedbreve'] = 0x020E;
  5229. t['Omacron'] = 0x014C;
  5230. t['Omacronacute'] = 0x1E52;
  5231. t['Omacrongrave'] = 0x1E50;
  5232. t['Omega'] = 0x2126;
  5233. t['Omegacyrillic'] = 0x0460;
  5234. t['Omegagreek'] = 0x03A9;
  5235. t['Omegaroundcyrillic'] = 0x047A;
  5236. t['Omegatitlocyrillic'] = 0x047C;
  5237. t['Omegatonos'] = 0x038F;
  5238. t['Omicron'] = 0x039F;
  5239. t['Omicrontonos'] = 0x038C;
  5240. t['Omonospace'] = 0xFF2F;
  5241. t['Oneroman'] = 0x2160;
  5242. t['Oogonek'] = 0x01EA;
  5243. t['Oogonekmacron'] = 0x01EC;
  5244. t['Oopen'] = 0x0186;
  5245. t['Oslash'] = 0x00D8;
  5246. t['Oslashacute'] = 0x01FE;
  5247. t['Oslashsmall'] = 0xF7F8;
  5248. t['Osmall'] = 0xF76F;
  5249. t['Ostrokeacute'] = 0x01FE;
  5250. t['Otcyrillic'] = 0x047E;
  5251. t['Otilde'] = 0x00D5;
  5252. t['Otildeacute'] = 0x1E4C;
  5253. t['Otildedieresis'] = 0x1E4E;
  5254. t['Otildesmall'] = 0xF7F5;
  5255. t['P'] = 0x0050;
  5256. t['Pacute'] = 0x1E54;
  5257. t['Pcircle'] = 0x24C5;
  5258. t['Pdotaccent'] = 0x1E56;
  5259. t['Pecyrillic'] = 0x041F;
  5260. t['Peharmenian'] = 0x054A;
  5261. t['Pemiddlehookcyrillic'] = 0x04A6;
  5262. t['Phi'] = 0x03A6;
  5263. t['Phook'] = 0x01A4;
  5264. t['Pi'] = 0x03A0;
  5265. t['Piwrarmenian'] = 0x0553;
  5266. t['Pmonospace'] = 0xFF30;
  5267. t['Psi'] = 0x03A8;
  5268. t['Psicyrillic'] = 0x0470;
  5269. t['Psmall'] = 0xF770;
  5270. t['Q'] = 0x0051;
  5271. t['Qcircle'] = 0x24C6;
  5272. t['Qmonospace'] = 0xFF31;
  5273. t['Qsmall'] = 0xF771;
  5274. t['R'] = 0x0052;
  5275. t['Raarmenian'] = 0x054C;
  5276. t['Racute'] = 0x0154;
  5277. t['Rcaron'] = 0x0158;
  5278. t['Rcedilla'] = 0x0156;
  5279. t['Rcircle'] = 0x24C7;
  5280. t['Rcommaaccent'] = 0x0156;
  5281. t['Rdblgrave'] = 0x0210;
  5282. t['Rdotaccent'] = 0x1E58;
  5283. t['Rdotbelow'] = 0x1E5A;
  5284. t['Rdotbelowmacron'] = 0x1E5C;
  5285. t['Reharmenian'] = 0x0550;
  5286. t['Rfraktur'] = 0x211C;
  5287. t['Rho'] = 0x03A1;
  5288. t['Ringsmall'] = 0xF6FC;
  5289. t['Rinvertedbreve'] = 0x0212;
  5290. t['Rlinebelow'] = 0x1E5E;
  5291. t['Rmonospace'] = 0xFF32;
  5292. t['Rsmall'] = 0xF772;
  5293. t['Rsmallinverted'] = 0x0281;
  5294. t['Rsmallinvertedsuperior'] = 0x02B6;
  5295. t['S'] = 0x0053;
  5296. t['SF010000'] = 0x250C;
  5297. t['SF020000'] = 0x2514;
  5298. t['SF030000'] = 0x2510;
  5299. t['SF040000'] = 0x2518;
  5300. t['SF050000'] = 0x253C;
  5301. t['SF060000'] = 0x252C;
  5302. t['SF070000'] = 0x2534;
  5303. t['SF080000'] = 0x251C;
  5304. t['SF090000'] = 0x2524;
  5305. t['SF100000'] = 0x2500;
  5306. t['SF110000'] = 0x2502;
  5307. t['SF190000'] = 0x2561;
  5308. t['SF200000'] = 0x2562;
  5309. t['SF210000'] = 0x2556;
  5310. t['SF220000'] = 0x2555;
  5311. t['SF230000'] = 0x2563;
  5312. t['SF240000'] = 0x2551;
  5313. t['SF250000'] = 0x2557;
  5314. t['SF260000'] = 0x255D;
  5315. t['SF270000'] = 0x255C;
  5316. t['SF280000'] = 0x255B;
  5317. t['SF360000'] = 0x255E;
  5318. t['SF370000'] = 0x255F;
  5319. t['SF380000'] = 0x255A;
  5320. t['SF390000'] = 0x2554;
  5321. t['SF400000'] = 0x2569;
  5322. t['SF410000'] = 0x2566;
  5323. t['SF420000'] = 0x2560;
  5324. t['SF430000'] = 0x2550;
  5325. t['SF440000'] = 0x256C;
  5326. t['SF450000'] = 0x2567;
  5327. t['SF460000'] = 0x2568;
  5328. t['SF470000'] = 0x2564;
  5329. t['SF480000'] = 0x2565;
  5330. t['SF490000'] = 0x2559;
  5331. t['SF500000'] = 0x2558;
  5332. t['SF510000'] = 0x2552;
  5333. t['SF520000'] = 0x2553;
  5334. t['SF530000'] = 0x256B;
  5335. t['SF540000'] = 0x256A;
  5336. t['Sacute'] = 0x015A;
  5337. t['Sacutedotaccent'] = 0x1E64;
  5338. t['Sampigreek'] = 0x03E0;
  5339. t['Scaron'] = 0x0160;
  5340. t['Scarondotaccent'] = 0x1E66;
  5341. t['Scaronsmall'] = 0xF6FD;
  5342. t['Scedilla'] = 0x015E;
  5343. t['Schwa'] = 0x018F;
  5344. t['Schwacyrillic'] = 0x04D8;
  5345. t['Schwadieresiscyrillic'] = 0x04DA;
  5346. t['Scircle'] = 0x24C8;
  5347. t['Scircumflex'] = 0x015C;
  5348. t['Scommaaccent'] = 0x0218;
  5349. t['Sdotaccent'] = 0x1E60;
  5350. t['Sdotbelow'] = 0x1E62;
  5351. t['Sdotbelowdotaccent'] = 0x1E68;
  5352. t['Seharmenian'] = 0x054D;
  5353. t['Sevenroman'] = 0x2166;
  5354. t['Shaarmenian'] = 0x0547;
  5355. t['Shacyrillic'] = 0x0428;
  5356. t['Shchacyrillic'] = 0x0429;
  5357. t['Sheicoptic'] = 0x03E2;
  5358. t['Shhacyrillic'] = 0x04BA;
  5359. t['Shimacoptic'] = 0x03EC;
  5360. t['Sigma'] = 0x03A3;
  5361. t['Sixroman'] = 0x2165;
  5362. t['Smonospace'] = 0xFF33;
  5363. t['Softsigncyrillic'] = 0x042C;
  5364. t['Ssmall'] = 0xF773;
  5365. t['Stigmagreek'] = 0x03DA;
  5366. t['T'] = 0x0054;
  5367. t['Tau'] = 0x03A4;
  5368. t['Tbar'] = 0x0166;
  5369. t['Tcaron'] = 0x0164;
  5370. t['Tcedilla'] = 0x0162;
  5371. t['Tcircle'] = 0x24C9;
  5372. t['Tcircumflexbelow'] = 0x1E70;
  5373. t['Tcommaaccent'] = 0x0162;
  5374. t['Tdotaccent'] = 0x1E6A;
  5375. t['Tdotbelow'] = 0x1E6C;
  5376. t['Tecyrillic'] = 0x0422;
  5377. t['Tedescendercyrillic'] = 0x04AC;
  5378. t['Tenroman'] = 0x2169;
  5379. t['Tetsecyrillic'] = 0x04B4;
  5380. t['Theta'] = 0x0398;
  5381. t['Thook'] = 0x01AC;
  5382. t['Thorn'] = 0x00DE;
  5383. t['Thornsmall'] = 0xF7FE;
  5384. t['Threeroman'] = 0x2162;
  5385. t['Tildesmall'] = 0xF6FE;
  5386. t['Tiwnarmenian'] = 0x054F;
  5387. t['Tlinebelow'] = 0x1E6E;
  5388. t['Tmonospace'] = 0xFF34;
  5389. t['Toarmenian'] = 0x0539;
  5390. t['Tonefive'] = 0x01BC;
  5391. t['Tonesix'] = 0x0184;
  5392. t['Tonetwo'] = 0x01A7;
  5393. t['Tretroflexhook'] = 0x01AE;
  5394. t['Tsecyrillic'] = 0x0426;
  5395. t['Tshecyrillic'] = 0x040B;
  5396. t['Tsmall'] = 0xF774;
  5397. t['Twelveroman'] = 0x216B;
  5398. t['Tworoman'] = 0x2161;
  5399. t['U'] = 0x0055;
  5400. t['Uacute'] = 0x00DA;
  5401. t['Uacutesmall'] = 0xF7FA;
  5402. t['Ubreve'] = 0x016C;
  5403. t['Ucaron'] = 0x01D3;
  5404. t['Ucircle'] = 0x24CA;
  5405. t['Ucircumflex'] = 0x00DB;
  5406. t['Ucircumflexbelow'] = 0x1E76;
  5407. t['Ucircumflexsmall'] = 0xF7FB;
  5408. t['Ucyrillic'] = 0x0423;
  5409. t['Udblacute'] = 0x0170;
  5410. t['Udblgrave'] = 0x0214;
  5411. t['Udieresis'] = 0x00DC;
  5412. t['Udieresisacute'] = 0x01D7;
  5413. t['Udieresisbelow'] = 0x1E72;
  5414. t['Udieresiscaron'] = 0x01D9;
  5415. t['Udieresiscyrillic'] = 0x04F0;
  5416. t['Udieresisgrave'] = 0x01DB;
  5417. t['Udieresismacron'] = 0x01D5;
  5418. t['Udieresissmall'] = 0xF7FC;
  5419. t['Udotbelow'] = 0x1EE4;
  5420. t['Ugrave'] = 0x00D9;
  5421. t['Ugravesmall'] = 0xF7F9;
  5422. t['Uhookabove'] = 0x1EE6;
  5423. t['Uhorn'] = 0x01AF;
  5424. t['Uhornacute'] = 0x1EE8;
  5425. t['Uhorndotbelow'] = 0x1EF0;
  5426. t['Uhorngrave'] = 0x1EEA;
  5427. t['Uhornhookabove'] = 0x1EEC;
  5428. t['Uhorntilde'] = 0x1EEE;
  5429. t['Uhungarumlaut'] = 0x0170;
  5430. t['Uhungarumlautcyrillic'] = 0x04F2;
  5431. t['Uinvertedbreve'] = 0x0216;
  5432. t['Ukcyrillic'] = 0x0478;
  5433. t['Umacron'] = 0x016A;
  5434. t['Umacroncyrillic'] = 0x04EE;
  5435. t['Umacrondieresis'] = 0x1E7A;
  5436. t['Umonospace'] = 0xFF35;
  5437. t['Uogonek'] = 0x0172;
  5438. t['Upsilon'] = 0x03A5;
  5439. t['Upsilon1'] = 0x03D2;
  5440. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  5441. t['Upsilonafrican'] = 0x01B1;
  5442. t['Upsilondieresis'] = 0x03AB;
  5443. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  5444. t['Upsilonhooksymbol'] = 0x03D2;
  5445. t['Upsilontonos'] = 0x038E;
  5446. t['Uring'] = 0x016E;
  5447. t['Ushortcyrillic'] = 0x040E;
  5448. t['Usmall'] = 0xF775;
  5449. t['Ustraightcyrillic'] = 0x04AE;
  5450. t['Ustraightstrokecyrillic'] = 0x04B0;
  5451. t['Utilde'] = 0x0168;
  5452. t['Utildeacute'] = 0x1E78;
  5453. t['Utildebelow'] = 0x1E74;
  5454. t['V'] = 0x0056;
  5455. t['Vcircle'] = 0x24CB;
  5456. t['Vdotbelow'] = 0x1E7E;
  5457. t['Vecyrillic'] = 0x0412;
  5458. t['Vewarmenian'] = 0x054E;
  5459. t['Vhook'] = 0x01B2;
  5460. t['Vmonospace'] = 0xFF36;
  5461. t['Voarmenian'] = 0x0548;
  5462. t['Vsmall'] = 0xF776;
  5463. t['Vtilde'] = 0x1E7C;
  5464. t['W'] = 0x0057;
  5465. t['Wacute'] = 0x1E82;
  5466. t['Wcircle'] = 0x24CC;
  5467. t['Wcircumflex'] = 0x0174;
  5468. t['Wdieresis'] = 0x1E84;
  5469. t['Wdotaccent'] = 0x1E86;
  5470. t['Wdotbelow'] = 0x1E88;
  5471. t['Wgrave'] = 0x1E80;
  5472. t['Wmonospace'] = 0xFF37;
  5473. t['Wsmall'] = 0xF777;
  5474. t['X'] = 0x0058;
  5475. t['Xcircle'] = 0x24CD;
  5476. t['Xdieresis'] = 0x1E8C;
  5477. t['Xdotaccent'] = 0x1E8A;
  5478. t['Xeharmenian'] = 0x053D;
  5479. t['Xi'] = 0x039E;
  5480. t['Xmonospace'] = 0xFF38;
  5481. t['Xsmall'] = 0xF778;
  5482. t['Y'] = 0x0059;
  5483. t['Yacute'] = 0x00DD;
  5484. t['Yacutesmall'] = 0xF7FD;
  5485. t['Yatcyrillic'] = 0x0462;
  5486. t['Ycircle'] = 0x24CE;
  5487. t['Ycircumflex'] = 0x0176;
  5488. t['Ydieresis'] = 0x0178;
  5489. t['Ydieresissmall'] = 0xF7FF;
  5490. t['Ydotaccent'] = 0x1E8E;
  5491. t['Ydotbelow'] = 0x1EF4;
  5492. t['Yericyrillic'] = 0x042B;
  5493. t['Yerudieresiscyrillic'] = 0x04F8;
  5494. t['Ygrave'] = 0x1EF2;
  5495. t['Yhook'] = 0x01B3;
  5496. t['Yhookabove'] = 0x1EF6;
  5497. t['Yiarmenian'] = 0x0545;
  5498. t['Yicyrillic'] = 0x0407;
  5499. t['Yiwnarmenian'] = 0x0552;
  5500. t['Ymonospace'] = 0xFF39;
  5501. t['Ysmall'] = 0xF779;
  5502. t['Ytilde'] = 0x1EF8;
  5503. t['Yusbigcyrillic'] = 0x046A;
  5504. t['Yusbigiotifiedcyrillic'] = 0x046C;
  5505. t['Yuslittlecyrillic'] = 0x0466;
  5506. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  5507. t['Z'] = 0x005A;
  5508. t['Zaarmenian'] = 0x0536;
  5509. t['Zacute'] = 0x0179;
  5510. t['Zcaron'] = 0x017D;
  5511. t['Zcaronsmall'] = 0xF6FF;
  5512. t['Zcircle'] = 0x24CF;
  5513. t['Zcircumflex'] = 0x1E90;
  5514. t['Zdot'] = 0x017B;
  5515. t['Zdotaccent'] = 0x017B;
  5516. t['Zdotbelow'] = 0x1E92;
  5517. t['Zecyrillic'] = 0x0417;
  5518. t['Zedescendercyrillic'] = 0x0498;
  5519. t['Zedieresiscyrillic'] = 0x04DE;
  5520. t['Zeta'] = 0x0396;
  5521. t['Zhearmenian'] = 0x053A;
  5522. t['Zhebrevecyrillic'] = 0x04C1;
  5523. t['Zhecyrillic'] = 0x0416;
  5524. t['Zhedescendercyrillic'] = 0x0496;
  5525. t['Zhedieresiscyrillic'] = 0x04DC;
  5526. t['Zlinebelow'] = 0x1E94;
  5527. t['Zmonospace'] = 0xFF3A;
  5528. t['Zsmall'] = 0xF77A;
  5529. t['Zstroke'] = 0x01B5;
  5530. t['a'] = 0x0061;
  5531. t['aabengali'] = 0x0986;
  5532. t['aacute'] = 0x00E1;
  5533. t['aadeva'] = 0x0906;
  5534. t['aagujarati'] = 0x0A86;
  5535. t['aagurmukhi'] = 0x0A06;
  5536. t['aamatragurmukhi'] = 0x0A3E;
  5537. t['aarusquare'] = 0x3303;
  5538. t['aavowelsignbengali'] = 0x09BE;
  5539. t['aavowelsigndeva'] = 0x093E;
  5540. t['aavowelsigngujarati'] = 0x0ABE;
  5541. t['abbreviationmarkarmenian'] = 0x055F;
  5542. t['abbreviationsigndeva'] = 0x0970;
  5543. t['abengali'] = 0x0985;
  5544. t['abopomofo'] = 0x311A;
  5545. t['abreve'] = 0x0103;
  5546. t['abreveacute'] = 0x1EAF;
  5547. t['abrevecyrillic'] = 0x04D1;
  5548. t['abrevedotbelow'] = 0x1EB7;
  5549. t['abrevegrave'] = 0x1EB1;
  5550. t['abrevehookabove'] = 0x1EB3;
  5551. t['abrevetilde'] = 0x1EB5;
  5552. t['acaron'] = 0x01CE;
  5553. t['acircle'] = 0x24D0;
  5554. t['acircumflex'] = 0x00E2;
  5555. t['acircumflexacute'] = 0x1EA5;
  5556. t['acircumflexdotbelow'] = 0x1EAD;
  5557. t['acircumflexgrave'] = 0x1EA7;
  5558. t['acircumflexhookabove'] = 0x1EA9;
  5559. t['acircumflextilde'] = 0x1EAB;
  5560. t['acute'] = 0x00B4;
  5561. t['acutebelowcmb'] = 0x0317;
  5562. t['acutecmb'] = 0x0301;
  5563. t['acutecomb'] = 0x0301;
  5564. t['acutedeva'] = 0x0954;
  5565. t['acutelowmod'] = 0x02CF;
  5566. t['acutetonecmb'] = 0x0341;
  5567. t['acyrillic'] = 0x0430;
  5568. t['adblgrave'] = 0x0201;
  5569. t['addakgurmukhi'] = 0x0A71;
  5570. t['adeva'] = 0x0905;
  5571. t['adieresis'] = 0x00E4;
  5572. t['adieresiscyrillic'] = 0x04D3;
  5573. t['adieresismacron'] = 0x01DF;
  5574. t['adotbelow'] = 0x1EA1;
  5575. t['adotmacron'] = 0x01E1;
  5576. t['ae'] = 0x00E6;
  5577. t['aeacute'] = 0x01FD;
  5578. t['aekorean'] = 0x3150;
  5579. t['aemacron'] = 0x01E3;
  5580. t['afii00208'] = 0x2015;
  5581. t['afii08941'] = 0x20A4;
  5582. t['afii10017'] = 0x0410;
  5583. t['afii10018'] = 0x0411;
  5584. t['afii10019'] = 0x0412;
  5585. t['afii10020'] = 0x0413;
  5586. t['afii10021'] = 0x0414;
  5587. t['afii10022'] = 0x0415;
  5588. t['afii10023'] = 0x0401;
  5589. t['afii10024'] = 0x0416;
  5590. t['afii10025'] = 0x0417;
  5591. t['afii10026'] = 0x0418;
  5592. t['afii10027'] = 0x0419;
  5593. t['afii10028'] = 0x041A;
  5594. t['afii10029'] = 0x041B;
  5595. t['afii10030'] = 0x041C;
  5596. t['afii10031'] = 0x041D;
  5597. t['afii10032'] = 0x041E;
  5598. t['afii10033'] = 0x041F;
  5599. t['afii10034'] = 0x0420;
  5600. t['afii10035'] = 0x0421;
  5601. t['afii10036'] = 0x0422;
  5602. t['afii10037'] = 0x0423;
  5603. t['afii10038'] = 0x0424;
  5604. t['afii10039'] = 0x0425;
  5605. t['afii10040'] = 0x0426;
  5606. t['afii10041'] = 0x0427;
  5607. t['afii10042'] = 0x0428;
  5608. t['afii10043'] = 0x0429;
  5609. t['afii10044'] = 0x042A;
  5610. t['afii10045'] = 0x042B;
  5611. t['afii10046'] = 0x042C;
  5612. t['afii10047'] = 0x042D;
  5613. t['afii10048'] = 0x042E;
  5614. t['afii10049'] = 0x042F;
  5615. t['afii10050'] = 0x0490;
  5616. t['afii10051'] = 0x0402;
  5617. t['afii10052'] = 0x0403;
  5618. t['afii10053'] = 0x0404;
  5619. t['afii10054'] = 0x0405;
  5620. t['afii10055'] = 0x0406;
  5621. t['afii10056'] = 0x0407;
  5622. t['afii10057'] = 0x0408;
  5623. t['afii10058'] = 0x0409;
  5624. t['afii10059'] = 0x040A;
  5625. t['afii10060'] = 0x040B;
  5626. t['afii10061'] = 0x040C;
  5627. t['afii10062'] = 0x040E;
  5628. t['afii10063'] = 0xF6C4;
  5629. t['afii10064'] = 0xF6C5;
  5630. t['afii10065'] = 0x0430;
  5631. t['afii10066'] = 0x0431;
  5632. t['afii10067'] = 0x0432;
  5633. t['afii10068'] = 0x0433;
  5634. t['afii10069'] = 0x0434;
  5635. t['afii10070'] = 0x0435;
  5636. t['afii10071'] = 0x0451;
  5637. t['afii10072'] = 0x0436;
  5638. t['afii10073'] = 0x0437;
  5639. t['afii10074'] = 0x0438;
  5640. t['afii10075'] = 0x0439;
  5641. t['afii10076'] = 0x043A;
  5642. t['afii10077'] = 0x043B;
  5643. t['afii10078'] = 0x043C;
  5644. t['afii10079'] = 0x043D;
  5645. t['afii10080'] = 0x043E;
  5646. t['afii10081'] = 0x043F;
  5647. t['afii10082'] = 0x0440;
  5648. t['afii10083'] = 0x0441;
  5649. t['afii10084'] = 0x0442;
  5650. t['afii10085'] = 0x0443;
  5651. t['afii10086'] = 0x0444;
  5652. t['afii10087'] = 0x0445;
  5653. t['afii10088'] = 0x0446;
  5654. t['afii10089'] = 0x0447;
  5655. t['afii10090'] = 0x0448;
  5656. t['afii10091'] = 0x0449;
  5657. t['afii10092'] = 0x044A;
  5658. t['afii10093'] = 0x044B;
  5659. t['afii10094'] = 0x044C;
  5660. t['afii10095'] = 0x044D;
  5661. t['afii10096'] = 0x044E;
  5662. t['afii10097'] = 0x044F;
  5663. t['afii10098'] = 0x0491;
  5664. t['afii10099'] = 0x0452;
  5665. t['afii10100'] = 0x0453;
  5666. t['afii10101'] = 0x0454;
  5667. t['afii10102'] = 0x0455;
  5668. t['afii10103'] = 0x0456;
  5669. t['afii10104'] = 0x0457;
  5670. t['afii10105'] = 0x0458;
  5671. t['afii10106'] = 0x0459;
  5672. t['afii10107'] = 0x045A;
  5673. t['afii10108'] = 0x045B;
  5674. t['afii10109'] = 0x045C;
  5675. t['afii10110'] = 0x045E;
  5676. t['afii10145'] = 0x040F;
  5677. t['afii10146'] = 0x0462;
  5678. t['afii10147'] = 0x0472;
  5679. t['afii10148'] = 0x0474;
  5680. t['afii10192'] = 0xF6C6;
  5681. t['afii10193'] = 0x045F;
  5682. t['afii10194'] = 0x0463;
  5683. t['afii10195'] = 0x0473;
  5684. t['afii10196'] = 0x0475;
  5685. t['afii10831'] = 0xF6C7;
  5686. t['afii10832'] = 0xF6C8;
  5687. t['afii10846'] = 0x04D9;
  5688. t['afii299'] = 0x200E;
  5689. t['afii300'] = 0x200F;
  5690. t['afii301'] = 0x200D;
  5691. t['afii57381'] = 0x066A;
  5692. t['afii57388'] = 0x060C;
  5693. t['afii57392'] = 0x0660;
  5694. t['afii57393'] = 0x0661;
  5695. t['afii57394'] = 0x0662;
  5696. t['afii57395'] = 0x0663;
  5697. t['afii57396'] = 0x0664;
  5698. t['afii57397'] = 0x0665;
  5699. t['afii57398'] = 0x0666;
  5700. t['afii57399'] = 0x0667;
  5701. t['afii57400'] = 0x0668;
  5702. t['afii57401'] = 0x0669;
  5703. t['afii57403'] = 0x061B;
  5704. t['afii57407'] = 0x061F;
  5705. t['afii57409'] = 0x0621;
  5706. t['afii57410'] = 0x0622;
  5707. t['afii57411'] = 0x0623;
  5708. t['afii57412'] = 0x0624;
  5709. t['afii57413'] = 0x0625;
  5710. t['afii57414'] = 0x0626;
  5711. t['afii57415'] = 0x0627;
  5712. t['afii57416'] = 0x0628;
  5713. t['afii57417'] = 0x0629;
  5714. t['afii57418'] = 0x062A;
  5715. t['afii57419'] = 0x062B;
  5716. t['afii57420'] = 0x062C;
  5717. t['afii57421'] = 0x062D;
  5718. t['afii57422'] = 0x062E;
  5719. t['afii57423'] = 0x062F;
  5720. t['afii57424'] = 0x0630;
  5721. t['afii57425'] = 0x0631;
  5722. t['afii57426'] = 0x0632;
  5723. t['afii57427'] = 0x0633;
  5724. t['afii57428'] = 0x0634;
  5725. t['afii57429'] = 0x0635;
  5726. t['afii57430'] = 0x0636;
  5727. t['afii57431'] = 0x0637;
  5728. t['afii57432'] = 0x0638;
  5729. t['afii57433'] = 0x0639;
  5730. t['afii57434'] = 0x063A;
  5731. t['afii57440'] = 0x0640;
  5732. t['afii57441'] = 0x0641;
  5733. t['afii57442'] = 0x0642;
  5734. t['afii57443'] = 0x0643;
  5735. t['afii57444'] = 0x0644;
  5736. t['afii57445'] = 0x0645;
  5737. t['afii57446'] = 0x0646;
  5738. t['afii57448'] = 0x0648;
  5739. t['afii57449'] = 0x0649;
  5740. t['afii57450'] = 0x064A;
  5741. t['afii57451'] = 0x064B;
  5742. t['afii57452'] = 0x064C;
  5743. t['afii57453'] = 0x064D;
  5744. t['afii57454'] = 0x064E;
  5745. t['afii57455'] = 0x064F;
  5746. t['afii57456'] = 0x0650;
  5747. t['afii57457'] = 0x0651;
  5748. t['afii57458'] = 0x0652;
  5749. t['afii57470'] = 0x0647;
  5750. t['afii57505'] = 0x06A4;
  5751. t['afii57506'] = 0x067E;
  5752. t['afii57507'] = 0x0686;
  5753. t['afii57508'] = 0x0698;
  5754. t['afii57509'] = 0x06AF;
  5755. t['afii57511'] = 0x0679;
  5756. t['afii57512'] = 0x0688;
  5757. t['afii57513'] = 0x0691;
  5758. t['afii57514'] = 0x06BA;
  5759. t['afii57519'] = 0x06D2;
  5760. t['afii57534'] = 0x06D5;
  5761. t['afii57636'] = 0x20AA;
  5762. t['afii57645'] = 0x05BE;
  5763. t['afii57658'] = 0x05C3;
  5764. t['afii57664'] = 0x05D0;
  5765. t['afii57665'] = 0x05D1;
  5766. t['afii57666'] = 0x05D2;
  5767. t['afii57667'] = 0x05D3;
  5768. t['afii57668'] = 0x05D4;
  5769. t['afii57669'] = 0x05D5;
  5770. t['afii57670'] = 0x05D6;
  5771. t['afii57671'] = 0x05D7;
  5772. t['afii57672'] = 0x05D8;
  5773. t['afii57673'] = 0x05D9;
  5774. t['afii57674'] = 0x05DA;
  5775. t['afii57675'] = 0x05DB;
  5776. t['afii57676'] = 0x05DC;
  5777. t['afii57677'] = 0x05DD;
  5778. t['afii57678'] = 0x05DE;
  5779. t['afii57679'] = 0x05DF;
  5780. t['afii57680'] = 0x05E0;
  5781. t['afii57681'] = 0x05E1;
  5782. t['afii57682'] = 0x05E2;
  5783. t['afii57683'] = 0x05E3;
  5784. t['afii57684'] = 0x05E4;
  5785. t['afii57685'] = 0x05E5;
  5786. t['afii57686'] = 0x05E6;
  5787. t['afii57687'] = 0x05E7;
  5788. t['afii57688'] = 0x05E8;
  5789. t['afii57689'] = 0x05E9;
  5790. t['afii57690'] = 0x05EA;
  5791. t['afii57694'] = 0xFB2A;
  5792. t['afii57695'] = 0xFB2B;
  5793. t['afii57700'] = 0xFB4B;
  5794. t['afii57705'] = 0xFB1F;
  5795. t['afii57716'] = 0x05F0;
  5796. t['afii57717'] = 0x05F1;
  5797. t['afii57718'] = 0x05F2;
  5798. t['afii57723'] = 0xFB35;
  5799. t['afii57793'] = 0x05B4;
  5800. t['afii57794'] = 0x05B5;
  5801. t['afii57795'] = 0x05B6;
  5802. t['afii57796'] = 0x05BB;
  5803. t['afii57797'] = 0x05B8;
  5804. t['afii57798'] = 0x05B7;
  5805. t['afii57799'] = 0x05B0;
  5806. t['afii57800'] = 0x05B2;
  5807. t['afii57801'] = 0x05B1;
  5808. t['afii57802'] = 0x05B3;
  5809. t['afii57803'] = 0x05C2;
  5810. t['afii57804'] = 0x05C1;
  5811. t['afii57806'] = 0x05B9;
  5812. t['afii57807'] = 0x05BC;
  5813. t['afii57839'] = 0x05BD;
  5814. t['afii57841'] = 0x05BF;
  5815. t['afii57842'] = 0x05C0;
  5816. t['afii57929'] = 0x02BC;
  5817. t['afii61248'] = 0x2105;
  5818. t['afii61289'] = 0x2113;
  5819. t['afii61352'] = 0x2116;
  5820. t['afii61573'] = 0x202C;
  5821. t['afii61574'] = 0x202D;
  5822. t['afii61575'] = 0x202E;
  5823. t['afii61664'] = 0x200C;
  5824. t['afii63167'] = 0x066D;
  5825. t['afii64937'] = 0x02BD;
  5826. t['agrave'] = 0x00E0;
  5827. t['agujarati'] = 0x0A85;
  5828. t['agurmukhi'] = 0x0A05;
  5829. t['ahiragana'] = 0x3042;
  5830. t['ahookabove'] = 0x1EA3;
  5831. t['aibengali'] = 0x0990;
  5832. t['aibopomofo'] = 0x311E;
  5833. t['aideva'] = 0x0910;
  5834. t['aiecyrillic'] = 0x04D5;
  5835. t['aigujarati'] = 0x0A90;
  5836. t['aigurmukhi'] = 0x0A10;
  5837. t['aimatragurmukhi'] = 0x0A48;
  5838. t['ainarabic'] = 0x0639;
  5839. t['ainfinalarabic'] = 0xFECA;
  5840. t['aininitialarabic'] = 0xFECB;
  5841. t['ainmedialarabic'] = 0xFECC;
  5842. t['ainvertedbreve'] = 0x0203;
  5843. t['aivowelsignbengali'] = 0x09C8;
  5844. t['aivowelsigndeva'] = 0x0948;
  5845. t['aivowelsigngujarati'] = 0x0AC8;
  5846. t['akatakana'] = 0x30A2;
  5847. t['akatakanahalfwidth'] = 0xFF71;
  5848. t['akorean'] = 0x314F;
  5849. t['alef'] = 0x05D0;
  5850. t['alefarabic'] = 0x0627;
  5851. t['alefdageshhebrew'] = 0xFB30;
  5852. t['aleffinalarabic'] = 0xFE8E;
  5853. t['alefhamzaabovearabic'] = 0x0623;
  5854. t['alefhamzaabovefinalarabic'] = 0xFE84;
  5855. t['alefhamzabelowarabic'] = 0x0625;
  5856. t['alefhamzabelowfinalarabic'] = 0xFE88;
  5857. t['alefhebrew'] = 0x05D0;
  5858. t['aleflamedhebrew'] = 0xFB4F;
  5859. t['alefmaddaabovearabic'] = 0x0622;
  5860. t['alefmaddaabovefinalarabic'] = 0xFE82;
  5861. t['alefmaksuraarabic'] = 0x0649;
  5862. t['alefmaksurafinalarabic'] = 0xFEF0;
  5863. t['alefmaksurainitialarabic'] = 0xFEF3;
  5864. t['alefmaksuramedialarabic'] = 0xFEF4;
  5865. t['alefpatahhebrew'] = 0xFB2E;
  5866. t['alefqamatshebrew'] = 0xFB2F;
  5867. t['aleph'] = 0x2135;
  5868. t['allequal'] = 0x224C;
  5869. t['alpha'] = 0x03B1;
  5870. t['alphatonos'] = 0x03AC;
  5871. t['amacron'] = 0x0101;
  5872. t['amonospace'] = 0xFF41;
  5873. t['ampersand'] = 0x0026;
  5874. t['ampersandmonospace'] = 0xFF06;
  5875. t['ampersandsmall'] = 0xF726;
  5876. t['amsquare'] = 0x33C2;
  5877. t['anbopomofo'] = 0x3122;
  5878. t['angbopomofo'] = 0x3124;
  5879. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  5880. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  5881. t['angkhankhuthai'] = 0x0E5A;
  5882. t['angle'] = 0x2220;
  5883. t['anglebracketleft'] = 0x3008;
  5884. t['anglebracketleftvertical'] = 0xFE3F;
  5885. t['anglebracketright'] = 0x3009;
  5886. t['anglebracketrightvertical'] = 0xFE40;
  5887. t['angleleft'] = 0x2329;
  5888. t['angleright'] = 0x232A;
  5889. t['angstrom'] = 0x212B;
  5890. t['anoteleia'] = 0x0387;
  5891. t['anudattadeva'] = 0x0952;
  5892. t['anusvarabengali'] = 0x0982;
  5893. t['anusvaradeva'] = 0x0902;
  5894. t['anusvaragujarati'] = 0x0A82;
  5895. t['aogonek'] = 0x0105;
  5896. t['apaatosquare'] = 0x3300;
  5897. t['aparen'] = 0x249C;
  5898. t['apostrophearmenian'] = 0x055A;
  5899. t['apostrophemod'] = 0x02BC;
  5900. t['apple'] = 0xF8FF;
  5901. t['approaches'] = 0x2250;
  5902. t['approxequal'] = 0x2248;
  5903. t['approxequalorimage'] = 0x2252;
  5904. t['approximatelyequal'] = 0x2245;
  5905. t['araeaekorean'] = 0x318E;
  5906. t['araeakorean'] = 0x318D;
  5907. t['arc'] = 0x2312;
  5908. t['arighthalfring'] = 0x1E9A;
  5909. t['aring'] = 0x00E5;
  5910. t['aringacute'] = 0x01FB;
  5911. t['aringbelow'] = 0x1E01;
  5912. t['arrowboth'] = 0x2194;
  5913. t['arrowdashdown'] = 0x21E3;
  5914. t['arrowdashleft'] = 0x21E0;
  5915. t['arrowdashright'] = 0x21E2;
  5916. t['arrowdashup'] = 0x21E1;
  5917. t['arrowdblboth'] = 0x21D4;
  5918. t['arrowdbldown'] = 0x21D3;
  5919. t['arrowdblleft'] = 0x21D0;
  5920. t['arrowdblright'] = 0x21D2;
  5921. t['arrowdblup'] = 0x21D1;
  5922. t['arrowdown'] = 0x2193;
  5923. t['arrowdownleft'] = 0x2199;
  5924. t['arrowdownright'] = 0x2198;
  5925. t['arrowdownwhite'] = 0x21E9;
  5926. t['arrowheaddownmod'] = 0x02C5;
  5927. t['arrowheadleftmod'] = 0x02C2;
  5928. t['arrowheadrightmod'] = 0x02C3;
  5929. t['arrowheadupmod'] = 0x02C4;
  5930. t['arrowhorizex'] = 0xF8E7;
  5931. t['arrowleft'] = 0x2190;
  5932. t['arrowleftdbl'] = 0x21D0;
  5933. t['arrowleftdblstroke'] = 0x21CD;
  5934. t['arrowleftoverright'] = 0x21C6;
  5935. t['arrowleftwhite'] = 0x21E6;
  5936. t['arrowright'] = 0x2192;
  5937. t['arrowrightdblstroke'] = 0x21CF;
  5938. t['arrowrightheavy'] = 0x279E;
  5939. t['arrowrightoverleft'] = 0x21C4;
  5940. t['arrowrightwhite'] = 0x21E8;
  5941. t['arrowtableft'] = 0x21E4;
  5942. t['arrowtabright'] = 0x21E5;
  5943. t['arrowup'] = 0x2191;
  5944. t['arrowupdn'] = 0x2195;
  5945. t['arrowupdnbse'] = 0x21A8;
  5946. t['arrowupdownbase'] = 0x21A8;
  5947. t['arrowupleft'] = 0x2196;
  5948. t['arrowupleftofdown'] = 0x21C5;
  5949. t['arrowupright'] = 0x2197;
  5950. t['arrowupwhite'] = 0x21E7;
  5951. t['arrowvertex'] = 0xF8E6;
  5952. t['asciicircum'] = 0x005E;
  5953. t['asciicircummonospace'] = 0xFF3E;
  5954. t['asciitilde'] = 0x007E;
  5955. t['asciitildemonospace'] = 0xFF5E;
  5956. t['ascript'] = 0x0251;
  5957. t['ascriptturned'] = 0x0252;
  5958. t['asmallhiragana'] = 0x3041;
  5959. t['asmallkatakana'] = 0x30A1;
  5960. t['asmallkatakanahalfwidth'] = 0xFF67;
  5961. t['asterisk'] = 0x002A;
  5962. t['asteriskaltonearabic'] = 0x066D;
  5963. t['asteriskarabic'] = 0x066D;
  5964. t['asteriskmath'] = 0x2217;
  5965. t['asteriskmonospace'] = 0xFF0A;
  5966. t['asterisksmall'] = 0xFE61;
  5967. t['asterism'] = 0x2042;
  5968. t['asuperior'] = 0xF6E9;
  5969. t['asymptoticallyequal'] = 0x2243;
  5970. t['at'] = 0x0040;
  5971. t['atilde'] = 0x00E3;
  5972. t['atmonospace'] = 0xFF20;
  5973. t['atsmall'] = 0xFE6B;
  5974. t['aturned'] = 0x0250;
  5975. t['aubengali'] = 0x0994;
  5976. t['aubopomofo'] = 0x3120;
  5977. t['audeva'] = 0x0914;
  5978. t['augujarati'] = 0x0A94;
  5979. t['augurmukhi'] = 0x0A14;
  5980. t['aulengthmarkbengali'] = 0x09D7;
  5981. t['aumatragurmukhi'] = 0x0A4C;
  5982. t['auvowelsignbengali'] = 0x09CC;
  5983. t['auvowelsigndeva'] = 0x094C;
  5984. t['auvowelsigngujarati'] = 0x0ACC;
  5985. t['avagrahadeva'] = 0x093D;
  5986. t['aybarmenian'] = 0x0561;
  5987. t['ayin'] = 0x05E2;
  5988. t['ayinaltonehebrew'] = 0xFB20;
  5989. t['ayinhebrew'] = 0x05E2;
  5990. t['b'] = 0x0062;
  5991. t['babengali'] = 0x09AC;
  5992. t['backslash'] = 0x005C;
  5993. t['backslashmonospace'] = 0xFF3C;
  5994. t['badeva'] = 0x092C;
  5995. t['bagujarati'] = 0x0AAC;
  5996. t['bagurmukhi'] = 0x0A2C;
  5997. t['bahiragana'] = 0x3070;
  5998. t['bahtthai'] = 0x0E3F;
  5999. t['bakatakana'] = 0x30D0;
  6000. t['bar'] = 0x007C;
  6001. t['barmonospace'] = 0xFF5C;
  6002. t['bbopomofo'] = 0x3105;
  6003. t['bcircle'] = 0x24D1;
  6004. t['bdotaccent'] = 0x1E03;
  6005. t['bdotbelow'] = 0x1E05;
  6006. t['beamedsixteenthnotes'] = 0x266C;
  6007. t['because'] = 0x2235;
  6008. t['becyrillic'] = 0x0431;
  6009. t['beharabic'] = 0x0628;
  6010. t['behfinalarabic'] = 0xFE90;
  6011. t['behinitialarabic'] = 0xFE91;
  6012. t['behiragana'] = 0x3079;
  6013. t['behmedialarabic'] = 0xFE92;
  6014. t['behmeeminitialarabic'] = 0xFC9F;
  6015. t['behmeemisolatedarabic'] = 0xFC08;
  6016. t['behnoonfinalarabic'] = 0xFC6D;
  6017. t['bekatakana'] = 0x30D9;
  6018. t['benarmenian'] = 0x0562;
  6019. t['bet'] = 0x05D1;
  6020. t['beta'] = 0x03B2;
  6021. t['betasymbolgreek'] = 0x03D0;
  6022. t['betdagesh'] = 0xFB31;
  6023. t['betdageshhebrew'] = 0xFB31;
  6024. t['bethebrew'] = 0x05D1;
  6025. t['betrafehebrew'] = 0xFB4C;
  6026. t['bhabengali'] = 0x09AD;
  6027. t['bhadeva'] = 0x092D;
  6028. t['bhagujarati'] = 0x0AAD;
  6029. t['bhagurmukhi'] = 0x0A2D;
  6030. t['bhook'] = 0x0253;
  6031. t['bihiragana'] = 0x3073;
  6032. t['bikatakana'] = 0x30D3;
  6033. t['bilabialclick'] = 0x0298;
  6034. t['bindigurmukhi'] = 0x0A02;
  6035. t['birusquare'] = 0x3331;
  6036. t['blackcircle'] = 0x25CF;
  6037. t['blackdiamond'] = 0x25C6;
  6038. t['blackdownpointingtriangle'] = 0x25BC;
  6039. t['blackleftpointingpointer'] = 0x25C4;
  6040. t['blackleftpointingtriangle'] = 0x25C0;
  6041. t['blacklenticularbracketleft'] = 0x3010;
  6042. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  6043. t['blacklenticularbracketright'] = 0x3011;
  6044. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  6045. t['blacklowerlefttriangle'] = 0x25E3;
  6046. t['blacklowerrighttriangle'] = 0x25E2;
  6047. t['blackrectangle'] = 0x25AC;
  6048. t['blackrightpointingpointer'] = 0x25BA;
  6049. t['blackrightpointingtriangle'] = 0x25B6;
  6050. t['blacksmallsquare'] = 0x25AA;
  6051. t['blacksmilingface'] = 0x263B;
  6052. t['blacksquare'] = 0x25A0;
  6053. t['blackstar'] = 0x2605;
  6054. t['blackupperlefttriangle'] = 0x25E4;
  6055. t['blackupperrighttriangle'] = 0x25E5;
  6056. t['blackuppointingsmalltriangle'] = 0x25B4;
  6057. t['blackuppointingtriangle'] = 0x25B2;
  6058. t['blank'] = 0x2423;
  6059. t['blinebelow'] = 0x1E07;
  6060. t['block'] = 0x2588;
  6061. t['bmonospace'] = 0xFF42;
  6062. t['bobaimaithai'] = 0x0E1A;
  6063. t['bohiragana'] = 0x307C;
  6064. t['bokatakana'] = 0x30DC;
  6065. t['bparen'] = 0x249D;
  6066. t['bqsquare'] = 0x33C3;
  6067. t['braceex'] = 0xF8F4;
  6068. t['braceleft'] = 0x007B;
  6069. t['braceleftbt'] = 0xF8F3;
  6070. t['braceleftmid'] = 0xF8F2;
  6071. t['braceleftmonospace'] = 0xFF5B;
  6072. t['braceleftsmall'] = 0xFE5B;
  6073. t['bracelefttp'] = 0xF8F1;
  6074. t['braceleftvertical'] = 0xFE37;
  6075. t['braceright'] = 0x007D;
  6076. t['bracerightbt'] = 0xF8FE;
  6077. t['bracerightmid'] = 0xF8FD;
  6078. t['bracerightmonospace'] = 0xFF5D;
  6079. t['bracerightsmall'] = 0xFE5C;
  6080. t['bracerighttp'] = 0xF8FC;
  6081. t['bracerightvertical'] = 0xFE38;
  6082. t['bracketleft'] = 0x005B;
  6083. t['bracketleftbt'] = 0xF8F0;
  6084. t['bracketleftex'] = 0xF8EF;
  6085. t['bracketleftmonospace'] = 0xFF3B;
  6086. t['bracketlefttp'] = 0xF8EE;
  6087. t['bracketright'] = 0x005D;
  6088. t['bracketrightbt'] = 0xF8FB;
  6089. t['bracketrightex'] = 0xF8FA;
  6090. t['bracketrightmonospace'] = 0xFF3D;
  6091. t['bracketrighttp'] = 0xF8F9;
  6092. t['breve'] = 0x02D8;
  6093. t['brevebelowcmb'] = 0x032E;
  6094. t['brevecmb'] = 0x0306;
  6095. t['breveinvertedbelowcmb'] = 0x032F;
  6096. t['breveinvertedcmb'] = 0x0311;
  6097. t['breveinverteddoublecmb'] = 0x0361;
  6098. t['bridgebelowcmb'] = 0x032A;
  6099. t['bridgeinvertedbelowcmb'] = 0x033A;
  6100. t['brokenbar'] = 0x00A6;
  6101. t['bstroke'] = 0x0180;
  6102. t['bsuperior'] = 0xF6EA;
  6103. t['btopbar'] = 0x0183;
  6104. t['buhiragana'] = 0x3076;
  6105. t['bukatakana'] = 0x30D6;
  6106. t['bullet'] = 0x2022;
  6107. t['bulletinverse'] = 0x25D8;
  6108. t['bulletoperator'] = 0x2219;
  6109. t['bullseye'] = 0x25CE;
  6110. t['c'] = 0x0063;
  6111. t['caarmenian'] = 0x056E;
  6112. t['cabengali'] = 0x099A;
  6113. t['cacute'] = 0x0107;
  6114. t['cadeva'] = 0x091A;
  6115. t['cagujarati'] = 0x0A9A;
  6116. t['cagurmukhi'] = 0x0A1A;
  6117. t['calsquare'] = 0x3388;
  6118. t['candrabindubengali'] = 0x0981;
  6119. t['candrabinducmb'] = 0x0310;
  6120. t['candrabindudeva'] = 0x0901;
  6121. t['candrabindugujarati'] = 0x0A81;
  6122. t['capslock'] = 0x21EA;
  6123. t['careof'] = 0x2105;
  6124. t['caron'] = 0x02C7;
  6125. t['caronbelowcmb'] = 0x032C;
  6126. t['caroncmb'] = 0x030C;
  6127. t['carriagereturn'] = 0x21B5;
  6128. t['cbopomofo'] = 0x3118;
  6129. t['ccaron'] = 0x010D;
  6130. t['ccedilla'] = 0x00E7;
  6131. t['ccedillaacute'] = 0x1E09;
  6132. t['ccircle'] = 0x24D2;
  6133. t['ccircumflex'] = 0x0109;
  6134. t['ccurl'] = 0x0255;
  6135. t['cdot'] = 0x010B;
  6136. t['cdotaccent'] = 0x010B;
  6137. t['cdsquare'] = 0x33C5;
  6138. t['cedilla'] = 0x00B8;
  6139. t['cedillacmb'] = 0x0327;
  6140. t['cent'] = 0x00A2;
  6141. t['centigrade'] = 0x2103;
  6142. t['centinferior'] = 0xF6DF;
  6143. t['centmonospace'] = 0xFFE0;
  6144. t['centoldstyle'] = 0xF7A2;
  6145. t['centsuperior'] = 0xF6E0;
  6146. t['chaarmenian'] = 0x0579;
  6147. t['chabengali'] = 0x099B;
  6148. t['chadeva'] = 0x091B;
  6149. t['chagujarati'] = 0x0A9B;
  6150. t['chagurmukhi'] = 0x0A1B;
  6151. t['chbopomofo'] = 0x3114;
  6152. t['cheabkhasiancyrillic'] = 0x04BD;
  6153. t['checkmark'] = 0x2713;
  6154. t['checyrillic'] = 0x0447;
  6155. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  6156. t['chedescendercyrillic'] = 0x04B7;
  6157. t['chedieresiscyrillic'] = 0x04F5;
  6158. t['cheharmenian'] = 0x0573;
  6159. t['chekhakassiancyrillic'] = 0x04CC;
  6160. t['cheverticalstrokecyrillic'] = 0x04B9;
  6161. t['chi'] = 0x03C7;
  6162. t['chieuchacirclekorean'] = 0x3277;
  6163. t['chieuchaparenkorean'] = 0x3217;
  6164. t['chieuchcirclekorean'] = 0x3269;
  6165. t['chieuchkorean'] = 0x314A;
  6166. t['chieuchparenkorean'] = 0x3209;
  6167. t['chochangthai'] = 0x0E0A;
  6168. t['chochanthai'] = 0x0E08;
  6169. t['chochingthai'] = 0x0E09;
  6170. t['chochoethai'] = 0x0E0C;
  6171. t['chook'] = 0x0188;
  6172. t['cieucacirclekorean'] = 0x3276;
  6173. t['cieucaparenkorean'] = 0x3216;
  6174. t['cieuccirclekorean'] = 0x3268;
  6175. t['cieuckorean'] = 0x3148;
  6176. t['cieucparenkorean'] = 0x3208;
  6177. t['cieucuparenkorean'] = 0x321C;
  6178. t['circle'] = 0x25CB;
  6179. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  6180. t['circlemultiply'] = 0x2297;
  6181. t['circleot'] = 0x2299;
  6182. t['circleplus'] = 0x2295;
  6183. t['circlepostalmark'] = 0x3036;
  6184. t['circlewithlefthalfblack'] = 0x25D0;
  6185. t['circlewithrighthalfblack'] = 0x25D1;
  6186. t['circumflex'] = 0x02C6;
  6187. t['circumflexbelowcmb'] = 0x032D;
  6188. t['circumflexcmb'] = 0x0302;
  6189. t['clear'] = 0x2327;
  6190. t['clickalveolar'] = 0x01C2;
  6191. t['clickdental'] = 0x01C0;
  6192. t['clicklateral'] = 0x01C1;
  6193. t['clickretroflex'] = 0x01C3;
  6194. t['club'] = 0x2663;
  6195. t['clubsuitblack'] = 0x2663;
  6196. t['clubsuitwhite'] = 0x2667;
  6197. t['cmcubedsquare'] = 0x33A4;
  6198. t['cmonospace'] = 0xFF43;
  6199. t['cmsquaredsquare'] = 0x33A0;
  6200. t['coarmenian'] = 0x0581;
  6201. t['colon'] = 0x003A;
  6202. t['colonmonetary'] = 0x20A1;
  6203. t['colonmonospace'] = 0xFF1A;
  6204. t['colonsign'] = 0x20A1;
  6205. t['colonsmall'] = 0xFE55;
  6206. t['colontriangularhalfmod'] = 0x02D1;
  6207. t['colontriangularmod'] = 0x02D0;
  6208. t['comma'] = 0x002C;
  6209. t['commaabovecmb'] = 0x0313;
  6210. t['commaaboverightcmb'] = 0x0315;
  6211. t['commaaccent'] = 0xF6C3;
  6212. t['commaarabic'] = 0x060C;
  6213. t['commaarmenian'] = 0x055D;
  6214. t['commainferior'] = 0xF6E1;
  6215. t['commamonospace'] = 0xFF0C;
  6216. t['commareversedabovecmb'] = 0x0314;
  6217. t['commareversedmod'] = 0x02BD;
  6218. t['commasmall'] = 0xFE50;
  6219. t['commasuperior'] = 0xF6E2;
  6220. t['commaturnedabovecmb'] = 0x0312;
  6221. t['commaturnedmod'] = 0x02BB;
  6222. t['compass'] = 0x263C;
  6223. t['congruent'] = 0x2245;
  6224. t['contourintegral'] = 0x222E;
  6225. t['control'] = 0x2303;
  6226. t['controlACK'] = 0x0006;
  6227. t['controlBEL'] = 0x0007;
  6228. t['controlBS'] = 0x0008;
  6229. t['controlCAN'] = 0x0018;
  6230. t['controlCR'] = 0x000D;
  6231. t['controlDC1'] = 0x0011;
  6232. t['controlDC2'] = 0x0012;
  6233. t['controlDC3'] = 0x0013;
  6234. t['controlDC4'] = 0x0014;
  6235. t['controlDEL'] = 0x007F;
  6236. t['controlDLE'] = 0x0010;
  6237. t['controlEM'] = 0x0019;
  6238. t['controlENQ'] = 0x0005;
  6239. t['controlEOT'] = 0x0004;
  6240. t['controlESC'] = 0x001B;
  6241. t['controlETB'] = 0x0017;
  6242. t['controlETX'] = 0x0003;
  6243. t['controlFF'] = 0x000C;
  6244. t['controlFS'] = 0x001C;
  6245. t['controlGS'] = 0x001D;
  6246. t['controlHT'] = 0x0009;
  6247. t['controlLF'] = 0x000A;
  6248. t['controlNAK'] = 0x0015;
  6249. t['controlRS'] = 0x001E;
  6250. t['controlSI'] = 0x000F;
  6251. t['controlSO'] = 0x000E;
  6252. t['controlSOT'] = 0x0002;
  6253. t['controlSTX'] = 0x0001;
  6254. t['controlSUB'] = 0x001A;
  6255. t['controlSYN'] = 0x0016;
  6256. t['controlUS'] = 0x001F;
  6257. t['controlVT'] = 0x000B;
  6258. t['copyright'] = 0x00A9;
  6259. t['copyrightsans'] = 0xF8E9;
  6260. t['copyrightserif'] = 0xF6D9;
  6261. t['cornerbracketleft'] = 0x300C;
  6262. t['cornerbracketlefthalfwidth'] = 0xFF62;
  6263. t['cornerbracketleftvertical'] = 0xFE41;
  6264. t['cornerbracketright'] = 0x300D;
  6265. t['cornerbracketrighthalfwidth'] = 0xFF63;
  6266. t['cornerbracketrightvertical'] = 0xFE42;
  6267. t['corporationsquare'] = 0x337F;
  6268. t['cosquare'] = 0x33C7;
  6269. t['coverkgsquare'] = 0x33C6;
  6270. t['cparen'] = 0x249E;
  6271. t['cruzeiro'] = 0x20A2;
  6272. t['cstretched'] = 0x0297;
  6273. t['curlyand'] = 0x22CF;
  6274. t['curlyor'] = 0x22CE;
  6275. t['currency'] = 0x00A4;
  6276. t['cyrBreve'] = 0xF6D1;
  6277. t['cyrFlex'] = 0xF6D2;
  6278. t['cyrbreve'] = 0xF6D4;
  6279. t['cyrflex'] = 0xF6D5;
  6280. t['d'] = 0x0064;
  6281. t['daarmenian'] = 0x0564;
  6282. t['dabengali'] = 0x09A6;
  6283. t['dadarabic'] = 0x0636;
  6284. t['dadeva'] = 0x0926;
  6285. t['dadfinalarabic'] = 0xFEBE;
  6286. t['dadinitialarabic'] = 0xFEBF;
  6287. t['dadmedialarabic'] = 0xFEC0;
  6288. t['dagesh'] = 0x05BC;
  6289. t['dageshhebrew'] = 0x05BC;
  6290. t['dagger'] = 0x2020;
  6291. t['daggerdbl'] = 0x2021;
  6292. t['dagujarati'] = 0x0AA6;
  6293. t['dagurmukhi'] = 0x0A26;
  6294. t['dahiragana'] = 0x3060;
  6295. t['dakatakana'] = 0x30C0;
  6296. t['dalarabic'] = 0x062F;
  6297. t['dalet'] = 0x05D3;
  6298. t['daletdagesh'] = 0xFB33;
  6299. t['daletdageshhebrew'] = 0xFB33;
  6300. t['dalethebrew'] = 0x05D3;
  6301. t['dalfinalarabic'] = 0xFEAA;
  6302. t['dammaarabic'] = 0x064F;
  6303. t['dammalowarabic'] = 0x064F;
  6304. t['dammatanaltonearabic'] = 0x064C;
  6305. t['dammatanarabic'] = 0x064C;
  6306. t['danda'] = 0x0964;
  6307. t['dargahebrew'] = 0x05A7;
  6308. t['dargalefthebrew'] = 0x05A7;
  6309. t['dasiapneumatacyrilliccmb'] = 0x0485;
  6310. t['dblGrave'] = 0xF6D3;
  6311. t['dblanglebracketleft'] = 0x300A;
  6312. t['dblanglebracketleftvertical'] = 0xFE3D;
  6313. t['dblanglebracketright'] = 0x300B;
  6314. t['dblanglebracketrightvertical'] = 0xFE3E;
  6315. t['dblarchinvertedbelowcmb'] = 0x032B;
  6316. t['dblarrowleft'] = 0x21D4;
  6317. t['dblarrowright'] = 0x21D2;
  6318. t['dbldanda'] = 0x0965;
  6319. t['dblgrave'] = 0xF6D6;
  6320. t['dblgravecmb'] = 0x030F;
  6321. t['dblintegral'] = 0x222C;
  6322. t['dbllowline'] = 0x2017;
  6323. t['dbllowlinecmb'] = 0x0333;
  6324. t['dbloverlinecmb'] = 0x033F;
  6325. t['dblprimemod'] = 0x02BA;
  6326. t['dblverticalbar'] = 0x2016;
  6327. t['dblverticallineabovecmb'] = 0x030E;
  6328. t['dbopomofo'] = 0x3109;
  6329. t['dbsquare'] = 0x33C8;
  6330. t['dcaron'] = 0x010F;
  6331. t['dcedilla'] = 0x1E11;
  6332. t['dcircle'] = 0x24D3;
  6333. t['dcircumflexbelow'] = 0x1E13;
  6334. t['dcroat'] = 0x0111;
  6335. t['ddabengali'] = 0x09A1;
  6336. t['ddadeva'] = 0x0921;
  6337. t['ddagujarati'] = 0x0AA1;
  6338. t['ddagurmukhi'] = 0x0A21;
  6339. t['ddalarabic'] = 0x0688;
  6340. t['ddalfinalarabic'] = 0xFB89;
  6341. t['dddhadeva'] = 0x095C;
  6342. t['ddhabengali'] = 0x09A2;
  6343. t['ddhadeva'] = 0x0922;
  6344. t['ddhagujarati'] = 0x0AA2;
  6345. t['ddhagurmukhi'] = 0x0A22;
  6346. t['ddotaccent'] = 0x1E0B;
  6347. t['ddotbelow'] = 0x1E0D;
  6348. t['decimalseparatorarabic'] = 0x066B;
  6349. t['decimalseparatorpersian'] = 0x066B;
  6350. t['decyrillic'] = 0x0434;
  6351. t['degree'] = 0x00B0;
  6352. t['dehihebrew'] = 0x05AD;
  6353. t['dehiragana'] = 0x3067;
  6354. t['deicoptic'] = 0x03EF;
  6355. t['dekatakana'] = 0x30C7;
  6356. t['deleteleft'] = 0x232B;
  6357. t['deleteright'] = 0x2326;
  6358. t['delta'] = 0x03B4;
  6359. t['deltaturned'] = 0x018D;
  6360. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  6361. t['dezh'] = 0x02A4;
  6362. t['dhabengali'] = 0x09A7;
  6363. t['dhadeva'] = 0x0927;
  6364. t['dhagujarati'] = 0x0AA7;
  6365. t['dhagurmukhi'] = 0x0A27;
  6366. t['dhook'] = 0x0257;
  6367. t['dialytikatonos'] = 0x0385;
  6368. t['dialytikatonoscmb'] = 0x0344;
  6369. t['diamond'] = 0x2666;
  6370. t['diamondsuitwhite'] = 0x2662;
  6371. t['dieresis'] = 0x00A8;
  6372. t['dieresisacute'] = 0xF6D7;
  6373. t['dieresisbelowcmb'] = 0x0324;
  6374. t['dieresiscmb'] = 0x0308;
  6375. t['dieresisgrave'] = 0xF6D8;
  6376. t['dieresistonos'] = 0x0385;
  6377. t['dihiragana'] = 0x3062;
  6378. t['dikatakana'] = 0x30C2;
  6379. t['dittomark'] = 0x3003;
  6380. t['divide'] = 0x00F7;
  6381. t['divides'] = 0x2223;
  6382. t['divisionslash'] = 0x2215;
  6383. t['djecyrillic'] = 0x0452;
  6384. t['dkshade'] = 0x2593;
  6385. t['dlinebelow'] = 0x1E0F;
  6386. t['dlsquare'] = 0x3397;
  6387. t['dmacron'] = 0x0111;
  6388. t['dmonospace'] = 0xFF44;
  6389. t['dnblock'] = 0x2584;
  6390. t['dochadathai'] = 0x0E0E;
  6391. t['dodekthai'] = 0x0E14;
  6392. t['dohiragana'] = 0x3069;
  6393. t['dokatakana'] = 0x30C9;
  6394. t['dollar'] = 0x0024;
  6395. t['dollarinferior'] = 0xF6E3;
  6396. t['dollarmonospace'] = 0xFF04;
  6397. t['dollaroldstyle'] = 0xF724;
  6398. t['dollarsmall'] = 0xFE69;
  6399. t['dollarsuperior'] = 0xF6E4;
  6400. t['dong'] = 0x20AB;
  6401. t['dorusquare'] = 0x3326;
  6402. t['dotaccent'] = 0x02D9;
  6403. t['dotaccentcmb'] = 0x0307;
  6404. t['dotbelowcmb'] = 0x0323;
  6405. t['dotbelowcomb'] = 0x0323;
  6406. t['dotkatakana'] = 0x30FB;
  6407. t['dotlessi'] = 0x0131;
  6408. t['dotlessj'] = 0xF6BE;
  6409. t['dotlessjstrokehook'] = 0x0284;
  6410. t['dotmath'] = 0x22C5;
  6411. t['dottedcircle'] = 0x25CC;
  6412. t['doubleyodpatah'] = 0xFB1F;
  6413. t['doubleyodpatahhebrew'] = 0xFB1F;
  6414. t['downtackbelowcmb'] = 0x031E;
  6415. t['downtackmod'] = 0x02D5;
  6416. t['dparen'] = 0x249F;
  6417. t['dsuperior'] = 0xF6EB;
  6418. t['dtail'] = 0x0256;
  6419. t['dtopbar'] = 0x018C;
  6420. t['duhiragana'] = 0x3065;
  6421. t['dukatakana'] = 0x30C5;
  6422. t['dz'] = 0x01F3;
  6423. t['dzaltone'] = 0x02A3;
  6424. t['dzcaron'] = 0x01C6;
  6425. t['dzcurl'] = 0x02A5;
  6426. t['dzeabkhasiancyrillic'] = 0x04E1;
  6427. t['dzecyrillic'] = 0x0455;
  6428. t['dzhecyrillic'] = 0x045F;
  6429. t['e'] = 0x0065;
  6430. t['eacute'] = 0x00E9;
  6431. t['earth'] = 0x2641;
  6432. t['ebengali'] = 0x098F;
  6433. t['ebopomofo'] = 0x311C;
  6434. t['ebreve'] = 0x0115;
  6435. t['ecandradeva'] = 0x090D;
  6436. t['ecandragujarati'] = 0x0A8D;
  6437. t['ecandravowelsigndeva'] = 0x0945;
  6438. t['ecandravowelsigngujarati'] = 0x0AC5;
  6439. t['ecaron'] = 0x011B;
  6440. t['ecedillabreve'] = 0x1E1D;
  6441. t['echarmenian'] = 0x0565;
  6442. t['echyiwnarmenian'] = 0x0587;
  6443. t['ecircle'] = 0x24D4;
  6444. t['ecircumflex'] = 0x00EA;
  6445. t['ecircumflexacute'] = 0x1EBF;
  6446. t['ecircumflexbelow'] = 0x1E19;
  6447. t['ecircumflexdotbelow'] = 0x1EC7;
  6448. t['ecircumflexgrave'] = 0x1EC1;
  6449. t['ecircumflexhookabove'] = 0x1EC3;
  6450. t['ecircumflextilde'] = 0x1EC5;
  6451. t['ecyrillic'] = 0x0454;
  6452. t['edblgrave'] = 0x0205;
  6453. t['edeva'] = 0x090F;
  6454. t['edieresis'] = 0x00EB;
  6455. t['edot'] = 0x0117;
  6456. t['edotaccent'] = 0x0117;
  6457. t['edotbelow'] = 0x1EB9;
  6458. t['eegurmukhi'] = 0x0A0F;
  6459. t['eematragurmukhi'] = 0x0A47;
  6460. t['efcyrillic'] = 0x0444;
  6461. t['egrave'] = 0x00E8;
  6462. t['egujarati'] = 0x0A8F;
  6463. t['eharmenian'] = 0x0567;
  6464. t['ehbopomofo'] = 0x311D;
  6465. t['ehiragana'] = 0x3048;
  6466. t['ehookabove'] = 0x1EBB;
  6467. t['eibopomofo'] = 0x311F;
  6468. t['eight'] = 0x0038;
  6469. t['eightarabic'] = 0x0668;
  6470. t['eightbengali'] = 0x09EE;
  6471. t['eightcircle'] = 0x2467;
  6472. t['eightcircleinversesansserif'] = 0x2791;
  6473. t['eightdeva'] = 0x096E;
  6474. t['eighteencircle'] = 0x2471;
  6475. t['eighteenparen'] = 0x2485;
  6476. t['eighteenperiod'] = 0x2499;
  6477. t['eightgujarati'] = 0x0AEE;
  6478. t['eightgurmukhi'] = 0x0A6E;
  6479. t['eighthackarabic'] = 0x0668;
  6480. t['eighthangzhou'] = 0x3028;
  6481. t['eighthnotebeamed'] = 0x266B;
  6482. t['eightideographicparen'] = 0x3227;
  6483. t['eightinferior'] = 0x2088;
  6484. t['eightmonospace'] = 0xFF18;
  6485. t['eightoldstyle'] = 0xF738;
  6486. t['eightparen'] = 0x247B;
  6487. t['eightperiod'] = 0x248F;
  6488. t['eightpersian'] = 0x06F8;
  6489. t['eightroman'] = 0x2177;
  6490. t['eightsuperior'] = 0x2078;
  6491. t['eightthai'] = 0x0E58;
  6492. t['einvertedbreve'] = 0x0207;
  6493. t['eiotifiedcyrillic'] = 0x0465;
  6494. t['ekatakana'] = 0x30A8;
  6495. t['ekatakanahalfwidth'] = 0xFF74;
  6496. t['ekonkargurmukhi'] = 0x0A74;
  6497. t['ekorean'] = 0x3154;
  6498. t['elcyrillic'] = 0x043B;
  6499. t['element'] = 0x2208;
  6500. t['elevencircle'] = 0x246A;
  6501. t['elevenparen'] = 0x247E;
  6502. t['elevenperiod'] = 0x2492;
  6503. t['elevenroman'] = 0x217A;
  6504. t['ellipsis'] = 0x2026;
  6505. t['ellipsisvertical'] = 0x22EE;
  6506. t['emacron'] = 0x0113;
  6507. t['emacronacute'] = 0x1E17;
  6508. t['emacrongrave'] = 0x1E15;
  6509. t['emcyrillic'] = 0x043C;
  6510. t['emdash'] = 0x2014;
  6511. t['emdashvertical'] = 0xFE31;
  6512. t['emonospace'] = 0xFF45;
  6513. t['emphasismarkarmenian'] = 0x055B;
  6514. t['emptyset'] = 0x2205;
  6515. t['enbopomofo'] = 0x3123;
  6516. t['encyrillic'] = 0x043D;
  6517. t['endash'] = 0x2013;
  6518. t['endashvertical'] = 0xFE32;
  6519. t['endescendercyrillic'] = 0x04A3;
  6520. t['eng'] = 0x014B;
  6521. t['engbopomofo'] = 0x3125;
  6522. t['enghecyrillic'] = 0x04A5;
  6523. t['enhookcyrillic'] = 0x04C8;
  6524. t['enspace'] = 0x2002;
  6525. t['eogonek'] = 0x0119;
  6526. t['eokorean'] = 0x3153;
  6527. t['eopen'] = 0x025B;
  6528. t['eopenclosed'] = 0x029A;
  6529. t['eopenreversed'] = 0x025C;
  6530. t['eopenreversedclosed'] = 0x025E;
  6531. t['eopenreversedhook'] = 0x025D;
  6532. t['eparen'] = 0x24A0;
  6533. t['epsilon'] = 0x03B5;
  6534. t['epsilontonos'] = 0x03AD;
  6535. t['equal'] = 0x003D;
  6536. t['equalmonospace'] = 0xFF1D;
  6537. t['equalsmall'] = 0xFE66;
  6538. t['equalsuperior'] = 0x207C;
  6539. t['equivalence'] = 0x2261;
  6540. t['erbopomofo'] = 0x3126;
  6541. t['ercyrillic'] = 0x0440;
  6542. t['ereversed'] = 0x0258;
  6543. t['ereversedcyrillic'] = 0x044D;
  6544. t['escyrillic'] = 0x0441;
  6545. t['esdescendercyrillic'] = 0x04AB;
  6546. t['esh'] = 0x0283;
  6547. t['eshcurl'] = 0x0286;
  6548. t['eshortdeva'] = 0x090E;
  6549. t['eshortvowelsigndeva'] = 0x0946;
  6550. t['eshreversedloop'] = 0x01AA;
  6551. t['eshsquatreversed'] = 0x0285;
  6552. t['esmallhiragana'] = 0x3047;
  6553. t['esmallkatakana'] = 0x30A7;
  6554. t['esmallkatakanahalfwidth'] = 0xFF6A;
  6555. t['estimated'] = 0x212E;
  6556. t['esuperior'] = 0xF6EC;
  6557. t['eta'] = 0x03B7;
  6558. t['etarmenian'] = 0x0568;
  6559. t['etatonos'] = 0x03AE;
  6560. t['eth'] = 0x00F0;
  6561. t['etilde'] = 0x1EBD;
  6562. t['etildebelow'] = 0x1E1B;
  6563. t['etnahtafoukhhebrew'] = 0x0591;
  6564. t['etnahtafoukhlefthebrew'] = 0x0591;
  6565. t['etnahtahebrew'] = 0x0591;
  6566. t['etnahtalefthebrew'] = 0x0591;
  6567. t['eturned'] = 0x01DD;
  6568. t['eukorean'] = 0x3161;
  6569. t['euro'] = 0x20AC;
  6570. t['evowelsignbengali'] = 0x09C7;
  6571. t['evowelsigndeva'] = 0x0947;
  6572. t['evowelsigngujarati'] = 0x0AC7;
  6573. t['exclam'] = 0x0021;
  6574. t['exclamarmenian'] = 0x055C;
  6575. t['exclamdbl'] = 0x203C;
  6576. t['exclamdown'] = 0x00A1;
  6577. t['exclamdownsmall'] = 0xF7A1;
  6578. t['exclammonospace'] = 0xFF01;
  6579. t['exclamsmall'] = 0xF721;
  6580. t['existential'] = 0x2203;
  6581. t['ezh'] = 0x0292;
  6582. t['ezhcaron'] = 0x01EF;
  6583. t['ezhcurl'] = 0x0293;
  6584. t['ezhreversed'] = 0x01B9;
  6585. t['ezhtail'] = 0x01BA;
  6586. t['f'] = 0x0066;
  6587. t['fadeva'] = 0x095E;
  6588. t['fagurmukhi'] = 0x0A5E;
  6589. t['fahrenheit'] = 0x2109;
  6590. t['fathaarabic'] = 0x064E;
  6591. t['fathalowarabic'] = 0x064E;
  6592. t['fathatanarabic'] = 0x064B;
  6593. t['fbopomofo'] = 0x3108;
  6594. t['fcircle'] = 0x24D5;
  6595. t['fdotaccent'] = 0x1E1F;
  6596. t['feharabic'] = 0x0641;
  6597. t['feharmenian'] = 0x0586;
  6598. t['fehfinalarabic'] = 0xFED2;
  6599. t['fehinitialarabic'] = 0xFED3;
  6600. t['fehmedialarabic'] = 0xFED4;
  6601. t['feicoptic'] = 0x03E5;
  6602. t['female'] = 0x2640;
  6603. t['ff'] = 0xFB00;
  6604. t['ffi'] = 0xFB03;
  6605. t['ffl'] = 0xFB04;
  6606. t['fi'] = 0xFB01;
  6607. t['fifteencircle'] = 0x246E;
  6608. t['fifteenparen'] = 0x2482;
  6609. t['fifteenperiod'] = 0x2496;
  6610. t['figuredash'] = 0x2012;
  6611. t['filledbox'] = 0x25A0;
  6612. t['filledrect'] = 0x25AC;
  6613. t['finalkaf'] = 0x05DA;
  6614. t['finalkafdagesh'] = 0xFB3A;
  6615. t['finalkafdageshhebrew'] = 0xFB3A;
  6616. t['finalkafhebrew'] = 0x05DA;
  6617. t['finalmem'] = 0x05DD;
  6618. t['finalmemhebrew'] = 0x05DD;
  6619. t['finalnun'] = 0x05DF;
  6620. t['finalnunhebrew'] = 0x05DF;
  6621. t['finalpe'] = 0x05E3;
  6622. t['finalpehebrew'] = 0x05E3;
  6623. t['finaltsadi'] = 0x05E5;
  6624. t['finaltsadihebrew'] = 0x05E5;
  6625. t['firsttonechinese'] = 0x02C9;
  6626. t['fisheye'] = 0x25C9;
  6627. t['fitacyrillic'] = 0x0473;
  6628. t['five'] = 0x0035;
  6629. t['fivearabic'] = 0x0665;
  6630. t['fivebengali'] = 0x09EB;
  6631. t['fivecircle'] = 0x2464;
  6632. t['fivecircleinversesansserif'] = 0x278E;
  6633. t['fivedeva'] = 0x096B;
  6634. t['fiveeighths'] = 0x215D;
  6635. t['fivegujarati'] = 0x0AEB;
  6636. t['fivegurmukhi'] = 0x0A6B;
  6637. t['fivehackarabic'] = 0x0665;
  6638. t['fivehangzhou'] = 0x3025;
  6639. t['fiveideographicparen'] = 0x3224;
  6640. t['fiveinferior'] = 0x2085;
  6641. t['fivemonospace'] = 0xFF15;
  6642. t['fiveoldstyle'] = 0xF735;
  6643. t['fiveparen'] = 0x2478;
  6644. t['fiveperiod'] = 0x248C;
  6645. t['fivepersian'] = 0x06F5;
  6646. t['fiveroman'] = 0x2174;
  6647. t['fivesuperior'] = 0x2075;
  6648. t['fivethai'] = 0x0E55;
  6649. t['fl'] = 0xFB02;
  6650. t['florin'] = 0x0192;
  6651. t['fmonospace'] = 0xFF46;
  6652. t['fmsquare'] = 0x3399;
  6653. t['fofanthai'] = 0x0E1F;
  6654. t['fofathai'] = 0x0E1D;
  6655. t['fongmanthai'] = 0x0E4F;
  6656. t['forall'] = 0x2200;
  6657. t['four'] = 0x0034;
  6658. t['fourarabic'] = 0x0664;
  6659. t['fourbengali'] = 0x09EA;
  6660. t['fourcircle'] = 0x2463;
  6661. t['fourcircleinversesansserif'] = 0x278D;
  6662. t['fourdeva'] = 0x096A;
  6663. t['fourgujarati'] = 0x0AEA;
  6664. t['fourgurmukhi'] = 0x0A6A;
  6665. t['fourhackarabic'] = 0x0664;
  6666. t['fourhangzhou'] = 0x3024;
  6667. t['fourideographicparen'] = 0x3223;
  6668. t['fourinferior'] = 0x2084;
  6669. t['fourmonospace'] = 0xFF14;
  6670. t['fournumeratorbengali'] = 0x09F7;
  6671. t['fouroldstyle'] = 0xF734;
  6672. t['fourparen'] = 0x2477;
  6673. t['fourperiod'] = 0x248B;
  6674. t['fourpersian'] = 0x06F4;
  6675. t['fourroman'] = 0x2173;
  6676. t['foursuperior'] = 0x2074;
  6677. t['fourteencircle'] = 0x246D;
  6678. t['fourteenparen'] = 0x2481;
  6679. t['fourteenperiod'] = 0x2495;
  6680. t['fourthai'] = 0x0E54;
  6681. t['fourthtonechinese'] = 0x02CB;
  6682. t['fparen'] = 0x24A1;
  6683. t['fraction'] = 0x2044;
  6684. t['franc'] = 0x20A3;
  6685. t['g'] = 0x0067;
  6686. t['gabengali'] = 0x0997;
  6687. t['gacute'] = 0x01F5;
  6688. t['gadeva'] = 0x0917;
  6689. t['gafarabic'] = 0x06AF;
  6690. t['gaffinalarabic'] = 0xFB93;
  6691. t['gafinitialarabic'] = 0xFB94;
  6692. t['gafmedialarabic'] = 0xFB95;
  6693. t['gagujarati'] = 0x0A97;
  6694. t['gagurmukhi'] = 0x0A17;
  6695. t['gahiragana'] = 0x304C;
  6696. t['gakatakana'] = 0x30AC;
  6697. t['gamma'] = 0x03B3;
  6698. t['gammalatinsmall'] = 0x0263;
  6699. t['gammasuperior'] = 0x02E0;
  6700. t['gangiacoptic'] = 0x03EB;
  6701. t['gbopomofo'] = 0x310D;
  6702. t['gbreve'] = 0x011F;
  6703. t['gcaron'] = 0x01E7;
  6704. t['gcedilla'] = 0x0123;
  6705. t['gcircle'] = 0x24D6;
  6706. t['gcircumflex'] = 0x011D;
  6707. t['gcommaaccent'] = 0x0123;
  6708. t['gdot'] = 0x0121;
  6709. t['gdotaccent'] = 0x0121;
  6710. t['gecyrillic'] = 0x0433;
  6711. t['gehiragana'] = 0x3052;
  6712. t['gekatakana'] = 0x30B2;
  6713. t['geometricallyequal'] = 0x2251;
  6714. t['gereshaccenthebrew'] = 0x059C;
  6715. t['gereshhebrew'] = 0x05F3;
  6716. t['gereshmuqdamhebrew'] = 0x059D;
  6717. t['germandbls'] = 0x00DF;
  6718. t['gershayimaccenthebrew'] = 0x059E;
  6719. t['gershayimhebrew'] = 0x05F4;
  6720. t['getamark'] = 0x3013;
  6721. t['ghabengali'] = 0x0998;
  6722. t['ghadarmenian'] = 0x0572;
  6723. t['ghadeva'] = 0x0918;
  6724. t['ghagujarati'] = 0x0A98;
  6725. t['ghagurmukhi'] = 0x0A18;
  6726. t['ghainarabic'] = 0x063A;
  6727. t['ghainfinalarabic'] = 0xFECE;
  6728. t['ghaininitialarabic'] = 0xFECF;
  6729. t['ghainmedialarabic'] = 0xFED0;
  6730. t['ghemiddlehookcyrillic'] = 0x0495;
  6731. t['ghestrokecyrillic'] = 0x0493;
  6732. t['gheupturncyrillic'] = 0x0491;
  6733. t['ghhadeva'] = 0x095A;
  6734. t['ghhagurmukhi'] = 0x0A5A;
  6735. t['ghook'] = 0x0260;
  6736. t['ghzsquare'] = 0x3393;
  6737. t['gihiragana'] = 0x304E;
  6738. t['gikatakana'] = 0x30AE;
  6739. t['gimarmenian'] = 0x0563;
  6740. t['gimel'] = 0x05D2;
  6741. t['gimeldagesh'] = 0xFB32;
  6742. t['gimeldageshhebrew'] = 0xFB32;
  6743. t['gimelhebrew'] = 0x05D2;
  6744. t['gjecyrillic'] = 0x0453;
  6745. t['glottalinvertedstroke'] = 0x01BE;
  6746. t['glottalstop'] = 0x0294;
  6747. t['glottalstopinverted'] = 0x0296;
  6748. t['glottalstopmod'] = 0x02C0;
  6749. t['glottalstopreversed'] = 0x0295;
  6750. t['glottalstopreversedmod'] = 0x02C1;
  6751. t['glottalstopreversedsuperior'] = 0x02E4;
  6752. t['glottalstopstroke'] = 0x02A1;
  6753. t['glottalstopstrokereversed'] = 0x02A2;
  6754. t['gmacron'] = 0x1E21;
  6755. t['gmonospace'] = 0xFF47;
  6756. t['gohiragana'] = 0x3054;
  6757. t['gokatakana'] = 0x30B4;
  6758. t['gparen'] = 0x24A2;
  6759. t['gpasquare'] = 0x33AC;
  6760. t['gradient'] = 0x2207;
  6761. t['grave'] = 0x0060;
  6762. t['gravebelowcmb'] = 0x0316;
  6763. t['gravecmb'] = 0x0300;
  6764. t['gravecomb'] = 0x0300;
  6765. t['gravedeva'] = 0x0953;
  6766. t['gravelowmod'] = 0x02CE;
  6767. t['gravemonospace'] = 0xFF40;
  6768. t['gravetonecmb'] = 0x0340;
  6769. t['greater'] = 0x003E;
  6770. t['greaterequal'] = 0x2265;
  6771. t['greaterequalorless'] = 0x22DB;
  6772. t['greatermonospace'] = 0xFF1E;
  6773. t['greaterorequivalent'] = 0x2273;
  6774. t['greaterorless'] = 0x2277;
  6775. t['greateroverequal'] = 0x2267;
  6776. t['greatersmall'] = 0xFE65;
  6777. t['gscript'] = 0x0261;
  6778. t['gstroke'] = 0x01E5;
  6779. t['guhiragana'] = 0x3050;
  6780. t['guillemotleft'] = 0x00AB;
  6781. t['guillemotright'] = 0x00BB;
  6782. t['guilsinglleft'] = 0x2039;
  6783. t['guilsinglright'] = 0x203A;
  6784. t['gukatakana'] = 0x30B0;
  6785. t['guramusquare'] = 0x3318;
  6786. t['gysquare'] = 0x33C9;
  6787. t['h'] = 0x0068;
  6788. t['haabkhasiancyrillic'] = 0x04A9;
  6789. t['haaltonearabic'] = 0x06C1;
  6790. t['habengali'] = 0x09B9;
  6791. t['hadescendercyrillic'] = 0x04B3;
  6792. t['hadeva'] = 0x0939;
  6793. t['hagujarati'] = 0x0AB9;
  6794. t['hagurmukhi'] = 0x0A39;
  6795. t['haharabic'] = 0x062D;
  6796. t['hahfinalarabic'] = 0xFEA2;
  6797. t['hahinitialarabic'] = 0xFEA3;
  6798. t['hahiragana'] = 0x306F;
  6799. t['hahmedialarabic'] = 0xFEA4;
  6800. t['haitusquare'] = 0x332A;
  6801. t['hakatakana'] = 0x30CF;
  6802. t['hakatakanahalfwidth'] = 0xFF8A;
  6803. t['halantgurmukhi'] = 0x0A4D;
  6804. t['hamzaarabic'] = 0x0621;
  6805. t['hamzalowarabic'] = 0x0621;
  6806. t['hangulfiller'] = 0x3164;
  6807. t['hardsigncyrillic'] = 0x044A;
  6808. t['harpoonleftbarbup'] = 0x21BC;
  6809. t['harpoonrightbarbup'] = 0x21C0;
  6810. t['hasquare'] = 0x33CA;
  6811. t['hatafpatah'] = 0x05B2;
  6812. t['hatafpatah16'] = 0x05B2;
  6813. t['hatafpatah23'] = 0x05B2;
  6814. t['hatafpatah2f'] = 0x05B2;
  6815. t['hatafpatahhebrew'] = 0x05B2;
  6816. t['hatafpatahnarrowhebrew'] = 0x05B2;
  6817. t['hatafpatahquarterhebrew'] = 0x05B2;
  6818. t['hatafpatahwidehebrew'] = 0x05B2;
  6819. t['hatafqamats'] = 0x05B3;
  6820. t['hatafqamats1b'] = 0x05B3;
  6821. t['hatafqamats28'] = 0x05B3;
  6822. t['hatafqamats34'] = 0x05B3;
  6823. t['hatafqamatshebrew'] = 0x05B3;
  6824. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  6825. t['hatafqamatsquarterhebrew'] = 0x05B3;
  6826. t['hatafqamatswidehebrew'] = 0x05B3;
  6827. t['hatafsegol'] = 0x05B1;
  6828. t['hatafsegol17'] = 0x05B1;
  6829. t['hatafsegol24'] = 0x05B1;
  6830. t['hatafsegol30'] = 0x05B1;
  6831. t['hatafsegolhebrew'] = 0x05B1;
  6832. t['hatafsegolnarrowhebrew'] = 0x05B1;
  6833. t['hatafsegolquarterhebrew'] = 0x05B1;
  6834. t['hatafsegolwidehebrew'] = 0x05B1;
  6835. t['hbar'] = 0x0127;
  6836. t['hbopomofo'] = 0x310F;
  6837. t['hbrevebelow'] = 0x1E2B;
  6838. t['hcedilla'] = 0x1E29;
  6839. t['hcircle'] = 0x24D7;
  6840. t['hcircumflex'] = 0x0125;
  6841. t['hdieresis'] = 0x1E27;
  6842. t['hdotaccent'] = 0x1E23;
  6843. t['hdotbelow'] = 0x1E25;
  6844. t['he'] = 0x05D4;
  6845. t['heart'] = 0x2665;
  6846. t['heartsuitblack'] = 0x2665;
  6847. t['heartsuitwhite'] = 0x2661;
  6848. t['hedagesh'] = 0xFB34;
  6849. t['hedageshhebrew'] = 0xFB34;
  6850. t['hehaltonearabic'] = 0x06C1;
  6851. t['heharabic'] = 0x0647;
  6852. t['hehebrew'] = 0x05D4;
  6853. t['hehfinalaltonearabic'] = 0xFBA7;
  6854. t['hehfinalalttwoarabic'] = 0xFEEA;
  6855. t['hehfinalarabic'] = 0xFEEA;
  6856. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  6857. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  6858. t['hehinitialaltonearabic'] = 0xFBA8;
  6859. t['hehinitialarabic'] = 0xFEEB;
  6860. t['hehiragana'] = 0x3078;
  6861. t['hehmedialaltonearabic'] = 0xFBA9;
  6862. t['hehmedialarabic'] = 0xFEEC;
  6863. t['heiseierasquare'] = 0x337B;
  6864. t['hekatakana'] = 0x30D8;
  6865. t['hekatakanahalfwidth'] = 0xFF8D;
  6866. t['hekutaarusquare'] = 0x3336;
  6867. t['henghook'] = 0x0267;
  6868. t['herutusquare'] = 0x3339;
  6869. t['het'] = 0x05D7;
  6870. t['hethebrew'] = 0x05D7;
  6871. t['hhook'] = 0x0266;
  6872. t['hhooksuperior'] = 0x02B1;
  6873. t['hieuhacirclekorean'] = 0x327B;
  6874. t['hieuhaparenkorean'] = 0x321B;
  6875. t['hieuhcirclekorean'] = 0x326D;
  6876. t['hieuhkorean'] = 0x314E;
  6877. t['hieuhparenkorean'] = 0x320D;
  6878. t['hihiragana'] = 0x3072;
  6879. t['hikatakana'] = 0x30D2;
  6880. t['hikatakanahalfwidth'] = 0xFF8B;
  6881. t['hiriq'] = 0x05B4;
  6882. t['hiriq14'] = 0x05B4;
  6883. t['hiriq21'] = 0x05B4;
  6884. t['hiriq2d'] = 0x05B4;
  6885. t['hiriqhebrew'] = 0x05B4;
  6886. t['hiriqnarrowhebrew'] = 0x05B4;
  6887. t['hiriqquarterhebrew'] = 0x05B4;
  6888. t['hiriqwidehebrew'] = 0x05B4;
  6889. t['hlinebelow'] = 0x1E96;
  6890. t['hmonospace'] = 0xFF48;
  6891. t['hoarmenian'] = 0x0570;
  6892. t['hohipthai'] = 0x0E2B;
  6893. t['hohiragana'] = 0x307B;
  6894. t['hokatakana'] = 0x30DB;
  6895. t['hokatakanahalfwidth'] = 0xFF8E;
  6896. t['holam'] = 0x05B9;
  6897. t['holam19'] = 0x05B9;
  6898. t['holam26'] = 0x05B9;
  6899. t['holam32'] = 0x05B9;
  6900. t['holamhebrew'] = 0x05B9;
  6901. t['holamnarrowhebrew'] = 0x05B9;
  6902. t['holamquarterhebrew'] = 0x05B9;
  6903. t['holamwidehebrew'] = 0x05B9;
  6904. t['honokhukthai'] = 0x0E2E;
  6905. t['hookabovecomb'] = 0x0309;
  6906. t['hookcmb'] = 0x0309;
  6907. t['hookpalatalizedbelowcmb'] = 0x0321;
  6908. t['hookretroflexbelowcmb'] = 0x0322;
  6909. t['hoonsquare'] = 0x3342;
  6910. t['horicoptic'] = 0x03E9;
  6911. t['horizontalbar'] = 0x2015;
  6912. t['horncmb'] = 0x031B;
  6913. t['hotsprings'] = 0x2668;
  6914. t['house'] = 0x2302;
  6915. t['hparen'] = 0x24A3;
  6916. t['hsuperior'] = 0x02B0;
  6917. t['hturned'] = 0x0265;
  6918. t['huhiragana'] = 0x3075;
  6919. t['huiitosquare'] = 0x3333;
  6920. t['hukatakana'] = 0x30D5;
  6921. t['hukatakanahalfwidth'] = 0xFF8C;
  6922. t['hungarumlaut'] = 0x02DD;
  6923. t['hungarumlautcmb'] = 0x030B;
  6924. t['hv'] = 0x0195;
  6925. t['hyphen'] = 0x002D;
  6926. t['hypheninferior'] = 0xF6E5;
  6927. t['hyphenmonospace'] = 0xFF0D;
  6928. t['hyphensmall'] = 0xFE63;
  6929. t['hyphensuperior'] = 0xF6E6;
  6930. t['hyphentwo'] = 0x2010;
  6931. t['i'] = 0x0069;
  6932. t['iacute'] = 0x00ED;
  6933. t['iacyrillic'] = 0x044F;
  6934. t['ibengali'] = 0x0987;
  6935. t['ibopomofo'] = 0x3127;
  6936. t['ibreve'] = 0x012D;
  6937. t['icaron'] = 0x01D0;
  6938. t['icircle'] = 0x24D8;
  6939. t['icircumflex'] = 0x00EE;
  6940. t['icyrillic'] = 0x0456;
  6941. t['idblgrave'] = 0x0209;
  6942. t['ideographearthcircle'] = 0x328F;
  6943. t['ideographfirecircle'] = 0x328B;
  6944. t['ideographicallianceparen'] = 0x323F;
  6945. t['ideographiccallparen'] = 0x323A;
  6946. t['ideographiccentrecircle'] = 0x32A5;
  6947. t['ideographicclose'] = 0x3006;
  6948. t['ideographiccomma'] = 0x3001;
  6949. t['ideographiccommaleft'] = 0xFF64;
  6950. t['ideographiccongratulationparen'] = 0x3237;
  6951. t['ideographiccorrectcircle'] = 0x32A3;
  6952. t['ideographicearthparen'] = 0x322F;
  6953. t['ideographicenterpriseparen'] = 0x323D;
  6954. t['ideographicexcellentcircle'] = 0x329D;
  6955. t['ideographicfestivalparen'] = 0x3240;
  6956. t['ideographicfinancialcircle'] = 0x3296;
  6957. t['ideographicfinancialparen'] = 0x3236;
  6958. t['ideographicfireparen'] = 0x322B;
  6959. t['ideographichaveparen'] = 0x3232;
  6960. t['ideographichighcircle'] = 0x32A4;
  6961. t['ideographiciterationmark'] = 0x3005;
  6962. t['ideographiclaborcircle'] = 0x3298;
  6963. t['ideographiclaborparen'] = 0x3238;
  6964. t['ideographicleftcircle'] = 0x32A7;
  6965. t['ideographiclowcircle'] = 0x32A6;
  6966. t['ideographicmedicinecircle'] = 0x32A9;
  6967. t['ideographicmetalparen'] = 0x322E;
  6968. t['ideographicmoonparen'] = 0x322A;
  6969. t['ideographicnameparen'] = 0x3234;
  6970. t['ideographicperiod'] = 0x3002;
  6971. t['ideographicprintcircle'] = 0x329E;
  6972. t['ideographicreachparen'] = 0x3243;
  6973. t['ideographicrepresentparen'] = 0x3239;
  6974. t['ideographicresourceparen'] = 0x323E;
  6975. t['ideographicrightcircle'] = 0x32A8;
  6976. t['ideographicsecretcircle'] = 0x3299;
  6977. t['ideographicselfparen'] = 0x3242;
  6978. t['ideographicsocietyparen'] = 0x3233;
  6979. t['ideographicspace'] = 0x3000;
  6980. t['ideographicspecialparen'] = 0x3235;
  6981. t['ideographicstockparen'] = 0x3231;
  6982. t['ideographicstudyparen'] = 0x323B;
  6983. t['ideographicsunparen'] = 0x3230;
  6984. t['ideographicsuperviseparen'] = 0x323C;
  6985. t['ideographicwaterparen'] = 0x322C;
  6986. t['ideographicwoodparen'] = 0x322D;
  6987. t['ideographiczero'] = 0x3007;
  6988. t['ideographmetalcircle'] = 0x328E;
  6989. t['ideographmooncircle'] = 0x328A;
  6990. t['ideographnamecircle'] = 0x3294;
  6991. t['ideographsuncircle'] = 0x3290;
  6992. t['ideographwatercircle'] = 0x328C;
  6993. t['ideographwoodcircle'] = 0x328D;
  6994. t['ideva'] = 0x0907;
  6995. t['idieresis'] = 0x00EF;
  6996. t['idieresisacute'] = 0x1E2F;
  6997. t['idieresiscyrillic'] = 0x04E5;
  6998. t['idotbelow'] = 0x1ECB;
  6999. t['iebrevecyrillic'] = 0x04D7;
  7000. t['iecyrillic'] = 0x0435;
  7001. t['ieungacirclekorean'] = 0x3275;
  7002. t['ieungaparenkorean'] = 0x3215;
  7003. t['ieungcirclekorean'] = 0x3267;
  7004. t['ieungkorean'] = 0x3147;
  7005. t['ieungparenkorean'] = 0x3207;
  7006. t['igrave'] = 0x00EC;
  7007. t['igujarati'] = 0x0A87;
  7008. t['igurmukhi'] = 0x0A07;
  7009. t['ihiragana'] = 0x3044;
  7010. t['ihookabove'] = 0x1EC9;
  7011. t['iibengali'] = 0x0988;
  7012. t['iicyrillic'] = 0x0438;
  7013. t['iideva'] = 0x0908;
  7014. t['iigujarati'] = 0x0A88;
  7015. t['iigurmukhi'] = 0x0A08;
  7016. t['iimatragurmukhi'] = 0x0A40;
  7017. t['iinvertedbreve'] = 0x020B;
  7018. t['iishortcyrillic'] = 0x0439;
  7019. t['iivowelsignbengali'] = 0x09C0;
  7020. t['iivowelsigndeva'] = 0x0940;
  7021. t['iivowelsigngujarati'] = 0x0AC0;
  7022. t['ij'] = 0x0133;
  7023. t['ikatakana'] = 0x30A4;
  7024. t['ikatakanahalfwidth'] = 0xFF72;
  7025. t['ikorean'] = 0x3163;
  7026. t['ilde'] = 0x02DC;
  7027. t['iluyhebrew'] = 0x05AC;
  7028. t['imacron'] = 0x012B;
  7029. t['imacroncyrillic'] = 0x04E3;
  7030. t['imageorapproximatelyequal'] = 0x2253;
  7031. t['imatragurmukhi'] = 0x0A3F;
  7032. t['imonospace'] = 0xFF49;
  7033. t['increment'] = 0x2206;
  7034. t['infinity'] = 0x221E;
  7035. t['iniarmenian'] = 0x056B;
  7036. t['integral'] = 0x222B;
  7037. t['integralbottom'] = 0x2321;
  7038. t['integralbt'] = 0x2321;
  7039. t['integralex'] = 0xF8F5;
  7040. t['integraltop'] = 0x2320;
  7041. t['integraltp'] = 0x2320;
  7042. t['intersection'] = 0x2229;
  7043. t['intisquare'] = 0x3305;
  7044. t['invbullet'] = 0x25D8;
  7045. t['invcircle'] = 0x25D9;
  7046. t['invsmileface'] = 0x263B;
  7047. t['iocyrillic'] = 0x0451;
  7048. t['iogonek'] = 0x012F;
  7049. t['iota'] = 0x03B9;
  7050. t['iotadieresis'] = 0x03CA;
  7051. t['iotadieresistonos'] = 0x0390;
  7052. t['iotalatin'] = 0x0269;
  7053. t['iotatonos'] = 0x03AF;
  7054. t['iparen'] = 0x24A4;
  7055. t['irigurmukhi'] = 0x0A72;
  7056. t['ismallhiragana'] = 0x3043;
  7057. t['ismallkatakana'] = 0x30A3;
  7058. t['ismallkatakanahalfwidth'] = 0xFF68;
  7059. t['issharbengali'] = 0x09FA;
  7060. t['istroke'] = 0x0268;
  7061. t['isuperior'] = 0xF6ED;
  7062. t['iterationhiragana'] = 0x309D;
  7063. t['iterationkatakana'] = 0x30FD;
  7064. t['itilde'] = 0x0129;
  7065. t['itildebelow'] = 0x1E2D;
  7066. t['iubopomofo'] = 0x3129;
  7067. t['iucyrillic'] = 0x044E;
  7068. t['ivowelsignbengali'] = 0x09BF;
  7069. t['ivowelsigndeva'] = 0x093F;
  7070. t['ivowelsigngujarati'] = 0x0ABF;
  7071. t['izhitsacyrillic'] = 0x0475;
  7072. t['izhitsadblgravecyrillic'] = 0x0477;
  7073. t['j'] = 0x006A;
  7074. t['jaarmenian'] = 0x0571;
  7075. t['jabengali'] = 0x099C;
  7076. t['jadeva'] = 0x091C;
  7077. t['jagujarati'] = 0x0A9C;
  7078. t['jagurmukhi'] = 0x0A1C;
  7079. t['jbopomofo'] = 0x3110;
  7080. t['jcaron'] = 0x01F0;
  7081. t['jcircle'] = 0x24D9;
  7082. t['jcircumflex'] = 0x0135;
  7083. t['jcrossedtail'] = 0x029D;
  7084. t['jdotlessstroke'] = 0x025F;
  7085. t['jecyrillic'] = 0x0458;
  7086. t['jeemarabic'] = 0x062C;
  7087. t['jeemfinalarabic'] = 0xFE9E;
  7088. t['jeeminitialarabic'] = 0xFE9F;
  7089. t['jeemmedialarabic'] = 0xFEA0;
  7090. t['jeharabic'] = 0x0698;
  7091. t['jehfinalarabic'] = 0xFB8B;
  7092. t['jhabengali'] = 0x099D;
  7093. t['jhadeva'] = 0x091D;
  7094. t['jhagujarati'] = 0x0A9D;
  7095. t['jhagurmukhi'] = 0x0A1D;
  7096. t['jheharmenian'] = 0x057B;
  7097. t['jis'] = 0x3004;
  7098. t['jmonospace'] = 0xFF4A;
  7099. t['jparen'] = 0x24A5;
  7100. t['jsuperior'] = 0x02B2;
  7101. t['k'] = 0x006B;
  7102. t['kabashkircyrillic'] = 0x04A1;
  7103. t['kabengali'] = 0x0995;
  7104. t['kacute'] = 0x1E31;
  7105. t['kacyrillic'] = 0x043A;
  7106. t['kadescendercyrillic'] = 0x049B;
  7107. t['kadeva'] = 0x0915;
  7108. t['kaf'] = 0x05DB;
  7109. t['kafarabic'] = 0x0643;
  7110. t['kafdagesh'] = 0xFB3B;
  7111. t['kafdageshhebrew'] = 0xFB3B;
  7112. t['kaffinalarabic'] = 0xFEDA;
  7113. t['kafhebrew'] = 0x05DB;
  7114. t['kafinitialarabic'] = 0xFEDB;
  7115. t['kafmedialarabic'] = 0xFEDC;
  7116. t['kafrafehebrew'] = 0xFB4D;
  7117. t['kagujarati'] = 0x0A95;
  7118. t['kagurmukhi'] = 0x0A15;
  7119. t['kahiragana'] = 0x304B;
  7120. t['kahookcyrillic'] = 0x04C4;
  7121. t['kakatakana'] = 0x30AB;
  7122. t['kakatakanahalfwidth'] = 0xFF76;
  7123. t['kappa'] = 0x03BA;
  7124. t['kappasymbolgreek'] = 0x03F0;
  7125. t['kapyeounmieumkorean'] = 0x3171;
  7126. t['kapyeounphieuphkorean'] = 0x3184;
  7127. t['kapyeounpieupkorean'] = 0x3178;
  7128. t['kapyeounssangpieupkorean'] = 0x3179;
  7129. t['karoriisquare'] = 0x330D;
  7130. t['kashidaautoarabic'] = 0x0640;
  7131. t['kashidaautonosidebearingarabic'] = 0x0640;
  7132. t['kasmallkatakana'] = 0x30F5;
  7133. t['kasquare'] = 0x3384;
  7134. t['kasraarabic'] = 0x0650;
  7135. t['kasratanarabic'] = 0x064D;
  7136. t['kastrokecyrillic'] = 0x049F;
  7137. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  7138. t['kaverticalstrokecyrillic'] = 0x049D;
  7139. t['kbopomofo'] = 0x310E;
  7140. t['kcalsquare'] = 0x3389;
  7141. t['kcaron'] = 0x01E9;
  7142. t['kcedilla'] = 0x0137;
  7143. t['kcircle'] = 0x24DA;
  7144. t['kcommaaccent'] = 0x0137;
  7145. t['kdotbelow'] = 0x1E33;
  7146. t['keharmenian'] = 0x0584;
  7147. t['kehiragana'] = 0x3051;
  7148. t['kekatakana'] = 0x30B1;
  7149. t['kekatakanahalfwidth'] = 0xFF79;
  7150. t['kenarmenian'] = 0x056F;
  7151. t['kesmallkatakana'] = 0x30F6;
  7152. t['kgreenlandic'] = 0x0138;
  7153. t['khabengali'] = 0x0996;
  7154. t['khacyrillic'] = 0x0445;
  7155. t['khadeva'] = 0x0916;
  7156. t['khagujarati'] = 0x0A96;
  7157. t['khagurmukhi'] = 0x0A16;
  7158. t['khaharabic'] = 0x062E;
  7159. t['khahfinalarabic'] = 0xFEA6;
  7160. t['khahinitialarabic'] = 0xFEA7;
  7161. t['khahmedialarabic'] = 0xFEA8;
  7162. t['kheicoptic'] = 0x03E7;
  7163. t['khhadeva'] = 0x0959;
  7164. t['khhagurmukhi'] = 0x0A59;
  7165. t['khieukhacirclekorean'] = 0x3278;
  7166. t['khieukhaparenkorean'] = 0x3218;
  7167. t['khieukhcirclekorean'] = 0x326A;
  7168. t['khieukhkorean'] = 0x314B;
  7169. t['khieukhparenkorean'] = 0x320A;
  7170. t['khokhaithai'] = 0x0E02;
  7171. t['khokhonthai'] = 0x0E05;
  7172. t['khokhuatthai'] = 0x0E03;
  7173. t['khokhwaithai'] = 0x0E04;
  7174. t['khomutthai'] = 0x0E5B;
  7175. t['khook'] = 0x0199;
  7176. t['khorakhangthai'] = 0x0E06;
  7177. t['khzsquare'] = 0x3391;
  7178. t['kihiragana'] = 0x304D;
  7179. t['kikatakana'] = 0x30AD;
  7180. t['kikatakanahalfwidth'] = 0xFF77;
  7181. t['kiroguramusquare'] = 0x3315;
  7182. t['kiromeetorusquare'] = 0x3316;
  7183. t['kirosquare'] = 0x3314;
  7184. t['kiyeokacirclekorean'] = 0x326E;
  7185. t['kiyeokaparenkorean'] = 0x320E;
  7186. t['kiyeokcirclekorean'] = 0x3260;
  7187. t['kiyeokkorean'] = 0x3131;
  7188. t['kiyeokparenkorean'] = 0x3200;
  7189. t['kiyeoksioskorean'] = 0x3133;
  7190. t['kjecyrillic'] = 0x045C;
  7191. t['klinebelow'] = 0x1E35;
  7192. t['klsquare'] = 0x3398;
  7193. t['kmcubedsquare'] = 0x33A6;
  7194. t['kmonospace'] = 0xFF4B;
  7195. t['kmsquaredsquare'] = 0x33A2;
  7196. t['kohiragana'] = 0x3053;
  7197. t['kohmsquare'] = 0x33C0;
  7198. t['kokaithai'] = 0x0E01;
  7199. t['kokatakana'] = 0x30B3;
  7200. t['kokatakanahalfwidth'] = 0xFF7A;
  7201. t['kooposquare'] = 0x331E;
  7202. t['koppacyrillic'] = 0x0481;
  7203. t['koreanstandardsymbol'] = 0x327F;
  7204. t['koroniscmb'] = 0x0343;
  7205. t['kparen'] = 0x24A6;
  7206. t['kpasquare'] = 0x33AA;
  7207. t['ksicyrillic'] = 0x046F;
  7208. t['ktsquare'] = 0x33CF;
  7209. t['kturned'] = 0x029E;
  7210. t['kuhiragana'] = 0x304F;
  7211. t['kukatakana'] = 0x30AF;
  7212. t['kukatakanahalfwidth'] = 0xFF78;
  7213. t['kvsquare'] = 0x33B8;
  7214. t['kwsquare'] = 0x33BE;
  7215. t['l'] = 0x006C;
  7216. t['labengali'] = 0x09B2;
  7217. t['lacute'] = 0x013A;
  7218. t['ladeva'] = 0x0932;
  7219. t['lagujarati'] = 0x0AB2;
  7220. t['lagurmukhi'] = 0x0A32;
  7221. t['lakkhangyaothai'] = 0x0E45;
  7222. t['lamaleffinalarabic'] = 0xFEFC;
  7223. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  7224. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  7225. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  7226. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  7227. t['lamalefisolatedarabic'] = 0xFEFB;
  7228. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  7229. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  7230. t['lamarabic'] = 0x0644;
  7231. t['lambda'] = 0x03BB;
  7232. t['lambdastroke'] = 0x019B;
  7233. t['lamed'] = 0x05DC;
  7234. t['lameddagesh'] = 0xFB3C;
  7235. t['lameddageshhebrew'] = 0xFB3C;
  7236. t['lamedhebrew'] = 0x05DC;
  7237. t['lamfinalarabic'] = 0xFEDE;
  7238. t['lamhahinitialarabic'] = 0xFCCA;
  7239. t['laminitialarabic'] = 0xFEDF;
  7240. t['lamjeeminitialarabic'] = 0xFCC9;
  7241. t['lamkhahinitialarabic'] = 0xFCCB;
  7242. t['lamlamhehisolatedarabic'] = 0xFDF2;
  7243. t['lammedialarabic'] = 0xFEE0;
  7244. t['lammeemhahinitialarabic'] = 0xFD88;
  7245. t['lammeeminitialarabic'] = 0xFCCC;
  7246. t['largecircle'] = 0x25EF;
  7247. t['lbar'] = 0x019A;
  7248. t['lbelt'] = 0x026C;
  7249. t['lbopomofo'] = 0x310C;
  7250. t['lcaron'] = 0x013E;
  7251. t['lcedilla'] = 0x013C;
  7252. t['lcircle'] = 0x24DB;
  7253. t['lcircumflexbelow'] = 0x1E3D;
  7254. t['lcommaaccent'] = 0x013C;
  7255. t['ldot'] = 0x0140;
  7256. t['ldotaccent'] = 0x0140;
  7257. t['ldotbelow'] = 0x1E37;
  7258. t['ldotbelowmacron'] = 0x1E39;
  7259. t['leftangleabovecmb'] = 0x031A;
  7260. t['lefttackbelowcmb'] = 0x0318;
  7261. t['less'] = 0x003C;
  7262. t['lessequal'] = 0x2264;
  7263. t['lessequalorgreater'] = 0x22DA;
  7264. t['lessmonospace'] = 0xFF1C;
  7265. t['lessorequivalent'] = 0x2272;
  7266. t['lessorgreater'] = 0x2276;
  7267. t['lessoverequal'] = 0x2266;
  7268. t['lesssmall'] = 0xFE64;
  7269. t['lezh'] = 0x026E;
  7270. t['lfblock'] = 0x258C;
  7271. t['lhookretroflex'] = 0x026D;
  7272. t['lira'] = 0x20A4;
  7273. t['liwnarmenian'] = 0x056C;
  7274. t['lj'] = 0x01C9;
  7275. t['ljecyrillic'] = 0x0459;
  7276. t['ll'] = 0xF6C0;
  7277. t['lladeva'] = 0x0933;
  7278. t['llagujarati'] = 0x0AB3;
  7279. t['llinebelow'] = 0x1E3B;
  7280. t['llladeva'] = 0x0934;
  7281. t['llvocalicbengali'] = 0x09E1;
  7282. t['llvocalicdeva'] = 0x0961;
  7283. t['llvocalicvowelsignbengali'] = 0x09E3;
  7284. t['llvocalicvowelsigndeva'] = 0x0963;
  7285. t['lmiddletilde'] = 0x026B;
  7286. t['lmonospace'] = 0xFF4C;
  7287. t['lmsquare'] = 0x33D0;
  7288. t['lochulathai'] = 0x0E2C;
  7289. t['logicaland'] = 0x2227;
  7290. t['logicalnot'] = 0x00AC;
  7291. t['logicalnotreversed'] = 0x2310;
  7292. t['logicalor'] = 0x2228;
  7293. t['lolingthai'] = 0x0E25;
  7294. t['longs'] = 0x017F;
  7295. t['lowlinecenterline'] = 0xFE4E;
  7296. t['lowlinecmb'] = 0x0332;
  7297. t['lowlinedashed'] = 0xFE4D;
  7298. t['lozenge'] = 0x25CA;
  7299. t['lparen'] = 0x24A7;
  7300. t['lslash'] = 0x0142;
  7301. t['lsquare'] = 0x2113;
  7302. t['lsuperior'] = 0xF6EE;
  7303. t['ltshade'] = 0x2591;
  7304. t['luthai'] = 0x0E26;
  7305. t['lvocalicbengali'] = 0x098C;
  7306. t['lvocalicdeva'] = 0x090C;
  7307. t['lvocalicvowelsignbengali'] = 0x09E2;
  7308. t['lvocalicvowelsigndeva'] = 0x0962;
  7309. t['lxsquare'] = 0x33D3;
  7310. t['m'] = 0x006D;
  7311. t['mabengali'] = 0x09AE;
  7312. t['macron'] = 0x00AF;
  7313. t['macronbelowcmb'] = 0x0331;
  7314. t['macroncmb'] = 0x0304;
  7315. t['macronlowmod'] = 0x02CD;
  7316. t['macronmonospace'] = 0xFFE3;
  7317. t['macute'] = 0x1E3F;
  7318. t['madeva'] = 0x092E;
  7319. t['magujarati'] = 0x0AAE;
  7320. t['magurmukhi'] = 0x0A2E;
  7321. t['mahapakhhebrew'] = 0x05A4;
  7322. t['mahapakhlefthebrew'] = 0x05A4;
  7323. t['mahiragana'] = 0x307E;
  7324. t['maichattawalowleftthai'] = 0xF895;
  7325. t['maichattawalowrightthai'] = 0xF894;
  7326. t['maichattawathai'] = 0x0E4B;
  7327. t['maichattawaupperleftthai'] = 0xF893;
  7328. t['maieklowleftthai'] = 0xF88C;
  7329. t['maieklowrightthai'] = 0xF88B;
  7330. t['maiekthai'] = 0x0E48;
  7331. t['maiekupperleftthai'] = 0xF88A;
  7332. t['maihanakatleftthai'] = 0xF884;
  7333. t['maihanakatthai'] = 0x0E31;
  7334. t['maitaikhuleftthai'] = 0xF889;
  7335. t['maitaikhuthai'] = 0x0E47;
  7336. t['maitholowleftthai'] = 0xF88F;
  7337. t['maitholowrightthai'] = 0xF88E;
  7338. t['maithothai'] = 0x0E49;
  7339. t['maithoupperleftthai'] = 0xF88D;
  7340. t['maitrilowleftthai'] = 0xF892;
  7341. t['maitrilowrightthai'] = 0xF891;
  7342. t['maitrithai'] = 0x0E4A;
  7343. t['maitriupperleftthai'] = 0xF890;
  7344. t['maiyamokthai'] = 0x0E46;
  7345. t['makatakana'] = 0x30DE;
  7346. t['makatakanahalfwidth'] = 0xFF8F;
  7347. t['male'] = 0x2642;
  7348. t['mansyonsquare'] = 0x3347;
  7349. t['maqafhebrew'] = 0x05BE;
  7350. t['mars'] = 0x2642;
  7351. t['masoracirclehebrew'] = 0x05AF;
  7352. t['masquare'] = 0x3383;
  7353. t['mbopomofo'] = 0x3107;
  7354. t['mbsquare'] = 0x33D4;
  7355. t['mcircle'] = 0x24DC;
  7356. t['mcubedsquare'] = 0x33A5;
  7357. t['mdotaccent'] = 0x1E41;
  7358. t['mdotbelow'] = 0x1E43;
  7359. t['meemarabic'] = 0x0645;
  7360. t['meemfinalarabic'] = 0xFEE2;
  7361. t['meeminitialarabic'] = 0xFEE3;
  7362. t['meemmedialarabic'] = 0xFEE4;
  7363. t['meemmeeminitialarabic'] = 0xFCD1;
  7364. t['meemmeemisolatedarabic'] = 0xFC48;
  7365. t['meetorusquare'] = 0x334D;
  7366. t['mehiragana'] = 0x3081;
  7367. t['meizierasquare'] = 0x337E;
  7368. t['mekatakana'] = 0x30E1;
  7369. t['mekatakanahalfwidth'] = 0xFF92;
  7370. t['mem'] = 0x05DE;
  7371. t['memdagesh'] = 0xFB3E;
  7372. t['memdageshhebrew'] = 0xFB3E;
  7373. t['memhebrew'] = 0x05DE;
  7374. t['menarmenian'] = 0x0574;
  7375. t['merkhahebrew'] = 0x05A5;
  7376. t['merkhakefulahebrew'] = 0x05A6;
  7377. t['merkhakefulalefthebrew'] = 0x05A6;
  7378. t['merkhalefthebrew'] = 0x05A5;
  7379. t['mhook'] = 0x0271;
  7380. t['mhzsquare'] = 0x3392;
  7381. t['middledotkatakanahalfwidth'] = 0xFF65;
  7382. t['middot'] = 0x00B7;
  7383. t['mieumacirclekorean'] = 0x3272;
  7384. t['mieumaparenkorean'] = 0x3212;
  7385. t['mieumcirclekorean'] = 0x3264;
  7386. t['mieumkorean'] = 0x3141;
  7387. t['mieumpansioskorean'] = 0x3170;
  7388. t['mieumparenkorean'] = 0x3204;
  7389. t['mieumpieupkorean'] = 0x316E;
  7390. t['mieumsioskorean'] = 0x316F;
  7391. t['mihiragana'] = 0x307F;
  7392. t['mikatakana'] = 0x30DF;
  7393. t['mikatakanahalfwidth'] = 0xFF90;
  7394. t['minus'] = 0x2212;
  7395. t['minusbelowcmb'] = 0x0320;
  7396. t['minuscircle'] = 0x2296;
  7397. t['minusmod'] = 0x02D7;
  7398. t['minusplus'] = 0x2213;
  7399. t['minute'] = 0x2032;
  7400. t['miribaarusquare'] = 0x334A;
  7401. t['mirisquare'] = 0x3349;
  7402. t['mlonglegturned'] = 0x0270;
  7403. t['mlsquare'] = 0x3396;
  7404. t['mmcubedsquare'] = 0x33A3;
  7405. t['mmonospace'] = 0xFF4D;
  7406. t['mmsquaredsquare'] = 0x339F;
  7407. t['mohiragana'] = 0x3082;
  7408. t['mohmsquare'] = 0x33C1;
  7409. t['mokatakana'] = 0x30E2;
  7410. t['mokatakanahalfwidth'] = 0xFF93;
  7411. t['molsquare'] = 0x33D6;
  7412. t['momathai'] = 0x0E21;
  7413. t['moverssquare'] = 0x33A7;
  7414. t['moverssquaredsquare'] = 0x33A8;
  7415. t['mparen'] = 0x24A8;
  7416. t['mpasquare'] = 0x33AB;
  7417. t['mssquare'] = 0x33B3;
  7418. t['msuperior'] = 0xF6EF;
  7419. t['mturned'] = 0x026F;
  7420. t['mu'] = 0x00B5;
  7421. t['mu1'] = 0x00B5;
  7422. t['muasquare'] = 0x3382;
  7423. t['muchgreater'] = 0x226B;
  7424. t['muchless'] = 0x226A;
  7425. t['mufsquare'] = 0x338C;
  7426. t['mugreek'] = 0x03BC;
  7427. t['mugsquare'] = 0x338D;
  7428. t['muhiragana'] = 0x3080;
  7429. t['mukatakana'] = 0x30E0;
  7430. t['mukatakanahalfwidth'] = 0xFF91;
  7431. t['mulsquare'] = 0x3395;
  7432. t['multiply'] = 0x00D7;
  7433. t['mumsquare'] = 0x339B;
  7434. t['munahhebrew'] = 0x05A3;
  7435. t['munahlefthebrew'] = 0x05A3;
  7436. t['musicalnote'] = 0x266A;
  7437. t['musicalnotedbl'] = 0x266B;
  7438. t['musicflatsign'] = 0x266D;
  7439. t['musicsharpsign'] = 0x266F;
  7440. t['mussquare'] = 0x33B2;
  7441. t['muvsquare'] = 0x33B6;
  7442. t['muwsquare'] = 0x33BC;
  7443. t['mvmegasquare'] = 0x33B9;
  7444. t['mvsquare'] = 0x33B7;
  7445. t['mwmegasquare'] = 0x33BF;
  7446. t['mwsquare'] = 0x33BD;
  7447. t['n'] = 0x006E;
  7448. t['nabengali'] = 0x09A8;
  7449. t['nabla'] = 0x2207;
  7450. t['nacute'] = 0x0144;
  7451. t['nadeva'] = 0x0928;
  7452. t['nagujarati'] = 0x0AA8;
  7453. t['nagurmukhi'] = 0x0A28;
  7454. t['nahiragana'] = 0x306A;
  7455. t['nakatakana'] = 0x30CA;
  7456. t['nakatakanahalfwidth'] = 0xFF85;
  7457. t['napostrophe'] = 0x0149;
  7458. t['nasquare'] = 0x3381;
  7459. t['nbopomofo'] = 0x310B;
  7460. t['nbspace'] = 0x00A0;
  7461. t['ncaron'] = 0x0148;
  7462. t['ncedilla'] = 0x0146;
  7463. t['ncircle'] = 0x24DD;
  7464. t['ncircumflexbelow'] = 0x1E4B;
  7465. t['ncommaaccent'] = 0x0146;
  7466. t['ndotaccent'] = 0x1E45;
  7467. t['ndotbelow'] = 0x1E47;
  7468. t['nehiragana'] = 0x306D;
  7469. t['nekatakana'] = 0x30CD;
  7470. t['nekatakanahalfwidth'] = 0xFF88;
  7471. t['newsheqelsign'] = 0x20AA;
  7472. t['nfsquare'] = 0x338B;
  7473. t['ngabengali'] = 0x0999;
  7474. t['ngadeva'] = 0x0919;
  7475. t['ngagujarati'] = 0x0A99;
  7476. t['ngagurmukhi'] = 0x0A19;
  7477. t['ngonguthai'] = 0x0E07;
  7478. t['nhiragana'] = 0x3093;
  7479. t['nhookleft'] = 0x0272;
  7480. t['nhookretroflex'] = 0x0273;
  7481. t['nieunacirclekorean'] = 0x326F;
  7482. t['nieunaparenkorean'] = 0x320F;
  7483. t['nieuncieuckorean'] = 0x3135;
  7484. t['nieuncirclekorean'] = 0x3261;
  7485. t['nieunhieuhkorean'] = 0x3136;
  7486. t['nieunkorean'] = 0x3134;
  7487. t['nieunpansioskorean'] = 0x3168;
  7488. t['nieunparenkorean'] = 0x3201;
  7489. t['nieunsioskorean'] = 0x3167;
  7490. t['nieuntikeutkorean'] = 0x3166;
  7491. t['nihiragana'] = 0x306B;
  7492. t['nikatakana'] = 0x30CB;
  7493. t['nikatakanahalfwidth'] = 0xFF86;
  7494. t['nikhahitleftthai'] = 0xF899;
  7495. t['nikhahitthai'] = 0x0E4D;
  7496. t['nine'] = 0x0039;
  7497. t['ninearabic'] = 0x0669;
  7498. t['ninebengali'] = 0x09EF;
  7499. t['ninecircle'] = 0x2468;
  7500. t['ninecircleinversesansserif'] = 0x2792;
  7501. t['ninedeva'] = 0x096F;
  7502. t['ninegujarati'] = 0x0AEF;
  7503. t['ninegurmukhi'] = 0x0A6F;
  7504. t['ninehackarabic'] = 0x0669;
  7505. t['ninehangzhou'] = 0x3029;
  7506. t['nineideographicparen'] = 0x3228;
  7507. t['nineinferior'] = 0x2089;
  7508. t['ninemonospace'] = 0xFF19;
  7509. t['nineoldstyle'] = 0xF739;
  7510. t['nineparen'] = 0x247C;
  7511. t['nineperiod'] = 0x2490;
  7512. t['ninepersian'] = 0x06F9;
  7513. t['nineroman'] = 0x2178;
  7514. t['ninesuperior'] = 0x2079;
  7515. t['nineteencircle'] = 0x2472;
  7516. t['nineteenparen'] = 0x2486;
  7517. t['nineteenperiod'] = 0x249A;
  7518. t['ninethai'] = 0x0E59;
  7519. t['nj'] = 0x01CC;
  7520. t['njecyrillic'] = 0x045A;
  7521. t['nkatakana'] = 0x30F3;
  7522. t['nkatakanahalfwidth'] = 0xFF9D;
  7523. t['nlegrightlong'] = 0x019E;
  7524. t['nlinebelow'] = 0x1E49;
  7525. t['nmonospace'] = 0xFF4E;
  7526. t['nmsquare'] = 0x339A;
  7527. t['nnabengali'] = 0x09A3;
  7528. t['nnadeva'] = 0x0923;
  7529. t['nnagujarati'] = 0x0AA3;
  7530. t['nnagurmukhi'] = 0x0A23;
  7531. t['nnnadeva'] = 0x0929;
  7532. t['nohiragana'] = 0x306E;
  7533. t['nokatakana'] = 0x30CE;
  7534. t['nokatakanahalfwidth'] = 0xFF89;
  7535. t['nonbreakingspace'] = 0x00A0;
  7536. t['nonenthai'] = 0x0E13;
  7537. t['nonuthai'] = 0x0E19;
  7538. t['noonarabic'] = 0x0646;
  7539. t['noonfinalarabic'] = 0xFEE6;
  7540. t['noonghunnaarabic'] = 0x06BA;
  7541. t['noonghunnafinalarabic'] = 0xFB9F;
  7542. t['nooninitialarabic'] = 0xFEE7;
  7543. t['noonjeeminitialarabic'] = 0xFCD2;
  7544. t['noonjeemisolatedarabic'] = 0xFC4B;
  7545. t['noonmedialarabic'] = 0xFEE8;
  7546. t['noonmeeminitialarabic'] = 0xFCD5;
  7547. t['noonmeemisolatedarabic'] = 0xFC4E;
  7548. t['noonnoonfinalarabic'] = 0xFC8D;
  7549. t['notcontains'] = 0x220C;
  7550. t['notelement'] = 0x2209;
  7551. t['notelementof'] = 0x2209;
  7552. t['notequal'] = 0x2260;
  7553. t['notgreater'] = 0x226F;
  7554. t['notgreaternorequal'] = 0x2271;
  7555. t['notgreaternorless'] = 0x2279;
  7556. t['notidentical'] = 0x2262;
  7557. t['notless'] = 0x226E;
  7558. t['notlessnorequal'] = 0x2270;
  7559. t['notparallel'] = 0x2226;
  7560. t['notprecedes'] = 0x2280;
  7561. t['notsubset'] = 0x2284;
  7562. t['notsucceeds'] = 0x2281;
  7563. t['notsuperset'] = 0x2285;
  7564. t['nowarmenian'] = 0x0576;
  7565. t['nparen'] = 0x24A9;
  7566. t['nssquare'] = 0x33B1;
  7567. t['nsuperior'] = 0x207F;
  7568. t['ntilde'] = 0x00F1;
  7569. t['nu'] = 0x03BD;
  7570. t['nuhiragana'] = 0x306C;
  7571. t['nukatakana'] = 0x30CC;
  7572. t['nukatakanahalfwidth'] = 0xFF87;
  7573. t['nuktabengali'] = 0x09BC;
  7574. t['nuktadeva'] = 0x093C;
  7575. t['nuktagujarati'] = 0x0ABC;
  7576. t['nuktagurmukhi'] = 0x0A3C;
  7577. t['numbersign'] = 0x0023;
  7578. t['numbersignmonospace'] = 0xFF03;
  7579. t['numbersignsmall'] = 0xFE5F;
  7580. t['numeralsigngreek'] = 0x0374;
  7581. t['numeralsignlowergreek'] = 0x0375;
  7582. t['numero'] = 0x2116;
  7583. t['nun'] = 0x05E0;
  7584. t['nundagesh'] = 0xFB40;
  7585. t['nundageshhebrew'] = 0xFB40;
  7586. t['nunhebrew'] = 0x05E0;
  7587. t['nvsquare'] = 0x33B5;
  7588. t['nwsquare'] = 0x33BB;
  7589. t['nyabengali'] = 0x099E;
  7590. t['nyadeva'] = 0x091E;
  7591. t['nyagujarati'] = 0x0A9E;
  7592. t['nyagurmukhi'] = 0x0A1E;
  7593. t['o'] = 0x006F;
  7594. t['oacute'] = 0x00F3;
  7595. t['oangthai'] = 0x0E2D;
  7596. t['obarred'] = 0x0275;
  7597. t['obarredcyrillic'] = 0x04E9;
  7598. t['obarreddieresiscyrillic'] = 0x04EB;
  7599. t['obengali'] = 0x0993;
  7600. t['obopomofo'] = 0x311B;
  7601. t['obreve'] = 0x014F;
  7602. t['ocandradeva'] = 0x0911;
  7603. t['ocandragujarati'] = 0x0A91;
  7604. t['ocandravowelsigndeva'] = 0x0949;
  7605. t['ocandravowelsigngujarati'] = 0x0AC9;
  7606. t['ocaron'] = 0x01D2;
  7607. t['ocircle'] = 0x24DE;
  7608. t['ocircumflex'] = 0x00F4;
  7609. t['ocircumflexacute'] = 0x1ED1;
  7610. t['ocircumflexdotbelow'] = 0x1ED9;
  7611. t['ocircumflexgrave'] = 0x1ED3;
  7612. t['ocircumflexhookabove'] = 0x1ED5;
  7613. t['ocircumflextilde'] = 0x1ED7;
  7614. t['ocyrillic'] = 0x043E;
  7615. t['odblacute'] = 0x0151;
  7616. t['odblgrave'] = 0x020D;
  7617. t['odeva'] = 0x0913;
  7618. t['odieresis'] = 0x00F6;
  7619. t['odieresiscyrillic'] = 0x04E7;
  7620. t['odotbelow'] = 0x1ECD;
  7621. t['oe'] = 0x0153;
  7622. t['oekorean'] = 0x315A;
  7623. t['ogonek'] = 0x02DB;
  7624. t['ogonekcmb'] = 0x0328;
  7625. t['ograve'] = 0x00F2;
  7626. t['ogujarati'] = 0x0A93;
  7627. t['oharmenian'] = 0x0585;
  7628. t['ohiragana'] = 0x304A;
  7629. t['ohookabove'] = 0x1ECF;
  7630. t['ohorn'] = 0x01A1;
  7631. t['ohornacute'] = 0x1EDB;
  7632. t['ohorndotbelow'] = 0x1EE3;
  7633. t['ohorngrave'] = 0x1EDD;
  7634. t['ohornhookabove'] = 0x1EDF;
  7635. t['ohorntilde'] = 0x1EE1;
  7636. t['ohungarumlaut'] = 0x0151;
  7637. t['oi'] = 0x01A3;
  7638. t['oinvertedbreve'] = 0x020F;
  7639. t['okatakana'] = 0x30AA;
  7640. t['okatakanahalfwidth'] = 0xFF75;
  7641. t['okorean'] = 0x3157;
  7642. t['olehebrew'] = 0x05AB;
  7643. t['omacron'] = 0x014D;
  7644. t['omacronacute'] = 0x1E53;
  7645. t['omacrongrave'] = 0x1E51;
  7646. t['omdeva'] = 0x0950;
  7647. t['omega'] = 0x03C9;
  7648. t['omega1'] = 0x03D6;
  7649. t['omegacyrillic'] = 0x0461;
  7650. t['omegalatinclosed'] = 0x0277;
  7651. t['omegaroundcyrillic'] = 0x047B;
  7652. t['omegatitlocyrillic'] = 0x047D;
  7653. t['omegatonos'] = 0x03CE;
  7654. t['omgujarati'] = 0x0AD0;
  7655. t['omicron'] = 0x03BF;
  7656. t['omicrontonos'] = 0x03CC;
  7657. t['omonospace'] = 0xFF4F;
  7658. t['one'] = 0x0031;
  7659. t['onearabic'] = 0x0661;
  7660. t['onebengali'] = 0x09E7;
  7661. t['onecircle'] = 0x2460;
  7662. t['onecircleinversesansserif'] = 0x278A;
  7663. t['onedeva'] = 0x0967;
  7664. t['onedotenleader'] = 0x2024;
  7665. t['oneeighth'] = 0x215B;
  7666. t['onefitted'] = 0xF6DC;
  7667. t['onegujarati'] = 0x0AE7;
  7668. t['onegurmukhi'] = 0x0A67;
  7669. t['onehackarabic'] = 0x0661;
  7670. t['onehalf'] = 0x00BD;
  7671. t['onehangzhou'] = 0x3021;
  7672. t['oneideographicparen'] = 0x3220;
  7673. t['oneinferior'] = 0x2081;
  7674. t['onemonospace'] = 0xFF11;
  7675. t['onenumeratorbengali'] = 0x09F4;
  7676. t['oneoldstyle'] = 0xF731;
  7677. t['oneparen'] = 0x2474;
  7678. t['oneperiod'] = 0x2488;
  7679. t['onepersian'] = 0x06F1;
  7680. t['onequarter'] = 0x00BC;
  7681. t['oneroman'] = 0x2170;
  7682. t['onesuperior'] = 0x00B9;
  7683. t['onethai'] = 0x0E51;
  7684. t['onethird'] = 0x2153;
  7685. t['oogonek'] = 0x01EB;
  7686. t['oogonekmacron'] = 0x01ED;
  7687. t['oogurmukhi'] = 0x0A13;
  7688. t['oomatragurmukhi'] = 0x0A4B;
  7689. t['oopen'] = 0x0254;
  7690. t['oparen'] = 0x24AA;
  7691. t['openbullet'] = 0x25E6;
  7692. t['option'] = 0x2325;
  7693. t['ordfeminine'] = 0x00AA;
  7694. t['ordmasculine'] = 0x00BA;
  7695. t['orthogonal'] = 0x221F;
  7696. t['oshortdeva'] = 0x0912;
  7697. t['oshortvowelsigndeva'] = 0x094A;
  7698. t['oslash'] = 0x00F8;
  7699. t['oslashacute'] = 0x01FF;
  7700. t['osmallhiragana'] = 0x3049;
  7701. t['osmallkatakana'] = 0x30A9;
  7702. t['osmallkatakanahalfwidth'] = 0xFF6B;
  7703. t['ostrokeacute'] = 0x01FF;
  7704. t['osuperior'] = 0xF6F0;
  7705. t['otcyrillic'] = 0x047F;
  7706. t['otilde'] = 0x00F5;
  7707. t['otildeacute'] = 0x1E4D;
  7708. t['otildedieresis'] = 0x1E4F;
  7709. t['oubopomofo'] = 0x3121;
  7710. t['overline'] = 0x203E;
  7711. t['overlinecenterline'] = 0xFE4A;
  7712. t['overlinecmb'] = 0x0305;
  7713. t['overlinedashed'] = 0xFE49;
  7714. t['overlinedblwavy'] = 0xFE4C;
  7715. t['overlinewavy'] = 0xFE4B;
  7716. t['overscore'] = 0x00AF;
  7717. t['ovowelsignbengali'] = 0x09CB;
  7718. t['ovowelsigndeva'] = 0x094B;
  7719. t['ovowelsigngujarati'] = 0x0ACB;
  7720. t['p'] = 0x0070;
  7721. t['paampssquare'] = 0x3380;
  7722. t['paasentosquare'] = 0x332B;
  7723. t['pabengali'] = 0x09AA;
  7724. t['pacute'] = 0x1E55;
  7725. t['padeva'] = 0x092A;
  7726. t['pagedown'] = 0x21DF;
  7727. t['pageup'] = 0x21DE;
  7728. t['pagujarati'] = 0x0AAA;
  7729. t['pagurmukhi'] = 0x0A2A;
  7730. t['pahiragana'] = 0x3071;
  7731. t['paiyannoithai'] = 0x0E2F;
  7732. t['pakatakana'] = 0x30D1;
  7733. t['palatalizationcyrilliccmb'] = 0x0484;
  7734. t['palochkacyrillic'] = 0x04C0;
  7735. t['pansioskorean'] = 0x317F;
  7736. t['paragraph'] = 0x00B6;
  7737. t['parallel'] = 0x2225;
  7738. t['parenleft'] = 0x0028;
  7739. t['parenleftaltonearabic'] = 0xFD3E;
  7740. t['parenleftbt'] = 0xF8ED;
  7741. t['parenleftex'] = 0xF8EC;
  7742. t['parenleftinferior'] = 0x208D;
  7743. t['parenleftmonospace'] = 0xFF08;
  7744. t['parenleftsmall'] = 0xFE59;
  7745. t['parenleftsuperior'] = 0x207D;
  7746. t['parenlefttp'] = 0xF8EB;
  7747. t['parenleftvertical'] = 0xFE35;
  7748. t['parenright'] = 0x0029;
  7749. t['parenrightaltonearabic'] = 0xFD3F;
  7750. t['parenrightbt'] = 0xF8F8;
  7751. t['parenrightex'] = 0xF8F7;
  7752. t['parenrightinferior'] = 0x208E;
  7753. t['parenrightmonospace'] = 0xFF09;
  7754. t['parenrightsmall'] = 0xFE5A;
  7755. t['parenrightsuperior'] = 0x207E;
  7756. t['parenrighttp'] = 0xF8F6;
  7757. t['parenrightvertical'] = 0xFE36;
  7758. t['partialdiff'] = 0x2202;
  7759. t['paseqhebrew'] = 0x05C0;
  7760. t['pashtahebrew'] = 0x0599;
  7761. t['pasquare'] = 0x33A9;
  7762. t['patah'] = 0x05B7;
  7763. t['patah11'] = 0x05B7;
  7764. t['patah1d'] = 0x05B7;
  7765. t['patah2a'] = 0x05B7;
  7766. t['patahhebrew'] = 0x05B7;
  7767. t['patahnarrowhebrew'] = 0x05B7;
  7768. t['patahquarterhebrew'] = 0x05B7;
  7769. t['patahwidehebrew'] = 0x05B7;
  7770. t['pazerhebrew'] = 0x05A1;
  7771. t['pbopomofo'] = 0x3106;
  7772. t['pcircle'] = 0x24DF;
  7773. t['pdotaccent'] = 0x1E57;
  7774. t['pe'] = 0x05E4;
  7775. t['pecyrillic'] = 0x043F;
  7776. t['pedagesh'] = 0xFB44;
  7777. t['pedageshhebrew'] = 0xFB44;
  7778. t['peezisquare'] = 0x333B;
  7779. t['pefinaldageshhebrew'] = 0xFB43;
  7780. t['peharabic'] = 0x067E;
  7781. t['peharmenian'] = 0x057A;
  7782. t['pehebrew'] = 0x05E4;
  7783. t['pehfinalarabic'] = 0xFB57;
  7784. t['pehinitialarabic'] = 0xFB58;
  7785. t['pehiragana'] = 0x307A;
  7786. t['pehmedialarabic'] = 0xFB59;
  7787. t['pekatakana'] = 0x30DA;
  7788. t['pemiddlehookcyrillic'] = 0x04A7;
  7789. t['perafehebrew'] = 0xFB4E;
  7790. t['percent'] = 0x0025;
  7791. t['percentarabic'] = 0x066A;
  7792. t['percentmonospace'] = 0xFF05;
  7793. t['percentsmall'] = 0xFE6A;
  7794. t['period'] = 0x002E;
  7795. t['periodarmenian'] = 0x0589;
  7796. t['periodcentered'] = 0x00B7;
  7797. t['periodhalfwidth'] = 0xFF61;
  7798. t['periodinferior'] = 0xF6E7;
  7799. t['periodmonospace'] = 0xFF0E;
  7800. t['periodsmall'] = 0xFE52;
  7801. t['periodsuperior'] = 0xF6E8;
  7802. t['perispomenigreekcmb'] = 0x0342;
  7803. t['perpendicular'] = 0x22A5;
  7804. t['perthousand'] = 0x2030;
  7805. t['peseta'] = 0x20A7;
  7806. t['pfsquare'] = 0x338A;
  7807. t['phabengali'] = 0x09AB;
  7808. t['phadeva'] = 0x092B;
  7809. t['phagujarati'] = 0x0AAB;
  7810. t['phagurmukhi'] = 0x0A2B;
  7811. t['phi'] = 0x03C6;
  7812. t['phi1'] = 0x03D5;
  7813. t['phieuphacirclekorean'] = 0x327A;
  7814. t['phieuphaparenkorean'] = 0x321A;
  7815. t['phieuphcirclekorean'] = 0x326C;
  7816. t['phieuphkorean'] = 0x314D;
  7817. t['phieuphparenkorean'] = 0x320C;
  7818. t['philatin'] = 0x0278;
  7819. t['phinthuthai'] = 0x0E3A;
  7820. t['phisymbolgreek'] = 0x03D5;
  7821. t['phook'] = 0x01A5;
  7822. t['phophanthai'] = 0x0E1E;
  7823. t['phophungthai'] = 0x0E1C;
  7824. t['phosamphaothai'] = 0x0E20;
  7825. t['pi'] = 0x03C0;
  7826. t['pieupacirclekorean'] = 0x3273;
  7827. t['pieupaparenkorean'] = 0x3213;
  7828. t['pieupcieuckorean'] = 0x3176;
  7829. t['pieupcirclekorean'] = 0x3265;
  7830. t['pieupkiyeokkorean'] = 0x3172;
  7831. t['pieupkorean'] = 0x3142;
  7832. t['pieupparenkorean'] = 0x3205;
  7833. t['pieupsioskiyeokkorean'] = 0x3174;
  7834. t['pieupsioskorean'] = 0x3144;
  7835. t['pieupsiostikeutkorean'] = 0x3175;
  7836. t['pieupthieuthkorean'] = 0x3177;
  7837. t['pieuptikeutkorean'] = 0x3173;
  7838. t['pihiragana'] = 0x3074;
  7839. t['pikatakana'] = 0x30D4;
  7840. t['pisymbolgreek'] = 0x03D6;
  7841. t['piwrarmenian'] = 0x0583;
  7842. t['plus'] = 0x002B;
  7843. t['plusbelowcmb'] = 0x031F;
  7844. t['pluscircle'] = 0x2295;
  7845. t['plusminus'] = 0x00B1;
  7846. t['plusmod'] = 0x02D6;
  7847. t['plusmonospace'] = 0xFF0B;
  7848. t['plussmall'] = 0xFE62;
  7849. t['plussuperior'] = 0x207A;
  7850. t['pmonospace'] = 0xFF50;
  7851. t['pmsquare'] = 0x33D8;
  7852. t['pohiragana'] = 0x307D;
  7853. t['pointingindexdownwhite'] = 0x261F;
  7854. t['pointingindexleftwhite'] = 0x261C;
  7855. t['pointingindexrightwhite'] = 0x261E;
  7856. t['pointingindexupwhite'] = 0x261D;
  7857. t['pokatakana'] = 0x30DD;
  7858. t['poplathai'] = 0x0E1B;
  7859. t['postalmark'] = 0x3012;
  7860. t['postalmarkface'] = 0x3020;
  7861. t['pparen'] = 0x24AB;
  7862. t['precedes'] = 0x227A;
  7863. t['prescription'] = 0x211E;
  7864. t['primemod'] = 0x02B9;
  7865. t['primereversed'] = 0x2035;
  7866. t['product'] = 0x220F;
  7867. t['projective'] = 0x2305;
  7868. t['prolongedkana'] = 0x30FC;
  7869. t['propellor'] = 0x2318;
  7870. t['propersubset'] = 0x2282;
  7871. t['propersuperset'] = 0x2283;
  7872. t['proportion'] = 0x2237;
  7873. t['proportional'] = 0x221D;
  7874. t['psi'] = 0x03C8;
  7875. t['psicyrillic'] = 0x0471;
  7876. t['psilipneumatacyrilliccmb'] = 0x0486;
  7877. t['pssquare'] = 0x33B0;
  7878. t['puhiragana'] = 0x3077;
  7879. t['pukatakana'] = 0x30D7;
  7880. t['pvsquare'] = 0x33B4;
  7881. t['pwsquare'] = 0x33BA;
  7882. t['q'] = 0x0071;
  7883. t['qadeva'] = 0x0958;
  7884. t['qadmahebrew'] = 0x05A8;
  7885. t['qafarabic'] = 0x0642;
  7886. t['qaffinalarabic'] = 0xFED6;
  7887. t['qafinitialarabic'] = 0xFED7;
  7888. t['qafmedialarabic'] = 0xFED8;
  7889. t['qamats'] = 0x05B8;
  7890. t['qamats10'] = 0x05B8;
  7891. t['qamats1a'] = 0x05B8;
  7892. t['qamats1c'] = 0x05B8;
  7893. t['qamats27'] = 0x05B8;
  7894. t['qamats29'] = 0x05B8;
  7895. t['qamats33'] = 0x05B8;
  7896. t['qamatsde'] = 0x05B8;
  7897. t['qamatshebrew'] = 0x05B8;
  7898. t['qamatsnarrowhebrew'] = 0x05B8;
  7899. t['qamatsqatanhebrew'] = 0x05B8;
  7900. t['qamatsqatannarrowhebrew'] = 0x05B8;
  7901. t['qamatsqatanquarterhebrew'] = 0x05B8;
  7902. t['qamatsqatanwidehebrew'] = 0x05B8;
  7903. t['qamatsquarterhebrew'] = 0x05B8;
  7904. t['qamatswidehebrew'] = 0x05B8;
  7905. t['qarneyparahebrew'] = 0x059F;
  7906. t['qbopomofo'] = 0x3111;
  7907. t['qcircle'] = 0x24E0;
  7908. t['qhook'] = 0x02A0;
  7909. t['qmonospace'] = 0xFF51;
  7910. t['qof'] = 0x05E7;
  7911. t['qofdagesh'] = 0xFB47;
  7912. t['qofdageshhebrew'] = 0xFB47;
  7913. t['qofhebrew'] = 0x05E7;
  7914. t['qparen'] = 0x24AC;
  7915. t['quarternote'] = 0x2669;
  7916. t['qubuts'] = 0x05BB;
  7917. t['qubuts18'] = 0x05BB;
  7918. t['qubuts25'] = 0x05BB;
  7919. t['qubuts31'] = 0x05BB;
  7920. t['qubutshebrew'] = 0x05BB;
  7921. t['qubutsnarrowhebrew'] = 0x05BB;
  7922. t['qubutsquarterhebrew'] = 0x05BB;
  7923. t['qubutswidehebrew'] = 0x05BB;
  7924. t['question'] = 0x003F;
  7925. t['questionarabic'] = 0x061F;
  7926. t['questionarmenian'] = 0x055E;
  7927. t['questiondown'] = 0x00BF;
  7928. t['questiondownsmall'] = 0xF7BF;
  7929. t['questiongreek'] = 0x037E;
  7930. t['questionmonospace'] = 0xFF1F;
  7931. t['questionsmall'] = 0xF73F;
  7932. t['quotedbl'] = 0x0022;
  7933. t['quotedblbase'] = 0x201E;
  7934. t['quotedblleft'] = 0x201C;
  7935. t['quotedblmonospace'] = 0xFF02;
  7936. t['quotedblprime'] = 0x301E;
  7937. t['quotedblprimereversed'] = 0x301D;
  7938. t['quotedblright'] = 0x201D;
  7939. t['quoteleft'] = 0x2018;
  7940. t['quoteleftreversed'] = 0x201B;
  7941. t['quotereversed'] = 0x201B;
  7942. t['quoteright'] = 0x2019;
  7943. t['quoterightn'] = 0x0149;
  7944. t['quotesinglbase'] = 0x201A;
  7945. t['quotesingle'] = 0x0027;
  7946. t['quotesinglemonospace'] = 0xFF07;
  7947. t['r'] = 0x0072;
  7948. t['raarmenian'] = 0x057C;
  7949. t['rabengali'] = 0x09B0;
  7950. t['racute'] = 0x0155;
  7951. t['radeva'] = 0x0930;
  7952. t['radical'] = 0x221A;
  7953. t['radicalex'] = 0xF8E5;
  7954. t['radoverssquare'] = 0x33AE;
  7955. t['radoverssquaredsquare'] = 0x33AF;
  7956. t['radsquare'] = 0x33AD;
  7957. t['rafe'] = 0x05BF;
  7958. t['rafehebrew'] = 0x05BF;
  7959. t['ragujarati'] = 0x0AB0;
  7960. t['ragurmukhi'] = 0x0A30;
  7961. t['rahiragana'] = 0x3089;
  7962. t['rakatakana'] = 0x30E9;
  7963. t['rakatakanahalfwidth'] = 0xFF97;
  7964. t['ralowerdiagonalbengali'] = 0x09F1;
  7965. t['ramiddlediagonalbengali'] = 0x09F0;
  7966. t['ramshorn'] = 0x0264;
  7967. t['ratio'] = 0x2236;
  7968. t['rbopomofo'] = 0x3116;
  7969. t['rcaron'] = 0x0159;
  7970. t['rcedilla'] = 0x0157;
  7971. t['rcircle'] = 0x24E1;
  7972. t['rcommaaccent'] = 0x0157;
  7973. t['rdblgrave'] = 0x0211;
  7974. t['rdotaccent'] = 0x1E59;
  7975. t['rdotbelow'] = 0x1E5B;
  7976. t['rdotbelowmacron'] = 0x1E5D;
  7977. t['referencemark'] = 0x203B;
  7978. t['reflexsubset'] = 0x2286;
  7979. t['reflexsuperset'] = 0x2287;
  7980. t['registered'] = 0x00AE;
  7981. t['registersans'] = 0xF8E8;
  7982. t['registerserif'] = 0xF6DA;
  7983. t['reharabic'] = 0x0631;
  7984. t['reharmenian'] = 0x0580;
  7985. t['rehfinalarabic'] = 0xFEAE;
  7986. t['rehiragana'] = 0x308C;
  7987. t['rekatakana'] = 0x30EC;
  7988. t['rekatakanahalfwidth'] = 0xFF9A;
  7989. t['resh'] = 0x05E8;
  7990. t['reshdageshhebrew'] = 0xFB48;
  7991. t['reshhebrew'] = 0x05E8;
  7992. t['reversedtilde'] = 0x223D;
  7993. t['reviahebrew'] = 0x0597;
  7994. t['reviamugrashhebrew'] = 0x0597;
  7995. t['revlogicalnot'] = 0x2310;
  7996. t['rfishhook'] = 0x027E;
  7997. t['rfishhookreversed'] = 0x027F;
  7998. t['rhabengali'] = 0x09DD;
  7999. t['rhadeva'] = 0x095D;
  8000. t['rho'] = 0x03C1;
  8001. t['rhook'] = 0x027D;
  8002. t['rhookturned'] = 0x027B;
  8003. t['rhookturnedsuperior'] = 0x02B5;
  8004. t['rhosymbolgreek'] = 0x03F1;
  8005. t['rhotichookmod'] = 0x02DE;
  8006. t['rieulacirclekorean'] = 0x3271;
  8007. t['rieulaparenkorean'] = 0x3211;
  8008. t['rieulcirclekorean'] = 0x3263;
  8009. t['rieulhieuhkorean'] = 0x3140;
  8010. t['rieulkiyeokkorean'] = 0x313A;
  8011. t['rieulkiyeoksioskorean'] = 0x3169;
  8012. t['rieulkorean'] = 0x3139;
  8013. t['rieulmieumkorean'] = 0x313B;
  8014. t['rieulpansioskorean'] = 0x316C;
  8015. t['rieulparenkorean'] = 0x3203;
  8016. t['rieulphieuphkorean'] = 0x313F;
  8017. t['rieulpieupkorean'] = 0x313C;
  8018. t['rieulpieupsioskorean'] = 0x316B;
  8019. t['rieulsioskorean'] = 0x313D;
  8020. t['rieulthieuthkorean'] = 0x313E;
  8021. t['rieultikeutkorean'] = 0x316A;
  8022. t['rieulyeorinhieuhkorean'] = 0x316D;
  8023. t['rightangle'] = 0x221F;
  8024. t['righttackbelowcmb'] = 0x0319;
  8025. t['righttriangle'] = 0x22BF;
  8026. t['rihiragana'] = 0x308A;
  8027. t['rikatakana'] = 0x30EA;
  8028. t['rikatakanahalfwidth'] = 0xFF98;
  8029. t['ring'] = 0x02DA;
  8030. t['ringbelowcmb'] = 0x0325;
  8031. t['ringcmb'] = 0x030A;
  8032. t['ringhalfleft'] = 0x02BF;
  8033. t['ringhalfleftarmenian'] = 0x0559;
  8034. t['ringhalfleftbelowcmb'] = 0x031C;
  8035. t['ringhalfleftcentered'] = 0x02D3;
  8036. t['ringhalfright'] = 0x02BE;
  8037. t['ringhalfrightbelowcmb'] = 0x0339;
  8038. t['ringhalfrightcentered'] = 0x02D2;
  8039. t['rinvertedbreve'] = 0x0213;
  8040. t['rittorusquare'] = 0x3351;
  8041. t['rlinebelow'] = 0x1E5F;
  8042. t['rlongleg'] = 0x027C;
  8043. t['rlonglegturned'] = 0x027A;
  8044. t['rmonospace'] = 0xFF52;
  8045. t['rohiragana'] = 0x308D;
  8046. t['rokatakana'] = 0x30ED;
  8047. t['rokatakanahalfwidth'] = 0xFF9B;
  8048. t['roruathai'] = 0x0E23;
  8049. t['rparen'] = 0x24AD;
  8050. t['rrabengali'] = 0x09DC;
  8051. t['rradeva'] = 0x0931;
  8052. t['rragurmukhi'] = 0x0A5C;
  8053. t['rreharabic'] = 0x0691;
  8054. t['rrehfinalarabic'] = 0xFB8D;
  8055. t['rrvocalicbengali'] = 0x09E0;
  8056. t['rrvocalicdeva'] = 0x0960;
  8057. t['rrvocalicgujarati'] = 0x0AE0;
  8058. t['rrvocalicvowelsignbengali'] = 0x09C4;
  8059. t['rrvocalicvowelsigndeva'] = 0x0944;
  8060. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  8061. t['rsuperior'] = 0xF6F1;
  8062. t['rtblock'] = 0x2590;
  8063. t['rturned'] = 0x0279;
  8064. t['rturnedsuperior'] = 0x02B4;
  8065. t['ruhiragana'] = 0x308B;
  8066. t['rukatakana'] = 0x30EB;
  8067. t['rukatakanahalfwidth'] = 0xFF99;
  8068. t['rupeemarkbengali'] = 0x09F2;
  8069. t['rupeesignbengali'] = 0x09F3;
  8070. t['rupiah'] = 0xF6DD;
  8071. t['ruthai'] = 0x0E24;
  8072. t['rvocalicbengali'] = 0x098B;
  8073. t['rvocalicdeva'] = 0x090B;
  8074. t['rvocalicgujarati'] = 0x0A8B;
  8075. t['rvocalicvowelsignbengali'] = 0x09C3;
  8076. t['rvocalicvowelsigndeva'] = 0x0943;
  8077. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  8078. t['s'] = 0x0073;
  8079. t['sabengali'] = 0x09B8;
  8080. t['sacute'] = 0x015B;
  8081. t['sacutedotaccent'] = 0x1E65;
  8082. t['sadarabic'] = 0x0635;
  8083. t['sadeva'] = 0x0938;
  8084. t['sadfinalarabic'] = 0xFEBA;
  8085. t['sadinitialarabic'] = 0xFEBB;
  8086. t['sadmedialarabic'] = 0xFEBC;
  8087. t['sagujarati'] = 0x0AB8;
  8088. t['sagurmukhi'] = 0x0A38;
  8089. t['sahiragana'] = 0x3055;
  8090. t['sakatakana'] = 0x30B5;
  8091. t['sakatakanahalfwidth'] = 0xFF7B;
  8092. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  8093. t['samekh'] = 0x05E1;
  8094. t['samekhdagesh'] = 0xFB41;
  8095. t['samekhdageshhebrew'] = 0xFB41;
  8096. t['samekhhebrew'] = 0x05E1;
  8097. t['saraaathai'] = 0x0E32;
  8098. t['saraaethai'] = 0x0E41;
  8099. t['saraaimaimalaithai'] = 0x0E44;
  8100. t['saraaimaimuanthai'] = 0x0E43;
  8101. t['saraamthai'] = 0x0E33;
  8102. t['saraathai'] = 0x0E30;
  8103. t['saraethai'] = 0x0E40;
  8104. t['saraiileftthai'] = 0xF886;
  8105. t['saraiithai'] = 0x0E35;
  8106. t['saraileftthai'] = 0xF885;
  8107. t['saraithai'] = 0x0E34;
  8108. t['saraothai'] = 0x0E42;
  8109. t['saraueeleftthai'] = 0xF888;
  8110. t['saraueethai'] = 0x0E37;
  8111. t['saraueleftthai'] = 0xF887;
  8112. t['sarauethai'] = 0x0E36;
  8113. t['sarauthai'] = 0x0E38;
  8114. t['sarauuthai'] = 0x0E39;
  8115. t['sbopomofo'] = 0x3119;
  8116. t['scaron'] = 0x0161;
  8117. t['scarondotaccent'] = 0x1E67;
  8118. t['scedilla'] = 0x015F;
  8119. t['schwa'] = 0x0259;
  8120. t['schwacyrillic'] = 0x04D9;
  8121. t['schwadieresiscyrillic'] = 0x04DB;
  8122. t['schwahook'] = 0x025A;
  8123. t['scircle'] = 0x24E2;
  8124. t['scircumflex'] = 0x015D;
  8125. t['scommaaccent'] = 0x0219;
  8126. t['sdotaccent'] = 0x1E61;
  8127. t['sdotbelow'] = 0x1E63;
  8128. t['sdotbelowdotaccent'] = 0x1E69;
  8129. t['seagullbelowcmb'] = 0x033C;
  8130. t['second'] = 0x2033;
  8131. t['secondtonechinese'] = 0x02CA;
  8132. t['section'] = 0x00A7;
  8133. t['seenarabic'] = 0x0633;
  8134. t['seenfinalarabic'] = 0xFEB2;
  8135. t['seeninitialarabic'] = 0xFEB3;
  8136. t['seenmedialarabic'] = 0xFEB4;
  8137. t['segol'] = 0x05B6;
  8138. t['segol13'] = 0x05B6;
  8139. t['segol1f'] = 0x05B6;
  8140. t['segol2c'] = 0x05B6;
  8141. t['segolhebrew'] = 0x05B6;
  8142. t['segolnarrowhebrew'] = 0x05B6;
  8143. t['segolquarterhebrew'] = 0x05B6;
  8144. t['segoltahebrew'] = 0x0592;
  8145. t['segolwidehebrew'] = 0x05B6;
  8146. t['seharmenian'] = 0x057D;
  8147. t['sehiragana'] = 0x305B;
  8148. t['sekatakana'] = 0x30BB;
  8149. t['sekatakanahalfwidth'] = 0xFF7E;
  8150. t['semicolon'] = 0x003B;
  8151. t['semicolonarabic'] = 0x061B;
  8152. t['semicolonmonospace'] = 0xFF1B;
  8153. t['semicolonsmall'] = 0xFE54;
  8154. t['semivoicedmarkkana'] = 0x309C;
  8155. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  8156. t['sentisquare'] = 0x3322;
  8157. t['sentosquare'] = 0x3323;
  8158. t['seven'] = 0x0037;
  8159. t['sevenarabic'] = 0x0667;
  8160. t['sevenbengali'] = 0x09ED;
  8161. t['sevencircle'] = 0x2466;
  8162. t['sevencircleinversesansserif'] = 0x2790;
  8163. t['sevendeva'] = 0x096D;
  8164. t['seveneighths'] = 0x215E;
  8165. t['sevengujarati'] = 0x0AED;
  8166. t['sevengurmukhi'] = 0x0A6D;
  8167. t['sevenhackarabic'] = 0x0667;
  8168. t['sevenhangzhou'] = 0x3027;
  8169. t['sevenideographicparen'] = 0x3226;
  8170. t['seveninferior'] = 0x2087;
  8171. t['sevenmonospace'] = 0xFF17;
  8172. t['sevenoldstyle'] = 0xF737;
  8173. t['sevenparen'] = 0x247A;
  8174. t['sevenperiod'] = 0x248E;
  8175. t['sevenpersian'] = 0x06F7;
  8176. t['sevenroman'] = 0x2176;
  8177. t['sevensuperior'] = 0x2077;
  8178. t['seventeencircle'] = 0x2470;
  8179. t['seventeenparen'] = 0x2484;
  8180. t['seventeenperiod'] = 0x2498;
  8181. t['seventhai'] = 0x0E57;
  8182. t['sfthyphen'] = 0x00AD;
  8183. t['shaarmenian'] = 0x0577;
  8184. t['shabengali'] = 0x09B6;
  8185. t['shacyrillic'] = 0x0448;
  8186. t['shaddaarabic'] = 0x0651;
  8187. t['shaddadammaarabic'] = 0xFC61;
  8188. t['shaddadammatanarabic'] = 0xFC5E;
  8189. t['shaddafathaarabic'] = 0xFC60;
  8190. t['shaddakasraarabic'] = 0xFC62;
  8191. t['shaddakasratanarabic'] = 0xFC5F;
  8192. t['shade'] = 0x2592;
  8193. t['shadedark'] = 0x2593;
  8194. t['shadelight'] = 0x2591;
  8195. t['shademedium'] = 0x2592;
  8196. t['shadeva'] = 0x0936;
  8197. t['shagujarati'] = 0x0AB6;
  8198. t['shagurmukhi'] = 0x0A36;
  8199. t['shalshelethebrew'] = 0x0593;
  8200. t['shbopomofo'] = 0x3115;
  8201. t['shchacyrillic'] = 0x0449;
  8202. t['sheenarabic'] = 0x0634;
  8203. t['sheenfinalarabic'] = 0xFEB6;
  8204. t['sheeninitialarabic'] = 0xFEB7;
  8205. t['sheenmedialarabic'] = 0xFEB8;
  8206. t['sheicoptic'] = 0x03E3;
  8207. t['sheqel'] = 0x20AA;
  8208. t['sheqelhebrew'] = 0x20AA;
  8209. t['sheva'] = 0x05B0;
  8210. t['sheva115'] = 0x05B0;
  8211. t['sheva15'] = 0x05B0;
  8212. t['sheva22'] = 0x05B0;
  8213. t['sheva2e'] = 0x05B0;
  8214. t['shevahebrew'] = 0x05B0;
  8215. t['shevanarrowhebrew'] = 0x05B0;
  8216. t['shevaquarterhebrew'] = 0x05B0;
  8217. t['shevawidehebrew'] = 0x05B0;
  8218. t['shhacyrillic'] = 0x04BB;
  8219. t['shimacoptic'] = 0x03ED;
  8220. t['shin'] = 0x05E9;
  8221. t['shindagesh'] = 0xFB49;
  8222. t['shindageshhebrew'] = 0xFB49;
  8223. t['shindageshshindot'] = 0xFB2C;
  8224. t['shindageshshindothebrew'] = 0xFB2C;
  8225. t['shindageshsindot'] = 0xFB2D;
  8226. t['shindageshsindothebrew'] = 0xFB2D;
  8227. t['shindothebrew'] = 0x05C1;
  8228. t['shinhebrew'] = 0x05E9;
  8229. t['shinshindot'] = 0xFB2A;
  8230. t['shinshindothebrew'] = 0xFB2A;
  8231. t['shinsindot'] = 0xFB2B;
  8232. t['shinsindothebrew'] = 0xFB2B;
  8233. t['shook'] = 0x0282;
  8234. t['sigma'] = 0x03C3;
  8235. t['sigma1'] = 0x03C2;
  8236. t['sigmafinal'] = 0x03C2;
  8237. t['sigmalunatesymbolgreek'] = 0x03F2;
  8238. t['sihiragana'] = 0x3057;
  8239. t['sikatakana'] = 0x30B7;
  8240. t['sikatakanahalfwidth'] = 0xFF7C;
  8241. t['siluqhebrew'] = 0x05BD;
  8242. t['siluqlefthebrew'] = 0x05BD;
  8243. t['similar'] = 0x223C;
  8244. t['sindothebrew'] = 0x05C2;
  8245. t['siosacirclekorean'] = 0x3274;
  8246. t['siosaparenkorean'] = 0x3214;
  8247. t['sioscieuckorean'] = 0x317E;
  8248. t['sioscirclekorean'] = 0x3266;
  8249. t['sioskiyeokkorean'] = 0x317A;
  8250. t['sioskorean'] = 0x3145;
  8251. t['siosnieunkorean'] = 0x317B;
  8252. t['siosparenkorean'] = 0x3206;
  8253. t['siospieupkorean'] = 0x317D;
  8254. t['siostikeutkorean'] = 0x317C;
  8255. t['six'] = 0x0036;
  8256. t['sixarabic'] = 0x0666;
  8257. t['sixbengali'] = 0x09EC;
  8258. t['sixcircle'] = 0x2465;
  8259. t['sixcircleinversesansserif'] = 0x278F;
  8260. t['sixdeva'] = 0x096C;
  8261. t['sixgujarati'] = 0x0AEC;
  8262. t['sixgurmukhi'] = 0x0A6C;
  8263. t['sixhackarabic'] = 0x0666;
  8264. t['sixhangzhou'] = 0x3026;
  8265. t['sixideographicparen'] = 0x3225;
  8266. t['sixinferior'] = 0x2086;
  8267. t['sixmonospace'] = 0xFF16;
  8268. t['sixoldstyle'] = 0xF736;
  8269. t['sixparen'] = 0x2479;
  8270. t['sixperiod'] = 0x248D;
  8271. t['sixpersian'] = 0x06F6;
  8272. t['sixroman'] = 0x2175;
  8273. t['sixsuperior'] = 0x2076;
  8274. t['sixteencircle'] = 0x246F;
  8275. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  8276. t['sixteenparen'] = 0x2483;
  8277. t['sixteenperiod'] = 0x2497;
  8278. t['sixthai'] = 0x0E56;
  8279. t['slash'] = 0x002F;
  8280. t['slashmonospace'] = 0xFF0F;
  8281. t['slong'] = 0x017F;
  8282. t['slongdotaccent'] = 0x1E9B;
  8283. t['smileface'] = 0x263A;
  8284. t['smonospace'] = 0xFF53;
  8285. t['sofpasuqhebrew'] = 0x05C3;
  8286. t['softhyphen'] = 0x00AD;
  8287. t['softsigncyrillic'] = 0x044C;
  8288. t['sohiragana'] = 0x305D;
  8289. t['sokatakana'] = 0x30BD;
  8290. t['sokatakanahalfwidth'] = 0xFF7F;
  8291. t['soliduslongoverlaycmb'] = 0x0338;
  8292. t['solidusshortoverlaycmb'] = 0x0337;
  8293. t['sorusithai'] = 0x0E29;
  8294. t['sosalathai'] = 0x0E28;
  8295. t['sosothai'] = 0x0E0B;
  8296. t['sosuathai'] = 0x0E2A;
  8297. t['space'] = 0x0020;
  8298. t['spacehackarabic'] = 0x0020;
  8299. t['spade'] = 0x2660;
  8300. t['spadesuitblack'] = 0x2660;
  8301. t['spadesuitwhite'] = 0x2664;
  8302. t['sparen'] = 0x24AE;
  8303. t['squarebelowcmb'] = 0x033B;
  8304. t['squarecc'] = 0x33C4;
  8305. t['squarecm'] = 0x339D;
  8306. t['squarediagonalcrosshatchfill'] = 0x25A9;
  8307. t['squarehorizontalfill'] = 0x25A4;
  8308. t['squarekg'] = 0x338F;
  8309. t['squarekm'] = 0x339E;
  8310. t['squarekmcapital'] = 0x33CE;
  8311. t['squareln'] = 0x33D1;
  8312. t['squarelog'] = 0x33D2;
  8313. t['squaremg'] = 0x338E;
  8314. t['squaremil'] = 0x33D5;
  8315. t['squaremm'] = 0x339C;
  8316. t['squaremsquared'] = 0x33A1;
  8317. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  8318. t['squareupperlefttolowerrightfill'] = 0x25A7;
  8319. t['squareupperrighttolowerleftfill'] = 0x25A8;
  8320. t['squareverticalfill'] = 0x25A5;
  8321. t['squarewhitewithsmallblack'] = 0x25A3;
  8322. t['srsquare'] = 0x33DB;
  8323. t['ssabengali'] = 0x09B7;
  8324. t['ssadeva'] = 0x0937;
  8325. t['ssagujarati'] = 0x0AB7;
  8326. t['ssangcieuckorean'] = 0x3149;
  8327. t['ssanghieuhkorean'] = 0x3185;
  8328. t['ssangieungkorean'] = 0x3180;
  8329. t['ssangkiyeokkorean'] = 0x3132;
  8330. t['ssangnieunkorean'] = 0x3165;
  8331. t['ssangpieupkorean'] = 0x3143;
  8332. t['ssangsioskorean'] = 0x3146;
  8333. t['ssangtikeutkorean'] = 0x3138;
  8334. t['ssuperior'] = 0xF6F2;
  8335. t['sterling'] = 0x00A3;
  8336. t['sterlingmonospace'] = 0xFFE1;
  8337. t['strokelongoverlaycmb'] = 0x0336;
  8338. t['strokeshortoverlaycmb'] = 0x0335;
  8339. t['subset'] = 0x2282;
  8340. t['subsetnotequal'] = 0x228A;
  8341. t['subsetorequal'] = 0x2286;
  8342. t['succeeds'] = 0x227B;
  8343. t['suchthat'] = 0x220B;
  8344. t['suhiragana'] = 0x3059;
  8345. t['sukatakana'] = 0x30B9;
  8346. t['sukatakanahalfwidth'] = 0xFF7D;
  8347. t['sukunarabic'] = 0x0652;
  8348. t['summation'] = 0x2211;
  8349. t['sun'] = 0x263C;
  8350. t['superset'] = 0x2283;
  8351. t['supersetnotequal'] = 0x228B;
  8352. t['supersetorequal'] = 0x2287;
  8353. t['svsquare'] = 0x33DC;
  8354. t['syouwaerasquare'] = 0x337C;
  8355. t['t'] = 0x0074;
  8356. t['tabengali'] = 0x09A4;
  8357. t['tackdown'] = 0x22A4;
  8358. t['tackleft'] = 0x22A3;
  8359. t['tadeva'] = 0x0924;
  8360. t['tagujarati'] = 0x0AA4;
  8361. t['tagurmukhi'] = 0x0A24;
  8362. t['taharabic'] = 0x0637;
  8363. t['tahfinalarabic'] = 0xFEC2;
  8364. t['tahinitialarabic'] = 0xFEC3;
  8365. t['tahiragana'] = 0x305F;
  8366. t['tahmedialarabic'] = 0xFEC4;
  8367. t['taisyouerasquare'] = 0x337D;
  8368. t['takatakana'] = 0x30BF;
  8369. t['takatakanahalfwidth'] = 0xFF80;
  8370. t['tatweelarabic'] = 0x0640;
  8371. t['tau'] = 0x03C4;
  8372. t['tav'] = 0x05EA;
  8373. t['tavdages'] = 0xFB4A;
  8374. t['tavdagesh'] = 0xFB4A;
  8375. t['tavdageshhebrew'] = 0xFB4A;
  8376. t['tavhebrew'] = 0x05EA;
  8377. t['tbar'] = 0x0167;
  8378. t['tbopomofo'] = 0x310A;
  8379. t['tcaron'] = 0x0165;
  8380. t['tccurl'] = 0x02A8;
  8381. t['tcedilla'] = 0x0163;
  8382. t['tcheharabic'] = 0x0686;
  8383. t['tchehfinalarabic'] = 0xFB7B;
  8384. t['tchehinitialarabic'] = 0xFB7C;
  8385. t['tchehmedialarabic'] = 0xFB7D;
  8386. t['tcircle'] = 0x24E3;
  8387. t['tcircumflexbelow'] = 0x1E71;
  8388. t['tcommaaccent'] = 0x0163;
  8389. t['tdieresis'] = 0x1E97;
  8390. t['tdotaccent'] = 0x1E6B;
  8391. t['tdotbelow'] = 0x1E6D;
  8392. t['tecyrillic'] = 0x0442;
  8393. t['tedescendercyrillic'] = 0x04AD;
  8394. t['teharabic'] = 0x062A;
  8395. t['tehfinalarabic'] = 0xFE96;
  8396. t['tehhahinitialarabic'] = 0xFCA2;
  8397. t['tehhahisolatedarabic'] = 0xFC0C;
  8398. t['tehinitialarabic'] = 0xFE97;
  8399. t['tehiragana'] = 0x3066;
  8400. t['tehjeeminitialarabic'] = 0xFCA1;
  8401. t['tehjeemisolatedarabic'] = 0xFC0B;
  8402. t['tehmarbutaarabic'] = 0x0629;
  8403. t['tehmarbutafinalarabic'] = 0xFE94;
  8404. t['tehmedialarabic'] = 0xFE98;
  8405. t['tehmeeminitialarabic'] = 0xFCA4;
  8406. t['tehmeemisolatedarabic'] = 0xFC0E;
  8407. t['tehnoonfinalarabic'] = 0xFC73;
  8408. t['tekatakana'] = 0x30C6;
  8409. t['tekatakanahalfwidth'] = 0xFF83;
  8410. t['telephone'] = 0x2121;
  8411. t['telephoneblack'] = 0x260E;
  8412. t['telishagedolahebrew'] = 0x05A0;
  8413. t['telishaqetanahebrew'] = 0x05A9;
  8414. t['tencircle'] = 0x2469;
  8415. t['tenideographicparen'] = 0x3229;
  8416. t['tenparen'] = 0x247D;
  8417. t['tenperiod'] = 0x2491;
  8418. t['tenroman'] = 0x2179;
  8419. t['tesh'] = 0x02A7;
  8420. t['tet'] = 0x05D8;
  8421. t['tetdagesh'] = 0xFB38;
  8422. t['tetdageshhebrew'] = 0xFB38;
  8423. t['tethebrew'] = 0x05D8;
  8424. t['tetsecyrillic'] = 0x04B5;
  8425. t['tevirhebrew'] = 0x059B;
  8426. t['tevirlefthebrew'] = 0x059B;
  8427. t['thabengali'] = 0x09A5;
  8428. t['thadeva'] = 0x0925;
  8429. t['thagujarati'] = 0x0AA5;
  8430. t['thagurmukhi'] = 0x0A25;
  8431. t['thalarabic'] = 0x0630;
  8432. t['thalfinalarabic'] = 0xFEAC;
  8433. t['thanthakhatlowleftthai'] = 0xF898;
  8434. t['thanthakhatlowrightthai'] = 0xF897;
  8435. t['thanthakhatthai'] = 0x0E4C;
  8436. t['thanthakhatupperleftthai'] = 0xF896;
  8437. t['theharabic'] = 0x062B;
  8438. t['thehfinalarabic'] = 0xFE9A;
  8439. t['thehinitialarabic'] = 0xFE9B;
  8440. t['thehmedialarabic'] = 0xFE9C;
  8441. t['thereexists'] = 0x2203;
  8442. t['therefore'] = 0x2234;
  8443. t['theta'] = 0x03B8;
  8444. t['theta1'] = 0x03D1;
  8445. t['thetasymbolgreek'] = 0x03D1;
  8446. t['thieuthacirclekorean'] = 0x3279;
  8447. t['thieuthaparenkorean'] = 0x3219;
  8448. t['thieuthcirclekorean'] = 0x326B;
  8449. t['thieuthkorean'] = 0x314C;
  8450. t['thieuthparenkorean'] = 0x320B;
  8451. t['thirteencircle'] = 0x246C;
  8452. t['thirteenparen'] = 0x2480;
  8453. t['thirteenperiod'] = 0x2494;
  8454. t['thonangmonthothai'] = 0x0E11;
  8455. t['thook'] = 0x01AD;
  8456. t['thophuthaothai'] = 0x0E12;
  8457. t['thorn'] = 0x00FE;
  8458. t['thothahanthai'] = 0x0E17;
  8459. t['thothanthai'] = 0x0E10;
  8460. t['thothongthai'] = 0x0E18;
  8461. t['thothungthai'] = 0x0E16;
  8462. t['thousandcyrillic'] = 0x0482;
  8463. t['thousandsseparatorarabic'] = 0x066C;
  8464. t['thousandsseparatorpersian'] = 0x066C;
  8465. t['three'] = 0x0033;
  8466. t['threearabic'] = 0x0663;
  8467. t['threebengali'] = 0x09E9;
  8468. t['threecircle'] = 0x2462;
  8469. t['threecircleinversesansserif'] = 0x278C;
  8470. t['threedeva'] = 0x0969;
  8471. t['threeeighths'] = 0x215C;
  8472. t['threegujarati'] = 0x0AE9;
  8473. t['threegurmukhi'] = 0x0A69;
  8474. t['threehackarabic'] = 0x0663;
  8475. t['threehangzhou'] = 0x3023;
  8476. t['threeideographicparen'] = 0x3222;
  8477. t['threeinferior'] = 0x2083;
  8478. t['threemonospace'] = 0xFF13;
  8479. t['threenumeratorbengali'] = 0x09F6;
  8480. t['threeoldstyle'] = 0xF733;
  8481. t['threeparen'] = 0x2476;
  8482. t['threeperiod'] = 0x248A;
  8483. t['threepersian'] = 0x06F3;
  8484. t['threequarters'] = 0x00BE;
  8485. t['threequartersemdash'] = 0xF6DE;
  8486. t['threeroman'] = 0x2172;
  8487. t['threesuperior'] = 0x00B3;
  8488. t['threethai'] = 0x0E53;
  8489. t['thzsquare'] = 0x3394;
  8490. t['tihiragana'] = 0x3061;
  8491. t['tikatakana'] = 0x30C1;
  8492. t['tikatakanahalfwidth'] = 0xFF81;
  8493. t['tikeutacirclekorean'] = 0x3270;
  8494. t['tikeutaparenkorean'] = 0x3210;
  8495. t['tikeutcirclekorean'] = 0x3262;
  8496. t['tikeutkorean'] = 0x3137;
  8497. t['tikeutparenkorean'] = 0x3202;
  8498. t['tilde'] = 0x02DC;
  8499. t['tildebelowcmb'] = 0x0330;
  8500. t['tildecmb'] = 0x0303;
  8501. t['tildecomb'] = 0x0303;
  8502. t['tildedoublecmb'] = 0x0360;
  8503. t['tildeoperator'] = 0x223C;
  8504. t['tildeoverlaycmb'] = 0x0334;
  8505. t['tildeverticalcmb'] = 0x033E;
  8506. t['timescircle'] = 0x2297;
  8507. t['tipehahebrew'] = 0x0596;
  8508. t['tipehalefthebrew'] = 0x0596;
  8509. t['tippigurmukhi'] = 0x0A70;
  8510. t['titlocyrilliccmb'] = 0x0483;
  8511. t['tiwnarmenian'] = 0x057F;
  8512. t['tlinebelow'] = 0x1E6F;
  8513. t['tmonospace'] = 0xFF54;
  8514. t['toarmenian'] = 0x0569;
  8515. t['tohiragana'] = 0x3068;
  8516. t['tokatakana'] = 0x30C8;
  8517. t['tokatakanahalfwidth'] = 0xFF84;
  8518. t['tonebarextrahighmod'] = 0x02E5;
  8519. t['tonebarextralowmod'] = 0x02E9;
  8520. t['tonebarhighmod'] = 0x02E6;
  8521. t['tonebarlowmod'] = 0x02E8;
  8522. t['tonebarmidmod'] = 0x02E7;
  8523. t['tonefive'] = 0x01BD;
  8524. t['tonesix'] = 0x0185;
  8525. t['tonetwo'] = 0x01A8;
  8526. t['tonos'] = 0x0384;
  8527. t['tonsquare'] = 0x3327;
  8528. t['topatakthai'] = 0x0E0F;
  8529. t['tortoiseshellbracketleft'] = 0x3014;
  8530. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  8531. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  8532. t['tortoiseshellbracketright'] = 0x3015;
  8533. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  8534. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  8535. t['totaothai'] = 0x0E15;
  8536. t['tpalatalhook'] = 0x01AB;
  8537. t['tparen'] = 0x24AF;
  8538. t['trademark'] = 0x2122;
  8539. t['trademarksans'] = 0xF8EA;
  8540. t['trademarkserif'] = 0xF6DB;
  8541. t['tretroflexhook'] = 0x0288;
  8542. t['triagdn'] = 0x25BC;
  8543. t['triaglf'] = 0x25C4;
  8544. t['triagrt'] = 0x25BA;
  8545. t['triagup'] = 0x25B2;
  8546. t['ts'] = 0x02A6;
  8547. t['tsadi'] = 0x05E6;
  8548. t['tsadidagesh'] = 0xFB46;
  8549. t['tsadidageshhebrew'] = 0xFB46;
  8550. t['tsadihebrew'] = 0x05E6;
  8551. t['tsecyrillic'] = 0x0446;
  8552. t['tsere'] = 0x05B5;
  8553. t['tsere12'] = 0x05B5;
  8554. t['tsere1e'] = 0x05B5;
  8555. t['tsere2b'] = 0x05B5;
  8556. t['tserehebrew'] = 0x05B5;
  8557. t['tserenarrowhebrew'] = 0x05B5;
  8558. t['tserequarterhebrew'] = 0x05B5;
  8559. t['tserewidehebrew'] = 0x05B5;
  8560. t['tshecyrillic'] = 0x045B;
  8561. t['tsuperior'] = 0xF6F3;
  8562. t['ttabengali'] = 0x099F;
  8563. t['ttadeva'] = 0x091F;
  8564. t['ttagujarati'] = 0x0A9F;
  8565. t['ttagurmukhi'] = 0x0A1F;
  8566. t['tteharabic'] = 0x0679;
  8567. t['ttehfinalarabic'] = 0xFB67;
  8568. t['ttehinitialarabic'] = 0xFB68;
  8569. t['ttehmedialarabic'] = 0xFB69;
  8570. t['tthabengali'] = 0x09A0;
  8571. t['tthadeva'] = 0x0920;
  8572. t['tthagujarati'] = 0x0AA0;
  8573. t['tthagurmukhi'] = 0x0A20;
  8574. t['tturned'] = 0x0287;
  8575. t['tuhiragana'] = 0x3064;
  8576. t['tukatakana'] = 0x30C4;
  8577. t['tukatakanahalfwidth'] = 0xFF82;
  8578. t['tusmallhiragana'] = 0x3063;
  8579. t['tusmallkatakana'] = 0x30C3;
  8580. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  8581. t['twelvecircle'] = 0x246B;
  8582. t['twelveparen'] = 0x247F;
  8583. t['twelveperiod'] = 0x2493;
  8584. t['twelveroman'] = 0x217B;
  8585. t['twentycircle'] = 0x2473;
  8586. t['twentyhangzhou'] = 0x5344;
  8587. t['twentyparen'] = 0x2487;
  8588. t['twentyperiod'] = 0x249B;
  8589. t['two'] = 0x0032;
  8590. t['twoarabic'] = 0x0662;
  8591. t['twobengali'] = 0x09E8;
  8592. t['twocircle'] = 0x2461;
  8593. t['twocircleinversesansserif'] = 0x278B;
  8594. t['twodeva'] = 0x0968;
  8595. t['twodotenleader'] = 0x2025;
  8596. t['twodotleader'] = 0x2025;
  8597. t['twodotleadervertical'] = 0xFE30;
  8598. t['twogujarati'] = 0x0AE8;
  8599. t['twogurmukhi'] = 0x0A68;
  8600. t['twohackarabic'] = 0x0662;
  8601. t['twohangzhou'] = 0x3022;
  8602. t['twoideographicparen'] = 0x3221;
  8603. t['twoinferior'] = 0x2082;
  8604. t['twomonospace'] = 0xFF12;
  8605. t['twonumeratorbengali'] = 0x09F5;
  8606. t['twooldstyle'] = 0xF732;
  8607. t['twoparen'] = 0x2475;
  8608. t['twoperiod'] = 0x2489;
  8609. t['twopersian'] = 0x06F2;
  8610. t['tworoman'] = 0x2171;
  8611. t['twostroke'] = 0x01BB;
  8612. t['twosuperior'] = 0x00B2;
  8613. t['twothai'] = 0x0E52;
  8614. t['twothirds'] = 0x2154;
  8615. t['u'] = 0x0075;
  8616. t['uacute'] = 0x00FA;
  8617. t['ubar'] = 0x0289;
  8618. t['ubengali'] = 0x0989;
  8619. t['ubopomofo'] = 0x3128;
  8620. t['ubreve'] = 0x016D;
  8621. t['ucaron'] = 0x01D4;
  8622. t['ucircle'] = 0x24E4;
  8623. t['ucircumflex'] = 0x00FB;
  8624. t['ucircumflexbelow'] = 0x1E77;
  8625. t['ucyrillic'] = 0x0443;
  8626. t['udattadeva'] = 0x0951;
  8627. t['udblacute'] = 0x0171;
  8628. t['udblgrave'] = 0x0215;
  8629. t['udeva'] = 0x0909;
  8630. t['udieresis'] = 0x00FC;
  8631. t['udieresisacute'] = 0x01D8;
  8632. t['udieresisbelow'] = 0x1E73;
  8633. t['udieresiscaron'] = 0x01DA;
  8634. t['udieresiscyrillic'] = 0x04F1;
  8635. t['udieresisgrave'] = 0x01DC;
  8636. t['udieresismacron'] = 0x01D6;
  8637. t['udotbelow'] = 0x1EE5;
  8638. t['ugrave'] = 0x00F9;
  8639. t['ugujarati'] = 0x0A89;
  8640. t['ugurmukhi'] = 0x0A09;
  8641. t['uhiragana'] = 0x3046;
  8642. t['uhookabove'] = 0x1EE7;
  8643. t['uhorn'] = 0x01B0;
  8644. t['uhornacute'] = 0x1EE9;
  8645. t['uhorndotbelow'] = 0x1EF1;
  8646. t['uhorngrave'] = 0x1EEB;
  8647. t['uhornhookabove'] = 0x1EED;
  8648. t['uhorntilde'] = 0x1EEF;
  8649. t['uhungarumlaut'] = 0x0171;
  8650. t['uhungarumlautcyrillic'] = 0x04F3;
  8651. t['uinvertedbreve'] = 0x0217;
  8652. t['ukatakana'] = 0x30A6;
  8653. t['ukatakanahalfwidth'] = 0xFF73;
  8654. t['ukcyrillic'] = 0x0479;
  8655. t['ukorean'] = 0x315C;
  8656. t['umacron'] = 0x016B;
  8657. t['umacroncyrillic'] = 0x04EF;
  8658. t['umacrondieresis'] = 0x1E7B;
  8659. t['umatragurmukhi'] = 0x0A41;
  8660. t['umonospace'] = 0xFF55;
  8661. t['underscore'] = 0x005F;
  8662. t['underscoredbl'] = 0x2017;
  8663. t['underscoremonospace'] = 0xFF3F;
  8664. t['underscorevertical'] = 0xFE33;
  8665. t['underscorewavy'] = 0xFE4F;
  8666. t['union'] = 0x222A;
  8667. t['universal'] = 0x2200;
  8668. t['uogonek'] = 0x0173;
  8669. t['uparen'] = 0x24B0;
  8670. t['upblock'] = 0x2580;
  8671. t['upperdothebrew'] = 0x05C4;
  8672. t['upsilon'] = 0x03C5;
  8673. t['upsilondieresis'] = 0x03CB;
  8674. t['upsilondieresistonos'] = 0x03B0;
  8675. t['upsilonlatin'] = 0x028A;
  8676. t['upsilontonos'] = 0x03CD;
  8677. t['uptackbelowcmb'] = 0x031D;
  8678. t['uptackmod'] = 0x02D4;
  8679. t['uragurmukhi'] = 0x0A73;
  8680. t['uring'] = 0x016F;
  8681. t['ushortcyrillic'] = 0x045E;
  8682. t['usmallhiragana'] = 0x3045;
  8683. t['usmallkatakana'] = 0x30A5;
  8684. t['usmallkatakanahalfwidth'] = 0xFF69;
  8685. t['ustraightcyrillic'] = 0x04AF;
  8686. t['ustraightstrokecyrillic'] = 0x04B1;
  8687. t['utilde'] = 0x0169;
  8688. t['utildeacute'] = 0x1E79;
  8689. t['utildebelow'] = 0x1E75;
  8690. t['uubengali'] = 0x098A;
  8691. t['uudeva'] = 0x090A;
  8692. t['uugujarati'] = 0x0A8A;
  8693. t['uugurmukhi'] = 0x0A0A;
  8694. t['uumatragurmukhi'] = 0x0A42;
  8695. t['uuvowelsignbengali'] = 0x09C2;
  8696. t['uuvowelsigndeva'] = 0x0942;
  8697. t['uuvowelsigngujarati'] = 0x0AC2;
  8698. t['uvowelsignbengali'] = 0x09C1;
  8699. t['uvowelsigndeva'] = 0x0941;
  8700. t['uvowelsigngujarati'] = 0x0AC1;
  8701. t['v'] = 0x0076;
  8702. t['vadeva'] = 0x0935;
  8703. t['vagujarati'] = 0x0AB5;
  8704. t['vagurmukhi'] = 0x0A35;
  8705. t['vakatakana'] = 0x30F7;
  8706. t['vav'] = 0x05D5;
  8707. t['vavdagesh'] = 0xFB35;
  8708. t['vavdagesh65'] = 0xFB35;
  8709. t['vavdageshhebrew'] = 0xFB35;
  8710. t['vavhebrew'] = 0x05D5;
  8711. t['vavholam'] = 0xFB4B;
  8712. t['vavholamhebrew'] = 0xFB4B;
  8713. t['vavvavhebrew'] = 0x05F0;
  8714. t['vavyodhebrew'] = 0x05F1;
  8715. t['vcircle'] = 0x24E5;
  8716. t['vdotbelow'] = 0x1E7F;
  8717. t['vecyrillic'] = 0x0432;
  8718. t['veharabic'] = 0x06A4;
  8719. t['vehfinalarabic'] = 0xFB6B;
  8720. t['vehinitialarabic'] = 0xFB6C;
  8721. t['vehmedialarabic'] = 0xFB6D;
  8722. t['vekatakana'] = 0x30F9;
  8723. t['venus'] = 0x2640;
  8724. t['verticalbar'] = 0x007C;
  8725. t['verticallineabovecmb'] = 0x030D;
  8726. t['verticallinebelowcmb'] = 0x0329;
  8727. t['verticallinelowmod'] = 0x02CC;
  8728. t['verticallinemod'] = 0x02C8;
  8729. t['vewarmenian'] = 0x057E;
  8730. t['vhook'] = 0x028B;
  8731. t['vikatakana'] = 0x30F8;
  8732. t['viramabengali'] = 0x09CD;
  8733. t['viramadeva'] = 0x094D;
  8734. t['viramagujarati'] = 0x0ACD;
  8735. t['visargabengali'] = 0x0983;
  8736. t['visargadeva'] = 0x0903;
  8737. t['visargagujarati'] = 0x0A83;
  8738. t['vmonospace'] = 0xFF56;
  8739. t['voarmenian'] = 0x0578;
  8740. t['voicediterationhiragana'] = 0x309E;
  8741. t['voicediterationkatakana'] = 0x30FE;
  8742. t['voicedmarkkana'] = 0x309B;
  8743. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  8744. t['vokatakana'] = 0x30FA;
  8745. t['vparen'] = 0x24B1;
  8746. t['vtilde'] = 0x1E7D;
  8747. t['vturned'] = 0x028C;
  8748. t['vuhiragana'] = 0x3094;
  8749. t['vukatakana'] = 0x30F4;
  8750. t['w'] = 0x0077;
  8751. t['wacute'] = 0x1E83;
  8752. t['waekorean'] = 0x3159;
  8753. t['wahiragana'] = 0x308F;
  8754. t['wakatakana'] = 0x30EF;
  8755. t['wakatakanahalfwidth'] = 0xFF9C;
  8756. t['wakorean'] = 0x3158;
  8757. t['wasmallhiragana'] = 0x308E;
  8758. t['wasmallkatakana'] = 0x30EE;
  8759. t['wattosquare'] = 0x3357;
  8760. t['wavedash'] = 0x301C;
  8761. t['wavyunderscorevertical'] = 0xFE34;
  8762. t['wawarabic'] = 0x0648;
  8763. t['wawfinalarabic'] = 0xFEEE;
  8764. t['wawhamzaabovearabic'] = 0x0624;
  8765. t['wawhamzaabovefinalarabic'] = 0xFE86;
  8766. t['wbsquare'] = 0x33DD;
  8767. t['wcircle'] = 0x24E6;
  8768. t['wcircumflex'] = 0x0175;
  8769. t['wdieresis'] = 0x1E85;
  8770. t['wdotaccent'] = 0x1E87;
  8771. t['wdotbelow'] = 0x1E89;
  8772. t['wehiragana'] = 0x3091;
  8773. t['weierstrass'] = 0x2118;
  8774. t['wekatakana'] = 0x30F1;
  8775. t['wekorean'] = 0x315E;
  8776. t['weokorean'] = 0x315D;
  8777. t['wgrave'] = 0x1E81;
  8778. t['whitebullet'] = 0x25E6;
  8779. t['whitecircle'] = 0x25CB;
  8780. t['whitecircleinverse'] = 0x25D9;
  8781. t['whitecornerbracketleft'] = 0x300E;
  8782. t['whitecornerbracketleftvertical'] = 0xFE43;
  8783. t['whitecornerbracketright'] = 0x300F;
  8784. t['whitecornerbracketrightvertical'] = 0xFE44;
  8785. t['whitediamond'] = 0x25C7;
  8786. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  8787. t['whitedownpointingsmalltriangle'] = 0x25BF;
  8788. t['whitedownpointingtriangle'] = 0x25BD;
  8789. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  8790. t['whiteleftpointingtriangle'] = 0x25C1;
  8791. t['whitelenticularbracketleft'] = 0x3016;
  8792. t['whitelenticularbracketright'] = 0x3017;
  8793. t['whiterightpointingsmalltriangle'] = 0x25B9;
  8794. t['whiterightpointingtriangle'] = 0x25B7;
  8795. t['whitesmallsquare'] = 0x25AB;
  8796. t['whitesmilingface'] = 0x263A;
  8797. t['whitesquare'] = 0x25A1;
  8798. t['whitestar'] = 0x2606;
  8799. t['whitetelephone'] = 0x260F;
  8800. t['whitetortoiseshellbracketleft'] = 0x3018;
  8801. t['whitetortoiseshellbracketright'] = 0x3019;
  8802. t['whiteuppointingsmalltriangle'] = 0x25B5;
  8803. t['whiteuppointingtriangle'] = 0x25B3;
  8804. t['wihiragana'] = 0x3090;
  8805. t['wikatakana'] = 0x30F0;
  8806. t['wikorean'] = 0x315F;
  8807. t['wmonospace'] = 0xFF57;
  8808. t['wohiragana'] = 0x3092;
  8809. t['wokatakana'] = 0x30F2;
  8810. t['wokatakanahalfwidth'] = 0xFF66;
  8811. t['won'] = 0x20A9;
  8812. t['wonmonospace'] = 0xFFE6;
  8813. t['wowaenthai'] = 0x0E27;
  8814. t['wparen'] = 0x24B2;
  8815. t['wring'] = 0x1E98;
  8816. t['wsuperior'] = 0x02B7;
  8817. t['wturned'] = 0x028D;
  8818. t['wynn'] = 0x01BF;
  8819. t['x'] = 0x0078;
  8820. t['xabovecmb'] = 0x033D;
  8821. t['xbopomofo'] = 0x3112;
  8822. t['xcircle'] = 0x24E7;
  8823. t['xdieresis'] = 0x1E8D;
  8824. t['xdotaccent'] = 0x1E8B;
  8825. t['xeharmenian'] = 0x056D;
  8826. t['xi'] = 0x03BE;
  8827. t['xmonospace'] = 0xFF58;
  8828. t['xparen'] = 0x24B3;
  8829. t['xsuperior'] = 0x02E3;
  8830. t['y'] = 0x0079;
  8831. t['yaadosquare'] = 0x334E;
  8832. t['yabengali'] = 0x09AF;
  8833. t['yacute'] = 0x00FD;
  8834. t['yadeva'] = 0x092F;
  8835. t['yaekorean'] = 0x3152;
  8836. t['yagujarati'] = 0x0AAF;
  8837. t['yagurmukhi'] = 0x0A2F;
  8838. t['yahiragana'] = 0x3084;
  8839. t['yakatakana'] = 0x30E4;
  8840. t['yakatakanahalfwidth'] = 0xFF94;
  8841. t['yakorean'] = 0x3151;
  8842. t['yamakkanthai'] = 0x0E4E;
  8843. t['yasmallhiragana'] = 0x3083;
  8844. t['yasmallkatakana'] = 0x30E3;
  8845. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  8846. t['yatcyrillic'] = 0x0463;
  8847. t['ycircle'] = 0x24E8;
  8848. t['ycircumflex'] = 0x0177;
  8849. t['ydieresis'] = 0x00FF;
  8850. t['ydotaccent'] = 0x1E8F;
  8851. t['ydotbelow'] = 0x1EF5;
  8852. t['yeharabic'] = 0x064A;
  8853. t['yehbarreearabic'] = 0x06D2;
  8854. t['yehbarreefinalarabic'] = 0xFBAF;
  8855. t['yehfinalarabic'] = 0xFEF2;
  8856. t['yehhamzaabovearabic'] = 0x0626;
  8857. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  8858. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  8859. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  8860. t['yehinitialarabic'] = 0xFEF3;
  8861. t['yehmedialarabic'] = 0xFEF4;
  8862. t['yehmeeminitialarabic'] = 0xFCDD;
  8863. t['yehmeemisolatedarabic'] = 0xFC58;
  8864. t['yehnoonfinalarabic'] = 0xFC94;
  8865. t['yehthreedotsbelowarabic'] = 0x06D1;
  8866. t['yekorean'] = 0x3156;
  8867. t['yen'] = 0x00A5;
  8868. t['yenmonospace'] = 0xFFE5;
  8869. t['yeokorean'] = 0x3155;
  8870. t['yeorinhieuhkorean'] = 0x3186;
  8871. t['yerahbenyomohebrew'] = 0x05AA;
  8872. t['yerahbenyomolefthebrew'] = 0x05AA;
  8873. t['yericyrillic'] = 0x044B;
  8874. t['yerudieresiscyrillic'] = 0x04F9;
  8875. t['yesieungkorean'] = 0x3181;
  8876. t['yesieungpansioskorean'] = 0x3183;
  8877. t['yesieungsioskorean'] = 0x3182;
  8878. t['yetivhebrew'] = 0x059A;
  8879. t['ygrave'] = 0x1EF3;
  8880. t['yhook'] = 0x01B4;
  8881. t['yhookabove'] = 0x1EF7;
  8882. t['yiarmenian'] = 0x0575;
  8883. t['yicyrillic'] = 0x0457;
  8884. t['yikorean'] = 0x3162;
  8885. t['yinyang'] = 0x262F;
  8886. t['yiwnarmenian'] = 0x0582;
  8887. t['ymonospace'] = 0xFF59;
  8888. t['yod'] = 0x05D9;
  8889. t['yoddagesh'] = 0xFB39;
  8890. t['yoddageshhebrew'] = 0xFB39;
  8891. t['yodhebrew'] = 0x05D9;
  8892. t['yodyodhebrew'] = 0x05F2;
  8893. t['yodyodpatahhebrew'] = 0xFB1F;
  8894. t['yohiragana'] = 0x3088;
  8895. t['yoikorean'] = 0x3189;
  8896. t['yokatakana'] = 0x30E8;
  8897. t['yokatakanahalfwidth'] = 0xFF96;
  8898. t['yokorean'] = 0x315B;
  8899. t['yosmallhiragana'] = 0x3087;
  8900. t['yosmallkatakana'] = 0x30E7;
  8901. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  8902. t['yotgreek'] = 0x03F3;
  8903. t['yoyaekorean'] = 0x3188;
  8904. t['yoyakorean'] = 0x3187;
  8905. t['yoyakthai'] = 0x0E22;
  8906. t['yoyingthai'] = 0x0E0D;
  8907. t['yparen'] = 0x24B4;
  8908. t['ypogegrammeni'] = 0x037A;
  8909. t['ypogegrammenigreekcmb'] = 0x0345;
  8910. t['yr'] = 0x01A6;
  8911. t['yring'] = 0x1E99;
  8912. t['ysuperior'] = 0x02B8;
  8913. t['ytilde'] = 0x1EF9;
  8914. t['yturned'] = 0x028E;
  8915. t['yuhiragana'] = 0x3086;
  8916. t['yuikorean'] = 0x318C;
  8917. t['yukatakana'] = 0x30E6;
  8918. t['yukatakanahalfwidth'] = 0xFF95;
  8919. t['yukorean'] = 0x3160;
  8920. t['yusbigcyrillic'] = 0x046B;
  8921. t['yusbigiotifiedcyrillic'] = 0x046D;
  8922. t['yuslittlecyrillic'] = 0x0467;
  8923. t['yuslittleiotifiedcyrillic'] = 0x0469;
  8924. t['yusmallhiragana'] = 0x3085;
  8925. t['yusmallkatakana'] = 0x30E5;
  8926. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  8927. t['yuyekorean'] = 0x318B;
  8928. t['yuyeokorean'] = 0x318A;
  8929. t['yyabengali'] = 0x09DF;
  8930. t['yyadeva'] = 0x095F;
  8931. t['z'] = 0x007A;
  8932. t['zaarmenian'] = 0x0566;
  8933. t['zacute'] = 0x017A;
  8934. t['zadeva'] = 0x095B;
  8935. t['zagurmukhi'] = 0x0A5B;
  8936. t['zaharabic'] = 0x0638;
  8937. t['zahfinalarabic'] = 0xFEC6;
  8938. t['zahinitialarabic'] = 0xFEC7;
  8939. t['zahiragana'] = 0x3056;
  8940. t['zahmedialarabic'] = 0xFEC8;
  8941. t['zainarabic'] = 0x0632;
  8942. t['zainfinalarabic'] = 0xFEB0;
  8943. t['zakatakana'] = 0x30B6;
  8944. t['zaqefgadolhebrew'] = 0x0595;
  8945. t['zaqefqatanhebrew'] = 0x0594;
  8946. t['zarqahebrew'] = 0x0598;
  8947. t['zayin'] = 0x05D6;
  8948. t['zayindagesh'] = 0xFB36;
  8949. t['zayindageshhebrew'] = 0xFB36;
  8950. t['zayinhebrew'] = 0x05D6;
  8951. t['zbopomofo'] = 0x3117;
  8952. t['zcaron'] = 0x017E;
  8953. t['zcircle'] = 0x24E9;
  8954. t['zcircumflex'] = 0x1E91;
  8955. t['zcurl'] = 0x0291;
  8956. t['zdot'] = 0x017C;
  8957. t['zdotaccent'] = 0x017C;
  8958. t['zdotbelow'] = 0x1E93;
  8959. t['zecyrillic'] = 0x0437;
  8960. t['zedescendercyrillic'] = 0x0499;
  8961. t['zedieresiscyrillic'] = 0x04DF;
  8962. t['zehiragana'] = 0x305C;
  8963. t['zekatakana'] = 0x30BC;
  8964. t['zero'] = 0x0030;
  8965. t['zeroarabic'] = 0x0660;
  8966. t['zerobengali'] = 0x09E6;
  8967. t['zerodeva'] = 0x0966;
  8968. t['zerogujarati'] = 0x0AE6;
  8969. t['zerogurmukhi'] = 0x0A66;
  8970. t['zerohackarabic'] = 0x0660;
  8971. t['zeroinferior'] = 0x2080;
  8972. t['zeromonospace'] = 0xFF10;
  8973. t['zerooldstyle'] = 0xF730;
  8974. t['zeropersian'] = 0x06F0;
  8975. t['zerosuperior'] = 0x2070;
  8976. t['zerothai'] = 0x0E50;
  8977. t['zerowidthjoiner'] = 0xFEFF;
  8978. t['zerowidthnonjoiner'] = 0x200C;
  8979. t['zerowidthspace'] = 0x200B;
  8980. t['zeta'] = 0x03B6;
  8981. t['zhbopomofo'] = 0x3113;
  8982. t['zhearmenian'] = 0x056A;
  8983. t['zhebrevecyrillic'] = 0x04C2;
  8984. t['zhecyrillic'] = 0x0436;
  8985. t['zhedescendercyrillic'] = 0x0497;
  8986. t['zhedieresiscyrillic'] = 0x04DD;
  8987. t['zihiragana'] = 0x3058;
  8988. t['zikatakana'] = 0x30B8;
  8989. t['zinorhebrew'] = 0x05AE;
  8990. t['zlinebelow'] = 0x1E95;
  8991. t['zmonospace'] = 0xFF5A;
  8992. t['zohiragana'] = 0x305E;
  8993. t['zokatakana'] = 0x30BE;
  8994. t['zparen'] = 0x24B5;
  8995. t['zretroflexhook'] = 0x0290;
  8996. t['zstroke'] = 0x01B6;
  8997. t['zuhiragana'] = 0x305A;
  8998. t['zukatakana'] = 0x30BA;
  8999. t['.notdef'] = 0x0000;
  9000. });
  9001. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  9002. t['space'] = 0x0020;
  9003. t['a1'] = 0x2701;
  9004. t['a2'] = 0x2702;
  9005. t['a202'] = 0x2703;
  9006. t['a3'] = 0x2704;
  9007. t['a4'] = 0x260E;
  9008. t['a5'] = 0x2706;
  9009. t['a119'] = 0x2707;
  9010. t['a118'] = 0x2708;
  9011. t['a117'] = 0x2709;
  9012. t['a11'] = 0x261B;
  9013. t['a12'] = 0x261E;
  9014. t['a13'] = 0x270C;
  9015. t['a14'] = 0x270D;
  9016. t['a15'] = 0x270E;
  9017. t['a16'] = 0x270F;
  9018. t['a105'] = 0x2710;
  9019. t['a17'] = 0x2711;
  9020. t['a18'] = 0x2712;
  9021. t['a19'] = 0x2713;
  9022. t['a20'] = 0x2714;
  9023. t['a21'] = 0x2715;
  9024. t['a22'] = 0x2716;
  9025. t['a23'] = 0x2717;
  9026. t['a24'] = 0x2718;
  9027. t['a25'] = 0x2719;
  9028. t['a26'] = 0x271A;
  9029. t['a27'] = 0x271B;
  9030. t['a28'] = 0x271C;
  9031. t['a6'] = 0x271D;
  9032. t['a7'] = 0x271E;
  9033. t['a8'] = 0x271F;
  9034. t['a9'] = 0x2720;
  9035. t['a10'] = 0x2721;
  9036. t['a29'] = 0x2722;
  9037. t['a30'] = 0x2723;
  9038. t['a31'] = 0x2724;
  9039. t['a32'] = 0x2725;
  9040. t['a33'] = 0x2726;
  9041. t['a34'] = 0x2727;
  9042. t['a35'] = 0x2605;
  9043. t['a36'] = 0x2729;
  9044. t['a37'] = 0x272A;
  9045. t['a38'] = 0x272B;
  9046. t['a39'] = 0x272C;
  9047. t['a40'] = 0x272D;
  9048. t['a41'] = 0x272E;
  9049. t['a42'] = 0x272F;
  9050. t['a43'] = 0x2730;
  9051. t['a44'] = 0x2731;
  9052. t['a45'] = 0x2732;
  9053. t['a46'] = 0x2733;
  9054. t['a47'] = 0x2734;
  9055. t['a48'] = 0x2735;
  9056. t['a49'] = 0x2736;
  9057. t['a50'] = 0x2737;
  9058. t['a51'] = 0x2738;
  9059. t['a52'] = 0x2739;
  9060. t['a53'] = 0x273A;
  9061. t['a54'] = 0x273B;
  9062. t['a55'] = 0x273C;
  9063. t['a56'] = 0x273D;
  9064. t['a57'] = 0x273E;
  9065. t['a58'] = 0x273F;
  9066. t['a59'] = 0x2740;
  9067. t['a60'] = 0x2741;
  9068. t['a61'] = 0x2742;
  9069. t['a62'] = 0x2743;
  9070. t['a63'] = 0x2744;
  9071. t['a64'] = 0x2745;
  9072. t['a65'] = 0x2746;
  9073. t['a66'] = 0x2747;
  9074. t['a67'] = 0x2748;
  9075. t['a68'] = 0x2749;
  9076. t['a69'] = 0x274A;
  9077. t['a70'] = 0x274B;
  9078. t['a71'] = 0x25CF;
  9079. t['a72'] = 0x274D;
  9080. t['a73'] = 0x25A0;
  9081. t['a74'] = 0x274F;
  9082. t['a203'] = 0x2750;
  9083. t['a75'] = 0x2751;
  9084. t['a204'] = 0x2752;
  9085. t['a76'] = 0x25B2;
  9086. t['a77'] = 0x25BC;
  9087. t['a78'] = 0x25C6;
  9088. t['a79'] = 0x2756;
  9089. t['a81'] = 0x25D7;
  9090. t['a82'] = 0x2758;
  9091. t['a83'] = 0x2759;
  9092. t['a84'] = 0x275A;
  9093. t['a97'] = 0x275B;
  9094. t['a98'] = 0x275C;
  9095. t['a99'] = 0x275D;
  9096. t['a100'] = 0x275E;
  9097. t['a101'] = 0x2761;
  9098. t['a102'] = 0x2762;
  9099. t['a103'] = 0x2763;
  9100. t['a104'] = 0x2764;
  9101. t['a106'] = 0x2765;
  9102. t['a107'] = 0x2766;
  9103. t['a108'] = 0x2767;
  9104. t['a112'] = 0x2663;
  9105. t['a111'] = 0x2666;
  9106. t['a110'] = 0x2665;
  9107. t['a109'] = 0x2660;
  9108. t['a120'] = 0x2460;
  9109. t['a121'] = 0x2461;
  9110. t['a122'] = 0x2462;
  9111. t['a123'] = 0x2463;
  9112. t['a124'] = 0x2464;
  9113. t['a125'] = 0x2465;
  9114. t['a126'] = 0x2466;
  9115. t['a127'] = 0x2467;
  9116. t['a128'] = 0x2468;
  9117. t['a129'] = 0x2469;
  9118. t['a130'] = 0x2776;
  9119. t['a131'] = 0x2777;
  9120. t['a132'] = 0x2778;
  9121. t['a133'] = 0x2779;
  9122. t['a134'] = 0x277A;
  9123. t['a135'] = 0x277B;
  9124. t['a136'] = 0x277C;
  9125. t['a137'] = 0x277D;
  9126. t['a138'] = 0x277E;
  9127. t['a139'] = 0x277F;
  9128. t['a140'] = 0x2780;
  9129. t['a141'] = 0x2781;
  9130. t['a142'] = 0x2782;
  9131. t['a143'] = 0x2783;
  9132. t['a144'] = 0x2784;
  9133. t['a145'] = 0x2785;
  9134. t['a146'] = 0x2786;
  9135. t['a147'] = 0x2787;
  9136. t['a148'] = 0x2788;
  9137. t['a149'] = 0x2789;
  9138. t['a150'] = 0x278A;
  9139. t['a151'] = 0x278B;
  9140. t['a152'] = 0x278C;
  9141. t['a153'] = 0x278D;
  9142. t['a154'] = 0x278E;
  9143. t['a155'] = 0x278F;
  9144. t['a156'] = 0x2790;
  9145. t['a157'] = 0x2791;
  9146. t['a158'] = 0x2792;
  9147. t['a159'] = 0x2793;
  9148. t['a160'] = 0x2794;
  9149. t['a161'] = 0x2192;
  9150. t['a163'] = 0x2194;
  9151. t['a164'] = 0x2195;
  9152. t['a196'] = 0x2798;
  9153. t['a165'] = 0x2799;
  9154. t['a192'] = 0x279A;
  9155. t['a166'] = 0x279B;
  9156. t['a167'] = 0x279C;
  9157. t['a168'] = 0x279D;
  9158. t['a169'] = 0x279E;
  9159. t['a170'] = 0x279F;
  9160. t['a171'] = 0x27A0;
  9161. t['a172'] = 0x27A1;
  9162. t['a173'] = 0x27A2;
  9163. t['a162'] = 0x27A3;
  9164. t['a174'] = 0x27A4;
  9165. t['a175'] = 0x27A5;
  9166. t['a176'] = 0x27A6;
  9167. t['a177'] = 0x27A7;
  9168. t['a178'] = 0x27A8;
  9169. t['a179'] = 0x27A9;
  9170. t['a193'] = 0x27AA;
  9171. t['a180'] = 0x27AB;
  9172. t['a199'] = 0x27AC;
  9173. t['a181'] = 0x27AD;
  9174. t['a200'] = 0x27AE;
  9175. t['a182'] = 0x27AF;
  9176. t['a201'] = 0x27B1;
  9177. t['a183'] = 0x27B2;
  9178. t['a184'] = 0x27B3;
  9179. t['a197'] = 0x27B4;
  9180. t['a185'] = 0x27B5;
  9181. t['a194'] = 0x27B6;
  9182. t['a198'] = 0x27B7;
  9183. t['a186'] = 0x27B8;
  9184. t['a195'] = 0x27B9;
  9185. t['a187'] = 0x27BA;
  9186. t['a188'] = 0x27BB;
  9187. t['a189'] = 0x27BC;
  9188. t['a190'] = 0x27BD;
  9189. t['a191'] = 0x27BE;
  9190. t['a89'] = 0x2768; // 0xF8D7
  9191. t['a90'] = 0x2769; // 0xF8D8
  9192. t['a93'] = 0x276A; // 0xF8D9
  9193. t['a94'] = 0x276B; // 0xF8DA
  9194. t['a91'] = 0x276C; // 0xF8DB
  9195. t['a92'] = 0x276D; // 0xF8DC
  9196. t['a205'] = 0x276E; // 0xF8DD
  9197. t['a85'] = 0x276F; // 0xF8DE
  9198. t['a206'] = 0x2770; // 0xF8DF
  9199. t['a86'] = 0x2771; // 0xF8E0
  9200. t['a87'] = 0x2772; // 0xF8E1
  9201. t['a88'] = 0x2773; // 0xF8E2
  9202. t['a95'] = 0x2774; // 0xF8E3
  9203. t['a96'] = 0x2775; // 0xF8E4
  9204. t['.notdef'] = 0x0000;
  9205. });
  9206. exports.getGlyphsUnicode = getGlyphsUnicode;
  9207. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  9208. }));
  9209. (function (root, factory) {
  9210. {
  9211. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  9212. root.pdfjsCoreArithmeticDecoder);
  9213. }
  9214. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  9215. var error = sharedUtil.error;
  9216. var log2 = sharedUtil.log2;
  9217. var readInt8 = sharedUtil.readInt8;
  9218. var readUint16 = sharedUtil.readUint16;
  9219. var readUint32 = sharedUtil.readUint32;
  9220. var shadow = sharedUtil.shadow;
  9221. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  9222. var Jbig2Image = (function Jbig2ImageClosure() {
  9223. // Utility data structures
  9224. function ContextCache() {}
  9225. ContextCache.prototype = {
  9226. getContexts: function(id) {
  9227. if (id in this) {
  9228. return this[id];
  9229. }
  9230. return (this[id] = new Int8Array(1 << 16));
  9231. }
  9232. };
  9233. function DecodingContext(data, start, end) {
  9234. this.data = data;
  9235. this.start = start;
  9236. this.end = end;
  9237. }
  9238. DecodingContext.prototype = {
  9239. get decoder() {
  9240. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  9241. return shadow(this, 'decoder', decoder);
  9242. },
  9243. get contextCache() {
  9244. var cache = new ContextCache();
  9245. return shadow(this, 'contextCache', cache);
  9246. }
  9247. };
  9248. // Annex A. Arithmetic Integer Decoding Procedure
  9249. // A.2 Procedure for decoding values
  9250. function decodeInteger(contextCache, procedure, decoder) {
  9251. var contexts = contextCache.getContexts(procedure);
  9252. var prev = 1;
  9253. function readBits(length) {
  9254. var v = 0;
  9255. for (var i = 0; i < length; i++) {
  9256. var bit = decoder.readBit(contexts, prev);
  9257. prev = (prev < 256 ? (prev << 1) | bit :
  9258. (((prev << 1) | bit) & 511) | 256);
  9259. v = (v << 1) | bit;
  9260. }
  9261. return v >>> 0;
  9262. }
  9263. var sign = readBits(1);
  9264. var value = readBits(1) ?
  9265. (readBits(1) ?
  9266. (readBits(1) ?
  9267. (readBits(1) ?
  9268. (readBits(1) ?
  9269. (readBits(32) + 4436) :
  9270. readBits(12) + 340) :
  9271. readBits(8) + 84) :
  9272. readBits(6) + 20) :
  9273. readBits(4) + 4) :
  9274. readBits(2);
  9275. return (sign === 0 ? value : (value > 0 ? -value : null));
  9276. }
  9277. // A.3 The IAID decoding procedure
  9278. function decodeIAID(contextCache, decoder, codeLength) {
  9279. var contexts = contextCache.getContexts('IAID');
  9280. var prev = 1;
  9281. for (var i = 0; i < codeLength; i++) {
  9282. var bit = decoder.readBit(contexts, prev);
  9283. prev = (prev << 1) | bit;
  9284. }
  9285. if (codeLength < 31) {
  9286. return prev & ((1 << codeLength) - 1);
  9287. }
  9288. return prev & 0x7FFFFFFF;
  9289. }
  9290. // 7.3 Segment types
  9291. var SegmentTypes = [
  9292. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  9293. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  9294. null, null, null, null, null, 'patternDictionary', null, null, null,
  9295. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  9296. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  9297. null, null, null, null, null, 'IntermediateGenericRegion', null,
  9298. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  9299. 'IntermediateGenericRefinementRegion', null,
  9300. 'ImmediateGenericRefinementRegion',
  9301. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  9302. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  9303. 'Tables', null, null, null, null, null, null, null, null,
  9304. 'Extension'
  9305. ];
  9306. var CodingTemplates = [
  9307. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9308. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  9309. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9310. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  9311. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  9312. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  9313. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  9314. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  9315. {x: -1, y: 0}],
  9316. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  9317. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  9318. ];
  9319. var RefinementTemplates = [
  9320. {
  9321. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9322. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  9323. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  9324. },
  9325. {
  9326. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  9327. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  9328. {x: 0, y: 1}, {x: 1, y: 1}]
  9329. }
  9330. ];
  9331. // See 6.2.5.7 Decoding the bitmap.
  9332. var ReusedContexts = [
  9333. 0x9B25, // 10011 0110010 0101
  9334. 0x0795, // 0011 110010 101
  9335. 0x00E5, // 001 11001 01
  9336. 0x0195 // 011001 0101
  9337. ];
  9338. var RefinementReusedContexts = [
  9339. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  9340. 0x0008 // '0000' + '001000'
  9341. ];
  9342. function decodeBitmapTemplate0(width, height, decodingContext) {
  9343. var decoder = decodingContext.decoder;
  9344. var contexts = decodingContext.contextCache.getContexts('GB');
  9345. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  9346. // ...ooooo....
  9347. // ..ooooooo... Context template for current pixel (X)
  9348. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  9349. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  9350. for (i = 0; i < height; i++) {
  9351. row = bitmap[i] = new Uint8Array(width);
  9352. row1 = (i < 1) ? row : bitmap[i - 1];
  9353. row2 = (i < 2) ? row : bitmap[i - 2];
  9354. // At the beginning of each row:
  9355. // Fill contextLabel with pixels that are above/right of (X)
  9356. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  9357. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  9358. (row1[3] << 4);
  9359. for (j = 0; j < width; j++) {
  9360. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  9361. // At each pixel: Clear contextLabel pixels that are shifted
  9362. // out of the context, then add new ones.
  9363. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  9364. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  9365. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  9366. }
  9367. }
  9368. return bitmap;
  9369. }
  9370. // 6.2 Generic Region Decoding Procedure
  9371. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  9372. decodingContext) {
  9373. if (mmr) {
  9374. error('JBIG2 error: MMR encoding is not supported');
  9375. }
  9376. // Use optimized version for the most common case
  9377. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  9378. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  9379. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  9380. return decodeBitmapTemplate0(width, height, decodingContext);
  9381. }
  9382. var useskip = !!skip;
  9383. var template = CodingTemplates[templateIndex].concat(at);
  9384. // Sorting is non-standard, and it is not required. But sorting increases
  9385. // the number of template bits that can be reused from the previous
  9386. // contextLabel in the main loop.
  9387. template.sort(function (a, b) {
  9388. return (a.y - b.y) || (a.x - b.x);
  9389. });
  9390. var templateLength = template.length;
  9391. var templateX = new Int8Array(templateLength);
  9392. var templateY = new Int8Array(templateLength);
  9393. var changingTemplateEntries = [];
  9394. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  9395. var c, k;
  9396. for (k = 0; k < templateLength; k++) {
  9397. templateX[k] = template[k].x;
  9398. templateY[k] = template[k].y;
  9399. minX = Math.min(minX, template[k].x);
  9400. maxX = Math.max(maxX, template[k].x);
  9401. minY = Math.min(minY, template[k].y);
  9402. // Check if the template pixel appears in two consecutive context labels,
  9403. // so it can be reused. Otherwise, we add it to the list of changing
  9404. // template entries.
  9405. if (k < templateLength - 1 &&
  9406. template[k].y === template[k + 1].y &&
  9407. template[k].x === template[k + 1].x - 1) {
  9408. reuseMask |= 1 << (templateLength - 1 - k);
  9409. } else {
  9410. changingTemplateEntries.push(k);
  9411. }
  9412. }
  9413. var changingEntriesLength = changingTemplateEntries.length;
  9414. var changingTemplateX = new Int8Array(changingEntriesLength);
  9415. var changingTemplateY = new Int8Array(changingEntriesLength);
  9416. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  9417. for (c = 0; c < changingEntriesLength; c++) {
  9418. k = changingTemplateEntries[c];
  9419. changingTemplateX[c] = template[k].x;
  9420. changingTemplateY[c] = template[k].y;
  9421. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  9422. }
  9423. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  9424. var sbb_left = -minX;
  9425. var sbb_top = -minY;
  9426. var sbb_right = width - maxX;
  9427. var pseudoPixelContext = ReusedContexts[templateIndex];
  9428. var row = new Uint8Array(width);
  9429. var bitmap = [];
  9430. var decoder = decodingContext.decoder;
  9431. var contexts = decodingContext.contextCache.getContexts('GB');
  9432. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  9433. for (var i = 0; i < height; i++) {
  9434. if (prediction) {
  9435. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9436. ltp ^= sltp;
  9437. if (ltp) {
  9438. bitmap.push(row); // duplicate previous row
  9439. continue;
  9440. }
  9441. }
  9442. row = new Uint8Array(row);
  9443. bitmap.push(row);
  9444. for (j = 0; j < width; j++) {
  9445. if (useskip && skip[i][j]) {
  9446. row[j] = 0;
  9447. continue;
  9448. }
  9449. // Are we in the middle of a scanline, so we can reuse contextLabel
  9450. // bits?
  9451. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  9452. // If yes, we can just shift the bits that are reusable and only
  9453. // fetch the remaining ones.
  9454. contextLabel = (contextLabel << 1) & reuseMask;
  9455. for (k = 0; k < changingEntriesLength; k++) {
  9456. i0 = i + changingTemplateY[k];
  9457. j0 = j + changingTemplateX[k];
  9458. bit = bitmap[i0][j0];
  9459. if (bit) {
  9460. bit = changingTemplateBit[k];
  9461. contextLabel |= bit;
  9462. }
  9463. }
  9464. } else {
  9465. // compute the contextLabel from scratch
  9466. contextLabel = 0;
  9467. shift = templateLength - 1;
  9468. for (k = 0; k < templateLength; k++, shift--) {
  9469. j0 = j + templateX[k];
  9470. if (j0 >= 0 && j0 < width) {
  9471. i0 = i + templateY[k];
  9472. if (i0 >= 0) {
  9473. bit = bitmap[i0][j0];
  9474. if (bit) {
  9475. contextLabel |= bit << shift;
  9476. }
  9477. }
  9478. }
  9479. }
  9480. }
  9481. var pixel = decoder.readBit(contexts, contextLabel);
  9482. row[j] = pixel;
  9483. }
  9484. }
  9485. return bitmap;
  9486. }
  9487. // 6.3.2 Generic Refinement Region Decoding Procedure
  9488. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  9489. offsetX, offsetY, prediction, at,
  9490. decodingContext) {
  9491. var codingTemplate = RefinementTemplates[templateIndex].coding;
  9492. if (templateIndex === 0) {
  9493. codingTemplate = codingTemplate.concat([at[0]]);
  9494. }
  9495. var codingTemplateLength = codingTemplate.length;
  9496. var codingTemplateX = new Int32Array(codingTemplateLength);
  9497. var codingTemplateY = new Int32Array(codingTemplateLength);
  9498. var k;
  9499. for (k = 0; k < codingTemplateLength; k++) {
  9500. codingTemplateX[k] = codingTemplate[k].x;
  9501. codingTemplateY[k] = codingTemplate[k].y;
  9502. }
  9503. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  9504. if (templateIndex === 0) {
  9505. referenceTemplate = referenceTemplate.concat([at[1]]);
  9506. }
  9507. var referenceTemplateLength = referenceTemplate.length;
  9508. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  9509. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  9510. for (k = 0; k < referenceTemplateLength; k++) {
  9511. referenceTemplateX[k] = referenceTemplate[k].x;
  9512. referenceTemplateY[k] = referenceTemplate[k].y;
  9513. }
  9514. var referenceWidth = referenceBitmap[0].length;
  9515. var referenceHeight = referenceBitmap.length;
  9516. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  9517. var bitmap = [];
  9518. var decoder = decodingContext.decoder;
  9519. var contexts = decodingContext.contextCache.getContexts('GR');
  9520. var ltp = 0;
  9521. for (var i = 0; i < height; i++) {
  9522. if (prediction) {
  9523. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  9524. ltp ^= sltp;
  9525. if (ltp) {
  9526. error('JBIG2 error: prediction is not supported');
  9527. }
  9528. }
  9529. var row = new Uint8Array(width);
  9530. bitmap.push(row);
  9531. for (var j = 0; j < width; j++) {
  9532. var i0, j0;
  9533. var contextLabel = 0;
  9534. for (k = 0; k < codingTemplateLength; k++) {
  9535. i0 = i + codingTemplateY[k];
  9536. j0 = j + codingTemplateX[k];
  9537. if (i0 < 0 || j0 < 0 || j0 >= width) {
  9538. contextLabel <<= 1; // out of bound pixel
  9539. } else {
  9540. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  9541. }
  9542. }
  9543. for (k = 0; k < referenceTemplateLength; k++) {
  9544. i0 = i + referenceTemplateY[k] + offsetY;
  9545. j0 = j + referenceTemplateX[k] + offsetX;
  9546. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  9547. j0 >= referenceWidth) {
  9548. contextLabel <<= 1; // out of bound pixel
  9549. } else {
  9550. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  9551. }
  9552. }
  9553. var pixel = decoder.readBit(contexts, contextLabel);
  9554. row[j] = pixel;
  9555. }
  9556. }
  9557. return bitmap;
  9558. }
  9559. // 6.5.5 Decoding the symbol dictionary
  9560. function decodeSymbolDictionary(huffman, refinement, symbols,
  9561. numberOfNewSymbols, numberOfExportedSymbols,
  9562. huffmanTables, templateIndex, at,
  9563. refinementTemplateIndex, refinementAt,
  9564. decodingContext) {
  9565. if (huffman) {
  9566. error('JBIG2 error: huffman is not supported');
  9567. }
  9568. var newSymbols = [];
  9569. var currentHeight = 0;
  9570. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  9571. var decoder = decodingContext.decoder;
  9572. var contextCache = decodingContext.contextCache;
  9573. while (newSymbols.length < numberOfNewSymbols) {
  9574. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  9575. currentHeight += deltaHeight;
  9576. var currentWidth = 0;
  9577. var totalWidth = 0;
  9578. while (true) {
  9579. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  9580. if (deltaWidth === null) {
  9581. break; // OOB
  9582. }
  9583. currentWidth += deltaWidth;
  9584. totalWidth += currentWidth;
  9585. var bitmap;
  9586. if (refinement) {
  9587. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  9588. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  9589. if (numberOfInstances > 1) {
  9590. bitmap = decodeTextRegion(huffman, refinement,
  9591. currentWidth, currentHeight, 0,
  9592. numberOfInstances, 1, //strip size
  9593. symbols.concat(newSymbols),
  9594. symbolCodeLength,
  9595. 0, //transposed
  9596. 0, //ds offset
  9597. 1, //top left 7.4.3.1.1
  9598. 0, //OR operator
  9599. huffmanTables,
  9600. refinementTemplateIndex, refinementAt,
  9601. decodingContext);
  9602. } else {
  9603. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9604. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9605. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9606. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  9607. newSymbols[symbolId - symbols.length]);
  9608. bitmap = decodeRefinement(currentWidth, currentHeight,
  9609. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  9610. decodingContext);
  9611. }
  9612. } else {
  9613. // 6.5.8.1 Direct-coded symbol bitmap
  9614. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  9615. templateIndex, false, null, at, decodingContext);
  9616. }
  9617. newSymbols.push(bitmap);
  9618. }
  9619. }
  9620. // 6.5.10 Exported symbols
  9621. var exportedSymbols = [];
  9622. var flags = [], currentFlag = false;
  9623. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  9624. while (flags.length < totalSymbolsLength) {
  9625. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  9626. while (runLength--) {
  9627. flags.push(currentFlag);
  9628. }
  9629. currentFlag = !currentFlag;
  9630. }
  9631. for (var i = 0, ii = symbols.length; i < ii; i++) {
  9632. if (flags[i]) {
  9633. exportedSymbols.push(symbols[i]);
  9634. }
  9635. }
  9636. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  9637. if (flags[i]) {
  9638. exportedSymbols.push(newSymbols[j]);
  9639. }
  9640. }
  9641. return exportedSymbols;
  9642. }
  9643. function decodeTextRegion(huffman, refinement, width, height,
  9644. defaultPixelValue, numberOfSymbolInstances,
  9645. stripSize, inputSymbols, symbolCodeLength,
  9646. transposed, dsOffset, referenceCorner,
  9647. combinationOperator, huffmanTables,
  9648. refinementTemplateIndex, refinementAt,
  9649. decodingContext) {
  9650. if (huffman) {
  9651. error('JBIG2 error: huffman is not supported');
  9652. }
  9653. // Prepare bitmap
  9654. var bitmap = [];
  9655. var i, row;
  9656. for (i = 0; i < height; i++) {
  9657. row = new Uint8Array(width);
  9658. if (defaultPixelValue) {
  9659. for (var j = 0; j < width; j++) {
  9660. row[j] = defaultPixelValue;
  9661. }
  9662. }
  9663. bitmap.push(row);
  9664. }
  9665. var decoder = decodingContext.decoder;
  9666. var contextCache = decodingContext.contextCache;
  9667. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9668. var firstS = 0;
  9669. i = 0;
  9670. while (i < numberOfSymbolInstances) {
  9671. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  9672. stripT += deltaT;
  9673. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  9674. firstS += deltaFirstS;
  9675. var currentS = firstS;
  9676. do {
  9677. var currentT = (stripSize === 1 ? 0 :
  9678. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  9679. var t = stripSize * stripT + currentT;
  9680. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  9681. var applyRefinement = (refinement &&
  9682. decodeInteger(contextCache, 'IARI', decoder));
  9683. var symbolBitmap = inputSymbols[symbolId];
  9684. var symbolWidth = symbolBitmap[0].length;
  9685. var symbolHeight = symbolBitmap.length;
  9686. if (applyRefinement) {
  9687. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  9688. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  9689. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  9690. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  9691. symbolWidth += rdw;
  9692. symbolHeight += rdh;
  9693. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  9694. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  9695. (rdh >> 1) + rdy, false, refinementAt,
  9696. decodingContext);
  9697. }
  9698. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  9699. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  9700. var s2, t2, symbolRow;
  9701. if (transposed) {
  9702. // Place Symbol Bitmap from T1,S1
  9703. for (s2 = 0; s2 < symbolHeight; s2++) {
  9704. row = bitmap[offsetS + s2];
  9705. if (!row) {
  9706. continue;
  9707. }
  9708. symbolRow = symbolBitmap[s2];
  9709. // To ignore Parts of Symbol bitmap which goes
  9710. // outside bitmap region
  9711. var maxWidth = Math.min(width - offsetT, symbolWidth);
  9712. switch (combinationOperator) {
  9713. case 0: // OR
  9714. for (t2 = 0; t2 < maxWidth; t2++) {
  9715. row[offsetT + t2] |= symbolRow[t2];
  9716. }
  9717. break;
  9718. case 2: // XOR
  9719. for (t2 = 0; t2 < maxWidth; t2++) {
  9720. row[offsetT + t2] ^= symbolRow[t2];
  9721. }
  9722. break;
  9723. default:
  9724. error('JBIG2 error: operator ' + combinationOperator +
  9725. ' is not supported');
  9726. }
  9727. }
  9728. currentS += symbolHeight - 1;
  9729. } else {
  9730. for (t2 = 0; t2 < symbolHeight; t2++) {
  9731. row = bitmap[offsetT + t2];
  9732. if (!row) {
  9733. continue;
  9734. }
  9735. symbolRow = symbolBitmap[t2];
  9736. switch (combinationOperator) {
  9737. case 0: // OR
  9738. for (s2 = 0; s2 < symbolWidth; s2++) {
  9739. row[offsetS + s2] |= symbolRow[s2];
  9740. }
  9741. break;
  9742. case 2: // XOR
  9743. for (s2 = 0; s2 < symbolWidth; s2++) {
  9744. row[offsetS + s2] ^= symbolRow[s2];
  9745. }
  9746. break;
  9747. default:
  9748. error('JBIG2 error: operator ' + combinationOperator +
  9749. ' is not supported');
  9750. }
  9751. }
  9752. currentS += symbolWidth - 1;
  9753. }
  9754. i++;
  9755. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  9756. if (deltaS === null) {
  9757. break; // OOB
  9758. }
  9759. currentS += deltaS + dsOffset;
  9760. } while (true);
  9761. }
  9762. return bitmap;
  9763. }
  9764. function readSegmentHeader(data, start) {
  9765. var segmentHeader = {};
  9766. segmentHeader.number = readUint32(data, start);
  9767. var flags = data[start + 4];
  9768. var segmentType = flags & 0x3F;
  9769. if (!SegmentTypes[segmentType]) {
  9770. error('JBIG2 error: invalid segment type: ' + segmentType);
  9771. }
  9772. segmentHeader.type = segmentType;
  9773. segmentHeader.typeName = SegmentTypes[segmentType];
  9774. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  9775. var pageAssociationFieldSize = !!(flags & 0x40);
  9776. var referredFlags = data[start + 5];
  9777. var referredToCount = (referredFlags >> 5) & 7;
  9778. var retainBits = [referredFlags & 31];
  9779. var position = start + 6;
  9780. if (referredFlags === 7) {
  9781. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  9782. position += 3;
  9783. var bytes = (referredToCount + 7) >> 3;
  9784. retainBits[0] = data[position++];
  9785. while (--bytes > 0) {
  9786. retainBits.push(data[position++]);
  9787. }
  9788. } else if (referredFlags === 5 || referredFlags === 6) {
  9789. error('JBIG2 error: invalid referred-to flags');
  9790. }
  9791. segmentHeader.retainBits = retainBits;
  9792. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  9793. (segmentHeader.number <= 65536 ? 2 : 4));
  9794. var referredTo = [];
  9795. var i, ii;
  9796. for (i = 0; i < referredToCount; i++) {
  9797. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  9798. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  9799. readUint32(data, position)));
  9800. referredTo.push(number);
  9801. position += referredToSegmentNumberSize;
  9802. }
  9803. segmentHeader.referredTo = referredTo;
  9804. if (!pageAssociationFieldSize) {
  9805. segmentHeader.pageAssociation = data[position++];
  9806. } else {
  9807. segmentHeader.pageAssociation = readUint32(data, position);
  9808. position += 4;
  9809. }
  9810. segmentHeader.length = readUint32(data, position);
  9811. position += 4;
  9812. if (segmentHeader.length === 0xFFFFFFFF) {
  9813. // 7.2.7 Segment data length, unknown segment length
  9814. if (segmentType === 38) { // ImmediateGenericRegion
  9815. var genericRegionInfo = readRegionSegmentInformation(data, position);
  9816. var genericRegionSegmentFlags = data[position +
  9817. RegionSegmentInformationFieldLength];
  9818. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  9819. // searching for the segment end
  9820. var searchPatternLength = 6;
  9821. var searchPattern = new Uint8Array(searchPatternLength);
  9822. if (!genericRegionMmr) {
  9823. searchPattern[0] = 0xFF;
  9824. searchPattern[1] = 0xAC;
  9825. }
  9826. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  9827. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  9828. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  9829. searchPattern[5] = genericRegionInfo.height & 0xFF;
  9830. for (i = position, ii = data.length; i < ii; i++) {
  9831. var j = 0;
  9832. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  9833. j++;
  9834. }
  9835. if (j === searchPatternLength) {
  9836. segmentHeader.length = i + searchPatternLength;
  9837. break;
  9838. }
  9839. }
  9840. if (segmentHeader.length === 0xFFFFFFFF) {
  9841. error('JBIG2 error: segment end was not found');
  9842. }
  9843. } else {
  9844. error('JBIG2 error: invalid unknown segment length');
  9845. }
  9846. }
  9847. segmentHeader.headerEnd = position;
  9848. return segmentHeader;
  9849. }
  9850. function readSegments(header, data, start, end) {
  9851. var segments = [];
  9852. var position = start;
  9853. while (position < end) {
  9854. var segmentHeader = readSegmentHeader(data, position);
  9855. position = segmentHeader.headerEnd;
  9856. var segment = {
  9857. header: segmentHeader,
  9858. data: data
  9859. };
  9860. if (!header.randomAccess) {
  9861. segment.start = position;
  9862. position += segmentHeader.length;
  9863. segment.end = position;
  9864. }
  9865. segments.push(segment);
  9866. if (segmentHeader.type === 51) {
  9867. break; // end of file is found
  9868. }
  9869. }
  9870. if (header.randomAccess) {
  9871. for (var i = 0, ii = segments.length; i < ii; i++) {
  9872. segments[i].start = position;
  9873. position += segments[i].header.length;
  9874. segments[i].end = position;
  9875. }
  9876. }
  9877. return segments;
  9878. }
  9879. // 7.4.1 Region segment information field
  9880. function readRegionSegmentInformation(data, start) {
  9881. return {
  9882. width: readUint32(data, start),
  9883. height: readUint32(data, start + 4),
  9884. x: readUint32(data, start + 8),
  9885. y: readUint32(data, start + 12),
  9886. combinationOperator: data[start + 16] & 7
  9887. };
  9888. }
  9889. var RegionSegmentInformationFieldLength = 17;
  9890. function processSegment(segment, visitor) {
  9891. var header = segment.header;
  9892. var data = segment.data, position = segment.start, end = segment.end;
  9893. var args, at, i, atLength;
  9894. switch (header.type) {
  9895. case 0: // SymbolDictionary
  9896. // 7.4.2 Symbol dictionary segment syntax
  9897. var dictionary = {};
  9898. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  9899. dictionary.huffman = !!(dictionaryFlags & 1);
  9900. dictionary.refinement = !!(dictionaryFlags & 2);
  9901. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  9902. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  9903. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  9904. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  9905. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  9906. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  9907. dictionary.template = (dictionaryFlags >> 10) & 3;
  9908. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  9909. position += 2;
  9910. if (!dictionary.huffman) {
  9911. atLength = dictionary.template === 0 ? 4 : 1;
  9912. at = [];
  9913. for (i = 0; i < atLength; i++) {
  9914. at.push({
  9915. x: readInt8(data, position),
  9916. y: readInt8(data, position + 1)
  9917. });
  9918. position += 2;
  9919. }
  9920. dictionary.at = at;
  9921. }
  9922. if (dictionary.refinement && !dictionary.refinementTemplate) {
  9923. at = [];
  9924. for (i = 0; i < 2; i++) {
  9925. at.push({
  9926. x: readInt8(data, position),
  9927. y: readInt8(data, position + 1)
  9928. });
  9929. position += 2;
  9930. }
  9931. dictionary.refinementAt = at;
  9932. }
  9933. dictionary.numberOfExportedSymbols = readUint32(data, position);
  9934. position += 4;
  9935. dictionary.numberOfNewSymbols = readUint32(data, position);
  9936. position += 4;
  9937. args = [dictionary, header.number, header.referredTo,
  9938. data, position, end];
  9939. break;
  9940. case 6: // ImmediateTextRegion
  9941. case 7: // ImmediateLosslessTextRegion
  9942. var textRegion = {};
  9943. textRegion.info = readRegionSegmentInformation(data, position);
  9944. position += RegionSegmentInformationFieldLength;
  9945. var textRegionSegmentFlags = readUint16(data, position);
  9946. position += 2;
  9947. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  9948. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  9949. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  9950. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  9951. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  9952. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  9953. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  9954. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  9955. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  9956. if (textRegion.huffman) {
  9957. var textRegionHuffmanFlags = readUint16(data, position);
  9958. position += 2;
  9959. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  9960. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  9961. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  9962. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  9963. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  9964. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  9965. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  9966. textRegion.huffmanRefinementSizeSelector =
  9967. !!(textRegionHuffmanFlags & 14);
  9968. }
  9969. if (textRegion.refinement && !textRegion.refinementTemplate) {
  9970. at = [];
  9971. for (i = 0; i < 2; i++) {
  9972. at.push({
  9973. x: readInt8(data, position),
  9974. y: readInt8(data, position + 1)
  9975. });
  9976. position += 2;
  9977. }
  9978. textRegion.refinementAt = at;
  9979. }
  9980. textRegion.numberOfSymbolInstances = readUint32(data, position);
  9981. position += 4;
  9982. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  9983. if (textRegion.huffman) {
  9984. error('JBIG2 error: huffman is not supported');
  9985. }
  9986. args = [textRegion, header.referredTo, data, position, end];
  9987. break;
  9988. case 38: // ImmediateGenericRegion
  9989. case 39: // ImmediateLosslessGenericRegion
  9990. var genericRegion = {};
  9991. genericRegion.info = readRegionSegmentInformation(data, position);
  9992. position += RegionSegmentInformationFieldLength;
  9993. var genericRegionSegmentFlags = data[position++];
  9994. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  9995. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  9996. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  9997. if (!genericRegion.mmr) {
  9998. atLength = genericRegion.template === 0 ? 4 : 1;
  9999. at = [];
  10000. for (i = 0; i < atLength; i++) {
  10001. at.push({
  10002. x: readInt8(data, position),
  10003. y: readInt8(data, position + 1)
  10004. });
  10005. position += 2;
  10006. }
  10007. genericRegion.at = at;
  10008. }
  10009. args = [genericRegion, data, position, end];
  10010. break;
  10011. case 48: // PageInformation
  10012. var pageInfo = {
  10013. width: readUint32(data, position),
  10014. height: readUint32(data, position + 4),
  10015. resolutionX: readUint32(data, position + 8),
  10016. resolutionY: readUint32(data, position + 12)
  10017. };
  10018. if (pageInfo.height === 0xFFFFFFFF) {
  10019. delete pageInfo.height;
  10020. }
  10021. var pageSegmentFlags = data[position + 16];
  10022. var pageStripingInformation = readUint16(data, position + 17);
  10023. pageInfo.lossless = !!(pageSegmentFlags & 1);
  10024. pageInfo.refinement = !!(pageSegmentFlags & 2);
  10025. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  10026. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  10027. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  10028. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  10029. args = [pageInfo];
  10030. break;
  10031. case 49: // EndOfPage
  10032. break;
  10033. case 50: // EndOfStripe
  10034. break;
  10035. case 51: // EndOfFile
  10036. break;
  10037. case 62: // 7.4.15 defines 2 extension types which
  10038. // are comments and can be ignored.
  10039. break;
  10040. default:
  10041. error('JBIG2 error: segment type ' + header.typeName + '(' +
  10042. header.type + ') is not implemented');
  10043. }
  10044. var callbackName = 'on' + header.typeName;
  10045. if (callbackName in visitor) {
  10046. visitor[callbackName].apply(visitor, args);
  10047. }
  10048. }
  10049. function processSegments(segments, visitor) {
  10050. for (var i = 0, ii = segments.length; i < ii; i++) {
  10051. processSegment(segments[i], visitor);
  10052. }
  10053. }
  10054. function parseJbig2(data, start, end) {
  10055. var position = start;
  10056. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  10057. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  10058. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  10059. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  10060. error('JBIG2 error: invalid header');
  10061. }
  10062. var header = {};
  10063. position += 8;
  10064. var flags = data[position++];
  10065. header.randomAccess = !(flags & 1);
  10066. if (!(flags & 2)) {
  10067. header.numberOfPages = readUint32(data, position);
  10068. position += 4;
  10069. }
  10070. var segments = readSegments(header, data, position, end);
  10071. error('Not implemented');
  10072. // processSegments(segments, new SimpleSegmentVisitor());
  10073. }
  10074. function parseJbig2Chunks(chunks) {
  10075. var visitor = new SimpleSegmentVisitor();
  10076. for (var i = 0, ii = chunks.length; i < ii; i++) {
  10077. var chunk = chunks[i];
  10078. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  10079. processSegments(segments, visitor);
  10080. }
  10081. return visitor.buffer;
  10082. }
  10083. function SimpleSegmentVisitor() {}
  10084. SimpleSegmentVisitor.prototype = {
  10085. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  10086. this.currentPageInfo = info;
  10087. var rowSize = (info.width + 7) >> 3;
  10088. var buffer = new Uint8Array(rowSize * info.height);
  10089. // The contents of ArrayBuffers are initialized to 0.
  10090. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  10091. if (info.defaultPixelValue) {
  10092. for (var i = 0, ii = buffer.length; i < ii; i++) {
  10093. buffer[i] = 0xFF;
  10094. }
  10095. }
  10096. this.buffer = buffer;
  10097. },
  10098. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  10099. var pageInfo = this.currentPageInfo;
  10100. var width = regionInfo.width, height = regionInfo.height;
  10101. var rowSize = (pageInfo.width + 7) >> 3;
  10102. var combinationOperator = pageInfo.combinationOperatorOverride ?
  10103. regionInfo.combinationOperator : pageInfo.combinationOperator;
  10104. var buffer = this.buffer;
  10105. var mask0 = 128 >> (regionInfo.x & 7);
  10106. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  10107. var i, j, mask, offset;
  10108. switch (combinationOperator) {
  10109. case 0: // OR
  10110. for (i = 0; i < height; i++) {
  10111. mask = mask0;
  10112. offset = offset0;
  10113. for (j = 0; j < width; j++) {
  10114. if (bitmap[i][j]) {
  10115. buffer[offset] |= mask;
  10116. }
  10117. mask >>= 1;
  10118. if (!mask) {
  10119. mask = 128;
  10120. offset++;
  10121. }
  10122. }
  10123. offset0 += rowSize;
  10124. }
  10125. break;
  10126. case 2: // XOR
  10127. for (i = 0; i < height; i++) {
  10128. mask = mask0;
  10129. offset = offset0;
  10130. for (j = 0; j < width; j++) {
  10131. if (bitmap[i][j]) {
  10132. buffer[offset] ^= mask;
  10133. }
  10134. mask >>= 1;
  10135. if (!mask) {
  10136. mask = 128;
  10137. offset++;
  10138. }
  10139. }
  10140. offset0 += rowSize;
  10141. }
  10142. break;
  10143. default:
  10144. error('JBIG2 error: operator ' + combinationOperator +
  10145. ' is not supported');
  10146. }
  10147. },
  10148. onImmediateGenericRegion:
  10149. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  10150. start, end) {
  10151. var regionInfo = region.info;
  10152. var decodingContext = new DecodingContext(data, start, end);
  10153. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  10154. region.template, region.prediction, null,
  10155. region.at, decodingContext);
  10156. this.drawBitmap(regionInfo, bitmap);
  10157. },
  10158. onImmediateLosslessGenericRegion:
  10159. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  10160. this.onImmediateGenericRegion.apply(this, arguments);
  10161. },
  10162. onSymbolDictionary:
  10163. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  10164. currentSegment,
  10165. referredSegments,
  10166. data, start, end) {
  10167. var huffmanTables;
  10168. if (dictionary.huffman) {
  10169. error('JBIG2 error: huffman is not supported');
  10170. }
  10171. // Combines exported symbols from all referred segments
  10172. var symbols = this.symbols;
  10173. if (!symbols) {
  10174. this.symbols = symbols = {};
  10175. }
  10176. var inputSymbols = [];
  10177. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10178. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10179. }
  10180. var decodingContext = new DecodingContext(data, start, end);
  10181. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  10182. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  10183. dictionary.numberOfExportedSymbols, huffmanTables,
  10184. dictionary.template, dictionary.at,
  10185. dictionary.refinementTemplate, dictionary.refinementAt,
  10186. decodingContext);
  10187. },
  10188. onImmediateTextRegion:
  10189. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  10190. referredSegments,
  10191. data, start, end) {
  10192. var regionInfo = region.info;
  10193. var huffmanTables;
  10194. // Combines exported symbols from all referred segments
  10195. var symbols = this.symbols;
  10196. var inputSymbols = [];
  10197. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  10198. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  10199. }
  10200. var symbolCodeLength = log2(inputSymbols.length);
  10201. var decodingContext = new DecodingContext(data, start, end);
  10202. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  10203. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  10204. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  10205. symbolCodeLength, region.transposed, region.dsOffset,
  10206. region.referenceCorner, region.combinationOperator, huffmanTables,
  10207. region.refinementTemplate, region.refinementAt, decodingContext);
  10208. this.drawBitmap(regionInfo, bitmap);
  10209. },
  10210. onImmediateLosslessTextRegion:
  10211. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  10212. this.onImmediateTextRegion.apply(this, arguments);
  10213. }
  10214. };
  10215. function Jbig2Image() {}
  10216. Jbig2Image.prototype = {
  10217. parseChunks: function Jbig2Image_parseChunks(chunks) {
  10218. return parseJbig2Chunks(chunks);
  10219. }
  10220. };
  10221. return Jbig2Image;
  10222. })();
  10223. exports.Jbig2Image = Jbig2Image;
  10224. }));
  10225. (function (root, factory) {
  10226. {
  10227. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  10228. root.pdfjsCoreArithmeticDecoder);
  10229. }
  10230. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10231. var info = sharedUtil.info;
  10232. var log2 = sharedUtil.log2;
  10233. var readUint16 = sharedUtil.readUint16;
  10234. var readUint32 = sharedUtil.readUint32;
  10235. var warn = sharedUtil.warn;
  10236. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10237. var JpxImage = (function JpxImageClosure() {
  10238. // Table E.1
  10239. var SubbandsGainLog2 = {
  10240. 'LL': 0,
  10241. 'LH': 1,
  10242. 'HL': 1,
  10243. 'HH': 2
  10244. };
  10245. function JpxImage() {
  10246. this.failOnCorruptedImage = false;
  10247. }
  10248. JpxImage.prototype = {
  10249. parse: function JpxImage_parse(data) {
  10250. var head = readUint16(data, 0);
  10251. // No box header, immediate start of codestream (SOC)
  10252. if (head === 0xFF4F) {
  10253. this.parseCodestream(data, 0, data.length);
  10254. return;
  10255. }
  10256. var position = 0, length = data.length;
  10257. while (position < length) {
  10258. var headerSize = 8;
  10259. var lbox = readUint32(data, position);
  10260. var tbox = readUint32(data, position + 4);
  10261. position += headerSize;
  10262. if (lbox === 1) {
  10263. // XLBox: read UInt64 according to spec.
  10264. // JavaScript's int precision of 53 bit should be sufficient here.
  10265. lbox = readUint32(data, position) * 4294967296 +
  10266. readUint32(data, position + 4);
  10267. position += 8;
  10268. headerSize += 8;
  10269. }
  10270. if (lbox === 0) {
  10271. lbox = length - position + headerSize;
  10272. }
  10273. if (lbox < headerSize) {
  10274. throw new Error('JPX Error: Invalid box field size');
  10275. }
  10276. var dataLength = lbox - headerSize;
  10277. var jumpDataLength = true;
  10278. switch (tbox) {
  10279. case 0x6A703268: // 'jp2h'
  10280. jumpDataLength = false; // parsing child boxes
  10281. break;
  10282. case 0x636F6C72: // 'colr'
  10283. // Colorspaces are not used, the CS from the PDF is used.
  10284. var method = data[position];
  10285. if (method === 1) {
  10286. // enumerated colorspace
  10287. var colorspace = readUint32(data, position + 3);
  10288. switch (colorspace) {
  10289. case 16: // this indicates a sRGB colorspace
  10290. case 17: // this indicates a grayscale colorspace
  10291. case 18: // this indicates a YUV colorspace
  10292. break;
  10293. default:
  10294. warn('Unknown colorspace ' + colorspace);
  10295. break;
  10296. }
  10297. } else if (method === 2) {
  10298. info('ICC profile not supported');
  10299. }
  10300. break;
  10301. case 0x6A703263: // 'jp2c'
  10302. this.parseCodestream(data, position, position + dataLength);
  10303. break;
  10304. case 0x6A502020: // 'jP\024\024'
  10305. if (0x0d0a870a !== readUint32(data, position)) {
  10306. warn('Invalid JP2 signature');
  10307. }
  10308. break;
  10309. // The following header types are valid but currently not used:
  10310. case 0x6A501A1A: // 'jP\032\032'
  10311. case 0x66747970: // 'ftyp'
  10312. case 0x72726571: // 'rreq'
  10313. case 0x72657320: // 'res '
  10314. case 0x69686472: // 'ihdr'
  10315. break;
  10316. default:
  10317. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  10318. (tbox >> 16) & 0xFF,
  10319. (tbox >> 8) & 0xFF,
  10320. tbox & 0xFF);
  10321. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  10322. break;
  10323. }
  10324. if (jumpDataLength) {
  10325. position += dataLength;
  10326. }
  10327. }
  10328. },
  10329. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  10330. var newByte = stream.getByte();
  10331. while (newByte >= 0) {
  10332. var oldByte = newByte;
  10333. newByte = stream.getByte();
  10334. var code = (oldByte << 8) | newByte;
  10335. // Image and tile size (SIZ)
  10336. if (code === 0xFF51) {
  10337. stream.skip(4);
  10338. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  10339. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  10340. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  10341. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  10342. stream.skip(16);
  10343. var Csiz = stream.getUint16(); // Byte 36
  10344. this.width = Xsiz - XOsiz;
  10345. this.height = Ysiz - YOsiz;
  10346. this.componentsCount = Csiz;
  10347. // Results are always returned as Uint8Arrays
  10348. this.bitsPerComponent = 8;
  10349. return;
  10350. }
  10351. }
  10352. throw new Error('JPX Error: No size marker found in JPX stream');
  10353. },
  10354. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  10355. var context = {};
  10356. try {
  10357. var doNotRecover = false;
  10358. var position = start;
  10359. while (position + 1 < end) {
  10360. var code = readUint16(data, position);
  10361. position += 2;
  10362. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  10363. switch (code) {
  10364. case 0xFF4F: // Start of codestream (SOC)
  10365. context.mainHeader = true;
  10366. break;
  10367. case 0xFFD9: // End of codestream (EOC)
  10368. break;
  10369. case 0xFF51: // Image and tile size (SIZ)
  10370. length = readUint16(data, position);
  10371. var siz = {};
  10372. siz.Xsiz = readUint32(data, position + 4);
  10373. siz.Ysiz = readUint32(data, position + 8);
  10374. siz.XOsiz = readUint32(data, position + 12);
  10375. siz.YOsiz = readUint32(data, position + 16);
  10376. siz.XTsiz = readUint32(data, position + 20);
  10377. siz.YTsiz = readUint32(data, position + 24);
  10378. siz.XTOsiz = readUint32(data, position + 28);
  10379. siz.YTOsiz = readUint32(data, position + 32);
  10380. var componentsCount = readUint16(data, position + 36);
  10381. siz.Csiz = componentsCount;
  10382. var components = [];
  10383. j = position + 38;
  10384. for (var i = 0; i < componentsCount; i++) {
  10385. var component = {
  10386. precision: (data[j] & 0x7F) + 1,
  10387. isSigned: !!(data[j] & 0x80),
  10388. XRsiz: data[j + 1],
  10389. YRsiz: data[j + 1]
  10390. };
  10391. calculateComponentDimensions(component, siz);
  10392. components.push(component);
  10393. }
  10394. context.SIZ = siz;
  10395. context.components = components;
  10396. calculateTileGrids(context, components);
  10397. context.QCC = [];
  10398. context.COC = [];
  10399. break;
  10400. case 0xFF5C: // Quantization default (QCD)
  10401. length = readUint16(data, position);
  10402. var qcd = {};
  10403. j = position + 2;
  10404. sqcd = data[j++];
  10405. switch (sqcd & 0x1F) {
  10406. case 0:
  10407. spqcdSize = 8;
  10408. scalarExpounded = true;
  10409. break;
  10410. case 1:
  10411. spqcdSize = 16;
  10412. scalarExpounded = false;
  10413. break;
  10414. case 2:
  10415. spqcdSize = 16;
  10416. scalarExpounded = true;
  10417. break;
  10418. default:
  10419. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10420. }
  10421. qcd.noQuantization = (spqcdSize === 8);
  10422. qcd.scalarExpounded = scalarExpounded;
  10423. qcd.guardBits = sqcd >> 5;
  10424. spqcds = [];
  10425. while (j < length + position) {
  10426. var spqcd = {};
  10427. if (spqcdSize === 8) {
  10428. spqcd.epsilon = data[j++] >> 3;
  10429. spqcd.mu = 0;
  10430. } else {
  10431. spqcd.epsilon = data[j] >> 3;
  10432. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10433. j += 2;
  10434. }
  10435. spqcds.push(spqcd);
  10436. }
  10437. qcd.SPqcds = spqcds;
  10438. if (context.mainHeader) {
  10439. context.QCD = qcd;
  10440. } else {
  10441. context.currentTile.QCD = qcd;
  10442. context.currentTile.QCC = [];
  10443. }
  10444. break;
  10445. case 0xFF5D: // Quantization component (QCC)
  10446. length = readUint16(data, position);
  10447. var qcc = {};
  10448. j = position + 2;
  10449. var cqcc;
  10450. if (context.SIZ.Csiz < 257) {
  10451. cqcc = data[j++];
  10452. } else {
  10453. cqcc = readUint16(data, j);
  10454. j += 2;
  10455. }
  10456. sqcd = data[j++];
  10457. switch (sqcd & 0x1F) {
  10458. case 0:
  10459. spqcdSize = 8;
  10460. scalarExpounded = true;
  10461. break;
  10462. case 1:
  10463. spqcdSize = 16;
  10464. scalarExpounded = false;
  10465. break;
  10466. case 2:
  10467. spqcdSize = 16;
  10468. scalarExpounded = true;
  10469. break;
  10470. default:
  10471. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  10472. }
  10473. qcc.noQuantization = (spqcdSize === 8);
  10474. qcc.scalarExpounded = scalarExpounded;
  10475. qcc.guardBits = sqcd >> 5;
  10476. spqcds = [];
  10477. while (j < (length + position)) {
  10478. spqcd = {};
  10479. if (spqcdSize === 8) {
  10480. spqcd.epsilon = data[j++] >> 3;
  10481. spqcd.mu = 0;
  10482. } else {
  10483. spqcd.epsilon = data[j] >> 3;
  10484. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  10485. j += 2;
  10486. }
  10487. spqcds.push(spqcd);
  10488. }
  10489. qcc.SPqcds = spqcds;
  10490. if (context.mainHeader) {
  10491. context.QCC[cqcc] = qcc;
  10492. } else {
  10493. context.currentTile.QCC[cqcc] = qcc;
  10494. }
  10495. break;
  10496. case 0xFF52: // Coding style default (COD)
  10497. length = readUint16(data, position);
  10498. var cod = {};
  10499. j = position + 2;
  10500. var scod = data[j++];
  10501. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  10502. cod.sopMarkerUsed = !!(scod & 2);
  10503. cod.ephMarkerUsed = !!(scod & 4);
  10504. cod.progressionOrder = data[j++];
  10505. cod.layersCount = readUint16(data, j);
  10506. j += 2;
  10507. cod.multipleComponentTransform = data[j++];
  10508. cod.decompositionLevelsCount = data[j++];
  10509. cod.xcb = (data[j++] & 0xF) + 2;
  10510. cod.ycb = (data[j++] & 0xF) + 2;
  10511. var blockStyle = data[j++];
  10512. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  10513. cod.resetContextProbabilities = !!(blockStyle & 2);
  10514. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  10515. cod.verticalyStripe = !!(blockStyle & 8);
  10516. cod.predictableTermination = !!(blockStyle & 16);
  10517. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  10518. cod.reversibleTransformation = data[j++];
  10519. if (cod.entropyCoderWithCustomPrecincts) {
  10520. var precinctsSizes = [];
  10521. while (j < length + position) {
  10522. var precinctsSize = data[j++];
  10523. precinctsSizes.push({
  10524. PPx: precinctsSize & 0xF,
  10525. PPy: precinctsSize >> 4
  10526. });
  10527. }
  10528. cod.precinctsSizes = precinctsSizes;
  10529. }
  10530. var unsupported = [];
  10531. if (cod.selectiveArithmeticCodingBypass) {
  10532. unsupported.push('selectiveArithmeticCodingBypass');
  10533. }
  10534. if (cod.resetContextProbabilities) {
  10535. unsupported.push('resetContextProbabilities');
  10536. }
  10537. if (cod.terminationOnEachCodingPass) {
  10538. unsupported.push('terminationOnEachCodingPass');
  10539. }
  10540. if (cod.verticalyStripe) {
  10541. unsupported.push('verticalyStripe');
  10542. }
  10543. if (cod.predictableTermination) {
  10544. unsupported.push('predictableTermination');
  10545. }
  10546. if (unsupported.length > 0) {
  10547. doNotRecover = true;
  10548. throw new Error('JPX Error: Unsupported COD options (' +
  10549. unsupported.join(', ') + ')');
  10550. }
  10551. if (context.mainHeader) {
  10552. context.COD = cod;
  10553. } else {
  10554. context.currentTile.COD = cod;
  10555. context.currentTile.COC = [];
  10556. }
  10557. break;
  10558. case 0xFF90: // Start of tile-part (SOT)
  10559. length = readUint16(data, position);
  10560. tile = {};
  10561. tile.index = readUint16(data, position + 2);
  10562. tile.length = readUint32(data, position + 4);
  10563. tile.dataEnd = tile.length + position - 2;
  10564. tile.partIndex = data[position + 8];
  10565. tile.partsCount = data[position + 9];
  10566. context.mainHeader = false;
  10567. if (tile.partIndex === 0) {
  10568. // reset component specific settings
  10569. tile.COD = context.COD;
  10570. tile.COC = context.COC.slice(0); // clone of the global COC
  10571. tile.QCD = context.QCD;
  10572. tile.QCC = context.QCC.slice(0); // clone of the global COC
  10573. }
  10574. context.currentTile = tile;
  10575. break;
  10576. case 0xFF93: // Start of data (SOD)
  10577. tile = context.currentTile;
  10578. if (tile.partIndex === 0) {
  10579. initializeTile(context, tile.index);
  10580. buildPackets(context);
  10581. }
  10582. // moving to the end of the data
  10583. length = tile.dataEnd - position;
  10584. parseTilePackets(context, data, position, length);
  10585. break;
  10586. case 0xFF55: // Tile-part lengths, main header (TLM)
  10587. case 0xFF57: // Packet length, main header (PLM)
  10588. case 0xFF58: // Packet length, tile-part header (PLT)
  10589. case 0xFF64: // Comment (COM)
  10590. length = readUint16(data, position);
  10591. // skipping content
  10592. break;
  10593. case 0xFF53: // Coding style component (COC)
  10594. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  10595. 'not implemented');
  10596. default:
  10597. throw new Error('JPX Error: Unknown codestream code: ' +
  10598. code.toString(16));
  10599. }
  10600. position += length;
  10601. }
  10602. } catch (e) {
  10603. if (doNotRecover || this.failOnCorruptedImage) {
  10604. throw e;
  10605. } else {
  10606. warn('Trying to recover from ' + e.message);
  10607. }
  10608. }
  10609. this.tiles = transformComponents(context);
  10610. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  10611. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  10612. this.componentsCount = context.SIZ.Csiz;
  10613. }
  10614. };
  10615. function calculateComponentDimensions(component, siz) {
  10616. // Section B.2 Component mapping
  10617. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  10618. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  10619. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  10620. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  10621. component.width = component.x1 - component.x0;
  10622. component.height = component.y1 - component.y0;
  10623. }
  10624. function calculateTileGrids(context, components) {
  10625. var siz = context.SIZ;
  10626. // Section B.3 Division into tile and tile-components
  10627. var tile, tiles = [];
  10628. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  10629. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  10630. for (var q = 0; q < numYtiles; q++) {
  10631. for (var p = 0; p < numXtiles; p++) {
  10632. tile = {};
  10633. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  10634. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  10635. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  10636. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  10637. tile.width = tile.tx1 - tile.tx0;
  10638. tile.height = tile.ty1 - tile.ty0;
  10639. tile.components = [];
  10640. tiles.push(tile);
  10641. }
  10642. }
  10643. context.tiles = tiles;
  10644. var componentsCount = siz.Csiz;
  10645. for (var i = 0, ii = componentsCount; i < ii; i++) {
  10646. var component = components[i];
  10647. for (var j = 0, jj = tiles.length; j < jj; j++) {
  10648. var tileComponent = {};
  10649. tile = tiles[j];
  10650. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  10651. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  10652. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  10653. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  10654. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  10655. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  10656. tile.components[i] = tileComponent;
  10657. }
  10658. }
  10659. }
  10660. function getBlocksDimensions(context, component, r) {
  10661. var codOrCoc = component.codingStyleParameters;
  10662. var result = {};
  10663. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  10664. result.PPx = 15;
  10665. result.PPy = 15;
  10666. } else {
  10667. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  10668. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  10669. }
  10670. // calculate codeblock size as described in section B.7
  10671. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  10672. Math.min(codOrCoc.xcb, result.PPx));
  10673. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  10674. Math.min(codOrCoc.ycb, result.PPy));
  10675. return result;
  10676. }
  10677. function buildPrecincts(context, resolution, dimensions) {
  10678. // Section B.6 Division resolution to precincts
  10679. var precinctWidth = 1 << dimensions.PPx;
  10680. var precinctHeight = 1 << dimensions.PPy;
  10681. // Jasper introduces codeblock groups for mapping each subband codeblocks
  10682. // to precincts. Precinct partition divides a resolution according to width
  10683. // and height parameters. The subband that belongs to the resolution level
  10684. // has a different size than the level, unless it is the zero resolution.
  10685. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  10686. // The precinct partitioning for a particular subband is derived from a
  10687. // partitioning of its parent LL band (i.e., the LL band at the next higher
  10688. // resolution level)... The LL band associated with each resolution level is
  10689. // divided into precincts... Each of the resulting precinct regions is then
  10690. // mapped into its child subbands (if any) at the next lower resolution
  10691. // level. This is accomplished by using the coordinate transformation
  10692. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  10693. // coordinates of a point in the LL band and child subband, respectively.
  10694. var isZeroRes = resolution.resLevel === 0;
  10695. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  10696. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  10697. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  10698. Math.ceil(resolution.trx1 / precinctWidth) -
  10699. Math.floor(resolution.trx0 / precinctWidth) : 0);
  10700. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  10701. Math.ceil(resolution.try1 / precinctHeight) -
  10702. Math.floor(resolution.try0 / precinctHeight) : 0);
  10703. var numprecincts = numprecinctswide * numprecinctshigh;
  10704. resolution.precinctParameters = {
  10705. precinctWidth: precinctWidth,
  10706. precinctHeight: precinctHeight,
  10707. numprecinctswide: numprecinctswide,
  10708. numprecinctshigh: numprecinctshigh,
  10709. numprecincts: numprecincts,
  10710. precinctWidthInSubband: precinctWidthInSubband,
  10711. precinctHeightInSubband: precinctHeightInSubband
  10712. };
  10713. }
  10714. function buildCodeblocks(context, subband, dimensions) {
  10715. // Section B.7 Division sub-band into code-blocks
  10716. var xcb_ = dimensions.xcb_;
  10717. var ycb_ = dimensions.ycb_;
  10718. var codeblockWidth = 1 << xcb_;
  10719. var codeblockHeight = 1 << ycb_;
  10720. var cbx0 = subband.tbx0 >> xcb_;
  10721. var cby0 = subband.tby0 >> ycb_;
  10722. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  10723. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  10724. var precinctParameters = subband.resolution.precinctParameters;
  10725. var codeblocks = [];
  10726. var precincts = [];
  10727. var i, j, codeblock, precinctNumber;
  10728. for (j = cby0; j < cby1; j++) {
  10729. for (i = cbx0; i < cbx1; i++) {
  10730. codeblock = {
  10731. cbx: i,
  10732. cby: j,
  10733. tbx0: codeblockWidth * i,
  10734. tby0: codeblockHeight * j,
  10735. tbx1: codeblockWidth * (i + 1),
  10736. tby1: codeblockHeight * (j + 1)
  10737. };
  10738. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  10739. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  10740. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  10741. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  10742. // Calculate precinct number for this codeblock, codeblock position
  10743. // should be relative to its subband, use actual dimension and position
  10744. // See comment about codeblock group width and height
  10745. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  10746. precinctParameters.precinctWidthInSubband);
  10747. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  10748. precinctParameters.precinctHeightInSubband);
  10749. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  10750. codeblock.precinctNumber = precinctNumber;
  10751. codeblock.subbandType = subband.type;
  10752. codeblock.Lblock = 3;
  10753. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  10754. codeblock.tby1_ <= codeblock.tby0_) {
  10755. continue;
  10756. }
  10757. codeblocks.push(codeblock);
  10758. // building precinct for the sub-band
  10759. var precinct = precincts[precinctNumber];
  10760. if (precinct !== undefined) {
  10761. if (i < precinct.cbxMin) {
  10762. precinct.cbxMin = i;
  10763. } else if (i > precinct.cbxMax) {
  10764. precinct.cbxMax = i;
  10765. }
  10766. if (j < precinct.cbyMin) {
  10767. precinct.cbxMin = j;
  10768. } else if (j > precinct.cbyMax) {
  10769. precinct.cbyMax = j;
  10770. }
  10771. } else {
  10772. precincts[precinctNumber] = precinct = {
  10773. cbxMin: i,
  10774. cbyMin: j,
  10775. cbxMax: i,
  10776. cbyMax: j
  10777. };
  10778. }
  10779. codeblock.precinct = precinct;
  10780. }
  10781. }
  10782. subband.codeblockParameters = {
  10783. codeblockWidth: xcb_,
  10784. codeblockHeight: ycb_,
  10785. numcodeblockwide: cbx1 - cbx0 + 1,
  10786. numcodeblockhigh: cby1 - cby0 + 1
  10787. };
  10788. subband.codeblocks = codeblocks;
  10789. subband.precincts = precincts;
  10790. }
  10791. function createPacket(resolution, precinctNumber, layerNumber) {
  10792. var precinctCodeblocks = [];
  10793. // Section B.10.8 Order of info in packet
  10794. var subbands = resolution.subbands;
  10795. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  10796. for (var i = 0, ii = subbands.length; i < ii; i++) {
  10797. var subband = subbands[i];
  10798. var codeblocks = subband.codeblocks;
  10799. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  10800. var codeblock = codeblocks[j];
  10801. if (codeblock.precinctNumber !== precinctNumber) {
  10802. continue;
  10803. }
  10804. precinctCodeblocks.push(codeblock);
  10805. }
  10806. }
  10807. return {
  10808. layerNumber: layerNumber,
  10809. codeblocks: precinctCodeblocks
  10810. };
  10811. }
  10812. function LayerResolutionComponentPositionIterator(context) {
  10813. var siz = context.SIZ;
  10814. var tileIndex = context.currentTile.index;
  10815. var tile = context.tiles[tileIndex];
  10816. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10817. var componentsCount = siz.Csiz;
  10818. var maxDecompositionLevelsCount = 0;
  10819. for (var q = 0; q < componentsCount; q++) {
  10820. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10821. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10822. }
  10823. var l = 0, r = 0, i = 0, k = 0;
  10824. this.nextPacket = function JpxImage_nextPacket() {
  10825. // Section B.12.1.1 Layer-resolution-component-position
  10826. for (; l < layersCount; l++) {
  10827. for (; r <= maxDecompositionLevelsCount; r++) {
  10828. for (; i < componentsCount; i++) {
  10829. var component = tile.components[i];
  10830. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10831. continue;
  10832. }
  10833. var resolution = component.resolutions[r];
  10834. var numprecincts = resolution.precinctParameters.numprecincts;
  10835. for (; k < numprecincts;) {
  10836. var packet = createPacket(resolution, k, l);
  10837. k++;
  10838. return packet;
  10839. }
  10840. k = 0;
  10841. }
  10842. i = 0;
  10843. }
  10844. r = 0;
  10845. }
  10846. throw new Error('JPX Error: Out of packets');
  10847. };
  10848. }
  10849. function ResolutionLayerComponentPositionIterator(context) {
  10850. var siz = context.SIZ;
  10851. var tileIndex = context.currentTile.index;
  10852. var tile = context.tiles[tileIndex];
  10853. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10854. var componentsCount = siz.Csiz;
  10855. var maxDecompositionLevelsCount = 0;
  10856. for (var q = 0; q < componentsCount; q++) {
  10857. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10858. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  10859. }
  10860. var r = 0, l = 0, i = 0, k = 0;
  10861. this.nextPacket = function JpxImage_nextPacket() {
  10862. // Section B.12.1.2 Resolution-layer-component-position
  10863. for (; r <= maxDecompositionLevelsCount; r++) {
  10864. for (; l < layersCount; l++) {
  10865. for (; i < componentsCount; i++) {
  10866. var component = tile.components[i];
  10867. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10868. continue;
  10869. }
  10870. var resolution = component.resolutions[r];
  10871. var numprecincts = resolution.precinctParameters.numprecincts;
  10872. for (; k < numprecincts;) {
  10873. var packet = createPacket(resolution, k, l);
  10874. k++;
  10875. return packet;
  10876. }
  10877. k = 0;
  10878. }
  10879. i = 0;
  10880. }
  10881. l = 0;
  10882. }
  10883. throw new Error('JPX Error: Out of packets');
  10884. };
  10885. }
  10886. function ResolutionPositionComponentLayerIterator(context) {
  10887. var siz = context.SIZ;
  10888. var tileIndex = context.currentTile.index;
  10889. var tile = context.tiles[tileIndex];
  10890. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10891. var componentsCount = siz.Csiz;
  10892. var l, r, c, p;
  10893. var maxDecompositionLevelsCount = 0;
  10894. for (c = 0; c < componentsCount; c++) {
  10895. var component = tile.components[c];
  10896. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  10897. component.codingStyleParameters.decompositionLevelsCount);
  10898. }
  10899. var maxNumPrecinctsInLevel = new Int32Array(
  10900. maxDecompositionLevelsCount + 1);
  10901. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  10902. var maxNumPrecincts = 0;
  10903. for (c = 0; c < componentsCount; ++c) {
  10904. var resolutions = tile.components[c].resolutions;
  10905. if (r < resolutions.length) {
  10906. maxNumPrecincts = Math.max(maxNumPrecincts,
  10907. resolutions[r].precinctParameters.numprecincts);
  10908. }
  10909. }
  10910. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  10911. }
  10912. l = 0;
  10913. r = 0;
  10914. c = 0;
  10915. p = 0;
  10916. this.nextPacket = function JpxImage_nextPacket() {
  10917. // Section B.12.1.3 Resolution-position-component-layer
  10918. for (; r <= maxDecompositionLevelsCount; r++) {
  10919. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  10920. for (; c < componentsCount; c++) {
  10921. var component = tile.components[c];
  10922. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  10923. continue;
  10924. }
  10925. var resolution = component.resolutions[r];
  10926. var numprecincts = resolution.precinctParameters.numprecincts;
  10927. if (p >= numprecincts) {
  10928. continue;
  10929. }
  10930. for (; l < layersCount;) {
  10931. var packet = createPacket(resolution, p, l);
  10932. l++;
  10933. return packet;
  10934. }
  10935. l = 0;
  10936. }
  10937. c = 0;
  10938. }
  10939. p = 0;
  10940. }
  10941. throw new Error('JPX Error: Out of packets');
  10942. };
  10943. }
  10944. function PositionComponentResolutionLayerIterator(context) {
  10945. var siz = context.SIZ;
  10946. var tileIndex = context.currentTile.index;
  10947. var tile = context.tiles[tileIndex];
  10948. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10949. var componentsCount = siz.Csiz;
  10950. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10951. var precinctsIterationSizes = precinctsSizes;
  10952. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10953. this.nextPacket = function JpxImage_nextPacket() {
  10954. // Section B.12.1.4 Position-component-resolution-layer
  10955. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  10956. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  10957. for (; c < componentsCount; c++) {
  10958. var component = tile.components[c];
  10959. var decompositionLevelsCount =
  10960. component.codingStyleParameters.decompositionLevelsCount;
  10961. for (; r <= decompositionLevelsCount; r++) {
  10962. var resolution = component.resolutions[r];
  10963. var sizeInImageScale =
  10964. precinctsSizes.components[c].resolutions[r];
  10965. var k = getPrecinctIndexIfExist(
  10966. px,
  10967. py,
  10968. sizeInImageScale,
  10969. precinctsIterationSizes,
  10970. resolution);
  10971. if (k === null) {
  10972. continue;
  10973. }
  10974. for (; l < layersCount;) {
  10975. var packet = createPacket(resolution, k, l);
  10976. l++;
  10977. return packet;
  10978. }
  10979. l = 0;
  10980. }
  10981. r = 0;
  10982. }
  10983. c = 0;
  10984. }
  10985. px = 0;
  10986. }
  10987. throw new Error('JPX Error: Out of packets');
  10988. };
  10989. }
  10990. function ComponentPositionResolutionLayerIterator(context) {
  10991. var siz = context.SIZ;
  10992. var tileIndex = context.currentTile.index;
  10993. var tile = context.tiles[tileIndex];
  10994. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  10995. var componentsCount = siz.Csiz;
  10996. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  10997. var l = 0, r = 0, c = 0, px = 0, py = 0;
  10998. this.nextPacket = function JpxImage_nextPacket() {
  10999. // Section B.12.1.5 Component-position-resolution-layer
  11000. for (; c < componentsCount; ++c) {
  11001. var component = tile.components[c];
  11002. var precinctsIterationSizes = precinctsSizes.components[c];
  11003. var decompositionLevelsCount =
  11004. component.codingStyleParameters.decompositionLevelsCount;
  11005. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  11006. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  11007. for (; r <= decompositionLevelsCount; r++) {
  11008. var resolution = component.resolutions[r];
  11009. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  11010. var k = getPrecinctIndexIfExist(
  11011. px,
  11012. py,
  11013. sizeInImageScale,
  11014. precinctsIterationSizes,
  11015. resolution);
  11016. if (k === null) {
  11017. continue;
  11018. }
  11019. for (; l < layersCount;) {
  11020. var packet = createPacket(resolution, k, l);
  11021. l++;
  11022. return packet;
  11023. }
  11024. l = 0;
  11025. }
  11026. r = 0;
  11027. }
  11028. px = 0;
  11029. }
  11030. py = 0;
  11031. }
  11032. throw new Error('JPX Error: Out of packets');
  11033. };
  11034. }
  11035. function getPrecinctIndexIfExist(
  11036. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  11037. var posX = pxIndex * precinctIterationSizes.minWidth;
  11038. var posY = pyIndex * precinctIterationSizes.minHeight;
  11039. if (posX % sizeInImageScale.width !== 0 ||
  11040. posY % sizeInImageScale.height !== 0) {
  11041. return null;
  11042. }
  11043. var startPrecinctRowIndex =
  11044. (posY / sizeInImageScale.width) *
  11045. resolution.precinctParameters.numprecinctswide;
  11046. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  11047. }
  11048. function getPrecinctSizesInImageScale(tile) {
  11049. var componentsCount = tile.components.length;
  11050. var minWidth = Number.MAX_VALUE;
  11051. var minHeight = Number.MAX_VALUE;
  11052. var maxNumWide = 0;
  11053. var maxNumHigh = 0;
  11054. var sizePerComponent = new Array(componentsCount);
  11055. for (var c = 0; c < componentsCount; c++) {
  11056. var component = tile.components[c];
  11057. var decompositionLevelsCount =
  11058. component.codingStyleParameters.decompositionLevelsCount;
  11059. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  11060. var minWidthCurrentComponent = Number.MAX_VALUE;
  11061. var minHeightCurrentComponent = Number.MAX_VALUE;
  11062. var maxNumWideCurrentComponent = 0;
  11063. var maxNumHighCurrentComponent = 0;
  11064. var scale = 1;
  11065. for (var r = decompositionLevelsCount; r >= 0; --r) {
  11066. var resolution = component.resolutions[r];
  11067. var widthCurrentResolution =
  11068. scale * resolution.precinctParameters.precinctWidth;
  11069. var heightCurrentResolution =
  11070. scale * resolution.precinctParameters.precinctHeight;
  11071. minWidthCurrentComponent = Math.min(
  11072. minWidthCurrentComponent,
  11073. widthCurrentResolution);
  11074. minHeightCurrentComponent = Math.min(
  11075. minHeightCurrentComponent,
  11076. heightCurrentResolution);
  11077. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  11078. resolution.precinctParameters.numprecinctswide);
  11079. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  11080. resolution.precinctParameters.numprecinctshigh);
  11081. sizePerResolution[r] = {
  11082. width: widthCurrentResolution,
  11083. height: heightCurrentResolution
  11084. };
  11085. scale <<= 1;
  11086. }
  11087. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  11088. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  11089. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  11090. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  11091. sizePerComponent[c] = {
  11092. resolutions: sizePerResolution,
  11093. minWidth: minWidthCurrentComponent,
  11094. minHeight: minHeightCurrentComponent,
  11095. maxNumWide: maxNumWideCurrentComponent,
  11096. maxNumHigh: maxNumHighCurrentComponent
  11097. };
  11098. }
  11099. return {
  11100. components: sizePerComponent,
  11101. minWidth: minWidth,
  11102. minHeight: minHeight,
  11103. maxNumWide: maxNumWide,
  11104. maxNumHigh: maxNumHigh
  11105. };
  11106. }
  11107. function buildPackets(context) {
  11108. var siz = context.SIZ;
  11109. var tileIndex = context.currentTile.index;
  11110. var tile = context.tiles[tileIndex];
  11111. var componentsCount = siz.Csiz;
  11112. // Creating resolutions and sub-bands for each component
  11113. for (var c = 0; c < componentsCount; c++) {
  11114. var component = tile.components[c];
  11115. var decompositionLevelsCount =
  11116. component.codingStyleParameters.decompositionLevelsCount;
  11117. // Section B.5 Resolution levels and sub-bands
  11118. var resolutions = [];
  11119. var subbands = [];
  11120. for (var r = 0; r <= decompositionLevelsCount; r++) {
  11121. var blocksDimensions = getBlocksDimensions(context, component, r);
  11122. var resolution = {};
  11123. var scale = 1 << (decompositionLevelsCount - r);
  11124. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  11125. resolution.try0 = Math.ceil(component.tcy0 / scale);
  11126. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  11127. resolution.try1 = Math.ceil(component.tcy1 / scale);
  11128. resolution.resLevel = r;
  11129. buildPrecincts(context, resolution, blocksDimensions);
  11130. resolutions.push(resolution);
  11131. var subband;
  11132. if (r === 0) {
  11133. // one sub-band (LL) with last decomposition
  11134. subband = {};
  11135. subband.type = 'LL';
  11136. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  11137. subband.tby0 = Math.ceil(component.tcy0 / scale);
  11138. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  11139. subband.tby1 = Math.ceil(component.tcy1 / scale);
  11140. subband.resolution = resolution;
  11141. buildCodeblocks(context, subband, blocksDimensions);
  11142. subbands.push(subband);
  11143. resolution.subbands = [subband];
  11144. } else {
  11145. var bscale = 1 << (decompositionLevelsCount - r + 1);
  11146. var resolutionSubbands = [];
  11147. // three sub-bands (HL, LH and HH) with rest of decompositions
  11148. subband = {};
  11149. subband.type = 'HL';
  11150. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11151. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  11152. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11153. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  11154. subband.resolution = resolution;
  11155. buildCodeblocks(context, subband, blocksDimensions);
  11156. subbands.push(subband);
  11157. resolutionSubbands.push(subband);
  11158. subband = {};
  11159. subband.type = 'LH';
  11160. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  11161. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11162. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  11163. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11164. subband.resolution = resolution;
  11165. buildCodeblocks(context, subband, blocksDimensions);
  11166. subbands.push(subband);
  11167. resolutionSubbands.push(subband);
  11168. subband = {};
  11169. subband.type = 'HH';
  11170. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  11171. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  11172. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  11173. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  11174. subband.resolution = resolution;
  11175. buildCodeblocks(context, subband, blocksDimensions);
  11176. subbands.push(subband);
  11177. resolutionSubbands.push(subband);
  11178. resolution.subbands = resolutionSubbands;
  11179. }
  11180. }
  11181. component.resolutions = resolutions;
  11182. component.subbands = subbands;
  11183. }
  11184. // Generate the packets sequence
  11185. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  11186. switch (progressionOrder) {
  11187. case 0:
  11188. tile.packetsIterator =
  11189. new LayerResolutionComponentPositionIterator(context);
  11190. break;
  11191. case 1:
  11192. tile.packetsIterator =
  11193. new ResolutionLayerComponentPositionIterator(context);
  11194. break;
  11195. case 2:
  11196. tile.packetsIterator =
  11197. new ResolutionPositionComponentLayerIterator(context);
  11198. break;
  11199. case 3:
  11200. tile.packetsIterator =
  11201. new PositionComponentResolutionLayerIterator(context);
  11202. break;
  11203. case 4:
  11204. tile.packetsIterator =
  11205. new ComponentPositionResolutionLayerIterator(context);
  11206. break;
  11207. default:
  11208. throw new Error('JPX Error: Unsupported progression order ' +
  11209. progressionOrder);
  11210. }
  11211. }
  11212. function parseTilePackets(context, data, offset, dataLength) {
  11213. var position = 0;
  11214. var buffer, bufferSize = 0, skipNextBit = false;
  11215. function readBits(count) {
  11216. while (bufferSize < count) {
  11217. var b = data[offset + position];
  11218. position++;
  11219. if (skipNextBit) {
  11220. buffer = (buffer << 7) | b;
  11221. bufferSize += 7;
  11222. skipNextBit = false;
  11223. } else {
  11224. buffer = (buffer << 8) | b;
  11225. bufferSize += 8;
  11226. }
  11227. if (b === 0xFF) {
  11228. skipNextBit = true;
  11229. }
  11230. }
  11231. bufferSize -= count;
  11232. return (buffer >>> bufferSize) & ((1 << count) - 1);
  11233. }
  11234. function skipMarkerIfEqual(value) {
  11235. if (data[offset + position - 1] === 0xFF &&
  11236. data[offset + position] === value) {
  11237. skipBytes(1);
  11238. return true;
  11239. } else if (data[offset + position] === 0xFF &&
  11240. data[offset + position + 1] === value) {
  11241. skipBytes(2);
  11242. return true;
  11243. }
  11244. return false;
  11245. }
  11246. function skipBytes(count) {
  11247. position += count;
  11248. }
  11249. function alignToByte() {
  11250. bufferSize = 0;
  11251. if (skipNextBit) {
  11252. position++;
  11253. skipNextBit = false;
  11254. }
  11255. }
  11256. function readCodingpasses() {
  11257. if (readBits(1) === 0) {
  11258. return 1;
  11259. }
  11260. if (readBits(1) === 0) {
  11261. return 2;
  11262. }
  11263. var value = readBits(2);
  11264. if (value < 3) {
  11265. return value + 3;
  11266. }
  11267. value = readBits(5);
  11268. if (value < 31) {
  11269. return value + 6;
  11270. }
  11271. value = readBits(7);
  11272. return value + 37;
  11273. }
  11274. var tileIndex = context.currentTile.index;
  11275. var tile = context.tiles[tileIndex];
  11276. var sopMarkerUsed = context.COD.sopMarkerUsed;
  11277. var ephMarkerUsed = context.COD.ephMarkerUsed;
  11278. var packetsIterator = tile.packetsIterator;
  11279. while (position < dataLength) {
  11280. alignToByte();
  11281. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  11282. // Skip also marker segment length and packet sequence ID
  11283. skipBytes(4);
  11284. }
  11285. var packet = packetsIterator.nextPacket();
  11286. if (!readBits(1)) {
  11287. continue;
  11288. }
  11289. var layerNumber = packet.layerNumber;
  11290. var queue = [], codeblock;
  11291. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  11292. codeblock = packet.codeblocks[i];
  11293. var precinct = codeblock.precinct;
  11294. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  11295. var codeblockRow = codeblock.cby - precinct.cbyMin;
  11296. var codeblockIncluded = false;
  11297. var firstTimeInclusion = false;
  11298. var valueReady;
  11299. if (codeblock['included'] !== undefined) {
  11300. codeblockIncluded = !!readBits(1);
  11301. } else {
  11302. // reading inclusion tree
  11303. precinct = codeblock.precinct;
  11304. var inclusionTree, zeroBitPlanesTree;
  11305. if (precinct['inclusionTree'] !== undefined) {
  11306. inclusionTree = precinct.inclusionTree;
  11307. } else {
  11308. // building inclusion and zero bit-planes trees
  11309. var width = precinct.cbxMax - precinct.cbxMin + 1;
  11310. var height = precinct.cbyMax - precinct.cbyMin + 1;
  11311. inclusionTree = new InclusionTree(width, height, layerNumber);
  11312. zeroBitPlanesTree = new TagTree(width, height);
  11313. precinct.inclusionTree = inclusionTree;
  11314. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  11315. }
  11316. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  11317. while (true) {
  11318. if (readBits(1)) {
  11319. valueReady = !inclusionTree.nextLevel();
  11320. if (valueReady) {
  11321. codeblock.included = true;
  11322. codeblockIncluded = firstTimeInclusion = true;
  11323. break;
  11324. }
  11325. } else {
  11326. inclusionTree.incrementValue(layerNumber);
  11327. break;
  11328. }
  11329. }
  11330. }
  11331. }
  11332. if (!codeblockIncluded) {
  11333. continue;
  11334. }
  11335. if (firstTimeInclusion) {
  11336. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  11337. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  11338. while (true) {
  11339. if (readBits(1)) {
  11340. valueReady = !zeroBitPlanesTree.nextLevel();
  11341. if (valueReady) {
  11342. break;
  11343. }
  11344. } else {
  11345. zeroBitPlanesTree.incrementValue();
  11346. }
  11347. }
  11348. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  11349. }
  11350. var codingpasses = readCodingpasses();
  11351. while (readBits(1)) {
  11352. codeblock.Lblock++;
  11353. }
  11354. var codingpassesLog2 = log2(codingpasses);
  11355. // rounding down log2
  11356. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  11357. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  11358. var codedDataLength = readBits(bits);
  11359. queue.push({
  11360. codeblock: codeblock,
  11361. codingpasses: codingpasses,
  11362. dataLength: codedDataLength
  11363. });
  11364. }
  11365. alignToByte();
  11366. if (ephMarkerUsed) {
  11367. skipMarkerIfEqual(0x92);
  11368. }
  11369. while (queue.length > 0) {
  11370. var packetItem = queue.shift();
  11371. codeblock = packetItem.codeblock;
  11372. if (codeblock['data'] === undefined) {
  11373. codeblock.data = [];
  11374. }
  11375. codeblock.data.push({
  11376. data: data,
  11377. start: offset + position,
  11378. end: offset + position + packetItem.dataLength,
  11379. codingpasses: packetItem.codingpasses
  11380. });
  11381. position += packetItem.dataLength;
  11382. }
  11383. }
  11384. return position;
  11385. }
  11386. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  11387. delta, mb, reversible, segmentationSymbolUsed) {
  11388. var x0 = subband.tbx0;
  11389. var y0 = subband.tby0;
  11390. var width = subband.tbx1 - subband.tbx0;
  11391. var codeblocks = subband.codeblocks;
  11392. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  11393. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  11394. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  11395. var codeblock = codeblocks[i];
  11396. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  11397. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  11398. if (blockWidth === 0 || blockHeight === 0) {
  11399. continue;
  11400. }
  11401. if (codeblock['data'] === undefined) {
  11402. continue;
  11403. }
  11404. var bitModel, currentCodingpassType;
  11405. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  11406. codeblock.zeroBitPlanes, mb);
  11407. currentCodingpassType = 2; // first bit plane starts from cleanup
  11408. // collect data
  11409. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  11410. var j, jj, dataItem;
  11411. for (j = 0, jj = data.length; j < jj; j++) {
  11412. dataItem = data[j];
  11413. totalLength += dataItem.end - dataItem.start;
  11414. codingpasses += dataItem.codingpasses;
  11415. }
  11416. var encodedData = new Uint8Array(totalLength);
  11417. var position = 0;
  11418. for (j = 0, jj = data.length; j < jj; j++) {
  11419. dataItem = data[j];
  11420. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  11421. encodedData.set(chunk, position);
  11422. position += chunk.length;
  11423. }
  11424. // decoding the item
  11425. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  11426. bitModel.setDecoder(decoder);
  11427. for (j = 0; j < codingpasses; j++) {
  11428. switch (currentCodingpassType) {
  11429. case 0:
  11430. bitModel.runSignificancePropogationPass();
  11431. break;
  11432. case 1:
  11433. bitModel.runMagnitudeRefinementPass();
  11434. break;
  11435. case 2:
  11436. bitModel.runCleanupPass();
  11437. if (segmentationSymbolUsed) {
  11438. bitModel.checkSegmentationSymbol();
  11439. }
  11440. break;
  11441. }
  11442. currentCodingpassType = (currentCodingpassType + 1) % 3;
  11443. }
  11444. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  11445. var sign = bitModel.coefficentsSign;
  11446. var magnitude = bitModel.coefficentsMagnitude;
  11447. var bitsDecoded = bitModel.bitsDecoded;
  11448. var magnitudeCorrection = reversible ? 0 : 0.5;
  11449. var k, n, nb;
  11450. position = 0;
  11451. // Do the interleaving of Section F.3.3 here, so we do not need
  11452. // to copy later. LL level is not interleaved, just copied.
  11453. var interleave = (subband.type !== 'LL');
  11454. for (j = 0; j < blockHeight; j++) {
  11455. var row = (offset / width) | 0; // row in the non-interleaved subband
  11456. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  11457. for (k = 0; k < blockWidth; k++) {
  11458. n = magnitude[position];
  11459. if (n !== 0) {
  11460. n = (n + magnitudeCorrection) * delta;
  11461. if (sign[position] !== 0) {
  11462. n = -n;
  11463. }
  11464. nb = bitsDecoded[position];
  11465. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  11466. if (reversible && (nb >= mb)) {
  11467. coefficients[pos] = n;
  11468. } else {
  11469. coefficients[pos] = n * (1 << (mb - nb));
  11470. }
  11471. }
  11472. offset++;
  11473. position++;
  11474. }
  11475. offset += width - blockWidth;
  11476. }
  11477. }
  11478. }
  11479. function transformTile(context, tile, c) {
  11480. var component = tile.components[c];
  11481. var codingStyleParameters = component.codingStyleParameters;
  11482. var quantizationParameters = component.quantizationParameters;
  11483. var decompositionLevelsCount =
  11484. codingStyleParameters.decompositionLevelsCount;
  11485. var spqcds = quantizationParameters.SPqcds;
  11486. var scalarExpounded = quantizationParameters.scalarExpounded;
  11487. var guardBits = quantizationParameters.guardBits;
  11488. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  11489. var precision = context.components[c].precision;
  11490. var reversible = codingStyleParameters.reversibleTransformation;
  11491. var transform = (reversible ? new ReversibleTransform() :
  11492. new IrreversibleTransform());
  11493. var subbandCoefficients = [];
  11494. var b = 0;
  11495. for (var i = 0; i <= decompositionLevelsCount; i++) {
  11496. var resolution = component.resolutions[i];
  11497. var width = resolution.trx1 - resolution.trx0;
  11498. var height = resolution.try1 - resolution.try0;
  11499. // Allocate space for the whole sublevel.
  11500. var coefficients = new Float32Array(width * height);
  11501. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  11502. var mu, epsilon;
  11503. if (!scalarExpounded) {
  11504. // formula E-5
  11505. mu = spqcds[0].mu;
  11506. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  11507. } else {
  11508. mu = spqcds[b].mu;
  11509. epsilon = spqcds[b].epsilon;
  11510. b++;
  11511. }
  11512. var subband = resolution.subbands[j];
  11513. var gainLog2 = SubbandsGainLog2[subband.type];
  11514. // calulate quantization coefficient (Section E.1.1.1)
  11515. var delta = (reversible ? 1 :
  11516. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  11517. var mb = (guardBits + epsilon - 1);
  11518. // In the first resolution level, copyCoefficients will fill the
  11519. // whole array with coefficients. In the succeding passes,
  11520. // copyCoefficients will consecutively fill in the values that belong
  11521. // to the interleaved positions of the HL, LH, and HH coefficients.
  11522. // The LL coefficients will then be interleaved in Transform.iterate().
  11523. copyCoefficients(coefficients, width, height, subband, delta, mb,
  11524. reversible, segmentationSymbolUsed);
  11525. }
  11526. subbandCoefficients.push({
  11527. width: width,
  11528. height: height,
  11529. items: coefficients
  11530. });
  11531. }
  11532. var result = transform.calculate(subbandCoefficients,
  11533. component.tcx0, component.tcy0);
  11534. return {
  11535. left: component.tcx0,
  11536. top: component.tcy0,
  11537. width: result.width,
  11538. height: result.height,
  11539. items: result.items
  11540. };
  11541. }
  11542. function transformComponents(context) {
  11543. var siz = context.SIZ;
  11544. var components = context.components;
  11545. var componentsCount = siz.Csiz;
  11546. var resultImages = [];
  11547. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  11548. var tile = context.tiles[i];
  11549. var transformedTiles = [];
  11550. var c;
  11551. for (c = 0; c < componentsCount; c++) {
  11552. transformedTiles[c] = transformTile(context, tile, c);
  11553. }
  11554. var tile0 = transformedTiles[0];
  11555. var out = new Uint8Array(tile0.items.length * componentsCount);
  11556. var result = {
  11557. left: tile0.left,
  11558. top: tile0.top,
  11559. width: tile0.width,
  11560. height: tile0.height,
  11561. items: out
  11562. };
  11563. // Section G.2.2 Inverse multi component transform
  11564. var shift, offset, max, min, maxK;
  11565. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  11566. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  11567. var fourComponents = componentsCount === 4;
  11568. var y0items = transformedTiles[0].items;
  11569. var y1items = transformedTiles[1].items;
  11570. var y2items = transformedTiles[2].items;
  11571. var y3items = fourComponents ? transformedTiles[3].items : null;
  11572. // HACK: The multiple component transform formulas below assume that
  11573. // all components have the same precision. With this in mind, we
  11574. // compute shift and offset only once.
  11575. shift = components[0].precision - 8;
  11576. offset = (128 << shift) + 0.5;
  11577. max = 255 * (1 << shift);
  11578. maxK = max * 0.5;
  11579. min = -maxK;
  11580. var component0 = tile.components[0];
  11581. var alpha01 = componentsCount - 3;
  11582. jj = y0items.length;
  11583. if (!component0.codingStyleParameters.reversibleTransformation) {
  11584. // inverse irreversible multiple component transform
  11585. for (j = 0; j < jj; j++, pos += alpha01) {
  11586. y0 = y0items[j] + offset;
  11587. y1 = y1items[j];
  11588. y2 = y2items[j];
  11589. r = y0 + 1.402 * y2;
  11590. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  11591. b = y0 + 1.772 * y1;
  11592. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11593. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11594. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11595. }
  11596. } else {
  11597. // inverse reversible multiple component transform
  11598. for (j = 0; j < jj; j++, pos += alpha01) {
  11599. y0 = y0items[j] + offset;
  11600. y1 = y1items[j];
  11601. y2 = y2items[j];
  11602. g = y0 - ((y2 + y1) >> 2);
  11603. r = g + y2;
  11604. b = g + y1;
  11605. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  11606. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  11607. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  11608. }
  11609. }
  11610. if (fourComponents) {
  11611. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  11612. k = y3items[j];
  11613. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  11614. }
  11615. }
  11616. } else { // no multi-component transform
  11617. for (c = 0; c < componentsCount; c++) {
  11618. var items = transformedTiles[c].items;
  11619. shift = components[c].precision - 8;
  11620. offset = (128 << shift) + 0.5;
  11621. max = (127.5 * (1 << shift));
  11622. min = -max;
  11623. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  11624. val = items[j];
  11625. out[pos] = val <= min ? 0 :
  11626. val >= max ? 255 : (val + offset) >> shift;
  11627. pos += componentsCount;
  11628. }
  11629. }
  11630. }
  11631. resultImages.push(result);
  11632. }
  11633. return resultImages;
  11634. }
  11635. function initializeTile(context, tileIndex) {
  11636. var siz = context.SIZ;
  11637. var componentsCount = siz.Csiz;
  11638. var tile = context.tiles[tileIndex];
  11639. for (var c = 0; c < componentsCount; c++) {
  11640. var component = tile.components[c];
  11641. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  11642. context.currentTile.QCC[c] : context.currentTile.QCD);
  11643. component.quantizationParameters = qcdOrQcc;
  11644. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  11645. context.currentTile.COC[c] : context.currentTile.COD);
  11646. component.codingStyleParameters = codOrCoc;
  11647. }
  11648. tile.codingStyleDefaultParameters = context.currentTile.COD;
  11649. }
  11650. // Section B.10.2 Tag trees
  11651. var TagTree = (function TagTreeClosure() {
  11652. function TagTree(width, height) {
  11653. var levelsLength = log2(Math.max(width, height)) + 1;
  11654. this.levels = [];
  11655. for (var i = 0; i < levelsLength; i++) {
  11656. var level = {
  11657. width: width,
  11658. height: height,
  11659. items: []
  11660. };
  11661. this.levels.push(level);
  11662. width = Math.ceil(width / 2);
  11663. height = Math.ceil(height / 2);
  11664. }
  11665. }
  11666. TagTree.prototype = {
  11667. reset: function TagTree_reset(i, j) {
  11668. var currentLevel = 0, value = 0, level;
  11669. while (currentLevel < this.levels.length) {
  11670. level = this.levels[currentLevel];
  11671. var index = i + j * level.width;
  11672. if (level.items[index] !== undefined) {
  11673. value = level.items[index];
  11674. break;
  11675. }
  11676. level.index = index;
  11677. i >>= 1;
  11678. j >>= 1;
  11679. currentLevel++;
  11680. }
  11681. currentLevel--;
  11682. level = this.levels[currentLevel];
  11683. level.items[level.index] = value;
  11684. this.currentLevel = currentLevel;
  11685. delete this.value;
  11686. },
  11687. incrementValue: function TagTree_incrementValue() {
  11688. var level = this.levels[this.currentLevel];
  11689. level.items[level.index]++;
  11690. },
  11691. nextLevel: function TagTree_nextLevel() {
  11692. var currentLevel = this.currentLevel;
  11693. var level = this.levels[currentLevel];
  11694. var value = level.items[level.index];
  11695. currentLevel--;
  11696. if (currentLevel < 0) {
  11697. this.value = value;
  11698. return false;
  11699. }
  11700. this.currentLevel = currentLevel;
  11701. level = this.levels[currentLevel];
  11702. level.items[level.index] = value;
  11703. return true;
  11704. }
  11705. };
  11706. return TagTree;
  11707. })();
  11708. var InclusionTree = (function InclusionTreeClosure() {
  11709. function InclusionTree(width, height, defaultValue) {
  11710. var levelsLength = log2(Math.max(width, height)) + 1;
  11711. this.levels = [];
  11712. for (var i = 0; i < levelsLength; i++) {
  11713. var items = new Uint8Array(width * height);
  11714. for (var j = 0, jj = items.length; j < jj; j++) {
  11715. items[j] = defaultValue;
  11716. }
  11717. var level = {
  11718. width: width,
  11719. height: height,
  11720. items: items
  11721. };
  11722. this.levels.push(level);
  11723. width = Math.ceil(width / 2);
  11724. height = Math.ceil(height / 2);
  11725. }
  11726. }
  11727. InclusionTree.prototype = {
  11728. reset: function InclusionTree_reset(i, j, stopValue) {
  11729. var currentLevel = 0;
  11730. while (currentLevel < this.levels.length) {
  11731. var level = this.levels[currentLevel];
  11732. var index = i + j * level.width;
  11733. level.index = index;
  11734. var value = level.items[index];
  11735. if (value === 0xFF) {
  11736. break;
  11737. }
  11738. if (value > stopValue) {
  11739. this.currentLevel = currentLevel;
  11740. // already know about this one, propagating the value to top levels
  11741. this.propagateValues();
  11742. return false;
  11743. }
  11744. i >>= 1;
  11745. j >>= 1;
  11746. currentLevel++;
  11747. }
  11748. this.currentLevel = currentLevel - 1;
  11749. return true;
  11750. },
  11751. incrementValue: function InclusionTree_incrementValue(stopValue) {
  11752. var level = this.levels[this.currentLevel];
  11753. level.items[level.index] = stopValue + 1;
  11754. this.propagateValues();
  11755. },
  11756. propagateValues: function InclusionTree_propagateValues() {
  11757. var levelIndex = this.currentLevel;
  11758. var level = this.levels[levelIndex];
  11759. var currentValue = level.items[level.index];
  11760. while (--levelIndex >= 0) {
  11761. level = this.levels[levelIndex];
  11762. level.items[level.index] = currentValue;
  11763. }
  11764. },
  11765. nextLevel: function InclusionTree_nextLevel() {
  11766. var currentLevel = this.currentLevel;
  11767. var level = this.levels[currentLevel];
  11768. var value = level.items[level.index];
  11769. level.items[level.index] = 0xFF;
  11770. currentLevel--;
  11771. if (currentLevel < 0) {
  11772. return false;
  11773. }
  11774. this.currentLevel = currentLevel;
  11775. level = this.levels[currentLevel];
  11776. level.items[level.index] = value;
  11777. return true;
  11778. }
  11779. };
  11780. return InclusionTree;
  11781. })();
  11782. // Section D. Coefficient bit modeling
  11783. var BitModel = (function BitModelClosure() {
  11784. var UNIFORM_CONTEXT = 17;
  11785. var RUNLENGTH_CONTEXT = 18;
  11786. // Table D-1
  11787. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  11788. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  11789. var LLAndLHContextsLabel = new Uint8Array([
  11790. 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,
  11791. 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,
  11792. 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
  11793. ]);
  11794. var HLContextLabel = new Uint8Array([
  11795. 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,
  11796. 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,
  11797. 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
  11798. ]);
  11799. var HHContextLabel = new Uint8Array([
  11800. 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,
  11801. 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,
  11802. 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
  11803. ]);
  11804. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  11805. this.width = width;
  11806. this.height = height;
  11807. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  11808. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  11809. var coefficientCount = width * height;
  11810. // coefficients outside the encoding region treated as insignificant
  11811. // add border state cells for significanceState
  11812. this.neighborsSignificance = new Uint8Array(coefficientCount);
  11813. this.coefficentsSign = new Uint8Array(coefficientCount);
  11814. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  11815. mb > 6 ? new Uint16Array(coefficientCount) :
  11816. new Uint8Array(coefficientCount);
  11817. this.processingFlags = new Uint8Array(coefficientCount);
  11818. var bitsDecoded = new Uint8Array(coefficientCount);
  11819. if (zeroBitPlanes !== 0) {
  11820. for (var i = 0; i < coefficientCount; i++) {
  11821. bitsDecoded[i] = zeroBitPlanes;
  11822. }
  11823. }
  11824. this.bitsDecoded = bitsDecoded;
  11825. this.reset();
  11826. }
  11827. BitModel.prototype = {
  11828. setDecoder: function BitModel_setDecoder(decoder) {
  11829. this.decoder = decoder;
  11830. },
  11831. reset: function BitModel_reset() {
  11832. // We have 17 contexts that are accessed via context labels,
  11833. // plus the uniform and runlength context.
  11834. this.contexts = new Int8Array(19);
  11835. // Contexts are packed into 1 byte:
  11836. // highest 7 bits carry the index, lowest bit carries mps
  11837. this.contexts[0] = (4 << 1) | 0;
  11838. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  11839. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  11840. },
  11841. setNeighborsSignificance:
  11842. function BitModel_setNeighborsSignificance(row, column, index) {
  11843. var neighborsSignificance = this.neighborsSignificance;
  11844. var width = this.width, height = this.height;
  11845. var left = (column > 0);
  11846. var right = (column + 1 < width);
  11847. var i;
  11848. if (row > 0) {
  11849. i = index - width;
  11850. if (left) {
  11851. neighborsSignificance[i - 1] += 0x10;
  11852. }
  11853. if (right) {
  11854. neighborsSignificance[i + 1] += 0x10;
  11855. }
  11856. neighborsSignificance[i] += 0x04;
  11857. }
  11858. if (row + 1 < height) {
  11859. i = index + width;
  11860. if (left) {
  11861. neighborsSignificance[i - 1] += 0x10;
  11862. }
  11863. if (right) {
  11864. neighborsSignificance[i + 1] += 0x10;
  11865. }
  11866. neighborsSignificance[i] += 0x04;
  11867. }
  11868. if (left) {
  11869. neighborsSignificance[index - 1] += 0x01;
  11870. }
  11871. if (right) {
  11872. neighborsSignificance[index + 1] += 0x01;
  11873. }
  11874. neighborsSignificance[index] |= 0x80;
  11875. },
  11876. runSignificancePropogationPass:
  11877. function BitModel_runSignificancePropogationPass() {
  11878. var decoder = this.decoder;
  11879. var width = this.width, height = this.height;
  11880. var coefficentsMagnitude = this.coefficentsMagnitude;
  11881. var coefficentsSign = this.coefficentsSign;
  11882. var neighborsSignificance = this.neighborsSignificance;
  11883. var processingFlags = this.processingFlags;
  11884. var contexts = this.contexts;
  11885. var labels = this.contextLabelTable;
  11886. var bitsDecoded = this.bitsDecoded;
  11887. var processedInverseMask = ~1;
  11888. var processedMask = 1;
  11889. var firstMagnitudeBitMask = 2;
  11890. for (var i0 = 0; i0 < height; i0 += 4) {
  11891. for (var j = 0; j < width; j++) {
  11892. var index = i0 * width + j;
  11893. for (var i1 = 0; i1 < 4; i1++, index += width) {
  11894. var i = i0 + i1;
  11895. if (i >= height) {
  11896. break;
  11897. }
  11898. // clear processed flag first
  11899. processingFlags[index] &= processedInverseMask;
  11900. if (coefficentsMagnitude[index] ||
  11901. !neighborsSignificance[index]) {
  11902. continue;
  11903. }
  11904. var contextLabel = labels[neighborsSignificance[index]];
  11905. var decision = decoder.readBit(contexts, contextLabel);
  11906. if (decision) {
  11907. var sign = this.decodeSignBit(i, j, index);
  11908. coefficentsSign[index] = sign;
  11909. coefficentsMagnitude[index] = 1;
  11910. this.setNeighborsSignificance(i, j, index);
  11911. processingFlags[index] |= firstMagnitudeBitMask;
  11912. }
  11913. bitsDecoded[index]++;
  11914. processingFlags[index] |= processedMask;
  11915. }
  11916. }
  11917. }
  11918. },
  11919. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  11920. var width = this.width, height = this.height;
  11921. var coefficentsMagnitude = this.coefficentsMagnitude;
  11922. var coefficentsSign = this.coefficentsSign;
  11923. var contribution, sign0, sign1, significance1;
  11924. var contextLabel, decoded;
  11925. // calculate horizontal contribution
  11926. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  11927. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  11928. sign1 = coefficentsSign[index + 1];
  11929. if (significance1) {
  11930. sign0 = coefficentsSign[index - 1];
  11931. contribution = 1 - sign1 - sign0;
  11932. } else {
  11933. contribution = 1 - sign1 - sign1;
  11934. }
  11935. } else if (significance1) {
  11936. sign0 = coefficentsSign[index - 1];
  11937. contribution = 1 - sign0 - sign0;
  11938. } else {
  11939. contribution = 0;
  11940. }
  11941. var horizontalContribution = 3 * contribution;
  11942. // calculate vertical contribution and combine with the horizontal
  11943. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  11944. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  11945. sign1 = coefficentsSign[index + width];
  11946. if (significance1) {
  11947. sign0 = coefficentsSign[index - width];
  11948. contribution = 1 - sign1 - sign0 + horizontalContribution;
  11949. } else {
  11950. contribution = 1 - sign1 - sign1 + horizontalContribution;
  11951. }
  11952. } else if (significance1) {
  11953. sign0 = coefficentsSign[index - width];
  11954. contribution = 1 - sign0 - sign0 + horizontalContribution;
  11955. } else {
  11956. contribution = horizontalContribution;
  11957. }
  11958. if (contribution >= 0) {
  11959. contextLabel = 9 + contribution;
  11960. decoded = this.decoder.readBit(this.contexts, contextLabel);
  11961. } else {
  11962. contextLabel = 9 - contribution;
  11963. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  11964. }
  11965. return decoded;
  11966. },
  11967. runMagnitudeRefinementPass:
  11968. function BitModel_runMagnitudeRefinementPass() {
  11969. var decoder = this.decoder;
  11970. var width = this.width, height = this.height;
  11971. var coefficentsMagnitude = this.coefficentsMagnitude;
  11972. var neighborsSignificance = this.neighborsSignificance;
  11973. var contexts = this.contexts;
  11974. var bitsDecoded = this.bitsDecoded;
  11975. var processingFlags = this.processingFlags;
  11976. var processedMask = 1;
  11977. var firstMagnitudeBitMask = 2;
  11978. var length = width * height;
  11979. var width4 = width * 4;
  11980. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  11981. indexNext = Math.min(length, index0 + width4);
  11982. for (var j = 0; j < width; j++) {
  11983. for (var index = index0 + j; index < indexNext; index += width) {
  11984. // significant but not those that have just become
  11985. if (!coefficentsMagnitude[index] ||
  11986. (processingFlags[index] & processedMask) !== 0) {
  11987. continue;
  11988. }
  11989. var contextLabel = 16;
  11990. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  11991. processingFlags[index] ^= firstMagnitudeBitMask;
  11992. // first refinement
  11993. var significance = neighborsSignificance[index] & 127;
  11994. contextLabel = significance === 0 ? 15 : 14;
  11995. }
  11996. var bit = decoder.readBit(contexts, contextLabel);
  11997. coefficentsMagnitude[index] =
  11998. (coefficentsMagnitude[index] << 1) | bit;
  11999. bitsDecoded[index]++;
  12000. processingFlags[index] |= processedMask;
  12001. }
  12002. }
  12003. }
  12004. },
  12005. runCleanupPass: function BitModel_runCleanupPass() {
  12006. var decoder = this.decoder;
  12007. var width = this.width, height = this.height;
  12008. var neighborsSignificance = this.neighborsSignificance;
  12009. var coefficentsMagnitude = this.coefficentsMagnitude;
  12010. var coefficentsSign = this.coefficentsSign;
  12011. var contexts = this.contexts;
  12012. var labels = this.contextLabelTable;
  12013. var bitsDecoded = this.bitsDecoded;
  12014. var processingFlags = this.processingFlags;
  12015. var processedMask = 1;
  12016. var firstMagnitudeBitMask = 2;
  12017. var oneRowDown = width;
  12018. var twoRowsDown = width * 2;
  12019. var threeRowsDown = width * 3;
  12020. var iNext;
  12021. for (var i0 = 0; i0 < height; i0 = iNext) {
  12022. iNext = Math.min(i0 + 4, height);
  12023. var indexBase = i0 * width;
  12024. var checkAllEmpty = i0 + 3 < height;
  12025. for (var j = 0; j < width; j++) {
  12026. var index0 = indexBase + j;
  12027. // using the property: labels[neighborsSignificance[index]] === 0
  12028. // when neighborsSignificance[index] === 0
  12029. var allEmpty = (checkAllEmpty &&
  12030. processingFlags[index0] === 0 &&
  12031. processingFlags[index0 + oneRowDown] === 0 &&
  12032. processingFlags[index0 + twoRowsDown] === 0 &&
  12033. processingFlags[index0 + threeRowsDown] === 0 &&
  12034. neighborsSignificance[index0] === 0 &&
  12035. neighborsSignificance[index0 + oneRowDown] === 0 &&
  12036. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  12037. neighborsSignificance[index0 + threeRowsDown] === 0);
  12038. var i1 = 0, index = index0;
  12039. var i = i0, sign;
  12040. if (allEmpty) {
  12041. var hasSignificantCoefficent =
  12042. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  12043. if (!hasSignificantCoefficent) {
  12044. bitsDecoded[index0]++;
  12045. bitsDecoded[index0 + oneRowDown]++;
  12046. bitsDecoded[index0 + twoRowsDown]++;
  12047. bitsDecoded[index0 + threeRowsDown]++;
  12048. continue; // next column
  12049. }
  12050. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  12051. decoder.readBit(contexts, UNIFORM_CONTEXT);
  12052. if (i1 !== 0) {
  12053. i = i0 + i1;
  12054. index += i1 * width;
  12055. }
  12056. sign = this.decodeSignBit(i, j, index);
  12057. coefficentsSign[index] = sign;
  12058. coefficentsMagnitude[index] = 1;
  12059. this.setNeighborsSignificance(i, j, index);
  12060. processingFlags[index] |= firstMagnitudeBitMask;
  12061. index = index0;
  12062. for (var i2 = i0; i2 <= i; i2++, index += width) {
  12063. bitsDecoded[index]++;
  12064. }
  12065. i1++;
  12066. }
  12067. for (i = i0 + i1; i < iNext; i++, index += width) {
  12068. if (coefficentsMagnitude[index] ||
  12069. (processingFlags[index] & processedMask) !== 0) {
  12070. continue;
  12071. }
  12072. var contextLabel = labels[neighborsSignificance[index]];
  12073. var decision = decoder.readBit(contexts, contextLabel);
  12074. if (decision === 1) {
  12075. sign = this.decodeSignBit(i, j, index);
  12076. coefficentsSign[index] = sign;
  12077. coefficentsMagnitude[index] = 1;
  12078. this.setNeighborsSignificance(i, j, index);
  12079. processingFlags[index] |= firstMagnitudeBitMask;
  12080. }
  12081. bitsDecoded[index]++;
  12082. }
  12083. }
  12084. }
  12085. },
  12086. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  12087. var decoder = this.decoder;
  12088. var contexts = this.contexts;
  12089. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  12090. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  12091. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  12092. decoder.readBit(contexts, UNIFORM_CONTEXT);
  12093. if (symbol !== 0xA) {
  12094. throw new Error('JPX Error: Invalid segmentation symbol');
  12095. }
  12096. }
  12097. };
  12098. return BitModel;
  12099. })();
  12100. // Section F, Discrete wavelet transformation
  12101. var Transform = (function TransformClosure() {
  12102. function Transform() {}
  12103. Transform.prototype.calculate =
  12104. function transformCalculate(subbands, u0, v0) {
  12105. var ll = subbands[0];
  12106. for (var i = 1, ii = subbands.length; i < ii; i++) {
  12107. ll = this.iterate(ll, subbands[i], u0, v0);
  12108. }
  12109. return ll;
  12110. };
  12111. Transform.prototype.extend = function extend(buffer, offset, size) {
  12112. // Section F.3.7 extending... using max extension of 4
  12113. var i1 = offset - 1, j1 = offset + 1;
  12114. var i2 = offset + size - 2, j2 = offset + size;
  12115. buffer[i1--] = buffer[j1++];
  12116. buffer[j2++] = buffer[i2--];
  12117. buffer[i1--] = buffer[j1++];
  12118. buffer[j2++] = buffer[i2--];
  12119. buffer[i1--] = buffer[j1++];
  12120. buffer[j2++] = buffer[i2--];
  12121. buffer[i1] = buffer[j1];
  12122. buffer[j2] = buffer[i2];
  12123. };
  12124. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  12125. u0, v0) {
  12126. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  12127. var width = hl_lh_hh.width;
  12128. var height = hl_lh_hh.height;
  12129. var items = hl_lh_hh.items;
  12130. var i, j, k, l, u, v;
  12131. // Interleave LL according to Section F.3.3
  12132. for (k = 0, i = 0; i < llHeight; i++) {
  12133. l = i * 2 * width;
  12134. for (j = 0; j < llWidth; j++, k++, l += 2) {
  12135. items[l] = llItems[k];
  12136. }
  12137. }
  12138. // The LL band is not needed anymore.
  12139. llItems = ll.items = null;
  12140. var bufferPadding = 4;
  12141. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  12142. // Section F.3.4 HOR_SR
  12143. if (width === 1) {
  12144. // if width = 1, when u0 even keep items as is, when odd divide by 2
  12145. if ((u0 & 1) !== 0) {
  12146. for (v = 0, k = 0; v < height; v++, k += width) {
  12147. items[k] *= 0.5;
  12148. }
  12149. }
  12150. } else {
  12151. for (v = 0, k = 0; v < height; v++, k += width) {
  12152. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  12153. this.extend(rowBuffer, bufferPadding, width);
  12154. this.filter(rowBuffer, bufferPadding, width);
  12155. items.set(
  12156. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  12157. k);
  12158. }
  12159. }
  12160. // Accesses to the items array can take long, because it may not fit into
  12161. // CPU cache and has to be fetched from main memory. Since subsequent
  12162. // accesses to the items array are not local when reading columns, we
  12163. // have a cache miss every time. To reduce cache misses, get up to
  12164. // 'numBuffers' items at a time and store them into the individual
  12165. // buffers. The colBuffers should be small enough to fit into CPU cache.
  12166. var numBuffers = 16;
  12167. var colBuffers = [];
  12168. for (i = 0; i < numBuffers; i++) {
  12169. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  12170. }
  12171. var b, currentBuffer = 0;
  12172. ll = bufferPadding + height;
  12173. // Section F.3.5 VER_SR
  12174. if (height === 1) {
  12175. // if height = 1, when v0 even keep items as is, when odd divide by 2
  12176. if ((v0 & 1) !== 0) {
  12177. for (u = 0; u < width; u++) {
  12178. items[u] *= 0.5;
  12179. }
  12180. }
  12181. } else {
  12182. for (u = 0; u < width; u++) {
  12183. // if we ran out of buffers, copy several image columns at once
  12184. if (currentBuffer === 0) {
  12185. numBuffers = Math.min(width - u, numBuffers);
  12186. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  12187. for (b = 0; b < numBuffers; b++) {
  12188. colBuffers[b][l] = items[k + b];
  12189. }
  12190. }
  12191. currentBuffer = numBuffers;
  12192. }
  12193. currentBuffer--;
  12194. var buffer = colBuffers[currentBuffer];
  12195. this.extend(buffer, bufferPadding, height);
  12196. this.filter(buffer, bufferPadding, height);
  12197. // If this is last buffer in this group of buffers, flush all buffers.
  12198. if (currentBuffer === 0) {
  12199. k = u - numBuffers + 1;
  12200. for (l = bufferPadding; l < ll; k += width, l++) {
  12201. for (b = 0; b < numBuffers; b++) {
  12202. items[k + b] = colBuffers[b][l];
  12203. }
  12204. }
  12205. }
  12206. }
  12207. }
  12208. return {
  12209. width: width,
  12210. height: height,
  12211. items: items
  12212. };
  12213. };
  12214. return Transform;
  12215. })();
  12216. // Section 3.8.2 Irreversible 9-7 filter
  12217. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  12218. function IrreversibleTransform() {
  12219. Transform.call(this);
  12220. }
  12221. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  12222. IrreversibleTransform.prototype.filter =
  12223. function irreversibleTransformFilter(x, offset, length) {
  12224. var len = length >> 1;
  12225. offset = offset | 0;
  12226. var j, n, current, next;
  12227. var alpha = -1.586134342059924;
  12228. var beta = -0.052980118572961;
  12229. var gamma = 0.882911075530934;
  12230. var delta = 0.443506852043971;
  12231. var K = 1.230174104914001;
  12232. var K_ = 1 / K;
  12233. // step 1 is combined with step 3
  12234. // step 2
  12235. j = offset - 3;
  12236. for (n = len + 4; n--; j += 2) {
  12237. x[j] *= K_;
  12238. }
  12239. // step 1 & 3
  12240. j = offset - 2;
  12241. current = delta * x[j -1];
  12242. for (n = len + 3; n--; j += 2) {
  12243. next = delta * x[j + 1];
  12244. x[j] = K * x[j] - current - next;
  12245. if (n--) {
  12246. j += 2;
  12247. current = delta * x[j + 1];
  12248. x[j] = K * x[j] - current - next;
  12249. } else {
  12250. break;
  12251. }
  12252. }
  12253. // step 4
  12254. j = offset - 1;
  12255. current = gamma * x[j - 1];
  12256. for (n = len + 2; n--; j += 2) {
  12257. next = gamma * x[j + 1];
  12258. x[j] -= current + next;
  12259. if (n--) {
  12260. j += 2;
  12261. current = gamma * x[j + 1];
  12262. x[j] -= current + next;
  12263. } else {
  12264. break;
  12265. }
  12266. }
  12267. // step 5
  12268. j = offset;
  12269. current = beta * x[j - 1];
  12270. for (n = len + 1; n--; j += 2) {
  12271. next = beta * x[j + 1];
  12272. x[j] -= current + next;
  12273. if (n--) {
  12274. j += 2;
  12275. current = beta * x[j + 1];
  12276. x[j] -= current + next;
  12277. } else {
  12278. break;
  12279. }
  12280. }
  12281. // step 6
  12282. if (len !== 0) {
  12283. j = offset + 1;
  12284. current = alpha * x[j - 1];
  12285. for (n = len; n--; j += 2) {
  12286. next = alpha * x[j + 1];
  12287. x[j] -= current + next;
  12288. if (n--) {
  12289. j += 2;
  12290. current = alpha * x[j + 1];
  12291. x[j] -= current + next;
  12292. } else {
  12293. break;
  12294. }
  12295. }
  12296. }
  12297. };
  12298. return IrreversibleTransform;
  12299. })();
  12300. // Section 3.8.1 Reversible 5-3 filter
  12301. var ReversibleTransform = (function ReversibleTransformClosure() {
  12302. function ReversibleTransform() {
  12303. Transform.call(this);
  12304. }
  12305. ReversibleTransform.prototype = Object.create(Transform.prototype);
  12306. ReversibleTransform.prototype.filter =
  12307. function reversibleTransformFilter(x, offset, length) {
  12308. var len = length >> 1;
  12309. offset = offset | 0;
  12310. var j, n;
  12311. for (j = offset, n = len + 1; n--; j += 2) {
  12312. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  12313. }
  12314. for (j = offset + 1, n = len; n--; j += 2) {
  12315. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  12316. }
  12317. };
  12318. return ReversibleTransform;
  12319. })();
  12320. return JpxImage;
  12321. })();
  12322. exports.JpxImage = JpxImage;
  12323. }));
  12324. (function (root, factory) {
  12325. {
  12326. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  12327. }
  12328. }(this, function (exports, sharedUtil) {
  12329. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  12330. // The Metrics object contains glyph widths (in glyph space units).
  12331. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  12332. // space unit corresponds to 1/1000th of text space unit.
  12333. var getMetrics = getLookupTableFactory(function (t) {
  12334. t['Courier'] = 600;
  12335. t['Courier-Bold'] = 600;
  12336. t['Courier-BoldOblique'] = 600;
  12337. t['Courier-Oblique'] = 600;
  12338. t['Helvetica'] = getLookupTableFactory(function (t) {
  12339. t['space'] = 278;
  12340. t['exclam'] = 278;
  12341. t['quotedbl'] = 355;
  12342. t['numbersign'] = 556;
  12343. t['dollar'] = 556;
  12344. t['percent'] = 889;
  12345. t['ampersand'] = 667;
  12346. t['quoteright'] = 222;
  12347. t['parenleft'] = 333;
  12348. t['parenright'] = 333;
  12349. t['asterisk'] = 389;
  12350. t['plus'] = 584;
  12351. t['comma'] = 278;
  12352. t['hyphen'] = 333;
  12353. t['period'] = 278;
  12354. t['slash'] = 278;
  12355. t['zero'] = 556;
  12356. t['one'] = 556;
  12357. t['two'] = 556;
  12358. t['three'] = 556;
  12359. t['four'] = 556;
  12360. t['five'] = 556;
  12361. t['six'] = 556;
  12362. t['seven'] = 556;
  12363. t['eight'] = 556;
  12364. t['nine'] = 556;
  12365. t['colon'] = 278;
  12366. t['semicolon'] = 278;
  12367. t['less'] = 584;
  12368. t['equal'] = 584;
  12369. t['greater'] = 584;
  12370. t['question'] = 556;
  12371. t['at'] = 1015;
  12372. t['A'] = 667;
  12373. t['B'] = 667;
  12374. t['C'] = 722;
  12375. t['D'] = 722;
  12376. t['E'] = 667;
  12377. t['F'] = 611;
  12378. t['G'] = 778;
  12379. t['H'] = 722;
  12380. t['I'] = 278;
  12381. t['J'] = 500;
  12382. t['K'] = 667;
  12383. t['L'] = 556;
  12384. t['M'] = 833;
  12385. t['N'] = 722;
  12386. t['O'] = 778;
  12387. t['P'] = 667;
  12388. t['Q'] = 778;
  12389. t['R'] = 722;
  12390. t['S'] = 667;
  12391. t['T'] = 611;
  12392. t['U'] = 722;
  12393. t['V'] = 667;
  12394. t['W'] = 944;
  12395. t['X'] = 667;
  12396. t['Y'] = 667;
  12397. t['Z'] = 611;
  12398. t['bracketleft'] = 278;
  12399. t['backslash'] = 278;
  12400. t['bracketright'] = 278;
  12401. t['asciicircum'] = 469;
  12402. t['underscore'] = 556;
  12403. t['quoteleft'] = 222;
  12404. t['a'] = 556;
  12405. t['b'] = 556;
  12406. t['c'] = 500;
  12407. t['d'] = 556;
  12408. t['e'] = 556;
  12409. t['f'] = 278;
  12410. t['g'] = 556;
  12411. t['h'] = 556;
  12412. t['i'] = 222;
  12413. t['j'] = 222;
  12414. t['k'] = 500;
  12415. t['l'] = 222;
  12416. t['m'] = 833;
  12417. t['n'] = 556;
  12418. t['o'] = 556;
  12419. t['p'] = 556;
  12420. t['q'] = 556;
  12421. t['r'] = 333;
  12422. t['s'] = 500;
  12423. t['t'] = 278;
  12424. t['u'] = 556;
  12425. t['v'] = 500;
  12426. t['w'] = 722;
  12427. t['x'] = 500;
  12428. t['y'] = 500;
  12429. t['z'] = 500;
  12430. t['braceleft'] = 334;
  12431. t['bar'] = 260;
  12432. t['braceright'] = 334;
  12433. t['asciitilde'] = 584;
  12434. t['exclamdown'] = 333;
  12435. t['cent'] = 556;
  12436. t['sterling'] = 556;
  12437. t['fraction'] = 167;
  12438. t['yen'] = 556;
  12439. t['florin'] = 556;
  12440. t['section'] = 556;
  12441. t['currency'] = 556;
  12442. t['quotesingle'] = 191;
  12443. t['quotedblleft'] = 333;
  12444. t['guillemotleft'] = 556;
  12445. t['guilsinglleft'] = 333;
  12446. t['guilsinglright'] = 333;
  12447. t['fi'] = 500;
  12448. t['fl'] = 500;
  12449. t['endash'] = 556;
  12450. t['dagger'] = 556;
  12451. t['daggerdbl'] = 556;
  12452. t['periodcentered'] = 278;
  12453. t['paragraph'] = 537;
  12454. t['bullet'] = 350;
  12455. t['quotesinglbase'] = 222;
  12456. t['quotedblbase'] = 333;
  12457. t['quotedblright'] = 333;
  12458. t['guillemotright'] = 556;
  12459. t['ellipsis'] = 1000;
  12460. t['perthousand'] = 1000;
  12461. t['questiondown'] = 611;
  12462. t['grave'] = 333;
  12463. t['acute'] = 333;
  12464. t['circumflex'] = 333;
  12465. t['tilde'] = 333;
  12466. t['macron'] = 333;
  12467. t['breve'] = 333;
  12468. t['dotaccent'] = 333;
  12469. t['dieresis'] = 333;
  12470. t['ring'] = 333;
  12471. t['cedilla'] = 333;
  12472. t['hungarumlaut'] = 333;
  12473. t['ogonek'] = 333;
  12474. t['caron'] = 333;
  12475. t['emdash'] = 1000;
  12476. t['AE'] = 1000;
  12477. t['ordfeminine'] = 370;
  12478. t['Lslash'] = 556;
  12479. t['Oslash'] = 778;
  12480. t['OE'] = 1000;
  12481. t['ordmasculine'] = 365;
  12482. t['ae'] = 889;
  12483. t['dotlessi'] = 278;
  12484. t['lslash'] = 222;
  12485. t['oslash'] = 611;
  12486. t['oe'] = 944;
  12487. t['germandbls'] = 611;
  12488. t['Idieresis'] = 278;
  12489. t['eacute'] = 556;
  12490. t['abreve'] = 556;
  12491. t['uhungarumlaut'] = 556;
  12492. t['ecaron'] = 556;
  12493. t['Ydieresis'] = 667;
  12494. t['divide'] = 584;
  12495. t['Yacute'] = 667;
  12496. t['Acircumflex'] = 667;
  12497. t['aacute'] = 556;
  12498. t['Ucircumflex'] = 722;
  12499. t['yacute'] = 500;
  12500. t['scommaaccent'] = 500;
  12501. t['ecircumflex'] = 556;
  12502. t['Uring'] = 722;
  12503. t['Udieresis'] = 722;
  12504. t['aogonek'] = 556;
  12505. t['Uacute'] = 722;
  12506. t['uogonek'] = 556;
  12507. t['Edieresis'] = 667;
  12508. t['Dcroat'] = 722;
  12509. t['commaaccent'] = 250;
  12510. t['copyright'] = 737;
  12511. t['Emacron'] = 667;
  12512. t['ccaron'] = 500;
  12513. t['aring'] = 556;
  12514. t['Ncommaaccent'] = 722;
  12515. t['lacute'] = 222;
  12516. t['agrave'] = 556;
  12517. t['Tcommaaccent'] = 611;
  12518. t['Cacute'] = 722;
  12519. t['atilde'] = 556;
  12520. t['Edotaccent'] = 667;
  12521. t['scaron'] = 500;
  12522. t['scedilla'] = 500;
  12523. t['iacute'] = 278;
  12524. t['lozenge'] = 471;
  12525. t['Rcaron'] = 722;
  12526. t['Gcommaaccent'] = 778;
  12527. t['ucircumflex'] = 556;
  12528. t['acircumflex'] = 556;
  12529. t['Amacron'] = 667;
  12530. t['rcaron'] = 333;
  12531. t['ccedilla'] = 500;
  12532. t['Zdotaccent'] = 611;
  12533. t['Thorn'] = 667;
  12534. t['Omacron'] = 778;
  12535. t['Racute'] = 722;
  12536. t['Sacute'] = 667;
  12537. t['dcaron'] = 643;
  12538. t['Umacron'] = 722;
  12539. t['uring'] = 556;
  12540. t['threesuperior'] = 333;
  12541. t['Ograve'] = 778;
  12542. t['Agrave'] = 667;
  12543. t['Abreve'] = 667;
  12544. t['multiply'] = 584;
  12545. t['uacute'] = 556;
  12546. t['Tcaron'] = 611;
  12547. t['partialdiff'] = 476;
  12548. t['ydieresis'] = 500;
  12549. t['Nacute'] = 722;
  12550. t['icircumflex'] = 278;
  12551. t['Ecircumflex'] = 667;
  12552. t['adieresis'] = 556;
  12553. t['edieresis'] = 556;
  12554. t['cacute'] = 500;
  12555. t['nacute'] = 556;
  12556. t['umacron'] = 556;
  12557. t['Ncaron'] = 722;
  12558. t['Iacute'] = 278;
  12559. t['plusminus'] = 584;
  12560. t['brokenbar'] = 260;
  12561. t['registered'] = 737;
  12562. t['Gbreve'] = 778;
  12563. t['Idotaccent'] = 278;
  12564. t['summation'] = 600;
  12565. t['Egrave'] = 667;
  12566. t['racute'] = 333;
  12567. t['omacron'] = 556;
  12568. t['Zacute'] = 611;
  12569. t['Zcaron'] = 611;
  12570. t['greaterequal'] = 549;
  12571. t['Eth'] = 722;
  12572. t['Ccedilla'] = 722;
  12573. t['lcommaaccent'] = 222;
  12574. t['tcaron'] = 317;
  12575. t['eogonek'] = 556;
  12576. t['Uogonek'] = 722;
  12577. t['Aacute'] = 667;
  12578. t['Adieresis'] = 667;
  12579. t['egrave'] = 556;
  12580. t['zacute'] = 500;
  12581. t['iogonek'] = 222;
  12582. t['Oacute'] = 778;
  12583. t['oacute'] = 556;
  12584. t['amacron'] = 556;
  12585. t['sacute'] = 500;
  12586. t['idieresis'] = 278;
  12587. t['Ocircumflex'] = 778;
  12588. t['Ugrave'] = 722;
  12589. t['Delta'] = 612;
  12590. t['thorn'] = 556;
  12591. t['twosuperior'] = 333;
  12592. t['Odieresis'] = 778;
  12593. t['mu'] = 556;
  12594. t['igrave'] = 278;
  12595. t['ohungarumlaut'] = 556;
  12596. t['Eogonek'] = 667;
  12597. t['dcroat'] = 556;
  12598. t['threequarters'] = 834;
  12599. t['Scedilla'] = 667;
  12600. t['lcaron'] = 299;
  12601. t['Kcommaaccent'] = 667;
  12602. t['Lacute'] = 556;
  12603. t['trademark'] = 1000;
  12604. t['edotaccent'] = 556;
  12605. t['Igrave'] = 278;
  12606. t['Imacron'] = 278;
  12607. t['Lcaron'] = 556;
  12608. t['onehalf'] = 834;
  12609. t['lessequal'] = 549;
  12610. t['ocircumflex'] = 556;
  12611. t['ntilde'] = 556;
  12612. t['Uhungarumlaut'] = 722;
  12613. t['Eacute'] = 667;
  12614. t['emacron'] = 556;
  12615. t['gbreve'] = 556;
  12616. t['onequarter'] = 834;
  12617. t['Scaron'] = 667;
  12618. t['Scommaaccent'] = 667;
  12619. t['Ohungarumlaut'] = 778;
  12620. t['degree'] = 400;
  12621. t['ograve'] = 556;
  12622. t['Ccaron'] = 722;
  12623. t['ugrave'] = 556;
  12624. t['radical'] = 453;
  12625. t['Dcaron'] = 722;
  12626. t['rcommaaccent'] = 333;
  12627. t['Ntilde'] = 722;
  12628. t['otilde'] = 556;
  12629. t['Rcommaaccent'] = 722;
  12630. t['Lcommaaccent'] = 556;
  12631. t['Atilde'] = 667;
  12632. t['Aogonek'] = 667;
  12633. t['Aring'] = 667;
  12634. t['Otilde'] = 778;
  12635. t['zdotaccent'] = 500;
  12636. t['Ecaron'] = 667;
  12637. t['Iogonek'] = 278;
  12638. t['kcommaaccent'] = 500;
  12639. t['minus'] = 584;
  12640. t['Icircumflex'] = 278;
  12641. t['ncaron'] = 556;
  12642. t['tcommaaccent'] = 278;
  12643. t['logicalnot'] = 584;
  12644. t['odieresis'] = 556;
  12645. t['udieresis'] = 556;
  12646. t['notequal'] = 549;
  12647. t['gcommaaccent'] = 556;
  12648. t['eth'] = 556;
  12649. t['zcaron'] = 500;
  12650. t['ncommaaccent'] = 556;
  12651. t['onesuperior'] = 333;
  12652. t['imacron'] = 278;
  12653. t['Euro'] = 556;
  12654. });
  12655. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  12656. t['space'] = 278;
  12657. t['exclam'] = 333;
  12658. t['quotedbl'] = 474;
  12659. t['numbersign'] = 556;
  12660. t['dollar'] = 556;
  12661. t['percent'] = 889;
  12662. t['ampersand'] = 722;
  12663. t['quoteright'] = 278;
  12664. t['parenleft'] = 333;
  12665. t['parenright'] = 333;
  12666. t['asterisk'] = 389;
  12667. t['plus'] = 584;
  12668. t['comma'] = 278;
  12669. t['hyphen'] = 333;
  12670. t['period'] = 278;
  12671. t['slash'] = 278;
  12672. t['zero'] = 556;
  12673. t['one'] = 556;
  12674. t['two'] = 556;
  12675. t['three'] = 556;
  12676. t['four'] = 556;
  12677. t['five'] = 556;
  12678. t['six'] = 556;
  12679. t['seven'] = 556;
  12680. t['eight'] = 556;
  12681. t['nine'] = 556;
  12682. t['colon'] = 333;
  12683. t['semicolon'] = 333;
  12684. t['less'] = 584;
  12685. t['equal'] = 584;
  12686. t['greater'] = 584;
  12687. t['question'] = 611;
  12688. t['at'] = 975;
  12689. t['A'] = 722;
  12690. t['B'] = 722;
  12691. t['C'] = 722;
  12692. t['D'] = 722;
  12693. t['E'] = 667;
  12694. t['F'] = 611;
  12695. t['G'] = 778;
  12696. t['H'] = 722;
  12697. t['I'] = 278;
  12698. t['J'] = 556;
  12699. t['K'] = 722;
  12700. t['L'] = 611;
  12701. t['M'] = 833;
  12702. t['N'] = 722;
  12703. t['O'] = 778;
  12704. t['P'] = 667;
  12705. t['Q'] = 778;
  12706. t['R'] = 722;
  12707. t['S'] = 667;
  12708. t['T'] = 611;
  12709. t['U'] = 722;
  12710. t['V'] = 667;
  12711. t['W'] = 944;
  12712. t['X'] = 667;
  12713. t['Y'] = 667;
  12714. t['Z'] = 611;
  12715. t['bracketleft'] = 333;
  12716. t['backslash'] = 278;
  12717. t['bracketright'] = 333;
  12718. t['asciicircum'] = 584;
  12719. t['underscore'] = 556;
  12720. t['quoteleft'] = 278;
  12721. t['a'] = 556;
  12722. t['b'] = 611;
  12723. t['c'] = 556;
  12724. t['d'] = 611;
  12725. t['e'] = 556;
  12726. t['f'] = 333;
  12727. t['g'] = 611;
  12728. t['h'] = 611;
  12729. t['i'] = 278;
  12730. t['j'] = 278;
  12731. t['k'] = 556;
  12732. t['l'] = 278;
  12733. t['m'] = 889;
  12734. t['n'] = 611;
  12735. t['o'] = 611;
  12736. t['p'] = 611;
  12737. t['q'] = 611;
  12738. t['r'] = 389;
  12739. t['s'] = 556;
  12740. t['t'] = 333;
  12741. t['u'] = 611;
  12742. t['v'] = 556;
  12743. t['w'] = 778;
  12744. t['x'] = 556;
  12745. t['y'] = 556;
  12746. t['z'] = 500;
  12747. t['braceleft'] = 389;
  12748. t['bar'] = 280;
  12749. t['braceright'] = 389;
  12750. t['asciitilde'] = 584;
  12751. t['exclamdown'] = 333;
  12752. t['cent'] = 556;
  12753. t['sterling'] = 556;
  12754. t['fraction'] = 167;
  12755. t['yen'] = 556;
  12756. t['florin'] = 556;
  12757. t['section'] = 556;
  12758. t['currency'] = 556;
  12759. t['quotesingle'] = 238;
  12760. t['quotedblleft'] = 500;
  12761. t['guillemotleft'] = 556;
  12762. t['guilsinglleft'] = 333;
  12763. t['guilsinglright'] = 333;
  12764. t['fi'] = 611;
  12765. t['fl'] = 611;
  12766. t['endash'] = 556;
  12767. t['dagger'] = 556;
  12768. t['daggerdbl'] = 556;
  12769. t['periodcentered'] = 278;
  12770. t['paragraph'] = 556;
  12771. t['bullet'] = 350;
  12772. t['quotesinglbase'] = 278;
  12773. t['quotedblbase'] = 500;
  12774. t['quotedblright'] = 500;
  12775. t['guillemotright'] = 556;
  12776. t['ellipsis'] = 1000;
  12777. t['perthousand'] = 1000;
  12778. t['questiondown'] = 611;
  12779. t['grave'] = 333;
  12780. t['acute'] = 333;
  12781. t['circumflex'] = 333;
  12782. t['tilde'] = 333;
  12783. t['macron'] = 333;
  12784. t['breve'] = 333;
  12785. t['dotaccent'] = 333;
  12786. t['dieresis'] = 333;
  12787. t['ring'] = 333;
  12788. t['cedilla'] = 333;
  12789. t['hungarumlaut'] = 333;
  12790. t['ogonek'] = 333;
  12791. t['caron'] = 333;
  12792. t['emdash'] = 1000;
  12793. t['AE'] = 1000;
  12794. t['ordfeminine'] = 370;
  12795. t['Lslash'] = 611;
  12796. t['Oslash'] = 778;
  12797. t['OE'] = 1000;
  12798. t['ordmasculine'] = 365;
  12799. t['ae'] = 889;
  12800. t['dotlessi'] = 278;
  12801. t['lslash'] = 278;
  12802. t['oslash'] = 611;
  12803. t['oe'] = 944;
  12804. t['germandbls'] = 611;
  12805. t['Idieresis'] = 278;
  12806. t['eacute'] = 556;
  12807. t['abreve'] = 556;
  12808. t['uhungarumlaut'] = 611;
  12809. t['ecaron'] = 556;
  12810. t['Ydieresis'] = 667;
  12811. t['divide'] = 584;
  12812. t['Yacute'] = 667;
  12813. t['Acircumflex'] = 722;
  12814. t['aacute'] = 556;
  12815. t['Ucircumflex'] = 722;
  12816. t['yacute'] = 556;
  12817. t['scommaaccent'] = 556;
  12818. t['ecircumflex'] = 556;
  12819. t['Uring'] = 722;
  12820. t['Udieresis'] = 722;
  12821. t['aogonek'] = 556;
  12822. t['Uacute'] = 722;
  12823. t['uogonek'] = 611;
  12824. t['Edieresis'] = 667;
  12825. t['Dcroat'] = 722;
  12826. t['commaaccent'] = 250;
  12827. t['copyright'] = 737;
  12828. t['Emacron'] = 667;
  12829. t['ccaron'] = 556;
  12830. t['aring'] = 556;
  12831. t['Ncommaaccent'] = 722;
  12832. t['lacute'] = 278;
  12833. t['agrave'] = 556;
  12834. t['Tcommaaccent'] = 611;
  12835. t['Cacute'] = 722;
  12836. t['atilde'] = 556;
  12837. t['Edotaccent'] = 667;
  12838. t['scaron'] = 556;
  12839. t['scedilla'] = 556;
  12840. t['iacute'] = 278;
  12841. t['lozenge'] = 494;
  12842. t['Rcaron'] = 722;
  12843. t['Gcommaaccent'] = 778;
  12844. t['ucircumflex'] = 611;
  12845. t['acircumflex'] = 556;
  12846. t['Amacron'] = 722;
  12847. t['rcaron'] = 389;
  12848. t['ccedilla'] = 556;
  12849. t['Zdotaccent'] = 611;
  12850. t['Thorn'] = 667;
  12851. t['Omacron'] = 778;
  12852. t['Racute'] = 722;
  12853. t['Sacute'] = 667;
  12854. t['dcaron'] = 743;
  12855. t['Umacron'] = 722;
  12856. t['uring'] = 611;
  12857. t['threesuperior'] = 333;
  12858. t['Ograve'] = 778;
  12859. t['Agrave'] = 722;
  12860. t['Abreve'] = 722;
  12861. t['multiply'] = 584;
  12862. t['uacute'] = 611;
  12863. t['Tcaron'] = 611;
  12864. t['partialdiff'] = 494;
  12865. t['ydieresis'] = 556;
  12866. t['Nacute'] = 722;
  12867. t['icircumflex'] = 278;
  12868. t['Ecircumflex'] = 667;
  12869. t['adieresis'] = 556;
  12870. t['edieresis'] = 556;
  12871. t['cacute'] = 556;
  12872. t['nacute'] = 611;
  12873. t['umacron'] = 611;
  12874. t['Ncaron'] = 722;
  12875. t['Iacute'] = 278;
  12876. t['plusminus'] = 584;
  12877. t['brokenbar'] = 280;
  12878. t['registered'] = 737;
  12879. t['Gbreve'] = 778;
  12880. t['Idotaccent'] = 278;
  12881. t['summation'] = 600;
  12882. t['Egrave'] = 667;
  12883. t['racute'] = 389;
  12884. t['omacron'] = 611;
  12885. t['Zacute'] = 611;
  12886. t['Zcaron'] = 611;
  12887. t['greaterequal'] = 549;
  12888. t['Eth'] = 722;
  12889. t['Ccedilla'] = 722;
  12890. t['lcommaaccent'] = 278;
  12891. t['tcaron'] = 389;
  12892. t['eogonek'] = 556;
  12893. t['Uogonek'] = 722;
  12894. t['Aacute'] = 722;
  12895. t['Adieresis'] = 722;
  12896. t['egrave'] = 556;
  12897. t['zacute'] = 500;
  12898. t['iogonek'] = 278;
  12899. t['Oacute'] = 778;
  12900. t['oacute'] = 611;
  12901. t['amacron'] = 556;
  12902. t['sacute'] = 556;
  12903. t['idieresis'] = 278;
  12904. t['Ocircumflex'] = 778;
  12905. t['Ugrave'] = 722;
  12906. t['Delta'] = 612;
  12907. t['thorn'] = 611;
  12908. t['twosuperior'] = 333;
  12909. t['Odieresis'] = 778;
  12910. t['mu'] = 611;
  12911. t['igrave'] = 278;
  12912. t['ohungarumlaut'] = 611;
  12913. t['Eogonek'] = 667;
  12914. t['dcroat'] = 611;
  12915. t['threequarters'] = 834;
  12916. t['Scedilla'] = 667;
  12917. t['lcaron'] = 400;
  12918. t['Kcommaaccent'] = 722;
  12919. t['Lacute'] = 611;
  12920. t['trademark'] = 1000;
  12921. t['edotaccent'] = 556;
  12922. t['Igrave'] = 278;
  12923. t['Imacron'] = 278;
  12924. t['Lcaron'] = 611;
  12925. t['onehalf'] = 834;
  12926. t['lessequal'] = 549;
  12927. t['ocircumflex'] = 611;
  12928. t['ntilde'] = 611;
  12929. t['Uhungarumlaut'] = 722;
  12930. t['Eacute'] = 667;
  12931. t['emacron'] = 556;
  12932. t['gbreve'] = 611;
  12933. t['onequarter'] = 834;
  12934. t['Scaron'] = 667;
  12935. t['Scommaaccent'] = 667;
  12936. t['Ohungarumlaut'] = 778;
  12937. t['degree'] = 400;
  12938. t['ograve'] = 611;
  12939. t['Ccaron'] = 722;
  12940. t['ugrave'] = 611;
  12941. t['radical'] = 549;
  12942. t['Dcaron'] = 722;
  12943. t['rcommaaccent'] = 389;
  12944. t['Ntilde'] = 722;
  12945. t['otilde'] = 611;
  12946. t['Rcommaaccent'] = 722;
  12947. t['Lcommaaccent'] = 611;
  12948. t['Atilde'] = 722;
  12949. t['Aogonek'] = 722;
  12950. t['Aring'] = 722;
  12951. t['Otilde'] = 778;
  12952. t['zdotaccent'] = 500;
  12953. t['Ecaron'] = 667;
  12954. t['Iogonek'] = 278;
  12955. t['kcommaaccent'] = 556;
  12956. t['minus'] = 584;
  12957. t['Icircumflex'] = 278;
  12958. t['ncaron'] = 611;
  12959. t['tcommaaccent'] = 333;
  12960. t['logicalnot'] = 584;
  12961. t['odieresis'] = 611;
  12962. t['udieresis'] = 611;
  12963. t['notequal'] = 549;
  12964. t['gcommaaccent'] = 611;
  12965. t['eth'] = 611;
  12966. t['zcaron'] = 500;
  12967. t['ncommaaccent'] = 611;
  12968. t['onesuperior'] = 333;
  12969. t['imacron'] = 278;
  12970. t['Euro'] = 556;
  12971. });
  12972. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  12973. t['space'] = 278;
  12974. t['exclam'] = 333;
  12975. t['quotedbl'] = 474;
  12976. t['numbersign'] = 556;
  12977. t['dollar'] = 556;
  12978. t['percent'] = 889;
  12979. t['ampersand'] = 722;
  12980. t['quoteright'] = 278;
  12981. t['parenleft'] = 333;
  12982. t['parenright'] = 333;
  12983. t['asterisk'] = 389;
  12984. t['plus'] = 584;
  12985. t['comma'] = 278;
  12986. t['hyphen'] = 333;
  12987. t['period'] = 278;
  12988. t['slash'] = 278;
  12989. t['zero'] = 556;
  12990. t['one'] = 556;
  12991. t['two'] = 556;
  12992. t['three'] = 556;
  12993. t['four'] = 556;
  12994. t['five'] = 556;
  12995. t['six'] = 556;
  12996. t['seven'] = 556;
  12997. t['eight'] = 556;
  12998. t['nine'] = 556;
  12999. t['colon'] = 333;
  13000. t['semicolon'] = 333;
  13001. t['less'] = 584;
  13002. t['equal'] = 584;
  13003. t['greater'] = 584;
  13004. t['question'] = 611;
  13005. t['at'] = 975;
  13006. t['A'] = 722;
  13007. t['B'] = 722;
  13008. t['C'] = 722;
  13009. t['D'] = 722;
  13010. t['E'] = 667;
  13011. t['F'] = 611;
  13012. t['G'] = 778;
  13013. t['H'] = 722;
  13014. t['I'] = 278;
  13015. t['J'] = 556;
  13016. t['K'] = 722;
  13017. t['L'] = 611;
  13018. t['M'] = 833;
  13019. t['N'] = 722;
  13020. t['O'] = 778;
  13021. t['P'] = 667;
  13022. t['Q'] = 778;
  13023. t['R'] = 722;
  13024. t['S'] = 667;
  13025. t['T'] = 611;
  13026. t['U'] = 722;
  13027. t['V'] = 667;
  13028. t['W'] = 944;
  13029. t['X'] = 667;
  13030. t['Y'] = 667;
  13031. t['Z'] = 611;
  13032. t['bracketleft'] = 333;
  13033. t['backslash'] = 278;
  13034. t['bracketright'] = 333;
  13035. t['asciicircum'] = 584;
  13036. t['underscore'] = 556;
  13037. t['quoteleft'] = 278;
  13038. t['a'] = 556;
  13039. t['b'] = 611;
  13040. t['c'] = 556;
  13041. t['d'] = 611;
  13042. t['e'] = 556;
  13043. t['f'] = 333;
  13044. t['g'] = 611;
  13045. t['h'] = 611;
  13046. t['i'] = 278;
  13047. t['j'] = 278;
  13048. t['k'] = 556;
  13049. t['l'] = 278;
  13050. t['m'] = 889;
  13051. t['n'] = 611;
  13052. t['o'] = 611;
  13053. t['p'] = 611;
  13054. t['q'] = 611;
  13055. t['r'] = 389;
  13056. t['s'] = 556;
  13057. t['t'] = 333;
  13058. t['u'] = 611;
  13059. t['v'] = 556;
  13060. t['w'] = 778;
  13061. t['x'] = 556;
  13062. t['y'] = 556;
  13063. t['z'] = 500;
  13064. t['braceleft'] = 389;
  13065. t['bar'] = 280;
  13066. t['braceright'] = 389;
  13067. t['asciitilde'] = 584;
  13068. t['exclamdown'] = 333;
  13069. t['cent'] = 556;
  13070. t['sterling'] = 556;
  13071. t['fraction'] = 167;
  13072. t['yen'] = 556;
  13073. t['florin'] = 556;
  13074. t['section'] = 556;
  13075. t['currency'] = 556;
  13076. t['quotesingle'] = 238;
  13077. t['quotedblleft'] = 500;
  13078. t['guillemotleft'] = 556;
  13079. t['guilsinglleft'] = 333;
  13080. t['guilsinglright'] = 333;
  13081. t['fi'] = 611;
  13082. t['fl'] = 611;
  13083. t['endash'] = 556;
  13084. t['dagger'] = 556;
  13085. t['daggerdbl'] = 556;
  13086. t['periodcentered'] = 278;
  13087. t['paragraph'] = 556;
  13088. t['bullet'] = 350;
  13089. t['quotesinglbase'] = 278;
  13090. t['quotedblbase'] = 500;
  13091. t['quotedblright'] = 500;
  13092. t['guillemotright'] = 556;
  13093. t['ellipsis'] = 1000;
  13094. t['perthousand'] = 1000;
  13095. t['questiondown'] = 611;
  13096. t['grave'] = 333;
  13097. t['acute'] = 333;
  13098. t['circumflex'] = 333;
  13099. t['tilde'] = 333;
  13100. t['macron'] = 333;
  13101. t['breve'] = 333;
  13102. t['dotaccent'] = 333;
  13103. t['dieresis'] = 333;
  13104. t['ring'] = 333;
  13105. t['cedilla'] = 333;
  13106. t['hungarumlaut'] = 333;
  13107. t['ogonek'] = 333;
  13108. t['caron'] = 333;
  13109. t['emdash'] = 1000;
  13110. t['AE'] = 1000;
  13111. t['ordfeminine'] = 370;
  13112. t['Lslash'] = 611;
  13113. t['Oslash'] = 778;
  13114. t['OE'] = 1000;
  13115. t['ordmasculine'] = 365;
  13116. t['ae'] = 889;
  13117. t['dotlessi'] = 278;
  13118. t['lslash'] = 278;
  13119. t['oslash'] = 611;
  13120. t['oe'] = 944;
  13121. t['germandbls'] = 611;
  13122. t['Idieresis'] = 278;
  13123. t['eacute'] = 556;
  13124. t['abreve'] = 556;
  13125. t['uhungarumlaut'] = 611;
  13126. t['ecaron'] = 556;
  13127. t['Ydieresis'] = 667;
  13128. t['divide'] = 584;
  13129. t['Yacute'] = 667;
  13130. t['Acircumflex'] = 722;
  13131. t['aacute'] = 556;
  13132. t['Ucircumflex'] = 722;
  13133. t['yacute'] = 556;
  13134. t['scommaaccent'] = 556;
  13135. t['ecircumflex'] = 556;
  13136. t['Uring'] = 722;
  13137. t['Udieresis'] = 722;
  13138. t['aogonek'] = 556;
  13139. t['Uacute'] = 722;
  13140. t['uogonek'] = 611;
  13141. t['Edieresis'] = 667;
  13142. t['Dcroat'] = 722;
  13143. t['commaaccent'] = 250;
  13144. t['copyright'] = 737;
  13145. t['Emacron'] = 667;
  13146. t['ccaron'] = 556;
  13147. t['aring'] = 556;
  13148. t['Ncommaaccent'] = 722;
  13149. t['lacute'] = 278;
  13150. t['agrave'] = 556;
  13151. t['Tcommaaccent'] = 611;
  13152. t['Cacute'] = 722;
  13153. t['atilde'] = 556;
  13154. t['Edotaccent'] = 667;
  13155. t['scaron'] = 556;
  13156. t['scedilla'] = 556;
  13157. t['iacute'] = 278;
  13158. t['lozenge'] = 494;
  13159. t['Rcaron'] = 722;
  13160. t['Gcommaaccent'] = 778;
  13161. t['ucircumflex'] = 611;
  13162. t['acircumflex'] = 556;
  13163. t['Amacron'] = 722;
  13164. t['rcaron'] = 389;
  13165. t['ccedilla'] = 556;
  13166. t['Zdotaccent'] = 611;
  13167. t['Thorn'] = 667;
  13168. t['Omacron'] = 778;
  13169. t['Racute'] = 722;
  13170. t['Sacute'] = 667;
  13171. t['dcaron'] = 743;
  13172. t['Umacron'] = 722;
  13173. t['uring'] = 611;
  13174. t['threesuperior'] = 333;
  13175. t['Ograve'] = 778;
  13176. t['Agrave'] = 722;
  13177. t['Abreve'] = 722;
  13178. t['multiply'] = 584;
  13179. t['uacute'] = 611;
  13180. t['Tcaron'] = 611;
  13181. t['partialdiff'] = 494;
  13182. t['ydieresis'] = 556;
  13183. t['Nacute'] = 722;
  13184. t['icircumflex'] = 278;
  13185. t['Ecircumflex'] = 667;
  13186. t['adieresis'] = 556;
  13187. t['edieresis'] = 556;
  13188. t['cacute'] = 556;
  13189. t['nacute'] = 611;
  13190. t['umacron'] = 611;
  13191. t['Ncaron'] = 722;
  13192. t['Iacute'] = 278;
  13193. t['plusminus'] = 584;
  13194. t['brokenbar'] = 280;
  13195. t['registered'] = 737;
  13196. t['Gbreve'] = 778;
  13197. t['Idotaccent'] = 278;
  13198. t['summation'] = 600;
  13199. t['Egrave'] = 667;
  13200. t['racute'] = 389;
  13201. t['omacron'] = 611;
  13202. t['Zacute'] = 611;
  13203. t['Zcaron'] = 611;
  13204. t['greaterequal'] = 549;
  13205. t['Eth'] = 722;
  13206. t['Ccedilla'] = 722;
  13207. t['lcommaaccent'] = 278;
  13208. t['tcaron'] = 389;
  13209. t['eogonek'] = 556;
  13210. t['Uogonek'] = 722;
  13211. t['Aacute'] = 722;
  13212. t['Adieresis'] = 722;
  13213. t['egrave'] = 556;
  13214. t['zacute'] = 500;
  13215. t['iogonek'] = 278;
  13216. t['Oacute'] = 778;
  13217. t['oacute'] = 611;
  13218. t['amacron'] = 556;
  13219. t['sacute'] = 556;
  13220. t['idieresis'] = 278;
  13221. t['Ocircumflex'] = 778;
  13222. t['Ugrave'] = 722;
  13223. t['Delta'] = 612;
  13224. t['thorn'] = 611;
  13225. t['twosuperior'] = 333;
  13226. t['Odieresis'] = 778;
  13227. t['mu'] = 611;
  13228. t['igrave'] = 278;
  13229. t['ohungarumlaut'] = 611;
  13230. t['Eogonek'] = 667;
  13231. t['dcroat'] = 611;
  13232. t['threequarters'] = 834;
  13233. t['Scedilla'] = 667;
  13234. t['lcaron'] = 400;
  13235. t['Kcommaaccent'] = 722;
  13236. t['Lacute'] = 611;
  13237. t['trademark'] = 1000;
  13238. t['edotaccent'] = 556;
  13239. t['Igrave'] = 278;
  13240. t['Imacron'] = 278;
  13241. t['Lcaron'] = 611;
  13242. t['onehalf'] = 834;
  13243. t['lessequal'] = 549;
  13244. t['ocircumflex'] = 611;
  13245. t['ntilde'] = 611;
  13246. t['Uhungarumlaut'] = 722;
  13247. t['Eacute'] = 667;
  13248. t['emacron'] = 556;
  13249. t['gbreve'] = 611;
  13250. t['onequarter'] = 834;
  13251. t['Scaron'] = 667;
  13252. t['Scommaaccent'] = 667;
  13253. t['Ohungarumlaut'] = 778;
  13254. t['degree'] = 400;
  13255. t['ograve'] = 611;
  13256. t['Ccaron'] = 722;
  13257. t['ugrave'] = 611;
  13258. t['radical'] = 549;
  13259. t['Dcaron'] = 722;
  13260. t['rcommaaccent'] = 389;
  13261. t['Ntilde'] = 722;
  13262. t['otilde'] = 611;
  13263. t['Rcommaaccent'] = 722;
  13264. t['Lcommaaccent'] = 611;
  13265. t['Atilde'] = 722;
  13266. t['Aogonek'] = 722;
  13267. t['Aring'] = 722;
  13268. t['Otilde'] = 778;
  13269. t['zdotaccent'] = 500;
  13270. t['Ecaron'] = 667;
  13271. t['Iogonek'] = 278;
  13272. t['kcommaaccent'] = 556;
  13273. t['minus'] = 584;
  13274. t['Icircumflex'] = 278;
  13275. t['ncaron'] = 611;
  13276. t['tcommaaccent'] = 333;
  13277. t['logicalnot'] = 584;
  13278. t['odieresis'] = 611;
  13279. t['udieresis'] = 611;
  13280. t['notequal'] = 549;
  13281. t['gcommaaccent'] = 611;
  13282. t['eth'] = 611;
  13283. t['zcaron'] = 500;
  13284. t['ncommaaccent'] = 611;
  13285. t['onesuperior'] = 333;
  13286. t['imacron'] = 278;
  13287. t['Euro'] = 556;
  13288. });
  13289. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  13290. t['space'] = 278;
  13291. t['exclam'] = 278;
  13292. t['quotedbl'] = 355;
  13293. t['numbersign'] = 556;
  13294. t['dollar'] = 556;
  13295. t['percent'] = 889;
  13296. t['ampersand'] = 667;
  13297. t['quoteright'] = 222;
  13298. t['parenleft'] = 333;
  13299. t['parenright'] = 333;
  13300. t['asterisk'] = 389;
  13301. t['plus'] = 584;
  13302. t['comma'] = 278;
  13303. t['hyphen'] = 333;
  13304. t['period'] = 278;
  13305. t['slash'] = 278;
  13306. t['zero'] = 556;
  13307. t['one'] = 556;
  13308. t['two'] = 556;
  13309. t['three'] = 556;
  13310. t['four'] = 556;
  13311. t['five'] = 556;
  13312. t['six'] = 556;
  13313. t['seven'] = 556;
  13314. t['eight'] = 556;
  13315. t['nine'] = 556;
  13316. t['colon'] = 278;
  13317. t['semicolon'] = 278;
  13318. t['less'] = 584;
  13319. t['equal'] = 584;
  13320. t['greater'] = 584;
  13321. t['question'] = 556;
  13322. t['at'] = 1015;
  13323. t['A'] = 667;
  13324. t['B'] = 667;
  13325. t['C'] = 722;
  13326. t['D'] = 722;
  13327. t['E'] = 667;
  13328. t['F'] = 611;
  13329. t['G'] = 778;
  13330. t['H'] = 722;
  13331. t['I'] = 278;
  13332. t['J'] = 500;
  13333. t['K'] = 667;
  13334. t['L'] = 556;
  13335. t['M'] = 833;
  13336. t['N'] = 722;
  13337. t['O'] = 778;
  13338. t['P'] = 667;
  13339. t['Q'] = 778;
  13340. t['R'] = 722;
  13341. t['S'] = 667;
  13342. t['T'] = 611;
  13343. t['U'] = 722;
  13344. t['V'] = 667;
  13345. t['W'] = 944;
  13346. t['X'] = 667;
  13347. t['Y'] = 667;
  13348. t['Z'] = 611;
  13349. t['bracketleft'] = 278;
  13350. t['backslash'] = 278;
  13351. t['bracketright'] = 278;
  13352. t['asciicircum'] = 469;
  13353. t['underscore'] = 556;
  13354. t['quoteleft'] = 222;
  13355. t['a'] = 556;
  13356. t['b'] = 556;
  13357. t['c'] = 500;
  13358. t['d'] = 556;
  13359. t['e'] = 556;
  13360. t['f'] = 278;
  13361. t['g'] = 556;
  13362. t['h'] = 556;
  13363. t['i'] = 222;
  13364. t['j'] = 222;
  13365. t['k'] = 500;
  13366. t['l'] = 222;
  13367. t['m'] = 833;
  13368. t['n'] = 556;
  13369. t['o'] = 556;
  13370. t['p'] = 556;
  13371. t['q'] = 556;
  13372. t['r'] = 333;
  13373. t['s'] = 500;
  13374. t['t'] = 278;
  13375. t['u'] = 556;
  13376. t['v'] = 500;
  13377. t['w'] = 722;
  13378. t['x'] = 500;
  13379. t['y'] = 500;
  13380. t['z'] = 500;
  13381. t['braceleft'] = 334;
  13382. t['bar'] = 260;
  13383. t['braceright'] = 334;
  13384. t['asciitilde'] = 584;
  13385. t['exclamdown'] = 333;
  13386. t['cent'] = 556;
  13387. t['sterling'] = 556;
  13388. t['fraction'] = 167;
  13389. t['yen'] = 556;
  13390. t['florin'] = 556;
  13391. t['section'] = 556;
  13392. t['currency'] = 556;
  13393. t['quotesingle'] = 191;
  13394. t['quotedblleft'] = 333;
  13395. t['guillemotleft'] = 556;
  13396. t['guilsinglleft'] = 333;
  13397. t['guilsinglright'] = 333;
  13398. t['fi'] = 500;
  13399. t['fl'] = 500;
  13400. t['endash'] = 556;
  13401. t['dagger'] = 556;
  13402. t['daggerdbl'] = 556;
  13403. t['periodcentered'] = 278;
  13404. t['paragraph'] = 537;
  13405. t['bullet'] = 350;
  13406. t['quotesinglbase'] = 222;
  13407. t['quotedblbase'] = 333;
  13408. t['quotedblright'] = 333;
  13409. t['guillemotright'] = 556;
  13410. t['ellipsis'] = 1000;
  13411. t['perthousand'] = 1000;
  13412. t['questiondown'] = 611;
  13413. t['grave'] = 333;
  13414. t['acute'] = 333;
  13415. t['circumflex'] = 333;
  13416. t['tilde'] = 333;
  13417. t['macron'] = 333;
  13418. t['breve'] = 333;
  13419. t['dotaccent'] = 333;
  13420. t['dieresis'] = 333;
  13421. t['ring'] = 333;
  13422. t['cedilla'] = 333;
  13423. t['hungarumlaut'] = 333;
  13424. t['ogonek'] = 333;
  13425. t['caron'] = 333;
  13426. t['emdash'] = 1000;
  13427. t['AE'] = 1000;
  13428. t['ordfeminine'] = 370;
  13429. t['Lslash'] = 556;
  13430. t['Oslash'] = 778;
  13431. t['OE'] = 1000;
  13432. t['ordmasculine'] = 365;
  13433. t['ae'] = 889;
  13434. t['dotlessi'] = 278;
  13435. t['lslash'] = 222;
  13436. t['oslash'] = 611;
  13437. t['oe'] = 944;
  13438. t['germandbls'] = 611;
  13439. t['Idieresis'] = 278;
  13440. t['eacute'] = 556;
  13441. t['abreve'] = 556;
  13442. t['uhungarumlaut'] = 556;
  13443. t['ecaron'] = 556;
  13444. t['Ydieresis'] = 667;
  13445. t['divide'] = 584;
  13446. t['Yacute'] = 667;
  13447. t['Acircumflex'] = 667;
  13448. t['aacute'] = 556;
  13449. t['Ucircumflex'] = 722;
  13450. t['yacute'] = 500;
  13451. t['scommaaccent'] = 500;
  13452. t['ecircumflex'] = 556;
  13453. t['Uring'] = 722;
  13454. t['Udieresis'] = 722;
  13455. t['aogonek'] = 556;
  13456. t['Uacute'] = 722;
  13457. t['uogonek'] = 556;
  13458. t['Edieresis'] = 667;
  13459. t['Dcroat'] = 722;
  13460. t['commaaccent'] = 250;
  13461. t['copyright'] = 737;
  13462. t['Emacron'] = 667;
  13463. t['ccaron'] = 500;
  13464. t['aring'] = 556;
  13465. t['Ncommaaccent'] = 722;
  13466. t['lacute'] = 222;
  13467. t['agrave'] = 556;
  13468. t['Tcommaaccent'] = 611;
  13469. t['Cacute'] = 722;
  13470. t['atilde'] = 556;
  13471. t['Edotaccent'] = 667;
  13472. t['scaron'] = 500;
  13473. t['scedilla'] = 500;
  13474. t['iacute'] = 278;
  13475. t['lozenge'] = 471;
  13476. t['Rcaron'] = 722;
  13477. t['Gcommaaccent'] = 778;
  13478. t['ucircumflex'] = 556;
  13479. t['acircumflex'] = 556;
  13480. t['Amacron'] = 667;
  13481. t['rcaron'] = 333;
  13482. t['ccedilla'] = 500;
  13483. t['Zdotaccent'] = 611;
  13484. t['Thorn'] = 667;
  13485. t['Omacron'] = 778;
  13486. t['Racute'] = 722;
  13487. t['Sacute'] = 667;
  13488. t['dcaron'] = 643;
  13489. t['Umacron'] = 722;
  13490. t['uring'] = 556;
  13491. t['threesuperior'] = 333;
  13492. t['Ograve'] = 778;
  13493. t['Agrave'] = 667;
  13494. t['Abreve'] = 667;
  13495. t['multiply'] = 584;
  13496. t['uacute'] = 556;
  13497. t['Tcaron'] = 611;
  13498. t['partialdiff'] = 476;
  13499. t['ydieresis'] = 500;
  13500. t['Nacute'] = 722;
  13501. t['icircumflex'] = 278;
  13502. t['Ecircumflex'] = 667;
  13503. t['adieresis'] = 556;
  13504. t['edieresis'] = 556;
  13505. t['cacute'] = 500;
  13506. t['nacute'] = 556;
  13507. t['umacron'] = 556;
  13508. t['Ncaron'] = 722;
  13509. t['Iacute'] = 278;
  13510. t['plusminus'] = 584;
  13511. t['brokenbar'] = 260;
  13512. t['registered'] = 737;
  13513. t['Gbreve'] = 778;
  13514. t['Idotaccent'] = 278;
  13515. t['summation'] = 600;
  13516. t['Egrave'] = 667;
  13517. t['racute'] = 333;
  13518. t['omacron'] = 556;
  13519. t['Zacute'] = 611;
  13520. t['Zcaron'] = 611;
  13521. t['greaterequal'] = 549;
  13522. t['Eth'] = 722;
  13523. t['Ccedilla'] = 722;
  13524. t['lcommaaccent'] = 222;
  13525. t['tcaron'] = 317;
  13526. t['eogonek'] = 556;
  13527. t['Uogonek'] = 722;
  13528. t['Aacute'] = 667;
  13529. t['Adieresis'] = 667;
  13530. t['egrave'] = 556;
  13531. t['zacute'] = 500;
  13532. t['iogonek'] = 222;
  13533. t['Oacute'] = 778;
  13534. t['oacute'] = 556;
  13535. t['amacron'] = 556;
  13536. t['sacute'] = 500;
  13537. t['idieresis'] = 278;
  13538. t['Ocircumflex'] = 778;
  13539. t['Ugrave'] = 722;
  13540. t['Delta'] = 612;
  13541. t['thorn'] = 556;
  13542. t['twosuperior'] = 333;
  13543. t['Odieresis'] = 778;
  13544. t['mu'] = 556;
  13545. t['igrave'] = 278;
  13546. t['ohungarumlaut'] = 556;
  13547. t['Eogonek'] = 667;
  13548. t['dcroat'] = 556;
  13549. t['threequarters'] = 834;
  13550. t['Scedilla'] = 667;
  13551. t['lcaron'] = 299;
  13552. t['Kcommaaccent'] = 667;
  13553. t['Lacute'] = 556;
  13554. t['trademark'] = 1000;
  13555. t['edotaccent'] = 556;
  13556. t['Igrave'] = 278;
  13557. t['Imacron'] = 278;
  13558. t['Lcaron'] = 556;
  13559. t['onehalf'] = 834;
  13560. t['lessequal'] = 549;
  13561. t['ocircumflex'] = 556;
  13562. t['ntilde'] = 556;
  13563. t['Uhungarumlaut'] = 722;
  13564. t['Eacute'] = 667;
  13565. t['emacron'] = 556;
  13566. t['gbreve'] = 556;
  13567. t['onequarter'] = 834;
  13568. t['Scaron'] = 667;
  13569. t['Scommaaccent'] = 667;
  13570. t['Ohungarumlaut'] = 778;
  13571. t['degree'] = 400;
  13572. t['ograve'] = 556;
  13573. t['Ccaron'] = 722;
  13574. t['ugrave'] = 556;
  13575. t['radical'] = 453;
  13576. t['Dcaron'] = 722;
  13577. t['rcommaaccent'] = 333;
  13578. t['Ntilde'] = 722;
  13579. t['otilde'] = 556;
  13580. t['Rcommaaccent'] = 722;
  13581. t['Lcommaaccent'] = 556;
  13582. t['Atilde'] = 667;
  13583. t['Aogonek'] = 667;
  13584. t['Aring'] = 667;
  13585. t['Otilde'] = 778;
  13586. t['zdotaccent'] = 500;
  13587. t['Ecaron'] = 667;
  13588. t['Iogonek'] = 278;
  13589. t['kcommaaccent'] = 500;
  13590. t['minus'] = 584;
  13591. t['Icircumflex'] = 278;
  13592. t['ncaron'] = 556;
  13593. t['tcommaaccent'] = 278;
  13594. t['logicalnot'] = 584;
  13595. t['odieresis'] = 556;
  13596. t['udieresis'] = 556;
  13597. t['notequal'] = 549;
  13598. t['gcommaaccent'] = 556;
  13599. t['eth'] = 556;
  13600. t['zcaron'] = 500;
  13601. t['ncommaaccent'] = 556;
  13602. t['onesuperior'] = 333;
  13603. t['imacron'] = 278;
  13604. t['Euro'] = 556;
  13605. });
  13606. t['Symbol'] = getLookupTableFactory(function (t) {
  13607. t['space'] = 250;
  13608. t['exclam'] = 333;
  13609. t['universal'] = 713;
  13610. t['numbersign'] = 500;
  13611. t['existential'] = 549;
  13612. t['percent'] = 833;
  13613. t['ampersand'] = 778;
  13614. t['suchthat'] = 439;
  13615. t['parenleft'] = 333;
  13616. t['parenright'] = 333;
  13617. t['asteriskmath'] = 500;
  13618. t['plus'] = 549;
  13619. t['comma'] = 250;
  13620. t['minus'] = 549;
  13621. t['period'] = 250;
  13622. t['slash'] = 278;
  13623. t['zero'] = 500;
  13624. t['one'] = 500;
  13625. t['two'] = 500;
  13626. t['three'] = 500;
  13627. t['four'] = 500;
  13628. t['five'] = 500;
  13629. t['six'] = 500;
  13630. t['seven'] = 500;
  13631. t['eight'] = 500;
  13632. t['nine'] = 500;
  13633. t['colon'] = 278;
  13634. t['semicolon'] = 278;
  13635. t['less'] = 549;
  13636. t['equal'] = 549;
  13637. t['greater'] = 549;
  13638. t['question'] = 444;
  13639. t['congruent'] = 549;
  13640. t['Alpha'] = 722;
  13641. t['Beta'] = 667;
  13642. t['Chi'] = 722;
  13643. t['Delta'] = 612;
  13644. t['Epsilon'] = 611;
  13645. t['Phi'] = 763;
  13646. t['Gamma'] = 603;
  13647. t['Eta'] = 722;
  13648. t['Iota'] = 333;
  13649. t['theta1'] = 631;
  13650. t['Kappa'] = 722;
  13651. t['Lambda'] = 686;
  13652. t['Mu'] = 889;
  13653. t['Nu'] = 722;
  13654. t['Omicron'] = 722;
  13655. t['Pi'] = 768;
  13656. t['Theta'] = 741;
  13657. t['Rho'] = 556;
  13658. t['Sigma'] = 592;
  13659. t['Tau'] = 611;
  13660. t['Upsilon'] = 690;
  13661. t['sigma1'] = 439;
  13662. t['Omega'] = 768;
  13663. t['Xi'] = 645;
  13664. t['Psi'] = 795;
  13665. t['Zeta'] = 611;
  13666. t['bracketleft'] = 333;
  13667. t['therefore'] = 863;
  13668. t['bracketright'] = 333;
  13669. t['perpendicular'] = 658;
  13670. t['underscore'] = 500;
  13671. t['radicalex'] = 500;
  13672. t['alpha'] = 631;
  13673. t['beta'] = 549;
  13674. t['chi'] = 549;
  13675. t['delta'] = 494;
  13676. t['epsilon'] = 439;
  13677. t['phi'] = 521;
  13678. t['gamma'] = 411;
  13679. t['eta'] = 603;
  13680. t['iota'] = 329;
  13681. t['phi1'] = 603;
  13682. t['kappa'] = 549;
  13683. t['lambda'] = 549;
  13684. t['mu'] = 576;
  13685. t['nu'] = 521;
  13686. t['omicron'] = 549;
  13687. t['pi'] = 549;
  13688. t['theta'] = 521;
  13689. t['rho'] = 549;
  13690. t['sigma'] = 603;
  13691. t['tau'] = 439;
  13692. t['upsilon'] = 576;
  13693. t['omega1'] = 713;
  13694. t['omega'] = 686;
  13695. t['xi'] = 493;
  13696. t['psi'] = 686;
  13697. t['zeta'] = 494;
  13698. t['braceleft'] = 480;
  13699. t['bar'] = 200;
  13700. t['braceright'] = 480;
  13701. t['similar'] = 549;
  13702. t['Euro'] = 750;
  13703. t['Upsilon1'] = 620;
  13704. t['minute'] = 247;
  13705. t['lessequal'] = 549;
  13706. t['fraction'] = 167;
  13707. t['infinity'] = 713;
  13708. t['florin'] = 500;
  13709. t['club'] = 753;
  13710. t['diamond'] = 753;
  13711. t['heart'] = 753;
  13712. t['spade'] = 753;
  13713. t['arrowboth'] = 1042;
  13714. t['arrowleft'] = 987;
  13715. t['arrowup'] = 603;
  13716. t['arrowright'] = 987;
  13717. t['arrowdown'] = 603;
  13718. t['degree'] = 400;
  13719. t['plusminus'] = 549;
  13720. t['second'] = 411;
  13721. t['greaterequal'] = 549;
  13722. t['multiply'] = 549;
  13723. t['proportional'] = 713;
  13724. t['partialdiff'] = 494;
  13725. t['bullet'] = 460;
  13726. t['divide'] = 549;
  13727. t['notequal'] = 549;
  13728. t['equivalence'] = 549;
  13729. t['approxequal'] = 549;
  13730. t['ellipsis'] = 1000;
  13731. t['arrowvertex'] = 603;
  13732. t['arrowhorizex'] = 1000;
  13733. t['carriagereturn'] = 658;
  13734. t['aleph'] = 823;
  13735. t['Ifraktur'] = 686;
  13736. t['Rfraktur'] = 795;
  13737. t['weierstrass'] = 987;
  13738. t['circlemultiply'] = 768;
  13739. t['circleplus'] = 768;
  13740. t['emptyset'] = 823;
  13741. t['intersection'] = 768;
  13742. t['union'] = 768;
  13743. t['propersuperset'] = 713;
  13744. t['reflexsuperset'] = 713;
  13745. t['notsubset'] = 713;
  13746. t['propersubset'] = 713;
  13747. t['reflexsubset'] = 713;
  13748. t['element'] = 713;
  13749. t['notelement'] = 713;
  13750. t['angle'] = 768;
  13751. t['gradient'] = 713;
  13752. t['registerserif'] = 790;
  13753. t['copyrightserif'] = 790;
  13754. t['trademarkserif'] = 890;
  13755. t['product'] = 823;
  13756. t['radical'] = 549;
  13757. t['dotmath'] = 250;
  13758. t['logicalnot'] = 713;
  13759. t['logicaland'] = 603;
  13760. t['logicalor'] = 603;
  13761. t['arrowdblboth'] = 1042;
  13762. t['arrowdblleft'] = 987;
  13763. t['arrowdblup'] = 603;
  13764. t['arrowdblright'] = 987;
  13765. t['arrowdbldown'] = 603;
  13766. t['lozenge'] = 494;
  13767. t['angleleft'] = 329;
  13768. t['registersans'] = 790;
  13769. t['copyrightsans'] = 790;
  13770. t['trademarksans'] = 786;
  13771. t['summation'] = 713;
  13772. t['parenlefttp'] = 384;
  13773. t['parenleftex'] = 384;
  13774. t['parenleftbt'] = 384;
  13775. t['bracketlefttp'] = 384;
  13776. t['bracketleftex'] = 384;
  13777. t['bracketleftbt'] = 384;
  13778. t['bracelefttp'] = 494;
  13779. t['braceleftmid'] = 494;
  13780. t['braceleftbt'] = 494;
  13781. t['braceex'] = 494;
  13782. t['angleright'] = 329;
  13783. t['integral'] = 274;
  13784. t['integraltp'] = 686;
  13785. t['integralex'] = 686;
  13786. t['integralbt'] = 686;
  13787. t['parenrighttp'] = 384;
  13788. t['parenrightex'] = 384;
  13789. t['parenrightbt'] = 384;
  13790. t['bracketrighttp'] = 384;
  13791. t['bracketrightex'] = 384;
  13792. t['bracketrightbt'] = 384;
  13793. t['bracerighttp'] = 494;
  13794. t['bracerightmid'] = 494;
  13795. t['bracerightbt'] = 494;
  13796. t['apple'] = 790;
  13797. });
  13798. t['Times-Roman'] = getLookupTableFactory(function (t) {
  13799. t['space'] = 250;
  13800. t['exclam'] = 333;
  13801. t['quotedbl'] = 408;
  13802. t['numbersign'] = 500;
  13803. t['dollar'] = 500;
  13804. t['percent'] = 833;
  13805. t['ampersand'] = 778;
  13806. t['quoteright'] = 333;
  13807. t['parenleft'] = 333;
  13808. t['parenright'] = 333;
  13809. t['asterisk'] = 500;
  13810. t['plus'] = 564;
  13811. t['comma'] = 250;
  13812. t['hyphen'] = 333;
  13813. t['period'] = 250;
  13814. t['slash'] = 278;
  13815. t['zero'] = 500;
  13816. t['one'] = 500;
  13817. t['two'] = 500;
  13818. t['three'] = 500;
  13819. t['four'] = 500;
  13820. t['five'] = 500;
  13821. t['six'] = 500;
  13822. t['seven'] = 500;
  13823. t['eight'] = 500;
  13824. t['nine'] = 500;
  13825. t['colon'] = 278;
  13826. t['semicolon'] = 278;
  13827. t['less'] = 564;
  13828. t['equal'] = 564;
  13829. t['greater'] = 564;
  13830. t['question'] = 444;
  13831. t['at'] = 921;
  13832. t['A'] = 722;
  13833. t['B'] = 667;
  13834. t['C'] = 667;
  13835. t['D'] = 722;
  13836. t['E'] = 611;
  13837. t['F'] = 556;
  13838. t['G'] = 722;
  13839. t['H'] = 722;
  13840. t['I'] = 333;
  13841. t['J'] = 389;
  13842. t['K'] = 722;
  13843. t['L'] = 611;
  13844. t['M'] = 889;
  13845. t['N'] = 722;
  13846. t['O'] = 722;
  13847. t['P'] = 556;
  13848. t['Q'] = 722;
  13849. t['R'] = 667;
  13850. t['S'] = 556;
  13851. t['T'] = 611;
  13852. t['U'] = 722;
  13853. t['V'] = 722;
  13854. t['W'] = 944;
  13855. t['X'] = 722;
  13856. t['Y'] = 722;
  13857. t['Z'] = 611;
  13858. t['bracketleft'] = 333;
  13859. t['backslash'] = 278;
  13860. t['bracketright'] = 333;
  13861. t['asciicircum'] = 469;
  13862. t['underscore'] = 500;
  13863. t['quoteleft'] = 333;
  13864. t['a'] = 444;
  13865. t['b'] = 500;
  13866. t['c'] = 444;
  13867. t['d'] = 500;
  13868. t['e'] = 444;
  13869. t['f'] = 333;
  13870. t['g'] = 500;
  13871. t['h'] = 500;
  13872. t['i'] = 278;
  13873. t['j'] = 278;
  13874. t['k'] = 500;
  13875. t['l'] = 278;
  13876. t['m'] = 778;
  13877. t['n'] = 500;
  13878. t['o'] = 500;
  13879. t['p'] = 500;
  13880. t['q'] = 500;
  13881. t['r'] = 333;
  13882. t['s'] = 389;
  13883. t['t'] = 278;
  13884. t['u'] = 500;
  13885. t['v'] = 500;
  13886. t['w'] = 722;
  13887. t['x'] = 500;
  13888. t['y'] = 500;
  13889. t['z'] = 444;
  13890. t['braceleft'] = 480;
  13891. t['bar'] = 200;
  13892. t['braceright'] = 480;
  13893. t['asciitilde'] = 541;
  13894. t['exclamdown'] = 333;
  13895. t['cent'] = 500;
  13896. t['sterling'] = 500;
  13897. t['fraction'] = 167;
  13898. t['yen'] = 500;
  13899. t['florin'] = 500;
  13900. t['section'] = 500;
  13901. t['currency'] = 500;
  13902. t['quotesingle'] = 180;
  13903. t['quotedblleft'] = 444;
  13904. t['guillemotleft'] = 500;
  13905. t['guilsinglleft'] = 333;
  13906. t['guilsinglright'] = 333;
  13907. t['fi'] = 556;
  13908. t['fl'] = 556;
  13909. t['endash'] = 500;
  13910. t['dagger'] = 500;
  13911. t['daggerdbl'] = 500;
  13912. t['periodcentered'] = 250;
  13913. t['paragraph'] = 453;
  13914. t['bullet'] = 350;
  13915. t['quotesinglbase'] = 333;
  13916. t['quotedblbase'] = 444;
  13917. t['quotedblright'] = 444;
  13918. t['guillemotright'] = 500;
  13919. t['ellipsis'] = 1000;
  13920. t['perthousand'] = 1000;
  13921. t['questiondown'] = 444;
  13922. t['grave'] = 333;
  13923. t['acute'] = 333;
  13924. t['circumflex'] = 333;
  13925. t['tilde'] = 333;
  13926. t['macron'] = 333;
  13927. t['breve'] = 333;
  13928. t['dotaccent'] = 333;
  13929. t['dieresis'] = 333;
  13930. t['ring'] = 333;
  13931. t['cedilla'] = 333;
  13932. t['hungarumlaut'] = 333;
  13933. t['ogonek'] = 333;
  13934. t['caron'] = 333;
  13935. t['emdash'] = 1000;
  13936. t['AE'] = 889;
  13937. t['ordfeminine'] = 276;
  13938. t['Lslash'] = 611;
  13939. t['Oslash'] = 722;
  13940. t['OE'] = 889;
  13941. t['ordmasculine'] = 310;
  13942. t['ae'] = 667;
  13943. t['dotlessi'] = 278;
  13944. t['lslash'] = 278;
  13945. t['oslash'] = 500;
  13946. t['oe'] = 722;
  13947. t['germandbls'] = 500;
  13948. t['Idieresis'] = 333;
  13949. t['eacute'] = 444;
  13950. t['abreve'] = 444;
  13951. t['uhungarumlaut'] = 500;
  13952. t['ecaron'] = 444;
  13953. t['Ydieresis'] = 722;
  13954. t['divide'] = 564;
  13955. t['Yacute'] = 722;
  13956. t['Acircumflex'] = 722;
  13957. t['aacute'] = 444;
  13958. t['Ucircumflex'] = 722;
  13959. t['yacute'] = 500;
  13960. t['scommaaccent'] = 389;
  13961. t['ecircumflex'] = 444;
  13962. t['Uring'] = 722;
  13963. t['Udieresis'] = 722;
  13964. t['aogonek'] = 444;
  13965. t['Uacute'] = 722;
  13966. t['uogonek'] = 500;
  13967. t['Edieresis'] = 611;
  13968. t['Dcroat'] = 722;
  13969. t['commaaccent'] = 250;
  13970. t['copyright'] = 760;
  13971. t['Emacron'] = 611;
  13972. t['ccaron'] = 444;
  13973. t['aring'] = 444;
  13974. t['Ncommaaccent'] = 722;
  13975. t['lacute'] = 278;
  13976. t['agrave'] = 444;
  13977. t['Tcommaaccent'] = 611;
  13978. t['Cacute'] = 667;
  13979. t['atilde'] = 444;
  13980. t['Edotaccent'] = 611;
  13981. t['scaron'] = 389;
  13982. t['scedilla'] = 389;
  13983. t['iacute'] = 278;
  13984. t['lozenge'] = 471;
  13985. t['Rcaron'] = 667;
  13986. t['Gcommaaccent'] = 722;
  13987. t['ucircumflex'] = 500;
  13988. t['acircumflex'] = 444;
  13989. t['Amacron'] = 722;
  13990. t['rcaron'] = 333;
  13991. t['ccedilla'] = 444;
  13992. t['Zdotaccent'] = 611;
  13993. t['Thorn'] = 556;
  13994. t['Omacron'] = 722;
  13995. t['Racute'] = 667;
  13996. t['Sacute'] = 556;
  13997. t['dcaron'] = 588;
  13998. t['Umacron'] = 722;
  13999. t['uring'] = 500;
  14000. t['threesuperior'] = 300;
  14001. t['Ograve'] = 722;
  14002. t['Agrave'] = 722;
  14003. t['Abreve'] = 722;
  14004. t['multiply'] = 564;
  14005. t['uacute'] = 500;
  14006. t['Tcaron'] = 611;
  14007. t['partialdiff'] = 476;
  14008. t['ydieresis'] = 500;
  14009. t['Nacute'] = 722;
  14010. t['icircumflex'] = 278;
  14011. t['Ecircumflex'] = 611;
  14012. t['adieresis'] = 444;
  14013. t['edieresis'] = 444;
  14014. t['cacute'] = 444;
  14015. t['nacute'] = 500;
  14016. t['umacron'] = 500;
  14017. t['Ncaron'] = 722;
  14018. t['Iacute'] = 333;
  14019. t['plusminus'] = 564;
  14020. t['brokenbar'] = 200;
  14021. t['registered'] = 760;
  14022. t['Gbreve'] = 722;
  14023. t['Idotaccent'] = 333;
  14024. t['summation'] = 600;
  14025. t['Egrave'] = 611;
  14026. t['racute'] = 333;
  14027. t['omacron'] = 500;
  14028. t['Zacute'] = 611;
  14029. t['Zcaron'] = 611;
  14030. t['greaterequal'] = 549;
  14031. t['Eth'] = 722;
  14032. t['Ccedilla'] = 667;
  14033. t['lcommaaccent'] = 278;
  14034. t['tcaron'] = 326;
  14035. t['eogonek'] = 444;
  14036. t['Uogonek'] = 722;
  14037. t['Aacute'] = 722;
  14038. t['Adieresis'] = 722;
  14039. t['egrave'] = 444;
  14040. t['zacute'] = 444;
  14041. t['iogonek'] = 278;
  14042. t['Oacute'] = 722;
  14043. t['oacute'] = 500;
  14044. t['amacron'] = 444;
  14045. t['sacute'] = 389;
  14046. t['idieresis'] = 278;
  14047. t['Ocircumflex'] = 722;
  14048. t['Ugrave'] = 722;
  14049. t['Delta'] = 612;
  14050. t['thorn'] = 500;
  14051. t['twosuperior'] = 300;
  14052. t['Odieresis'] = 722;
  14053. t['mu'] = 500;
  14054. t['igrave'] = 278;
  14055. t['ohungarumlaut'] = 500;
  14056. t['Eogonek'] = 611;
  14057. t['dcroat'] = 500;
  14058. t['threequarters'] = 750;
  14059. t['Scedilla'] = 556;
  14060. t['lcaron'] = 344;
  14061. t['Kcommaaccent'] = 722;
  14062. t['Lacute'] = 611;
  14063. t['trademark'] = 980;
  14064. t['edotaccent'] = 444;
  14065. t['Igrave'] = 333;
  14066. t['Imacron'] = 333;
  14067. t['Lcaron'] = 611;
  14068. t['onehalf'] = 750;
  14069. t['lessequal'] = 549;
  14070. t['ocircumflex'] = 500;
  14071. t['ntilde'] = 500;
  14072. t['Uhungarumlaut'] = 722;
  14073. t['Eacute'] = 611;
  14074. t['emacron'] = 444;
  14075. t['gbreve'] = 500;
  14076. t['onequarter'] = 750;
  14077. t['Scaron'] = 556;
  14078. t['Scommaaccent'] = 556;
  14079. t['Ohungarumlaut'] = 722;
  14080. t['degree'] = 400;
  14081. t['ograve'] = 500;
  14082. t['Ccaron'] = 667;
  14083. t['ugrave'] = 500;
  14084. t['radical'] = 453;
  14085. t['Dcaron'] = 722;
  14086. t['rcommaaccent'] = 333;
  14087. t['Ntilde'] = 722;
  14088. t['otilde'] = 500;
  14089. t['Rcommaaccent'] = 667;
  14090. t['Lcommaaccent'] = 611;
  14091. t['Atilde'] = 722;
  14092. t['Aogonek'] = 722;
  14093. t['Aring'] = 722;
  14094. t['Otilde'] = 722;
  14095. t['zdotaccent'] = 444;
  14096. t['Ecaron'] = 611;
  14097. t['Iogonek'] = 333;
  14098. t['kcommaaccent'] = 500;
  14099. t['minus'] = 564;
  14100. t['Icircumflex'] = 333;
  14101. t['ncaron'] = 500;
  14102. t['tcommaaccent'] = 278;
  14103. t['logicalnot'] = 564;
  14104. t['odieresis'] = 500;
  14105. t['udieresis'] = 500;
  14106. t['notequal'] = 549;
  14107. t['gcommaaccent'] = 500;
  14108. t['eth'] = 500;
  14109. t['zcaron'] = 444;
  14110. t['ncommaaccent'] = 500;
  14111. t['onesuperior'] = 300;
  14112. t['imacron'] = 278;
  14113. t['Euro'] = 500;
  14114. });
  14115. t['Times-Bold'] = getLookupTableFactory(function (t) {
  14116. t['space'] = 250;
  14117. t['exclam'] = 333;
  14118. t['quotedbl'] = 555;
  14119. t['numbersign'] = 500;
  14120. t['dollar'] = 500;
  14121. t['percent'] = 1000;
  14122. t['ampersand'] = 833;
  14123. t['quoteright'] = 333;
  14124. t['parenleft'] = 333;
  14125. t['parenright'] = 333;
  14126. t['asterisk'] = 500;
  14127. t['plus'] = 570;
  14128. t['comma'] = 250;
  14129. t['hyphen'] = 333;
  14130. t['period'] = 250;
  14131. t['slash'] = 278;
  14132. t['zero'] = 500;
  14133. t['one'] = 500;
  14134. t['two'] = 500;
  14135. t['three'] = 500;
  14136. t['four'] = 500;
  14137. t['five'] = 500;
  14138. t['six'] = 500;
  14139. t['seven'] = 500;
  14140. t['eight'] = 500;
  14141. t['nine'] = 500;
  14142. t['colon'] = 333;
  14143. t['semicolon'] = 333;
  14144. t['less'] = 570;
  14145. t['equal'] = 570;
  14146. t['greater'] = 570;
  14147. t['question'] = 500;
  14148. t['at'] = 930;
  14149. t['A'] = 722;
  14150. t['B'] = 667;
  14151. t['C'] = 722;
  14152. t['D'] = 722;
  14153. t['E'] = 667;
  14154. t['F'] = 611;
  14155. t['G'] = 778;
  14156. t['H'] = 778;
  14157. t['I'] = 389;
  14158. t['J'] = 500;
  14159. t['K'] = 778;
  14160. t['L'] = 667;
  14161. t['M'] = 944;
  14162. t['N'] = 722;
  14163. t['O'] = 778;
  14164. t['P'] = 611;
  14165. t['Q'] = 778;
  14166. t['R'] = 722;
  14167. t['S'] = 556;
  14168. t['T'] = 667;
  14169. t['U'] = 722;
  14170. t['V'] = 722;
  14171. t['W'] = 1000;
  14172. t['X'] = 722;
  14173. t['Y'] = 722;
  14174. t['Z'] = 667;
  14175. t['bracketleft'] = 333;
  14176. t['backslash'] = 278;
  14177. t['bracketright'] = 333;
  14178. t['asciicircum'] = 581;
  14179. t['underscore'] = 500;
  14180. t['quoteleft'] = 333;
  14181. t['a'] = 500;
  14182. t['b'] = 556;
  14183. t['c'] = 444;
  14184. t['d'] = 556;
  14185. t['e'] = 444;
  14186. t['f'] = 333;
  14187. t['g'] = 500;
  14188. t['h'] = 556;
  14189. t['i'] = 278;
  14190. t['j'] = 333;
  14191. t['k'] = 556;
  14192. t['l'] = 278;
  14193. t['m'] = 833;
  14194. t['n'] = 556;
  14195. t['o'] = 500;
  14196. t['p'] = 556;
  14197. t['q'] = 556;
  14198. t['r'] = 444;
  14199. t['s'] = 389;
  14200. t['t'] = 333;
  14201. t['u'] = 556;
  14202. t['v'] = 500;
  14203. t['w'] = 722;
  14204. t['x'] = 500;
  14205. t['y'] = 500;
  14206. t['z'] = 444;
  14207. t['braceleft'] = 394;
  14208. t['bar'] = 220;
  14209. t['braceright'] = 394;
  14210. t['asciitilde'] = 520;
  14211. t['exclamdown'] = 333;
  14212. t['cent'] = 500;
  14213. t['sterling'] = 500;
  14214. t['fraction'] = 167;
  14215. t['yen'] = 500;
  14216. t['florin'] = 500;
  14217. t['section'] = 500;
  14218. t['currency'] = 500;
  14219. t['quotesingle'] = 278;
  14220. t['quotedblleft'] = 500;
  14221. t['guillemotleft'] = 500;
  14222. t['guilsinglleft'] = 333;
  14223. t['guilsinglright'] = 333;
  14224. t['fi'] = 556;
  14225. t['fl'] = 556;
  14226. t['endash'] = 500;
  14227. t['dagger'] = 500;
  14228. t['daggerdbl'] = 500;
  14229. t['periodcentered'] = 250;
  14230. t['paragraph'] = 540;
  14231. t['bullet'] = 350;
  14232. t['quotesinglbase'] = 333;
  14233. t['quotedblbase'] = 500;
  14234. t['quotedblright'] = 500;
  14235. t['guillemotright'] = 500;
  14236. t['ellipsis'] = 1000;
  14237. t['perthousand'] = 1000;
  14238. t['questiondown'] = 500;
  14239. t['grave'] = 333;
  14240. t['acute'] = 333;
  14241. t['circumflex'] = 333;
  14242. t['tilde'] = 333;
  14243. t['macron'] = 333;
  14244. t['breve'] = 333;
  14245. t['dotaccent'] = 333;
  14246. t['dieresis'] = 333;
  14247. t['ring'] = 333;
  14248. t['cedilla'] = 333;
  14249. t['hungarumlaut'] = 333;
  14250. t['ogonek'] = 333;
  14251. t['caron'] = 333;
  14252. t['emdash'] = 1000;
  14253. t['AE'] = 1000;
  14254. t['ordfeminine'] = 300;
  14255. t['Lslash'] = 667;
  14256. t['Oslash'] = 778;
  14257. t['OE'] = 1000;
  14258. t['ordmasculine'] = 330;
  14259. t['ae'] = 722;
  14260. t['dotlessi'] = 278;
  14261. t['lslash'] = 278;
  14262. t['oslash'] = 500;
  14263. t['oe'] = 722;
  14264. t['germandbls'] = 556;
  14265. t['Idieresis'] = 389;
  14266. t['eacute'] = 444;
  14267. t['abreve'] = 500;
  14268. t['uhungarumlaut'] = 556;
  14269. t['ecaron'] = 444;
  14270. t['Ydieresis'] = 722;
  14271. t['divide'] = 570;
  14272. t['Yacute'] = 722;
  14273. t['Acircumflex'] = 722;
  14274. t['aacute'] = 500;
  14275. t['Ucircumflex'] = 722;
  14276. t['yacute'] = 500;
  14277. t['scommaaccent'] = 389;
  14278. t['ecircumflex'] = 444;
  14279. t['Uring'] = 722;
  14280. t['Udieresis'] = 722;
  14281. t['aogonek'] = 500;
  14282. t['Uacute'] = 722;
  14283. t['uogonek'] = 556;
  14284. t['Edieresis'] = 667;
  14285. t['Dcroat'] = 722;
  14286. t['commaaccent'] = 250;
  14287. t['copyright'] = 747;
  14288. t['Emacron'] = 667;
  14289. t['ccaron'] = 444;
  14290. t['aring'] = 500;
  14291. t['Ncommaaccent'] = 722;
  14292. t['lacute'] = 278;
  14293. t['agrave'] = 500;
  14294. t['Tcommaaccent'] = 667;
  14295. t['Cacute'] = 722;
  14296. t['atilde'] = 500;
  14297. t['Edotaccent'] = 667;
  14298. t['scaron'] = 389;
  14299. t['scedilla'] = 389;
  14300. t['iacute'] = 278;
  14301. t['lozenge'] = 494;
  14302. t['Rcaron'] = 722;
  14303. t['Gcommaaccent'] = 778;
  14304. t['ucircumflex'] = 556;
  14305. t['acircumflex'] = 500;
  14306. t['Amacron'] = 722;
  14307. t['rcaron'] = 444;
  14308. t['ccedilla'] = 444;
  14309. t['Zdotaccent'] = 667;
  14310. t['Thorn'] = 611;
  14311. t['Omacron'] = 778;
  14312. t['Racute'] = 722;
  14313. t['Sacute'] = 556;
  14314. t['dcaron'] = 672;
  14315. t['Umacron'] = 722;
  14316. t['uring'] = 556;
  14317. t['threesuperior'] = 300;
  14318. t['Ograve'] = 778;
  14319. t['Agrave'] = 722;
  14320. t['Abreve'] = 722;
  14321. t['multiply'] = 570;
  14322. t['uacute'] = 556;
  14323. t['Tcaron'] = 667;
  14324. t['partialdiff'] = 494;
  14325. t['ydieresis'] = 500;
  14326. t['Nacute'] = 722;
  14327. t['icircumflex'] = 278;
  14328. t['Ecircumflex'] = 667;
  14329. t['adieresis'] = 500;
  14330. t['edieresis'] = 444;
  14331. t['cacute'] = 444;
  14332. t['nacute'] = 556;
  14333. t['umacron'] = 556;
  14334. t['Ncaron'] = 722;
  14335. t['Iacute'] = 389;
  14336. t['plusminus'] = 570;
  14337. t['brokenbar'] = 220;
  14338. t['registered'] = 747;
  14339. t['Gbreve'] = 778;
  14340. t['Idotaccent'] = 389;
  14341. t['summation'] = 600;
  14342. t['Egrave'] = 667;
  14343. t['racute'] = 444;
  14344. t['omacron'] = 500;
  14345. t['Zacute'] = 667;
  14346. t['Zcaron'] = 667;
  14347. t['greaterequal'] = 549;
  14348. t['Eth'] = 722;
  14349. t['Ccedilla'] = 722;
  14350. t['lcommaaccent'] = 278;
  14351. t['tcaron'] = 416;
  14352. t['eogonek'] = 444;
  14353. t['Uogonek'] = 722;
  14354. t['Aacute'] = 722;
  14355. t['Adieresis'] = 722;
  14356. t['egrave'] = 444;
  14357. t['zacute'] = 444;
  14358. t['iogonek'] = 278;
  14359. t['Oacute'] = 778;
  14360. t['oacute'] = 500;
  14361. t['amacron'] = 500;
  14362. t['sacute'] = 389;
  14363. t['idieresis'] = 278;
  14364. t['Ocircumflex'] = 778;
  14365. t['Ugrave'] = 722;
  14366. t['Delta'] = 612;
  14367. t['thorn'] = 556;
  14368. t['twosuperior'] = 300;
  14369. t['Odieresis'] = 778;
  14370. t['mu'] = 556;
  14371. t['igrave'] = 278;
  14372. t['ohungarumlaut'] = 500;
  14373. t['Eogonek'] = 667;
  14374. t['dcroat'] = 556;
  14375. t['threequarters'] = 750;
  14376. t['Scedilla'] = 556;
  14377. t['lcaron'] = 394;
  14378. t['Kcommaaccent'] = 778;
  14379. t['Lacute'] = 667;
  14380. t['trademark'] = 1000;
  14381. t['edotaccent'] = 444;
  14382. t['Igrave'] = 389;
  14383. t['Imacron'] = 389;
  14384. t['Lcaron'] = 667;
  14385. t['onehalf'] = 750;
  14386. t['lessequal'] = 549;
  14387. t['ocircumflex'] = 500;
  14388. t['ntilde'] = 556;
  14389. t['Uhungarumlaut'] = 722;
  14390. t['Eacute'] = 667;
  14391. t['emacron'] = 444;
  14392. t['gbreve'] = 500;
  14393. t['onequarter'] = 750;
  14394. t['Scaron'] = 556;
  14395. t['Scommaaccent'] = 556;
  14396. t['Ohungarumlaut'] = 778;
  14397. t['degree'] = 400;
  14398. t['ograve'] = 500;
  14399. t['Ccaron'] = 722;
  14400. t['ugrave'] = 556;
  14401. t['radical'] = 549;
  14402. t['Dcaron'] = 722;
  14403. t['rcommaaccent'] = 444;
  14404. t['Ntilde'] = 722;
  14405. t['otilde'] = 500;
  14406. t['Rcommaaccent'] = 722;
  14407. t['Lcommaaccent'] = 667;
  14408. t['Atilde'] = 722;
  14409. t['Aogonek'] = 722;
  14410. t['Aring'] = 722;
  14411. t['Otilde'] = 778;
  14412. t['zdotaccent'] = 444;
  14413. t['Ecaron'] = 667;
  14414. t['Iogonek'] = 389;
  14415. t['kcommaaccent'] = 556;
  14416. t['minus'] = 570;
  14417. t['Icircumflex'] = 389;
  14418. t['ncaron'] = 556;
  14419. t['tcommaaccent'] = 333;
  14420. t['logicalnot'] = 570;
  14421. t['odieresis'] = 500;
  14422. t['udieresis'] = 556;
  14423. t['notequal'] = 549;
  14424. t['gcommaaccent'] = 500;
  14425. t['eth'] = 500;
  14426. t['zcaron'] = 444;
  14427. t['ncommaaccent'] = 556;
  14428. t['onesuperior'] = 300;
  14429. t['imacron'] = 278;
  14430. t['Euro'] = 500;
  14431. });
  14432. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  14433. t['space'] = 250;
  14434. t['exclam'] = 389;
  14435. t['quotedbl'] = 555;
  14436. t['numbersign'] = 500;
  14437. t['dollar'] = 500;
  14438. t['percent'] = 833;
  14439. t['ampersand'] = 778;
  14440. t['quoteright'] = 333;
  14441. t['parenleft'] = 333;
  14442. t['parenright'] = 333;
  14443. t['asterisk'] = 500;
  14444. t['plus'] = 570;
  14445. t['comma'] = 250;
  14446. t['hyphen'] = 333;
  14447. t['period'] = 250;
  14448. t['slash'] = 278;
  14449. t['zero'] = 500;
  14450. t['one'] = 500;
  14451. t['two'] = 500;
  14452. t['three'] = 500;
  14453. t['four'] = 500;
  14454. t['five'] = 500;
  14455. t['six'] = 500;
  14456. t['seven'] = 500;
  14457. t['eight'] = 500;
  14458. t['nine'] = 500;
  14459. t['colon'] = 333;
  14460. t['semicolon'] = 333;
  14461. t['less'] = 570;
  14462. t['equal'] = 570;
  14463. t['greater'] = 570;
  14464. t['question'] = 500;
  14465. t['at'] = 832;
  14466. t['A'] = 667;
  14467. t['B'] = 667;
  14468. t['C'] = 667;
  14469. t['D'] = 722;
  14470. t['E'] = 667;
  14471. t['F'] = 667;
  14472. t['G'] = 722;
  14473. t['H'] = 778;
  14474. t['I'] = 389;
  14475. t['J'] = 500;
  14476. t['K'] = 667;
  14477. t['L'] = 611;
  14478. t['M'] = 889;
  14479. t['N'] = 722;
  14480. t['O'] = 722;
  14481. t['P'] = 611;
  14482. t['Q'] = 722;
  14483. t['R'] = 667;
  14484. t['S'] = 556;
  14485. t['T'] = 611;
  14486. t['U'] = 722;
  14487. t['V'] = 667;
  14488. t['W'] = 889;
  14489. t['X'] = 667;
  14490. t['Y'] = 611;
  14491. t['Z'] = 611;
  14492. t['bracketleft'] = 333;
  14493. t['backslash'] = 278;
  14494. t['bracketright'] = 333;
  14495. t['asciicircum'] = 570;
  14496. t['underscore'] = 500;
  14497. t['quoteleft'] = 333;
  14498. t['a'] = 500;
  14499. t['b'] = 500;
  14500. t['c'] = 444;
  14501. t['d'] = 500;
  14502. t['e'] = 444;
  14503. t['f'] = 333;
  14504. t['g'] = 500;
  14505. t['h'] = 556;
  14506. t['i'] = 278;
  14507. t['j'] = 278;
  14508. t['k'] = 500;
  14509. t['l'] = 278;
  14510. t['m'] = 778;
  14511. t['n'] = 556;
  14512. t['o'] = 500;
  14513. t['p'] = 500;
  14514. t['q'] = 500;
  14515. t['r'] = 389;
  14516. t['s'] = 389;
  14517. t['t'] = 278;
  14518. t['u'] = 556;
  14519. t['v'] = 444;
  14520. t['w'] = 667;
  14521. t['x'] = 500;
  14522. t['y'] = 444;
  14523. t['z'] = 389;
  14524. t['braceleft'] = 348;
  14525. t['bar'] = 220;
  14526. t['braceright'] = 348;
  14527. t['asciitilde'] = 570;
  14528. t['exclamdown'] = 389;
  14529. t['cent'] = 500;
  14530. t['sterling'] = 500;
  14531. t['fraction'] = 167;
  14532. t['yen'] = 500;
  14533. t['florin'] = 500;
  14534. t['section'] = 500;
  14535. t['currency'] = 500;
  14536. t['quotesingle'] = 278;
  14537. t['quotedblleft'] = 500;
  14538. t['guillemotleft'] = 500;
  14539. t['guilsinglleft'] = 333;
  14540. t['guilsinglright'] = 333;
  14541. t['fi'] = 556;
  14542. t['fl'] = 556;
  14543. t['endash'] = 500;
  14544. t['dagger'] = 500;
  14545. t['daggerdbl'] = 500;
  14546. t['periodcentered'] = 250;
  14547. t['paragraph'] = 500;
  14548. t['bullet'] = 350;
  14549. t['quotesinglbase'] = 333;
  14550. t['quotedblbase'] = 500;
  14551. t['quotedblright'] = 500;
  14552. t['guillemotright'] = 500;
  14553. t['ellipsis'] = 1000;
  14554. t['perthousand'] = 1000;
  14555. t['questiondown'] = 500;
  14556. t['grave'] = 333;
  14557. t['acute'] = 333;
  14558. t['circumflex'] = 333;
  14559. t['tilde'] = 333;
  14560. t['macron'] = 333;
  14561. t['breve'] = 333;
  14562. t['dotaccent'] = 333;
  14563. t['dieresis'] = 333;
  14564. t['ring'] = 333;
  14565. t['cedilla'] = 333;
  14566. t['hungarumlaut'] = 333;
  14567. t['ogonek'] = 333;
  14568. t['caron'] = 333;
  14569. t['emdash'] = 1000;
  14570. t['AE'] = 944;
  14571. t['ordfeminine'] = 266;
  14572. t['Lslash'] = 611;
  14573. t['Oslash'] = 722;
  14574. t['OE'] = 944;
  14575. t['ordmasculine'] = 300;
  14576. t['ae'] = 722;
  14577. t['dotlessi'] = 278;
  14578. t['lslash'] = 278;
  14579. t['oslash'] = 500;
  14580. t['oe'] = 722;
  14581. t['germandbls'] = 500;
  14582. t['Idieresis'] = 389;
  14583. t['eacute'] = 444;
  14584. t['abreve'] = 500;
  14585. t['uhungarumlaut'] = 556;
  14586. t['ecaron'] = 444;
  14587. t['Ydieresis'] = 611;
  14588. t['divide'] = 570;
  14589. t['Yacute'] = 611;
  14590. t['Acircumflex'] = 667;
  14591. t['aacute'] = 500;
  14592. t['Ucircumflex'] = 722;
  14593. t['yacute'] = 444;
  14594. t['scommaaccent'] = 389;
  14595. t['ecircumflex'] = 444;
  14596. t['Uring'] = 722;
  14597. t['Udieresis'] = 722;
  14598. t['aogonek'] = 500;
  14599. t['Uacute'] = 722;
  14600. t['uogonek'] = 556;
  14601. t['Edieresis'] = 667;
  14602. t['Dcroat'] = 722;
  14603. t['commaaccent'] = 250;
  14604. t['copyright'] = 747;
  14605. t['Emacron'] = 667;
  14606. t['ccaron'] = 444;
  14607. t['aring'] = 500;
  14608. t['Ncommaaccent'] = 722;
  14609. t['lacute'] = 278;
  14610. t['agrave'] = 500;
  14611. t['Tcommaaccent'] = 611;
  14612. t['Cacute'] = 667;
  14613. t['atilde'] = 500;
  14614. t['Edotaccent'] = 667;
  14615. t['scaron'] = 389;
  14616. t['scedilla'] = 389;
  14617. t['iacute'] = 278;
  14618. t['lozenge'] = 494;
  14619. t['Rcaron'] = 667;
  14620. t['Gcommaaccent'] = 722;
  14621. t['ucircumflex'] = 556;
  14622. t['acircumflex'] = 500;
  14623. t['Amacron'] = 667;
  14624. t['rcaron'] = 389;
  14625. t['ccedilla'] = 444;
  14626. t['Zdotaccent'] = 611;
  14627. t['Thorn'] = 611;
  14628. t['Omacron'] = 722;
  14629. t['Racute'] = 667;
  14630. t['Sacute'] = 556;
  14631. t['dcaron'] = 608;
  14632. t['Umacron'] = 722;
  14633. t['uring'] = 556;
  14634. t['threesuperior'] = 300;
  14635. t['Ograve'] = 722;
  14636. t['Agrave'] = 667;
  14637. t['Abreve'] = 667;
  14638. t['multiply'] = 570;
  14639. t['uacute'] = 556;
  14640. t['Tcaron'] = 611;
  14641. t['partialdiff'] = 494;
  14642. t['ydieresis'] = 444;
  14643. t['Nacute'] = 722;
  14644. t['icircumflex'] = 278;
  14645. t['Ecircumflex'] = 667;
  14646. t['adieresis'] = 500;
  14647. t['edieresis'] = 444;
  14648. t['cacute'] = 444;
  14649. t['nacute'] = 556;
  14650. t['umacron'] = 556;
  14651. t['Ncaron'] = 722;
  14652. t['Iacute'] = 389;
  14653. t['plusminus'] = 570;
  14654. t['brokenbar'] = 220;
  14655. t['registered'] = 747;
  14656. t['Gbreve'] = 722;
  14657. t['Idotaccent'] = 389;
  14658. t['summation'] = 600;
  14659. t['Egrave'] = 667;
  14660. t['racute'] = 389;
  14661. t['omacron'] = 500;
  14662. t['Zacute'] = 611;
  14663. t['Zcaron'] = 611;
  14664. t['greaterequal'] = 549;
  14665. t['Eth'] = 722;
  14666. t['Ccedilla'] = 667;
  14667. t['lcommaaccent'] = 278;
  14668. t['tcaron'] = 366;
  14669. t['eogonek'] = 444;
  14670. t['Uogonek'] = 722;
  14671. t['Aacute'] = 667;
  14672. t['Adieresis'] = 667;
  14673. t['egrave'] = 444;
  14674. t['zacute'] = 389;
  14675. t['iogonek'] = 278;
  14676. t['Oacute'] = 722;
  14677. t['oacute'] = 500;
  14678. t['amacron'] = 500;
  14679. t['sacute'] = 389;
  14680. t['idieresis'] = 278;
  14681. t['Ocircumflex'] = 722;
  14682. t['Ugrave'] = 722;
  14683. t['Delta'] = 612;
  14684. t['thorn'] = 500;
  14685. t['twosuperior'] = 300;
  14686. t['Odieresis'] = 722;
  14687. t['mu'] = 576;
  14688. t['igrave'] = 278;
  14689. t['ohungarumlaut'] = 500;
  14690. t['Eogonek'] = 667;
  14691. t['dcroat'] = 500;
  14692. t['threequarters'] = 750;
  14693. t['Scedilla'] = 556;
  14694. t['lcaron'] = 382;
  14695. t['Kcommaaccent'] = 667;
  14696. t['Lacute'] = 611;
  14697. t['trademark'] = 1000;
  14698. t['edotaccent'] = 444;
  14699. t['Igrave'] = 389;
  14700. t['Imacron'] = 389;
  14701. t['Lcaron'] = 611;
  14702. t['onehalf'] = 750;
  14703. t['lessequal'] = 549;
  14704. t['ocircumflex'] = 500;
  14705. t['ntilde'] = 556;
  14706. t['Uhungarumlaut'] = 722;
  14707. t['Eacute'] = 667;
  14708. t['emacron'] = 444;
  14709. t['gbreve'] = 500;
  14710. t['onequarter'] = 750;
  14711. t['Scaron'] = 556;
  14712. t['Scommaaccent'] = 556;
  14713. t['Ohungarumlaut'] = 722;
  14714. t['degree'] = 400;
  14715. t['ograve'] = 500;
  14716. t['Ccaron'] = 667;
  14717. t['ugrave'] = 556;
  14718. t['radical'] = 549;
  14719. t['Dcaron'] = 722;
  14720. t['rcommaaccent'] = 389;
  14721. t['Ntilde'] = 722;
  14722. t['otilde'] = 500;
  14723. t['Rcommaaccent'] = 667;
  14724. t['Lcommaaccent'] = 611;
  14725. t['Atilde'] = 667;
  14726. t['Aogonek'] = 667;
  14727. t['Aring'] = 667;
  14728. t['Otilde'] = 722;
  14729. t['zdotaccent'] = 389;
  14730. t['Ecaron'] = 667;
  14731. t['Iogonek'] = 389;
  14732. t['kcommaaccent'] = 500;
  14733. t['minus'] = 606;
  14734. t['Icircumflex'] = 389;
  14735. t['ncaron'] = 556;
  14736. t['tcommaaccent'] = 278;
  14737. t['logicalnot'] = 606;
  14738. t['odieresis'] = 500;
  14739. t['udieresis'] = 556;
  14740. t['notequal'] = 549;
  14741. t['gcommaaccent'] = 500;
  14742. t['eth'] = 500;
  14743. t['zcaron'] = 389;
  14744. t['ncommaaccent'] = 556;
  14745. t['onesuperior'] = 300;
  14746. t['imacron'] = 278;
  14747. t['Euro'] = 500;
  14748. });
  14749. t['Times-Italic'] = getLookupTableFactory(function (t) {
  14750. t['space'] = 250;
  14751. t['exclam'] = 333;
  14752. t['quotedbl'] = 420;
  14753. t['numbersign'] = 500;
  14754. t['dollar'] = 500;
  14755. t['percent'] = 833;
  14756. t['ampersand'] = 778;
  14757. t['quoteright'] = 333;
  14758. t['parenleft'] = 333;
  14759. t['parenright'] = 333;
  14760. t['asterisk'] = 500;
  14761. t['plus'] = 675;
  14762. t['comma'] = 250;
  14763. t['hyphen'] = 333;
  14764. t['period'] = 250;
  14765. t['slash'] = 278;
  14766. t['zero'] = 500;
  14767. t['one'] = 500;
  14768. t['two'] = 500;
  14769. t['three'] = 500;
  14770. t['four'] = 500;
  14771. t['five'] = 500;
  14772. t['six'] = 500;
  14773. t['seven'] = 500;
  14774. t['eight'] = 500;
  14775. t['nine'] = 500;
  14776. t['colon'] = 333;
  14777. t['semicolon'] = 333;
  14778. t['less'] = 675;
  14779. t['equal'] = 675;
  14780. t['greater'] = 675;
  14781. t['question'] = 500;
  14782. t['at'] = 920;
  14783. t['A'] = 611;
  14784. t['B'] = 611;
  14785. t['C'] = 667;
  14786. t['D'] = 722;
  14787. t['E'] = 611;
  14788. t['F'] = 611;
  14789. t['G'] = 722;
  14790. t['H'] = 722;
  14791. t['I'] = 333;
  14792. t['J'] = 444;
  14793. t['K'] = 667;
  14794. t['L'] = 556;
  14795. t['M'] = 833;
  14796. t['N'] = 667;
  14797. t['O'] = 722;
  14798. t['P'] = 611;
  14799. t['Q'] = 722;
  14800. t['R'] = 611;
  14801. t['S'] = 500;
  14802. t['T'] = 556;
  14803. t['U'] = 722;
  14804. t['V'] = 611;
  14805. t['W'] = 833;
  14806. t['X'] = 611;
  14807. t['Y'] = 556;
  14808. t['Z'] = 556;
  14809. t['bracketleft'] = 389;
  14810. t['backslash'] = 278;
  14811. t['bracketright'] = 389;
  14812. t['asciicircum'] = 422;
  14813. t['underscore'] = 500;
  14814. t['quoteleft'] = 333;
  14815. t['a'] = 500;
  14816. t['b'] = 500;
  14817. t['c'] = 444;
  14818. t['d'] = 500;
  14819. t['e'] = 444;
  14820. t['f'] = 278;
  14821. t['g'] = 500;
  14822. t['h'] = 500;
  14823. t['i'] = 278;
  14824. t['j'] = 278;
  14825. t['k'] = 444;
  14826. t['l'] = 278;
  14827. t['m'] = 722;
  14828. t['n'] = 500;
  14829. t['o'] = 500;
  14830. t['p'] = 500;
  14831. t['q'] = 500;
  14832. t['r'] = 389;
  14833. t['s'] = 389;
  14834. t['t'] = 278;
  14835. t['u'] = 500;
  14836. t['v'] = 444;
  14837. t['w'] = 667;
  14838. t['x'] = 444;
  14839. t['y'] = 444;
  14840. t['z'] = 389;
  14841. t['braceleft'] = 400;
  14842. t['bar'] = 275;
  14843. t['braceright'] = 400;
  14844. t['asciitilde'] = 541;
  14845. t['exclamdown'] = 389;
  14846. t['cent'] = 500;
  14847. t['sterling'] = 500;
  14848. t['fraction'] = 167;
  14849. t['yen'] = 500;
  14850. t['florin'] = 500;
  14851. t['section'] = 500;
  14852. t['currency'] = 500;
  14853. t['quotesingle'] = 214;
  14854. t['quotedblleft'] = 556;
  14855. t['guillemotleft'] = 500;
  14856. t['guilsinglleft'] = 333;
  14857. t['guilsinglright'] = 333;
  14858. t['fi'] = 500;
  14859. t['fl'] = 500;
  14860. t['endash'] = 500;
  14861. t['dagger'] = 500;
  14862. t['daggerdbl'] = 500;
  14863. t['periodcentered'] = 250;
  14864. t['paragraph'] = 523;
  14865. t['bullet'] = 350;
  14866. t['quotesinglbase'] = 333;
  14867. t['quotedblbase'] = 556;
  14868. t['quotedblright'] = 556;
  14869. t['guillemotright'] = 500;
  14870. t['ellipsis'] = 889;
  14871. t['perthousand'] = 1000;
  14872. t['questiondown'] = 500;
  14873. t['grave'] = 333;
  14874. t['acute'] = 333;
  14875. t['circumflex'] = 333;
  14876. t['tilde'] = 333;
  14877. t['macron'] = 333;
  14878. t['breve'] = 333;
  14879. t['dotaccent'] = 333;
  14880. t['dieresis'] = 333;
  14881. t['ring'] = 333;
  14882. t['cedilla'] = 333;
  14883. t['hungarumlaut'] = 333;
  14884. t['ogonek'] = 333;
  14885. t['caron'] = 333;
  14886. t['emdash'] = 889;
  14887. t['AE'] = 889;
  14888. t['ordfeminine'] = 276;
  14889. t['Lslash'] = 556;
  14890. t['Oslash'] = 722;
  14891. t['OE'] = 944;
  14892. t['ordmasculine'] = 310;
  14893. t['ae'] = 667;
  14894. t['dotlessi'] = 278;
  14895. t['lslash'] = 278;
  14896. t['oslash'] = 500;
  14897. t['oe'] = 667;
  14898. t['germandbls'] = 500;
  14899. t['Idieresis'] = 333;
  14900. t['eacute'] = 444;
  14901. t['abreve'] = 500;
  14902. t['uhungarumlaut'] = 500;
  14903. t['ecaron'] = 444;
  14904. t['Ydieresis'] = 556;
  14905. t['divide'] = 675;
  14906. t['Yacute'] = 556;
  14907. t['Acircumflex'] = 611;
  14908. t['aacute'] = 500;
  14909. t['Ucircumflex'] = 722;
  14910. t['yacute'] = 444;
  14911. t['scommaaccent'] = 389;
  14912. t['ecircumflex'] = 444;
  14913. t['Uring'] = 722;
  14914. t['Udieresis'] = 722;
  14915. t['aogonek'] = 500;
  14916. t['Uacute'] = 722;
  14917. t['uogonek'] = 500;
  14918. t['Edieresis'] = 611;
  14919. t['Dcroat'] = 722;
  14920. t['commaaccent'] = 250;
  14921. t['copyright'] = 760;
  14922. t['Emacron'] = 611;
  14923. t['ccaron'] = 444;
  14924. t['aring'] = 500;
  14925. t['Ncommaaccent'] = 667;
  14926. t['lacute'] = 278;
  14927. t['agrave'] = 500;
  14928. t['Tcommaaccent'] = 556;
  14929. t['Cacute'] = 667;
  14930. t['atilde'] = 500;
  14931. t['Edotaccent'] = 611;
  14932. t['scaron'] = 389;
  14933. t['scedilla'] = 389;
  14934. t['iacute'] = 278;
  14935. t['lozenge'] = 471;
  14936. t['Rcaron'] = 611;
  14937. t['Gcommaaccent'] = 722;
  14938. t['ucircumflex'] = 500;
  14939. t['acircumflex'] = 500;
  14940. t['Amacron'] = 611;
  14941. t['rcaron'] = 389;
  14942. t['ccedilla'] = 444;
  14943. t['Zdotaccent'] = 556;
  14944. t['Thorn'] = 611;
  14945. t['Omacron'] = 722;
  14946. t['Racute'] = 611;
  14947. t['Sacute'] = 500;
  14948. t['dcaron'] = 544;
  14949. t['Umacron'] = 722;
  14950. t['uring'] = 500;
  14951. t['threesuperior'] = 300;
  14952. t['Ograve'] = 722;
  14953. t['Agrave'] = 611;
  14954. t['Abreve'] = 611;
  14955. t['multiply'] = 675;
  14956. t['uacute'] = 500;
  14957. t['Tcaron'] = 556;
  14958. t['partialdiff'] = 476;
  14959. t['ydieresis'] = 444;
  14960. t['Nacute'] = 667;
  14961. t['icircumflex'] = 278;
  14962. t['Ecircumflex'] = 611;
  14963. t['adieresis'] = 500;
  14964. t['edieresis'] = 444;
  14965. t['cacute'] = 444;
  14966. t['nacute'] = 500;
  14967. t['umacron'] = 500;
  14968. t['Ncaron'] = 667;
  14969. t['Iacute'] = 333;
  14970. t['plusminus'] = 675;
  14971. t['brokenbar'] = 275;
  14972. t['registered'] = 760;
  14973. t['Gbreve'] = 722;
  14974. t['Idotaccent'] = 333;
  14975. t['summation'] = 600;
  14976. t['Egrave'] = 611;
  14977. t['racute'] = 389;
  14978. t['omacron'] = 500;
  14979. t['Zacute'] = 556;
  14980. t['Zcaron'] = 556;
  14981. t['greaterequal'] = 549;
  14982. t['Eth'] = 722;
  14983. t['Ccedilla'] = 667;
  14984. t['lcommaaccent'] = 278;
  14985. t['tcaron'] = 300;
  14986. t['eogonek'] = 444;
  14987. t['Uogonek'] = 722;
  14988. t['Aacute'] = 611;
  14989. t['Adieresis'] = 611;
  14990. t['egrave'] = 444;
  14991. t['zacute'] = 389;
  14992. t['iogonek'] = 278;
  14993. t['Oacute'] = 722;
  14994. t['oacute'] = 500;
  14995. t['amacron'] = 500;
  14996. t['sacute'] = 389;
  14997. t['idieresis'] = 278;
  14998. t['Ocircumflex'] = 722;
  14999. t['Ugrave'] = 722;
  15000. t['Delta'] = 612;
  15001. t['thorn'] = 500;
  15002. t['twosuperior'] = 300;
  15003. t['Odieresis'] = 722;
  15004. t['mu'] = 500;
  15005. t['igrave'] = 278;
  15006. t['ohungarumlaut'] = 500;
  15007. t['Eogonek'] = 611;
  15008. t['dcroat'] = 500;
  15009. t['threequarters'] = 750;
  15010. t['Scedilla'] = 500;
  15011. t['lcaron'] = 300;
  15012. t['Kcommaaccent'] = 667;
  15013. t['Lacute'] = 556;
  15014. t['trademark'] = 980;
  15015. t['edotaccent'] = 444;
  15016. t['Igrave'] = 333;
  15017. t['Imacron'] = 333;
  15018. t['Lcaron'] = 611;
  15019. t['onehalf'] = 750;
  15020. t['lessequal'] = 549;
  15021. t['ocircumflex'] = 500;
  15022. t['ntilde'] = 500;
  15023. t['Uhungarumlaut'] = 722;
  15024. t['Eacute'] = 611;
  15025. t['emacron'] = 444;
  15026. t['gbreve'] = 500;
  15027. t['onequarter'] = 750;
  15028. t['Scaron'] = 500;
  15029. t['Scommaaccent'] = 500;
  15030. t['Ohungarumlaut'] = 722;
  15031. t['degree'] = 400;
  15032. t['ograve'] = 500;
  15033. t['Ccaron'] = 667;
  15034. t['ugrave'] = 500;
  15035. t['radical'] = 453;
  15036. t['Dcaron'] = 722;
  15037. t['rcommaaccent'] = 389;
  15038. t['Ntilde'] = 667;
  15039. t['otilde'] = 500;
  15040. t['Rcommaaccent'] = 611;
  15041. t['Lcommaaccent'] = 556;
  15042. t['Atilde'] = 611;
  15043. t['Aogonek'] = 611;
  15044. t['Aring'] = 611;
  15045. t['Otilde'] = 722;
  15046. t['zdotaccent'] = 389;
  15047. t['Ecaron'] = 611;
  15048. t['Iogonek'] = 333;
  15049. t['kcommaaccent'] = 444;
  15050. t['minus'] = 675;
  15051. t['Icircumflex'] = 333;
  15052. t['ncaron'] = 500;
  15053. t['tcommaaccent'] = 278;
  15054. t['logicalnot'] = 675;
  15055. t['odieresis'] = 500;
  15056. t['udieresis'] = 500;
  15057. t['notequal'] = 549;
  15058. t['gcommaaccent'] = 500;
  15059. t['eth'] = 500;
  15060. t['zcaron'] = 389;
  15061. t['ncommaaccent'] = 500;
  15062. t['onesuperior'] = 300;
  15063. t['imacron'] = 278;
  15064. t['Euro'] = 500;
  15065. });
  15066. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  15067. t['space'] = 278;
  15068. t['a1'] = 974;
  15069. t['a2'] = 961;
  15070. t['a202'] = 974;
  15071. t['a3'] = 980;
  15072. t['a4'] = 719;
  15073. t['a5'] = 789;
  15074. t['a119'] = 790;
  15075. t['a118'] = 791;
  15076. t['a117'] = 690;
  15077. t['a11'] = 960;
  15078. t['a12'] = 939;
  15079. t['a13'] = 549;
  15080. t['a14'] = 855;
  15081. t['a15'] = 911;
  15082. t['a16'] = 933;
  15083. t['a105'] = 911;
  15084. t['a17'] = 945;
  15085. t['a18'] = 974;
  15086. t['a19'] = 755;
  15087. t['a20'] = 846;
  15088. t['a21'] = 762;
  15089. t['a22'] = 761;
  15090. t['a23'] = 571;
  15091. t['a24'] = 677;
  15092. t['a25'] = 763;
  15093. t['a26'] = 760;
  15094. t['a27'] = 759;
  15095. t['a28'] = 754;
  15096. t['a6'] = 494;
  15097. t['a7'] = 552;
  15098. t['a8'] = 537;
  15099. t['a9'] = 577;
  15100. t['a10'] = 692;
  15101. t['a29'] = 786;
  15102. t['a30'] = 788;
  15103. t['a31'] = 788;
  15104. t['a32'] = 790;
  15105. t['a33'] = 793;
  15106. t['a34'] = 794;
  15107. t['a35'] = 816;
  15108. t['a36'] = 823;
  15109. t['a37'] = 789;
  15110. t['a38'] = 841;
  15111. t['a39'] = 823;
  15112. t['a40'] = 833;
  15113. t['a41'] = 816;
  15114. t['a42'] = 831;
  15115. t['a43'] = 923;
  15116. t['a44'] = 744;
  15117. t['a45'] = 723;
  15118. t['a46'] = 749;
  15119. t['a47'] = 790;
  15120. t['a48'] = 792;
  15121. t['a49'] = 695;
  15122. t['a50'] = 776;
  15123. t['a51'] = 768;
  15124. t['a52'] = 792;
  15125. t['a53'] = 759;
  15126. t['a54'] = 707;
  15127. t['a55'] = 708;
  15128. t['a56'] = 682;
  15129. t['a57'] = 701;
  15130. t['a58'] = 826;
  15131. t['a59'] = 815;
  15132. t['a60'] = 789;
  15133. t['a61'] = 789;
  15134. t['a62'] = 707;
  15135. t['a63'] = 687;
  15136. t['a64'] = 696;
  15137. t['a65'] = 689;
  15138. t['a66'] = 786;
  15139. t['a67'] = 787;
  15140. t['a68'] = 713;
  15141. t['a69'] = 791;
  15142. t['a70'] = 785;
  15143. t['a71'] = 791;
  15144. t['a72'] = 873;
  15145. t['a73'] = 761;
  15146. t['a74'] = 762;
  15147. t['a203'] = 762;
  15148. t['a75'] = 759;
  15149. t['a204'] = 759;
  15150. t['a76'] = 892;
  15151. t['a77'] = 892;
  15152. t['a78'] = 788;
  15153. t['a79'] = 784;
  15154. t['a81'] = 438;
  15155. t['a82'] = 138;
  15156. t['a83'] = 277;
  15157. t['a84'] = 415;
  15158. t['a97'] = 392;
  15159. t['a98'] = 392;
  15160. t['a99'] = 668;
  15161. t['a100'] = 668;
  15162. t['a89'] = 390;
  15163. t['a90'] = 390;
  15164. t['a93'] = 317;
  15165. t['a94'] = 317;
  15166. t['a91'] = 276;
  15167. t['a92'] = 276;
  15168. t['a205'] = 509;
  15169. t['a85'] = 509;
  15170. t['a206'] = 410;
  15171. t['a86'] = 410;
  15172. t['a87'] = 234;
  15173. t['a88'] = 234;
  15174. t['a95'] = 334;
  15175. t['a96'] = 334;
  15176. t['a101'] = 732;
  15177. t['a102'] = 544;
  15178. t['a103'] = 544;
  15179. t['a104'] = 910;
  15180. t['a106'] = 667;
  15181. t['a107'] = 760;
  15182. t['a108'] = 760;
  15183. t['a112'] = 776;
  15184. t['a111'] = 595;
  15185. t['a110'] = 694;
  15186. t['a109'] = 626;
  15187. t['a120'] = 788;
  15188. t['a121'] = 788;
  15189. t['a122'] = 788;
  15190. t['a123'] = 788;
  15191. t['a124'] = 788;
  15192. t['a125'] = 788;
  15193. t['a126'] = 788;
  15194. t['a127'] = 788;
  15195. t['a128'] = 788;
  15196. t['a129'] = 788;
  15197. t['a130'] = 788;
  15198. t['a131'] = 788;
  15199. t['a132'] = 788;
  15200. t['a133'] = 788;
  15201. t['a134'] = 788;
  15202. t['a135'] = 788;
  15203. t['a136'] = 788;
  15204. t['a137'] = 788;
  15205. t['a138'] = 788;
  15206. t['a139'] = 788;
  15207. t['a140'] = 788;
  15208. t['a141'] = 788;
  15209. t['a142'] = 788;
  15210. t['a143'] = 788;
  15211. t['a144'] = 788;
  15212. t['a145'] = 788;
  15213. t['a146'] = 788;
  15214. t['a147'] = 788;
  15215. t['a148'] = 788;
  15216. t['a149'] = 788;
  15217. t['a150'] = 788;
  15218. t['a151'] = 788;
  15219. t['a152'] = 788;
  15220. t['a153'] = 788;
  15221. t['a154'] = 788;
  15222. t['a155'] = 788;
  15223. t['a156'] = 788;
  15224. t['a157'] = 788;
  15225. t['a158'] = 788;
  15226. t['a159'] = 788;
  15227. t['a160'] = 894;
  15228. t['a161'] = 838;
  15229. t['a163'] = 1016;
  15230. t['a164'] = 458;
  15231. t['a196'] = 748;
  15232. t['a165'] = 924;
  15233. t['a192'] = 748;
  15234. t['a166'] = 918;
  15235. t['a167'] = 927;
  15236. t['a168'] = 928;
  15237. t['a169'] = 928;
  15238. t['a170'] = 834;
  15239. t['a171'] = 873;
  15240. t['a172'] = 828;
  15241. t['a173'] = 924;
  15242. t['a162'] = 924;
  15243. t['a174'] = 917;
  15244. t['a175'] = 930;
  15245. t['a176'] = 931;
  15246. t['a177'] = 463;
  15247. t['a178'] = 883;
  15248. t['a179'] = 836;
  15249. t['a193'] = 836;
  15250. t['a180'] = 867;
  15251. t['a199'] = 867;
  15252. t['a181'] = 696;
  15253. t['a200'] = 696;
  15254. t['a182'] = 874;
  15255. t['a201'] = 874;
  15256. t['a183'] = 760;
  15257. t['a184'] = 946;
  15258. t['a197'] = 771;
  15259. t['a185'] = 865;
  15260. t['a194'] = 771;
  15261. t['a198'] = 888;
  15262. t['a186'] = 967;
  15263. t['a195'] = 888;
  15264. t['a187'] = 831;
  15265. t['a188'] = 873;
  15266. t['a189'] = 927;
  15267. t['a190'] = 970;
  15268. t['a191'] = 918;
  15269. });
  15270. });
  15271. exports.getMetrics = getMetrics;
  15272. }));
  15273. (function (root, factory) {
  15274. {
  15275. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  15276. }
  15277. }(this, function (exports, sharedUtil) {
  15278. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  15279. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  15280. // Workaround for missing math precison in JS.
  15281. var MASK_HIGH = 0xffff0000;
  15282. var MASK_LOW = 0xffff;
  15283. function MurmurHash3_64 (seed) {
  15284. var SEED = 0xc3d2e1f0;
  15285. this.h1 = seed ? seed & 0xffffffff : SEED;
  15286. this.h2 = seed ? seed & 0xffffffff : SEED;
  15287. }
  15288. var alwaysUseUint32ArrayView = false;
  15289. // old webkits have issues with non-aligned arrays
  15290. try {
  15291. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  15292. } catch (e) {
  15293. alwaysUseUint32ArrayView = true;
  15294. }
  15295. MurmurHash3_64.prototype = {
  15296. update: function MurmurHash3_64_update(input) {
  15297. var useUint32ArrayView = alwaysUseUint32ArrayView;
  15298. var i;
  15299. if (typeof input === 'string') {
  15300. var data = new Uint8Array(input.length * 2);
  15301. var length = 0;
  15302. for (i = 0; i < input.length; i++) {
  15303. var code = input.charCodeAt(i);
  15304. if (code <= 0xff) {
  15305. data[length++] = code;
  15306. }
  15307. else {
  15308. data[length++] = code >>> 8;
  15309. data[length++] = code & 0xff;
  15310. }
  15311. }
  15312. } else if (input instanceof Uint8Array) {
  15313. data = input;
  15314. length = data.length;
  15315. } else if (typeof input === 'object' && ('length' in input)) {
  15316. // processing regular arrays as well, e.g. for IE9
  15317. data = input;
  15318. length = data.length;
  15319. useUint32ArrayView = true;
  15320. } else {
  15321. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  15322. 'Input must be a string or array.');
  15323. }
  15324. var blockCounts = length >> 2;
  15325. var tailLength = length - blockCounts * 4;
  15326. // we don't care about endianness here
  15327. var dataUint32 = useUint32ArrayView ?
  15328. new Uint32ArrayView(data, blockCounts) :
  15329. new Uint32Array(data.buffer, 0, blockCounts);
  15330. var k1 = 0;
  15331. var k2 = 0;
  15332. var h1 = this.h1;
  15333. var h2 = this.h2;
  15334. var C1 = 0xcc9e2d51;
  15335. var C2 = 0x1b873593;
  15336. var C1_LOW = C1 & MASK_LOW;
  15337. var C2_LOW = C2 & MASK_LOW;
  15338. for (i = 0; i < blockCounts; i++) {
  15339. if (i & 1) {
  15340. k1 = dataUint32[i];
  15341. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15342. k1 = k1 << 15 | k1 >>> 17;
  15343. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15344. h1 ^= k1;
  15345. h1 = h1 << 13 | h1 >>> 19;
  15346. h1 = h1 * 5 + 0xe6546b64;
  15347. } else {
  15348. k2 = dataUint32[i];
  15349. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  15350. k2 = k2 << 15 | k2 >>> 17;
  15351. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  15352. h2 ^= k2;
  15353. h2 = h2 << 13 | h2 >>> 19;
  15354. h2 = h2 * 5 + 0xe6546b64;
  15355. }
  15356. }
  15357. k1 = 0;
  15358. switch (tailLength) {
  15359. case 3:
  15360. k1 ^= data[blockCounts * 4 + 2] << 16;
  15361. /* falls through */
  15362. case 2:
  15363. k1 ^= data[blockCounts * 4 + 1] << 8;
  15364. /* falls through */
  15365. case 1:
  15366. k1 ^= data[blockCounts * 4];
  15367. /* falls through */
  15368. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  15369. k1 = k1 << 15 | k1 >>> 17;
  15370. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  15371. if (blockCounts & 1) {
  15372. h1 ^= k1;
  15373. } else {
  15374. h2 ^= k1;
  15375. }
  15376. }
  15377. this.h1 = h1;
  15378. this.h2 = h2;
  15379. return this;
  15380. },
  15381. hexdigest: function MurmurHash3_64_hexdigest () {
  15382. var h1 = this.h1;
  15383. var h2 = this.h2;
  15384. h1 ^= h2 >>> 1;
  15385. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  15386. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  15387. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  15388. h1 ^= h2 >>> 1;
  15389. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  15390. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  15391. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  15392. h1 ^= h2 >>> 1;
  15393. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  15394. var hex = (arr[i] >>> 0).toString(16);
  15395. while (hex.length < 8) {
  15396. hex = '0' + hex;
  15397. }
  15398. str += hex;
  15399. }
  15400. return str;
  15401. }
  15402. };
  15403. return MurmurHash3_64;
  15404. })();
  15405. exports.MurmurHash3_64 = MurmurHash3_64;
  15406. }));
  15407. (function (root, factory) {
  15408. {
  15409. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  15410. }
  15411. }(this, function (exports, sharedUtil) {
  15412. var isArray = sharedUtil.isArray;
  15413. var Name = (function NameClosure() {
  15414. function Name(name) {
  15415. this.name = name;
  15416. }
  15417. Name.prototype = {};
  15418. var nameCache = Object.create(null);
  15419. Name.get = function Name_get(name) {
  15420. var nameValue = nameCache[name];
  15421. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  15422. };
  15423. return Name;
  15424. })();
  15425. var Cmd = (function CmdClosure() {
  15426. function Cmd(cmd) {
  15427. this.cmd = cmd;
  15428. }
  15429. Cmd.prototype = {};
  15430. var cmdCache = Object.create(null);
  15431. Cmd.get = function Cmd_get(cmd) {
  15432. var cmdValue = cmdCache[cmd];
  15433. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  15434. };
  15435. return Cmd;
  15436. })();
  15437. var Dict = (function DictClosure() {
  15438. var nonSerializable = function nonSerializableClosure() {
  15439. return nonSerializable; // creating closure on some variable
  15440. };
  15441. var GETALL_DICTIONARY_TYPES_WHITELIST = {
  15442. 'Background': true,
  15443. 'ExtGState': true,
  15444. 'Halftone': true,
  15445. 'Layout': true,
  15446. 'Mask': true,
  15447. 'Pagination': true,
  15448. 'Printing': true
  15449. };
  15450. function isRecursionAllowedFor(dict) {
  15451. if (!isName(dict.Type)) {
  15452. return true;
  15453. }
  15454. var dictType = dict.Type.name;
  15455. return GETALL_DICTIONARY_TYPES_WHITELIST[dictType] === true;
  15456. }
  15457. // xref is optional
  15458. function Dict(xref) {
  15459. // Map should only be used internally, use functions below to access.
  15460. this.map = Object.create(null);
  15461. this.xref = xref;
  15462. this.objId = null;
  15463. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  15464. }
  15465. Dict.prototype = {
  15466. assignXref: function Dict_assignXref(newXref) {
  15467. this.xref = newXref;
  15468. },
  15469. // automatically dereferences Ref objects
  15470. get: function Dict_get(key1, key2, key3) {
  15471. var value;
  15472. var xref = this.xref;
  15473. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15474. typeof key2 === 'undefined') {
  15475. return xref ? xref.fetchIfRef(value) : value;
  15476. }
  15477. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15478. typeof key3 === 'undefined') {
  15479. return xref ? xref.fetchIfRef(value) : value;
  15480. }
  15481. value = this.map[key3] || null;
  15482. return xref ? xref.fetchIfRef(value) : value;
  15483. },
  15484. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  15485. getAsync: function Dict_getAsync(key1, key2, key3) {
  15486. var value;
  15487. var xref = this.xref;
  15488. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  15489. typeof key2 === 'undefined') {
  15490. if (xref) {
  15491. return xref.fetchIfRefAsync(value);
  15492. }
  15493. return Promise.resolve(value);
  15494. }
  15495. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  15496. typeof key3 === 'undefined') {
  15497. if (xref) {
  15498. return xref.fetchIfRefAsync(value);
  15499. }
  15500. return Promise.resolve(value);
  15501. }
  15502. value = this.map[key3] || null;
  15503. if (xref) {
  15504. return xref.fetchIfRefAsync(value);
  15505. }
  15506. return Promise.resolve(value);
  15507. },
  15508. // Same as get(), but dereferences all elements if the result is an Array.
  15509. getArray: function Dict_getArray(key1, key2, key3) {
  15510. var value = this.get(key1, key2, key3);
  15511. var xref = this.xref;
  15512. if (!isArray(value) || !xref) {
  15513. return value;
  15514. }
  15515. value = value.slice(); // Ensure that we don't modify the Dict data.
  15516. for (var i = 0, ii = value.length; i < ii; i++) {
  15517. if (!isRef(value[i])) {
  15518. continue;
  15519. }
  15520. value[i] = xref.fetch(value[i]);
  15521. }
  15522. return value;
  15523. },
  15524. // no dereferencing
  15525. getRaw: function Dict_getRaw(key) {
  15526. return this.map[key];
  15527. },
  15528. // creates new map and dereferences all Refs
  15529. getAll: function Dict_getAll() {
  15530. var all = Object.create(null);
  15531. var queue = null;
  15532. var key, obj;
  15533. for (key in this.map) {
  15534. obj = this.get(key);
  15535. if (obj instanceof Dict) {
  15536. if (isRecursionAllowedFor(obj)) {
  15537. (queue || (queue = [])).push({target: all, key: key, obj: obj});
  15538. } else {
  15539. all[key] = this.getRaw(key);
  15540. }
  15541. } else {
  15542. all[key] = obj;
  15543. }
  15544. }
  15545. if (!queue) {
  15546. return all;
  15547. }
  15548. // trying to take cyclic references into the account
  15549. var processed = Object.create(null);
  15550. while (queue.length > 0) {
  15551. var item = queue.shift();
  15552. var itemObj = item.obj;
  15553. var objId = itemObj.objId;
  15554. if (objId && objId in processed) {
  15555. item.target[item.key] = processed[objId];
  15556. continue;
  15557. }
  15558. var dereferenced = Object.create(null);
  15559. for (key in itemObj.map) {
  15560. obj = itemObj.get(key);
  15561. if (obj instanceof Dict) {
  15562. if (isRecursionAllowedFor(obj)) {
  15563. queue.push({target: dereferenced, key: key, obj: obj});
  15564. } else {
  15565. dereferenced[key] = itemObj.getRaw(key);
  15566. }
  15567. } else {
  15568. dereferenced[key] = obj;
  15569. }
  15570. }
  15571. if (objId) {
  15572. processed[objId] = dereferenced;
  15573. }
  15574. item.target[item.key] = dereferenced;
  15575. }
  15576. return all;
  15577. },
  15578. getKeys: function Dict_getKeys() {
  15579. return Object.keys(this.map);
  15580. },
  15581. set: function Dict_set(key, value) {
  15582. this.map[key] = value;
  15583. },
  15584. has: function Dict_has(key) {
  15585. return key in this.map;
  15586. },
  15587. forEach: function Dict_forEach(callback) {
  15588. for (var key in this.map) {
  15589. callback(key, this.get(key));
  15590. }
  15591. }
  15592. };
  15593. Dict.empty = new Dict(null);
  15594. Dict.merge = function Dict_merge(xref, dictArray) {
  15595. var mergedDict = new Dict(xref);
  15596. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  15597. var dict = dictArray[i];
  15598. if (!isDict(dict)) {
  15599. continue;
  15600. }
  15601. for (var keyName in dict.map) {
  15602. if (mergedDict.map[keyName]) {
  15603. continue;
  15604. }
  15605. mergedDict.map[keyName] = dict.map[keyName];
  15606. }
  15607. }
  15608. return mergedDict;
  15609. };
  15610. return Dict;
  15611. })();
  15612. var Ref = (function RefClosure() {
  15613. function Ref(num, gen) {
  15614. this.num = num;
  15615. this.gen = gen;
  15616. }
  15617. Ref.prototype = {
  15618. toString: function Ref_toString() {
  15619. // This function is hot, so we make the string as compact as possible.
  15620. // |this.gen| is almost always zero, so we treat that case specially.
  15621. var str = this.num + 'R';
  15622. if (this.gen !== 0) {
  15623. str += this.gen;
  15624. }
  15625. return str;
  15626. }
  15627. };
  15628. return Ref;
  15629. })();
  15630. // The reference is identified by number and generation.
  15631. // This structure stores only one instance of the reference.
  15632. var RefSet = (function RefSetClosure() {
  15633. function RefSet() {
  15634. this.dict = Object.create(null);
  15635. }
  15636. RefSet.prototype = {
  15637. has: function RefSet_has(ref) {
  15638. return ref.toString() in this.dict;
  15639. },
  15640. put: function RefSet_put(ref) {
  15641. this.dict[ref.toString()] = true;
  15642. },
  15643. remove: function RefSet_remove(ref) {
  15644. delete this.dict[ref.toString()];
  15645. }
  15646. };
  15647. return RefSet;
  15648. })();
  15649. var RefSetCache = (function RefSetCacheClosure() {
  15650. function RefSetCache() {
  15651. this.dict = Object.create(null);
  15652. }
  15653. RefSetCache.prototype = {
  15654. get: function RefSetCache_get(ref) {
  15655. return this.dict[ref.toString()];
  15656. },
  15657. has: function RefSetCache_has(ref) {
  15658. return ref.toString() in this.dict;
  15659. },
  15660. put: function RefSetCache_put(ref, obj) {
  15661. this.dict[ref.toString()] = obj;
  15662. },
  15663. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  15664. this.dict[ref.toString()] = this.get(aliasRef);
  15665. },
  15666. forEach: function RefSetCache_forEach(fn, thisArg) {
  15667. for (var i in this.dict) {
  15668. fn.call(thisArg, this.dict[i]);
  15669. }
  15670. },
  15671. clear: function RefSetCache_clear() {
  15672. this.dict = Object.create(null);
  15673. }
  15674. };
  15675. return RefSetCache;
  15676. })();
  15677. function isName(v) {
  15678. return v instanceof Name;
  15679. }
  15680. function isCmd(v, cmd) {
  15681. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  15682. }
  15683. function isDict(v, type) {
  15684. if (!(v instanceof Dict)) {
  15685. return false;
  15686. }
  15687. if (!type) {
  15688. return true;
  15689. }
  15690. var dictType = v.get('Type');
  15691. return isName(dictType) && dictType.name === type;
  15692. }
  15693. function isRef(v) {
  15694. return v instanceof Ref;
  15695. }
  15696. function isStream(v) {
  15697. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  15698. }
  15699. exports.Cmd = Cmd;
  15700. exports.Dict = Dict;
  15701. exports.Name = Name;
  15702. exports.Ref = Ref;
  15703. exports.RefSet = RefSet;
  15704. exports.RefSetCache = RefSetCache;
  15705. exports.isCmd = isCmd;
  15706. exports.isDict = isDict;
  15707. exports.isName = isName;
  15708. exports.isRef = isRef;
  15709. exports.isStream = isStream;
  15710. }));
  15711. (function (root, factory) {
  15712. {
  15713. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  15714. }
  15715. }(this, function (exports, sharedUtil) {
  15716. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  15717. /**
  15718. * Hold a map of decoded fonts and of the standard fourteen Type1
  15719. * fonts and their acronyms.
  15720. */
  15721. var getStdFontMap = getLookupTableFactory(function (t) {
  15722. t['ArialNarrow'] = 'Helvetica';
  15723. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  15724. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  15725. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  15726. t['ArialBlack'] = 'Helvetica';
  15727. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  15728. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  15729. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  15730. t['Arial'] = 'Helvetica';
  15731. t['Arial-Bold'] = 'Helvetica-Bold';
  15732. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  15733. t['Arial-Italic'] = 'Helvetica-Oblique';
  15734. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  15735. t['Arial-BoldMT'] = 'Helvetica-Bold';
  15736. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  15737. t['ArialMT'] = 'Helvetica';
  15738. t['Courier-Bold'] = 'Courier-Bold';
  15739. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  15740. t['Courier-Italic'] = 'Courier-Oblique';
  15741. t['CourierNew'] = 'Courier';
  15742. t['CourierNew-Bold'] = 'Courier-Bold';
  15743. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  15744. t['CourierNew-Italic'] = 'Courier-Oblique';
  15745. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  15746. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  15747. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  15748. t['CourierNewPSMT'] = 'Courier';
  15749. t['Helvetica'] = 'Helvetica';
  15750. t['Helvetica-Bold'] = 'Helvetica-Bold';
  15751. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  15752. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  15753. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  15754. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  15755. t['Symbol-Bold'] = 'Symbol';
  15756. t['Symbol-BoldItalic'] = 'Symbol';
  15757. t['Symbol-Italic'] = 'Symbol';
  15758. t['TimesNewRoman'] = 'Times-Roman';
  15759. t['TimesNewRoman-Bold'] = 'Times-Bold';
  15760. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  15761. t['TimesNewRoman-Italic'] = 'Times-Italic';
  15762. t['TimesNewRomanPS'] = 'Times-Roman';
  15763. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  15764. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  15765. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  15766. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  15767. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  15768. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  15769. t['TimesNewRomanPSMT'] = 'Times-Roman';
  15770. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  15771. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  15772. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  15773. });
  15774. /**
  15775. * Holds the map of the non-standard fonts that might be included as
  15776. * a standard fonts without glyph data.
  15777. */
  15778. var getNonStdFontMap = getLookupTableFactory(function (t) {
  15779. t['CenturyGothic'] = 'Helvetica';
  15780. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  15781. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  15782. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  15783. t['ComicSansMS'] = 'Comic Sans MS';
  15784. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  15785. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  15786. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  15787. t['LucidaConsole'] = 'Courier';
  15788. t['LucidaConsole-Bold'] = 'Courier-Bold';
  15789. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  15790. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  15791. t['MS-Gothic'] = 'MS Gothic';
  15792. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  15793. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  15794. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  15795. t['MS-Mincho'] = 'MS Mincho';
  15796. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  15797. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  15798. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  15799. t['MS-PGothic'] = 'MS PGothic';
  15800. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  15801. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  15802. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  15803. t['MS-PMincho'] = 'MS PMincho';
  15804. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  15805. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  15806. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  15807. t['Wingdings'] = 'ZapfDingbats';
  15808. });
  15809. var getSerifFonts = getLookupTableFactory(function (t) {
  15810. t['Adobe Jenson'] = true;
  15811. t['Adobe Text'] = true;
  15812. t['Albertus'] = true;
  15813. t['Aldus'] = true;
  15814. t['Alexandria'] = true;
  15815. t['Algerian'] = true;
  15816. t['American Typewriter'] = true;
  15817. t['Antiqua'] = true;
  15818. t['Apex'] = true;
  15819. t['Arno'] = true;
  15820. t['Aster'] = true;
  15821. t['Aurora'] = true;
  15822. t['Baskerville'] = true;
  15823. t['Bell'] = true;
  15824. t['Bembo'] = true;
  15825. t['Bembo Schoolbook'] = true;
  15826. t['Benguiat'] = true;
  15827. t['Berkeley Old Style'] = true;
  15828. t['Bernhard Modern'] = true;
  15829. t['Berthold City'] = true;
  15830. t['Bodoni'] = true;
  15831. t['Bauer Bodoni'] = true;
  15832. t['Book Antiqua'] = true;
  15833. t['Bookman'] = true;
  15834. t['Bordeaux Roman'] = true;
  15835. t['Californian FB'] = true;
  15836. t['Calisto'] = true;
  15837. t['Calvert'] = true;
  15838. t['Capitals'] = true;
  15839. t['Cambria'] = true;
  15840. t['Cartier'] = true;
  15841. t['Caslon'] = true;
  15842. t['Catull'] = true;
  15843. t['Centaur'] = true;
  15844. t['Century Old Style'] = true;
  15845. t['Century Schoolbook'] = true;
  15846. t['Chaparral'] = true;
  15847. t['Charis SIL'] = true;
  15848. t['Cheltenham'] = true;
  15849. t['Cholla Slab'] = true;
  15850. t['Clarendon'] = true;
  15851. t['Clearface'] = true;
  15852. t['Cochin'] = true;
  15853. t['Colonna'] = true;
  15854. t['Computer Modern'] = true;
  15855. t['Concrete Roman'] = true;
  15856. t['Constantia'] = true;
  15857. t['Cooper Black'] = true;
  15858. t['Corona'] = true;
  15859. t['Ecotype'] = true;
  15860. t['Egyptienne'] = true;
  15861. t['Elephant'] = true;
  15862. t['Excelsior'] = true;
  15863. t['Fairfield'] = true;
  15864. t['FF Scala'] = true;
  15865. t['Folkard'] = true;
  15866. t['Footlight'] = true;
  15867. t['FreeSerif'] = true;
  15868. t['Friz Quadrata'] = true;
  15869. t['Garamond'] = true;
  15870. t['Gentium'] = true;
  15871. t['Georgia'] = true;
  15872. t['Gloucester'] = true;
  15873. t['Goudy Old Style'] = true;
  15874. t['Goudy Schoolbook'] = true;
  15875. t['Goudy Pro Font'] = true;
  15876. t['Granjon'] = true;
  15877. t['Guardian Egyptian'] = true;
  15878. t['Heather'] = true;
  15879. t['Hercules'] = true;
  15880. t['High Tower Text'] = true;
  15881. t['Hiroshige'] = true;
  15882. t['Hoefler Text'] = true;
  15883. t['Humana Serif'] = true;
  15884. t['Imprint'] = true;
  15885. t['Ionic No. 5'] = true;
  15886. t['Janson'] = true;
  15887. t['Joanna'] = true;
  15888. t['Korinna'] = true;
  15889. t['Lexicon'] = true;
  15890. t['Liberation Serif'] = true;
  15891. t['Linux Libertine'] = true;
  15892. t['Literaturnaya'] = true;
  15893. t['Lucida'] = true;
  15894. t['Lucida Bright'] = true;
  15895. t['Melior'] = true;
  15896. t['Memphis'] = true;
  15897. t['Miller'] = true;
  15898. t['Minion'] = true;
  15899. t['Modern'] = true;
  15900. t['Mona Lisa'] = true;
  15901. t['Mrs Eaves'] = true;
  15902. t['MS Serif'] = true;
  15903. t['Museo Slab'] = true;
  15904. t['New York'] = true;
  15905. t['Nimbus Roman'] = true;
  15906. t['NPS Rawlinson Roadway'] = true;
  15907. t['Palatino'] = true;
  15908. t['Perpetua'] = true;
  15909. t['Plantin'] = true;
  15910. t['Plantin Schoolbook'] = true;
  15911. t['Playbill'] = true;
  15912. t['Poor Richard'] = true;
  15913. t['Rawlinson Roadway'] = true;
  15914. t['Renault'] = true;
  15915. t['Requiem'] = true;
  15916. t['Rockwell'] = true;
  15917. t['Roman'] = true;
  15918. t['Rotis Serif'] = true;
  15919. t['Sabon'] = true;
  15920. t['Scala'] = true;
  15921. t['Seagull'] = true;
  15922. t['Sistina'] = true;
  15923. t['Souvenir'] = true;
  15924. t['STIX'] = true;
  15925. t['Stone Informal'] = true;
  15926. t['Stone Serif'] = true;
  15927. t['Sylfaen'] = true;
  15928. t['Times'] = true;
  15929. t['Trajan'] = true;
  15930. t['Trinité'] = true;
  15931. t['Trump Mediaeval'] = true;
  15932. t['Utopia'] = true;
  15933. t['Vale Type'] = true;
  15934. t['Bitstream Vera'] = true;
  15935. t['Vera Serif'] = true;
  15936. t['Versailles'] = true;
  15937. t['Wanted'] = true;
  15938. t['Weiss'] = true;
  15939. t['Wide Latin'] = true;
  15940. t['Windsor'] = true;
  15941. t['XITS'] = true;
  15942. });
  15943. var getSymbolsFonts = getLookupTableFactory(function (t) {
  15944. t['Dingbats'] = true;
  15945. t['Symbol'] = true;
  15946. t['ZapfDingbats'] = true;
  15947. });
  15948. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  15949. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  15950. // for all glyphs, but common for some set of the standard fonts.
  15951. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  15952. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  15953. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  15954. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  15955. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  15956. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  15957. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  15958. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  15959. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  15960. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  15961. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  15962. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  15963. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  15964. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  15965. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  15966. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  15967. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  15968. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  15969. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  15970. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  15971. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  15972. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  15973. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  15974. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  15975. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  15976. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  15977. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  15978. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  15979. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  15980. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  15981. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  15982. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  15983. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  15984. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  15985. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  15986. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  15987. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  15988. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  15989. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  15990. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  15991. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  15992. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  15993. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  15994. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  15995. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  15996. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  15997. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  15998. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  15999. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  16000. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  16001. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  16002. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  16003. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  16004. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  16005. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  16006. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  16007. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  16008. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  16009. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  16010. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  16011. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  16012. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  16013. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  16014. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  16015. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  16016. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  16017. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  16018. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  16019. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  16020. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  16021. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  16022. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  16023. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  16024. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  16025. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  16026. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  16027. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  16028. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  16029. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  16030. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  16031. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  16032. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  16033. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  16034. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  16035. t[3416] = 8377;
  16036. });
  16037. // The glyph map for ArialBlack differs slightly from the glyph map used for
  16038. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  16039. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  16040. var getSupplementalGlyphMapForArialBlack =
  16041. getLookupTableFactory(function (t) {
  16042. t[227] = 322; t[264] = 261; t[291] = 346;
  16043. });
  16044. exports.getStdFontMap = getStdFontMap;
  16045. exports.getNonStdFontMap = getNonStdFontMap;
  16046. exports.getSerifFonts = getSerifFonts;
  16047. exports.getSymbolsFonts = getSymbolsFonts;
  16048. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  16049. exports.getSupplementalGlyphMapForArialBlack =
  16050. getSupplementalGlyphMapForArialBlack;
  16051. }));
  16052. (function (root, factory) {
  16053. {
  16054. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  16055. }
  16056. }(this, function (exports, sharedUtil) {
  16057. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  16058. // Some characters, e.g. copyrightserif, are mapped to the private use area
  16059. // and might not be displayed using standard fonts. Mapping/hacking well-known
  16060. // chars to the similar equivalents in the normal characters range.
  16061. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  16062. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  16063. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  16064. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  16065. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  16066. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  16067. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  16068. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  16069. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  16070. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  16071. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  16072. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  16073. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  16074. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  16075. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  16076. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  16077. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  16078. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  16079. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  16080. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  16081. t[63724] = 0x239C; // parenleftex (0xF8EC)
  16082. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  16083. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  16084. t[63735] = 0x239F; // parenrightex (0xF8F7)
  16085. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  16086. });
  16087. function mapSpecialUnicodeValues(code) {
  16088. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  16089. return 0;
  16090. } else if (code >= 0xF600 && code <= 0xF8FF) {
  16091. return (getSpecialPUASymbols()[code] || code);
  16092. }
  16093. return code;
  16094. }
  16095. var UnicodeRanges = [
  16096. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  16097. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  16098. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  16099. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  16100. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  16101. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  16102. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  16103. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  16104. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  16105. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  16106. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  16107. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  16108. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  16109. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  16110. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  16111. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  16112. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  16113. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  16114. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  16115. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  16116. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  16117. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  16118. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  16119. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  16120. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  16121. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  16122. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  16123. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  16124. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  16125. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  16126. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  16127. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  16128. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  16129. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  16130. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  16131. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  16132. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  16133. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  16134. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  16135. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  16136. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  16137. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  16138. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  16139. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  16140. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  16141. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  16142. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  16143. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  16144. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  16145. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  16146. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  16147. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  16148. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  16149. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  16150. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  16151. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  16152. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  16153. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  16154. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  16155. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  16156. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  16157. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  16158. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  16159. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  16160. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  16161. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  16162. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  16163. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  16164. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  16165. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  16166. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  16167. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  16168. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  16169. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  16170. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  16171. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  16172. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  16173. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  16174. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  16175. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  16176. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  16177. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  16178. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  16179. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  16180. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  16181. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  16182. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  16183. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  16184. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  16185. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  16186. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  16187. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  16188. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  16189. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  16190. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  16191. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  16192. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  16193. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  16194. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  16195. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  16196. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  16197. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  16198. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  16199. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  16200. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  16201. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  16202. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  16203. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  16204. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  16205. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  16206. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  16207. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  16208. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  16209. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  16210. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  16211. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  16212. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  16213. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  16214. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  16215. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  16216. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  16217. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  16218. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  16219. ];
  16220. function getUnicodeRangeFor(value) {
  16221. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  16222. var range = UnicodeRanges[i];
  16223. if (value >= range.begin && value < range.end) {
  16224. return i;
  16225. }
  16226. }
  16227. return -1;
  16228. }
  16229. function isRTLRangeFor(value) {
  16230. var range = UnicodeRanges[13];
  16231. if (value >= range.begin && value < range.end) {
  16232. return true;
  16233. }
  16234. range = UnicodeRanges[11];
  16235. if (value >= range.begin && value < range.end) {
  16236. return true;
  16237. }
  16238. return false;
  16239. }
  16240. // The normalization table is obtained by filtering the Unicode characters
  16241. // database with <compat> entries.
  16242. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  16243. t['\u00A8'] = '\u0020\u0308';
  16244. t['\u00AF'] = '\u0020\u0304';
  16245. t['\u00B4'] = '\u0020\u0301';
  16246. t['\u00B5'] = '\u03BC';
  16247. t['\u00B8'] = '\u0020\u0327';
  16248. t['\u0132'] = '\u0049\u004A';
  16249. t['\u0133'] = '\u0069\u006A';
  16250. t['\u013F'] = '\u004C\u00B7';
  16251. t['\u0140'] = '\u006C\u00B7';
  16252. t['\u0149'] = '\u02BC\u006E';
  16253. t['\u017F'] = '\u0073';
  16254. t['\u01C4'] = '\u0044\u017D';
  16255. t['\u01C5'] = '\u0044\u017E';
  16256. t['\u01C6'] = '\u0064\u017E';
  16257. t['\u01C7'] = '\u004C\u004A';
  16258. t['\u01C8'] = '\u004C\u006A';
  16259. t['\u01C9'] = '\u006C\u006A';
  16260. t['\u01CA'] = '\u004E\u004A';
  16261. t['\u01CB'] = '\u004E\u006A';
  16262. t['\u01CC'] = '\u006E\u006A';
  16263. t['\u01F1'] = '\u0044\u005A';
  16264. t['\u01F2'] = '\u0044\u007A';
  16265. t['\u01F3'] = '\u0064\u007A';
  16266. t['\u02D8'] = '\u0020\u0306';
  16267. t['\u02D9'] = '\u0020\u0307';
  16268. t['\u02DA'] = '\u0020\u030A';
  16269. t['\u02DB'] = '\u0020\u0328';
  16270. t['\u02DC'] = '\u0020\u0303';
  16271. t['\u02DD'] = '\u0020\u030B';
  16272. t['\u037A'] = '\u0020\u0345';
  16273. t['\u0384'] = '\u0020\u0301';
  16274. t['\u03D0'] = '\u03B2';
  16275. t['\u03D1'] = '\u03B8';
  16276. t['\u03D2'] = '\u03A5';
  16277. t['\u03D5'] = '\u03C6';
  16278. t['\u03D6'] = '\u03C0';
  16279. t['\u03F0'] = '\u03BA';
  16280. t['\u03F1'] = '\u03C1';
  16281. t['\u03F2'] = '\u03C2';
  16282. t['\u03F4'] = '\u0398';
  16283. t['\u03F5'] = '\u03B5';
  16284. t['\u03F9'] = '\u03A3';
  16285. t['\u0587'] = '\u0565\u0582';
  16286. t['\u0675'] = '\u0627\u0674';
  16287. t['\u0676'] = '\u0648\u0674';
  16288. t['\u0677'] = '\u06C7\u0674';
  16289. t['\u0678'] = '\u064A\u0674';
  16290. t['\u0E33'] = '\u0E4D\u0E32';
  16291. t['\u0EB3'] = '\u0ECD\u0EB2';
  16292. t['\u0EDC'] = '\u0EAB\u0E99';
  16293. t['\u0EDD'] = '\u0EAB\u0EA1';
  16294. t['\u0F77'] = '\u0FB2\u0F81';
  16295. t['\u0F79'] = '\u0FB3\u0F81';
  16296. t['\u1E9A'] = '\u0061\u02BE';
  16297. t['\u1FBD'] = '\u0020\u0313';
  16298. t['\u1FBF'] = '\u0020\u0313';
  16299. t['\u1FC0'] = '\u0020\u0342';
  16300. t['\u1FFE'] = '\u0020\u0314';
  16301. t['\u2002'] = '\u0020';
  16302. t['\u2003'] = '\u0020';
  16303. t['\u2004'] = '\u0020';
  16304. t['\u2005'] = '\u0020';
  16305. t['\u2006'] = '\u0020';
  16306. t['\u2008'] = '\u0020';
  16307. t['\u2009'] = '\u0020';
  16308. t['\u200A'] = '\u0020';
  16309. t['\u2017'] = '\u0020\u0333';
  16310. t['\u2024'] = '\u002E';
  16311. t['\u2025'] = '\u002E\u002E';
  16312. t['\u2026'] = '\u002E\u002E\u002E';
  16313. t['\u2033'] = '\u2032\u2032';
  16314. t['\u2034'] = '\u2032\u2032\u2032';
  16315. t['\u2036'] = '\u2035\u2035';
  16316. t['\u2037'] = '\u2035\u2035\u2035';
  16317. t['\u203C'] = '\u0021\u0021';
  16318. t['\u203E'] = '\u0020\u0305';
  16319. t['\u2047'] = '\u003F\u003F';
  16320. t['\u2048'] = '\u003F\u0021';
  16321. t['\u2049'] = '\u0021\u003F';
  16322. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  16323. t['\u205F'] = '\u0020';
  16324. t['\u20A8'] = '\u0052\u0073';
  16325. t['\u2100'] = '\u0061\u002F\u0063';
  16326. t['\u2101'] = '\u0061\u002F\u0073';
  16327. t['\u2103'] = '\u00B0\u0043';
  16328. t['\u2105'] = '\u0063\u002F\u006F';
  16329. t['\u2106'] = '\u0063\u002F\u0075';
  16330. t['\u2107'] = '\u0190';
  16331. t['\u2109'] = '\u00B0\u0046';
  16332. t['\u2116'] = '\u004E\u006F';
  16333. t['\u2121'] = '\u0054\u0045\u004C';
  16334. t['\u2135'] = '\u05D0';
  16335. t['\u2136'] = '\u05D1';
  16336. t['\u2137'] = '\u05D2';
  16337. t['\u2138'] = '\u05D3';
  16338. t['\u213B'] = '\u0046\u0041\u0058';
  16339. t['\u2160'] = '\u0049';
  16340. t['\u2161'] = '\u0049\u0049';
  16341. t['\u2162'] = '\u0049\u0049\u0049';
  16342. t['\u2163'] = '\u0049\u0056';
  16343. t['\u2164'] = '\u0056';
  16344. t['\u2165'] = '\u0056\u0049';
  16345. t['\u2166'] = '\u0056\u0049\u0049';
  16346. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  16347. t['\u2168'] = '\u0049\u0058';
  16348. t['\u2169'] = '\u0058';
  16349. t['\u216A'] = '\u0058\u0049';
  16350. t['\u216B'] = '\u0058\u0049\u0049';
  16351. t['\u216C'] = '\u004C';
  16352. t['\u216D'] = '\u0043';
  16353. t['\u216E'] = '\u0044';
  16354. t['\u216F'] = '\u004D';
  16355. t['\u2170'] = '\u0069';
  16356. t['\u2171'] = '\u0069\u0069';
  16357. t['\u2172'] = '\u0069\u0069\u0069';
  16358. t['\u2173'] = '\u0069\u0076';
  16359. t['\u2174'] = '\u0076';
  16360. t['\u2175'] = '\u0076\u0069';
  16361. t['\u2176'] = '\u0076\u0069\u0069';
  16362. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  16363. t['\u2178'] = '\u0069\u0078';
  16364. t['\u2179'] = '\u0078';
  16365. t['\u217A'] = '\u0078\u0069';
  16366. t['\u217B'] = '\u0078\u0069\u0069';
  16367. t['\u217C'] = '\u006C';
  16368. t['\u217D'] = '\u0063';
  16369. t['\u217E'] = '\u0064';
  16370. t['\u217F'] = '\u006D';
  16371. t['\u222C'] = '\u222B\u222B';
  16372. t['\u222D'] = '\u222B\u222B\u222B';
  16373. t['\u222F'] = '\u222E\u222E';
  16374. t['\u2230'] = '\u222E\u222E\u222E';
  16375. t['\u2474'] = '\u0028\u0031\u0029';
  16376. t['\u2475'] = '\u0028\u0032\u0029';
  16377. t['\u2476'] = '\u0028\u0033\u0029';
  16378. t['\u2477'] = '\u0028\u0034\u0029';
  16379. t['\u2478'] = '\u0028\u0035\u0029';
  16380. t['\u2479'] = '\u0028\u0036\u0029';
  16381. t['\u247A'] = '\u0028\u0037\u0029';
  16382. t['\u247B'] = '\u0028\u0038\u0029';
  16383. t['\u247C'] = '\u0028\u0039\u0029';
  16384. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  16385. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  16386. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  16387. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  16388. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  16389. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  16390. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  16391. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  16392. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  16393. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  16394. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  16395. t['\u2488'] = '\u0031\u002E';
  16396. t['\u2489'] = '\u0032\u002E';
  16397. t['\u248A'] = '\u0033\u002E';
  16398. t['\u248B'] = '\u0034\u002E';
  16399. t['\u248C'] = '\u0035\u002E';
  16400. t['\u248D'] = '\u0036\u002E';
  16401. t['\u248E'] = '\u0037\u002E';
  16402. t['\u248F'] = '\u0038\u002E';
  16403. t['\u2490'] = '\u0039\u002E';
  16404. t['\u2491'] = '\u0031\u0030\u002E';
  16405. t['\u2492'] = '\u0031\u0031\u002E';
  16406. t['\u2493'] = '\u0031\u0032\u002E';
  16407. t['\u2494'] = '\u0031\u0033\u002E';
  16408. t['\u2495'] = '\u0031\u0034\u002E';
  16409. t['\u2496'] = '\u0031\u0035\u002E';
  16410. t['\u2497'] = '\u0031\u0036\u002E';
  16411. t['\u2498'] = '\u0031\u0037\u002E';
  16412. t['\u2499'] = '\u0031\u0038\u002E';
  16413. t['\u249A'] = '\u0031\u0039\u002E';
  16414. t['\u249B'] = '\u0032\u0030\u002E';
  16415. t['\u249C'] = '\u0028\u0061\u0029';
  16416. t['\u249D'] = '\u0028\u0062\u0029';
  16417. t['\u249E'] = '\u0028\u0063\u0029';
  16418. t['\u249F'] = '\u0028\u0064\u0029';
  16419. t['\u24A0'] = '\u0028\u0065\u0029';
  16420. t['\u24A1'] = '\u0028\u0066\u0029';
  16421. t['\u24A2'] = '\u0028\u0067\u0029';
  16422. t['\u24A3'] = '\u0028\u0068\u0029';
  16423. t['\u24A4'] = '\u0028\u0069\u0029';
  16424. t['\u24A5'] = '\u0028\u006A\u0029';
  16425. t['\u24A6'] = '\u0028\u006B\u0029';
  16426. t['\u24A7'] = '\u0028\u006C\u0029';
  16427. t['\u24A8'] = '\u0028\u006D\u0029';
  16428. t['\u24A9'] = '\u0028\u006E\u0029';
  16429. t['\u24AA'] = '\u0028\u006F\u0029';
  16430. t['\u24AB'] = '\u0028\u0070\u0029';
  16431. t['\u24AC'] = '\u0028\u0071\u0029';
  16432. t['\u24AD'] = '\u0028\u0072\u0029';
  16433. t['\u24AE'] = '\u0028\u0073\u0029';
  16434. t['\u24AF'] = '\u0028\u0074\u0029';
  16435. t['\u24B0'] = '\u0028\u0075\u0029';
  16436. t['\u24B1'] = '\u0028\u0076\u0029';
  16437. t['\u24B2'] = '\u0028\u0077\u0029';
  16438. t['\u24B3'] = '\u0028\u0078\u0029';
  16439. t['\u24B4'] = '\u0028\u0079\u0029';
  16440. t['\u24B5'] = '\u0028\u007A\u0029';
  16441. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  16442. t['\u2A74'] = '\u003A\u003A\u003D';
  16443. t['\u2A75'] = '\u003D\u003D';
  16444. t['\u2A76'] = '\u003D\u003D\u003D';
  16445. t['\u2E9F'] = '\u6BCD';
  16446. t['\u2EF3'] = '\u9F9F';
  16447. t['\u2F00'] = '\u4E00';
  16448. t['\u2F01'] = '\u4E28';
  16449. t['\u2F02'] = '\u4E36';
  16450. t['\u2F03'] = '\u4E3F';
  16451. t['\u2F04'] = '\u4E59';
  16452. t['\u2F05'] = '\u4E85';
  16453. t['\u2F06'] = '\u4E8C';
  16454. t['\u2F07'] = '\u4EA0';
  16455. t['\u2F08'] = '\u4EBA';
  16456. t['\u2F09'] = '\u513F';
  16457. t['\u2F0A'] = '\u5165';
  16458. t['\u2F0B'] = '\u516B';
  16459. t['\u2F0C'] = '\u5182';
  16460. t['\u2F0D'] = '\u5196';
  16461. t['\u2F0E'] = '\u51AB';
  16462. t['\u2F0F'] = '\u51E0';
  16463. t['\u2F10'] = '\u51F5';
  16464. t['\u2F11'] = '\u5200';
  16465. t['\u2F12'] = '\u529B';
  16466. t['\u2F13'] = '\u52F9';
  16467. t['\u2F14'] = '\u5315';
  16468. t['\u2F15'] = '\u531A';
  16469. t['\u2F16'] = '\u5338';
  16470. t['\u2F17'] = '\u5341';
  16471. t['\u2F18'] = '\u535C';
  16472. t['\u2F19'] = '\u5369';
  16473. t['\u2F1A'] = '\u5382';
  16474. t['\u2F1B'] = '\u53B6';
  16475. t['\u2F1C'] = '\u53C8';
  16476. t['\u2F1D'] = '\u53E3';
  16477. t['\u2F1E'] = '\u56D7';
  16478. t['\u2F1F'] = '\u571F';
  16479. t['\u2F20'] = '\u58EB';
  16480. t['\u2F21'] = '\u5902';
  16481. t['\u2F22'] = '\u590A';
  16482. t['\u2F23'] = '\u5915';
  16483. t['\u2F24'] = '\u5927';
  16484. t['\u2F25'] = '\u5973';
  16485. t['\u2F26'] = '\u5B50';
  16486. t['\u2F27'] = '\u5B80';
  16487. t['\u2F28'] = '\u5BF8';
  16488. t['\u2F29'] = '\u5C0F';
  16489. t['\u2F2A'] = '\u5C22';
  16490. t['\u2F2B'] = '\u5C38';
  16491. t['\u2F2C'] = '\u5C6E';
  16492. t['\u2F2D'] = '\u5C71';
  16493. t['\u2F2E'] = '\u5DDB';
  16494. t['\u2F2F'] = '\u5DE5';
  16495. t['\u2F30'] = '\u5DF1';
  16496. t['\u2F31'] = '\u5DFE';
  16497. t['\u2F32'] = '\u5E72';
  16498. t['\u2F33'] = '\u5E7A';
  16499. t['\u2F34'] = '\u5E7F';
  16500. t['\u2F35'] = '\u5EF4';
  16501. t['\u2F36'] = '\u5EFE';
  16502. t['\u2F37'] = '\u5F0B';
  16503. t['\u2F38'] = '\u5F13';
  16504. t['\u2F39'] = '\u5F50';
  16505. t['\u2F3A'] = '\u5F61';
  16506. t['\u2F3B'] = '\u5F73';
  16507. t['\u2F3C'] = '\u5FC3';
  16508. t['\u2F3D'] = '\u6208';
  16509. t['\u2F3E'] = '\u6236';
  16510. t['\u2F3F'] = '\u624B';
  16511. t['\u2F40'] = '\u652F';
  16512. t['\u2F41'] = '\u6534';
  16513. t['\u2F42'] = '\u6587';
  16514. t['\u2F43'] = '\u6597';
  16515. t['\u2F44'] = '\u65A4';
  16516. t['\u2F45'] = '\u65B9';
  16517. t['\u2F46'] = '\u65E0';
  16518. t['\u2F47'] = '\u65E5';
  16519. t['\u2F48'] = '\u66F0';
  16520. t['\u2F49'] = '\u6708';
  16521. t['\u2F4A'] = '\u6728';
  16522. t['\u2F4B'] = '\u6B20';
  16523. t['\u2F4C'] = '\u6B62';
  16524. t['\u2F4D'] = '\u6B79';
  16525. t['\u2F4E'] = '\u6BB3';
  16526. t['\u2F4F'] = '\u6BCB';
  16527. t['\u2F50'] = '\u6BD4';
  16528. t['\u2F51'] = '\u6BDB';
  16529. t['\u2F52'] = '\u6C0F';
  16530. t['\u2F53'] = '\u6C14';
  16531. t['\u2F54'] = '\u6C34';
  16532. t['\u2F55'] = '\u706B';
  16533. t['\u2F56'] = '\u722A';
  16534. t['\u2F57'] = '\u7236';
  16535. t['\u2F58'] = '\u723B';
  16536. t['\u2F59'] = '\u723F';
  16537. t['\u2F5A'] = '\u7247';
  16538. t['\u2F5B'] = '\u7259';
  16539. t['\u2F5C'] = '\u725B';
  16540. t['\u2F5D'] = '\u72AC';
  16541. t['\u2F5E'] = '\u7384';
  16542. t['\u2F5F'] = '\u7389';
  16543. t['\u2F60'] = '\u74DC';
  16544. t['\u2F61'] = '\u74E6';
  16545. t['\u2F62'] = '\u7518';
  16546. t['\u2F63'] = '\u751F';
  16547. t['\u2F64'] = '\u7528';
  16548. t['\u2F65'] = '\u7530';
  16549. t['\u2F66'] = '\u758B';
  16550. t['\u2F67'] = '\u7592';
  16551. t['\u2F68'] = '\u7676';
  16552. t['\u2F69'] = '\u767D';
  16553. t['\u2F6A'] = '\u76AE';
  16554. t['\u2F6B'] = '\u76BF';
  16555. t['\u2F6C'] = '\u76EE';
  16556. t['\u2F6D'] = '\u77DB';
  16557. t['\u2F6E'] = '\u77E2';
  16558. t['\u2F6F'] = '\u77F3';
  16559. t['\u2F70'] = '\u793A';
  16560. t['\u2F71'] = '\u79B8';
  16561. t['\u2F72'] = '\u79BE';
  16562. t['\u2F73'] = '\u7A74';
  16563. t['\u2F74'] = '\u7ACB';
  16564. t['\u2F75'] = '\u7AF9';
  16565. t['\u2F76'] = '\u7C73';
  16566. t['\u2F77'] = '\u7CF8';
  16567. t['\u2F78'] = '\u7F36';
  16568. t['\u2F79'] = '\u7F51';
  16569. t['\u2F7A'] = '\u7F8A';
  16570. t['\u2F7B'] = '\u7FBD';
  16571. t['\u2F7C'] = '\u8001';
  16572. t['\u2F7D'] = '\u800C';
  16573. t['\u2F7E'] = '\u8012';
  16574. t['\u2F7F'] = '\u8033';
  16575. t['\u2F80'] = '\u807F';
  16576. t['\u2F81'] = '\u8089';
  16577. t['\u2F82'] = '\u81E3';
  16578. t['\u2F83'] = '\u81EA';
  16579. t['\u2F84'] = '\u81F3';
  16580. t['\u2F85'] = '\u81FC';
  16581. t['\u2F86'] = '\u820C';
  16582. t['\u2F87'] = '\u821B';
  16583. t['\u2F88'] = '\u821F';
  16584. t['\u2F89'] = '\u826E';
  16585. t['\u2F8A'] = '\u8272';
  16586. t['\u2F8B'] = '\u8278';
  16587. t['\u2F8C'] = '\u864D';
  16588. t['\u2F8D'] = '\u866B';
  16589. t['\u2F8E'] = '\u8840';
  16590. t['\u2F8F'] = '\u884C';
  16591. t['\u2F90'] = '\u8863';
  16592. t['\u2F91'] = '\u897E';
  16593. t['\u2F92'] = '\u898B';
  16594. t['\u2F93'] = '\u89D2';
  16595. t['\u2F94'] = '\u8A00';
  16596. t['\u2F95'] = '\u8C37';
  16597. t['\u2F96'] = '\u8C46';
  16598. t['\u2F97'] = '\u8C55';
  16599. t['\u2F98'] = '\u8C78';
  16600. t['\u2F99'] = '\u8C9D';
  16601. t['\u2F9A'] = '\u8D64';
  16602. t['\u2F9B'] = '\u8D70';
  16603. t['\u2F9C'] = '\u8DB3';
  16604. t['\u2F9D'] = '\u8EAB';
  16605. t['\u2F9E'] = '\u8ECA';
  16606. t['\u2F9F'] = '\u8F9B';
  16607. t['\u2FA0'] = '\u8FB0';
  16608. t['\u2FA1'] = '\u8FB5';
  16609. t['\u2FA2'] = '\u9091';
  16610. t['\u2FA3'] = '\u9149';
  16611. t['\u2FA4'] = '\u91C6';
  16612. t['\u2FA5'] = '\u91CC';
  16613. t['\u2FA6'] = '\u91D1';
  16614. t['\u2FA7'] = '\u9577';
  16615. t['\u2FA8'] = '\u9580';
  16616. t['\u2FA9'] = '\u961C';
  16617. t['\u2FAA'] = '\u96B6';
  16618. t['\u2FAB'] = '\u96B9';
  16619. t['\u2FAC'] = '\u96E8';
  16620. t['\u2FAD'] = '\u9751';
  16621. t['\u2FAE'] = '\u975E';
  16622. t['\u2FAF'] = '\u9762';
  16623. t['\u2FB0'] = '\u9769';
  16624. t['\u2FB1'] = '\u97CB';
  16625. t['\u2FB2'] = '\u97ED';
  16626. t['\u2FB3'] = '\u97F3';
  16627. t['\u2FB4'] = '\u9801';
  16628. t['\u2FB5'] = '\u98A8';
  16629. t['\u2FB6'] = '\u98DB';
  16630. t['\u2FB7'] = '\u98DF';
  16631. t['\u2FB8'] = '\u9996';
  16632. t['\u2FB9'] = '\u9999';
  16633. t['\u2FBA'] = '\u99AC';
  16634. t['\u2FBB'] = '\u9AA8';
  16635. t['\u2FBC'] = '\u9AD8';
  16636. t['\u2FBD'] = '\u9ADF';
  16637. t['\u2FBE'] = '\u9B25';
  16638. t['\u2FBF'] = '\u9B2F';
  16639. t['\u2FC0'] = '\u9B32';
  16640. t['\u2FC1'] = '\u9B3C';
  16641. t['\u2FC2'] = '\u9B5A';
  16642. t['\u2FC3'] = '\u9CE5';
  16643. t['\u2FC4'] = '\u9E75';
  16644. t['\u2FC5'] = '\u9E7F';
  16645. t['\u2FC6'] = '\u9EA5';
  16646. t['\u2FC7'] = '\u9EBB';
  16647. t['\u2FC8'] = '\u9EC3';
  16648. t['\u2FC9'] = '\u9ECD';
  16649. t['\u2FCA'] = '\u9ED1';
  16650. t['\u2FCB'] = '\u9EF9';
  16651. t['\u2FCC'] = '\u9EFD';
  16652. t['\u2FCD'] = '\u9F0E';
  16653. t['\u2FCE'] = '\u9F13';
  16654. t['\u2FCF'] = '\u9F20';
  16655. t['\u2FD0'] = '\u9F3B';
  16656. t['\u2FD1'] = '\u9F4A';
  16657. t['\u2FD2'] = '\u9F52';
  16658. t['\u2FD3'] = '\u9F8D';
  16659. t['\u2FD4'] = '\u9F9C';
  16660. t['\u2FD5'] = '\u9FA0';
  16661. t['\u3036'] = '\u3012';
  16662. t['\u3038'] = '\u5341';
  16663. t['\u3039'] = '\u5344';
  16664. t['\u303A'] = '\u5345';
  16665. t['\u309B'] = '\u0020\u3099';
  16666. t['\u309C'] = '\u0020\u309A';
  16667. t['\u3131'] = '\u1100';
  16668. t['\u3132'] = '\u1101';
  16669. t['\u3133'] = '\u11AA';
  16670. t['\u3134'] = '\u1102';
  16671. t['\u3135'] = '\u11AC';
  16672. t['\u3136'] = '\u11AD';
  16673. t['\u3137'] = '\u1103';
  16674. t['\u3138'] = '\u1104';
  16675. t['\u3139'] = '\u1105';
  16676. t['\u313A'] = '\u11B0';
  16677. t['\u313B'] = '\u11B1';
  16678. t['\u313C'] = '\u11B2';
  16679. t['\u313D'] = '\u11B3';
  16680. t['\u313E'] = '\u11B4';
  16681. t['\u313F'] = '\u11B5';
  16682. t['\u3140'] = '\u111A';
  16683. t['\u3141'] = '\u1106';
  16684. t['\u3142'] = '\u1107';
  16685. t['\u3143'] = '\u1108';
  16686. t['\u3144'] = '\u1121';
  16687. t['\u3145'] = '\u1109';
  16688. t['\u3146'] = '\u110A';
  16689. t['\u3147'] = '\u110B';
  16690. t['\u3148'] = '\u110C';
  16691. t['\u3149'] = '\u110D';
  16692. t['\u314A'] = '\u110E';
  16693. t['\u314B'] = '\u110F';
  16694. t['\u314C'] = '\u1110';
  16695. t['\u314D'] = '\u1111';
  16696. t['\u314E'] = '\u1112';
  16697. t['\u314F'] = '\u1161';
  16698. t['\u3150'] = '\u1162';
  16699. t['\u3151'] = '\u1163';
  16700. t['\u3152'] = '\u1164';
  16701. t['\u3153'] = '\u1165';
  16702. t['\u3154'] = '\u1166';
  16703. t['\u3155'] = '\u1167';
  16704. t['\u3156'] = '\u1168';
  16705. t['\u3157'] = '\u1169';
  16706. t['\u3158'] = '\u116A';
  16707. t['\u3159'] = '\u116B';
  16708. t['\u315A'] = '\u116C';
  16709. t['\u315B'] = '\u116D';
  16710. t['\u315C'] = '\u116E';
  16711. t['\u315D'] = '\u116F';
  16712. t['\u315E'] = '\u1170';
  16713. t['\u315F'] = '\u1171';
  16714. t['\u3160'] = '\u1172';
  16715. t['\u3161'] = '\u1173';
  16716. t['\u3162'] = '\u1174';
  16717. t['\u3163'] = '\u1175';
  16718. t['\u3164'] = '\u1160';
  16719. t['\u3165'] = '\u1114';
  16720. t['\u3166'] = '\u1115';
  16721. t['\u3167'] = '\u11C7';
  16722. t['\u3168'] = '\u11C8';
  16723. t['\u3169'] = '\u11CC';
  16724. t['\u316A'] = '\u11CE';
  16725. t['\u316B'] = '\u11D3';
  16726. t['\u316C'] = '\u11D7';
  16727. t['\u316D'] = '\u11D9';
  16728. t['\u316E'] = '\u111C';
  16729. t['\u316F'] = '\u11DD';
  16730. t['\u3170'] = '\u11DF';
  16731. t['\u3171'] = '\u111D';
  16732. t['\u3172'] = '\u111E';
  16733. t['\u3173'] = '\u1120';
  16734. t['\u3174'] = '\u1122';
  16735. t['\u3175'] = '\u1123';
  16736. t['\u3176'] = '\u1127';
  16737. t['\u3177'] = '\u1129';
  16738. t['\u3178'] = '\u112B';
  16739. t['\u3179'] = '\u112C';
  16740. t['\u317A'] = '\u112D';
  16741. t['\u317B'] = '\u112E';
  16742. t['\u317C'] = '\u112F';
  16743. t['\u317D'] = '\u1132';
  16744. t['\u317E'] = '\u1136';
  16745. t['\u317F'] = '\u1140';
  16746. t['\u3180'] = '\u1147';
  16747. t['\u3181'] = '\u114C';
  16748. t['\u3182'] = '\u11F1';
  16749. t['\u3183'] = '\u11F2';
  16750. t['\u3184'] = '\u1157';
  16751. t['\u3185'] = '\u1158';
  16752. t['\u3186'] = '\u1159';
  16753. t['\u3187'] = '\u1184';
  16754. t['\u3188'] = '\u1185';
  16755. t['\u3189'] = '\u1188';
  16756. t['\u318A'] = '\u1191';
  16757. t['\u318B'] = '\u1192';
  16758. t['\u318C'] = '\u1194';
  16759. t['\u318D'] = '\u119E';
  16760. t['\u318E'] = '\u11A1';
  16761. t['\u3200'] = '\u0028\u1100\u0029';
  16762. t['\u3201'] = '\u0028\u1102\u0029';
  16763. t['\u3202'] = '\u0028\u1103\u0029';
  16764. t['\u3203'] = '\u0028\u1105\u0029';
  16765. t['\u3204'] = '\u0028\u1106\u0029';
  16766. t['\u3205'] = '\u0028\u1107\u0029';
  16767. t['\u3206'] = '\u0028\u1109\u0029';
  16768. t['\u3207'] = '\u0028\u110B\u0029';
  16769. t['\u3208'] = '\u0028\u110C\u0029';
  16770. t['\u3209'] = '\u0028\u110E\u0029';
  16771. t['\u320A'] = '\u0028\u110F\u0029';
  16772. t['\u320B'] = '\u0028\u1110\u0029';
  16773. t['\u320C'] = '\u0028\u1111\u0029';
  16774. t['\u320D'] = '\u0028\u1112\u0029';
  16775. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  16776. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  16777. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  16778. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  16779. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  16780. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  16781. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  16782. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  16783. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  16784. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  16785. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  16786. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  16787. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  16788. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  16789. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  16790. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  16791. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  16792. t['\u3220'] = '\u0028\u4E00\u0029';
  16793. t['\u3221'] = '\u0028\u4E8C\u0029';
  16794. t['\u3222'] = '\u0028\u4E09\u0029';
  16795. t['\u3223'] = '\u0028\u56DB\u0029';
  16796. t['\u3224'] = '\u0028\u4E94\u0029';
  16797. t['\u3225'] = '\u0028\u516D\u0029';
  16798. t['\u3226'] = '\u0028\u4E03\u0029';
  16799. t['\u3227'] = '\u0028\u516B\u0029';
  16800. t['\u3228'] = '\u0028\u4E5D\u0029';
  16801. t['\u3229'] = '\u0028\u5341\u0029';
  16802. t['\u322A'] = '\u0028\u6708\u0029';
  16803. t['\u322B'] = '\u0028\u706B\u0029';
  16804. t['\u322C'] = '\u0028\u6C34\u0029';
  16805. t['\u322D'] = '\u0028\u6728\u0029';
  16806. t['\u322E'] = '\u0028\u91D1\u0029';
  16807. t['\u322F'] = '\u0028\u571F\u0029';
  16808. t['\u3230'] = '\u0028\u65E5\u0029';
  16809. t['\u3231'] = '\u0028\u682A\u0029';
  16810. t['\u3232'] = '\u0028\u6709\u0029';
  16811. t['\u3233'] = '\u0028\u793E\u0029';
  16812. t['\u3234'] = '\u0028\u540D\u0029';
  16813. t['\u3235'] = '\u0028\u7279\u0029';
  16814. t['\u3236'] = '\u0028\u8CA1\u0029';
  16815. t['\u3237'] = '\u0028\u795D\u0029';
  16816. t['\u3238'] = '\u0028\u52B4\u0029';
  16817. t['\u3239'] = '\u0028\u4EE3\u0029';
  16818. t['\u323A'] = '\u0028\u547C\u0029';
  16819. t['\u323B'] = '\u0028\u5B66\u0029';
  16820. t['\u323C'] = '\u0028\u76E3\u0029';
  16821. t['\u323D'] = '\u0028\u4F01\u0029';
  16822. t['\u323E'] = '\u0028\u8CC7\u0029';
  16823. t['\u323F'] = '\u0028\u5354\u0029';
  16824. t['\u3240'] = '\u0028\u796D\u0029';
  16825. t['\u3241'] = '\u0028\u4F11\u0029';
  16826. t['\u3242'] = '\u0028\u81EA\u0029';
  16827. t['\u3243'] = '\u0028\u81F3\u0029';
  16828. t['\u32C0'] = '\u0031\u6708';
  16829. t['\u32C1'] = '\u0032\u6708';
  16830. t['\u32C2'] = '\u0033\u6708';
  16831. t['\u32C3'] = '\u0034\u6708';
  16832. t['\u32C4'] = '\u0035\u6708';
  16833. t['\u32C5'] = '\u0036\u6708';
  16834. t['\u32C6'] = '\u0037\u6708';
  16835. t['\u32C7'] = '\u0038\u6708';
  16836. t['\u32C8'] = '\u0039\u6708';
  16837. t['\u32C9'] = '\u0031\u0030\u6708';
  16838. t['\u32CA'] = '\u0031\u0031\u6708';
  16839. t['\u32CB'] = '\u0031\u0032\u6708';
  16840. t['\u3358'] = '\u0030\u70B9';
  16841. t['\u3359'] = '\u0031\u70B9';
  16842. t['\u335A'] = '\u0032\u70B9';
  16843. t['\u335B'] = '\u0033\u70B9';
  16844. t['\u335C'] = '\u0034\u70B9';
  16845. t['\u335D'] = '\u0035\u70B9';
  16846. t['\u335E'] = '\u0036\u70B9';
  16847. t['\u335F'] = '\u0037\u70B9';
  16848. t['\u3360'] = '\u0038\u70B9';
  16849. t['\u3361'] = '\u0039\u70B9';
  16850. t['\u3362'] = '\u0031\u0030\u70B9';
  16851. t['\u3363'] = '\u0031\u0031\u70B9';
  16852. t['\u3364'] = '\u0031\u0032\u70B9';
  16853. t['\u3365'] = '\u0031\u0033\u70B9';
  16854. t['\u3366'] = '\u0031\u0034\u70B9';
  16855. t['\u3367'] = '\u0031\u0035\u70B9';
  16856. t['\u3368'] = '\u0031\u0036\u70B9';
  16857. t['\u3369'] = '\u0031\u0037\u70B9';
  16858. t['\u336A'] = '\u0031\u0038\u70B9';
  16859. t['\u336B'] = '\u0031\u0039\u70B9';
  16860. t['\u336C'] = '\u0032\u0030\u70B9';
  16861. t['\u336D'] = '\u0032\u0031\u70B9';
  16862. t['\u336E'] = '\u0032\u0032\u70B9';
  16863. t['\u336F'] = '\u0032\u0033\u70B9';
  16864. t['\u3370'] = '\u0032\u0034\u70B9';
  16865. t['\u33E0'] = '\u0031\u65E5';
  16866. t['\u33E1'] = '\u0032\u65E5';
  16867. t['\u33E2'] = '\u0033\u65E5';
  16868. t['\u33E3'] = '\u0034\u65E5';
  16869. t['\u33E4'] = '\u0035\u65E5';
  16870. t['\u33E5'] = '\u0036\u65E5';
  16871. t['\u33E6'] = '\u0037\u65E5';
  16872. t['\u33E7'] = '\u0038\u65E5';
  16873. t['\u33E8'] = '\u0039\u65E5';
  16874. t['\u33E9'] = '\u0031\u0030\u65E5';
  16875. t['\u33EA'] = '\u0031\u0031\u65E5';
  16876. t['\u33EB'] = '\u0031\u0032\u65E5';
  16877. t['\u33EC'] = '\u0031\u0033\u65E5';
  16878. t['\u33ED'] = '\u0031\u0034\u65E5';
  16879. t['\u33EE'] = '\u0031\u0035\u65E5';
  16880. t['\u33EF'] = '\u0031\u0036\u65E5';
  16881. t['\u33F0'] = '\u0031\u0037\u65E5';
  16882. t['\u33F1'] = '\u0031\u0038\u65E5';
  16883. t['\u33F2'] = '\u0031\u0039\u65E5';
  16884. t['\u33F3'] = '\u0032\u0030\u65E5';
  16885. t['\u33F4'] = '\u0032\u0031\u65E5';
  16886. t['\u33F5'] = '\u0032\u0032\u65E5';
  16887. t['\u33F6'] = '\u0032\u0033\u65E5';
  16888. t['\u33F7'] = '\u0032\u0034\u65E5';
  16889. t['\u33F8'] = '\u0032\u0035\u65E5';
  16890. t['\u33F9'] = '\u0032\u0036\u65E5';
  16891. t['\u33FA'] = '\u0032\u0037\u65E5';
  16892. t['\u33FB'] = '\u0032\u0038\u65E5';
  16893. t['\u33FC'] = '\u0032\u0039\u65E5';
  16894. t['\u33FD'] = '\u0033\u0030\u65E5';
  16895. t['\u33FE'] = '\u0033\u0031\u65E5';
  16896. t['\uFB00'] = '\u0066\u0066';
  16897. t['\uFB01'] = '\u0066\u0069';
  16898. t['\uFB02'] = '\u0066\u006C';
  16899. t['\uFB03'] = '\u0066\u0066\u0069';
  16900. t['\uFB04'] = '\u0066\u0066\u006C';
  16901. t['\uFB05'] = '\u017F\u0074';
  16902. t['\uFB06'] = '\u0073\u0074';
  16903. t['\uFB13'] = '\u0574\u0576';
  16904. t['\uFB14'] = '\u0574\u0565';
  16905. t['\uFB15'] = '\u0574\u056B';
  16906. t['\uFB16'] = '\u057E\u0576';
  16907. t['\uFB17'] = '\u0574\u056D';
  16908. t['\uFB4F'] = '\u05D0\u05DC';
  16909. t['\uFB50'] = '\u0671';
  16910. t['\uFB51'] = '\u0671';
  16911. t['\uFB52'] = '\u067B';
  16912. t['\uFB53'] = '\u067B';
  16913. t['\uFB54'] = '\u067B';
  16914. t['\uFB55'] = '\u067B';
  16915. t['\uFB56'] = '\u067E';
  16916. t['\uFB57'] = '\u067E';
  16917. t['\uFB58'] = '\u067E';
  16918. t['\uFB59'] = '\u067E';
  16919. t['\uFB5A'] = '\u0680';
  16920. t['\uFB5B'] = '\u0680';
  16921. t['\uFB5C'] = '\u0680';
  16922. t['\uFB5D'] = '\u0680';
  16923. t['\uFB5E'] = '\u067A';
  16924. t['\uFB5F'] = '\u067A';
  16925. t['\uFB60'] = '\u067A';
  16926. t['\uFB61'] = '\u067A';
  16927. t['\uFB62'] = '\u067F';
  16928. t['\uFB63'] = '\u067F';
  16929. t['\uFB64'] = '\u067F';
  16930. t['\uFB65'] = '\u067F';
  16931. t['\uFB66'] = '\u0679';
  16932. t['\uFB67'] = '\u0679';
  16933. t['\uFB68'] = '\u0679';
  16934. t['\uFB69'] = '\u0679';
  16935. t['\uFB6A'] = '\u06A4';
  16936. t['\uFB6B'] = '\u06A4';
  16937. t['\uFB6C'] = '\u06A4';
  16938. t['\uFB6D'] = '\u06A4';
  16939. t['\uFB6E'] = '\u06A6';
  16940. t['\uFB6F'] = '\u06A6';
  16941. t['\uFB70'] = '\u06A6';
  16942. t['\uFB71'] = '\u06A6';
  16943. t['\uFB72'] = '\u0684';
  16944. t['\uFB73'] = '\u0684';
  16945. t['\uFB74'] = '\u0684';
  16946. t['\uFB75'] = '\u0684';
  16947. t['\uFB76'] = '\u0683';
  16948. t['\uFB77'] = '\u0683';
  16949. t['\uFB78'] = '\u0683';
  16950. t['\uFB79'] = '\u0683';
  16951. t['\uFB7A'] = '\u0686';
  16952. t['\uFB7B'] = '\u0686';
  16953. t['\uFB7C'] = '\u0686';
  16954. t['\uFB7D'] = '\u0686';
  16955. t['\uFB7E'] = '\u0687';
  16956. t['\uFB7F'] = '\u0687';
  16957. t['\uFB80'] = '\u0687';
  16958. t['\uFB81'] = '\u0687';
  16959. t['\uFB82'] = '\u068D';
  16960. t['\uFB83'] = '\u068D';
  16961. t['\uFB84'] = '\u068C';
  16962. t['\uFB85'] = '\u068C';
  16963. t['\uFB86'] = '\u068E';
  16964. t['\uFB87'] = '\u068E';
  16965. t['\uFB88'] = '\u0688';
  16966. t['\uFB89'] = '\u0688';
  16967. t['\uFB8A'] = '\u0698';
  16968. t['\uFB8B'] = '\u0698';
  16969. t['\uFB8C'] = '\u0691';
  16970. t['\uFB8D'] = '\u0691';
  16971. t['\uFB8E'] = '\u06A9';
  16972. t['\uFB8F'] = '\u06A9';
  16973. t['\uFB90'] = '\u06A9';
  16974. t['\uFB91'] = '\u06A9';
  16975. t['\uFB92'] = '\u06AF';
  16976. t['\uFB93'] = '\u06AF';
  16977. t['\uFB94'] = '\u06AF';
  16978. t['\uFB95'] = '\u06AF';
  16979. t['\uFB96'] = '\u06B3';
  16980. t['\uFB97'] = '\u06B3';
  16981. t['\uFB98'] = '\u06B3';
  16982. t['\uFB99'] = '\u06B3';
  16983. t['\uFB9A'] = '\u06B1';
  16984. t['\uFB9B'] = '\u06B1';
  16985. t['\uFB9C'] = '\u06B1';
  16986. t['\uFB9D'] = '\u06B1';
  16987. t['\uFB9E'] = '\u06BA';
  16988. t['\uFB9F'] = '\u06BA';
  16989. t['\uFBA0'] = '\u06BB';
  16990. t['\uFBA1'] = '\u06BB';
  16991. t['\uFBA2'] = '\u06BB';
  16992. t['\uFBA3'] = '\u06BB';
  16993. t['\uFBA4'] = '\u06C0';
  16994. t['\uFBA5'] = '\u06C0';
  16995. t['\uFBA6'] = '\u06C1';
  16996. t['\uFBA7'] = '\u06C1';
  16997. t['\uFBA8'] = '\u06C1';
  16998. t['\uFBA9'] = '\u06C1';
  16999. t['\uFBAA'] = '\u06BE';
  17000. t['\uFBAB'] = '\u06BE';
  17001. t['\uFBAC'] = '\u06BE';
  17002. t['\uFBAD'] = '\u06BE';
  17003. t['\uFBAE'] = '\u06D2';
  17004. t['\uFBAF'] = '\u06D2';
  17005. t['\uFBB0'] = '\u06D3';
  17006. t['\uFBB1'] = '\u06D3';
  17007. t['\uFBD3'] = '\u06AD';
  17008. t['\uFBD4'] = '\u06AD';
  17009. t['\uFBD5'] = '\u06AD';
  17010. t['\uFBD6'] = '\u06AD';
  17011. t['\uFBD7'] = '\u06C7';
  17012. t['\uFBD8'] = '\u06C7';
  17013. t['\uFBD9'] = '\u06C6';
  17014. t['\uFBDA'] = '\u06C6';
  17015. t['\uFBDB'] = '\u06C8';
  17016. t['\uFBDC'] = '\u06C8';
  17017. t['\uFBDD'] = '\u0677';
  17018. t['\uFBDE'] = '\u06CB';
  17019. t['\uFBDF'] = '\u06CB';
  17020. t['\uFBE0'] = '\u06C5';
  17021. t['\uFBE1'] = '\u06C5';
  17022. t['\uFBE2'] = '\u06C9';
  17023. t['\uFBE3'] = '\u06C9';
  17024. t['\uFBE4'] = '\u06D0';
  17025. t['\uFBE5'] = '\u06D0';
  17026. t['\uFBE6'] = '\u06D0';
  17027. t['\uFBE7'] = '\u06D0';
  17028. t['\uFBE8'] = '\u0649';
  17029. t['\uFBE9'] = '\u0649';
  17030. t['\uFBEA'] = '\u0626\u0627';
  17031. t['\uFBEB'] = '\u0626\u0627';
  17032. t['\uFBEC'] = '\u0626\u06D5';
  17033. t['\uFBED'] = '\u0626\u06D5';
  17034. t['\uFBEE'] = '\u0626\u0648';
  17035. t['\uFBEF'] = '\u0626\u0648';
  17036. t['\uFBF0'] = '\u0626\u06C7';
  17037. t['\uFBF1'] = '\u0626\u06C7';
  17038. t['\uFBF2'] = '\u0626\u06C6';
  17039. t['\uFBF3'] = '\u0626\u06C6';
  17040. t['\uFBF4'] = '\u0626\u06C8';
  17041. t['\uFBF5'] = '\u0626\u06C8';
  17042. t['\uFBF6'] = '\u0626\u06D0';
  17043. t['\uFBF7'] = '\u0626\u06D0';
  17044. t['\uFBF8'] = '\u0626\u06D0';
  17045. t['\uFBF9'] = '\u0626\u0649';
  17046. t['\uFBFA'] = '\u0626\u0649';
  17047. t['\uFBFB'] = '\u0626\u0649';
  17048. t['\uFBFC'] = '\u06CC';
  17049. t['\uFBFD'] = '\u06CC';
  17050. t['\uFBFE'] = '\u06CC';
  17051. t['\uFBFF'] = '\u06CC';
  17052. t['\uFC00'] = '\u0626\u062C';
  17053. t['\uFC01'] = '\u0626\u062D';
  17054. t['\uFC02'] = '\u0626\u0645';
  17055. t['\uFC03'] = '\u0626\u0649';
  17056. t['\uFC04'] = '\u0626\u064A';
  17057. t['\uFC05'] = '\u0628\u062C';
  17058. t['\uFC06'] = '\u0628\u062D';
  17059. t['\uFC07'] = '\u0628\u062E';
  17060. t['\uFC08'] = '\u0628\u0645';
  17061. t['\uFC09'] = '\u0628\u0649';
  17062. t['\uFC0A'] = '\u0628\u064A';
  17063. t['\uFC0B'] = '\u062A\u062C';
  17064. t['\uFC0C'] = '\u062A\u062D';
  17065. t['\uFC0D'] = '\u062A\u062E';
  17066. t['\uFC0E'] = '\u062A\u0645';
  17067. t['\uFC0F'] = '\u062A\u0649';
  17068. t['\uFC10'] = '\u062A\u064A';
  17069. t['\uFC11'] = '\u062B\u062C';
  17070. t['\uFC12'] = '\u062B\u0645';
  17071. t['\uFC13'] = '\u062B\u0649';
  17072. t['\uFC14'] = '\u062B\u064A';
  17073. t['\uFC15'] = '\u062C\u062D';
  17074. t['\uFC16'] = '\u062C\u0645';
  17075. t['\uFC17'] = '\u062D\u062C';
  17076. t['\uFC18'] = '\u062D\u0645';
  17077. t['\uFC19'] = '\u062E\u062C';
  17078. t['\uFC1A'] = '\u062E\u062D';
  17079. t['\uFC1B'] = '\u062E\u0645';
  17080. t['\uFC1C'] = '\u0633\u062C';
  17081. t['\uFC1D'] = '\u0633\u062D';
  17082. t['\uFC1E'] = '\u0633\u062E';
  17083. t['\uFC1F'] = '\u0633\u0645';
  17084. t['\uFC20'] = '\u0635\u062D';
  17085. t['\uFC21'] = '\u0635\u0645';
  17086. t['\uFC22'] = '\u0636\u062C';
  17087. t['\uFC23'] = '\u0636\u062D';
  17088. t['\uFC24'] = '\u0636\u062E';
  17089. t['\uFC25'] = '\u0636\u0645';
  17090. t['\uFC26'] = '\u0637\u062D';
  17091. t['\uFC27'] = '\u0637\u0645';
  17092. t['\uFC28'] = '\u0638\u0645';
  17093. t['\uFC29'] = '\u0639\u062C';
  17094. t['\uFC2A'] = '\u0639\u0645';
  17095. t['\uFC2B'] = '\u063A\u062C';
  17096. t['\uFC2C'] = '\u063A\u0645';
  17097. t['\uFC2D'] = '\u0641\u062C';
  17098. t['\uFC2E'] = '\u0641\u062D';
  17099. t['\uFC2F'] = '\u0641\u062E';
  17100. t['\uFC30'] = '\u0641\u0645';
  17101. t['\uFC31'] = '\u0641\u0649';
  17102. t['\uFC32'] = '\u0641\u064A';
  17103. t['\uFC33'] = '\u0642\u062D';
  17104. t['\uFC34'] = '\u0642\u0645';
  17105. t['\uFC35'] = '\u0642\u0649';
  17106. t['\uFC36'] = '\u0642\u064A';
  17107. t['\uFC37'] = '\u0643\u0627';
  17108. t['\uFC38'] = '\u0643\u062C';
  17109. t['\uFC39'] = '\u0643\u062D';
  17110. t['\uFC3A'] = '\u0643\u062E';
  17111. t['\uFC3B'] = '\u0643\u0644';
  17112. t['\uFC3C'] = '\u0643\u0645';
  17113. t['\uFC3D'] = '\u0643\u0649';
  17114. t['\uFC3E'] = '\u0643\u064A';
  17115. t['\uFC3F'] = '\u0644\u062C';
  17116. t['\uFC40'] = '\u0644\u062D';
  17117. t['\uFC41'] = '\u0644\u062E';
  17118. t['\uFC42'] = '\u0644\u0645';
  17119. t['\uFC43'] = '\u0644\u0649';
  17120. t['\uFC44'] = '\u0644\u064A';
  17121. t['\uFC45'] = '\u0645\u062C';
  17122. t['\uFC46'] = '\u0645\u062D';
  17123. t['\uFC47'] = '\u0645\u062E';
  17124. t['\uFC48'] = '\u0645\u0645';
  17125. t['\uFC49'] = '\u0645\u0649';
  17126. t['\uFC4A'] = '\u0645\u064A';
  17127. t['\uFC4B'] = '\u0646\u062C';
  17128. t['\uFC4C'] = '\u0646\u062D';
  17129. t['\uFC4D'] = '\u0646\u062E';
  17130. t['\uFC4E'] = '\u0646\u0645';
  17131. t['\uFC4F'] = '\u0646\u0649';
  17132. t['\uFC50'] = '\u0646\u064A';
  17133. t['\uFC51'] = '\u0647\u062C';
  17134. t['\uFC52'] = '\u0647\u0645';
  17135. t['\uFC53'] = '\u0647\u0649';
  17136. t['\uFC54'] = '\u0647\u064A';
  17137. t['\uFC55'] = '\u064A\u062C';
  17138. t['\uFC56'] = '\u064A\u062D';
  17139. t['\uFC57'] = '\u064A\u062E';
  17140. t['\uFC58'] = '\u064A\u0645';
  17141. t['\uFC59'] = '\u064A\u0649';
  17142. t['\uFC5A'] = '\u064A\u064A';
  17143. t['\uFC5B'] = '\u0630\u0670';
  17144. t['\uFC5C'] = '\u0631\u0670';
  17145. t['\uFC5D'] = '\u0649\u0670';
  17146. t['\uFC5E'] = '\u0020\u064C\u0651';
  17147. t['\uFC5F'] = '\u0020\u064D\u0651';
  17148. t['\uFC60'] = '\u0020\u064E\u0651';
  17149. t['\uFC61'] = '\u0020\u064F\u0651';
  17150. t['\uFC62'] = '\u0020\u0650\u0651';
  17151. t['\uFC63'] = '\u0020\u0651\u0670';
  17152. t['\uFC64'] = '\u0626\u0631';
  17153. t['\uFC65'] = '\u0626\u0632';
  17154. t['\uFC66'] = '\u0626\u0645';
  17155. t['\uFC67'] = '\u0626\u0646';
  17156. t['\uFC68'] = '\u0626\u0649';
  17157. t['\uFC69'] = '\u0626\u064A';
  17158. t['\uFC6A'] = '\u0628\u0631';
  17159. t['\uFC6B'] = '\u0628\u0632';
  17160. t['\uFC6C'] = '\u0628\u0645';
  17161. t['\uFC6D'] = '\u0628\u0646';
  17162. t['\uFC6E'] = '\u0628\u0649';
  17163. t['\uFC6F'] = '\u0628\u064A';
  17164. t['\uFC70'] = '\u062A\u0631';
  17165. t['\uFC71'] = '\u062A\u0632';
  17166. t['\uFC72'] = '\u062A\u0645';
  17167. t['\uFC73'] = '\u062A\u0646';
  17168. t['\uFC74'] = '\u062A\u0649';
  17169. t['\uFC75'] = '\u062A\u064A';
  17170. t['\uFC76'] = '\u062B\u0631';
  17171. t['\uFC77'] = '\u062B\u0632';
  17172. t['\uFC78'] = '\u062B\u0645';
  17173. t['\uFC79'] = '\u062B\u0646';
  17174. t['\uFC7A'] = '\u062B\u0649';
  17175. t['\uFC7B'] = '\u062B\u064A';
  17176. t['\uFC7C'] = '\u0641\u0649';
  17177. t['\uFC7D'] = '\u0641\u064A';
  17178. t['\uFC7E'] = '\u0642\u0649';
  17179. t['\uFC7F'] = '\u0642\u064A';
  17180. t['\uFC80'] = '\u0643\u0627';
  17181. t['\uFC81'] = '\u0643\u0644';
  17182. t['\uFC82'] = '\u0643\u0645';
  17183. t['\uFC83'] = '\u0643\u0649';
  17184. t['\uFC84'] = '\u0643\u064A';
  17185. t['\uFC85'] = '\u0644\u0645';
  17186. t['\uFC86'] = '\u0644\u0649';
  17187. t['\uFC87'] = '\u0644\u064A';
  17188. t['\uFC88'] = '\u0645\u0627';
  17189. t['\uFC89'] = '\u0645\u0645';
  17190. t['\uFC8A'] = '\u0646\u0631';
  17191. t['\uFC8B'] = '\u0646\u0632';
  17192. t['\uFC8C'] = '\u0646\u0645';
  17193. t['\uFC8D'] = '\u0646\u0646';
  17194. t['\uFC8E'] = '\u0646\u0649';
  17195. t['\uFC8F'] = '\u0646\u064A';
  17196. t['\uFC90'] = '\u0649\u0670';
  17197. t['\uFC91'] = '\u064A\u0631';
  17198. t['\uFC92'] = '\u064A\u0632';
  17199. t['\uFC93'] = '\u064A\u0645';
  17200. t['\uFC94'] = '\u064A\u0646';
  17201. t['\uFC95'] = '\u064A\u0649';
  17202. t['\uFC96'] = '\u064A\u064A';
  17203. t['\uFC97'] = '\u0626\u062C';
  17204. t['\uFC98'] = '\u0626\u062D';
  17205. t['\uFC99'] = '\u0626\u062E';
  17206. t['\uFC9A'] = '\u0626\u0645';
  17207. t['\uFC9B'] = '\u0626\u0647';
  17208. t['\uFC9C'] = '\u0628\u062C';
  17209. t['\uFC9D'] = '\u0628\u062D';
  17210. t['\uFC9E'] = '\u0628\u062E';
  17211. t['\uFC9F'] = '\u0628\u0645';
  17212. t['\uFCA0'] = '\u0628\u0647';
  17213. t['\uFCA1'] = '\u062A\u062C';
  17214. t['\uFCA2'] = '\u062A\u062D';
  17215. t['\uFCA3'] = '\u062A\u062E';
  17216. t['\uFCA4'] = '\u062A\u0645';
  17217. t['\uFCA5'] = '\u062A\u0647';
  17218. t['\uFCA6'] = '\u062B\u0645';
  17219. t['\uFCA7'] = '\u062C\u062D';
  17220. t['\uFCA8'] = '\u062C\u0645';
  17221. t['\uFCA9'] = '\u062D\u062C';
  17222. t['\uFCAA'] = '\u062D\u0645';
  17223. t['\uFCAB'] = '\u062E\u062C';
  17224. t['\uFCAC'] = '\u062E\u0645';
  17225. t['\uFCAD'] = '\u0633\u062C';
  17226. t['\uFCAE'] = '\u0633\u062D';
  17227. t['\uFCAF'] = '\u0633\u062E';
  17228. t['\uFCB0'] = '\u0633\u0645';
  17229. t['\uFCB1'] = '\u0635\u062D';
  17230. t['\uFCB2'] = '\u0635\u062E';
  17231. t['\uFCB3'] = '\u0635\u0645';
  17232. t['\uFCB4'] = '\u0636\u062C';
  17233. t['\uFCB5'] = '\u0636\u062D';
  17234. t['\uFCB6'] = '\u0636\u062E';
  17235. t['\uFCB7'] = '\u0636\u0645';
  17236. t['\uFCB8'] = '\u0637\u062D';
  17237. t['\uFCB9'] = '\u0638\u0645';
  17238. t['\uFCBA'] = '\u0639\u062C';
  17239. t['\uFCBB'] = '\u0639\u0645';
  17240. t['\uFCBC'] = '\u063A\u062C';
  17241. t['\uFCBD'] = '\u063A\u0645';
  17242. t['\uFCBE'] = '\u0641\u062C';
  17243. t['\uFCBF'] = '\u0641\u062D';
  17244. t['\uFCC0'] = '\u0641\u062E';
  17245. t['\uFCC1'] = '\u0641\u0645';
  17246. t['\uFCC2'] = '\u0642\u062D';
  17247. t['\uFCC3'] = '\u0642\u0645';
  17248. t['\uFCC4'] = '\u0643\u062C';
  17249. t['\uFCC5'] = '\u0643\u062D';
  17250. t['\uFCC6'] = '\u0643\u062E';
  17251. t['\uFCC7'] = '\u0643\u0644';
  17252. t['\uFCC8'] = '\u0643\u0645';
  17253. t['\uFCC9'] = '\u0644\u062C';
  17254. t['\uFCCA'] = '\u0644\u062D';
  17255. t['\uFCCB'] = '\u0644\u062E';
  17256. t['\uFCCC'] = '\u0644\u0645';
  17257. t['\uFCCD'] = '\u0644\u0647';
  17258. t['\uFCCE'] = '\u0645\u062C';
  17259. t['\uFCCF'] = '\u0645\u062D';
  17260. t['\uFCD0'] = '\u0645\u062E';
  17261. t['\uFCD1'] = '\u0645\u0645';
  17262. t['\uFCD2'] = '\u0646\u062C';
  17263. t['\uFCD3'] = '\u0646\u062D';
  17264. t['\uFCD4'] = '\u0646\u062E';
  17265. t['\uFCD5'] = '\u0646\u0645';
  17266. t['\uFCD6'] = '\u0646\u0647';
  17267. t['\uFCD7'] = '\u0647\u062C';
  17268. t['\uFCD8'] = '\u0647\u0645';
  17269. t['\uFCD9'] = '\u0647\u0670';
  17270. t['\uFCDA'] = '\u064A\u062C';
  17271. t['\uFCDB'] = '\u064A\u062D';
  17272. t['\uFCDC'] = '\u064A\u062E';
  17273. t['\uFCDD'] = '\u064A\u0645';
  17274. t['\uFCDE'] = '\u064A\u0647';
  17275. t['\uFCDF'] = '\u0626\u0645';
  17276. t['\uFCE0'] = '\u0626\u0647';
  17277. t['\uFCE1'] = '\u0628\u0645';
  17278. t['\uFCE2'] = '\u0628\u0647';
  17279. t['\uFCE3'] = '\u062A\u0645';
  17280. t['\uFCE4'] = '\u062A\u0647';
  17281. t['\uFCE5'] = '\u062B\u0645';
  17282. t['\uFCE6'] = '\u062B\u0647';
  17283. t['\uFCE7'] = '\u0633\u0645';
  17284. t['\uFCE8'] = '\u0633\u0647';
  17285. t['\uFCE9'] = '\u0634\u0645';
  17286. t['\uFCEA'] = '\u0634\u0647';
  17287. t['\uFCEB'] = '\u0643\u0644';
  17288. t['\uFCEC'] = '\u0643\u0645';
  17289. t['\uFCED'] = '\u0644\u0645';
  17290. t['\uFCEE'] = '\u0646\u0645';
  17291. t['\uFCEF'] = '\u0646\u0647';
  17292. t['\uFCF0'] = '\u064A\u0645';
  17293. t['\uFCF1'] = '\u064A\u0647';
  17294. t['\uFCF2'] = '\u0640\u064E\u0651';
  17295. t['\uFCF3'] = '\u0640\u064F\u0651';
  17296. t['\uFCF4'] = '\u0640\u0650\u0651';
  17297. t['\uFCF5'] = '\u0637\u0649';
  17298. t['\uFCF6'] = '\u0637\u064A';
  17299. t['\uFCF7'] = '\u0639\u0649';
  17300. t['\uFCF8'] = '\u0639\u064A';
  17301. t['\uFCF9'] = '\u063A\u0649';
  17302. t['\uFCFA'] = '\u063A\u064A';
  17303. t['\uFCFB'] = '\u0633\u0649';
  17304. t['\uFCFC'] = '\u0633\u064A';
  17305. t['\uFCFD'] = '\u0634\u0649';
  17306. t['\uFCFE'] = '\u0634\u064A';
  17307. t['\uFCFF'] = '\u062D\u0649';
  17308. t['\uFD00'] = '\u062D\u064A';
  17309. t['\uFD01'] = '\u062C\u0649';
  17310. t['\uFD02'] = '\u062C\u064A';
  17311. t['\uFD03'] = '\u062E\u0649';
  17312. t['\uFD04'] = '\u062E\u064A';
  17313. t['\uFD05'] = '\u0635\u0649';
  17314. t['\uFD06'] = '\u0635\u064A';
  17315. t['\uFD07'] = '\u0636\u0649';
  17316. t['\uFD08'] = '\u0636\u064A';
  17317. t['\uFD09'] = '\u0634\u062C';
  17318. t['\uFD0A'] = '\u0634\u062D';
  17319. t['\uFD0B'] = '\u0634\u062E';
  17320. t['\uFD0C'] = '\u0634\u0645';
  17321. t['\uFD0D'] = '\u0634\u0631';
  17322. t['\uFD0E'] = '\u0633\u0631';
  17323. t['\uFD0F'] = '\u0635\u0631';
  17324. t['\uFD10'] = '\u0636\u0631';
  17325. t['\uFD11'] = '\u0637\u0649';
  17326. t['\uFD12'] = '\u0637\u064A';
  17327. t['\uFD13'] = '\u0639\u0649';
  17328. t['\uFD14'] = '\u0639\u064A';
  17329. t['\uFD15'] = '\u063A\u0649';
  17330. t['\uFD16'] = '\u063A\u064A';
  17331. t['\uFD17'] = '\u0633\u0649';
  17332. t['\uFD18'] = '\u0633\u064A';
  17333. t['\uFD19'] = '\u0634\u0649';
  17334. t['\uFD1A'] = '\u0634\u064A';
  17335. t['\uFD1B'] = '\u062D\u0649';
  17336. t['\uFD1C'] = '\u062D\u064A';
  17337. t['\uFD1D'] = '\u062C\u0649';
  17338. t['\uFD1E'] = '\u062C\u064A';
  17339. t['\uFD1F'] = '\u062E\u0649';
  17340. t['\uFD20'] = '\u062E\u064A';
  17341. t['\uFD21'] = '\u0635\u0649';
  17342. t['\uFD22'] = '\u0635\u064A';
  17343. t['\uFD23'] = '\u0636\u0649';
  17344. t['\uFD24'] = '\u0636\u064A';
  17345. t['\uFD25'] = '\u0634\u062C';
  17346. t['\uFD26'] = '\u0634\u062D';
  17347. t['\uFD27'] = '\u0634\u062E';
  17348. t['\uFD28'] = '\u0634\u0645';
  17349. t['\uFD29'] = '\u0634\u0631';
  17350. t['\uFD2A'] = '\u0633\u0631';
  17351. t['\uFD2B'] = '\u0635\u0631';
  17352. t['\uFD2C'] = '\u0636\u0631';
  17353. t['\uFD2D'] = '\u0634\u062C';
  17354. t['\uFD2E'] = '\u0634\u062D';
  17355. t['\uFD2F'] = '\u0634\u062E';
  17356. t['\uFD30'] = '\u0634\u0645';
  17357. t['\uFD31'] = '\u0633\u0647';
  17358. t['\uFD32'] = '\u0634\u0647';
  17359. t['\uFD33'] = '\u0637\u0645';
  17360. t['\uFD34'] = '\u0633\u062C';
  17361. t['\uFD35'] = '\u0633\u062D';
  17362. t['\uFD36'] = '\u0633\u062E';
  17363. t['\uFD37'] = '\u0634\u062C';
  17364. t['\uFD38'] = '\u0634\u062D';
  17365. t['\uFD39'] = '\u0634\u062E';
  17366. t['\uFD3A'] = '\u0637\u0645';
  17367. t['\uFD3B'] = '\u0638\u0645';
  17368. t['\uFD3C'] = '\u0627\u064B';
  17369. t['\uFD3D'] = '\u0627\u064B';
  17370. t['\uFD50'] = '\u062A\u062C\u0645';
  17371. t['\uFD51'] = '\u062A\u062D\u062C';
  17372. t['\uFD52'] = '\u062A\u062D\u062C';
  17373. t['\uFD53'] = '\u062A\u062D\u0645';
  17374. t['\uFD54'] = '\u062A\u062E\u0645';
  17375. t['\uFD55'] = '\u062A\u0645\u062C';
  17376. t['\uFD56'] = '\u062A\u0645\u062D';
  17377. t['\uFD57'] = '\u062A\u0645\u062E';
  17378. t['\uFD58'] = '\u062C\u0645\u062D';
  17379. t['\uFD59'] = '\u062C\u0645\u062D';
  17380. t['\uFD5A'] = '\u062D\u0645\u064A';
  17381. t['\uFD5B'] = '\u062D\u0645\u0649';
  17382. t['\uFD5C'] = '\u0633\u062D\u062C';
  17383. t['\uFD5D'] = '\u0633\u062C\u062D';
  17384. t['\uFD5E'] = '\u0633\u062C\u0649';
  17385. t['\uFD5F'] = '\u0633\u0645\u062D';
  17386. t['\uFD60'] = '\u0633\u0645\u062D';
  17387. t['\uFD61'] = '\u0633\u0645\u062C';
  17388. t['\uFD62'] = '\u0633\u0645\u0645';
  17389. t['\uFD63'] = '\u0633\u0645\u0645';
  17390. t['\uFD64'] = '\u0635\u062D\u062D';
  17391. t['\uFD65'] = '\u0635\u062D\u062D';
  17392. t['\uFD66'] = '\u0635\u0645\u0645';
  17393. t['\uFD67'] = '\u0634\u062D\u0645';
  17394. t['\uFD68'] = '\u0634\u062D\u0645';
  17395. t['\uFD69'] = '\u0634\u062C\u064A';
  17396. t['\uFD6A'] = '\u0634\u0645\u062E';
  17397. t['\uFD6B'] = '\u0634\u0645\u062E';
  17398. t['\uFD6C'] = '\u0634\u0645\u0645';
  17399. t['\uFD6D'] = '\u0634\u0645\u0645';
  17400. t['\uFD6E'] = '\u0636\u062D\u0649';
  17401. t['\uFD6F'] = '\u0636\u062E\u0645';
  17402. t['\uFD70'] = '\u0636\u062E\u0645';
  17403. t['\uFD71'] = '\u0637\u0645\u062D';
  17404. t['\uFD72'] = '\u0637\u0645\u062D';
  17405. t['\uFD73'] = '\u0637\u0645\u0645';
  17406. t['\uFD74'] = '\u0637\u0645\u064A';
  17407. t['\uFD75'] = '\u0639\u062C\u0645';
  17408. t['\uFD76'] = '\u0639\u0645\u0645';
  17409. t['\uFD77'] = '\u0639\u0645\u0645';
  17410. t['\uFD78'] = '\u0639\u0645\u0649';
  17411. t['\uFD79'] = '\u063A\u0645\u0645';
  17412. t['\uFD7A'] = '\u063A\u0645\u064A';
  17413. t['\uFD7B'] = '\u063A\u0645\u0649';
  17414. t['\uFD7C'] = '\u0641\u062E\u0645';
  17415. t['\uFD7D'] = '\u0641\u062E\u0645';
  17416. t['\uFD7E'] = '\u0642\u0645\u062D';
  17417. t['\uFD7F'] = '\u0642\u0645\u0645';
  17418. t['\uFD80'] = '\u0644\u062D\u0645';
  17419. t['\uFD81'] = '\u0644\u062D\u064A';
  17420. t['\uFD82'] = '\u0644\u062D\u0649';
  17421. t['\uFD83'] = '\u0644\u062C\u062C';
  17422. t['\uFD84'] = '\u0644\u062C\u062C';
  17423. t['\uFD85'] = '\u0644\u062E\u0645';
  17424. t['\uFD86'] = '\u0644\u062E\u0645';
  17425. t['\uFD87'] = '\u0644\u0645\u062D';
  17426. t['\uFD88'] = '\u0644\u0645\u062D';
  17427. t['\uFD89'] = '\u0645\u062D\u062C';
  17428. t['\uFD8A'] = '\u0645\u062D\u0645';
  17429. t['\uFD8B'] = '\u0645\u062D\u064A';
  17430. t['\uFD8C'] = '\u0645\u062C\u062D';
  17431. t['\uFD8D'] = '\u0645\u062C\u0645';
  17432. t['\uFD8E'] = '\u0645\u062E\u062C';
  17433. t['\uFD8F'] = '\u0645\u062E\u0645';
  17434. t['\uFD92'] = '\u0645\u062C\u062E';
  17435. t['\uFD93'] = '\u0647\u0645\u062C';
  17436. t['\uFD94'] = '\u0647\u0645\u0645';
  17437. t['\uFD95'] = '\u0646\u062D\u0645';
  17438. t['\uFD96'] = '\u0646\u062D\u0649';
  17439. t['\uFD97'] = '\u0646\u062C\u0645';
  17440. t['\uFD98'] = '\u0646\u062C\u0645';
  17441. t['\uFD99'] = '\u0646\u062C\u0649';
  17442. t['\uFD9A'] = '\u0646\u0645\u064A';
  17443. t['\uFD9B'] = '\u0646\u0645\u0649';
  17444. t['\uFD9C'] = '\u064A\u0645\u0645';
  17445. t['\uFD9D'] = '\u064A\u0645\u0645';
  17446. t['\uFD9E'] = '\u0628\u062E\u064A';
  17447. t['\uFD9F'] = '\u062A\u062C\u064A';
  17448. t['\uFDA0'] = '\u062A\u062C\u0649';
  17449. t['\uFDA1'] = '\u062A\u062E\u064A';
  17450. t['\uFDA2'] = '\u062A\u062E\u0649';
  17451. t['\uFDA3'] = '\u062A\u0645\u064A';
  17452. t['\uFDA4'] = '\u062A\u0645\u0649';
  17453. t['\uFDA5'] = '\u062C\u0645\u064A';
  17454. t['\uFDA6'] = '\u062C\u062D\u0649';
  17455. t['\uFDA7'] = '\u062C\u0645\u0649';
  17456. t['\uFDA8'] = '\u0633\u062E\u0649';
  17457. t['\uFDA9'] = '\u0635\u062D\u064A';
  17458. t['\uFDAA'] = '\u0634\u062D\u064A';
  17459. t['\uFDAB'] = '\u0636\u062D\u064A';
  17460. t['\uFDAC'] = '\u0644\u062C\u064A';
  17461. t['\uFDAD'] = '\u0644\u0645\u064A';
  17462. t['\uFDAE'] = '\u064A\u062D\u064A';
  17463. t['\uFDAF'] = '\u064A\u062C\u064A';
  17464. t['\uFDB0'] = '\u064A\u0645\u064A';
  17465. t['\uFDB1'] = '\u0645\u0645\u064A';
  17466. t['\uFDB2'] = '\u0642\u0645\u064A';
  17467. t['\uFDB3'] = '\u0646\u062D\u064A';
  17468. t['\uFDB4'] = '\u0642\u0645\u062D';
  17469. t['\uFDB5'] = '\u0644\u062D\u0645';
  17470. t['\uFDB6'] = '\u0639\u0645\u064A';
  17471. t['\uFDB7'] = '\u0643\u0645\u064A';
  17472. t['\uFDB8'] = '\u0646\u062C\u062D';
  17473. t['\uFDB9'] = '\u0645\u062E\u064A';
  17474. t['\uFDBA'] = '\u0644\u062C\u0645';
  17475. t['\uFDBB'] = '\u0643\u0645\u0645';
  17476. t['\uFDBC'] = '\u0644\u062C\u0645';
  17477. t['\uFDBD'] = '\u0646\u062C\u062D';
  17478. t['\uFDBE'] = '\u062C\u062D\u064A';
  17479. t['\uFDBF'] = '\u062D\u062C\u064A';
  17480. t['\uFDC0'] = '\u0645\u062C\u064A';
  17481. t['\uFDC1'] = '\u0641\u0645\u064A';
  17482. t['\uFDC2'] = '\u0628\u062D\u064A';
  17483. t['\uFDC3'] = '\u0643\u0645\u0645';
  17484. t['\uFDC4'] = '\u0639\u062C\u0645';
  17485. t['\uFDC5'] = '\u0635\u0645\u0645';
  17486. t['\uFDC6'] = '\u0633\u062E\u064A';
  17487. t['\uFDC7'] = '\u0646\u062C\u064A';
  17488. t['\uFE49'] = '\u203E';
  17489. t['\uFE4A'] = '\u203E';
  17490. t['\uFE4B'] = '\u203E';
  17491. t['\uFE4C'] = '\u203E';
  17492. t['\uFE4D'] = '\u005F';
  17493. t['\uFE4E'] = '\u005F';
  17494. t['\uFE4F'] = '\u005F';
  17495. t['\uFE80'] = '\u0621';
  17496. t['\uFE81'] = '\u0622';
  17497. t['\uFE82'] = '\u0622';
  17498. t['\uFE83'] = '\u0623';
  17499. t['\uFE84'] = '\u0623';
  17500. t['\uFE85'] = '\u0624';
  17501. t['\uFE86'] = '\u0624';
  17502. t['\uFE87'] = '\u0625';
  17503. t['\uFE88'] = '\u0625';
  17504. t['\uFE89'] = '\u0626';
  17505. t['\uFE8A'] = '\u0626';
  17506. t['\uFE8B'] = '\u0626';
  17507. t['\uFE8C'] = '\u0626';
  17508. t['\uFE8D'] = '\u0627';
  17509. t['\uFE8E'] = '\u0627';
  17510. t['\uFE8F'] = '\u0628';
  17511. t['\uFE90'] = '\u0628';
  17512. t['\uFE91'] = '\u0628';
  17513. t['\uFE92'] = '\u0628';
  17514. t['\uFE93'] = '\u0629';
  17515. t['\uFE94'] = '\u0629';
  17516. t['\uFE95'] = '\u062A';
  17517. t['\uFE96'] = '\u062A';
  17518. t['\uFE97'] = '\u062A';
  17519. t['\uFE98'] = '\u062A';
  17520. t['\uFE99'] = '\u062B';
  17521. t['\uFE9A'] = '\u062B';
  17522. t['\uFE9B'] = '\u062B';
  17523. t['\uFE9C'] = '\u062B';
  17524. t['\uFE9D'] = '\u062C';
  17525. t['\uFE9E'] = '\u062C';
  17526. t['\uFE9F'] = '\u062C';
  17527. t['\uFEA0'] = '\u062C';
  17528. t['\uFEA1'] = '\u062D';
  17529. t['\uFEA2'] = '\u062D';
  17530. t['\uFEA3'] = '\u062D';
  17531. t['\uFEA4'] = '\u062D';
  17532. t['\uFEA5'] = '\u062E';
  17533. t['\uFEA6'] = '\u062E';
  17534. t['\uFEA7'] = '\u062E';
  17535. t['\uFEA8'] = '\u062E';
  17536. t['\uFEA9'] = '\u062F';
  17537. t['\uFEAA'] = '\u062F';
  17538. t['\uFEAB'] = '\u0630';
  17539. t['\uFEAC'] = '\u0630';
  17540. t['\uFEAD'] = '\u0631';
  17541. t['\uFEAE'] = '\u0631';
  17542. t['\uFEAF'] = '\u0632';
  17543. t['\uFEB0'] = '\u0632';
  17544. t['\uFEB1'] = '\u0633';
  17545. t['\uFEB2'] = '\u0633';
  17546. t['\uFEB3'] = '\u0633';
  17547. t['\uFEB4'] = '\u0633';
  17548. t['\uFEB5'] = '\u0634';
  17549. t['\uFEB6'] = '\u0634';
  17550. t['\uFEB7'] = '\u0634';
  17551. t['\uFEB8'] = '\u0634';
  17552. t['\uFEB9'] = '\u0635';
  17553. t['\uFEBA'] = '\u0635';
  17554. t['\uFEBB'] = '\u0635';
  17555. t['\uFEBC'] = '\u0635';
  17556. t['\uFEBD'] = '\u0636';
  17557. t['\uFEBE'] = '\u0636';
  17558. t['\uFEBF'] = '\u0636';
  17559. t['\uFEC0'] = '\u0636';
  17560. t['\uFEC1'] = '\u0637';
  17561. t['\uFEC2'] = '\u0637';
  17562. t['\uFEC3'] = '\u0637';
  17563. t['\uFEC4'] = '\u0637';
  17564. t['\uFEC5'] = '\u0638';
  17565. t['\uFEC6'] = '\u0638';
  17566. t['\uFEC7'] = '\u0638';
  17567. t['\uFEC8'] = '\u0638';
  17568. t['\uFEC9'] = '\u0639';
  17569. t['\uFECA'] = '\u0639';
  17570. t['\uFECB'] = '\u0639';
  17571. t['\uFECC'] = '\u0639';
  17572. t['\uFECD'] = '\u063A';
  17573. t['\uFECE'] = '\u063A';
  17574. t['\uFECF'] = '\u063A';
  17575. t['\uFED0'] = '\u063A';
  17576. t['\uFED1'] = '\u0641';
  17577. t['\uFED2'] = '\u0641';
  17578. t['\uFED3'] = '\u0641';
  17579. t['\uFED4'] = '\u0641';
  17580. t['\uFED5'] = '\u0642';
  17581. t['\uFED6'] = '\u0642';
  17582. t['\uFED7'] = '\u0642';
  17583. t['\uFED8'] = '\u0642';
  17584. t['\uFED9'] = '\u0643';
  17585. t['\uFEDA'] = '\u0643';
  17586. t['\uFEDB'] = '\u0643';
  17587. t['\uFEDC'] = '\u0643';
  17588. t['\uFEDD'] = '\u0644';
  17589. t['\uFEDE'] = '\u0644';
  17590. t['\uFEDF'] = '\u0644';
  17591. t['\uFEE0'] = '\u0644';
  17592. t['\uFEE1'] = '\u0645';
  17593. t['\uFEE2'] = '\u0645';
  17594. t['\uFEE3'] = '\u0645';
  17595. t['\uFEE4'] = '\u0645';
  17596. t['\uFEE5'] = '\u0646';
  17597. t['\uFEE6'] = '\u0646';
  17598. t['\uFEE7'] = '\u0646';
  17599. t['\uFEE8'] = '\u0646';
  17600. t['\uFEE9'] = '\u0647';
  17601. t['\uFEEA'] = '\u0647';
  17602. t['\uFEEB'] = '\u0647';
  17603. t['\uFEEC'] = '\u0647';
  17604. t['\uFEED'] = '\u0648';
  17605. t['\uFEEE'] = '\u0648';
  17606. t['\uFEEF'] = '\u0649';
  17607. t['\uFEF0'] = '\u0649';
  17608. t['\uFEF1'] = '\u064A';
  17609. t['\uFEF2'] = '\u064A';
  17610. t['\uFEF3'] = '\u064A';
  17611. t['\uFEF4'] = '\u064A';
  17612. t['\uFEF5'] = '\u0644\u0622';
  17613. t['\uFEF6'] = '\u0644\u0622';
  17614. t['\uFEF7'] = '\u0644\u0623';
  17615. t['\uFEF8'] = '\u0644\u0623';
  17616. t['\uFEF9'] = '\u0644\u0625';
  17617. t['\uFEFA'] = '\u0644\u0625';
  17618. t['\uFEFB'] = '\u0644\u0627';
  17619. t['\uFEFC'] = '\u0644\u0627';
  17620. });
  17621. function reverseIfRtl(chars) {
  17622. var charsLength = chars.length;
  17623. //reverse an arabic ligature
  17624. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  17625. return chars;
  17626. }
  17627. var s = '';
  17628. for (var ii = charsLength - 1; ii >= 0; ii--) {
  17629. s += chars[ii];
  17630. }
  17631. return s;
  17632. }
  17633. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  17634. exports.reverseIfRtl = reverseIfRtl;
  17635. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  17636. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  17637. }));
  17638. (function (root, factory) {
  17639. {
  17640. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  17641. root.pdfjsDisplayDOMUtils);
  17642. }
  17643. }(this, function (exports, sharedUtil, displayDOMUtils) {
  17644. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  17645. var AnnotationType = sharedUtil.AnnotationType;
  17646. var Util = sharedUtil.Util;
  17647. var addLinkAttributes = sharedUtil.addLinkAttributes;
  17648. var warn = sharedUtil.warn;
  17649. var CustomStyle = displayDOMUtils.CustomStyle;
  17650. /**
  17651. * @typedef {Object} AnnotationElementParameters
  17652. * @property {Object} data
  17653. * @property {HTMLDivElement} layer
  17654. * @property {PDFPage} page
  17655. * @property {PageViewport} viewport
  17656. * @property {IPDFLinkService} linkService
  17657. */
  17658. /**
  17659. * @class
  17660. * @alias AnnotationElementFactory
  17661. */
  17662. function AnnotationElementFactory() {}
  17663. AnnotationElementFactory.prototype =
  17664. /** @lends AnnotationElementFactory.prototype */ {
  17665. /**
  17666. * @param {AnnotationElementParameters} parameters
  17667. * @returns {AnnotationElement}
  17668. */
  17669. create: function AnnotationElementFactory_create(parameters) {
  17670. var subtype = parameters.data.annotationType;
  17671. switch (subtype) {
  17672. case AnnotationType.LINK:
  17673. return new LinkAnnotationElement(parameters);
  17674. case AnnotationType.TEXT:
  17675. return new TextAnnotationElement(parameters);
  17676. case AnnotationType.WIDGET:
  17677. return new WidgetAnnotationElement(parameters);
  17678. case AnnotationType.POPUP:
  17679. return new PopupAnnotationElement(parameters);
  17680. case AnnotationType.HIGHLIGHT:
  17681. return new HighlightAnnotationElement(parameters);
  17682. case AnnotationType.UNDERLINE:
  17683. return new UnderlineAnnotationElement(parameters);
  17684. case AnnotationType.SQUIGGLY:
  17685. return new SquigglyAnnotationElement(parameters);
  17686. case AnnotationType.STRIKEOUT:
  17687. return new StrikeOutAnnotationElement(parameters);
  17688. default:
  17689. throw new Error('Unimplemented annotation type "' + subtype + '"');
  17690. }
  17691. }
  17692. };
  17693. /**
  17694. * @class
  17695. * @alias AnnotationElement
  17696. */
  17697. var AnnotationElement = (function AnnotationElementClosure() {
  17698. function AnnotationElement(parameters) {
  17699. this.data = parameters.data;
  17700. this.layer = parameters.layer;
  17701. this.page = parameters.page;
  17702. this.viewport = parameters.viewport;
  17703. this.linkService = parameters.linkService;
  17704. this.container = this._createContainer();
  17705. }
  17706. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  17707. /**
  17708. * Create an empty container for the annotation's HTML element.
  17709. *
  17710. * @private
  17711. * @memberof AnnotationElement
  17712. * @returns {HTMLSectionElement}
  17713. */
  17714. _createContainer: function AnnotationElement_createContainer() {
  17715. var data = this.data, page = this.page, viewport = this.viewport;
  17716. var container = document.createElement('section');
  17717. var width = data.rect[2] - data.rect[0];
  17718. var height = data.rect[3] - data.rect[1];
  17719. container.setAttribute('data-annotation-id', data.id);
  17720. // Do *not* modify `data.rect`, since that will corrupt the annotation
  17721. // position on subsequent calls to `_createContainer` (see issue 6804).
  17722. var rect = Util.normalizeRect([
  17723. data.rect[0],
  17724. page.view[3] - data.rect[1] + page.view[1],
  17725. data.rect[2],
  17726. page.view[3] - data.rect[3] + page.view[1]
  17727. ]);
  17728. CustomStyle.setProp('transform', container,
  17729. 'matrix(' + viewport.transform.join(',') + ')');
  17730. CustomStyle.setProp('transformOrigin', container,
  17731. -rect[0] + 'px ' + -rect[1] + 'px');
  17732. if (data.borderStyle.width > 0) {
  17733. container.style.borderWidth = data.borderStyle.width + 'px';
  17734. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  17735. // Underline styles only have a bottom border, so we do not need
  17736. // to adjust for all borders. This yields a similar result as
  17737. // Adobe Acrobat/Reader.
  17738. width = width - 2 * data.borderStyle.width;
  17739. height = height - 2 * data.borderStyle.width;
  17740. }
  17741. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  17742. var verticalRadius = data.borderStyle.verticalCornerRadius;
  17743. if (horizontalRadius > 0 || verticalRadius > 0) {
  17744. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  17745. CustomStyle.setProp('borderRadius', container, radius);
  17746. }
  17747. switch (data.borderStyle.style) {
  17748. case AnnotationBorderStyleType.SOLID:
  17749. container.style.borderStyle = 'solid';
  17750. break;
  17751. case AnnotationBorderStyleType.DASHED:
  17752. container.style.borderStyle = 'dashed';
  17753. break;
  17754. case AnnotationBorderStyleType.BEVELED:
  17755. warn('Unimplemented border style: beveled');
  17756. break;
  17757. case AnnotationBorderStyleType.INSET:
  17758. warn('Unimplemented border style: inset');
  17759. break;
  17760. case AnnotationBorderStyleType.UNDERLINE:
  17761. container.style.borderBottomStyle = 'solid';
  17762. break;
  17763. default:
  17764. break;
  17765. }
  17766. if (data.color) {
  17767. container.style.borderColor =
  17768. Util.makeCssRgb(data.color[0] | 0,
  17769. data.color[1] | 0,
  17770. data.color[2] | 0);
  17771. } else {
  17772. // Transparent (invisible) border, so do not draw it at all.
  17773. container.style.borderWidth = 0;
  17774. }
  17775. }
  17776. container.style.left = rect[0] + 'px';
  17777. container.style.top = rect[1] + 'px';
  17778. container.style.width = width + 'px';
  17779. container.style.height = height + 'px';
  17780. return container;
  17781. },
  17782. /**
  17783. * Render the annotation's HTML element in the empty container.
  17784. *
  17785. * @public
  17786. * @memberof AnnotationElement
  17787. */
  17788. render: function AnnotationElement_render() {
  17789. throw new Error('Abstract method AnnotationElement.render called');
  17790. }
  17791. };
  17792. return AnnotationElement;
  17793. })();
  17794. /**
  17795. * @class
  17796. * @alias LinkAnnotationElement
  17797. */
  17798. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  17799. function LinkAnnotationElement(parameters) {
  17800. AnnotationElement.call(this, parameters);
  17801. }
  17802. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  17803. /**
  17804. * Render the link annotation's HTML element in the empty container.
  17805. *
  17806. * @public
  17807. * @memberof LinkAnnotationElement
  17808. * @returns {HTMLSectionElement}
  17809. */
  17810. render: function LinkAnnotationElement_render() {
  17811. this.container.className = 'linkAnnotation';
  17812. var link = document.createElement('a');
  17813. addLinkAttributes(link, { url: this.data.url });
  17814. if (!this.data.url) {
  17815. if (this.data.action) {
  17816. this._bindNamedAction(link, this.data.action);
  17817. } else {
  17818. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  17819. }
  17820. }
  17821. this.container.appendChild(link);
  17822. return this.container;
  17823. },
  17824. /**
  17825. * Bind internal links to the link element.
  17826. *
  17827. * @private
  17828. * @param {Object} link
  17829. * @param {Object} destination
  17830. * @memberof LinkAnnotationElement
  17831. */
  17832. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  17833. var self = this;
  17834. link.href = this.linkService.getDestinationHash(destination);
  17835. link.onclick = function() {
  17836. if (destination) {
  17837. self.linkService.navigateTo(destination);
  17838. }
  17839. return false;
  17840. };
  17841. if (destination) {
  17842. link.className = 'internalLink';
  17843. }
  17844. },
  17845. /**
  17846. * Bind named actions to the link element.
  17847. *
  17848. * @private
  17849. * @param {Object} link
  17850. * @param {Object} action
  17851. * @memberof LinkAnnotationElement
  17852. */
  17853. _bindNamedAction:
  17854. function LinkAnnotationElement_bindNamedAction(link, action) {
  17855. var self = this;
  17856. link.href = this.linkService.getAnchorUrl('');
  17857. link.onclick = function() {
  17858. self.linkService.executeNamedAction(action);
  17859. return false;
  17860. };
  17861. link.className = 'internalLink';
  17862. }
  17863. });
  17864. return LinkAnnotationElement;
  17865. })();
  17866. /**
  17867. * @class
  17868. * @alias TextAnnotationElement
  17869. */
  17870. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  17871. function TextAnnotationElement(parameters) {
  17872. AnnotationElement.call(this, parameters);
  17873. }
  17874. Util.inherit(TextAnnotationElement, AnnotationElement, {
  17875. /**
  17876. * Render the text annotation's HTML element in the empty container.
  17877. *
  17878. * @public
  17879. * @memberof TextAnnotationElement
  17880. * @returns {HTMLSectionElement}
  17881. */
  17882. render: function TextAnnotationElement_render() {
  17883. this.container.className = 'textAnnotation';
  17884. var image = document.createElement('img');
  17885. image.style.height = this.container.style.height;
  17886. image.style.width = this.container.style.width;
  17887. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  17888. this.data.name.toLowerCase() + '.svg';
  17889. image.alt = '[{{type}} Annotation]';
  17890. image.dataset.l10nId = 'text_annotation_type';
  17891. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  17892. if (!this.data.hasPopup) {
  17893. var popupElement = new PopupElement({
  17894. container: this.container,
  17895. trigger: image,
  17896. color: this.data.color,
  17897. title: this.data.title,
  17898. contents: this.data.contents,
  17899. hideWrapper: true
  17900. });
  17901. var popup = popupElement.render();
  17902. // Position the popup next to the Text annotation's container.
  17903. popup.style.left = image.style.width;
  17904. this.container.appendChild(popup);
  17905. }
  17906. this.container.appendChild(image);
  17907. return this.container;
  17908. }
  17909. });
  17910. return TextAnnotationElement;
  17911. })();
  17912. /**
  17913. * @class
  17914. * @alias WidgetAnnotationElement
  17915. */
  17916. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  17917. function WidgetAnnotationElement(parameters) {
  17918. AnnotationElement.call(this, parameters);
  17919. }
  17920. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  17921. /**
  17922. * Render the widget annotation's HTML element in the empty container.
  17923. *
  17924. * @public
  17925. * @memberof WidgetAnnotationElement
  17926. * @returns {HTMLSectionElement}
  17927. */
  17928. render: function WidgetAnnotationElement_render() {
  17929. var content = document.createElement('div');
  17930. content.textContent = this.data.fieldValue;
  17931. var textAlignment = this.data.textAlignment;
  17932. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  17933. content.style.verticalAlign = 'middle';
  17934. content.style.display = 'table-cell';
  17935. var font = (this.data.fontRefName ?
  17936. this.page.commonObjs.getData(this.data.fontRefName) : null);
  17937. this._setTextStyle(content, font);
  17938. this.container.appendChild(content);
  17939. return this.container;
  17940. },
  17941. /**
  17942. * Apply text styles to the text in the element.
  17943. *
  17944. * @private
  17945. * @param {HTMLDivElement} element
  17946. * @param {Object} font
  17947. * @memberof WidgetAnnotationElement
  17948. */
  17949. _setTextStyle:
  17950. function WidgetAnnotationElement_setTextStyle(element, font) {
  17951. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  17952. var style = element.style;
  17953. style.fontSize = this.data.fontSize + 'px';
  17954. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  17955. if (!font) {
  17956. return;
  17957. }
  17958. style.fontWeight = (font.black ?
  17959. (font.bold ? '900' : 'bold') :
  17960. (font.bold ? 'bold' : 'normal'));
  17961. style.fontStyle = (font.italic ? 'italic' : 'normal');
  17962. // Use a reasonable default font if the font doesn't specify a fallback.
  17963. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  17964. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  17965. style.fontFamily = fontFamily + fallbackName;
  17966. }
  17967. });
  17968. return WidgetAnnotationElement;
  17969. })();
  17970. /**
  17971. * @class
  17972. * @alias PopupAnnotationElement
  17973. */
  17974. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  17975. function PopupAnnotationElement(parameters) {
  17976. AnnotationElement.call(this, parameters);
  17977. }
  17978. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  17979. /**
  17980. * Render the popup annotation's HTML element in the empty container.
  17981. *
  17982. * @public
  17983. * @memberof PopupAnnotationElement
  17984. * @returns {HTMLSectionElement}
  17985. */
  17986. render: function PopupAnnotationElement_render() {
  17987. this.container.className = 'popupAnnotation';
  17988. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  17989. var parentElement = this.layer.querySelector(selector);
  17990. if (!parentElement) {
  17991. return this.container;
  17992. }
  17993. var popup = new PopupElement({
  17994. container: this.container,
  17995. trigger: parentElement,
  17996. color: this.data.color,
  17997. title: this.data.title,
  17998. contents: this.data.contents
  17999. });
  18000. // Position the popup next to the parent annotation's container.
  18001. // PDF viewers ignore a popup annotation's rectangle.
  18002. var parentLeft = parseFloat(parentElement.style.left);
  18003. var parentWidth = parseFloat(parentElement.style.width);
  18004. CustomStyle.setProp('transformOrigin', this.container,
  18005. -(parentLeft + parentWidth) + 'px -' +
  18006. parentElement.style.top);
  18007. this.container.style.left = (parentLeft + parentWidth) + 'px';
  18008. this.container.appendChild(popup.render());
  18009. return this.container;
  18010. }
  18011. });
  18012. return PopupAnnotationElement;
  18013. })();
  18014. /**
  18015. * @class
  18016. * @alias PopupElement
  18017. */
  18018. var PopupElement = (function PopupElementClosure() {
  18019. var BACKGROUND_ENLIGHT = 0.7;
  18020. function PopupElement(parameters) {
  18021. this.container = parameters.container;
  18022. this.trigger = parameters.trigger;
  18023. this.color = parameters.color;
  18024. this.title = parameters.title;
  18025. this.contents = parameters.contents;
  18026. this.hideWrapper = parameters.hideWrapper || false;
  18027. this.pinned = false;
  18028. }
  18029. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  18030. /**
  18031. * Render the popup's HTML element.
  18032. *
  18033. * @public
  18034. * @memberof PopupElement
  18035. * @returns {HTMLSectionElement}
  18036. */
  18037. render: function PopupElement_render() {
  18038. var wrapper = document.createElement('div');
  18039. wrapper.className = 'popupWrapper';
  18040. // For Popup annotations we hide the entire section because it contains
  18041. // only the popup. However, for Text annotations without a separate Popup
  18042. // annotation, we cannot hide the entire container as the image would
  18043. // disappear too. In that special case, hiding the wrapper suffices.
  18044. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  18045. this.hideElement.setAttribute('hidden', true);
  18046. var popup = document.createElement('div');
  18047. popup.className = 'popup';
  18048. var color = this.color;
  18049. if (color) {
  18050. // Enlighten the color.
  18051. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  18052. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  18053. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  18054. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  18055. }
  18056. var contents = this._formatContents(this.contents);
  18057. var title = document.createElement('h1');
  18058. title.textContent = this.title;
  18059. // Attach the event listeners to the trigger element.
  18060. this.trigger.addEventListener('click', this._toggle.bind(this));
  18061. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  18062. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  18063. popup.addEventListener('click', this._hide.bind(this, true));
  18064. popup.appendChild(title);
  18065. popup.appendChild(contents);
  18066. wrapper.appendChild(popup);
  18067. return wrapper;
  18068. },
  18069. /**
  18070. * Format the contents of the popup by adding newlines where necessary.
  18071. *
  18072. * @private
  18073. * @param {string} contents
  18074. * @memberof PopupElement
  18075. * @returns {HTMLParagraphElement}
  18076. */
  18077. _formatContents: function PopupElement_formatContents(contents) {
  18078. var p = document.createElement('p');
  18079. var lines = contents.split(/(?:\r\n?|\n)/);
  18080. for (var i = 0, ii = lines.length; i < ii; ++i) {
  18081. var line = lines[i];
  18082. p.appendChild(document.createTextNode(line));
  18083. if (i < (ii - 1)) {
  18084. p.appendChild(document.createElement('br'));
  18085. }
  18086. }
  18087. return p;
  18088. },
  18089. /**
  18090. * Toggle the visibility of the popup.
  18091. *
  18092. * @private
  18093. * @memberof PopupElement
  18094. */
  18095. _toggle: function PopupElement_toggle() {
  18096. if (this.pinned) {
  18097. this._hide(true);
  18098. } else {
  18099. this._show(true);
  18100. }
  18101. },
  18102. /**
  18103. * Show the popup.
  18104. *
  18105. * @private
  18106. * @param {boolean} pin
  18107. * @memberof PopupElement
  18108. */
  18109. _show: function PopupElement_show(pin) {
  18110. if (pin) {
  18111. this.pinned = true;
  18112. }
  18113. if (this.hideElement.hasAttribute('hidden')) {
  18114. this.hideElement.removeAttribute('hidden');
  18115. this.container.style.zIndex += 1;
  18116. }
  18117. },
  18118. /**
  18119. * Hide the popup.
  18120. *
  18121. * @private
  18122. * @param {boolean} unpin
  18123. * @memberof PopupElement
  18124. */
  18125. _hide: function PopupElement_hide(unpin) {
  18126. if (unpin) {
  18127. this.pinned = false;
  18128. }
  18129. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  18130. this.hideElement.setAttribute('hidden', true);
  18131. this.container.style.zIndex -= 1;
  18132. }
  18133. }
  18134. };
  18135. return PopupElement;
  18136. })();
  18137. /**
  18138. * @class
  18139. * @alias HighlightAnnotationElement
  18140. */
  18141. var HighlightAnnotationElement = (
  18142. function HighlightAnnotationElementClosure() {
  18143. function HighlightAnnotationElement(parameters) {
  18144. AnnotationElement.call(this, parameters);
  18145. }
  18146. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  18147. /**
  18148. * Render the highlight annotation's HTML element in the empty container.
  18149. *
  18150. * @public
  18151. * @memberof HighlightAnnotationElement
  18152. * @returns {HTMLSectionElement}
  18153. */
  18154. render: function HighlightAnnotationElement_render() {
  18155. this.container.className = 'highlightAnnotation';
  18156. return this.container;
  18157. }
  18158. });
  18159. return HighlightAnnotationElement;
  18160. })();
  18161. /**
  18162. * @class
  18163. * @alias UnderlineAnnotationElement
  18164. */
  18165. var UnderlineAnnotationElement = (
  18166. function UnderlineAnnotationElementClosure() {
  18167. function UnderlineAnnotationElement(parameters) {
  18168. AnnotationElement.call(this, parameters);
  18169. }
  18170. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  18171. /**
  18172. * Render the underline annotation's HTML element in the empty container.
  18173. *
  18174. * @public
  18175. * @memberof UnderlineAnnotationElement
  18176. * @returns {HTMLSectionElement}
  18177. */
  18178. render: function UnderlineAnnotationElement_render() {
  18179. this.container.className = 'underlineAnnotation';
  18180. return this.container;
  18181. }
  18182. });
  18183. return UnderlineAnnotationElement;
  18184. })();
  18185. /**
  18186. * @class
  18187. * @alias SquigglyAnnotationElement
  18188. */
  18189. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  18190. function SquigglyAnnotationElement(parameters) {
  18191. AnnotationElement.call(this, parameters);
  18192. }
  18193. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  18194. /**
  18195. * Render the squiggly annotation's HTML element in the empty container.
  18196. *
  18197. * @public
  18198. * @memberof SquigglyAnnotationElement
  18199. * @returns {HTMLSectionElement}
  18200. */
  18201. render: function SquigglyAnnotationElement_render() {
  18202. this.container.className = 'squigglyAnnotation';
  18203. return this.container;
  18204. }
  18205. });
  18206. return SquigglyAnnotationElement;
  18207. })();
  18208. /**
  18209. * @class
  18210. * @alias StrikeOutAnnotationElement
  18211. */
  18212. var StrikeOutAnnotationElement = (
  18213. function StrikeOutAnnotationElementClosure() {
  18214. function StrikeOutAnnotationElement(parameters) {
  18215. AnnotationElement.call(this, parameters);
  18216. }
  18217. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  18218. /**
  18219. * Render the strikeout annotation's HTML element in the empty container.
  18220. *
  18221. * @public
  18222. * @memberof StrikeOutAnnotationElement
  18223. * @returns {HTMLSectionElement}
  18224. */
  18225. render: function StrikeOutAnnotationElement_render() {
  18226. this.container.className = 'strikeoutAnnotation';
  18227. return this.container;
  18228. }
  18229. });
  18230. return StrikeOutAnnotationElement;
  18231. })();
  18232. /**
  18233. * @typedef {Object} AnnotationLayerParameters
  18234. * @property {PageViewport} viewport
  18235. * @property {HTMLDivElement} div
  18236. * @property {Array} annotations
  18237. * @property {PDFPage} page
  18238. * @property {IPDFLinkService} linkService
  18239. */
  18240. /**
  18241. * @class
  18242. * @alias AnnotationLayer
  18243. */
  18244. var AnnotationLayer = (function AnnotationLayerClosure() {
  18245. return {
  18246. /**
  18247. * Render a new annotation layer with all annotation elements.
  18248. *
  18249. * @public
  18250. * @param {AnnotationLayerParameters} parameters
  18251. * @memberof AnnotationLayer
  18252. */
  18253. render: function AnnotationLayer_render(parameters) {
  18254. var annotationElementFactory = new AnnotationElementFactory();
  18255. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  18256. var data = parameters.annotations[i];
  18257. if (!data || !data.hasHtml) {
  18258. continue;
  18259. }
  18260. var properties = {
  18261. data: data,
  18262. layer: parameters.div,
  18263. page: parameters.page,
  18264. viewport: parameters.viewport,
  18265. linkService: parameters.linkService
  18266. };
  18267. var element = annotationElementFactory.create(properties);
  18268. parameters.div.appendChild(element.render());
  18269. }
  18270. },
  18271. /**
  18272. * Update the annotation elements on existing annotation layer.
  18273. *
  18274. * @public
  18275. * @param {AnnotationLayerParameters} parameters
  18276. * @memberof AnnotationLayer
  18277. */
  18278. update: function AnnotationLayer_update(parameters) {
  18279. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  18280. var data = parameters.annotations[i];
  18281. var element = parameters.div.querySelector(
  18282. '[data-annotation-id="' + data.id + '"]');
  18283. if (element) {
  18284. CustomStyle.setProp('transform', element,
  18285. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  18286. }
  18287. }
  18288. parameters.div.removeAttribute('hidden');
  18289. }
  18290. };
  18291. })();
  18292. PDFJS.AnnotationLayer = AnnotationLayer;
  18293. exports.AnnotationLayer = AnnotationLayer;
  18294. }));
  18295. (function (root, factory) {
  18296. {
  18297. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  18298. root.pdfjsSharedGlobal);
  18299. }
  18300. }(this, function (exports, sharedUtil, sharedGlobal) {
  18301. var assert = sharedUtil.assert;
  18302. var bytesToString = sharedUtil.bytesToString;
  18303. var string32 = sharedUtil.string32;
  18304. var shadow = sharedUtil.shadow;
  18305. var warn = sharedUtil.warn;
  18306. var PDFJS = sharedGlobal.PDFJS;
  18307. var globalScope = sharedGlobal.globalScope;
  18308. var isWorker = sharedGlobal.isWorker;
  18309. function FontLoader(docId) {
  18310. this.docId = docId;
  18311. this.styleElement = null;
  18312. this.nativeFontFaces = [];
  18313. this.loadTestFontId = 0;
  18314. this.loadingContext = {
  18315. requests: [],
  18316. nextRequestId: 0
  18317. };
  18318. }
  18319. FontLoader.prototype = {
  18320. insertRule: function fontLoaderInsertRule(rule) {
  18321. var styleElement = this.styleElement;
  18322. if (!styleElement) {
  18323. styleElement = this.styleElement = document.createElement('style');
  18324. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  18325. document.documentElement.getElementsByTagName('head')[0].appendChild(
  18326. styleElement);
  18327. }
  18328. var styleSheet = styleElement.sheet;
  18329. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  18330. },
  18331. clear: function fontLoaderClear() {
  18332. var styleElement = this.styleElement;
  18333. if (styleElement) {
  18334. styleElement.parentNode.removeChild(styleElement);
  18335. styleElement = this.styleElement = null;
  18336. }
  18337. this.nativeFontFaces.forEach(function(nativeFontFace) {
  18338. document.fonts.delete(nativeFontFace);
  18339. });
  18340. this.nativeFontFaces.length = 0;
  18341. },
  18342. get loadTestFont() {
  18343. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  18344. // height.
  18345. return shadow(this, 'loadTestFont', atob(
  18346. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  18347. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  18348. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  18349. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  18350. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  18351. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  18352. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  18353. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  18354. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  18355. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  18356. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  18357. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  18358. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  18359. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18360. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18361. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  18362. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  18363. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  18364. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  18365. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  18366. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  18367. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  18368. ));
  18369. },
  18370. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  18371. this.nativeFontFaces.push(nativeFontFace);
  18372. document.fonts.add(nativeFontFace);
  18373. },
  18374. bind: function fontLoaderBind(fonts, callback) {
  18375. assert(!isWorker, 'bind() shall be called from main thread');
  18376. var rules = [];
  18377. var fontsToLoad = [];
  18378. var fontLoadPromises = [];
  18379. var getNativeFontPromise = function(nativeFontFace) {
  18380. // Return a promise that is always fulfilled, even when the font fails to
  18381. // load.
  18382. return nativeFontFace.loaded.catch(function(e) {
  18383. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  18384. });
  18385. };
  18386. for (var i = 0, ii = fonts.length; i < ii; i++) {
  18387. var font = fonts[i];
  18388. // Add the font to the DOM only once or skip if the font
  18389. // is already loaded.
  18390. if (font.attached || font.loading === false) {
  18391. continue;
  18392. }
  18393. font.attached = true;
  18394. if (FontLoader.isFontLoadingAPISupported) {
  18395. var nativeFontFace = font.createNativeFontFace();
  18396. if (nativeFontFace) {
  18397. this.addNativeFontFace(nativeFontFace);
  18398. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  18399. }
  18400. } else {
  18401. var rule = font.createFontFaceRule();
  18402. if (rule) {
  18403. this.insertRule(rule);
  18404. rules.push(rule);
  18405. fontsToLoad.push(font);
  18406. }
  18407. }
  18408. }
  18409. var request = this.queueLoadingCallback(callback);
  18410. if (FontLoader.isFontLoadingAPISupported) {
  18411. Promise.all(fontLoadPromises).then(function() {
  18412. request.complete();
  18413. });
  18414. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  18415. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  18416. } else {
  18417. request.complete();
  18418. }
  18419. },
  18420. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  18421. function LoadLoader_completeRequest() {
  18422. assert(!request.end, 'completeRequest() cannot be called twice');
  18423. request.end = Date.now();
  18424. // sending all completed requests in order how they were queued
  18425. while (context.requests.length > 0 && context.requests[0].end) {
  18426. var otherRequest = context.requests.shift();
  18427. setTimeout(otherRequest.callback, 0);
  18428. }
  18429. }
  18430. var context = this.loadingContext;
  18431. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  18432. var request = {
  18433. id: requestId,
  18434. complete: LoadLoader_completeRequest,
  18435. callback: callback,
  18436. started: Date.now()
  18437. };
  18438. context.requests.push(request);
  18439. return request;
  18440. },
  18441. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  18442. fonts,
  18443. request) {
  18444. /** Hack begin */
  18445. // There's currently no event when a font has finished downloading so the
  18446. // following code is a dirty hack to 'guess' when a font is
  18447. // ready. It's assumed fonts are loaded in order, so add a known test
  18448. // font after the desired fonts and then test for the loading of that
  18449. // test font.
  18450. function int32(data, offset) {
  18451. return (data.charCodeAt(offset) << 24) |
  18452. (data.charCodeAt(offset + 1) << 16) |
  18453. (data.charCodeAt(offset + 2) << 8) |
  18454. (data.charCodeAt(offset + 3) & 0xff);
  18455. }
  18456. function spliceString(s, offset, remove, insert) {
  18457. var chunk1 = s.substr(0, offset);
  18458. var chunk2 = s.substr(offset + remove);
  18459. return chunk1 + insert + chunk2;
  18460. }
  18461. var i, ii;
  18462. var canvas = document.createElement('canvas');
  18463. canvas.width = 1;
  18464. canvas.height = 1;
  18465. var ctx = canvas.getContext('2d');
  18466. var called = 0;
  18467. function isFontReady(name, callback) {
  18468. called++;
  18469. // With setTimeout clamping this gives the font ~100ms to load.
  18470. if(called > 30) {
  18471. warn('Load test font never loaded.');
  18472. callback();
  18473. return;
  18474. }
  18475. ctx.font = '30px ' + name;
  18476. ctx.fillText('.', 0, 20);
  18477. var imageData = ctx.getImageData(0, 0, 1, 1);
  18478. if (imageData.data[3] > 0) {
  18479. callback();
  18480. return;
  18481. }
  18482. setTimeout(isFontReady.bind(null, name, callback));
  18483. }
  18484. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  18485. // Chromium seems to cache fonts based on a hash of the actual font data,
  18486. // so the font must be modified for each load test else it will appear to
  18487. // be loaded already.
  18488. // TODO: This could maybe be made faster by avoiding the btoa of the full
  18489. // font by splitting it in chunks before hand and padding the font id.
  18490. var data = this.loadTestFont;
  18491. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  18492. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  18493. loadTestFontId);
  18494. // CFF checksum is important for IE, adjusting it
  18495. var CFF_CHECKSUM_OFFSET = 16;
  18496. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  18497. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  18498. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  18499. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  18500. }
  18501. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  18502. checksum = (checksum - XXXX_VALUE +
  18503. int32(loadTestFontId + 'XXX', i)) | 0;
  18504. }
  18505. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  18506. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  18507. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  18508. url + '}';
  18509. this.insertRule(rule);
  18510. var names = [];
  18511. for (i = 0, ii = fonts.length; i < ii; i++) {
  18512. names.push(fonts[i].loadedName);
  18513. }
  18514. names.push(loadTestFontId);
  18515. var div = document.createElement('div');
  18516. div.setAttribute('style',
  18517. 'visibility: hidden;' +
  18518. 'width: 10px; height: 10px;' +
  18519. 'position: absolute; top: 0px; left: 0px;');
  18520. for (i = 0, ii = names.length; i < ii; ++i) {
  18521. var span = document.createElement('span');
  18522. span.textContent = 'Hi';
  18523. span.style.fontFamily = names[i];
  18524. div.appendChild(span);
  18525. }
  18526. document.body.appendChild(div);
  18527. isFontReady(loadTestFontId, function() {
  18528. document.body.removeChild(div);
  18529. request.complete();
  18530. });
  18531. /** Hack end */
  18532. }
  18533. };
  18534. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  18535. typeof document !== 'undefined' && !!document.fonts);
  18536. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  18537. get: function () {
  18538. var supported = false;
  18539. // User agent string sniffing is bad, but there is no reliable way to tell
  18540. // if font is fully loaded and ready to be used with canvas.
  18541. var userAgent = window.navigator.userAgent;
  18542. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  18543. if (m && m[1] >= 14) {
  18544. supported = true;
  18545. }
  18546. // TODO other browsers
  18547. if (userAgent === 'node') {
  18548. supported = true;
  18549. }
  18550. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  18551. },
  18552. enumerable: true,
  18553. configurable: true
  18554. });
  18555. var FontFaceObject = (function FontFaceObjectClosure() {
  18556. function FontFaceObject(translatedData) {
  18557. this.compiledGlyphs = Object.create(null);
  18558. // importing translated data
  18559. for (var i in translatedData) {
  18560. this[i] = translatedData[i];
  18561. }
  18562. }
  18563. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  18564. get: function () {
  18565. var evalSupport = false;
  18566. if (PDFJS.isEvalSupported) {
  18567. try {
  18568. /* jshint evil: true */
  18569. new Function('');
  18570. evalSupport = true;
  18571. } catch (e) {}
  18572. }
  18573. return shadow(this, 'isEvalSupported', evalSupport);
  18574. },
  18575. enumerable: true,
  18576. configurable: true
  18577. });
  18578. FontFaceObject.prototype = {
  18579. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  18580. if (!this.data) {
  18581. return null;
  18582. }
  18583. if (PDFJS.disableFontFace) {
  18584. this.disableFontFace = true;
  18585. return null;
  18586. }
  18587. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  18588. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  18589. globalScope['FontInspector'].enabled) {
  18590. globalScope['FontInspector'].fontAdded(this);
  18591. }
  18592. return nativeFontFace;
  18593. },
  18594. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  18595. if (!this.data) {
  18596. return null;
  18597. }
  18598. if (PDFJS.disableFontFace) {
  18599. this.disableFontFace = true;
  18600. return null;
  18601. }
  18602. var data = bytesToString(new Uint8Array(this.data));
  18603. var fontName = this.loadedName;
  18604. // Add the font-face rule to the document
  18605. var url = ('url(data:' + this.mimetype + ';base64,' +
  18606. window.btoa(data) + ');');
  18607. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  18608. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  18609. globalScope['FontInspector'].enabled) {
  18610. globalScope['FontInspector'].fontAdded(this, url);
  18611. }
  18612. return rule;
  18613. },
  18614. getPathGenerator:
  18615. function FontFaceObject_getPathGenerator(objs, character) {
  18616. if (!(character in this.compiledGlyphs)) {
  18617. var cmds = objs.get(this.loadedName + '_path_' + character);
  18618. var current, i, len;
  18619. // If we can, compile cmds into JS for MAXIMUM SPEED
  18620. if (FontFaceObject.isEvalSupported) {
  18621. var args, js = '';
  18622. for (i = 0, len = cmds.length; i < len; i++) {
  18623. current = cmds[i];
  18624. if (current.args !== undefined) {
  18625. args = current.args.join(',');
  18626. } else {
  18627. args = '';
  18628. }
  18629. js += 'c.' + current.cmd + '(' + args + ');\n';
  18630. }
  18631. /* jshint -W054 */
  18632. this.compiledGlyphs[character] = new Function('c', 'size', js);
  18633. } else {
  18634. // But fall back on using Function.prototype.apply() if we're
  18635. // blocked from using eval() for whatever reason (like CSP policies)
  18636. this.compiledGlyphs[character] = function(c, size) {
  18637. for (i = 0, len = cmds.length; i < len; i++) {
  18638. current = cmds[i];
  18639. if (current.cmd === 'scale') {
  18640. current.args = [size, -size];
  18641. }
  18642. c[current.cmd].apply(c, current.args);
  18643. }
  18644. };
  18645. }
  18646. }
  18647. return this.compiledGlyphs[character];
  18648. }
  18649. };
  18650. return FontFaceObject;
  18651. })();
  18652. exports.FontFaceObject = FontFaceObject;
  18653. exports.FontLoader = FontLoader;
  18654. }));
  18655. (function (root, factory) {
  18656. {
  18657. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil);
  18658. }
  18659. }(this, function (exports, sharedUtil) {
  18660. var error = sharedUtil.error;
  18661. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  18662. function fixMetadata(meta) {
  18663. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  18664. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  18665. function(code, d1, d2, d3) {
  18666. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  18667. });
  18668. var chars = '';
  18669. for (var i = 0; i < bytes.length; i += 2) {
  18670. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  18671. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  18672. code !== 38 && false ? String.fromCharCode(code) :
  18673. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  18674. }
  18675. return '>' + chars;
  18676. });
  18677. }
  18678. function Metadata(meta) {
  18679. if (typeof meta === 'string') {
  18680. // Ghostscript produces invalid metadata
  18681. meta = fixMetadata(meta);
  18682. var parser = new DOMParser();
  18683. meta = parser.parseFromString(meta, 'application/xml');
  18684. } else if (!(meta instanceof Document)) {
  18685. error('Metadata: Invalid metadata object');
  18686. }
  18687. this.metaDocument = meta;
  18688. this.metadata = Object.create(null);
  18689. this.parse();
  18690. }
  18691. Metadata.prototype = {
  18692. parse: function Metadata_parse() {
  18693. var doc = this.metaDocument;
  18694. var rdf = doc.documentElement;
  18695. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  18696. rdf = rdf.firstChild;
  18697. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  18698. rdf = rdf.nextSibling;
  18699. }
  18700. }
  18701. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  18702. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  18703. return;
  18704. }
  18705. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  18706. for (i = 0, length = children.length; i < length; i++) {
  18707. desc = children[i];
  18708. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  18709. continue;
  18710. }
  18711. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  18712. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  18713. entry = desc.childNodes[ii];
  18714. name = entry.nodeName.toLowerCase();
  18715. this.metadata[name] = entry.textContent.trim();
  18716. }
  18717. }
  18718. }
  18719. },
  18720. get: function Metadata_get(name) {
  18721. return this.metadata[name] || null;
  18722. },
  18723. has: function Metadata_has(name) {
  18724. return typeof this.metadata[name] !== 'undefined';
  18725. }
  18726. };
  18727. return Metadata;
  18728. })();
  18729. exports.Metadata = Metadata;
  18730. }));
  18731. (function (root, factory) {
  18732. {
  18733. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil);
  18734. }
  18735. }(this, function (exports, sharedUtil) {
  18736. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  18737. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  18738. var ImageKind = sharedUtil.ImageKind;
  18739. var OPS = sharedUtil.OPS;
  18740. var Util = sharedUtil.Util;
  18741. var isNum = sharedUtil.isNum;
  18742. var isArray = sharedUtil.isArray;
  18743. var warn = sharedUtil.warn;
  18744. var SVG_DEFAULTS = {
  18745. fontStyle: 'normal',
  18746. fontWeight: 'normal',
  18747. fillColor: '#000000'
  18748. };
  18749. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  18750. var PNG_HEADER =
  18751. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  18752. var CHUNK_WRAPPER_SIZE = 12;
  18753. var crcTable = new Int32Array(256);
  18754. for (var i = 0; i < 256; i++) {
  18755. var c = i;
  18756. for (var h = 0; h < 8; h++) {
  18757. if (c & 1) {
  18758. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  18759. } else {
  18760. c = (c >> 1) & 0x7fffffff;
  18761. }
  18762. }
  18763. crcTable[i] = c;
  18764. }
  18765. function crc32(data, start, end) {
  18766. var crc = -1;
  18767. for (var i = start; i < end; i++) {
  18768. var a = (crc ^ data[i]) & 0xff;
  18769. var b = crcTable[a];
  18770. crc = (crc >>> 8) ^ b;
  18771. }
  18772. return crc ^ -1;
  18773. }
  18774. function writePngChunk(type, body, data, offset) {
  18775. var p = offset;
  18776. var len = body.length;
  18777. data[p] = len >> 24 & 0xff;
  18778. data[p + 1] = len >> 16 & 0xff;
  18779. data[p + 2] = len >> 8 & 0xff;
  18780. data[p + 3] = len & 0xff;
  18781. p += 4;
  18782. data[p] = type.charCodeAt(0) & 0xff;
  18783. data[p + 1] = type.charCodeAt(1) & 0xff;
  18784. data[p + 2] = type.charCodeAt(2) & 0xff;
  18785. data[p + 3] = type.charCodeAt(3) & 0xff;
  18786. p += 4;
  18787. data.set(body, p);
  18788. p += body.length;
  18789. var crc = crc32(data, offset + 4, p);
  18790. data[p] = crc >> 24 & 0xff;
  18791. data[p + 1] = crc >> 16 & 0xff;
  18792. data[p + 2] = crc >> 8 & 0xff;
  18793. data[p + 3] = crc & 0xff;
  18794. }
  18795. function adler32(data, start, end) {
  18796. var a = 1;
  18797. var b = 0;
  18798. for (var i = start; i < end; ++i) {
  18799. a = (a + (data[i] & 0xff)) % 65521;
  18800. b = (b + a) % 65521;
  18801. }
  18802. return (b << 16) | a;
  18803. }
  18804. function encode(imgData, kind) {
  18805. var width = imgData.width;
  18806. var height = imgData.height;
  18807. var bitDepth, colorType, lineSize;
  18808. var bytes = imgData.data;
  18809. switch (kind) {
  18810. case ImageKind.GRAYSCALE_1BPP:
  18811. colorType = 0;
  18812. bitDepth = 1;
  18813. lineSize = (width + 7) >> 3;
  18814. break;
  18815. case ImageKind.RGB_24BPP:
  18816. colorType = 2;
  18817. bitDepth = 8;
  18818. lineSize = width * 3;
  18819. break;
  18820. case ImageKind.RGBA_32BPP:
  18821. colorType = 6;
  18822. bitDepth = 8;
  18823. lineSize = width * 4;
  18824. break;
  18825. default:
  18826. throw new Error('invalid format');
  18827. }
  18828. // prefix every row with predictor 0
  18829. var literals = new Uint8Array((1 + lineSize) * height);
  18830. var offsetLiterals = 0, offsetBytes = 0;
  18831. var y, i;
  18832. for (y = 0; y < height; ++y) {
  18833. literals[offsetLiterals++] = 0; // no prediction
  18834. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  18835. offsetLiterals);
  18836. offsetBytes += lineSize;
  18837. offsetLiterals += lineSize;
  18838. }
  18839. if (kind === ImageKind.GRAYSCALE_1BPP) {
  18840. // inverting for B/W
  18841. offsetLiterals = 0;
  18842. for (y = 0; y < height; y++) {
  18843. offsetLiterals++; // skipping predictor
  18844. for (i = 0; i < lineSize; i++) {
  18845. literals[offsetLiterals++] ^= 0xFF;
  18846. }
  18847. }
  18848. }
  18849. var ihdr = new Uint8Array([
  18850. width >> 24 & 0xff,
  18851. width >> 16 & 0xff,
  18852. width >> 8 & 0xff,
  18853. width & 0xff,
  18854. height >> 24 & 0xff,
  18855. height >> 16 & 0xff,
  18856. height >> 8 & 0xff,
  18857. height & 0xff,
  18858. bitDepth, // bit depth
  18859. colorType, // color type
  18860. 0x00, // compression method
  18861. 0x00, // filter method
  18862. 0x00 // interlace method
  18863. ]);
  18864. var len = literals.length;
  18865. var maxBlockLength = 0xFFFF;
  18866. var deflateBlocks = Math.ceil(len / maxBlockLength);
  18867. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  18868. var pi = 0;
  18869. idat[pi++] = 0x78; // compression method and flags
  18870. idat[pi++] = 0x9c; // flags
  18871. var pos = 0;
  18872. while (len > maxBlockLength) {
  18873. // writing non-final DEFLATE blocks type 0 and length of 65535
  18874. idat[pi++] = 0x00;
  18875. idat[pi++] = 0xff;
  18876. idat[pi++] = 0xff;
  18877. idat[pi++] = 0x00;
  18878. idat[pi++] = 0x00;
  18879. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  18880. pi += maxBlockLength;
  18881. pos += maxBlockLength;
  18882. len -= maxBlockLength;
  18883. }
  18884. // writing non-final DEFLATE blocks type 0
  18885. idat[pi++] = 0x01;
  18886. idat[pi++] = len & 0xff;
  18887. idat[pi++] = len >> 8 & 0xff;
  18888. idat[pi++] = (~len & 0xffff) & 0xff;
  18889. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  18890. idat.set(literals.subarray(pos), pi);
  18891. pi += literals.length - pos;
  18892. var adler = adler32(literals, 0, literals.length); // checksum
  18893. idat[pi++] = adler >> 24 & 0xff;
  18894. idat[pi++] = adler >> 16 & 0xff;
  18895. idat[pi++] = adler >> 8 & 0xff;
  18896. idat[pi++] = adler & 0xff;
  18897. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  18898. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  18899. ihdr.length + idat.length;
  18900. var data = new Uint8Array(pngLength);
  18901. var offset = 0;
  18902. data.set(PNG_HEADER, offset);
  18903. offset += PNG_HEADER.length;
  18904. writePngChunk('IHDR', ihdr, data, offset);
  18905. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  18906. writePngChunk('IDATA', idat, data, offset);
  18907. offset += CHUNK_WRAPPER_SIZE + idat.length;
  18908. writePngChunk('IEND', new Uint8Array(0), data, offset);
  18909. return PDFJS.createObjectURL(data, 'image/png');
  18910. }
  18911. return function convertImgDataToPng(imgData) {
  18912. var kind = (imgData.kind === undefined ?
  18913. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  18914. return encode(imgData, kind);
  18915. };
  18916. })();
  18917. var SVGExtraState = (function SVGExtraStateClosure() {
  18918. function SVGExtraState() {
  18919. this.fontSizeScale = 1;
  18920. this.fontWeight = SVG_DEFAULTS.fontWeight;
  18921. this.fontSize = 0;
  18922. this.textMatrix = IDENTITY_MATRIX;
  18923. this.fontMatrix = FONT_IDENTITY_MATRIX;
  18924. this.leading = 0;
  18925. // Current point (in user coordinates)
  18926. this.x = 0;
  18927. this.y = 0;
  18928. // Start of text line (in text coordinates)
  18929. this.lineX = 0;
  18930. this.lineY = 0;
  18931. // Character and word spacing
  18932. this.charSpacing = 0;
  18933. this.wordSpacing = 0;
  18934. this.textHScale = 1;
  18935. this.textRise = 0;
  18936. // Default foreground and background colors
  18937. this.fillColor = SVG_DEFAULTS.fillColor;
  18938. this.strokeColor = '#000000';
  18939. this.fillAlpha = 1;
  18940. this.strokeAlpha = 1;
  18941. this.lineWidth = 1;
  18942. this.lineJoin = '';
  18943. this.lineCap = '';
  18944. this.miterLimit = 0;
  18945. this.dashArray = [];
  18946. this.dashPhase = 0;
  18947. this.dependencies = [];
  18948. // Clipping
  18949. this.clipId = '';
  18950. this.pendingClip = false;
  18951. this.maskId = '';
  18952. }
  18953. SVGExtraState.prototype = {
  18954. clone: function SVGExtraState_clone() {
  18955. return Object.create(this);
  18956. },
  18957. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  18958. this.x = x;
  18959. this.y = y;
  18960. }
  18961. };
  18962. return SVGExtraState;
  18963. })();
  18964. var SVGGraphics = (function SVGGraphicsClosure() {
  18965. function createScratchSVG(width, height) {
  18966. var NS = 'http://www.w3.org/2000/svg';
  18967. var svg = document.createElementNS(NS, 'svg:svg');
  18968. svg.setAttributeNS(null, 'version', '1.1');
  18969. svg.setAttributeNS(null, 'width', width + 'px');
  18970. svg.setAttributeNS(null, 'height', height + 'px');
  18971. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  18972. return svg;
  18973. }
  18974. function opListToTree(opList) {
  18975. var opTree = [];
  18976. var tmp = [];
  18977. var opListLen = opList.length;
  18978. for (var x = 0; x < opListLen; x++) {
  18979. if (opList[x].fn === 'save') {
  18980. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  18981. tmp.push(opTree);
  18982. opTree = opTree[opTree.length - 1].items;
  18983. continue;
  18984. }
  18985. if(opList[x].fn === 'restore') {
  18986. opTree = tmp.pop();
  18987. } else {
  18988. opTree.push(opList[x]);
  18989. }
  18990. }
  18991. return opTree;
  18992. }
  18993. /**
  18994. * Formats float number.
  18995. * @param value {number} number to format.
  18996. * @returns {string}
  18997. */
  18998. function pf(value) {
  18999. if (value === (value | 0)) { // integer number
  19000. return value.toString();
  19001. }
  19002. var s = value.toFixed(10);
  19003. var i = s.length - 1;
  19004. if (s[i] !== '0') {
  19005. return s;
  19006. }
  19007. // removing trailing zeros
  19008. do {
  19009. i--;
  19010. } while (s[i] === '0');
  19011. return s.substr(0, s[i] === '.' ? i : i + 1);
  19012. }
  19013. /**
  19014. * Formats transform matrix. The standard rotation, scale and translate
  19015. * matrices are replaced by their shorter forms, and for identity matrix
  19016. * returns empty string to save the memory.
  19017. * @param m {Array} matrix to format.
  19018. * @returns {string}
  19019. */
  19020. function pm(m) {
  19021. if (m[4] === 0 && m[5] === 0) {
  19022. if (m[1] === 0 && m[2] === 0) {
  19023. if (m[0] === 1 && m[3] === 1) {
  19024. return '';
  19025. }
  19026. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  19027. }
  19028. if (m[0] === m[3] && m[1] === -m[2]) {
  19029. var a = Math.acos(m[0]) * 180 / Math.PI;
  19030. return 'rotate(' + pf(a) + ')';
  19031. }
  19032. } else {
  19033. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  19034. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19035. }
  19036. }
  19037. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  19038. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  19039. }
  19040. function SVGGraphics(commonObjs, objs) {
  19041. this.current = new SVGExtraState();
  19042. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  19043. this.transformStack = [];
  19044. this.extraStack = [];
  19045. this.commonObjs = commonObjs;
  19046. this.objs = objs;
  19047. this.pendingEOFill = false;
  19048. this.embedFonts = false;
  19049. this.embeddedFonts = Object.create(null);
  19050. this.cssStyle = null;
  19051. }
  19052. var NS = 'http://www.w3.org/2000/svg';
  19053. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  19054. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  19055. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  19056. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  19057. var clipCount = 0;
  19058. var maskCount = 0;
  19059. SVGGraphics.prototype = {
  19060. save: function SVGGraphics_save() {
  19061. this.transformStack.push(this.transformMatrix);
  19062. var old = this.current;
  19063. this.extraStack.push(old);
  19064. this.current = old.clone();
  19065. },
  19066. restore: function SVGGraphics_restore() {
  19067. this.transformMatrix = this.transformStack.pop();
  19068. this.current = this.extraStack.pop();
  19069. this.tgrp = document.createElementNS(NS, 'svg:g');
  19070. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19071. this.pgrp.appendChild(this.tgrp);
  19072. },
  19073. group: function SVGGraphics_group(items) {
  19074. this.save();
  19075. this.executeOpTree(items);
  19076. this.restore();
  19077. },
  19078. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  19079. var fnArray = operatorList.fnArray;
  19080. var fnArrayLen = fnArray.length;
  19081. var argsArray = operatorList.argsArray;
  19082. var self = this;
  19083. for (var i = 0; i < fnArrayLen; i++) {
  19084. if (OPS.dependency === fnArray[i]) {
  19085. var deps = argsArray[i];
  19086. for (var n = 0, nn = deps.length; n < nn; n++) {
  19087. var obj = deps[n];
  19088. var common = obj.substring(0, 2) === 'g_';
  19089. var promise;
  19090. if (common) {
  19091. promise = new Promise(function(resolve) {
  19092. self.commonObjs.get(obj, resolve);
  19093. });
  19094. } else {
  19095. promise = new Promise(function(resolve) {
  19096. self.objs.get(obj, resolve);
  19097. });
  19098. }
  19099. this.current.dependencies.push(promise);
  19100. }
  19101. }
  19102. }
  19103. return Promise.all(this.current.dependencies);
  19104. },
  19105. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  19106. var transformMatrix = [a, b, c, d, e, f];
  19107. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  19108. transformMatrix);
  19109. this.tgrp = document.createElementNS(NS, 'svg:g');
  19110. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19111. },
  19112. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  19113. this.svg = createScratchSVG(viewport.width, viewport.height);
  19114. this.viewport = viewport;
  19115. return this.loadDependencies(operatorList).then(function () {
  19116. this.transformMatrix = IDENTITY_MATRIX;
  19117. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  19118. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  19119. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  19120. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19121. this.defs = document.createElementNS(NS, 'svg:defs');
  19122. this.pgrp.appendChild(this.defs);
  19123. this.pgrp.appendChild(this.tgrp);
  19124. this.svg.appendChild(this.pgrp);
  19125. var opTree = this.convertOpList(operatorList);
  19126. this.executeOpTree(opTree);
  19127. return this.svg;
  19128. }.bind(this));
  19129. },
  19130. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  19131. var argsArray = operatorList.argsArray;
  19132. var fnArray = operatorList.fnArray;
  19133. var fnArrayLen = fnArray.length;
  19134. var REVOPS = [];
  19135. var opList = [];
  19136. for (var op in OPS) {
  19137. REVOPS[OPS[op]] = op;
  19138. }
  19139. for (var x = 0; x < fnArrayLen; x++) {
  19140. var fnId = fnArray[x];
  19141. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  19142. }
  19143. return opListToTree(opList);
  19144. },
  19145. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  19146. var opTreeLen = opTree.length;
  19147. for(var x = 0; x < opTreeLen; x++) {
  19148. var fn = opTree[x].fn;
  19149. var fnId = opTree[x].fnId;
  19150. var args = opTree[x].args;
  19151. switch (fnId | 0) {
  19152. case OPS.beginText:
  19153. this.beginText();
  19154. break;
  19155. case OPS.setLeading:
  19156. this.setLeading(args);
  19157. break;
  19158. case OPS.setLeadingMoveText:
  19159. this.setLeadingMoveText(args[0], args[1]);
  19160. break;
  19161. case OPS.setFont:
  19162. this.setFont(args);
  19163. break;
  19164. case OPS.showText:
  19165. this.showText(args[0]);
  19166. break;
  19167. case OPS.showSpacedText:
  19168. this.showText(args[0]);
  19169. break;
  19170. case OPS.endText:
  19171. this.endText();
  19172. break;
  19173. case OPS.moveText:
  19174. this.moveText(args[0], args[1]);
  19175. break;
  19176. case OPS.setCharSpacing:
  19177. this.setCharSpacing(args[0]);
  19178. break;
  19179. case OPS.setWordSpacing:
  19180. this.setWordSpacing(args[0]);
  19181. break;
  19182. case OPS.setHScale:
  19183. this.setHScale(args[0]);
  19184. break;
  19185. case OPS.setTextMatrix:
  19186. this.setTextMatrix(args[0], args[1], args[2],
  19187. args[3], args[4], args[5]);
  19188. break;
  19189. case OPS.setLineWidth:
  19190. this.setLineWidth(args[0]);
  19191. break;
  19192. case OPS.setLineJoin:
  19193. this.setLineJoin(args[0]);
  19194. break;
  19195. case OPS.setLineCap:
  19196. this.setLineCap(args[0]);
  19197. break;
  19198. case OPS.setMiterLimit:
  19199. this.setMiterLimit(args[0]);
  19200. break;
  19201. case OPS.setFillRGBColor:
  19202. this.setFillRGBColor(args[0], args[1], args[2]);
  19203. break;
  19204. case OPS.setStrokeRGBColor:
  19205. this.setStrokeRGBColor(args[0], args[1], args[2]);
  19206. break;
  19207. case OPS.setDash:
  19208. this.setDash(args[0], args[1]);
  19209. break;
  19210. case OPS.setGState:
  19211. this.setGState(args[0]);
  19212. break;
  19213. case OPS.fill:
  19214. this.fill();
  19215. break;
  19216. case OPS.eoFill:
  19217. this.eoFill();
  19218. break;
  19219. case OPS.stroke:
  19220. this.stroke();
  19221. break;
  19222. case OPS.fillStroke:
  19223. this.fillStroke();
  19224. break;
  19225. case OPS.eoFillStroke:
  19226. this.eoFillStroke();
  19227. break;
  19228. case OPS.clip:
  19229. this.clip('nonzero');
  19230. break;
  19231. case OPS.eoClip:
  19232. this.clip('evenodd');
  19233. break;
  19234. case OPS.paintSolidColorImageMask:
  19235. this.paintSolidColorImageMask();
  19236. break;
  19237. case OPS.paintJpegXObject:
  19238. this.paintJpegXObject(args[0], args[1], args[2]);
  19239. break;
  19240. case OPS.paintImageXObject:
  19241. this.paintImageXObject(args[0]);
  19242. break;
  19243. case OPS.paintInlineImageXObject:
  19244. this.paintInlineImageXObject(args[0]);
  19245. break;
  19246. case OPS.paintImageMaskXObject:
  19247. this.paintImageMaskXObject(args[0]);
  19248. break;
  19249. case OPS.paintFormXObjectBegin:
  19250. this.paintFormXObjectBegin(args[0], args[1]);
  19251. break;
  19252. case OPS.paintFormXObjectEnd:
  19253. this.paintFormXObjectEnd();
  19254. break;
  19255. case OPS.closePath:
  19256. this.closePath();
  19257. break;
  19258. case OPS.closeStroke:
  19259. this.closeStroke();
  19260. break;
  19261. case OPS.closeFillStroke:
  19262. this.closeFillStroke();
  19263. break;
  19264. case OPS.nextLine:
  19265. this.nextLine();
  19266. break;
  19267. case OPS.transform:
  19268. this.transform(args[0], args[1], args[2], args[3],
  19269. args[4], args[5]);
  19270. break;
  19271. case OPS.constructPath:
  19272. this.constructPath(args[0], args[1]);
  19273. break;
  19274. case OPS.endPath:
  19275. this.endPath();
  19276. break;
  19277. case 92:
  19278. this.group(opTree[x].items);
  19279. break;
  19280. default:
  19281. warn('Unimplemented method '+ fn);
  19282. break;
  19283. }
  19284. }
  19285. },
  19286. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  19287. this.current.wordSpacing = wordSpacing;
  19288. },
  19289. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  19290. this.current.charSpacing = charSpacing;
  19291. },
  19292. nextLine: function SVGGraphics_nextLine() {
  19293. this.moveText(0, this.current.leading);
  19294. },
  19295. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  19296. var current = this.current;
  19297. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  19298. this.current.x = this.current.lineX = 0;
  19299. this.current.y = this.current.lineY = 0;
  19300. current.xcoords = [];
  19301. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19302. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19303. current.tspan.setAttributeNS(null, 'font-size',
  19304. pf(current.fontSize) + 'px');
  19305. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19306. current.txtElement = document.createElementNS(NS, 'svg:text');
  19307. current.txtElement.appendChild(current.tspan);
  19308. },
  19309. beginText: function SVGGraphics_beginText() {
  19310. this.current.x = this.current.lineX = 0;
  19311. this.current.y = this.current.lineY = 0;
  19312. this.current.textMatrix = IDENTITY_MATRIX;
  19313. this.current.lineMatrix = IDENTITY_MATRIX;
  19314. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  19315. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  19316. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  19317. this.current.xcoords = [];
  19318. },
  19319. moveText: function SVGGraphics_moveText(x, y) {
  19320. var current = this.current;
  19321. this.current.x = this.current.lineX += x;
  19322. this.current.y = this.current.lineY += y;
  19323. current.xcoords = [];
  19324. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19325. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19326. current.tspan.setAttributeNS(null, 'font-size',
  19327. pf(current.fontSize) + 'px');
  19328. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19329. },
  19330. showText: function SVGGraphics_showText(glyphs) {
  19331. var current = this.current;
  19332. var font = current.font;
  19333. var fontSize = current.fontSize;
  19334. if (fontSize === 0) {
  19335. return;
  19336. }
  19337. var charSpacing = current.charSpacing;
  19338. var wordSpacing = current.wordSpacing;
  19339. var fontDirection = current.fontDirection;
  19340. var textHScale = current.textHScale * fontDirection;
  19341. var glyphsLength = glyphs.length;
  19342. var vertical = font.vertical;
  19343. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  19344. var x = 0, i;
  19345. for (i = 0; i < glyphsLength; ++i) {
  19346. var glyph = glyphs[i];
  19347. if (glyph === null) {
  19348. // word break
  19349. x += fontDirection * wordSpacing;
  19350. continue;
  19351. } else if (isNum(glyph)) {
  19352. x += -glyph * fontSize * 0.001;
  19353. continue;
  19354. }
  19355. current.xcoords.push(current.x + x * textHScale);
  19356. var width = glyph.width;
  19357. var character = glyph.fontChar;
  19358. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  19359. x += charWidth;
  19360. current.tspan.textContent += character;
  19361. }
  19362. if (vertical) {
  19363. current.y -= x * textHScale;
  19364. } else {
  19365. current.x += x * textHScale;
  19366. }
  19367. current.tspan.setAttributeNS(null, 'x',
  19368. current.xcoords.map(pf).join(' '));
  19369. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19370. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  19371. current.tspan.setAttributeNS(null, 'font-size',
  19372. pf(current.fontSize) + 'px');
  19373. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  19374. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  19375. }
  19376. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  19377. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  19378. }
  19379. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  19380. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  19381. }
  19382. current.txtElement.setAttributeNS(null, 'transform',
  19383. pm(current.textMatrix) +
  19384. ' scale(1, -1)' );
  19385. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  19386. current.txtElement.appendChild(current.tspan);
  19387. current.txtgrp.appendChild(current.txtElement);
  19388. this.tgrp.appendChild(current.txtElement);
  19389. },
  19390. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  19391. this.setLeading(-y);
  19392. this.moveText(x, y);
  19393. },
  19394. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  19395. if (!this.cssStyle) {
  19396. this.cssStyle = document.createElementNS(NS, 'svg:style');
  19397. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  19398. this.defs.appendChild(this.cssStyle);
  19399. }
  19400. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  19401. this.cssStyle.textContent +=
  19402. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  19403. ' src: url(' + url + '); }\n';
  19404. },
  19405. setFont: function SVGGraphics_setFont(details) {
  19406. var current = this.current;
  19407. var fontObj = this.commonObjs.get(details[0]);
  19408. var size = details[1];
  19409. this.current.font = fontObj;
  19410. if (this.embedFonts && fontObj.data &&
  19411. !this.embeddedFonts[fontObj.loadedName]) {
  19412. this.addFontStyle(fontObj);
  19413. this.embeddedFonts[fontObj.loadedName] = fontObj;
  19414. }
  19415. current.fontMatrix = (fontObj.fontMatrix ?
  19416. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  19417. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  19418. (fontObj.bold ? 'bold' : 'normal');
  19419. var italic = fontObj.italic ? 'italic' : 'normal';
  19420. if (size < 0) {
  19421. size = -size;
  19422. current.fontDirection = -1;
  19423. } else {
  19424. current.fontDirection = 1;
  19425. }
  19426. current.fontSize = size;
  19427. current.fontFamily = fontObj.loadedName;
  19428. current.fontWeight = bold;
  19429. current.fontStyle = italic;
  19430. current.tspan = document.createElementNS(NS, 'svg:tspan');
  19431. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  19432. current.xcoords = [];
  19433. },
  19434. endText: function SVGGraphics_endText() {
  19435. if (this.current.pendingClip) {
  19436. this.cgrp.appendChild(this.tgrp);
  19437. this.pgrp.appendChild(this.cgrp);
  19438. } else {
  19439. this.pgrp.appendChild(this.tgrp);
  19440. }
  19441. this.tgrp = document.createElementNS(NS, 'svg:g');
  19442. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19443. },
  19444. // Path properties
  19445. setLineWidth: function SVGGraphics_setLineWidth(width) {
  19446. this.current.lineWidth = width;
  19447. },
  19448. setLineCap: function SVGGraphics_setLineCap(style) {
  19449. this.current.lineCap = LINE_CAP_STYLES[style];
  19450. },
  19451. setLineJoin: function SVGGraphics_setLineJoin(style) {
  19452. this.current.lineJoin = LINE_JOIN_STYLES[style];
  19453. },
  19454. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  19455. this.current.miterLimit = limit;
  19456. },
  19457. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  19458. var color = Util.makeCssRgb(r, g, b);
  19459. this.current.strokeColor = color;
  19460. },
  19461. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  19462. var color = Util.makeCssRgb(r, g, b);
  19463. this.current.fillColor = color;
  19464. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  19465. this.current.xcoords = [];
  19466. },
  19467. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  19468. this.current.dashArray = dashArray;
  19469. this.current.dashPhase = dashPhase;
  19470. },
  19471. constructPath: function SVGGraphics_constructPath(ops, args) {
  19472. var current = this.current;
  19473. var x = current.x, y = current.y;
  19474. current.path = document.createElementNS(NS, 'svg:path');
  19475. var d = [];
  19476. var opLength = ops.length;
  19477. for (var i = 0, j = 0; i < opLength; i++) {
  19478. switch (ops[i] | 0) {
  19479. case OPS.rectangle:
  19480. x = args[j++];
  19481. y = args[j++];
  19482. var width = args[j++];
  19483. var height = args[j++];
  19484. var xw = x + width;
  19485. var yh = y + height;
  19486. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  19487. 'L', pf(x), pf(yh), 'Z');
  19488. break;
  19489. case OPS.moveTo:
  19490. x = args[j++];
  19491. y = args[j++];
  19492. d.push('M', pf(x), pf(y));
  19493. break;
  19494. case OPS.lineTo:
  19495. x = args[j++];
  19496. y = args[j++];
  19497. d.push('L', pf(x) , pf(y));
  19498. break;
  19499. case OPS.curveTo:
  19500. x = args[j + 4];
  19501. y = args[j + 5];
  19502. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  19503. pf(args[j + 3]), pf(x), pf(y));
  19504. j += 6;
  19505. break;
  19506. case OPS.curveTo2:
  19507. x = args[j + 2];
  19508. y = args[j + 3];
  19509. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  19510. pf(args[j + 2]), pf(args[j + 3]));
  19511. j += 4;
  19512. break;
  19513. case OPS.curveTo3:
  19514. x = args[j + 2];
  19515. y = args[j + 3];
  19516. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  19517. pf(x), pf(y));
  19518. j += 4;
  19519. break;
  19520. case OPS.closePath:
  19521. d.push('Z');
  19522. break;
  19523. }
  19524. }
  19525. current.path.setAttributeNS(null, 'd', d.join(' '));
  19526. current.path.setAttributeNS(null, 'stroke-miterlimit',
  19527. pf(current.miterLimit));
  19528. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  19529. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  19530. current.path.setAttributeNS(null, 'stroke-width',
  19531. pf(current.lineWidth) + 'px');
  19532. current.path.setAttributeNS(null, 'stroke-dasharray',
  19533. current.dashArray.map(pf).join(' '));
  19534. current.path.setAttributeNS(null, 'stroke-dashoffset',
  19535. pf(current.dashPhase) + 'px');
  19536. current.path.setAttributeNS(null, 'fill', 'none');
  19537. this.tgrp.appendChild(current.path);
  19538. if (current.pendingClip) {
  19539. this.cgrp.appendChild(this.tgrp);
  19540. this.pgrp.appendChild(this.cgrp);
  19541. } else {
  19542. this.pgrp.appendChild(this.tgrp);
  19543. }
  19544. // Saving a reference in current.element so that it can be addressed
  19545. // in 'fill' and 'stroke'
  19546. current.element = current.path;
  19547. current.setCurrentPoint(x, y);
  19548. },
  19549. endPath: function SVGGraphics_endPath() {
  19550. var current = this.current;
  19551. if (current.pendingClip) {
  19552. this.cgrp.appendChild(this.tgrp);
  19553. this.pgrp.appendChild(this.cgrp);
  19554. } else {
  19555. this.pgrp.appendChild(this.tgrp);
  19556. }
  19557. this.tgrp = document.createElementNS(NS, 'svg:g');
  19558. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19559. },
  19560. clip: function SVGGraphics_clip(type) {
  19561. var current = this.current;
  19562. // Add current path to clipping path
  19563. current.clipId = 'clippath' + clipCount;
  19564. clipCount++;
  19565. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  19566. this.clippath.setAttributeNS(null, 'id', current.clipId);
  19567. var clipElement = current.element.cloneNode();
  19568. if (type === 'evenodd') {
  19569. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  19570. } else {
  19571. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  19572. }
  19573. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  19574. this.clippath.appendChild(clipElement);
  19575. this.defs.appendChild(this.clippath);
  19576. // Create a new group with that attribute
  19577. current.pendingClip = true;
  19578. this.cgrp = document.createElementNS(NS, 'svg:g');
  19579. this.cgrp.setAttributeNS(null, 'clip-path',
  19580. 'url(#' + current.clipId + ')');
  19581. this.pgrp.appendChild(this.cgrp);
  19582. },
  19583. closePath: function SVGGraphics_closePath() {
  19584. var current = this.current;
  19585. var d = current.path.getAttributeNS(null, 'd');
  19586. d += 'Z';
  19587. current.path.setAttributeNS(null, 'd', d);
  19588. },
  19589. setLeading: function SVGGraphics_setLeading(leading) {
  19590. this.current.leading = -leading;
  19591. },
  19592. setTextRise: function SVGGraphics_setTextRise(textRise) {
  19593. this.current.textRise = textRise;
  19594. },
  19595. setHScale: function SVGGraphics_setHScale(scale) {
  19596. this.current.textHScale = scale / 100;
  19597. },
  19598. setGState: function SVGGraphics_setGState(states) {
  19599. for (var i = 0, ii = states.length; i < ii; i++) {
  19600. var state = states[i];
  19601. var key = state[0];
  19602. var value = state[1];
  19603. switch (key) {
  19604. case 'LW':
  19605. this.setLineWidth(value);
  19606. break;
  19607. case 'LC':
  19608. this.setLineCap(value);
  19609. break;
  19610. case 'LJ':
  19611. this.setLineJoin(value);
  19612. break;
  19613. case 'ML':
  19614. this.setMiterLimit(value);
  19615. break;
  19616. case 'D':
  19617. this.setDash(value[0], value[1]);
  19618. break;
  19619. case 'RI':
  19620. break;
  19621. case 'FL':
  19622. break;
  19623. case 'Font':
  19624. this.setFont(value);
  19625. break;
  19626. case 'CA':
  19627. break;
  19628. case 'ca':
  19629. break;
  19630. case 'BM':
  19631. break;
  19632. case 'SMask':
  19633. break;
  19634. }
  19635. }
  19636. },
  19637. fill: function SVGGraphics_fill() {
  19638. var current = this.current;
  19639. current.element.setAttributeNS(null, 'fill', current.fillColor);
  19640. },
  19641. stroke: function SVGGraphics_stroke() {
  19642. var current = this.current;
  19643. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  19644. current.element.setAttributeNS(null, 'fill', 'none');
  19645. },
  19646. eoFill: function SVGGraphics_eoFill() {
  19647. var current = this.current;
  19648. current.element.setAttributeNS(null, 'fill', current.fillColor);
  19649. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  19650. },
  19651. fillStroke: function SVGGraphics_fillStroke() {
  19652. // Order is important since stroke wants fill to be none.
  19653. // First stroke, then if fill needed, it will be overwritten.
  19654. this.stroke();
  19655. this.fill();
  19656. },
  19657. eoFillStroke: function SVGGraphics_eoFillStroke() {
  19658. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  19659. this.fillStroke();
  19660. },
  19661. closeStroke: function SVGGraphics_closeStroke() {
  19662. this.closePath();
  19663. this.stroke();
  19664. },
  19665. closeFillStroke: function SVGGraphics_closeFillStroke() {
  19666. this.closePath();
  19667. this.fillStroke();
  19668. },
  19669. paintSolidColorImageMask:
  19670. function SVGGraphics_paintSolidColorImageMask() {
  19671. var current = this.current;
  19672. var rect = document.createElementNS(NS, 'svg:rect');
  19673. rect.setAttributeNS(null, 'x', '0');
  19674. rect.setAttributeNS(null, 'y', '0');
  19675. rect.setAttributeNS(null, 'width', '1px');
  19676. rect.setAttributeNS(null, 'height', '1px');
  19677. rect.setAttributeNS(null, 'fill', current.fillColor);
  19678. this.tgrp.appendChild(rect);
  19679. },
  19680. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  19681. var current = this.current;
  19682. var imgObj = this.objs.get(objId);
  19683. var imgEl = document.createElementNS(NS, 'svg:image');
  19684. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  19685. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  19686. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  19687. imgEl.setAttributeNS(null, 'x', '0');
  19688. imgEl.setAttributeNS(null, 'y', pf(-h));
  19689. imgEl.setAttributeNS(null, 'transform',
  19690. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  19691. this.tgrp.appendChild(imgEl);
  19692. if (current.pendingClip) {
  19693. this.cgrp.appendChild(this.tgrp);
  19694. this.pgrp.appendChild(this.cgrp);
  19695. } else {
  19696. this.pgrp.appendChild(this.tgrp);
  19697. }
  19698. },
  19699. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  19700. var imgData = this.objs.get(objId);
  19701. if (!imgData) {
  19702. warn('Dependent image isn\'t ready yet');
  19703. return;
  19704. }
  19705. this.paintInlineImageXObject(imgData);
  19706. },
  19707. paintInlineImageXObject:
  19708. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  19709. var current = this.current;
  19710. var width = imgData.width;
  19711. var height = imgData.height;
  19712. var imgSrc = convertImgDataToPng(imgData);
  19713. var cliprect = document.createElementNS(NS, 'svg:rect');
  19714. cliprect.setAttributeNS(null, 'x', '0');
  19715. cliprect.setAttributeNS(null, 'y', '0');
  19716. cliprect.setAttributeNS(null, 'width', pf(width));
  19717. cliprect.setAttributeNS(null, 'height', pf(height));
  19718. current.element = cliprect;
  19719. this.clip('nonzero');
  19720. var imgEl = document.createElementNS(NS, 'svg:image');
  19721. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  19722. imgEl.setAttributeNS(null, 'x', '0');
  19723. imgEl.setAttributeNS(null, 'y', pf(-height));
  19724. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  19725. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  19726. imgEl.setAttributeNS(null, 'transform',
  19727. 'scale(' + pf(1 / width) + ' ' +
  19728. pf(-1 / height) + ')');
  19729. if (mask) {
  19730. mask.appendChild(imgEl);
  19731. } else {
  19732. this.tgrp.appendChild(imgEl);
  19733. }
  19734. if (current.pendingClip) {
  19735. this.cgrp.appendChild(this.tgrp);
  19736. this.pgrp.appendChild(this.cgrp);
  19737. } else {
  19738. this.pgrp.appendChild(this.tgrp);
  19739. }
  19740. },
  19741. paintImageMaskXObject:
  19742. function SVGGraphics_paintImageMaskXObject(imgData) {
  19743. var current = this.current;
  19744. var width = imgData.width;
  19745. var height = imgData.height;
  19746. var fillColor = current.fillColor;
  19747. current.maskId = 'mask' + maskCount++;
  19748. var mask = document.createElementNS(NS, 'svg:mask');
  19749. mask.setAttributeNS(null, 'id', current.maskId);
  19750. var rect = document.createElementNS(NS, 'svg:rect');
  19751. rect.setAttributeNS(null, 'x', '0');
  19752. rect.setAttributeNS(null, 'y', '0');
  19753. rect.setAttributeNS(null, 'width', pf(width));
  19754. rect.setAttributeNS(null, 'height', pf(height));
  19755. rect.setAttributeNS(null, 'fill', fillColor);
  19756. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  19757. this.defs.appendChild(mask);
  19758. this.tgrp.appendChild(rect);
  19759. this.paintInlineImageXObject(imgData, mask);
  19760. },
  19761. paintFormXObjectBegin:
  19762. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  19763. this.save();
  19764. if (isArray(matrix) && matrix.length === 6) {
  19765. this.transform(matrix[0], matrix[1], matrix[2],
  19766. matrix[3], matrix[4], matrix[5]);
  19767. }
  19768. if (isArray(bbox) && bbox.length === 4) {
  19769. var width = bbox[2] - bbox[0];
  19770. var height = bbox[3] - bbox[1];
  19771. var cliprect = document.createElementNS(NS, 'svg:rect');
  19772. cliprect.setAttributeNS(null, 'x', bbox[0]);
  19773. cliprect.setAttributeNS(null, 'y', bbox[1]);
  19774. cliprect.setAttributeNS(null, 'width', pf(width));
  19775. cliprect.setAttributeNS(null, 'height', pf(height));
  19776. this.current.element = cliprect;
  19777. this.clip('nonzero');
  19778. this.endPath();
  19779. }
  19780. },
  19781. paintFormXObjectEnd:
  19782. function SVGGraphics_paintFormXObjectEnd() {
  19783. this.restore();
  19784. }
  19785. };
  19786. return SVGGraphics;
  19787. })();
  19788. PDFJS.SVGGraphics = SVGGraphics;
  19789. exports.SVGGraphics = SVGGraphics;
  19790. }));
  19791. (function (root, factory) {
  19792. {
  19793. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  19794. root.pdfjsDisplayDOMUtils, root.pdfjsSharedGlobal);
  19795. }
  19796. }(this, function (exports, sharedUtil, displayDOMUtils, sharedGlobal) {
  19797. var Util = sharedUtil.Util;
  19798. var createPromiseCapability = sharedUtil.createPromiseCapability;
  19799. var CustomStyle = displayDOMUtils.CustomStyle;
  19800. var PDFJS = sharedGlobal.PDFJS;
  19801. /**
  19802. * Text layer render parameters.
  19803. *
  19804. * @typedef {Object} TextLayerRenderParameters
  19805. * @property {TextContent} textContent - Text content to render (the object is
  19806. * returned by the page's getTextContent() method).
  19807. * @property {HTMLElement} container - HTML element that will contain text runs.
  19808. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  19809. * layout the text runs.
  19810. * @property {Array} textDivs - (optional) HTML elements that are correspond
  19811. * the text items of the textContent input. This is output and shall be
  19812. * initially be set to empty array.
  19813. * @property {number} timeout - (optional) Delay in milliseconds before
  19814. * rendering of the text runs occurs.
  19815. */
  19816. var renderTextLayer = (function renderTextLayerClosure() {
  19817. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  19818. var NonWhitespaceRegexp = /\S/;
  19819. function isAllWhitespace(str) {
  19820. return !NonWhitespaceRegexp.test(str);
  19821. }
  19822. function appendText(textDivs, viewport, geom, styles) {
  19823. var style = styles[geom.fontName];
  19824. var textDiv = document.createElement('div');
  19825. textDivs.push(textDiv);
  19826. if (isAllWhitespace(geom.str)) {
  19827. textDiv.dataset.isWhitespace = true;
  19828. return;
  19829. }
  19830. var tx = Util.transform(viewport.transform, geom.transform);
  19831. var angle = Math.atan2(tx[1], tx[0]);
  19832. if (style.vertical) {
  19833. angle += Math.PI / 2;
  19834. }
  19835. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  19836. var fontAscent = fontHeight;
  19837. if (style.ascent) {
  19838. fontAscent = style.ascent * fontAscent;
  19839. } else if (style.descent) {
  19840. fontAscent = (1 + style.descent) * fontAscent;
  19841. }
  19842. var left;
  19843. var top;
  19844. if (angle === 0) {
  19845. left = tx[4];
  19846. top = tx[5] - fontAscent;
  19847. } else {
  19848. left = tx[4] + (fontAscent * Math.sin(angle));
  19849. top = tx[5] - (fontAscent * Math.cos(angle));
  19850. }
  19851. textDiv.style.left = left + 'px';
  19852. textDiv.style.top = top + 'px';
  19853. textDiv.style.fontSize = fontHeight + 'px';
  19854. textDiv.style.fontFamily = style.fontFamily;
  19855. textDiv.textContent = geom.str;
  19856. // |fontName| is only used by the Font Inspector. This test will succeed
  19857. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  19858. // not worth the effort to do a more accurate test.
  19859. if (PDFJS.pdfBug) {
  19860. textDiv.dataset.fontName = geom.fontName;
  19861. }
  19862. // Storing into dataset will convert number into string.
  19863. if (angle !== 0) {
  19864. textDiv.dataset.angle = angle * (180 / Math.PI);
  19865. }
  19866. // We don't bother scaling single-char text divs, because it has very
  19867. // little effect on text highlighting. This makes scrolling on docs with
  19868. // lots of such divs a lot faster.
  19869. if (geom.str.length > 1) {
  19870. if (style.vertical) {
  19871. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  19872. } else {
  19873. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  19874. }
  19875. }
  19876. }
  19877. function render(task) {
  19878. if (task._canceled) {
  19879. return;
  19880. }
  19881. var textLayerFrag = task._container;
  19882. var textDivs = task._textDivs;
  19883. var capability = task._capability;
  19884. var textDivsLength = textDivs.length;
  19885. // No point in rendering many divs as it would make the browser
  19886. // unusable even after the divs are rendered.
  19887. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  19888. capability.resolve();
  19889. return;
  19890. }
  19891. var canvas = document.createElement('canvas');
  19892. var ctx = canvas.getContext('2d', {alpha: false});
  19893. var lastFontSize;
  19894. var lastFontFamily;
  19895. for (var i = 0; i < textDivsLength; i++) {
  19896. var textDiv = textDivs[i];
  19897. if (textDiv.dataset.isWhitespace !== undefined) {
  19898. continue;
  19899. }
  19900. var fontSize = textDiv.style.fontSize;
  19901. var fontFamily = textDiv.style.fontFamily;
  19902. // Only build font string and set to context if different from last.
  19903. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  19904. ctx.font = fontSize + ' ' + fontFamily;
  19905. lastFontSize = fontSize;
  19906. lastFontFamily = fontFamily;
  19907. }
  19908. var width = ctx.measureText(textDiv.textContent).width;
  19909. if (width > 0) {
  19910. textLayerFrag.appendChild(textDiv);
  19911. var transform;
  19912. if (textDiv.dataset.canvasWidth !== undefined) {
  19913. // Dataset values come of type string.
  19914. var textScale = textDiv.dataset.canvasWidth / width;
  19915. transform = 'scaleX(' + textScale + ')';
  19916. } else {
  19917. transform = '';
  19918. }
  19919. var rotation = textDiv.dataset.angle;
  19920. if (rotation) {
  19921. transform = 'rotate(' + rotation + 'deg) ' + transform;
  19922. }
  19923. if (transform) {
  19924. CustomStyle.setProp('transform' , textDiv, transform);
  19925. }
  19926. }
  19927. }
  19928. capability.resolve();
  19929. }
  19930. /**
  19931. * Text layer rendering task.
  19932. *
  19933. * @param {TextContent} textContent
  19934. * @param {HTMLElement} container
  19935. * @param {PDFJS.PageViewport} viewport
  19936. * @param {Array} textDivs
  19937. * @private
  19938. */
  19939. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  19940. this._textContent = textContent;
  19941. this._container = container;
  19942. this._viewport = viewport;
  19943. textDivs = textDivs || [];
  19944. this._textDivs = textDivs;
  19945. this._canceled = false;
  19946. this._capability = createPromiseCapability();
  19947. this._renderTimer = null;
  19948. }
  19949. TextLayerRenderTask.prototype = {
  19950. get promise() {
  19951. return this._capability.promise;
  19952. },
  19953. cancel: function TextLayer_cancel() {
  19954. this._canceled = true;
  19955. if (this._renderTimer !== null) {
  19956. clearTimeout(this._renderTimer);
  19957. this._renderTimer = null;
  19958. }
  19959. this._capability.reject('canceled');
  19960. },
  19961. _render: function TextLayer_render(timeout) {
  19962. var textItems = this._textContent.items;
  19963. var styles = this._textContent.styles;
  19964. var textDivs = this._textDivs;
  19965. var viewport = this._viewport;
  19966. for (var i = 0, len = textItems.length; i < len; i++) {
  19967. appendText(textDivs, viewport, textItems[i], styles);
  19968. }
  19969. if (!timeout) { // Render right away
  19970. render(this);
  19971. } else { // Schedule
  19972. var self = this;
  19973. this._renderTimer = setTimeout(function() {
  19974. render(self);
  19975. self._renderTimer = null;
  19976. }, timeout);
  19977. }
  19978. }
  19979. };
  19980. /**
  19981. * Starts rendering of the text layer.
  19982. *
  19983. * @param {TextLayerRenderParameters} renderParameters
  19984. * @returns {TextLayerRenderTask}
  19985. */
  19986. function renderTextLayer(renderParameters) {
  19987. var task = new TextLayerRenderTask(renderParameters.textContent,
  19988. renderParameters.container,
  19989. renderParameters.viewport,
  19990. renderParameters.textDivs);
  19991. task._render(renderParameters.timeout);
  19992. return task;
  19993. }
  19994. return renderTextLayer;
  19995. })();
  19996. PDFJS.renderTextLayer = renderTextLayer;
  19997. exports.renderTextLayer = renderTextLayer;
  19998. }));
  19999. (function (root, factory) {
  20000. {
  20001. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil);
  20002. }
  20003. }(this, function (exports, sharedUtil) {
  20004. var shadow = sharedUtil.shadow;
  20005. var WebGLUtils = (function WebGLUtilsClosure() {
  20006. function loadShader(gl, code, shaderType) {
  20007. var shader = gl.createShader(shaderType);
  20008. gl.shaderSource(shader, code);
  20009. gl.compileShader(shader);
  20010. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  20011. if (!compiled) {
  20012. var errorMsg = gl.getShaderInfoLog(shader);
  20013. throw new Error('Error during shader compilation: ' + errorMsg);
  20014. }
  20015. return shader;
  20016. }
  20017. function createVertexShader(gl, code) {
  20018. return loadShader(gl, code, gl.VERTEX_SHADER);
  20019. }
  20020. function createFragmentShader(gl, code) {
  20021. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  20022. }
  20023. function createProgram(gl, shaders) {
  20024. var program = gl.createProgram();
  20025. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  20026. gl.attachShader(program, shaders[i]);
  20027. }
  20028. gl.linkProgram(program);
  20029. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  20030. if (!linked) {
  20031. var errorMsg = gl.getProgramInfoLog(program);
  20032. throw new Error('Error during program linking: ' + errorMsg);
  20033. }
  20034. return program;
  20035. }
  20036. function createTexture(gl, image, textureId) {
  20037. gl.activeTexture(textureId);
  20038. var texture = gl.createTexture();
  20039. gl.bindTexture(gl.TEXTURE_2D, texture);
  20040. // Set the parameters so we can render any size image.
  20041. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  20042. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  20043. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  20044. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  20045. // Upload the image into the texture.
  20046. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  20047. return texture;
  20048. }
  20049. var currentGL, currentCanvas;
  20050. function generateGL() {
  20051. if (currentGL) {
  20052. return;
  20053. }
  20054. currentCanvas = document.createElement('canvas');
  20055. currentGL = currentCanvas.getContext('webgl',
  20056. { premultipliedalpha: false });
  20057. }
  20058. var smaskVertexShaderCode = '\
  20059. attribute vec2 a_position; \
  20060. attribute vec2 a_texCoord; \
  20061. \
  20062. uniform vec2 u_resolution; \
  20063. \
  20064. varying vec2 v_texCoord; \
  20065. \
  20066. void main() { \
  20067. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  20068. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  20069. \
  20070. v_texCoord = a_texCoord; \
  20071. } ';
  20072. var smaskFragmentShaderCode = '\
  20073. precision mediump float; \
  20074. \
  20075. uniform vec4 u_backdrop; \
  20076. uniform int u_subtype; \
  20077. uniform sampler2D u_image; \
  20078. uniform sampler2D u_mask; \
  20079. \
  20080. varying vec2 v_texCoord; \
  20081. \
  20082. void main() { \
  20083. vec4 imageColor = texture2D(u_image, v_texCoord); \
  20084. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  20085. if (u_backdrop.a > 0.0) { \
  20086. maskColor.rgb = maskColor.rgb * maskColor.a + \
  20087. u_backdrop.rgb * (1.0 - maskColor.a); \
  20088. } \
  20089. float lum; \
  20090. if (u_subtype == 0) { \
  20091. lum = maskColor.a; \
  20092. } else { \
  20093. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  20094. maskColor.b * 0.11; \
  20095. } \
  20096. imageColor.a *= lum; \
  20097. imageColor.rgb *= imageColor.a; \
  20098. gl_FragColor = imageColor; \
  20099. } ';
  20100. var smaskCache = null;
  20101. function initSmaskGL() {
  20102. var canvas, gl;
  20103. generateGL();
  20104. canvas = currentCanvas;
  20105. currentCanvas = null;
  20106. gl = currentGL;
  20107. currentGL = null;
  20108. // setup a GLSL program
  20109. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  20110. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  20111. var program = createProgram(gl, [vertexShader, fragmentShader]);
  20112. gl.useProgram(program);
  20113. var cache = {};
  20114. cache.gl = gl;
  20115. cache.canvas = canvas;
  20116. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  20117. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  20118. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  20119. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  20120. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  20121. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  20122. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  20123. // provide texture coordinates for the rectangle.
  20124. var texCoordBuffer = gl.createBuffer();
  20125. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  20126. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  20127. 0.0, 0.0,
  20128. 1.0, 0.0,
  20129. 0.0, 1.0,
  20130. 0.0, 1.0,
  20131. 1.0, 0.0,
  20132. 1.0, 1.0]), gl.STATIC_DRAW);
  20133. gl.enableVertexAttribArray(texCoordLocation);
  20134. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  20135. gl.uniform1i(texLayerLocation, 0);
  20136. gl.uniform1i(texMaskLocation, 1);
  20137. smaskCache = cache;
  20138. }
  20139. function composeSMask(layer, mask, properties) {
  20140. var width = layer.width, height = layer.height;
  20141. if (!smaskCache) {
  20142. initSmaskGL();
  20143. }
  20144. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  20145. canvas.width = width;
  20146. canvas.height = height;
  20147. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  20148. gl.uniform2f(cache.resolutionLocation, width, height);
  20149. if (properties.backdrop) {
  20150. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  20151. properties.backdrop[1], properties.backdrop[2], 1);
  20152. } else {
  20153. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  20154. }
  20155. gl.uniform1i(cache.subtypeLocation,
  20156. properties.subtype === 'Luminosity' ? 1 : 0);
  20157. // Create a textures
  20158. var texture = createTexture(gl, layer, gl.TEXTURE0);
  20159. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  20160. // Create a buffer and put a single clipspace rectangle in
  20161. // it (2 triangles)
  20162. var buffer = gl.createBuffer();
  20163. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  20164. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  20165. 0, 0,
  20166. width, 0,
  20167. 0, height,
  20168. 0, height,
  20169. width, 0,
  20170. width, height]), gl.STATIC_DRAW);
  20171. gl.enableVertexAttribArray(cache.positionLocation);
  20172. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  20173. // draw
  20174. gl.clearColor(0, 0, 0, 0);
  20175. gl.enable(gl.BLEND);
  20176. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  20177. gl.clear(gl.COLOR_BUFFER_BIT);
  20178. gl.drawArrays(gl.TRIANGLES, 0, 6);
  20179. gl.flush();
  20180. gl.deleteTexture(texture);
  20181. gl.deleteTexture(maskTexture);
  20182. gl.deleteBuffer(buffer);
  20183. return canvas;
  20184. }
  20185. var figuresVertexShaderCode = '\
  20186. attribute vec2 a_position; \
  20187. attribute vec3 a_color; \
  20188. \
  20189. uniform vec2 u_resolution; \
  20190. uniform vec2 u_scale; \
  20191. uniform vec2 u_offset; \
  20192. \
  20193. varying vec4 v_color; \
  20194. \
  20195. void main() { \
  20196. vec2 position = (a_position + u_offset) * u_scale; \
  20197. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  20198. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  20199. \
  20200. v_color = vec4(a_color / 255.0, 1.0); \
  20201. } ';
  20202. var figuresFragmentShaderCode = '\
  20203. precision mediump float; \
  20204. \
  20205. varying vec4 v_color; \
  20206. \
  20207. void main() { \
  20208. gl_FragColor = v_color; \
  20209. } ';
  20210. var figuresCache = null;
  20211. function initFiguresGL() {
  20212. var canvas, gl;
  20213. generateGL();
  20214. canvas = currentCanvas;
  20215. currentCanvas = null;
  20216. gl = currentGL;
  20217. currentGL = null;
  20218. // setup a GLSL program
  20219. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  20220. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  20221. var program = createProgram(gl, [vertexShader, fragmentShader]);
  20222. gl.useProgram(program);
  20223. var cache = {};
  20224. cache.gl = gl;
  20225. cache.canvas = canvas;
  20226. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  20227. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  20228. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  20229. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  20230. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  20231. figuresCache = cache;
  20232. }
  20233. function drawFigures(width, height, backgroundColor, figures, context) {
  20234. if (!figuresCache) {
  20235. initFiguresGL();
  20236. }
  20237. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  20238. canvas.width = width;
  20239. canvas.height = height;
  20240. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  20241. gl.uniform2f(cache.resolutionLocation, width, height);
  20242. // count triangle points
  20243. var count = 0;
  20244. var i, ii, rows;
  20245. for (i = 0, ii = figures.length; i < ii; i++) {
  20246. switch (figures[i].type) {
  20247. case 'lattice':
  20248. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  20249. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  20250. break;
  20251. case 'triangles':
  20252. count += figures[i].coords.length;
  20253. break;
  20254. }
  20255. }
  20256. // transfer data
  20257. var coords = new Float32Array(count * 2);
  20258. var colors = new Uint8Array(count * 3);
  20259. var coordsMap = context.coords, colorsMap = context.colors;
  20260. var pIndex = 0, cIndex = 0;
  20261. for (i = 0, ii = figures.length; i < ii; i++) {
  20262. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  20263. switch (figure.type) {
  20264. case 'lattice':
  20265. var cols = figure.verticesPerRow;
  20266. rows = (ps.length / cols) | 0;
  20267. for (var row = 1; row < rows; row++) {
  20268. var offset = row * cols + 1;
  20269. for (var col = 1; col < cols; col++, offset++) {
  20270. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  20271. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  20272. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  20273. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  20274. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  20275. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  20276. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  20277. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  20278. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  20279. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  20280. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  20281. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  20282. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  20283. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  20284. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  20285. coords[pIndex + 6] = coords[pIndex + 2];
  20286. coords[pIndex + 7] = coords[pIndex + 3];
  20287. coords[pIndex + 8] = coords[pIndex + 4];
  20288. coords[pIndex + 9] = coords[pIndex + 5];
  20289. coords[pIndex + 10] = coordsMap[ps[offset]];
  20290. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  20291. colors[cIndex + 9] = colors[cIndex + 3];
  20292. colors[cIndex + 10] = colors[cIndex + 4];
  20293. colors[cIndex + 11] = colors[cIndex + 5];
  20294. colors[cIndex + 12] = colors[cIndex + 6];
  20295. colors[cIndex + 13] = colors[cIndex + 7];
  20296. colors[cIndex + 14] = colors[cIndex + 8];
  20297. colors[cIndex + 15] = colorsMap[cs[offset]];
  20298. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  20299. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  20300. pIndex += 12;
  20301. cIndex += 18;
  20302. }
  20303. }
  20304. break;
  20305. case 'triangles':
  20306. for (var j = 0, jj = ps.length; j < jj; j++) {
  20307. coords[pIndex] = coordsMap[ps[j]];
  20308. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  20309. colors[cIndex] = colorsMap[cs[j]];
  20310. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  20311. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  20312. pIndex += 2;
  20313. cIndex += 3;
  20314. }
  20315. break;
  20316. }
  20317. }
  20318. // draw
  20319. if (backgroundColor) {
  20320. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  20321. backgroundColor[2] / 255, 1.0);
  20322. } else {
  20323. gl.clearColor(0, 0, 0, 0);
  20324. }
  20325. gl.clear(gl.COLOR_BUFFER_BIT);
  20326. var coordsBuffer = gl.createBuffer();
  20327. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  20328. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  20329. gl.enableVertexAttribArray(cache.positionLocation);
  20330. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  20331. var colorsBuffer = gl.createBuffer();
  20332. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  20333. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  20334. gl.enableVertexAttribArray(cache.colorLocation);
  20335. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  20336. 0, 0);
  20337. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  20338. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  20339. gl.drawArrays(gl.TRIANGLES, 0, count);
  20340. gl.flush();
  20341. gl.deleteBuffer(coordsBuffer);
  20342. gl.deleteBuffer(colorsBuffer);
  20343. return canvas;
  20344. }
  20345. function cleanup() {
  20346. if (smaskCache && smaskCache.canvas) {
  20347. smaskCache.canvas.width = 0;
  20348. smaskCache.canvas.height = 0;
  20349. }
  20350. if (figuresCache && figuresCache.canvas) {
  20351. figuresCache.canvas.width = 0;
  20352. figuresCache.canvas.height = 0;
  20353. }
  20354. smaskCache = null;
  20355. figuresCache = null;
  20356. }
  20357. return {
  20358. get isEnabled() {
  20359. if (PDFJS.disableWebGL) {
  20360. return false;
  20361. }
  20362. var enabled = false;
  20363. try {
  20364. generateGL();
  20365. enabled = !!currentGL;
  20366. } catch (e) { }
  20367. return shadow(this, 'isEnabled', enabled);
  20368. },
  20369. composeSMask: composeSMask,
  20370. drawFigures: drawFigures,
  20371. clear: cleanup
  20372. };
  20373. })();
  20374. exports.WebGLUtils = WebGLUtils;
  20375. }));
  20376. (function (root, factory) {
  20377. {
  20378. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  20379. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  20380. root.pdfjsCoreJpx);
  20381. }
  20382. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  20383. coreJpx) {
  20384. var Util = sharedUtil.Util;
  20385. var error = sharedUtil.error;
  20386. var info = sharedUtil.info;
  20387. var isArray = sharedUtil.isArray;
  20388. var shadow = sharedUtil.shadow;
  20389. var warn = sharedUtil.warn;
  20390. var Dict = corePrimitives.Dict;
  20391. var Jbig2Image = coreJbig2.Jbig2Image;
  20392. var JpegImage = coreJpg.JpegImage;
  20393. var JpxImage = coreJpx.JpxImage;
  20394. var coreParser; // see _setCoreParser below
  20395. var EOF; // = coreParser.EOF;
  20396. var Lexer; // = coreParser.Lexer;
  20397. var coreColorSpace; // see _setCoreColorSpace below
  20398. var ColorSpace; // = coreColorSpace.ColorSpace;
  20399. var Stream = (function StreamClosure() {
  20400. function Stream(arrayBuffer, start, length, dict) {
  20401. this.bytes = (arrayBuffer instanceof Uint8Array ?
  20402. arrayBuffer : new Uint8Array(arrayBuffer));
  20403. this.start = start || 0;
  20404. this.pos = this.start;
  20405. this.end = (start + length) || this.bytes.length;
  20406. this.dict = dict;
  20407. }
  20408. // required methods for a stream. if a particular stream does not
  20409. // implement these, an error should be thrown
  20410. Stream.prototype = {
  20411. get length() {
  20412. return this.end - this.start;
  20413. },
  20414. get isEmpty() {
  20415. return this.length === 0;
  20416. },
  20417. getByte: function Stream_getByte() {
  20418. if (this.pos >= this.end) {
  20419. return -1;
  20420. }
  20421. return this.bytes[this.pos++];
  20422. },
  20423. getUint16: function Stream_getUint16() {
  20424. var b0 = this.getByte();
  20425. var b1 = this.getByte();
  20426. if (b0 === -1 || b1 === -1) {
  20427. return -1;
  20428. }
  20429. return (b0 << 8) + b1;
  20430. },
  20431. getInt32: function Stream_getInt32() {
  20432. var b0 = this.getByte();
  20433. var b1 = this.getByte();
  20434. var b2 = this.getByte();
  20435. var b3 = this.getByte();
  20436. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20437. },
  20438. // returns subarray of original buffer
  20439. // should only be read
  20440. getBytes: function Stream_getBytes(length) {
  20441. var bytes = this.bytes;
  20442. var pos = this.pos;
  20443. var strEnd = this.end;
  20444. if (!length) {
  20445. return bytes.subarray(pos, strEnd);
  20446. }
  20447. var end = pos + length;
  20448. if (end > strEnd) {
  20449. end = strEnd;
  20450. }
  20451. this.pos = end;
  20452. return bytes.subarray(pos, end);
  20453. },
  20454. peekByte: function Stream_peekByte() {
  20455. var peekedByte = this.getByte();
  20456. this.pos--;
  20457. return peekedByte;
  20458. },
  20459. peekBytes: function Stream_peekBytes(length) {
  20460. var bytes = this.getBytes(length);
  20461. this.pos -= bytes.length;
  20462. return bytes;
  20463. },
  20464. skip: function Stream_skip(n) {
  20465. if (!n) {
  20466. n = 1;
  20467. }
  20468. this.pos += n;
  20469. },
  20470. reset: function Stream_reset() {
  20471. this.pos = this.start;
  20472. },
  20473. moveStart: function Stream_moveStart() {
  20474. this.start = this.pos;
  20475. },
  20476. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  20477. return new Stream(this.bytes.buffer, start, length, dict);
  20478. },
  20479. isStream: true
  20480. };
  20481. return Stream;
  20482. })();
  20483. var StringStream = (function StringStreamClosure() {
  20484. function StringStream(str) {
  20485. var length = str.length;
  20486. var bytes = new Uint8Array(length);
  20487. for (var n = 0; n < length; ++n) {
  20488. bytes[n] = str.charCodeAt(n);
  20489. }
  20490. Stream.call(this, bytes);
  20491. }
  20492. StringStream.prototype = Stream.prototype;
  20493. return StringStream;
  20494. })();
  20495. // super class for the decoding streams
  20496. var DecodeStream = (function DecodeStreamClosure() {
  20497. // Lots of DecodeStreams are created whose buffers are never used. For these
  20498. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  20499. // having special cases that would be required if we used |null| for an empty
  20500. // buffer.
  20501. var emptyBuffer = new Uint8Array(0);
  20502. function DecodeStream(maybeMinBufferLength) {
  20503. this.pos = 0;
  20504. this.bufferLength = 0;
  20505. this.eof = false;
  20506. this.buffer = emptyBuffer;
  20507. this.minBufferLength = 512;
  20508. if (maybeMinBufferLength) {
  20509. // Compute the first power of two that is as big as maybeMinBufferLength.
  20510. while (this.minBufferLength < maybeMinBufferLength) {
  20511. this.minBufferLength *= 2;
  20512. }
  20513. }
  20514. }
  20515. DecodeStream.prototype = {
  20516. get isEmpty() {
  20517. while (!this.eof && this.bufferLength === 0) {
  20518. this.readBlock();
  20519. }
  20520. return this.bufferLength === 0;
  20521. },
  20522. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  20523. var buffer = this.buffer;
  20524. if (requested <= buffer.byteLength) {
  20525. return buffer;
  20526. }
  20527. var size = this.minBufferLength;
  20528. while (size < requested) {
  20529. size *= 2;
  20530. }
  20531. var buffer2 = new Uint8Array(size);
  20532. buffer2.set(buffer);
  20533. return (this.buffer = buffer2);
  20534. },
  20535. getByte: function DecodeStream_getByte() {
  20536. var pos = this.pos;
  20537. while (this.bufferLength <= pos) {
  20538. if (this.eof) {
  20539. return -1;
  20540. }
  20541. this.readBlock();
  20542. }
  20543. return this.buffer[this.pos++];
  20544. },
  20545. getUint16: function DecodeStream_getUint16() {
  20546. var b0 = this.getByte();
  20547. var b1 = this.getByte();
  20548. if (b0 === -1 || b1 === -1) {
  20549. return -1;
  20550. }
  20551. return (b0 << 8) + b1;
  20552. },
  20553. getInt32: function DecodeStream_getInt32() {
  20554. var b0 = this.getByte();
  20555. var b1 = this.getByte();
  20556. var b2 = this.getByte();
  20557. var b3 = this.getByte();
  20558. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  20559. },
  20560. getBytes: function DecodeStream_getBytes(length) {
  20561. var end, pos = this.pos;
  20562. if (length) {
  20563. this.ensureBuffer(pos + length);
  20564. end = pos + length;
  20565. while (!this.eof && this.bufferLength < end) {
  20566. this.readBlock();
  20567. }
  20568. var bufEnd = this.bufferLength;
  20569. if (end > bufEnd) {
  20570. end = bufEnd;
  20571. }
  20572. } else {
  20573. while (!this.eof) {
  20574. this.readBlock();
  20575. }
  20576. end = this.bufferLength;
  20577. }
  20578. this.pos = end;
  20579. return this.buffer.subarray(pos, end);
  20580. },
  20581. peekByte: function DecodeStream_peekByte() {
  20582. var peekedByte = this.getByte();
  20583. this.pos--;
  20584. return peekedByte;
  20585. },
  20586. peekBytes: function DecodeStream_peekBytes(length) {
  20587. var bytes = this.getBytes(length);
  20588. this.pos -= bytes.length;
  20589. return bytes;
  20590. },
  20591. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  20592. var end = start + length;
  20593. while (this.bufferLength <= end && !this.eof) {
  20594. this.readBlock();
  20595. }
  20596. return new Stream(this.buffer, start, length, dict);
  20597. },
  20598. skip: function DecodeStream_skip(n) {
  20599. if (!n) {
  20600. n = 1;
  20601. }
  20602. this.pos += n;
  20603. },
  20604. reset: function DecodeStream_reset() {
  20605. this.pos = 0;
  20606. },
  20607. getBaseStreams: function DecodeStream_getBaseStreams() {
  20608. if (this.str && this.str.getBaseStreams) {
  20609. return this.str.getBaseStreams();
  20610. }
  20611. return [];
  20612. }
  20613. };
  20614. return DecodeStream;
  20615. })();
  20616. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  20617. function StreamsSequenceStream(streams) {
  20618. this.streams = streams;
  20619. DecodeStream.call(this, /* maybeLength = */ null);
  20620. }
  20621. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  20622. StreamsSequenceStream.prototype.readBlock =
  20623. function streamSequenceStreamReadBlock() {
  20624. var streams = this.streams;
  20625. if (streams.length === 0) {
  20626. this.eof = true;
  20627. return;
  20628. }
  20629. var stream = streams.shift();
  20630. var chunk = stream.getBytes();
  20631. var bufferLength = this.bufferLength;
  20632. var newLength = bufferLength + chunk.length;
  20633. var buffer = this.ensureBuffer(newLength);
  20634. buffer.set(chunk, bufferLength);
  20635. this.bufferLength = newLength;
  20636. };
  20637. StreamsSequenceStream.prototype.getBaseStreams =
  20638. function StreamsSequenceStream_getBaseStreams() {
  20639. var baseStreams = [];
  20640. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  20641. var stream = this.streams[i];
  20642. if (stream.getBaseStreams) {
  20643. Util.appendToArray(baseStreams, stream.getBaseStreams());
  20644. }
  20645. }
  20646. return baseStreams;
  20647. };
  20648. return StreamsSequenceStream;
  20649. })();
  20650. var FlateStream = (function FlateStreamClosure() {
  20651. var codeLenCodeMap = new Int32Array([
  20652. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  20653. ]);
  20654. var lengthDecode = new Int32Array([
  20655. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  20656. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  20657. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  20658. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  20659. ]);
  20660. var distDecode = new Int32Array([
  20661. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  20662. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  20663. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  20664. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  20665. ]);
  20666. var fixedLitCodeTab = [new Int32Array([
  20667. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  20668. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  20669. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  20670. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  20671. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  20672. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  20673. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  20674. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  20675. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  20676. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  20677. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  20678. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  20679. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  20680. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  20681. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  20682. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  20683. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  20684. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  20685. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  20686. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  20687. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  20688. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  20689. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  20690. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  20691. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  20692. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  20693. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  20694. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  20695. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  20696. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  20697. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  20698. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  20699. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  20700. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  20701. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  20702. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  20703. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  20704. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  20705. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  20706. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  20707. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  20708. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  20709. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  20710. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  20711. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  20712. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  20713. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  20714. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  20715. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  20716. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  20717. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  20718. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  20719. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  20720. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  20721. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  20722. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  20723. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  20724. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  20725. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  20726. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  20727. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  20728. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  20729. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  20730. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  20731. ]), 9];
  20732. var fixedDistCodeTab = [new Int32Array([
  20733. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  20734. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  20735. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  20736. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  20737. ]), 5];
  20738. function FlateStream(str, maybeLength) {
  20739. this.str = str;
  20740. this.dict = str.dict;
  20741. var cmf = str.getByte();
  20742. var flg = str.getByte();
  20743. if (cmf === -1 || flg === -1) {
  20744. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  20745. }
  20746. if ((cmf & 0x0f) !== 0x08) {
  20747. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  20748. }
  20749. if ((((cmf << 8) + flg) % 31) !== 0) {
  20750. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  20751. }
  20752. if (flg & 0x20) {
  20753. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  20754. }
  20755. this.codeSize = 0;
  20756. this.codeBuf = 0;
  20757. DecodeStream.call(this, maybeLength);
  20758. }
  20759. FlateStream.prototype = Object.create(DecodeStream.prototype);
  20760. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  20761. var str = this.str;
  20762. var codeSize = this.codeSize;
  20763. var codeBuf = this.codeBuf;
  20764. var b;
  20765. while (codeSize < bits) {
  20766. if ((b = str.getByte()) === -1) {
  20767. error('Bad encoding in flate stream');
  20768. }
  20769. codeBuf |= b << codeSize;
  20770. codeSize += 8;
  20771. }
  20772. b = codeBuf & ((1 << bits) - 1);
  20773. this.codeBuf = codeBuf >> bits;
  20774. this.codeSize = codeSize -= bits;
  20775. return b;
  20776. };
  20777. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  20778. var str = this.str;
  20779. var codes = table[0];
  20780. var maxLen = table[1];
  20781. var codeSize = this.codeSize;
  20782. var codeBuf = this.codeBuf;
  20783. var b;
  20784. while (codeSize < maxLen) {
  20785. if ((b = str.getByte()) === -1) {
  20786. // premature end of stream. code might however still be valid.
  20787. // codeSize < codeLen check below guards against incomplete codeVal.
  20788. break;
  20789. }
  20790. codeBuf |= (b << codeSize);
  20791. codeSize += 8;
  20792. }
  20793. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  20794. var codeLen = code >> 16;
  20795. var codeVal = code & 0xffff;
  20796. if (codeLen < 1 || codeSize < codeLen) {
  20797. error('Bad encoding in flate stream');
  20798. }
  20799. this.codeBuf = (codeBuf >> codeLen);
  20800. this.codeSize = (codeSize - codeLen);
  20801. return codeVal;
  20802. };
  20803. FlateStream.prototype.generateHuffmanTable =
  20804. function flateStreamGenerateHuffmanTable(lengths) {
  20805. var n = lengths.length;
  20806. // find max code length
  20807. var maxLen = 0;
  20808. var i;
  20809. for (i = 0; i < n; ++i) {
  20810. if (lengths[i] > maxLen) {
  20811. maxLen = lengths[i];
  20812. }
  20813. }
  20814. // build the table
  20815. var size = 1 << maxLen;
  20816. var codes = new Int32Array(size);
  20817. for (var len = 1, code = 0, skip = 2;
  20818. len <= maxLen;
  20819. ++len, code <<= 1, skip <<= 1) {
  20820. for (var val = 0; val < n; ++val) {
  20821. if (lengths[val] === len) {
  20822. // bit-reverse the code
  20823. var code2 = 0;
  20824. var t = code;
  20825. for (i = 0; i < len; ++i) {
  20826. code2 = (code2 << 1) | (t & 1);
  20827. t >>= 1;
  20828. }
  20829. // fill the table entries
  20830. for (i = code2; i < size; i += skip) {
  20831. codes[i] = (len << 16) | val;
  20832. }
  20833. ++code;
  20834. }
  20835. }
  20836. }
  20837. return [codes, maxLen];
  20838. };
  20839. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  20840. var buffer, len;
  20841. var str = this.str;
  20842. // read block header
  20843. var hdr = this.getBits(3);
  20844. if (hdr & 1) {
  20845. this.eof = true;
  20846. }
  20847. hdr >>= 1;
  20848. if (hdr === 0) { // uncompressed block
  20849. var b;
  20850. if ((b = str.getByte()) === -1) {
  20851. error('Bad block header in flate stream');
  20852. }
  20853. var blockLen = b;
  20854. if ((b = str.getByte()) === -1) {
  20855. error('Bad block header in flate stream');
  20856. }
  20857. blockLen |= (b << 8);
  20858. if ((b = str.getByte()) === -1) {
  20859. error('Bad block header in flate stream');
  20860. }
  20861. var check = b;
  20862. if ((b = str.getByte()) === -1) {
  20863. error('Bad block header in flate stream');
  20864. }
  20865. check |= (b << 8);
  20866. if (check !== (~blockLen & 0xffff) &&
  20867. (blockLen !== 0 || check !== 0)) {
  20868. // Ignoring error for bad "empty" block (see issue 1277)
  20869. error('Bad uncompressed block length in flate stream');
  20870. }
  20871. this.codeBuf = 0;
  20872. this.codeSize = 0;
  20873. var bufferLength = this.bufferLength;
  20874. buffer = this.ensureBuffer(bufferLength + blockLen);
  20875. var end = bufferLength + blockLen;
  20876. this.bufferLength = end;
  20877. if (blockLen === 0) {
  20878. if (str.peekByte() === -1) {
  20879. this.eof = true;
  20880. }
  20881. } else {
  20882. for (var n = bufferLength; n < end; ++n) {
  20883. if ((b = str.getByte()) === -1) {
  20884. this.eof = true;
  20885. break;
  20886. }
  20887. buffer[n] = b;
  20888. }
  20889. }
  20890. return;
  20891. }
  20892. var litCodeTable;
  20893. var distCodeTable;
  20894. if (hdr === 1) { // compressed block, fixed codes
  20895. litCodeTable = fixedLitCodeTab;
  20896. distCodeTable = fixedDistCodeTab;
  20897. } else if (hdr === 2) { // compressed block, dynamic codes
  20898. var numLitCodes = this.getBits(5) + 257;
  20899. var numDistCodes = this.getBits(5) + 1;
  20900. var numCodeLenCodes = this.getBits(4) + 4;
  20901. // build the code lengths code table
  20902. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  20903. var i;
  20904. for (i = 0; i < numCodeLenCodes; ++i) {
  20905. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  20906. }
  20907. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  20908. // build the literal and distance code tables
  20909. len = 0;
  20910. i = 0;
  20911. var codes = numLitCodes + numDistCodes;
  20912. var codeLengths = new Uint8Array(codes);
  20913. var bitsLength, bitsOffset, what;
  20914. while (i < codes) {
  20915. var code = this.getCode(codeLenCodeTab);
  20916. if (code === 16) {
  20917. bitsLength = 2; bitsOffset = 3; what = len;
  20918. } else if (code === 17) {
  20919. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  20920. } else if (code === 18) {
  20921. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  20922. } else {
  20923. codeLengths[i++] = len = code;
  20924. continue;
  20925. }
  20926. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  20927. while (repeatLength-- > 0) {
  20928. codeLengths[i++] = what;
  20929. }
  20930. }
  20931. litCodeTable =
  20932. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  20933. distCodeTable =
  20934. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  20935. } else {
  20936. error('Unknown block type in flate stream');
  20937. }
  20938. buffer = this.buffer;
  20939. var limit = buffer ? buffer.length : 0;
  20940. var pos = this.bufferLength;
  20941. while (true) {
  20942. var code1 = this.getCode(litCodeTable);
  20943. if (code1 < 256) {
  20944. if (pos + 1 >= limit) {
  20945. buffer = this.ensureBuffer(pos + 1);
  20946. limit = buffer.length;
  20947. }
  20948. buffer[pos++] = code1;
  20949. continue;
  20950. }
  20951. if (code1 === 256) {
  20952. this.bufferLength = pos;
  20953. return;
  20954. }
  20955. code1 -= 257;
  20956. code1 = lengthDecode[code1];
  20957. var code2 = code1 >> 16;
  20958. if (code2 > 0) {
  20959. code2 = this.getBits(code2);
  20960. }
  20961. len = (code1 & 0xffff) + code2;
  20962. code1 = this.getCode(distCodeTable);
  20963. code1 = distDecode[code1];
  20964. code2 = code1 >> 16;
  20965. if (code2 > 0) {
  20966. code2 = this.getBits(code2);
  20967. }
  20968. var dist = (code1 & 0xffff) + code2;
  20969. if (pos + len >= limit) {
  20970. buffer = this.ensureBuffer(pos + len);
  20971. limit = buffer.length;
  20972. }
  20973. for (var k = 0; k < len; ++k, ++pos) {
  20974. buffer[pos] = buffer[pos - dist];
  20975. }
  20976. }
  20977. };
  20978. return FlateStream;
  20979. })();
  20980. var PredictorStream = (function PredictorStreamClosure() {
  20981. function PredictorStream(str, maybeLength, params) {
  20982. var predictor = this.predictor = params.get('Predictor') || 1;
  20983. if (predictor <= 1) {
  20984. return str; // no prediction
  20985. }
  20986. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  20987. error('Unsupported predictor: ' + predictor);
  20988. }
  20989. if (predictor === 2) {
  20990. this.readBlock = this.readBlockTiff;
  20991. } else {
  20992. this.readBlock = this.readBlockPng;
  20993. }
  20994. this.str = str;
  20995. this.dict = str.dict;
  20996. var colors = this.colors = params.get('Colors') || 1;
  20997. var bits = this.bits = params.get('BitsPerComponent') || 8;
  20998. var columns = this.columns = params.get('Columns') || 1;
  20999. this.pixBytes = (colors * bits + 7) >> 3;
  21000. this.rowBytes = (columns * colors * bits + 7) >> 3;
  21001. DecodeStream.call(this, maybeLength);
  21002. return this;
  21003. }
  21004. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  21005. PredictorStream.prototype.readBlockTiff =
  21006. function predictorStreamReadBlockTiff() {
  21007. var rowBytes = this.rowBytes;
  21008. var bufferLength = this.bufferLength;
  21009. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21010. var bits = this.bits;
  21011. var colors = this.colors;
  21012. var rawBytes = this.str.getBytes(rowBytes);
  21013. this.eof = !rawBytes.length;
  21014. if (this.eof) {
  21015. return;
  21016. }
  21017. var inbuf = 0, outbuf = 0;
  21018. var inbits = 0, outbits = 0;
  21019. var pos = bufferLength;
  21020. var i;
  21021. if (bits === 1) {
  21022. for (i = 0; i < rowBytes; ++i) {
  21023. var c = rawBytes[i];
  21024. inbuf = (inbuf << 8) | c;
  21025. // bitwise addition is exclusive or
  21026. // first shift inbuf and then add
  21027. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  21028. // truncate inbuf (assumes colors < 16)
  21029. inbuf &= 0xFFFF;
  21030. }
  21031. } else if (bits === 8) {
  21032. for (i = 0; i < colors; ++i) {
  21033. buffer[pos++] = rawBytes[i];
  21034. }
  21035. for (; i < rowBytes; ++i) {
  21036. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  21037. pos++;
  21038. }
  21039. } else {
  21040. var compArray = new Uint8Array(colors + 1);
  21041. var bitMask = (1 << bits) - 1;
  21042. var j = 0, k = bufferLength;
  21043. var columns = this.columns;
  21044. for (i = 0; i < columns; ++i) {
  21045. for (var kk = 0; kk < colors; ++kk) {
  21046. if (inbits < bits) {
  21047. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  21048. inbits += 8;
  21049. }
  21050. compArray[kk] = (compArray[kk] +
  21051. (inbuf >> (inbits - bits))) & bitMask;
  21052. inbits -= bits;
  21053. outbuf = (outbuf << bits) | compArray[kk];
  21054. outbits += bits;
  21055. if (outbits >= 8) {
  21056. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  21057. outbits -= 8;
  21058. }
  21059. }
  21060. }
  21061. if (outbits > 0) {
  21062. buffer[k++] = (outbuf << (8 - outbits)) +
  21063. (inbuf & ((1 << (8 - outbits)) - 1));
  21064. }
  21065. }
  21066. this.bufferLength += rowBytes;
  21067. };
  21068. PredictorStream.prototype.readBlockPng =
  21069. function predictorStreamReadBlockPng() {
  21070. var rowBytes = this.rowBytes;
  21071. var pixBytes = this.pixBytes;
  21072. var predictor = this.str.getByte();
  21073. var rawBytes = this.str.getBytes(rowBytes);
  21074. this.eof = !rawBytes.length;
  21075. if (this.eof) {
  21076. return;
  21077. }
  21078. var bufferLength = this.bufferLength;
  21079. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  21080. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  21081. if (prevRow.length === 0) {
  21082. prevRow = new Uint8Array(rowBytes);
  21083. }
  21084. var i, j = bufferLength, up, c;
  21085. switch (predictor) {
  21086. case 0:
  21087. for (i = 0; i < rowBytes; ++i) {
  21088. buffer[j++] = rawBytes[i];
  21089. }
  21090. break;
  21091. case 1:
  21092. for (i = 0; i < pixBytes; ++i) {
  21093. buffer[j++] = rawBytes[i];
  21094. }
  21095. for (; i < rowBytes; ++i) {
  21096. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  21097. j++;
  21098. }
  21099. break;
  21100. case 2:
  21101. for (i = 0; i < rowBytes; ++i) {
  21102. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  21103. }
  21104. break;
  21105. case 3:
  21106. for (i = 0; i < pixBytes; ++i) {
  21107. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  21108. }
  21109. for (; i < rowBytes; ++i) {
  21110. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  21111. rawBytes[i]) & 0xFF;
  21112. j++;
  21113. }
  21114. break;
  21115. case 4:
  21116. // we need to save the up left pixels values. the simplest way
  21117. // is to create a new buffer
  21118. for (i = 0; i < pixBytes; ++i) {
  21119. up = prevRow[i];
  21120. c = rawBytes[i];
  21121. buffer[j++] = up + c;
  21122. }
  21123. for (; i < rowBytes; ++i) {
  21124. up = prevRow[i];
  21125. var upLeft = prevRow[i - pixBytes];
  21126. var left = buffer[j - pixBytes];
  21127. var p = left + up - upLeft;
  21128. var pa = p - left;
  21129. if (pa < 0) {
  21130. pa = -pa;
  21131. }
  21132. var pb = p - up;
  21133. if (pb < 0) {
  21134. pb = -pb;
  21135. }
  21136. var pc = p - upLeft;
  21137. if (pc < 0) {
  21138. pc = -pc;
  21139. }
  21140. c = rawBytes[i];
  21141. if (pa <= pb && pa <= pc) {
  21142. buffer[j++] = left + c;
  21143. } else if (pb <= pc) {
  21144. buffer[j++] = up + c;
  21145. } else {
  21146. buffer[j++] = upLeft + c;
  21147. }
  21148. }
  21149. break;
  21150. default:
  21151. error('Unsupported predictor: ' + predictor);
  21152. }
  21153. this.bufferLength += rowBytes;
  21154. };
  21155. return PredictorStream;
  21156. })();
  21157. /**
  21158. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  21159. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  21160. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  21161. * a library to decode these images and the stream behaves like all the other
  21162. * DecodeStreams.
  21163. */
  21164. var JpegStream = (function JpegStreamClosure() {
  21165. function JpegStream(stream, maybeLength, dict, xref) {
  21166. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  21167. // Note: this seems to mainly affect inline images.
  21168. var ch;
  21169. while ((ch = stream.getByte()) !== -1) {
  21170. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  21171. stream.skip(-1); // Reset the stream position to the SOI.
  21172. break;
  21173. }
  21174. }
  21175. this.stream = stream;
  21176. this.maybeLength = maybeLength;
  21177. this.dict = dict;
  21178. DecodeStream.call(this, maybeLength);
  21179. }
  21180. JpegStream.prototype = Object.create(DecodeStream.prototype);
  21181. Object.defineProperty(JpegStream.prototype, 'bytes', {
  21182. get: function JpegStream_bytes() {
  21183. // If this.maybeLength is null, we'll get the entire stream.
  21184. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21185. },
  21186. configurable: true
  21187. });
  21188. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  21189. if (this.bufferLength) {
  21190. return;
  21191. }
  21192. try {
  21193. var jpegImage = new JpegImage();
  21194. // checking if values needs to be transformed before conversion
  21195. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  21196. var decodeArr = this.dict.get('Decode');
  21197. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  21198. var decodeArrLength = decodeArr.length;
  21199. var transform = new Int32Array(decodeArrLength);
  21200. var transformNeeded = false;
  21201. var maxValue = (1 << bitsPerComponent) - 1;
  21202. for (var i = 0; i < decodeArrLength; i += 2) {
  21203. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  21204. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  21205. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  21206. transformNeeded = true;
  21207. }
  21208. }
  21209. if (transformNeeded) {
  21210. jpegImage.decodeTransform = transform;
  21211. }
  21212. }
  21213. jpegImage.parse(this.bytes);
  21214. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  21215. this.forceRGB);
  21216. this.buffer = data;
  21217. this.bufferLength = data.length;
  21218. this.eof = true;
  21219. } catch (e) {
  21220. error('JPEG error: ' + e);
  21221. }
  21222. };
  21223. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  21224. this.ensureBuffer();
  21225. return this.buffer;
  21226. };
  21227. JpegStream.prototype.getIR = function JpegStream_getIR() {
  21228. return PDFJS.createObjectURL(this.bytes, 'image/jpeg');
  21229. };
  21230. /**
  21231. * Checks if the image can be decoded and displayed by the browser without any
  21232. * further processing such as color space conversions.
  21233. */
  21234. JpegStream.prototype.isNativelySupported =
  21235. function JpegStream_isNativelySupported(xref, res) {
  21236. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  21237. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  21238. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  21239. };
  21240. /**
  21241. * Checks if the image can be decoded by the browser.
  21242. */
  21243. JpegStream.prototype.isNativelyDecodable =
  21244. function JpegStream_isNativelyDecodable(xref, res) {
  21245. var cs = ColorSpace.parse(this.dict.get('ColorSpace', 'CS'), xref, res);
  21246. return (cs.numComps === 1 || cs.numComps === 3) &&
  21247. cs.isDefaultDecode(this.dict.get('Decode', 'D'));
  21248. };
  21249. return JpegStream;
  21250. })();
  21251. /**
  21252. * For JPEG 2000's we use a library to decode these images and
  21253. * the stream behaves like all the other DecodeStreams.
  21254. */
  21255. var JpxStream = (function JpxStreamClosure() {
  21256. function JpxStream(stream, maybeLength, dict) {
  21257. this.stream = stream;
  21258. this.maybeLength = maybeLength;
  21259. this.dict = dict;
  21260. DecodeStream.call(this, maybeLength);
  21261. }
  21262. JpxStream.prototype = Object.create(DecodeStream.prototype);
  21263. Object.defineProperty(JpxStream.prototype, 'bytes', {
  21264. get: function JpxStream_bytes() {
  21265. // If this.maybeLength is null, we'll get the entire stream.
  21266. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21267. },
  21268. configurable: true
  21269. });
  21270. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  21271. if (this.bufferLength) {
  21272. return;
  21273. }
  21274. var jpxImage = new JpxImage();
  21275. jpxImage.parse(this.bytes);
  21276. var width = jpxImage.width;
  21277. var height = jpxImage.height;
  21278. var componentsCount = jpxImage.componentsCount;
  21279. var tileCount = jpxImage.tiles.length;
  21280. if (tileCount === 1) {
  21281. this.buffer = jpxImage.tiles[0].items;
  21282. } else {
  21283. var data = new Uint8Array(width * height * componentsCount);
  21284. for (var k = 0; k < tileCount; k++) {
  21285. var tileComponents = jpxImage.tiles[k];
  21286. var tileWidth = tileComponents.width;
  21287. var tileHeight = tileComponents.height;
  21288. var tileLeft = tileComponents.left;
  21289. var tileTop = tileComponents.top;
  21290. var src = tileComponents.items;
  21291. var srcPosition = 0;
  21292. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  21293. var imgRowSize = width * componentsCount;
  21294. var tileRowSize = tileWidth * componentsCount;
  21295. for (var j = 0; j < tileHeight; j++) {
  21296. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  21297. data.set(rowBytes, dataPosition);
  21298. srcPosition += tileRowSize;
  21299. dataPosition += imgRowSize;
  21300. }
  21301. }
  21302. this.buffer = data;
  21303. }
  21304. this.bufferLength = this.buffer.length;
  21305. this.eof = true;
  21306. };
  21307. return JpxStream;
  21308. })();
  21309. /**
  21310. * For JBIG2's we use a library to decode these images and
  21311. * the stream behaves like all the other DecodeStreams.
  21312. */
  21313. var Jbig2Stream = (function Jbig2StreamClosure() {
  21314. function Jbig2Stream(stream, maybeLength, dict) {
  21315. this.stream = stream;
  21316. this.maybeLength = maybeLength;
  21317. this.dict = dict;
  21318. DecodeStream.call(this, maybeLength);
  21319. }
  21320. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  21321. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  21322. get: function Jbig2Stream_bytes() {
  21323. // If this.maybeLength is null, we'll get the entire stream.
  21324. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  21325. },
  21326. configurable: true
  21327. });
  21328. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  21329. if (this.bufferLength) {
  21330. return;
  21331. }
  21332. var jbig2Image = new Jbig2Image();
  21333. var chunks = [], xref = this.dict.xref;
  21334. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  21335. // According to the PDF specification, DecodeParms can be either
  21336. // a dictionary, or an array whose elements are dictionaries.
  21337. if (isArray(decodeParams)) {
  21338. if (decodeParams.length > 1) {
  21339. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  21340. 'not supported.');
  21341. }
  21342. decodeParams = xref.fetchIfRef(decodeParams[0]);
  21343. }
  21344. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  21345. var globalsStream = decodeParams.get('JBIG2Globals');
  21346. var globals = globalsStream.getBytes();
  21347. chunks.push({data: globals, start: 0, end: globals.length});
  21348. }
  21349. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  21350. var data = jbig2Image.parseChunks(chunks);
  21351. var dataLength = data.length;
  21352. // JBIG2 had black as 1 and white as 0, inverting the colors
  21353. for (var i = 0; i < dataLength; i++) {
  21354. data[i] ^= 0xFF;
  21355. }
  21356. this.buffer = data;
  21357. this.bufferLength = dataLength;
  21358. this.eof = true;
  21359. };
  21360. return Jbig2Stream;
  21361. })();
  21362. var DecryptStream = (function DecryptStreamClosure() {
  21363. function DecryptStream(str, maybeLength, decrypt) {
  21364. this.str = str;
  21365. this.dict = str.dict;
  21366. this.decrypt = decrypt;
  21367. this.nextChunk = null;
  21368. this.initialized = false;
  21369. DecodeStream.call(this, maybeLength);
  21370. }
  21371. var chunkSize = 512;
  21372. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  21373. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  21374. var chunk;
  21375. if (this.initialized) {
  21376. chunk = this.nextChunk;
  21377. } else {
  21378. chunk = this.str.getBytes(chunkSize);
  21379. this.initialized = true;
  21380. }
  21381. if (!chunk || chunk.length === 0) {
  21382. this.eof = true;
  21383. return;
  21384. }
  21385. this.nextChunk = this.str.getBytes(chunkSize);
  21386. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  21387. var decrypt = this.decrypt;
  21388. chunk = decrypt(chunk, !hasMoreData);
  21389. var bufferLength = this.bufferLength;
  21390. var i, n = chunk.length;
  21391. var buffer = this.ensureBuffer(bufferLength + n);
  21392. for (i = 0; i < n; i++) {
  21393. buffer[bufferLength++] = chunk[i];
  21394. }
  21395. this.bufferLength = bufferLength;
  21396. };
  21397. return DecryptStream;
  21398. })();
  21399. var Ascii85Stream = (function Ascii85StreamClosure() {
  21400. function Ascii85Stream(str, maybeLength) {
  21401. this.str = str;
  21402. this.dict = str.dict;
  21403. this.input = new Uint8Array(5);
  21404. // Most streams increase in size when decoded, but Ascii85 streams
  21405. // typically shrink by ~20%.
  21406. if (maybeLength) {
  21407. maybeLength = 0.8 * maybeLength;
  21408. }
  21409. DecodeStream.call(this, maybeLength);
  21410. }
  21411. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  21412. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  21413. var TILDA_CHAR = 0x7E; // '~'
  21414. var Z_LOWER_CHAR = 0x7A; // 'z'
  21415. var EOF = -1;
  21416. var str = this.str;
  21417. var c = str.getByte();
  21418. while (Lexer.isSpace(c)) {
  21419. c = str.getByte();
  21420. }
  21421. if (c === EOF || c === TILDA_CHAR) {
  21422. this.eof = true;
  21423. return;
  21424. }
  21425. var bufferLength = this.bufferLength, buffer;
  21426. var i;
  21427. // special code for z
  21428. if (c === Z_LOWER_CHAR) {
  21429. buffer = this.ensureBuffer(bufferLength + 4);
  21430. for (i = 0; i < 4; ++i) {
  21431. buffer[bufferLength + i] = 0;
  21432. }
  21433. this.bufferLength += 4;
  21434. } else {
  21435. var input = this.input;
  21436. input[0] = c;
  21437. for (i = 1; i < 5; ++i) {
  21438. c = str.getByte();
  21439. while (Lexer.isSpace(c)) {
  21440. c = str.getByte();
  21441. }
  21442. input[i] = c;
  21443. if (c === EOF || c === TILDA_CHAR) {
  21444. break;
  21445. }
  21446. }
  21447. buffer = this.ensureBuffer(bufferLength + i - 1);
  21448. this.bufferLength += i - 1;
  21449. // partial ending;
  21450. if (i < 5) {
  21451. for (; i < 5; ++i) {
  21452. input[i] = 0x21 + 84;
  21453. }
  21454. this.eof = true;
  21455. }
  21456. var t = 0;
  21457. for (i = 0; i < 5; ++i) {
  21458. t = t * 85 + (input[i] - 0x21);
  21459. }
  21460. for (i = 3; i >= 0; --i) {
  21461. buffer[bufferLength + i] = t & 0xFF;
  21462. t >>= 8;
  21463. }
  21464. }
  21465. };
  21466. return Ascii85Stream;
  21467. })();
  21468. var AsciiHexStream = (function AsciiHexStreamClosure() {
  21469. function AsciiHexStream(str, maybeLength) {
  21470. this.str = str;
  21471. this.dict = str.dict;
  21472. this.firstDigit = -1;
  21473. // Most streams increase in size when decoded, but AsciiHex streams shrink
  21474. // by 50%.
  21475. if (maybeLength) {
  21476. maybeLength = 0.5 * maybeLength;
  21477. }
  21478. DecodeStream.call(this, maybeLength);
  21479. }
  21480. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  21481. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  21482. var UPSTREAM_BLOCK_SIZE = 8000;
  21483. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  21484. if (!bytes.length) {
  21485. this.eof = true;
  21486. return;
  21487. }
  21488. var maxDecodeLength = (bytes.length + 1) >> 1;
  21489. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  21490. var bufferLength = this.bufferLength;
  21491. var firstDigit = this.firstDigit;
  21492. for (var i = 0, ii = bytes.length; i < ii; i++) {
  21493. var ch = bytes[i], digit;
  21494. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  21495. digit = ch & 0x0F;
  21496. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  21497. // 'A'-'Z', 'a'-'z'
  21498. digit = (ch & 0x0F) + 9;
  21499. } else if (ch === 0x3E) { // '>'
  21500. this.eof = true;
  21501. break;
  21502. } else { // probably whitespace
  21503. continue; // ignoring
  21504. }
  21505. if (firstDigit < 0) {
  21506. firstDigit = digit;
  21507. } else {
  21508. buffer[bufferLength++] = (firstDigit << 4) | digit;
  21509. firstDigit = -1;
  21510. }
  21511. }
  21512. if (firstDigit >= 0 && this.eof) {
  21513. // incomplete byte
  21514. buffer[bufferLength++] = (firstDigit << 4);
  21515. firstDigit = -1;
  21516. }
  21517. this.firstDigit = firstDigit;
  21518. this.bufferLength = bufferLength;
  21519. };
  21520. return AsciiHexStream;
  21521. })();
  21522. var RunLengthStream = (function RunLengthStreamClosure() {
  21523. function RunLengthStream(str, maybeLength) {
  21524. this.str = str;
  21525. this.dict = str.dict;
  21526. DecodeStream.call(this, maybeLength);
  21527. }
  21528. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  21529. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  21530. // The repeatHeader has following format. The first byte defines type of run
  21531. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  21532. // (in addition to the second byte from the header), n = 129 through 255 -
  21533. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  21534. var repeatHeader = this.str.getBytes(2);
  21535. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  21536. this.eof = true;
  21537. return;
  21538. }
  21539. var buffer;
  21540. var bufferLength = this.bufferLength;
  21541. var n = repeatHeader[0];
  21542. if (n < 128) {
  21543. // copy n bytes
  21544. buffer = this.ensureBuffer(bufferLength + n + 1);
  21545. buffer[bufferLength++] = repeatHeader[1];
  21546. if (n > 0) {
  21547. var source = this.str.getBytes(n);
  21548. buffer.set(source, bufferLength);
  21549. bufferLength += n;
  21550. }
  21551. } else {
  21552. n = 257 - n;
  21553. var b = repeatHeader[1];
  21554. buffer = this.ensureBuffer(bufferLength + n + 1);
  21555. for (var i = 0; i < n; i++) {
  21556. buffer[bufferLength++] = b;
  21557. }
  21558. }
  21559. this.bufferLength = bufferLength;
  21560. };
  21561. return RunLengthStream;
  21562. })();
  21563. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  21564. var ccittEOL = -2;
  21565. var twoDimPass = 0;
  21566. var twoDimHoriz = 1;
  21567. var twoDimVert0 = 2;
  21568. var twoDimVertR1 = 3;
  21569. var twoDimVertL1 = 4;
  21570. var twoDimVertR2 = 5;
  21571. var twoDimVertL2 = 6;
  21572. var twoDimVertR3 = 7;
  21573. var twoDimVertL3 = 8;
  21574. var twoDimTable = [
  21575. [-1, -1], [-1, -1], // 000000x
  21576. [7, twoDimVertL3], // 0000010
  21577. [7, twoDimVertR3], // 0000011
  21578. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  21579. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  21580. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  21581. [4, twoDimPass], [4, twoDimPass],
  21582. [4, twoDimPass], [4, twoDimPass],
  21583. [4, twoDimPass], [4, twoDimPass],
  21584. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  21585. [3, twoDimHoriz], [3, twoDimHoriz],
  21586. [3, twoDimHoriz], [3, twoDimHoriz],
  21587. [3, twoDimHoriz], [3, twoDimHoriz],
  21588. [3, twoDimHoriz], [3, twoDimHoriz],
  21589. [3, twoDimHoriz], [3, twoDimHoriz],
  21590. [3, twoDimHoriz], [3, twoDimHoriz],
  21591. [3, twoDimHoriz], [3, twoDimHoriz],
  21592. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  21593. [3, twoDimVertL1], [3, twoDimVertL1],
  21594. [3, twoDimVertL1], [3, twoDimVertL1],
  21595. [3, twoDimVertL1], [3, twoDimVertL1],
  21596. [3, twoDimVertL1], [3, twoDimVertL1],
  21597. [3, twoDimVertL1], [3, twoDimVertL1],
  21598. [3, twoDimVertL1], [3, twoDimVertL1],
  21599. [3, twoDimVertL1], [3, twoDimVertL1],
  21600. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  21601. [3, twoDimVertR1], [3, twoDimVertR1],
  21602. [3, twoDimVertR1], [3, twoDimVertR1],
  21603. [3, twoDimVertR1], [3, twoDimVertR1],
  21604. [3, twoDimVertR1], [3, twoDimVertR1],
  21605. [3, twoDimVertR1], [3, twoDimVertR1],
  21606. [3, twoDimVertR1], [3, twoDimVertR1],
  21607. [3, twoDimVertR1], [3, twoDimVertR1],
  21608. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  21609. [1, twoDimVert0], [1, twoDimVert0],
  21610. [1, twoDimVert0], [1, twoDimVert0],
  21611. [1, twoDimVert0], [1, twoDimVert0],
  21612. [1, twoDimVert0], [1, twoDimVert0],
  21613. [1, twoDimVert0], [1, twoDimVert0],
  21614. [1, twoDimVert0], [1, twoDimVert0],
  21615. [1, twoDimVert0], [1, twoDimVert0],
  21616. [1, twoDimVert0], [1, twoDimVert0],
  21617. [1, twoDimVert0], [1, twoDimVert0],
  21618. [1, twoDimVert0], [1, twoDimVert0],
  21619. [1, twoDimVert0], [1, twoDimVert0],
  21620. [1, twoDimVert0], [1, twoDimVert0],
  21621. [1, twoDimVert0], [1, twoDimVert0],
  21622. [1, twoDimVert0], [1, twoDimVert0],
  21623. [1, twoDimVert0], [1, twoDimVert0],
  21624. [1, twoDimVert0], [1, twoDimVert0],
  21625. [1, twoDimVert0], [1, twoDimVert0],
  21626. [1, twoDimVert0], [1, twoDimVert0],
  21627. [1, twoDimVert0], [1, twoDimVert0],
  21628. [1, twoDimVert0], [1, twoDimVert0],
  21629. [1, twoDimVert0], [1, twoDimVert0],
  21630. [1, twoDimVert0], [1, twoDimVert0],
  21631. [1, twoDimVert0], [1, twoDimVert0],
  21632. [1, twoDimVert0], [1, twoDimVert0],
  21633. [1, twoDimVert0], [1, twoDimVert0],
  21634. [1, twoDimVert0], [1, twoDimVert0],
  21635. [1, twoDimVert0], [1, twoDimVert0],
  21636. [1, twoDimVert0], [1, twoDimVert0],
  21637. [1, twoDimVert0], [1, twoDimVert0],
  21638. [1, twoDimVert0], [1, twoDimVert0],
  21639. [1, twoDimVert0], [1, twoDimVert0]
  21640. ];
  21641. var whiteTable1 = [
  21642. [-1, -1], // 00000
  21643. [12, ccittEOL], // 00001
  21644. [-1, -1], [-1, -1], // 0001x
  21645. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  21646. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  21647. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  21648. [11, 1792], [11, 1792], // 1000x
  21649. [12, 1984], // 10010
  21650. [12, 2048], // 10011
  21651. [12, 2112], // 10100
  21652. [12, 2176], // 10101
  21653. [12, 2240], // 10110
  21654. [12, 2304], // 10111
  21655. [11, 1856], [11, 1856], // 1100x
  21656. [11, 1920], [11, 1920], // 1101x
  21657. [12, 2368], // 11100
  21658. [12, 2432], // 11101
  21659. [12, 2496], // 11110
  21660. [12, 2560] // 11111
  21661. ];
  21662. var whiteTable2 = [
  21663. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  21664. [8, 29], [8, 29], // 00000010x
  21665. [8, 30], [8, 30], // 00000011x
  21666. [8, 45], [8, 45], // 00000100x
  21667. [8, 46], [8, 46], // 00000101x
  21668. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  21669. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  21670. [8, 47], [8, 47], // 00001010x
  21671. [8, 48], [8, 48], // 00001011x
  21672. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  21673. [6, 13], [6, 13], [6, 13], [6, 13],
  21674. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  21675. [8, 33], [8, 33], // 00010010x
  21676. [8, 34], [8, 34], // 00010011x
  21677. [8, 35], [8, 35], // 00010100x
  21678. [8, 36], [8, 36], // 00010101x
  21679. [8, 37], [8, 37], // 00010110x
  21680. [8, 38], [8, 38], // 00010111x
  21681. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  21682. [8, 31], [8, 31], // 00011010x
  21683. [8, 32], [8, 32], // 00011011x
  21684. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  21685. [6, 1], [6, 1], [6, 1], [6, 1],
  21686. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  21687. [6, 12], [6, 12], [6, 12], [6, 12],
  21688. [8, 53], [8, 53], // 00100100x
  21689. [8, 54], [8, 54], // 00100101x
  21690. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  21691. [8, 39], [8, 39], // 00101000x
  21692. [8, 40], [8, 40], // 00101001x
  21693. [8, 41], [8, 41], // 00101010x
  21694. [8, 42], [8, 42], // 00101011x
  21695. [8, 43], [8, 43], // 00101100x
  21696. [8, 44], [8, 44], // 00101101x
  21697. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  21698. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  21699. [8, 61], [8, 61], // 00110010x
  21700. [8, 62], [8, 62], // 00110011x
  21701. [8, 63], [8, 63], // 00110100x
  21702. [8, 0], [8, 0], // 00110101x
  21703. [8, 320], [8, 320], // 00110110x
  21704. [8, 384], [8, 384], // 00110111x
  21705. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  21706. [5, 10], [5, 10], [5, 10], [5, 10],
  21707. [5, 10], [5, 10], [5, 10], [5, 10],
  21708. [5, 10], [5, 10], [5, 10], [5, 10],
  21709. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  21710. [5, 11], [5, 11], [5, 11], [5, 11],
  21711. [5, 11], [5, 11], [5, 11], [5, 11],
  21712. [5, 11], [5, 11], [5, 11], [5, 11],
  21713. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  21714. [8, 59], [8, 59], // 01001010x
  21715. [8, 60], [8, 60], // 01001011x
  21716. [9, 1472], // 010011000
  21717. [9, 1536], // 010011001
  21718. [9, 1600], // 010011010
  21719. [9, 1728], // 010011011
  21720. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  21721. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  21722. [8, 49], [8, 49], // 01010010x
  21723. [8, 50], [8, 50], // 01010011x
  21724. [8, 51], [8, 51], // 01010100x
  21725. [8, 52], [8, 52], // 01010101x
  21726. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  21727. [8, 55], [8, 55], // 01011000x
  21728. [8, 56], [8, 56], // 01011001x
  21729. [8, 57], [8, 57], // 01011010x
  21730. [8, 58], [8, 58], // 01011011x
  21731. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  21732. [6, 192], [6, 192], [6, 192], [6, 192],
  21733. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  21734. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  21735. [8, 448], [8, 448], // 01100100x
  21736. [8, 512], [8, 512], // 01100101x
  21737. [9, 704], // 011001100
  21738. [9, 768], // 011001101
  21739. [8, 640], [8, 640], // 01100111x
  21740. [8, 576], [8, 576], // 01101000x
  21741. [9, 832], // 011010010
  21742. [9, 896], // 011010011
  21743. [9, 960], // 011010100
  21744. [9, 1024], // 011010101
  21745. [9, 1088], // 011010110
  21746. [9, 1152], // 011010111
  21747. [9, 1216], // 011011000
  21748. [9, 1280], // 011011001
  21749. [9, 1344], // 011011010
  21750. [9, 1408], // 011011011
  21751. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  21752. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  21753. [4, 2], [4, 2], [4, 2], [4, 2],
  21754. [4, 2], [4, 2], [4, 2], [4, 2],
  21755. [4, 2], [4, 2], [4, 2], [4, 2],
  21756. [4, 2], [4, 2], [4, 2], [4, 2],
  21757. [4, 2], [4, 2], [4, 2], [4, 2],
  21758. [4, 2], [4, 2], [4, 2], [4, 2],
  21759. [4, 2], [4, 2], [4, 2], [4, 2],
  21760. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  21761. [4, 3], [4, 3], [4, 3], [4, 3],
  21762. [4, 3], [4, 3], [4, 3], [4, 3],
  21763. [4, 3], [4, 3], [4, 3], [4, 3],
  21764. [4, 3], [4, 3], [4, 3], [4, 3],
  21765. [4, 3], [4, 3], [4, 3], [4, 3],
  21766. [4, 3], [4, 3], [4, 3], [4, 3],
  21767. [4, 3], [4, 3], [4, 3], [4, 3],
  21768. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  21769. [5, 128], [5, 128], [5, 128], [5, 128],
  21770. [5, 128], [5, 128], [5, 128], [5, 128],
  21771. [5, 128], [5, 128], [5, 128], [5, 128],
  21772. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  21773. [5, 8], [5, 8], [5, 8], [5, 8],
  21774. [5, 8], [5, 8], [5, 8], [5, 8],
  21775. [5, 8], [5, 8], [5, 8], [5, 8],
  21776. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  21777. [5, 9], [5, 9], [5, 9], [5, 9],
  21778. [5, 9], [5, 9], [5, 9], [5, 9],
  21779. [5, 9], [5, 9], [5, 9], [5, 9],
  21780. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  21781. [6, 16], [6, 16], [6, 16], [6, 16],
  21782. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  21783. [6, 17], [6, 17], [6, 17], [6, 17],
  21784. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  21785. [4, 4], [4, 4], [4, 4], [4, 4],
  21786. [4, 4], [4, 4], [4, 4], [4, 4],
  21787. [4, 4], [4, 4], [4, 4], [4, 4],
  21788. [4, 4], [4, 4], [4, 4], [4, 4],
  21789. [4, 4], [4, 4], [4, 4], [4, 4],
  21790. [4, 4], [4, 4], [4, 4], [4, 4],
  21791. [4, 4], [4, 4], [4, 4], [4, 4],
  21792. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  21793. [4, 5], [4, 5], [4, 5], [4, 5],
  21794. [4, 5], [4, 5], [4, 5], [4, 5],
  21795. [4, 5], [4, 5], [4, 5], [4, 5],
  21796. [4, 5], [4, 5], [4, 5], [4, 5],
  21797. [4, 5], [4, 5], [4, 5], [4, 5],
  21798. [4, 5], [4, 5], [4, 5], [4, 5],
  21799. [4, 5], [4, 5], [4, 5], [4, 5],
  21800. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  21801. [6, 14], [6, 14], [6, 14], [6, 14],
  21802. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  21803. [6, 15], [6, 15], [6, 15], [6, 15],
  21804. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  21805. [5, 64], [5, 64], [5, 64], [5, 64],
  21806. [5, 64], [5, 64], [5, 64], [5, 64],
  21807. [5, 64], [5, 64], [5, 64], [5, 64],
  21808. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  21809. [4, 6], [4, 6], [4, 6], [4, 6],
  21810. [4, 6], [4, 6], [4, 6], [4, 6],
  21811. [4, 6], [4, 6], [4, 6], [4, 6],
  21812. [4, 6], [4, 6], [4, 6], [4, 6],
  21813. [4, 6], [4, 6], [4, 6], [4, 6],
  21814. [4, 6], [4, 6], [4, 6], [4, 6],
  21815. [4, 6], [4, 6], [4, 6], [4, 6],
  21816. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  21817. [4, 7], [4, 7], [4, 7], [4, 7],
  21818. [4, 7], [4, 7], [4, 7], [4, 7],
  21819. [4, 7], [4, 7], [4, 7], [4, 7],
  21820. [4, 7], [4, 7], [4, 7], [4, 7],
  21821. [4, 7], [4, 7], [4, 7], [4, 7],
  21822. [4, 7], [4, 7], [4, 7], [4, 7],
  21823. [4, 7], [4, 7], [4, 7], [4, 7]
  21824. ];
  21825. var blackTable1 = [
  21826. [-1, -1], [-1, -1], // 000000000000x
  21827. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  21828. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  21829. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  21830. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  21831. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  21832. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  21833. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  21834. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  21835. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  21836. [12, 1984], [12, 1984], // 000000010010x
  21837. [12, 2048], [12, 2048], // 000000010011x
  21838. [12, 2112], [12, 2112], // 000000010100x
  21839. [12, 2176], [12, 2176], // 000000010101x
  21840. [12, 2240], [12, 2240], // 000000010110x
  21841. [12, 2304], [12, 2304], // 000000010111x
  21842. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  21843. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  21844. [12, 2368], [12, 2368], // 000000011100x
  21845. [12, 2432], [12, 2432], // 000000011101x
  21846. [12, 2496], [12, 2496], // 000000011110x
  21847. [12, 2560], [12, 2560], // 000000011111x
  21848. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  21849. [10, 18], [10, 18], [10, 18], [10, 18],
  21850. [12, 52], [12, 52], // 000000100100x
  21851. [13, 640], // 0000001001010
  21852. [13, 704], // 0000001001011
  21853. [13, 768], // 0000001001100
  21854. [13, 832], // 0000001001101
  21855. [12, 55], [12, 55], // 000000100111x
  21856. [12, 56], [12, 56], // 000000101000x
  21857. [13, 1280], // 0000001010010
  21858. [13, 1344], // 0000001010011
  21859. [13, 1408], // 0000001010100
  21860. [13, 1472], // 0000001010101
  21861. [12, 59], [12, 59], // 000000101011x
  21862. [12, 60], [12, 60], // 000000101100x
  21863. [13, 1536], // 0000001011010
  21864. [13, 1600], // 0000001011011
  21865. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  21866. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  21867. [13, 1664], // 0000001100100
  21868. [13, 1728], // 0000001100101
  21869. [12, 320], [12, 320], // 000000110011x
  21870. [12, 384], [12, 384], // 000000110100x
  21871. [12, 448], [12, 448], // 000000110101x
  21872. [13, 512], // 0000001101100
  21873. [13, 576], // 0000001101101
  21874. [12, 53], [12, 53], // 000000110111x
  21875. [12, 54], [12, 54], // 000000111000x
  21876. [13, 896], // 0000001110010
  21877. [13, 960], // 0000001110011
  21878. [13, 1024], // 0000001110100
  21879. [13, 1088], // 0000001110101
  21880. [13, 1152], // 0000001110110
  21881. [13, 1216], // 0000001110111
  21882. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  21883. [10, 64], [10, 64], [10, 64], [10, 64]
  21884. ];
  21885. var blackTable2 = [
  21886. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  21887. [8, 13], [8, 13], [8, 13], [8, 13],
  21888. [8, 13], [8, 13], [8, 13], [8, 13],
  21889. [8, 13], [8, 13], [8, 13], [8, 13],
  21890. [11, 23], [11, 23], // 00000101000x
  21891. [12, 50], // 000001010010
  21892. [12, 51], // 000001010011
  21893. [12, 44], // 000001010100
  21894. [12, 45], // 000001010101
  21895. [12, 46], // 000001010110
  21896. [12, 47], // 000001010111
  21897. [12, 57], // 000001011000
  21898. [12, 58], // 000001011001
  21899. [12, 61], // 000001011010
  21900. [12, 256], // 000001011011
  21901. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  21902. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  21903. [12, 48], // 000001100100
  21904. [12, 49], // 000001100101
  21905. [12, 62], // 000001100110
  21906. [12, 63], // 000001100111
  21907. [12, 30], // 000001101000
  21908. [12, 31], // 000001101001
  21909. [12, 32], // 000001101010
  21910. [12, 33], // 000001101011
  21911. [12, 40], // 000001101100
  21912. [12, 41], // 000001101101
  21913. [11, 22], [11, 22], // 00000110111x
  21914. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  21915. [8, 14], [8, 14], [8, 14], [8, 14],
  21916. [8, 14], [8, 14], [8, 14], [8, 14],
  21917. [8, 14], [8, 14], [8, 14], [8, 14],
  21918. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  21919. [7, 10], [7, 10], [7, 10], [7, 10],
  21920. [7, 10], [7, 10], [7, 10], [7, 10],
  21921. [7, 10], [7, 10], [7, 10], [7, 10],
  21922. [7, 10], [7, 10], [7, 10], [7, 10],
  21923. [7, 10], [7, 10], [7, 10], [7, 10],
  21924. [7, 10], [7, 10], [7, 10], [7, 10],
  21925. [7, 10], [7, 10], [7, 10], [7, 10],
  21926. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  21927. [7, 11], [7, 11], [7, 11], [7, 11],
  21928. [7, 11], [7, 11], [7, 11], [7, 11],
  21929. [7, 11], [7, 11], [7, 11], [7, 11],
  21930. [7, 11], [7, 11], [7, 11], [7, 11],
  21931. [7, 11], [7, 11], [7, 11], [7, 11],
  21932. [7, 11], [7, 11], [7, 11], [7, 11],
  21933. [7, 11], [7, 11], [7, 11], [7, 11],
  21934. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  21935. [9, 15], [9, 15], [9, 15], [9, 15],
  21936. [12, 128], // 000011001000
  21937. [12, 192], // 000011001001
  21938. [12, 26], // 000011001010
  21939. [12, 27], // 000011001011
  21940. [12, 28], // 000011001100
  21941. [12, 29], // 000011001101
  21942. [11, 19], [11, 19], // 00001100111x
  21943. [11, 20], [11, 20], // 00001101000x
  21944. [12, 34], // 000011010010
  21945. [12, 35], // 000011010011
  21946. [12, 36], // 000011010100
  21947. [12, 37], // 000011010101
  21948. [12, 38], // 000011010110
  21949. [12, 39], // 000011010111
  21950. [11, 21], [11, 21], // 00001101100x
  21951. [12, 42], // 000011011010
  21952. [12, 43], // 000011011011
  21953. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  21954. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  21955. [7, 12], [7, 12], [7, 12], [7, 12],
  21956. [7, 12], [7, 12], [7, 12], [7, 12],
  21957. [7, 12], [7, 12], [7, 12], [7, 12],
  21958. [7, 12], [7, 12], [7, 12], [7, 12],
  21959. [7, 12], [7, 12], [7, 12], [7, 12],
  21960. [7, 12], [7, 12], [7, 12], [7, 12],
  21961. [7, 12], [7, 12], [7, 12], [7, 12]
  21962. ];
  21963. var blackTable3 = [
  21964. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  21965. [6, 9], // 000100
  21966. [6, 8], // 000101
  21967. [5, 7], [5, 7], // 00011x
  21968. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  21969. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  21970. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  21971. [3, 1], [3, 1], [3, 1], [3, 1],
  21972. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  21973. [3, 4], [3, 4], [3, 4], [3, 4],
  21974. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  21975. [2, 3], [2, 3], [2, 3], [2, 3],
  21976. [2, 3], [2, 3], [2, 3], [2, 3],
  21977. [2, 3], [2, 3], [2, 3], [2, 3],
  21978. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  21979. [2, 2], [2, 2], [2, 2], [2, 2],
  21980. [2, 2], [2, 2], [2, 2], [2, 2],
  21981. [2, 2], [2, 2], [2, 2], [2, 2]
  21982. ];
  21983. function CCITTFaxStream(str, maybeLength, params) {
  21984. this.str = str;
  21985. this.dict = str.dict;
  21986. params = params || Dict.empty;
  21987. this.encoding = params.get('K') || 0;
  21988. this.eoline = params.get('EndOfLine') || false;
  21989. this.byteAlign = params.get('EncodedByteAlign') || false;
  21990. this.columns = params.get('Columns') || 1728;
  21991. this.rows = params.get('Rows') || 0;
  21992. var eoblock = params.get('EndOfBlock');
  21993. if (eoblock === null || eoblock === undefined) {
  21994. eoblock = true;
  21995. }
  21996. this.eoblock = eoblock;
  21997. this.black = params.get('BlackIs1') || false;
  21998. this.codingLine = new Uint32Array(this.columns + 1);
  21999. this.refLine = new Uint32Array(this.columns + 2);
  22000. this.codingLine[0] = this.columns;
  22001. this.codingPos = 0;
  22002. this.row = 0;
  22003. this.nextLine2D = this.encoding < 0;
  22004. this.inputBits = 0;
  22005. this.inputBuf = 0;
  22006. this.outputBits = 0;
  22007. var code1;
  22008. while ((code1 = this.lookBits(12)) === 0) {
  22009. this.eatBits(1);
  22010. }
  22011. if (code1 === 1) {
  22012. this.eatBits(12);
  22013. }
  22014. if (this.encoding > 0) {
  22015. this.nextLine2D = !this.lookBits(1);
  22016. this.eatBits(1);
  22017. }
  22018. DecodeStream.call(this, maybeLength);
  22019. }
  22020. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  22021. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  22022. while (!this.eof) {
  22023. var c = this.lookChar();
  22024. this.ensureBuffer(this.bufferLength + 1);
  22025. this.buffer[this.bufferLength++] = c;
  22026. }
  22027. };
  22028. CCITTFaxStream.prototype.addPixels =
  22029. function ccittFaxStreamAddPixels(a1, blackPixels) {
  22030. var codingLine = this.codingLine;
  22031. var codingPos = this.codingPos;
  22032. if (a1 > codingLine[codingPos]) {
  22033. if (a1 > this.columns) {
  22034. info('row is wrong length');
  22035. this.err = true;
  22036. a1 = this.columns;
  22037. }
  22038. if ((codingPos & 1) ^ blackPixels) {
  22039. ++codingPos;
  22040. }
  22041. codingLine[codingPos] = a1;
  22042. }
  22043. this.codingPos = codingPos;
  22044. };
  22045. CCITTFaxStream.prototype.addPixelsNeg =
  22046. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  22047. var codingLine = this.codingLine;
  22048. var codingPos = this.codingPos;
  22049. if (a1 > codingLine[codingPos]) {
  22050. if (a1 > this.columns) {
  22051. info('row is wrong length');
  22052. this.err = true;
  22053. a1 = this.columns;
  22054. }
  22055. if ((codingPos & 1) ^ blackPixels) {
  22056. ++codingPos;
  22057. }
  22058. codingLine[codingPos] = a1;
  22059. } else if (a1 < codingLine[codingPos]) {
  22060. if (a1 < 0) {
  22061. info('invalid code');
  22062. this.err = true;
  22063. a1 = 0;
  22064. }
  22065. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  22066. --codingPos;
  22067. }
  22068. codingLine[codingPos] = a1;
  22069. }
  22070. this.codingPos = codingPos;
  22071. };
  22072. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  22073. var refLine = this.refLine;
  22074. var codingLine = this.codingLine;
  22075. var columns = this.columns;
  22076. var refPos, blackPixels, bits, i;
  22077. if (this.outputBits === 0) {
  22078. if (this.eof) {
  22079. return null;
  22080. }
  22081. this.err = false;
  22082. var code1, code2, code3;
  22083. if (this.nextLine2D) {
  22084. for (i = 0; codingLine[i] < columns; ++i) {
  22085. refLine[i] = codingLine[i];
  22086. }
  22087. refLine[i++] = columns;
  22088. refLine[i] = columns;
  22089. codingLine[0] = 0;
  22090. this.codingPos = 0;
  22091. refPos = 0;
  22092. blackPixels = 0;
  22093. while (codingLine[this.codingPos] < columns) {
  22094. code1 = this.getTwoDimCode();
  22095. switch (code1) {
  22096. case twoDimPass:
  22097. this.addPixels(refLine[refPos + 1], blackPixels);
  22098. if (refLine[refPos + 1] < columns) {
  22099. refPos += 2;
  22100. }
  22101. break;
  22102. case twoDimHoriz:
  22103. code1 = code2 = 0;
  22104. if (blackPixels) {
  22105. do {
  22106. code1 += (code3 = this.getBlackCode());
  22107. } while (code3 >= 64);
  22108. do {
  22109. code2 += (code3 = this.getWhiteCode());
  22110. } while (code3 >= 64);
  22111. } else {
  22112. do {
  22113. code1 += (code3 = this.getWhiteCode());
  22114. } while (code3 >= 64);
  22115. do {
  22116. code2 += (code3 = this.getBlackCode());
  22117. } while (code3 >= 64);
  22118. }
  22119. this.addPixels(codingLine[this.codingPos] +
  22120. code1, blackPixels);
  22121. if (codingLine[this.codingPos] < columns) {
  22122. this.addPixels(codingLine[this.codingPos] + code2,
  22123. blackPixels ^ 1);
  22124. }
  22125. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22126. refLine[refPos] < columns) {
  22127. refPos += 2;
  22128. }
  22129. break;
  22130. case twoDimVertR3:
  22131. this.addPixels(refLine[refPos] + 3, blackPixels);
  22132. blackPixels ^= 1;
  22133. if (codingLine[this.codingPos] < columns) {
  22134. ++refPos;
  22135. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22136. refLine[refPos] < columns) {
  22137. refPos += 2;
  22138. }
  22139. }
  22140. break;
  22141. case twoDimVertR2:
  22142. this.addPixels(refLine[refPos] + 2, blackPixels);
  22143. blackPixels ^= 1;
  22144. if (codingLine[this.codingPos] < columns) {
  22145. ++refPos;
  22146. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22147. refLine[refPos] < columns) {
  22148. refPos += 2;
  22149. }
  22150. }
  22151. break;
  22152. case twoDimVertR1:
  22153. this.addPixels(refLine[refPos] + 1, blackPixels);
  22154. blackPixels ^= 1;
  22155. if (codingLine[this.codingPos] < columns) {
  22156. ++refPos;
  22157. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22158. refLine[refPos] < columns) {
  22159. refPos += 2;
  22160. }
  22161. }
  22162. break;
  22163. case twoDimVert0:
  22164. this.addPixels(refLine[refPos], blackPixels);
  22165. blackPixels ^= 1;
  22166. if (codingLine[this.codingPos] < columns) {
  22167. ++refPos;
  22168. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22169. refLine[refPos] < columns) {
  22170. refPos += 2;
  22171. }
  22172. }
  22173. break;
  22174. case twoDimVertL3:
  22175. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  22176. blackPixels ^= 1;
  22177. if (codingLine[this.codingPos] < columns) {
  22178. if (refPos > 0) {
  22179. --refPos;
  22180. } else {
  22181. ++refPos;
  22182. }
  22183. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22184. refLine[refPos] < columns) {
  22185. refPos += 2;
  22186. }
  22187. }
  22188. break;
  22189. case twoDimVertL2:
  22190. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  22191. blackPixels ^= 1;
  22192. if (codingLine[this.codingPos] < columns) {
  22193. if (refPos > 0) {
  22194. --refPos;
  22195. } else {
  22196. ++refPos;
  22197. }
  22198. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22199. refLine[refPos] < columns) {
  22200. refPos += 2;
  22201. }
  22202. }
  22203. break;
  22204. case twoDimVertL1:
  22205. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  22206. blackPixels ^= 1;
  22207. if (codingLine[this.codingPos] < columns) {
  22208. if (refPos > 0) {
  22209. --refPos;
  22210. } else {
  22211. ++refPos;
  22212. }
  22213. while (refLine[refPos] <= codingLine[this.codingPos] &&
  22214. refLine[refPos] < columns) {
  22215. refPos += 2;
  22216. }
  22217. }
  22218. break;
  22219. case EOF:
  22220. this.addPixels(columns, 0);
  22221. this.eof = true;
  22222. break;
  22223. default:
  22224. info('bad 2d code');
  22225. this.addPixels(columns, 0);
  22226. this.err = true;
  22227. }
  22228. }
  22229. } else {
  22230. codingLine[0] = 0;
  22231. this.codingPos = 0;
  22232. blackPixels = 0;
  22233. while (codingLine[this.codingPos] < columns) {
  22234. code1 = 0;
  22235. if (blackPixels) {
  22236. do {
  22237. code1 += (code3 = this.getBlackCode());
  22238. } while (code3 >= 64);
  22239. } else {
  22240. do {
  22241. code1 += (code3 = this.getWhiteCode());
  22242. } while (code3 >= 64);
  22243. }
  22244. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  22245. blackPixels ^= 1;
  22246. }
  22247. }
  22248. var gotEOL = false;
  22249. if (this.byteAlign) {
  22250. this.inputBits &= ~7;
  22251. }
  22252. if (!this.eoblock && this.row === this.rows - 1) {
  22253. this.eof = true;
  22254. } else {
  22255. code1 = this.lookBits(12);
  22256. if (this.eoline) {
  22257. while (code1 !== EOF && code1 !== 1) {
  22258. this.eatBits(1);
  22259. code1 = this.lookBits(12);
  22260. }
  22261. } else {
  22262. while (code1 === 0) {
  22263. this.eatBits(1);
  22264. code1 = this.lookBits(12);
  22265. }
  22266. }
  22267. if (code1 === 1) {
  22268. this.eatBits(12);
  22269. gotEOL = true;
  22270. } else if (code1 === EOF) {
  22271. this.eof = true;
  22272. }
  22273. }
  22274. if (!this.eof && this.encoding > 0) {
  22275. this.nextLine2D = !this.lookBits(1);
  22276. this.eatBits(1);
  22277. }
  22278. if (this.eoblock && gotEOL && this.byteAlign) {
  22279. code1 = this.lookBits(12);
  22280. if (code1 === 1) {
  22281. this.eatBits(12);
  22282. if (this.encoding > 0) {
  22283. this.lookBits(1);
  22284. this.eatBits(1);
  22285. }
  22286. if (this.encoding >= 0) {
  22287. for (i = 0; i < 4; ++i) {
  22288. code1 = this.lookBits(12);
  22289. if (code1 !== 1) {
  22290. info('bad rtc code: ' + code1);
  22291. }
  22292. this.eatBits(12);
  22293. if (this.encoding > 0) {
  22294. this.lookBits(1);
  22295. this.eatBits(1);
  22296. }
  22297. }
  22298. }
  22299. this.eof = true;
  22300. }
  22301. } else if (this.err && this.eoline) {
  22302. while (true) {
  22303. code1 = this.lookBits(13);
  22304. if (code1 === EOF) {
  22305. this.eof = true;
  22306. return null;
  22307. }
  22308. if ((code1 >> 1) === 1) {
  22309. break;
  22310. }
  22311. this.eatBits(1);
  22312. }
  22313. this.eatBits(12);
  22314. if (this.encoding > 0) {
  22315. this.eatBits(1);
  22316. this.nextLine2D = !(code1 & 1);
  22317. }
  22318. }
  22319. if (codingLine[0] > 0) {
  22320. this.outputBits = codingLine[this.codingPos = 0];
  22321. } else {
  22322. this.outputBits = codingLine[this.codingPos = 1];
  22323. }
  22324. this.row++;
  22325. }
  22326. var c;
  22327. if (this.outputBits >= 8) {
  22328. c = (this.codingPos & 1) ? 0 : 0xFF;
  22329. this.outputBits -= 8;
  22330. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  22331. this.codingPos++;
  22332. this.outputBits = (codingLine[this.codingPos] -
  22333. codingLine[this.codingPos - 1]);
  22334. }
  22335. } else {
  22336. bits = 8;
  22337. c = 0;
  22338. do {
  22339. if (this.outputBits > bits) {
  22340. c <<= bits;
  22341. if (!(this.codingPos & 1)) {
  22342. c |= 0xFF >> (8 - bits);
  22343. }
  22344. this.outputBits -= bits;
  22345. bits = 0;
  22346. } else {
  22347. c <<= this.outputBits;
  22348. if (!(this.codingPos & 1)) {
  22349. c |= 0xFF >> (8 - this.outputBits);
  22350. }
  22351. bits -= this.outputBits;
  22352. this.outputBits = 0;
  22353. if (codingLine[this.codingPos] < columns) {
  22354. this.codingPos++;
  22355. this.outputBits = (codingLine[this.codingPos] -
  22356. codingLine[this.codingPos - 1]);
  22357. } else if (bits > 0) {
  22358. c <<= bits;
  22359. bits = 0;
  22360. }
  22361. }
  22362. } while (bits);
  22363. }
  22364. if (this.black) {
  22365. c ^= 0xFF;
  22366. }
  22367. return c;
  22368. };
  22369. // This functions returns the code found from the table.
  22370. // The start and end parameters set the boundaries for searching the table.
  22371. // The limit parameter is optional. Function returns an array with three
  22372. // values. The first array element indicates whether a valid code is being
  22373. // returned. The second array element is the actual code. The third array
  22374. // element indicates whether EOF was reached.
  22375. CCITTFaxStream.prototype.findTableCode =
  22376. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  22377. var limitValue = limit || 0;
  22378. for (var i = start; i <= end; ++i) {
  22379. var code = this.lookBits(i);
  22380. if (code === EOF) {
  22381. return [true, 1, false];
  22382. }
  22383. if (i < end) {
  22384. code <<= end - i;
  22385. }
  22386. if (!limitValue || code >= limitValue) {
  22387. var p = table[code - limitValue];
  22388. if (p[0] === i) {
  22389. this.eatBits(i);
  22390. return [true, p[1], true];
  22391. }
  22392. }
  22393. }
  22394. return [false, 0, false];
  22395. };
  22396. CCITTFaxStream.prototype.getTwoDimCode =
  22397. function ccittFaxStreamGetTwoDimCode() {
  22398. var code = 0;
  22399. var p;
  22400. if (this.eoblock) {
  22401. code = this.lookBits(7);
  22402. p = twoDimTable[code];
  22403. if (p && p[0] > 0) {
  22404. this.eatBits(p[0]);
  22405. return p[1];
  22406. }
  22407. } else {
  22408. var result = this.findTableCode(1, 7, twoDimTable);
  22409. if (result[0] && result[2]) {
  22410. return result[1];
  22411. }
  22412. }
  22413. info('Bad two dim code');
  22414. return EOF;
  22415. };
  22416. CCITTFaxStream.prototype.getWhiteCode =
  22417. function ccittFaxStreamGetWhiteCode() {
  22418. var code = 0;
  22419. var p;
  22420. if (this.eoblock) {
  22421. code = this.lookBits(12);
  22422. if (code === EOF) {
  22423. return 1;
  22424. }
  22425. if ((code >> 5) === 0) {
  22426. p = whiteTable1[code];
  22427. } else {
  22428. p = whiteTable2[code >> 3];
  22429. }
  22430. if (p[0] > 0) {
  22431. this.eatBits(p[0]);
  22432. return p[1];
  22433. }
  22434. } else {
  22435. var result = this.findTableCode(1, 9, whiteTable2);
  22436. if (result[0]) {
  22437. return result[1];
  22438. }
  22439. result = this.findTableCode(11, 12, whiteTable1);
  22440. if (result[0]) {
  22441. return result[1];
  22442. }
  22443. }
  22444. info('bad white code');
  22445. this.eatBits(1);
  22446. return 1;
  22447. };
  22448. CCITTFaxStream.prototype.getBlackCode =
  22449. function ccittFaxStreamGetBlackCode() {
  22450. var code, p;
  22451. if (this.eoblock) {
  22452. code = this.lookBits(13);
  22453. if (code === EOF) {
  22454. return 1;
  22455. }
  22456. if ((code >> 7) === 0) {
  22457. p = blackTable1[code];
  22458. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  22459. p = blackTable2[(code >> 1) - 64];
  22460. } else {
  22461. p = blackTable3[code >> 7];
  22462. }
  22463. if (p[0] > 0) {
  22464. this.eatBits(p[0]);
  22465. return p[1];
  22466. }
  22467. } else {
  22468. var result = this.findTableCode(2, 6, blackTable3);
  22469. if (result[0]) {
  22470. return result[1];
  22471. }
  22472. result = this.findTableCode(7, 12, blackTable2, 64);
  22473. if (result[0]) {
  22474. return result[1];
  22475. }
  22476. result = this.findTableCode(10, 13, blackTable1);
  22477. if (result[0]) {
  22478. return result[1];
  22479. }
  22480. }
  22481. info('bad black code');
  22482. this.eatBits(1);
  22483. return 1;
  22484. };
  22485. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  22486. var c;
  22487. while (this.inputBits < n) {
  22488. if ((c = this.str.getByte()) === -1) {
  22489. if (this.inputBits === 0) {
  22490. return EOF;
  22491. }
  22492. return ((this.inputBuf << (n - this.inputBits)) &
  22493. (0xFFFF >> (16 - n)));
  22494. }
  22495. this.inputBuf = (this.inputBuf << 8) + c;
  22496. this.inputBits += 8;
  22497. }
  22498. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  22499. };
  22500. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  22501. if ((this.inputBits -= n) < 0) {
  22502. this.inputBits = 0;
  22503. }
  22504. };
  22505. return CCITTFaxStream;
  22506. })();
  22507. var LZWStream = (function LZWStreamClosure() {
  22508. function LZWStream(str, maybeLength, earlyChange) {
  22509. this.str = str;
  22510. this.dict = str.dict;
  22511. this.cachedData = 0;
  22512. this.bitsCached = 0;
  22513. var maxLzwDictionarySize = 4096;
  22514. var lzwState = {
  22515. earlyChange: earlyChange,
  22516. codeLength: 9,
  22517. nextCode: 258,
  22518. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  22519. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  22520. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  22521. currentSequence: new Uint8Array(maxLzwDictionarySize),
  22522. currentSequenceLength: 0
  22523. };
  22524. for (var i = 0; i < 256; ++i) {
  22525. lzwState.dictionaryValues[i] = i;
  22526. lzwState.dictionaryLengths[i] = 1;
  22527. }
  22528. this.lzwState = lzwState;
  22529. DecodeStream.call(this, maybeLength);
  22530. }
  22531. LZWStream.prototype = Object.create(DecodeStream.prototype);
  22532. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  22533. var bitsCached = this.bitsCached;
  22534. var cachedData = this.cachedData;
  22535. while (bitsCached < n) {
  22536. var c = this.str.getByte();
  22537. if (c === -1) {
  22538. this.eof = true;
  22539. return null;
  22540. }
  22541. cachedData = (cachedData << 8) | c;
  22542. bitsCached += 8;
  22543. }
  22544. this.bitsCached = (bitsCached -= n);
  22545. this.cachedData = cachedData;
  22546. this.lastCode = null;
  22547. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  22548. };
  22549. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  22550. var blockSize = 512;
  22551. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  22552. var i, j, q;
  22553. var lzwState = this.lzwState;
  22554. if (!lzwState) {
  22555. return; // eof was found
  22556. }
  22557. var earlyChange = lzwState.earlyChange;
  22558. var nextCode = lzwState.nextCode;
  22559. var dictionaryValues = lzwState.dictionaryValues;
  22560. var dictionaryLengths = lzwState.dictionaryLengths;
  22561. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  22562. var codeLength = lzwState.codeLength;
  22563. var prevCode = lzwState.prevCode;
  22564. var currentSequence = lzwState.currentSequence;
  22565. var currentSequenceLength = lzwState.currentSequenceLength;
  22566. var decodedLength = 0;
  22567. var currentBufferLength = this.bufferLength;
  22568. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22569. for (i = 0; i < blockSize; i++) {
  22570. var code = this.readBits(codeLength);
  22571. var hasPrev = currentSequenceLength > 0;
  22572. if (code < 256) {
  22573. currentSequence[0] = code;
  22574. currentSequenceLength = 1;
  22575. } else if (code >= 258) {
  22576. if (code < nextCode) {
  22577. currentSequenceLength = dictionaryLengths[code];
  22578. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  22579. currentSequence[j] = dictionaryValues[q];
  22580. q = dictionaryPrevCodes[q];
  22581. }
  22582. } else {
  22583. currentSequence[currentSequenceLength++] = currentSequence[0];
  22584. }
  22585. } else if (code === 256) {
  22586. codeLength = 9;
  22587. nextCode = 258;
  22588. currentSequenceLength = 0;
  22589. continue;
  22590. } else {
  22591. this.eof = true;
  22592. delete this.lzwState;
  22593. break;
  22594. }
  22595. if (hasPrev) {
  22596. dictionaryPrevCodes[nextCode] = prevCode;
  22597. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  22598. dictionaryValues[nextCode] = currentSequence[0];
  22599. nextCode++;
  22600. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  22601. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  22602. 0.6931471805599453 + 1, 12) | 0;
  22603. }
  22604. prevCode = code;
  22605. decodedLength += currentSequenceLength;
  22606. if (estimatedDecodedSize < decodedLength) {
  22607. do {
  22608. estimatedDecodedSize += decodedSizeDelta;
  22609. } while (estimatedDecodedSize < decodedLength);
  22610. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  22611. }
  22612. for (j = 0; j < currentSequenceLength; j++) {
  22613. buffer[currentBufferLength++] = currentSequence[j];
  22614. }
  22615. }
  22616. lzwState.nextCode = nextCode;
  22617. lzwState.codeLength = codeLength;
  22618. lzwState.prevCode = prevCode;
  22619. lzwState.currentSequenceLength = currentSequenceLength;
  22620. this.bufferLength = currentBufferLength;
  22621. };
  22622. return LZWStream;
  22623. })();
  22624. var NullStream = (function NullStreamClosure() {
  22625. function NullStream() {
  22626. Stream.call(this, new Uint8Array(0));
  22627. }
  22628. NullStream.prototype = Stream.prototype;
  22629. return NullStream;
  22630. })();
  22631. // TODO refactor to remove dependency on parser.js
  22632. function _setCoreParser(coreParser_) {
  22633. coreParser = coreParser_;
  22634. EOF = coreParser_.EOF;
  22635. Lexer = coreParser_.Lexer;
  22636. }
  22637. exports._setCoreParser = _setCoreParser;
  22638. // TODO refactor to remove dependency on colorspace.js
  22639. function _setCoreColorSpace(coreColorSpace_) {
  22640. coreColorSpace = coreColorSpace_;
  22641. ColorSpace = coreColorSpace_.ColorSpace;
  22642. }
  22643. exports._setCoreColorSpace = _setCoreColorSpace;
  22644. exports.Ascii85Stream = Ascii85Stream;
  22645. exports.AsciiHexStream = AsciiHexStream;
  22646. exports.CCITTFaxStream = CCITTFaxStream;
  22647. exports.DecryptStream = DecryptStream;
  22648. exports.DecodeStream = DecodeStream;
  22649. exports.FlateStream = FlateStream;
  22650. exports.Jbig2Stream = Jbig2Stream;
  22651. exports.JpegStream = JpegStream;
  22652. exports.JpxStream = JpxStream;
  22653. exports.NullStream = NullStream;
  22654. exports.PredictorStream = PredictorStream;
  22655. exports.RunLengthStream = RunLengthStream;
  22656. exports.Stream = Stream;
  22657. exports.StreamsSequenceStream = StreamsSequenceStream;
  22658. exports.StringStream = StringStream;
  22659. exports.LZWStream = LZWStream;
  22660. }));
  22661. (function (root, factory) {
  22662. {
  22663. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  22664. root.pdfjsDisplayWebGL);
  22665. }
  22666. }(this, function (exports, sharedUtil, displayWebGL) {
  22667. var Util = sharedUtil.Util;
  22668. var info = sharedUtil.info;
  22669. var isArray = sharedUtil.isArray;
  22670. var error = sharedUtil.error;
  22671. var WebGLUtils = displayWebGL.WebGLUtils;
  22672. var ShadingIRs = {};
  22673. ShadingIRs.RadialAxial = {
  22674. fromIR: function RadialAxial_fromIR(raw) {
  22675. var type = raw[1];
  22676. var colorStops = raw[2];
  22677. var p0 = raw[3];
  22678. var p1 = raw[4];
  22679. var r0 = raw[5];
  22680. var r1 = raw[6];
  22681. return {
  22682. type: 'Pattern',
  22683. getPattern: function RadialAxial_getPattern(ctx) {
  22684. var grad;
  22685. if (type === 'axial') {
  22686. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  22687. } else if (type === 'radial') {
  22688. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  22689. }
  22690. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  22691. var c = colorStops[i];
  22692. grad.addColorStop(c[0], c[1]);
  22693. }
  22694. return grad;
  22695. }
  22696. };
  22697. }
  22698. };
  22699. var createMeshCanvas = (function createMeshCanvasClosure() {
  22700. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  22701. // Very basic Gouraud-shaded triangle rasterization algorithm.
  22702. var coords = context.coords, colors = context.colors;
  22703. var bytes = data.data, rowSize = data.width * 4;
  22704. var tmp;
  22705. if (coords[p1 + 1] > coords[p2 + 1]) {
  22706. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  22707. }
  22708. if (coords[p2 + 1] > coords[p3 + 1]) {
  22709. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  22710. }
  22711. if (coords[p1 + 1] > coords[p2 + 1]) {
  22712. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  22713. }
  22714. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  22715. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  22716. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  22717. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  22718. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  22719. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  22720. if (y1 >= y3) {
  22721. return;
  22722. }
  22723. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  22724. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  22725. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  22726. var minY = Math.round(y1), maxY = Math.round(y3);
  22727. var xa, car, cag, cab;
  22728. var xb, cbr, cbg, cbb;
  22729. var k;
  22730. for (var y = minY; y <= maxY; y++) {
  22731. if (y < y2) {
  22732. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  22733. xa = x1 - (x1 - x2) * k;
  22734. car = c1r - (c1r - c2r) * k;
  22735. cag = c1g - (c1g - c2g) * k;
  22736. cab = c1b - (c1b - c2b) * k;
  22737. } else {
  22738. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  22739. xa = x2 - (x2 - x3) * k;
  22740. car = c2r - (c2r - c3r) * k;
  22741. cag = c2g - (c2g - c3g) * k;
  22742. cab = c2b - (c2b - c3b) * k;
  22743. }
  22744. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  22745. xb = x1 - (x1 - x3) * k;
  22746. cbr = c1r - (c1r - c3r) * k;
  22747. cbg = c1g - (c1g - c3g) * k;
  22748. cbb = c1b - (c1b - c3b) * k;
  22749. var x1_ = Math.round(Math.min(xa, xb));
  22750. var x2_ = Math.round(Math.max(xa, xb));
  22751. var j = rowSize * y + x1_ * 4;
  22752. for (var x = x1_; x <= x2_; x++) {
  22753. k = (xa - x) / (xa - xb);
  22754. k = k < 0 ? 0 : k > 1 ? 1 : k;
  22755. bytes[j++] = (car - (car - cbr) * k) | 0;
  22756. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  22757. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  22758. bytes[j++] = 255;
  22759. }
  22760. }
  22761. }
  22762. function drawFigure(data, figure, context) {
  22763. var ps = figure.coords;
  22764. var cs = figure.colors;
  22765. var i, ii;
  22766. switch (figure.type) {
  22767. case 'lattice':
  22768. var verticesPerRow = figure.verticesPerRow;
  22769. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  22770. var cols = verticesPerRow - 1;
  22771. for (i = 0; i < rows; i++) {
  22772. var q = i * verticesPerRow;
  22773. for (var j = 0; j < cols; j++, q++) {
  22774. drawTriangle(data, context,
  22775. ps[q], ps[q + 1], ps[q + verticesPerRow],
  22776. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  22777. drawTriangle(data, context,
  22778. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  22779. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  22780. }
  22781. }
  22782. break;
  22783. case 'triangles':
  22784. for (i = 0, ii = ps.length; i < ii; i += 3) {
  22785. drawTriangle(data, context,
  22786. ps[i], ps[i + 1], ps[i + 2],
  22787. cs[i], cs[i + 1], cs[i + 2]);
  22788. }
  22789. break;
  22790. default:
  22791. error('illigal figure');
  22792. break;
  22793. }
  22794. }
  22795. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  22796. backgroundColor, cachedCanvases) {
  22797. // we will increase scale on some weird factor to let antialiasing take
  22798. // care of "rough" edges
  22799. var EXPECTED_SCALE = 1.1;
  22800. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  22801. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  22802. var offsetX = Math.floor(bounds[0]);
  22803. var offsetY = Math.floor(bounds[1]);
  22804. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  22805. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  22806. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  22807. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  22808. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  22809. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  22810. var scaleX = boundsWidth / width;
  22811. var scaleY = boundsHeight / height;
  22812. var context = {
  22813. coords: coords,
  22814. colors: colors,
  22815. offsetX: -offsetX,
  22816. offsetY: -offsetY,
  22817. scaleX: 1 / scaleX,
  22818. scaleY: 1 / scaleY
  22819. };
  22820. var canvas, tmpCanvas, i, ii;
  22821. if (WebGLUtils.isEnabled) {
  22822. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  22823. figures, context);
  22824. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  22825. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  22826. tmpCanvas.context.drawImage(canvas, 0, 0);
  22827. canvas = tmpCanvas.canvas;
  22828. } else {
  22829. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  22830. var tmpCtx = tmpCanvas.context;
  22831. var data = tmpCtx.createImageData(width, height);
  22832. if (backgroundColor) {
  22833. var bytes = data.data;
  22834. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  22835. bytes[i] = backgroundColor[0];
  22836. bytes[i + 1] = backgroundColor[1];
  22837. bytes[i + 2] = backgroundColor[2];
  22838. bytes[i + 3] = 255;
  22839. }
  22840. }
  22841. for (i = 0; i < figures.length; i++) {
  22842. drawFigure(data, figures[i], context);
  22843. }
  22844. tmpCtx.putImageData(data, 0, 0);
  22845. canvas = tmpCanvas.canvas;
  22846. }
  22847. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  22848. scaleX: scaleX, scaleY: scaleY};
  22849. }
  22850. return createMeshCanvas;
  22851. })();
  22852. ShadingIRs.Mesh = {
  22853. fromIR: function Mesh_fromIR(raw) {
  22854. //var type = raw[1];
  22855. var coords = raw[2];
  22856. var colors = raw[3];
  22857. var figures = raw[4];
  22858. var bounds = raw[5];
  22859. var matrix = raw[6];
  22860. //var bbox = raw[7];
  22861. var background = raw[8];
  22862. return {
  22863. type: 'Pattern',
  22864. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  22865. var scale;
  22866. if (shadingFill) {
  22867. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  22868. } else {
  22869. // Obtain scale from matrix and current transformation matrix.
  22870. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  22871. if (matrix) {
  22872. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  22873. scale = [scale[0] * matrixScale[0],
  22874. scale[1] * matrixScale[1]];
  22875. }
  22876. }
  22877. // Rasterizing on the main thread since sending/queue large canvases
  22878. // might cause OOM.
  22879. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  22880. colors, figures, shadingFill ? null : background,
  22881. owner.cachedCanvases);
  22882. if (!shadingFill) {
  22883. ctx.setTransform.apply(ctx, owner.baseTransform);
  22884. if (matrix) {
  22885. ctx.transform.apply(ctx, matrix);
  22886. }
  22887. }
  22888. ctx.translate(temporaryPatternCanvas.offsetX,
  22889. temporaryPatternCanvas.offsetY);
  22890. ctx.scale(temporaryPatternCanvas.scaleX,
  22891. temporaryPatternCanvas.scaleY);
  22892. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  22893. }
  22894. };
  22895. }
  22896. };
  22897. ShadingIRs.Dummy = {
  22898. fromIR: function Dummy_fromIR() {
  22899. return {
  22900. type: 'Pattern',
  22901. getPattern: function Dummy_fromIR_getPattern() {
  22902. return 'hotpink';
  22903. }
  22904. };
  22905. }
  22906. };
  22907. function getShadingPatternFromIR(raw) {
  22908. var shadingIR = ShadingIRs[raw[0]];
  22909. if (!shadingIR) {
  22910. error('Unknown IR type: ' + raw[0]);
  22911. }
  22912. return shadingIR.fromIR(raw);
  22913. }
  22914. var TilingPattern = (function TilingPatternClosure() {
  22915. var PaintType = {
  22916. COLORED: 1,
  22917. UNCOLORED: 2
  22918. };
  22919. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  22920. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  22921. this.operatorList = IR[2];
  22922. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  22923. this.bbox = IR[4];
  22924. this.xstep = IR[5];
  22925. this.ystep = IR[6];
  22926. this.paintType = IR[7];
  22927. this.tilingType = IR[8];
  22928. this.color = color;
  22929. this.canvasGraphicsFactory = canvasGraphicsFactory;
  22930. this.baseTransform = baseTransform;
  22931. this.type = 'Pattern';
  22932. this.ctx = ctx;
  22933. }
  22934. TilingPattern.prototype = {
  22935. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  22936. var operatorList = this.operatorList;
  22937. var bbox = this.bbox;
  22938. var xstep = this.xstep;
  22939. var ystep = this.ystep;
  22940. var paintType = this.paintType;
  22941. var tilingType = this.tilingType;
  22942. var color = this.color;
  22943. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  22944. info('TilingType: ' + tilingType);
  22945. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  22946. var topLeft = [x0, y0];
  22947. // we want the canvas to be as large as the step size
  22948. var botRight = [x0 + xstep, y0 + ystep];
  22949. var width = botRight[0] - topLeft[0];
  22950. var height = botRight[1] - topLeft[1];
  22951. // Obtain scale from matrix and current transformation matrix.
  22952. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  22953. var curMatrixScale = Util.singularValueDecompose2dScale(
  22954. this.baseTransform);
  22955. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  22956. matrixScale[1] * curMatrixScale[1]];
  22957. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  22958. // Use width and height values that are as close as possible to the end
  22959. // result when the pattern is used. Too low value makes the pattern look
  22960. // blurry. Too large value makes it look too crispy.
  22961. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  22962. MAX_PATTERN_SIZE);
  22963. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  22964. MAX_PATTERN_SIZE);
  22965. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  22966. width, height, true);
  22967. var tmpCtx = tmpCanvas.context;
  22968. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  22969. graphics.groupLevel = owner.groupLevel;
  22970. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  22971. this.setScale(width, height, xstep, ystep);
  22972. this.transformToScale(graphics);
  22973. // transform coordinates to pattern space
  22974. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  22975. graphics.transform.apply(graphics, tmpTranslate);
  22976. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  22977. graphics.executeOperatorList(operatorList);
  22978. return tmpCanvas.canvas;
  22979. },
  22980. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  22981. this.scale = [width / xstep, height / ystep];
  22982. },
  22983. transformToScale: function TilingPattern_transformToScale(graphics) {
  22984. var scale = this.scale;
  22985. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  22986. graphics.transform.apply(graphics, tmpScale);
  22987. },
  22988. scaleToContext: function TilingPattern_scaleToContext() {
  22989. var scale = this.scale;
  22990. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  22991. },
  22992. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  22993. if (bbox && isArray(bbox) && bbox.length === 4) {
  22994. var bboxWidth = x1 - x0;
  22995. var bboxHeight = y1 - y0;
  22996. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  22997. graphics.clip();
  22998. graphics.endPath();
  22999. }
  23000. },
  23001. setFillAndStrokeStyleToContext:
  23002. function setFillAndStrokeStyleToContext(context, paintType, color) {
  23003. switch (paintType) {
  23004. case PaintType.COLORED:
  23005. var ctx = this.ctx;
  23006. context.fillStyle = ctx.fillStyle;
  23007. context.strokeStyle = ctx.strokeStyle;
  23008. break;
  23009. case PaintType.UNCOLORED:
  23010. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  23011. context.fillStyle = cssColor;
  23012. context.strokeStyle = cssColor;
  23013. break;
  23014. default:
  23015. error('Unsupported paint type: ' + paintType);
  23016. }
  23017. },
  23018. getPattern: function TilingPattern_getPattern(ctx, owner) {
  23019. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  23020. ctx = this.ctx;
  23021. ctx.setTransform.apply(ctx, this.baseTransform);
  23022. ctx.transform.apply(ctx, this.matrix);
  23023. this.scaleToContext();
  23024. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  23025. }
  23026. };
  23027. return TilingPattern;
  23028. })();
  23029. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  23030. exports.TilingPattern = TilingPattern;
  23031. }));
  23032. (function (root, factory) {
  23033. {
  23034. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  23035. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23036. }
  23037. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23038. var PasswordException = sharedUtil.PasswordException;
  23039. var PasswordResponses = sharedUtil.PasswordResponses;
  23040. var bytesToString = sharedUtil.bytesToString;
  23041. var error = sharedUtil.error;
  23042. var isInt = sharedUtil.isInt;
  23043. var stringToBytes = sharedUtil.stringToBytes;
  23044. var utf8StringToString = sharedUtil.utf8StringToString;
  23045. var warn = sharedUtil.warn;
  23046. var Name = corePrimitives.Name;
  23047. var isName = corePrimitives.isName;
  23048. var isDict = corePrimitives.isDict;
  23049. var DecryptStream = coreStream.DecryptStream;
  23050. var ARCFourCipher = (function ARCFourCipherClosure() {
  23051. function ARCFourCipher(key) {
  23052. this.a = 0;
  23053. this.b = 0;
  23054. var s = new Uint8Array(256);
  23055. var i, j = 0, tmp, keyLength = key.length;
  23056. for (i = 0; i < 256; ++i) {
  23057. s[i] = i;
  23058. }
  23059. for (i = 0; i < 256; ++i) {
  23060. tmp = s[i];
  23061. j = (j + tmp + key[i % keyLength]) & 0xFF;
  23062. s[i] = s[j];
  23063. s[j] = tmp;
  23064. }
  23065. this.s = s;
  23066. }
  23067. ARCFourCipher.prototype = {
  23068. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  23069. var i, n = data.length, tmp, tmp2;
  23070. var a = this.a, b = this.b, s = this.s;
  23071. var output = new Uint8Array(n);
  23072. for (i = 0; i < n; ++i) {
  23073. a = (a + 1) & 0xFF;
  23074. tmp = s[a];
  23075. b = (b + tmp) & 0xFF;
  23076. tmp2 = s[b];
  23077. s[a] = tmp2;
  23078. s[b] = tmp;
  23079. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  23080. }
  23081. this.a = a;
  23082. this.b = b;
  23083. return output;
  23084. }
  23085. };
  23086. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  23087. return ARCFourCipher;
  23088. })();
  23089. var calculateMD5 = (function calculateMD5Closure() {
  23090. var r = new Uint8Array([
  23091. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23092. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23093. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23094. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23095. var k = new Int32Array([
  23096. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23097. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23098. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23099. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23100. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23101. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23102. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23103. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23104. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23105. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23106. -145523070, -1120210379, 718787259, -343485551]);
  23107. function hash(data, offset, length) {
  23108. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23109. // pre-processing
  23110. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23111. var padded = new Uint8Array(paddedLength);
  23112. var i, j, n;
  23113. for (i = 0; i < length; ++i) {
  23114. padded[i] = data[offset++];
  23115. }
  23116. padded[i++] = 0x80;
  23117. n = paddedLength - 8;
  23118. while (i < n) {
  23119. padded[i++] = 0;
  23120. }
  23121. padded[i++] = (length << 3) & 0xFF;
  23122. padded[i++] = (length >> 5) & 0xFF;
  23123. padded[i++] = (length >> 13) & 0xFF;
  23124. padded[i++] = (length >> 21) & 0xFF;
  23125. padded[i++] = (length >>> 29) & 0xFF;
  23126. padded[i++] = 0;
  23127. padded[i++] = 0;
  23128. padded[i++] = 0;
  23129. var w = new Int32Array(16);
  23130. for (i = 0; i < paddedLength;) {
  23131. for (j = 0; j < 16; ++j, i += 4) {
  23132. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23133. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23134. }
  23135. var a = h0, b = h1, c = h2, d = h3, f, g;
  23136. for (j = 0; j < 64; ++j) {
  23137. if (j < 16) {
  23138. f = (b & c) | ((~b) & d);
  23139. g = j;
  23140. } else if (j < 32) {
  23141. f = (d & b) | ((~d) & c);
  23142. g = (5 * j + 1) & 15;
  23143. } else if (j < 48) {
  23144. f = b ^ c ^ d;
  23145. g = (3 * j + 5) & 15;
  23146. } else {
  23147. f = c ^ (b | (~d));
  23148. g = (7 * j) & 15;
  23149. }
  23150. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23151. d = c;
  23152. c = b;
  23153. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23154. a = tmp;
  23155. }
  23156. h0 = (h0 + a) | 0;
  23157. h1 = (h1 + b) | 0;
  23158. h2 = (h2 + c) | 0;
  23159. h3 = (h3 + d) | 0;
  23160. }
  23161. return new Uint8Array([
  23162. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23163. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23164. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23165. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23166. ]);
  23167. }
  23168. return hash;
  23169. })();
  23170. var Word64 = (function Word64Closure() {
  23171. function Word64(highInteger, lowInteger) {
  23172. this.high = highInteger | 0;
  23173. this.low = lowInteger | 0;
  23174. }
  23175. Word64.prototype = {
  23176. and: function Word64_and(word) {
  23177. this.high &= word.high;
  23178. this.low &= word.low;
  23179. },
  23180. xor: function Word64_xor(word) {
  23181. this.high ^= word.high;
  23182. this.low ^= word.low;
  23183. },
  23184. or: function Word64_or(word) {
  23185. this.high |= word.high;
  23186. this.low |= word.low;
  23187. },
  23188. shiftRight: function Word64_shiftRight(places) {
  23189. if (places >= 32) {
  23190. this.low = (this.high >>> (places - 32)) | 0;
  23191. this.high = 0;
  23192. } else {
  23193. this.low = (this.low >>> places) | (this.high << (32 - places));
  23194. this.high = (this.high >>> places) | 0;
  23195. }
  23196. },
  23197. shiftLeft: function Word64_shiftLeft(places) {
  23198. if (places >= 32) {
  23199. this.high = this.low << (places - 32);
  23200. this.low = 0;
  23201. } else {
  23202. this.high = (this.high << places) | (this.low >>> (32 - places));
  23203. this.low = this.low << places;
  23204. }
  23205. },
  23206. rotateRight: function Word64_rotateRight(places) {
  23207. var low, high;
  23208. if (places & 32) {
  23209. high = this.low;
  23210. low = this.high;
  23211. } else {
  23212. low = this.low;
  23213. high = this.high;
  23214. }
  23215. places &= 31;
  23216. this.low = (low >>> places) | (high << (32 - places));
  23217. this.high = (high >>> places) | (low << (32 - places));
  23218. },
  23219. not: function Word64_not() {
  23220. this.high = ~this.high;
  23221. this.low = ~this.low;
  23222. },
  23223. add: function Word64_add(word) {
  23224. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  23225. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  23226. if (lowAdd > 0xFFFFFFFF) {
  23227. highAdd += 1;
  23228. }
  23229. this.low = lowAdd | 0;
  23230. this.high = highAdd | 0;
  23231. },
  23232. copyTo: function Word64_copyTo(bytes, offset) {
  23233. bytes[offset] = (this.high >>> 24) & 0xFF;
  23234. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  23235. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  23236. bytes[offset + 3] = this.high & 0xFF;
  23237. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  23238. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  23239. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  23240. bytes[offset + 7] = this.low & 0xFF;
  23241. },
  23242. assign: function Word64_assign(word) {
  23243. this.high = word.high;
  23244. this.low = word.low;
  23245. }
  23246. };
  23247. return Word64;
  23248. })();
  23249. var calculateSHA256 = (function calculateSHA256Closure() {
  23250. function rotr(x, n) {
  23251. return (x >>> n) | (x << 32 - n);
  23252. }
  23253. function ch(x, y, z) {
  23254. return (x & y) ^ (~x & z);
  23255. }
  23256. function maj(x, y, z) {
  23257. return (x & y) ^ (x & z) ^ (y & z);
  23258. }
  23259. function sigma(x) {
  23260. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  23261. }
  23262. function sigmaPrime(x) {
  23263. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  23264. }
  23265. function littleSigma(x) {
  23266. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  23267. }
  23268. function littleSigmaPrime(x) {
  23269. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  23270. }
  23271. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  23272. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  23273. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  23274. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  23275. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  23276. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  23277. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  23278. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  23279. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  23280. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  23281. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  23282. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  23283. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  23284. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  23285. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  23286. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  23287. function hash(data, offset, length) {
  23288. // initial hash values
  23289. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  23290. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  23291. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  23292. // pre-processing
  23293. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  23294. var padded = new Uint8Array(paddedLength);
  23295. var i, j, n;
  23296. for (i = 0; i < length; ++i) {
  23297. padded[i] = data[offset++];
  23298. }
  23299. padded[i++] = 0x80;
  23300. n = paddedLength - 8;
  23301. while (i < n) {
  23302. padded[i++] = 0;
  23303. }
  23304. padded[i++] = 0;
  23305. padded[i++] = 0;
  23306. padded[i++] = 0;
  23307. padded[i++] = (length >>> 29) & 0xFF;
  23308. padded[i++] = (length >> 21) & 0xFF;
  23309. padded[i++] = (length >> 13) & 0xFF;
  23310. padded[i++] = (length >> 5) & 0xFF;
  23311. padded[i++] = (length << 3) & 0xFF;
  23312. var w = new Uint32Array(64);
  23313. // for each 512 bit block
  23314. for (i = 0; i < paddedLength;) {
  23315. for (j = 0; j < 16; ++j) {
  23316. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  23317. (padded[i + 2] << 8) | (padded[i + 3]));
  23318. i += 4;
  23319. }
  23320. for (j = 16; j < 64; ++j) {
  23321. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  23322. littleSigma(w[j - 15]) + w[j - 16] | 0;
  23323. }
  23324. var a = h0, b = h1, c = h2, d = h3, e = h4,
  23325. f = h5, g = h6, h = h7, t1, t2;
  23326. for (j = 0; j < 64; ++j) {
  23327. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  23328. t2 = sigma(a) + maj(a, b, c);
  23329. h = g;
  23330. g = f;
  23331. f = e;
  23332. e = (d + t1) | 0;
  23333. d = c;
  23334. c = b;
  23335. b = a;
  23336. a = (t1 + t2) | 0;
  23337. }
  23338. h0 = (h0 + a) | 0;
  23339. h1 = (h1 + b) | 0;
  23340. h2 = (h2 + c) | 0;
  23341. h3 = (h3 + d) | 0;
  23342. h4 = (h4 + e) | 0;
  23343. h5 = (h5 + f) | 0;
  23344. h6 = (h6 + g) | 0;
  23345. h7 = (h7 + h) | 0;
  23346. }
  23347. return new Uint8Array([
  23348. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  23349. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  23350. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  23351. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  23352. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  23353. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  23354. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  23355. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  23356. ]);
  23357. }
  23358. return hash;
  23359. })();
  23360. var calculateSHA512 = (function calculateSHA512Closure() {
  23361. function ch(result, x, y, z, tmp) {
  23362. result.assign(x);
  23363. result.and(y);
  23364. tmp.assign(x);
  23365. tmp.not();
  23366. tmp.and(z);
  23367. result.xor(tmp);
  23368. }
  23369. function maj(result, x, y, z, tmp) {
  23370. result.assign(x);
  23371. result.and(y);
  23372. tmp.assign(x);
  23373. tmp.and(z);
  23374. result.xor(tmp);
  23375. tmp.assign(y);
  23376. tmp.and(z);
  23377. result.xor(tmp);
  23378. }
  23379. function sigma(result, x, tmp) {
  23380. result.assign(x);
  23381. result.rotateRight(28);
  23382. tmp.assign(x);
  23383. tmp.rotateRight(34);
  23384. result.xor(tmp);
  23385. tmp.assign(x);
  23386. tmp.rotateRight(39);
  23387. result.xor(tmp);
  23388. }
  23389. function sigmaPrime(result, x, tmp) {
  23390. result.assign(x);
  23391. result.rotateRight(14);
  23392. tmp.assign(x);
  23393. tmp.rotateRight(18);
  23394. result.xor(tmp);
  23395. tmp.assign(x);
  23396. tmp.rotateRight(41);
  23397. result.xor(tmp);
  23398. }
  23399. function littleSigma(result, x, tmp) {
  23400. result.assign(x);
  23401. result.rotateRight(1);
  23402. tmp.assign(x);
  23403. tmp.rotateRight(8);
  23404. result.xor(tmp);
  23405. tmp.assign(x);
  23406. tmp.shiftRight(7);
  23407. result.xor(tmp);
  23408. }
  23409. function littleSigmaPrime(result, x, tmp) {
  23410. result.assign(x);
  23411. result.rotateRight(19);
  23412. tmp.assign(x);
  23413. tmp.rotateRight(61);
  23414. result.xor(tmp);
  23415. tmp.assign(x);
  23416. tmp.shiftRight(6);
  23417. result.xor(tmp);
  23418. }
  23419. var k = [
  23420. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  23421. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  23422. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  23423. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  23424. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  23425. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  23426. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  23427. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  23428. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  23429. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  23430. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  23431. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  23432. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  23433. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  23434. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  23435. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  23436. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  23437. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  23438. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  23439. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  23440. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  23441. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  23442. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  23443. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  23444. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  23445. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  23446. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  23447. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  23448. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  23449. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  23450. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  23451. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  23452. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  23453. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  23454. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  23455. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  23456. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  23457. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  23458. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  23459. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  23460. function hash(data, offset, length, mode384) {
  23461. mode384 = !!mode384;
  23462. // initial hash values
  23463. var h0, h1, h2, h3, h4, h5, h6, h7;
  23464. if (!mode384) {
  23465. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  23466. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  23467. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  23468. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  23469. h4 = new Word64(0x510e527f, 0xade682d1);
  23470. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  23471. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  23472. h7 = new Word64(0x5be0cd19, 0x137e2179);
  23473. }
  23474. else {
  23475. // SHA384 is exactly the same
  23476. // except with different starting values and a trimmed result
  23477. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  23478. h1 = new Word64(0x629a292a, 0x367cd507);
  23479. h2 = new Word64(0x9159015a, 0x3070dd17);
  23480. h3 = new Word64(0x152fecd8, 0xf70e5939);
  23481. h4 = new Word64(0x67332667, 0xffc00b31);
  23482. h5 = new Word64(0x8eb44a87, 0x68581511);
  23483. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  23484. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  23485. }
  23486. // pre-processing
  23487. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  23488. var padded = new Uint8Array(paddedLength);
  23489. var i, j, n;
  23490. for (i = 0; i < length; ++i) {
  23491. padded[i] = data[offset++];
  23492. }
  23493. padded[i++] = 0x80;
  23494. n = paddedLength - 16;
  23495. while (i < n) {
  23496. padded[i++] = 0;
  23497. }
  23498. padded[i++] = 0;
  23499. padded[i++] = 0;
  23500. padded[i++] = 0;
  23501. padded[i++] = 0;
  23502. padded[i++] = 0;
  23503. padded[i++] = 0;
  23504. padded[i++] = 0;
  23505. padded[i++] = 0;
  23506. padded[i++] = 0;
  23507. padded[i++] = 0;
  23508. padded[i++] = 0;
  23509. padded[i++] = (length >>> 29) & 0xFF;
  23510. padded[i++] = (length >> 21) & 0xFF;
  23511. padded[i++] = (length >> 13) & 0xFF;
  23512. padded[i++] = (length >> 5) & 0xFF;
  23513. padded[i++] = (length << 3) & 0xFF;
  23514. var w = new Array(80);
  23515. for (i = 0; i < 80; i++) {
  23516. w[i] = new Word64(0, 0);
  23517. }
  23518. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  23519. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  23520. var g = new Word64(0, 0), h = new Word64(0, 0);
  23521. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  23522. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  23523. // for each 1024 bit block
  23524. for (i = 0; i < paddedLength;) {
  23525. for (j = 0; j < 16; ++j) {
  23526. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  23527. (padded[i + 2] << 8) | (padded[i + 3]);
  23528. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  23529. (padded[i + 6]) << 8 | (padded[i + 7]);
  23530. i += 8;
  23531. }
  23532. for (j = 16; j < 80; ++j) {
  23533. tmp3 = w[j];
  23534. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  23535. tmp3.add(w[j - 7]);
  23536. littleSigma(tmp1, w[j - 15], tmp2);
  23537. tmp3.add(tmp1);
  23538. tmp3.add(w[j - 16]);
  23539. }
  23540. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  23541. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  23542. for (j = 0; j < 80; ++j) {
  23543. t1.assign(h);
  23544. sigmaPrime(tmp1, e, tmp2);
  23545. t1.add(tmp1);
  23546. ch(tmp1, e, f, g, tmp2);
  23547. t1.add(tmp1);
  23548. t1.add(k[j]);
  23549. t1.add(w[j]);
  23550. sigma(t2, a, tmp2);
  23551. maj(tmp1, a, b, c, tmp2);
  23552. t2.add(tmp1);
  23553. tmp3 = h;
  23554. h = g;
  23555. g = f;
  23556. f = e;
  23557. d.add(t1);
  23558. e = d;
  23559. d = c;
  23560. c = b;
  23561. b = a;
  23562. tmp3.assign(t1);
  23563. tmp3.add(t2);
  23564. a = tmp3;
  23565. }
  23566. h0.add(a);
  23567. h1.add(b);
  23568. h2.add(c);
  23569. h3.add(d);
  23570. h4.add(e);
  23571. h5.add(f);
  23572. h6.add(g);
  23573. h7.add(h);
  23574. }
  23575. var result;
  23576. if (!mode384) {
  23577. result = new Uint8Array(64);
  23578. h0.copyTo(result,0);
  23579. h1.copyTo(result,8);
  23580. h2.copyTo(result,16);
  23581. h3.copyTo(result,24);
  23582. h4.copyTo(result,32);
  23583. h5.copyTo(result,40);
  23584. h6.copyTo(result,48);
  23585. h7.copyTo(result,56);
  23586. }
  23587. else {
  23588. result = new Uint8Array(48);
  23589. h0.copyTo(result,0);
  23590. h1.copyTo(result,8);
  23591. h2.copyTo(result,16);
  23592. h3.copyTo(result,24);
  23593. h4.copyTo(result,32);
  23594. h5.copyTo(result,40);
  23595. }
  23596. return result;
  23597. }
  23598. return hash;
  23599. })();
  23600. var calculateSHA384 = (function calculateSHA384Closure() {
  23601. function hash(data, offset, length) {
  23602. return calculateSHA512(data, offset, length, true);
  23603. }
  23604. return hash;
  23605. })();
  23606. var NullCipher = (function NullCipherClosure() {
  23607. function NullCipher() {
  23608. }
  23609. NullCipher.prototype = {
  23610. decryptBlock: function NullCipher_decryptBlock(data) {
  23611. return data;
  23612. }
  23613. };
  23614. return NullCipher;
  23615. })();
  23616. var AES128Cipher = (function AES128CipherClosure() {
  23617. var rcon = new Uint8Array([
  23618. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23619. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23620. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23621. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23622. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  23623. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  23624. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  23625. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  23626. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  23627. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  23628. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  23629. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  23630. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  23631. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  23632. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  23633. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  23634. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  23635. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23636. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23637. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23638. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23639. 0x74, 0xe8, 0xcb, 0x8d]);
  23640. var s = new Uint8Array([
  23641. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  23642. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  23643. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  23644. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  23645. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  23646. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  23647. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  23648. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  23649. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  23650. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  23651. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  23652. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  23653. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  23654. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  23655. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  23656. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  23657. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  23658. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  23659. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  23660. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  23661. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  23662. 0xb0, 0x54, 0xbb, 0x16]);
  23663. var inv_s = new Uint8Array([
  23664. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  23665. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  23666. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  23667. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  23668. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  23669. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  23670. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  23671. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  23672. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  23673. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  23674. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  23675. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  23676. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  23677. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  23678. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  23679. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  23680. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  23681. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  23682. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  23683. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  23684. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  23685. 0x55, 0x21, 0x0c, 0x7d]);
  23686. var mixCol = new Uint8Array(256);
  23687. for (var i = 0; i < 256; i++) {
  23688. if (i < 128) {
  23689. mixCol[i] = i << 1;
  23690. } else {
  23691. mixCol[i] = (i << 1) ^ 0x1b;
  23692. }
  23693. }
  23694. var mix = new Uint32Array([
  23695. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  23696. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  23697. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  23698. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  23699. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  23700. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  23701. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  23702. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  23703. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  23704. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  23705. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  23706. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  23707. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  23708. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  23709. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  23710. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  23711. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  23712. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  23713. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  23714. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  23715. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  23716. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  23717. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  23718. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  23719. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  23720. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  23721. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  23722. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  23723. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  23724. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  23725. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  23726. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  23727. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  23728. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  23729. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  23730. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  23731. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  23732. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  23733. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  23734. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  23735. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  23736. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  23737. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  23738. function expandKey128(cipherKey) {
  23739. var b = 176, result = new Uint8Array(b);
  23740. result.set(cipherKey);
  23741. for (var j = 16, i = 1; j < b; ++i) {
  23742. // RotWord
  23743. var t1 = result[j - 3], t2 = result[j - 2],
  23744. t3 = result[j - 1], t4 = result[j - 4];
  23745. // SubWord
  23746. t1 = s[t1];
  23747. t2 = s[t2];
  23748. t3 = s[t3];
  23749. t4 = s[t4];
  23750. // Rcon
  23751. t1 = t1 ^ rcon[i];
  23752. for (var n = 0; n < 4; ++n) {
  23753. result[j] = (t1 ^= result[j - 16]);
  23754. j++;
  23755. result[j] = (t2 ^= result[j - 16]);
  23756. j++;
  23757. result[j] = (t3 ^= result[j - 16]);
  23758. j++;
  23759. result[j] = (t4 ^= result[j - 16]);
  23760. j++;
  23761. }
  23762. }
  23763. return result;
  23764. }
  23765. function decrypt128(input, key) {
  23766. var state = new Uint8Array(16);
  23767. state.set(input);
  23768. var i, j, k;
  23769. var t, u, v;
  23770. // AddRoundKey
  23771. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23772. state[j] ^= key[k];
  23773. }
  23774. for (i = 9; i >= 1; --i) {
  23775. // InvShiftRows
  23776. t = state[13];
  23777. state[13] = state[9];
  23778. state[9] = state[5];
  23779. state[5] = state[1];
  23780. state[1] = t;
  23781. t = state[14];
  23782. u = state[10];
  23783. state[14] = state[6];
  23784. state[10] = state[2];
  23785. state[6] = t;
  23786. state[2] = u;
  23787. t = state[15];
  23788. u = state[11];
  23789. v = state[7];
  23790. state[15] = state[3];
  23791. state[11] = t;
  23792. state[7] = u;
  23793. state[3] = v;
  23794. // InvSubBytes
  23795. for (j = 0; j < 16; ++j) {
  23796. state[j] = inv_s[state[j]];
  23797. }
  23798. // AddRoundKey
  23799. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23800. state[j] ^= key[k];
  23801. }
  23802. // InvMixColumns
  23803. for (j = 0; j < 16; j += 4) {
  23804. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  23805. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  23806. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  23807. (s3 >>> 24) ^ (s3 << 8));
  23808. state[j] = (t >>> 24) & 0xFF;
  23809. state[j + 1] = (t >> 16) & 0xFF;
  23810. state[j + 2] = (t >> 8) & 0xFF;
  23811. state[j + 3] = t & 0xFF;
  23812. }
  23813. }
  23814. // InvShiftRows
  23815. t = state[13];
  23816. state[13] = state[9];
  23817. state[9] = state[5];
  23818. state[5] = state[1];
  23819. state[1] = t;
  23820. t = state[14];
  23821. u = state[10];
  23822. state[14] = state[6];
  23823. state[10] = state[2];
  23824. state[6] = t;
  23825. state[2] = u;
  23826. t = state[15];
  23827. u = state[11];
  23828. v = state[7];
  23829. state[15] = state[3];
  23830. state[11] = t;
  23831. state[7] = u;
  23832. state[3] = v;
  23833. for (j = 0; j < 16; ++j) {
  23834. // InvSubBytes
  23835. state[j] = inv_s[state[j]];
  23836. // AddRoundKey
  23837. state[j] ^= key[j];
  23838. }
  23839. return state;
  23840. }
  23841. function encrypt128(input, key) {
  23842. var t, u, v, k;
  23843. var state = new Uint8Array(16);
  23844. state.set(input);
  23845. for (j = 0; j < 16; ++j) {
  23846. // AddRoundKey
  23847. state[j] ^= key[j];
  23848. }
  23849. for (i = 1; i < 10; i++) {
  23850. //SubBytes
  23851. for (j = 0; j < 16; ++j) {
  23852. state[j] = s[state[j]];
  23853. }
  23854. //ShiftRows
  23855. v = state[1];
  23856. state[1] = state[5];
  23857. state[5] = state[9];
  23858. state[9] = state[13];
  23859. state[13] = v;
  23860. v = state[2];
  23861. u = state[6];
  23862. state[2] = state[10];
  23863. state[6] = state[14];
  23864. state[10] = v;
  23865. state[14] = u;
  23866. v = state[3];
  23867. u = state[7];
  23868. t = state[11];
  23869. state[3] = state[15];
  23870. state[7] = v;
  23871. state[11] = u;
  23872. state[15] = t;
  23873. //MixColumns
  23874. for (var j = 0; j < 16; j += 4) {
  23875. var s0 = state[j + 0], s1 = state[j + 1];
  23876. var s2 = state[j + 2], s3 = state[j + 3];
  23877. t = s0 ^ s1 ^ s2 ^ s3;
  23878. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  23879. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  23880. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  23881. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  23882. }
  23883. //AddRoundKey
  23884. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23885. state[j] ^= key[k];
  23886. }
  23887. }
  23888. //SubBytes
  23889. for (j = 0; j < 16; ++j) {
  23890. state[j] = s[state[j]];
  23891. }
  23892. //ShiftRows
  23893. v = state[1];
  23894. state[1] = state[5];
  23895. state[5] = state[9];
  23896. state[9] = state[13];
  23897. state[13] = v;
  23898. v = state[2];
  23899. u = state[6];
  23900. state[2] = state[10];
  23901. state[6] = state[14];
  23902. state[10] = v;
  23903. state[14] = u;
  23904. v = state[3];
  23905. u = state[7];
  23906. t = state[11];
  23907. state[3] = state[15];
  23908. state[7] = v;
  23909. state[11] = u;
  23910. state[15] = t;
  23911. //AddRoundKey
  23912. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23913. state[j] ^= key[k];
  23914. }
  23915. return state;
  23916. }
  23917. function AES128Cipher(key) {
  23918. this.key = expandKey128(key);
  23919. this.buffer = new Uint8Array(16);
  23920. this.bufferPosition = 0;
  23921. }
  23922. function decryptBlock2(data, finalize) {
  23923. var i, j, ii, sourceLength = data.length,
  23924. buffer = this.buffer, bufferLength = this.bufferPosition,
  23925. result = [], iv = this.iv;
  23926. for (i = 0; i < sourceLength; ++i) {
  23927. buffer[bufferLength] = data[i];
  23928. ++bufferLength;
  23929. if (bufferLength < 16) {
  23930. continue;
  23931. }
  23932. // buffer is full, decrypting
  23933. var plain = decrypt128(buffer, this.key);
  23934. // xor-ing the IV vector to get plain text
  23935. for (j = 0; j < 16; ++j) {
  23936. plain[j] ^= iv[j];
  23937. }
  23938. iv = buffer;
  23939. result.push(plain);
  23940. buffer = new Uint8Array(16);
  23941. bufferLength = 0;
  23942. }
  23943. // saving incomplete buffer
  23944. this.buffer = buffer;
  23945. this.bufferLength = bufferLength;
  23946. this.iv = iv;
  23947. if (result.length === 0) {
  23948. return new Uint8Array([]);
  23949. }
  23950. // combining plain text blocks into one
  23951. var outputLength = 16 * result.length;
  23952. if (finalize) {
  23953. // undo a padding that is described in RFC 2898
  23954. var lastBlock = result[result.length - 1];
  23955. var psLen = lastBlock[15];
  23956. if (psLen <= 16) {
  23957. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  23958. if (lastBlock[i] !== psLen) {
  23959. // Invalid padding, assume that the block has no padding.
  23960. psLen = 0;
  23961. break;
  23962. }
  23963. }
  23964. outputLength -= psLen;
  23965. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  23966. }
  23967. }
  23968. var output = new Uint8Array(outputLength);
  23969. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  23970. output.set(result[i], j);
  23971. }
  23972. return output;
  23973. }
  23974. AES128Cipher.prototype = {
  23975. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  23976. var i, sourceLength = data.length;
  23977. var buffer = this.buffer, bufferLength = this.bufferPosition;
  23978. // waiting for IV values -- they are at the start of the stream
  23979. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  23980. buffer[bufferLength] = data[i];
  23981. }
  23982. if (bufferLength < 16) {
  23983. // need more data
  23984. this.bufferLength = bufferLength;
  23985. return new Uint8Array([]);
  23986. }
  23987. this.iv = buffer;
  23988. this.buffer = new Uint8Array(16);
  23989. this.bufferLength = 0;
  23990. // starting decryption
  23991. this.decryptBlock = decryptBlock2;
  23992. return this.decryptBlock(data.subarray(16), finalize);
  23993. },
  23994. encrypt: function AES128Cipher_encrypt(data, iv) {
  23995. var i, j, ii, sourceLength = data.length,
  23996. buffer = this.buffer, bufferLength = this.bufferPosition,
  23997. result = [];
  23998. if (!iv) {
  23999. iv = new Uint8Array(16);
  24000. }
  24001. for (i = 0; i < sourceLength; ++i) {
  24002. buffer[bufferLength] = data[i];
  24003. ++bufferLength;
  24004. if (bufferLength < 16) {
  24005. continue;
  24006. }
  24007. for (j = 0; j < 16; ++j) {
  24008. buffer[j] ^= iv[j];
  24009. }
  24010. // buffer is full, encrypting
  24011. var cipher = encrypt128(buffer, this.key);
  24012. iv = cipher;
  24013. result.push(cipher);
  24014. buffer = new Uint8Array(16);
  24015. bufferLength = 0;
  24016. }
  24017. // saving incomplete buffer
  24018. this.buffer = buffer;
  24019. this.bufferLength = bufferLength;
  24020. this.iv = iv;
  24021. if (result.length === 0) {
  24022. return new Uint8Array([]);
  24023. }
  24024. // combining plain text blocks into one
  24025. var outputLength = 16 * result.length;
  24026. var output = new Uint8Array(outputLength);
  24027. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24028. output.set(result[i], j);
  24029. }
  24030. return output;
  24031. }
  24032. };
  24033. return AES128Cipher;
  24034. })();
  24035. var AES256Cipher = (function AES256CipherClosure() {
  24036. var rcon = new Uint8Array([
  24037. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24038. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24039. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24040. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24041. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24042. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24043. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24044. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24045. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24046. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24047. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24048. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24049. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24050. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24051. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24052. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24053. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24054. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24055. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24056. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24057. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24058. 0x74, 0xe8, 0xcb, 0x8d]);
  24059. var s = new Uint8Array([
  24060. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24061. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24062. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24063. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24064. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24065. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24066. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24067. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24068. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24069. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24070. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24071. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24072. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24073. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24074. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24075. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24076. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24077. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24078. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24079. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24080. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24081. 0xb0, 0x54, 0xbb, 0x16]);
  24082. var inv_s = new Uint8Array([
  24083. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24084. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24085. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24086. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24087. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24088. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24089. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24090. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24091. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24092. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24093. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24094. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24095. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24096. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24097. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24098. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24099. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24100. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24101. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24102. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24103. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24104. 0x55, 0x21, 0x0c, 0x7d]);
  24105. var mixCol = new Uint8Array(256);
  24106. for (var i = 0; i < 256; i++) {
  24107. if (i < 128) {
  24108. mixCol[i] = i << 1;
  24109. } else {
  24110. mixCol[i] = (i << 1) ^ 0x1b;
  24111. }
  24112. }
  24113. var mix = new Uint32Array([
  24114. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24115. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24116. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24117. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24118. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24119. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24120. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24121. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24122. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24123. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24124. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24125. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24126. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24127. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24128. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24129. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24130. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24131. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24132. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24133. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24134. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24135. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24136. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24137. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24138. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24139. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24140. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24141. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24142. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24143. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24144. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24145. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24146. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24147. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24148. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24149. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24150. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24151. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24152. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24153. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24154. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24155. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24156. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24157. function expandKey256(cipherKey) {
  24158. var b = 240, result = new Uint8Array(b);
  24159. var r = 1;
  24160. result.set(cipherKey);
  24161. for (var j = 32, i = 1; j < b; ++i) {
  24162. if (j % 32 === 16) {
  24163. t1 = s[t1];
  24164. t2 = s[t2];
  24165. t3 = s[t3];
  24166. t4 = s[t4];
  24167. } else if (j % 32 === 0) {
  24168. // RotWord
  24169. var t1 = result[j - 3], t2 = result[j - 2],
  24170. t3 = result[j - 1], t4 = result[j - 4];
  24171. // SubWord
  24172. t1 = s[t1];
  24173. t2 = s[t2];
  24174. t3 = s[t3];
  24175. t4 = s[t4];
  24176. // Rcon
  24177. t1 = t1 ^ r;
  24178. if ((r <<= 1) >= 256) {
  24179. r = (r ^ 0x1b) & 0xFF;
  24180. }
  24181. }
  24182. for (var n = 0; n < 4; ++n) {
  24183. result[j] = (t1 ^= result[j - 32]);
  24184. j++;
  24185. result[j] = (t2 ^= result[j - 32]);
  24186. j++;
  24187. result[j] = (t3 ^= result[j - 32]);
  24188. j++;
  24189. result[j] = (t4 ^= result[j - 32]);
  24190. j++;
  24191. }
  24192. }
  24193. return result;
  24194. }
  24195. function decrypt256(input, key) {
  24196. var state = new Uint8Array(16);
  24197. state.set(input);
  24198. var i, j, k;
  24199. var t, u, v;
  24200. // AddRoundKey
  24201. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24202. state[j] ^= key[k];
  24203. }
  24204. for (i = 13; i >= 1; --i) {
  24205. // InvShiftRows
  24206. t = state[13];
  24207. state[13] = state[9];
  24208. state[9] = state[5];
  24209. state[5] = state[1];
  24210. state[1] = t;
  24211. t = state[14];
  24212. u = state[10];
  24213. state[14] = state[6];
  24214. state[10] = state[2];
  24215. state[6] = t;
  24216. state[2] = u;
  24217. t = state[15];
  24218. u = state[11];
  24219. v = state[7];
  24220. state[15] = state[3];
  24221. state[11] = t;
  24222. state[7] = u;
  24223. state[3] = v;
  24224. // InvSubBytes
  24225. for (j = 0; j < 16; ++j) {
  24226. state[j] = inv_s[state[j]];
  24227. }
  24228. // AddRoundKey
  24229. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24230. state[j] ^= key[k];
  24231. }
  24232. // InvMixColumns
  24233. for (j = 0; j < 16; j += 4) {
  24234. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24235. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24236. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24237. (s3 >>> 24) ^ (s3 << 8));
  24238. state[j] = (t >>> 24) & 0xFF;
  24239. state[j + 1] = (t >> 16) & 0xFF;
  24240. state[j + 2] = (t >> 8) & 0xFF;
  24241. state[j + 3] = t & 0xFF;
  24242. }
  24243. }
  24244. // InvShiftRows
  24245. t = state[13];
  24246. state[13] = state[9];
  24247. state[9] = state[5];
  24248. state[5] = state[1];
  24249. state[1] = t;
  24250. t = state[14];
  24251. u = state[10];
  24252. state[14] = state[6];
  24253. state[10] = state[2];
  24254. state[6] = t;
  24255. state[2] = u;
  24256. t = state[15];
  24257. u = state[11];
  24258. v = state[7];
  24259. state[15] = state[3];
  24260. state[11] = t;
  24261. state[7] = u;
  24262. state[3] = v;
  24263. for (j = 0; j < 16; ++j) {
  24264. // InvSubBytes
  24265. state[j] = inv_s[state[j]];
  24266. // AddRoundKey
  24267. state[j] ^= key[j];
  24268. }
  24269. return state;
  24270. }
  24271. function encrypt256(input, key) {
  24272. var t, u, v, k;
  24273. var state = new Uint8Array(16);
  24274. state.set(input);
  24275. for (j = 0; j < 16; ++j) {
  24276. // AddRoundKey
  24277. state[j] ^= key[j];
  24278. }
  24279. for (i = 1; i < 14; i++) {
  24280. //SubBytes
  24281. for (j = 0; j < 16; ++j) {
  24282. state[j] = s[state[j]];
  24283. }
  24284. //ShiftRows
  24285. v = state[1];
  24286. state[1] = state[5];
  24287. state[5] = state[9];
  24288. state[9] = state[13];
  24289. state[13] = v;
  24290. v = state[2];
  24291. u = state[6];
  24292. state[2] = state[10];
  24293. state[6] = state[14];
  24294. state[10] = v;
  24295. state[14] = u;
  24296. v = state[3];
  24297. u = state[7];
  24298. t = state[11];
  24299. state[3] = state[15];
  24300. state[7] = v;
  24301. state[11] = u;
  24302. state[15] = t;
  24303. //MixColumns
  24304. for (var j = 0; j < 16; j += 4) {
  24305. var s0 = state[j + 0], s1 = state[j + 1];
  24306. var s2 = state[j + 2], s3 = state[j + 3];
  24307. t = s0 ^ s1 ^ s2 ^ s3;
  24308. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24309. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24310. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24311. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24312. }
  24313. //AddRoundKey
  24314. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24315. state[j] ^= key[k];
  24316. }
  24317. }
  24318. //SubBytes
  24319. for (j = 0; j < 16; ++j) {
  24320. state[j] = s[state[j]];
  24321. }
  24322. //ShiftRows
  24323. v = state[1];
  24324. state[1] = state[5];
  24325. state[5] = state[9];
  24326. state[9] = state[13];
  24327. state[13] = v;
  24328. v = state[2];
  24329. u = state[6];
  24330. state[2] = state[10];
  24331. state[6] = state[14];
  24332. state[10] = v;
  24333. state[14] = u;
  24334. v = state[3];
  24335. u = state[7];
  24336. t = state[11];
  24337. state[3] = state[15];
  24338. state[7] = v;
  24339. state[11] = u;
  24340. state[15] = t;
  24341. //AddRoundKey
  24342. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24343. state[j] ^= key[k];
  24344. }
  24345. return state;
  24346. }
  24347. function AES256Cipher(key) {
  24348. this.key = expandKey256(key);
  24349. this.buffer = new Uint8Array(16);
  24350. this.bufferPosition = 0;
  24351. }
  24352. function decryptBlock2(data, finalize) {
  24353. var i, j, ii, sourceLength = data.length,
  24354. buffer = this.buffer, bufferLength = this.bufferPosition,
  24355. result = [], iv = this.iv;
  24356. for (i = 0; i < sourceLength; ++i) {
  24357. buffer[bufferLength] = data[i];
  24358. ++bufferLength;
  24359. if (bufferLength < 16) {
  24360. continue;
  24361. }
  24362. // buffer is full, decrypting
  24363. var plain = decrypt256(buffer, this.key);
  24364. // xor-ing the IV vector to get plain text
  24365. for (j = 0; j < 16; ++j) {
  24366. plain[j] ^= iv[j];
  24367. }
  24368. iv = buffer;
  24369. result.push(plain);
  24370. buffer = new Uint8Array(16);
  24371. bufferLength = 0;
  24372. }
  24373. // saving incomplete buffer
  24374. this.buffer = buffer;
  24375. this.bufferLength = bufferLength;
  24376. this.iv = iv;
  24377. if (result.length === 0) {
  24378. return new Uint8Array([]);
  24379. }
  24380. // combining plain text blocks into one
  24381. var outputLength = 16 * result.length;
  24382. if (finalize) {
  24383. // undo a padding that is described in RFC 2898
  24384. var lastBlock = result[result.length - 1];
  24385. var psLen = lastBlock[15];
  24386. if (psLen <= 16) {
  24387. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24388. if (lastBlock[i] !== psLen) {
  24389. // Invalid padding, assume that the block has no padding.
  24390. psLen = 0;
  24391. break;
  24392. }
  24393. }
  24394. outputLength -= psLen;
  24395. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24396. }
  24397. }
  24398. var output = new Uint8Array(outputLength);
  24399. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24400. output.set(result[i], j);
  24401. }
  24402. return output;
  24403. }
  24404. AES256Cipher.prototype = {
  24405. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  24406. var i, sourceLength = data.length;
  24407. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24408. // if not supplied an IV wait for IV values
  24409. // they are at the start of the stream
  24410. if (iv) {
  24411. this.iv = iv;
  24412. } else {
  24413. for (i = 0; bufferLength < 16 &&
  24414. i < sourceLength; ++i, ++bufferLength) {
  24415. buffer[bufferLength] = data[i];
  24416. }
  24417. if (bufferLength < 16) {
  24418. //need more data
  24419. this.bufferLength = bufferLength;
  24420. return new Uint8Array([]);
  24421. }
  24422. this.iv = buffer;
  24423. data = data.subarray(16);
  24424. }
  24425. this.buffer = new Uint8Array(16);
  24426. this.bufferLength = 0;
  24427. // starting decryption
  24428. this.decryptBlock = decryptBlock2;
  24429. return this.decryptBlock(data, finalize);
  24430. },
  24431. encrypt: function AES256Cipher_encrypt(data, iv) {
  24432. var i, j, ii, sourceLength = data.length,
  24433. buffer = this.buffer, bufferLength = this.bufferPosition,
  24434. result = [];
  24435. if (!iv) {
  24436. iv = new Uint8Array(16);
  24437. }
  24438. for (i = 0; i < sourceLength; ++i) {
  24439. buffer[bufferLength] = data[i];
  24440. ++bufferLength;
  24441. if (bufferLength < 16) {
  24442. continue;
  24443. }
  24444. for (j = 0; j < 16; ++j) {
  24445. buffer[j] ^= iv[j];
  24446. }
  24447. // buffer is full, encrypting
  24448. var cipher = encrypt256(buffer, this.key);
  24449. this.iv = cipher;
  24450. result.push(cipher);
  24451. buffer = new Uint8Array(16);
  24452. bufferLength = 0;
  24453. }
  24454. // saving incomplete buffer
  24455. this.buffer = buffer;
  24456. this.bufferLength = bufferLength;
  24457. this.iv = iv;
  24458. if (result.length === 0) {
  24459. return new Uint8Array([]);
  24460. }
  24461. // combining plain text blocks into one
  24462. var outputLength = 16 * result.length;
  24463. var output = new Uint8Array(outputLength);
  24464. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24465. output.set(result[i], j);
  24466. }
  24467. return output;
  24468. }
  24469. };
  24470. return AES256Cipher;
  24471. })();
  24472. var PDF17 = (function PDF17Closure() {
  24473. function compareByteArrays(array1, array2) {
  24474. if (array1.length !== array2.length) {
  24475. return false;
  24476. }
  24477. for (var i = 0; i < array1.length; i++) {
  24478. if (array1[i] !== array2[i]) {
  24479. return false;
  24480. }
  24481. }
  24482. return true;
  24483. }
  24484. function PDF17() {
  24485. }
  24486. PDF17.prototype = {
  24487. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  24488. ownerValidationSalt,
  24489. userBytes,
  24490. ownerPassword) {
  24491. var hashData = new Uint8Array(password.length + 56);
  24492. hashData.set(password, 0);
  24493. hashData.set(ownerValidationSalt, password.length);
  24494. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24495. var result = calculateSHA256(hashData, 0, hashData.length);
  24496. return compareByteArrays(result, ownerPassword);
  24497. },
  24498. checkUserPassword: function PDF17_checkUserPassword(password,
  24499. userValidationSalt,
  24500. userPassword) {
  24501. var hashData = new Uint8Array(password.length + 8);
  24502. hashData.set(password, 0);
  24503. hashData.set(userValidationSalt, password.length);
  24504. var result = calculateSHA256(hashData, 0, hashData.length);
  24505. return compareByteArrays(result, userPassword);
  24506. },
  24507. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  24508. ownerEncryption) {
  24509. var hashData = new Uint8Array(password.length + 56);
  24510. hashData.set(password, 0);
  24511. hashData.set(ownerKeySalt, password.length);
  24512. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24513. var key = calculateSHA256(hashData, 0, hashData.length);
  24514. var cipher = new AES256Cipher(key);
  24515. return cipher.decryptBlock(ownerEncryption,
  24516. false,
  24517. new Uint8Array(16));
  24518. },
  24519. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  24520. userEncryption) {
  24521. var hashData = new Uint8Array(password.length + 8);
  24522. hashData.set(password, 0);
  24523. hashData.set(userKeySalt, password.length);
  24524. //key is the decryption key for the UE string
  24525. var key = calculateSHA256(hashData, 0, hashData.length);
  24526. var cipher = new AES256Cipher(key);
  24527. return cipher.decryptBlock(userEncryption,
  24528. false,
  24529. new Uint8Array(16));
  24530. }
  24531. };
  24532. return PDF17;
  24533. })();
  24534. var PDF20 = (function PDF20Closure() {
  24535. function concatArrays(array1, array2) {
  24536. var t = new Uint8Array(array1.length + array2.length);
  24537. t.set(array1, 0);
  24538. t.set(array2, array1.length);
  24539. return t;
  24540. }
  24541. function calculatePDF20Hash(password, input, userBytes) {
  24542. //This refers to Algorithm 2.B as defined in ISO 32000-2
  24543. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  24544. var e = [0];
  24545. var i = 0;
  24546. while (i < 64 || e[e.length - 1] > i - 32) {
  24547. var arrayLength = password.length + k.length + userBytes.length;
  24548. var k1 = new Uint8Array(arrayLength * 64);
  24549. var array = concatArrays(password, k);
  24550. array = concatArrays(array, userBytes);
  24551. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  24552. k1.set(array, pos);
  24553. }
  24554. //AES128 CBC NO PADDING with
  24555. //first 16 bytes of k as the key and the second 16 as the iv.
  24556. var cipher = new AES128Cipher(k.subarray(0, 16));
  24557. e = cipher.encrypt(k1, k.subarray(16, 32));
  24558. //Now we have to take the first 16 bytes of an unsigned
  24559. //big endian integer... and compute the remainder
  24560. //modulo 3.... That is a fairly large number and
  24561. //JavaScript isn't going to handle that well...
  24562. //So we're using a trick that allows us to perform
  24563. //modulo math byte by byte
  24564. var remainder = 0;
  24565. for (var z = 0; z < 16; z++) {
  24566. remainder *= (256 % 3);
  24567. remainder %= 3;
  24568. remainder += ((e[z] >>> 0) % 3);
  24569. remainder %= 3;
  24570. }
  24571. if (remainder === 0) {
  24572. k = calculateSHA256(e, 0, e.length);
  24573. }
  24574. else if (remainder === 1) {
  24575. k = calculateSHA384(e, 0, e.length);
  24576. }
  24577. else if (remainder === 2) {
  24578. k = calculateSHA512(e, 0, e.length);
  24579. }
  24580. i++;
  24581. }
  24582. return k.subarray(0, 32);
  24583. }
  24584. function PDF20() {
  24585. }
  24586. function compareByteArrays(array1, array2) {
  24587. if (array1.length !== array2.length) {
  24588. return false;
  24589. }
  24590. for (var i = 0; i < array1.length; i++) {
  24591. if (array1[i] !== array2[i]) {
  24592. return false;
  24593. }
  24594. }
  24595. return true;
  24596. }
  24597. PDF20.prototype = {
  24598. hash: function PDF20_hash(password, concatBytes, userBytes) {
  24599. return calculatePDF20Hash(password, concatBytes, userBytes);
  24600. },
  24601. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  24602. ownerValidationSalt,
  24603. userBytes,
  24604. ownerPassword) {
  24605. var hashData = new Uint8Array(password.length + 56);
  24606. hashData.set(password, 0);
  24607. hashData.set(ownerValidationSalt, password.length);
  24608. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24609. var result = calculatePDF20Hash(password, hashData, userBytes);
  24610. return compareByteArrays(result, ownerPassword);
  24611. },
  24612. checkUserPassword: function PDF20_checkUserPassword(password,
  24613. userValidationSalt,
  24614. userPassword) {
  24615. var hashData = new Uint8Array(password.length + 8);
  24616. hashData.set(password, 0);
  24617. hashData.set(userValidationSalt, password.length);
  24618. var result = calculatePDF20Hash(password, hashData, []);
  24619. return compareByteArrays(result, userPassword);
  24620. },
  24621. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  24622. ownerEncryption) {
  24623. var hashData = new Uint8Array(password.length + 56);
  24624. hashData.set(password, 0);
  24625. hashData.set(ownerKeySalt, password.length);
  24626. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24627. var key = calculatePDF20Hash(password, hashData, userBytes);
  24628. var cipher = new AES256Cipher(key);
  24629. return cipher.decryptBlock(ownerEncryption,
  24630. false,
  24631. new Uint8Array(16));
  24632. },
  24633. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  24634. userEncryption) {
  24635. var hashData = new Uint8Array(password.length + 8);
  24636. hashData.set(password, 0);
  24637. hashData.set(userKeySalt, password.length);
  24638. //key is the decryption key for the UE string
  24639. var key = calculatePDF20Hash(password, hashData, []);
  24640. var cipher = new AES256Cipher(key);
  24641. return cipher.decryptBlock(userEncryption,
  24642. false,
  24643. new Uint8Array(16));
  24644. }
  24645. };
  24646. return PDF20;
  24647. })();
  24648. var CipherTransform = (function CipherTransformClosure() {
  24649. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  24650. this.stringCipherConstructor = stringCipherConstructor;
  24651. this.streamCipherConstructor = streamCipherConstructor;
  24652. }
  24653. CipherTransform.prototype = {
  24654. createStream: function CipherTransform_createStream(stream, length) {
  24655. var cipher = new this.streamCipherConstructor();
  24656. return new DecryptStream(stream, length,
  24657. function cipherTransformDecryptStream(data, finalize) {
  24658. return cipher.decryptBlock(data, finalize);
  24659. }
  24660. );
  24661. },
  24662. decryptString: function CipherTransform_decryptString(s) {
  24663. var cipher = new this.stringCipherConstructor();
  24664. var data = stringToBytes(s);
  24665. data = cipher.decryptBlock(data, true);
  24666. return bytesToString(data);
  24667. }
  24668. };
  24669. return CipherTransform;
  24670. })();
  24671. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  24672. var defaultPasswordBytes = new Uint8Array([
  24673. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  24674. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  24675. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  24676. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  24677. function createEncryptionKey20(revision, password, ownerPassword,
  24678. ownerValidationSalt, ownerKeySalt, uBytes,
  24679. userPassword, userValidationSalt, userKeySalt,
  24680. ownerEncryption, userEncryption, perms) {
  24681. if (password) {
  24682. var passwordLength = Math.min(127, password.length);
  24683. password = password.subarray(0, passwordLength);
  24684. } else {
  24685. password = [];
  24686. }
  24687. var pdfAlgorithm;
  24688. if (revision === 6) {
  24689. pdfAlgorithm = new PDF20();
  24690. } else {
  24691. pdfAlgorithm = new PDF17();
  24692. }
  24693. if (pdfAlgorithm) {
  24694. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  24695. userPassword)) {
  24696. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  24697. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  24698. ownerValidationSalt,
  24699. uBytes,
  24700. ownerPassword)) {
  24701. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  24702. ownerEncryption);
  24703. }
  24704. }
  24705. return null;
  24706. }
  24707. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  24708. flags, revision, keyLength, encryptMetadata) {
  24709. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  24710. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  24711. if (password) {
  24712. n = Math.min(32, password.length);
  24713. for (; i < n; ++i) {
  24714. hashData[i] = password[i];
  24715. }
  24716. }
  24717. j = 0;
  24718. while (i < 32) {
  24719. hashData[i++] = defaultPasswordBytes[j++];
  24720. }
  24721. // as now the padded password in the hashData[0..i]
  24722. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  24723. hashData[i++] = ownerPassword[j];
  24724. }
  24725. hashData[i++] = flags & 0xFF;
  24726. hashData[i++] = (flags >> 8) & 0xFF;
  24727. hashData[i++] = (flags >> 16) & 0xFF;
  24728. hashData[i++] = (flags >>> 24) & 0xFF;
  24729. for (j = 0, n = fileId.length; j < n; ++j) {
  24730. hashData[i++] = fileId[j];
  24731. }
  24732. if (revision >= 4 && !encryptMetadata) {
  24733. hashData[i++] = 0xFF;
  24734. hashData[i++] = 0xFF;
  24735. hashData[i++] = 0xFF;
  24736. hashData[i++] = 0xFF;
  24737. }
  24738. var hash = calculateMD5(hashData, 0, i);
  24739. var keyLengthInBytes = keyLength >> 3;
  24740. if (revision >= 3) {
  24741. for (j = 0; j < 50; ++j) {
  24742. hash = calculateMD5(hash, 0, keyLengthInBytes);
  24743. }
  24744. }
  24745. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  24746. var cipher, checkData;
  24747. if (revision >= 3) {
  24748. for (i = 0; i < 32; ++i) {
  24749. hashData[i] = defaultPasswordBytes[i];
  24750. }
  24751. for (j = 0, n = fileId.length; j < n; ++j) {
  24752. hashData[i++] = fileId[j];
  24753. }
  24754. cipher = new ARCFourCipher(encryptionKey);
  24755. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  24756. n = encryptionKey.length;
  24757. var derivedKey = new Uint8Array(n), k;
  24758. for (j = 1; j <= 19; ++j) {
  24759. for (k = 0; k < n; ++k) {
  24760. derivedKey[k] = encryptionKey[k] ^ j;
  24761. }
  24762. cipher = new ARCFourCipher(derivedKey);
  24763. checkData = cipher.encryptBlock(checkData);
  24764. }
  24765. for (j = 0, n = checkData.length; j < n; ++j) {
  24766. if (userPassword[j] !== checkData[j]) {
  24767. return null;
  24768. }
  24769. }
  24770. } else {
  24771. cipher = new ARCFourCipher(encryptionKey);
  24772. checkData = cipher.encryptBlock(defaultPasswordBytes);
  24773. for (j = 0, n = checkData.length; j < n; ++j) {
  24774. if (userPassword[j] !== checkData[j]) {
  24775. return null;
  24776. }
  24777. }
  24778. }
  24779. return encryptionKey;
  24780. }
  24781. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  24782. var hashData = new Uint8Array(32), i = 0, j, n;
  24783. n = Math.min(32, password.length);
  24784. for (; i < n; ++i) {
  24785. hashData[i] = password[i];
  24786. }
  24787. j = 0;
  24788. while (i < 32) {
  24789. hashData[i++] = defaultPasswordBytes[j++];
  24790. }
  24791. var hash = calculateMD5(hashData, 0, i);
  24792. var keyLengthInBytes = keyLength >> 3;
  24793. if (revision >= 3) {
  24794. for (j = 0; j < 50; ++j) {
  24795. hash = calculateMD5(hash, 0, hash.length);
  24796. }
  24797. }
  24798. var cipher, userPassword;
  24799. if (revision >= 3) {
  24800. userPassword = ownerPassword;
  24801. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  24802. for (j = 19; j >= 0; j--) {
  24803. for (k = 0; k < keyLengthInBytes; ++k) {
  24804. derivedKey[k] = hash[k] ^ j;
  24805. }
  24806. cipher = new ARCFourCipher(derivedKey);
  24807. userPassword = cipher.encryptBlock(userPassword);
  24808. }
  24809. } else {
  24810. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  24811. userPassword = cipher.encryptBlock(ownerPassword);
  24812. }
  24813. return userPassword;
  24814. }
  24815. var identityName = Name.get('Identity');
  24816. function CipherTransformFactory(dict, fileId, password) {
  24817. var filter = dict.get('Filter');
  24818. if (!isName(filter) || filter.name !== 'Standard') {
  24819. error('unknown encryption method');
  24820. }
  24821. this.dict = dict;
  24822. var algorithm = dict.get('V');
  24823. if (!isInt(algorithm) ||
  24824. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  24825. algorithm !== 5)) {
  24826. error('unsupported encryption algorithm');
  24827. }
  24828. this.algorithm = algorithm;
  24829. var keyLength = dict.get('Length');
  24830. if (!keyLength) {
  24831. // Spec asks to rely on encryption dictionary's Length entry, however
  24832. // some PDFs don't have it. Trying to recover.
  24833. if (algorithm <= 3) {
  24834. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  24835. keyLength = 40;
  24836. } else {
  24837. // Trying to find default handler -- it usually has Length.
  24838. var cfDict = dict.get('CF');
  24839. var streamCryptoName = dict.get('StmF');
  24840. if (isDict(cfDict) && isName(streamCryptoName)) {
  24841. var handlerDict = cfDict.get(streamCryptoName.name);
  24842. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  24843. if (keyLength < 40) {
  24844. // Sometimes it's incorrect value of bits, generators specify bytes.
  24845. keyLength <<= 3;
  24846. }
  24847. }
  24848. }
  24849. }
  24850. if (!isInt(keyLength) ||
  24851. keyLength < 40 || (keyLength % 8) !== 0) {
  24852. error('invalid key length');
  24853. }
  24854. // prepare keys
  24855. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  24856. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  24857. var flags = dict.get('P');
  24858. var revision = dict.get('R');
  24859. // meaningful when V is 4 or 5
  24860. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  24861. dict.get('EncryptMetadata') !== false);
  24862. this.encryptMetadata = encryptMetadata;
  24863. var fileIdBytes = stringToBytes(fileId);
  24864. var passwordBytes;
  24865. if (password) {
  24866. if (revision === 6) {
  24867. try {
  24868. password = utf8StringToString(password);
  24869. } catch (ex) {
  24870. warn('CipherTransformFactory: ' +
  24871. 'Unable to convert UTF8 encoded password.');
  24872. }
  24873. }
  24874. passwordBytes = stringToBytes(password);
  24875. }
  24876. var encryptionKey;
  24877. if (algorithm !== 5) {
  24878. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  24879. ownerPassword, userPassword, flags,
  24880. revision, keyLength, encryptMetadata);
  24881. }
  24882. else {
  24883. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  24884. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  24885. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  24886. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  24887. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  24888. var ownerEncryption = stringToBytes(dict.get('OE'));
  24889. var userEncryption = stringToBytes(dict.get('UE'));
  24890. var perms = stringToBytes(dict.get('Perms'));
  24891. encryptionKey =
  24892. createEncryptionKey20(revision, passwordBytes,
  24893. ownerPassword, ownerValidationSalt,
  24894. ownerKeySalt, uBytes,
  24895. userPassword, userValidationSalt,
  24896. userKeySalt, ownerEncryption,
  24897. userEncryption, perms);
  24898. }
  24899. if (!encryptionKey && !password) {
  24900. throw new PasswordException('No password given',
  24901. PasswordResponses.NEED_PASSWORD);
  24902. } else if (!encryptionKey && password) {
  24903. // Attempting use the password as an owner password
  24904. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  24905. revision, keyLength);
  24906. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  24907. ownerPassword, userPassword, flags,
  24908. revision, keyLength, encryptMetadata);
  24909. }
  24910. if (!encryptionKey) {
  24911. throw new PasswordException('Incorrect Password',
  24912. PasswordResponses.INCORRECT_PASSWORD);
  24913. }
  24914. this.encryptionKey = encryptionKey;
  24915. if (algorithm >= 4) {
  24916. this.cf = dict.get('CF');
  24917. this.stmf = dict.get('StmF') || identityName;
  24918. this.strf = dict.get('StrF') || identityName;
  24919. this.eff = dict.get('EFF') || this.stmf;
  24920. }
  24921. }
  24922. function buildObjectKey(num, gen, encryptionKey, isAes) {
  24923. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  24924. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  24925. key[i] = encryptionKey[i];
  24926. }
  24927. key[i++] = num & 0xFF;
  24928. key[i++] = (num >> 8) & 0xFF;
  24929. key[i++] = (num >> 16) & 0xFF;
  24930. key[i++] = gen & 0xFF;
  24931. key[i++] = (gen >> 8) & 0xFF;
  24932. if (isAes) {
  24933. key[i++] = 0x73;
  24934. key[i++] = 0x41;
  24935. key[i++] = 0x6C;
  24936. key[i++] = 0x54;
  24937. }
  24938. var hash = calculateMD5(key, 0, i);
  24939. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  24940. }
  24941. function buildCipherConstructor(cf, name, num, gen, key) {
  24942. var cryptFilter = cf.get(name.name);
  24943. var cfm;
  24944. if (cryptFilter !== null && cryptFilter !== undefined) {
  24945. cfm = cryptFilter.get('CFM');
  24946. }
  24947. if (!cfm || cfm.name === 'None') {
  24948. return function cipherTransformFactoryBuildCipherConstructorNone() {
  24949. return new NullCipher();
  24950. };
  24951. }
  24952. if ('V2' === cfm.name) {
  24953. return function cipherTransformFactoryBuildCipherConstructorV2() {
  24954. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  24955. };
  24956. }
  24957. if ('AESV2' === cfm.name) {
  24958. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  24959. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  24960. };
  24961. }
  24962. if ('AESV3' === cfm.name) {
  24963. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  24964. return new AES256Cipher(key);
  24965. };
  24966. }
  24967. error('Unknown crypto method');
  24968. }
  24969. CipherTransformFactory.prototype = {
  24970. createCipherTransform:
  24971. function CipherTransformFactory_createCipherTransform(num, gen) {
  24972. if (this.algorithm === 4 || this.algorithm === 5) {
  24973. return new CipherTransform(
  24974. buildCipherConstructor(this.cf, this.stmf,
  24975. num, gen, this.encryptionKey),
  24976. buildCipherConstructor(this.cf, this.strf,
  24977. num, gen, this.encryptionKey));
  24978. }
  24979. // algorithms 1 and 2
  24980. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  24981. var cipherConstructor = function buildCipherCipherConstructor() {
  24982. return new ARCFourCipher(key);
  24983. };
  24984. return new CipherTransform(cipherConstructor, cipherConstructor);
  24985. }
  24986. };
  24987. return CipherTransformFactory;
  24988. })();
  24989. exports.AES128Cipher = AES128Cipher;
  24990. exports.AES256Cipher = AES256Cipher;
  24991. exports.ARCFourCipher = ARCFourCipher;
  24992. exports.CipherTransformFactory = CipherTransformFactory;
  24993. exports.PDF17 = PDF17;
  24994. exports.PDF20 = PDF20;
  24995. exports.calculateMD5 = calculateMD5;
  24996. exports.calculateSHA256 = calculateSHA256;
  24997. exports.calculateSHA384 = calculateSHA384;
  24998. exports.calculateSHA512 = calculateSHA512;
  24999. }));
  25000. (function (root, factory) {
  25001. {
  25002. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  25003. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings);
  25004. }
  25005. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  25006. coreEncodings) {
  25007. var Util = sharedUtil.Util;
  25008. var bytesToString = sharedUtil.bytesToString;
  25009. var error = sharedUtil.error;
  25010. var Stream = coreStream.Stream;
  25011. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  25012. var StandardEncoding = coreEncodings.StandardEncoding;
  25013. var coreFonts; // see _setCoreFonts below
  25014. var CFFParser; // = coreFonts.CFFParser;
  25015. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25016. function getLong(data, offset) {
  25017. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25018. (data[offset + 2] << 8) | data[offset + 3];
  25019. }
  25020. function getUshort(data, offset) {
  25021. return (data[offset] << 8) | data[offset + 1];
  25022. }
  25023. function parseCmap(data, start, end) {
  25024. var offset = (getUshort(data, start + 2) === 1 ?
  25025. getLong(data, start + 8) : getLong(data, start + 16));
  25026. var format = getUshort(data, start + offset);
  25027. var length, ranges, p, i;
  25028. if (format === 4) {
  25029. length = getUshort(data, start + offset + 2);
  25030. var segCount = getUshort(data, start + offset + 6) >> 1;
  25031. p = start + offset + 14;
  25032. ranges = [];
  25033. for (i = 0; i < segCount; i++, p += 2) {
  25034. ranges[i] = {end: getUshort(data, p)};
  25035. }
  25036. p += 2;
  25037. for (i = 0; i < segCount; i++, p += 2) {
  25038. ranges[i].start = getUshort(data, p);
  25039. }
  25040. for (i = 0; i < segCount; i++, p += 2) {
  25041. ranges[i].idDelta = getUshort(data, p);
  25042. }
  25043. for (i = 0; i < segCount; i++, p += 2) {
  25044. var idOffset = getUshort(data, p);
  25045. if (idOffset === 0) {
  25046. continue;
  25047. }
  25048. ranges[i].ids = [];
  25049. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25050. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25051. idOffset += 2;
  25052. }
  25053. }
  25054. return ranges;
  25055. } else if (format === 12) {
  25056. length = getLong(data, start + offset + 4);
  25057. var groups = getLong(data, start + offset + 12);
  25058. p = start + offset + 16;
  25059. ranges = [];
  25060. for (i = 0; i < groups; i++) {
  25061. ranges.push({
  25062. start: getLong(data, p),
  25063. end: getLong(data, p + 4),
  25064. idDelta: getLong(data, p + 8) - getLong(data, p)
  25065. });
  25066. p += 12;
  25067. }
  25068. return ranges;
  25069. }
  25070. error('not supported cmap: ' + format);
  25071. }
  25072. function parseCff(data, start, end) {
  25073. var properties = {};
  25074. var parser = new CFFParser(new Stream(data, start, end - start),
  25075. properties);
  25076. var cff = parser.parse();
  25077. return {
  25078. glyphs: cff.charStrings.objects,
  25079. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25080. cff.topDict.privateDict.subrsIndex.objects),
  25081. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25082. };
  25083. }
  25084. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25085. var itemSize, itemDecode;
  25086. if (isGlyphLocationsLong) {
  25087. itemSize = 4;
  25088. itemDecode = function fontItemDecodeLong(data, offset) {
  25089. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25090. (data[offset + 2] << 8) | data[offset + 3];
  25091. };
  25092. } else {
  25093. itemSize = 2;
  25094. itemDecode = function fontItemDecode(data, offset) {
  25095. return (data[offset] << 9) | (data[offset + 1] << 1);
  25096. };
  25097. }
  25098. var glyphs = [];
  25099. var startOffset = itemDecode(loca, 0);
  25100. for (var j = itemSize; j < loca.length; j += itemSize) {
  25101. var endOffset = itemDecode(loca, j);
  25102. glyphs.push(glyf.subarray(startOffset, endOffset));
  25103. startOffset = endOffset;
  25104. }
  25105. return glyphs;
  25106. }
  25107. function lookupCmap(ranges, unicode) {
  25108. var code = unicode.charCodeAt(0);
  25109. var l = 0, r = ranges.length - 1;
  25110. while (l < r) {
  25111. var c = (l + r + 1) >> 1;
  25112. if (code < ranges[c].start) {
  25113. r = c - 1;
  25114. } else {
  25115. l = c;
  25116. }
  25117. }
  25118. if (ranges[l].start <= code && code <= ranges[l].end) {
  25119. return (ranges[l].idDelta + (ranges[l].ids ?
  25120. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25121. }
  25122. return 0;
  25123. }
  25124. function compileGlyf(code, cmds, font) {
  25125. function moveTo(x, y) {
  25126. cmds.push({cmd: 'moveTo', args: [x, y]});
  25127. }
  25128. function lineTo(x, y) {
  25129. cmds.push({cmd: 'lineTo', args: [x, y]});
  25130. }
  25131. function quadraticCurveTo(xa, ya, x, y) {
  25132. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25133. }
  25134. var i = 0;
  25135. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25136. var flags;
  25137. var x = 0, y = 0;
  25138. i += 10;
  25139. if (numberOfContours < 0) {
  25140. // composite glyph
  25141. do {
  25142. flags = (code[i] << 8) | code[i + 1];
  25143. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25144. i += 4;
  25145. var arg1, arg2;
  25146. if ((flags & 0x01)) {
  25147. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25148. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25149. i += 4;
  25150. } else {
  25151. arg1 = code[i++]; arg2 = code[i++];
  25152. }
  25153. if ((flags & 0x02)) {
  25154. x = arg1;
  25155. y = arg2;
  25156. } else {
  25157. x = 0; y = 0; // TODO "they are points" ?
  25158. }
  25159. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25160. if ((flags & 0x08)) {
  25161. scaleX =
  25162. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25163. i += 2;
  25164. } else if ((flags & 0x40)) {
  25165. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25166. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25167. i += 4;
  25168. } else if ((flags & 0x80)) {
  25169. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25170. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25171. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25172. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25173. i += 8;
  25174. }
  25175. var subglyph = font.glyphs[glyphIndex];
  25176. if (subglyph) {
  25177. cmds.push({cmd: 'save'});
  25178. cmds.push({cmd: 'transform',
  25179. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25180. compileGlyf(subglyph, cmds, font);
  25181. cmds.push({cmd: 'restore'});
  25182. }
  25183. } while ((flags & 0x20));
  25184. } else {
  25185. // simple glyph
  25186. var endPtsOfContours = [];
  25187. var j, jj;
  25188. for (j = 0; j < numberOfContours; j++) {
  25189. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25190. i += 2;
  25191. }
  25192. var instructionLength = (code[i] << 8) | code[i + 1];
  25193. i += 2 + instructionLength; // skipping the instructions
  25194. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25195. var points = [];
  25196. while (points.length < numberOfPoints) {
  25197. flags = code[i++];
  25198. var repeat = 1;
  25199. if ((flags & 0x08)) {
  25200. repeat += code[i++];
  25201. }
  25202. while (repeat-- > 0) {
  25203. points.push({flags: flags});
  25204. }
  25205. }
  25206. for (j = 0; j < numberOfPoints; j++) {
  25207. switch (points[j].flags & 0x12) {
  25208. case 0x00:
  25209. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25210. i += 2;
  25211. break;
  25212. case 0x02:
  25213. x -= code[i++];
  25214. break;
  25215. case 0x12:
  25216. x += code[i++];
  25217. break;
  25218. }
  25219. points[j].x = x;
  25220. }
  25221. for (j = 0; j < numberOfPoints; j++) {
  25222. switch (points[j].flags & 0x24) {
  25223. case 0x00:
  25224. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25225. i += 2;
  25226. break;
  25227. case 0x04:
  25228. y -= code[i++];
  25229. break;
  25230. case 0x24:
  25231. y += code[i++];
  25232. break;
  25233. }
  25234. points[j].y = y;
  25235. }
  25236. var startPoint = 0;
  25237. for (i = 0; i < numberOfContours; i++) {
  25238. var endPoint = endPtsOfContours[i];
  25239. // contours might have implicit points, which is located in the middle
  25240. // between two neighboring off-curve points
  25241. var contour = points.slice(startPoint, endPoint + 1);
  25242. if ((contour[0].flags & 1)) {
  25243. contour.push(contour[0]); // using start point at the contour end
  25244. } else if ((contour[contour.length - 1].flags & 1)) {
  25245. // first is off-curve point, trying to use one from the end
  25246. contour.unshift(contour[contour.length - 1]);
  25247. } else {
  25248. // start and end are off-curve points, creating implicit one
  25249. var p = {
  25250. flags: 1,
  25251. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25252. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25253. };
  25254. contour.unshift(p);
  25255. contour.push(p);
  25256. }
  25257. moveTo(contour[0].x, contour[0].y);
  25258. for (j = 1, jj = contour.length; j < jj; j++) {
  25259. if ((contour[j].flags & 1)) {
  25260. lineTo(contour[j].x, contour[j].y);
  25261. } else if ((contour[j + 1].flags & 1)){
  25262. quadraticCurveTo(contour[j].x, contour[j].y,
  25263. contour[j + 1].x, contour[j + 1].y);
  25264. j++;
  25265. } else {
  25266. quadraticCurveTo(contour[j].x, contour[j].y,
  25267. (contour[j].x + contour[j + 1].x) / 2,
  25268. (contour[j].y + contour[j + 1].y) / 2);
  25269. }
  25270. }
  25271. startPoint = endPoint + 1;
  25272. }
  25273. }
  25274. }
  25275. function compileCharString(code, cmds, font) {
  25276. var stack = [];
  25277. var x = 0, y = 0;
  25278. var stems = 0;
  25279. function moveTo(x, y) {
  25280. cmds.push({cmd: 'moveTo', args: [x, y]});
  25281. }
  25282. function lineTo(x, y) {
  25283. cmds.push({cmd: 'lineTo', args: [x, y]});
  25284. }
  25285. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25286. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  25287. }
  25288. function parse(code) {
  25289. var i = 0;
  25290. while (i < code.length) {
  25291. var stackClean = false;
  25292. var v = code[i++];
  25293. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25294. switch (v) {
  25295. case 1: // hstem
  25296. stems += stack.length >> 1;
  25297. stackClean = true;
  25298. break;
  25299. case 3: // vstem
  25300. stems += stack.length >> 1;
  25301. stackClean = true;
  25302. break;
  25303. case 4: // vmoveto
  25304. y += stack.pop();
  25305. moveTo(x, y);
  25306. stackClean = true;
  25307. break;
  25308. case 5: // rlineto
  25309. while (stack.length > 0) {
  25310. x += stack.shift();
  25311. y += stack.shift();
  25312. lineTo(x, y);
  25313. }
  25314. break;
  25315. case 6: // hlineto
  25316. while (stack.length > 0) {
  25317. x += stack.shift();
  25318. lineTo(x, y);
  25319. if (stack.length === 0) {
  25320. break;
  25321. }
  25322. y += stack.shift();
  25323. lineTo(x, y);
  25324. }
  25325. break;
  25326. case 7: // vlineto
  25327. while (stack.length > 0) {
  25328. y += stack.shift();
  25329. lineTo(x, y);
  25330. if (stack.length === 0) {
  25331. break;
  25332. }
  25333. x += stack.shift();
  25334. lineTo(x, y);
  25335. }
  25336. break;
  25337. case 8: // rrcurveto
  25338. while (stack.length > 0) {
  25339. xa = x + stack.shift(); ya = y + stack.shift();
  25340. xb = xa + stack.shift(); yb = ya + stack.shift();
  25341. x = xb + stack.shift(); y = yb + stack.shift();
  25342. bezierCurveTo(xa, ya, xb, yb, x, y);
  25343. }
  25344. break;
  25345. case 10: // callsubr
  25346. n = stack.pop() + font.subrsBias;
  25347. subrCode = font.subrs[n];
  25348. if (subrCode) {
  25349. parse(subrCode);
  25350. }
  25351. break;
  25352. case 11: // return
  25353. return;
  25354. case 12:
  25355. v = code[i++];
  25356. switch (v) {
  25357. case 34: // flex
  25358. xa = x + stack.shift();
  25359. xb = xa + stack.shift(); y1 = y + stack.shift();
  25360. x = xb + stack.shift();
  25361. bezierCurveTo(xa, y, xb, y1, x, y1);
  25362. xa = x + stack.shift();
  25363. xb = xa + stack.shift();
  25364. x = xb + stack.shift();
  25365. bezierCurveTo(xa, y1, xb, y, x, y);
  25366. break;
  25367. case 35: // flex
  25368. xa = x + stack.shift(); ya = y + stack.shift();
  25369. xb = xa + stack.shift(); yb = ya + stack.shift();
  25370. x = xb + stack.shift(); y = yb + stack.shift();
  25371. bezierCurveTo(xa, ya, xb, yb, x, y);
  25372. xa = x + stack.shift(); ya = y + stack.shift();
  25373. xb = xa + stack.shift(); yb = ya + stack.shift();
  25374. x = xb + stack.shift(); y = yb + stack.shift();
  25375. bezierCurveTo(xa, ya, xb, yb, x, y);
  25376. stack.pop(); // fd
  25377. break;
  25378. case 36: // hflex1
  25379. xa = x + stack.shift(); y1 = y + stack.shift();
  25380. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25381. x = xb + stack.shift();
  25382. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25383. xa = x + stack.shift();
  25384. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25385. x = xb + stack.shift();
  25386. bezierCurveTo(xa, y2, xb, y3, x, y);
  25387. break;
  25388. case 37: // flex1
  25389. var x0 = x, y0 = y;
  25390. xa = x + stack.shift(); ya = y + stack.shift();
  25391. xb = xa + stack.shift(); yb = ya + stack.shift();
  25392. x = xb + stack.shift(); y = yb + stack.shift();
  25393. bezierCurveTo(xa, ya, xb, yb, x, y);
  25394. xa = x + stack.shift(); ya = y + stack.shift();
  25395. xb = xa + stack.shift(); yb = ya + stack.shift();
  25396. x = xb; y = yb;
  25397. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25398. x += stack.shift();
  25399. } else {
  25400. y += stack.shift();
  25401. }
  25402. bezierCurveTo(xa, ya, xb, yb, x, y);
  25403. break;
  25404. default:
  25405. error('unknown operator: 12 ' + v);
  25406. }
  25407. break;
  25408. case 14: // endchar
  25409. if (stack.length >= 4) {
  25410. var achar = stack.pop();
  25411. var bchar = stack.pop();
  25412. y = stack.pop();
  25413. x = stack.pop();
  25414. cmds.push({cmd: 'save'});
  25415. cmds.push({cmd: 'translate', args: [x, y]});
  25416. var gid = lookupCmap(font.cmap, String.fromCharCode(
  25417. font.glyphNameMap[StandardEncoding[achar]]));
  25418. compileCharString(font.glyphs[gid], cmds, font);
  25419. cmds.push({cmd: 'restore'});
  25420. gid = lookupCmap(font.cmap, String.fromCharCode(
  25421. font.glyphNameMap[StandardEncoding[bchar]]));
  25422. compileCharString(font.glyphs[gid], cmds, font);
  25423. }
  25424. return;
  25425. case 18: // hstemhm
  25426. stems += stack.length >> 1;
  25427. stackClean = true;
  25428. break;
  25429. case 19: // hintmask
  25430. stems += stack.length >> 1;
  25431. i += (stems + 7) >> 3;
  25432. stackClean = true;
  25433. break;
  25434. case 20: // cntrmask
  25435. stems += stack.length >> 1;
  25436. i += (stems + 7) >> 3;
  25437. stackClean = true;
  25438. break;
  25439. case 21: // rmoveto
  25440. y += stack.pop();
  25441. x += stack.pop();
  25442. moveTo(x, y);
  25443. stackClean = true;
  25444. break;
  25445. case 22: // hmoveto
  25446. x += stack.pop();
  25447. moveTo(x, y);
  25448. stackClean = true;
  25449. break;
  25450. case 23: // vstemhm
  25451. stems += stack.length >> 1;
  25452. stackClean = true;
  25453. break;
  25454. case 24: // rcurveline
  25455. while (stack.length > 2) {
  25456. xa = x + stack.shift(); ya = y + stack.shift();
  25457. xb = xa + stack.shift(); yb = ya + stack.shift();
  25458. x = xb + stack.shift(); y = yb + stack.shift();
  25459. bezierCurveTo(xa, ya, xb, yb, x, y);
  25460. }
  25461. x += stack.shift();
  25462. y += stack.shift();
  25463. lineTo(x, y);
  25464. break;
  25465. case 25: // rlinecurve
  25466. while (stack.length > 6) {
  25467. x += stack.shift();
  25468. y += stack.shift();
  25469. lineTo(x, y);
  25470. }
  25471. xa = x + stack.shift(); ya = y + stack.shift();
  25472. xb = xa + stack.shift(); yb = ya + stack.shift();
  25473. x = xb + stack.shift(); y = yb + stack.shift();
  25474. bezierCurveTo(xa, ya, xb, yb, x, y);
  25475. break;
  25476. case 26: // vvcurveto
  25477. if (stack.length % 2) {
  25478. x += stack.shift();
  25479. }
  25480. while (stack.length > 0) {
  25481. xa = x; ya = y + stack.shift();
  25482. xb = xa + stack.shift(); yb = ya + stack.shift();
  25483. x = xb; y = yb + stack.shift();
  25484. bezierCurveTo(xa, ya, xb, yb, x, y);
  25485. }
  25486. break;
  25487. case 27: // hhcurveto
  25488. if (stack.length % 2) {
  25489. y += stack.shift();
  25490. }
  25491. while (stack.length > 0) {
  25492. xa = x + stack.shift(); ya = y;
  25493. xb = xa + stack.shift(); yb = ya + stack.shift();
  25494. x = xb + stack.shift(); y = yb;
  25495. bezierCurveTo(xa, ya, xb, yb, x, y);
  25496. }
  25497. break;
  25498. case 28:
  25499. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25500. i += 2;
  25501. break;
  25502. case 29: // callgsubr
  25503. n = stack.pop() + font.gsubrsBias;
  25504. subrCode = font.gsubrs[n];
  25505. if (subrCode) {
  25506. parse(subrCode);
  25507. }
  25508. break;
  25509. case 30: // vhcurveto
  25510. while (stack.length > 0) {
  25511. xa = x; ya = y + stack.shift();
  25512. xb = xa + stack.shift(); yb = ya + stack.shift();
  25513. x = xb + stack.shift();
  25514. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25515. bezierCurveTo(xa, ya, xb, yb, x, y);
  25516. if (stack.length === 0) {
  25517. break;
  25518. }
  25519. xa = x + stack.shift(); ya = y;
  25520. xb = xa + stack.shift(); yb = ya + stack.shift();
  25521. y = yb + stack.shift();
  25522. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25523. bezierCurveTo(xa, ya, xb, yb, x, y);
  25524. }
  25525. break;
  25526. case 31: // hvcurveto
  25527. while (stack.length > 0) {
  25528. xa = x + stack.shift(); ya = y;
  25529. xb = xa + stack.shift(); yb = ya + stack.shift();
  25530. y = yb + stack.shift();
  25531. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25532. bezierCurveTo(xa, ya, xb, yb, x, y);
  25533. if (stack.length === 0) {
  25534. break;
  25535. }
  25536. xa = x; ya = y + stack.shift();
  25537. xb = xa + stack.shift(); yb = ya + stack.shift();
  25538. x = xb + stack.shift();
  25539. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25540. bezierCurveTo(xa, ya, xb, yb, x, y);
  25541. }
  25542. break;
  25543. default:
  25544. if (v < 32) {
  25545. error('unknown operator: ' + v);
  25546. }
  25547. if (v < 247) {
  25548. stack.push(v - 139);
  25549. } else if (v < 251) {
  25550. stack.push((v - 247) * 256 + code[i++] + 108);
  25551. } else if (v < 255) {
  25552. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25553. } else {
  25554. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25555. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25556. i += 4;
  25557. }
  25558. break;
  25559. }
  25560. if (stackClean) {
  25561. stack.length = 0;
  25562. }
  25563. }
  25564. }
  25565. parse(code);
  25566. }
  25567. var noop = '';
  25568. function CompiledFont(fontMatrix) {
  25569. this.compiledGlyphs = Object.create(null);
  25570. this.fontMatrix = fontMatrix;
  25571. }
  25572. CompiledFont.prototype = {
  25573. getPathJs: function (unicode) {
  25574. var gid = lookupCmap(this.cmap, unicode);
  25575. var fn = this.compiledGlyphs[gid];
  25576. if (!fn) {
  25577. this.compiledGlyphs[gid] = fn = this.compileGlyph(this.glyphs[gid]);
  25578. }
  25579. return fn;
  25580. },
  25581. compileGlyph: function (code) {
  25582. if (!code || code.length === 0 || code[0] === 14) {
  25583. return noop;
  25584. }
  25585. var cmds = [];
  25586. cmds.push({cmd: 'save'});
  25587. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  25588. cmds.push({cmd: 'scale', args: ['size', '-size']});
  25589. this.compileGlyphImpl(code, cmds);
  25590. cmds.push({cmd: 'restore'});
  25591. return cmds;
  25592. },
  25593. compileGlyphImpl: function () {
  25594. error('Children classes should implement this.');
  25595. },
  25596. hasBuiltPath: function (unicode) {
  25597. var gid = lookupCmap(this.cmap, unicode);
  25598. return gid in this.compiledGlyphs;
  25599. }
  25600. };
  25601. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25602. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25603. CompiledFont.call(this, fontMatrix);
  25604. this.glyphs = glyphs;
  25605. this.cmap = cmap;
  25606. this.compiledGlyphs = [];
  25607. }
  25608. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25609. compileGlyphImpl: function (code, cmds) {
  25610. compileGlyf(code, cmds, this);
  25611. }
  25612. });
  25613. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25614. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25615. CompiledFont.call(this, fontMatrix);
  25616. this.glyphs = cffInfo.glyphs;
  25617. this.gsubrs = cffInfo.gsubrs || [];
  25618. this.subrs = cffInfo.subrs || [];
  25619. this.cmap = cmap;
  25620. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  25621. this.compiledGlyphs = [];
  25622. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25623. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25624. this.subrsBias = (this.subrs.length < 1240 ?
  25625. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25626. }
  25627. Util.inherit(Type2Compiled, CompiledFont, {
  25628. compileGlyphImpl: function (code, cmds) {
  25629. compileCharString(code, cmds, this);
  25630. }
  25631. });
  25632. return {
  25633. create: function FontRendererFactory_create(font) {
  25634. var data = new Uint8Array(font.data);
  25635. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25636. var numTables = getUshort(data, 4);
  25637. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25638. var tag = bytesToString(data.subarray(p, p + 4));
  25639. var offset = getLong(data, p + 8);
  25640. var length = getLong(data, p + 12);
  25641. switch (tag) {
  25642. case 'cmap':
  25643. cmap = parseCmap(data, offset, offset + length);
  25644. break;
  25645. case 'glyf':
  25646. glyf = data.subarray(offset, offset + length);
  25647. break;
  25648. case 'loca':
  25649. loca = data.subarray(offset, offset + length);
  25650. break;
  25651. case 'head':
  25652. unitsPerEm = getUshort(data, offset + 18);
  25653. indexToLocFormat = getUshort(data, offset + 50);
  25654. break;
  25655. case 'CFF ':
  25656. cff = parseCff(data, offset, offset + length);
  25657. break;
  25658. }
  25659. }
  25660. if (glyf) {
  25661. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25662. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25663. return new TrueTypeCompiled(
  25664. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25665. } else {
  25666. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25667. }
  25668. }
  25669. };
  25670. })();
  25671. // TODO refactor to remove cyclic dependency on fonts.js
  25672. function _setCoreFonts(coreFonts_) {
  25673. coreFonts = coreFonts_;
  25674. CFFParser = coreFonts_.CFFParser;
  25675. }
  25676. exports._setCoreFonts = _setCoreFonts;
  25677. exports.FontRendererFactory = FontRendererFactory;
  25678. }));
  25679. (function (root, factory) {
  25680. {
  25681. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  25682. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  25683. }
  25684. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  25685. var MissingDataException = sharedUtil.MissingDataException;
  25686. var StreamType = sharedUtil.StreamType;
  25687. var assert = sharedUtil.assert;
  25688. var error = sharedUtil.error;
  25689. var info = sharedUtil.info;
  25690. var isArray = sharedUtil.isArray;
  25691. var isInt = sharedUtil.isInt;
  25692. var isNum = sharedUtil.isNum;
  25693. var isString = sharedUtil.isString;
  25694. var warn = sharedUtil.warn;
  25695. var Cmd = corePrimitives.Cmd;
  25696. var Dict = corePrimitives.Dict;
  25697. var Name = corePrimitives.Name;
  25698. var Ref = corePrimitives.Ref;
  25699. var isCmd = corePrimitives.isCmd;
  25700. var isDict = corePrimitives.isDict;
  25701. var isName = corePrimitives.isName;
  25702. var Ascii85Stream = coreStream.Ascii85Stream;
  25703. var AsciiHexStream = coreStream.AsciiHexStream;
  25704. var CCITTFaxStream = coreStream.CCITTFaxStream;
  25705. var FlateStream = coreStream.FlateStream;
  25706. var Jbig2Stream = coreStream.Jbig2Stream;
  25707. var JpegStream = coreStream.JpegStream;
  25708. var JpxStream = coreStream.JpxStream;
  25709. var LZWStream = coreStream.LZWStream;
  25710. var NullStream = coreStream.NullStream;
  25711. var PredictorStream = coreStream.PredictorStream;
  25712. var RunLengthStream = coreStream.RunLengthStream;
  25713. var EOF = {};
  25714. function isEOF(v) {
  25715. return (v === EOF);
  25716. }
  25717. var MAX_LENGTH_TO_CACHE = 1000;
  25718. var Parser = (function ParserClosure() {
  25719. function Parser(lexer, allowStreams, xref) {
  25720. this.lexer = lexer;
  25721. this.allowStreams = allowStreams;
  25722. this.xref = xref;
  25723. this.imageCache = Object.create(null);
  25724. this.refill();
  25725. }
  25726. Parser.prototype = {
  25727. refill: function Parser_refill() {
  25728. this.buf1 = this.lexer.getObj();
  25729. this.buf2 = this.lexer.getObj();
  25730. },
  25731. shift: function Parser_shift() {
  25732. if (isCmd(this.buf2, 'ID')) {
  25733. this.buf1 = this.buf2;
  25734. this.buf2 = null;
  25735. } else {
  25736. this.buf1 = this.buf2;
  25737. this.buf2 = this.lexer.getObj();
  25738. }
  25739. },
  25740. tryShift: function Parser_tryShift() {
  25741. try {
  25742. this.shift();
  25743. return true;
  25744. } catch (e) {
  25745. if (e instanceof MissingDataException) {
  25746. throw e;
  25747. }
  25748. // Upon failure, the caller should reset this.lexer.pos to a known good
  25749. // state and call this.shift() twice to reset the buffers.
  25750. return false;
  25751. }
  25752. },
  25753. getObj: function Parser_getObj(cipherTransform) {
  25754. var buf1 = this.buf1;
  25755. this.shift();
  25756. if (buf1 instanceof Cmd) {
  25757. switch (buf1.cmd) {
  25758. case 'BI': // inline image
  25759. return this.makeInlineImage(cipherTransform);
  25760. case '[': // array
  25761. var array = [];
  25762. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  25763. array.push(this.getObj(cipherTransform));
  25764. }
  25765. if (isEOF(this.buf1)) {
  25766. error('End of file inside array');
  25767. }
  25768. this.shift();
  25769. return array;
  25770. case '<<': // dictionary or stream
  25771. var dict = new Dict(this.xref);
  25772. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  25773. if (!isName(this.buf1)) {
  25774. info('Malformed dictionary: key must be a name object');
  25775. this.shift();
  25776. continue;
  25777. }
  25778. var key = this.buf1.name;
  25779. this.shift();
  25780. if (isEOF(this.buf1)) {
  25781. break;
  25782. }
  25783. dict.set(key, this.getObj(cipherTransform));
  25784. }
  25785. if (isEOF(this.buf1)) {
  25786. error('End of file inside dictionary');
  25787. }
  25788. // Stream objects are not allowed inside content streams or
  25789. // object streams.
  25790. if (isCmd(this.buf2, 'stream')) {
  25791. return (this.allowStreams ?
  25792. this.makeStream(dict, cipherTransform) : dict);
  25793. }
  25794. this.shift();
  25795. return dict;
  25796. default: // simple object
  25797. return buf1;
  25798. }
  25799. }
  25800. if (isInt(buf1)) { // indirect reference or integer
  25801. var num = buf1;
  25802. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  25803. var ref = new Ref(num, this.buf1);
  25804. this.shift();
  25805. this.shift();
  25806. return ref;
  25807. }
  25808. return num;
  25809. }
  25810. if (isString(buf1)) { // string
  25811. var str = buf1;
  25812. if (cipherTransform) {
  25813. str = cipherTransform.decryptString(str);
  25814. }
  25815. return str;
  25816. }
  25817. // simple object
  25818. return buf1;
  25819. },
  25820. /**
  25821. * Find the end of the stream by searching for the /EI\s/.
  25822. * @returns {number} The inline stream length.
  25823. */
  25824. findDefaultInlineStreamEnd:
  25825. function Parser_findDefaultInlineStreamEnd(stream) {
  25826. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  25827. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  25828. while ((ch = stream.getByte()) !== -1) {
  25829. if (state === 0) {
  25830. state = (ch === E) ? 1 : 0;
  25831. } else if (state === 1) {
  25832. state = (ch === I) ? 2 : 0;
  25833. } else {
  25834. assert(state === 2);
  25835. if (ch === SPACE || ch === LF || ch === CR) {
  25836. // Let's check the next five bytes are ASCII... just be sure.
  25837. n = 5;
  25838. followingBytes = stream.peekBytes(n);
  25839. for (i = 0; i < n; i++) {
  25840. ch = followingBytes[i];
  25841. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  25842. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  25843. // it's binary stuff. Resetting the state.
  25844. state = 0;
  25845. break;
  25846. }
  25847. }
  25848. if (state === 2) {
  25849. break; // Finished!
  25850. }
  25851. } else {
  25852. state = 0;
  25853. }
  25854. }
  25855. }
  25856. return ((stream.pos - 4) - startPos);
  25857. },
  25858. /**
  25859. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  25860. * @returns {number} The inline stream length.
  25861. */
  25862. findDCTDecodeInlineStreamEnd:
  25863. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  25864. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  25865. while ((b = stream.getByte()) !== -1) {
  25866. if (b !== 0xFF) { // Not a valid marker.
  25867. continue;
  25868. }
  25869. switch (stream.getByte()) {
  25870. case 0x00: // Byte stuffing.
  25871. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  25872. break;
  25873. case 0xFF: // Fill byte.
  25874. // Avoid skipping a valid marker, resetting the stream position.
  25875. stream.skip(-1);
  25876. break;
  25877. case 0xD9: // EOI
  25878. foundEOI = true;
  25879. break;
  25880. case 0xC0: // SOF0
  25881. case 0xC1: // SOF1
  25882. case 0xC2: // SOF2
  25883. case 0xC3: // SOF3
  25884. case 0xC5: // SOF5
  25885. case 0xC6: // SOF6
  25886. case 0xC7: // SOF7
  25887. case 0xC9: // SOF9
  25888. case 0xCA: // SOF10
  25889. case 0xCB: // SOF11
  25890. case 0xCD: // SOF13
  25891. case 0xCE: // SOF14
  25892. case 0xCF: // SOF15
  25893. case 0xC4: // DHT
  25894. case 0xCC: // DAC
  25895. case 0xDA: // SOS
  25896. case 0xDB: // DQT
  25897. case 0xDC: // DNL
  25898. case 0xDD: // DRI
  25899. case 0xDE: // DHP
  25900. case 0xDF: // EXP
  25901. case 0xE0: // APP0
  25902. case 0xE1: // APP1
  25903. case 0xE2: // APP2
  25904. case 0xE3: // APP3
  25905. case 0xE4: // APP4
  25906. case 0xE5: // APP5
  25907. case 0xE6: // APP6
  25908. case 0xE7: // APP7
  25909. case 0xE8: // APP8
  25910. case 0xE9: // APP9
  25911. case 0xEA: // APP10
  25912. case 0xEB: // APP11
  25913. case 0xEC: // APP12
  25914. case 0xED: // APP13
  25915. case 0xEE: // APP14
  25916. case 0xEF: // APP15
  25917. case 0xFE: // COM
  25918. // The marker should be followed by the length of the segment.
  25919. markerLength = stream.getUint16();
  25920. if (markerLength > 2) {
  25921. // |markerLength| contains the byte length of the marker segment,
  25922. // including its own length (2 bytes) and excluding the marker.
  25923. stream.skip(markerLength - 2); // Jump to the next marker.
  25924. } else {
  25925. // The marker length is invalid, resetting the stream position.
  25926. stream.skip(-2);
  25927. }
  25928. break;
  25929. }
  25930. if (foundEOI) {
  25931. break;
  25932. }
  25933. }
  25934. length = stream.pos - startPos;
  25935. if (b === -1) {
  25936. warn('Inline DCTDecode image stream: ' +
  25937. 'EOI marker not found, searching for /EI/ instead.');
  25938. stream.skip(-length); // Reset the stream position.
  25939. return this.findDefaultInlineStreamEnd(stream);
  25940. }
  25941. this.inlineStreamSkipEI(stream);
  25942. return length;
  25943. },
  25944. /**
  25945. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  25946. * @returns {number} The inline stream length.
  25947. */
  25948. findASCII85DecodeInlineStreamEnd:
  25949. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  25950. var TILDE = 0x7E, GT = 0x3E;
  25951. var startPos = stream.pos, ch, length;
  25952. while ((ch = stream.getByte()) !== -1) {
  25953. if (ch === TILDE && stream.peekByte() === GT) {
  25954. stream.skip();
  25955. break;
  25956. }
  25957. }
  25958. length = stream.pos - startPos;
  25959. if (ch === -1) {
  25960. warn('Inline ASCII85Decode image stream: ' +
  25961. 'EOD marker not found, searching for /EI/ instead.');
  25962. stream.skip(-length); // Reset the stream position.
  25963. return this.findDefaultInlineStreamEnd(stream);
  25964. }
  25965. this.inlineStreamSkipEI(stream);
  25966. return length;
  25967. },
  25968. /**
  25969. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  25970. * @returns {number} The inline stream length.
  25971. */
  25972. findASCIIHexDecodeInlineStreamEnd:
  25973. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  25974. var GT = 0x3E;
  25975. var startPos = stream.pos, ch, length;
  25976. while ((ch = stream.getByte()) !== -1) {
  25977. if (ch === GT) {
  25978. break;
  25979. }
  25980. }
  25981. length = stream.pos - startPos;
  25982. if (ch === -1) {
  25983. warn('Inline ASCIIHexDecode image stream: ' +
  25984. 'EOD marker not found, searching for /EI/ instead.');
  25985. stream.skip(-length); // Reset the stream position.
  25986. return this.findDefaultInlineStreamEnd(stream);
  25987. }
  25988. this.inlineStreamSkipEI(stream);
  25989. return length;
  25990. },
  25991. /**
  25992. * Skip over the /EI/ for streams where we search for an EOD marker.
  25993. */
  25994. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  25995. var E = 0x45, I = 0x49;
  25996. var state = 0, ch;
  25997. while ((ch = stream.getByte()) !== -1) {
  25998. if (state === 0) {
  25999. state = (ch === E) ? 1 : 0;
  26000. } else if (state === 1) {
  26001. state = (ch === I) ? 2 : 0;
  26002. } else if (state === 2) {
  26003. break;
  26004. }
  26005. }
  26006. },
  26007. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  26008. var lexer = this.lexer;
  26009. var stream = lexer.stream;
  26010. // Parse dictionary.
  26011. var dict = new Dict(this.xref);
  26012. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  26013. if (!isName(this.buf1)) {
  26014. error('Dictionary key must be a name object');
  26015. }
  26016. var key = this.buf1.name;
  26017. this.shift();
  26018. if (isEOF(this.buf1)) {
  26019. break;
  26020. }
  26021. dict.set(key, this.getObj(cipherTransform));
  26022. }
  26023. // Extract the name of the first (i.e. the current) image filter.
  26024. var filter = dict.get('Filter', 'F'), filterName;
  26025. if (isName(filter)) {
  26026. filterName = filter.name;
  26027. } else if (isArray(filter) && isName(filter[0])) {
  26028. filterName = filter[0].name;
  26029. }
  26030. // Parse image stream.
  26031. var startPos = stream.pos, length, i, ii;
  26032. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  26033. length = this.findDCTDecodeInlineStreamEnd(stream);
  26034. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  26035. length = this.findASCII85DecodeInlineStreamEnd(stream);
  26036. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  26037. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  26038. } else {
  26039. length = this.findDefaultInlineStreamEnd(stream);
  26040. }
  26041. var imageStream = stream.makeSubStream(startPos, length, dict);
  26042. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  26043. // adler32 checksum.
  26044. var adler32;
  26045. if (length < MAX_LENGTH_TO_CACHE) {
  26046. var imageBytes = imageStream.getBytes();
  26047. imageStream.reset();
  26048. var a = 1;
  26049. var b = 0;
  26050. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  26051. // No modulo required in the loop if imageBytes.length < 5552.
  26052. a += imageBytes[i] & 0xff;
  26053. b += a;
  26054. }
  26055. adler32 = ((b % 65521) << 16) | (a % 65521);
  26056. if (this.imageCache.adler32 === adler32) {
  26057. this.buf2 = Cmd.get('EI');
  26058. this.shift();
  26059. this.imageCache[adler32].reset();
  26060. return this.imageCache[adler32];
  26061. }
  26062. }
  26063. if (cipherTransform) {
  26064. imageStream = cipherTransform.createStream(imageStream, length);
  26065. }
  26066. imageStream = this.filter(imageStream, dict, length);
  26067. imageStream.dict = dict;
  26068. if (adler32 !== undefined) {
  26069. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  26070. this.imageCache[adler32] = imageStream;
  26071. }
  26072. this.buf2 = Cmd.get('EI');
  26073. this.shift();
  26074. return imageStream;
  26075. },
  26076. makeStream: function Parser_makeStream(dict, cipherTransform) {
  26077. var lexer = this.lexer;
  26078. var stream = lexer.stream;
  26079. // get stream start position
  26080. lexer.skipToNextLine();
  26081. var pos = stream.pos - 1;
  26082. // get length
  26083. var length = dict.get('Length');
  26084. if (!isInt(length)) {
  26085. info('Bad ' + length + ' attribute in stream');
  26086. length = 0;
  26087. }
  26088. // skip over the stream data
  26089. stream.pos = pos + length;
  26090. lexer.nextChar();
  26091. // Shift '>>' and check whether the new object marks the end of the stream
  26092. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26093. this.shift(); // 'stream'
  26094. } else {
  26095. // bad stream length, scanning for endstream
  26096. stream.pos = pos;
  26097. var SCAN_BLOCK_SIZE = 2048;
  26098. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26099. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26100. 0x61, 0x6D];
  26101. var skipped = 0, found = false, i, j;
  26102. while (stream.pos < stream.end) {
  26103. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26104. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26105. if (scanLength <= 0) {
  26106. break;
  26107. }
  26108. found = false;
  26109. i = 0;
  26110. while (i < scanLength) {
  26111. j = 0;
  26112. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  26113. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  26114. j++;
  26115. }
  26116. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26117. found = true;
  26118. break;
  26119. }
  26120. i++;
  26121. }
  26122. if (found) {
  26123. skipped += i;
  26124. stream.pos += i;
  26125. break;
  26126. }
  26127. skipped += scanLength;
  26128. stream.pos += scanLength;
  26129. }
  26130. if (!found) {
  26131. error('Missing endstream');
  26132. }
  26133. length = skipped;
  26134. lexer.nextChar();
  26135. this.shift();
  26136. this.shift();
  26137. }
  26138. this.shift(); // 'endstream'
  26139. stream = stream.makeSubStream(pos, length, dict);
  26140. if (cipherTransform) {
  26141. stream = cipherTransform.createStream(stream, length);
  26142. }
  26143. stream = this.filter(stream, dict, length);
  26144. stream.dict = dict;
  26145. return stream;
  26146. },
  26147. filter: function Parser_filter(stream, dict, length) {
  26148. var filter = dict.get('Filter', 'F');
  26149. var params = dict.get('DecodeParms', 'DP');
  26150. if (isName(filter)) {
  26151. return this.makeFilter(stream, filter.name, length, params);
  26152. }
  26153. var maybeLength = length;
  26154. if (isArray(filter)) {
  26155. var filterArray = filter;
  26156. var paramsArray = params;
  26157. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26158. filter = filterArray[i];
  26159. if (!isName(filter)) {
  26160. error('Bad filter name: ' + filter);
  26161. }
  26162. params = null;
  26163. if (isArray(paramsArray) && (i in paramsArray)) {
  26164. params = paramsArray[i];
  26165. }
  26166. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26167. // after the first stream the length variable is invalid
  26168. maybeLength = null;
  26169. }
  26170. }
  26171. return stream;
  26172. },
  26173. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26174. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26175. warn('Empty "' + name + '" stream.');
  26176. return new NullStream(stream);
  26177. }
  26178. try {
  26179. if (params && this.xref) {
  26180. params = this.xref.fetchIfRef(params);
  26181. }
  26182. var xrefStreamStats = this.xref.stats.streamTypes;
  26183. if (name === 'FlateDecode' || name === 'Fl') {
  26184. xrefStreamStats[StreamType.FLATE] = true;
  26185. if (params) {
  26186. return new PredictorStream(new FlateStream(stream, maybeLength),
  26187. maybeLength, params);
  26188. }
  26189. return new FlateStream(stream, maybeLength);
  26190. }
  26191. if (name === 'LZWDecode' || name === 'LZW') {
  26192. xrefStreamStats[StreamType.LZW] = true;
  26193. var earlyChange = 1;
  26194. if (params) {
  26195. if (params.has('EarlyChange')) {
  26196. earlyChange = params.get('EarlyChange');
  26197. }
  26198. return new PredictorStream(
  26199. new LZWStream(stream, maybeLength, earlyChange),
  26200. maybeLength, params);
  26201. }
  26202. return new LZWStream(stream, maybeLength, earlyChange);
  26203. }
  26204. if (name === 'DCTDecode' || name === 'DCT') {
  26205. xrefStreamStats[StreamType.DCT] = true;
  26206. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26207. }
  26208. if (name === 'JPXDecode' || name === 'JPX') {
  26209. xrefStreamStats[StreamType.JPX] = true;
  26210. return new JpxStream(stream, maybeLength, stream.dict);
  26211. }
  26212. if (name === 'ASCII85Decode' || name === 'A85') {
  26213. xrefStreamStats[StreamType.A85] = true;
  26214. return new Ascii85Stream(stream, maybeLength);
  26215. }
  26216. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26217. xrefStreamStats[StreamType.AHX] = true;
  26218. return new AsciiHexStream(stream, maybeLength);
  26219. }
  26220. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26221. xrefStreamStats[StreamType.CCF] = true;
  26222. return new CCITTFaxStream(stream, maybeLength, params);
  26223. }
  26224. if (name === 'RunLengthDecode' || name === 'RL') {
  26225. xrefStreamStats[StreamType.RL] = true;
  26226. return new RunLengthStream(stream, maybeLength);
  26227. }
  26228. if (name === 'JBIG2Decode') {
  26229. xrefStreamStats[StreamType.JBIG] = true;
  26230. return new Jbig2Stream(stream, maybeLength, stream.dict);
  26231. }
  26232. warn('filter "' + name + '" not supported yet');
  26233. return stream;
  26234. } catch (ex) {
  26235. if (ex instanceof MissingDataException) {
  26236. throw ex;
  26237. }
  26238. warn('Invalid stream: \"' + ex + '\"');
  26239. return new NullStream(stream);
  26240. }
  26241. }
  26242. };
  26243. return Parser;
  26244. })();
  26245. var Lexer = (function LexerClosure() {
  26246. function Lexer(stream, knownCommands) {
  26247. this.stream = stream;
  26248. this.nextChar();
  26249. // While lexing, we build up many strings one char at a time. Using += for
  26250. // this can result in lots of garbage strings. It's better to build an
  26251. // array of single-char strings and then join() them together at the end.
  26252. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  26253. // purpose uses less memory than using a new array for each string.
  26254. this.strBuf = [];
  26255. // The PDFs might have "glued" commands with other commands, operands or
  26256. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  26257. // commands and their prefixes. The prefixes are built the following way:
  26258. // if there a command that is a prefix of the other valid command or
  26259. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  26260. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  26261. // other commands or literals as a prefix. The knowCommands is optional.
  26262. this.knownCommands = knownCommands;
  26263. }
  26264. Lexer.isSpace = function Lexer_isSpace(ch) {
  26265. // Space is one of the following characters: SPACE, TAB, CR or LF.
  26266. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  26267. };
  26268. // A '1' in this array means the character is white space. A '1' or
  26269. // '2' means the character ends a name or command.
  26270. var specialChars = [
  26271. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  26272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  26273. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  26274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  26275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  26276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  26277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  26278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  26279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  26280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  26281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  26282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  26283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  26284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  26285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  26286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  26287. ];
  26288. function toHexDigit(ch) {
  26289. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  26290. return ch & 0x0F;
  26291. }
  26292. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  26293. // 'A'-'F', 'a'-'f'
  26294. return (ch & 0x0F) + 9;
  26295. }
  26296. return -1;
  26297. }
  26298. Lexer.prototype = {
  26299. nextChar: function Lexer_nextChar() {
  26300. return (this.currentChar = this.stream.getByte());
  26301. },
  26302. peekChar: function Lexer_peekChar() {
  26303. return this.stream.peekByte();
  26304. },
  26305. getNumber: function Lexer_getNumber() {
  26306. var ch = this.currentChar;
  26307. var eNotation = false;
  26308. var divideBy = 0; // different from 0 if it's a floating point value
  26309. var sign = 1;
  26310. if (ch === 0x2D) { // '-'
  26311. sign = -1;
  26312. ch = this.nextChar();
  26313. if (ch === 0x2D) { // '-'
  26314. // Ignore double negative (this is consistent with Adobe Reader).
  26315. ch = this.nextChar();
  26316. }
  26317. } else if (ch === 0x2B) { // '+'
  26318. ch = this.nextChar();
  26319. }
  26320. if (ch === 0x2E) { // '.'
  26321. divideBy = 10;
  26322. ch = this.nextChar();
  26323. }
  26324. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26325. error('Invalid number: ' + String.fromCharCode(ch));
  26326. return 0;
  26327. }
  26328. var baseValue = ch - 0x30; // '0'
  26329. var powerValue = 0;
  26330. var powerValueSign = 1;
  26331. while ((ch = this.nextChar()) >= 0) {
  26332. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  26333. var currentDigit = ch - 0x30; // '0'
  26334. if (eNotation) { // We are after an 'e' or 'E'
  26335. powerValue = powerValue * 10 + currentDigit;
  26336. } else {
  26337. if (divideBy !== 0) { // We are after a point
  26338. divideBy *= 10;
  26339. }
  26340. baseValue = baseValue * 10 + currentDigit;
  26341. }
  26342. } else if (ch === 0x2E) { // '.'
  26343. if (divideBy === 0) {
  26344. divideBy = 1;
  26345. } else {
  26346. // A number can have only one '.'
  26347. break;
  26348. }
  26349. } else if (ch === 0x2D) { // '-'
  26350. // ignore minus signs in the middle of numbers to match
  26351. // Adobe's behavior
  26352. warn('Badly formated number');
  26353. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  26354. // 'E' can be either a scientific notation or the beginning of a new
  26355. // operator
  26356. ch = this.peekChar();
  26357. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  26358. powerValueSign = (ch === 0x2D) ? -1 : 1;
  26359. this.nextChar(); // Consume the sign character
  26360. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26361. // The 'E' must be the beginning of a new operator
  26362. break;
  26363. }
  26364. eNotation = true;
  26365. } else {
  26366. // the last character doesn't belong to us
  26367. break;
  26368. }
  26369. }
  26370. if (divideBy !== 0) {
  26371. baseValue /= divideBy;
  26372. }
  26373. if (eNotation) {
  26374. baseValue *= Math.pow(10, powerValueSign * powerValue);
  26375. }
  26376. return sign * baseValue;
  26377. },
  26378. getString: function Lexer_getString() {
  26379. var numParen = 1;
  26380. var done = false;
  26381. var strBuf = this.strBuf;
  26382. strBuf.length = 0;
  26383. var ch = this.nextChar();
  26384. while (true) {
  26385. var charBuffered = false;
  26386. switch (ch | 0) {
  26387. case -1:
  26388. warn('Unterminated string');
  26389. done = true;
  26390. break;
  26391. case 0x28: // '('
  26392. ++numParen;
  26393. strBuf.push('(');
  26394. break;
  26395. case 0x29: // ')'
  26396. if (--numParen === 0) {
  26397. this.nextChar(); // consume strings ')'
  26398. done = true;
  26399. } else {
  26400. strBuf.push(')');
  26401. }
  26402. break;
  26403. case 0x5C: // '\\'
  26404. ch = this.nextChar();
  26405. switch (ch) {
  26406. case -1:
  26407. warn('Unterminated string');
  26408. done = true;
  26409. break;
  26410. case 0x6E: // 'n'
  26411. strBuf.push('\n');
  26412. break;
  26413. case 0x72: // 'r'
  26414. strBuf.push('\r');
  26415. break;
  26416. case 0x74: // 't'
  26417. strBuf.push('\t');
  26418. break;
  26419. case 0x62: // 'b'
  26420. strBuf.push('\b');
  26421. break;
  26422. case 0x66: // 'f'
  26423. strBuf.push('\f');
  26424. break;
  26425. case 0x5C: // '\'
  26426. case 0x28: // '('
  26427. case 0x29: // ')'
  26428. strBuf.push(String.fromCharCode(ch));
  26429. break;
  26430. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  26431. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  26432. var x = ch & 0x0F;
  26433. ch = this.nextChar();
  26434. charBuffered = true;
  26435. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26436. x = (x << 3) + (ch & 0x0F);
  26437. ch = this.nextChar();
  26438. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26439. charBuffered = false;
  26440. x = (x << 3) + (ch & 0x0F);
  26441. }
  26442. }
  26443. strBuf.push(String.fromCharCode(x));
  26444. break;
  26445. case 0x0D: // CR
  26446. if (this.peekChar() === 0x0A) { // LF
  26447. this.nextChar();
  26448. }
  26449. break;
  26450. case 0x0A: // LF
  26451. break;
  26452. default:
  26453. strBuf.push(String.fromCharCode(ch));
  26454. break;
  26455. }
  26456. break;
  26457. default:
  26458. strBuf.push(String.fromCharCode(ch));
  26459. break;
  26460. }
  26461. if (done) {
  26462. break;
  26463. }
  26464. if (!charBuffered) {
  26465. ch = this.nextChar();
  26466. }
  26467. }
  26468. return strBuf.join('');
  26469. },
  26470. getName: function Lexer_getName() {
  26471. var ch, previousCh;
  26472. var strBuf = this.strBuf;
  26473. strBuf.length = 0;
  26474. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26475. if (ch === 0x23) { // '#'
  26476. ch = this.nextChar();
  26477. if (specialChars[ch]) {
  26478. warn('Lexer_getName: ' +
  26479. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  26480. strBuf.push('#');
  26481. break;
  26482. }
  26483. var x = toHexDigit(ch);
  26484. if (x !== -1) {
  26485. previousCh = ch;
  26486. ch = this.nextChar();
  26487. var x2 = toHexDigit(ch);
  26488. if (x2 === -1) {
  26489. warn('Lexer_getName: Illegal digit (' +
  26490. String.fromCharCode(ch) +') in hexadecimal number.');
  26491. strBuf.push('#', String.fromCharCode(previousCh));
  26492. if (specialChars[ch]) {
  26493. break;
  26494. }
  26495. strBuf.push(String.fromCharCode(ch));
  26496. continue;
  26497. }
  26498. strBuf.push(String.fromCharCode((x << 4) | x2));
  26499. } else {
  26500. strBuf.push('#', String.fromCharCode(ch));
  26501. }
  26502. } else {
  26503. strBuf.push(String.fromCharCode(ch));
  26504. }
  26505. }
  26506. if (strBuf.length > 127) {
  26507. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  26508. }
  26509. return Name.get(strBuf.join(''));
  26510. },
  26511. getHexString: function Lexer_getHexString() {
  26512. var strBuf = this.strBuf;
  26513. strBuf.length = 0;
  26514. var ch = this.currentChar;
  26515. var isFirstHex = true;
  26516. var firstDigit;
  26517. var secondDigit;
  26518. while (true) {
  26519. if (ch < 0) {
  26520. warn('Unterminated hex string');
  26521. break;
  26522. } else if (ch === 0x3E) { // '>'
  26523. this.nextChar();
  26524. break;
  26525. } else if (specialChars[ch] === 1) {
  26526. ch = this.nextChar();
  26527. continue;
  26528. } else {
  26529. if (isFirstHex) {
  26530. firstDigit = toHexDigit(ch);
  26531. if (firstDigit === -1) {
  26532. warn('Ignoring invalid character "' + ch + '" in hex string');
  26533. ch = this.nextChar();
  26534. continue;
  26535. }
  26536. } else {
  26537. secondDigit = toHexDigit(ch);
  26538. if (secondDigit === -1) {
  26539. warn('Ignoring invalid character "' + ch + '" in hex string');
  26540. ch = this.nextChar();
  26541. continue;
  26542. }
  26543. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  26544. }
  26545. isFirstHex = !isFirstHex;
  26546. ch = this.nextChar();
  26547. }
  26548. }
  26549. return strBuf.join('');
  26550. },
  26551. getObj: function Lexer_getObj() {
  26552. // skip whitespace and comments
  26553. var comment = false;
  26554. var ch = this.currentChar;
  26555. while (true) {
  26556. if (ch < 0) {
  26557. return EOF;
  26558. }
  26559. if (comment) {
  26560. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  26561. comment = false;
  26562. }
  26563. } else if (ch === 0x25) { // '%'
  26564. comment = true;
  26565. } else if (specialChars[ch] !== 1) {
  26566. break;
  26567. }
  26568. ch = this.nextChar();
  26569. }
  26570. // start reading token
  26571. switch (ch | 0) {
  26572. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  26573. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  26574. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  26575. return this.getNumber();
  26576. case 0x28: // '('
  26577. return this.getString();
  26578. case 0x2F: // '/'
  26579. return this.getName();
  26580. // array punctuation
  26581. case 0x5B: // '['
  26582. this.nextChar();
  26583. return Cmd.get('[');
  26584. case 0x5D: // ']'
  26585. this.nextChar();
  26586. return Cmd.get(']');
  26587. // hex string or dict punctuation
  26588. case 0x3C: // '<'
  26589. ch = this.nextChar();
  26590. if (ch === 0x3C) {
  26591. // dict punctuation
  26592. this.nextChar();
  26593. return Cmd.get('<<');
  26594. }
  26595. return this.getHexString();
  26596. // dict punctuation
  26597. case 0x3E: // '>'
  26598. ch = this.nextChar();
  26599. if (ch === 0x3E) {
  26600. this.nextChar();
  26601. return Cmd.get('>>');
  26602. }
  26603. return Cmd.get('>');
  26604. case 0x7B: // '{'
  26605. this.nextChar();
  26606. return Cmd.get('{');
  26607. case 0x7D: // '}'
  26608. this.nextChar();
  26609. return Cmd.get('}');
  26610. case 0x29: // ')'
  26611. error('Illegal character: ' + ch);
  26612. break;
  26613. }
  26614. // command
  26615. var str = String.fromCharCode(ch);
  26616. var knownCommands = this.knownCommands;
  26617. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26618. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26619. // stop if known command is found and next character does not make
  26620. // the str a command
  26621. var possibleCommand = str + String.fromCharCode(ch);
  26622. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  26623. break;
  26624. }
  26625. if (str.length === 128) {
  26626. error('Command token too long: ' + str.length);
  26627. }
  26628. str = possibleCommand;
  26629. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26630. }
  26631. if (str === 'true') {
  26632. return true;
  26633. }
  26634. if (str === 'false') {
  26635. return false;
  26636. }
  26637. if (str === 'null') {
  26638. return null;
  26639. }
  26640. return Cmd.get(str);
  26641. },
  26642. skipToNextLine: function Lexer_skipToNextLine() {
  26643. var ch = this.currentChar;
  26644. while (ch >= 0) {
  26645. if (ch === 0x0D) { // CR
  26646. ch = this.nextChar();
  26647. if (ch === 0x0A) { // LF
  26648. this.nextChar();
  26649. }
  26650. break;
  26651. } else if (ch === 0x0A) { // LF
  26652. this.nextChar();
  26653. break;
  26654. }
  26655. ch = this.nextChar();
  26656. }
  26657. }
  26658. };
  26659. return Lexer;
  26660. })();
  26661. var Linearization = {
  26662. create: function LinearizationCreate(stream) {
  26663. function getInt(name, allowZeroValue) {
  26664. var obj = linDict.get(name);
  26665. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  26666. return obj;
  26667. }
  26668. throw new Error('The "' + name + '" parameter in the linearization ' +
  26669. 'dictionary is invalid.');
  26670. }
  26671. function getHints() {
  26672. var hints = linDict.get('H'), hintsLength, item;
  26673. if (isArray(hints) &&
  26674. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  26675. for (var index = 0; index < hintsLength; index++) {
  26676. if (!(isInt(item = hints[index]) && item > 0)) {
  26677. throw new Error('Hint (' + index +
  26678. ') in the linearization dictionary is invalid.');
  26679. }
  26680. }
  26681. return hints;
  26682. }
  26683. throw new Error('Hint array in the linearization dictionary is invalid.');
  26684. }
  26685. var parser = new Parser(new Lexer(stream), false, null);
  26686. var obj1 = parser.getObj();
  26687. var obj2 = parser.getObj();
  26688. var obj3 = parser.getObj();
  26689. var linDict = parser.getObj();
  26690. var obj, length;
  26691. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  26692. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  26693. return null; // No valid linearization dictionary found.
  26694. } else if ((length = getInt('L')) !== stream.length) {
  26695. throw new Error('The "L" parameter in the linearization dictionary ' +
  26696. 'does not equal the stream length.');
  26697. }
  26698. return {
  26699. length: length,
  26700. hints: getHints(),
  26701. objectNumberFirst: getInt('O'),
  26702. endFirst: getInt('E'),
  26703. numPages: getInt('N'),
  26704. mainXRefEntriesOffset: getInt('T'),
  26705. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  26706. };
  26707. }
  26708. };
  26709. exports.EOF = EOF;
  26710. exports.Lexer = Lexer;
  26711. exports.Linearization = Linearization;
  26712. exports.Parser = Parser;
  26713. exports.isEOF = isEOF;
  26714. // TODO refactor to remove dependency on stream.js
  26715. coreStream._setCoreParser(exports);
  26716. }));
  26717. (function (root, factory) {
  26718. {
  26719. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  26720. root.pdfjsDisplayPatternHelper, root.pdfjsDisplayWebGL);
  26721. }
  26722. }(this, function (exports, sharedUtil, displayPatternHelper, displayWebGL) {
  26723. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  26724. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  26725. var ImageKind = sharedUtil.ImageKind;
  26726. var OPS = sharedUtil.OPS;
  26727. var TextRenderingMode = sharedUtil.TextRenderingMode;
  26728. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  26729. var Util = sharedUtil.Util;
  26730. var assert = sharedUtil.assert;
  26731. var info = sharedUtil.info;
  26732. var isNum = sharedUtil.isNum;
  26733. var isArray = sharedUtil.isArray;
  26734. var error = sharedUtil.error;
  26735. var shadow = sharedUtil.shadow;
  26736. var warn = sharedUtil.warn;
  26737. var TilingPattern = displayPatternHelper.TilingPattern;
  26738. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  26739. var WebGLUtils = displayWebGL.WebGLUtils;
  26740. // <canvas> contexts store most of the state we need natively.
  26741. // However, PDF needs a bit more state, which we store here.
  26742. // Minimal font size that would be used during canvas fillText operations.
  26743. var MIN_FONT_SIZE = 16;
  26744. // Maximum font size that would be used during canvas fillText operations.
  26745. var MAX_FONT_SIZE = 100;
  26746. var MAX_GROUP_SIZE = 4096;
  26747. // Heuristic value used when enforcing minimum line widths.
  26748. var MIN_WIDTH_FACTOR = 0.65;
  26749. var COMPILE_TYPE3_GLYPHS = true;
  26750. var MAX_SIZE_TO_COMPILE = 1000;
  26751. var FULL_CHUNK_HEIGHT = 16;
  26752. function createScratchCanvas(width, height) {
  26753. var canvas = document.createElement('canvas');
  26754. canvas.width = width;
  26755. canvas.height = height;
  26756. return canvas;
  26757. }
  26758. function addContextCurrentTransform(ctx) {
  26759. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  26760. if (!ctx.mozCurrentTransform) {
  26761. ctx._originalSave = ctx.save;
  26762. ctx._originalRestore = ctx.restore;
  26763. ctx._originalRotate = ctx.rotate;
  26764. ctx._originalScale = ctx.scale;
  26765. ctx._originalTranslate = ctx.translate;
  26766. ctx._originalTransform = ctx.transform;
  26767. ctx._originalSetTransform = ctx.setTransform;
  26768. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  26769. ctx._transformStack = [];
  26770. Object.defineProperty(ctx, 'mozCurrentTransform', {
  26771. get: function getCurrentTransform() {
  26772. return this._transformMatrix;
  26773. }
  26774. });
  26775. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  26776. get: function getCurrentTransformInverse() {
  26777. // Calculation done using WolframAlpha:
  26778. // http://www.wolframalpha.com/input/?
  26779. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  26780. var m = this._transformMatrix;
  26781. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  26782. var ad_bc = a * d - b * c;
  26783. var bc_ad = b * c - a * d;
  26784. return [
  26785. d / ad_bc,
  26786. b / bc_ad,
  26787. c / bc_ad,
  26788. a / ad_bc,
  26789. (d * e - c * f) / bc_ad,
  26790. (b * e - a * f) / ad_bc
  26791. ];
  26792. }
  26793. });
  26794. ctx.save = function ctxSave() {
  26795. var old = this._transformMatrix;
  26796. this._transformStack.push(old);
  26797. this._transformMatrix = old.slice(0, 6);
  26798. this._originalSave();
  26799. };
  26800. ctx.restore = function ctxRestore() {
  26801. var prev = this._transformStack.pop();
  26802. if (prev) {
  26803. this._transformMatrix = prev;
  26804. this._originalRestore();
  26805. }
  26806. };
  26807. ctx.translate = function ctxTranslate(x, y) {
  26808. var m = this._transformMatrix;
  26809. m[4] = m[0] * x + m[2] * y + m[4];
  26810. m[5] = m[1] * x + m[3] * y + m[5];
  26811. this._originalTranslate(x, y);
  26812. };
  26813. ctx.scale = function ctxScale(x, y) {
  26814. var m = this._transformMatrix;
  26815. m[0] = m[0] * x;
  26816. m[1] = m[1] * x;
  26817. m[2] = m[2] * y;
  26818. m[3] = m[3] * y;
  26819. this._originalScale(x, y);
  26820. };
  26821. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  26822. var m = this._transformMatrix;
  26823. this._transformMatrix = [
  26824. m[0] * a + m[2] * b,
  26825. m[1] * a + m[3] * b,
  26826. m[0] * c + m[2] * d,
  26827. m[1] * c + m[3] * d,
  26828. m[0] * e + m[2] * f + m[4],
  26829. m[1] * e + m[3] * f + m[5]
  26830. ];
  26831. ctx._originalTransform(a, b, c, d, e, f);
  26832. };
  26833. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  26834. this._transformMatrix = [a, b, c, d, e, f];
  26835. ctx._originalSetTransform(a, b, c, d, e, f);
  26836. };
  26837. ctx.rotate = function ctxRotate(angle) {
  26838. var cosValue = Math.cos(angle);
  26839. var sinValue = Math.sin(angle);
  26840. var m = this._transformMatrix;
  26841. this._transformMatrix = [
  26842. m[0] * cosValue + m[2] * sinValue,
  26843. m[1] * cosValue + m[3] * sinValue,
  26844. m[0] * (-sinValue) + m[2] * cosValue,
  26845. m[1] * (-sinValue) + m[3] * cosValue,
  26846. m[4],
  26847. m[5]
  26848. ];
  26849. this._originalRotate(angle);
  26850. };
  26851. }
  26852. }
  26853. var CachedCanvases = (function CachedCanvasesClosure() {
  26854. function CachedCanvases() {
  26855. this.cache = Object.create(null);
  26856. }
  26857. CachedCanvases.prototype = {
  26858. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  26859. trackTransform) {
  26860. var canvasEntry;
  26861. if (this.cache[id] !== undefined) {
  26862. canvasEntry = this.cache[id];
  26863. canvasEntry.canvas.width = width;
  26864. canvasEntry.canvas.height = height;
  26865. // reset canvas transform for emulated mozCurrentTransform, if needed
  26866. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  26867. } else {
  26868. var canvas = createScratchCanvas(width, height);
  26869. var ctx = canvas.getContext('2d');
  26870. if (trackTransform) {
  26871. addContextCurrentTransform(ctx);
  26872. }
  26873. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  26874. }
  26875. return canvasEntry;
  26876. },
  26877. clear: function () {
  26878. for (var id in this.cache) {
  26879. var canvasEntry = this.cache[id];
  26880. // Zeroing the width and height causes Firefox to release graphics
  26881. // resources immediately, which can greatly reduce memory consumption.
  26882. canvasEntry.canvas.width = 0;
  26883. canvasEntry.canvas.height = 0;
  26884. delete this.cache[id];
  26885. }
  26886. }
  26887. };
  26888. return CachedCanvases;
  26889. })();
  26890. function compileType3Glyph(imgData) {
  26891. var POINT_TO_PROCESS_LIMIT = 1000;
  26892. var width = imgData.width, height = imgData.height;
  26893. var i, j, j0, width1 = width + 1;
  26894. var points = new Uint8Array(width1 * (height + 1));
  26895. var POINT_TYPES =
  26896. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  26897. // decodes bit-packed mask data
  26898. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  26899. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  26900. for (i = 0, ii = data0.length; i < ii; i++) {
  26901. var mask = 128, elem = data0[i];
  26902. while (mask > 0) {
  26903. data[pos++] = (elem & mask) ? 0 : 255;
  26904. mask >>= 1;
  26905. }
  26906. }
  26907. // finding iteresting points: every point is located between mask pixels,
  26908. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  26909. // will have flags assigned based on neighboring mask pixels:
  26910. // 4 | 8
  26911. // --P--
  26912. // 2 | 1
  26913. // We are interested only in points with the flags:
  26914. // - outside corners: 1, 2, 4, 8;
  26915. // - inside corners: 7, 11, 13, 14;
  26916. // - and, intersections: 5, 10.
  26917. var count = 0;
  26918. pos = 0;
  26919. if (data[pos] !== 0) {
  26920. points[0] = 1;
  26921. ++count;
  26922. }
  26923. for (j = 1; j < width; j++) {
  26924. if (data[pos] !== data[pos + 1]) {
  26925. points[j] = data[pos] ? 2 : 1;
  26926. ++count;
  26927. }
  26928. pos++;
  26929. }
  26930. if (data[pos] !== 0) {
  26931. points[j] = 2;
  26932. ++count;
  26933. }
  26934. for (i = 1; i < height; i++) {
  26935. pos = i * lineSize;
  26936. j0 = i * width1;
  26937. if (data[pos - lineSize] !== data[pos]) {
  26938. points[j0] = data[pos] ? 1 : 8;
  26939. ++count;
  26940. }
  26941. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  26942. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  26943. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  26944. for (j = 1; j < width; j++) {
  26945. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  26946. (data[pos - lineSize + 1] ? 8 : 0);
  26947. if (POINT_TYPES[sum]) {
  26948. points[j0 + j] = POINT_TYPES[sum];
  26949. ++count;
  26950. }
  26951. pos++;
  26952. }
  26953. if (data[pos - lineSize] !== data[pos]) {
  26954. points[j0 + j] = data[pos] ? 2 : 4;
  26955. ++count;
  26956. }
  26957. if (count > POINT_TO_PROCESS_LIMIT) {
  26958. return null;
  26959. }
  26960. }
  26961. pos = lineSize * (height - 1);
  26962. j0 = i * width1;
  26963. if (data[pos] !== 0) {
  26964. points[j0] = 8;
  26965. ++count;
  26966. }
  26967. for (j = 1; j < width; j++) {
  26968. if (data[pos] !== data[pos + 1]) {
  26969. points[j0 + j] = data[pos] ? 4 : 8;
  26970. ++count;
  26971. }
  26972. pos++;
  26973. }
  26974. if (data[pos] !== 0) {
  26975. points[j0 + j] = 4;
  26976. ++count;
  26977. }
  26978. if (count > POINT_TO_PROCESS_LIMIT) {
  26979. return null;
  26980. }
  26981. // building outlines
  26982. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  26983. var outlines = [];
  26984. for (i = 0; count && i <= height; i++) {
  26985. var p = i * width1;
  26986. var end = p + width;
  26987. while (p < end && !points[p]) {
  26988. p++;
  26989. }
  26990. if (p === end) {
  26991. continue;
  26992. }
  26993. var coords = [p % width1, i];
  26994. var type = points[p], p0 = p, pp;
  26995. do {
  26996. var step = steps[type];
  26997. do {
  26998. p += step;
  26999. } while (!points[p]);
  27000. pp = points[p];
  27001. if (pp !== 5 && pp !== 10) {
  27002. // set new direction
  27003. type = pp;
  27004. // delete mark
  27005. points[p] = 0;
  27006. } else { // type is 5 or 10, ie, a crossing
  27007. // set new direction
  27008. type = pp & ((0x33 * type) >> 4);
  27009. // set new type for "future hit"
  27010. points[p] &= (type >> 2 | type << 2);
  27011. }
  27012. coords.push(p % width1);
  27013. coords.push((p / width1) | 0);
  27014. --count;
  27015. } while (p0 !== p);
  27016. outlines.push(coords);
  27017. --i;
  27018. }
  27019. var drawOutline = function(c) {
  27020. c.save();
  27021. // the path shall be painted in [0..1]x[0..1] space
  27022. c.scale(1 / width, -1 / height);
  27023. c.translate(0, -height);
  27024. c.beginPath();
  27025. for (var i = 0, ii = outlines.length; i < ii; i++) {
  27026. var o = outlines[i];
  27027. c.moveTo(o[0], o[1]);
  27028. for (var j = 2, jj = o.length; j < jj; j += 2) {
  27029. c.lineTo(o[j], o[j+1]);
  27030. }
  27031. }
  27032. c.fill();
  27033. c.beginPath();
  27034. c.restore();
  27035. };
  27036. return drawOutline;
  27037. }
  27038. var CanvasExtraState = (function CanvasExtraStateClosure() {
  27039. function CanvasExtraState(old) {
  27040. // Are soft masks and alpha values shapes or opacities?
  27041. this.alphaIsShape = false;
  27042. this.fontSize = 0;
  27043. this.fontSizeScale = 1;
  27044. this.textMatrix = IDENTITY_MATRIX;
  27045. this.textMatrixScale = 1;
  27046. this.fontMatrix = FONT_IDENTITY_MATRIX;
  27047. this.leading = 0;
  27048. // Current point (in user coordinates)
  27049. this.x = 0;
  27050. this.y = 0;
  27051. // Start of text line (in text coordinates)
  27052. this.lineX = 0;
  27053. this.lineY = 0;
  27054. // Character and word spacing
  27055. this.charSpacing = 0;
  27056. this.wordSpacing = 0;
  27057. this.textHScale = 1;
  27058. this.textRenderingMode = TextRenderingMode.FILL;
  27059. this.textRise = 0;
  27060. // Default fore and background colors
  27061. this.fillColor = '#000000';
  27062. this.strokeColor = '#000000';
  27063. this.patternFill = false;
  27064. // Note: fill alpha applies to all non-stroking operations
  27065. this.fillAlpha = 1;
  27066. this.strokeAlpha = 1;
  27067. this.lineWidth = 1;
  27068. this.activeSMask = null; // nonclonable field (see the save method below)
  27069. this.old = old;
  27070. }
  27071. CanvasExtraState.prototype = {
  27072. clone: function CanvasExtraState_clone() {
  27073. return Object.create(this);
  27074. },
  27075. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  27076. this.x = x;
  27077. this.y = y;
  27078. }
  27079. };
  27080. return CanvasExtraState;
  27081. })();
  27082. var CanvasGraphics = (function CanvasGraphicsClosure() {
  27083. // Defines the time the executeOperatorList is going to be executing
  27084. // before it stops and shedules a continue of execution.
  27085. var EXECUTION_TIME = 15;
  27086. // Defines the number of steps before checking the execution time
  27087. var EXECUTION_STEPS = 10;
  27088. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  27089. this.ctx = canvasCtx;
  27090. this.current = new CanvasExtraState();
  27091. this.stateStack = [];
  27092. this.pendingClip = null;
  27093. this.pendingEOFill = false;
  27094. this.res = null;
  27095. this.xobjs = null;
  27096. this.commonObjs = commonObjs;
  27097. this.objs = objs;
  27098. this.imageLayer = imageLayer;
  27099. this.groupStack = [];
  27100. this.processingType3 = null;
  27101. // Patterns are painted relative to the initial page/form transform, see pdf
  27102. // spec 8.7.2 NOTE 1.
  27103. this.baseTransform = null;
  27104. this.baseTransformStack = [];
  27105. this.groupLevel = 0;
  27106. this.smaskStack = [];
  27107. this.smaskCounter = 0;
  27108. this.tempSMask = null;
  27109. this.cachedCanvases = new CachedCanvases();
  27110. if (canvasCtx) {
  27111. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  27112. // the transformation must already be set in canvasCtx._transformMatrix.
  27113. addContextCurrentTransform(canvasCtx);
  27114. }
  27115. this.cachedGetSinglePixelWidth = null;
  27116. }
  27117. function putBinaryImageData(ctx, imgData) {
  27118. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  27119. ctx.putImageData(imgData, 0, 0);
  27120. return;
  27121. }
  27122. // Put the image data to the canvas in chunks, rather than putting the
  27123. // whole image at once. This saves JS memory, because the ImageData object
  27124. // is smaller. It also possibly saves C++ memory within the implementation
  27125. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  27126. // the data passed to putImageData()). |n| shouldn't be too small, however,
  27127. // because too many putImageData() calls will slow things down.
  27128. //
  27129. // Note: as written, if the last chunk is partial, the putImageData() call
  27130. // will (conceptually) put pixels past the bounds of the canvas. But
  27131. // that's ok; any such pixels are ignored.
  27132. var height = imgData.height, width = imgData.width;
  27133. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  27134. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  27135. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  27136. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  27137. var srcPos = 0, destPos;
  27138. var src = imgData.data;
  27139. var dest = chunkImgData.data;
  27140. var i, j, thisChunkHeight, elemsInThisChunk;
  27141. // There are multiple forms in which the pixel data can be passed, and
  27142. // imgData.kind tells us which one this is.
  27143. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  27144. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  27145. var srcLength = src.byteLength;
  27146. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  27147. new Uint32ArrayView(dest);
  27148. var dest32DataLength = dest32.length;
  27149. var fullSrcDiff = (width + 7) >> 3;
  27150. var white = 0xFFFFFFFF;
  27151. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  27152. 0xFF000000 : 0x000000FF;
  27153. for (i = 0; i < totalChunks; i++) {
  27154. thisChunkHeight =
  27155. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  27156. destPos = 0;
  27157. for (j = 0; j < thisChunkHeight; j++) {
  27158. var srcDiff = srcLength - srcPos;
  27159. var k = 0;
  27160. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  27161. var kEndUnrolled = kEnd & ~7;
  27162. var mask = 0;
  27163. var srcByte = 0;
  27164. for (; k < kEndUnrolled; k += 8) {
  27165. srcByte = src[srcPos++];
  27166. dest32[destPos++] = (srcByte & 128) ? white : black;
  27167. dest32[destPos++] = (srcByte & 64) ? white : black;
  27168. dest32[destPos++] = (srcByte & 32) ? white : black;
  27169. dest32[destPos++] = (srcByte & 16) ? white : black;
  27170. dest32[destPos++] = (srcByte & 8) ? white : black;
  27171. dest32[destPos++] = (srcByte & 4) ? white : black;
  27172. dest32[destPos++] = (srcByte & 2) ? white : black;
  27173. dest32[destPos++] = (srcByte & 1) ? white : black;
  27174. }
  27175. for (; k < kEnd; k++) {
  27176. if (mask === 0) {
  27177. srcByte = src[srcPos++];
  27178. mask = 128;
  27179. }
  27180. dest32[destPos++] = (srcByte & mask) ? white : black;
  27181. mask >>= 1;
  27182. }
  27183. }
  27184. // We ran out of input. Make all remaining pixels transparent.
  27185. while (destPos < dest32DataLength) {
  27186. dest32[destPos++] = 0;
  27187. }
  27188. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27189. }
  27190. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  27191. // RGBA, 32-bits per pixel.
  27192. j = 0;
  27193. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  27194. for (i = 0; i < fullChunks; i++) {
  27195. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  27196. srcPos += elemsInThisChunk;
  27197. ctx.putImageData(chunkImgData, 0, j);
  27198. j += FULL_CHUNK_HEIGHT;
  27199. }
  27200. if (i < totalChunks) {
  27201. elemsInThisChunk = width * partialChunkHeight * 4;
  27202. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  27203. ctx.putImageData(chunkImgData, 0, j);
  27204. }
  27205. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  27206. // RGB, 24-bits per pixel.
  27207. thisChunkHeight = FULL_CHUNK_HEIGHT;
  27208. elemsInThisChunk = width * thisChunkHeight;
  27209. for (i = 0; i < totalChunks; i++) {
  27210. if (i >= fullChunks) {
  27211. thisChunkHeight = partialChunkHeight;
  27212. elemsInThisChunk = width * thisChunkHeight;
  27213. }
  27214. destPos = 0;
  27215. for (j = elemsInThisChunk; j--;) {
  27216. dest[destPos++] = src[srcPos++];
  27217. dest[destPos++] = src[srcPos++];
  27218. dest[destPos++] = src[srcPos++];
  27219. dest[destPos++] = 255;
  27220. }
  27221. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27222. }
  27223. } else {
  27224. error('bad image kind: ' + imgData.kind);
  27225. }
  27226. }
  27227. function putBinaryImageMask(ctx, imgData) {
  27228. var height = imgData.height, width = imgData.width;
  27229. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  27230. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  27231. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  27232. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  27233. var srcPos = 0;
  27234. var src = imgData.data;
  27235. var dest = chunkImgData.data;
  27236. for (var i = 0; i < totalChunks; i++) {
  27237. var thisChunkHeight =
  27238. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  27239. // Expand the mask so it can be used by the canvas. Any required
  27240. // inversion has already been handled.
  27241. var destPos = 3; // alpha component offset
  27242. for (var j = 0; j < thisChunkHeight; j++) {
  27243. var mask = 0;
  27244. for (var k = 0; k < width; k++) {
  27245. if (!mask) {
  27246. var elem = src[srcPos++];
  27247. mask = 128;
  27248. }
  27249. dest[destPos] = (elem & mask) ? 0 : 255;
  27250. destPos += 4;
  27251. mask >>= 1;
  27252. }
  27253. }
  27254. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  27255. }
  27256. }
  27257. function copyCtxState(sourceCtx, destCtx) {
  27258. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  27259. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  27260. 'globalCompositeOperation', 'font'];
  27261. for (var i = 0, ii = properties.length; i < ii; i++) {
  27262. var property = properties[i];
  27263. if (sourceCtx[property] !== undefined) {
  27264. destCtx[property] = sourceCtx[property];
  27265. }
  27266. }
  27267. if (sourceCtx.setLineDash !== undefined) {
  27268. destCtx.setLineDash(sourceCtx.getLineDash());
  27269. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  27270. } else if (sourceCtx.mozDashOffset !== undefined) {
  27271. destCtx.mozDash = sourceCtx.mozDash;
  27272. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  27273. }
  27274. }
  27275. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  27276. var length = bytes.length;
  27277. for (var i = 3; i < length; i += 4) {
  27278. var alpha = bytes[i];
  27279. if (alpha === 0) {
  27280. bytes[i - 3] = r0;
  27281. bytes[i - 2] = g0;
  27282. bytes[i - 1] = b0;
  27283. } else if (alpha < 255) {
  27284. var alpha_ = 255 - alpha;
  27285. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  27286. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  27287. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  27288. }
  27289. }
  27290. }
  27291. function composeSMaskAlpha(maskData, layerData, transferMap) {
  27292. var length = maskData.length;
  27293. var scale = 1 / 255;
  27294. for (var i = 3; i < length; i += 4) {
  27295. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  27296. layerData[i] = (layerData[i] * alpha * scale) | 0;
  27297. }
  27298. }
  27299. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  27300. var length = maskData.length;
  27301. for (var i = 3; i < length; i += 4) {
  27302. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  27303. (maskData[i - 2] * 152) + // * 0.59 ....
  27304. (maskData[i - 1] * 28); // * 0.11 ....
  27305. layerData[i] = transferMap ?
  27306. (layerData[i] * transferMap[y >> 8]) >> 8 :
  27307. (layerData[i] * y) >> 16;
  27308. }
  27309. }
  27310. function genericComposeSMask(maskCtx, layerCtx, width, height,
  27311. subtype, backdrop, transferMap) {
  27312. var hasBackdrop = !!backdrop;
  27313. var r0 = hasBackdrop ? backdrop[0] : 0;
  27314. var g0 = hasBackdrop ? backdrop[1] : 0;
  27315. var b0 = hasBackdrop ? backdrop[2] : 0;
  27316. var composeFn;
  27317. if (subtype === 'Luminosity') {
  27318. composeFn = composeSMaskLuminosity;
  27319. } else {
  27320. composeFn = composeSMaskAlpha;
  27321. }
  27322. // processing image in chunks to save memory
  27323. var PIXELS_TO_PROCESS = 1048576;
  27324. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  27325. for (var row = 0; row < height; row += chunkSize) {
  27326. var chunkHeight = Math.min(chunkSize, height - row);
  27327. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  27328. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  27329. if (hasBackdrop) {
  27330. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  27331. }
  27332. composeFn(maskData.data, layerData.data, transferMap);
  27333. maskCtx.putImageData(layerData, 0, row);
  27334. }
  27335. }
  27336. function composeSMask(ctx, smask, layerCtx) {
  27337. var mask = smask.canvas;
  27338. var maskCtx = smask.context;
  27339. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  27340. smask.offsetX, smask.offsetY);
  27341. var backdrop = smask.backdrop || null;
  27342. if (!smask.transferMap && WebGLUtils.isEnabled) {
  27343. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  27344. {subtype: smask.subtype, backdrop: backdrop});
  27345. ctx.setTransform(1, 0, 0, 1, 0, 0);
  27346. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  27347. return;
  27348. }
  27349. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  27350. smask.subtype, backdrop, smask.transferMap);
  27351. ctx.drawImage(mask, 0, 0);
  27352. }
  27353. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  27354. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  27355. var NORMAL_CLIP = {};
  27356. var EO_CLIP = {};
  27357. CanvasGraphics.prototype = {
  27358. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  27359. transparency) {
  27360. // For pdfs that use blend modes we have to clear the canvas else certain
  27361. // blend modes can look wrong since we'd be blending with a white
  27362. // backdrop. The problem with a transparent backdrop though is we then
  27363. // don't get sub pixel anti aliasing on text, creating temporary
  27364. // transparent canvas when we have blend modes.
  27365. var width = this.ctx.canvas.width;
  27366. var height = this.ctx.canvas.height;
  27367. this.ctx.save();
  27368. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  27369. this.ctx.fillRect(0, 0, width, height);
  27370. this.ctx.restore();
  27371. if (transparency) {
  27372. var transparentCanvas = this.cachedCanvases.getCanvas(
  27373. 'transparent', width, height, true);
  27374. this.compositeCtx = this.ctx;
  27375. this.transparentCanvas = transparentCanvas.canvas;
  27376. this.ctx = transparentCanvas.context;
  27377. this.ctx.save();
  27378. // The transform can be applied before rendering, transferring it to
  27379. // the new canvas.
  27380. this.ctx.transform.apply(this.ctx,
  27381. this.compositeCtx.mozCurrentTransform);
  27382. }
  27383. this.ctx.save();
  27384. if (transform) {
  27385. this.ctx.transform.apply(this.ctx, transform);
  27386. }
  27387. this.ctx.transform.apply(this.ctx, viewport.transform);
  27388. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  27389. if (this.imageLayer) {
  27390. this.imageLayer.beginLayout();
  27391. }
  27392. },
  27393. executeOperatorList: function CanvasGraphics_executeOperatorList(
  27394. operatorList,
  27395. executionStartIdx, continueCallback,
  27396. stepper) {
  27397. var argsArray = operatorList.argsArray;
  27398. var fnArray = operatorList.fnArray;
  27399. var i = executionStartIdx || 0;
  27400. var argsArrayLen = argsArray.length;
  27401. // Sometimes the OperatorList to execute is empty.
  27402. if (argsArrayLen === i) {
  27403. return i;
  27404. }
  27405. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  27406. typeof continueCallback === 'function');
  27407. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  27408. var steps = 0;
  27409. var commonObjs = this.commonObjs;
  27410. var objs = this.objs;
  27411. var fnId;
  27412. while (true) {
  27413. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  27414. stepper.breakIt(i, continueCallback);
  27415. return i;
  27416. }
  27417. fnId = fnArray[i];
  27418. if (fnId !== OPS.dependency) {
  27419. this[fnId].apply(this, argsArray[i]);
  27420. } else {
  27421. var deps = argsArray[i];
  27422. for (var n = 0, nn = deps.length; n < nn; n++) {
  27423. var depObjId = deps[n];
  27424. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  27425. var objsPool = common ? commonObjs : objs;
  27426. // If the promise isn't resolved yet, add the continueCallback
  27427. // to the promise and bail out.
  27428. if (!objsPool.isResolved(depObjId)) {
  27429. objsPool.get(depObjId, continueCallback);
  27430. return i;
  27431. }
  27432. }
  27433. }
  27434. i++;
  27435. // If the entire operatorList was executed, stop as were done.
  27436. if (i === argsArrayLen) {
  27437. return i;
  27438. }
  27439. // If the execution took longer then a certain amount of time and
  27440. // `continueCallback` is specified, interrupt the execution.
  27441. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  27442. if (Date.now() > endTime) {
  27443. continueCallback();
  27444. return i;
  27445. }
  27446. steps = 0;
  27447. }
  27448. // If the operatorList isn't executed completely yet OR the execution
  27449. // time was short enough, do another execution round.
  27450. }
  27451. },
  27452. endDrawing: function CanvasGraphics_endDrawing() {
  27453. this.ctx.restore();
  27454. if (this.transparentCanvas) {
  27455. this.ctx = this.compositeCtx;
  27456. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  27457. this.transparentCanvas = null;
  27458. }
  27459. this.cachedCanvases.clear();
  27460. WebGLUtils.clear();
  27461. if (this.imageLayer) {
  27462. this.imageLayer.endLayout();
  27463. }
  27464. },
  27465. // Graphics state
  27466. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  27467. this.current.lineWidth = width;
  27468. this.ctx.lineWidth = width;
  27469. },
  27470. setLineCap: function CanvasGraphics_setLineCap(style) {
  27471. this.ctx.lineCap = LINE_CAP_STYLES[style];
  27472. },
  27473. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  27474. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  27475. },
  27476. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  27477. this.ctx.miterLimit = limit;
  27478. },
  27479. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  27480. var ctx = this.ctx;
  27481. if (ctx.setLineDash !== undefined) {
  27482. ctx.setLineDash(dashArray);
  27483. ctx.lineDashOffset = dashPhase;
  27484. } else {
  27485. ctx.mozDash = dashArray;
  27486. ctx.mozDashOffset = dashPhase;
  27487. }
  27488. },
  27489. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  27490. // Maybe if we one day fully support color spaces this will be important
  27491. // for now we can ignore.
  27492. // TODO set rendering intent?
  27493. },
  27494. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  27495. // There's no way to control this with canvas, but we can safely ignore.
  27496. // TODO set flatness?
  27497. },
  27498. setGState: function CanvasGraphics_setGState(states) {
  27499. for (var i = 0, ii = states.length; i < ii; i++) {
  27500. var state = states[i];
  27501. var key = state[0];
  27502. var value = state[1];
  27503. switch (key) {
  27504. case 'LW':
  27505. this.setLineWidth(value);
  27506. break;
  27507. case 'LC':
  27508. this.setLineCap(value);
  27509. break;
  27510. case 'LJ':
  27511. this.setLineJoin(value);
  27512. break;
  27513. case 'ML':
  27514. this.setMiterLimit(value);
  27515. break;
  27516. case 'D':
  27517. this.setDash(value[0], value[1]);
  27518. break;
  27519. case 'RI':
  27520. this.setRenderingIntent(value);
  27521. break;
  27522. case 'FL':
  27523. this.setFlatness(value);
  27524. break;
  27525. case 'Font':
  27526. this.setFont(value[0], value[1]);
  27527. break;
  27528. case 'CA':
  27529. this.current.strokeAlpha = state[1];
  27530. break;
  27531. case 'ca':
  27532. this.current.fillAlpha = state[1];
  27533. this.ctx.globalAlpha = state[1];
  27534. break;
  27535. case 'BM':
  27536. if (value && value.name && (value.name !== 'Normal')) {
  27537. var mode = value.name.replace(/([A-Z])/g,
  27538. function(c) {
  27539. return '-' + c.toLowerCase();
  27540. }
  27541. ).substring(1);
  27542. this.ctx.globalCompositeOperation = mode;
  27543. if (this.ctx.globalCompositeOperation !== mode) {
  27544. warn('globalCompositeOperation "' + mode +
  27545. '" is not supported');
  27546. }
  27547. } else {
  27548. this.ctx.globalCompositeOperation = 'source-over';
  27549. }
  27550. break;
  27551. case 'SMask':
  27552. if (this.current.activeSMask) {
  27553. this.endSMaskGroup();
  27554. }
  27555. this.current.activeSMask = value ? this.tempSMask : null;
  27556. if (this.current.activeSMask) {
  27557. this.beginSMaskGroup();
  27558. }
  27559. this.tempSMask = null;
  27560. break;
  27561. }
  27562. }
  27563. },
  27564. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  27565. var activeSMask = this.current.activeSMask;
  27566. var drawnWidth = activeSMask.canvas.width;
  27567. var drawnHeight = activeSMask.canvas.height;
  27568. var cacheId = 'smaskGroupAt' + this.groupLevel;
  27569. var scratchCanvas = this.cachedCanvases.getCanvas(
  27570. cacheId, drawnWidth, drawnHeight, true);
  27571. var currentCtx = this.ctx;
  27572. var currentTransform = currentCtx.mozCurrentTransform;
  27573. this.ctx.save();
  27574. var groupCtx = scratchCanvas.context;
  27575. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  27576. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  27577. groupCtx.transform.apply(groupCtx, currentTransform);
  27578. copyCtxState(currentCtx, groupCtx);
  27579. this.ctx = groupCtx;
  27580. this.setGState([
  27581. ['BM', 'Normal'],
  27582. ['ca', 1],
  27583. ['CA', 1]
  27584. ]);
  27585. this.groupStack.push(currentCtx);
  27586. this.groupLevel++;
  27587. },
  27588. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  27589. var groupCtx = this.ctx;
  27590. this.groupLevel--;
  27591. this.ctx = this.groupStack.pop();
  27592. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  27593. this.ctx.restore();
  27594. copyCtxState(groupCtx, this.ctx);
  27595. },
  27596. save: function CanvasGraphics_save() {
  27597. this.ctx.save();
  27598. var old = this.current;
  27599. this.stateStack.push(old);
  27600. this.current = old.clone();
  27601. this.current.activeSMask = null;
  27602. },
  27603. restore: function CanvasGraphics_restore() {
  27604. if (this.stateStack.length !== 0) {
  27605. if (this.current.activeSMask !== null) {
  27606. this.endSMaskGroup();
  27607. }
  27608. this.current = this.stateStack.pop();
  27609. this.ctx.restore();
  27610. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  27611. this.pendingClip = null;
  27612. this.cachedGetSinglePixelWidth = null;
  27613. }
  27614. },
  27615. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  27616. this.ctx.transform(a, b, c, d, e, f);
  27617. this.cachedGetSinglePixelWidth = null;
  27618. },
  27619. // Path
  27620. constructPath: function CanvasGraphics_constructPath(ops, args) {
  27621. var ctx = this.ctx;
  27622. var current = this.current;
  27623. var x = current.x, y = current.y;
  27624. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  27625. switch (ops[i] | 0) {
  27626. case OPS.rectangle:
  27627. x = args[j++];
  27628. y = args[j++];
  27629. var width = args[j++];
  27630. var height = args[j++];
  27631. if (width === 0) {
  27632. width = this.getSinglePixelWidth();
  27633. }
  27634. if (height === 0) {
  27635. height = this.getSinglePixelWidth();
  27636. }
  27637. var xw = x + width;
  27638. var yh = y + height;
  27639. this.ctx.moveTo(x, y);
  27640. this.ctx.lineTo(xw, y);
  27641. this.ctx.lineTo(xw, yh);
  27642. this.ctx.lineTo(x, yh);
  27643. this.ctx.lineTo(x, y);
  27644. this.ctx.closePath();
  27645. break;
  27646. case OPS.moveTo:
  27647. x = args[j++];
  27648. y = args[j++];
  27649. ctx.moveTo(x, y);
  27650. break;
  27651. case OPS.lineTo:
  27652. x = args[j++];
  27653. y = args[j++];
  27654. ctx.lineTo(x, y);
  27655. break;
  27656. case OPS.curveTo:
  27657. x = args[j + 4];
  27658. y = args[j + 5];
  27659. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  27660. x, y);
  27661. j += 6;
  27662. break;
  27663. case OPS.curveTo2:
  27664. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  27665. args[j + 2], args[j + 3]);
  27666. x = args[j + 2];
  27667. y = args[j + 3];
  27668. j += 4;
  27669. break;
  27670. case OPS.curveTo3:
  27671. x = args[j + 2];
  27672. y = args[j + 3];
  27673. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  27674. j += 4;
  27675. break;
  27676. case OPS.closePath:
  27677. ctx.closePath();
  27678. break;
  27679. }
  27680. }
  27681. current.setCurrentPoint(x, y);
  27682. },
  27683. closePath: function CanvasGraphics_closePath() {
  27684. this.ctx.closePath();
  27685. },
  27686. stroke: function CanvasGraphics_stroke(consumePath) {
  27687. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  27688. var ctx = this.ctx;
  27689. var strokeColor = this.current.strokeColor;
  27690. // Prevent drawing too thin lines by enforcing a minimum line width.
  27691. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  27692. this.current.lineWidth);
  27693. // For stroke we want to temporarily change the global alpha to the
  27694. // stroking alpha.
  27695. ctx.globalAlpha = this.current.strokeAlpha;
  27696. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  27697. strokeColor.type === 'Pattern') {
  27698. // for patterns, we transform to pattern space, calculate
  27699. // the pattern, call stroke, and restore to user space
  27700. ctx.save();
  27701. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  27702. ctx.stroke();
  27703. ctx.restore();
  27704. } else {
  27705. ctx.stroke();
  27706. }
  27707. if (consumePath) {
  27708. this.consumePath();
  27709. }
  27710. // Restore the global alpha to the fill alpha
  27711. ctx.globalAlpha = this.current.fillAlpha;
  27712. },
  27713. closeStroke: function CanvasGraphics_closeStroke() {
  27714. this.closePath();
  27715. this.stroke();
  27716. },
  27717. fill: function CanvasGraphics_fill(consumePath) {
  27718. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  27719. var ctx = this.ctx;
  27720. var fillColor = this.current.fillColor;
  27721. var isPatternFill = this.current.patternFill;
  27722. var needRestore = false;
  27723. if (isPatternFill) {
  27724. ctx.save();
  27725. if (this.baseTransform) {
  27726. ctx.setTransform.apply(ctx, this.baseTransform);
  27727. }
  27728. ctx.fillStyle = fillColor.getPattern(ctx, this);
  27729. needRestore = true;
  27730. }
  27731. if (this.pendingEOFill) {
  27732. if (ctx.mozFillRule !== undefined) {
  27733. ctx.mozFillRule = 'evenodd';
  27734. ctx.fill();
  27735. ctx.mozFillRule = 'nonzero';
  27736. } else {
  27737. ctx.fill('evenodd');
  27738. }
  27739. this.pendingEOFill = false;
  27740. } else {
  27741. ctx.fill();
  27742. }
  27743. if (needRestore) {
  27744. ctx.restore();
  27745. }
  27746. if (consumePath) {
  27747. this.consumePath();
  27748. }
  27749. },
  27750. eoFill: function CanvasGraphics_eoFill() {
  27751. this.pendingEOFill = true;
  27752. this.fill();
  27753. },
  27754. fillStroke: function CanvasGraphics_fillStroke() {
  27755. this.fill(false);
  27756. this.stroke(false);
  27757. this.consumePath();
  27758. },
  27759. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  27760. this.pendingEOFill = true;
  27761. this.fillStroke();
  27762. },
  27763. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  27764. this.closePath();
  27765. this.fillStroke();
  27766. },
  27767. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  27768. this.pendingEOFill = true;
  27769. this.closePath();
  27770. this.fillStroke();
  27771. },
  27772. endPath: function CanvasGraphics_endPath() {
  27773. this.consumePath();
  27774. },
  27775. // Clipping
  27776. clip: function CanvasGraphics_clip() {
  27777. this.pendingClip = NORMAL_CLIP;
  27778. },
  27779. eoClip: function CanvasGraphics_eoClip() {
  27780. this.pendingClip = EO_CLIP;
  27781. },
  27782. // Text
  27783. beginText: function CanvasGraphics_beginText() {
  27784. this.current.textMatrix = IDENTITY_MATRIX;
  27785. this.current.textMatrixScale = 1;
  27786. this.current.x = this.current.lineX = 0;
  27787. this.current.y = this.current.lineY = 0;
  27788. },
  27789. endText: function CanvasGraphics_endText() {
  27790. var paths = this.pendingTextPaths;
  27791. var ctx = this.ctx;
  27792. if (paths === undefined) {
  27793. ctx.beginPath();
  27794. return;
  27795. }
  27796. ctx.save();
  27797. ctx.beginPath();
  27798. for (var i = 0; i < paths.length; i++) {
  27799. var path = paths[i];
  27800. ctx.setTransform.apply(ctx, path.transform);
  27801. ctx.translate(path.x, path.y);
  27802. path.addToPath(ctx, path.fontSize);
  27803. }
  27804. ctx.restore();
  27805. ctx.clip();
  27806. ctx.beginPath();
  27807. delete this.pendingTextPaths;
  27808. },
  27809. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  27810. this.current.charSpacing = spacing;
  27811. },
  27812. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  27813. this.current.wordSpacing = spacing;
  27814. },
  27815. setHScale: function CanvasGraphics_setHScale(scale) {
  27816. this.current.textHScale = scale / 100;
  27817. },
  27818. setLeading: function CanvasGraphics_setLeading(leading) {
  27819. this.current.leading = -leading;
  27820. },
  27821. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  27822. var fontObj = this.commonObjs.get(fontRefName);
  27823. var current = this.current;
  27824. if (!fontObj) {
  27825. error('Can\'t find font for ' + fontRefName);
  27826. }
  27827. current.fontMatrix = (fontObj.fontMatrix ?
  27828. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  27829. // A valid matrix needs all main diagonal elements to be non-zero
  27830. // This also ensures we bypass FF bugzilla bug #719844.
  27831. if (current.fontMatrix[0] === 0 ||
  27832. current.fontMatrix[3] === 0) {
  27833. warn('Invalid font matrix for font ' + fontRefName);
  27834. }
  27835. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  27836. // and in some docs this can be negative (inverted x-y axes).
  27837. if (size < 0) {
  27838. size = -size;
  27839. current.fontDirection = -1;
  27840. } else {
  27841. current.fontDirection = 1;
  27842. }
  27843. this.current.font = fontObj;
  27844. this.current.fontSize = size;
  27845. if (fontObj.isType3Font) {
  27846. return; // we don't need ctx.font for Type3 fonts
  27847. }
  27848. var name = fontObj.loadedName || 'sans-serif';
  27849. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  27850. (fontObj.bold ? 'bold' : 'normal');
  27851. var italic = fontObj.italic ? 'italic' : 'normal';
  27852. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  27853. // Some font backends cannot handle fonts below certain size.
  27854. // Keeping the font at minimal size and using the fontSizeScale to change
  27855. // the current transformation matrix before the fillText/strokeText.
  27856. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  27857. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  27858. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  27859. this.current.fontSizeScale = size / browserFontSize;
  27860. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  27861. this.ctx.font = rule;
  27862. },
  27863. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  27864. this.current.textRenderingMode = mode;
  27865. },
  27866. setTextRise: function CanvasGraphics_setTextRise(rise) {
  27867. this.current.textRise = rise;
  27868. },
  27869. moveText: function CanvasGraphics_moveText(x, y) {
  27870. this.current.x = this.current.lineX += x;
  27871. this.current.y = this.current.lineY += y;
  27872. },
  27873. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  27874. this.setLeading(-y);
  27875. this.moveText(x, y);
  27876. },
  27877. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  27878. this.current.textMatrix = [a, b, c, d, e, f];
  27879. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  27880. this.current.x = this.current.lineX = 0;
  27881. this.current.y = this.current.lineY = 0;
  27882. },
  27883. nextLine: function CanvasGraphics_nextLine() {
  27884. this.moveText(0, this.current.leading);
  27885. },
  27886. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  27887. var ctx = this.ctx;
  27888. var current = this.current;
  27889. var font = current.font;
  27890. var textRenderingMode = current.textRenderingMode;
  27891. var fontSize = current.fontSize / current.fontSizeScale;
  27892. var fillStrokeMode = textRenderingMode &
  27893. TextRenderingMode.FILL_STROKE_MASK;
  27894. var isAddToPathSet = !!(textRenderingMode &
  27895. TextRenderingMode.ADD_TO_PATH_FLAG);
  27896. var addToPath;
  27897. if (font.disableFontFace || isAddToPathSet) {
  27898. addToPath = font.getPathGenerator(this.commonObjs, character);
  27899. }
  27900. if (font.disableFontFace) {
  27901. ctx.save();
  27902. ctx.translate(x, y);
  27903. ctx.beginPath();
  27904. addToPath(ctx, fontSize);
  27905. if (fillStrokeMode === TextRenderingMode.FILL ||
  27906. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27907. ctx.fill();
  27908. }
  27909. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27910. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27911. ctx.stroke();
  27912. }
  27913. ctx.restore();
  27914. } else {
  27915. if (fillStrokeMode === TextRenderingMode.FILL ||
  27916. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27917. ctx.fillText(character, x, y);
  27918. }
  27919. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27920. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27921. ctx.strokeText(character, x, y);
  27922. }
  27923. }
  27924. if (isAddToPathSet) {
  27925. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  27926. paths.push({
  27927. transform: ctx.mozCurrentTransform,
  27928. x: x,
  27929. y: y,
  27930. fontSize: fontSize,
  27931. addToPath: addToPath
  27932. });
  27933. }
  27934. },
  27935. get isFontSubpixelAAEnabled() {
  27936. // Checks if anti-aliasing is enabled when scaled text is painted.
  27937. // On Windows GDI scaled fonts looks bad.
  27938. var ctx = document.createElement('canvas').getContext('2d');
  27939. ctx.scale(1.5, 1);
  27940. ctx.fillText('I', 0, 10);
  27941. var data = ctx.getImageData(0, 0, 10, 10).data;
  27942. var enabled = false;
  27943. for (var i = 3; i < data.length; i += 4) {
  27944. if (data[i] > 0 && data[i] < 255) {
  27945. enabled = true;
  27946. break;
  27947. }
  27948. }
  27949. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  27950. },
  27951. showText: function CanvasGraphics_showText(glyphs) {
  27952. var current = this.current;
  27953. var font = current.font;
  27954. if (font.isType3Font) {
  27955. return this.showType3Text(glyphs);
  27956. }
  27957. var fontSize = current.fontSize;
  27958. if (fontSize === 0) {
  27959. return;
  27960. }
  27961. var ctx = this.ctx;
  27962. var fontSizeScale = current.fontSizeScale;
  27963. var charSpacing = current.charSpacing;
  27964. var wordSpacing = current.wordSpacing;
  27965. var fontDirection = current.fontDirection;
  27966. var textHScale = current.textHScale * fontDirection;
  27967. var glyphsLength = glyphs.length;
  27968. var vertical = font.vertical;
  27969. var spacingDir = vertical ? 1 : -1;
  27970. var defaultVMetrics = font.defaultVMetrics;
  27971. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  27972. var simpleFillText =
  27973. current.textRenderingMode === TextRenderingMode.FILL &&
  27974. !font.disableFontFace;
  27975. ctx.save();
  27976. ctx.transform.apply(ctx, current.textMatrix);
  27977. ctx.translate(current.x, current.y + current.textRise);
  27978. if (current.patternFill) {
  27979. // TODO: Some shading patterns are not applied correctly to text,
  27980. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  27981. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  27982. }
  27983. if (fontDirection > 0) {
  27984. ctx.scale(textHScale, -1);
  27985. } else {
  27986. ctx.scale(textHScale, 1);
  27987. }
  27988. var lineWidth = current.lineWidth;
  27989. var scale = current.textMatrixScale;
  27990. if (scale === 0 || lineWidth === 0) {
  27991. var fillStrokeMode = current.textRenderingMode &
  27992. TextRenderingMode.FILL_STROKE_MASK;
  27993. if (fillStrokeMode === TextRenderingMode.STROKE ||
  27994. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  27995. this.cachedGetSinglePixelWidth = null;
  27996. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  27997. }
  27998. } else {
  27999. lineWidth /= scale;
  28000. }
  28001. if (fontSizeScale !== 1.0) {
  28002. ctx.scale(fontSizeScale, fontSizeScale);
  28003. lineWidth /= fontSizeScale;
  28004. }
  28005. ctx.lineWidth = lineWidth;
  28006. var x = 0, i;
  28007. for (i = 0; i < glyphsLength; ++i) {
  28008. var glyph = glyphs[i];
  28009. if (isNum(glyph)) {
  28010. x += spacingDir * glyph * fontSize / 1000;
  28011. continue;
  28012. }
  28013. var restoreNeeded = false;
  28014. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  28015. var character = glyph.fontChar;
  28016. var accent = glyph.accent;
  28017. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  28018. var width = glyph.width;
  28019. if (vertical) {
  28020. var vmetric, vx, vy;
  28021. vmetric = glyph.vmetric || defaultVMetrics;
  28022. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  28023. vx = -vx * widthAdvanceScale;
  28024. vy = vmetric[2] * widthAdvanceScale;
  28025. width = vmetric ? -vmetric[0] : width;
  28026. scaledX = vx / fontSizeScale;
  28027. scaledY = (x + vy) / fontSizeScale;
  28028. } else {
  28029. scaledX = x / fontSizeScale;
  28030. scaledY = 0;
  28031. }
  28032. if (font.remeasure && width > 0) {
  28033. // Some standard fonts may not have the exact width: rescale per
  28034. // character if measured width is greater than expected glyph width
  28035. // and subpixel-aa is enabled, otherwise just center the glyph.
  28036. var measuredWidth = ctx.measureText(character).width * 1000 /
  28037. fontSize * fontSizeScale;
  28038. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  28039. var characterScaleX = width / measuredWidth;
  28040. restoreNeeded = true;
  28041. ctx.save();
  28042. ctx.scale(characterScaleX, 1);
  28043. scaledX /= characterScaleX;
  28044. } else if (width !== measuredWidth) {
  28045. scaledX += (width - measuredWidth) / 2000 *
  28046. fontSize / fontSizeScale;
  28047. }
  28048. }
  28049. if (simpleFillText && !accent) {
  28050. // common case
  28051. ctx.fillText(character, scaledX, scaledY);
  28052. } else {
  28053. this.paintChar(character, scaledX, scaledY);
  28054. if (accent) {
  28055. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  28056. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  28057. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  28058. }
  28059. }
  28060. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  28061. x += charWidth;
  28062. if (restoreNeeded) {
  28063. ctx.restore();
  28064. }
  28065. }
  28066. if (vertical) {
  28067. current.y -= x * textHScale;
  28068. } else {
  28069. current.x += x * textHScale;
  28070. }
  28071. ctx.restore();
  28072. },
  28073. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  28074. // Type3 fonts - each glyph is a "mini-PDF"
  28075. var ctx = this.ctx;
  28076. var current = this.current;
  28077. var font = current.font;
  28078. var fontSize = current.fontSize;
  28079. var fontDirection = current.fontDirection;
  28080. var spacingDir = font.vertical ? 1 : -1;
  28081. var charSpacing = current.charSpacing;
  28082. var wordSpacing = current.wordSpacing;
  28083. var textHScale = current.textHScale * fontDirection;
  28084. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  28085. var glyphsLength = glyphs.length;
  28086. var isTextInvisible =
  28087. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  28088. var i, glyph, width, spacingLength;
  28089. if (isTextInvisible || fontSize === 0) {
  28090. return;
  28091. }
  28092. this.cachedGetSinglePixelWidth = null;
  28093. ctx.save();
  28094. ctx.transform.apply(ctx, current.textMatrix);
  28095. ctx.translate(current.x, current.y);
  28096. ctx.scale(textHScale, fontDirection);
  28097. for (i = 0; i < glyphsLength; ++i) {
  28098. glyph = glyphs[i];
  28099. if (isNum(glyph)) {
  28100. spacingLength = spacingDir * glyph * fontSize / 1000;
  28101. this.ctx.translate(spacingLength, 0);
  28102. current.x += spacingLength * textHScale;
  28103. continue;
  28104. }
  28105. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  28106. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  28107. if (!operatorList) {
  28108. warn('Type3 character \"' + glyph.operatorListId +
  28109. '\" is not available');
  28110. continue;
  28111. }
  28112. this.processingType3 = glyph;
  28113. this.save();
  28114. ctx.scale(fontSize, fontSize);
  28115. ctx.transform.apply(ctx, fontMatrix);
  28116. this.executeOperatorList(operatorList);
  28117. this.restore();
  28118. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  28119. width = transformed[0] * fontSize + spacing;
  28120. ctx.translate(width, 0);
  28121. current.x += width * textHScale;
  28122. }
  28123. ctx.restore();
  28124. this.processingType3 = null;
  28125. },
  28126. // Type3 fonts
  28127. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  28128. // We can safely ignore this since the width should be the same
  28129. // as the width in the Widths array.
  28130. },
  28131. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  28132. yWidth,
  28133. llx,
  28134. lly,
  28135. urx,
  28136. ury) {
  28137. // TODO According to the spec we're also suppose to ignore any operators
  28138. // that set color or include images while processing this type3 font.
  28139. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  28140. this.clip();
  28141. this.endPath();
  28142. },
  28143. // Color
  28144. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  28145. var pattern;
  28146. if (IR[0] === 'TilingPattern') {
  28147. var color = IR[1];
  28148. var baseTransform = this.baseTransform ||
  28149. this.ctx.mozCurrentTransform.slice();
  28150. var self = this;
  28151. var canvasGraphicsFactory = {
  28152. createCanvasGraphics: function (ctx) {
  28153. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  28154. }
  28155. };
  28156. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  28157. baseTransform);
  28158. } else {
  28159. pattern = getShadingPatternFromIR(IR);
  28160. }
  28161. return pattern;
  28162. },
  28163. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  28164. this.current.strokeColor = this.getColorN_Pattern(arguments);
  28165. },
  28166. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  28167. this.current.fillColor = this.getColorN_Pattern(arguments);
  28168. this.current.patternFill = true;
  28169. },
  28170. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  28171. var color = Util.makeCssRgb(r, g, b);
  28172. this.ctx.strokeStyle = color;
  28173. this.current.strokeColor = color;
  28174. },
  28175. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  28176. var color = Util.makeCssRgb(r, g, b);
  28177. this.ctx.fillStyle = color;
  28178. this.current.fillColor = color;
  28179. this.current.patternFill = false;
  28180. },
  28181. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  28182. var ctx = this.ctx;
  28183. this.save();
  28184. var pattern = getShadingPatternFromIR(patternIR);
  28185. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  28186. var inv = ctx.mozCurrentTransformInverse;
  28187. if (inv) {
  28188. var canvas = ctx.canvas;
  28189. var width = canvas.width;
  28190. var height = canvas.height;
  28191. var bl = Util.applyTransform([0, 0], inv);
  28192. var br = Util.applyTransform([0, height], inv);
  28193. var ul = Util.applyTransform([width, 0], inv);
  28194. var ur = Util.applyTransform([width, height], inv);
  28195. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  28196. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  28197. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  28198. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  28199. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  28200. } else {
  28201. // HACK to draw the gradient onto an infinite rectangle.
  28202. // PDF gradients are drawn across the entire image while
  28203. // Canvas only allows gradients to be drawn in a rectangle
  28204. // The following bug should allow us to remove this.
  28205. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  28206. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  28207. }
  28208. this.restore();
  28209. },
  28210. // Images
  28211. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  28212. error('Should not call beginInlineImage');
  28213. },
  28214. beginImageData: function CanvasGraphics_beginImageData() {
  28215. error('Should not call beginImageData');
  28216. },
  28217. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  28218. bbox) {
  28219. this.save();
  28220. this.baseTransformStack.push(this.baseTransform);
  28221. if (isArray(matrix) && 6 === matrix.length) {
  28222. this.transform.apply(this, matrix);
  28223. }
  28224. this.baseTransform = this.ctx.mozCurrentTransform;
  28225. if (isArray(bbox) && 4 === bbox.length) {
  28226. var width = bbox[2] - bbox[0];
  28227. var height = bbox[3] - bbox[1];
  28228. this.ctx.rect(bbox[0], bbox[1], width, height);
  28229. this.clip();
  28230. this.endPath();
  28231. }
  28232. },
  28233. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  28234. this.restore();
  28235. this.baseTransform = this.baseTransformStack.pop();
  28236. },
  28237. beginGroup: function CanvasGraphics_beginGroup(group) {
  28238. this.save();
  28239. var currentCtx = this.ctx;
  28240. // TODO non-isolated groups - according to Rik at adobe non-isolated
  28241. // group results aren't usually that different and they even have tools
  28242. // that ignore this setting. Notes from Rik on implmenting:
  28243. // - When you encounter an transparency group, create a new canvas with
  28244. // the dimensions of the bbox
  28245. // - copy the content from the previous canvas to the new canvas
  28246. // - draw as usual
  28247. // - remove the backdrop alpha:
  28248. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  28249. // value of your transparency group and 'alphaBackdrop' the alpha of the
  28250. // backdrop
  28251. // - remove background color:
  28252. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  28253. if (!group.isolated) {
  28254. info('TODO: Support non-isolated groups.');
  28255. }
  28256. // TODO knockout - supposedly possible with the clever use of compositing
  28257. // modes.
  28258. if (group.knockout) {
  28259. warn('Knockout groups not supported.');
  28260. }
  28261. var currentTransform = currentCtx.mozCurrentTransform;
  28262. if (group.matrix) {
  28263. currentCtx.transform.apply(currentCtx, group.matrix);
  28264. }
  28265. assert(group.bbox, 'Bounding box is required.');
  28266. // Based on the current transform figure out how big the bounding box
  28267. // will actually be.
  28268. var bounds = Util.getAxialAlignedBoundingBox(
  28269. group.bbox,
  28270. currentCtx.mozCurrentTransform);
  28271. // Clip the bounding box to the current canvas.
  28272. var canvasBounds = [0,
  28273. 0,
  28274. currentCtx.canvas.width,
  28275. currentCtx.canvas.height];
  28276. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  28277. // Use ceil in case we're between sizes so we don't create canvas that is
  28278. // too small and make the canvas at least 1x1 pixels.
  28279. var offsetX = Math.floor(bounds[0]);
  28280. var offsetY = Math.floor(bounds[1]);
  28281. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  28282. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  28283. var scaleX = 1, scaleY = 1;
  28284. if (drawnWidth > MAX_GROUP_SIZE) {
  28285. scaleX = drawnWidth / MAX_GROUP_SIZE;
  28286. drawnWidth = MAX_GROUP_SIZE;
  28287. }
  28288. if (drawnHeight > MAX_GROUP_SIZE) {
  28289. scaleY = drawnHeight / MAX_GROUP_SIZE;
  28290. drawnHeight = MAX_GROUP_SIZE;
  28291. }
  28292. var cacheId = 'groupAt' + this.groupLevel;
  28293. if (group.smask) {
  28294. // Using two cache entries is case if masks are used one after another.
  28295. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  28296. }
  28297. var scratchCanvas = this.cachedCanvases.getCanvas(
  28298. cacheId, drawnWidth, drawnHeight, true);
  28299. var groupCtx = scratchCanvas.context;
  28300. // Since we created a new canvas that is just the size of the bounding box
  28301. // we have to translate the group ctx.
  28302. groupCtx.scale(1 / scaleX, 1 / scaleY);
  28303. groupCtx.translate(-offsetX, -offsetY);
  28304. groupCtx.transform.apply(groupCtx, currentTransform);
  28305. if (group.smask) {
  28306. // Saving state and cached mask to be used in setGState.
  28307. this.smaskStack.push({
  28308. canvas: scratchCanvas.canvas,
  28309. context: groupCtx,
  28310. offsetX: offsetX,
  28311. offsetY: offsetY,
  28312. scaleX: scaleX,
  28313. scaleY: scaleY,
  28314. subtype: group.smask.subtype,
  28315. backdrop: group.smask.backdrop,
  28316. transferMap: group.smask.transferMap || null
  28317. });
  28318. } else {
  28319. // Setup the current ctx so when the group is popped we draw it at the
  28320. // right location.
  28321. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  28322. currentCtx.translate(offsetX, offsetY);
  28323. currentCtx.scale(scaleX, scaleY);
  28324. }
  28325. // The transparency group inherits all off the current graphics state
  28326. // except the blend mode, soft mask, and alpha constants.
  28327. copyCtxState(currentCtx, groupCtx);
  28328. this.ctx = groupCtx;
  28329. this.setGState([
  28330. ['BM', 'Normal'],
  28331. ['ca', 1],
  28332. ['CA', 1]
  28333. ]);
  28334. this.groupStack.push(currentCtx);
  28335. this.groupLevel++;
  28336. },
  28337. endGroup: function CanvasGraphics_endGroup(group) {
  28338. this.groupLevel--;
  28339. var groupCtx = this.ctx;
  28340. this.ctx = this.groupStack.pop();
  28341. // Turn off image smoothing to avoid sub pixel interpolation which can
  28342. // look kind of blurry for some pdfs.
  28343. if (this.ctx.imageSmoothingEnabled !== undefined) {
  28344. this.ctx.imageSmoothingEnabled = false;
  28345. } else {
  28346. this.ctx.mozImageSmoothingEnabled = false;
  28347. }
  28348. if (group.smask) {
  28349. this.tempSMask = this.smaskStack.pop();
  28350. } else {
  28351. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  28352. }
  28353. this.restore();
  28354. },
  28355. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  28356. this.save();
  28357. this.current = new CanvasExtraState();
  28358. if (this.baseTransform) {
  28359. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  28360. }
  28361. },
  28362. endAnnotations: function CanvasGraphics_endAnnotations() {
  28363. this.restore();
  28364. },
  28365. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  28366. matrix) {
  28367. this.save();
  28368. if (isArray(rect) && 4 === rect.length) {
  28369. var width = rect[2] - rect[0];
  28370. var height = rect[3] - rect[1];
  28371. this.ctx.rect(rect[0], rect[1], width, height);
  28372. this.clip();
  28373. this.endPath();
  28374. }
  28375. this.transform.apply(this, transform);
  28376. this.transform.apply(this, matrix);
  28377. },
  28378. endAnnotation: function CanvasGraphics_endAnnotation() {
  28379. this.restore();
  28380. },
  28381. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  28382. var domImage = this.objs.get(objId);
  28383. if (!domImage) {
  28384. warn('Dependent image isn\'t ready yet');
  28385. return;
  28386. }
  28387. this.save();
  28388. var ctx = this.ctx;
  28389. // scale the image to the unit square
  28390. ctx.scale(1 / w, -1 / h);
  28391. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  28392. 0, -h, w, h);
  28393. if (this.imageLayer) {
  28394. var currentTransform = ctx.mozCurrentTransformInverse;
  28395. var position = this.getCanvasPosition(0, 0);
  28396. this.imageLayer.appendImage({
  28397. objId: objId,
  28398. left: position[0],
  28399. top: position[1],
  28400. width: w / currentTransform[0],
  28401. height: h / currentTransform[3]
  28402. });
  28403. }
  28404. this.restore();
  28405. },
  28406. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  28407. var ctx = this.ctx;
  28408. var width = img.width, height = img.height;
  28409. var fillColor = this.current.fillColor;
  28410. var isPatternFill = this.current.patternFill;
  28411. var glyph = this.processingType3;
  28412. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  28413. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  28414. glyph.compiled =
  28415. compileType3Glyph({data: img.data, width: width, height: height});
  28416. } else {
  28417. glyph.compiled = null;
  28418. }
  28419. }
  28420. if (glyph && glyph.compiled) {
  28421. glyph.compiled(ctx);
  28422. return;
  28423. }
  28424. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28425. width, height);
  28426. var maskCtx = maskCanvas.context;
  28427. maskCtx.save();
  28428. putBinaryImageMask(maskCtx, img);
  28429. maskCtx.globalCompositeOperation = 'source-in';
  28430. maskCtx.fillStyle = isPatternFill ?
  28431. fillColor.getPattern(maskCtx, this) : fillColor;
  28432. maskCtx.fillRect(0, 0, width, height);
  28433. maskCtx.restore();
  28434. this.paintInlineImageXObject(maskCanvas.canvas);
  28435. },
  28436. paintImageMaskXObjectRepeat:
  28437. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  28438. scaleY, positions) {
  28439. var width = imgData.width;
  28440. var height = imgData.height;
  28441. var fillColor = this.current.fillColor;
  28442. var isPatternFill = this.current.patternFill;
  28443. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28444. width, height);
  28445. var maskCtx = maskCanvas.context;
  28446. maskCtx.save();
  28447. putBinaryImageMask(maskCtx, imgData);
  28448. maskCtx.globalCompositeOperation = 'source-in';
  28449. maskCtx.fillStyle = isPatternFill ?
  28450. fillColor.getPattern(maskCtx, this) : fillColor;
  28451. maskCtx.fillRect(0, 0, width, height);
  28452. maskCtx.restore();
  28453. var ctx = this.ctx;
  28454. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  28455. ctx.save();
  28456. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  28457. ctx.scale(1, -1);
  28458. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  28459. 0, -1, 1, 1);
  28460. ctx.restore();
  28461. }
  28462. },
  28463. paintImageMaskXObjectGroup:
  28464. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  28465. var ctx = this.ctx;
  28466. var fillColor = this.current.fillColor;
  28467. var isPatternFill = this.current.patternFill;
  28468. for (var i = 0, ii = images.length; i < ii; i++) {
  28469. var image = images[i];
  28470. var width = image.width, height = image.height;
  28471. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  28472. width, height);
  28473. var maskCtx = maskCanvas.context;
  28474. maskCtx.save();
  28475. putBinaryImageMask(maskCtx, image);
  28476. maskCtx.globalCompositeOperation = 'source-in';
  28477. maskCtx.fillStyle = isPatternFill ?
  28478. fillColor.getPattern(maskCtx, this) : fillColor;
  28479. maskCtx.fillRect(0, 0, width, height);
  28480. maskCtx.restore();
  28481. ctx.save();
  28482. ctx.transform.apply(ctx, image.transform);
  28483. ctx.scale(1, -1);
  28484. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  28485. 0, -1, 1, 1);
  28486. ctx.restore();
  28487. }
  28488. },
  28489. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  28490. var imgData = this.objs.get(objId);
  28491. if (!imgData) {
  28492. warn('Dependent image isn\'t ready yet');
  28493. return;
  28494. }
  28495. this.paintInlineImageXObject(imgData);
  28496. },
  28497. paintImageXObjectRepeat:
  28498. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  28499. positions) {
  28500. var imgData = this.objs.get(objId);
  28501. if (!imgData) {
  28502. warn('Dependent image isn\'t ready yet');
  28503. return;
  28504. }
  28505. var width = imgData.width;
  28506. var height = imgData.height;
  28507. var map = [];
  28508. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  28509. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  28510. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  28511. }
  28512. this.paintInlineImageXObjectGroup(imgData, map);
  28513. },
  28514. paintInlineImageXObject:
  28515. function CanvasGraphics_paintInlineImageXObject(imgData) {
  28516. var width = imgData.width;
  28517. var height = imgData.height;
  28518. var ctx = this.ctx;
  28519. this.save();
  28520. // scale the image to the unit square
  28521. ctx.scale(1 / width, -1 / height);
  28522. var currentTransform = ctx.mozCurrentTransformInverse;
  28523. var a = currentTransform[0], b = currentTransform[1];
  28524. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  28525. var c = currentTransform[2], d = currentTransform[3];
  28526. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  28527. var imgToPaint, tmpCanvas;
  28528. // instanceof HTMLElement does not work in jsdom node.js module
  28529. if (imgData instanceof HTMLElement || !imgData.data) {
  28530. imgToPaint = imgData;
  28531. } else {
  28532. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  28533. width, height);
  28534. var tmpCtx = tmpCanvas.context;
  28535. putBinaryImageData(tmpCtx, imgData);
  28536. imgToPaint = tmpCanvas.canvas;
  28537. }
  28538. var paintWidth = width, paintHeight = height;
  28539. var tmpCanvasId = 'prescale1';
  28540. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  28541. // pixels during drawImage operation, painting on the temporary canvas(es)
  28542. // that are twice smaller in size
  28543. while ((widthScale > 2 && paintWidth > 1) ||
  28544. (heightScale > 2 && paintHeight > 1)) {
  28545. var newWidth = paintWidth, newHeight = paintHeight;
  28546. if (widthScale > 2 && paintWidth > 1) {
  28547. newWidth = Math.ceil(paintWidth / 2);
  28548. widthScale /= paintWidth / newWidth;
  28549. }
  28550. if (heightScale > 2 && paintHeight > 1) {
  28551. newHeight = Math.ceil(paintHeight / 2);
  28552. heightScale /= paintHeight / newHeight;
  28553. }
  28554. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  28555. newWidth, newHeight);
  28556. tmpCtx = tmpCanvas.context;
  28557. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  28558. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  28559. 0, 0, newWidth, newHeight);
  28560. imgToPaint = tmpCanvas.canvas;
  28561. paintWidth = newWidth;
  28562. paintHeight = newHeight;
  28563. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  28564. }
  28565. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  28566. 0, -height, width, height);
  28567. if (this.imageLayer) {
  28568. var position = this.getCanvasPosition(0, -height);
  28569. this.imageLayer.appendImage({
  28570. imgData: imgData,
  28571. left: position[0],
  28572. top: position[1],
  28573. width: width / currentTransform[0],
  28574. height: height / currentTransform[3]
  28575. });
  28576. }
  28577. this.restore();
  28578. },
  28579. paintInlineImageXObjectGroup:
  28580. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  28581. var ctx = this.ctx;
  28582. var w = imgData.width;
  28583. var h = imgData.height;
  28584. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  28585. var tmpCtx = tmpCanvas.context;
  28586. putBinaryImageData(tmpCtx, imgData);
  28587. for (var i = 0, ii = map.length; i < ii; i++) {
  28588. var entry = map[i];
  28589. ctx.save();
  28590. ctx.transform.apply(ctx, entry.transform);
  28591. ctx.scale(1, -1);
  28592. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  28593. 0, -1, 1, 1);
  28594. if (this.imageLayer) {
  28595. var position = this.getCanvasPosition(entry.x, entry.y);
  28596. this.imageLayer.appendImage({
  28597. imgData: imgData,
  28598. left: position[0],
  28599. top: position[1],
  28600. width: w,
  28601. height: h
  28602. });
  28603. }
  28604. ctx.restore();
  28605. }
  28606. },
  28607. paintSolidColorImageMask:
  28608. function CanvasGraphics_paintSolidColorImageMask() {
  28609. this.ctx.fillRect(0, 0, 1, 1);
  28610. },
  28611. paintXObject: function CanvasGraphics_paintXObject() {
  28612. warn('Unsupported \'paintXObject\' command.');
  28613. },
  28614. // Marked content
  28615. markPoint: function CanvasGraphics_markPoint(tag) {
  28616. // TODO Marked content.
  28617. },
  28618. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  28619. // TODO Marked content.
  28620. },
  28621. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  28622. // TODO Marked content.
  28623. },
  28624. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  28625. tag, properties) {
  28626. // TODO Marked content.
  28627. },
  28628. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  28629. // TODO Marked content.
  28630. },
  28631. // Compatibility
  28632. beginCompat: function CanvasGraphics_beginCompat() {
  28633. // TODO ignore undefined operators (should we do that anyway?)
  28634. },
  28635. endCompat: function CanvasGraphics_endCompat() {
  28636. // TODO stop ignoring undefined operators
  28637. },
  28638. // Helper functions
  28639. consumePath: function CanvasGraphics_consumePath() {
  28640. var ctx = this.ctx;
  28641. if (this.pendingClip) {
  28642. if (this.pendingClip === EO_CLIP) {
  28643. if (ctx.mozFillRule !== undefined) {
  28644. ctx.mozFillRule = 'evenodd';
  28645. ctx.clip();
  28646. ctx.mozFillRule = 'nonzero';
  28647. } else {
  28648. ctx.clip('evenodd');
  28649. }
  28650. } else {
  28651. ctx.clip();
  28652. }
  28653. this.pendingClip = null;
  28654. }
  28655. ctx.beginPath();
  28656. },
  28657. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  28658. if (this.cachedGetSinglePixelWidth === null) {
  28659. var inverse = this.ctx.mozCurrentTransformInverse;
  28660. // max of the current horizontal and vertical scale
  28661. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  28662. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  28663. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  28664. }
  28665. return this.cachedGetSinglePixelWidth;
  28666. },
  28667. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  28668. var transform = this.ctx.mozCurrentTransform;
  28669. return [
  28670. transform[0] * x + transform[2] * y + transform[4],
  28671. transform[1] * x + transform[3] * y + transform[5]
  28672. ];
  28673. }
  28674. };
  28675. for (var op in OPS) {
  28676. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  28677. }
  28678. return CanvasGraphics;
  28679. })();
  28680. exports.CanvasGraphics = CanvasGraphics;
  28681. exports.createScratchCanvas = createScratchCanvas;
  28682. }));
  28683. (function (root, factory) {
  28684. {
  28685. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  28686. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  28687. }
  28688. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  28689. var Util = sharedUtil.Util;
  28690. var assert = sharedUtil.assert;
  28691. var error = sharedUtil.error;
  28692. var isInt = sharedUtil.isInt;
  28693. var isString = sharedUtil.isString;
  28694. var warn = sharedUtil.warn;
  28695. var isName = corePrimitives.isName;
  28696. var isCmd = corePrimitives.isCmd;
  28697. var isStream = corePrimitives.isStream;
  28698. var StringStream = coreStream.StringStream;
  28699. var Lexer = coreParser.Lexer;
  28700. var isEOF = coreParser.isEOF;
  28701. var BUILT_IN_CMAPS = [
  28702. // << Start unicode maps.
  28703. 'Adobe-GB1-UCS2',
  28704. 'Adobe-CNS1-UCS2',
  28705. 'Adobe-Japan1-UCS2',
  28706. 'Adobe-Korea1-UCS2',
  28707. // >> End unicode maps.
  28708. '78-EUC-H',
  28709. '78-EUC-V',
  28710. '78-H',
  28711. '78-RKSJ-H',
  28712. '78-RKSJ-V',
  28713. '78-V',
  28714. '78ms-RKSJ-H',
  28715. '78ms-RKSJ-V',
  28716. '83pv-RKSJ-H',
  28717. '90ms-RKSJ-H',
  28718. '90ms-RKSJ-V',
  28719. '90msp-RKSJ-H',
  28720. '90msp-RKSJ-V',
  28721. '90pv-RKSJ-H',
  28722. '90pv-RKSJ-V',
  28723. 'Add-H',
  28724. 'Add-RKSJ-H',
  28725. 'Add-RKSJ-V',
  28726. 'Add-V',
  28727. 'Adobe-CNS1-0',
  28728. 'Adobe-CNS1-1',
  28729. 'Adobe-CNS1-2',
  28730. 'Adobe-CNS1-3',
  28731. 'Adobe-CNS1-4',
  28732. 'Adobe-CNS1-5',
  28733. 'Adobe-CNS1-6',
  28734. 'Adobe-GB1-0',
  28735. 'Adobe-GB1-1',
  28736. 'Adobe-GB1-2',
  28737. 'Adobe-GB1-3',
  28738. 'Adobe-GB1-4',
  28739. 'Adobe-GB1-5',
  28740. 'Adobe-Japan1-0',
  28741. 'Adobe-Japan1-1',
  28742. 'Adobe-Japan1-2',
  28743. 'Adobe-Japan1-3',
  28744. 'Adobe-Japan1-4',
  28745. 'Adobe-Japan1-5',
  28746. 'Adobe-Japan1-6',
  28747. 'Adobe-Korea1-0',
  28748. 'Adobe-Korea1-1',
  28749. 'Adobe-Korea1-2',
  28750. 'B5-H',
  28751. 'B5-V',
  28752. 'B5pc-H',
  28753. 'B5pc-V',
  28754. 'CNS-EUC-H',
  28755. 'CNS-EUC-V',
  28756. 'CNS1-H',
  28757. 'CNS1-V',
  28758. 'CNS2-H',
  28759. 'CNS2-V',
  28760. 'ETHK-B5-H',
  28761. 'ETHK-B5-V',
  28762. 'ETen-B5-H',
  28763. 'ETen-B5-V',
  28764. 'ETenms-B5-H',
  28765. 'ETenms-B5-V',
  28766. 'EUC-H',
  28767. 'EUC-V',
  28768. 'Ext-H',
  28769. 'Ext-RKSJ-H',
  28770. 'Ext-RKSJ-V',
  28771. 'Ext-V',
  28772. 'GB-EUC-H',
  28773. 'GB-EUC-V',
  28774. 'GB-H',
  28775. 'GB-V',
  28776. 'GBK-EUC-H',
  28777. 'GBK-EUC-V',
  28778. 'GBK2K-H',
  28779. 'GBK2K-V',
  28780. 'GBKp-EUC-H',
  28781. 'GBKp-EUC-V',
  28782. 'GBT-EUC-H',
  28783. 'GBT-EUC-V',
  28784. 'GBT-H',
  28785. 'GBT-V',
  28786. 'GBTpc-EUC-H',
  28787. 'GBTpc-EUC-V',
  28788. 'GBpc-EUC-H',
  28789. 'GBpc-EUC-V',
  28790. 'H',
  28791. 'HKdla-B5-H',
  28792. 'HKdla-B5-V',
  28793. 'HKdlb-B5-H',
  28794. 'HKdlb-B5-V',
  28795. 'HKgccs-B5-H',
  28796. 'HKgccs-B5-V',
  28797. 'HKm314-B5-H',
  28798. 'HKm314-B5-V',
  28799. 'HKm471-B5-H',
  28800. 'HKm471-B5-V',
  28801. 'HKscs-B5-H',
  28802. 'HKscs-B5-V',
  28803. 'Hankaku',
  28804. 'Hiragana',
  28805. 'KSC-EUC-H',
  28806. 'KSC-EUC-V',
  28807. 'KSC-H',
  28808. 'KSC-Johab-H',
  28809. 'KSC-Johab-V',
  28810. 'KSC-V',
  28811. 'KSCms-UHC-H',
  28812. 'KSCms-UHC-HW-H',
  28813. 'KSCms-UHC-HW-V',
  28814. 'KSCms-UHC-V',
  28815. 'KSCpc-EUC-H',
  28816. 'KSCpc-EUC-V',
  28817. 'Katakana',
  28818. 'NWP-H',
  28819. 'NWP-V',
  28820. 'RKSJ-H',
  28821. 'RKSJ-V',
  28822. 'Roman',
  28823. 'UniCNS-UCS2-H',
  28824. 'UniCNS-UCS2-V',
  28825. 'UniCNS-UTF16-H',
  28826. 'UniCNS-UTF16-V',
  28827. 'UniCNS-UTF32-H',
  28828. 'UniCNS-UTF32-V',
  28829. 'UniCNS-UTF8-H',
  28830. 'UniCNS-UTF8-V',
  28831. 'UniGB-UCS2-H',
  28832. 'UniGB-UCS2-V',
  28833. 'UniGB-UTF16-H',
  28834. 'UniGB-UTF16-V',
  28835. 'UniGB-UTF32-H',
  28836. 'UniGB-UTF32-V',
  28837. 'UniGB-UTF8-H',
  28838. 'UniGB-UTF8-V',
  28839. 'UniJIS-UCS2-H',
  28840. 'UniJIS-UCS2-HW-H',
  28841. 'UniJIS-UCS2-HW-V',
  28842. 'UniJIS-UCS2-V',
  28843. 'UniJIS-UTF16-H',
  28844. 'UniJIS-UTF16-V',
  28845. 'UniJIS-UTF32-H',
  28846. 'UniJIS-UTF32-V',
  28847. 'UniJIS-UTF8-H',
  28848. 'UniJIS-UTF8-V',
  28849. 'UniJIS2004-UTF16-H',
  28850. 'UniJIS2004-UTF16-V',
  28851. 'UniJIS2004-UTF32-H',
  28852. 'UniJIS2004-UTF32-V',
  28853. 'UniJIS2004-UTF8-H',
  28854. 'UniJIS2004-UTF8-V',
  28855. 'UniJISPro-UCS2-HW-V',
  28856. 'UniJISPro-UCS2-V',
  28857. 'UniJISPro-UTF8-V',
  28858. 'UniJISX0213-UTF32-H',
  28859. 'UniJISX0213-UTF32-V',
  28860. 'UniJISX02132004-UTF32-H',
  28861. 'UniJISX02132004-UTF32-V',
  28862. 'UniKS-UCS2-H',
  28863. 'UniKS-UCS2-V',
  28864. 'UniKS-UTF16-H',
  28865. 'UniKS-UTF16-V',
  28866. 'UniKS-UTF32-H',
  28867. 'UniKS-UTF32-V',
  28868. 'UniKS-UTF8-H',
  28869. 'UniKS-UTF8-V',
  28870. 'V',
  28871. 'WP-Symbol'];
  28872. // CMap, not to be confused with TrueType's cmap.
  28873. var CMap = (function CMapClosure() {
  28874. function CMap(builtInCMap) {
  28875. // Codespace ranges are stored as follows:
  28876. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  28877. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  28878. this.codespaceRanges = [[], [], [], []];
  28879. this.numCodespaceRanges = 0;
  28880. // Map entries have one of two forms.
  28881. // - cid chars are 16-bit unsigned integers, stored as integers.
  28882. // - bf chars are variable-length byte sequences, stored as strings, with
  28883. // one byte per character.
  28884. this._map = [];
  28885. this.name = '';
  28886. this.vertical = false;
  28887. this.useCMap = null;
  28888. this.builtInCMap = builtInCMap;
  28889. }
  28890. CMap.prototype = {
  28891. addCodespaceRange: function(n, low, high) {
  28892. this.codespaceRanges[n - 1].push(low, high);
  28893. this.numCodespaceRanges++;
  28894. },
  28895. mapCidRange: function(low, high, dstLow) {
  28896. while (low <= high) {
  28897. this._map[low++] = dstLow++;
  28898. }
  28899. },
  28900. mapBfRange: function(low, high, dstLow) {
  28901. var lastByte = dstLow.length - 1;
  28902. while (low <= high) {
  28903. this._map[low++] = dstLow;
  28904. // Only the last byte has to be incremented.
  28905. dstLow = dstLow.substr(0, lastByte) +
  28906. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  28907. }
  28908. },
  28909. mapBfRangeToArray: function(low, high, array) {
  28910. var i = 0, ii = array.length;
  28911. while (low <= high && i < ii) {
  28912. this._map[low] = array[i++];
  28913. ++low;
  28914. }
  28915. },
  28916. // This is used for both bf and cid chars.
  28917. mapOne: function(src, dst) {
  28918. this._map[src] = dst;
  28919. },
  28920. lookup: function(code) {
  28921. return this._map[code];
  28922. },
  28923. contains: function(code) {
  28924. return this._map[code] !== undefined;
  28925. },
  28926. forEach: function(callback) {
  28927. // Most maps have fewer than 65536 entries, and for those we use normal
  28928. // array iteration. But really sparse tables are possible -- e.g. with
  28929. // indices in the *billions*. For such tables we use for..in, which isn't
  28930. // ideal because it stringifies the indices for all present elements, but
  28931. // it does avoid iterating over every undefined entry.
  28932. var map = this._map;
  28933. var length = map.length;
  28934. var i;
  28935. if (length <= 0x10000) {
  28936. for (i = 0; i < length; i++) {
  28937. if (map[i] !== undefined) {
  28938. callback(i, map[i]);
  28939. }
  28940. }
  28941. } else {
  28942. for (i in this._map) {
  28943. callback(i, map[i]);
  28944. }
  28945. }
  28946. },
  28947. charCodeOf: function(value) {
  28948. return this._map.indexOf(value);
  28949. },
  28950. getMap: function() {
  28951. return this._map;
  28952. },
  28953. readCharCode: function(str, offset, out) {
  28954. var c = 0;
  28955. var codespaceRanges = this.codespaceRanges;
  28956. var codespaceRangesLen = this.codespaceRanges.length;
  28957. // 9.7.6.2 CMap Mapping
  28958. // The code length is at most 4.
  28959. for (var n = 0; n < codespaceRangesLen; n++) {
  28960. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  28961. // Check each codespace range to see if it falls within.
  28962. var codespaceRange = codespaceRanges[n];
  28963. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  28964. var low = codespaceRange[k++];
  28965. var high = codespaceRange[k++];
  28966. if (c >= low && c <= high) {
  28967. out.charcode = c;
  28968. out.length = n + 1;
  28969. return;
  28970. }
  28971. }
  28972. }
  28973. out.charcode = 0;
  28974. out.length = 1;
  28975. },
  28976. get length() {
  28977. return this._map.length;
  28978. },
  28979. get isIdentityCMap() {
  28980. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  28981. return false;
  28982. }
  28983. if (this._map.length !== 0x10000) {
  28984. return false;
  28985. }
  28986. for (var i = 0; i < 0x10000; i++) {
  28987. if (this._map[i] !== i) {
  28988. return false;
  28989. }
  28990. }
  28991. return true;
  28992. }
  28993. };
  28994. return CMap;
  28995. })();
  28996. // A special case of CMap, where the _map array implicitly has a length of
  28997. // 65536 and each element is equal to its index.
  28998. var IdentityCMap = (function IdentityCMapClosure() {
  28999. function IdentityCMap(vertical, n) {
  29000. CMap.call(this);
  29001. this.vertical = vertical;
  29002. this.addCodespaceRange(n, 0, 0xffff);
  29003. }
  29004. Util.inherit(IdentityCMap, CMap, {});
  29005. IdentityCMap.prototype = {
  29006. addCodespaceRange: CMap.prototype.addCodespaceRange,
  29007. mapCidRange: function(low, high, dstLow) {
  29008. error('should not call mapCidRange');
  29009. },
  29010. mapBfRange: function(low, high, dstLow) {
  29011. error('should not call mapBfRange');
  29012. },
  29013. mapBfRangeToArray: function(low, high, array) {
  29014. error('should not call mapBfRangeToArray');
  29015. },
  29016. mapOne: function(src, dst) {
  29017. error('should not call mapCidOne');
  29018. },
  29019. lookup: function(code) {
  29020. return (isInt(code) && code <= 0xffff) ? code : undefined;
  29021. },
  29022. contains: function(code) {
  29023. return isInt(code) && code <= 0xffff;
  29024. },
  29025. forEach: function(callback) {
  29026. for (var i = 0; i <= 0xffff; i++) {
  29027. callback(i, i);
  29028. }
  29029. },
  29030. charCodeOf: function(value) {
  29031. return (isInt(value) && value <= 0xffff) ? value : -1;
  29032. },
  29033. getMap: function() {
  29034. // Sometimes identity maps must be instantiated, but it's rare.
  29035. var map = new Array(0x10000);
  29036. for (var i = 0; i <= 0xffff; i++) {
  29037. map[i] = i;
  29038. }
  29039. return map;
  29040. },
  29041. readCharCode: CMap.prototype.readCharCode,
  29042. get length() {
  29043. return 0x10000;
  29044. },
  29045. get isIdentityCMap() {
  29046. error('should not access .isIdentityCMap');
  29047. }
  29048. };
  29049. return IdentityCMap;
  29050. })();
  29051. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  29052. function fetchBinaryData(url) {
  29053. var nonBinaryRequest = PDFJS.disableWorker;
  29054. var request = new XMLHttpRequest();
  29055. request.open('GET', url, false);
  29056. if (!nonBinaryRequest) {
  29057. try {
  29058. request.responseType = 'arraybuffer';
  29059. nonBinaryRequest = request.responseType !== 'arraybuffer';
  29060. } catch (e) {
  29061. nonBinaryRequest = true;
  29062. }
  29063. }
  29064. if (nonBinaryRequest && request.overrideMimeType) {
  29065. request.overrideMimeType('text/plain; charset=x-user-defined');
  29066. }
  29067. request.send(null);
  29068. if (nonBinaryRequest ? !request.responseText : !request.response) {
  29069. error('Unable to get binary cMap at: ' + url);
  29070. }
  29071. if (nonBinaryRequest) {
  29072. var data = Array.prototype.map.call(request.responseText, function (ch) {
  29073. return ch.charCodeAt(0) & 255;
  29074. });
  29075. return new Uint8Array(data);
  29076. }
  29077. return new Uint8Array(request.response);
  29078. }
  29079. function hexToInt(a, size) {
  29080. var n = 0;
  29081. for (var i = 0; i <= size; i++) {
  29082. n = (n << 8) | a[i];
  29083. }
  29084. return n >>> 0;
  29085. }
  29086. function hexToStr(a, size) {
  29087. // This code is hot. Special-case some common values to avoid creating an
  29088. // object with subarray().
  29089. if (size === 1) {
  29090. return String.fromCharCode(a[0], a[1]);
  29091. }
  29092. if (size === 3) {
  29093. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  29094. }
  29095. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  29096. }
  29097. function addHex(a, b, size) {
  29098. var c = 0;
  29099. for (var i = size; i >= 0; i--) {
  29100. c += a[i] + b[i];
  29101. a[i] = c & 255;
  29102. c >>= 8;
  29103. }
  29104. }
  29105. function incHex(a, size) {
  29106. var c = 1;
  29107. for (var i = size; i >= 0 && c > 0; i--) {
  29108. c += a[i];
  29109. a[i] = c & 255;
  29110. c >>= 8;
  29111. }
  29112. }
  29113. var MAX_NUM_SIZE = 16;
  29114. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  29115. function BinaryCMapStream(data) {
  29116. this.buffer = data;
  29117. this.pos = 0;
  29118. this.end = data.length;
  29119. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  29120. }
  29121. BinaryCMapStream.prototype = {
  29122. readByte: function () {
  29123. if (this.pos >= this.end) {
  29124. return -1;
  29125. }
  29126. return this.buffer[this.pos++];
  29127. },
  29128. readNumber: function () {
  29129. var n = 0;
  29130. var last;
  29131. do {
  29132. var b = this.readByte();
  29133. if (b < 0) {
  29134. error('unexpected EOF in bcmap');
  29135. }
  29136. last = !(b & 0x80);
  29137. n = (n << 7) | (b & 0x7F);
  29138. } while (!last);
  29139. return n;
  29140. },
  29141. readSigned: function () {
  29142. var n = this.readNumber();
  29143. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  29144. },
  29145. readHex: function (num, size) {
  29146. num.set(this.buffer.subarray(this.pos,
  29147. this.pos + size + 1));
  29148. this.pos += size + 1;
  29149. },
  29150. readHexNumber: function (num, size) {
  29151. var last;
  29152. var stack = this.tmpBuf, sp = 0;
  29153. do {
  29154. var b = this.readByte();
  29155. if (b < 0) {
  29156. error('unexpected EOF in bcmap');
  29157. }
  29158. last = !(b & 0x80);
  29159. stack[sp++] = b & 0x7F;
  29160. } while (!last);
  29161. var i = size, buffer = 0, bufferSize = 0;
  29162. while (i >= 0) {
  29163. while (bufferSize < 8 && stack.length > 0) {
  29164. buffer = (stack[--sp] << bufferSize) | buffer;
  29165. bufferSize += 7;
  29166. }
  29167. num[i] = buffer & 255;
  29168. i--;
  29169. buffer >>= 8;
  29170. bufferSize -= 8;
  29171. }
  29172. },
  29173. readHexSigned: function (num, size) {
  29174. this.readHexNumber(num, size);
  29175. var sign = num[size] & 1 ? 255 : 0;
  29176. var c = 0;
  29177. for (var i = 0; i <= size; i++) {
  29178. c = ((c & 1) << 8) | num[i];
  29179. num[i] = (c >> 1) ^ sign;
  29180. }
  29181. },
  29182. readString: function () {
  29183. var len = this.readNumber();
  29184. var s = '';
  29185. for (var i = 0; i < len; i++) {
  29186. s += String.fromCharCode(this.readNumber());
  29187. }
  29188. return s;
  29189. }
  29190. };
  29191. function processBinaryCMap(url, cMap, extend) {
  29192. var data = fetchBinaryData(url);
  29193. var stream = new BinaryCMapStream(data);
  29194. var header = stream.readByte();
  29195. cMap.vertical = !!(header & 1);
  29196. var useCMap = null;
  29197. var start = new Uint8Array(MAX_NUM_SIZE);
  29198. var end = new Uint8Array(MAX_NUM_SIZE);
  29199. var char = new Uint8Array(MAX_NUM_SIZE);
  29200. var charCode = new Uint8Array(MAX_NUM_SIZE);
  29201. var tmp = new Uint8Array(MAX_NUM_SIZE);
  29202. var code;
  29203. var b;
  29204. while ((b = stream.readByte()) >= 0) {
  29205. var type = b >> 5;
  29206. if (type === 7) { // metadata, e.g. comment or usecmap
  29207. switch (b & 0x1F) {
  29208. case 0:
  29209. stream.readString(); // skipping comment
  29210. break;
  29211. case 1:
  29212. useCMap = stream.readString();
  29213. break;
  29214. }
  29215. continue;
  29216. }
  29217. var sequence = !!(b & 0x10);
  29218. var dataSize = b & 15;
  29219. assert(dataSize + 1 <= MAX_NUM_SIZE);
  29220. var ucs2DataSize = 1;
  29221. var subitemsCount = stream.readNumber();
  29222. var i;
  29223. switch (type) {
  29224. case 0: // codespacerange
  29225. stream.readHex(start, dataSize);
  29226. stream.readHexNumber(end, dataSize);
  29227. addHex(end, start, dataSize);
  29228. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29229. hexToInt(end, dataSize));
  29230. for (i = 1; i < subitemsCount; i++) {
  29231. incHex(end, dataSize);
  29232. stream.readHexNumber(start, dataSize);
  29233. addHex(start, end, dataSize);
  29234. stream.readHexNumber(end, dataSize);
  29235. addHex(end, start, dataSize);
  29236. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  29237. hexToInt(end, dataSize));
  29238. }
  29239. break;
  29240. case 1: // notdefrange
  29241. stream.readHex(start, dataSize);
  29242. stream.readHexNumber(end, dataSize);
  29243. addHex(end, start, dataSize);
  29244. code = stream.readNumber();
  29245. // undefined range, skipping
  29246. for (i = 1; i < subitemsCount; i++) {
  29247. incHex(end, dataSize);
  29248. stream.readHexNumber(start, dataSize);
  29249. addHex(start, end, dataSize);
  29250. stream.readHexNumber(end, dataSize);
  29251. addHex(end, start, dataSize);
  29252. code = stream.readNumber();
  29253. // nop
  29254. }
  29255. break;
  29256. case 2: // cidchar
  29257. stream.readHex(char, dataSize);
  29258. code = stream.readNumber();
  29259. cMap.mapOne(hexToInt(char, dataSize), code);
  29260. for (i = 1; i < subitemsCount; i++) {
  29261. incHex(char, dataSize);
  29262. if (!sequence) {
  29263. stream.readHexNumber(tmp, dataSize);
  29264. addHex(char, tmp, dataSize);
  29265. }
  29266. code = stream.readSigned() + (code + 1);
  29267. cMap.mapOne(hexToInt(char, dataSize), code);
  29268. }
  29269. break;
  29270. case 3: // cidrange
  29271. stream.readHex(start, dataSize);
  29272. stream.readHexNumber(end, dataSize);
  29273. addHex(end, start, dataSize);
  29274. code = stream.readNumber();
  29275. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29276. code);
  29277. for (i = 1; i < subitemsCount; i++) {
  29278. incHex(end, dataSize);
  29279. if (!sequence) {
  29280. stream.readHexNumber(start, dataSize);
  29281. addHex(start, end, dataSize);
  29282. } else {
  29283. start.set(end);
  29284. }
  29285. stream.readHexNumber(end, dataSize);
  29286. addHex(end, start, dataSize);
  29287. code = stream.readNumber();
  29288. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  29289. code);
  29290. }
  29291. break;
  29292. case 4: // bfchar
  29293. stream.readHex(char, ucs2DataSize);
  29294. stream.readHex(charCode, dataSize);
  29295. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29296. hexToStr(charCode, dataSize));
  29297. for (i = 1; i < subitemsCount; i++) {
  29298. incHex(char, ucs2DataSize);
  29299. if (!sequence) {
  29300. stream.readHexNumber(tmp, ucs2DataSize);
  29301. addHex(char, tmp, ucs2DataSize);
  29302. }
  29303. incHex(charCode, dataSize);
  29304. stream.readHexSigned(tmp, dataSize);
  29305. addHex(charCode, tmp, dataSize);
  29306. cMap.mapOne(hexToInt(char, ucs2DataSize),
  29307. hexToStr(charCode, dataSize));
  29308. }
  29309. break;
  29310. case 5: // bfrange
  29311. stream.readHex(start, ucs2DataSize);
  29312. stream.readHexNumber(end, ucs2DataSize);
  29313. addHex(end, start, ucs2DataSize);
  29314. stream.readHex(charCode, dataSize);
  29315. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29316. hexToInt(end, ucs2DataSize),
  29317. hexToStr(charCode, dataSize));
  29318. for (i = 1; i < subitemsCount; i++) {
  29319. incHex(end, ucs2DataSize);
  29320. if (!sequence) {
  29321. stream.readHexNumber(start, ucs2DataSize);
  29322. addHex(start, end, ucs2DataSize);
  29323. } else {
  29324. start.set(end);
  29325. }
  29326. stream.readHexNumber(end, ucs2DataSize);
  29327. addHex(end, start, ucs2DataSize);
  29328. stream.readHex(charCode, dataSize);
  29329. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  29330. hexToInt(end, ucs2DataSize),
  29331. hexToStr(charCode, dataSize));
  29332. }
  29333. break;
  29334. default:
  29335. error('Unknown type: ' + type);
  29336. break;
  29337. }
  29338. }
  29339. if (useCMap) {
  29340. extend(useCMap);
  29341. }
  29342. return cMap;
  29343. }
  29344. function BinaryCMapReader() {}
  29345. BinaryCMapReader.prototype = {
  29346. read: processBinaryCMap
  29347. };
  29348. return BinaryCMapReader;
  29349. })();
  29350. var CMapFactory = (function CMapFactoryClosure() {
  29351. function strToInt(str) {
  29352. var a = 0;
  29353. for (var i = 0; i < str.length; i++) {
  29354. a = (a << 8) | str.charCodeAt(i);
  29355. }
  29356. return a >>> 0;
  29357. }
  29358. function expectString(obj) {
  29359. if (!isString(obj)) {
  29360. error('Malformed CMap: expected string.');
  29361. }
  29362. }
  29363. function expectInt(obj) {
  29364. if (!isInt(obj)) {
  29365. error('Malformed CMap: expected int.');
  29366. }
  29367. }
  29368. function parseBfChar(cMap, lexer) {
  29369. while (true) {
  29370. var obj = lexer.getObj();
  29371. if (isEOF(obj)) {
  29372. break;
  29373. }
  29374. if (isCmd(obj, 'endbfchar')) {
  29375. return;
  29376. }
  29377. expectString(obj);
  29378. var src = strToInt(obj);
  29379. obj = lexer.getObj();
  29380. // TODO are /dstName used?
  29381. expectString(obj);
  29382. var dst = obj;
  29383. cMap.mapOne(src, dst);
  29384. }
  29385. }
  29386. function parseBfRange(cMap, lexer) {
  29387. while (true) {
  29388. var obj = lexer.getObj();
  29389. if (isEOF(obj)) {
  29390. break;
  29391. }
  29392. if (isCmd(obj, 'endbfrange')) {
  29393. return;
  29394. }
  29395. expectString(obj);
  29396. var low = strToInt(obj);
  29397. obj = lexer.getObj();
  29398. expectString(obj);
  29399. var high = strToInt(obj);
  29400. obj = lexer.getObj();
  29401. if (isInt(obj) || isString(obj)) {
  29402. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  29403. cMap.mapBfRange(low, high, dstLow);
  29404. } else if (isCmd(obj, '[')) {
  29405. obj = lexer.getObj();
  29406. var array = [];
  29407. while (!isCmd(obj, ']') && !isEOF(obj)) {
  29408. array.push(obj);
  29409. obj = lexer.getObj();
  29410. }
  29411. cMap.mapBfRangeToArray(low, high, array);
  29412. } else {
  29413. break;
  29414. }
  29415. }
  29416. error('Invalid bf range.');
  29417. }
  29418. function parseCidChar(cMap, lexer) {
  29419. while (true) {
  29420. var obj = lexer.getObj();
  29421. if (isEOF(obj)) {
  29422. break;
  29423. }
  29424. if (isCmd(obj, 'endcidchar')) {
  29425. return;
  29426. }
  29427. expectString(obj);
  29428. var src = strToInt(obj);
  29429. obj = lexer.getObj();
  29430. expectInt(obj);
  29431. var dst = obj;
  29432. cMap.mapOne(src, dst);
  29433. }
  29434. }
  29435. function parseCidRange(cMap, lexer) {
  29436. while (true) {
  29437. var obj = lexer.getObj();
  29438. if (isEOF(obj)) {
  29439. break;
  29440. }
  29441. if (isCmd(obj, 'endcidrange')) {
  29442. return;
  29443. }
  29444. expectString(obj);
  29445. var low = strToInt(obj);
  29446. obj = lexer.getObj();
  29447. expectString(obj);
  29448. var high = strToInt(obj);
  29449. obj = lexer.getObj();
  29450. expectInt(obj);
  29451. var dstLow = obj;
  29452. cMap.mapCidRange(low, high, dstLow);
  29453. }
  29454. }
  29455. function parseCodespaceRange(cMap, lexer) {
  29456. while (true) {
  29457. var obj = lexer.getObj();
  29458. if (isEOF(obj)) {
  29459. break;
  29460. }
  29461. if (isCmd(obj, 'endcodespacerange')) {
  29462. return;
  29463. }
  29464. if (!isString(obj)) {
  29465. break;
  29466. }
  29467. var low = strToInt(obj);
  29468. obj = lexer.getObj();
  29469. if (!isString(obj)) {
  29470. break;
  29471. }
  29472. var high = strToInt(obj);
  29473. cMap.addCodespaceRange(obj.length, low, high);
  29474. }
  29475. error('Invalid codespace range.');
  29476. }
  29477. function parseWMode(cMap, lexer) {
  29478. var obj = lexer.getObj();
  29479. if (isInt(obj)) {
  29480. cMap.vertical = !!obj;
  29481. }
  29482. }
  29483. function parseCMapName(cMap, lexer) {
  29484. var obj = lexer.getObj();
  29485. if (isName(obj) && isString(obj.name)) {
  29486. cMap.name = obj.name;
  29487. }
  29488. }
  29489. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  29490. var previous;
  29491. var embededUseCMap;
  29492. objLoop: while (true) {
  29493. var obj = lexer.getObj();
  29494. if (isEOF(obj)) {
  29495. break;
  29496. } else if (isName(obj)) {
  29497. if (obj.name === 'WMode') {
  29498. parseWMode(cMap, lexer);
  29499. } else if (obj.name === 'CMapName') {
  29500. parseCMapName(cMap, lexer);
  29501. }
  29502. previous = obj;
  29503. } else if (isCmd(obj)) {
  29504. switch (obj.cmd) {
  29505. case 'endcmap':
  29506. break objLoop;
  29507. case 'usecmap':
  29508. if (isName(previous)) {
  29509. embededUseCMap = previous.name;
  29510. }
  29511. break;
  29512. case 'begincodespacerange':
  29513. parseCodespaceRange(cMap, lexer);
  29514. break;
  29515. case 'beginbfchar':
  29516. parseBfChar(cMap, lexer);
  29517. break;
  29518. case 'begincidchar':
  29519. parseCidChar(cMap, lexer);
  29520. break;
  29521. case 'beginbfrange':
  29522. parseBfRange(cMap, lexer);
  29523. break;
  29524. case 'begincidrange':
  29525. parseCidRange(cMap, lexer);
  29526. break;
  29527. }
  29528. }
  29529. }
  29530. if (!useCMap && embededUseCMap) {
  29531. // Load the usecmap definition from the file only if there wasn't one
  29532. // specified.
  29533. useCMap = embededUseCMap;
  29534. }
  29535. if (useCMap) {
  29536. extendCMap(cMap, builtInCMapParams, useCMap);
  29537. }
  29538. }
  29539. function extendCMap(cMap, builtInCMapParams, useCMap) {
  29540. cMap.useCMap = createBuiltInCMap(useCMap, builtInCMapParams);
  29541. // If there aren't any code space ranges defined clone all the parent ones
  29542. // into this cMap.
  29543. if (cMap.numCodespaceRanges === 0) {
  29544. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  29545. for (var i = 0; i < useCodespaceRanges.length; i++) {
  29546. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  29547. }
  29548. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  29549. }
  29550. // Merge the map into the current one, making sure not to override
  29551. // any previously defined entries.
  29552. cMap.useCMap.forEach(function(key, value) {
  29553. if (!cMap.contains(key)) {
  29554. cMap.mapOne(key, cMap.useCMap.lookup(key));
  29555. }
  29556. });
  29557. }
  29558. function parseBinaryCMap(name, builtInCMapParams) {
  29559. var url = builtInCMapParams.url + name + '.bcmap';
  29560. var cMap = new CMap(true);
  29561. new BinaryCMapReader().read(url, cMap, function (useCMap) {
  29562. extendCMap(cMap, builtInCMapParams, useCMap);
  29563. });
  29564. return cMap;
  29565. }
  29566. function createBuiltInCMap(name, builtInCMapParams) {
  29567. if (name === 'Identity-H') {
  29568. return new IdentityCMap(false, 2);
  29569. } else if (name === 'Identity-V') {
  29570. return new IdentityCMap(true, 2);
  29571. }
  29572. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  29573. error('Unknown cMap name: ' + name);
  29574. }
  29575. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  29576. if (builtInCMapParams.packed) {
  29577. return parseBinaryCMap(name, builtInCMapParams);
  29578. }
  29579. var request = new XMLHttpRequest();
  29580. var url = builtInCMapParams.url + name;
  29581. request.open('GET', url, false);
  29582. request.send(null);
  29583. if (!request.responseText) {
  29584. error('Unable to get cMap at: ' + url);
  29585. }
  29586. var cMap = new CMap(true);
  29587. var lexer = new Lexer(new StringStream(request.responseText));
  29588. parseCMap(cMap, lexer, builtInCMapParams, null);
  29589. return cMap;
  29590. }
  29591. return {
  29592. create: function (encoding, builtInCMapParams, useCMap) {
  29593. if (isName(encoding)) {
  29594. return createBuiltInCMap(encoding.name, builtInCMapParams);
  29595. } else if (isStream(encoding)) {
  29596. var cMap = new CMap();
  29597. var lexer = new Lexer(encoding);
  29598. try {
  29599. parseCMap(cMap, lexer, builtInCMapParams, useCMap);
  29600. } catch (e) {
  29601. warn('Invalid CMap data. ' + e);
  29602. }
  29603. if (cMap.isIdentityCMap) {
  29604. return createBuiltInCMap(cMap.name, builtInCMapParams);
  29605. }
  29606. return cMap;
  29607. }
  29608. error('Encoding required.');
  29609. }
  29610. };
  29611. })();
  29612. exports.CMap = CMap;
  29613. exports.CMapFactory = CMapFactory;
  29614. exports.IdentityCMap = IdentityCMap;
  29615. }));
  29616. (function (root, factory) {
  29617. {
  29618. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  29619. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  29620. root.pdfjsCoreChunkedStream);
  29621. }
  29622. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  29623. coreChunkedStream) {
  29624. var InvalidPDFException = sharedUtil.InvalidPDFException;
  29625. var MissingDataException = sharedUtil.MissingDataException;
  29626. var XRefParseException = sharedUtil.XRefParseException;
  29627. var assert = sharedUtil.assert;
  29628. var bytesToString = sharedUtil.bytesToString;
  29629. var createPromiseCapability = sharedUtil.createPromiseCapability;
  29630. var error = sharedUtil.error;
  29631. var info = sharedUtil.info;
  29632. var isArray = sharedUtil.isArray;
  29633. var isInt = sharedUtil.isInt;
  29634. var isString = sharedUtil.isString;
  29635. var shadow = sharedUtil.shadow;
  29636. var stringToPDFString = sharedUtil.stringToPDFString;
  29637. var stringToUTF8String = sharedUtil.stringToUTF8String;
  29638. var warn = sharedUtil.warn;
  29639. var isValidUrl = sharedUtil.isValidUrl;
  29640. var Util = sharedUtil.Util;
  29641. var Ref = corePrimitives.Ref;
  29642. var RefSet = corePrimitives.RefSet;
  29643. var RefSetCache = corePrimitives.RefSetCache;
  29644. var isName = corePrimitives.isName;
  29645. var isCmd = corePrimitives.isCmd;
  29646. var isDict = corePrimitives.isDict;
  29647. var isRef = corePrimitives.isRef;
  29648. var isStream = corePrimitives.isStream;
  29649. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  29650. var Lexer = coreParser.Lexer;
  29651. var Parser = coreParser.Parser;
  29652. var ChunkedStream = coreChunkedStream.ChunkedStream;
  29653. var Catalog = (function CatalogClosure() {
  29654. function Catalog(pdfManager, xref, pageFactory) {
  29655. this.pdfManager = pdfManager;
  29656. this.xref = xref;
  29657. this.catDict = xref.getCatalogObj();
  29658. this.fontCache = new RefSetCache();
  29659. assert(isDict(this.catDict),
  29660. 'catalog object is not a dictionary');
  29661. // TODO refactor to move getPage() to the PDFDocument.
  29662. this.pageFactory = pageFactory;
  29663. this.pagePromises = [];
  29664. }
  29665. Catalog.prototype = {
  29666. get metadata() {
  29667. var streamRef = this.catDict.getRaw('Metadata');
  29668. if (!isRef(streamRef)) {
  29669. return shadow(this, 'metadata', null);
  29670. }
  29671. var encryptMetadata = (!this.xref.encrypt ? false :
  29672. this.xref.encrypt.encryptMetadata);
  29673. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  29674. var metadata;
  29675. if (stream && isDict(stream.dict)) {
  29676. var type = stream.dict.get('Type');
  29677. var subtype = stream.dict.get('Subtype');
  29678. if (isName(type) && isName(subtype) &&
  29679. type.name === 'Metadata' && subtype.name === 'XML') {
  29680. // XXX: This should examine the charset the XML document defines,
  29681. // however since there are currently no real means to decode
  29682. // arbitrary charsets, let's just hope that the author of the PDF
  29683. // was reasonable enough to stick with the XML default charset,
  29684. // which is UTF-8.
  29685. try {
  29686. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  29687. } catch (e) {
  29688. info('Skipping invalid metadata.');
  29689. }
  29690. }
  29691. }
  29692. return shadow(this, 'metadata', metadata);
  29693. },
  29694. get toplevelPagesDict() {
  29695. var pagesObj = this.catDict.get('Pages');
  29696. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  29697. // shadow the prototype getter
  29698. return shadow(this, 'toplevelPagesDict', pagesObj);
  29699. },
  29700. get documentOutline() {
  29701. var obj = null;
  29702. try {
  29703. obj = this.readDocumentOutline();
  29704. } catch (ex) {
  29705. if (ex instanceof MissingDataException) {
  29706. throw ex;
  29707. }
  29708. warn('Unable to read document outline');
  29709. }
  29710. return shadow(this, 'documentOutline', obj);
  29711. },
  29712. readDocumentOutline: function Catalog_readDocumentOutline() {
  29713. var xref = this.xref;
  29714. var obj = this.catDict.get('Outlines');
  29715. var root = { items: [] };
  29716. if (isDict(obj)) {
  29717. obj = obj.getRaw('First');
  29718. var processed = new RefSet();
  29719. if (isRef(obj)) {
  29720. var queue = [{obj: obj, parent: root}];
  29721. // to avoid recursion keeping track of the items
  29722. // in the processed dictionary
  29723. processed.put(obj);
  29724. while (queue.length > 0) {
  29725. var i = queue.shift();
  29726. var outlineDict = xref.fetchIfRef(i.obj);
  29727. if (outlineDict === null) {
  29728. continue;
  29729. }
  29730. if (!outlineDict.has('Title')) {
  29731. error('Invalid outline item');
  29732. }
  29733. var actionDict = outlineDict.get('A'), dest = null, url = null;
  29734. if (actionDict) {
  29735. var destEntry = actionDict.get('D');
  29736. if (destEntry) {
  29737. dest = destEntry;
  29738. } else {
  29739. var uriEntry = actionDict.get('URI');
  29740. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  29741. url = uriEntry;
  29742. }
  29743. }
  29744. } else if (outlineDict.has('Dest')) {
  29745. dest = outlineDict.getRaw('Dest');
  29746. if (isName(dest)) {
  29747. dest = dest.name;
  29748. }
  29749. }
  29750. var title = outlineDict.get('Title');
  29751. var outlineItem = {
  29752. dest: dest,
  29753. url: url,
  29754. title: stringToPDFString(title),
  29755. color: outlineDict.get('C') || [0, 0, 0],
  29756. count: outlineDict.get('Count'),
  29757. bold: !!(outlineDict.get('F') & 2),
  29758. italic: !!(outlineDict.get('F') & 1),
  29759. items: []
  29760. };
  29761. i.parent.items.push(outlineItem);
  29762. obj = outlineDict.getRaw('First');
  29763. if (isRef(obj) && !processed.has(obj)) {
  29764. queue.push({obj: obj, parent: outlineItem});
  29765. processed.put(obj);
  29766. }
  29767. obj = outlineDict.getRaw('Next');
  29768. if (isRef(obj) && !processed.has(obj)) {
  29769. queue.push({obj: obj, parent: i.parent});
  29770. processed.put(obj);
  29771. }
  29772. }
  29773. }
  29774. }
  29775. return (root.items.length > 0 ? root.items : null);
  29776. },
  29777. get numPages() {
  29778. var obj = this.toplevelPagesDict.get('Count');
  29779. assert(
  29780. isInt(obj),
  29781. 'page count in top level pages object is not an integer'
  29782. );
  29783. // shadow the prototype getter
  29784. return shadow(this, 'num', obj);
  29785. },
  29786. get destinations() {
  29787. function fetchDestination(dest) {
  29788. return isDict(dest) ? dest.get('D') : dest;
  29789. }
  29790. var xref = this.xref;
  29791. var dests = {}, nameTreeRef, nameDictionaryRef;
  29792. var obj = this.catDict.get('Names');
  29793. if (obj && obj.has('Dests')) {
  29794. nameTreeRef = obj.getRaw('Dests');
  29795. } else if (this.catDict.has('Dests')) {
  29796. nameDictionaryRef = this.catDict.get('Dests');
  29797. }
  29798. if (nameDictionaryRef) {
  29799. // reading simple destination dictionary
  29800. obj = nameDictionaryRef;
  29801. obj.forEach(function catalogForEach(key, value) {
  29802. if (!value) {
  29803. return;
  29804. }
  29805. dests[key] = fetchDestination(value);
  29806. });
  29807. }
  29808. if (nameTreeRef) {
  29809. var nameTree = new NameTree(nameTreeRef, xref);
  29810. var names = nameTree.getAll();
  29811. for (var name in names) {
  29812. dests[name] = fetchDestination(names[name]);
  29813. }
  29814. }
  29815. return shadow(this, 'destinations', dests);
  29816. },
  29817. getDestination: function Catalog_getDestination(destinationId) {
  29818. function fetchDestination(dest) {
  29819. return isDict(dest) ? dest.get('D') : dest;
  29820. }
  29821. var xref = this.xref;
  29822. var dest = null, nameTreeRef, nameDictionaryRef;
  29823. var obj = this.catDict.get('Names');
  29824. if (obj && obj.has('Dests')) {
  29825. nameTreeRef = obj.getRaw('Dests');
  29826. } else if (this.catDict.has('Dests')) {
  29827. nameDictionaryRef = this.catDict.get('Dests');
  29828. }
  29829. if (nameDictionaryRef) { // Simple destination dictionary.
  29830. var value = nameDictionaryRef.get(destinationId);
  29831. if (value) {
  29832. dest = fetchDestination(value);
  29833. }
  29834. }
  29835. if (nameTreeRef) {
  29836. var nameTree = new NameTree(nameTreeRef, xref);
  29837. dest = fetchDestination(nameTree.get(destinationId));
  29838. }
  29839. return dest;
  29840. },
  29841. get pageLabels() {
  29842. var obj = null;
  29843. try {
  29844. obj = this.readPageLabels();
  29845. } catch (ex) {
  29846. if (ex instanceof MissingDataException) {
  29847. throw ex;
  29848. }
  29849. warn('Unable to read page labels.');
  29850. }
  29851. return shadow(this, 'pageLabels', obj);
  29852. },
  29853. readPageLabels: function Catalog_readPageLabels() {
  29854. var obj = this.catDict.getRaw('PageLabels');
  29855. if (!obj) {
  29856. return null;
  29857. }
  29858. var pageLabels = new Array(this.numPages);
  29859. var style = null;
  29860. var prefix = '';
  29861. var start = 1;
  29862. var numberTree = new NumberTree(obj, this.xref);
  29863. var nums = numberTree.getAll();
  29864. var currentLabel = '', currentIndex = 1;
  29865. for (var i = 0, ii = this.numPages; i < ii; i++) {
  29866. if (i in nums) {
  29867. var labelDict = nums[i];
  29868. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  29869. var type = labelDict.get('Type');
  29870. assert(!type || (isName(type) && type.name === 'PageLabel'),
  29871. 'Invalid type in PageLabel dictionary.');
  29872. var s = labelDict.get('S');
  29873. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  29874. style = (s ? s.name : null);
  29875. prefix = labelDict.get('P') || '';
  29876. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  29877. start = labelDict.get('St') || 1;
  29878. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  29879. currentIndex = start;
  29880. }
  29881. switch (style) {
  29882. case 'D':
  29883. currentLabel = currentIndex;
  29884. break;
  29885. case 'R':
  29886. case 'r':
  29887. currentLabel = Util.toRoman(currentIndex, style === 'r');
  29888. break;
  29889. case 'A':
  29890. case 'a':
  29891. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  29892. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  29893. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  29894. var letterIndex = currentIndex - 1;
  29895. var character = String.fromCharCode(baseCharCode +
  29896. (letterIndex % LIMIT));
  29897. var charBuf = [];
  29898. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  29899. charBuf.push(character);
  29900. }
  29901. currentLabel = charBuf.join('');
  29902. break;
  29903. default:
  29904. assert(!style,
  29905. 'Invalid style "' + style + '" in PageLabel dictionary.');
  29906. }
  29907. pageLabels[i] = prefix + currentLabel;
  29908. currentLabel = '';
  29909. currentIndex++;
  29910. }
  29911. return pageLabels;
  29912. },
  29913. get attachments() {
  29914. var xref = this.xref;
  29915. var attachments = null, nameTreeRef;
  29916. var obj = this.catDict.get('Names');
  29917. if (obj) {
  29918. nameTreeRef = obj.getRaw('EmbeddedFiles');
  29919. }
  29920. if (nameTreeRef) {
  29921. var nameTree = new NameTree(nameTreeRef, xref);
  29922. var names = nameTree.getAll();
  29923. for (var name in names) {
  29924. var fs = new FileSpec(names[name], xref);
  29925. if (!attachments) {
  29926. attachments = Object.create(null);
  29927. }
  29928. attachments[stringToPDFString(name)] = fs.serializable;
  29929. }
  29930. }
  29931. return shadow(this, 'attachments', attachments);
  29932. },
  29933. get javaScript() {
  29934. var xref = this.xref;
  29935. var obj = this.catDict.get('Names');
  29936. var javaScript = [];
  29937. function appendIfJavaScriptDict(jsDict) {
  29938. var type = jsDict.get('S');
  29939. if (!isName(type) || type.name !== 'JavaScript') {
  29940. return;
  29941. }
  29942. var js = jsDict.get('JS');
  29943. if (isStream(js)) {
  29944. js = bytesToString(js.getBytes());
  29945. } else if (!isString(js)) {
  29946. return;
  29947. }
  29948. javaScript.push(stringToPDFString(js));
  29949. }
  29950. if (obj && obj.has('JavaScript')) {
  29951. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  29952. var names = nameTree.getAll();
  29953. for (var name in names) {
  29954. // We don't really use the JavaScript right now. This code is
  29955. // defensive so we don't cause errors on document load.
  29956. var jsDict = names[name];
  29957. if (isDict(jsDict)) {
  29958. appendIfJavaScriptDict(jsDict);
  29959. }
  29960. }
  29961. }
  29962. // Append OpenAction actions to javaScript array
  29963. var openactionDict = this.catDict.get('OpenAction');
  29964. if (isDict(openactionDict, 'Action')) {
  29965. var actionType = openactionDict.get('S');
  29966. if (isName(actionType) && actionType.name === 'Named') {
  29967. // The named Print action is not a part of the PDF 1.7 specification,
  29968. // but is supported by many PDF readers/writers (including Adobe's).
  29969. var action = openactionDict.get('N');
  29970. if (isName(action) && action.name === 'Print') {
  29971. javaScript.push('print({});');
  29972. }
  29973. } else {
  29974. appendIfJavaScriptDict(openactionDict);
  29975. }
  29976. }
  29977. return shadow(this, 'javaScript', javaScript);
  29978. },
  29979. cleanup: function Catalog_cleanup() {
  29980. var promises = [];
  29981. this.fontCache.forEach(function (promise) {
  29982. promises.push(promise);
  29983. });
  29984. return Promise.all(promises).then(function (translatedFonts) {
  29985. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  29986. var font = translatedFonts[i].dict;
  29987. delete font.translated;
  29988. }
  29989. this.fontCache.clear();
  29990. }.bind(this));
  29991. },
  29992. getPage: function Catalog_getPage(pageIndex) {
  29993. if (!(pageIndex in this.pagePromises)) {
  29994. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  29995. function (a) {
  29996. var dict = a[0];
  29997. var ref = a[1];
  29998. return this.pageFactory.createPage(pageIndex, dict, ref,
  29999. this.fontCache);
  30000. }.bind(this)
  30001. );
  30002. }
  30003. return this.pagePromises[pageIndex];
  30004. },
  30005. getPageDict: function Catalog_getPageDict(pageIndex) {
  30006. var capability = createPromiseCapability();
  30007. var nodesToVisit = [this.catDict.getRaw('Pages')];
  30008. var currentPageIndex = 0;
  30009. var xref = this.xref;
  30010. var checkAllKids = false;
  30011. function next() {
  30012. while (nodesToVisit.length) {
  30013. var currentNode = nodesToVisit.pop();
  30014. if (isRef(currentNode)) {
  30015. xref.fetchAsync(currentNode).then(function (obj) {
  30016. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  30017. if (pageIndex === currentPageIndex) {
  30018. capability.resolve([obj, currentNode]);
  30019. } else {
  30020. currentPageIndex++;
  30021. next();
  30022. }
  30023. return;
  30024. }
  30025. nodesToVisit.push(obj);
  30026. next();
  30027. }, capability.reject);
  30028. return;
  30029. }
  30030. // Must be a child page dictionary.
  30031. assert(
  30032. isDict(currentNode),
  30033. 'page dictionary kid reference points to wrong type of object'
  30034. );
  30035. var count = currentNode.get('Count');
  30036. // If the current node doesn't have any children, avoid getting stuck
  30037. // in an empty node further down in the tree (see issue5644.pdf).
  30038. if (count === 0) {
  30039. checkAllKids = true;
  30040. }
  30041. // Skip nodes where the page can't be.
  30042. if (currentPageIndex + count <= pageIndex) {
  30043. currentPageIndex += count;
  30044. continue;
  30045. }
  30046. var kids = currentNode.get('Kids');
  30047. assert(isArray(kids), 'page dictionary kids object is not an array');
  30048. if (!checkAllKids && count === kids.length) {
  30049. // Nodes that don't have the page have been skipped and this is the
  30050. // bottom of the tree which means the page requested must be a
  30051. // descendant of this pages node. Ideally we would just resolve the
  30052. // promise with the page ref here, but there is the case where more
  30053. // pages nodes could link to single a page (see issue 3666 pdf). To
  30054. // handle this push it back on the queue so if it is a pages node it
  30055. // will be descended into.
  30056. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  30057. currentPageIndex = pageIndex;
  30058. continue;
  30059. } else {
  30060. for (var last = kids.length - 1; last >= 0; last--) {
  30061. nodesToVisit.push(kids[last]);
  30062. }
  30063. }
  30064. }
  30065. capability.reject('Page index ' + pageIndex + ' not found.');
  30066. }
  30067. next();
  30068. return capability.promise;
  30069. },
  30070. getPageIndex: function Catalog_getPageIndex(ref) {
  30071. // The page tree nodes have the count of all the leaves below them. To get
  30072. // how many pages are before we just have to walk up the tree and keep
  30073. // adding the count of siblings to the left of the node.
  30074. var xref = this.xref;
  30075. function pagesBeforeRef(kidRef) {
  30076. var total = 0;
  30077. var parentRef;
  30078. return xref.fetchAsync(kidRef).then(function (node) {
  30079. if (!node) {
  30080. return null;
  30081. }
  30082. parentRef = node.getRaw('Parent');
  30083. return node.getAsync('Parent');
  30084. }).then(function (parent) {
  30085. if (!parent) {
  30086. return null;
  30087. }
  30088. return parent.getAsync('Kids');
  30089. }).then(function (kids) {
  30090. if (!kids) {
  30091. return null;
  30092. }
  30093. var kidPromises = [];
  30094. var found = false;
  30095. for (var i = 0; i < kids.length; i++) {
  30096. var kid = kids[i];
  30097. assert(isRef(kid), 'kids must be a ref');
  30098. if (kid.num === kidRef.num) {
  30099. found = true;
  30100. break;
  30101. }
  30102. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  30103. if (kid.has('Count')) {
  30104. var count = kid.get('Count');
  30105. total += count;
  30106. } else { // page leaf node
  30107. total++;
  30108. }
  30109. }));
  30110. }
  30111. if (!found) {
  30112. error('kid ref not found in parents kids');
  30113. }
  30114. return Promise.all(kidPromises).then(function () {
  30115. return [total, parentRef];
  30116. });
  30117. });
  30118. }
  30119. var total = 0;
  30120. function next(ref) {
  30121. return pagesBeforeRef(ref).then(function (args) {
  30122. if (!args) {
  30123. return total;
  30124. }
  30125. var count = args[0];
  30126. var parentRef = args[1];
  30127. total += count;
  30128. return next(parentRef);
  30129. });
  30130. }
  30131. return next(ref);
  30132. }
  30133. };
  30134. return Catalog;
  30135. })();
  30136. var XRef = (function XRefClosure() {
  30137. function XRef(stream, password) {
  30138. this.stream = stream;
  30139. this.entries = [];
  30140. this.xrefstms = Object.create(null);
  30141. // prepare the XRef cache
  30142. this.cache = [];
  30143. this.password = password;
  30144. this.stats = {
  30145. streamTypes: [],
  30146. fontTypes: []
  30147. };
  30148. }
  30149. XRef.prototype = {
  30150. setStartXRef: function XRef_setStartXRef(startXRef) {
  30151. // Store the starting positions of xref tables as we process them
  30152. // so we can recover from missing data errors
  30153. this.startXRefQueue = [startXRef];
  30154. },
  30155. parse: function XRef_parse(recoveryMode) {
  30156. var trailerDict;
  30157. if (!recoveryMode) {
  30158. trailerDict = this.readXRef();
  30159. } else {
  30160. warn('Indexing all PDF objects');
  30161. trailerDict = this.indexObjects();
  30162. }
  30163. trailerDict.assignXref(this);
  30164. this.trailer = trailerDict;
  30165. var encrypt = trailerDict.get('Encrypt');
  30166. if (encrypt) {
  30167. var ids = trailerDict.get('ID');
  30168. var fileId = (ids && ids.length) ? ids[0] : '';
  30169. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  30170. this.password);
  30171. }
  30172. // get the root dictionary (catalog) object
  30173. if (!(this.root = trailerDict.get('Root'))) {
  30174. error('Invalid root reference');
  30175. }
  30176. },
  30177. processXRefTable: function XRef_processXRefTable(parser) {
  30178. if (!('tableState' in this)) {
  30179. // Stores state of the table as we process it so we can resume
  30180. // from middle of table in case of missing data error
  30181. this.tableState = {
  30182. entryNum: 0,
  30183. streamPos: parser.lexer.stream.pos,
  30184. parserBuf1: parser.buf1,
  30185. parserBuf2: parser.buf2
  30186. };
  30187. }
  30188. var obj = this.readXRefTable(parser);
  30189. // Sanity check
  30190. if (!isCmd(obj, 'trailer')) {
  30191. error('Invalid XRef table: could not find trailer dictionary');
  30192. }
  30193. // Read trailer dictionary, e.g.
  30194. // trailer
  30195. // << /Size 22
  30196. // /Root 20R
  30197. // /Info 10R
  30198. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  30199. // >>
  30200. // The parser goes through the entire stream << ... >> and provides
  30201. // a getter interface for the key-value table
  30202. var dict = parser.getObj();
  30203. // The pdflib PDF generator can generate a nested trailer dictionary
  30204. if (!isDict(dict) && dict.dict) {
  30205. dict = dict.dict;
  30206. }
  30207. if (!isDict(dict)) {
  30208. error('Invalid XRef table: could not parse trailer dictionary');
  30209. }
  30210. delete this.tableState;
  30211. return dict;
  30212. },
  30213. readXRefTable: function XRef_readXRefTable(parser) {
  30214. // Example of cross-reference table:
  30215. // xref
  30216. // 0 1 <-- subsection header (first obj #, obj count)
  30217. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  30218. // 23 2 <-- subsection header ... and so on ...
  30219. // 0000025518 00002 n
  30220. // 0000025635 00000 n
  30221. // trailer
  30222. // ...
  30223. var stream = parser.lexer.stream;
  30224. var tableState = this.tableState;
  30225. stream.pos = tableState.streamPos;
  30226. parser.buf1 = tableState.parserBuf1;
  30227. parser.buf2 = tableState.parserBuf2;
  30228. // Outer loop is over subsection headers
  30229. var obj;
  30230. while (true) {
  30231. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  30232. if (isCmd(obj = parser.getObj(), 'trailer')) {
  30233. break;
  30234. }
  30235. tableState.firstEntryNum = obj;
  30236. tableState.entryCount = parser.getObj();
  30237. }
  30238. var first = tableState.firstEntryNum;
  30239. var count = tableState.entryCount;
  30240. if (!isInt(first) || !isInt(count)) {
  30241. error('Invalid XRef table: wrong types in subsection header');
  30242. }
  30243. // Inner loop is over objects themselves
  30244. for (var i = tableState.entryNum; i < count; i++) {
  30245. tableState.streamPos = stream.pos;
  30246. tableState.entryNum = i;
  30247. tableState.parserBuf1 = parser.buf1;
  30248. tableState.parserBuf2 = parser.buf2;
  30249. var entry = {};
  30250. entry.offset = parser.getObj();
  30251. entry.gen = parser.getObj();
  30252. var type = parser.getObj();
  30253. if (isCmd(type, 'f')) {
  30254. entry.free = true;
  30255. } else if (isCmd(type, 'n')) {
  30256. entry.uncompressed = true;
  30257. }
  30258. // Validate entry obj
  30259. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  30260. !(entry.free || entry.uncompressed)) {
  30261. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  30262. }
  30263. if (!this.entries[i + first]) {
  30264. this.entries[i + first] = entry;
  30265. }
  30266. }
  30267. tableState.entryNum = 0;
  30268. tableState.streamPos = stream.pos;
  30269. tableState.parserBuf1 = parser.buf1;
  30270. tableState.parserBuf2 = parser.buf2;
  30271. delete tableState.firstEntryNum;
  30272. delete tableState.entryCount;
  30273. }
  30274. // Per issue 3248: hp scanners generate bad XRef
  30275. if (first === 1 && this.entries[1] && this.entries[1].free) {
  30276. // shifting the entries
  30277. this.entries.shift();
  30278. }
  30279. // Sanity check: as per spec, first object must be free
  30280. if (this.entries[0] && !this.entries[0].free) {
  30281. error('Invalid XRef table: unexpected first object');
  30282. }
  30283. return obj;
  30284. },
  30285. processXRefStream: function XRef_processXRefStream(stream) {
  30286. if (!('streamState' in this)) {
  30287. // Stores state of the stream as we process it so we can resume
  30288. // from middle of stream in case of missing data error
  30289. var streamParameters = stream.dict;
  30290. var byteWidths = streamParameters.get('W');
  30291. var range = streamParameters.get('Index');
  30292. if (!range) {
  30293. range = [0, streamParameters.get('Size')];
  30294. }
  30295. this.streamState = {
  30296. entryRanges: range,
  30297. byteWidths: byteWidths,
  30298. entryNum: 0,
  30299. streamPos: stream.pos
  30300. };
  30301. }
  30302. this.readXRefStream(stream);
  30303. delete this.streamState;
  30304. return stream.dict;
  30305. },
  30306. readXRefStream: function XRef_readXRefStream(stream) {
  30307. var i, j;
  30308. var streamState = this.streamState;
  30309. stream.pos = streamState.streamPos;
  30310. var byteWidths = streamState.byteWidths;
  30311. var typeFieldWidth = byteWidths[0];
  30312. var offsetFieldWidth = byteWidths[1];
  30313. var generationFieldWidth = byteWidths[2];
  30314. var entryRanges = streamState.entryRanges;
  30315. while (entryRanges.length > 0) {
  30316. var first = entryRanges[0];
  30317. var n = entryRanges[1];
  30318. if (!isInt(first) || !isInt(n)) {
  30319. error('Invalid XRef range fields: ' + first + ', ' + n);
  30320. }
  30321. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  30322. !isInt(generationFieldWidth)) {
  30323. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  30324. }
  30325. for (i = streamState.entryNum; i < n; ++i) {
  30326. streamState.entryNum = i;
  30327. streamState.streamPos = stream.pos;
  30328. var type = 0, offset = 0, generation = 0;
  30329. for (j = 0; j < typeFieldWidth; ++j) {
  30330. type = (type << 8) | stream.getByte();
  30331. }
  30332. // if type field is absent, its default value is 1
  30333. if (typeFieldWidth === 0) {
  30334. type = 1;
  30335. }
  30336. for (j = 0; j < offsetFieldWidth; ++j) {
  30337. offset = (offset << 8) | stream.getByte();
  30338. }
  30339. for (j = 0; j < generationFieldWidth; ++j) {
  30340. generation = (generation << 8) | stream.getByte();
  30341. }
  30342. var entry = {};
  30343. entry.offset = offset;
  30344. entry.gen = generation;
  30345. switch (type) {
  30346. case 0:
  30347. entry.free = true;
  30348. break;
  30349. case 1:
  30350. entry.uncompressed = true;
  30351. break;
  30352. case 2:
  30353. break;
  30354. default:
  30355. error('Invalid XRef entry type: ' + type);
  30356. }
  30357. if (!this.entries[first + i]) {
  30358. this.entries[first + i] = entry;
  30359. }
  30360. }
  30361. streamState.entryNum = 0;
  30362. streamState.streamPos = stream.pos;
  30363. entryRanges.splice(0, 2);
  30364. }
  30365. },
  30366. indexObjects: function XRef_indexObjects() {
  30367. // Simple scan through the PDF content to find objects,
  30368. // trailers and XRef streams.
  30369. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  30370. var PERCENT = 0x25, LT = 0x3C;
  30371. function readToken(data, offset) {
  30372. var token = '', ch = data[offset];
  30373. while (ch !== LF && ch !== CR && ch !== LT) {
  30374. if (++offset >= data.length) {
  30375. break;
  30376. }
  30377. token += String.fromCharCode(ch);
  30378. ch = data[offset];
  30379. }
  30380. return token;
  30381. }
  30382. function skipUntil(data, offset, what) {
  30383. var length = what.length, dataLength = data.length;
  30384. var skipped = 0;
  30385. // finding byte sequence
  30386. while (offset < dataLength) {
  30387. var i = 0;
  30388. while (i < length && data[offset + i] === what[i]) {
  30389. ++i;
  30390. }
  30391. if (i >= length) {
  30392. break; // sequence found
  30393. }
  30394. offset++;
  30395. skipped++;
  30396. }
  30397. return skipped;
  30398. }
  30399. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  30400. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  30401. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  30402. 101, 102]);
  30403. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  30404. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  30405. // Clear out any existing entries, since they may be bogus.
  30406. this.entries.length = 0;
  30407. var stream = this.stream;
  30408. stream.pos = 0;
  30409. var buffer = stream.getBytes();
  30410. var position = stream.start, length = buffer.length;
  30411. var trailers = [], xrefStms = [];
  30412. while (position < length) {
  30413. var ch = buffer[position];
  30414. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  30415. ++position;
  30416. continue;
  30417. }
  30418. if (ch === PERCENT) { // %-comment
  30419. do {
  30420. ++position;
  30421. if (position >= length) {
  30422. break;
  30423. }
  30424. ch = buffer[position];
  30425. } while (ch !== LF && ch !== CR);
  30426. continue;
  30427. }
  30428. var token = readToken(buffer, position);
  30429. var m;
  30430. if (token.indexOf('xref') === 0 &&
  30431. (token.length === 4 || /\s/.test(token[4]))) {
  30432. position += skipUntil(buffer, position, trailerBytes);
  30433. trailers.push(position);
  30434. position += skipUntil(buffer, position, startxrefBytes);
  30435. } else if ((m = objRegExp.exec(token))) {
  30436. if (typeof this.entries[m[1]] === 'undefined') {
  30437. this.entries[m[1]] = {
  30438. offset: position - stream.start,
  30439. gen: m[2] | 0,
  30440. uncompressed: true
  30441. };
  30442. }
  30443. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  30444. var content = buffer.subarray(position, position + contentLength);
  30445. // checking XRef stream suspect
  30446. // (it shall have '/XRef' and next char is not a letter)
  30447. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  30448. if (xrefTagOffset < contentLength &&
  30449. content[xrefTagOffset + 5] < 64) {
  30450. xrefStms.push(position - stream.start);
  30451. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  30452. }
  30453. position += contentLength;
  30454. } else if (token.indexOf('trailer') === 0 &&
  30455. (token.length === 7 || /\s/.test(token[7]))) {
  30456. trailers.push(position);
  30457. position += skipUntil(buffer, position, startxrefBytes);
  30458. } else {
  30459. position += token.length + 1;
  30460. }
  30461. }
  30462. // reading XRef streams
  30463. var i, ii;
  30464. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  30465. this.startXRefQueue.push(xrefStms[i]);
  30466. this.readXRef(/* recoveryMode */ true);
  30467. }
  30468. // finding main trailer
  30469. var dict;
  30470. for (i = 0, ii = trailers.length; i < ii; ++i) {
  30471. stream.pos = trailers[i];
  30472. var parser = new Parser(new Lexer(stream), true, this);
  30473. var obj = parser.getObj();
  30474. if (!isCmd(obj, 'trailer')) {
  30475. continue;
  30476. }
  30477. // read the trailer dictionary
  30478. if (!isDict(dict = parser.getObj())) {
  30479. continue;
  30480. }
  30481. // taking the first one with 'ID'
  30482. if (dict.has('ID')) {
  30483. return dict;
  30484. }
  30485. }
  30486. // no tailer with 'ID', taking last one (if exists)
  30487. if (dict) {
  30488. return dict;
  30489. }
  30490. // nothing helps
  30491. // calling error() would reject worker with an UnknownErrorException.
  30492. throw new InvalidPDFException('Invalid PDF structure');
  30493. },
  30494. readXRef: function XRef_readXRef(recoveryMode) {
  30495. var stream = this.stream;
  30496. try {
  30497. while (this.startXRefQueue.length) {
  30498. var startXRef = this.startXRefQueue[0];
  30499. stream.pos = startXRef + stream.start;
  30500. var parser = new Parser(new Lexer(stream), true, this);
  30501. var obj = parser.getObj();
  30502. var dict;
  30503. // Get dictionary
  30504. if (isCmd(obj, 'xref')) {
  30505. // Parse end-of-file XRef
  30506. dict = this.processXRefTable(parser);
  30507. if (!this.topDict) {
  30508. this.topDict = dict;
  30509. }
  30510. // Recursively get other XRefs 'XRefStm', if any
  30511. obj = dict.get('XRefStm');
  30512. if (isInt(obj)) {
  30513. var pos = obj;
  30514. // ignore previously loaded xref streams
  30515. // (possible infinite recursion)
  30516. if (!(pos in this.xrefstms)) {
  30517. this.xrefstms[pos] = 1;
  30518. this.startXRefQueue.push(pos);
  30519. }
  30520. }
  30521. } else if (isInt(obj)) {
  30522. // Parse in-stream XRef
  30523. if (!isInt(parser.getObj()) ||
  30524. !isCmd(parser.getObj(), 'obj') ||
  30525. !isStream(obj = parser.getObj())) {
  30526. error('Invalid XRef stream');
  30527. }
  30528. dict = this.processXRefStream(obj);
  30529. if (!this.topDict) {
  30530. this.topDict = dict;
  30531. }
  30532. if (!dict) {
  30533. error('Failed to read XRef stream');
  30534. }
  30535. } else {
  30536. error('Invalid XRef stream header');
  30537. }
  30538. // Recursively get previous dictionary, if any
  30539. obj = dict.get('Prev');
  30540. if (isInt(obj)) {
  30541. this.startXRefQueue.push(obj);
  30542. } else if (isRef(obj)) {
  30543. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  30544. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  30545. this.startXRefQueue.push(obj.num);
  30546. }
  30547. this.startXRefQueue.shift();
  30548. }
  30549. return this.topDict;
  30550. } catch (e) {
  30551. if (e instanceof MissingDataException) {
  30552. throw e;
  30553. }
  30554. info('(while reading XRef): ' + e);
  30555. }
  30556. if (recoveryMode) {
  30557. return;
  30558. }
  30559. throw new XRefParseException();
  30560. },
  30561. getEntry: function XRef_getEntry(i) {
  30562. var xrefEntry = this.entries[i];
  30563. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  30564. return xrefEntry;
  30565. }
  30566. return null;
  30567. },
  30568. fetchIfRef: function XRef_fetchIfRef(obj) {
  30569. if (!isRef(obj)) {
  30570. return obj;
  30571. }
  30572. return this.fetch(obj);
  30573. },
  30574. fetch: function XRef_fetch(ref, suppressEncryption) {
  30575. assert(isRef(ref), 'ref object is not a reference');
  30576. var num = ref.num;
  30577. if (num in this.cache) {
  30578. var cacheEntry = this.cache[num];
  30579. return cacheEntry;
  30580. }
  30581. var xrefEntry = this.getEntry(num);
  30582. // the referenced entry can be free
  30583. if (xrefEntry === null) {
  30584. return (this.cache[num] = null);
  30585. }
  30586. if (xrefEntry.uncompressed) {
  30587. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  30588. } else {
  30589. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  30590. }
  30591. if (isDict(xrefEntry)){
  30592. xrefEntry.objId = ref.toString();
  30593. } else if (isStream(xrefEntry)) {
  30594. xrefEntry.dict.objId = ref.toString();
  30595. }
  30596. return xrefEntry;
  30597. },
  30598. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  30599. suppressEncryption) {
  30600. var gen = ref.gen;
  30601. var num = ref.num;
  30602. if (xrefEntry.gen !== gen) {
  30603. error('inconsistent generation in XRef');
  30604. }
  30605. var stream = this.stream.makeSubStream(xrefEntry.offset +
  30606. this.stream.start);
  30607. var parser = new Parser(new Lexer(stream), true, this);
  30608. var obj1 = parser.getObj();
  30609. var obj2 = parser.getObj();
  30610. var obj3 = parser.getObj();
  30611. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  30612. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  30613. !isCmd(obj3)) {
  30614. error('bad XRef entry');
  30615. }
  30616. if (!isCmd(obj3, 'obj')) {
  30617. // some bad PDFs use "obj1234" and really mean 1234
  30618. if (obj3.cmd.indexOf('obj') === 0) {
  30619. num = parseInt(obj3.cmd.substring(3), 10);
  30620. if (!isNaN(num)) {
  30621. return num;
  30622. }
  30623. }
  30624. error('bad XRef entry');
  30625. }
  30626. if (this.encrypt && !suppressEncryption) {
  30627. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  30628. } else {
  30629. xrefEntry = parser.getObj();
  30630. }
  30631. if (!isStream(xrefEntry)) {
  30632. this.cache[num] = xrefEntry;
  30633. }
  30634. return xrefEntry;
  30635. },
  30636. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  30637. suppressEncryption) {
  30638. var tableOffset = xrefEntry.offset;
  30639. var stream = this.fetch(new Ref(tableOffset, 0));
  30640. if (!isStream(stream)) {
  30641. error('bad ObjStm stream');
  30642. }
  30643. var first = stream.dict.get('First');
  30644. var n = stream.dict.get('N');
  30645. if (!isInt(first) || !isInt(n)) {
  30646. error('invalid first and n parameters for ObjStm stream');
  30647. }
  30648. var parser = new Parser(new Lexer(stream), false, this);
  30649. parser.allowStreams = true;
  30650. var i, entries = [], num, nums = [];
  30651. // read the object numbers to populate cache
  30652. for (i = 0; i < n; ++i) {
  30653. num = parser.getObj();
  30654. if (!isInt(num)) {
  30655. error('invalid object number in the ObjStm stream: ' + num);
  30656. }
  30657. nums.push(num);
  30658. var offset = parser.getObj();
  30659. if (!isInt(offset)) {
  30660. error('invalid object offset in the ObjStm stream: ' + offset);
  30661. }
  30662. }
  30663. // read stream objects for cache
  30664. for (i = 0; i < n; ++i) {
  30665. entries.push(parser.getObj());
  30666. num = nums[i];
  30667. var entry = this.entries[num];
  30668. if (entry && entry.offset === tableOffset && entry.gen === i) {
  30669. this.cache[num] = entries[i];
  30670. }
  30671. }
  30672. xrefEntry = entries[xrefEntry.gen];
  30673. if (xrefEntry === undefined) {
  30674. error('bad XRef entry for compressed object');
  30675. }
  30676. return xrefEntry;
  30677. },
  30678. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  30679. if (!isRef(obj)) {
  30680. return Promise.resolve(obj);
  30681. }
  30682. return this.fetchAsync(obj);
  30683. },
  30684. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  30685. var streamManager = this.stream.manager;
  30686. var xref = this;
  30687. return new Promise(function tryFetch(resolve, reject) {
  30688. try {
  30689. resolve(xref.fetch(ref, suppressEncryption));
  30690. } catch (e) {
  30691. if (e instanceof MissingDataException) {
  30692. streamManager.requestRange(e.begin, e.end).then(function () {
  30693. tryFetch(resolve, reject);
  30694. }, reject);
  30695. return;
  30696. }
  30697. reject(e);
  30698. }
  30699. });
  30700. },
  30701. getCatalogObj: function XRef_getCatalogObj() {
  30702. return this.root;
  30703. }
  30704. };
  30705. return XRef;
  30706. })();
  30707. /**
  30708. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  30709. * see the specification (7.9.6 and 7.9.7) for additional details.
  30710. * TODO: implement all the Dict functions and make this more efficient.
  30711. */
  30712. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  30713. function NameOrNumberTree(root, xref) {
  30714. throw new Error('Cannot initialize NameOrNumberTree.');
  30715. }
  30716. NameOrNumberTree.prototype = {
  30717. getAll: function NameOrNumberTree_getAll() {
  30718. var dict = Object.create(null);
  30719. if (!this.root) {
  30720. return dict;
  30721. }
  30722. var xref = this.xref;
  30723. // Reading Name/Number tree.
  30724. var processed = new RefSet();
  30725. processed.put(this.root);
  30726. var queue = [this.root];
  30727. while (queue.length > 0) {
  30728. var i, n;
  30729. var obj = xref.fetchIfRef(queue.shift());
  30730. if (!isDict(obj)) {
  30731. continue;
  30732. }
  30733. if (obj.has('Kids')) {
  30734. var kids = obj.get('Kids');
  30735. for (i = 0, n = kids.length; i < n; i++) {
  30736. var kid = kids[i];
  30737. assert(!processed.has(kid),
  30738. 'Duplicate entry in "' + this._type + '" tree.');
  30739. queue.push(kid);
  30740. processed.put(kid);
  30741. }
  30742. continue;
  30743. }
  30744. var entries = obj.get(this._type);
  30745. if (isArray(entries)) {
  30746. for (i = 0, n = entries.length; i < n; i += 2) {
  30747. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  30748. }
  30749. }
  30750. }
  30751. return dict;
  30752. },
  30753. get: function NameOrNumberTree_get(key) {
  30754. if (!this.root) {
  30755. return null;
  30756. }
  30757. var xref = this.xref;
  30758. var kidsOrEntries = xref.fetchIfRef(this.root);
  30759. var loopCount = 0;
  30760. var MAX_LEVELS = 10;
  30761. var l, r, m;
  30762. // Perform a binary search to quickly find the entry that
  30763. // contains the key we are looking for.
  30764. while (kidsOrEntries.has('Kids')) {
  30765. if (++loopCount > MAX_LEVELS) {
  30766. warn('Search depth limit reached for "' + this._type + '" tree.');
  30767. return null;
  30768. }
  30769. var kids = kidsOrEntries.get('Kids');
  30770. if (!isArray(kids)) {
  30771. return null;
  30772. }
  30773. l = 0;
  30774. r = kids.length - 1;
  30775. while (l <= r) {
  30776. m = (l + r) >> 1;
  30777. var kid = xref.fetchIfRef(kids[m]);
  30778. var limits = kid.get('Limits');
  30779. if (key < xref.fetchIfRef(limits[0])) {
  30780. r = m - 1;
  30781. } else if (key > xref.fetchIfRef(limits[1])) {
  30782. l = m + 1;
  30783. } else {
  30784. kidsOrEntries = xref.fetchIfRef(kids[m]);
  30785. break;
  30786. }
  30787. }
  30788. if (l > r) {
  30789. return null;
  30790. }
  30791. }
  30792. // If we get here, then we have found the right entry. Now go through the
  30793. // entries in the dictionary until we find the key we're looking for.
  30794. var entries = kidsOrEntries.get(this._type);
  30795. if (isArray(entries)) {
  30796. // Perform a binary search to reduce the lookup time.
  30797. l = 0;
  30798. r = entries.length - 2;
  30799. while (l <= r) {
  30800. // Check only even indices (0, 2, 4, ...) because the
  30801. // odd indices contain the actual data.
  30802. m = (l + r) & ~1;
  30803. var currentKey = xref.fetchIfRef(entries[m]);
  30804. if (key < currentKey) {
  30805. r = m - 2;
  30806. } else if (key > currentKey) {
  30807. l = m + 2;
  30808. } else {
  30809. return xref.fetchIfRef(entries[m + 1]);
  30810. }
  30811. }
  30812. }
  30813. return null;
  30814. }
  30815. };
  30816. return NameOrNumberTree;
  30817. })();
  30818. var NameTree = (function NameTreeClosure() {
  30819. function NameTree(root, xref) {
  30820. this.root = root;
  30821. this.xref = xref;
  30822. this._type = 'Names';
  30823. }
  30824. Util.inherit(NameTree, NameOrNumberTree, {});
  30825. return NameTree;
  30826. })();
  30827. var NumberTree = (function NumberTreeClosure() {
  30828. function NumberTree(root, xref) {
  30829. this.root = root;
  30830. this.xref = xref;
  30831. this._type = 'Nums';
  30832. }
  30833. Util.inherit(NumberTree, NameOrNumberTree, {});
  30834. return NumberTree;
  30835. })();
  30836. /**
  30837. * "A PDF file can refer to the contents of another file by using a File
  30838. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  30839. * NOTE: Only embedded files are supported (as part of the attachments support)
  30840. * TODO: support the 'URL' file system (with caching if !/V), portable
  30841. * collections attributes and related files (/RF)
  30842. */
  30843. var FileSpec = (function FileSpecClosure() {
  30844. function FileSpec(root, xref) {
  30845. if (!root || !isDict(root)) {
  30846. return;
  30847. }
  30848. this.xref = xref;
  30849. this.root = root;
  30850. if (root.has('FS')) {
  30851. this.fs = root.get('FS');
  30852. }
  30853. this.description = root.has('Desc') ?
  30854. stringToPDFString(root.get('Desc')) :
  30855. '';
  30856. if (root.has('RF')) {
  30857. warn('Related file specifications are not supported');
  30858. }
  30859. this.contentAvailable = true;
  30860. if (!root.has('EF')) {
  30861. this.contentAvailable = false;
  30862. warn('Non-embedded file specifications are not supported');
  30863. }
  30864. }
  30865. function pickPlatformItem(dict) {
  30866. // Look for the filename in this order:
  30867. // UF, F, Unix, Mac, DOS
  30868. if (dict.has('UF')) {
  30869. return dict.get('UF');
  30870. } else if (dict.has('F')) {
  30871. return dict.get('F');
  30872. } else if (dict.has('Unix')) {
  30873. return dict.get('Unix');
  30874. } else if (dict.has('Mac')) {
  30875. return dict.get('Mac');
  30876. } else if (dict.has('DOS')) {
  30877. return dict.get('DOS');
  30878. } else {
  30879. return null;
  30880. }
  30881. }
  30882. FileSpec.prototype = {
  30883. get filename() {
  30884. if (!this._filename && this.root) {
  30885. var filename = pickPlatformItem(this.root) || 'unnamed';
  30886. this._filename = stringToPDFString(filename).
  30887. replace(/\\\\/g, '\\').
  30888. replace(/\\\//g, '/').
  30889. replace(/\\/g, '/');
  30890. }
  30891. return this._filename;
  30892. },
  30893. get content() {
  30894. if (!this.contentAvailable) {
  30895. return null;
  30896. }
  30897. if (!this.contentRef && this.root) {
  30898. this.contentRef = pickPlatformItem(this.root.get('EF'));
  30899. }
  30900. var content = null;
  30901. if (this.contentRef) {
  30902. var xref = this.xref;
  30903. var fileObj = xref.fetchIfRef(this.contentRef);
  30904. if (fileObj && isStream(fileObj)) {
  30905. content = fileObj.getBytes();
  30906. } else {
  30907. warn('Embedded file specification points to non-existing/invalid ' +
  30908. 'content');
  30909. }
  30910. } else {
  30911. warn('Embedded file specification does not have a content');
  30912. }
  30913. return content;
  30914. },
  30915. get serializable() {
  30916. return {
  30917. filename: this.filename,
  30918. content: this.content
  30919. };
  30920. }
  30921. };
  30922. return FileSpec;
  30923. })();
  30924. /**
  30925. * A helper for loading missing data in object graphs. It traverses the graph
  30926. * depth first and queues up any objects that have missing data. Once it has
  30927. * has traversed as many objects that are available it attempts to bundle the
  30928. * missing data requests and then resume from the nodes that weren't ready.
  30929. *
  30930. * NOTE: It provides protection from circular references by keeping track of
  30931. * of loaded references. However, you must be careful not to load any graphs
  30932. * that have references to the catalog or other pages since that will cause the
  30933. * entire PDF document object graph to be traversed.
  30934. */
  30935. var ObjectLoader = (function() {
  30936. function mayHaveChildren(value) {
  30937. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  30938. }
  30939. function addChildren(node, nodesToVisit) {
  30940. var value;
  30941. if (isDict(node) || isStream(node)) {
  30942. var map;
  30943. if (isDict(node)) {
  30944. map = node.map;
  30945. } else {
  30946. map = node.dict.map;
  30947. }
  30948. for (var key in map) {
  30949. value = map[key];
  30950. if (mayHaveChildren(value)) {
  30951. nodesToVisit.push(value);
  30952. }
  30953. }
  30954. } else if (isArray(node)) {
  30955. for (var i = 0, ii = node.length; i < ii; i++) {
  30956. value = node[i];
  30957. if (mayHaveChildren(value)) {
  30958. nodesToVisit.push(value);
  30959. }
  30960. }
  30961. }
  30962. }
  30963. function ObjectLoader(obj, keys, xref) {
  30964. this.obj = obj;
  30965. this.keys = keys;
  30966. this.xref = xref;
  30967. this.refSet = null;
  30968. this.capability = null;
  30969. }
  30970. ObjectLoader.prototype = {
  30971. load: function ObjectLoader_load() {
  30972. var keys = this.keys;
  30973. this.capability = createPromiseCapability();
  30974. // Don't walk the graph if all the data is already loaded.
  30975. if (!(this.xref.stream instanceof ChunkedStream) ||
  30976. this.xref.stream.getMissingChunks().length === 0) {
  30977. this.capability.resolve();
  30978. return this.capability.promise;
  30979. }
  30980. this.refSet = new RefSet();
  30981. // Setup the initial nodes to visit.
  30982. var nodesToVisit = [];
  30983. for (var i = 0; i < keys.length; i++) {
  30984. nodesToVisit.push(this.obj[keys[i]]);
  30985. }
  30986. this._walk(nodesToVisit);
  30987. return this.capability.promise;
  30988. },
  30989. _walk: function ObjectLoader_walk(nodesToVisit) {
  30990. var nodesToRevisit = [];
  30991. var pendingRequests = [];
  30992. // DFS walk of the object graph.
  30993. while (nodesToVisit.length) {
  30994. var currentNode = nodesToVisit.pop();
  30995. // Only references or chunked streams can cause missing data exceptions.
  30996. if (isRef(currentNode)) {
  30997. // Skip nodes that have already been visited.
  30998. if (this.refSet.has(currentNode)) {
  30999. continue;
  31000. }
  31001. try {
  31002. var ref = currentNode;
  31003. this.refSet.put(ref);
  31004. currentNode = this.xref.fetch(currentNode);
  31005. } catch (e) {
  31006. if (!(e instanceof MissingDataException)) {
  31007. throw e;
  31008. }
  31009. nodesToRevisit.push(currentNode);
  31010. pendingRequests.push({ begin: e.begin, end: e.end });
  31011. }
  31012. }
  31013. if (currentNode && currentNode.getBaseStreams) {
  31014. var baseStreams = currentNode.getBaseStreams();
  31015. var foundMissingData = false;
  31016. for (var i = 0; i < baseStreams.length; i++) {
  31017. var stream = baseStreams[i];
  31018. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  31019. foundMissingData = true;
  31020. pendingRequests.push({
  31021. begin: stream.start,
  31022. end: stream.end
  31023. });
  31024. }
  31025. }
  31026. if (foundMissingData) {
  31027. nodesToRevisit.push(currentNode);
  31028. }
  31029. }
  31030. addChildren(currentNode, nodesToVisit);
  31031. }
  31032. if (pendingRequests.length) {
  31033. this.xref.stream.manager.requestRanges(pendingRequests).then(
  31034. function pendingRequestCallback() {
  31035. nodesToVisit = nodesToRevisit;
  31036. for (var i = 0; i < nodesToRevisit.length; i++) {
  31037. var node = nodesToRevisit[i];
  31038. // Remove any reference nodes from the currrent refset so they
  31039. // aren't skipped when we revist them.
  31040. if (isRef(node)) {
  31041. this.refSet.remove(node);
  31042. }
  31043. }
  31044. this._walk(nodesToVisit);
  31045. }.bind(this), this.capability.reject);
  31046. return;
  31047. }
  31048. // Everything is loaded.
  31049. this.refSet = null;
  31050. this.capability.resolve();
  31051. }
  31052. };
  31053. return ObjectLoader;
  31054. })();
  31055. exports.Catalog = Catalog;
  31056. exports.ObjectLoader = ObjectLoader;
  31057. exports.XRef = XRef;
  31058. }));
  31059. (function (root, factory) {
  31060. {
  31061. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  31062. root.pdfjsCoreParser);
  31063. }
  31064. }(this, function (exports, sharedUtil, coreParser) {
  31065. var error = sharedUtil.error;
  31066. var EOF = coreParser.EOF;
  31067. var Lexer = coreParser.Lexer;
  31068. var PostScriptParser = (function PostScriptParserClosure() {
  31069. function PostScriptParser(lexer) {
  31070. this.lexer = lexer;
  31071. this.operators = [];
  31072. this.token = null;
  31073. this.prev = null;
  31074. }
  31075. PostScriptParser.prototype = {
  31076. nextToken: function PostScriptParser_nextToken() {
  31077. this.prev = this.token;
  31078. this.token = this.lexer.getToken();
  31079. },
  31080. accept: function PostScriptParser_accept(type) {
  31081. if (this.token.type === type) {
  31082. this.nextToken();
  31083. return true;
  31084. }
  31085. return false;
  31086. },
  31087. expect: function PostScriptParser_expect(type) {
  31088. if (this.accept(type)) {
  31089. return true;
  31090. }
  31091. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  31092. type + '.');
  31093. },
  31094. parse: function PostScriptParser_parse() {
  31095. this.nextToken();
  31096. this.expect(PostScriptTokenTypes.LBRACE);
  31097. this.parseBlock();
  31098. this.expect(PostScriptTokenTypes.RBRACE);
  31099. return this.operators;
  31100. },
  31101. parseBlock: function PostScriptParser_parseBlock() {
  31102. while (true) {
  31103. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  31104. this.operators.push(this.prev.value);
  31105. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  31106. this.operators.push(this.prev.value);
  31107. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  31108. this.parseCondition();
  31109. } else {
  31110. return;
  31111. }
  31112. }
  31113. },
  31114. parseCondition: function PostScriptParser_parseCondition() {
  31115. // Add two place holders that will be updated later
  31116. var conditionLocation = this.operators.length;
  31117. this.operators.push(null, null);
  31118. this.parseBlock();
  31119. this.expect(PostScriptTokenTypes.RBRACE);
  31120. if (this.accept(PostScriptTokenTypes.IF)) {
  31121. // The true block is right after the 'if' so it just falls through on
  31122. // true else it jumps and skips the true block.
  31123. this.operators[conditionLocation] = this.operators.length;
  31124. this.operators[conditionLocation + 1] = 'jz';
  31125. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  31126. var jumpLocation = this.operators.length;
  31127. this.operators.push(null, null);
  31128. var endOfTrue = this.operators.length;
  31129. this.parseBlock();
  31130. this.expect(PostScriptTokenTypes.RBRACE);
  31131. this.expect(PostScriptTokenTypes.IFELSE);
  31132. // The jump is added at the end of the true block to skip the false
  31133. // block.
  31134. this.operators[jumpLocation] = this.operators.length;
  31135. this.operators[jumpLocation + 1] = 'j';
  31136. this.operators[conditionLocation] = endOfTrue;
  31137. this.operators[conditionLocation + 1] = 'jz';
  31138. } else {
  31139. error('PS Function: error parsing conditional.');
  31140. }
  31141. }
  31142. };
  31143. return PostScriptParser;
  31144. })();
  31145. var PostScriptTokenTypes = {
  31146. LBRACE: 0,
  31147. RBRACE: 1,
  31148. NUMBER: 2,
  31149. OPERATOR: 3,
  31150. IF: 4,
  31151. IFELSE: 5
  31152. };
  31153. var PostScriptToken = (function PostScriptTokenClosure() {
  31154. function PostScriptToken(type, value) {
  31155. this.type = type;
  31156. this.value = value;
  31157. }
  31158. var opCache = Object.create(null);
  31159. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  31160. var opValue = opCache[op];
  31161. if (opValue) {
  31162. return opValue;
  31163. }
  31164. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  31165. };
  31166. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  31167. '{');
  31168. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  31169. '}');
  31170. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  31171. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  31172. 'IFELSE');
  31173. return PostScriptToken;
  31174. })();
  31175. var PostScriptLexer = (function PostScriptLexerClosure() {
  31176. function PostScriptLexer(stream) {
  31177. this.stream = stream;
  31178. this.nextChar();
  31179. this.strBuf = [];
  31180. }
  31181. PostScriptLexer.prototype = {
  31182. nextChar: function PostScriptLexer_nextChar() {
  31183. return (this.currentChar = this.stream.getByte());
  31184. },
  31185. getToken: function PostScriptLexer_getToken() {
  31186. var comment = false;
  31187. var ch = this.currentChar;
  31188. // skip comments
  31189. while (true) {
  31190. if (ch < 0) {
  31191. return EOF;
  31192. }
  31193. if (comment) {
  31194. if (ch === 0x0A || ch === 0x0D) {
  31195. comment = false;
  31196. }
  31197. } else if (ch === 0x25) { // '%'
  31198. comment = true;
  31199. } else if (!Lexer.isSpace(ch)) {
  31200. break;
  31201. }
  31202. ch = this.nextChar();
  31203. }
  31204. switch (ch | 0) {
  31205. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  31206. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  31207. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  31208. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  31209. this.getNumber());
  31210. case 0x7B: // '{'
  31211. this.nextChar();
  31212. return PostScriptToken.LBRACE;
  31213. case 0x7D: // '}'
  31214. this.nextChar();
  31215. return PostScriptToken.RBRACE;
  31216. }
  31217. // operator
  31218. var strBuf = this.strBuf;
  31219. strBuf.length = 0;
  31220. strBuf[0] = String.fromCharCode(ch);
  31221. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  31222. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  31223. strBuf.push(String.fromCharCode(ch));
  31224. }
  31225. var str = strBuf.join('');
  31226. switch (str.toLowerCase()) {
  31227. case 'if':
  31228. return PostScriptToken.IF;
  31229. case 'ifelse':
  31230. return PostScriptToken.IFELSE;
  31231. default:
  31232. return PostScriptToken.getOperator(str);
  31233. }
  31234. },
  31235. getNumber: function PostScriptLexer_getNumber() {
  31236. var ch = this.currentChar;
  31237. var strBuf = this.strBuf;
  31238. strBuf.length = 0;
  31239. strBuf[0] = String.fromCharCode(ch);
  31240. while ((ch = this.nextChar()) >= 0) {
  31241. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  31242. ch === 0x2D || ch === 0x2E) { // '-', '.'
  31243. strBuf.push(String.fromCharCode(ch));
  31244. } else {
  31245. break;
  31246. }
  31247. }
  31248. var value = parseFloat(strBuf.join(''));
  31249. if (isNaN(value)) {
  31250. error('Invalid floating point number: ' + value);
  31251. }
  31252. return value;
  31253. }
  31254. };
  31255. return PostScriptLexer;
  31256. })();
  31257. exports.PostScriptLexer = PostScriptLexer;
  31258. exports.PostScriptParser = PostScriptParser;
  31259. }));
  31260. (function (root, factory) {
  31261. {
  31262. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  31263. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  31264. root.pdfjsDisplayMetadata, root.pdfjsSharedGlobal);
  31265. }
  31266. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  31267. displayMetadata, sharedGlobal, amdRequire) {
  31268. var InvalidPDFException = sharedUtil.InvalidPDFException;
  31269. var MessageHandler = sharedUtil.MessageHandler;
  31270. var MissingPDFException = sharedUtil.MissingPDFException;
  31271. var PasswordResponses = sharedUtil.PasswordResponses;
  31272. var PasswordException = sharedUtil.PasswordException;
  31273. var StatTimer = sharedUtil.StatTimer;
  31274. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  31275. var UnknownErrorException = sharedUtil.UnknownErrorException;
  31276. var Util = sharedUtil.Util;
  31277. var createPromiseCapability = sharedUtil.createPromiseCapability;
  31278. var combineUrl = sharedUtil.combineUrl;
  31279. var error = sharedUtil.error;
  31280. var deprecated = sharedUtil.deprecated;
  31281. var info = sharedUtil.info;
  31282. var isArrayBuffer = sharedUtil.isArrayBuffer;
  31283. var isSameOrigin = sharedUtil.isSameOrigin;
  31284. var loadJpegStream = sharedUtil.loadJpegStream;
  31285. var stringToBytes = sharedUtil.stringToBytes;
  31286. var warn = sharedUtil.warn;
  31287. var FontFaceObject = displayFontLoader.FontFaceObject;
  31288. var FontLoader = displayFontLoader.FontLoader;
  31289. var CanvasGraphics = displayCanvas.CanvasGraphics;
  31290. var createScratchCanvas = displayCanvas.createScratchCanvas;
  31291. var Metadata = displayMetadata.Metadata;
  31292. var PDFJS = sharedGlobal.PDFJS;
  31293. var globalScope = sharedGlobal.globalScope;
  31294. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  31295. /**
  31296. * The maximum allowed image size in total pixels e.g. width * height. Images
  31297. * above this value will not be drawn. Use -1 for no limit.
  31298. * @var {number}
  31299. */
  31300. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  31301. -1 : PDFJS.maxImageSize);
  31302. /**
  31303. * The url of where the predefined Adobe CMaps are located. Include trailing
  31304. * slash.
  31305. * @var {string}
  31306. */
  31307. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  31308. /**
  31309. * Specifies if CMaps are binary packed.
  31310. * @var {boolean}
  31311. */
  31312. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  31313. /**
  31314. * By default fonts are converted to OpenType fonts and loaded via font face
  31315. * rules. If disabled, the font will be rendered using a built in font renderer
  31316. * that constructs the glyphs with primitive path commands.
  31317. * @var {boolean}
  31318. */
  31319. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  31320. false : PDFJS.disableFontFace);
  31321. /**
  31322. * Path for image resources, mainly for annotation icons. Include trailing
  31323. * slash.
  31324. * @var {string}
  31325. */
  31326. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  31327. '' : PDFJS.imageResourcesPath);
  31328. /**
  31329. * Disable the web worker and run all code on the main thread. This will happen
  31330. * automatically if the browser doesn't support workers or sending typed arrays
  31331. * to workers.
  31332. * @var {boolean}
  31333. */
  31334. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  31335. false : PDFJS.disableWorker);
  31336. /**
  31337. * Path and filename of the worker file. Required when the worker is enabled in
  31338. * development mode. If unspecified in the production build, the worker will be
  31339. * loaded based on the location of the pdf.js file. It is recommended that
  31340. * the workerSrc is set in a custom application to prevent issues caused by
  31341. * third-party frameworks and libraries.
  31342. * @var {string}
  31343. */
  31344. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  31345. /**
  31346. * Disable range request loading of PDF files. When enabled and if the server
  31347. * supports partial content requests then the PDF will be fetched in chunks.
  31348. * Enabled (false) by default.
  31349. * @var {boolean}
  31350. */
  31351. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  31352. false : PDFJS.disableRange);
  31353. /**
  31354. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  31355. * in chunks. This default behavior can be disabled.
  31356. * @var {boolean}
  31357. */
  31358. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  31359. false : PDFJS.disableStream);
  31360. /**
  31361. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  31362. * will automatically keep fetching more data even if it isn't needed to display
  31363. * the current page. This default behavior can be disabled.
  31364. *
  31365. * NOTE: It is also necessary to disable streaming, see above,
  31366. * in order for disabling of pre-fetching to work correctly.
  31367. * @var {boolean}
  31368. */
  31369. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  31370. false : PDFJS.disableAutoFetch);
  31371. /**
  31372. * Enables special hooks for debugging PDF.js.
  31373. * @var {boolean}
  31374. */
  31375. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  31376. /**
  31377. * Enables transfer usage in postMessage for ArrayBuffers.
  31378. * @var {boolean}
  31379. */
  31380. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  31381. true : PDFJS.postMessageTransfers);
  31382. /**
  31383. * Disables URL.createObjectURL usage.
  31384. * @var {boolean}
  31385. */
  31386. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  31387. false : PDFJS.disableCreateObjectURL);
  31388. /**
  31389. * Disables WebGL usage.
  31390. * @var {boolean}
  31391. */
  31392. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  31393. true : PDFJS.disableWebGL);
  31394. /**
  31395. * Disables fullscreen support, and by extension Presentation Mode,
  31396. * in browsers which support the fullscreen API.
  31397. * @var {boolean}
  31398. */
  31399. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  31400. false : PDFJS.disableFullscreen);
  31401. /**
  31402. * Enables CSS only zooming.
  31403. * @var {boolean}
  31404. */
  31405. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  31406. false : PDFJS.useOnlyCssZoom);
  31407. /**
  31408. * Controls the logging level.
  31409. * The constants from PDFJS.VERBOSITY_LEVELS should be used:
  31410. * - errors
  31411. * - warnings [default]
  31412. * - infos
  31413. * @var {number}
  31414. */
  31415. PDFJS.verbosity = (PDFJS.verbosity === undefined ?
  31416. PDFJS.VERBOSITY_LEVELS.warnings : PDFJS.verbosity);
  31417. /**
  31418. * The maximum supported canvas size in total pixels e.g. width * height.
  31419. * The default value is 4096 * 4096. Use -1 for no limit.
  31420. * @var {number}
  31421. */
  31422. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  31423. 16777216 : PDFJS.maxCanvasPixels);
  31424. /**
  31425. * (Deprecated) Opens external links in a new window if enabled.
  31426. * The default behavior opens external links in the PDF.js window.
  31427. *
  31428. * NOTE: This property has been deprecated, please use
  31429. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  31430. * @var {boolean}
  31431. */
  31432. PDFJS.openExternalLinksInNewWindow = (
  31433. PDFJS.openExternalLinksInNewWindow === undefined ?
  31434. false : PDFJS.openExternalLinksInNewWindow);
  31435. /**
  31436. * Specifies the |target| attribute for external links.
  31437. * The constants from PDFJS.LinkTarget should be used:
  31438. * - NONE [default]
  31439. * - SELF
  31440. * - BLANK
  31441. * - PARENT
  31442. * - TOP
  31443. * @var {number}
  31444. */
  31445. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  31446. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  31447. /**
  31448. * Specifies the |rel| attribute for external links. Defaults to stripping
  31449. * the referrer.
  31450. * @var {string}
  31451. */
  31452. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  31453. 'noreferrer' : PDFJS.externalLinkRel);
  31454. /**
  31455. * Determines if we can eval strings as JS. Primarily used to improve
  31456. * performance for font rendering.
  31457. * @var {boolean}
  31458. */
  31459. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  31460. true : PDFJS.isEvalSupported);
  31461. /**
  31462. * Document initialization / loading parameters object.
  31463. *
  31464. * @typedef {Object} DocumentInitParameters
  31465. * @property {string} url - The URL of the PDF.
  31466. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  31467. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  31468. * use atob() to convert it to a binary string first.
  31469. * @property {Object} httpHeaders - Basic authentication headers.
  31470. * @property {boolean} withCredentials - Indicates whether or not cross-site
  31471. * Access-Control requests should be made using credentials such as cookies
  31472. * or authorization headers. The default is false.
  31473. * @property {string} password - For decrypting password-protected PDFs.
  31474. * @property {TypedArray} initialData - A typed array with the first portion or
  31475. * all of the pdf data. Used by the extension since some data is already
  31476. * loaded before the switch to range requests.
  31477. * @property {number} length - The PDF file length. It's used for progress
  31478. * reports and range requests operations.
  31479. * @property {PDFDataRangeTransport} range
  31480. * @property {number} rangeChunkSize - Optional parameter to specify
  31481. * maximum number of bytes fetched per range request. The default value is
  31482. * 2^16 = 65536.
  31483. * @property {PDFWorker} worker - The worker that will be used for the loading
  31484. * and parsing of the PDF data.
  31485. */
  31486. /**
  31487. * @typedef {Object} PDFDocumentStats
  31488. * @property {Array} streamTypes - Used stream types in the document (an item
  31489. * is set to true if specific stream ID was used in the document).
  31490. * @property {Array} fontTypes - Used font type in the document (an item is set
  31491. * to true if specific font ID was used in the document).
  31492. */
  31493. /**
  31494. * This is the main entry point for loading a PDF and interacting with it.
  31495. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  31496. * is used, which means it must follow the same origin rules that any XHR does
  31497. * e.g. No cross domain requests without CORS.
  31498. *
  31499. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  31500. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  31501. * already populated with data or parameter object.
  31502. *
  31503. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  31504. * if you want to manually serve range requests for data in the PDF.
  31505. *
  31506. * @param {function} passwordCallback (deprecated) It is used to request a
  31507. * password if wrong or no password was provided. The callback receives two
  31508. * parameters: function that needs to be called with new password and reason
  31509. * (see {PasswordResponses}).
  31510. *
  31511. * @param {function} progressCallback (deprecated) It is used to be able to
  31512. * monitor the loading progress of the PDF file (necessary to implement e.g.
  31513. * a loading bar). The callback receives an {Object} with the properties:
  31514. * {number} loaded and {number} total.
  31515. *
  31516. * @return {PDFDocumentLoadingTask}
  31517. */
  31518. PDFJS.getDocument = function getDocument(src,
  31519. pdfDataRangeTransport,
  31520. passwordCallback,
  31521. progressCallback) {
  31522. var task = new PDFDocumentLoadingTask();
  31523. // Support of the obsolete arguments (for compatibility with API v1.0)
  31524. if (arguments.length > 1) {
  31525. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  31526. 'passwordCallback or progressCallback argument');
  31527. }
  31528. if (pdfDataRangeTransport) {
  31529. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  31530. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  31531. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  31532. pdfDataRangeTransport.length = src.length;
  31533. pdfDataRangeTransport.initialData = src.initialData;
  31534. if (!pdfDataRangeTransport.abort) {
  31535. pdfDataRangeTransport.abort = function () {};
  31536. }
  31537. }
  31538. src = Object.create(src);
  31539. src.range = pdfDataRangeTransport;
  31540. }
  31541. task.onPassword = passwordCallback || null;
  31542. task.onProgress = progressCallback || null;
  31543. var source;
  31544. if (typeof src === 'string') {
  31545. source = { url: src };
  31546. } else if (isArrayBuffer(src)) {
  31547. source = { data: src };
  31548. } else if (src instanceof PDFDataRangeTransport) {
  31549. source = { range: src };
  31550. } else {
  31551. if (typeof src !== 'object') {
  31552. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  31553. 'string or a parameter object');
  31554. }
  31555. if (!src.url && !src.data && !src.range) {
  31556. error('Invalid parameter object: need either .data, .range or .url');
  31557. }
  31558. source = src;
  31559. }
  31560. var params = {};
  31561. var rangeTransport = null;
  31562. var worker = null;
  31563. for (var key in source) {
  31564. if (key === 'url' && typeof window !== 'undefined') {
  31565. // The full path is required in the 'url' field.
  31566. params[key] = combineUrl(window.location.href, source[key]);
  31567. continue;
  31568. } else if (key === 'range') {
  31569. rangeTransport = source[key];
  31570. continue;
  31571. } else if (key === 'worker') {
  31572. worker = source[key];
  31573. continue;
  31574. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  31575. // Converting string or array-like data to Uint8Array.
  31576. var pdfBytes = source[key];
  31577. if (typeof pdfBytes === 'string') {
  31578. params[key] = stringToBytes(pdfBytes);
  31579. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  31580. !isNaN(pdfBytes.length)) {
  31581. params[key] = new Uint8Array(pdfBytes);
  31582. } else if (isArrayBuffer(pdfBytes)) {
  31583. params[key] = new Uint8Array(pdfBytes);
  31584. } else {
  31585. error('Invalid PDF binary data: either typed array, string or ' +
  31586. 'array-like object is expected in the data property.');
  31587. }
  31588. continue;
  31589. }
  31590. params[key] = source[key];
  31591. }
  31592. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  31593. if (!worker) {
  31594. // Worker was not provided -- creating and owning our own.
  31595. worker = new PDFWorker();
  31596. task._worker = worker;
  31597. }
  31598. var docId = task.docId;
  31599. worker.promise.then(function () {
  31600. if (task.destroyed) {
  31601. throw new Error('Loading aborted');
  31602. }
  31603. return _fetchDocument(worker, params, rangeTransport, docId).then(
  31604. function (workerId) {
  31605. if (task.destroyed) {
  31606. throw new Error('Loading aborted');
  31607. }
  31608. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  31609. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  31610. task._transport = transport;
  31611. messageHandler.send('Ready', null);
  31612. });
  31613. }).catch(task._capability.reject);
  31614. return task;
  31615. };
  31616. /**
  31617. * Starts fetching of specified PDF document/data.
  31618. * @param {PDFWorker} worker
  31619. * @param {Object} source
  31620. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  31621. * @param {string} docId Unique document id, used as MessageHandler id.
  31622. * @returns {Promise} The promise, which is resolved when worker id of
  31623. * MessageHandler is known.
  31624. * @private
  31625. */
  31626. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  31627. if (worker.destroyed) {
  31628. return Promise.reject(new Error('Worker was destroyed'));
  31629. }
  31630. source.disableAutoFetch = PDFJS.disableAutoFetch;
  31631. source.disableStream = PDFJS.disableStream;
  31632. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  31633. if (pdfDataRangeTransport) {
  31634. source.length = pdfDataRangeTransport.length;
  31635. source.initialData = pdfDataRangeTransport.initialData;
  31636. }
  31637. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  31638. docId: docId,
  31639. source: source,
  31640. disableRange: PDFJS.disableRange,
  31641. maxImageSize: PDFJS.maxImageSize,
  31642. cMapUrl: PDFJS.cMapUrl,
  31643. cMapPacked: PDFJS.cMapPacked,
  31644. disableFontFace: PDFJS.disableFontFace,
  31645. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  31646. verbosity: PDFJS.verbosity
  31647. }).then(function (workerId) {
  31648. if (worker.destroyed) {
  31649. throw new Error('Worker was destroyed');
  31650. }
  31651. return workerId;
  31652. });
  31653. }
  31654. /**
  31655. * PDF document loading operation.
  31656. * @class
  31657. * @alias PDFDocumentLoadingTask
  31658. */
  31659. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  31660. var nextDocumentId = 0;
  31661. /** @constructs PDFDocumentLoadingTask */
  31662. function PDFDocumentLoadingTask() {
  31663. this._capability = createPromiseCapability();
  31664. this._transport = null;
  31665. this._worker = null;
  31666. /**
  31667. * Unique document loading task id -- used in MessageHandlers.
  31668. * @type {string}
  31669. */
  31670. this.docId = 'd' + (nextDocumentId++);
  31671. /**
  31672. * Shows if loading task is destroyed.
  31673. * @type {boolean}
  31674. */
  31675. this.destroyed = false;
  31676. /**
  31677. * Callback to request a password if wrong or no password was provided.
  31678. * The callback receives two parameters: function that needs to be called
  31679. * with new password and reason (see {PasswordResponses}).
  31680. */
  31681. this.onPassword = null;
  31682. /**
  31683. * Callback to be able to monitor the loading progress of the PDF file
  31684. * (necessary to implement e.g. a loading bar). The callback receives
  31685. * an {Object} with the properties: {number} loaded and {number} total.
  31686. */
  31687. this.onProgress = null;
  31688. /**
  31689. * Callback to when unsupported feature is used. The callback receives
  31690. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  31691. */
  31692. this.onUnsupportedFeature = null;
  31693. }
  31694. PDFDocumentLoadingTask.prototype =
  31695. /** @lends PDFDocumentLoadingTask.prototype */ {
  31696. /**
  31697. * @return {Promise}
  31698. */
  31699. get promise() {
  31700. return this._capability.promise;
  31701. },
  31702. /**
  31703. * Aborts all network requests and destroys worker.
  31704. * @return {Promise} A promise that is resolved after destruction activity
  31705. * is completed.
  31706. */
  31707. destroy: function () {
  31708. this.destroyed = true;
  31709. var transportDestroyed = !this._transport ? Promise.resolve() :
  31710. this._transport.destroy();
  31711. return transportDestroyed.then(function () {
  31712. this._transport = null;
  31713. if (this._worker) {
  31714. this._worker.destroy();
  31715. this._worker = null;
  31716. }
  31717. }.bind(this));
  31718. },
  31719. /**
  31720. * Registers callbacks to indicate the document loading completion.
  31721. *
  31722. * @param {function} onFulfilled The callback for the loading completion.
  31723. * @param {function} onRejected The callback for the loading failure.
  31724. * @return {Promise} A promise that is resolved after the onFulfilled or
  31725. * onRejected callback.
  31726. */
  31727. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  31728. return this.promise.then.apply(this.promise, arguments);
  31729. }
  31730. };
  31731. return PDFDocumentLoadingTask;
  31732. })();
  31733. /**
  31734. * Abstract class to support range requests file loading.
  31735. * @class
  31736. * @alias PDFJS.PDFDataRangeTransport
  31737. * @param {number} length
  31738. * @param {Uint8Array} initialData
  31739. */
  31740. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  31741. function PDFDataRangeTransport(length, initialData) {
  31742. this.length = length;
  31743. this.initialData = initialData;
  31744. this._rangeListeners = [];
  31745. this._progressListeners = [];
  31746. this._progressiveReadListeners = [];
  31747. this._readyCapability = createPromiseCapability();
  31748. }
  31749. PDFDataRangeTransport.prototype =
  31750. /** @lends PDFDataRangeTransport.prototype */ {
  31751. addRangeListener:
  31752. function PDFDataRangeTransport_addRangeListener(listener) {
  31753. this._rangeListeners.push(listener);
  31754. },
  31755. addProgressListener:
  31756. function PDFDataRangeTransport_addProgressListener(listener) {
  31757. this._progressListeners.push(listener);
  31758. },
  31759. addProgressiveReadListener:
  31760. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  31761. this._progressiveReadListeners.push(listener);
  31762. },
  31763. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  31764. var listeners = this._rangeListeners;
  31765. for (var i = 0, n = listeners.length; i < n; ++i) {
  31766. listeners[i](begin, chunk);
  31767. }
  31768. },
  31769. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  31770. this._readyCapability.promise.then(function () {
  31771. var listeners = this._progressListeners;
  31772. for (var i = 0, n = listeners.length; i < n; ++i) {
  31773. listeners[i](loaded);
  31774. }
  31775. }.bind(this));
  31776. },
  31777. onDataProgressiveRead:
  31778. function PDFDataRangeTransport_onDataProgress(chunk) {
  31779. this._readyCapability.promise.then(function () {
  31780. var listeners = this._progressiveReadListeners;
  31781. for (var i = 0, n = listeners.length; i < n; ++i) {
  31782. listeners[i](chunk);
  31783. }
  31784. }.bind(this));
  31785. },
  31786. transportReady: function PDFDataRangeTransport_transportReady() {
  31787. this._readyCapability.resolve();
  31788. },
  31789. requestDataRange:
  31790. function PDFDataRangeTransport_requestDataRange(begin, end) {
  31791. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  31792. },
  31793. abort: function PDFDataRangeTransport_abort() {
  31794. }
  31795. };
  31796. return PDFDataRangeTransport;
  31797. })();
  31798. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  31799. /**
  31800. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  31801. * properties that can be read synchronously.
  31802. * @class
  31803. * @alias PDFDocumentProxy
  31804. */
  31805. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  31806. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  31807. this.pdfInfo = pdfInfo;
  31808. this.transport = transport;
  31809. this.loadingTask = loadingTask;
  31810. }
  31811. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  31812. /**
  31813. * @return {number} Total number of pages the PDF contains.
  31814. */
  31815. get numPages() {
  31816. return this.pdfInfo.numPages;
  31817. },
  31818. /**
  31819. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  31820. * unique.
  31821. */
  31822. get fingerprint() {
  31823. return this.pdfInfo.fingerprint;
  31824. },
  31825. /**
  31826. * @param {number} pageNumber The page number to get. The first page is 1.
  31827. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  31828. * object.
  31829. */
  31830. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  31831. return this.transport.getPage(pageNumber);
  31832. },
  31833. /**
  31834. * @param {{num: number, gen: number}} ref The page reference. Must have
  31835. * the 'num' and 'gen' properties.
  31836. * @return {Promise} A promise that is resolved with the page index that is
  31837. * associated with the reference.
  31838. */
  31839. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  31840. return this.transport.getPageIndex(ref);
  31841. },
  31842. /**
  31843. * @return {Promise} A promise that is resolved with a lookup table for
  31844. * mapping named destinations to reference numbers.
  31845. *
  31846. * This can be slow for large documents: use getDestination instead
  31847. */
  31848. getDestinations: function PDFDocumentProxy_getDestinations() {
  31849. return this.transport.getDestinations();
  31850. },
  31851. /**
  31852. * @param {string} id The named destination to get.
  31853. * @return {Promise} A promise that is resolved with all information
  31854. * of the given named destination.
  31855. */
  31856. getDestination: function PDFDocumentProxy_getDestination(id) {
  31857. return this.transport.getDestination(id);
  31858. },
  31859. /**
  31860. * @return {Promise} A promise that is resolved with:
  31861. * an Array containing the pageLabels that correspond to the pageIndexes,
  31862. * or `null` when no pageLabels are present in the PDF file.
  31863. */
  31864. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  31865. return this.transport.getPageLabels();
  31866. },
  31867. /**
  31868. * @return {Promise} A promise that is resolved with a lookup table for
  31869. * mapping named attachments to their content.
  31870. */
  31871. getAttachments: function PDFDocumentProxy_getAttachments() {
  31872. return this.transport.getAttachments();
  31873. },
  31874. /**
  31875. * @return {Promise} A promise that is resolved with an array of all the
  31876. * JavaScript strings in the name tree.
  31877. */
  31878. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  31879. return this.transport.getJavaScript();
  31880. },
  31881. /**
  31882. * @return {Promise} A promise that is resolved with an {Array} that is a
  31883. * tree outline (if it has one) of the PDF. The tree is in the format of:
  31884. * [
  31885. * {
  31886. * title: string,
  31887. * bold: boolean,
  31888. * italic: boolean,
  31889. * color: rgb array,
  31890. * dest: dest obj,
  31891. * url: string,
  31892. * items: array of more items like this
  31893. * },
  31894. * ...
  31895. * ].
  31896. */
  31897. getOutline: function PDFDocumentProxy_getOutline() {
  31898. return this.transport.getOutline();
  31899. },
  31900. /**
  31901. * @return {Promise} A promise that is resolved with an {Object} that has
  31902. * info and metadata properties. Info is an {Object} filled with anything
  31903. * available in the information dictionary and similarly metadata is a
  31904. * {Metadata} object with information from the metadata section of the PDF.
  31905. */
  31906. getMetadata: function PDFDocumentProxy_getMetadata() {
  31907. return this.transport.getMetadata();
  31908. },
  31909. /**
  31910. * @return {Promise} A promise that is resolved with a TypedArray that has
  31911. * the raw data from the PDF.
  31912. */
  31913. getData: function PDFDocumentProxy_getData() {
  31914. return this.transport.getData();
  31915. },
  31916. /**
  31917. * @return {Promise} A promise that is resolved when the document's data
  31918. * is loaded. It is resolved with an {Object} that contains the length
  31919. * property that indicates size of the PDF data in bytes.
  31920. */
  31921. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  31922. return this.transport.downloadInfoCapability.promise;
  31923. },
  31924. /**
  31925. * @return {Promise} A promise this is resolved with current stats about
  31926. * document structures (see {@link PDFDocumentStats}).
  31927. */
  31928. getStats: function PDFDocumentProxy_getStats() {
  31929. return this.transport.getStats();
  31930. },
  31931. /**
  31932. * Cleans up resources allocated by the document, e.g. created @font-face.
  31933. */
  31934. cleanup: function PDFDocumentProxy_cleanup() {
  31935. this.transport.startCleanup();
  31936. },
  31937. /**
  31938. * Destroys current document instance and terminates worker.
  31939. */
  31940. destroy: function PDFDocumentProxy_destroy() {
  31941. return this.loadingTask.destroy();
  31942. }
  31943. };
  31944. return PDFDocumentProxy;
  31945. })();
  31946. /**
  31947. * Page getTextContent parameters.
  31948. *
  31949. * @typedef {Object} getTextContentParameters
  31950. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  31951. * whitespace with standard spaces (0x20). The default value is `false`.
  31952. */
  31953. /**
  31954. * Page text content.
  31955. *
  31956. * @typedef {Object} TextContent
  31957. * @property {array} items - array of {@link TextItem}
  31958. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  31959. * name.
  31960. */
  31961. /**
  31962. * Page text content part.
  31963. *
  31964. * @typedef {Object} TextItem
  31965. * @property {string} str - text content.
  31966. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  31967. * @property {array} transform - transformation matrix.
  31968. * @property {number} width - width in device space.
  31969. * @property {number} height - height in device space.
  31970. * @property {string} fontName - font name used by pdf.js for converted font.
  31971. */
  31972. /**
  31973. * Text style.
  31974. *
  31975. * @typedef {Object} TextStyle
  31976. * @property {number} ascent - font ascent.
  31977. * @property {number} descent - font descent.
  31978. * @property {boolean} vertical - text is in vertical mode.
  31979. * @property {string} fontFamily - possible font family
  31980. */
  31981. /**
  31982. * Page annotation parameters.
  31983. *
  31984. * @typedef {Object} GetAnnotationsParameters
  31985. * @param {string} intent - Determines the annotations that will be fetched,
  31986. * can be either 'display' (viewable annotations) or 'print'
  31987. * (printable annotations).
  31988. * If the parameter is omitted, all annotations are fetched.
  31989. */
  31990. /**
  31991. * Page render parameters.
  31992. *
  31993. * @typedef {Object} RenderParameters
  31994. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  31995. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  31996. * calling of PDFPage.getViewport method.
  31997. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  31998. * (default value is 'display').
  31999. * @property {Array} transform - (optional) Additional transform, applied
  32000. * just before viewport transform.
  32001. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  32002. * endLayout and appendImage functions.
  32003. * @property {function} continueCallback - (deprecated) A function that will be
  32004. * called each time the rendering is paused. To continue
  32005. * rendering call the function that is the first argument
  32006. * to the callback.
  32007. */
  32008. /**
  32009. * PDF page operator list.
  32010. *
  32011. * @typedef {Object} PDFOperatorList
  32012. * @property {Array} fnArray - Array containing the operator functions.
  32013. * @property {Array} argsArray - Array containing the arguments of the
  32014. * functions.
  32015. */
  32016. /**
  32017. * Proxy to a PDFPage in the worker thread.
  32018. * @class
  32019. * @alias PDFPageProxy
  32020. */
  32021. var PDFPageProxy = (function PDFPageProxyClosure() {
  32022. function PDFPageProxy(pageIndex, pageInfo, transport) {
  32023. this.pageIndex = pageIndex;
  32024. this.pageInfo = pageInfo;
  32025. this.transport = transport;
  32026. this.stats = new StatTimer();
  32027. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  32028. this.commonObjs = transport.commonObjs;
  32029. this.objs = new PDFObjects();
  32030. this.cleanupAfterRender = false;
  32031. this.pendingCleanup = false;
  32032. this.intentStates = Object.create(null);
  32033. this.destroyed = false;
  32034. }
  32035. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  32036. /**
  32037. * @return {number} Page number of the page. First page is 1.
  32038. */
  32039. get pageNumber() {
  32040. return this.pageIndex + 1;
  32041. },
  32042. /**
  32043. * @return {number} The number of degrees the page is rotated clockwise.
  32044. */
  32045. get rotate() {
  32046. return this.pageInfo.rotate;
  32047. },
  32048. /**
  32049. * @return {Object} The reference that points to this page. It has 'num' and
  32050. * 'gen' properties.
  32051. */
  32052. get ref() {
  32053. return this.pageInfo.ref;
  32054. },
  32055. /**
  32056. * @return {Array} An array of the visible portion of the PDF page in the
  32057. * user space units - [x1, y1, x2, y2].
  32058. */
  32059. get view() {
  32060. return this.pageInfo.view;
  32061. },
  32062. /**
  32063. * @param {number} scale The desired scale of the viewport.
  32064. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  32065. * defaults to the page rotation.
  32066. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  32067. * along with transforms required for rendering.
  32068. */
  32069. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  32070. if (arguments.length < 2) {
  32071. rotate = this.rotate;
  32072. }
  32073. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  32074. },
  32075. /**
  32076. * @param {GetAnnotationsParameters} params - Annotation parameters.
  32077. * @return {Promise} A promise that is resolved with an {Array} of the
  32078. * annotation objects.
  32079. */
  32080. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  32081. var intent = (params && params.intent) || null;
  32082. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  32083. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  32084. intent);
  32085. this.annotationsIntent = intent;
  32086. }
  32087. return this.annotationsPromise;
  32088. },
  32089. /**
  32090. * Begins the process of rendering a page to the desired context.
  32091. * @param {RenderParameters} params Page render parameters.
  32092. * @return {RenderTask} An object that contains the promise, which
  32093. * is resolved when the page finishes rendering.
  32094. */
  32095. render: function PDFPageProxy_render(params) {
  32096. var stats = this.stats;
  32097. stats.time('Overall');
  32098. // If there was a pending destroy cancel it so no cleanup happens during
  32099. // this call to render.
  32100. this.pendingCleanup = false;
  32101. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  32102. if (!this.intentStates[renderingIntent]) {
  32103. this.intentStates[renderingIntent] = Object.create(null);
  32104. }
  32105. var intentState = this.intentStates[renderingIntent];
  32106. // If there's no displayReadyCapability yet, then the operatorList
  32107. // was never requested before. Make the request and create the promise.
  32108. if (!intentState.displayReadyCapability) {
  32109. intentState.receivingOperatorList = true;
  32110. intentState.displayReadyCapability = createPromiseCapability();
  32111. intentState.operatorList = {
  32112. fnArray: [],
  32113. argsArray: [],
  32114. lastChunk: false
  32115. };
  32116. this.stats.time('Page Request');
  32117. this.transport.messageHandler.send('RenderPageRequest', {
  32118. pageIndex: this.pageNumber - 1,
  32119. intent: renderingIntent
  32120. });
  32121. }
  32122. var internalRenderTask = new InternalRenderTask(complete, params,
  32123. this.objs,
  32124. this.commonObjs,
  32125. intentState.operatorList,
  32126. this.pageNumber);
  32127. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  32128. if (!intentState.renderTasks) {
  32129. intentState.renderTasks = [];
  32130. }
  32131. intentState.renderTasks.push(internalRenderTask);
  32132. var renderTask = internalRenderTask.task;
  32133. // Obsolete parameter support
  32134. if (params.continueCallback) {
  32135. deprecated('render is used with continueCallback parameter');
  32136. renderTask.onContinue = params.continueCallback;
  32137. }
  32138. var self = this;
  32139. intentState.displayReadyCapability.promise.then(
  32140. function pageDisplayReadyPromise(transparency) {
  32141. if (self.pendingCleanup) {
  32142. complete();
  32143. return;
  32144. }
  32145. stats.time('Rendering');
  32146. internalRenderTask.initalizeGraphics(transparency);
  32147. internalRenderTask.operatorListChanged();
  32148. },
  32149. function pageDisplayReadPromiseError(reason) {
  32150. complete(reason);
  32151. }
  32152. );
  32153. function complete(error) {
  32154. var i = intentState.renderTasks.indexOf(internalRenderTask);
  32155. if (i >= 0) {
  32156. intentState.renderTasks.splice(i, 1);
  32157. }
  32158. if (self.cleanupAfterRender) {
  32159. self.pendingCleanup = true;
  32160. }
  32161. self._tryCleanup();
  32162. if (error) {
  32163. internalRenderTask.capability.reject(error);
  32164. } else {
  32165. internalRenderTask.capability.resolve();
  32166. }
  32167. stats.timeEnd('Rendering');
  32168. stats.timeEnd('Overall');
  32169. }
  32170. return renderTask;
  32171. },
  32172. /**
  32173. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  32174. * object that represents page's operator list.
  32175. */
  32176. getOperatorList: function PDFPageProxy_getOperatorList() {
  32177. function operatorListChanged() {
  32178. if (intentState.operatorList.lastChunk) {
  32179. intentState.opListReadCapability.resolve(intentState.operatorList);
  32180. var i = intentState.renderTasks.indexOf(opListTask);
  32181. if (i >= 0) {
  32182. intentState.renderTasks.splice(i, 1);
  32183. }
  32184. }
  32185. }
  32186. var renderingIntent = 'oplist';
  32187. if (!this.intentStates[renderingIntent]) {
  32188. this.intentStates[renderingIntent] = Object.create(null);
  32189. }
  32190. var intentState = this.intentStates[renderingIntent];
  32191. var opListTask;
  32192. if (!intentState.opListReadCapability) {
  32193. opListTask = {};
  32194. opListTask.operatorListChanged = operatorListChanged;
  32195. intentState.receivingOperatorList = true;
  32196. intentState.opListReadCapability = createPromiseCapability();
  32197. intentState.renderTasks = [];
  32198. intentState.renderTasks.push(opListTask);
  32199. intentState.operatorList = {
  32200. fnArray: [],
  32201. argsArray: [],
  32202. lastChunk: false
  32203. };
  32204. this.transport.messageHandler.send('RenderPageRequest', {
  32205. pageIndex: this.pageIndex,
  32206. intent: renderingIntent
  32207. });
  32208. }
  32209. return intentState.opListReadCapability.promise;
  32210. },
  32211. /**
  32212. * @param {getTextContentParameters} params - getTextContent parameters.
  32213. * @return {Promise} That is resolved a {@link TextContent}
  32214. * object that represent the page text content.
  32215. */
  32216. getTextContent: function PDFPageProxy_getTextContent(params) {
  32217. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  32218. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  32219. pageIndex: this.pageNumber - 1,
  32220. normalizeWhitespace: normalizeWhitespace,
  32221. });
  32222. },
  32223. /**
  32224. * Destroys page object.
  32225. */
  32226. _destroy: function PDFPageProxy_destroy() {
  32227. this.destroyed = true;
  32228. this.transport.pageCache[this.pageIndex] = null;
  32229. var waitOn = [];
  32230. Object.keys(this.intentStates).forEach(function(intent) {
  32231. if (intent === 'oplist') {
  32232. // Avoid errors below, since the renderTasks are just stubs.
  32233. return;
  32234. }
  32235. var intentState = this.intentStates[intent];
  32236. intentState.renderTasks.forEach(function(renderTask) {
  32237. var renderCompleted = renderTask.capability.promise.
  32238. catch(function () {}); // ignoring failures
  32239. waitOn.push(renderCompleted);
  32240. renderTask.cancel();
  32241. });
  32242. }, this);
  32243. this.objs.clear();
  32244. this.annotationsPromise = null;
  32245. this.pendingCleanup = false;
  32246. return Promise.all(waitOn);
  32247. },
  32248. /**
  32249. * Cleans up resources allocated by the page. (deprecated)
  32250. */
  32251. destroy: function() {
  32252. deprecated('page destroy method, use cleanup() instead');
  32253. this.cleanup();
  32254. },
  32255. /**
  32256. * Cleans up resources allocated by the page.
  32257. */
  32258. cleanup: function PDFPageProxy_cleanup() {
  32259. this.pendingCleanup = true;
  32260. this._tryCleanup();
  32261. },
  32262. /**
  32263. * For internal use only. Attempts to clean up if rendering is in a state
  32264. * where that's possible.
  32265. * @ignore
  32266. */
  32267. _tryCleanup: function PDFPageProxy_tryCleanup() {
  32268. if (!this.pendingCleanup ||
  32269. Object.keys(this.intentStates).some(function(intent) {
  32270. var intentState = this.intentStates[intent];
  32271. return (intentState.renderTasks.length !== 0 ||
  32272. intentState.receivingOperatorList);
  32273. }, this)) {
  32274. return;
  32275. }
  32276. Object.keys(this.intentStates).forEach(function(intent) {
  32277. delete this.intentStates[intent];
  32278. }, this);
  32279. this.objs.clear();
  32280. this.annotationsPromise = null;
  32281. this.pendingCleanup = false;
  32282. },
  32283. /**
  32284. * For internal use only.
  32285. * @ignore
  32286. */
  32287. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  32288. intent) {
  32289. var intentState = this.intentStates[intent];
  32290. // TODO Refactor RenderPageRequest to separate rendering
  32291. // and operator list logic
  32292. if (intentState.displayReadyCapability) {
  32293. intentState.displayReadyCapability.resolve(transparency);
  32294. }
  32295. },
  32296. /**
  32297. * For internal use only.
  32298. * @ignore
  32299. */
  32300. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  32301. intent) {
  32302. var intentState = this.intentStates[intent];
  32303. var i, ii;
  32304. // Add the new chunk to the current operator list.
  32305. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  32306. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  32307. intentState.operatorList.argsArray.push(
  32308. operatorListChunk.argsArray[i]);
  32309. }
  32310. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  32311. // Notify all the rendering tasks there are more operators to be consumed.
  32312. for (i = 0; i < intentState.renderTasks.length; i++) {
  32313. intentState.renderTasks[i].operatorListChanged();
  32314. }
  32315. if (operatorListChunk.lastChunk) {
  32316. intentState.receivingOperatorList = false;
  32317. this._tryCleanup();
  32318. }
  32319. }
  32320. };
  32321. return PDFPageProxy;
  32322. })();
  32323. /**
  32324. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  32325. * WorkerTransport for them. If creation of a web worker is not possible,
  32326. * a "fake" worker will be used instead.
  32327. * @class
  32328. */
  32329. var PDFWorker = (function PDFWorkerClosure() {
  32330. var nextFakeWorkerId = 0;
  32331. function getWorkerSrc() {
  32332. if (PDFJS.workerSrc) {
  32333. return PDFJS.workerSrc;
  32334. }
  32335. if (pdfjsFilePath) {
  32336. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  32337. }
  32338. error('No PDFJS.workerSrc specified');
  32339. }
  32340. // Loads worker code into main thread.
  32341. function setupFakeWorkerGlobal() {
  32342. if (!PDFJS.fakeWorkerFilesLoadedCapability) {
  32343. PDFJS.fakeWorkerFilesLoadedCapability = createPromiseCapability();
  32344. // In the developer build load worker_loader which in turn loads all the
  32345. // other files and resolves the promise. In production only the
  32346. // pdf.worker.js file is needed.
  32347. PDFJS.fakeWorkerFilesLoadedCapability.resolve();
  32348. }
  32349. return PDFJS.fakeWorkerFilesLoadedCapability.promise;
  32350. }
  32351. function createCDNWrapper(url) {
  32352. // We will rely on blob URL's property to specify origin.
  32353. // We want this function to fail in case if createObjectURL or Blob do not
  32354. // exist or fail for some reason -- our Worker creation will fail anyway.
  32355. var wrapper = 'importScripts(\'' + url + '\');';
  32356. return URL.createObjectURL(new Blob([wrapper]));
  32357. }
  32358. function PDFWorker(name) {
  32359. this.name = name;
  32360. this.destroyed = false;
  32361. this._readyCapability = createPromiseCapability();
  32362. this._port = null;
  32363. this._webWorker = null;
  32364. this._messageHandler = null;
  32365. this._initialize();
  32366. }
  32367. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  32368. get promise() {
  32369. return this._readyCapability.promise;
  32370. },
  32371. get port() {
  32372. return this._port;
  32373. },
  32374. get messageHandler() {
  32375. return this._messageHandler;
  32376. },
  32377. _initialize: function PDFWorker_initialize() {
  32378. // If worker support isn't disabled explicit and the browser has worker
  32379. // support, create a new web worker and test if it/the browser fulfills
  32380. // all requirements to run parts of pdf.js in a web worker.
  32381. // Right now, the requirement is, that an Uint8Array is still an
  32382. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  32383. // Either workers are disabled, not supported or have thrown an exception.
  32384. // Thus, we fallback to a faked worker.
  32385. this._setupFakeWorker();
  32386. },
  32387. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  32388. if (!globalScope.PDFJS.disableWorker) {
  32389. warn('Setting up fake worker.');
  32390. globalScope.PDFJS.disableWorker = true;
  32391. }
  32392. setupFakeWorkerGlobal().then(function () {
  32393. if (this.destroyed) {
  32394. this._readyCapability.reject(new Error('Worker was destroyed'));
  32395. return;
  32396. }
  32397. // If we don't use a worker, just post/sendMessage to the main thread.
  32398. var port = {
  32399. _listeners: [],
  32400. postMessage: function (obj) {
  32401. var e = {data: obj};
  32402. this._listeners.forEach(function (listener) {
  32403. listener.call(this, e);
  32404. }, this);
  32405. },
  32406. addEventListener: function (name, listener) {
  32407. this._listeners.push(listener);
  32408. },
  32409. removeEventListener: function (name, listener) {
  32410. var i = this._listeners.indexOf(listener);
  32411. this._listeners.splice(i, 1);
  32412. },
  32413. terminate: function () {}
  32414. };
  32415. this._port = port;
  32416. // All fake workers use the same port, making id unique.
  32417. var id = 'fake' + (nextFakeWorkerId++);
  32418. // If the main thread is our worker, setup the handling for the
  32419. // messages -- the main thread sends to it self.
  32420. var workerHandler = new MessageHandler(id + '_worker', id, port);
  32421. PDFJS.WorkerMessageHandler.setup(workerHandler, port);
  32422. var messageHandler = new MessageHandler(id, id + '_worker', port);
  32423. this._messageHandler = messageHandler;
  32424. this._readyCapability.resolve();
  32425. }.bind(this));
  32426. },
  32427. /**
  32428. * Destroys the worker instance.
  32429. */
  32430. destroy: function PDFWorker_destroy() {
  32431. this.destroyed = true;
  32432. if (this._webWorker) {
  32433. // We need to terminate only web worker created resource.
  32434. this._webWorker.terminate();
  32435. this._webWorker = null;
  32436. }
  32437. this._port = null;
  32438. if (this._messageHandler) {
  32439. this._messageHandler.destroy();
  32440. this._messageHandler = null;
  32441. }
  32442. }
  32443. };
  32444. return PDFWorker;
  32445. })();
  32446. PDFJS.PDFWorker = PDFWorker;
  32447. /**
  32448. * For internal use only.
  32449. * @ignore
  32450. */
  32451. var WorkerTransport = (function WorkerTransportClosure() {
  32452. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  32453. this.messageHandler = messageHandler;
  32454. this.loadingTask = loadingTask;
  32455. this.pdfDataRangeTransport = pdfDataRangeTransport;
  32456. this.commonObjs = new PDFObjects();
  32457. this.fontLoader = new FontLoader(loadingTask.docId);
  32458. this.destroyed = false;
  32459. this.destroyCapability = null;
  32460. this.pageCache = [];
  32461. this.pagePromises = [];
  32462. this.downloadInfoCapability = createPromiseCapability();
  32463. this.setupMessageHandler();
  32464. }
  32465. WorkerTransport.prototype = {
  32466. destroy: function WorkerTransport_destroy() {
  32467. if (this.destroyCapability) {
  32468. return this.destroyCapability.promise;
  32469. }
  32470. this.destroyed = true;
  32471. this.destroyCapability = createPromiseCapability();
  32472. var waitOn = [];
  32473. // We need to wait for all renderings to be completed, e.g.
  32474. // timeout/rAF can take a long time.
  32475. this.pageCache.forEach(function (page) {
  32476. if (page) {
  32477. waitOn.push(page._destroy());
  32478. }
  32479. });
  32480. this.pageCache = [];
  32481. this.pagePromises = [];
  32482. var self = this;
  32483. // We also need to wait for the worker to finish its long running tasks.
  32484. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  32485. waitOn.push(terminated);
  32486. Promise.all(waitOn).then(function () {
  32487. self.fontLoader.clear();
  32488. if (self.pdfDataRangeTransport) {
  32489. self.pdfDataRangeTransport.abort();
  32490. self.pdfDataRangeTransport = null;
  32491. }
  32492. if (self.messageHandler) {
  32493. self.messageHandler.destroy();
  32494. self.messageHandler = null;
  32495. }
  32496. self.destroyCapability.resolve();
  32497. }, this.destroyCapability.reject);
  32498. return this.destroyCapability.promise;
  32499. },
  32500. setupMessageHandler:
  32501. function WorkerTransport_setupMessageHandler() {
  32502. var messageHandler = this.messageHandler;
  32503. function updatePassword(password) {
  32504. messageHandler.send('UpdatePassword', password);
  32505. }
  32506. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  32507. if (pdfDataRangeTransport) {
  32508. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  32509. messageHandler.send('OnDataRange', {
  32510. begin: begin,
  32511. chunk: chunk
  32512. });
  32513. });
  32514. pdfDataRangeTransport.addProgressListener(function(loaded) {
  32515. messageHandler.send('OnDataProgress', {
  32516. loaded: loaded
  32517. });
  32518. });
  32519. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  32520. messageHandler.send('OnDataRange', {
  32521. chunk: chunk
  32522. });
  32523. });
  32524. messageHandler.on('RequestDataRange',
  32525. function transportDataRange(data) {
  32526. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  32527. }, this);
  32528. }
  32529. messageHandler.on('GetDoc', function transportDoc(data) {
  32530. var pdfInfo = data.pdfInfo;
  32531. this.numPages = data.pdfInfo.numPages;
  32532. var loadingTask = this.loadingTask;
  32533. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  32534. this.pdfDocument = pdfDocument;
  32535. loadingTask._capability.resolve(pdfDocument);
  32536. }, this);
  32537. messageHandler.on('NeedPassword',
  32538. function transportNeedPassword(exception) {
  32539. var loadingTask = this.loadingTask;
  32540. if (loadingTask.onPassword) {
  32541. return loadingTask.onPassword(updatePassword,
  32542. PasswordResponses.NEED_PASSWORD);
  32543. }
  32544. loadingTask._capability.reject(
  32545. new PasswordException(exception.message, exception.code));
  32546. }, this);
  32547. messageHandler.on('IncorrectPassword',
  32548. function transportIncorrectPassword(exception) {
  32549. var loadingTask = this.loadingTask;
  32550. if (loadingTask.onPassword) {
  32551. return loadingTask.onPassword(updatePassword,
  32552. PasswordResponses.INCORRECT_PASSWORD);
  32553. }
  32554. loadingTask._capability.reject(
  32555. new PasswordException(exception.message, exception.code));
  32556. }, this);
  32557. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  32558. this.loadingTask._capability.reject(
  32559. new InvalidPDFException(exception.message));
  32560. }, this);
  32561. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  32562. this.loadingTask._capability.reject(
  32563. new MissingPDFException(exception.message));
  32564. }, this);
  32565. messageHandler.on('UnexpectedResponse',
  32566. function transportUnexpectedResponse(exception) {
  32567. this.loadingTask._capability.reject(
  32568. new UnexpectedResponseException(exception.message, exception.status));
  32569. }, this);
  32570. messageHandler.on('UnknownError',
  32571. function transportUnknownError(exception) {
  32572. this.loadingTask._capability.reject(
  32573. new UnknownErrorException(exception.message, exception.details));
  32574. }, this);
  32575. messageHandler.on('DataLoaded', function transportPage(data) {
  32576. this.downloadInfoCapability.resolve(data);
  32577. }, this);
  32578. messageHandler.on('PDFManagerReady', function transportPage(data) {
  32579. if (this.pdfDataRangeTransport) {
  32580. this.pdfDataRangeTransport.transportReady();
  32581. }
  32582. }, this);
  32583. messageHandler.on('StartRenderPage', function transportRender(data) {
  32584. if (this.destroyed) {
  32585. return; // Ignore any pending requests if the worker was terminated.
  32586. }
  32587. var page = this.pageCache[data.pageIndex];
  32588. page.stats.timeEnd('Page Request');
  32589. page._startRenderPage(data.transparency, data.intent);
  32590. }, this);
  32591. messageHandler.on('RenderPageChunk', function transportRender(data) {
  32592. if (this.destroyed) {
  32593. return; // Ignore any pending requests if the worker was terminated.
  32594. }
  32595. var page = this.pageCache[data.pageIndex];
  32596. page._renderPageChunk(data.operatorList, data.intent);
  32597. }, this);
  32598. messageHandler.on('commonobj', function transportObj(data) {
  32599. if (this.destroyed) {
  32600. return; // Ignore any pending requests if the worker was terminated.
  32601. }
  32602. var id = data[0];
  32603. var type = data[1];
  32604. if (this.commonObjs.hasData(id)) {
  32605. return;
  32606. }
  32607. switch (type) {
  32608. case 'Font':
  32609. var exportedData = data[2];
  32610. var font;
  32611. if ('error' in exportedData) {
  32612. var error = exportedData.error;
  32613. warn('Error during font loading: ' + error);
  32614. this.commonObjs.resolve(id, error);
  32615. break;
  32616. } else {
  32617. font = new FontFaceObject(exportedData);
  32618. }
  32619. this.fontLoader.bind(
  32620. [font],
  32621. function fontReady(fontObjs) {
  32622. this.commonObjs.resolve(id, font);
  32623. }.bind(this)
  32624. );
  32625. break;
  32626. case 'FontPath':
  32627. this.commonObjs.resolve(id, data[2]);
  32628. break;
  32629. default:
  32630. error('Got unknown common object type ' + type);
  32631. }
  32632. }, this);
  32633. messageHandler.on('obj', function transportObj(data) {
  32634. if (this.destroyed) {
  32635. return; // Ignore any pending requests if the worker was terminated.
  32636. }
  32637. var id = data[0];
  32638. var pageIndex = data[1];
  32639. var type = data[2];
  32640. var pageProxy = this.pageCache[pageIndex];
  32641. var imageData;
  32642. if (pageProxy.objs.hasData(id)) {
  32643. return;
  32644. }
  32645. switch (type) {
  32646. case 'JpegStream':
  32647. imageData = data[3];
  32648. loadJpegStream(id, imageData, pageProxy.objs);
  32649. break;
  32650. case 'Image':
  32651. imageData = data[3];
  32652. pageProxy.objs.resolve(id, imageData);
  32653. // heuristics that will allow not to store large data
  32654. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  32655. if (imageData && 'data' in imageData &&
  32656. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  32657. pageProxy.cleanupAfterRender = true;
  32658. }
  32659. break;
  32660. default:
  32661. error('Got unknown object type ' + type);
  32662. }
  32663. }, this);
  32664. messageHandler.on('DocProgress', function transportDocProgress(data) {
  32665. if (this.destroyed) {
  32666. return; // Ignore any pending requests if the worker was terminated.
  32667. }
  32668. var loadingTask = this.loadingTask;
  32669. if (loadingTask.onProgress) {
  32670. loadingTask.onProgress({
  32671. loaded: data.loaded,
  32672. total: data.total
  32673. });
  32674. }
  32675. }, this);
  32676. messageHandler.on('PageError', function transportError(data) {
  32677. if (this.destroyed) {
  32678. return; // Ignore any pending requests if the worker was terminated.
  32679. }
  32680. var page = this.pageCache[data.pageNum - 1];
  32681. var intentState = page.intentStates[data.intent];
  32682. if (intentState.displayReadyCapability) {
  32683. intentState.displayReadyCapability.reject(data.error);
  32684. } else {
  32685. error(data.error);
  32686. }
  32687. }, this);
  32688. messageHandler.on('UnsupportedFeature',
  32689. function transportUnsupportedFeature(data) {
  32690. if (this.destroyed) {
  32691. return; // Ignore any pending requests if the worker was terminated.
  32692. }
  32693. var featureId = data.featureId;
  32694. var loadingTask = this.loadingTask;
  32695. if (loadingTask.onUnsupportedFeature) {
  32696. loadingTask.onUnsupportedFeature(featureId);
  32697. }
  32698. PDFJS.UnsupportedManager.notify(featureId);
  32699. }, this);
  32700. messageHandler.on('JpegDecode', function(data) {
  32701. if (this.destroyed) {
  32702. return Promise.reject('Worker was terminated');
  32703. }
  32704. var imageUrl = data[0];
  32705. var components = data[1];
  32706. if (components !== 3 && components !== 1) {
  32707. return Promise.reject(
  32708. new Error('Only 3 components or 1 component can be returned'));
  32709. }
  32710. return new Promise(function (resolve, reject) {
  32711. var img = new Image();
  32712. img.onload = function () {
  32713. var width = img.width;
  32714. var height = img.height;
  32715. var size = width * height;
  32716. var rgbaLength = size * 4;
  32717. var buf = new Uint8Array(size * components);
  32718. var tmpCanvas = createScratchCanvas(width, height);
  32719. var tmpCtx = tmpCanvas.getContext('2d');
  32720. tmpCtx.drawImage(img, 0, 0);
  32721. var data = tmpCtx.getImageData(0, 0, width, height).data;
  32722. var i, j;
  32723. if (components === 3) {
  32724. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  32725. buf[j] = data[i];
  32726. buf[j + 1] = data[i + 1];
  32727. buf[j + 2] = data[i + 2];
  32728. }
  32729. } else if (components === 1) {
  32730. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  32731. buf[j] = data[i];
  32732. }
  32733. }
  32734. resolve({ data: buf, width: width, height: height});
  32735. };
  32736. img.onerror = function () {
  32737. reject(new Error('JpegDecode failed to load image'));
  32738. };
  32739. img.src = imageUrl;
  32740. });
  32741. }, this);
  32742. },
  32743. getData: function WorkerTransport_getData() {
  32744. return this.messageHandler.sendWithPromise('GetData', null);
  32745. },
  32746. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  32747. if (pageNumber <= 0 || pageNumber > this.numPages ||
  32748. (pageNumber|0) !== pageNumber) {
  32749. return Promise.reject(new Error('Invalid page request'));
  32750. }
  32751. var pageIndex = pageNumber - 1;
  32752. if (pageIndex in this.pagePromises) {
  32753. return this.pagePromises[pageIndex];
  32754. }
  32755. var promise = this.messageHandler.sendWithPromise('GetPage', {
  32756. pageIndex: pageIndex
  32757. }).then(function (pageInfo) {
  32758. if (this.destroyed) {
  32759. throw new Error('Transport destroyed');
  32760. }
  32761. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  32762. this.pageCache[pageIndex] = page;
  32763. return page;
  32764. }.bind(this));
  32765. this.pagePromises[pageIndex] = promise;
  32766. return promise;
  32767. },
  32768. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  32769. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  32770. },
  32771. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  32772. return this.messageHandler.sendWithPromise('GetAnnotations', {
  32773. pageIndex: pageIndex,
  32774. intent: intent,
  32775. });
  32776. },
  32777. getDestinations: function WorkerTransport_getDestinations() {
  32778. return this.messageHandler.sendWithPromise('GetDestinations', null);
  32779. },
  32780. getDestination: function WorkerTransport_getDestination(id) {
  32781. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  32782. },
  32783. getPageLabels: function WorkerTransport_getPageLabels() {
  32784. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  32785. },
  32786. getAttachments: function WorkerTransport_getAttachments() {
  32787. return this.messageHandler.sendWithPromise('GetAttachments', null);
  32788. },
  32789. getJavaScript: function WorkerTransport_getJavaScript() {
  32790. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  32791. },
  32792. getOutline: function WorkerTransport_getOutline() {
  32793. return this.messageHandler.sendWithPromise('GetOutline', null);
  32794. },
  32795. getMetadata: function WorkerTransport_getMetadata() {
  32796. return this.messageHandler.sendWithPromise('GetMetadata', null).
  32797. then(function transportMetadata(results) {
  32798. return {
  32799. info: results[0],
  32800. metadata: (results[1] ? new Metadata(results[1]) : null)
  32801. };
  32802. });
  32803. },
  32804. getStats: function WorkerTransport_getStats() {
  32805. return this.messageHandler.sendWithPromise('GetStats', null);
  32806. },
  32807. startCleanup: function WorkerTransport_startCleanup() {
  32808. this.messageHandler.sendWithPromise('Cleanup', null).
  32809. then(function endCleanup() {
  32810. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  32811. var page = this.pageCache[i];
  32812. if (page) {
  32813. page.cleanup();
  32814. }
  32815. }
  32816. this.commonObjs.clear();
  32817. this.fontLoader.clear();
  32818. }.bind(this));
  32819. }
  32820. };
  32821. return WorkerTransport;
  32822. })();
  32823. /**
  32824. * A PDF document and page is built of many objects. E.g. there are objects
  32825. * for fonts, images, rendering code and such. These objects might get processed
  32826. * inside of a worker. The `PDFObjects` implements some basic functions to
  32827. * manage these objects.
  32828. * @ignore
  32829. */
  32830. var PDFObjects = (function PDFObjectsClosure() {
  32831. function PDFObjects() {
  32832. this.objs = Object.create(null);
  32833. }
  32834. PDFObjects.prototype = {
  32835. /**
  32836. * Internal function.
  32837. * Ensures there is an object defined for `objId`.
  32838. */
  32839. ensureObj: function PDFObjects_ensureObj(objId) {
  32840. if (this.objs[objId]) {
  32841. return this.objs[objId];
  32842. }
  32843. var obj = {
  32844. capability: createPromiseCapability(),
  32845. data: null,
  32846. resolved: false
  32847. };
  32848. this.objs[objId] = obj;
  32849. return obj;
  32850. },
  32851. /**
  32852. * If called *without* callback, this returns the data of `objId` but the
  32853. * object needs to be resolved. If it isn't, this function throws.
  32854. *
  32855. * If called *with* a callback, the callback is called with the data of the
  32856. * object once the object is resolved. That means, if you call this
  32857. * function and the object is already resolved, the callback gets called
  32858. * right away.
  32859. */
  32860. get: function PDFObjects_get(objId, callback) {
  32861. // If there is a callback, then the get can be async and the object is
  32862. // not required to be resolved right now
  32863. if (callback) {
  32864. this.ensureObj(objId).capability.promise.then(callback);
  32865. return null;
  32866. }
  32867. // If there isn't a callback, the user expects to get the resolved data
  32868. // directly.
  32869. var obj = this.objs[objId];
  32870. // If there isn't an object yet or the object isn't resolved, then the
  32871. // data isn't ready yet!
  32872. if (!obj || !obj.resolved) {
  32873. error('Requesting object that isn\'t resolved yet ' + objId);
  32874. }
  32875. return obj.data;
  32876. },
  32877. /**
  32878. * Resolves the object `objId` with optional `data`.
  32879. */
  32880. resolve: function PDFObjects_resolve(objId, data) {
  32881. var obj = this.ensureObj(objId);
  32882. obj.resolved = true;
  32883. obj.data = data;
  32884. obj.capability.resolve(data);
  32885. },
  32886. isResolved: function PDFObjects_isResolved(objId) {
  32887. var objs = this.objs;
  32888. if (!objs[objId]) {
  32889. return false;
  32890. } else {
  32891. return objs[objId].resolved;
  32892. }
  32893. },
  32894. hasData: function PDFObjects_hasData(objId) {
  32895. return this.isResolved(objId);
  32896. },
  32897. /**
  32898. * Returns the data of `objId` if object exists, null otherwise.
  32899. */
  32900. getData: function PDFObjects_getData(objId) {
  32901. var objs = this.objs;
  32902. if (!objs[objId] || !objs[objId].resolved) {
  32903. return null;
  32904. } else {
  32905. return objs[objId].data;
  32906. }
  32907. },
  32908. clear: function PDFObjects_clear() {
  32909. this.objs = Object.create(null);
  32910. }
  32911. };
  32912. return PDFObjects;
  32913. })();
  32914. /**
  32915. * Allows controlling of the rendering tasks.
  32916. * @class
  32917. * @alias RenderTask
  32918. */
  32919. var RenderTask = (function RenderTaskClosure() {
  32920. function RenderTask(internalRenderTask) {
  32921. this._internalRenderTask = internalRenderTask;
  32922. /**
  32923. * Callback for incremental rendering -- a function that will be called
  32924. * each time the rendering is paused. To continue rendering call the
  32925. * function that is the first argument to the callback.
  32926. * @type {function}
  32927. */
  32928. this.onContinue = null;
  32929. }
  32930. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  32931. /**
  32932. * Promise for rendering task completion.
  32933. * @return {Promise}
  32934. */
  32935. get promise() {
  32936. return this._internalRenderTask.capability.promise;
  32937. },
  32938. /**
  32939. * Cancels the rendering task. If the task is currently rendering it will
  32940. * not be cancelled until graphics pauses with a timeout. The promise that
  32941. * this object extends will resolved when cancelled.
  32942. */
  32943. cancel: function RenderTask_cancel() {
  32944. this._internalRenderTask.cancel();
  32945. },
  32946. /**
  32947. * Registers callbacks to indicate the rendering task completion.
  32948. *
  32949. * @param {function} onFulfilled The callback for the rendering completion.
  32950. * @param {function} onRejected The callback for the rendering failure.
  32951. * @return {Promise} A promise that is resolved after the onFulfilled or
  32952. * onRejected callback.
  32953. */
  32954. then: function RenderTask_then(onFulfilled, onRejected) {
  32955. return this.promise.then.apply(this.promise, arguments);
  32956. }
  32957. };
  32958. return RenderTask;
  32959. })();
  32960. /**
  32961. * For internal use only.
  32962. * @ignore
  32963. */
  32964. var InternalRenderTask = (function InternalRenderTaskClosure() {
  32965. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  32966. pageNumber) {
  32967. this.callback = callback;
  32968. this.params = params;
  32969. this.objs = objs;
  32970. this.commonObjs = commonObjs;
  32971. this.operatorListIdx = null;
  32972. this.operatorList = operatorList;
  32973. this.pageNumber = pageNumber;
  32974. this.running = false;
  32975. this.graphicsReadyCallback = null;
  32976. this.graphicsReady = false;
  32977. this.useRequestAnimationFrame = false;
  32978. this.cancelled = false;
  32979. this.capability = createPromiseCapability();
  32980. this.task = new RenderTask(this);
  32981. // caching this-bound methods
  32982. this._continueBound = this._continue.bind(this);
  32983. this._scheduleNextBound = this._scheduleNext.bind(this);
  32984. this._nextBound = this._next.bind(this);
  32985. }
  32986. InternalRenderTask.prototype = {
  32987. initalizeGraphics:
  32988. function InternalRenderTask_initalizeGraphics(transparency) {
  32989. if (this.cancelled) {
  32990. return;
  32991. }
  32992. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  32993. globalScope.StepperManager.enabled) {
  32994. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  32995. this.stepper.init(this.operatorList);
  32996. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  32997. }
  32998. var params = this.params;
  32999. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  33000. this.objs, params.imageLayer);
  33001. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  33002. this.operatorListIdx = 0;
  33003. this.graphicsReady = true;
  33004. if (this.graphicsReadyCallback) {
  33005. this.graphicsReadyCallback();
  33006. }
  33007. },
  33008. cancel: function InternalRenderTask_cancel() {
  33009. this.running = false;
  33010. this.cancelled = true;
  33011. this.callback('cancelled');
  33012. },
  33013. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  33014. if (!this.graphicsReady) {
  33015. if (!this.graphicsReadyCallback) {
  33016. this.graphicsReadyCallback = this._continueBound;
  33017. }
  33018. return;
  33019. }
  33020. if (this.stepper) {
  33021. this.stepper.updateOperatorList(this.operatorList);
  33022. }
  33023. if (this.running) {
  33024. return;
  33025. }
  33026. this._continue();
  33027. },
  33028. _continue: function InternalRenderTask__continue() {
  33029. this.running = true;
  33030. if (this.cancelled) {
  33031. return;
  33032. }
  33033. if (this.task.onContinue) {
  33034. this.task.onContinue.call(this.task, this._scheduleNextBound);
  33035. } else {
  33036. this._scheduleNext();
  33037. }
  33038. },
  33039. _scheduleNext: function InternalRenderTask__scheduleNext() {
  33040. if (this.useRequestAnimationFrame) {
  33041. window.requestAnimationFrame(this._nextBound);
  33042. } else {
  33043. Promise.resolve(undefined).then(this._nextBound);
  33044. }
  33045. },
  33046. _next: function InternalRenderTask__next() {
  33047. if (this.cancelled) {
  33048. return;
  33049. }
  33050. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  33051. this.operatorListIdx,
  33052. this._continueBound,
  33053. this.stepper);
  33054. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  33055. this.running = false;
  33056. if (this.operatorList.lastChunk) {
  33057. this.gfx.endDrawing();
  33058. this.callback();
  33059. }
  33060. }
  33061. }
  33062. };
  33063. return InternalRenderTask;
  33064. })();
  33065. /**
  33066. * (Deprecated) Global observer of unsupported feature usages. Use
  33067. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  33068. */
  33069. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  33070. var listeners = [];
  33071. return {
  33072. listen: function (cb) {
  33073. deprecated('Global UnsupportedManager.listen is used: ' +
  33074. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  33075. listeners.push(cb);
  33076. },
  33077. notify: function (featureId) {
  33078. for (var i = 0, ii = listeners.length; i < ii; i++) {
  33079. listeners[i](featureId);
  33080. }
  33081. }
  33082. };
  33083. })();
  33084. exports.getDocument = PDFJS.getDocument;
  33085. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  33086. exports.PDFDocumentProxy = PDFDocumentProxy;
  33087. exports.PDFPageProxy = PDFPageProxy;
  33088. }));
  33089. (function (root, factory) {
  33090. {
  33091. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  33092. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  33093. root.pdfjsCoreCMap, root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  33094. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  33095. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode);
  33096. }
  33097. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  33098. coreCMap, coreGlyphList, coreCharsets, coreFontRenderer,
  33099. coreEncodings, coreStandardFonts, coreUnicode) {
  33100. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  33101. var FontType = sharedUtil.FontType;
  33102. var Util = sharedUtil.Util;
  33103. var assert = sharedUtil.assert;
  33104. var bytesToString = sharedUtil.bytesToString;
  33105. var error = sharedUtil.error;
  33106. var info = sharedUtil.info;
  33107. var isArray = sharedUtil.isArray;
  33108. var isInt = sharedUtil.isInt;
  33109. var isNum = sharedUtil.isNum;
  33110. var readUint32 = sharedUtil.readUint32;
  33111. var shadow = sharedUtil.shadow;
  33112. var stringToBytes = sharedUtil.stringToBytes;
  33113. var string32 = sharedUtil.string32;
  33114. var warn = sharedUtil.warn;
  33115. var Name = corePrimitives.Name;
  33116. var Stream = coreStream.Stream;
  33117. var Lexer = coreParser.Lexer;
  33118. var CMapFactory = coreCMap.CMapFactory;
  33119. var IdentityCMap = coreCMap.IdentityCMap;
  33120. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  33121. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  33122. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  33123. var ExpertCharset = coreCharsets.ExpertCharset;
  33124. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  33125. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  33126. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  33127. var StandardEncoding = coreEncodings.StandardEncoding;
  33128. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  33129. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  33130. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  33131. var ExpertEncoding = coreEncodings.ExpertEncoding;
  33132. var getEncoding = coreEncodings.getEncoding;
  33133. var getStdFontMap = coreStandardFonts.getStdFontMap;
  33134. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  33135. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  33136. var getSupplementalGlyphMapForArialBlack =
  33137. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  33138. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  33139. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  33140. // Unicode Private Use Area
  33141. var PRIVATE_USE_OFFSET_START = 0xE000;
  33142. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  33143. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  33144. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  33145. // except for Type 3 fonts
  33146. var PDF_GLYPH_SPACE_UNITS = 1000;
  33147. // Hinting is currently disabled due to unknown problems on windows
  33148. // in tracemonkey and various other pdfs with type1 fonts.
  33149. var HINTING_ENABLED = false;
  33150. // Accented charactars are not displayed properly on windows, using this flag
  33151. // to control analysis of seac charstrings.
  33152. var SEAC_ANALYSIS_ENABLED = false;
  33153. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  33154. var MAX_SUBR_NESTING = 10;
  33155. var FontFlags = {
  33156. FixedPitch: 1,
  33157. Serif: 2,
  33158. Symbolic: 4,
  33159. Script: 8,
  33160. Nonsymbolic: 32,
  33161. Italic: 64,
  33162. AllCap: 65536,
  33163. SmallCap: 131072,
  33164. ForceBold: 262144
  33165. };
  33166. var MacStandardGlyphOrdering = [
  33167. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  33168. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  33169. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  33170. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  33171. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  33172. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  33173. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  33174. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  33175. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  33176. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  33177. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  33178. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  33179. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  33180. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  33181. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  33182. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  33183. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  33184. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  33185. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  33186. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  33187. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  33188. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  33189. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  33190. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  33191. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  33192. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  33193. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  33194. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  33195. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  33196. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  33197. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  33198. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  33199. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  33200. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  33201. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  33202. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  33203. function adjustWidths(properties) {
  33204. if (!properties.fontMatrix) {
  33205. return;
  33206. }
  33207. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  33208. return;
  33209. }
  33210. // adjusting width to fontMatrix scale
  33211. var scale = 0.001 / properties.fontMatrix[0];
  33212. var glyphsWidths = properties.widths;
  33213. for (var glyph in glyphsWidths) {
  33214. glyphsWidths[glyph] *= scale;
  33215. }
  33216. properties.defaultWidth *= scale;
  33217. }
  33218. function getFontType(type, subtype) {
  33219. switch (type) {
  33220. case 'Type1':
  33221. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  33222. case 'CIDFontType0':
  33223. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  33224. FontType.CIDFONTTYPE0;
  33225. case 'OpenType':
  33226. return FontType.OPENTYPE;
  33227. case 'TrueType':
  33228. return FontType.TRUETYPE;
  33229. case 'CIDFontType2':
  33230. return FontType.CIDFONTTYPE2;
  33231. case 'MMType1':
  33232. return FontType.MMTYPE1;
  33233. case 'Type0':
  33234. return FontType.TYPE0;
  33235. default:
  33236. return FontType.UNKNOWN;
  33237. }
  33238. }
  33239. var Glyph = (function GlyphClosure() {
  33240. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  33241. isSpace) {
  33242. this.fontChar = fontChar;
  33243. this.unicode = unicode;
  33244. this.accent = accent;
  33245. this.width = width;
  33246. this.vmetric = vmetric;
  33247. this.operatorListId = operatorListId;
  33248. this.isSpace = isSpace;
  33249. }
  33250. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  33251. vmetric, operatorListId, isSpace) {
  33252. return this.fontChar === fontChar &&
  33253. this.unicode === unicode &&
  33254. this.accent === accent &&
  33255. this.width === width &&
  33256. this.vmetric === vmetric &&
  33257. this.operatorListId === operatorListId &&
  33258. this.isSpace === isSpace;
  33259. };
  33260. return Glyph;
  33261. })();
  33262. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  33263. function ToUnicodeMap(cmap) {
  33264. // The elements of this._map can be integers or strings, depending on how
  33265. // |cmap| was created.
  33266. this._map = cmap;
  33267. }
  33268. ToUnicodeMap.prototype = {
  33269. get length() {
  33270. return this._map.length;
  33271. },
  33272. forEach: function(callback) {
  33273. for (var charCode in this._map) {
  33274. callback(charCode, this._map[charCode].charCodeAt(0));
  33275. }
  33276. },
  33277. has: function(i) {
  33278. return this._map[i] !== undefined;
  33279. },
  33280. get: function(i) {
  33281. return this._map[i];
  33282. },
  33283. charCodeOf: function(v) {
  33284. return this._map.indexOf(v);
  33285. }
  33286. };
  33287. return ToUnicodeMap;
  33288. })();
  33289. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  33290. function IdentityToUnicodeMap(firstChar, lastChar) {
  33291. this.firstChar = firstChar;
  33292. this.lastChar = lastChar;
  33293. }
  33294. IdentityToUnicodeMap.prototype = {
  33295. get length() {
  33296. return (this.lastChar + 1) - this.firstChar;
  33297. },
  33298. forEach: function (callback) {
  33299. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  33300. callback(i, i);
  33301. }
  33302. },
  33303. has: function (i) {
  33304. return this.firstChar <= i && i <= this.lastChar;
  33305. },
  33306. get: function (i) {
  33307. if (this.firstChar <= i && i <= this.lastChar) {
  33308. return String.fromCharCode(i);
  33309. }
  33310. return undefined;
  33311. },
  33312. charCodeOf: function (v) {
  33313. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  33314. }
  33315. };
  33316. return IdentityToUnicodeMap;
  33317. })();
  33318. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  33319. function writeInt16(dest, offset, num) {
  33320. dest[offset] = (num >> 8) & 0xFF;
  33321. dest[offset + 1] = num & 0xFF;
  33322. }
  33323. function writeInt32(dest, offset, num) {
  33324. dest[offset] = (num >> 24) & 0xFF;
  33325. dest[offset + 1] = (num >> 16) & 0xFF;
  33326. dest[offset + 2] = (num >> 8) & 0xFF;
  33327. dest[offset + 3] = num & 0xFF;
  33328. }
  33329. function writeData(dest, offset, data) {
  33330. var i, ii;
  33331. if (data instanceof Uint8Array) {
  33332. dest.set(data, offset);
  33333. } else if (typeof data === 'string') {
  33334. for (i = 0, ii = data.length; i < ii; i++) {
  33335. dest[offset++] = data.charCodeAt(i) & 0xFF;
  33336. }
  33337. } else {
  33338. // treating everything else as array
  33339. for (i = 0, ii = data.length; i < ii; i++) {
  33340. dest[offset++] = data[i] & 0xFF;
  33341. }
  33342. }
  33343. }
  33344. function OpenTypeFileBuilder(sfnt) {
  33345. this.sfnt = sfnt;
  33346. this.tables = Object.create(null);
  33347. }
  33348. OpenTypeFileBuilder.getSearchParams =
  33349. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  33350. var maxPower2 = 1, log2 = 0;
  33351. while ((maxPower2 ^ entriesCount) > maxPower2) {
  33352. maxPower2 <<= 1;
  33353. log2++;
  33354. }
  33355. var searchRange = maxPower2 * entrySize;
  33356. return {
  33357. range: searchRange,
  33358. entry: log2,
  33359. rangeShift: entrySize * entriesCount - searchRange
  33360. };
  33361. };
  33362. var OTF_HEADER_SIZE = 12;
  33363. var OTF_TABLE_ENTRY_SIZE = 16;
  33364. OpenTypeFileBuilder.prototype = {
  33365. toArray: function OpenTypeFileBuilder_toArray() {
  33366. var sfnt = this.sfnt;
  33367. // Tables needs to be written by ascendant alphabetic order
  33368. var tables = this.tables;
  33369. var tablesNames = Object.keys(tables);
  33370. tablesNames.sort();
  33371. var numTables = tablesNames.length;
  33372. var i, j, jj, table, tableName;
  33373. // layout the tables data
  33374. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  33375. var tableOffsets = [offset];
  33376. for (i = 0; i < numTables; i++) {
  33377. table = tables[tablesNames[i]];
  33378. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  33379. offset += paddedLength;
  33380. tableOffsets.push(offset);
  33381. }
  33382. var file = new Uint8Array(offset);
  33383. // write the table data first (mostly for checksum)
  33384. for (i = 0; i < numTables; i++) {
  33385. table = tables[tablesNames[i]];
  33386. writeData(file, tableOffsets[i], table);
  33387. }
  33388. // sfnt version (4 bytes)
  33389. if (sfnt === 'true') {
  33390. // Windows hates the Mac TrueType sfnt version number
  33391. sfnt = string32(0x00010000);
  33392. }
  33393. file[0] = sfnt.charCodeAt(0) & 0xFF;
  33394. file[1] = sfnt.charCodeAt(1) & 0xFF;
  33395. file[2] = sfnt.charCodeAt(2) & 0xFF;
  33396. file[3] = sfnt.charCodeAt(3) & 0xFF;
  33397. // numTables (2 bytes)
  33398. writeInt16(file, 4, numTables);
  33399. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  33400. // searchRange (2 bytes)
  33401. writeInt16(file, 6, searchParams.range);
  33402. // entrySelector (2 bytes)
  33403. writeInt16(file, 8, searchParams.entry);
  33404. // rangeShift (2 bytes)
  33405. writeInt16(file, 10, searchParams.rangeShift);
  33406. offset = OTF_HEADER_SIZE;
  33407. // writing table entries
  33408. for (i = 0; i < numTables; i++) {
  33409. tableName = tablesNames[i];
  33410. file[offset] = tableName.charCodeAt(0) & 0xFF;
  33411. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  33412. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  33413. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  33414. // checksum
  33415. var checksum = 0;
  33416. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  33417. var quad = (file[j] << 24) + (file[j + 1] << 16) +
  33418. (file[j + 2] << 8) + file[j + 3];
  33419. checksum = (checksum + quad) | 0;
  33420. }
  33421. writeInt32(file, offset + 4, checksum);
  33422. // offset
  33423. writeInt32(file, offset + 8, tableOffsets[i]);
  33424. // length
  33425. writeInt32(file, offset + 12, tables[tableName].length);
  33426. offset += OTF_TABLE_ENTRY_SIZE;
  33427. }
  33428. return file;
  33429. },
  33430. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  33431. if (tag in this.tables) {
  33432. throw new Error('Table ' + tag + ' already exists');
  33433. }
  33434. this.tables[tag] = data;
  33435. }
  33436. };
  33437. return OpenTypeFileBuilder;
  33438. })();
  33439. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  33440. // issues when they are painted on the canvas, e.g. complex-script shaping or
  33441. // control/whitespace characters. The ranges are listed in pairs: the first item
  33442. // is a code of the first problematic code, the second one is the next
  33443. // non-problematic code. The ranges must be in sorted order.
  33444. var ProblematicCharRanges = new Int32Array([
  33445. // Control characters.
  33446. 0x0000, 0x0020,
  33447. 0x007F, 0x00A1,
  33448. 0x00AD, 0x00AE,
  33449. // Chars that is used in complex-script shaping.
  33450. 0x0600, 0x0780,
  33451. 0x08A0, 0x10A0,
  33452. 0x1780, 0x1800,
  33453. // General punctuation chars.
  33454. 0x2000, 0x2010,
  33455. 0x2011, 0x2012,
  33456. 0x2028, 0x2030,
  33457. 0x205F, 0x2070,
  33458. 0x25CC, 0x25CD,
  33459. // Chars that is used in complex-script shaping.
  33460. 0xAA60, 0xAA80,
  33461. // Specials Unicode block.
  33462. 0xFFF0, 0x10000
  33463. ]);
  33464. /**
  33465. * 'Font' is the class the outside world should use, it encapsulate all the font
  33466. * decoding logics whatever type it is (assuming the font type is supported).
  33467. *
  33468. * For example to read a Type1 font and to attach it to the document:
  33469. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  33470. * type1Font.bind();
  33471. */
  33472. var Font = (function FontClosure() {
  33473. function Font(name, file, properties) {
  33474. var charCode, glyphName, fontChar;
  33475. this.name = name;
  33476. this.loadedName = properties.loadedName;
  33477. this.isType3Font = properties.isType3Font;
  33478. this.sizes = [];
  33479. this.glyphCache = Object.create(null);
  33480. var names = name.split('+');
  33481. names = names.length > 1 ? names[1] : names[0];
  33482. names = names.split(/[-,_]/g)[0];
  33483. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  33484. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  33485. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  33486. var type = properties.type;
  33487. var subtype = properties.subtype;
  33488. this.type = type;
  33489. this.fallbackName = (this.isMonospace ? 'monospace' :
  33490. (this.isSerifFont ? 'serif' : 'sans-serif'));
  33491. this.differences = properties.differences;
  33492. this.widths = properties.widths;
  33493. this.defaultWidth = properties.defaultWidth;
  33494. this.composite = properties.composite;
  33495. this.wideChars = properties.wideChars;
  33496. this.cMap = properties.cMap;
  33497. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  33498. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  33499. this.fontMatrix = properties.fontMatrix;
  33500. this.bbox = properties.bbox;
  33501. this.toUnicode = properties.toUnicode = this.buildToUnicode(properties);
  33502. this.toFontChar = [];
  33503. if (properties.type === 'Type3') {
  33504. for (charCode = 0; charCode < 256; charCode++) {
  33505. this.toFontChar[charCode] = (this.differences[charCode] ||
  33506. properties.defaultEncoding[charCode]);
  33507. }
  33508. this.fontType = FontType.TYPE3;
  33509. return;
  33510. }
  33511. this.cidEncoding = properties.cidEncoding;
  33512. this.vertical = properties.vertical;
  33513. if (this.vertical) {
  33514. this.vmetrics = properties.vmetrics;
  33515. this.defaultVMetrics = properties.defaultVMetrics;
  33516. }
  33517. var glyphsUnicodeMap;
  33518. if (!file || file.isEmpty) {
  33519. if (file) {
  33520. // Some bad PDF generators will include empty font files,
  33521. // attempting to recover by assuming that no file exists.
  33522. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  33523. }
  33524. this.missingFile = true;
  33525. // The file data is not specified. Trying to fix the font name
  33526. // to be used with the canvas.font.
  33527. var fontName = name.replace(/[,_]/g, '-');
  33528. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  33529. var isStandardFont = !!stdFontMap[fontName] ||
  33530. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  33531. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  33532. this.bold = (fontName.search(/bold/gi) !== -1);
  33533. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  33534. (fontName.search(/italic/gi) !== -1));
  33535. // Use 'name' instead of 'fontName' here because the original
  33536. // name ArialBlack for example will be replaced by Helvetica.
  33537. this.black = (name.search(/Black/g) !== -1);
  33538. // if at least one width is present, remeasure all chars when exists
  33539. this.remeasure = Object.keys(this.widths).length > 0;
  33540. if (isStandardFont && type === 'CIDFontType2' &&
  33541. properties.cidEncoding.indexOf('Identity-') === 0) {
  33542. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  33543. // Standard fonts might be embedded as CID font without glyph mapping.
  33544. // Building one based on GlyphMapForStandardFonts.
  33545. var map = [];
  33546. for (charCode in GlyphMapForStandardFonts) {
  33547. map[+charCode] = GlyphMapForStandardFonts[charCode];
  33548. }
  33549. if (/ArialBlack/i.test(name)) {
  33550. var SupplementalGlyphMapForArialBlack =
  33551. getSupplementalGlyphMapForArialBlack();
  33552. for (charCode in SupplementalGlyphMapForArialBlack) {
  33553. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  33554. }
  33555. }
  33556. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  33557. if (!isIdentityUnicode) {
  33558. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  33559. map[+charCode] = unicodeCharCode;
  33560. });
  33561. }
  33562. this.toFontChar = map;
  33563. this.toUnicode = new ToUnicodeMap(map);
  33564. } else if (/Symbol/i.test(fontName)) {
  33565. var symbols = SymbolSetEncoding;
  33566. glyphsUnicodeMap = getGlyphsUnicode();
  33567. for (charCode in symbols) {
  33568. fontChar = glyphsUnicodeMap[symbols[charCode]];
  33569. if (!fontChar) {
  33570. continue;
  33571. }
  33572. this.toFontChar[charCode] = fontChar;
  33573. }
  33574. for (charCode in properties.differences) {
  33575. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  33576. if (!fontChar) {
  33577. continue;
  33578. }
  33579. this.toFontChar[charCode] = fontChar;
  33580. }
  33581. } else if (/Dingbats/i.test(fontName)) {
  33582. glyphsUnicodeMap = getDingbatsGlyphsUnicode();
  33583. if (/Wingdings/i.test(name)) {
  33584. warn('Wingdings font without embedded font file, ' +
  33585. 'falling back to the ZapfDingbats encoding.');
  33586. }
  33587. var dingbats = ZapfDingbatsEncoding;
  33588. for (charCode in dingbats) {
  33589. fontChar = glyphsUnicodeMap[dingbats[charCode]];
  33590. if (!fontChar) {
  33591. continue;
  33592. }
  33593. this.toFontChar[charCode] = fontChar;
  33594. }
  33595. for (charCode in properties.differences) {
  33596. fontChar = glyphsUnicodeMap[properties.differences[charCode]];
  33597. if (!fontChar) {
  33598. continue;
  33599. }
  33600. this.toFontChar[charCode] = fontChar;
  33601. }
  33602. } else if (isStandardFont) {
  33603. this.toFontChar = [];
  33604. glyphsUnicodeMap = getGlyphsUnicode();
  33605. for (charCode in properties.defaultEncoding) {
  33606. glyphName = (properties.differences[charCode] ||
  33607. properties.defaultEncoding[charCode]);
  33608. this.toFontChar[charCode] = glyphsUnicodeMap[glyphName];
  33609. }
  33610. } else {
  33611. var unicodeCharCode, notCidFont = (type.indexOf('CIDFontType') === -1);
  33612. glyphsUnicodeMap = getGlyphsUnicode();
  33613. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  33614. if (notCidFont) {
  33615. glyphName = (properties.differences[charCode] ||
  33616. properties.defaultEncoding[charCode]);
  33617. unicodeCharCode = (glyphsUnicodeMap[glyphName] || unicodeCharCode);
  33618. }
  33619. this.toFontChar[charCode] = unicodeCharCode;
  33620. }.bind(this));
  33621. }
  33622. this.loadedName = fontName.split('-')[0];
  33623. this.loading = false;
  33624. this.fontType = getFontType(type, subtype);
  33625. return;
  33626. }
  33627. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  33628. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  33629. // Some TrueType fonts by mistake claim Type1C
  33630. if (isTrueTypeFile(file)) {
  33631. subtype = 'TrueType';
  33632. } else {
  33633. type = 'Type1';
  33634. }
  33635. }
  33636. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  33637. type = 'CIDFontType0';
  33638. }
  33639. if (subtype === 'OpenType') {
  33640. type = 'OpenType';
  33641. }
  33642. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  33643. if (type === 'CIDFontType0') {
  33644. if (isType1File(file)) {
  33645. subtype = 'CIDFontType0';
  33646. } else if (isOpenTypeFile(file)) {
  33647. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  33648. type = subtype = 'OpenType';
  33649. } else {
  33650. subtype = 'CIDFontType0C';
  33651. }
  33652. }
  33653. var data;
  33654. switch (type) {
  33655. case 'MMType1':
  33656. info('MMType1 font (' + name + '), falling back to Type1.');
  33657. /* falls through */
  33658. case 'Type1':
  33659. case 'CIDFontType0':
  33660. this.mimetype = 'font/opentype';
  33661. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  33662. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  33663. adjustWidths(properties);
  33664. // Wrap the CFF data inside an OTF font file
  33665. data = this.convert(name, cff, properties);
  33666. break;
  33667. case 'OpenType':
  33668. case 'TrueType':
  33669. case 'CIDFontType2':
  33670. this.mimetype = 'font/opentype';
  33671. // Repair the TrueType file. It is can be damaged in the point of
  33672. // view of the sanitizer
  33673. data = this.checkAndRepair(name, file, properties);
  33674. if (this.isOpenType) {
  33675. adjustWidths(properties);
  33676. type = 'OpenType';
  33677. }
  33678. break;
  33679. default:
  33680. error('Font ' + type + ' is not supported');
  33681. break;
  33682. }
  33683. this.data = data;
  33684. this.fontType = getFontType(type, subtype);
  33685. // Transfer some properties again that could change during font conversion
  33686. this.fontMatrix = properties.fontMatrix;
  33687. this.widths = properties.widths;
  33688. this.defaultWidth = properties.defaultWidth;
  33689. this.encoding = properties.baseEncoding;
  33690. this.seacMap = properties.seacMap;
  33691. this.loading = true;
  33692. }
  33693. Font.getFontID = (function () {
  33694. var ID = 1;
  33695. return function Font_getFontID() {
  33696. return String(ID++);
  33697. };
  33698. })();
  33699. function int16(b0, b1) {
  33700. return (b0 << 8) + b1;
  33701. }
  33702. function int32(b0, b1, b2, b3) {
  33703. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  33704. }
  33705. function string16(value) {
  33706. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  33707. }
  33708. function safeString16(value) {
  33709. // clamp value to the 16-bit int range
  33710. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  33711. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  33712. }
  33713. function isTrueTypeFile(file) {
  33714. var header = file.peekBytes(4);
  33715. return readUint32(header, 0) === 0x00010000;
  33716. }
  33717. function isOpenTypeFile(file) {
  33718. var header = file.peekBytes(4);
  33719. return bytesToString(header) === 'OTTO';
  33720. }
  33721. function isType1File(file) {
  33722. var header = file.peekBytes(2);
  33723. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  33724. if (header[0] === 0x25 && header[1] === 0x21) {
  33725. return true;
  33726. }
  33727. // ... obviously some fonts violate that part of the specification,
  33728. // please refer to the comment in |Type1Font| below.
  33729. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  33730. return true;
  33731. }
  33732. return false;
  33733. }
  33734. /**
  33735. * Helper function for |adjustMapping|.
  33736. * @return {boolean}
  33737. */
  33738. function isProblematicUnicodeLocation(code) {
  33739. // Using binary search to find a range start.
  33740. var i = 0, j = ProblematicCharRanges.length - 1;
  33741. while (i < j) {
  33742. var c = (i + j + 1) >> 1;
  33743. if (code < ProblematicCharRanges[c]) {
  33744. j = c - 1;
  33745. } else {
  33746. i = c;
  33747. }
  33748. }
  33749. // Even index means code in problematic range.
  33750. return !(i & 1);
  33751. }
  33752. /**
  33753. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  33754. * with their unicode value. It also moves char codes that are in known
  33755. * problematic locations.
  33756. * @return {Object} Two properties:
  33757. * 'toFontChar' - maps original char codes(the value that will be read
  33758. * from commands such as show text) to the char codes that will be used in the
  33759. * font that we build
  33760. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  33761. */
  33762. function adjustMapping(charCodeToGlyphId, properties) {
  33763. var toUnicode = properties.toUnicode;
  33764. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  33765. var isIdentityUnicode =
  33766. properties.toUnicode instanceof IdentityToUnicodeMap;
  33767. var newMap = Object.create(null);
  33768. var toFontChar = [];
  33769. var usedFontCharCodes = [];
  33770. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  33771. for (var originalCharCode in charCodeToGlyphId) {
  33772. originalCharCode |= 0;
  33773. var glyphId = charCodeToGlyphId[originalCharCode];
  33774. var fontCharCode = originalCharCode;
  33775. // First try to map the value to a unicode position if a non identity map
  33776. // was created.
  33777. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  33778. var unicode = toUnicode.get(fontCharCode);
  33779. // TODO: Try to map ligatures to the correct spot.
  33780. if (unicode.length === 1) {
  33781. fontCharCode = unicode.charCodeAt(0);
  33782. }
  33783. }
  33784. // Try to move control characters, special characters and already mapped
  33785. // characters to the private use area since they will not be drawn by
  33786. // canvas if left in their current position. Also, move characters if the
  33787. // font was symbolic and there is only an identity unicode map since the
  33788. // characters probably aren't in the correct position (fixes an issue
  33789. // with firefox and thuluthfont).
  33790. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  33791. isProblematicUnicodeLocation(fontCharCode) ||
  33792. (isSymbolic && isIdentityUnicode)) &&
  33793. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  33794. // Loop to try and find a free spot in the private use area.
  33795. do {
  33796. fontCharCode = nextAvailableFontCharCode++;
  33797. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  33798. fontCharCode = 0xF020;
  33799. nextAvailableFontCharCode = fontCharCode + 1;
  33800. }
  33801. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  33802. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  33803. }
  33804. newMap[fontCharCode] = glyphId;
  33805. toFontChar[originalCharCode] = fontCharCode;
  33806. usedFontCharCodes[fontCharCode] = true;
  33807. }
  33808. return {
  33809. toFontChar: toFontChar,
  33810. charCodeToGlyphId: newMap,
  33811. nextAvailableFontCharCode: nextAvailableFontCharCode
  33812. };
  33813. }
  33814. function getRanges(glyphs, numGlyphs) {
  33815. // Array.sort() sorts by characters, not numerically, so convert to an
  33816. // array of characters.
  33817. var codes = [];
  33818. for (var charCode in glyphs) {
  33819. // Remove an invalid glyph ID mappings to make OTS happy.
  33820. if (glyphs[charCode] >= numGlyphs) {
  33821. continue;
  33822. }
  33823. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  33824. }
  33825. codes.sort(function fontGetRangesSort(a, b) {
  33826. return a.fontCharCode - b.fontCharCode;
  33827. });
  33828. // Split the sorted codes into ranges.
  33829. var ranges = [];
  33830. var length = codes.length;
  33831. for (var n = 0; n < length; ) {
  33832. var start = codes[n].fontCharCode;
  33833. var codeIndices = [codes[n].glyphId];
  33834. ++n;
  33835. var end = start;
  33836. while (n < length && end + 1 === codes[n].fontCharCode) {
  33837. codeIndices.push(codes[n].glyphId);
  33838. ++end;
  33839. ++n;
  33840. if (end === 0xFFFF) {
  33841. break;
  33842. }
  33843. }
  33844. ranges.push([start, end, codeIndices]);
  33845. }
  33846. return ranges;
  33847. }
  33848. function createCmapTable(glyphs, numGlyphs) {
  33849. var ranges = getRanges(glyphs, numGlyphs);
  33850. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  33851. var cmap = '\x00\x00' + // version
  33852. string16(numTables) + // numTables
  33853. '\x00\x03' + // platformID
  33854. '\x00\x01' + // encodingID
  33855. string32(4 + numTables * 8); // start of the table record
  33856. var i, ii, j, jj;
  33857. for (i = ranges.length - 1; i >= 0; --i) {
  33858. if (ranges[i][0] <= 0xFFFF) { break; }
  33859. }
  33860. var bmpLength = i + 1;
  33861. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  33862. ranges[i][1] = 0xFFFE;
  33863. }
  33864. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  33865. var segCount = bmpLength + trailingRangesCount;
  33866. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  33867. // Fill up the 4 parallel arrays describing the segments.
  33868. var startCount = '';
  33869. var endCount = '';
  33870. var idDeltas = '';
  33871. var idRangeOffsets = '';
  33872. var glyphsIds = '';
  33873. var bias = 0;
  33874. var range, start, end, codes;
  33875. for (i = 0, ii = bmpLength; i < ii; i++) {
  33876. range = ranges[i];
  33877. start = range[0];
  33878. end = range[1];
  33879. startCount += string16(start);
  33880. endCount += string16(end);
  33881. codes = range[2];
  33882. var contiguous = true;
  33883. for (j = 1, jj = codes.length; j < jj; ++j) {
  33884. if (codes[j] !== codes[j - 1] + 1) {
  33885. contiguous = false;
  33886. break;
  33887. }
  33888. }
  33889. if (!contiguous) {
  33890. var offset = (segCount - i) * 2 + bias * 2;
  33891. bias += (end - start + 1);
  33892. idDeltas += string16(0);
  33893. idRangeOffsets += string16(offset);
  33894. for (j = 0, jj = codes.length; j < jj; ++j) {
  33895. glyphsIds += string16(codes[j]);
  33896. }
  33897. } else {
  33898. var startCode = codes[0];
  33899. idDeltas += string16((startCode - start) & 0xFFFF);
  33900. idRangeOffsets += string16(0);
  33901. }
  33902. }
  33903. if (trailingRangesCount > 0) {
  33904. endCount += '\xFF\xFF';
  33905. startCount += '\xFF\xFF';
  33906. idDeltas += '\x00\x01';
  33907. idRangeOffsets += '\x00\x00';
  33908. }
  33909. var format314 = '\x00\x00' + // language
  33910. string16(2 * segCount) +
  33911. string16(searchParams.range) +
  33912. string16(searchParams.entry) +
  33913. string16(searchParams.rangeShift) +
  33914. endCount + '\x00\x00' + startCount +
  33915. idDeltas + idRangeOffsets + glyphsIds;
  33916. var format31012 = '';
  33917. var header31012 = '';
  33918. if (numTables > 1) {
  33919. cmap += '\x00\x03' + // platformID
  33920. '\x00\x0A' + // encodingID
  33921. string32(4 + numTables * 8 +
  33922. 4 + format314.length); // start of the table record
  33923. format31012 = '';
  33924. for (i = 0, ii = ranges.length; i < ii; i++) {
  33925. range = ranges[i];
  33926. start = range[0];
  33927. codes = range[2];
  33928. var code = codes[0];
  33929. for (j = 1, jj = codes.length; j < jj; ++j) {
  33930. if (codes[j] !== codes[j - 1] + 1) {
  33931. end = range[0] + j - 1;
  33932. format31012 += string32(start) + // startCharCode
  33933. string32(end) + // endCharCode
  33934. string32(code); // startGlyphID
  33935. start = end + 1;
  33936. code = codes[j];
  33937. }
  33938. }
  33939. format31012 += string32(start) + // startCharCode
  33940. string32(range[1]) + // endCharCode
  33941. string32(code); // startGlyphID
  33942. }
  33943. header31012 = '\x00\x0C' + // format
  33944. '\x00\x00' + // reserved
  33945. string32(format31012.length + 16) + // length
  33946. '\x00\x00\x00\x00' + // language
  33947. string32(format31012.length / 12); // nGroups
  33948. }
  33949. return cmap + '\x00\x04' + // format
  33950. string16(format314.length + 4) + // length
  33951. format314 + header31012 + format31012;
  33952. }
  33953. function validateOS2Table(os2) {
  33954. var stream = new Stream(os2.data);
  33955. var version = stream.getUint16();
  33956. // TODO verify all OS/2 tables fields, but currently we validate only those
  33957. // that give us issues
  33958. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  33959. var selection = stream.getUint16();
  33960. if (version < 4 && (selection & 0x0300)) {
  33961. return false;
  33962. }
  33963. var firstChar = stream.getUint16();
  33964. var lastChar = stream.getUint16();
  33965. if (firstChar > lastChar) {
  33966. return false;
  33967. }
  33968. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  33969. var usWinAscent = stream.getUint16();
  33970. if (usWinAscent === 0) { // makes font unreadable by windows
  33971. return false;
  33972. }
  33973. // OS/2 appears to be valid, resetting some fields
  33974. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  33975. return true;
  33976. }
  33977. function createOS2Table(properties, charstrings, override) {
  33978. override = override || {
  33979. unitsPerEm: 0,
  33980. yMax: 0,
  33981. yMin: 0,
  33982. ascent: 0,
  33983. descent: 0
  33984. };
  33985. var ulUnicodeRange1 = 0;
  33986. var ulUnicodeRange2 = 0;
  33987. var ulUnicodeRange3 = 0;
  33988. var ulUnicodeRange4 = 0;
  33989. var firstCharIndex = null;
  33990. var lastCharIndex = 0;
  33991. if (charstrings) {
  33992. for (var code in charstrings) {
  33993. code |= 0;
  33994. if (firstCharIndex > code || !firstCharIndex) {
  33995. firstCharIndex = code;
  33996. }
  33997. if (lastCharIndex < code) {
  33998. lastCharIndex = code;
  33999. }
  34000. var position = getUnicodeRangeFor(code);
  34001. if (position < 32) {
  34002. ulUnicodeRange1 |= 1 << position;
  34003. } else if (position < 64) {
  34004. ulUnicodeRange2 |= 1 << position - 32;
  34005. } else if (position < 96) {
  34006. ulUnicodeRange3 |= 1 << position - 64;
  34007. } else if (position < 123) {
  34008. ulUnicodeRange4 |= 1 << position - 96;
  34009. } else {
  34010. error('Unicode ranges Bits > 123 are reserved for internal usage');
  34011. }
  34012. }
  34013. } else {
  34014. // TODO
  34015. firstCharIndex = 0;
  34016. lastCharIndex = 255;
  34017. }
  34018. var bbox = properties.bbox || [0, 0, 0, 0];
  34019. var unitsPerEm = (override.unitsPerEm ||
  34020. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  34021. // if the font units differ to the PDF glyph space units
  34022. // then scale up the values
  34023. var scale = (properties.ascentScaled ? 1.0 :
  34024. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  34025. var typoAscent = (override.ascent ||
  34026. Math.round(scale * (properties.ascent || bbox[3])));
  34027. var typoDescent = (override.descent ||
  34028. Math.round(scale * (properties.descent || bbox[1])));
  34029. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  34030. typoDescent = -typoDescent; // fixing incorrect descent
  34031. }
  34032. var winAscent = override.yMax || typoAscent;
  34033. var winDescent = -override.yMin || -typoDescent;
  34034. return '\x00\x03' + // version
  34035. '\x02\x24' + // xAvgCharWidth
  34036. '\x01\xF4' + // usWeightClass
  34037. '\x00\x05' + // usWidthClass
  34038. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  34039. '\x02\x8A' + // ySubscriptXSize
  34040. '\x02\xBB' + // ySubscriptYSize
  34041. '\x00\x00' + // ySubscriptXOffset
  34042. '\x00\x8C' + // ySubscriptYOffset
  34043. '\x02\x8A' + // ySuperScriptXSize
  34044. '\x02\xBB' + // ySuperScriptYSize
  34045. '\x00\x00' + // ySuperScriptXOffset
  34046. '\x01\xDF' + // ySuperScriptYOffset
  34047. '\x00\x31' + // yStrikeOutSize
  34048. '\x01\x02' + // yStrikeOutPosition
  34049. '\x00\x00' + // sFamilyClass
  34050. '\x00\x00\x06' +
  34051. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  34052. '\x00\x00\x00\x00\x00\x00' + // Panose
  34053. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  34054. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  34055. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  34056. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  34057. '\x2A\x32\x31\x2A' + // achVendID
  34058. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  34059. string16(firstCharIndex ||
  34060. properties.firstChar) + // usFirstCharIndex
  34061. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  34062. string16(typoAscent) + // sTypoAscender
  34063. string16(typoDescent) + // sTypoDescender
  34064. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  34065. string16(winAscent) + // usWinAscent
  34066. string16(winDescent) + // usWinDescent
  34067. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  34068. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  34069. string16(properties.xHeight) + // sxHeight
  34070. string16(properties.capHeight) + // sCapHeight
  34071. string16(0) + // usDefaultChar
  34072. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  34073. '\x00\x03'; // usMaxContext
  34074. }
  34075. function createPostTable(properties) {
  34076. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  34077. return ('\x00\x03\x00\x00' + // Version number
  34078. string32(angle) + // italicAngle
  34079. '\x00\x00' + // underlinePosition
  34080. '\x00\x00' + // underlineThickness
  34081. string32(properties.fixedPitch) + // isFixedPitch
  34082. '\x00\x00\x00\x00' + // minMemType42
  34083. '\x00\x00\x00\x00' + // maxMemType42
  34084. '\x00\x00\x00\x00' + // minMemType1
  34085. '\x00\x00\x00\x00'); // maxMemType1
  34086. }
  34087. function createNameTable(name, proto) {
  34088. if (!proto) {
  34089. proto = [[], []]; // no strings and unicode strings
  34090. }
  34091. var strings = [
  34092. proto[0][0] || 'Original licence', // 0.Copyright
  34093. proto[0][1] || name, // 1.Font family
  34094. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  34095. proto[0][3] || 'uniqueID', // 3.Unique ID
  34096. proto[0][4] || name, // 4.Full font name
  34097. proto[0][5] || 'Version 0.11', // 5.Version
  34098. proto[0][6] || '', // 6.Postscript name
  34099. proto[0][7] || 'Unknown', // 7.Trademark
  34100. proto[0][8] || 'Unknown', // 8.Manufacturer
  34101. proto[0][9] || 'Unknown' // 9.Designer
  34102. ];
  34103. // Mac want 1-byte per character strings while Windows want
  34104. // 2-bytes per character, so duplicate the names table
  34105. var stringsUnicode = [];
  34106. var i, ii, j, jj, str;
  34107. for (i = 0, ii = strings.length; i < ii; i++) {
  34108. str = proto[1][i] || strings[i];
  34109. var strBufUnicode = [];
  34110. for (j = 0, jj = str.length; j < jj; j++) {
  34111. strBufUnicode.push(string16(str.charCodeAt(j)));
  34112. }
  34113. stringsUnicode.push(strBufUnicode.join(''));
  34114. }
  34115. var names = [strings, stringsUnicode];
  34116. var platforms = ['\x00\x01', '\x00\x03'];
  34117. var encodings = ['\x00\x00', '\x00\x01'];
  34118. var languages = ['\x00\x00', '\x04\x09'];
  34119. var namesRecordCount = strings.length * platforms.length;
  34120. var nameTable =
  34121. '\x00\x00' + // format
  34122. string16(namesRecordCount) + // Number of names Record
  34123. string16(namesRecordCount * 12 + 6); // Storage
  34124. // Build the name records field
  34125. var strOffset = 0;
  34126. for (i = 0, ii = platforms.length; i < ii; i++) {
  34127. var strs = names[i];
  34128. for (j = 0, jj = strs.length; j < jj; j++) {
  34129. str = strs[j];
  34130. var nameRecord =
  34131. platforms[i] + // platform ID
  34132. encodings[i] + // encoding ID
  34133. languages[i] + // language ID
  34134. string16(j) + // name ID
  34135. string16(str.length) +
  34136. string16(strOffset);
  34137. nameTable += nameRecord;
  34138. strOffset += str.length;
  34139. }
  34140. }
  34141. nameTable += strings.join('') + stringsUnicode.join('');
  34142. return nameTable;
  34143. }
  34144. Font.prototype = {
  34145. name: null,
  34146. font: null,
  34147. mimetype: null,
  34148. encoding: null,
  34149. get renderer() {
  34150. var renderer = FontRendererFactory.create(this);
  34151. return shadow(this, 'renderer', renderer);
  34152. },
  34153. exportData: function Font_exportData() {
  34154. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  34155. var data = {};
  34156. for (var i in this) {
  34157. if (this.hasOwnProperty(i)) {
  34158. data[i] = this[i];
  34159. }
  34160. }
  34161. return data;
  34162. },
  34163. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  34164. function readTableEntry(file) {
  34165. var tag = bytesToString(file.getBytes(4));
  34166. var checksum = file.getInt32();
  34167. var offset = file.getInt32() >>> 0;
  34168. var length = file.getInt32() >>> 0;
  34169. // Read the table associated data
  34170. var previousPosition = file.pos;
  34171. file.pos = file.start ? file.start : 0;
  34172. file.skip(offset);
  34173. var data = file.getBytes(length);
  34174. file.pos = previousPosition;
  34175. if (tag === 'head') {
  34176. // clearing checksum adjustment
  34177. data[8] = data[9] = data[10] = data[11] = 0;
  34178. data[17] |= 0x20; //Set font optimized for cleartype flag
  34179. }
  34180. return {
  34181. tag: tag,
  34182. checksum: checksum,
  34183. length: length,
  34184. offset: offset,
  34185. data: data
  34186. };
  34187. }
  34188. function readOpenTypeHeader(ttf) {
  34189. return {
  34190. version: bytesToString(ttf.getBytes(4)),
  34191. numTables: ttf.getUint16(),
  34192. searchRange: ttf.getUint16(),
  34193. entrySelector: ttf.getUint16(),
  34194. rangeShift: ttf.getUint16()
  34195. };
  34196. }
  34197. /**
  34198. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  34199. * PDF spec
  34200. */
  34201. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  34202. if (!cmap) {
  34203. warn('No cmap table available.');
  34204. return {
  34205. platformId: -1,
  34206. encodingId: -1,
  34207. mappings: [],
  34208. hasShortCmap: false
  34209. };
  34210. }
  34211. var segment;
  34212. var start = (font.start ? font.start : 0) + cmap.offset;
  34213. font.pos = start;
  34214. var version = font.getUint16();
  34215. var numTables = font.getUint16();
  34216. var potentialTable;
  34217. var canBreak = false;
  34218. // There's an order of preference in terms of which cmap subtable to
  34219. // use:
  34220. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  34221. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  34222. // The following takes advantage of the fact that the tables are sorted
  34223. // to work.
  34224. for (var i = 0; i < numTables; i++) {
  34225. var platformId = font.getUint16();
  34226. var encodingId = font.getUint16();
  34227. var offset = font.getInt32() >>> 0;
  34228. var useTable = false;
  34229. if (platformId === 0 && encodingId === 0) {
  34230. useTable = true;
  34231. // Continue the loop since there still may be a higher priority
  34232. // table.
  34233. } else if (platformId === 1 && encodingId === 0) {
  34234. useTable = true;
  34235. // Continue the loop since there still may be a higher priority
  34236. // table.
  34237. } else if (platformId === 3 && encodingId === 1 &&
  34238. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  34239. useTable = true;
  34240. if (!isSymbolicFont) {
  34241. canBreak = true;
  34242. }
  34243. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  34244. useTable = true;
  34245. canBreak = true;
  34246. }
  34247. if (useTable) {
  34248. potentialTable = {
  34249. platformId: platformId,
  34250. encodingId: encodingId,
  34251. offset: offset
  34252. };
  34253. }
  34254. if (canBreak) {
  34255. break;
  34256. }
  34257. }
  34258. if (potentialTable) {
  34259. font.pos = start + potentialTable.offset;
  34260. }
  34261. if (!potentialTable || font.peekByte() === -1) {
  34262. warn('Could not find a preferred cmap table.');
  34263. return {
  34264. platformId: -1,
  34265. encodingId: -1,
  34266. mappings: [],
  34267. hasShortCmap: false
  34268. };
  34269. }
  34270. var format = font.getUint16();
  34271. var length = font.getUint16();
  34272. var language = font.getUint16();
  34273. var hasShortCmap = false;
  34274. var mappings = [];
  34275. var j, glyphId;
  34276. // TODO(mack): refactor this cmap subtable reading logic out
  34277. if (format === 0) {
  34278. for (j = 0; j < 256; j++) {
  34279. var index = font.getByte();
  34280. if (!index) {
  34281. continue;
  34282. }
  34283. mappings.push({
  34284. charCode: j,
  34285. glyphId: index
  34286. });
  34287. }
  34288. hasShortCmap = true;
  34289. } else if (format === 4) {
  34290. // re-creating the table in format 4 since the encoding
  34291. // might be changed
  34292. var segCount = (font.getUint16() >> 1);
  34293. font.getBytes(6); // skipping range fields
  34294. var segIndex, segments = [];
  34295. for (segIndex = 0; segIndex < segCount; segIndex++) {
  34296. segments.push({ end: font.getUint16() });
  34297. }
  34298. font.getUint16();
  34299. for (segIndex = 0; segIndex < segCount; segIndex++) {
  34300. segments[segIndex].start = font.getUint16();
  34301. }
  34302. for (segIndex = 0; segIndex < segCount; segIndex++) {
  34303. segments[segIndex].delta = font.getUint16();
  34304. }
  34305. var offsetsCount = 0;
  34306. for (segIndex = 0; segIndex < segCount; segIndex++) {
  34307. segment = segments[segIndex];
  34308. var rangeOffset = font.getUint16();
  34309. if (!rangeOffset) {
  34310. segment.offsetIndex = -1;
  34311. continue;
  34312. }
  34313. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  34314. segment.offsetIndex = offsetIndex;
  34315. offsetsCount = Math.max(offsetsCount, offsetIndex +
  34316. segment.end - segment.start + 1);
  34317. }
  34318. var offsets = [];
  34319. for (j = 0; j < offsetsCount; j++) {
  34320. offsets.push(font.getUint16());
  34321. }
  34322. for (segIndex = 0; segIndex < segCount; segIndex++) {
  34323. segment = segments[segIndex];
  34324. start = segment.start;
  34325. var end = segment.end;
  34326. var delta = segment.delta;
  34327. offsetIndex = segment.offsetIndex;
  34328. for (j = start; j <= end; j++) {
  34329. if (j === 0xFFFF) {
  34330. continue;
  34331. }
  34332. glyphId = (offsetIndex < 0 ?
  34333. j : offsets[offsetIndex + j - start]);
  34334. glyphId = (glyphId + delta) & 0xFFFF;
  34335. if (glyphId === 0) {
  34336. continue;
  34337. }
  34338. mappings.push({
  34339. charCode: j,
  34340. glyphId: glyphId
  34341. });
  34342. }
  34343. }
  34344. } else if (format === 6) {
  34345. // Format 6 is a 2-bytes dense mapping, which means the font data
  34346. // lives glue together even if they are pretty far in the unicode
  34347. // table. (This looks weird, so I can have missed something), this
  34348. // works on Linux but seems to fails on Mac so let's rewrite the
  34349. // cmap table to a 3-1-4 style
  34350. var firstCode = font.getUint16();
  34351. var entryCount = font.getUint16();
  34352. for (j = 0; j < entryCount; j++) {
  34353. glyphId = font.getUint16();
  34354. var charCode = firstCode + j;
  34355. mappings.push({
  34356. charCode: charCode,
  34357. glyphId: glyphId
  34358. });
  34359. }
  34360. } else {
  34361. warn('cmap table has unsupported format: ' + format);
  34362. return {
  34363. platformId: -1,
  34364. encodingId: -1,
  34365. mappings: [],
  34366. hasShortCmap: false
  34367. };
  34368. }
  34369. // removing duplicate entries
  34370. mappings.sort(function (a, b) {
  34371. return a.charCode - b.charCode;
  34372. });
  34373. for (i = 1; i < mappings.length; i++) {
  34374. if (mappings[i - 1].charCode === mappings[i].charCode) {
  34375. mappings.splice(i, 1);
  34376. i--;
  34377. }
  34378. }
  34379. return {
  34380. platformId: potentialTable.platformId,
  34381. encodingId: potentialTable.encodingId,
  34382. mappings: mappings,
  34383. hasShortCmap: hasShortCmap
  34384. };
  34385. }
  34386. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  34387. if (!header) {
  34388. if (metrics) {
  34389. metrics.data = null;
  34390. }
  34391. return;
  34392. }
  34393. font.pos = (font.start ? font.start : 0) + header.offset;
  34394. font.pos += header.length - 2;
  34395. var numOfMetrics = font.getUint16();
  34396. if (numOfMetrics > numGlyphs) {
  34397. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  34398. 'greater than the numGlyphs (' + numGlyphs + ')');
  34399. // Reduce numOfMetrics if it is greater than numGlyphs
  34400. numOfMetrics = numGlyphs;
  34401. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  34402. header.data[35] = numOfMetrics & 0x00ff;
  34403. }
  34404. var numOfSidebearings = numGlyphs - numOfMetrics;
  34405. var numMissing = numOfSidebearings -
  34406. ((metrics.length - numOfMetrics * 4) >> 1);
  34407. if (numMissing > 0) {
  34408. // For each missing glyph, we set both the width and lsb to 0 (zero).
  34409. // Since we need to add two properties for each glyph, this explains
  34410. // the use of |numMissing * 2| when initializing the typed array.
  34411. var entries = new Uint8Array(metrics.length + numMissing * 2);
  34412. entries.set(metrics.data);
  34413. metrics.data = entries;
  34414. }
  34415. }
  34416. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  34417. hintsValid) {
  34418. if (sourceEnd - sourceStart <= 12) {
  34419. // glyph with data less than 12 is invalid one
  34420. return 0;
  34421. }
  34422. var glyf = source.subarray(sourceStart, sourceEnd);
  34423. var contoursCount = (glyf[0] << 8) | glyf[1];
  34424. if (contoursCount & 0x8000) {
  34425. // complex glyph, writing as is
  34426. dest.set(glyf, destStart);
  34427. return glyf.length;
  34428. }
  34429. var i, j = 10, flagsCount = 0;
  34430. for (i = 0; i < contoursCount; i++) {
  34431. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  34432. flagsCount = endPoint + 1;
  34433. j += 2;
  34434. }
  34435. // skipping instructions
  34436. var instructionsStart = j;
  34437. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  34438. j += 2 + instructionsLength;
  34439. var instructionsEnd = j;
  34440. // validating flags
  34441. var coordinatesLength = 0;
  34442. for (i = 0; i < flagsCount; i++) {
  34443. var flag = glyf[j++];
  34444. if (flag & 0xC0) {
  34445. // reserved flags must be zero, cleaning up
  34446. glyf[j - 1] = flag & 0x3F;
  34447. }
  34448. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  34449. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  34450. coordinatesLength += xyLength;
  34451. if (flag & 8) {
  34452. var repeat = glyf[j++];
  34453. i += repeat;
  34454. coordinatesLength += repeat * xyLength;
  34455. }
  34456. }
  34457. // glyph without coordinates will be rejected
  34458. if (coordinatesLength === 0) {
  34459. return 0;
  34460. }
  34461. var glyphDataLength = j + coordinatesLength;
  34462. if (glyphDataLength > glyf.length) {
  34463. // not enough data for coordinates
  34464. return 0;
  34465. }
  34466. if (!hintsValid && instructionsLength > 0) {
  34467. dest.set(glyf.subarray(0, instructionsStart), destStart);
  34468. dest.set([0, 0], destStart + instructionsStart);
  34469. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  34470. destStart + instructionsStart + 2);
  34471. glyphDataLength -= instructionsLength;
  34472. if (glyf.length - glyphDataLength > 3) {
  34473. glyphDataLength = (glyphDataLength + 3) & ~3;
  34474. }
  34475. return glyphDataLength;
  34476. }
  34477. if (glyf.length - glyphDataLength > 3) {
  34478. // truncating and aligning to 4 bytes the long glyph data
  34479. glyphDataLength = (glyphDataLength + 3) & ~3;
  34480. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  34481. return glyphDataLength;
  34482. }
  34483. // glyph data is fine
  34484. dest.set(glyf, destStart);
  34485. return glyf.length;
  34486. }
  34487. function sanitizeHead(head, numGlyphs, locaLength) {
  34488. var data = head.data;
  34489. // Validate version:
  34490. // Should always be 0x00010000
  34491. var version = int32(data[0], data[1], data[2], data[3]);
  34492. if (version >> 16 !== 1) {
  34493. info('Attempting to fix invalid version in head table: ' + version);
  34494. data[0] = 0;
  34495. data[1] = 1;
  34496. data[2] = 0;
  34497. data[3] = 0;
  34498. }
  34499. var indexToLocFormat = int16(data[50], data[51]);
  34500. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  34501. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  34502. indexToLocFormat);
  34503. // The value of indexToLocFormat should be 0 if the loca table
  34504. // consists of short offsets, and should be 1 if the loca table
  34505. // consists of long offsets.
  34506. //
  34507. // The number of entries in the loca table should be numGlyphs + 1.
  34508. //
  34509. // Using this information, we can work backwards to deduce if the
  34510. // size of each offset in the loca table, and thus figure out the
  34511. // appropriate value for indexToLocFormat.
  34512. var numGlyphsPlusOne = numGlyphs + 1;
  34513. if (locaLength === numGlyphsPlusOne << 1) {
  34514. // 0x0000 indicates the loca table consists of short offsets
  34515. data[50] = 0;
  34516. data[51] = 0;
  34517. } else if (locaLength === numGlyphsPlusOne << 2) {
  34518. // 0x0001 indicates the loca table consists of long offsets
  34519. data[50] = 0;
  34520. data[51] = 1;
  34521. } else {
  34522. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  34523. }
  34524. }
  34525. }
  34526. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  34527. isGlyphLocationsLong, hintsValid,
  34528. dupFirstEntry) {
  34529. var itemSize, itemDecode, itemEncode;
  34530. if (isGlyphLocationsLong) {
  34531. itemSize = 4;
  34532. itemDecode = function fontItemDecodeLong(data, offset) {
  34533. return (data[offset] << 24) | (data[offset + 1] << 16) |
  34534. (data[offset + 2] << 8) | data[offset + 3];
  34535. };
  34536. itemEncode = function fontItemEncodeLong(data, offset, value) {
  34537. data[offset] = (value >>> 24) & 0xFF;
  34538. data[offset + 1] = (value >> 16) & 0xFF;
  34539. data[offset + 2] = (value >> 8) & 0xFF;
  34540. data[offset + 3] = value & 0xFF;
  34541. };
  34542. } else {
  34543. itemSize = 2;
  34544. itemDecode = function fontItemDecode(data, offset) {
  34545. return (data[offset] << 9) | (data[offset + 1] << 1);
  34546. };
  34547. itemEncode = function fontItemEncode(data, offset, value) {
  34548. data[offset] = (value >> 9) & 0xFF;
  34549. data[offset + 1] = (value >> 1) & 0xFF;
  34550. };
  34551. }
  34552. var locaData = loca.data;
  34553. var locaDataSize = itemSize * (1 + numGlyphs);
  34554. // is loca.data too short or long?
  34555. if (locaData.length !== locaDataSize) {
  34556. locaData = new Uint8Array(locaDataSize);
  34557. locaData.set(loca.data.subarray(0, locaDataSize));
  34558. loca.data = locaData;
  34559. }
  34560. // removing the invalid glyphs
  34561. var oldGlyfData = glyf.data;
  34562. var oldGlyfDataLength = oldGlyfData.length;
  34563. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  34564. var startOffset = itemDecode(locaData, 0);
  34565. var writeOffset = 0;
  34566. var missingGlyphData = Object.create(null);
  34567. itemEncode(locaData, 0, writeOffset);
  34568. var i, j;
  34569. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  34570. var endOffset = itemDecode(locaData, j);
  34571. if (endOffset > oldGlyfDataLength &&
  34572. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  34573. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  34574. // the glyf table size, which makes last glyph out of range.
  34575. endOffset = oldGlyfDataLength;
  34576. }
  34577. if (endOffset > oldGlyfDataLength) {
  34578. // glyph end offset points outside glyf data, rejecting the glyph
  34579. itemEncode(locaData, j, writeOffset);
  34580. startOffset = endOffset;
  34581. continue;
  34582. }
  34583. if (startOffset === endOffset) {
  34584. missingGlyphData[i] = true;
  34585. }
  34586. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  34587. newGlyfData, writeOffset, hintsValid);
  34588. writeOffset += newLength;
  34589. itemEncode(locaData, j, writeOffset);
  34590. startOffset = endOffset;
  34591. }
  34592. if (writeOffset === 0) {
  34593. // glyf table cannot be empty -- redoing the glyf and loca tables
  34594. // to have single glyph with one point
  34595. var simpleGlyph = new Uint8Array(
  34596. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  34597. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  34598. itemEncode(locaData, j, simpleGlyph.length);
  34599. }
  34600. glyf.data = simpleGlyph;
  34601. return missingGlyphData;
  34602. }
  34603. if (dupFirstEntry) {
  34604. var firstEntryLength = itemDecode(locaData, itemSize);
  34605. if (newGlyfData.length > firstEntryLength + writeOffset) {
  34606. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  34607. } else {
  34608. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  34609. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  34610. }
  34611. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  34612. itemEncode(loca.data, locaData.length - itemSize,
  34613. writeOffset + firstEntryLength);
  34614. } else {
  34615. glyf.data = newGlyfData.subarray(0, writeOffset);
  34616. }
  34617. return missingGlyphData;
  34618. }
  34619. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  34620. var start = (font.start ? font.start : 0) + post.offset;
  34621. font.pos = start;
  34622. var length = post.length, end = start + length;
  34623. var version = font.getInt32();
  34624. // skip rest to the tables
  34625. font.getBytes(28);
  34626. var glyphNames;
  34627. var valid = true;
  34628. var i;
  34629. switch (version) {
  34630. case 0x00010000:
  34631. glyphNames = MacStandardGlyphOrdering;
  34632. break;
  34633. case 0x00020000:
  34634. var numGlyphs = font.getUint16();
  34635. if (numGlyphs !== maxpNumGlyphs) {
  34636. valid = false;
  34637. break;
  34638. }
  34639. var glyphNameIndexes = [];
  34640. for (i = 0; i < numGlyphs; ++i) {
  34641. var index = font.getUint16();
  34642. if (index >= 32768) {
  34643. valid = false;
  34644. break;
  34645. }
  34646. glyphNameIndexes.push(index);
  34647. }
  34648. if (!valid) {
  34649. break;
  34650. }
  34651. var customNames = [];
  34652. var strBuf = [];
  34653. while (font.pos < end) {
  34654. var stringLength = font.getByte();
  34655. strBuf.length = stringLength;
  34656. for (i = 0; i < stringLength; ++i) {
  34657. strBuf[i] = String.fromCharCode(font.getByte());
  34658. }
  34659. customNames.push(strBuf.join(''));
  34660. }
  34661. glyphNames = [];
  34662. for (i = 0; i < numGlyphs; ++i) {
  34663. var j = glyphNameIndexes[i];
  34664. if (j < 258) {
  34665. glyphNames.push(MacStandardGlyphOrdering[j]);
  34666. continue;
  34667. }
  34668. glyphNames.push(customNames[j - 258]);
  34669. }
  34670. break;
  34671. case 0x00030000:
  34672. break;
  34673. default:
  34674. warn('Unknown/unsupported post table version ' + version);
  34675. valid = false;
  34676. if (properties.defaultEncoding) {
  34677. glyphNames = properties.defaultEncoding;
  34678. }
  34679. break;
  34680. }
  34681. properties.glyphNames = glyphNames;
  34682. return valid;
  34683. }
  34684. function readNameTable(nameTable) {
  34685. var start = (font.start ? font.start : 0) + nameTable.offset;
  34686. font.pos = start;
  34687. var names = [[], []];
  34688. var length = nameTable.length, end = start + length;
  34689. var format = font.getUint16();
  34690. var FORMAT_0_HEADER_LENGTH = 6;
  34691. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  34692. // unsupported name table format or table "too" small
  34693. return names;
  34694. }
  34695. var numRecords = font.getUint16();
  34696. var stringsStart = font.getUint16();
  34697. var records = [];
  34698. var NAME_RECORD_LENGTH = 12;
  34699. var i, ii;
  34700. for (i = 0; i < numRecords &&
  34701. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  34702. var r = {
  34703. platform: font.getUint16(),
  34704. encoding: font.getUint16(),
  34705. language: font.getUint16(),
  34706. name: font.getUint16(),
  34707. length: font.getUint16(),
  34708. offset: font.getUint16()
  34709. };
  34710. // using only Macintosh and Windows platform/encoding names
  34711. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  34712. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  34713. records.push(r);
  34714. }
  34715. }
  34716. for (i = 0, ii = records.length; i < ii; i++) {
  34717. var record = records[i];
  34718. var pos = start + stringsStart + record.offset;
  34719. if (pos + record.length > end) {
  34720. continue; // outside of name table, ignoring
  34721. }
  34722. font.pos = pos;
  34723. var nameIndex = record.name;
  34724. if (record.encoding) {
  34725. // unicode
  34726. var str = '';
  34727. for (var j = 0, jj = record.length; j < jj; j += 2) {
  34728. str += String.fromCharCode(font.getUint16());
  34729. }
  34730. names[1][nameIndex] = str;
  34731. } else {
  34732. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  34733. }
  34734. }
  34735. return names;
  34736. }
  34737. var TTOpsStackDeltas = [
  34738. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  34739. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  34740. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  34741. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  34742. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  34743. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  34744. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  34745. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  34746. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  34747. // 0xC0-DF == -1 and 0xE0-FF == -2
  34748. function sanitizeTTProgram(table, ttContext) {
  34749. var data = table.data;
  34750. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  34751. var stack = [];
  34752. var callstack = [];
  34753. var functionsCalled = [];
  34754. var tooComplexToFollowFunctions =
  34755. ttContext.tooComplexToFollowFunctions;
  34756. var inFDEF = false, ifLevel = 0, inELSE = 0;
  34757. for (var ii = data.length; i < ii;) {
  34758. var op = data[i++];
  34759. // The TrueType instruction set docs can be found at
  34760. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  34761. if (op === 0x40) { // NPUSHB - pushes n bytes
  34762. n = data[i++];
  34763. if (inFDEF || inELSE) {
  34764. i += n;
  34765. } else {
  34766. for (j = 0; j < n; j++) {
  34767. stack.push(data[i++]);
  34768. }
  34769. }
  34770. } else if (op === 0x41) { // NPUSHW - pushes n words
  34771. n = data[i++];
  34772. if (inFDEF || inELSE) {
  34773. i += n * 2;
  34774. } else {
  34775. for (j = 0; j < n; j++) {
  34776. b = data[i++];
  34777. stack.push((b << 8) | data[i++]);
  34778. }
  34779. }
  34780. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  34781. n = op - 0xB0 + 1;
  34782. if (inFDEF || inELSE) {
  34783. i += n;
  34784. } else {
  34785. for (j = 0; j < n; j++) {
  34786. stack.push(data[i++]);
  34787. }
  34788. }
  34789. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  34790. n = op - 0xB8 + 1;
  34791. if (inFDEF || inELSE) {
  34792. i += n * 2;
  34793. } else {
  34794. for (j = 0; j < n; j++) {
  34795. b = data[i++];
  34796. stack.push((b << 8) | data[i++]);
  34797. }
  34798. }
  34799. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  34800. if (!inFDEF && !inELSE) {
  34801. // collecting inforamtion about which functions are used
  34802. funcId = stack[stack.length - 1];
  34803. ttContext.functionsUsed[funcId] = true;
  34804. if (funcId in ttContext.functionsStackDeltas) {
  34805. stack.length += ttContext.functionsStackDeltas[funcId];
  34806. } else if (funcId in ttContext.functionsDefined &&
  34807. functionsCalled.indexOf(funcId) < 0) {
  34808. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  34809. functionsCalled.push(funcId);
  34810. pc = ttContext.functionsDefined[funcId];
  34811. if (!pc) {
  34812. warn('TT: CALL non-existent function');
  34813. ttContext.hintsValid = false;
  34814. return;
  34815. }
  34816. data = pc.data;
  34817. i = pc.i;
  34818. }
  34819. }
  34820. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  34821. if (inFDEF || inELSE) {
  34822. warn('TT: nested FDEFs not allowed');
  34823. tooComplexToFollowFunctions = true;
  34824. }
  34825. inFDEF = true;
  34826. // collecting inforamtion about which functions are defined
  34827. lastDeff = i;
  34828. funcId = stack.pop();
  34829. ttContext.functionsDefined[funcId] = {data: data, i: i};
  34830. } else if (op === 0x2D) { // ENDF - end of function
  34831. if (inFDEF) {
  34832. inFDEF = false;
  34833. lastEndf = i;
  34834. } else {
  34835. pc = callstack.pop();
  34836. if (!pc) {
  34837. warn('TT: ENDF bad stack');
  34838. ttContext.hintsValid = false;
  34839. return;
  34840. }
  34841. funcId = functionsCalled.pop();
  34842. data = pc.data;
  34843. i = pc.i;
  34844. ttContext.functionsStackDeltas[funcId] =
  34845. stack.length - pc.stackTop;
  34846. }
  34847. } else if (op === 0x89) { // IDEF - instruction definition
  34848. if (inFDEF || inELSE) {
  34849. warn('TT: nested IDEFs not allowed');
  34850. tooComplexToFollowFunctions = true;
  34851. }
  34852. inFDEF = true;
  34853. // recording it as a function to track ENDF
  34854. lastDeff = i;
  34855. } else if (op === 0x58) { // IF
  34856. ++ifLevel;
  34857. } else if (op === 0x1B) { // ELSE
  34858. inELSE = ifLevel;
  34859. } else if (op === 0x59) { // EIF
  34860. if (inELSE === ifLevel) {
  34861. inELSE = 0;
  34862. }
  34863. --ifLevel;
  34864. } else if (op === 0x1C) { // JMPR
  34865. if (!inFDEF && !inELSE) {
  34866. var offset = stack[stack.length - 1];
  34867. // only jumping forward to prevent infinite loop
  34868. if (offset > 0) {
  34869. i += offset - 1;
  34870. }
  34871. }
  34872. }
  34873. // Adjusting stack not extactly, but just enough to get function id
  34874. if (!inFDEF && !inELSE) {
  34875. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  34876. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  34877. if (op >= 0x71 && op <= 0x75) {
  34878. n = stack.pop();
  34879. if (n === n) {
  34880. stackDelta = -n * 2;
  34881. }
  34882. }
  34883. while (stackDelta < 0 && stack.length > 0) {
  34884. stack.pop();
  34885. stackDelta++;
  34886. }
  34887. while (stackDelta > 0) {
  34888. stack.push(NaN); // pushing any number into stack
  34889. stackDelta--;
  34890. }
  34891. }
  34892. }
  34893. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  34894. var content = [data];
  34895. if (i > data.length) {
  34896. content.push(new Uint8Array(i - data.length));
  34897. }
  34898. if (lastDeff > lastEndf) {
  34899. warn('TT: complementing a missing function tail');
  34900. // new function definition started, but not finished
  34901. // complete function by [CLEAR, ENDF]
  34902. content.push(new Uint8Array([0x22, 0x2D]));
  34903. }
  34904. foldTTTable(table, content);
  34905. }
  34906. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  34907. if (ttContext.tooComplexToFollowFunctions) {
  34908. return;
  34909. }
  34910. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  34911. warn('TT: more functions defined than expected');
  34912. ttContext.hintsValid = false;
  34913. return;
  34914. }
  34915. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  34916. if (j > maxFunctionDefs) {
  34917. warn('TT: invalid function id: ' + j);
  34918. ttContext.hintsValid = false;
  34919. return;
  34920. }
  34921. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  34922. warn('TT: undefined function: ' + j);
  34923. ttContext.hintsValid = false;
  34924. return;
  34925. }
  34926. }
  34927. }
  34928. function foldTTTable(table, content) {
  34929. if (content.length > 1) {
  34930. // concatenating the content items
  34931. var newLength = 0;
  34932. var j, jj;
  34933. for (j = 0, jj = content.length; j < jj; j++) {
  34934. newLength += content[j].length;
  34935. }
  34936. newLength = (newLength + 3) & ~3;
  34937. var result = new Uint8Array(newLength);
  34938. var pos = 0;
  34939. for (j = 0, jj = content.length; j < jj; j++) {
  34940. result.set(content[j], pos);
  34941. pos += content[j].length;
  34942. }
  34943. table.data = result;
  34944. table.length = newLength;
  34945. }
  34946. }
  34947. function sanitizeTTPrograms(fpgm, prep, cvt) {
  34948. var ttContext = {
  34949. functionsDefined: [],
  34950. functionsUsed: [],
  34951. functionsStackDeltas: [],
  34952. tooComplexToFollowFunctions: false,
  34953. hintsValid: true
  34954. };
  34955. if (fpgm) {
  34956. sanitizeTTProgram(fpgm, ttContext);
  34957. }
  34958. if (prep) {
  34959. sanitizeTTProgram(prep, ttContext);
  34960. }
  34961. if (fpgm) {
  34962. checkInvalidFunctions(ttContext, maxFunctionDefs);
  34963. }
  34964. if (cvt && (cvt.length & 1)) {
  34965. var cvtData = new Uint8Array(cvt.length + 1);
  34966. cvtData.set(cvt.data);
  34967. cvt.data = cvtData;
  34968. }
  34969. return ttContext.hintsValid;
  34970. }
  34971. // The following steps modify the original font data, making copy
  34972. font = new Stream(new Uint8Array(font.getBytes()));
  34973. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  34974. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  34975. var header = readOpenTypeHeader(font);
  34976. var numTables = header.numTables;
  34977. var cff, cffFile;
  34978. var tables = Object.create(null);
  34979. tables['OS/2'] = null;
  34980. tables['cmap'] = null;
  34981. tables['head'] = null;
  34982. tables['hhea'] = null;
  34983. tables['hmtx'] = null;
  34984. tables['maxp'] = null;
  34985. tables['name'] = null;
  34986. tables['post'] = null;
  34987. var table;
  34988. for (var i = 0; i < numTables; i++) {
  34989. table = readTableEntry(font);
  34990. if (VALID_TABLES.indexOf(table.tag) < 0) {
  34991. continue; // skipping table if it's not a required or optional table
  34992. }
  34993. if (table.length === 0) {
  34994. continue; // skipping empty tables
  34995. }
  34996. tables[table.tag] = table;
  34997. }
  34998. var isTrueType = !tables['CFF '];
  34999. if (!isTrueType) {
  35000. // OpenType font
  35001. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  35002. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  35003. !tables['post']) {
  35004. // no major tables: throwing everything at CFFFont
  35005. cffFile = new Stream(tables['CFF '].data);
  35006. cff = new CFFFont(cffFile, properties);
  35007. adjustWidths(properties);
  35008. return this.convert(name, cff, properties);
  35009. }
  35010. delete tables['glyf'];
  35011. delete tables['loca'];
  35012. delete tables['fpgm'];
  35013. delete tables['prep'];
  35014. delete tables['cvt '];
  35015. this.isOpenType = true;
  35016. } else {
  35017. if (!tables['loca']) {
  35018. error('Required "loca" table is not found');
  35019. }
  35020. if (!tables['glyf']) {
  35021. warn('Required "glyf" table is not found -- trying to recover.');
  35022. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  35023. tables['glyf'] = {
  35024. tag: 'glyf',
  35025. data: new Uint8Array(0),
  35026. };
  35027. }
  35028. this.isOpenType = false;
  35029. }
  35030. if (!tables['maxp']) {
  35031. error('Required "maxp" table is not found');
  35032. }
  35033. font.pos = (font.start || 0) + tables['maxp'].offset;
  35034. var version = font.getInt32();
  35035. var numGlyphs = font.getUint16();
  35036. var maxFunctionDefs = 0;
  35037. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  35038. // maxZones can be invalid
  35039. font.pos += 8;
  35040. var maxZones = font.getUint16();
  35041. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  35042. tables['maxp'].data[14] = 0;
  35043. tables['maxp'].data[15] = 2;
  35044. }
  35045. font.pos += 4;
  35046. maxFunctionDefs = font.getUint16();
  35047. }
  35048. var dupFirstEntry = false;
  35049. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  35050. properties.toUnicode.get(0) > '\u0000') {
  35051. // oracle's defect (see 3427), duplicating first entry
  35052. dupFirstEntry = true;
  35053. numGlyphs++;
  35054. tables['maxp'].data[4] = numGlyphs >> 8;
  35055. tables['maxp'].data[5] = numGlyphs & 255;
  35056. }
  35057. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  35058. tables['cvt '], maxFunctionDefs);
  35059. if (!hintsValid) {
  35060. delete tables['fpgm'];
  35061. delete tables['prep'];
  35062. delete tables['cvt '];
  35063. }
  35064. // Ensure the hmtx table contains the advance width and
  35065. // sidebearings information for numGlyphs in the maxp table
  35066. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  35067. if (!tables['head']) {
  35068. error('Required "head" table is not found');
  35069. }
  35070. sanitizeHead(tables['head'], numGlyphs,
  35071. isTrueType ? tables['loca'].length : 0);
  35072. var missingGlyphs = Object.create(null);
  35073. if (isTrueType) {
  35074. var isGlyphLocationsLong = int16(tables['head'].data[50],
  35075. tables['head'].data[51]);
  35076. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  35077. numGlyphs, isGlyphLocationsLong,
  35078. hintsValid, dupFirstEntry);
  35079. }
  35080. if (!tables['hhea']) {
  35081. error('Required "hhea" table is not found');
  35082. }
  35083. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  35084. // Sometimes it's 0. That needs to be fixed
  35085. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  35086. tables['hhea'].data[10] = 0xFF;
  35087. tables['hhea'].data[11] = 0xFF;
  35088. }
  35089. // Extract some more font properties from the OpenType head and
  35090. // hhea tables; yMin and descent value are always negative.
  35091. var metricsOverride = {
  35092. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  35093. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  35094. yMin: int16(tables['head'].data[38], tables['head'].data[39]) - 0x10000,
  35095. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  35096. descent: int16(tables['hhea'].data[6], tables['hhea'].data[7]) - 0x10000
  35097. };
  35098. // PDF FontDescriptor metrics lie -- using data from actual font.
  35099. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  35100. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  35101. // The 'post' table has glyphs names.
  35102. if (tables['post']) {
  35103. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  35104. if (!valid) {
  35105. tables['post'] = null;
  35106. }
  35107. }
  35108. var charCodeToGlyphId = [], charCode;
  35109. var toUnicode = properties.toUnicode, widths = properties.widths;
  35110. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  35111. toUnicode.length === 0x10000);
  35112. // Helper function to try to skip mapping of empty glyphs.
  35113. // Note: In some cases, just relying on the glyph data doesn't work,
  35114. // hence we also use a few heuristics to fix various PDF files.
  35115. function hasGlyph(glyphId, charCode, widthCode) {
  35116. if (!missingGlyphs[glyphId]) {
  35117. return true;
  35118. }
  35119. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  35120. return true;
  35121. }
  35122. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  35123. return true;
  35124. }
  35125. return false;
  35126. }
  35127. if (properties.type === 'CIDFontType2') {
  35128. var cidToGidMap = properties.cidToGidMap || [];
  35129. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  35130. properties.cMap.forEach(function(charCode, cid) {
  35131. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  35132. var glyphId = -1;
  35133. if (isCidToGidMapEmpty) {
  35134. glyphId = charCode;
  35135. } else if (cidToGidMap[cid] !== undefined) {
  35136. glyphId = cidToGidMap[cid];
  35137. }
  35138. if (glyphId >= 0 && glyphId < numGlyphs &&
  35139. hasGlyph(glyphId, charCode, cid)) {
  35140. charCodeToGlyphId[charCode] = glyphId;
  35141. }
  35142. });
  35143. if (dupFirstEntry) {
  35144. charCodeToGlyphId[0] = numGlyphs - 1;
  35145. }
  35146. } else {
  35147. // Most of the following logic in this code branch is based on the
  35148. // 9.6.6.4 of the PDF spec.
  35149. var hasEncoding =
  35150. properties.differences.length > 0 || !!properties.baseEncodingName;
  35151. var cmapTable =
  35152. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  35153. var cmapPlatformId = cmapTable.platformId;
  35154. var cmapEncodingId = cmapTable.encodingId;
  35155. var cmapMappings = cmapTable.mappings;
  35156. var cmapMappingsLength = cmapMappings.length;
  35157. // The spec seems to imply that if the font is symbolic the encoding
  35158. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  35159. // where the the font is symbolic and it has an encoding.
  35160. if (hasEncoding &&
  35161. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  35162. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  35163. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  35164. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  35165. // When no preferred cmap table was found and |baseEncodingName| is
  35166. // one of the predefined encodings, we seem to obtain a better
  35167. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  35168. // TODO: Note that this is a hack which should be removed as soon as
  35169. // we have proper support for more exotic cmap tables.
  35170. var baseEncoding = [];
  35171. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  35172. properties.baseEncodingName === 'WinAnsiEncoding') {
  35173. baseEncoding = getEncoding(properties.baseEncodingName);
  35174. }
  35175. var glyphsUnicodeMap = getGlyphsUnicode();
  35176. for (charCode = 0; charCode < 256; charCode++) {
  35177. var glyphName;
  35178. if (this.differences && charCode in this.differences) {
  35179. glyphName = this.differences[charCode];
  35180. } else if (charCode in baseEncoding &&
  35181. baseEncoding[charCode] !== '') {
  35182. glyphName = baseEncoding[charCode];
  35183. } else {
  35184. glyphName = StandardEncoding[charCode];
  35185. }
  35186. if (!glyphName) {
  35187. continue;
  35188. }
  35189. var unicodeOrCharCode, isUnicode = false;
  35190. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  35191. unicodeOrCharCode = glyphsUnicodeMap[glyphName];
  35192. isUnicode = true;
  35193. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  35194. // TODO: the encoding needs to be updated with mac os table.
  35195. unicodeOrCharCode = MacRomanEncoding.indexOf(glyphName);
  35196. }
  35197. var found = false;
  35198. for (i = 0; i < cmapMappingsLength; ++i) {
  35199. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  35200. continue;
  35201. }
  35202. var code = isUnicode ? charCode : unicodeOrCharCode;
  35203. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  35204. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  35205. found = true;
  35206. break;
  35207. }
  35208. }
  35209. if (!found && properties.glyphNames) {
  35210. // Try to map using the post table.
  35211. var glyphId = properties.glyphNames.indexOf(glyphName);
  35212. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  35213. charCodeToGlyphId[charCode] = glyphId;
  35214. found = true;
  35215. }
  35216. }
  35217. if (!found) {
  35218. charCodeToGlyphId[charCode] = 0; // notdef
  35219. }
  35220. }
  35221. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  35222. // Default Unicode semantics, use the charcodes as is.
  35223. for (i = 0; i < cmapMappingsLength; ++i) {
  35224. charCodeToGlyphId[cmapMappings[i].charCode] =
  35225. cmapMappings[i].glyphId;
  35226. }
  35227. } else {
  35228. // For (3, 0) cmap tables:
  35229. // The charcode key being stored in charCodeToGlyphId is the lower
  35230. // byte of the two-byte charcodes of the cmap table since according to
  35231. // the spec: 'each byte from the string shall be prepended with the
  35232. // high byte of the range [of charcodes in the cmap table], to form
  35233. // a two-byte character, which shall be used to select the
  35234. // associated glyph description from the subtable'.
  35235. //
  35236. // For (1, 0) cmap tables:
  35237. // 'single bytes from the string shall be used to look up the
  35238. // associated glyph descriptions from the subtable'. This means
  35239. // charcodes in the cmap will be single bytes, so no-op since
  35240. // glyph.charCode & 0xFF === glyph.charCode
  35241. for (i = 0; i < cmapMappingsLength; ++i) {
  35242. charCode = cmapMappings[i].charCode & 0xFF;
  35243. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  35244. }
  35245. }
  35246. }
  35247. if (charCodeToGlyphId.length === 0) {
  35248. // defines at least one glyph
  35249. charCodeToGlyphId[0] = 0;
  35250. }
  35251. // Converting glyphs and ids into font's cmap table
  35252. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  35253. this.toFontChar = newMapping.toFontChar;
  35254. tables['cmap'] = {
  35255. tag: 'cmap',
  35256. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  35257. };
  35258. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  35259. tables['OS/2'] = {
  35260. tag: 'OS/2',
  35261. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  35262. metricsOverride)
  35263. };
  35264. }
  35265. // Rewrite the 'post' table if needed
  35266. if (!tables['post']) {
  35267. tables['post'] = {
  35268. tag: 'post',
  35269. data: createPostTable(properties)
  35270. };
  35271. }
  35272. if (!isTrueType) {
  35273. try {
  35274. // Trying to repair CFF file
  35275. cffFile = new Stream(tables['CFF '].data);
  35276. var parser = new CFFParser(cffFile, properties);
  35277. cff = parser.parse();
  35278. var compiler = new CFFCompiler(cff);
  35279. tables['CFF '].data = compiler.compile();
  35280. } catch (e) {
  35281. warn('Failed to compile font ' + properties.loadedName);
  35282. }
  35283. }
  35284. // Re-creating 'name' table
  35285. if (!tables['name']) {
  35286. tables['name'] = {
  35287. tag: 'name',
  35288. data: createNameTable(this.name)
  35289. };
  35290. } else {
  35291. // ... using existing 'name' table as prototype
  35292. var namePrototype = readNameTable(tables['name']);
  35293. tables['name'].data = createNameTable(name, namePrototype);
  35294. }
  35295. var builder = new OpenTypeFileBuilder(header.version);
  35296. for (var tableTag in tables) {
  35297. builder.addTable(tableTag, tables[tableTag].data);
  35298. }
  35299. return builder.toArray();
  35300. },
  35301. convert: function Font_convert(fontName, font, properties) {
  35302. // TODO: Check the charstring widths to determine this.
  35303. properties.fixedPitch = false;
  35304. var mapping = font.getGlyphMapping(properties);
  35305. var newMapping = adjustMapping(mapping, properties);
  35306. this.toFontChar = newMapping.toFontChar;
  35307. var numGlyphs = font.numGlyphs;
  35308. function getCharCodes(charCodeToGlyphId, glyphId) {
  35309. var charCodes = null;
  35310. for (var charCode in charCodeToGlyphId) {
  35311. if (glyphId === charCodeToGlyphId[charCode]) {
  35312. if (!charCodes) {
  35313. charCodes = [];
  35314. }
  35315. charCodes.push(charCode | 0);
  35316. }
  35317. }
  35318. return charCodes;
  35319. }
  35320. function createCharCode(charCodeToGlyphId, glyphId) {
  35321. for (var charCode in charCodeToGlyphId) {
  35322. if (glyphId === charCodeToGlyphId[charCode]) {
  35323. return charCode | 0;
  35324. }
  35325. }
  35326. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  35327. glyphId;
  35328. return newMapping.nextAvailableFontCharCode++;
  35329. }
  35330. var seacs = font.seacs;
  35331. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  35332. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  35333. var charset = font.getCharset();
  35334. var seacMap = Object.create(null);
  35335. for (var glyphId in seacs) {
  35336. glyphId |= 0;
  35337. var seac = seacs[glyphId];
  35338. var baseGlyphName = StandardEncoding[seac[2]];
  35339. var accentGlyphName = StandardEncoding[seac[3]];
  35340. var baseGlyphId = charset.indexOf(baseGlyphName);
  35341. var accentGlyphId = charset.indexOf(accentGlyphName);
  35342. if (baseGlyphId < 0 || accentGlyphId < 0) {
  35343. continue;
  35344. }
  35345. var accentOffset = {
  35346. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  35347. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  35348. };
  35349. var charCodes = getCharCodes(mapping, glyphId);
  35350. if (!charCodes) {
  35351. // There's no point in mapping it if the char code was never mapped
  35352. // to begin with.
  35353. continue;
  35354. }
  35355. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  35356. var charCode = charCodes[i];
  35357. // Find a fontCharCode that maps to the base and accent glyphs.
  35358. // If one doesn't exists, create it.
  35359. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  35360. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  35361. baseGlyphId);
  35362. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  35363. accentGlyphId);
  35364. seacMap[charCode] = {
  35365. baseFontCharCode: baseFontCharCode,
  35366. accentFontCharCode: accentFontCharCode,
  35367. accentOffset: accentOffset
  35368. };
  35369. }
  35370. }
  35371. properties.seacMap = seacMap;
  35372. }
  35373. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  35374. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  35375. // PostScript Font Program
  35376. builder.addTable('CFF ', font.data);
  35377. // OS/2 and Windows Specific metrics
  35378. builder.addTable('OS/2', createOS2Table(properties,
  35379. newMapping.charCodeToGlyphId));
  35380. // Character to glyphs mapping
  35381. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  35382. numGlyphs));
  35383. // Font header
  35384. builder.addTable('head',
  35385. '\x00\x01\x00\x00' + // Version number
  35386. '\x00\x00\x10\x00' + // fontRevision
  35387. '\x00\x00\x00\x00' + // checksumAdjustement
  35388. '\x5F\x0F\x3C\xF5' + // magicNumber
  35389. '\x00\x00' + // Flags
  35390. safeString16(unitsPerEm) + // unitsPerEM
  35391. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  35392. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  35393. '\x00\x00' + // xMin
  35394. safeString16(properties.descent) + // yMin
  35395. '\x0F\xFF' + // xMax
  35396. safeString16(properties.ascent) + // yMax
  35397. string16(properties.italicAngle ? 2 : 0) + // macStyle
  35398. '\x00\x11' + // lowestRecPPEM
  35399. '\x00\x00' + // fontDirectionHint
  35400. '\x00\x00' + // indexToLocFormat
  35401. '\x00\x00'); // glyphDataFormat
  35402. // Horizontal header
  35403. builder.addTable('hhea',
  35404. '\x00\x01\x00\x00' + // Version number
  35405. safeString16(properties.ascent) + // Typographic Ascent
  35406. safeString16(properties.descent) + // Typographic Descent
  35407. '\x00\x00' + // Line Gap
  35408. '\xFF\xFF' + // advanceWidthMax
  35409. '\x00\x00' + // minLeftSidebearing
  35410. '\x00\x00' + // minRightSidebearing
  35411. '\x00\x00' + // xMaxExtent
  35412. safeString16(properties.capHeight) + // caretSlopeRise
  35413. safeString16(Math.tan(properties.italicAngle) *
  35414. properties.xHeight) + // caretSlopeRun
  35415. '\x00\x00' + // caretOffset
  35416. '\x00\x00' + // -reserved-
  35417. '\x00\x00' + // -reserved-
  35418. '\x00\x00' + // -reserved-
  35419. '\x00\x00' + // -reserved-
  35420. '\x00\x00' + // metricDataFormat
  35421. string16(numGlyphs)); // Number of HMetrics
  35422. // Horizontal metrics
  35423. builder.addTable('hmtx', (function fontFieldsHmtx() {
  35424. var charstrings = font.charstrings;
  35425. var cffWidths = font.cff ? font.cff.widths : null;
  35426. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  35427. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  35428. var width = 0;
  35429. if (charstrings) {
  35430. var charstring = charstrings[i - 1];
  35431. width = 'width' in charstring ? charstring.width : 0;
  35432. } else if (cffWidths) {
  35433. width = Math.ceil(cffWidths[i] || 0);
  35434. }
  35435. hmtx += string16(width) + string16(0);
  35436. }
  35437. return hmtx;
  35438. })());
  35439. // Maximum profile
  35440. builder.addTable('maxp',
  35441. '\x00\x00\x50\x00' + // Version number
  35442. string16(numGlyphs)); // Num of glyphs
  35443. // Naming tables
  35444. builder.addTable('name', createNameTable(fontName));
  35445. // PostScript informations
  35446. builder.addTable('post', createPostTable(properties));
  35447. return builder.toArray();
  35448. },
  35449. /**
  35450. * Builds a char code to unicode map based on section 9.10 of the spec.
  35451. * @param {Object} properties Font properties object.
  35452. * @return {Object} A ToUnicodeMap object.
  35453. */
  35454. buildToUnicode: function Font_buildToUnicode(properties) {
  35455. // Section 9.10.2 Mapping Character Codes to Unicode Values
  35456. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  35457. return properties.toUnicode;
  35458. }
  35459. // According to the spec if the font is a simple font we should only map
  35460. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  35461. // the differences array only contains adobe standard or symbol set names,
  35462. // in pratice it seems better to always try to create a toUnicode
  35463. // map based of the default encoding.
  35464. var toUnicode, charcode;
  35465. if (!properties.composite /* is simple font */) {
  35466. toUnicode = [];
  35467. var encoding = properties.defaultEncoding.slice();
  35468. var baseEncodingName = properties.baseEncodingName;
  35469. // Merge in the differences array.
  35470. var differences = properties.differences;
  35471. for (charcode in differences) {
  35472. encoding[charcode] = differences[charcode];
  35473. }
  35474. var glyphsUnicodeMap = getGlyphsUnicode();
  35475. for (charcode in encoding) {
  35476. // a) Map the character code to a character name.
  35477. var glyphName = encoding[charcode];
  35478. // b) Look up the character name in the Adobe Glyph List (see the
  35479. // Bibliography) to obtain the corresponding Unicode value.
  35480. if (glyphName === '') {
  35481. continue;
  35482. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  35483. // (undocumented) c) Few heuristics to recognize unknown glyphs
  35484. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  35485. var code = 0;
  35486. switch (glyphName[0]) {
  35487. case 'G': // Gxx glyph
  35488. if (glyphName.length === 3) {
  35489. code = parseInt(glyphName.substr(1), 16);
  35490. }
  35491. break;
  35492. case 'g': // g00xx glyph
  35493. if (glyphName.length === 5) {
  35494. code = parseInt(glyphName.substr(1), 16);
  35495. }
  35496. break;
  35497. case 'C': // Cddd glyph
  35498. case 'c': // cddd glyph
  35499. if (glyphName.length >= 3) {
  35500. code = +glyphName.substr(1);
  35501. }
  35502. break;
  35503. }
  35504. if (code) {
  35505. // If |baseEncodingName| is one the predefined encodings,
  35506. // and |code| equals |charcode|, using the glyph defined in the
  35507. // baseEncoding seems to yield a better |toUnicode| mapping
  35508. // (fixes issue 5070).
  35509. if (baseEncodingName && code === +charcode) {
  35510. var baseEncoding = getEncoding(baseEncodingName);
  35511. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  35512. toUnicode[charcode] =
  35513. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  35514. continue;
  35515. }
  35516. }
  35517. toUnicode[charcode] = String.fromCharCode(code);
  35518. }
  35519. continue;
  35520. }
  35521. toUnicode[charcode] =
  35522. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  35523. }
  35524. return new ToUnicodeMap(toUnicode);
  35525. }
  35526. // If the font is a composite font that uses one of the predefined CMaps
  35527. // listed in Table 118 (except Identity–H and Identity–V) or whose
  35528. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  35529. // Adobe-Korea1 character collection:
  35530. if (properties.composite && (
  35531. (properties.cMap.builtInCMap &&
  35532. !(properties.cMap instanceof IdentityCMap)) ||
  35533. (properties.cidSystemInfo.registry === 'Adobe' &&
  35534. (properties.cidSystemInfo.ordering === 'GB1' ||
  35535. properties.cidSystemInfo.ordering === 'CNS1' ||
  35536. properties.cidSystemInfo.ordering === 'Japan1' ||
  35537. properties.cidSystemInfo.ordering === 'Korea1')))) {
  35538. // Then:
  35539. // a) Map the character code to a character identifier (CID) according
  35540. // to the font’s CMap.
  35541. // b) Obtain the registry and ordering of the character collection used
  35542. // by the font’s CMap (for example, Adobe and Japan1) from its
  35543. // CIDSystemInfo dictionary.
  35544. var registry = properties.cidSystemInfo.registry;
  35545. var ordering = properties.cidSystemInfo.ordering;
  35546. // c) Construct a second CMap name by concatenating the registry and
  35547. // ordering obtained in step (b) in the format registry–ordering–UCS2
  35548. // (for example, Adobe–Japan1–UCS2).
  35549. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  35550. // d) Obtain the CMap with the name constructed in step (c) (available
  35551. // from the ASN Web site; see the Bibliography).
  35552. var ucs2CMap = CMapFactory.create(ucs2CMapName,
  35553. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  35554. var cMap = properties.cMap;
  35555. toUnicode = [];
  35556. cMap.forEach(function(charcode, cid) {
  35557. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  35558. // e) Map the CID obtained in step (a) according to the CMap obtained
  35559. // in step (d), producing a Unicode value.
  35560. var ucs2 = ucs2CMap.lookup(cid);
  35561. if (ucs2) {
  35562. toUnicode[charcode] =
  35563. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  35564. ucs2.charCodeAt(1));
  35565. }
  35566. });
  35567. return new ToUnicodeMap(toUnicode);
  35568. }
  35569. // The viewer's choice, just use an identity map.
  35570. return new IdentityToUnicodeMap(properties.firstChar,
  35571. properties.lastChar);
  35572. },
  35573. get spaceWidth() {
  35574. if ('_shadowWidth' in this) {
  35575. return this._shadowWidth;
  35576. }
  35577. // trying to estimate space character width
  35578. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  35579. var width;
  35580. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  35581. var glyphName = possibleSpaceReplacements[i];
  35582. // if possible, getting width by glyph name
  35583. if (glyphName in this.widths) {
  35584. width = this.widths[glyphName];
  35585. break;
  35586. }
  35587. var glyphsUnicodeMap = getGlyphsUnicode();
  35588. var glyphUnicode = glyphsUnicodeMap[glyphName];
  35589. // finding the charcode via unicodeToCID map
  35590. var charcode = 0;
  35591. if (this.composite) {
  35592. if (this.cMap.contains(glyphUnicode)) {
  35593. charcode = this.cMap.lookup(glyphUnicode);
  35594. }
  35595. }
  35596. // ... via toUnicode map
  35597. if (!charcode && this.toUnicode) {
  35598. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  35599. }
  35600. // setting it to unicode if negative or undefined
  35601. if (charcode <= 0) {
  35602. charcode = glyphUnicode;
  35603. }
  35604. // trying to get width via charcode
  35605. width = this.widths[charcode];
  35606. if (width) {
  35607. break; // the non-zero width found
  35608. }
  35609. }
  35610. width = width || this.defaultWidth;
  35611. // Do not shadow the property here. See discussion:
  35612. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  35613. this._shadowWidth = width;
  35614. return width;
  35615. },
  35616. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  35617. var fontCharCode, width, operatorListId;
  35618. var widthCode = charcode;
  35619. if (this.cMap && this.cMap.contains(charcode)) {
  35620. widthCode = this.cMap.lookup(charcode);
  35621. }
  35622. width = this.widths[widthCode];
  35623. width = isNum(width) ? width : this.defaultWidth;
  35624. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  35625. var unicode = this.toUnicode.get(charcode) || charcode;
  35626. if (typeof unicode === 'number') {
  35627. unicode = String.fromCharCode(unicode);
  35628. }
  35629. // First try the toFontChar map, if it's not there then try falling
  35630. // back to the char code.
  35631. fontCharCode = this.toFontChar[charcode] || charcode;
  35632. if (this.missingFile) {
  35633. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  35634. }
  35635. if (this.isType3Font) {
  35636. // Font char code in this case is actually a glyph name.
  35637. operatorListId = fontCharCode;
  35638. }
  35639. var accent = null;
  35640. if (this.seacMap && this.seacMap[charcode]) {
  35641. var seac = this.seacMap[charcode];
  35642. fontCharCode = seac.baseFontCharCode;
  35643. accent = {
  35644. fontChar: String.fromCharCode(seac.accentFontCharCode),
  35645. offset: seac.accentOffset
  35646. };
  35647. }
  35648. var fontChar = String.fromCharCode(fontCharCode);
  35649. var glyph = this.glyphCache[charcode];
  35650. if (!glyph ||
  35651. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  35652. operatorListId, isSpace)) {
  35653. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  35654. operatorListId, isSpace);
  35655. this.glyphCache[charcode] = glyph;
  35656. }
  35657. return glyph;
  35658. },
  35659. charsToGlyphs: function Font_charsToGlyphs(chars) {
  35660. var charsCache = this.charsCache;
  35661. var glyphs, glyph, charcode;
  35662. // if we translated this string before, just grab it from the cache
  35663. if (charsCache) {
  35664. glyphs = charsCache[chars];
  35665. if (glyphs) {
  35666. return glyphs;
  35667. }
  35668. }
  35669. // lazily create the translation cache
  35670. if (!charsCache) {
  35671. charsCache = this.charsCache = Object.create(null);
  35672. }
  35673. glyphs = [];
  35674. var charsCacheKey = chars;
  35675. var i = 0, ii;
  35676. if (this.cMap) {
  35677. // composite fonts have multi-byte strings convert the string from
  35678. // single-byte to multi-byte
  35679. var c = Object.create(null);
  35680. while (i < chars.length) {
  35681. this.cMap.readCharCode(chars, i, c);
  35682. charcode = c.charcode;
  35683. var length = c.length;
  35684. i += length;
  35685. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  35686. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  35687. glyph = this.charToGlyph(charcode, isSpace);
  35688. glyphs.push(glyph);
  35689. }
  35690. } else {
  35691. for (i = 0, ii = chars.length; i < ii; ++i) {
  35692. charcode = chars.charCodeAt(i);
  35693. glyph = this.charToGlyph(charcode, charcode === 0x20);
  35694. glyphs.push(glyph);
  35695. }
  35696. }
  35697. // Enter the translated string into the cache
  35698. return (charsCache[charsCacheKey] = glyphs);
  35699. }
  35700. };
  35701. return Font;
  35702. })();
  35703. var ErrorFont = (function ErrorFontClosure() {
  35704. function ErrorFont(error) {
  35705. this.error = error;
  35706. this.loadedName = 'g_font_error';
  35707. this.loading = false;
  35708. }
  35709. ErrorFont.prototype = {
  35710. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  35711. return [];
  35712. },
  35713. exportData: function ErrorFont_exportData() {
  35714. return {error: this.error};
  35715. }
  35716. };
  35717. return ErrorFont;
  35718. })();
  35719. /**
  35720. * Shared logic for building a char code to glyph id mapping for Type1 and
  35721. * simple CFF fonts. See section 9.6.6.2 of the spec.
  35722. * @param {Object} properties Font properties object.
  35723. * @param {Object} builtInEncoding The encoding contained within the actual font
  35724. * data.
  35725. * @param {Array} Array of glyph names where the index is the glyph ID.
  35726. * @returns {Object} A char code to glyph ID map.
  35727. */
  35728. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  35729. var charCodeToGlyphId = Object.create(null);
  35730. var glyphId, charCode, baseEncoding;
  35731. if (properties.baseEncodingName) {
  35732. // If a valid base encoding name was used, the mapping is initialized with
  35733. // that.
  35734. baseEncoding = getEncoding(properties.baseEncodingName);
  35735. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  35736. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  35737. if (glyphId >= 0) {
  35738. charCodeToGlyphId[charCode] = glyphId;
  35739. } else {
  35740. charCodeToGlyphId[charCode] = 0; // notdef
  35741. }
  35742. }
  35743. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  35744. // For a symbolic font the encoding should be the fonts built-in
  35745. // encoding.
  35746. for (charCode in builtInEncoding) {
  35747. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  35748. }
  35749. } else {
  35750. // For non-symbolic fonts that don't have a base encoding the standard
  35751. // encoding should be used.
  35752. baseEncoding = StandardEncoding;
  35753. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  35754. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  35755. if (glyphId >= 0) {
  35756. charCodeToGlyphId[charCode] = glyphId;
  35757. } else {
  35758. charCodeToGlyphId[charCode] = 0; // notdef
  35759. }
  35760. }
  35761. }
  35762. // Lastly, merge in the differences.
  35763. var differences = properties.differences;
  35764. if (differences) {
  35765. for (charCode in differences) {
  35766. var glyphName = differences[charCode];
  35767. glyphId = glyphNames.indexOf(glyphName);
  35768. if (glyphId >= 0) {
  35769. charCodeToGlyphId[charCode] = glyphId;
  35770. } else {
  35771. charCodeToGlyphId[charCode] = 0; // notdef
  35772. }
  35773. }
  35774. }
  35775. return charCodeToGlyphId;
  35776. }
  35777. /*
  35778. * CharStrings are encoded following the the CharString Encoding sequence
  35779. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  35780. * The value in a byte indicates a command, a number, or subsequent bytes
  35781. * that are to be interpreted in a special way.
  35782. *
  35783. * CharString Number Encoding:
  35784. * A CharString byte containing the values from 32 through 255 inclusive
  35785. * indicate an integer. These values are decoded in four ranges.
  35786. *
  35787. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  35788. * indicate the integer v - 139. Thus, the integer values from -107 through
  35789. * 107 inclusive may be encoded in single byte.
  35790. *
  35791. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  35792. * indicates an integer involving the next byte, w, according to the formula:
  35793. * [(v - 247) x 256] + w + 108
  35794. *
  35795. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  35796. * indicates an integer involving the next byte, w, according to the formula:
  35797. * -[(v - 251) * 256] - w - 108
  35798. *
  35799. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  35800. * are a two complement signed integer. The first of these bytes contains the
  35801. * highest order bits, the second byte contains the next higher order bits
  35802. * and the fourth byte contain the lowest order bits.
  35803. *
  35804. *
  35805. * CharString Command Encoding:
  35806. * CharStrings commands are encoded in 1 or 2 bytes.
  35807. *
  35808. * Single byte commands are encoded in 1 byte that contains a value between
  35809. * 0 and 31 inclusive.
  35810. * If a command byte contains the value 12, then the value in the next byte
  35811. * indicates a command. This "escape" mechanism allows many extra commands
  35812. * to be encoded and this encoding technique helps to minimize the length of
  35813. * the charStrings.
  35814. */
  35815. var Type1CharString = (function Type1CharStringClosure() {
  35816. var COMMAND_MAP = {
  35817. 'hstem': [1],
  35818. 'vstem': [3],
  35819. 'vmoveto': [4],
  35820. 'rlineto': [5],
  35821. 'hlineto': [6],
  35822. 'vlineto': [7],
  35823. 'rrcurveto': [8],
  35824. 'callsubr': [10],
  35825. 'flex': [12, 35],
  35826. 'drop' : [12, 18],
  35827. 'endchar': [14],
  35828. 'rmoveto': [21],
  35829. 'hmoveto': [22],
  35830. 'vhcurveto': [30],
  35831. 'hvcurveto': [31]
  35832. };
  35833. function Type1CharString() {
  35834. this.width = 0;
  35835. this.lsb = 0;
  35836. this.flexing = false;
  35837. this.output = [];
  35838. this.stack = [];
  35839. }
  35840. Type1CharString.prototype = {
  35841. convert: function Type1CharString_convert(encoded, subrs) {
  35842. var count = encoded.length;
  35843. var error = false;
  35844. var wx, sbx, subrNumber;
  35845. for (var i = 0; i < count; i++) {
  35846. var value = encoded[i];
  35847. if (value < 32) {
  35848. if (value === 12) {
  35849. value = (value << 8) + encoded[++i];
  35850. }
  35851. switch (value) {
  35852. case 1: // hstem
  35853. if (!HINTING_ENABLED) {
  35854. this.stack = [];
  35855. break;
  35856. }
  35857. error = this.executeCommand(2, COMMAND_MAP.hstem);
  35858. break;
  35859. case 3: // vstem
  35860. if (!HINTING_ENABLED) {
  35861. this.stack = [];
  35862. break;
  35863. }
  35864. error = this.executeCommand(2, COMMAND_MAP.vstem);
  35865. break;
  35866. case 4: // vmoveto
  35867. if (this.flexing) {
  35868. if (this.stack.length < 1) {
  35869. error = true;
  35870. break;
  35871. }
  35872. // Add the dx for flex and but also swap the values so they are
  35873. // the right order.
  35874. var dy = this.stack.pop();
  35875. this.stack.push(0, dy);
  35876. break;
  35877. }
  35878. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  35879. break;
  35880. case 5: // rlineto
  35881. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  35882. break;
  35883. case 6: // hlineto
  35884. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  35885. break;
  35886. case 7: // vlineto
  35887. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  35888. break;
  35889. case 8: // rrcurveto
  35890. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  35891. break;
  35892. case 9: // closepath
  35893. // closepath is a Type1 command that does not take argument and is
  35894. // useless in Type2 and it can simply be ignored.
  35895. this.stack = [];
  35896. break;
  35897. case 10: // callsubr
  35898. if (this.stack.length < 1) {
  35899. error = true;
  35900. break;
  35901. }
  35902. subrNumber = this.stack.pop();
  35903. error = this.convert(subrs[subrNumber], subrs);
  35904. break;
  35905. case 11: // return
  35906. return error;
  35907. case 13: // hsbw
  35908. if (this.stack.length < 2) {
  35909. error = true;
  35910. break;
  35911. }
  35912. // To convert to type2 we have to move the width value to the
  35913. // first part of the charstring and then use hmoveto with lsb.
  35914. wx = this.stack.pop();
  35915. sbx = this.stack.pop();
  35916. this.lsb = sbx;
  35917. this.width = wx;
  35918. this.stack.push(wx, sbx);
  35919. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  35920. break;
  35921. case 14: // endchar
  35922. this.output.push(COMMAND_MAP.endchar[0]);
  35923. break;
  35924. case 21: // rmoveto
  35925. if (this.flexing) {
  35926. break;
  35927. }
  35928. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  35929. break;
  35930. case 22: // hmoveto
  35931. if (this.flexing) {
  35932. // Add the dy for flex.
  35933. this.stack.push(0);
  35934. break;
  35935. }
  35936. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  35937. break;
  35938. case 30: // vhcurveto
  35939. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  35940. break;
  35941. case 31: // hvcurveto
  35942. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  35943. break;
  35944. case (12 << 8) + 0: // dotsection
  35945. // dotsection is a Type1 command to specify some hinting feature
  35946. // for dots that do not take a parameter and it can safely be
  35947. // ignored for Type2.
  35948. this.stack = [];
  35949. break;
  35950. case (12 << 8) + 1: // vstem3
  35951. if (!HINTING_ENABLED) {
  35952. this.stack = [];
  35953. break;
  35954. }
  35955. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  35956. // multiple parameters, so instead of returning [vh]stem3 take a
  35957. // shortcut and return [vhstem] instead.
  35958. error = this.executeCommand(2, COMMAND_MAP.vstem);
  35959. break;
  35960. case (12 << 8) + 2: // hstem3
  35961. if (!HINTING_ENABLED) {
  35962. this.stack = [];
  35963. break;
  35964. }
  35965. // See vstem3.
  35966. error = this.executeCommand(2, COMMAND_MAP.hstem);
  35967. break;
  35968. case (12 << 8) + 6: // seac
  35969. // seac is like type 2's special endchar but it doesn't use the
  35970. // first argument asb, so remove it.
  35971. if (SEAC_ANALYSIS_ENABLED) {
  35972. this.seac = this.stack.splice(-4, 4);
  35973. error = this.executeCommand(0, COMMAND_MAP.endchar);
  35974. } else {
  35975. error = this.executeCommand(4, COMMAND_MAP.endchar);
  35976. }
  35977. break;
  35978. case (12 << 8) + 7: // sbw
  35979. if (this.stack.length < 4) {
  35980. error = true;
  35981. break;
  35982. }
  35983. // To convert to type2 we have to move the width value to the
  35984. // first part of the charstring and then use rmoveto with
  35985. // (dx, dy). The height argument will not be used for vmtx and
  35986. // vhea tables reconstruction -- ignoring it.
  35987. var wy = this.stack.pop();
  35988. wx = this.stack.pop();
  35989. var sby = this.stack.pop();
  35990. sbx = this.stack.pop();
  35991. this.lsb = sbx;
  35992. this.width = wx;
  35993. this.stack.push(wx, sbx, sby);
  35994. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  35995. break;
  35996. case (12 << 8) + 12: // div
  35997. if (this.stack.length < 2) {
  35998. error = true;
  35999. break;
  36000. }
  36001. var num2 = this.stack.pop();
  36002. var num1 = this.stack.pop();
  36003. this.stack.push(num1 / num2);
  36004. break;
  36005. case (12 << 8) + 16: // callothersubr
  36006. if (this.stack.length < 2) {
  36007. error = true;
  36008. break;
  36009. }
  36010. subrNumber = this.stack.pop();
  36011. var numArgs = this.stack.pop();
  36012. if (subrNumber === 0 && numArgs === 3) {
  36013. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  36014. this.stack.push(
  36015. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  36016. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  36017. flexArgs[4], // bcp2x
  36018. flexArgs[5], // bcp2y
  36019. flexArgs[6], // p2x
  36020. flexArgs[7], // p2y
  36021. flexArgs[8], // bcp3x
  36022. flexArgs[9], // bcp3y
  36023. flexArgs[10], // bcp4x
  36024. flexArgs[11], // bcp4y
  36025. flexArgs[12], // p3x
  36026. flexArgs[13], // p3y
  36027. flexArgs[14] // flexDepth
  36028. // 15 = finalx unused by flex
  36029. // 16 = finaly unused by flex
  36030. );
  36031. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  36032. this.flexing = false;
  36033. this.stack.push(flexArgs[15], flexArgs[16]);
  36034. } else if (subrNumber === 1 && numArgs === 0) {
  36035. this.flexing = true;
  36036. }
  36037. break;
  36038. case (12 << 8) + 17: // pop
  36039. // Ignore this since it is only used with othersubr.
  36040. break;
  36041. case (12 << 8) + 33: // setcurrentpoint
  36042. // Ignore for now.
  36043. this.stack = [];
  36044. break;
  36045. default:
  36046. warn('Unknown type 1 charstring command of "' + value + '"');
  36047. break;
  36048. }
  36049. if (error) {
  36050. break;
  36051. }
  36052. continue;
  36053. } else if (value <= 246) {
  36054. value = value - 139;
  36055. } else if (value <= 250) {
  36056. value = ((value - 247) * 256) + encoded[++i] + 108;
  36057. } else if (value <= 254) {
  36058. value = -((value - 251) * 256) - encoded[++i] - 108;
  36059. } else {
  36060. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  36061. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  36062. }
  36063. this.stack.push(value);
  36064. }
  36065. return error;
  36066. },
  36067. executeCommand: function(howManyArgs, command, keepStack) {
  36068. var stackLength = this.stack.length;
  36069. if (howManyArgs > stackLength) {
  36070. return true;
  36071. }
  36072. var start = stackLength - howManyArgs;
  36073. for (var i = start; i < stackLength; i++) {
  36074. var value = this.stack[i];
  36075. if (value === (value | 0)) { // int
  36076. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  36077. } else { // fixed point
  36078. value = (65536 * value) | 0;
  36079. this.output.push(255,
  36080. (value >> 24) & 0xFF,
  36081. (value >> 16) & 0xFF,
  36082. (value >> 8) & 0xFF,
  36083. value & 0xFF);
  36084. }
  36085. }
  36086. this.output.push.apply(this.output, command);
  36087. if (keepStack) {
  36088. this.stack.splice(start, howManyArgs);
  36089. } else {
  36090. this.stack.length = 0;
  36091. }
  36092. return false;
  36093. }
  36094. };
  36095. return Type1CharString;
  36096. })();
  36097. /*
  36098. * Type1Parser encapsulate the needed code for parsing a Type1 font
  36099. * program. Some of its logic depends on the Type2 charstrings
  36100. * structure.
  36101. * Note: this doesn't really parse the font since that would require evaluation
  36102. * of PostScript, but it is possible in most cases to extract what we need
  36103. * without a full parse.
  36104. */
  36105. var Type1Parser = (function Type1ParserClosure() {
  36106. /*
  36107. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  36108. * of Plaintext Bytes. The function took a key as a parameter which can be
  36109. * for decrypting the eexec block of for decoding charStrings.
  36110. */
  36111. var EEXEC_ENCRYPT_KEY = 55665;
  36112. var CHAR_STRS_ENCRYPT_KEY = 4330;
  36113. function isHexDigit(code) {
  36114. return code >= 48 && code <= 57 || // '0'-'9'
  36115. code >= 65 && code <= 70 || // 'A'-'F'
  36116. code >= 97 && code <= 102; // 'a'-'f'
  36117. }
  36118. function decrypt(data, key, discardNumber) {
  36119. if (discardNumber >= data.length) {
  36120. return new Uint8Array(0);
  36121. }
  36122. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  36123. for (i = 0; i < discardNumber; i++) {
  36124. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  36125. }
  36126. var count = data.length - discardNumber;
  36127. var decrypted = new Uint8Array(count);
  36128. for (i = discardNumber, j = 0; j < count; i++, j++) {
  36129. var value = data[i];
  36130. decrypted[j] = value ^ (r >> 8);
  36131. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  36132. }
  36133. return decrypted;
  36134. }
  36135. function decryptAscii(data, key, discardNumber) {
  36136. var r = key | 0, c1 = 52845, c2 = 22719;
  36137. var count = data.length, maybeLength = count >>> 1;
  36138. var decrypted = new Uint8Array(maybeLength);
  36139. var i, j;
  36140. for (i = 0, j = 0; i < count; i++) {
  36141. var digit1 = data[i];
  36142. if (!isHexDigit(digit1)) {
  36143. continue;
  36144. }
  36145. i++;
  36146. var digit2;
  36147. while (i < count && !isHexDigit(digit2 = data[i])) {
  36148. i++;
  36149. }
  36150. if (i < count) {
  36151. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  36152. decrypted[j++] = value ^ (r >> 8);
  36153. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  36154. }
  36155. }
  36156. return Array.prototype.slice.call(decrypted, discardNumber, j);
  36157. }
  36158. function isSpecial(c) {
  36159. return c === 0x2F || // '/'
  36160. c === 0x5B || c === 0x5D || // '[', ']'
  36161. c === 0x7B || c === 0x7D || // '{', '}'
  36162. c === 0x28 || c === 0x29; // '(', ')'
  36163. }
  36164. function Type1Parser(stream, encrypted) {
  36165. if (encrypted) {
  36166. var data = stream.getBytes();
  36167. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  36168. isHexDigit(data[2]) && isHexDigit(data[3]));
  36169. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  36170. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  36171. }
  36172. this.stream = stream;
  36173. this.nextChar();
  36174. }
  36175. Type1Parser.prototype = {
  36176. readNumberArray: function Type1Parser_readNumberArray() {
  36177. this.getToken(); // read '[' or '{' (arrays can start with either)
  36178. var array = [];
  36179. while (true) {
  36180. var token = this.getToken();
  36181. if (token === null || token === ']' || token === '}') {
  36182. break;
  36183. }
  36184. array.push(parseFloat(token || 0));
  36185. }
  36186. return array;
  36187. },
  36188. readNumber: function Type1Parser_readNumber() {
  36189. var token = this.getToken();
  36190. return parseFloat(token || 0);
  36191. },
  36192. readInt: function Type1Parser_readInt() {
  36193. // Use '| 0' to prevent setting a double into length such as the double
  36194. // does not flow into the loop variable.
  36195. var token = this.getToken();
  36196. return parseInt(token || 0, 10) | 0;
  36197. },
  36198. readBoolean: function Type1Parser_readBoolean() {
  36199. var token = this.getToken();
  36200. // Use 1 and 0 since that's what type2 charstrings use.
  36201. return token === 'true' ? 1 : 0;
  36202. },
  36203. nextChar : function Type1_nextChar() {
  36204. return (this.currentChar = this.stream.getByte());
  36205. },
  36206. getToken: function Type1Parser_getToken() {
  36207. // Eat whitespace and comments.
  36208. var comment = false;
  36209. var ch = this.currentChar;
  36210. while (true) {
  36211. if (ch === -1) {
  36212. return null;
  36213. }
  36214. if (comment) {
  36215. if (ch === 0x0A || ch === 0x0D) {
  36216. comment = false;
  36217. }
  36218. } else if (ch === 0x25) { // '%'
  36219. comment = true;
  36220. } else if (!Lexer.isSpace(ch)) {
  36221. break;
  36222. }
  36223. ch = this.nextChar();
  36224. }
  36225. if (isSpecial(ch)) {
  36226. this.nextChar();
  36227. return String.fromCharCode(ch);
  36228. }
  36229. var token = '';
  36230. do {
  36231. token += String.fromCharCode(ch);
  36232. ch = this.nextChar();
  36233. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  36234. return token;
  36235. },
  36236. /*
  36237. * Returns an object containing a Subrs array and a CharStrings
  36238. * array extracted from and eexec encrypted block of data
  36239. */
  36240. extractFontProgram: function Type1Parser_extractFontProgram() {
  36241. var stream = this.stream;
  36242. var subrs = [], charstrings = [];
  36243. var privateData = Object.create(null);
  36244. privateData['lenIV'] = 4;
  36245. var program = {
  36246. subrs: [],
  36247. charstrings: [],
  36248. properties: {
  36249. 'privateData': privateData
  36250. }
  36251. };
  36252. var token, length, data, lenIV, encoded;
  36253. while ((token = this.getToken()) !== null) {
  36254. if (token !== '/') {
  36255. continue;
  36256. }
  36257. token = this.getToken();
  36258. switch (token) {
  36259. case 'CharStrings':
  36260. // The number immediately following CharStrings must be greater or
  36261. // equal to the number of CharStrings.
  36262. this.getToken();
  36263. this.getToken(); // read in 'dict'
  36264. this.getToken(); // read in 'dup'
  36265. this.getToken(); // read in 'begin'
  36266. while(true) {
  36267. token = this.getToken();
  36268. if (token === null || token === 'end') {
  36269. break;
  36270. }
  36271. if (token !== '/') {
  36272. continue;
  36273. }
  36274. var glyph = this.getToken();
  36275. length = this.readInt();
  36276. this.getToken(); // read in 'RD' or '-|'
  36277. data = stream.makeSubStream(stream.pos, length);
  36278. lenIV = program.properties.privateData['lenIV'];
  36279. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  36280. // Skip past the required space and binary data.
  36281. stream.skip(length);
  36282. this.nextChar();
  36283. token = this.getToken(); // read in 'ND' or '|-'
  36284. if (token === 'noaccess') {
  36285. this.getToken(); // read in 'def'
  36286. }
  36287. charstrings.push({
  36288. glyph: glyph,
  36289. encoded: encoded
  36290. });
  36291. }
  36292. break;
  36293. case 'Subrs':
  36294. var num = this.readInt();
  36295. this.getToken(); // read in 'array'
  36296. while ((token = this.getToken()) === 'dup') {
  36297. var index = this.readInt();
  36298. length = this.readInt();
  36299. this.getToken(); // read in 'RD' or '-|'
  36300. data = stream.makeSubStream(stream.pos, length);
  36301. lenIV = program.properties.privateData['lenIV'];
  36302. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  36303. // Skip past the required space and binary data.
  36304. stream.skip(length);
  36305. this.nextChar();
  36306. token = this.getToken(); // read in 'NP' or '|'
  36307. if (token === 'noaccess') {
  36308. this.getToken(); // read in 'put'
  36309. }
  36310. subrs[index] = encoded;
  36311. }
  36312. break;
  36313. case 'BlueValues':
  36314. case 'OtherBlues':
  36315. case 'FamilyBlues':
  36316. case 'FamilyOtherBlues':
  36317. var blueArray = this.readNumberArray();
  36318. // *Blue* values may contain invalid data: disables reading of
  36319. // those values when hinting is disabled.
  36320. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  36321. HINTING_ENABLED) {
  36322. program.properties.privateData[token] = blueArray;
  36323. }
  36324. break;
  36325. case 'StemSnapH':
  36326. case 'StemSnapV':
  36327. program.properties.privateData[token] = this.readNumberArray();
  36328. break;
  36329. case 'StdHW':
  36330. case 'StdVW':
  36331. program.properties.privateData[token] =
  36332. this.readNumberArray()[0];
  36333. break;
  36334. case 'BlueShift':
  36335. case 'lenIV':
  36336. case 'BlueFuzz':
  36337. case 'BlueScale':
  36338. case 'LanguageGroup':
  36339. case 'ExpansionFactor':
  36340. program.properties.privateData[token] = this.readNumber();
  36341. break;
  36342. case 'ForceBold':
  36343. program.properties.privateData[token] = this.readBoolean();
  36344. break;
  36345. }
  36346. }
  36347. for (var i = 0; i < charstrings.length; i++) {
  36348. glyph = charstrings[i].glyph;
  36349. encoded = charstrings[i].encoded;
  36350. var charString = new Type1CharString();
  36351. var error = charString.convert(encoded, subrs);
  36352. var output = charString.output;
  36353. if (error) {
  36354. // It seems when FreeType encounters an error while evaluating a glyph
  36355. // that it completely ignores the glyph so we'll mimic that behaviour
  36356. // here and put an endchar to make the validator happy.
  36357. output = [14];
  36358. }
  36359. program.charstrings.push({
  36360. glyphName: glyph,
  36361. charstring: output,
  36362. width: charString.width,
  36363. lsb: charString.lsb,
  36364. seac: charString.seac
  36365. });
  36366. }
  36367. return program;
  36368. },
  36369. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  36370. var token;
  36371. while ((token = this.getToken()) !== null) {
  36372. if (token !== '/') {
  36373. continue;
  36374. }
  36375. token = this.getToken();
  36376. switch (token) {
  36377. case 'FontMatrix':
  36378. var matrix = this.readNumberArray();
  36379. properties.fontMatrix = matrix;
  36380. break;
  36381. case 'Encoding':
  36382. var encodingArg = this.getToken();
  36383. var encoding;
  36384. if (!/^\d+$/.test(encodingArg)) {
  36385. // encoding name is specified
  36386. encoding = getEncoding(encodingArg);
  36387. } else {
  36388. encoding = [];
  36389. var size = parseInt(encodingArg, 10) | 0;
  36390. this.getToken(); // read in 'array'
  36391. for (var j = 0; j < size; j++) {
  36392. token = this.getToken();
  36393. // skipping till first dup or def (e.g. ignoring for statement)
  36394. while (token !== 'dup' && token !== 'def') {
  36395. token = this.getToken();
  36396. if (token === null) {
  36397. return; // invalid header
  36398. }
  36399. }
  36400. if (token === 'def') {
  36401. break; // read all array data
  36402. }
  36403. var index = this.readInt();
  36404. this.getToken(); // read in '/'
  36405. var glyph = this.getToken();
  36406. encoding[index] = glyph;
  36407. this.getToken(); // read the in 'put'
  36408. }
  36409. }
  36410. properties.builtInEncoding = encoding;
  36411. break;
  36412. case 'FontBBox':
  36413. var fontBBox = this.readNumberArray();
  36414. // adjusting ascent/descent
  36415. properties.ascent = fontBBox[3];
  36416. properties.descent = fontBBox[1];
  36417. properties.ascentScaled = true;
  36418. break;
  36419. }
  36420. }
  36421. }
  36422. };
  36423. return Type1Parser;
  36424. })();
  36425. /**
  36426. * The CFF class takes a Type1 file and wrap it into a
  36427. * 'Compact Font Format' which itself embed Type2 charstrings.
  36428. */
  36429. var CFFStandardStrings = [
  36430. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  36431. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  36432. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  36433. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  36434. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  36435. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  36436. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  36437. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  36438. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  36439. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  36440. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  36441. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  36442. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  36443. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  36444. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  36445. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  36446. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  36447. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  36448. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  36449. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  36450. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  36451. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  36452. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  36453. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  36454. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  36455. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  36456. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  36457. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  36458. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  36459. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  36460. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  36461. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  36462. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  36463. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  36464. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  36465. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  36466. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  36467. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  36468. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  36469. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  36470. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  36471. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  36472. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  36473. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  36474. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  36475. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  36476. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  36477. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  36478. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  36479. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  36480. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  36481. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  36482. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  36483. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  36484. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  36485. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  36486. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  36487. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  36488. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  36489. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  36490. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  36491. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  36492. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  36493. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  36494. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  36495. ];
  36496. // Type1Font is also a CIDFontType0.
  36497. var Type1Font = function Type1Font(name, file, properties) {
  36498. // Some bad generators embed pfb file as is, we have to strip 6-byte headers.
  36499. // Also, length1 and length2 might be off by 6 bytes as well.
  36500. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  36501. var PFB_HEADER_SIZE = 6;
  36502. var headerBlockLength = properties.length1;
  36503. var eexecBlockLength = properties.length2;
  36504. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  36505. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  36506. if (pfbHeaderPresent) {
  36507. file.skip(PFB_HEADER_SIZE);
  36508. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  36509. (pfbHeader[3] << 8) | pfbHeader[2];
  36510. }
  36511. // Get the data block containing glyphs and subrs informations
  36512. var headerBlock = new Stream(file.getBytes(headerBlockLength));
  36513. var headerBlockParser = new Type1Parser(headerBlock);
  36514. headerBlockParser.extractFontHeader(properties);
  36515. if (pfbHeaderPresent) {
  36516. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  36517. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  36518. (pfbHeader[3] << 8) | pfbHeader[2];
  36519. }
  36520. // Decrypt the data blocks and retrieve it's content
  36521. var eexecBlock = new Stream(file.getBytes(eexecBlockLength));
  36522. var eexecBlockParser = new Type1Parser(eexecBlock, true);
  36523. var data = eexecBlockParser.extractFontProgram();
  36524. for (var info in data.properties) {
  36525. properties[info] = data.properties[info];
  36526. }
  36527. var charstrings = data.charstrings;
  36528. var type2Charstrings = this.getType2Charstrings(charstrings);
  36529. var subrs = this.getType2Subrs(data.subrs);
  36530. this.charstrings = charstrings;
  36531. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  36532. subrs, properties);
  36533. this.seacs = this.getSeacs(data.charstrings);
  36534. };
  36535. Type1Font.prototype = {
  36536. get numGlyphs() {
  36537. return this.charstrings.length + 1;
  36538. },
  36539. getCharset: function Type1Font_getCharset() {
  36540. var charset = ['.notdef'];
  36541. var charstrings = this.charstrings;
  36542. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  36543. charset.push(charstrings[glyphId].glyphName);
  36544. }
  36545. return charset;
  36546. },
  36547. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  36548. var charstrings = this.charstrings;
  36549. var glyphNames = ['.notdef'], glyphId;
  36550. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  36551. glyphNames.push(charstrings[glyphId].glyphName);
  36552. }
  36553. var encoding = properties.builtInEncoding;
  36554. if (encoding) {
  36555. var builtInEncoding = Object.create(null);
  36556. for (var charCode in encoding) {
  36557. glyphId = glyphNames.indexOf(encoding[charCode]);
  36558. if (glyphId >= 0) {
  36559. builtInEncoding[charCode] = glyphId;
  36560. }
  36561. }
  36562. }
  36563. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  36564. },
  36565. getSeacs: function Type1Font_getSeacs(charstrings) {
  36566. var i, ii;
  36567. var seacMap = [];
  36568. for (i = 0, ii = charstrings.length; i < ii; i++) {
  36569. var charstring = charstrings[i];
  36570. if (charstring.seac) {
  36571. // Offset by 1 for .notdef
  36572. seacMap[i + 1] = charstring.seac;
  36573. }
  36574. }
  36575. return seacMap;
  36576. },
  36577. getType2Charstrings: function Type1Font_getType2Charstrings(
  36578. type1Charstrings) {
  36579. var type2Charstrings = [];
  36580. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  36581. type2Charstrings.push(type1Charstrings[i].charstring);
  36582. }
  36583. return type2Charstrings;
  36584. },
  36585. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  36586. var bias = 0;
  36587. var count = type1Subrs.length;
  36588. if (count < 1133) {
  36589. bias = 107;
  36590. } else if (count < 33769) {
  36591. bias = 1131;
  36592. } else {
  36593. bias = 32768;
  36594. }
  36595. // Add a bunch of empty subrs to deal with the Type2 bias
  36596. var type2Subrs = [];
  36597. var i;
  36598. for (i = 0; i < bias; i++) {
  36599. type2Subrs.push([0x0B]);
  36600. }
  36601. for (i = 0; i < count; i++) {
  36602. type2Subrs.push(type1Subrs[i]);
  36603. }
  36604. return type2Subrs;
  36605. },
  36606. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs, properties) {
  36607. var cff = new CFF();
  36608. cff.header = new CFFHeader(1, 0, 4, 4);
  36609. cff.names = [name];
  36610. var topDict = new CFFTopDict();
  36611. // CFF strings IDs 0...390 are predefined names, so refering
  36612. // to entries in our own String INDEX starts at SID 391.
  36613. topDict.setByName('version', 391);
  36614. topDict.setByName('Notice', 392);
  36615. topDict.setByName('FullName', 393);
  36616. topDict.setByName('FamilyName', 394);
  36617. topDict.setByName('Weight', 395);
  36618. topDict.setByName('Encoding', null); // placeholder
  36619. topDict.setByName('FontMatrix', properties.fontMatrix);
  36620. topDict.setByName('FontBBox', properties.bbox);
  36621. topDict.setByName('charset', null); // placeholder
  36622. topDict.setByName('CharStrings', null); // placeholder
  36623. topDict.setByName('Private', null); // placeholder
  36624. cff.topDict = topDict;
  36625. var strings = new CFFStrings();
  36626. strings.add('Version 0.11'); // Version
  36627. strings.add('See original notice'); // Notice
  36628. strings.add(name); // FullName
  36629. strings.add(name); // FamilyName
  36630. strings.add('Medium'); // Weight
  36631. cff.strings = strings;
  36632. cff.globalSubrIndex = new CFFIndex();
  36633. var count = glyphs.length;
  36634. var charsetArray = [0];
  36635. var i, ii;
  36636. for (i = 0; i < count; i++) {
  36637. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  36638. // TODO: Insert the string and correctly map it. Previously it was
  36639. // thought mapping names that aren't in the standard strings to .notdef
  36640. // was fine, however in issue818 when mapping them all to .notdef the
  36641. // adieresis glyph no longer worked.
  36642. if (index === -1) {
  36643. index = 0;
  36644. }
  36645. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  36646. }
  36647. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  36648. var charStringsIndex = new CFFIndex();
  36649. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  36650. for (i = 0; i < count; i++) {
  36651. charStringsIndex.add(glyphs[i]);
  36652. }
  36653. cff.charStrings = charStringsIndex;
  36654. var privateDict = new CFFPrivateDict();
  36655. privateDict.setByName('Subrs', null); // placeholder
  36656. var fields = [
  36657. 'BlueValues',
  36658. 'OtherBlues',
  36659. 'FamilyBlues',
  36660. 'FamilyOtherBlues',
  36661. 'StemSnapH',
  36662. 'StemSnapV',
  36663. 'BlueShift',
  36664. 'BlueFuzz',
  36665. 'BlueScale',
  36666. 'LanguageGroup',
  36667. 'ExpansionFactor',
  36668. 'ForceBold',
  36669. 'StdHW',
  36670. 'StdVW'
  36671. ];
  36672. for (i = 0, ii = fields.length; i < ii; i++) {
  36673. var field = fields[i];
  36674. if (!(field in properties.privateData)) {
  36675. continue;
  36676. }
  36677. var value = properties.privateData[field];
  36678. if (isArray(value)) {
  36679. // All of the private dictionary array data in CFF must be stored as
  36680. // "delta-encoded" numbers.
  36681. for (var j = value.length - 1; j > 0; j--) {
  36682. value[j] -= value[j - 1]; // ... difference from previous value
  36683. }
  36684. }
  36685. privateDict.setByName(field, value);
  36686. }
  36687. cff.topDict.privateDict = privateDict;
  36688. var subrIndex = new CFFIndex();
  36689. for (i = 0, ii = subrs.length; i < ii; i++) {
  36690. subrIndex.add(subrs[i]);
  36691. }
  36692. privateDict.subrsIndex = subrIndex;
  36693. var compiler = new CFFCompiler(cff);
  36694. return compiler.compile();
  36695. }
  36696. };
  36697. var CFFFont = (function CFFFontClosure() {
  36698. function CFFFont(file, properties) {
  36699. this.properties = properties;
  36700. var parser = new CFFParser(file, properties);
  36701. this.cff = parser.parse();
  36702. var compiler = new CFFCompiler(this.cff);
  36703. this.seacs = this.cff.seacs;
  36704. try {
  36705. this.data = compiler.compile();
  36706. } catch (e) {
  36707. warn('Failed to compile font ' + properties.loadedName);
  36708. // There may have just been an issue with the compiler, set the data
  36709. // anyway and hope the font loaded.
  36710. this.data = file;
  36711. }
  36712. }
  36713. CFFFont.prototype = {
  36714. get numGlyphs() {
  36715. return this.cff.charStrings.count;
  36716. },
  36717. getCharset: function CFFFont_getCharset() {
  36718. return this.cff.charset.charset;
  36719. },
  36720. getGlyphMapping: function CFFFont_getGlyphMapping() {
  36721. var cff = this.cff;
  36722. var properties = this.properties;
  36723. var charsets = cff.charset.charset;
  36724. var charCodeToGlyphId;
  36725. var glyphId;
  36726. if (properties.composite) {
  36727. charCodeToGlyphId = Object.create(null);
  36728. if (cff.isCIDFont) {
  36729. // If the font is actually a CID font then we should use the charset
  36730. // to map CIDs to GIDs.
  36731. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  36732. var cid = charsets[glyphId];
  36733. var charCode = properties.cMap.charCodeOf(cid);
  36734. charCodeToGlyphId[charCode] = glyphId;
  36735. }
  36736. } else {
  36737. // If it is NOT actually a CID font then CIDs should be mapped
  36738. // directly to GIDs.
  36739. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  36740. charCodeToGlyphId[glyphId] = glyphId;
  36741. }
  36742. }
  36743. return charCodeToGlyphId;
  36744. }
  36745. var encoding = cff.encoding ? cff.encoding.encoding : null;
  36746. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  36747. return charCodeToGlyphId;
  36748. }
  36749. };
  36750. return CFFFont;
  36751. })();
  36752. var CFFParser = (function CFFParserClosure() {
  36753. var CharstringValidationData = [
  36754. null,
  36755. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  36756. null,
  36757. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  36758. { id: 'vmoveto', min: 1, stackClearing: true },
  36759. { id: 'rlineto', min: 2, resetStack: true },
  36760. { id: 'hlineto', min: 1, resetStack: true },
  36761. { id: 'vlineto', min: 1, resetStack: true },
  36762. { id: 'rrcurveto', min: 6, resetStack: true },
  36763. null,
  36764. { id: 'callsubr', min: 1, undefStack: true },
  36765. { id: 'return', min: 0, undefStack: true },
  36766. null, // 12
  36767. null,
  36768. { id: 'endchar', min: 0, stackClearing: true },
  36769. null,
  36770. null,
  36771. null,
  36772. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  36773. { id: 'hintmask', min: 0, stackClearing: true },
  36774. { id: 'cntrmask', min: 0, stackClearing: true },
  36775. { id: 'rmoveto', min: 2, stackClearing: true },
  36776. { id: 'hmoveto', min: 1, stackClearing: true },
  36777. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  36778. { id: 'rcurveline', min: 8, resetStack: true },
  36779. { id: 'rlinecurve', min: 8, resetStack: true },
  36780. { id: 'vvcurveto', min: 4, resetStack: true },
  36781. { id: 'hhcurveto', min: 4, resetStack: true },
  36782. null, // shortint
  36783. { id: 'callgsubr', min: 1, undefStack: true },
  36784. { id: 'vhcurveto', min: 4, resetStack: true },
  36785. { id: 'hvcurveto', min: 4, resetStack: true }
  36786. ];
  36787. var CharstringValidationData12 = [
  36788. null,
  36789. null,
  36790. null,
  36791. { id: 'and', min: 2, stackDelta: -1 },
  36792. { id: 'or', min: 2, stackDelta: -1 },
  36793. { id: 'not', min: 1, stackDelta: 0 },
  36794. null,
  36795. null,
  36796. null,
  36797. { id: 'abs', min: 1, stackDelta: 0 },
  36798. { id: 'add', min: 2, stackDelta: -1,
  36799. stackFn: function stack_div(stack, index) {
  36800. stack[index - 2] = stack[index - 2] + stack[index - 1];
  36801. }
  36802. },
  36803. { id: 'sub', min: 2, stackDelta: -1,
  36804. stackFn: function stack_div(stack, index) {
  36805. stack[index - 2] = stack[index - 2] - stack[index - 1];
  36806. }
  36807. },
  36808. { id: 'div', min: 2, stackDelta: -1,
  36809. stackFn: function stack_div(stack, index) {
  36810. stack[index - 2] = stack[index - 2] / stack[index - 1];
  36811. }
  36812. },
  36813. null,
  36814. { id: 'neg', min: 1, stackDelta: 0,
  36815. stackFn: function stack_div(stack, index) {
  36816. stack[index - 1] = -stack[index - 1];
  36817. }
  36818. },
  36819. { id: 'eq', min: 2, stackDelta: -1 },
  36820. null,
  36821. null,
  36822. { id: 'drop', min: 1, stackDelta: -1 },
  36823. null,
  36824. { id: 'put', min: 2, stackDelta: -2 },
  36825. { id: 'get', min: 1, stackDelta: 0 },
  36826. { id: 'ifelse', min: 4, stackDelta: -3 },
  36827. { id: 'random', min: 0, stackDelta: 1 },
  36828. { id: 'mul', min: 2, stackDelta: -1,
  36829. stackFn: function stack_div(stack, index) {
  36830. stack[index - 2] = stack[index - 2] * stack[index - 1];
  36831. }
  36832. },
  36833. null,
  36834. { id: 'sqrt', min: 1, stackDelta: 0 },
  36835. { id: 'dup', min: 1, stackDelta: 1 },
  36836. { id: 'exch', min: 2, stackDelta: 0 },
  36837. { id: 'index', min: 2, stackDelta: 0 },
  36838. { id: 'roll', min: 3, stackDelta: -2 },
  36839. null,
  36840. null,
  36841. null,
  36842. { id: 'hflex', min: 7, resetStack: true },
  36843. { id: 'flex', min: 13, resetStack: true },
  36844. { id: 'hflex1', min: 9, resetStack: true },
  36845. { id: 'flex1', min: 11, resetStack: true }
  36846. ];
  36847. function CFFParser(file, properties) {
  36848. this.bytes = file.getBytes();
  36849. this.properties = properties;
  36850. }
  36851. CFFParser.prototype = {
  36852. parse: function CFFParser_parse() {
  36853. var properties = this.properties;
  36854. var cff = new CFF();
  36855. this.cff = cff;
  36856. // The first five sections must be in order, all the others are reached
  36857. // via offsets contained in one of the below.
  36858. var header = this.parseHeader();
  36859. var nameIndex = this.parseIndex(header.endPos);
  36860. var topDictIndex = this.parseIndex(nameIndex.endPos);
  36861. var stringIndex = this.parseIndex(topDictIndex.endPos);
  36862. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  36863. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  36864. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  36865. cff.header = header.obj;
  36866. cff.names = this.parseNameIndex(nameIndex.obj);
  36867. cff.strings = this.parseStringIndex(stringIndex.obj);
  36868. cff.topDict = topDict;
  36869. cff.globalSubrIndex = globalSubrIndex.obj;
  36870. this.parsePrivateDict(cff.topDict);
  36871. cff.isCIDFont = topDict.hasName('ROS');
  36872. var charStringOffset = topDict.getByName('CharStrings');
  36873. var charStringIndex = this.parseIndex(charStringOffset).obj;
  36874. var fontMatrix = topDict.getByName('FontMatrix');
  36875. if (fontMatrix) {
  36876. properties.fontMatrix = fontMatrix;
  36877. }
  36878. var fontBBox = topDict.getByName('FontBBox');
  36879. if (fontBBox) {
  36880. // adjusting ascent/descent
  36881. properties.ascent = fontBBox[3];
  36882. properties.descent = fontBBox[1];
  36883. properties.ascentScaled = true;
  36884. }
  36885. var charset, encoding;
  36886. if (cff.isCIDFont) {
  36887. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  36888. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  36889. var dictRaw = fdArrayIndex.get(i);
  36890. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  36891. cff.strings);
  36892. this.parsePrivateDict(fontDict);
  36893. cff.fdArray.push(fontDict);
  36894. }
  36895. // cid fonts don't have an encoding
  36896. encoding = null;
  36897. charset = this.parseCharsets(topDict.getByName('charset'),
  36898. charStringIndex.count, cff.strings, true);
  36899. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  36900. charStringIndex.count);
  36901. } else {
  36902. charset = this.parseCharsets(topDict.getByName('charset'),
  36903. charStringIndex.count, cff.strings, false);
  36904. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  36905. properties,
  36906. cff.strings, charset.charset);
  36907. }
  36908. cff.charset = charset;
  36909. cff.encoding = encoding;
  36910. var charStringsAndSeacs = this.parseCharStrings(
  36911. charStringIndex,
  36912. topDict.privateDict.subrsIndex,
  36913. globalSubrIndex.obj,
  36914. cff.fdSelect,
  36915. cff.fdArray);
  36916. cff.charStrings = charStringsAndSeacs.charStrings;
  36917. cff.seacs = charStringsAndSeacs.seacs;
  36918. cff.widths = charStringsAndSeacs.widths;
  36919. return cff;
  36920. },
  36921. parseHeader: function CFFParser_parseHeader() {
  36922. var bytes = this.bytes;
  36923. var bytesLength = bytes.length;
  36924. var offset = 0;
  36925. // Prevent an infinite loop, by checking that the offset is within the
  36926. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  36927. while (offset < bytesLength && bytes[offset] !== 1) {
  36928. ++offset;
  36929. }
  36930. if (offset >= bytesLength) {
  36931. error('Invalid CFF header');
  36932. } else if (offset !== 0) {
  36933. info('cff data is shifted');
  36934. bytes = bytes.subarray(offset);
  36935. this.bytes = bytes;
  36936. }
  36937. var major = bytes[0];
  36938. var minor = bytes[1];
  36939. var hdrSize = bytes[2];
  36940. var offSize = bytes[3];
  36941. var header = new CFFHeader(major, minor, hdrSize, offSize);
  36942. return { obj: header, endPos: hdrSize };
  36943. },
  36944. parseDict: function CFFParser_parseDict(dict) {
  36945. var pos = 0;
  36946. function parseOperand() {
  36947. var value = dict[pos++];
  36948. if (value === 30) {
  36949. return parseFloatOperand(pos);
  36950. } else if (value === 28) {
  36951. value = dict[pos++];
  36952. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  36953. return value;
  36954. } else if (value === 29) {
  36955. value = dict[pos++];
  36956. value = (value << 8) | dict[pos++];
  36957. value = (value << 8) | dict[pos++];
  36958. value = (value << 8) | dict[pos++];
  36959. return value;
  36960. } else if (value >= 32 && value <= 246) {
  36961. return value - 139;
  36962. } else if (value >= 247 && value <= 250) {
  36963. return ((value - 247) * 256) + dict[pos++] + 108;
  36964. } else if (value >= 251 && value <= 254) {
  36965. return -((value - 251) * 256) - dict[pos++] - 108;
  36966. } else {
  36967. error('255 is not a valid DICT command');
  36968. }
  36969. return -1;
  36970. }
  36971. function parseFloatOperand() {
  36972. var str = '';
  36973. var eof = 15;
  36974. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  36975. '9', '.', 'E', 'E-', null, '-'];
  36976. var length = dict.length;
  36977. while (pos < length) {
  36978. var b = dict[pos++];
  36979. var b1 = b >> 4;
  36980. var b2 = b & 15;
  36981. if (b1 === eof) {
  36982. break;
  36983. }
  36984. str += lookup[b1];
  36985. if (b2 === eof) {
  36986. break;
  36987. }
  36988. str += lookup[b2];
  36989. }
  36990. return parseFloat(str);
  36991. }
  36992. var operands = [];
  36993. var entries = [];
  36994. pos = 0;
  36995. var end = dict.length;
  36996. while (pos < end) {
  36997. var b = dict[pos];
  36998. if (b <= 21) {
  36999. if (b === 12) {
  37000. b = (b << 8) | dict[++pos];
  37001. }
  37002. entries.push([b, operands]);
  37003. operands = [];
  37004. ++pos;
  37005. } else {
  37006. operands.push(parseOperand());
  37007. }
  37008. }
  37009. return entries;
  37010. },
  37011. parseIndex: function CFFParser_parseIndex(pos) {
  37012. var cffIndex = new CFFIndex();
  37013. var bytes = this.bytes;
  37014. var count = (bytes[pos++] << 8) | bytes[pos++];
  37015. var offsets = [];
  37016. var end = pos;
  37017. var i, ii;
  37018. if (count !== 0) {
  37019. var offsetSize = bytes[pos++];
  37020. // add 1 for offset to determine size of last object
  37021. var startPos = pos + ((count + 1) * offsetSize) - 1;
  37022. for (i = 0, ii = count + 1; i < ii; ++i) {
  37023. var offset = 0;
  37024. for (var j = 0; j < offsetSize; ++j) {
  37025. offset <<= 8;
  37026. offset += bytes[pos++];
  37027. }
  37028. offsets.push(startPos + offset);
  37029. }
  37030. end = offsets[count];
  37031. }
  37032. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  37033. var offsetStart = offsets[i];
  37034. var offsetEnd = offsets[i + 1];
  37035. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  37036. }
  37037. return {obj: cffIndex, endPos: end};
  37038. },
  37039. parseNameIndex: function CFFParser_parseNameIndex(index) {
  37040. var names = [];
  37041. for (var i = 0, ii = index.count; i < ii; ++i) {
  37042. var name = index.get(i);
  37043. // OTS doesn't allow names to be over 127 characters.
  37044. var length = Math.min(name.length, 127);
  37045. var data = [];
  37046. // OTS also only permits certain characters in the name.
  37047. for (var j = 0; j < length; ++j) {
  37048. var c = name[j];
  37049. if (j === 0 && c === 0) {
  37050. data[j] = c;
  37051. continue;
  37052. }
  37053. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  37054. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  37055. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  37056. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  37057. data[j] = 95;
  37058. continue;
  37059. }
  37060. data[j] = c;
  37061. }
  37062. names.push(bytesToString(data));
  37063. }
  37064. return names;
  37065. },
  37066. parseStringIndex: function CFFParser_parseStringIndex(index) {
  37067. var strings = new CFFStrings();
  37068. for (var i = 0, ii = index.count; i < ii; ++i) {
  37069. var data = index.get(i);
  37070. strings.add(bytesToString(data));
  37071. }
  37072. return strings;
  37073. },
  37074. createDict: function CFFParser_createDict(Type, dict, strings) {
  37075. var cffDict = new Type(strings);
  37076. for (var i = 0, ii = dict.length; i < ii; ++i) {
  37077. var pair = dict[i];
  37078. var key = pair[0];
  37079. var value = pair[1];
  37080. cffDict.setByKey(key, value);
  37081. }
  37082. return cffDict;
  37083. },
  37084. parseCharString: function CFFParser_parseCharString(state, data,
  37085. localSubrIndex,
  37086. globalSubrIndex) {
  37087. if (state.callDepth > MAX_SUBR_NESTING) {
  37088. return false;
  37089. }
  37090. var stackSize = state.stackSize;
  37091. var stack = state.stack;
  37092. var length = data.length;
  37093. for (var j = 0; j < length;) {
  37094. var value = data[j++];
  37095. var validationCommand = null;
  37096. if (value === 12) {
  37097. var q = data[j++];
  37098. if (q === 0) {
  37099. // The CFF specification state that the 'dotsection' command
  37100. // (12, 0) is deprecated and treated as a no-op, but all Type2
  37101. // charstrings processors should support them. Unfortunately
  37102. // the font sanitizer don't. As a workaround the sequence (12, 0)
  37103. // is replaced by a useless (0, hmoveto).
  37104. data[j - 2] = 139;
  37105. data[j - 1] = 22;
  37106. stackSize = 0;
  37107. } else {
  37108. validationCommand = CharstringValidationData12[q];
  37109. }
  37110. } else if (value === 28) { // number (16 bit)
  37111. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  37112. j += 2;
  37113. stackSize++;
  37114. } else if (value === 14) {
  37115. if (stackSize >= 4) {
  37116. stackSize -= 4;
  37117. if (SEAC_ANALYSIS_ENABLED) {
  37118. state.seac = stack.slice(stackSize, stackSize + 4);
  37119. return false;
  37120. }
  37121. }
  37122. validationCommand = CharstringValidationData[value];
  37123. } else if (value >= 32 && value <= 246) { // number
  37124. stack[stackSize] = value - 139;
  37125. stackSize++;
  37126. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  37127. stack[stackSize] = (value < 251 ?
  37128. ((value - 247) << 8) + data[j] + 108 :
  37129. -((value - 251) << 8) - data[j] - 108);
  37130. j++;
  37131. stackSize++;
  37132. } else if (value === 255) { // number (32 bit)
  37133. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  37134. (data[j + 2] << 8) | data[j + 3]) / 65536;
  37135. j += 4;
  37136. stackSize++;
  37137. } else if (value === 19 || value === 20) {
  37138. state.hints += stackSize >> 1;
  37139. // skipping right amount of hints flag data
  37140. j += (state.hints + 7) >> 3;
  37141. stackSize %= 2;
  37142. validationCommand = CharstringValidationData[value];
  37143. } else if (value === 10 || value === 29) {
  37144. var subrsIndex;
  37145. if (value === 10) {
  37146. subrsIndex = localSubrIndex;
  37147. } else {
  37148. subrsIndex = globalSubrIndex;
  37149. }
  37150. if (!subrsIndex) {
  37151. validationCommand = CharstringValidationData[value];
  37152. warn('Missing subrsIndex for ' + validationCommand.id);
  37153. return false;
  37154. }
  37155. var bias = 32768;
  37156. if (subrsIndex.count < 1240) {
  37157. bias = 107;
  37158. } else if (subrsIndex.count < 33900) {
  37159. bias = 1131;
  37160. }
  37161. var subrNumber = stack[--stackSize] + bias;
  37162. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  37163. validationCommand = CharstringValidationData[value];
  37164. warn('Out of bounds subrIndex for ' + validationCommand.id);
  37165. return false;
  37166. }
  37167. state.stackSize = stackSize;
  37168. state.callDepth++;
  37169. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  37170. localSubrIndex, globalSubrIndex);
  37171. if (!valid) {
  37172. return false;
  37173. }
  37174. state.callDepth--;
  37175. stackSize = state.stackSize;
  37176. continue;
  37177. } else if (value === 11) {
  37178. state.stackSize = stackSize;
  37179. return true;
  37180. } else {
  37181. validationCommand = CharstringValidationData[value];
  37182. }
  37183. if (validationCommand) {
  37184. if (validationCommand.stem) {
  37185. state.hints += stackSize >> 1;
  37186. }
  37187. if ('min' in validationCommand) {
  37188. if (!state.undefStack && stackSize < validationCommand.min) {
  37189. warn('Not enough parameters for ' + validationCommand.id +
  37190. '; actual: ' + stackSize +
  37191. ', expected: ' + validationCommand.min);
  37192. return false;
  37193. }
  37194. }
  37195. if (state.firstStackClearing && validationCommand.stackClearing) {
  37196. state.firstStackClearing = false;
  37197. // the optional character width can be found before the first
  37198. // stack-clearing command arguments
  37199. stackSize -= validationCommand.min;
  37200. if (stackSize >= 2 && validationCommand.stem) {
  37201. // there are even amount of arguments for stem commands
  37202. stackSize %= 2;
  37203. } else if (stackSize > 1) {
  37204. warn('Found too many parameters for stack-clearing command');
  37205. }
  37206. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  37207. state.width = stack[stackSize - 1];
  37208. }
  37209. }
  37210. if ('stackDelta' in validationCommand) {
  37211. if ('stackFn' in validationCommand) {
  37212. validationCommand.stackFn(stack, stackSize);
  37213. }
  37214. stackSize += validationCommand.stackDelta;
  37215. } else if (validationCommand.stackClearing) {
  37216. stackSize = 0;
  37217. } else if (validationCommand.resetStack) {
  37218. stackSize = 0;
  37219. state.undefStack = false;
  37220. } else if (validationCommand.undefStack) {
  37221. stackSize = 0;
  37222. state.undefStack = true;
  37223. state.firstStackClearing = false;
  37224. }
  37225. }
  37226. }
  37227. state.stackSize = stackSize;
  37228. return true;
  37229. },
  37230. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  37231. localSubrIndex,
  37232. globalSubrIndex,
  37233. fdSelect,
  37234. fdArray) {
  37235. var seacs = [];
  37236. var widths = [];
  37237. var count = charStrings.count;
  37238. for (var i = 0; i < count; i++) {
  37239. var charstring = charStrings.get(i);
  37240. var state = {
  37241. callDepth: 0,
  37242. stackSize: 0,
  37243. stack: [],
  37244. undefStack: true,
  37245. hints: 0,
  37246. firstStackClearing: true,
  37247. seac: null,
  37248. width: null
  37249. };
  37250. var valid = true;
  37251. var localSubrToUse = null;
  37252. if (fdSelect && fdArray.length) {
  37253. var fdIndex = fdSelect.getFDIndex(i);
  37254. if (fdIndex === -1) {
  37255. warn('Glyph index is not in fd select.');
  37256. valid = false;
  37257. }
  37258. if (fdIndex >= fdArray.length) {
  37259. warn('Invalid fd index for glyph index.');
  37260. valid = false;
  37261. }
  37262. if (valid) {
  37263. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  37264. }
  37265. } else if (localSubrIndex) {
  37266. localSubrToUse = localSubrIndex;
  37267. }
  37268. if (valid) {
  37269. valid = this.parseCharString(state, charstring, localSubrToUse,
  37270. globalSubrIndex);
  37271. }
  37272. if (state.width !== null) {
  37273. widths[i] = state.width;
  37274. }
  37275. if (state.seac !== null) {
  37276. seacs[i] = state.seac;
  37277. }
  37278. if (!valid) {
  37279. // resetting invalid charstring to single 'endchar'
  37280. charStrings.set(i, new Uint8Array([14]));
  37281. }
  37282. }
  37283. return { charStrings: charStrings, seacs: seacs, widths: widths };
  37284. },
  37285. emptyPrivateDictionary:
  37286. function CFFParser_emptyPrivateDictionary(parentDict) {
  37287. var privateDict = this.createDict(CFFPrivateDict, [],
  37288. parentDict.strings);
  37289. parentDict.setByKey(18, [0, 0]);
  37290. parentDict.privateDict = privateDict;
  37291. },
  37292. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  37293. // no private dict, do nothing
  37294. if (!parentDict.hasName('Private')) {
  37295. this.emptyPrivateDictionary(parentDict);
  37296. return;
  37297. }
  37298. var privateOffset = parentDict.getByName('Private');
  37299. // make sure the params are formatted correctly
  37300. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  37301. parentDict.removeByName('Private');
  37302. return;
  37303. }
  37304. var size = privateOffset[0];
  37305. var offset = privateOffset[1];
  37306. // remove empty dicts or ones that refer to invalid location
  37307. if (size === 0 || offset >= this.bytes.length) {
  37308. this.emptyPrivateDictionary(parentDict);
  37309. return;
  37310. }
  37311. var privateDictEnd = offset + size;
  37312. var dictData = this.bytes.subarray(offset, privateDictEnd);
  37313. var dict = this.parseDict(dictData);
  37314. var privateDict = this.createDict(CFFPrivateDict, dict,
  37315. parentDict.strings);
  37316. parentDict.privateDict = privateDict;
  37317. // Parse the Subrs index also since it's relative to the private dict.
  37318. if (!privateDict.getByName('Subrs')) {
  37319. return;
  37320. }
  37321. var subrsOffset = privateDict.getByName('Subrs');
  37322. var relativeOffset = offset + subrsOffset;
  37323. // Validate the offset.
  37324. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  37325. this.emptyPrivateDictionary(parentDict);
  37326. return;
  37327. }
  37328. var subrsIndex = this.parseIndex(relativeOffset);
  37329. privateDict.subrsIndex = subrsIndex.obj;
  37330. },
  37331. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  37332. if (pos === 0) {
  37333. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  37334. ISOAdobeCharset);
  37335. } else if (pos === 1) {
  37336. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  37337. ExpertCharset);
  37338. } else if (pos === 2) {
  37339. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  37340. ExpertSubsetCharset);
  37341. }
  37342. var bytes = this.bytes;
  37343. var start = pos;
  37344. var format = bytes[pos++];
  37345. var charset = ['.notdef'];
  37346. var id, count, i;
  37347. // subtract 1 for the .notdef glyph
  37348. length -= 1;
  37349. switch (format) {
  37350. case 0:
  37351. for (i = 0; i < length; i++) {
  37352. id = (bytes[pos++] << 8) | bytes[pos++];
  37353. charset.push(cid ? id : strings.get(id));
  37354. }
  37355. break;
  37356. case 1:
  37357. while (charset.length <= length) {
  37358. id = (bytes[pos++] << 8) | bytes[pos++];
  37359. count = bytes[pos++];
  37360. for (i = 0; i <= count; i++) {
  37361. charset.push(cid ? id++ : strings.get(id++));
  37362. }
  37363. }
  37364. break;
  37365. case 2:
  37366. while (charset.length <= length) {
  37367. id = (bytes[pos++] << 8) | bytes[pos++];
  37368. count = (bytes[pos++] << 8) | bytes[pos++];
  37369. for (i = 0; i <= count; i++) {
  37370. charset.push(cid ? id++ : strings.get(id++));
  37371. }
  37372. }
  37373. break;
  37374. default:
  37375. error('Unknown charset format');
  37376. }
  37377. // Raw won't be needed if we actually compile the charset.
  37378. var end = pos;
  37379. var raw = bytes.subarray(start, end);
  37380. return new CFFCharset(false, format, charset, raw);
  37381. },
  37382. parseEncoding: function CFFParser_parseEncoding(pos,
  37383. properties,
  37384. strings,
  37385. charset) {
  37386. var encoding = Object.create(null);
  37387. var bytes = this.bytes;
  37388. var predefined = false;
  37389. var hasSupplement = false;
  37390. var format, i, ii;
  37391. var raw = null;
  37392. function readSupplement() {
  37393. var supplementsCount = bytes[pos++];
  37394. for (i = 0; i < supplementsCount; i++) {
  37395. var code = bytes[pos++];
  37396. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  37397. encoding[code] = charset.indexOf(strings.get(sid));
  37398. }
  37399. }
  37400. if (pos === 0 || pos === 1) {
  37401. predefined = true;
  37402. format = pos;
  37403. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  37404. for (i = 0, ii = charset.length; i < ii; i++) {
  37405. var index = baseEncoding.indexOf(charset[i]);
  37406. if (index !== -1) {
  37407. encoding[index] = i;
  37408. }
  37409. }
  37410. } else {
  37411. var dataStart = pos;
  37412. format = bytes[pos++];
  37413. switch (format & 0x7f) {
  37414. case 0:
  37415. var glyphsCount = bytes[pos++];
  37416. for (i = 1; i <= glyphsCount; i++) {
  37417. encoding[bytes[pos++]] = i;
  37418. }
  37419. break;
  37420. case 1:
  37421. var rangesCount = bytes[pos++];
  37422. var gid = 1;
  37423. for (i = 0; i < rangesCount; i++) {
  37424. var start = bytes[pos++];
  37425. var left = bytes[pos++];
  37426. for (var j = start; j <= start + left; j++) {
  37427. encoding[j] = gid++;
  37428. }
  37429. }
  37430. break;
  37431. default:
  37432. error('Unknow encoding format: ' + format + ' in CFF');
  37433. break;
  37434. }
  37435. var dataEnd = pos;
  37436. if (format & 0x80) {
  37437. // The font sanitizer does not support CFF encoding with a
  37438. // supplement, since the encoding is not really used to map
  37439. // between gid to glyph, let's overwrite what is declared in
  37440. // the top dictionary to let the sanitizer think the font use
  37441. // StandardEncoding, that's a lie but that's ok.
  37442. bytes[dataStart] &= 0x7f;
  37443. readSupplement();
  37444. hasSupplement = true;
  37445. }
  37446. raw = bytes.subarray(dataStart, dataEnd);
  37447. }
  37448. format = format & 0x7f;
  37449. return new CFFEncoding(predefined, format, encoding, raw);
  37450. },
  37451. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  37452. var start = pos;
  37453. var bytes = this.bytes;
  37454. var format = bytes[pos++];
  37455. var fdSelect = [];
  37456. var i;
  37457. switch (format) {
  37458. case 0:
  37459. for (i = 0; i < length; ++i) {
  37460. var id = bytes[pos++];
  37461. fdSelect.push(id);
  37462. }
  37463. break;
  37464. case 3:
  37465. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  37466. for (i = 0; i < rangesCount; ++i) {
  37467. var first = (bytes[pos++] << 8) | bytes[pos++];
  37468. var fdIndex = bytes[pos++];
  37469. var next = (bytes[pos] << 8) | bytes[pos + 1];
  37470. for (var j = first; j < next; ++j) {
  37471. fdSelect.push(fdIndex);
  37472. }
  37473. }
  37474. // Advance past the sentinel(next).
  37475. pos += 2;
  37476. break;
  37477. default:
  37478. error('Unknown fdselect format ' + format);
  37479. break;
  37480. }
  37481. var end = pos;
  37482. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  37483. }
  37484. };
  37485. return CFFParser;
  37486. })();
  37487. // Compact Font Format
  37488. var CFF = (function CFFClosure() {
  37489. function CFF() {
  37490. this.header = null;
  37491. this.names = [];
  37492. this.topDict = null;
  37493. this.strings = new CFFStrings();
  37494. this.globalSubrIndex = null;
  37495. // The following could really be per font, but since we only have one font
  37496. // store them here.
  37497. this.encoding = null;
  37498. this.charset = null;
  37499. this.charStrings = null;
  37500. this.fdArray = [];
  37501. this.fdSelect = null;
  37502. this.isCIDFont = false;
  37503. }
  37504. return CFF;
  37505. })();
  37506. var CFFHeader = (function CFFHeaderClosure() {
  37507. function CFFHeader(major, minor, hdrSize, offSize) {
  37508. this.major = major;
  37509. this.minor = minor;
  37510. this.hdrSize = hdrSize;
  37511. this.offSize = offSize;
  37512. }
  37513. return CFFHeader;
  37514. })();
  37515. var CFFStrings = (function CFFStringsClosure() {
  37516. function CFFStrings() {
  37517. this.strings = [];
  37518. }
  37519. CFFStrings.prototype = {
  37520. get: function CFFStrings_get(index) {
  37521. if (index >= 0 && index <= 390) {
  37522. return CFFStandardStrings[index];
  37523. }
  37524. if (index - 391 <= this.strings.length) {
  37525. return this.strings[index - 391];
  37526. }
  37527. return CFFStandardStrings[0];
  37528. },
  37529. add: function CFFStrings_add(value) {
  37530. this.strings.push(value);
  37531. },
  37532. get count() {
  37533. return this.strings.length;
  37534. }
  37535. };
  37536. return CFFStrings;
  37537. })();
  37538. var CFFIndex = (function CFFIndexClosure() {
  37539. function CFFIndex() {
  37540. this.objects = [];
  37541. this.length = 0;
  37542. }
  37543. CFFIndex.prototype = {
  37544. add: function CFFIndex_add(data) {
  37545. this.length += data.length;
  37546. this.objects.push(data);
  37547. },
  37548. set: function CFFIndex_set(index, data) {
  37549. this.length += data.length - this.objects[index].length;
  37550. this.objects[index] = data;
  37551. },
  37552. get: function CFFIndex_get(index) {
  37553. return this.objects[index];
  37554. },
  37555. get count() {
  37556. return this.objects.length;
  37557. }
  37558. };
  37559. return CFFIndex;
  37560. })();
  37561. var CFFDict = (function CFFDictClosure() {
  37562. function CFFDict(tables, strings) {
  37563. this.keyToNameMap = tables.keyToNameMap;
  37564. this.nameToKeyMap = tables.nameToKeyMap;
  37565. this.defaults = tables.defaults;
  37566. this.types = tables.types;
  37567. this.opcodes = tables.opcodes;
  37568. this.order = tables.order;
  37569. this.strings = strings;
  37570. this.values = Object.create(null);
  37571. }
  37572. CFFDict.prototype = {
  37573. // value should always be an array
  37574. setByKey: function CFFDict_setByKey(key, value) {
  37575. if (!(key in this.keyToNameMap)) {
  37576. return false;
  37577. }
  37578. // ignore empty values
  37579. if (value.length === 0) {
  37580. return true;
  37581. }
  37582. var type = this.types[key];
  37583. // remove the array wrapping these types of values
  37584. if (type === 'num' || type === 'sid' || type === 'offset') {
  37585. value = value[0];
  37586. }
  37587. this.values[key] = value;
  37588. return true;
  37589. },
  37590. setByName: function CFFDict_setByName(name, value) {
  37591. if (!(name in this.nameToKeyMap)) {
  37592. error('Invalid dictionary name "' + name + '"');
  37593. }
  37594. this.values[this.nameToKeyMap[name]] = value;
  37595. },
  37596. hasName: function CFFDict_hasName(name) {
  37597. return this.nameToKeyMap[name] in this.values;
  37598. },
  37599. getByName: function CFFDict_getByName(name) {
  37600. if (!(name in this.nameToKeyMap)) {
  37601. error('Invalid dictionary name "' + name + '"');
  37602. }
  37603. var key = this.nameToKeyMap[name];
  37604. if (!(key in this.values)) {
  37605. return this.defaults[key];
  37606. }
  37607. return this.values[key];
  37608. },
  37609. removeByName: function CFFDict_removeByName(name) {
  37610. delete this.values[this.nameToKeyMap[name]];
  37611. }
  37612. };
  37613. CFFDict.createTables = function CFFDict_createTables(layout) {
  37614. var tables = {
  37615. keyToNameMap: {},
  37616. nameToKeyMap: {},
  37617. defaults: {},
  37618. types: {},
  37619. opcodes: {},
  37620. order: []
  37621. };
  37622. for (var i = 0, ii = layout.length; i < ii; ++i) {
  37623. var entry = layout[i];
  37624. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  37625. tables.keyToNameMap[key] = entry[1];
  37626. tables.nameToKeyMap[entry[1]] = key;
  37627. tables.types[key] = entry[2];
  37628. tables.defaults[key] = entry[3];
  37629. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  37630. tables.order.push(key);
  37631. }
  37632. return tables;
  37633. };
  37634. return CFFDict;
  37635. })();
  37636. var CFFTopDict = (function CFFTopDictClosure() {
  37637. var layout = [
  37638. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  37639. [[12, 20], 'SyntheticBase', 'num', null],
  37640. [0, 'version', 'sid', null],
  37641. [1, 'Notice', 'sid', null],
  37642. [[12, 0], 'Copyright', 'sid', null],
  37643. [2, 'FullName', 'sid', null],
  37644. [3, 'FamilyName', 'sid', null],
  37645. [4, 'Weight', 'sid', null],
  37646. [[12, 1], 'isFixedPitch', 'num', 0],
  37647. [[12, 2], 'ItalicAngle', 'num', 0],
  37648. [[12, 3], 'UnderlinePosition', 'num', -100],
  37649. [[12, 4], 'UnderlineThickness', 'num', 50],
  37650. [[12, 5], 'PaintType', 'num', 0],
  37651. [[12, 6], 'CharstringType', 'num', 2],
  37652. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  37653. [0.001, 0, 0, 0.001, 0, 0]],
  37654. [13, 'UniqueID', 'num', null],
  37655. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  37656. [[12, 8], 'StrokeWidth', 'num', 0],
  37657. [14, 'XUID', 'array', null],
  37658. [15, 'charset', 'offset', 0],
  37659. [16, 'Encoding', 'offset', 0],
  37660. [17, 'CharStrings', 'offset', 0],
  37661. [18, 'Private', ['offset', 'offset'], null],
  37662. [[12, 21], 'PostScript', 'sid', null],
  37663. [[12, 22], 'BaseFontName', 'sid', null],
  37664. [[12, 23], 'BaseFontBlend', 'delta', null],
  37665. [[12, 31], 'CIDFontVersion', 'num', 0],
  37666. [[12, 32], 'CIDFontRevision', 'num', 0],
  37667. [[12, 33], 'CIDFontType', 'num', 0],
  37668. [[12, 34], 'CIDCount', 'num', 8720],
  37669. [[12, 35], 'UIDBase', 'num', null],
  37670. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  37671. // before FDArray.
  37672. [[12, 37], 'FDSelect', 'offset', null],
  37673. [[12, 36], 'FDArray', 'offset', null],
  37674. [[12, 38], 'FontName', 'sid', null]
  37675. ];
  37676. var tables = null;
  37677. function CFFTopDict(strings) {
  37678. if (tables === null) {
  37679. tables = CFFDict.createTables(layout);
  37680. }
  37681. CFFDict.call(this, tables, strings);
  37682. this.privateDict = null;
  37683. }
  37684. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  37685. return CFFTopDict;
  37686. })();
  37687. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  37688. var layout = [
  37689. [6, 'BlueValues', 'delta', null],
  37690. [7, 'OtherBlues', 'delta', null],
  37691. [8, 'FamilyBlues', 'delta', null],
  37692. [9, 'FamilyOtherBlues', 'delta', null],
  37693. [[12, 9], 'BlueScale', 'num', 0.039625],
  37694. [[12, 10], 'BlueShift', 'num', 7],
  37695. [[12, 11], 'BlueFuzz', 'num', 1],
  37696. [10, 'StdHW', 'num', null],
  37697. [11, 'StdVW', 'num', null],
  37698. [[12, 12], 'StemSnapH', 'delta', null],
  37699. [[12, 13], 'StemSnapV', 'delta', null],
  37700. [[12, 14], 'ForceBold', 'num', 0],
  37701. [[12, 17], 'LanguageGroup', 'num', 0],
  37702. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  37703. [[12, 19], 'initialRandomSeed', 'num', 0],
  37704. [20, 'defaultWidthX', 'num', 0],
  37705. [21, 'nominalWidthX', 'num', 0],
  37706. [19, 'Subrs', 'offset', null]
  37707. ];
  37708. var tables = null;
  37709. function CFFPrivateDict(strings) {
  37710. if (tables === null) {
  37711. tables = CFFDict.createTables(layout);
  37712. }
  37713. CFFDict.call(this, tables, strings);
  37714. this.subrsIndex = null;
  37715. }
  37716. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  37717. return CFFPrivateDict;
  37718. })();
  37719. var CFFCharsetPredefinedTypes = {
  37720. ISO_ADOBE: 0,
  37721. EXPERT: 1,
  37722. EXPERT_SUBSET: 2
  37723. };
  37724. var CFFCharset = (function CFFCharsetClosure() {
  37725. function CFFCharset(predefined, format, charset, raw) {
  37726. this.predefined = predefined;
  37727. this.format = format;
  37728. this.charset = charset;
  37729. this.raw = raw;
  37730. }
  37731. return CFFCharset;
  37732. })();
  37733. var CFFEncoding = (function CFFEncodingClosure() {
  37734. function CFFEncoding(predefined, format, encoding, raw) {
  37735. this.predefined = predefined;
  37736. this.format = format;
  37737. this.encoding = encoding;
  37738. this.raw = raw;
  37739. }
  37740. return CFFEncoding;
  37741. })();
  37742. var CFFFDSelect = (function CFFFDSelectClosure() {
  37743. function CFFFDSelect(fdSelect, raw) {
  37744. this.fdSelect = fdSelect;
  37745. this.raw = raw;
  37746. }
  37747. CFFFDSelect.prototype = {
  37748. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  37749. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  37750. return -1;
  37751. }
  37752. return this.fdSelect[glyphIndex];
  37753. }
  37754. };
  37755. return CFFFDSelect;
  37756. })();
  37757. // Helper class to keep track of where an offset is within the data and helps
  37758. // filling in that offset once it's known.
  37759. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  37760. function CFFOffsetTracker() {
  37761. this.offsets = Object.create(null);
  37762. }
  37763. CFFOffsetTracker.prototype = {
  37764. isTracking: function CFFOffsetTracker_isTracking(key) {
  37765. return key in this.offsets;
  37766. },
  37767. track: function CFFOffsetTracker_track(key, location) {
  37768. if (key in this.offsets) {
  37769. error('Already tracking location of ' + key);
  37770. }
  37771. this.offsets[key] = location;
  37772. },
  37773. offset: function CFFOffsetTracker_offset(value) {
  37774. for (var key in this.offsets) {
  37775. this.offsets[key] += value;
  37776. }
  37777. },
  37778. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  37779. values,
  37780. output) {
  37781. if (!(key in this.offsets)) {
  37782. error('Not tracking location of ' + key);
  37783. }
  37784. var data = output.data;
  37785. var dataOffset = this.offsets[key];
  37786. var size = 5;
  37787. for (var i = 0, ii = values.length; i < ii; ++i) {
  37788. var offset0 = i * size + dataOffset;
  37789. var offset1 = offset0 + 1;
  37790. var offset2 = offset0 + 2;
  37791. var offset3 = offset0 + 3;
  37792. var offset4 = offset0 + 4;
  37793. // It's easy to screw up offsets so perform this sanity check.
  37794. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  37795. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  37796. error('writing to an offset that is not empty');
  37797. }
  37798. var value = values[i];
  37799. data[offset0] = 0x1d;
  37800. data[offset1] = (value >> 24) & 0xFF;
  37801. data[offset2] = (value >> 16) & 0xFF;
  37802. data[offset3] = (value >> 8) & 0xFF;
  37803. data[offset4] = value & 0xFF;
  37804. }
  37805. }
  37806. };
  37807. return CFFOffsetTracker;
  37808. })();
  37809. // Takes a CFF and converts it to the binary representation.
  37810. var CFFCompiler = (function CFFCompilerClosure() {
  37811. function CFFCompiler(cff) {
  37812. this.cff = cff;
  37813. }
  37814. CFFCompiler.prototype = {
  37815. compile: function CFFCompiler_compile() {
  37816. var cff = this.cff;
  37817. var output = {
  37818. data: [],
  37819. length: 0,
  37820. add: function CFFCompiler_add(data) {
  37821. this.data = this.data.concat(data);
  37822. this.length = this.data.length;
  37823. }
  37824. };
  37825. // Compile the five entries that must be in order.
  37826. var header = this.compileHeader(cff.header);
  37827. output.add(header);
  37828. var nameIndex = this.compileNameIndex(cff.names);
  37829. output.add(nameIndex);
  37830. if (cff.isCIDFont) {
  37831. // The spec is unclear on how font matrices should relate to each other
  37832. // when there is one in the main top dict and the sub top dicts.
  37833. // Windows handles this differently than linux and osx so we have to
  37834. // normalize to work on all.
  37835. // Rules based off of some mailing list discussions:
  37836. // - If main font has a matrix and subfont doesn't, use the main matrix.
  37837. // - If no main font matrix and there is a subfont matrix, use the
  37838. // subfont matrix.
  37839. // - If both have matrices, concat together.
  37840. // - If neither have matrices, use default.
  37841. // To make this work on all platforms we move the top matrix into each
  37842. // sub top dict and concat if necessary.
  37843. if (cff.topDict.hasName('FontMatrix')) {
  37844. var base = cff.topDict.getByName('FontMatrix');
  37845. cff.topDict.removeByName('FontMatrix');
  37846. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  37847. var subDict = cff.fdArray[i];
  37848. var matrix = base.slice(0);
  37849. if (subDict.hasName('FontMatrix')) {
  37850. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  37851. }
  37852. subDict.setByName('FontMatrix', matrix);
  37853. }
  37854. }
  37855. }
  37856. var compiled = this.compileTopDicts([cff.topDict],
  37857. output.length,
  37858. cff.isCIDFont);
  37859. output.add(compiled.output);
  37860. var topDictTracker = compiled.trackers[0];
  37861. var stringIndex = this.compileStringIndex(cff.strings.strings);
  37862. output.add(stringIndex);
  37863. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  37864. output.add(globalSubrIndex);
  37865. // Now start on the other entries that have no specfic order.
  37866. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  37867. if (cff.encoding.predefined) {
  37868. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  37869. output);
  37870. } else {
  37871. var encoding = this.compileEncoding(cff.encoding);
  37872. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  37873. output.add(encoding);
  37874. }
  37875. }
  37876. if (cff.charset && cff.topDict.hasName('charset')) {
  37877. if (cff.charset.predefined) {
  37878. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  37879. output);
  37880. } else {
  37881. var charset = this.compileCharset(cff.charset);
  37882. topDictTracker.setEntryLocation('charset', [output.length], output);
  37883. output.add(charset);
  37884. }
  37885. }
  37886. var charStrings = this.compileCharStrings(cff.charStrings);
  37887. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  37888. output.add(charStrings);
  37889. if (cff.isCIDFont) {
  37890. // For some reason FDSelect must be in front of FDArray on windows. OSX
  37891. // and linux don't seem to care.
  37892. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  37893. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  37894. output.add(fdSelect);
  37895. // It is unclear if the sub font dictionary can have CID related
  37896. // dictionary keys, but the sanitizer doesn't like them so remove them.
  37897. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  37898. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  37899. output.add(compiled.output);
  37900. var fontDictTrackers = compiled.trackers;
  37901. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  37902. }
  37903. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  37904. // If the font data ends with INDEX whose object data is zero-length,
  37905. // the sanitizer will bail out. Add a dummy byte to avoid that.
  37906. output.add([0]);
  37907. return output.data;
  37908. },
  37909. encodeNumber: function CFFCompiler_encodeNumber(value) {
  37910. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  37911. return this.encodeInteger(value);
  37912. } else {
  37913. return this.encodeFloat(value);
  37914. }
  37915. },
  37916. encodeFloat: function CFFCompiler_encodeFloat(num) {
  37917. var value = num.toString();
  37918. // rounding inaccurate doubles
  37919. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  37920. if (m) {
  37921. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  37922. value = (Math.round(num * epsilon) / epsilon).toString();
  37923. }
  37924. var nibbles = '';
  37925. var i, ii;
  37926. for (i = 0, ii = value.length; i < ii; ++i) {
  37927. var a = value[i];
  37928. if (a === 'e') {
  37929. nibbles += value[++i] === '-' ? 'c' : 'b';
  37930. } else if (a === '.') {
  37931. nibbles += 'a';
  37932. } else if (a === '-') {
  37933. nibbles += 'e';
  37934. } else {
  37935. nibbles += a;
  37936. }
  37937. }
  37938. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  37939. var out = [30];
  37940. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  37941. out.push(parseInt(nibbles.substr(i, 2), 16));
  37942. }
  37943. return out;
  37944. },
  37945. encodeInteger: function CFFCompiler_encodeInteger(value) {
  37946. var code;
  37947. if (value >= -107 && value <= 107) {
  37948. code = [value + 139];
  37949. } else if (value >= 108 && value <= 1131) {
  37950. value = [value - 108];
  37951. code = [(value >> 8) + 247, value & 0xFF];
  37952. } else if (value >= -1131 && value <= -108) {
  37953. value = -value - 108;
  37954. code = [(value >> 8) + 251, value & 0xFF];
  37955. } else if (value >= -32768 && value <= 32767) {
  37956. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  37957. } else {
  37958. code = [0x1d,
  37959. (value >> 24) & 0xFF,
  37960. (value >> 16) & 0xFF,
  37961. (value >> 8) & 0xFF,
  37962. value & 0xFF];
  37963. }
  37964. return code;
  37965. },
  37966. compileHeader: function CFFCompiler_compileHeader(header) {
  37967. return [
  37968. header.major,
  37969. header.minor,
  37970. header.hdrSize,
  37971. header.offSize
  37972. ];
  37973. },
  37974. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  37975. var nameIndex = new CFFIndex();
  37976. for (var i = 0, ii = names.length; i < ii; ++i) {
  37977. nameIndex.add(stringToBytes(names[i]));
  37978. }
  37979. return this.compileIndex(nameIndex);
  37980. },
  37981. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  37982. length,
  37983. removeCidKeys) {
  37984. var fontDictTrackers = [];
  37985. var fdArrayIndex = new CFFIndex();
  37986. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  37987. var fontDict = dicts[i];
  37988. if (removeCidKeys) {
  37989. fontDict.removeByName('CIDFontVersion');
  37990. fontDict.removeByName('CIDFontRevision');
  37991. fontDict.removeByName('CIDFontType');
  37992. fontDict.removeByName('CIDCount');
  37993. fontDict.removeByName('UIDBase');
  37994. }
  37995. var fontDictTracker = new CFFOffsetTracker();
  37996. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  37997. fontDictTrackers.push(fontDictTracker);
  37998. fdArrayIndex.add(fontDictData);
  37999. fontDictTracker.offset(length);
  38000. }
  38001. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  38002. return {
  38003. trackers: fontDictTrackers,
  38004. output: fdArrayIndex
  38005. };
  38006. },
  38007. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  38008. trackers,
  38009. output) {
  38010. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  38011. var fontDict = dicts[i];
  38012. assert(fontDict.privateDict && fontDict.hasName('Private'),
  38013. 'There must be an private dictionary.');
  38014. var privateDict = fontDict.privateDict;
  38015. var privateDictTracker = new CFFOffsetTracker();
  38016. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  38017. var outputLength = output.length;
  38018. privateDictTracker.offset(outputLength);
  38019. if (!privateDictData.length) {
  38020. // The private dictionary was empty, set the output length to zero to
  38021. // ensure the offset length isn't out of bounds in the eyes of the
  38022. // sanitizer.
  38023. outputLength = 0;
  38024. }
  38025. trackers[i].setEntryLocation('Private',
  38026. [privateDictData.length, outputLength],
  38027. output);
  38028. output.add(privateDictData);
  38029. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  38030. var subrs = this.compileIndex(privateDict.subrsIndex);
  38031. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  38032. output);
  38033. output.add(subrs);
  38034. }
  38035. }
  38036. },
  38037. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  38038. var out = [];
  38039. // The dictionary keys must be in a certain order.
  38040. var order = dict.order;
  38041. for (var i = 0; i < order.length; ++i) {
  38042. var key = order[i];
  38043. if (!(key in dict.values)) {
  38044. continue;
  38045. }
  38046. var values = dict.values[key];
  38047. var types = dict.types[key];
  38048. if (!isArray(types)) {
  38049. types = [types];
  38050. }
  38051. if (!isArray(values)) {
  38052. values = [values];
  38053. }
  38054. // Remove any empty dict values.
  38055. if (values.length === 0) {
  38056. continue;
  38057. }
  38058. for (var j = 0, jj = types.length; j < jj; ++j) {
  38059. var type = types[j];
  38060. var value = values[j];
  38061. switch (type) {
  38062. case 'num':
  38063. case 'sid':
  38064. out = out.concat(this.encodeNumber(value));
  38065. break;
  38066. case 'offset':
  38067. // For offsets we just insert a 32bit integer so we don't have to
  38068. // deal with figuring out the length of the offset when it gets
  38069. // replaced later on by the compiler.
  38070. var name = dict.keyToNameMap[key];
  38071. // Some offsets have the offset and the length, so just record the
  38072. // position of the first one.
  38073. if (!offsetTracker.isTracking(name)) {
  38074. offsetTracker.track(name, out.length);
  38075. }
  38076. out = out.concat([0x1d, 0, 0, 0, 0]);
  38077. break;
  38078. case 'array':
  38079. case 'delta':
  38080. out = out.concat(this.encodeNumber(value));
  38081. for (var k = 1, kk = values.length; k < kk; ++k) {
  38082. out = out.concat(this.encodeNumber(values[k]));
  38083. }
  38084. break;
  38085. default:
  38086. error('Unknown data type of ' + type);
  38087. break;
  38088. }
  38089. }
  38090. out = out.concat(dict.opcodes[key]);
  38091. }
  38092. return out;
  38093. },
  38094. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  38095. var stringIndex = new CFFIndex();
  38096. for (var i = 0, ii = strings.length; i < ii; ++i) {
  38097. stringIndex.add(stringToBytes(strings[i]));
  38098. }
  38099. return this.compileIndex(stringIndex);
  38100. },
  38101. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  38102. var globalSubrIndex = this.cff.globalSubrIndex;
  38103. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  38104. },
  38105. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  38106. return this.compileIndex(charStrings);
  38107. },
  38108. compileCharset: function CFFCompiler_compileCharset(charset) {
  38109. return this.compileTypedArray(charset.raw);
  38110. },
  38111. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  38112. return this.compileTypedArray(encoding.raw);
  38113. },
  38114. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  38115. return this.compileTypedArray(fdSelect);
  38116. },
  38117. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  38118. var out = [];
  38119. for (var i = 0, ii = data.length; i < ii; ++i) {
  38120. out[i] = data[i];
  38121. }
  38122. return out;
  38123. },
  38124. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  38125. trackers = trackers || [];
  38126. var objects = index.objects;
  38127. // First 2 bytes contains the number of objects contained into this index
  38128. var count = objects.length;
  38129. // If there is no object, just create an index. This technically
  38130. // should just be [0, 0] but OTS has an issue with that.
  38131. if (count === 0) {
  38132. return [0, 0, 0];
  38133. }
  38134. var data = [(count >> 8) & 0xFF, count & 0xff];
  38135. var lastOffset = 1, i;
  38136. for (i = 0; i < count; ++i) {
  38137. lastOffset += objects[i].length;
  38138. }
  38139. var offsetSize;
  38140. if (lastOffset < 0x100) {
  38141. offsetSize = 1;
  38142. } else if (lastOffset < 0x10000) {
  38143. offsetSize = 2;
  38144. } else if (lastOffset < 0x1000000) {
  38145. offsetSize = 3;
  38146. } else {
  38147. offsetSize = 4;
  38148. }
  38149. // Next byte contains the offset size use to reference object in the file
  38150. data.push(offsetSize);
  38151. // Add another offset after this one because we need a new offset
  38152. var relativeOffset = 1;
  38153. for (i = 0; i < count + 1; i++) {
  38154. if (offsetSize === 1) {
  38155. data.push(relativeOffset & 0xFF);
  38156. } else if (offsetSize === 2) {
  38157. data.push((relativeOffset >> 8) & 0xFF,
  38158. relativeOffset & 0xFF);
  38159. } else if (offsetSize === 3) {
  38160. data.push((relativeOffset >> 16) & 0xFF,
  38161. (relativeOffset >> 8) & 0xFF,
  38162. relativeOffset & 0xFF);
  38163. } else {
  38164. data.push((relativeOffset >>> 24) & 0xFF,
  38165. (relativeOffset >> 16) & 0xFF,
  38166. (relativeOffset >> 8) & 0xFF,
  38167. relativeOffset & 0xFF);
  38168. }
  38169. if (objects[i]) {
  38170. relativeOffset += objects[i].length;
  38171. }
  38172. }
  38173. for (i = 0; i < count; i++) {
  38174. // Notify the tracker where the object will be offset in the data.
  38175. if (trackers[i]) {
  38176. trackers[i].offset(data.length);
  38177. }
  38178. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  38179. data.push(objects[i][j]);
  38180. }
  38181. }
  38182. return data;
  38183. }
  38184. };
  38185. return CFFCompiler;
  38186. })();
  38187. function _enableSeacAnalysis(enabled) {
  38188. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED = enabled;
  38189. }
  38190. // Workaround for seac on Windows.
  38191. (function checkSeacSupport() {
  38192. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  38193. SEAC_ANALYSIS_ENABLED = true;
  38194. }
  38195. })();
  38196. // Workaround for Private Use Area characters in Chrome on Windows
  38197. // http://code.google.com/p/chromium/issues/detail?id=122465
  38198. // https://github.com/mozilla/pdf.js/issues/1689
  38199. (function checkChromeWindows() {
  38200. if (typeof navigator !== 'undefined' &&
  38201. /Windows.*Chrome/.test(navigator.userAgent)) {
  38202. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  38203. }
  38204. })();
  38205. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  38206. exports.CFFCompiler = CFFCompiler;
  38207. exports.CFFIndex = CFFIndex;
  38208. exports.CFFParser = CFFParser;
  38209. exports.CFFStrings = CFFStrings;
  38210. exports.ErrorFont = ErrorFont;
  38211. exports.FontFlags = FontFlags;
  38212. exports.Font = Font;
  38213. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  38214. exports.ToUnicodeMap = ToUnicodeMap;
  38215. exports.Type1Parser = Type1Parser;
  38216. exports.getFontType = getFontType;
  38217. exports._enableSeacAnalysis = _enableSeacAnalysis;
  38218. // TODO refactor to remove cyclic dependency on font_renderer.js
  38219. coreFontRenderer._setCoreFonts(exports);
  38220. }));
  38221. (function (root, factory) {
  38222. {
  38223. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  38224. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  38225. }
  38226. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  38227. var error = sharedUtil.error;
  38228. var info = sharedUtil.info;
  38229. var isArray = sharedUtil.isArray;
  38230. var isBool = sharedUtil.isBool;
  38231. var isDict = corePrimitives.isDict;
  38232. var isStream = corePrimitives.isStream;
  38233. var PostScriptLexer = corePsParser.PostScriptLexer;
  38234. var PostScriptParser = corePsParser.PostScriptParser;
  38235. var PDFFunction = (function PDFFunctionClosure() {
  38236. var CONSTRUCT_SAMPLED = 0;
  38237. var CONSTRUCT_INTERPOLATED = 2;
  38238. var CONSTRUCT_STICHED = 3;
  38239. var CONSTRUCT_POSTSCRIPT = 4;
  38240. return {
  38241. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  38242. str) {
  38243. var i, ii;
  38244. var length = 1;
  38245. for (i = 0, ii = size.length; i < ii; i++) {
  38246. length *= size[i];
  38247. }
  38248. length *= outputSize;
  38249. var array = new Array(length);
  38250. var codeSize = 0;
  38251. var codeBuf = 0;
  38252. // 32 is a valid bps so shifting won't work
  38253. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  38254. var strBytes = str.getBytes((length * bps + 7) / 8);
  38255. var strIdx = 0;
  38256. for (i = 0; i < length; i++) {
  38257. while (codeSize < bps) {
  38258. codeBuf <<= 8;
  38259. codeBuf |= strBytes[strIdx++];
  38260. codeSize += 8;
  38261. }
  38262. codeSize -= bps;
  38263. array[i] = (codeBuf >> codeSize) * sampleMul;
  38264. codeBuf &= (1 << codeSize) - 1;
  38265. }
  38266. return array;
  38267. },
  38268. getIR: function PDFFunction_getIR(xref, fn) {
  38269. var dict = fn.dict;
  38270. if (!dict) {
  38271. dict = fn;
  38272. }
  38273. var types = [this.constructSampled,
  38274. null,
  38275. this.constructInterpolated,
  38276. this.constructStiched,
  38277. this.constructPostScript];
  38278. var typeNum = dict.get('FunctionType');
  38279. var typeFn = types[typeNum];
  38280. if (!typeFn) {
  38281. error('Unknown type of function');
  38282. }
  38283. return typeFn.call(this, fn, dict, xref);
  38284. },
  38285. fromIR: function PDFFunction_fromIR(IR) {
  38286. var type = IR[0];
  38287. switch (type) {
  38288. case CONSTRUCT_SAMPLED:
  38289. return this.constructSampledFromIR(IR);
  38290. case CONSTRUCT_INTERPOLATED:
  38291. return this.constructInterpolatedFromIR(IR);
  38292. case CONSTRUCT_STICHED:
  38293. return this.constructStichedFromIR(IR);
  38294. //case CONSTRUCT_POSTSCRIPT:
  38295. default:
  38296. return this.constructPostScriptFromIR(IR);
  38297. }
  38298. },
  38299. parse: function PDFFunction_parse(xref, fn) {
  38300. var IR = this.getIR(xref, fn);
  38301. return this.fromIR(IR);
  38302. },
  38303. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  38304. if (!isArray(fnObj)) {
  38305. // not an array -- parsing as regular function
  38306. return this.parse(xref, fnObj);
  38307. }
  38308. var fnArray = [];
  38309. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  38310. var obj = xref.fetchIfRef(fnObj[j]);
  38311. fnArray.push(PDFFunction.parse(xref, obj));
  38312. }
  38313. return function (src, srcOffset, dest, destOffset) {
  38314. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  38315. fnArray[i](src, srcOffset, dest, destOffset + i);
  38316. }
  38317. };
  38318. },
  38319. constructSampled: function PDFFunction_constructSampled(str, dict) {
  38320. function toMultiArray(arr) {
  38321. var inputLength = arr.length;
  38322. var out = [];
  38323. var index = 0;
  38324. for (var i = 0; i < inputLength; i += 2) {
  38325. out[index] = [arr[i], arr[i + 1]];
  38326. ++index;
  38327. }
  38328. return out;
  38329. }
  38330. var domain = dict.get('Domain');
  38331. var range = dict.get('Range');
  38332. if (!domain || !range) {
  38333. error('No domain or range');
  38334. }
  38335. var inputSize = domain.length / 2;
  38336. var outputSize = range.length / 2;
  38337. domain = toMultiArray(domain);
  38338. range = toMultiArray(range);
  38339. var size = dict.get('Size');
  38340. var bps = dict.get('BitsPerSample');
  38341. var order = dict.get('Order') || 1;
  38342. if (order !== 1) {
  38343. // No description how cubic spline interpolation works in PDF32000:2008
  38344. // As in poppler, ignoring order, linear interpolation may work as good
  38345. info('No support for cubic spline interpolation: ' + order);
  38346. }
  38347. var encode = dict.get('Encode');
  38348. if (!encode) {
  38349. encode = [];
  38350. for (var i = 0; i < inputSize; ++i) {
  38351. encode.push(0);
  38352. encode.push(size[i] - 1);
  38353. }
  38354. }
  38355. encode = toMultiArray(encode);
  38356. var decode = dict.get('Decode');
  38357. if (!decode) {
  38358. decode = range;
  38359. } else {
  38360. decode = toMultiArray(decode);
  38361. }
  38362. var samples = this.getSampleArray(size, outputSize, bps, str);
  38363. return [
  38364. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  38365. outputSize, Math.pow(2, bps) - 1, range
  38366. ];
  38367. },
  38368. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  38369. // See chapter 3, page 109 of the PDF reference
  38370. function interpolate(x, xmin, xmax, ymin, ymax) {
  38371. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  38372. }
  38373. return function constructSampledFromIRResult(src, srcOffset,
  38374. dest, destOffset) {
  38375. // See chapter 3, page 110 of the PDF reference.
  38376. var m = IR[1];
  38377. var domain = IR[2];
  38378. var encode = IR[3];
  38379. var decode = IR[4];
  38380. var samples = IR[5];
  38381. var size = IR[6];
  38382. var n = IR[7];
  38383. //var mask = IR[8];
  38384. var range = IR[9];
  38385. // Building the cube vertices: its part and sample index
  38386. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  38387. var cubeVertices = 1 << m;
  38388. var cubeN = new Float64Array(cubeVertices);
  38389. var cubeVertex = new Uint32Array(cubeVertices);
  38390. var i, j;
  38391. for (j = 0; j < cubeVertices; j++) {
  38392. cubeN[j] = 1;
  38393. }
  38394. var k = n, pos = 1;
  38395. // Map x_i to y_j for 0 <= i < m using the sampled function.
  38396. for (i = 0; i < m; ++i) {
  38397. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  38398. var domain_2i = domain[i][0];
  38399. var domain_2i_1 = domain[i][1];
  38400. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  38401. domain_2i_1);
  38402. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  38403. // Encode_2i, Encode_2i+1)
  38404. var e = interpolate(xi, domain_2i, domain_2i_1,
  38405. encode[i][0], encode[i][1]);
  38406. // e_i' = min(max(e_i, 0), Size_i - 1)
  38407. var size_i = size[i];
  38408. e = Math.min(Math.max(e, 0), size_i - 1);
  38409. // Adjusting the cube: N and vertex sample index
  38410. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  38411. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  38412. var n1 = e - e0; // (e - e0) / (e1 - e0);
  38413. var offset0 = e0 * k;
  38414. var offset1 = offset0 + k; // e1 * k
  38415. for (j = 0; j < cubeVertices; j++) {
  38416. if (j & pos) {
  38417. cubeN[j] *= n1;
  38418. cubeVertex[j] += offset1;
  38419. } else {
  38420. cubeN[j] *= n0;
  38421. cubeVertex[j] += offset0;
  38422. }
  38423. }
  38424. k *= size_i;
  38425. pos <<= 1;
  38426. }
  38427. for (j = 0; j < n; ++j) {
  38428. // Sum all cube vertices' samples portions
  38429. var rj = 0;
  38430. for (i = 0; i < cubeVertices; i++) {
  38431. rj += samples[cubeVertex[i] + j] * cubeN[i];
  38432. }
  38433. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  38434. // Decode_2j, Decode_2j+1)
  38435. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  38436. // y_j = min(max(r_j, range_2j), range_2j+1)
  38437. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  38438. range[j][1]);
  38439. }
  38440. };
  38441. },
  38442. constructInterpolated: function PDFFunction_constructInterpolated(str,
  38443. dict) {
  38444. var c0 = dict.get('C0') || [0];
  38445. var c1 = dict.get('C1') || [1];
  38446. var n = dict.get('N');
  38447. if (!isArray(c0) || !isArray(c1)) {
  38448. error('Illegal dictionary for interpolated function');
  38449. }
  38450. var length = c0.length;
  38451. var diff = [];
  38452. for (var i = 0; i < length; ++i) {
  38453. diff.push(c1[i] - c0[i]);
  38454. }
  38455. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  38456. },
  38457. constructInterpolatedFromIR:
  38458. function PDFFunction_constructInterpolatedFromIR(IR) {
  38459. var c0 = IR[1];
  38460. var diff = IR[2];
  38461. var n = IR[3];
  38462. var length = diff.length;
  38463. return function constructInterpolatedFromIRResult(src, srcOffset,
  38464. dest, destOffset) {
  38465. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  38466. for (var j = 0; j < length; ++j) {
  38467. dest[destOffset + j] = c0[j] + (x * diff[j]);
  38468. }
  38469. };
  38470. },
  38471. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  38472. var domain = dict.get('Domain');
  38473. if (!domain) {
  38474. error('No domain');
  38475. }
  38476. var inputSize = domain.length / 2;
  38477. if (inputSize !== 1) {
  38478. error('Bad domain for stiched function');
  38479. }
  38480. var fnRefs = dict.get('Functions');
  38481. var fns = [];
  38482. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  38483. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  38484. }
  38485. var bounds = dict.get('Bounds');
  38486. var encode = dict.get('Encode');
  38487. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  38488. },
  38489. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  38490. var domain = IR[1];
  38491. var bounds = IR[2];
  38492. var encode = IR[3];
  38493. var fnsIR = IR[4];
  38494. var fns = [];
  38495. var tmpBuf = new Float32Array(1);
  38496. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  38497. fns.push(PDFFunction.fromIR(fnsIR[i]));
  38498. }
  38499. return function constructStichedFromIRResult(src, srcOffset,
  38500. dest, destOffset) {
  38501. var clip = function constructStichedFromIRClip(v, min, max) {
  38502. if (v > max) {
  38503. v = max;
  38504. } else if (v < min) {
  38505. v = min;
  38506. }
  38507. return v;
  38508. };
  38509. // clip to domain
  38510. var v = clip(src[srcOffset], domain[0], domain[1]);
  38511. // calulate which bound the value is in
  38512. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  38513. if (v < bounds[i]) {
  38514. break;
  38515. }
  38516. }
  38517. // encode value into domain of function
  38518. var dmin = domain[0];
  38519. if (i > 0) {
  38520. dmin = bounds[i - 1];
  38521. }
  38522. var dmax = domain[1];
  38523. if (i < bounds.length) {
  38524. dmax = bounds[i];
  38525. }
  38526. var rmin = encode[2 * i];
  38527. var rmax = encode[2 * i + 1];
  38528. // Prevent the value from becoming NaN as a result
  38529. // of division by zero (fixes issue6113.pdf).
  38530. tmpBuf[0] = dmin === dmax ? rmin :
  38531. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  38532. // call the appropriate function
  38533. fns[i](tmpBuf, 0, dest, destOffset);
  38534. };
  38535. },
  38536. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  38537. xref) {
  38538. var domain = dict.get('Domain');
  38539. var range = dict.get('Range');
  38540. if (!domain) {
  38541. error('No domain.');
  38542. }
  38543. if (!range) {
  38544. error('No range.');
  38545. }
  38546. var lexer = new PostScriptLexer(fn);
  38547. var parser = new PostScriptParser(lexer);
  38548. var code = parser.parse();
  38549. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  38550. },
  38551. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  38552. IR) {
  38553. var domain = IR[1];
  38554. var range = IR[2];
  38555. var code = IR[3];
  38556. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  38557. if (compiled) {
  38558. // Compiled function consists of simple expressions such as addition,
  38559. // subtraction, Math.max, and also contains 'var' and 'return'
  38560. // statements. See the generation in the PostScriptCompiler below.
  38561. /*jshint -W054 */
  38562. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  38563. }
  38564. info('Unable to compile PS function');
  38565. var numOutputs = range.length >> 1;
  38566. var numInputs = domain.length >> 1;
  38567. var evaluator = new PostScriptEvaluator(code);
  38568. // Cache the values for a big speed up, the cache size is limited though
  38569. // since the number of possible values can be huge from a PS function.
  38570. var cache = Object.create(null);
  38571. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  38572. // seen in our tests.
  38573. var MAX_CACHE_SIZE = 2048 * 4;
  38574. var cache_available = MAX_CACHE_SIZE;
  38575. var tmpBuf = new Float32Array(numInputs);
  38576. return function constructPostScriptFromIRResult(src, srcOffset,
  38577. dest, destOffset) {
  38578. var i, value;
  38579. var key = '';
  38580. var input = tmpBuf;
  38581. for (i = 0; i < numInputs; i++) {
  38582. value = src[srcOffset + i];
  38583. input[i] = value;
  38584. key += value + '_';
  38585. }
  38586. var cachedValue = cache[key];
  38587. if (cachedValue !== undefined) {
  38588. dest.set(cachedValue, destOffset);
  38589. return;
  38590. }
  38591. var output = new Float32Array(numOutputs);
  38592. var stack = evaluator.execute(input);
  38593. var stackIndex = stack.length - numOutputs;
  38594. for (i = 0; i < numOutputs; i++) {
  38595. value = stack[stackIndex + i];
  38596. var bound = range[i * 2];
  38597. if (value < bound) {
  38598. value = bound;
  38599. } else {
  38600. bound = range[i * 2 +1];
  38601. if (value > bound) {
  38602. value = bound;
  38603. }
  38604. }
  38605. output[i] = value;
  38606. }
  38607. if (cache_available > 0) {
  38608. cache_available--;
  38609. cache[key] = output;
  38610. }
  38611. dest.set(output, destOffset);
  38612. };
  38613. }
  38614. };
  38615. })();
  38616. function isPDFFunction(v) {
  38617. var fnDict;
  38618. if (typeof v !== 'object') {
  38619. return false;
  38620. } else if (isDict(v)) {
  38621. fnDict = v;
  38622. } else if (isStream(v)) {
  38623. fnDict = v.dict;
  38624. } else {
  38625. return false;
  38626. }
  38627. return fnDict.has('FunctionType');
  38628. }
  38629. var PostScriptStack = (function PostScriptStackClosure() {
  38630. var MAX_STACK_SIZE = 100;
  38631. function PostScriptStack(initialStack) {
  38632. this.stack = !initialStack ? [] :
  38633. Array.prototype.slice.call(initialStack, 0);
  38634. }
  38635. PostScriptStack.prototype = {
  38636. push: function PostScriptStack_push(value) {
  38637. if (this.stack.length >= MAX_STACK_SIZE) {
  38638. error('PostScript function stack overflow.');
  38639. }
  38640. this.stack.push(value);
  38641. },
  38642. pop: function PostScriptStack_pop() {
  38643. if (this.stack.length <= 0) {
  38644. error('PostScript function stack underflow.');
  38645. }
  38646. return this.stack.pop();
  38647. },
  38648. copy: function PostScriptStack_copy(n) {
  38649. if (this.stack.length + n >= MAX_STACK_SIZE) {
  38650. error('PostScript function stack overflow.');
  38651. }
  38652. var stack = this.stack;
  38653. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  38654. stack.push(stack[i]);
  38655. }
  38656. },
  38657. index: function PostScriptStack_index(n) {
  38658. this.push(this.stack[this.stack.length - n - 1]);
  38659. },
  38660. // rotate the last n stack elements p times
  38661. roll: function PostScriptStack_roll(n, p) {
  38662. var stack = this.stack;
  38663. var l = stack.length - n;
  38664. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  38665. for (i = l, j = r; i < j; i++, j--) {
  38666. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  38667. }
  38668. for (i = l, j = c - 1; i < j; i++, j--) {
  38669. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  38670. }
  38671. for (i = c, j = r; i < j; i++, j--) {
  38672. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  38673. }
  38674. }
  38675. };
  38676. return PostScriptStack;
  38677. })();
  38678. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  38679. function PostScriptEvaluator(operators) {
  38680. this.operators = operators;
  38681. }
  38682. PostScriptEvaluator.prototype = {
  38683. execute: function PostScriptEvaluator_execute(initialStack) {
  38684. var stack = new PostScriptStack(initialStack);
  38685. var counter = 0;
  38686. var operators = this.operators;
  38687. var length = operators.length;
  38688. var operator, a, b;
  38689. while (counter < length) {
  38690. operator = operators[counter++];
  38691. if (typeof operator === 'number') {
  38692. // Operator is really an operand and should be pushed to the stack.
  38693. stack.push(operator);
  38694. continue;
  38695. }
  38696. switch (operator) {
  38697. // non standard ps operators
  38698. case 'jz': // jump if false
  38699. b = stack.pop();
  38700. a = stack.pop();
  38701. if (!a) {
  38702. counter = b;
  38703. }
  38704. break;
  38705. case 'j': // jump
  38706. a = stack.pop();
  38707. counter = a;
  38708. break;
  38709. // all ps operators in alphabetical order (excluding if/ifelse)
  38710. case 'abs':
  38711. a = stack.pop();
  38712. stack.push(Math.abs(a));
  38713. break;
  38714. case 'add':
  38715. b = stack.pop();
  38716. a = stack.pop();
  38717. stack.push(a + b);
  38718. break;
  38719. case 'and':
  38720. b = stack.pop();
  38721. a = stack.pop();
  38722. if (isBool(a) && isBool(b)) {
  38723. stack.push(a && b);
  38724. } else {
  38725. stack.push(a & b);
  38726. }
  38727. break;
  38728. case 'atan':
  38729. a = stack.pop();
  38730. stack.push(Math.atan(a));
  38731. break;
  38732. case 'bitshift':
  38733. b = stack.pop();
  38734. a = stack.pop();
  38735. if (a > 0) {
  38736. stack.push(a << b);
  38737. } else {
  38738. stack.push(a >> b);
  38739. }
  38740. break;
  38741. case 'ceiling':
  38742. a = stack.pop();
  38743. stack.push(Math.ceil(a));
  38744. break;
  38745. case 'copy':
  38746. a = stack.pop();
  38747. stack.copy(a);
  38748. break;
  38749. case 'cos':
  38750. a = stack.pop();
  38751. stack.push(Math.cos(a));
  38752. break;
  38753. case 'cvi':
  38754. a = stack.pop() | 0;
  38755. stack.push(a);
  38756. break;
  38757. case 'cvr':
  38758. // noop
  38759. break;
  38760. case 'div':
  38761. b = stack.pop();
  38762. a = stack.pop();
  38763. stack.push(a / b);
  38764. break;
  38765. case 'dup':
  38766. stack.copy(1);
  38767. break;
  38768. case 'eq':
  38769. b = stack.pop();
  38770. a = stack.pop();
  38771. stack.push(a === b);
  38772. break;
  38773. case 'exch':
  38774. stack.roll(2, 1);
  38775. break;
  38776. case 'exp':
  38777. b = stack.pop();
  38778. a = stack.pop();
  38779. stack.push(Math.pow(a, b));
  38780. break;
  38781. case 'false':
  38782. stack.push(false);
  38783. break;
  38784. case 'floor':
  38785. a = stack.pop();
  38786. stack.push(Math.floor(a));
  38787. break;
  38788. case 'ge':
  38789. b = stack.pop();
  38790. a = stack.pop();
  38791. stack.push(a >= b);
  38792. break;
  38793. case 'gt':
  38794. b = stack.pop();
  38795. a = stack.pop();
  38796. stack.push(a > b);
  38797. break;
  38798. case 'idiv':
  38799. b = stack.pop();
  38800. a = stack.pop();
  38801. stack.push((a / b) | 0);
  38802. break;
  38803. case 'index':
  38804. a = stack.pop();
  38805. stack.index(a);
  38806. break;
  38807. case 'le':
  38808. b = stack.pop();
  38809. a = stack.pop();
  38810. stack.push(a <= b);
  38811. break;
  38812. case 'ln':
  38813. a = stack.pop();
  38814. stack.push(Math.log(a));
  38815. break;
  38816. case 'log':
  38817. a = stack.pop();
  38818. stack.push(Math.log(a) / Math.LN10);
  38819. break;
  38820. case 'lt':
  38821. b = stack.pop();
  38822. a = stack.pop();
  38823. stack.push(a < b);
  38824. break;
  38825. case 'mod':
  38826. b = stack.pop();
  38827. a = stack.pop();
  38828. stack.push(a % b);
  38829. break;
  38830. case 'mul':
  38831. b = stack.pop();
  38832. a = stack.pop();
  38833. stack.push(a * b);
  38834. break;
  38835. case 'ne':
  38836. b = stack.pop();
  38837. a = stack.pop();
  38838. stack.push(a !== b);
  38839. break;
  38840. case 'neg':
  38841. a = stack.pop();
  38842. stack.push(-a);
  38843. break;
  38844. case 'not':
  38845. a = stack.pop();
  38846. if (isBool(a)) {
  38847. stack.push(!a);
  38848. } else {
  38849. stack.push(~a);
  38850. }
  38851. break;
  38852. case 'or':
  38853. b = stack.pop();
  38854. a = stack.pop();
  38855. if (isBool(a) && isBool(b)) {
  38856. stack.push(a || b);
  38857. } else {
  38858. stack.push(a | b);
  38859. }
  38860. break;
  38861. case 'pop':
  38862. stack.pop();
  38863. break;
  38864. case 'roll':
  38865. b = stack.pop();
  38866. a = stack.pop();
  38867. stack.roll(a, b);
  38868. break;
  38869. case 'round':
  38870. a = stack.pop();
  38871. stack.push(Math.round(a));
  38872. break;
  38873. case 'sin':
  38874. a = stack.pop();
  38875. stack.push(Math.sin(a));
  38876. break;
  38877. case 'sqrt':
  38878. a = stack.pop();
  38879. stack.push(Math.sqrt(a));
  38880. break;
  38881. case 'sub':
  38882. b = stack.pop();
  38883. a = stack.pop();
  38884. stack.push(a - b);
  38885. break;
  38886. case 'true':
  38887. stack.push(true);
  38888. break;
  38889. case 'truncate':
  38890. a = stack.pop();
  38891. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  38892. stack.push(a);
  38893. break;
  38894. case 'xor':
  38895. b = stack.pop();
  38896. a = stack.pop();
  38897. if (isBool(a) && isBool(b)) {
  38898. stack.push(a !== b);
  38899. } else {
  38900. stack.push(a ^ b);
  38901. }
  38902. break;
  38903. default:
  38904. error('Unknown operator ' + operator);
  38905. break;
  38906. }
  38907. }
  38908. return stack.stack;
  38909. }
  38910. };
  38911. return PostScriptEvaluator;
  38912. })();
  38913. // Most of the PDFs functions consist of simple operations such as:
  38914. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  38915. //
  38916. // We can compile most of such programs, and at the same moment, we can
  38917. // optimize some expressions using basic math properties. Keeping track of
  38918. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  38919. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  38920. function AstNode(type) {
  38921. this.type = type;
  38922. }
  38923. AstNode.prototype.visit = function (visitor) {
  38924. throw new Error('abstract method');
  38925. };
  38926. function AstArgument(index, min, max) {
  38927. AstNode.call(this, 'args');
  38928. this.index = index;
  38929. this.min = min;
  38930. this.max = max;
  38931. }
  38932. AstArgument.prototype = Object.create(AstNode.prototype);
  38933. AstArgument.prototype.visit = function (visitor) {
  38934. visitor.visitArgument(this);
  38935. };
  38936. function AstLiteral(number) {
  38937. AstNode.call(this, 'literal');
  38938. this.number = number;
  38939. this.min = number;
  38940. this.max = number;
  38941. }
  38942. AstLiteral.prototype = Object.create(AstNode.prototype);
  38943. AstLiteral.prototype.visit = function (visitor) {
  38944. visitor.visitLiteral(this);
  38945. };
  38946. function AstBinaryOperation(op, arg1, arg2, min, max) {
  38947. AstNode.call(this, 'binary');
  38948. this.op = op;
  38949. this.arg1 = arg1;
  38950. this.arg2 = arg2;
  38951. this.min = min;
  38952. this.max = max;
  38953. }
  38954. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  38955. AstBinaryOperation.prototype.visit = function (visitor) {
  38956. visitor.visitBinaryOperation(this);
  38957. };
  38958. function AstMin(arg, max) {
  38959. AstNode.call(this, 'max');
  38960. this.arg = arg;
  38961. this.min = arg.min;
  38962. this.max = max;
  38963. }
  38964. AstMin.prototype = Object.create(AstNode.prototype);
  38965. AstMin.prototype.visit = function (visitor) {
  38966. visitor.visitMin(this);
  38967. };
  38968. function AstVariable(index, min, max) {
  38969. AstNode.call(this, 'var');
  38970. this.index = index;
  38971. this.min = min;
  38972. this.max = max;
  38973. }
  38974. AstVariable.prototype = Object.create(AstNode.prototype);
  38975. AstVariable.prototype.visit = function (visitor) {
  38976. visitor.visitVariable(this);
  38977. };
  38978. function AstVariableDefinition(variable, arg) {
  38979. AstNode.call(this, 'definition');
  38980. this.variable = variable;
  38981. this.arg = arg;
  38982. }
  38983. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  38984. AstVariableDefinition.prototype.visit = function (visitor) {
  38985. visitor.visitVariableDefinition(this);
  38986. };
  38987. function ExpressionBuilderVisitor() {
  38988. this.parts = [];
  38989. }
  38990. ExpressionBuilderVisitor.prototype = {
  38991. visitArgument: function (arg) {
  38992. this.parts.push('Math.max(', arg.min, ', Math.min(',
  38993. arg.max, ', src[srcOffset + ', arg.index, ']))');
  38994. },
  38995. visitVariable: function (variable) {
  38996. this.parts.push('v', variable.index);
  38997. },
  38998. visitLiteral: function (literal) {
  38999. this.parts.push(literal.number);
  39000. },
  39001. visitBinaryOperation: function (operation) {
  39002. this.parts.push('(');
  39003. operation.arg1.visit(this);
  39004. this.parts.push(' ', operation.op, ' ');
  39005. operation.arg2.visit(this);
  39006. this.parts.push(')');
  39007. },
  39008. visitVariableDefinition: function (definition) {
  39009. this.parts.push('var ');
  39010. definition.variable.visit(this);
  39011. this.parts.push(' = ');
  39012. definition.arg.visit(this);
  39013. this.parts.push(';');
  39014. },
  39015. visitMin: function (max) {
  39016. this.parts.push('Math.min(');
  39017. max.arg.visit(this);
  39018. this.parts.push(', ', max.max, ')');
  39019. },
  39020. toString: function () {
  39021. return this.parts.join('');
  39022. }
  39023. };
  39024. function buildAddOperation(num1, num2) {
  39025. if (num2.type === 'literal' && num2.number === 0) {
  39026. // optimization: second operand is 0
  39027. return num1;
  39028. }
  39029. if (num1.type === 'literal' && num1.number === 0) {
  39030. // optimization: first operand is 0
  39031. return num2;
  39032. }
  39033. if (num2.type === 'literal' && num1.type === 'literal') {
  39034. // optimization: operands operand are literals
  39035. return new AstLiteral(num1.number + num2.number);
  39036. }
  39037. return new AstBinaryOperation('+', num1, num2,
  39038. num1.min + num2.min, num1.max + num2.max);
  39039. }
  39040. function buildMulOperation(num1, num2) {
  39041. if (num2.type === 'literal') {
  39042. // optimization: second operands is a literal...
  39043. if (num2.number === 0) {
  39044. return new AstLiteral(0); // and it's 0
  39045. } else if (num2.number === 1) {
  39046. return num1; // and it's 1
  39047. } else if (num1.type === 'literal') {
  39048. // ... and first operands is a literal too
  39049. return new AstLiteral(num1.number * num2.number);
  39050. }
  39051. }
  39052. if (num1.type === 'literal') {
  39053. // optimization: first operands is a literal...
  39054. if (num1.number === 0) {
  39055. return new AstLiteral(0); // and it's 0
  39056. } else if (num1.number === 1) {
  39057. return num2; // and it's 1
  39058. }
  39059. }
  39060. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  39061. num1.max * num2.min, num1.max * num2.max);
  39062. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  39063. num1.max * num2.min, num1.max * num2.max);
  39064. return new AstBinaryOperation('*', num1, num2, min, max);
  39065. }
  39066. function buildSubOperation(num1, num2) {
  39067. if (num2.type === 'literal') {
  39068. // optimization: second operands is a literal...
  39069. if (num2.number === 0) {
  39070. return num1; // ... and it's 0
  39071. } else if (num1.type === 'literal') {
  39072. // ... and first operands is a literal too
  39073. return new AstLiteral(num1.number - num2.number);
  39074. }
  39075. }
  39076. if (num2.type === 'binary' && num2.op === '-' &&
  39077. num1.type === 'literal' && num1.number === 1 &&
  39078. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  39079. // optimization for case: 1 - (1 - x)
  39080. return num2.arg2;
  39081. }
  39082. return new AstBinaryOperation('-', num1, num2,
  39083. num1.min - num2.max, num1.max - num2.min);
  39084. }
  39085. function buildMinOperation(num1, max) {
  39086. if (num1.min >= max) {
  39087. // optimization: num1 min value is not less than required max
  39088. return new AstLiteral(max); // just returning max
  39089. } else if (num1.max <= max) {
  39090. // optimization: num1 max value is not greater than required max
  39091. return num1; // just returning an argument
  39092. }
  39093. return new AstMin(num1, max);
  39094. }
  39095. function PostScriptCompiler() {}
  39096. PostScriptCompiler.prototype = {
  39097. compile: function PostScriptCompiler_compile(code, domain, range) {
  39098. var stack = [];
  39099. var i, ii;
  39100. var instructions = [];
  39101. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  39102. var lastRegister = 0;
  39103. var n, j;
  39104. var num1, num2, ast1, ast2, tmpVar, item;
  39105. for (i = 0; i < inputSize; i++) {
  39106. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  39107. }
  39108. for (i = 0, ii = code.length; i < ii; i++) {
  39109. item = code[i];
  39110. if (typeof item === 'number') {
  39111. stack.push(new AstLiteral(item));
  39112. continue;
  39113. }
  39114. switch (item) {
  39115. case 'add':
  39116. if (stack.length < 2) {
  39117. return null;
  39118. }
  39119. num2 = stack.pop();
  39120. num1 = stack.pop();
  39121. stack.push(buildAddOperation(num1, num2));
  39122. break;
  39123. case 'cvr':
  39124. if (stack.length < 1) {
  39125. return null;
  39126. }
  39127. break;
  39128. case 'mul':
  39129. if (stack.length < 2) {
  39130. return null;
  39131. }
  39132. num2 = stack.pop();
  39133. num1 = stack.pop();
  39134. stack.push(buildMulOperation(num1, num2));
  39135. break;
  39136. case 'sub':
  39137. if (stack.length < 2) {
  39138. return null;
  39139. }
  39140. num2 = stack.pop();
  39141. num1 = stack.pop();
  39142. stack.push(buildSubOperation(num1, num2));
  39143. break;
  39144. case 'exch':
  39145. if (stack.length < 2) {
  39146. return null;
  39147. }
  39148. ast1 = stack.pop(); ast2 = stack.pop();
  39149. stack.push(ast1, ast2);
  39150. break;
  39151. case 'pop':
  39152. if (stack.length < 1) {
  39153. return null;
  39154. }
  39155. stack.pop();
  39156. break;
  39157. case 'index':
  39158. if (stack.length < 1) {
  39159. return null;
  39160. }
  39161. num1 = stack.pop();
  39162. if (num1.type !== 'literal') {
  39163. return null;
  39164. }
  39165. n = num1.number;
  39166. if (n < 0 || (n|0) !== n || stack.length < n) {
  39167. return null;
  39168. }
  39169. ast1 = stack[stack.length - n - 1];
  39170. if (ast1.type === 'literal' || ast1.type === 'var') {
  39171. stack.push(ast1);
  39172. break;
  39173. }
  39174. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  39175. stack[stack.length - n - 1] = tmpVar;
  39176. stack.push(tmpVar);
  39177. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  39178. break;
  39179. case 'dup':
  39180. if (stack.length < 1) {
  39181. return null;
  39182. }
  39183. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  39184. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  39185. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  39186. // special case of the commands sequence for the min operation
  39187. num1 = stack.pop();
  39188. stack.push(buildMinOperation(num1, code[i + 1]));
  39189. i += 6;
  39190. break;
  39191. }
  39192. ast1 = stack[stack.length - 1];
  39193. if (ast1.type === 'literal' || ast1.type === 'var') {
  39194. // we don't have to save into intermediate variable a literal or
  39195. // variable.
  39196. stack.push(ast1);
  39197. break;
  39198. }
  39199. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  39200. stack[stack.length - 1] = tmpVar;
  39201. stack.push(tmpVar);
  39202. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  39203. break;
  39204. case 'roll':
  39205. if (stack.length < 2) {
  39206. return null;
  39207. }
  39208. num2 = stack.pop();
  39209. num1 = stack.pop();
  39210. if (num2.type !== 'literal' || num1.type !== 'literal') {
  39211. // both roll operands must be numbers
  39212. return null;
  39213. }
  39214. j = num2.number;
  39215. n = num1.number;
  39216. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  39217. // ... and integers
  39218. return null;
  39219. }
  39220. j = ((j % n) + n) % n;
  39221. if (j === 0) {
  39222. break; // just skipping -- there are nothing to rotate
  39223. }
  39224. Array.prototype.push.apply(stack,
  39225. stack.splice(stack.length - n, n - j));
  39226. break;
  39227. default:
  39228. return null; // unsupported operator
  39229. }
  39230. }
  39231. if (stack.length !== outputSize) {
  39232. return null;
  39233. }
  39234. var result = [];
  39235. instructions.forEach(function (instruction) {
  39236. var statementBuilder = new ExpressionBuilderVisitor();
  39237. instruction.visit(statementBuilder);
  39238. result.push(statementBuilder.toString());
  39239. });
  39240. stack.forEach(function (expr, i) {
  39241. var statementBuilder = new ExpressionBuilderVisitor();
  39242. expr.visit(statementBuilder);
  39243. var min = range[i * 2], max = range[i * 2 + 1];
  39244. var out = [statementBuilder.toString()];
  39245. if (min > expr.min) {
  39246. out.unshift('Math.max(', min, ', ');
  39247. out.push(')');
  39248. }
  39249. if (max < expr.max) {
  39250. out.unshift('Math.min(', max, ', ');
  39251. out.push(')');
  39252. }
  39253. out.unshift('dest[destOffset + ', i, '] = ');
  39254. out.push(';');
  39255. result.push(out.join(''));
  39256. });
  39257. return result.join('\n');
  39258. }
  39259. };
  39260. return PostScriptCompiler;
  39261. })();
  39262. exports.isPDFFunction = isPDFFunction;
  39263. exports.PDFFunction = PDFFunction;
  39264. exports.PostScriptEvaluator = PostScriptEvaluator;
  39265. exports.PostScriptCompiler = PostScriptCompiler;
  39266. }));
  39267. (function (root, factory) {
  39268. {
  39269. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  39270. root.pdfjsCorePrimitives, root.pdfjsCoreFunction, root.pdfjsCoreStream);
  39271. }
  39272. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  39273. coreStream) {
  39274. var error = sharedUtil.error;
  39275. var info = sharedUtil.info;
  39276. var isArray = sharedUtil.isArray;
  39277. var isString = sharedUtil.isString;
  39278. var shadow = sharedUtil.shadow;
  39279. var warn = sharedUtil.warn;
  39280. var isDict = corePrimitives.isDict;
  39281. var isName = corePrimitives.isName;
  39282. var isStream = corePrimitives.isStream;
  39283. var PDFFunction = coreFunction.PDFFunction;
  39284. var coreImage; // see _setCoreImage below
  39285. var PDFImage; // = coreImage.PDFImage;
  39286. var ColorSpace = (function ColorSpaceClosure() {
  39287. // Constructor should define this.numComps, this.defaultColor, this.name
  39288. function ColorSpace() {
  39289. error('should not call ColorSpace constructor');
  39290. }
  39291. ColorSpace.prototype = {
  39292. /**
  39293. * Converts the color value to the RGB color. The color components are
  39294. * located in the src array starting from the srcOffset. Returns the array
  39295. * of the rgb components, each value ranging from [0,255].
  39296. */
  39297. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  39298. var rgb = new Uint8Array(3);
  39299. this.getRgbItem(src, srcOffset, rgb, 0);
  39300. return rgb;
  39301. },
  39302. /**
  39303. * Converts the color value to the RGB color, similar to the getRgb method.
  39304. * The result placed into the dest array starting from the destOffset.
  39305. */
  39306. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  39307. dest, destOffset) {
  39308. error('Should not call ColorSpace.getRgbItem');
  39309. },
  39310. /**
  39311. * Converts the specified number of the color values to the RGB colors.
  39312. * The colors are located in the src array starting from the srcOffset.
  39313. * The result is placed into the dest array starting from the destOffset.
  39314. * The src array items shall be in [0,2^bits) range, the dest array items
  39315. * will be in [0,255] range. alpha01 indicates how many alpha components
  39316. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  39317. * array).
  39318. */
  39319. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  39320. dest, destOffset, bits,
  39321. alpha01) {
  39322. error('Should not call ColorSpace.getRgbBuffer');
  39323. },
  39324. /**
  39325. * Determines the number of bytes required to store the result of the
  39326. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  39327. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  39328. */
  39329. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  39330. alpha01) {
  39331. error('Should not call ColorSpace.getOutputLength');
  39332. },
  39333. /**
  39334. * Returns true if source data will be equal the result/output data.
  39335. */
  39336. isPassthrough: function ColorSpace_isPassthrough(bits) {
  39337. return false;
  39338. },
  39339. /**
  39340. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  39341. * how many alpha components there are in the dest array; it will be either
  39342. * 0 (RGB array) or 1 (RGBA array).
  39343. */
  39344. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  39345. originalHeight, width, height,
  39346. actualHeight, bpc, comps, alpha01) {
  39347. var count = originalWidth * originalHeight;
  39348. var rgbBuf = null;
  39349. var numComponentColors = 1 << bpc;
  39350. var needsResizing = originalHeight !== height || originalWidth !== width;
  39351. var i, ii;
  39352. if (this.isPassthrough(bpc)) {
  39353. rgbBuf = comps;
  39354. } else if (this.numComps === 1 && count > numComponentColors &&
  39355. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  39356. // Optimization: create a color map when there is just one component and
  39357. // we are converting more colors than the size of the color map. We
  39358. // don't build the map if the colorspace is gray or rgb since those
  39359. // methods are faster than building a map. This mainly offers big speed
  39360. // ups for indexed and alternate colorspaces.
  39361. //
  39362. // TODO it may be worth while to cache the color map. While running
  39363. // testing I never hit a cache so I will leave that out for now (perhaps
  39364. // we are reparsing colorspaces too much?).
  39365. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  39366. new Uint16Array(numComponentColors);
  39367. var key;
  39368. for (i = 0; i < numComponentColors; i++) {
  39369. allColors[i] = i;
  39370. }
  39371. var colorMap = new Uint8Array(numComponentColors * 3);
  39372. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  39373. /* alpha01 = */ 0);
  39374. var destPos, rgbPos;
  39375. if (!needsResizing) {
  39376. // Fill in the RGB values directly into |dest|.
  39377. destPos = 0;
  39378. for (i = 0; i < count; ++i) {
  39379. key = comps[i] * 3;
  39380. dest[destPos++] = colorMap[key];
  39381. dest[destPos++] = colorMap[key + 1];
  39382. dest[destPos++] = colorMap[key + 2];
  39383. destPos += alpha01;
  39384. }
  39385. } else {
  39386. rgbBuf = new Uint8Array(count * 3);
  39387. rgbPos = 0;
  39388. for (i = 0; i < count; ++i) {
  39389. key = comps[i] * 3;
  39390. rgbBuf[rgbPos++] = colorMap[key];
  39391. rgbBuf[rgbPos++] = colorMap[key + 1];
  39392. rgbBuf[rgbPos++] = colorMap[key + 2];
  39393. }
  39394. }
  39395. } else {
  39396. if (!needsResizing) {
  39397. // Fill in the RGB values directly into |dest|.
  39398. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  39399. alpha01);
  39400. } else {
  39401. rgbBuf = new Uint8Array(count * 3);
  39402. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  39403. /* alpha01 = */ 0);
  39404. }
  39405. }
  39406. if (rgbBuf) {
  39407. if (needsResizing) {
  39408. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  39409. height, dest, alpha01);
  39410. } else {
  39411. rgbPos = 0;
  39412. destPos = 0;
  39413. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  39414. dest[destPos++] = rgbBuf[rgbPos++];
  39415. dest[destPos++] = rgbBuf[rgbPos++];
  39416. dest[destPos++] = rgbBuf[rgbPos++];
  39417. destPos += alpha01;
  39418. }
  39419. }
  39420. }
  39421. },
  39422. /**
  39423. * True if the colorspace has components in the default range of [0, 1].
  39424. * This should be true for all colorspaces except for lab color spaces
  39425. * which are [0,100], [-128, 127], [-128, 127].
  39426. */
  39427. usesZeroToOneRange: true
  39428. };
  39429. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  39430. var IR = ColorSpace.parseToIR(cs, xref, res);
  39431. if (IR instanceof AlternateCS) {
  39432. return IR;
  39433. }
  39434. return ColorSpace.fromIR(IR);
  39435. };
  39436. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  39437. var name = isArray(IR) ? IR[0] : IR;
  39438. var whitePoint, blackPoint, gamma;
  39439. switch (name) {
  39440. case 'DeviceGrayCS':
  39441. return this.singletons.gray;
  39442. case 'DeviceRgbCS':
  39443. return this.singletons.rgb;
  39444. case 'DeviceCmykCS':
  39445. return this.singletons.cmyk;
  39446. case 'CalGrayCS':
  39447. whitePoint = IR[1];
  39448. blackPoint = IR[2];
  39449. gamma = IR[3];
  39450. return new CalGrayCS(whitePoint, blackPoint, gamma);
  39451. case 'CalRGBCS':
  39452. whitePoint = IR[1];
  39453. blackPoint = IR[2];
  39454. gamma = IR[3];
  39455. var matrix = IR[4];
  39456. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  39457. case 'PatternCS':
  39458. var basePatternCS = IR[1];
  39459. if (basePatternCS) {
  39460. basePatternCS = ColorSpace.fromIR(basePatternCS);
  39461. }
  39462. return new PatternCS(basePatternCS);
  39463. case 'IndexedCS':
  39464. var baseIndexedCS = IR[1];
  39465. var hiVal = IR[2];
  39466. var lookup = IR[3];
  39467. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  39468. case 'AlternateCS':
  39469. var numComps = IR[1];
  39470. var alt = IR[2];
  39471. var tintFnIR = IR[3];
  39472. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  39473. PDFFunction.fromIR(tintFnIR));
  39474. case 'LabCS':
  39475. whitePoint = IR[1];
  39476. blackPoint = IR[2];
  39477. var range = IR[3];
  39478. return new LabCS(whitePoint, blackPoint, range);
  39479. default:
  39480. error('Unknown name ' + name);
  39481. }
  39482. return null;
  39483. };
  39484. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  39485. if (isName(cs)) {
  39486. var colorSpaces = res.get('ColorSpace');
  39487. if (isDict(colorSpaces)) {
  39488. var refcs = colorSpaces.get(cs.name);
  39489. if (refcs) {
  39490. cs = refcs;
  39491. }
  39492. }
  39493. }
  39494. cs = xref.fetchIfRef(cs);
  39495. var mode;
  39496. if (isName(cs)) {
  39497. mode = cs.name;
  39498. this.mode = mode;
  39499. switch (mode) {
  39500. case 'DeviceGray':
  39501. case 'G':
  39502. return 'DeviceGrayCS';
  39503. case 'DeviceRGB':
  39504. case 'RGB':
  39505. return 'DeviceRgbCS';
  39506. case 'DeviceCMYK':
  39507. case 'CMYK':
  39508. return 'DeviceCmykCS';
  39509. case 'Pattern':
  39510. return ['PatternCS', null];
  39511. default:
  39512. error('unrecognized colorspace ' + mode);
  39513. }
  39514. } else if (isArray(cs)) {
  39515. mode = xref.fetchIfRef(cs[0]).name;
  39516. this.mode = mode;
  39517. var numComps, params, alt, whitePoint, blackPoint, gamma;
  39518. switch (mode) {
  39519. case 'DeviceGray':
  39520. case 'G':
  39521. return 'DeviceGrayCS';
  39522. case 'DeviceRGB':
  39523. case 'RGB':
  39524. return 'DeviceRgbCS';
  39525. case 'DeviceCMYK':
  39526. case 'CMYK':
  39527. return 'DeviceCmykCS';
  39528. case 'CalGray':
  39529. params = xref.fetchIfRef(cs[1]);
  39530. whitePoint = params.get('WhitePoint');
  39531. blackPoint = params.get('BlackPoint');
  39532. gamma = params.get('Gamma');
  39533. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  39534. case 'CalRGB':
  39535. params = xref.fetchIfRef(cs[1]);
  39536. whitePoint = params.get('WhitePoint');
  39537. blackPoint = params.get('BlackPoint');
  39538. gamma = params.get('Gamma');
  39539. var matrix = params.get('Matrix');
  39540. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  39541. case 'ICCBased':
  39542. var stream = xref.fetchIfRef(cs[1]);
  39543. var dict = stream.dict;
  39544. numComps = dict.get('N');
  39545. alt = dict.get('Alternate');
  39546. if (alt) {
  39547. var altIR = ColorSpace.parseToIR(alt, xref, res);
  39548. // Parse the /Alternate CS to ensure that the number of components
  39549. // are correct, and also (indirectly) that it is not a PatternCS.
  39550. var altCS = ColorSpace.fromIR(altIR);
  39551. if (altCS.numComps === numComps) {
  39552. return altIR;
  39553. }
  39554. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  39555. }
  39556. if (numComps === 1) {
  39557. return 'DeviceGrayCS';
  39558. } else if (numComps === 3) {
  39559. return 'DeviceRgbCS';
  39560. } else if (numComps === 4) {
  39561. return 'DeviceCmykCS';
  39562. }
  39563. break;
  39564. case 'Pattern':
  39565. var basePatternCS = cs[1] || null;
  39566. if (basePatternCS) {
  39567. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  39568. }
  39569. return ['PatternCS', basePatternCS];
  39570. case 'Indexed':
  39571. case 'I':
  39572. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  39573. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  39574. var lookup = xref.fetchIfRef(cs[3]);
  39575. if (isStream(lookup)) {
  39576. lookup = lookup.getBytes();
  39577. }
  39578. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  39579. case 'Separation':
  39580. case 'DeviceN':
  39581. var name = xref.fetchIfRef(cs[1]);
  39582. numComps = 1;
  39583. if (isName(name)) {
  39584. numComps = 1;
  39585. } else if (isArray(name)) {
  39586. numComps = name.length;
  39587. }
  39588. alt = ColorSpace.parseToIR(cs[2], xref, res);
  39589. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  39590. return ['AlternateCS', numComps, alt, tintFnIR];
  39591. case 'Lab':
  39592. params = xref.fetchIfRef(cs[1]);
  39593. whitePoint = params.get('WhitePoint');
  39594. blackPoint = params.get('BlackPoint');
  39595. var range = params.get('Range');
  39596. return ['LabCS', whitePoint, blackPoint, range];
  39597. default:
  39598. error('unimplemented color space object "' + mode + '"');
  39599. }
  39600. } else {
  39601. error('unrecognized color space object: "' + cs + '"');
  39602. }
  39603. return null;
  39604. };
  39605. /**
  39606. * Checks if a decode map matches the default decode map for a color space.
  39607. * This handles the general decode maps where there are two values per
  39608. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  39609. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  39610. * slightly different.
  39611. * @param {Array} decode Decode map (usually from an image).
  39612. * @param {Number} n Number of components the color space has.
  39613. */
  39614. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  39615. if (!isArray(decode)) {
  39616. return true;
  39617. }
  39618. if (n * 2 !== decode.length) {
  39619. warn('The decode map is not the correct length');
  39620. return true;
  39621. }
  39622. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  39623. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  39624. return false;
  39625. }
  39626. }
  39627. return true;
  39628. };
  39629. ColorSpace.singletons = {
  39630. get gray() {
  39631. return shadow(this, 'gray', new DeviceGrayCS());
  39632. },
  39633. get rgb() {
  39634. return shadow(this, 'rgb', new DeviceRgbCS());
  39635. },
  39636. get cmyk() {
  39637. return shadow(this, 'cmyk', new DeviceCmykCS());
  39638. }
  39639. };
  39640. return ColorSpace;
  39641. })();
  39642. /**
  39643. * Alternate color space handles both Separation and DeviceN color spaces. A
  39644. * Separation color space is actually just a DeviceN with one color component.
  39645. * Both color spaces use a tinting function to convert colors to a base color
  39646. * space.
  39647. */
  39648. var AlternateCS = (function AlternateCSClosure() {
  39649. function AlternateCS(numComps, base, tintFn) {
  39650. this.name = 'Alternate';
  39651. this.numComps = numComps;
  39652. this.defaultColor = new Float32Array(numComps);
  39653. for (var i = 0; i < numComps; ++i) {
  39654. this.defaultColor[i] = 1;
  39655. }
  39656. this.base = base;
  39657. this.tintFn = tintFn;
  39658. this.tmpBuf = new Float32Array(base.numComps);
  39659. }
  39660. AlternateCS.prototype = {
  39661. getRgb: ColorSpace.prototype.getRgb,
  39662. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  39663. dest, destOffset) {
  39664. var tmpBuf = this.tmpBuf;
  39665. this.tintFn(src, srcOffset, tmpBuf, 0);
  39666. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  39667. },
  39668. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  39669. dest, destOffset, bits,
  39670. alpha01) {
  39671. var tintFn = this.tintFn;
  39672. var base = this.base;
  39673. var scale = 1 / ((1 << bits) - 1);
  39674. var baseNumComps = base.numComps;
  39675. var usesZeroToOneRange = base.usesZeroToOneRange;
  39676. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  39677. alpha01 === 0;
  39678. var pos = isPassthrough ? destOffset : 0;
  39679. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  39680. var numComps = this.numComps;
  39681. var scaled = new Float32Array(numComps);
  39682. var tinted = new Float32Array(baseNumComps);
  39683. var i, j;
  39684. if (usesZeroToOneRange) {
  39685. for (i = 0; i < count; i++) {
  39686. for (j = 0; j < numComps; j++) {
  39687. scaled[j] = src[srcOffset++] * scale;
  39688. }
  39689. tintFn(scaled, 0, tinted, 0);
  39690. for (j = 0; j < baseNumComps; j++) {
  39691. baseBuf[pos++] = tinted[j] * 255;
  39692. }
  39693. }
  39694. } else {
  39695. for (i = 0; i < count; i++) {
  39696. for (j = 0; j < numComps; j++) {
  39697. scaled[j] = src[srcOffset++] * scale;
  39698. }
  39699. tintFn(scaled, 0, tinted, 0);
  39700. base.getRgbItem(tinted, 0, baseBuf, pos);
  39701. pos += baseNumComps;
  39702. }
  39703. }
  39704. if (!isPassthrough) {
  39705. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  39706. }
  39707. },
  39708. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  39709. alpha01) {
  39710. return this.base.getOutputLength(inputLength *
  39711. this.base.numComps / this.numComps,
  39712. alpha01);
  39713. },
  39714. isPassthrough: ColorSpace.prototype.isPassthrough,
  39715. fillRgb: ColorSpace.prototype.fillRgb,
  39716. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  39717. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39718. },
  39719. usesZeroToOneRange: true
  39720. };
  39721. return AlternateCS;
  39722. })();
  39723. var PatternCS = (function PatternCSClosure() {
  39724. function PatternCS(baseCS) {
  39725. this.name = 'Pattern';
  39726. this.base = baseCS;
  39727. }
  39728. PatternCS.prototype = {};
  39729. return PatternCS;
  39730. })();
  39731. var IndexedCS = (function IndexedCSClosure() {
  39732. function IndexedCS(base, highVal, lookup) {
  39733. this.name = 'Indexed';
  39734. this.numComps = 1;
  39735. this.defaultColor = new Uint8Array([0]);
  39736. this.base = base;
  39737. this.highVal = highVal;
  39738. var baseNumComps = base.numComps;
  39739. var length = baseNumComps * highVal;
  39740. var lookupArray;
  39741. if (isStream(lookup)) {
  39742. lookupArray = new Uint8Array(length);
  39743. var bytes = lookup.getBytes(length);
  39744. lookupArray.set(bytes);
  39745. } else if (isString(lookup)) {
  39746. lookupArray = new Uint8Array(length);
  39747. for (var i = 0; i < length; ++i) {
  39748. lookupArray[i] = lookup.charCodeAt(i);
  39749. }
  39750. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  39751. lookupArray = lookup;
  39752. } else {
  39753. error('Unrecognized lookup table: ' + lookup);
  39754. }
  39755. this.lookup = lookupArray;
  39756. }
  39757. IndexedCS.prototype = {
  39758. getRgb: ColorSpace.prototype.getRgb,
  39759. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  39760. dest, destOffset) {
  39761. var numComps = this.base.numComps;
  39762. var start = src[srcOffset] * numComps;
  39763. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  39764. },
  39765. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  39766. dest, destOffset, bits,
  39767. alpha01) {
  39768. var base = this.base;
  39769. var numComps = base.numComps;
  39770. var outputDelta = base.getOutputLength(numComps, alpha01);
  39771. var lookup = this.lookup;
  39772. for (var i = 0; i < count; ++i) {
  39773. var lookupPos = src[srcOffset++] * numComps;
  39774. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  39775. destOffset += outputDelta;
  39776. }
  39777. },
  39778. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  39779. return this.base.getOutputLength(inputLength * this.base.numComps,
  39780. alpha01);
  39781. },
  39782. isPassthrough: ColorSpace.prototype.isPassthrough,
  39783. fillRgb: ColorSpace.prototype.fillRgb,
  39784. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  39785. // indexed color maps shouldn't be changed
  39786. return true;
  39787. },
  39788. usesZeroToOneRange: true
  39789. };
  39790. return IndexedCS;
  39791. })();
  39792. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  39793. function DeviceGrayCS() {
  39794. this.name = 'DeviceGray';
  39795. this.numComps = 1;
  39796. this.defaultColor = new Float32Array([0]);
  39797. }
  39798. DeviceGrayCS.prototype = {
  39799. getRgb: ColorSpace.prototype.getRgb,
  39800. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  39801. dest, destOffset) {
  39802. var c = (src[srcOffset] * 255) | 0;
  39803. c = c < 0 ? 0 : c > 255 ? 255 : c;
  39804. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  39805. },
  39806. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  39807. dest, destOffset, bits,
  39808. alpha01) {
  39809. var scale = 255 / ((1 << bits) - 1);
  39810. var j = srcOffset, q = destOffset;
  39811. for (var i = 0; i < count; ++i) {
  39812. var c = (scale * src[j++]) | 0;
  39813. dest[q++] = c;
  39814. dest[q++] = c;
  39815. dest[q++] = c;
  39816. q += alpha01;
  39817. }
  39818. },
  39819. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  39820. alpha01) {
  39821. return inputLength * (3 + alpha01);
  39822. },
  39823. isPassthrough: ColorSpace.prototype.isPassthrough,
  39824. fillRgb: ColorSpace.prototype.fillRgb,
  39825. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  39826. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39827. },
  39828. usesZeroToOneRange: true
  39829. };
  39830. return DeviceGrayCS;
  39831. })();
  39832. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  39833. function DeviceRgbCS() {
  39834. this.name = 'DeviceRGB';
  39835. this.numComps = 3;
  39836. this.defaultColor = new Float32Array([0, 0, 0]);
  39837. }
  39838. DeviceRgbCS.prototype = {
  39839. getRgb: ColorSpace.prototype.getRgb,
  39840. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  39841. dest, destOffset) {
  39842. var r = (src[srcOffset] * 255) | 0;
  39843. var g = (src[srcOffset + 1] * 255) | 0;
  39844. var b = (src[srcOffset + 2] * 255) | 0;
  39845. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  39846. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  39847. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  39848. },
  39849. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  39850. dest, destOffset, bits,
  39851. alpha01) {
  39852. if (bits === 8 && alpha01 === 0) {
  39853. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  39854. return;
  39855. }
  39856. var scale = 255 / ((1 << bits) - 1);
  39857. var j = srcOffset, q = destOffset;
  39858. for (var i = 0; i < count; ++i) {
  39859. dest[q++] = (scale * src[j++]) | 0;
  39860. dest[q++] = (scale * src[j++]) | 0;
  39861. dest[q++] = (scale * src[j++]) | 0;
  39862. q += alpha01;
  39863. }
  39864. },
  39865. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  39866. alpha01) {
  39867. return (inputLength * (3 + alpha01) / 3) | 0;
  39868. },
  39869. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  39870. return bits === 8;
  39871. },
  39872. fillRgb: ColorSpace.prototype.fillRgb,
  39873. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  39874. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39875. },
  39876. usesZeroToOneRange: true
  39877. };
  39878. return DeviceRgbCS;
  39879. })();
  39880. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  39881. // The coefficients below was found using numerical analysis: the method of
  39882. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  39883. // where color_value is the tabular value from the table of sampled RGB colors
  39884. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  39885. // CMYK color conversion using the estimation below:
  39886. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  39887. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  39888. var c = src[srcOffset + 0] * srcScale;
  39889. var m = src[srcOffset + 1] * srcScale;
  39890. var y = src[srcOffset + 2] * srcScale;
  39891. var k = src[srcOffset + 3] * srcScale;
  39892. var r =
  39893. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  39894. 18.82290502165302 * y + 212.25662451639585 * k +
  39895. -285.2331026137004) +
  39896. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  39897. -17.873870861415444 * k - 5.497006427196366) +
  39898. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  39899. 17.5119270841813) +
  39900. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  39901. var g =
  39902. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  39903. 6.871425592049007 * y + 31.159100130055922 * k +
  39904. -79.2970844816548) +
  39905. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  39906. 131.35250912493976 * k - 190.9453302588951) +
  39907. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  39908. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  39909. var b =
  39910. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  39911. 30.89978309703729 * y - 0.23883238689178934 * k +
  39912. -14.183576799673286) +
  39913. m * (10.49593273432072 * m + 63.02378494754052 * y +
  39914. 50.606957656360734 * k - 112.23884253719248) +
  39915. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  39916. -193.58209356861505) +
  39917. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  39918. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  39919. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  39920. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  39921. }
  39922. function DeviceCmykCS() {
  39923. this.name = 'DeviceCMYK';
  39924. this.numComps = 4;
  39925. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  39926. }
  39927. DeviceCmykCS.prototype = {
  39928. getRgb: ColorSpace.prototype.getRgb,
  39929. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  39930. dest, destOffset) {
  39931. convertToRgb(src, srcOffset, 1, dest, destOffset);
  39932. },
  39933. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  39934. dest, destOffset, bits,
  39935. alpha01) {
  39936. var scale = 1 / ((1 << bits) - 1);
  39937. for (var i = 0; i < count; i++) {
  39938. convertToRgb(src, srcOffset, scale, dest, destOffset);
  39939. srcOffset += 4;
  39940. destOffset += 3 + alpha01;
  39941. }
  39942. },
  39943. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  39944. alpha01) {
  39945. return (inputLength / 4 * (3 + alpha01)) | 0;
  39946. },
  39947. isPassthrough: ColorSpace.prototype.isPassthrough,
  39948. fillRgb: ColorSpace.prototype.fillRgb,
  39949. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  39950. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  39951. },
  39952. usesZeroToOneRange: true
  39953. };
  39954. return DeviceCmykCS;
  39955. })();
  39956. //
  39957. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  39958. //
  39959. var CalGrayCS = (function CalGrayCSClosure() {
  39960. function CalGrayCS(whitePoint, blackPoint, gamma) {
  39961. this.name = 'CalGray';
  39962. this.numComps = 1;
  39963. this.defaultColor = new Float32Array([0]);
  39964. if (!whitePoint) {
  39965. error('WhitePoint missing - required for color space CalGray');
  39966. }
  39967. blackPoint = blackPoint || [0, 0, 0];
  39968. gamma = gamma || 1;
  39969. // Translate arguments to spec variables.
  39970. this.XW = whitePoint[0];
  39971. this.YW = whitePoint[1];
  39972. this.ZW = whitePoint[2];
  39973. this.XB = blackPoint[0];
  39974. this.YB = blackPoint[1];
  39975. this.ZB = blackPoint[2];
  39976. this.G = gamma;
  39977. // Validate variables as per spec.
  39978. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  39979. error('Invalid WhitePoint components for ' + this.name +
  39980. ', no fallback available');
  39981. }
  39982. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  39983. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  39984. this.XB = this.YB = this.ZB = 0;
  39985. }
  39986. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  39987. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  39988. ', ZB: ' + this.ZB + ', only default values are supported.');
  39989. }
  39990. if (this.G < 1) {
  39991. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  39992. ', falling back to default');
  39993. this.G = 1;
  39994. }
  39995. }
  39996. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  39997. // A represents a gray component of a calibrated gray space.
  39998. // A <---> AG in the spec
  39999. var A = src[srcOffset] * scale;
  40000. var AG = Math.pow(A, cs.G);
  40001. // Computes L as per spec. ( = cs.YW * AG )
  40002. // Except if other than default BlackPoint values are used.
  40003. var L = cs.YW * AG;
  40004. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  40005. // Convert values to rgb range [0, 255].
  40006. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  40007. dest[destOffset] = val;
  40008. dest[destOffset + 1] = val;
  40009. dest[destOffset + 2] = val;
  40010. }
  40011. CalGrayCS.prototype = {
  40012. getRgb: ColorSpace.prototype.getRgb,
  40013. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  40014. dest, destOffset) {
  40015. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  40016. },
  40017. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  40018. dest, destOffset, bits,
  40019. alpha01) {
  40020. var scale = 1 / ((1 << bits) - 1);
  40021. for (var i = 0; i < count; ++i) {
  40022. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  40023. srcOffset += 1;
  40024. destOffset += 3 + alpha01;
  40025. }
  40026. },
  40027. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  40028. return inputLength * (3 + alpha01);
  40029. },
  40030. isPassthrough: ColorSpace.prototype.isPassthrough,
  40031. fillRgb: ColorSpace.prototype.fillRgb,
  40032. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  40033. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  40034. },
  40035. usesZeroToOneRange: true
  40036. };
  40037. return CalGrayCS;
  40038. })();
  40039. //
  40040. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  40041. //
  40042. var CalRGBCS = (function CalRGBCSClosure() {
  40043. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  40044. // matrices.
  40045. var BRADFORD_SCALE_MATRIX = new Float32Array([
  40046. 0.8951, 0.2664, -0.1614,
  40047. -0.7502, 1.7135, 0.0367,
  40048. 0.0389, -0.0685, 1.0296]);
  40049. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  40050. 0.9869929, -0.1470543, 0.1599627,
  40051. 0.4323053, 0.5183603, 0.0492912,
  40052. -0.0085287, 0.0400428, 0.9684867]);
  40053. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  40054. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  40055. 3.2404542, -1.5371385, -0.4985314,
  40056. -0.9692660, 1.8760108, 0.0415560,
  40057. 0.0556434, -0.2040259, 1.0572252]);
  40058. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  40059. var tempNormalizeMatrix = new Float32Array(3);
  40060. var tempConvertMatrix1 = new Float32Array(3);
  40061. var tempConvertMatrix2 = new Float32Array(3);
  40062. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  40063. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  40064. this.name = 'CalRGB';
  40065. this.numComps = 3;
  40066. this.defaultColor = new Float32Array(3);
  40067. if (!whitePoint) {
  40068. error('WhitePoint missing - required for color space CalRGB');
  40069. }
  40070. blackPoint = blackPoint || new Float32Array(3);
  40071. gamma = gamma || new Float32Array([1, 1, 1]);
  40072. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  40073. // Translate arguments to spec variables.
  40074. var XW = whitePoint[0];
  40075. var YW = whitePoint[1];
  40076. var ZW = whitePoint[2];
  40077. this.whitePoint = whitePoint;
  40078. var XB = blackPoint[0];
  40079. var YB = blackPoint[1];
  40080. var ZB = blackPoint[2];
  40081. this.blackPoint = blackPoint;
  40082. this.GR = gamma[0];
  40083. this.GG = gamma[1];
  40084. this.GB = gamma[2];
  40085. this.MXA = matrix[0];
  40086. this.MYA = matrix[1];
  40087. this.MZA = matrix[2];
  40088. this.MXB = matrix[3];
  40089. this.MYB = matrix[4];
  40090. this.MZB = matrix[5];
  40091. this.MXC = matrix[6];
  40092. this.MYC = matrix[7];
  40093. this.MZC = matrix[8];
  40094. // Validate variables as per spec.
  40095. if (XW < 0 || ZW < 0 || YW !== 1) {
  40096. error('Invalid WhitePoint components for ' + this.name +
  40097. ', no fallback available');
  40098. }
  40099. if (XB < 0 || YB < 0 || ZB < 0) {
  40100. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  40101. ', ' + ZB + '], falling back to default');
  40102. this.blackPoint = new Float32Array(3);
  40103. }
  40104. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  40105. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  40106. '] for ' + this.name + ', falling back to default');
  40107. this.GR = this.GG = this.GB = 1;
  40108. }
  40109. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  40110. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  40111. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  40112. info('Invalid Matrix for ' + this.name + ' [' +
  40113. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  40114. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  40115. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  40116. '], falling back to default');
  40117. this.MXA = this.MYB = this.MZC = 1;
  40118. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  40119. }
  40120. }
  40121. function matrixProduct(a, b, result) {
  40122. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  40123. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  40124. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  40125. }
  40126. function convertToFlat(sourceWhitePoint, LMS, result) {
  40127. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  40128. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  40129. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  40130. }
  40131. function convertToD65(sourceWhitePoint, LMS, result) {
  40132. var D65X = 0.95047;
  40133. var D65Y = 1;
  40134. var D65Z = 1.08883;
  40135. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  40136. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  40137. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  40138. }
  40139. function sRGBTransferFunction(color) {
  40140. // See http://en.wikipedia.org/wiki/SRGB.
  40141. if (color <= 0.0031308){
  40142. return adjustToRange(0, 1, 12.92 * color);
  40143. }
  40144. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  40145. }
  40146. function adjustToRange(min, max, value) {
  40147. return Math.max(min, Math.min(max, value));
  40148. }
  40149. function decodeL(L) {
  40150. if (L < 0) {
  40151. return -decodeL(-L);
  40152. }
  40153. if (L > 8.0) {
  40154. return Math.pow(((L + 16) / 116), 3);
  40155. }
  40156. return L * DECODE_L_CONSTANT;
  40157. }
  40158. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  40159. // In case the blackPoint is already the default blackPoint then there is
  40160. // no need to do compensation.
  40161. if (sourceBlackPoint[0] === 0 &&
  40162. sourceBlackPoint[1] === 0 &&
  40163. sourceBlackPoint[2] === 0) {
  40164. result[0] = XYZ_Flat[0];
  40165. result[1] = XYZ_Flat[1];
  40166. result[2] = XYZ_Flat[2];
  40167. return;
  40168. }
  40169. // For the blackPoint calculation details, please see
  40170. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  40171. // AdobeBPC.pdf.
  40172. // The destination blackPoint is the default blackPoint [0, 0, 0].
  40173. var zeroDecodeL = decodeL(0);
  40174. var X_DST = zeroDecodeL;
  40175. var X_SRC = decodeL(sourceBlackPoint[0]);
  40176. var Y_DST = zeroDecodeL;
  40177. var Y_SRC = decodeL(sourceBlackPoint[1]);
  40178. var Z_DST = zeroDecodeL;
  40179. var Z_SRC = decodeL(sourceBlackPoint[2]);
  40180. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  40181. var X_Offset = 1 - X_Scale;
  40182. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  40183. var Y_Offset = 1 - Y_Scale;
  40184. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  40185. var Z_Offset = 1 - Z_Scale;
  40186. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  40187. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  40188. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  40189. }
  40190. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  40191. // In case the whitePoint is already flat then there is no need to do
  40192. // normalization.
  40193. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  40194. result[0] = XYZ_In[0];
  40195. result[1] = XYZ_In[1];
  40196. result[2] = XYZ_In[2];
  40197. return;
  40198. }
  40199. var LMS = result;
  40200. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  40201. var LMS_Flat = tempNormalizeMatrix;
  40202. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  40203. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  40204. }
  40205. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  40206. var LMS = result;
  40207. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  40208. var LMS_D65 = tempNormalizeMatrix;
  40209. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  40210. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  40211. }
  40212. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  40213. // A, B and C represent a red, green and blue components of a calibrated
  40214. // rgb space.
  40215. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  40216. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  40217. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  40218. // A <---> AGR in the spec
  40219. // B <---> BGG in the spec
  40220. // C <---> CGB in the spec
  40221. var AGR = Math.pow(A, cs.GR);
  40222. var BGG = Math.pow(B, cs.GG);
  40223. var CGB = Math.pow(C, cs.GB);
  40224. // Computes intermediate variables L, M, N as per spec.
  40225. // To decode X, Y, Z values map L, M, N directly to them.
  40226. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  40227. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  40228. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  40229. // The following calculations are based on this document:
  40230. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  40231. // AdobeBPC.pdf.
  40232. var XYZ = tempConvertMatrix1;
  40233. XYZ[0] = X;
  40234. XYZ[1] = Y;
  40235. XYZ[2] = Z;
  40236. var XYZ_Flat = tempConvertMatrix2;
  40237. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  40238. var XYZ_Black = tempConvertMatrix1;
  40239. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  40240. var XYZ_D65 = tempConvertMatrix2;
  40241. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  40242. var SRGB = tempConvertMatrix1;
  40243. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  40244. var sR = sRGBTransferFunction(SRGB[0]);
  40245. var sG = sRGBTransferFunction(SRGB[1]);
  40246. var sB = sRGBTransferFunction(SRGB[2]);
  40247. // Convert the values to rgb range [0, 255].
  40248. dest[destOffset] = Math.round(sR * 255);
  40249. dest[destOffset + 1] = Math.round(sG * 255);
  40250. dest[destOffset + 2] = Math.round(sB * 255);
  40251. }
  40252. CalRGBCS.prototype = {
  40253. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  40254. var rgb = new Uint8Array(3);
  40255. this.getRgbItem(src, srcOffset, rgb, 0);
  40256. return rgb;
  40257. },
  40258. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  40259. dest, destOffset) {
  40260. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  40261. },
  40262. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  40263. dest, destOffset, bits,
  40264. alpha01) {
  40265. var scale = 1 / ((1 << bits) - 1);
  40266. for (var i = 0; i < count; ++i) {
  40267. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  40268. srcOffset += 3;
  40269. destOffset += 3 + alpha01;
  40270. }
  40271. },
  40272. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  40273. return (inputLength * (3 + alpha01) / 3) | 0;
  40274. },
  40275. isPassthrough: ColorSpace.prototype.isPassthrough,
  40276. fillRgb: ColorSpace.prototype.fillRgb,
  40277. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  40278. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  40279. },
  40280. usesZeroToOneRange: true
  40281. };
  40282. return CalRGBCS;
  40283. })();
  40284. //
  40285. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  40286. //
  40287. var LabCS = (function LabCSClosure() {
  40288. function LabCS(whitePoint, blackPoint, range) {
  40289. this.name = 'Lab';
  40290. this.numComps = 3;
  40291. this.defaultColor = new Float32Array([0, 0, 0]);
  40292. if (!whitePoint) {
  40293. error('WhitePoint missing - required for color space Lab');
  40294. }
  40295. blackPoint = blackPoint || [0, 0, 0];
  40296. range = range || [-100, 100, -100, 100];
  40297. // Translate args to spec variables
  40298. this.XW = whitePoint[0];
  40299. this.YW = whitePoint[1];
  40300. this.ZW = whitePoint[2];
  40301. this.amin = range[0];
  40302. this.amax = range[1];
  40303. this.bmin = range[2];
  40304. this.bmax = range[3];
  40305. // These are here just for completeness - the spec doesn't offer any
  40306. // formulas that use BlackPoint in Lab
  40307. this.XB = blackPoint[0];
  40308. this.YB = blackPoint[1];
  40309. this.ZB = blackPoint[2];
  40310. // Validate vars as per spec
  40311. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  40312. error('Invalid WhitePoint components, no fallback available');
  40313. }
  40314. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  40315. info('Invalid BlackPoint, falling back to default');
  40316. this.XB = this.YB = this.ZB = 0;
  40317. }
  40318. if (this.amin > this.amax || this.bmin > this.bmax) {
  40319. info('Invalid Range, falling back to defaults');
  40320. this.amin = -100;
  40321. this.amax = 100;
  40322. this.bmin = -100;
  40323. this.bmax = 100;
  40324. }
  40325. }
  40326. // Function g(x) from spec
  40327. function fn_g(x) {
  40328. if (x >= 6 / 29) {
  40329. return x * x * x;
  40330. } else {
  40331. return (108 / 841) * (x - 4 / 29);
  40332. }
  40333. }
  40334. function decode(value, high1, low2, high2) {
  40335. return low2 + (value) * (high2 - low2) / (high1);
  40336. }
  40337. // If decoding is needed maxVal should be 2^bits per component - 1.
  40338. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  40339. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  40340. // not the usual [0, 1]. If a command like setFillColor is used the src
  40341. // values will already be within the correct range. However, if we are
  40342. // converting an image we have to map the values to the correct range given
  40343. // above.
  40344. // Ls,as,bs <---> L*,a*,b* in the spec
  40345. var Ls = src[srcOffset];
  40346. var as = src[srcOffset + 1];
  40347. var bs = src[srcOffset + 2];
  40348. if (maxVal !== false) {
  40349. Ls = decode(Ls, maxVal, 0, 100);
  40350. as = decode(as, maxVal, cs.amin, cs.amax);
  40351. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  40352. }
  40353. // Adjust limits of 'as' and 'bs'
  40354. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  40355. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  40356. // Computes intermediate variables X,Y,Z as per spec
  40357. var M = (Ls + 16) / 116;
  40358. var L = M + (as / 500);
  40359. var N = M - (bs / 200);
  40360. var X = cs.XW * fn_g(L);
  40361. var Y = cs.YW * fn_g(M);
  40362. var Z = cs.ZW * fn_g(N);
  40363. var r, g, b;
  40364. // Using different conversions for D50 and D65 white points,
  40365. // per http://www.color.org/srgb.pdf
  40366. if (cs.ZW < 1) {
  40367. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  40368. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  40369. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  40370. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  40371. } else {
  40372. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  40373. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  40374. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  40375. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  40376. }
  40377. // clamp color values to [0,1] range then convert to [0,255] range.
  40378. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  40379. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  40380. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  40381. }
  40382. LabCS.prototype = {
  40383. getRgb: ColorSpace.prototype.getRgb,
  40384. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  40385. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  40386. },
  40387. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  40388. dest, destOffset, bits,
  40389. alpha01) {
  40390. var maxVal = (1 << bits) - 1;
  40391. for (var i = 0; i < count; i++) {
  40392. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  40393. srcOffset += 3;
  40394. destOffset += 3 + alpha01;
  40395. }
  40396. },
  40397. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  40398. return (inputLength * (3 + alpha01) / 3) | 0;
  40399. },
  40400. isPassthrough: ColorSpace.prototype.isPassthrough,
  40401. fillRgb: ColorSpace.prototype.fillRgb,
  40402. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  40403. // XXX: Decoding is handled with the lab conversion because of the strange
  40404. // ranges that are used.
  40405. return true;
  40406. },
  40407. usesZeroToOneRange: false
  40408. };
  40409. return LabCS;
  40410. })();
  40411. // TODO refactor to remove dependency on image.js
  40412. function _setCoreImage(coreImage_) {
  40413. coreImage = coreImage_;
  40414. PDFImage = coreImage_.PDFImage;
  40415. }
  40416. exports._setCoreImage = _setCoreImage;
  40417. exports.ColorSpace = ColorSpace;
  40418. // TODO refactor to remove dependency on colorspace.js
  40419. coreStream._setCoreColorSpace(exports);
  40420. }));
  40421. (function (root, factory) {
  40422. {
  40423. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  40424. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  40425. root.pdfjsCoreJpx);
  40426. }
  40427. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  40428. coreStream, coreJpx) {
  40429. var ImageKind = sharedUtil.ImageKind;
  40430. var assert = sharedUtil.assert;
  40431. var error = sharedUtil.error;
  40432. var info = sharedUtil.info;
  40433. var isArray = sharedUtil.isArray;
  40434. var warn = sharedUtil.warn;
  40435. var Name = corePrimitives.Name;
  40436. var isStream = corePrimitives.isStream;
  40437. var ColorSpace = coreColorSpace.ColorSpace;
  40438. var DecodeStream = coreStream.DecodeStream;
  40439. var Stream = coreStream.Stream;
  40440. var JpegStream = coreStream.JpegStream;
  40441. var JpxImage = coreJpx.JpxImage;
  40442. var PDFImage = (function PDFImageClosure() {
  40443. /**
  40444. * Decode the image in the main thread if it supported. Resovles the promise
  40445. * when the image data is ready.
  40446. */
  40447. function handleImageData(handler, xref, res, image) {
  40448. if (image instanceof JpegStream && image.isNativelyDecodable(xref, res)) {
  40449. // For natively supported jpegs send them to the main thread for decoding.
  40450. var dict = image.dict;
  40451. var colorSpace = dict.get('ColorSpace', 'CS');
  40452. colorSpace = ColorSpace.parse(colorSpace, xref, res);
  40453. var numComps = colorSpace.numComps;
  40454. var decodePromise = handler.sendWithPromise('JpegDecode',
  40455. [image.getIR(), numComps]);
  40456. return decodePromise.then(function (message) {
  40457. var data = message.data;
  40458. return new Stream(data, 0, data.length, image.dict);
  40459. });
  40460. } else {
  40461. return Promise.resolve(image);
  40462. }
  40463. }
  40464. /**
  40465. * Decode and clamp a value. The formula is different from the spec because we
  40466. * don't decode to float range [0,1], we decode it in the [0,max] range.
  40467. */
  40468. function decodeAndClamp(value, addend, coefficient, max) {
  40469. value = addend + value * coefficient;
  40470. // Clamp the value to the range
  40471. return (value < 0 ? 0 : (value > max ? max : value));
  40472. }
  40473. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  40474. this.image = image;
  40475. var dict = image.dict;
  40476. if (dict.has('Filter')) {
  40477. var filter = dict.get('Filter').name;
  40478. if (filter === 'JPXDecode') {
  40479. var jpxImage = new JpxImage();
  40480. jpxImage.parseImageProperties(image.stream);
  40481. image.stream.reset();
  40482. image.bitsPerComponent = jpxImage.bitsPerComponent;
  40483. image.numComps = jpxImage.componentsCount;
  40484. } else if (filter === 'JBIG2Decode') {
  40485. image.bitsPerComponent = 1;
  40486. image.numComps = 1;
  40487. }
  40488. }
  40489. // TODO cache rendered images?
  40490. this.width = dict.get('Width', 'W');
  40491. this.height = dict.get('Height', 'H');
  40492. if (this.width < 1 || this.height < 1) {
  40493. error('Invalid image width: ' + this.width + ' or height: ' +
  40494. this.height);
  40495. }
  40496. this.interpolate = dict.get('Interpolate', 'I') || false;
  40497. this.imageMask = dict.get('ImageMask', 'IM') || false;
  40498. this.matte = dict.get('Matte') || false;
  40499. var bitsPerComponent = image.bitsPerComponent;
  40500. if (!bitsPerComponent) {
  40501. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  40502. if (!bitsPerComponent) {
  40503. if (this.imageMask) {
  40504. bitsPerComponent = 1;
  40505. } else {
  40506. error('Bits per component missing in image: ' + this.imageMask);
  40507. }
  40508. }
  40509. }
  40510. this.bpc = bitsPerComponent;
  40511. if (!this.imageMask) {
  40512. var colorSpace = dict.get('ColorSpace', 'CS');
  40513. if (!colorSpace) {
  40514. info('JPX images (which do not require color spaces)');
  40515. switch (image.numComps) {
  40516. case 1:
  40517. colorSpace = Name.get('DeviceGray');
  40518. break;
  40519. case 3:
  40520. colorSpace = Name.get('DeviceRGB');
  40521. break;
  40522. case 4:
  40523. colorSpace = Name.get('DeviceCMYK');
  40524. break;
  40525. default:
  40526. error('JPX images with ' + this.numComps +
  40527. ' color components not supported.');
  40528. }
  40529. }
  40530. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  40531. this.numComps = this.colorSpace.numComps;
  40532. }
  40533. this.decode = dict.get('Decode', 'D');
  40534. this.needsDecode = false;
  40535. if (this.decode &&
  40536. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  40537. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  40538. this.needsDecode = true;
  40539. // Do some preprocessing to avoid more math.
  40540. var max = (1 << bitsPerComponent) - 1;
  40541. this.decodeCoefficients = [];
  40542. this.decodeAddends = [];
  40543. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  40544. var dmin = this.decode[i];
  40545. var dmax = this.decode[i + 1];
  40546. this.decodeCoefficients[j] = dmax - dmin;
  40547. this.decodeAddends[j] = max * dmin;
  40548. }
  40549. }
  40550. if (smask) {
  40551. this.smask = new PDFImage(xref, res, smask, false);
  40552. } else if (mask) {
  40553. if (isStream(mask)) {
  40554. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  40555. if (!imageMask) {
  40556. warn('Ignoring /Mask in image without /ImageMask.');
  40557. } else {
  40558. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  40559. }
  40560. } else {
  40561. // Color key mask (just an array).
  40562. this.mask = mask;
  40563. }
  40564. }
  40565. }
  40566. /**
  40567. * Handles processing of image data and returns the Promise that is resolved
  40568. * with a PDFImage when the image is ready to be used.
  40569. */
  40570. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  40571. res, image, inline) {
  40572. var imagePromise = handleImageData(handler, xref, res, image);
  40573. var smaskPromise;
  40574. var maskPromise;
  40575. var smask = image.dict.get('SMask');
  40576. var mask = image.dict.get('Mask');
  40577. if (smask) {
  40578. smaskPromise = handleImageData(handler, xref, res, smask);
  40579. maskPromise = Promise.resolve(null);
  40580. } else {
  40581. smaskPromise = Promise.resolve(null);
  40582. if (mask) {
  40583. if (isStream(mask)) {
  40584. maskPromise = handleImageData(handler, xref, res, mask);
  40585. } else if (isArray(mask)) {
  40586. maskPromise = Promise.resolve(mask);
  40587. } else {
  40588. warn('Unsupported mask format.');
  40589. maskPromise = Promise.resolve(null);
  40590. }
  40591. } else {
  40592. maskPromise = Promise.resolve(null);
  40593. }
  40594. }
  40595. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  40596. function(results) {
  40597. var imageData = results[0];
  40598. var smaskData = results[1];
  40599. var maskData = results[2];
  40600. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  40601. });
  40602. };
  40603. /**
  40604. * Resize an image using the nearest neighbor algorithm. Currently only
  40605. * supports one and three component images.
  40606. * @param {TypedArray} pixels The original image with one component.
  40607. * @param {Number} bpc Number of bits per component.
  40608. * @param {Number} components Number of color components, 1 or 3 is supported.
  40609. * @param {Number} w1 Original width.
  40610. * @param {Number} h1 Original height.
  40611. * @param {Number} w2 New width.
  40612. * @param {Number} h2 New height.
  40613. * @param {TypedArray} dest (Optional) The destination buffer.
  40614. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  40615. * @return {TypedArray} Resized image data.
  40616. */
  40617. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  40618. w1, h1, w2, h2, dest, alpha01) {
  40619. if (components !== 1 && components !== 3) {
  40620. error('Unsupported component count for resizing.');
  40621. }
  40622. var length = w2 * h2 * components;
  40623. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  40624. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40625. var xRatio = w1 / w2;
  40626. var yRatio = h1 / h2;
  40627. var i, j, py, newIndex = 0, oldIndex;
  40628. var xScaled = new Uint16Array(w2);
  40629. var w1Scanline = w1 * components;
  40630. if (alpha01 !== 1) {
  40631. alpha01 = 0;
  40632. }
  40633. for (j = 0; j < w2; j++) {
  40634. xScaled[j] = Math.floor(j * xRatio) * components;
  40635. }
  40636. if (components === 1) {
  40637. for (i = 0; i < h2; i++) {
  40638. py = Math.floor(i * yRatio) * w1Scanline;
  40639. for (j = 0; j < w2; j++) {
  40640. oldIndex = py + xScaled[j];
  40641. temp[newIndex++] = pixels[oldIndex];
  40642. }
  40643. }
  40644. } else if (components === 3) {
  40645. for (i = 0; i < h2; i++) {
  40646. py = Math.floor(i * yRatio) * w1Scanline;
  40647. for (j = 0; j < w2; j++) {
  40648. oldIndex = py + xScaled[j];
  40649. temp[newIndex++] = pixels[oldIndex++];
  40650. temp[newIndex++] = pixels[oldIndex++];
  40651. temp[newIndex++] = pixels[oldIndex++];
  40652. newIndex += alpha01;
  40653. }
  40654. }
  40655. }
  40656. return temp;
  40657. };
  40658. PDFImage.createMask =
  40659. function PDFImage_createMask(imgArray, width, height,
  40660. imageIsFromDecodeStream, inverseDecode) {
  40661. // |imgArray| might not contain full data for every pixel of the mask, so
  40662. // we need to distinguish between |computedLength| and |actualLength|.
  40663. // In particular, if inverseDecode is true, then the array we return must
  40664. // have a length of |computedLength|.
  40665. var computedLength = ((width + 7) >> 3) * height;
  40666. var actualLength = imgArray.byteLength;
  40667. var haveFullData = computedLength === actualLength;
  40668. var data, i;
  40669. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  40670. // imgArray came from a DecodeStream and its data is in an appropriate
  40671. // form, so we can just transfer it.
  40672. data = imgArray;
  40673. } else if (!inverseDecode) {
  40674. data = new Uint8Array(actualLength);
  40675. data.set(imgArray);
  40676. } else {
  40677. data = new Uint8Array(computedLength);
  40678. data.set(imgArray);
  40679. for (i = actualLength; i < computedLength; i++) {
  40680. data[i] = 0xff;
  40681. }
  40682. }
  40683. // If necessary, invert the original mask data (but not any extra we might
  40684. // have added above). It's safe to modify the array -- whether it's the
  40685. // original or a copy, we're about to transfer it anyway, so nothing else
  40686. // in this thread can be relying on its contents.
  40687. if (inverseDecode) {
  40688. for (i = 0; i < actualLength; i++) {
  40689. data[i] = ~data[i];
  40690. }
  40691. }
  40692. return {data: data, width: width, height: height};
  40693. };
  40694. PDFImage.prototype = {
  40695. get drawWidth() {
  40696. return Math.max(this.width,
  40697. this.smask && this.smask.width || 0,
  40698. this.mask && this.mask.width || 0);
  40699. },
  40700. get drawHeight() {
  40701. return Math.max(this.height,
  40702. this.smask && this.smask.height || 0,
  40703. this.mask && this.mask.height || 0);
  40704. },
  40705. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  40706. var bpc = this.bpc;
  40707. var numComps = this.numComps;
  40708. var decodeAddends = this.decodeAddends;
  40709. var decodeCoefficients = this.decodeCoefficients;
  40710. var max = (1 << bpc) - 1;
  40711. var i, ii;
  40712. if (bpc === 1) {
  40713. // If the buffer needed decode that means it just needs to be inverted.
  40714. for (i = 0, ii = buffer.length; i < ii; i++) {
  40715. buffer[i] = +!(buffer[i]);
  40716. }
  40717. return;
  40718. }
  40719. var index = 0;
  40720. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  40721. for (var j = 0; j < numComps; j++) {
  40722. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  40723. decodeCoefficients[j], max);
  40724. index++;
  40725. }
  40726. }
  40727. },
  40728. getComponents: function PDFImage_getComponents(buffer) {
  40729. var bpc = this.bpc;
  40730. // This image doesn't require any extra work.
  40731. if (bpc === 8) {
  40732. return buffer;
  40733. }
  40734. var width = this.width;
  40735. var height = this.height;
  40736. var numComps = this.numComps;
  40737. var length = width * height * numComps;
  40738. var bufferPos = 0;
  40739. var output = (bpc <= 8 ? new Uint8Array(length) :
  40740. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  40741. var rowComps = width * numComps;
  40742. var max = (1 << bpc) - 1;
  40743. var i = 0, ii, buf;
  40744. if (bpc === 1) {
  40745. // Optimization for reading 1 bpc images.
  40746. var mask, loop1End, loop2End;
  40747. for (var j = 0; j < height; j++) {
  40748. loop1End = i + (rowComps & ~7);
  40749. loop2End = i + rowComps;
  40750. // unroll loop for all full bytes
  40751. while (i < loop1End) {
  40752. buf = buffer[bufferPos++];
  40753. output[i] = (buf >> 7) & 1;
  40754. output[i + 1] = (buf >> 6) & 1;
  40755. output[i + 2] = (buf >> 5) & 1;
  40756. output[i + 3] = (buf >> 4) & 1;
  40757. output[i + 4] = (buf >> 3) & 1;
  40758. output[i + 5] = (buf >> 2) & 1;
  40759. output[i + 6] = (buf >> 1) & 1;
  40760. output[i + 7] = buf & 1;
  40761. i += 8;
  40762. }
  40763. // handle remaing bits
  40764. if (i < loop2End) {
  40765. buf = buffer[bufferPos++];
  40766. mask = 128;
  40767. while (i < loop2End) {
  40768. output[i++] = +!!(buf & mask);
  40769. mask >>= 1;
  40770. }
  40771. }
  40772. }
  40773. } else {
  40774. // The general case that handles all other bpc values.
  40775. var bits = 0;
  40776. buf = 0;
  40777. for (i = 0, ii = length; i < ii; ++i) {
  40778. if (i % rowComps === 0) {
  40779. buf = 0;
  40780. bits = 0;
  40781. }
  40782. while (bits < bpc) {
  40783. buf = (buf << 8) | buffer[bufferPos++];
  40784. bits += 8;
  40785. }
  40786. var remainingBits = bits - bpc;
  40787. var value = buf >> remainingBits;
  40788. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  40789. buf = buf & ((1 << remainingBits) - 1);
  40790. bits = remainingBits;
  40791. }
  40792. }
  40793. return output;
  40794. },
  40795. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  40796. actualHeight, image) {
  40797. var smask = this.smask;
  40798. var mask = this.mask;
  40799. var alphaBuf, sw, sh, i, ii, j;
  40800. if (smask) {
  40801. sw = smask.width;
  40802. sh = smask.height;
  40803. alphaBuf = new Uint8Array(sw * sh);
  40804. smask.fillGrayBuffer(alphaBuf);
  40805. if (sw !== width || sh !== height) {
  40806. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  40807. height);
  40808. }
  40809. } else if (mask) {
  40810. if (mask instanceof PDFImage) {
  40811. sw = mask.width;
  40812. sh = mask.height;
  40813. alphaBuf = new Uint8Array(sw * sh);
  40814. mask.numComps = 1;
  40815. mask.fillGrayBuffer(alphaBuf);
  40816. // Need to invert values in rgbaBuf
  40817. for (i = 0, ii = sw * sh; i < ii; ++i) {
  40818. alphaBuf[i] = 255 - alphaBuf[i];
  40819. }
  40820. if (sw !== width || sh !== height) {
  40821. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  40822. height);
  40823. }
  40824. } else if (isArray(mask)) {
  40825. // Color key mask: if any of the compontents are outside the range
  40826. // then they should be painted.
  40827. alphaBuf = new Uint8Array(width * height);
  40828. var numComps = this.numComps;
  40829. for (i = 0, ii = width * height; i < ii; ++i) {
  40830. var opacity = 0;
  40831. var imageOffset = i * numComps;
  40832. for (j = 0; j < numComps; ++j) {
  40833. var color = image[imageOffset + j];
  40834. var maskOffset = j * 2;
  40835. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  40836. opacity = 255;
  40837. break;
  40838. }
  40839. }
  40840. alphaBuf[i] = opacity;
  40841. }
  40842. } else {
  40843. error('Unknown mask format.');
  40844. }
  40845. }
  40846. if (alphaBuf) {
  40847. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40848. rgbaBuf[j] = alphaBuf[i];
  40849. }
  40850. } else {
  40851. // No mask.
  40852. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  40853. rgbaBuf[j] = 255;
  40854. }
  40855. }
  40856. },
  40857. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  40858. var matte = this.smask && this.smask.matte;
  40859. if (!matte) {
  40860. return;
  40861. }
  40862. var matteRgb = this.colorSpace.getRgb(matte, 0);
  40863. var matteR = matteRgb[0];
  40864. var matteG = matteRgb[1];
  40865. var matteB = matteRgb[2];
  40866. var length = width * height * 4;
  40867. var r, g, b;
  40868. for (var i = 0; i < length; i += 4) {
  40869. var alpha = buffer[i + 3];
  40870. if (alpha === 0) {
  40871. // according formula we have to get Infinity in all components
  40872. // making it white (typical paper color) should be okay
  40873. buffer[i] = 255;
  40874. buffer[i + 1] = 255;
  40875. buffer[i + 2] = 255;
  40876. continue;
  40877. }
  40878. var k = 255 / alpha;
  40879. r = (buffer[i] - matteR) * k + matteR;
  40880. g = (buffer[i + 1] - matteG) * k + matteG;
  40881. b = (buffer[i + 2] - matteB) * k + matteB;
  40882. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  40883. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  40884. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  40885. }
  40886. },
  40887. createImageData: function PDFImage_createImageData(forceRGBA) {
  40888. var drawWidth = this.drawWidth;
  40889. var drawHeight = this.drawHeight;
  40890. var imgData = { // other fields are filled in below
  40891. width: drawWidth,
  40892. height: drawHeight
  40893. };
  40894. var numComps = this.numComps;
  40895. var originalWidth = this.width;
  40896. var originalHeight = this.height;
  40897. var bpc = this.bpc;
  40898. // Rows start at byte boundary.
  40899. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  40900. var imgArray;
  40901. if (!forceRGBA) {
  40902. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  40903. // without any complications, we pass a same-sized copy to the main
  40904. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  40905. // of memory for many scanned documents. It's also much faster.
  40906. //
  40907. // Similarly, if it is a 24-bit-per pixel RGB image without any
  40908. // complications, we avoid expanding by 1.333x to RGBA form.
  40909. var kind;
  40910. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  40911. kind = ImageKind.GRAYSCALE_1BPP;
  40912. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  40913. !this.needsDecode) {
  40914. kind = ImageKind.RGB_24BPP;
  40915. }
  40916. if (kind && !this.smask && !this.mask &&
  40917. drawWidth === originalWidth && drawHeight === originalHeight) {
  40918. imgData.kind = kind;
  40919. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40920. // If imgArray came from a DecodeStream, we're safe to transfer it
  40921. // (and thus detach its underlying buffer) because it will constitute
  40922. // the entire DecodeStream's data. But if it came from a Stream, we
  40923. // need to copy it because it'll only be a portion of the Stream's
  40924. // data, and the rest will be read later on.
  40925. if (this.image instanceof DecodeStream) {
  40926. imgData.data = imgArray;
  40927. } else {
  40928. var newArray = new Uint8Array(imgArray.length);
  40929. newArray.set(imgArray);
  40930. imgData.data = newArray;
  40931. }
  40932. if (this.needsDecode) {
  40933. // Invert the buffer (which must be grayscale if we reached here).
  40934. assert(kind === ImageKind.GRAYSCALE_1BPP);
  40935. var buffer = imgData.data;
  40936. for (var i = 0, ii = buffer.length; i < ii; i++) {
  40937. buffer[i] ^= 0xff;
  40938. }
  40939. }
  40940. return imgData;
  40941. }
  40942. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  40943. (this.colorSpace.name === 'DeviceGray' ||
  40944. this.colorSpace.name === 'DeviceRGB' ||
  40945. this.colorSpace.name === 'DeviceCMYK')) {
  40946. imgData.kind = ImageKind.RGB_24BPP;
  40947. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  40948. drawWidth, drawHeight, true);
  40949. return imgData;
  40950. }
  40951. }
  40952. imgArray = this.getImageBytes(originalHeight * rowBytes);
  40953. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  40954. var actualHeight = 0 | (imgArray.length / rowBytes *
  40955. drawHeight / originalHeight);
  40956. var comps = this.getComponents(imgArray);
  40957. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  40958. // more compact RGB_24BPP form if allowable.
  40959. var alpha01, maybeUndoPreblend;
  40960. if (!forceRGBA && !this.smask && !this.mask) {
  40961. imgData.kind = ImageKind.RGB_24BPP;
  40962. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  40963. alpha01 = 0;
  40964. maybeUndoPreblend = false;
  40965. } else {
  40966. imgData.kind = ImageKind.RGBA_32BPP;
  40967. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  40968. alpha01 = 1;
  40969. maybeUndoPreblend = true;
  40970. // Color key masking (opacity) must be performed before decoding.
  40971. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  40972. comps);
  40973. }
  40974. if (this.needsDecode) {
  40975. this.decodeBuffer(comps);
  40976. }
  40977. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  40978. drawWidth, drawHeight, actualHeight, bpc, comps,
  40979. alpha01);
  40980. if (maybeUndoPreblend) {
  40981. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  40982. }
  40983. return imgData;
  40984. },
  40985. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  40986. var numComps = this.numComps;
  40987. if (numComps !== 1) {
  40988. error('Reading gray scale from a color image: ' + numComps);
  40989. }
  40990. var width = this.width;
  40991. var height = this.height;
  40992. var bpc = this.bpc;
  40993. // rows start at byte boundary
  40994. var rowBytes = (width * numComps * bpc + 7) >> 3;
  40995. var imgArray = this.getImageBytes(height * rowBytes);
  40996. var comps = this.getComponents(imgArray);
  40997. var i, length;
  40998. if (bpc === 1) {
  40999. // inline decoding (= inversion) for 1 bpc images
  41000. length = width * height;
  41001. if (this.needsDecode) {
  41002. // invert and scale to {0, 255}
  41003. for (i = 0; i < length; ++i) {
  41004. buffer[i] = (comps[i] - 1) & 255;
  41005. }
  41006. } else {
  41007. // scale to {0, 255}
  41008. for (i = 0; i < length; ++i) {
  41009. buffer[i] = (-comps[i]) & 255;
  41010. }
  41011. }
  41012. return;
  41013. }
  41014. if (this.needsDecode) {
  41015. this.decodeBuffer(comps);
  41016. }
  41017. length = width * height;
  41018. // we aren't using a colorspace so we need to scale the value
  41019. var scale = 255 / ((1 << bpc) - 1);
  41020. for (i = 0; i < length; ++i) {
  41021. buffer[i] = (scale * comps[i]) | 0;
  41022. }
  41023. },
  41024. getImageBytes: function PDFImage_getImageBytes(length,
  41025. drawWidth, drawHeight,
  41026. forceRGB) {
  41027. this.image.reset();
  41028. this.image.drawWidth = drawWidth || this.width;
  41029. this.image.drawHeight = drawHeight || this.height;
  41030. this.image.forceRGB = !!forceRGB;
  41031. return this.image.getBytes(length);
  41032. }
  41033. };
  41034. return PDFImage;
  41035. })();
  41036. exports.PDFImage = PDFImage;
  41037. // TODO refactor to remove dependency on colorspace.js
  41038. coreColorSpace._setCoreImage(exports);
  41039. }));
  41040. (function (root, factory) {
  41041. {
  41042. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41043. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41044. root.pdfjsCoreColorSpace);
  41045. }
  41046. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41047. coreColorSpace) {
  41048. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41049. var MissingDataException = sharedUtil.MissingDataException;
  41050. var Util = sharedUtil.Util;
  41051. var assert = sharedUtil.assert;
  41052. var error = sharedUtil.error;
  41053. var info = sharedUtil.info;
  41054. var warn = sharedUtil.warn;
  41055. var isStream = corePrimitives.isStream;
  41056. var PDFFunction = coreFunction.PDFFunction;
  41057. var ColorSpace = coreColorSpace.ColorSpace;
  41058. var ShadingType = {
  41059. FUNCTION_BASED: 1,
  41060. AXIAL: 2,
  41061. RADIAL: 3,
  41062. FREE_FORM_MESH: 4,
  41063. LATTICE_FORM_MESH: 5,
  41064. COONS_PATCH_MESH: 6,
  41065. TENSOR_PATCH_MESH: 7
  41066. };
  41067. var Pattern = (function PatternClosure() {
  41068. // Constructor should define this.getPattern
  41069. function Pattern() {
  41070. error('should not call Pattern constructor');
  41071. }
  41072. Pattern.prototype = {
  41073. // Input: current Canvas context
  41074. // Output: the appropriate fillStyle or strokeStyle
  41075. getPattern: function Pattern_getPattern(ctx) {
  41076. error('Should not call Pattern.getStyle: ' + ctx);
  41077. }
  41078. };
  41079. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41080. res, handler) {
  41081. var dict = isStream(shading) ? shading.dict : shading;
  41082. var type = dict.get('ShadingType');
  41083. try {
  41084. switch (type) {
  41085. case ShadingType.AXIAL:
  41086. case ShadingType.RADIAL:
  41087. // Both radial and axial shadings are handled by RadialAxial shading.
  41088. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41089. case ShadingType.FREE_FORM_MESH:
  41090. case ShadingType.LATTICE_FORM_MESH:
  41091. case ShadingType.COONS_PATCH_MESH:
  41092. case ShadingType.TENSOR_PATCH_MESH:
  41093. return new Shadings.Mesh(shading, matrix, xref, res);
  41094. default:
  41095. throw new Error('Unsupported ShadingType: ' + type);
  41096. }
  41097. } catch (ex) {
  41098. if (ex instanceof MissingDataException) {
  41099. throw ex;
  41100. }
  41101. handler.send('UnsupportedFeature',
  41102. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41103. warn(ex);
  41104. return new Shadings.Dummy();
  41105. }
  41106. };
  41107. return Pattern;
  41108. })();
  41109. var Shadings = {};
  41110. // A small number to offset the first/last color stops so we can insert ones to
  41111. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41112. Shadings.SMALL_NUMBER = 1e-6;
  41113. // Radial and axial shading have very similar implementations
  41114. // If needed, the implementations can be broken into two classes
  41115. Shadings.RadialAxial = (function RadialAxialClosure() {
  41116. function RadialAxial(dict, matrix, xref, res) {
  41117. this.matrix = matrix;
  41118. this.coordsArr = dict.get('Coords');
  41119. this.shadingType = dict.get('ShadingType');
  41120. this.type = 'Pattern';
  41121. var cs = dict.get('ColorSpace', 'CS');
  41122. cs = ColorSpace.parse(cs, xref, res);
  41123. this.cs = cs;
  41124. var t0 = 0.0, t1 = 1.0;
  41125. if (dict.has('Domain')) {
  41126. var domainArr = dict.get('Domain');
  41127. t0 = domainArr[0];
  41128. t1 = domainArr[1];
  41129. }
  41130. var extendStart = false, extendEnd = false;
  41131. if (dict.has('Extend')) {
  41132. var extendArr = dict.get('Extend');
  41133. extendStart = extendArr[0];
  41134. extendEnd = extendArr[1];
  41135. }
  41136. if (this.shadingType === ShadingType.RADIAL &&
  41137. (!extendStart || !extendEnd)) {
  41138. // Radial gradient only currently works if either circle is fully within
  41139. // the other circle.
  41140. var x1 = this.coordsArr[0];
  41141. var y1 = this.coordsArr[1];
  41142. var r1 = this.coordsArr[2];
  41143. var x2 = this.coordsArr[3];
  41144. var y2 = this.coordsArr[4];
  41145. var r2 = this.coordsArr[5];
  41146. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  41147. if (r1 <= r2 + distance &&
  41148. r2 <= r1 + distance) {
  41149. warn('Unsupported radial gradient.');
  41150. }
  41151. }
  41152. this.extendStart = extendStart;
  41153. this.extendEnd = extendEnd;
  41154. var fnObj = dict.get('Function');
  41155. var fn = PDFFunction.parseArray(xref, fnObj);
  41156. // 10 samples seems good enough for now, but probably won't work
  41157. // if there are sharp color changes. Ideally, we would implement
  41158. // the spec faithfully and add lossless optimizations.
  41159. var diff = t1 - t0;
  41160. var step = diff / 10;
  41161. var colorStops = this.colorStops = [];
  41162. // Protect against bad domains so we don't end up in an infinte loop below.
  41163. if (t0 >= t1 || step <= 0) {
  41164. // Acrobat doesn't seem to handle these cases so we'll ignore for
  41165. // now.
  41166. info('Bad shading domain.');
  41167. return;
  41168. }
  41169. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  41170. var rgbColor;
  41171. for (var i = t0; i <= t1; i += step) {
  41172. ratio[0] = i;
  41173. fn(ratio, 0, color, 0);
  41174. rgbColor = cs.getRgb(color, 0);
  41175. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41176. colorStops.push([(i - t0) / diff, cssColor]);
  41177. }
  41178. var background = 'transparent';
  41179. if (dict.has('Background')) {
  41180. rgbColor = cs.getRgb(dict.get('Background'), 0);
  41181. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41182. }
  41183. if (!extendStart) {
  41184. // Insert a color stop at the front and offset the first real color stop
  41185. // so it doesn't conflict with the one we insert.
  41186. colorStops.unshift([0, background]);
  41187. colorStops[1][0] += Shadings.SMALL_NUMBER;
  41188. }
  41189. if (!extendEnd) {
  41190. // Same idea as above in extendStart but for the end.
  41191. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  41192. colorStops.push([1, background]);
  41193. }
  41194. this.colorStops = colorStops;
  41195. }
  41196. RadialAxial.prototype = {
  41197. getIR: function RadialAxial_getIR() {
  41198. var coordsArr = this.coordsArr;
  41199. var shadingType = this.shadingType;
  41200. var type, p0, p1, r0, r1;
  41201. if (shadingType === ShadingType.AXIAL) {
  41202. p0 = [coordsArr[0], coordsArr[1]];
  41203. p1 = [coordsArr[2], coordsArr[3]];
  41204. r0 = null;
  41205. r1 = null;
  41206. type = 'axial';
  41207. } else if (shadingType === ShadingType.RADIAL) {
  41208. p0 = [coordsArr[0], coordsArr[1]];
  41209. p1 = [coordsArr[3], coordsArr[4]];
  41210. r0 = coordsArr[2];
  41211. r1 = coordsArr[5];
  41212. type = 'radial';
  41213. } else {
  41214. error('getPattern type unknown: ' + shadingType);
  41215. }
  41216. var matrix = this.matrix;
  41217. if (matrix) {
  41218. p0 = Util.applyTransform(p0, matrix);
  41219. p1 = Util.applyTransform(p1, matrix);
  41220. if (shadingType === ShadingType.RADIAL) {
  41221. var scale = Util.singularValueDecompose2dScale(matrix);
  41222. r0 *= scale[0];
  41223. r1 *= scale[1];
  41224. }
  41225. }
  41226. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  41227. }
  41228. };
  41229. return RadialAxial;
  41230. })();
  41231. // All mesh shading. For now, they will be presented as set of the triangles
  41232. // to be drawn on the canvas and rgb color for each vertex.
  41233. Shadings.Mesh = (function MeshClosure() {
  41234. function MeshStreamReader(stream, context) {
  41235. this.stream = stream;
  41236. this.context = context;
  41237. this.buffer = 0;
  41238. this.bufferLength = 0;
  41239. var numComps = context.numComps;
  41240. this.tmpCompsBuf = new Float32Array(numComps);
  41241. var csNumComps = context.colorSpace.numComps;
  41242. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  41243. this.tmpCompsBuf;
  41244. }
  41245. MeshStreamReader.prototype = {
  41246. get hasData() {
  41247. if (this.stream.end) {
  41248. return this.stream.pos < this.stream.end;
  41249. }
  41250. if (this.bufferLength > 0) {
  41251. return true;
  41252. }
  41253. var nextByte = this.stream.getByte();
  41254. if (nextByte < 0) {
  41255. return false;
  41256. }
  41257. this.buffer = nextByte;
  41258. this.bufferLength = 8;
  41259. return true;
  41260. },
  41261. readBits: function MeshStreamReader_readBits(n) {
  41262. var buffer = this.buffer;
  41263. var bufferLength = this.bufferLength;
  41264. if (n === 32) {
  41265. if (bufferLength === 0) {
  41266. return ((this.stream.getByte() << 24) |
  41267. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  41268. this.stream.getByte()) >>> 0;
  41269. }
  41270. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  41271. (this.stream.getByte() << 8) | this.stream.getByte();
  41272. var nextByte = this.stream.getByte();
  41273. this.buffer = nextByte & ((1 << bufferLength) - 1);
  41274. return ((buffer << (8 - bufferLength)) |
  41275. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  41276. }
  41277. if (n === 8 && bufferLength === 0) {
  41278. return this.stream.getByte();
  41279. }
  41280. while (bufferLength < n) {
  41281. buffer = (buffer << 8) | this.stream.getByte();
  41282. bufferLength += 8;
  41283. }
  41284. bufferLength -= n;
  41285. this.bufferLength = bufferLength;
  41286. this.buffer = buffer & ((1 << bufferLength) - 1);
  41287. return buffer >> bufferLength;
  41288. },
  41289. align: function MeshStreamReader_align() {
  41290. this.buffer = 0;
  41291. this.bufferLength = 0;
  41292. },
  41293. readFlag: function MeshStreamReader_readFlag() {
  41294. return this.readBits(this.context.bitsPerFlag);
  41295. },
  41296. readCoordinate: function MeshStreamReader_readCoordinate() {
  41297. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  41298. var xi = this.readBits(bitsPerCoordinate);
  41299. var yi = this.readBits(bitsPerCoordinate);
  41300. var decode = this.context.decode;
  41301. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  41302. 2.3283064365386963e-10; // 2 ^ -32
  41303. return [
  41304. xi * scale * (decode[1] - decode[0]) + decode[0],
  41305. yi * scale * (decode[3] - decode[2]) + decode[2]
  41306. ];
  41307. },
  41308. readComponents: function MeshStreamReader_readComponents() {
  41309. var numComps = this.context.numComps;
  41310. var bitsPerComponent = this.context.bitsPerComponent;
  41311. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  41312. 2.3283064365386963e-10; // 2 ^ -32
  41313. var decode = this.context.decode;
  41314. var components = this.tmpCompsBuf;
  41315. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  41316. var ci = this.readBits(bitsPerComponent);
  41317. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  41318. }
  41319. var color = this.tmpCsCompsBuf;
  41320. if (this.context.colorFn) {
  41321. this.context.colorFn(components, 0, color, 0);
  41322. }
  41323. return this.context.colorSpace.getRgb(color, 0);
  41324. }
  41325. };
  41326. function decodeType4Shading(mesh, reader) {
  41327. var coords = mesh.coords;
  41328. var colors = mesh.colors;
  41329. var operators = [];
  41330. var ps = []; // not maintaining cs since that will match ps
  41331. var verticesLeft = 0; // assuming we have all data to start a new triangle
  41332. while (reader.hasData) {
  41333. var f = reader.readFlag();
  41334. var coord = reader.readCoordinate();
  41335. var color = reader.readComponents();
  41336. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  41337. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  41338. switch (f) {
  41339. case 0:
  41340. verticesLeft = 3;
  41341. break;
  41342. case 1:
  41343. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  41344. verticesLeft = 1;
  41345. break;
  41346. case 2:
  41347. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  41348. verticesLeft = 1;
  41349. break;
  41350. }
  41351. operators.push(f);
  41352. }
  41353. ps.push(coords.length);
  41354. coords.push(coord);
  41355. colors.push(color);
  41356. verticesLeft--;
  41357. reader.align();
  41358. }
  41359. mesh.figures.push({
  41360. type: 'triangles',
  41361. coords: new Int32Array(ps),
  41362. colors: new Int32Array(ps),
  41363. });
  41364. }
  41365. function decodeType5Shading(mesh, reader, verticesPerRow) {
  41366. var coords = mesh.coords;
  41367. var colors = mesh.colors;
  41368. var ps = []; // not maintaining cs since that will match ps
  41369. while (reader.hasData) {
  41370. var coord = reader.readCoordinate();
  41371. var color = reader.readComponents();
  41372. ps.push(coords.length);
  41373. coords.push(coord);
  41374. colors.push(color);
  41375. }
  41376. mesh.figures.push({
  41377. type: 'lattice',
  41378. coords: new Int32Array(ps),
  41379. colors: new Int32Array(ps),
  41380. verticesPerRow: verticesPerRow
  41381. });
  41382. }
  41383. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  41384. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  41385. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  41386. var getB = (function getBClosure() {
  41387. function buildB(count) {
  41388. var lut = [];
  41389. for (var i = 0; i <= count; i++) {
  41390. var t = i / count, t_ = 1 - t;
  41391. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  41392. 3 * t * t * t_, t * t * t]));
  41393. }
  41394. return lut;
  41395. }
  41396. var cache = [];
  41397. return function getB(count) {
  41398. if (!cache[count]) {
  41399. cache[count] = buildB(count);
  41400. }
  41401. return cache[count];
  41402. };
  41403. })();
  41404. function buildFigureFromPatch(mesh, index) {
  41405. var figure = mesh.figures[index];
  41406. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  41407. var coords = mesh.coords, colors = mesh.colors;
  41408. var pi = figure.coords;
  41409. var ci = figure.colors;
  41410. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  41411. coords[pi[12]][0], coords[pi[15]][0]);
  41412. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  41413. coords[pi[12]][1], coords[pi[15]][1]);
  41414. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  41415. coords[pi[12]][0], coords[pi[15]][0]);
  41416. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  41417. coords[pi[12]][1], coords[pi[15]][1]);
  41418. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  41419. (mesh.bounds[2] - mesh.bounds[0]));
  41420. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41421. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  41422. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  41423. (mesh.bounds[3] - mesh.bounds[1]));
  41424. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41425. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  41426. var verticesPerRow = splitXBy + 1;
  41427. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  41428. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  41429. var k = 0;
  41430. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  41431. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  41432. c2 = colors[ci[2]], c3 = colors[ci[3]];
  41433. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  41434. for (var row = 0; row <= splitYBy; row++) {
  41435. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  41436. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  41437. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  41438. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  41439. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  41440. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  41441. for (var col = 0; col <= splitXBy; col++, k++) {
  41442. if ((row === 0 || row === splitYBy) &&
  41443. (col === 0 || col === splitXBy)) {
  41444. continue;
  41445. }
  41446. var x = 0, y = 0;
  41447. var q = 0;
  41448. for (var i = 0; i <= 3; i++) {
  41449. for (var j = 0; j <= 3; j++, q++) {
  41450. var m = bRow[row][i] * bCol[col][j];
  41451. x += coords[pi[q]][0] * m;
  41452. y += coords[pi[q]][1] * m;
  41453. }
  41454. }
  41455. figureCoords[k] = coords.length;
  41456. coords.push([x, y]);
  41457. figureColors[k] = colors.length;
  41458. var newColor = new Uint8Array(3);
  41459. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  41460. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  41461. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  41462. colors.push(newColor);
  41463. }
  41464. }
  41465. figureCoords[0] = pi[0];
  41466. figureColors[0] = ci[0];
  41467. figureCoords[splitXBy] = pi[3];
  41468. figureColors[splitXBy] = ci[1];
  41469. figureCoords[verticesPerRow * splitYBy] = pi[12];
  41470. figureColors[verticesPerRow * splitYBy] = ci[2];
  41471. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  41472. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  41473. mesh.figures[index] = {
  41474. type: 'lattice',
  41475. coords: figureCoords,
  41476. colors: figureColors,
  41477. verticesPerRow: verticesPerRow
  41478. };
  41479. }
  41480. function decodeType6Shading(mesh, reader) {
  41481. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  41482. var coords = mesh.coords;
  41483. var colors = mesh.colors;
  41484. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41485. var cs = new Int32Array(4); // c00, c30, c03, c33
  41486. while (reader.hasData) {
  41487. var f = reader.readFlag();
  41488. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  41489. var i, ii;
  41490. var pi = coords.length;
  41491. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  41492. coords.push(reader.readCoordinate());
  41493. }
  41494. var ci = colors.length;
  41495. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41496. colors.push(reader.readComponents());
  41497. }
  41498. var tmp1, tmp2, tmp3, tmp4;
  41499. switch (f) {
  41500. case 0:
  41501. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41502. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  41503. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  41504. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41505. cs[2] = ci + 1; cs[3] = ci + 2;
  41506. cs[0] = ci; cs[1] = ci + 3;
  41507. break;
  41508. case 1:
  41509. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41510. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41511. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41512. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41513. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41514. tmp1 = cs[2]; tmp2 = cs[3];
  41515. cs[2] = tmp2; cs[3] = ci;
  41516. cs[0] = tmp1; cs[1] = ci + 1;
  41517. break;
  41518. case 2:
  41519. tmp1 = ps[15];
  41520. tmp2 = ps[11];
  41521. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41522. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41523. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41524. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41525. tmp1 = cs[3];
  41526. cs[2] = cs[1]; cs[3] = ci;
  41527. cs[0] = tmp1; cs[1] = ci + 1;
  41528. break;
  41529. case 3:
  41530. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41531. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41532. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  41533. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41534. cs[2] = cs[0]; cs[3] = ci;
  41535. cs[0] = cs[1]; cs[1] = ci + 1;
  41536. break;
  41537. }
  41538. // set p11, p12, p21, p22
  41539. ps[5] = coords.length;
  41540. coords.push([
  41541. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  41542. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  41543. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41544. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  41545. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  41546. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  41547. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41548. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  41549. ]);
  41550. ps[6] = coords.length;
  41551. coords.push([
  41552. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  41553. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  41554. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41555. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  41556. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  41557. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  41558. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41559. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  41560. ]);
  41561. ps[9] = coords.length;
  41562. coords.push([
  41563. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  41564. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  41565. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41566. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  41567. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  41568. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  41569. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41570. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  41571. ]);
  41572. ps[10] = coords.length;
  41573. coords.push([
  41574. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  41575. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  41576. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41577. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  41578. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  41579. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  41580. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41581. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  41582. ]);
  41583. mesh.figures.push({
  41584. type: 'patch',
  41585. coords: new Int32Array(ps), // making copies of ps and cs
  41586. colors: new Int32Array(cs)
  41587. });
  41588. }
  41589. }
  41590. function decodeType7Shading(mesh, reader) {
  41591. var coords = mesh.coords;
  41592. var colors = mesh.colors;
  41593. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41594. var cs = new Int32Array(4); // c00, c30, c03, c33
  41595. while (reader.hasData) {
  41596. var f = reader.readFlag();
  41597. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  41598. var i, ii;
  41599. var pi = coords.length;
  41600. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  41601. coords.push(reader.readCoordinate());
  41602. }
  41603. var ci = colors.length;
  41604. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41605. colors.push(reader.readComponents());
  41606. }
  41607. var tmp1, tmp2, tmp3, tmp4;
  41608. switch (f) {
  41609. case 0:
  41610. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41611. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  41612. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  41613. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41614. cs[2] = ci + 1; cs[3] = ci + 2;
  41615. cs[0] = ci; cs[1] = ci + 3;
  41616. break;
  41617. case 1:
  41618. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41619. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41620. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41621. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41622. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41623. tmp1 = cs[2]; tmp2 = cs[3];
  41624. cs[2] = tmp2; cs[3] = ci;
  41625. cs[0] = tmp1; cs[1] = ci + 1;
  41626. break;
  41627. case 2:
  41628. tmp1 = ps[15];
  41629. tmp2 = ps[11];
  41630. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41631. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41632. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41633. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41634. tmp1 = cs[3];
  41635. cs[2] = cs[1]; cs[3] = ci;
  41636. cs[0] = tmp1; cs[1] = ci + 1;
  41637. break;
  41638. case 3:
  41639. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41640. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41641. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41642. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41643. cs[2] = cs[0]; cs[3] = ci;
  41644. cs[0] = cs[1]; cs[1] = ci + 1;
  41645. break;
  41646. }
  41647. mesh.figures.push({
  41648. type: 'patch',
  41649. coords: new Int32Array(ps), // making copies of ps and cs
  41650. colors: new Int32Array(cs)
  41651. });
  41652. }
  41653. }
  41654. function updateBounds(mesh) {
  41655. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  41656. maxX = minX, maxY = minY;
  41657. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  41658. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  41659. minX = minX > x ? x : minX;
  41660. minY = minY > y ? y : minY;
  41661. maxX = maxX < x ? x : maxX;
  41662. maxY = maxY < y ? y : maxY;
  41663. }
  41664. mesh.bounds = [minX, minY, maxX, maxY];
  41665. }
  41666. function packData(mesh) {
  41667. var i, ii, j, jj;
  41668. var coords = mesh.coords;
  41669. var coordsPacked = new Float32Array(coords.length * 2);
  41670. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  41671. var xy = coords[i];
  41672. coordsPacked[j++] = xy[0];
  41673. coordsPacked[j++] = xy[1];
  41674. }
  41675. mesh.coords = coordsPacked;
  41676. var colors = mesh.colors;
  41677. var colorsPacked = new Uint8Array(colors.length * 3);
  41678. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  41679. var c = colors[i];
  41680. colorsPacked[j++] = c[0];
  41681. colorsPacked[j++] = c[1];
  41682. colorsPacked[j++] = c[2];
  41683. }
  41684. mesh.colors = colorsPacked;
  41685. var figures = mesh.figures;
  41686. for (i = 0, ii = figures.length; i < ii; i++) {
  41687. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  41688. for (j = 0, jj = ps.length; j < jj; j++) {
  41689. ps[j] *= 2;
  41690. cs[j] *= 3;
  41691. }
  41692. }
  41693. }
  41694. function Mesh(stream, matrix, xref, res) {
  41695. assert(isStream(stream), 'Mesh data is not a stream');
  41696. var dict = stream.dict;
  41697. this.matrix = matrix;
  41698. this.shadingType = dict.get('ShadingType');
  41699. this.type = 'Pattern';
  41700. this.bbox = dict.get('BBox');
  41701. var cs = dict.get('ColorSpace', 'CS');
  41702. cs = ColorSpace.parse(cs, xref, res);
  41703. this.cs = cs;
  41704. this.background = dict.has('Background') ?
  41705. cs.getRgb(dict.get('Background'), 0) : null;
  41706. var fnObj = dict.get('Function');
  41707. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  41708. this.coords = [];
  41709. this.colors = [];
  41710. this.figures = [];
  41711. var decodeContext = {
  41712. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  41713. bitsPerComponent: dict.get('BitsPerComponent'),
  41714. bitsPerFlag: dict.get('BitsPerFlag'),
  41715. decode: dict.get('Decode'),
  41716. colorFn: fn,
  41717. colorSpace: cs,
  41718. numComps: fn ? 1 : cs.numComps
  41719. };
  41720. var reader = new MeshStreamReader(stream, decodeContext);
  41721. var patchMesh = false;
  41722. switch (this.shadingType) {
  41723. case ShadingType.FREE_FORM_MESH:
  41724. decodeType4Shading(this, reader);
  41725. break;
  41726. case ShadingType.LATTICE_FORM_MESH:
  41727. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  41728. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  41729. decodeType5Shading(this, reader, verticesPerRow);
  41730. break;
  41731. case ShadingType.COONS_PATCH_MESH:
  41732. decodeType6Shading(this, reader);
  41733. patchMesh = true;
  41734. break;
  41735. case ShadingType.TENSOR_PATCH_MESH:
  41736. decodeType7Shading(this, reader);
  41737. patchMesh = true;
  41738. break;
  41739. default:
  41740. error('Unsupported mesh type.');
  41741. break;
  41742. }
  41743. if (patchMesh) {
  41744. // dirty bounds calculation for determining, how dense shall be triangles
  41745. updateBounds(this);
  41746. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  41747. buildFigureFromPatch(this, i);
  41748. }
  41749. }
  41750. // calculate bounds
  41751. updateBounds(this);
  41752. packData(this);
  41753. }
  41754. Mesh.prototype = {
  41755. getIR: function Mesh_getIR() {
  41756. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  41757. this.bounds, this.matrix, this.bbox, this.background];
  41758. }
  41759. };
  41760. return Mesh;
  41761. })();
  41762. Shadings.Dummy = (function DummyClosure() {
  41763. function Dummy() {
  41764. this.type = 'Pattern';
  41765. }
  41766. Dummy.prototype = {
  41767. getIR: function Dummy_getIR() {
  41768. return ['Dummy'];
  41769. }
  41770. };
  41771. return Dummy;
  41772. })();
  41773. function getTilingPatternIR(operatorList, dict, args) {
  41774. var matrix = dict.get('Matrix');
  41775. var bbox = dict.get('BBox');
  41776. var xstep = dict.get('XStep');
  41777. var ystep = dict.get('YStep');
  41778. var paintType = dict.get('PaintType');
  41779. var tilingType = dict.get('TilingType');
  41780. return [
  41781. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  41782. paintType, tilingType
  41783. ];
  41784. }
  41785. exports.Pattern = Pattern;
  41786. exports.getTilingPatternIR = getTilingPatternIR;
  41787. }));
  41788. (function (root, factory) {
  41789. {
  41790. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  41791. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  41792. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  41793. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  41794. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  41795. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  41796. root.pdfjsCoreUnicode);
  41797. }
  41798. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  41799. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  41800. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  41801. coreEncodings, coreStandardFonts, coreUnicode) {
  41802. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  41803. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  41804. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41805. var ImageKind = sharedUtil.ImageKind;
  41806. var OPS = sharedUtil.OPS;
  41807. var TextRenderingMode = sharedUtil.TextRenderingMode;
  41808. var Util = sharedUtil.Util;
  41809. var assert = sharedUtil.assert;
  41810. var createPromiseCapability = sharedUtil.createPromiseCapability;
  41811. var error = sharedUtil.error;
  41812. var info = sharedUtil.info;
  41813. var isArray = sharedUtil.isArray;
  41814. var isNum = sharedUtil.isNum;
  41815. var isString = sharedUtil.isString;
  41816. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  41817. var warn = sharedUtil.warn;
  41818. var Dict = corePrimitives.Dict;
  41819. var Name = corePrimitives.Name;
  41820. var isCmd = corePrimitives.isCmd;
  41821. var isDict = corePrimitives.isDict;
  41822. var isName = corePrimitives.isName;
  41823. var isRef = corePrimitives.isRef;
  41824. var isStream = corePrimitives.isStream;
  41825. var DecodeStream = coreStream.DecodeStream;
  41826. var JpegStream = coreStream.JpegStream;
  41827. var Lexer = coreParser.Lexer;
  41828. var Parser = coreParser.Parser;
  41829. var isEOF = coreParser.isEOF;
  41830. var PDFImage = coreImage.PDFImage;
  41831. var ColorSpace = coreColorSpace.ColorSpace;
  41832. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  41833. var ErrorFont = coreFonts.ErrorFont;
  41834. var FontFlags = coreFonts.FontFlags;
  41835. var Font = coreFonts.Font;
  41836. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  41837. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  41838. var getFontType = coreFonts.getFontType;
  41839. var isPDFFunction = coreFunction.isPDFFunction;
  41840. var PDFFunction = coreFunction.PDFFunction;
  41841. var Pattern = corePattern.Pattern;
  41842. var getTilingPatternIR = corePattern.getTilingPatternIR;
  41843. var CMapFactory = coreCMap.CMapFactory;
  41844. var IdentityCMap = coreCMap.IdentityCMap;
  41845. var getMetrics = coreMetrics.getMetrics;
  41846. var bidi = coreBidi.bidi;
  41847. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  41848. var StandardEncoding = coreEncodings.StandardEncoding;
  41849. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  41850. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  41851. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  41852. var getEncoding = coreEncodings.getEncoding;
  41853. var getStdFontMap = coreStandardFonts.getStdFontMap;
  41854. var getSerifFonts = coreStandardFonts.getSerifFonts;
  41855. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  41856. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  41857. var reverseIfRtl = coreUnicode.reverseIfRtl;
  41858. var PartialEvaluator = (function PartialEvaluatorClosure() {
  41859. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  41860. uniquePrefix, idCounters, fontCache) {
  41861. this.pdfManager = pdfManager;
  41862. this.xref = xref;
  41863. this.handler = handler;
  41864. this.pageIndex = pageIndex;
  41865. this.uniquePrefix = uniquePrefix;
  41866. this.idCounters = idCounters;
  41867. this.fontCache = fontCache;
  41868. }
  41869. // Trying to minimize Date.now() usage and check every 100 time
  41870. var TIME_SLOT_DURATION_MS = 20;
  41871. var CHECK_TIME_EVERY = 100;
  41872. function TimeSlotManager() {
  41873. this.reset();
  41874. }
  41875. TimeSlotManager.prototype = {
  41876. check: function TimeSlotManager_check() {
  41877. if (++this.checked < CHECK_TIME_EVERY) {
  41878. return false;
  41879. }
  41880. this.checked = 0;
  41881. return this.endTime <= Date.now();
  41882. },
  41883. reset: function TimeSlotManager_reset() {
  41884. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  41885. this.checked = 0;
  41886. }
  41887. };
  41888. var deferred = Promise.resolve();
  41889. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  41890. PartialEvaluator.prototype = {
  41891. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  41892. if (!isDict(resources)) {
  41893. return false;
  41894. }
  41895. var processed = Object.create(null);
  41896. if (resources.objId) {
  41897. processed[resources.objId] = true;
  41898. }
  41899. var nodes = [resources], xref = this.xref;
  41900. while (nodes.length) {
  41901. var key, i, ii;
  41902. var node = nodes.shift();
  41903. // First check the current resources for blend modes.
  41904. var graphicStates = node.get('ExtGState');
  41905. if (isDict(graphicStates)) {
  41906. var graphicStatesKeys = graphicStates.getKeys();
  41907. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  41908. key = graphicStatesKeys[i];
  41909. var graphicState = graphicStates.get(key);
  41910. var bm = graphicState.get('BM');
  41911. if (isName(bm) && bm.name !== 'Normal') {
  41912. return true;
  41913. }
  41914. }
  41915. }
  41916. // Descend into the XObjects to look for more resources and blend modes.
  41917. var xObjects = node.get('XObject');
  41918. if (!isDict(xObjects)) {
  41919. continue;
  41920. }
  41921. var xObjectsKeys = xObjects.getKeys();
  41922. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  41923. key = xObjectsKeys[i];
  41924. var xObject = xObjects.getRaw(key);
  41925. if (isRef(xObject)) {
  41926. if (processed[xObject.toString()]) {
  41927. // The XObject has already been processed, and by avoiding a
  41928. // redundant `xref.fetch` we can *significantly* reduce the load
  41929. // time for badly generated PDF files (fixes issue6961.pdf).
  41930. continue;
  41931. }
  41932. xObject = xref.fetch(xObject);
  41933. }
  41934. if (!isStream(xObject)) {
  41935. continue;
  41936. }
  41937. if (xObject.dict.objId) {
  41938. if (processed[xObject.dict.objId]) {
  41939. // stream has objId and is processed already
  41940. continue;
  41941. }
  41942. processed[xObject.dict.objId] = true;
  41943. }
  41944. var xResources = xObject.dict.get('Resources');
  41945. // Checking objId to detect an infinite loop.
  41946. if (isDict(xResources) &&
  41947. (!xResources.objId || !processed[xResources.objId])) {
  41948. nodes.push(xResources);
  41949. if (xResources.objId) {
  41950. processed[xResources.objId] = true;
  41951. }
  41952. }
  41953. }
  41954. }
  41955. return false;
  41956. },
  41957. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  41958. xobj, smask,
  41959. operatorList,
  41960. task,
  41961. initialState) {
  41962. var matrix = xobj.dict.getArray('Matrix');
  41963. var bbox = xobj.dict.getArray('BBox');
  41964. var group = xobj.dict.get('Group');
  41965. if (group) {
  41966. var groupOptions = {
  41967. matrix: matrix,
  41968. bbox: bbox,
  41969. smask: smask,
  41970. isolated: false,
  41971. knockout: false
  41972. };
  41973. var groupSubtype = group.get('S');
  41974. var colorSpace;
  41975. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  41976. groupOptions.isolated = (group.get('I') || false);
  41977. groupOptions.knockout = (group.get('K') || false);
  41978. colorSpace = (group.has('CS') ?
  41979. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  41980. }
  41981. if (smask && smask.backdrop) {
  41982. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  41983. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  41984. }
  41985. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  41986. }
  41987. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  41988. return this.getOperatorList(xobj, task,
  41989. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  41990. then(function () {
  41991. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  41992. if (group) {
  41993. operatorList.addOp(OPS.endGroup, [groupOptions]);
  41994. }
  41995. });
  41996. },
  41997. buildPaintImageXObject:
  41998. function PartialEvaluator_buildPaintImageXObject(resources, image,
  41999. inline, operatorList,
  42000. cacheKey, imageCache) {
  42001. var self = this;
  42002. var dict = image.dict;
  42003. var w = dict.get('Width', 'W');
  42004. var h = dict.get('Height', 'H');
  42005. if (!(w && isNum(w)) || !(h && isNum(h))) {
  42006. warn('Image dimensions are missing, or not numbers.');
  42007. return;
  42008. }
  42009. if (PDFJS.maxImageSize !== -1 && w * h > PDFJS.maxImageSize) {
  42010. warn('Image exceeded maximum allowed size and was removed.');
  42011. return;
  42012. }
  42013. var imageMask = (dict.get('ImageMask', 'IM') || false);
  42014. var imgData, args;
  42015. if (imageMask) {
  42016. // This depends on a tmpCanvas being filled with the
  42017. // current fillStyle, such that processing the pixel
  42018. // data can't be done here. Instead of creating a
  42019. // complete PDFImage, only read the information needed
  42020. // for later.
  42021. var width = dict.get('Width', 'W');
  42022. var height = dict.get('Height', 'H');
  42023. var bitStrideLength = (width + 7) >> 3;
  42024. var imgArray = image.getBytes(bitStrideLength * height);
  42025. var decode = dict.get('Decode', 'D');
  42026. var inverseDecode = (!!decode && decode[0] > 0);
  42027. imgData = PDFImage.createMask(imgArray, width, height,
  42028. image instanceof DecodeStream,
  42029. inverseDecode);
  42030. imgData.cached = true;
  42031. args = [imgData];
  42032. operatorList.addOp(OPS.paintImageMaskXObject, args);
  42033. if (cacheKey) {
  42034. imageCache[cacheKey] = {
  42035. fn: OPS.paintImageMaskXObject,
  42036. args: args
  42037. };
  42038. }
  42039. return;
  42040. }
  42041. var softMask = (dict.get('SMask', 'SM') || false);
  42042. var mask = (dict.get('Mask') || false);
  42043. var SMALL_IMAGE_DIMENSIONS = 200;
  42044. // Inlining small images into the queue as RGB data
  42045. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  42046. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  42047. var imageObj = new PDFImage(this.xref, resources, image,
  42048. inline, null, null);
  42049. // We force the use of RGBA_32BPP images here, because we can't handle
  42050. // any other kind.
  42051. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  42052. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  42053. return;
  42054. }
  42055. // If there is no imageMask, create the PDFImage and a lot
  42056. // of image processing can be done here.
  42057. var uniquePrefix = (this.uniquePrefix || '');
  42058. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  42059. operatorList.addDependency(objId);
  42060. args = [objId, w, h];
  42061. if (!softMask && !mask && image instanceof JpegStream &&
  42062. image.isNativelySupported(this.xref, resources)) {
  42063. // These JPEGs don't need any more processing so we can just send it.
  42064. operatorList.addOp(OPS.paintJpegXObject, args);
  42065. this.handler.send('obj',
  42066. [objId, this.pageIndex, 'JpegStream', image.getIR()]);
  42067. return;
  42068. }
  42069. PDFImage.buildImage(self.handler, self.xref, resources, image, inline).
  42070. then(function(imageObj) {
  42071. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  42072. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  42073. [imgData.data.buffer]);
  42074. }).then(undefined, function (reason) {
  42075. warn('Unable to decode image: ' + reason);
  42076. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  42077. });
  42078. operatorList.addOp(OPS.paintImageXObject, args);
  42079. if (cacheKey) {
  42080. imageCache[cacheKey] = {
  42081. fn: OPS.paintImageXObject,
  42082. args: args
  42083. };
  42084. }
  42085. },
  42086. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  42087. operatorList, task,
  42088. stateManager) {
  42089. var smaskContent = smask.get('G');
  42090. var smaskOptions = {
  42091. subtype: smask.get('S').name,
  42092. backdrop: smask.get('BC')
  42093. };
  42094. // The SMask might have a alpha/luminosity value transfer function --
  42095. // we will build a map of integer values in range 0..255 to be fast.
  42096. var transferObj = smask.get('TR');
  42097. if (isPDFFunction(transferObj)) {
  42098. var transferFn = PDFFunction.parse(this.xref, transferObj);
  42099. var transferMap = new Uint8Array(256);
  42100. var tmp = new Float32Array(1);
  42101. for (var i = 0; i < 256; i++) {
  42102. tmp[0] = i / 255;
  42103. transferFn(tmp, 0, tmp, 0);
  42104. transferMap[i] = (tmp[0] * 255) | 0;
  42105. }
  42106. smaskOptions.transferMap = transferMap;
  42107. }
  42108. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  42109. operatorList, task, stateManager.state.clone());
  42110. },
  42111. handleTilingType:
  42112. function PartialEvaluator_handleTilingType(fn, args, resources,
  42113. pattern, patternDict,
  42114. operatorList, task) {
  42115. // Create an IR of the pattern code.
  42116. var tilingOpList = new OperatorList();
  42117. // Merge the available resources, to prevent issues when the patternDict
  42118. // is missing some /Resources entries (fixes issue6541.pdf).
  42119. var resourcesArray = [patternDict.get('Resources'), resources];
  42120. var patternResources = Dict.merge(this.xref, resourcesArray);
  42121. return this.getOperatorList(pattern, task, patternResources,
  42122. tilingOpList).then(function () {
  42123. // Add the dependencies to the parent operator list so they are
  42124. // resolved before sub operator list is executed synchronously.
  42125. operatorList.addDependencies(tilingOpList.dependencies);
  42126. operatorList.addOp(fn, getTilingPatternIR({
  42127. fnArray: tilingOpList.fnArray,
  42128. argsArray: tilingOpList.argsArray
  42129. }, patternDict, args));
  42130. });
  42131. },
  42132. handleSetFont:
  42133. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  42134. operatorList, task, state) {
  42135. // TODO(mack): Not needed?
  42136. var fontName;
  42137. if (fontArgs) {
  42138. fontArgs = fontArgs.slice();
  42139. fontName = fontArgs[0].name;
  42140. }
  42141. var self = this;
  42142. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  42143. function (translated) {
  42144. if (!translated.font.isType3Font) {
  42145. return translated;
  42146. }
  42147. return translated.loadType3Data(self, resources, operatorList, task).
  42148. then(function () {
  42149. return translated;
  42150. }, function (reason) {
  42151. // Error in the font data -- sending unsupported feature notification.
  42152. self.handler.send('UnsupportedFeature',
  42153. {featureId: UNSUPPORTED_FEATURES.font});
  42154. return new TranslatedFont('g_font_error',
  42155. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  42156. });
  42157. }).then(function (translated) {
  42158. state.font = translated.font;
  42159. translated.send(self.handler);
  42160. return translated.loadedName;
  42161. });
  42162. },
  42163. handleText: function PartialEvaluator_handleText(chars, state) {
  42164. var font = state.font;
  42165. var glyphs = font.charsToGlyphs(chars);
  42166. var isAddToPathSet = !!(state.textRenderingMode &
  42167. TextRenderingMode.ADD_TO_PATH_FLAG);
  42168. if (font.data && (isAddToPathSet || PDFJS.disableFontFace)) {
  42169. var buildPath = function (fontChar) {
  42170. if (!font.renderer.hasBuiltPath(fontChar)) {
  42171. var path = font.renderer.getPathJs(fontChar);
  42172. this.handler.send('commonobj', [
  42173. font.loadedName + '_path_' + fontChar,
  42174. 'FontPath',
  42175. path
  42176. ]);
  42177. }
  42178. }.bind(this);
  42179. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  42180. var glyph = glyphs[i];
  42181. buildPath(glyph.fontChar);
  42182. // If the glyph has an accent we need to build a path for its
  42183. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  42184. var accent = glyph.accent;
  42185. if (accent && accent.fontChar) {
  42186. buildPath(accent.fontChar);
  42187. }
  42188. }
  42189. }
  42190. return glyphs;
  42191. },
  42192. setGState: function PartialEvaluator_setGState(resources, gState,
  42193. operatorList, task,
  42194. xref, stateManager) {
  42195. // This array holds the converted/processed state data.
  42196. var gStateObj = [];
  42197. var gStateKeys = gState.getKeys();
  42198. var self = this;
  42199. var promise = Promise.resolve();
  42200. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  42201. var key = gStateKeys[i];
  42202. var value = gState.get(key);
  42203. switch (key) {
  42204. case 'Type':
  42205. break;
  42206. case 'LW':
  42207. case 'LC':
  42208. case 'LJ':
  42209. case 'ML':
  42210. case 'D':
  42211. case 'RI':
  42212. case 'FL':
  42213. case 'CA':
  42214. case 'ca':
  42215. gStateObj.push([key, value]);
  42216. break;
  42217. case 'Font':
  42218. promise = promise.then(function () {
  42219. return self.handleSetFont(resources, null, value[0], operatorList,
  42220. task, stateManager.state).
  42221. then(function (loadedName) {
  42222. operatorList.addDependency(loadedName);
  42223. gStateObj.push([key, [loadedName, value[1]]]);
  42224. });
  42225. });
  42226. break;
  42227. case 'BM':
  42228. gStateObj.push([key, value]);
  42229. break;
  42230. case 'SMask':
  42231. if (isName(value) && value.name === 'None') {
  42232. gStateObj.push([key, false]);
  42233. break;
  42234. }
  42235. if (isDict(value)) {
  42236. promise = promise.then(function (dict) {
  42237. return self.handleSMask(dict, resources, operatorList,
  42238. task, stateManager);
  42239. }.bind(this, value));
  42240. gStateObj.push([key, true]);
  42241. } else {
  42242. warn('Unsupported SMask type');
  42243. }
  42244. break;
  42245. // Only generate info log messages for the following since
  42246. // they are unlikely to have a big impact on the rendering.
  42247. case 'OP':
  42248. case 'op':
  42249. case 'OPM':
  42250. case 'BG':
  42251. case 'BG2':
  42252. case 'UCR':
  42253. case 'UCR2':
  42254. case 'TR':
  42255. case 'TR2':
  42256. case 'HT':
  42257. case 'SM':
  42258. case 'SA':
  42259. case 'AIS':
  42260. case 'TK':
  42261. // TODO implement these operators.
  42262. info('graphic state operator ' + key);
  42263. break;
  42264. default:
  42265. info('Unknown graphic state operator ' + key);
  42266. break;
  42267. }
  42268. }
  42269. return promise.then(function () {
  42270. if (gStateObj.length > 0) {
  42271. operatorList.addOp(OPS.setGState, [gStateObj]);
  42272. }
  42273. });
  42274. },
  42275. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  42276. resources) {
  42277. function errorFont() {
  42278. return Promise.resolve(new TranslatedFont('g_font_error',
  42279. new ErrorFont('Font ' + fontName + ' is not available'), font));
  42280. }
  42281. var fontRef;
  42282. if (font) { // Loading by ref.
  42283. assert(isRef(font));
  42284. fontRef = font;
  42285. } else { // Loading by name.
  42286. var fontRes = resources.get('Font');
  42287. if (fontRes) {
  42288. fontRef = fontRes.getRaw(fontName);
  42289. } else {
  42290. warn('fontRes not available');
  42291. return errorFont();
  42292. }
  42293. }
  42294. if (!fontRef) {
  42295. warn('fontRef not available');
  42296. return errorFont();
  42297. }
  42298. if (this.fontCache.has(fontRef)) {
  42299. return this.fontCache.get(fontRef);
  42300. }
  42301. font = xref.fetchIfRef(fontRef);
  42302. if (!isDict(font)) {
  42303. return errorFont();
  42304. }
  42305. // We are holding font.translated references just for fontRef that are not
  42306. // dictionaries (Dict). See explanation below.
  42307. if (font.translated) {
  42308. return font.translated;
  42309. }
  42310. var fontCapability = createPromiseCapability();
  42311. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  42312. var descriptor = preEvaluatedFont.descriptor;
  42313. var fontID = fontRef.num + '_' + fontRef.gen;
  42314. if (isDict(descriptor)) {
  42315. if (!descriptor.fontAliases) {
  42316. descriptor.fontAliases = Object.create(null);
  42317. }
  42318. var fontAliases = descriptor.fontAliases;
  42319. var hash = preEvaluatedFont.hash;
  42320. if (fontAliases[hash]) {
  42321. var aliasFontRef = fontAliases[hash].aliasRef;
  42322. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  42323. this.fontCache.putAlias(fontRef, aliasFontRef);
  42324. return this.fontCache.get(fontRef);
  42325. }
  42326. }
  42327. if (!fontAliases[hash]) {
  42328. fontAliases[hash] = {
  42329. fontID: Font.getFontID()
  42330. };
  42331. }
  42332. fontAliases[hash].aliasRef = fontRef;
  42333. fontID = fontAliases[hash].fontID;
  42334. }
  42335. // Workaround for bad PDF generators that don't reference fonts
  42336. // properly, i.e. by not using an object identifier.
  42337. // Check if the fontRef is a Dict (as opposed to a standard object),
  42338. // in which case we don't cache the font and instead reference it by
  42339. // fontName in font.loadedName below.
  42340. var fontRefIsDict = isDict(fontRef);
  42341. if (!fontRefIsDict) {
  42342. this.fontCache.put(fontRef, fontCapability.promise);
  42343. }
  42344. // Keep track of each font we translated so the caller can
  42345. // load them asynchronously before calling display on a page.
  42346. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  42347. fontName.replace(/\W/g, '') : fontID);
  42348. font.translated = fontCapability.promise;
  42349. // TODO move promises into translate font
  42350. var translatedPromise;
  42351. try {
  42352. translatedPromise = Promise.resolve(
  42353. this.translateFont(preEvaluatedFont, xref));
  42354. } catch (e) {
  42355. translatedPromise = Promise.reject(e);
  42356. }
  42357. var self = this;
  42358. translatedPromise.then(function (translatedFont) {
  42359. if (translatedFont.fontType !== undefined) {
  42360. var xrefFontStats = xref.stats.fontTypes;
  42361. xrefFontStats[translatedFont.fontType] = true;
  42362. }
  42363. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42364. translatedFont, font));
  42365. }, function (reason) {
  42366. // TODO fontCapability.reject?
  42367. // Error in the font data -- sending unsupported feature notification.
  42368. self.handler.send('UnsupportedFeature',
  42369. {featureId: UNSUPPORTED_FEATURES.font});
  42370. try {
  42371. // error, but it's still nice to have font type reported
  42372. var descriptor = preEvaluatedFont.descriptor;
  42373. var fontFile3 = descriptor && descriptor.get('FontFile3');
  42374. var subtype = fontFile3 && fontFile3.get('Subtype');
  42375. var fontType = getFontType(preEvaluatedFont.type,
  42376. subtype && subtype.name);
  42377. var xrefFontStats = xref.stats.fontTypes;
  42378. xrefFontStats[fontType] = true;
  42379. } catch (ex) { }
  42380. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42381. new ErrorFont(reason instanceof Error ? reason.message : reason),
  42382. font));
  42383. });
  42384. return fontCapability.promise;
  42385. },
  42386. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  42387. var lastIndex = operatorList.length - 1;
  42388. if (!args) {
  42389. args = [];
  42390. }
  42391. if (lastIndex < 0 ||
  42392. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  42393. operatorList.addOp(OPS.constructPath, [[fn], args]);
  42394. } else {
  42395. var opArgs = operatorList.argsArray[lastIndex];
  42396. opArgs[0].push(fn);
  42397. Array.prototype.push.apply(opArgs[1], args);
  42398. }
  42399. },
  42400. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  42401. cs, patterns, resources, task, xref) {
  42402. // compile tiling patterns
  42403. var patternName = args[args.length - 1];
  42404. // SCN/scn applies patterns along with normal colors
  42405. var pattern;
  42406. if (isName(patternName) &&
  42407. (pattern = patterns.get(patternName.name))) {
  42408. var dict = (isStream(pattern) ? pattern.dict : pattern);
  42409. var typeNum = dict.get('PatternType');
  42410. if (typeNum === TILING_PATTERN) {
  42411. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  42412. return this.handleTilingType(fn, color, resources, pattern,
  42413. dict, operatorList, task);
  42414. } else if (typeNum === SHADING_PATTERN) {
  42415. var shading = dict.get('Shading');
  42416. var matrix = dict.get('Matrix');
  42417. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  42418. this.handler);
  42419. operatorList.addOp(fn, pattern.getIR());
  42420. return Promise.resolve();
  42421. } else {
  42422. return Promise.reject('Unknown PatternType: ' + typeNum);
  42423. }
  42424. }
  42425. // TODO shall we fail here?
  42426. operatorList.addOp(fn, args);
  42427. return Promise.resolve();
  42428. },
  42429. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  42430. task,
  42431. resources,
  42432. operatorList,
  42433. initialState) {
  42434. var self = this;
  42435. var xref = this.xref;
  42436. var imageCache = Object.create(null);
  42437. assert(operatorList);
  42438. resources = (resources || Dict.empty);
  42439. var xobjs = (resources.get('XObject') || Dict.empty);
  42440. var patterns = (resources.get('Pattern') || Dict.empty);
  42441. var stateManager = new StateManager(initialState || new EvalState());
  42442. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42443. var timeSlotManager = new TimeSlotManager();
  42444. return new Promise(function next(resolve, reject) {
  42445. task.ensureNotTerminated();
  42446. timeSlotManager.reset();
  42447. var stop, operation = {}, i, ii, cs;
  42448. while (!(stop = timeSlotManager.check())) {
  42449. // The arguments parsed by read() are used beyond this loop, so we
  42450. // cannot reuse the same array on each iteration. Therefore we pass
  42451. // in |null| as the initial value (see the comment on
  42452. // EvaluatorPreprocessor_read() for why).
  42453. operation.args = null;
  42454. if (!(preprocessor.read(operation))) {
  42455. break;
  42456. }
  42457. var args = operation.args;
  42458. var fn = operation.fn;
  42459. switch (fn | 0) {
  42460. case OPS.paintXObject:
  42461. if (args[0].code) {
  42462. break;
  42463. }
  42464. // eagerly compile XForm objects
  42465. var name = args[0].name;
  42466. if (!name) {
  42467. warn('XObject must be referred to by name.');
  42468. continue;
  42469. }
  42470. if (imageCache[name] !== undefined) {
  42471. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  42472. args = null;
  42473. continue;
  42474. }
  42475. var xobj = xobjs.get(name);
  42476. if (xobj) {
  42477. assert(isStream(xobj), 'XObject should be a stream');
  42478. var type = xobj.dict.get('Subtype');
  42479. assert(isName(type),
  42480. 'XObject should have a Name subtype');
  42481. if (type.name === 'Form') {
  42482. stateManager.save();
  42483. return self.buildFormXObject(resources, xobj, null,
  42484. operatorList, task,
  42485. stateManager.state.clone()).
  42486. then(function () {
  42487. stateManager.restore();
  42488. next(resolve, reject);
  42489. }, reject);
  42490. } else if (type.name === 'Image') {
  42491. self.buildPaintImageXObject(resources, xobj, false,
  42492. operatorList, name, imageCache);
  42493. args = null;
  42494. continue;
  42495. } else if (type.name === 'PS') {
  42496. // PostScript XObjects are unused when viewing documents.
  42497. // See section 4.7.1 of Adobe's PDF reference.
  42498. info('Ignored XObject subtype PS');
  42499. continue;
  42500. } else {
  42501. error('Unhandled XObject subtype ' + type.name);
  42502. }
  42503. }
  42504. break;
  42505. case OPS.setFont:
  42506. var fontSize = args[1];
  42507. // eagerly collect all fonts
  42508. return self.handleSetFont(resources, args, null, operatorList,
  42509. task, stateManager.state).
  42510. then(function (loadedName) {
  42511. operatorList.addDependency(loadedName);
  42512. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  42513. next(resolve, reject);
  42514. }, reject);
  42515. case OPS.endInlineImage:
  42516. var cacheKey = args[0].cacheKey;
  42517. if (cacheKey) {
  42518. var cacheEntry = imageCache[cacheKey];
  42519. if (cacheEntry !== undefined) {
  42520. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  42521. args = null;
  42522. continue;
  42523. }
  42524. }
  42525. self.buildPaintImageXObject(resources, args[0], true,
  42526. operatorList, cacheKey, imageCache);
  42527. args = null;
  42528. continue;
  42529. case OPS.showText:
  42530. args[0] = self.handleText(args[0], stateManager.state);
  42531. break;
  42532. case OPS.showSpacedText:
  42533. var arr = args[0];
  42534. var combinedGlyphs = [];
  42535. var arrLength = arr.length;
  42536. var state = stateManager.state;
  42537. for (i = 0; i < arrLength; ++i) {
  42538. var arrItem = arr[i];
  42539. if (isString(arrItem)) {
  42540. Array.prototype.push.apply(combinedGlyphs,
  42541. self.handleText(arrItem, state));
  42542. } else if (isNum(arrItem)) {
  42543. combinedGlyphs.push(arrItem);
  42544. }
  42545. }
  42546. args[0] = combinedGlyphs;
  42547. fn = OPS.showText;
  42548. break;
  42549. case OPS.nextLineShowText:
  42550. operatorList.addOp(OPS.nextLine);
  42551. args[0] = self.handleText(args[0], stateManager.state);
  42552. fn = OPS.showText;
  42553. break;
  42554. case OPS.nextLineSetSpacingShowText:
  42555. operatorList.addOp(OPS.nextLine);
  42556. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  42557. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  42558. args[0] = self.handleText(args[0], stateManager.state);
  42559. fn = OPS.showText;
  42560. break;
  42561. case OPS.setTextRenderingMode:
  42562. stateManager.state.textRenderingMode = args[0];
  42563. break;
  42564. case OPS.setFillColorSpace:
  42565. stateManager.state.fillColorSpace =
  42566. ColorSpace.parse(args[0], xref, resources);
  42567. continue;
  42568. case OPS.setStrokeColorSpace:
  42569. stateManager.state.strokeColorSpace =
  42570. ColorSpace.parse(args[0], xref, resources);
  42571. continue;
  42572. case OPS.setFillColor:
  42573. cs = stateManager.state.fillColorSpace;
  42574. args = cs.getRgb(args, 0);
  42575. fn = OPS.setFillRGBColor;
  42576. break;
  42577. case OPS.setStrokeColor:
  42578. cs = stateManager.state.strokeColorSpace;
  42579. args = cs.getRgb(args, 0);
  42580. fn = OPS.setStrokeRGBColor;
  42581. break;
  42582. case OPS.setFillGray:
  42583. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  42584. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42585. fn = OPS.setFillRGBColor;
  42586. break;
  42587. case OPS.setStrokeGray:
  42588. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  42589. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42590. fn = OPS.setStrokeRGBColor;
  42591. break;
  42592. case OPS.setFillCMYKColor:
  42593. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  42594. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42595. fn = OPS.setFillRGBColor;
  42596. break;
  42597. case OPS.setStrokeCMYKColor:
  42598. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  42599. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42600. fn = OPS.setStrokeRGBColor;
  42601. break;
  42602. case OPS.setFillRGBColor:
  42603. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  42604. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42605. break;
  42606. case OPS.setStrokeRGBColor:
  42607. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  42608. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42609. break;
  42610. case OPS.setFillColorN:
  42611. cs = stateManager.state.fillColorSpace;
  42612. if (cs.name === 'Pattern') {
  42613. return self.handleColorN(operatorList, OPS.setFillColorN,
  42614. args, cs, patterns, resources, task, xref).then(function() {
  42615. next(resolve, reject);
  42616. }, reject);
  42617. }
  42618. args = cs.getRgb(args, 0);
  42619. fn = OPS.setFillRGBColor;
  42620. break;
  42621. case OPS.setStrokeColorN:
  42622. cs = stateManager.state.strokeColorSpace;
  42623. if (cs.name === 'Pattern') {
  42624. return self.handleColorN(operatorList, OPS.setStrokeColorN,
  42625. args, cs, patterns, resources, task, xref).then(function() {
  42626. next(resolve, reject);
  42627. }, reject);
  42628. }
  42629. args = cs.getRgb(args, 0);
  42630. fn = OPS.setStrokeRGBColor;
  42631. break;
  42632. case OPS.shadingFill:
  42633. var shadingRes = resources.get('Shading');
  42634. if (!shadingRes) {
  42635. error('No shading resource found');
  42636. }
  42637. var shading = shadingRes.get(args[0].name);
  42638. if (!shading) {
  42639. error('No shading object found');
  42640. }
  42641. var shadingFill = Pattern.parseShading(shading, null, xref,
  42642. resources, self.handler);
  42643. var patternIR = shadingFill.getIR();
  42644. args = [patternIR];
  42645. fn = OPS.shadingFill;
  42646. break;
  42647. case OPS.setGState:
  42648. var dictName = args[0];
  42649. var extGState = resources.get('ExtGState');
  42650. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42651. break;
  42652. }
  42653. var gState = extGState.get(dictName.name);
  42654. return self.setGState(resources, gState, operatorList, task,
  42655. xref, stateManager).then(function() {
  42656. next(resolve, reject);
  42657. }, reject);
  42658. case OPS.moveTo:
  42659. case OPS.lineTo:
  42660. case OPS.curveTo:
  42661. case OPS.curveTo2:
  42662. case OPS.curveTo3:
  42663. case OPS.closePath:
  42664. self.buildPath(operatorList, fn, args);
  42665. continue;
  42666. case OPS.rectangle:
  42667. self.buildPath(operatorList, fn, args);
  42668. continue;
  42669. case OPS.markPoint:
  42670. case OPS.markPointProps:
  42671. case OPS.beginMarkedContent:
  42672. case OPS.beginMarkedContentProps:
  42673. case OPS.endMarkedContent:
  42674. case OPS.beginCompat:
  42675. case OPS.endCompat:
  42676. // Ignore operators where the corresponding handlers are known to
  42677. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  42678. // serialization errors and is also a bit more efficient.
  42679. // We could also try to serialize all objects in a general way,
  42680. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  42681. // but doing so is meaningless without knowing the semantics.
  42682. continue;
  42683. default:
  42684. // Note: Let's hope that the ignored operator does not have any
  42685. // non-serializable arguments, otherwise postMessage will throw
  42686. // "An object could not be cloned.".
  42687. }
  42688. operatorList.addOp(fn, args);
  42689. }
  42690. if (stop) {
  42691. deferred.then(function () {
  42692. next(resolve, reject);
  42693. }, reject);
  42694. return;
  42695. }
  42696. // Some PDFs don't close all restores inside object/form.
  42697. // Closing those for them.
  42698. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  42699. operatorList.addOp(OPS.restore, []);
  42700. }
  42701. resolve();
  42702. });
  42703. },
  42704. getTextContent:
  42705. function PartialEvaluator_getTextContent(stream, task, resources,
  42706. stateManager,
  42707. normalizeWhitespace) {
  42708. stateManager = (stateManager || new StateManager(new TextState()));
  42709. var WhitespaceRegexp = /\s/g;
  42710. var textContent = {
  42711. items: [],
  42712. styles: Object.create(null)
  42713. };
  42714. var textContentItem = {
  42715. initialized: false,
  42716. str: [],
  42717. width: 0,
  42718. height: 0,
  42719. vertical: false,
  42720. lastAdvanceWidth: 0,
  42721. lastAdvanceHeight: 0,
  42722. textAdvanceScale: 0,
  42723. spaceWidth: 0,
  42724. fakeSpaceMin: Infinity,
  42725. fakeMultiSpaceMin: Infinity,
  42726. fakeMultiSpaceMax: -0,
  42727. textRunBreakAllowed: false,
  42728. transform: null,
  42729. fontName: null
  42730. };
  42731. var SPACE_FACTOR = 0.3;
  42732. var MULTI_SPACE_FACTOR = 1.5;
  42733. var MULTI_SPACE_FACTOR_MAX = 4;
  42734. var self = this;
  42735. var xref = this.xref;
  42736. resources = (xref.fetchIfRef(resources) || Dict.empty);
  42737. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  42738. var xobjs = null;
  42739. var xobjsCache = Object.create(null);
  42740. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42741. var textState;
  42742. function ensureTextContentItem() {
  42743. if (textContentItem.initialized) {
  42744. return textContentItem;
  42745. }
  42746. var font = textState.font;
  42747. if (!(font.loadedName in textContent.styles)) {
  42748. textContent.styles[font.loadedName] = {
  42749. fontFamily: font.fallbackName,
  42750. ascent: font.ascent,
  42751. descent: font.descent,
  42752. vertical: font.vertical
  42753. };
  42754. }
  42755. textContentItem.fontName = font.loadedName;
  42756. // 9.4.4 Text Space Details
  42757. var tsm = [textState.fontSize * textState.textHScale, 0,
  42758. 0, textState.fontSize,
  42759. 0, textState.textRise];
  42760. if (font.isType3Font &&
  42761. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  42762. textState.fontSize === 1) {
  42763. var glyphHeight = font.bbox[3] - font.bbox[1];
  42764. if (glyphHeight > 0) {
  42765. glyphHeight = glyphHeight * textState.fontMatrix[3];
  42766. tsm[3] *= glyphHeight;
  42767. }
  42768. }
  42769. var trm = Util.transform(textState.ctm,
  42770. Util.transform(textState.textMatrix, tsm));
  42771. textContentItem.transform = trm;
  42772. if (!font.vertical) {
  42773. textContentItem.width = 0;
  42774. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  42775. textContentItem.vertical = false;
  42776. } else {
  42777. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  42778. textContentItem.height = 0;
  42779. textContentItem.vertical = true;
  42780. }
  42781. var a = textState.textLineMatrix[0];
  42782. var b = textState.textLineMatrix[1];
  42783. var scaleLineX = Math.sqrt(a * a + b * b);
  42784. a = textState.ctm[0];
  42785. b = textState.ctm[1];
  42786. var scaleCtmX = Math.sqrt(a * a + b * b);
  42787. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  42788. textContentItem.lastAdvanceWidth = 0;
  42789. textContentItem.lastAdvanceHeight = 0;
  42790. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  42791. if (spaceWidth) {
  42792. textContentItem.spaceWidth = spaceWidth;
  42793. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  42794. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  42795. textContentItem.fakeMultiSpaceMax =
  42796. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  42797. // It's okay for monospace fonts to fake as much space as needed.
  42798. textContentItem.textRunBreakAllowed = !font.isMonospace;
  42799. } else {
  42800. textContentItem.spaceWidth = 0;
  42801. textContentItem.fakeSpaceMin = Infinity;
  42802. textContentItem.fakeMultiSpaceMin = Infinity;
  42803. textContentItem.fakeMultiSpaceMax = 0;
  42804. textContentItem.textRunBreakAllowed = false;
  42805. }
  42806. textContentItem.initialized = true;
  42807. return textContentItem;
  42808. }
  42809. function replaceWhitespace(str) {
  42810. // Replaces all whitespaces with standard spaces (0x20), to avoid
  42811. // alignment issues between the textLayer and the canvas if the text
  42812. // contains e.g. tabs (fixes issue6612.pdf).
  42813. var i = 0, ii = str.length, code;
  42814. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  42815. i++;
  42816. }
  42817. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  42818. }
  42819. function runBidiTransform(textChunk) {
  42820. var str = textChunk.str.join('');
  42821. var bidiResult = PDFJS.bidi(str, -1, textChunk.vertical);
  42822. return {
  42823. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  42824. bidiResult.str),
  42825. dir: bidiResult.dir,
  42826. width: textChunk.width,
  42827. height: textChunk.height,
  42828. transform: textChunk.transform,
  42829. fontName: textChunk.fontName
  42830. };
  42831. }
  42832. function handleSetFont(fontName, fontRef) {
  42833. return self.loadFont(fontName, fontRef, xref, resources).
  42834. then(function (translated) {
  42835. textState.font = translated.font;
  42836. textState.fontMatrix = translated.font.fontMatrix ||
  42837. FONT_IDENTITY_MATRIX;
  42838. });
  42839. }
  42840. function buildTextContentItem(chars) {
  42841. var font = textState.font;
  42842. var textChunk = ensureTextContentItem();
  42843. var width = 0;
  42844. var height = 0;
  42845. var glyphs = font.charsToGlyphs(chars);
  42846. var defaultVMetrics = font.defaultVMetrics;
  42847. for (var i = 0; i < glyphs.length; i++) {
  42848. var glyph = glyphs[i];
  42849. var vMetricX = null;
  42850. var vMetricY = null;
  42851. var glyphWidth = null;
  42852. if (font.vertical) {
  42853. if (glyph.vmetric) {
  42854. glyphWidth = glyph.vmetric[0];
  42855. vMetricX = glyph.vmetric[1];
  42856. vMetricY = glyph.vmetric[2];
  42857. } else {
  42858. glyphWidth = glyph.width;
  42859. vMetricX = glyph.width * 0.5;
  42860. vMetricY = defaultVMetrics[2];
  42861. }
  42862. } else {
  42863. glyphWidth = glyph.width;
  42864. }
  42865. var glyphUnicode = glyph.unicode;
  42866. var NormalizedUnicodes = getNormalizedUnicodes();
  42867. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  42868. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  42869. }
  42870. glyphUnicode = reverseIfRtl(glyphUnicode);
  42871. // The following will calculate the x and y of the individual glyphs.
  42872. // if (font.vertical) {
  42873. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  42874. // textState.fontMatrix[0];
  42875. // tsm[5] -= vMetricY * textState.fontSize *
  42876. // textState.fontMatrix[0];
  42877. // }
  42878. // var trm = Util.transform(textState.textMatrix, tsm);
  42879. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  42880. // var x = pt[0];
  42881. // var y = pt[1];
  42882. var charSpacing = textState.charSpacing;
  42883. if (glyph.isSpace) {
  42884. var wordSpacing = textState.wordSpacing;
  42885. charSpacing += wordSpacing;
  42886. if (wordSpacing > 0) {
  42887. addFakeSpaces(wordSpacing, textChunk.str);
  42888. }
  42889. }
  42890. var tx = 0;
  42891. var ty = 0;
  42892. if (!font.vertical) {
  42893. var w0 = glyphWidth * textState.fontMatrix[0];
  42894. tx = (w0 * textState.fontSize + charSpacing) *
  42895. textState.textHScale;
  42896. width += tx;
  42897. } else {
  42898. var w1 = glyphWidth * textState.fontMatrix[0];
  42899. ty = w1 * textState.fontSize + charSpacing;
  42900. height += ty;
  42901. }
  42902. textState.translateTextMatrix(tx, ty);
  42903. textChunk.str.push(glyphUnicode);
  42904. }
  42905. if (!font.vertical) {
  42906. textChunk.lastAdvanceWidth = width;
  42907. textChunk.width += width * textChunk.textAdvanceScale;
  42908. } else {
  42909. textChunk.lastAdvanceHeight = height;
  42910. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  42911. }
  42912. return textChunk;
  42913. }
  42914. function addFakeSpaces(width, strBuf) {
  42915. if (width < textContentItem.fakeSpaceMin) {
  42916. return;
  42917. }
  42918. if (width < textContentItem.fakeMultiSpaceMin) {
  42919. strBuf.push(' ');
  42920. return;
  42921. }
  42922. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  42923. while (fakeSpaces-- > 0) {
  42924. strBuf.push(' ');
  42925. }
  42926. }
  42927. function flushTextContentItem() {
  42928. if (!textContentItem.initialized) {
  42929. return;
  42930. }
  42931. textContent.items.push(runBidiTransform(textContentItem));
  42932. textContentItem.initialized = false;
  42933. textContentItem.str.length = 0;
  42934. }
  42935. var timeSlotManager = new TimeSlotManager();
  42936. return new Promise(function next(resolve, reject) {
  42937. task.ensureNotTerminated();
  42938. timeSlotManager.reset();
  42939. var stop, operation = {}, args = [];
  42940. while (!(stop = timeSlotManager.check())) {
  42941. // The arguments parsed by read() are not used beyond this loop, so
  42942. // we can reuse the same array on every iteration, thus avoiding
  42943. // unnecessary allocations.
  42944. args.length = 0;
  42945. operation.args = args;
  42946. if (!(preprocessor.read(operation))) {
  42947. break;
  42948. }
  42949. textState = stateManager.state;
  42950. var fn = operation.fn;
  42951. args = operation.args;
  42952. var advance;
  42953. switch (fn | 0) {
  42954. case OPS.setFont:
  42955. flushTextContentItem();
  42956. textState.fontSize = args[1];
  42957. return handleSetFont(args[0].name).then(function() {
  42958. next(resolve, reject);
  42959. }, reject);
  42960. case OPS.setTextRise:
  42961. flushTextContentItem();
  42962. textState.textRise = args[0];
  42963. break;
  42964. case OPS.setHScale:
  42965. flushTextContentItem();
  42966. textState.textHScale = args[0] / 100;
  42967. break;
  42968. case OPS.setLeading:
  42969. flushTextContentItem();
  42970. textState.leading = args[0];
  42971. break;
  42972. case OPS.moveText:
  42973. // Optimization to treat same line movement as advance
  42974. var isSameTextLine = !textState.font ? false :
  42975. ((textState.font.vertical ? args[0] : args[1]) === 0);
  42976. advance = args[0] - args[1];
  42977. if (isSameTextLine && textContentItem.initialized &&
  42978. advance > 0 &&
  42979. advance <= textContentItem.fakeMultiSpaceMax) {
  42980. textState.translateTextLineMatrix(args[0], args[1]);
  42981. textContentItem.width +=
  42982. (args[0] - textContentItem.lastAdvanceWidth);
  42983. textContentItem.height +=
  42984. (args[1] - textContentItem.lastAdvanceHeight);
  42985. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  42986. (args[1] - textContentItem.lastAdvanceHeight);
  42987. addFakeSpaces(diff, textContentItem.str);
  42988. break;
  42989. }
  42990. flushTextContentItem();
  42991. textState.translateTextLineMatrix(args[0], args[1]);
  42992. textState.textMatrix = textState.textLineMatrix.slice();
  42993. break;
  42994. case OPS.setLeadingMoveText:
  42995. flushTextContentItem();
  42996. textState.leading = -args[1];
  42997. textState.translateTextLineMatrix(args[0], args[1]);
  42998. textState.textMatrix = textState.textLineMatrix.slice();
  42999. break;
  43000. case OPS.nextLine:
  43001. flushTextContentItem();
  43002. textState.carriageReturn();
  43003. break;
  43004. case OPS.setTextMatrix:
  43005. flushTextContentItem();
  43006. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  43007. args[4], args[5]);
  43008. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  43009. args[4], args[5]);
  43010. break;
  43011. case OPS.setCharSpacing:
  43012. textState.charSpacing = args[0];
  43013. break;
  43014. case OPS.setWordSpacing:
  43015. textState.wordSpacing = args[0];
  43016. break;
  43017. case OPS.beginText:
  43018. flushTextContentItem();
  43019. textState.textMatrix = IDENTITY_MATRIX.slice();
  43020. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  43021. break;
  43022. case OPS.showSpacedText:
  43023. var items = args[0];
  43024. var offset;
  43025. for (var j = 0, jj = items.length; j < jj; j++) {
  43026. if (typeof items[j] === 'string') {
  43027. buildTextContentItem(items[j]);
  43028. } else {
  43029. ensureTextContentItem();
  43030. // PDF Specification 5.3.2 states:
  43031. // The number is expressed in thousandths of a unit of text
  43032. // space.
  43033. // This amount is subtracted from the current horizontal or
  43034. // vertical coordinate, depending on the writing mode.
  43035. // In the default coordinate system, a positive adjustment
  43036. // has the effect of moving the next glyph painted either to
  43037. // the left or down by the given amount.
  43038. advance = items[j] * textState.fontSize / 1000;
  43039. var breakTextRun = false;
  43040. if (textState.font.vertical) {
  43041. offset = advance *
  43042. (textState.textHScale * textState.textMatrix[2] +
  43043. textState.textMatrix[3]);
  43044. textState.translateTextMatrix(0, advance);
  43045. breakTextRun = textContentItem.textRunBreakAllowed &&
  43046. advance > textContentItem.fakeMultiSpaceMax;
  43047. if (!breakTextRun) {
  43048. // Value needs to be added to height to paint down.
  43049. textContentItem.height += offset;
  43050. }
  43051. } else {
  43052. advance = -advance;
  43053. offset = advance * (
  43054. textState.textHScale * textState.textMatrix[0] +
  43055. textState.textMatrix[1]);
  43056. textState.translateTextMatrix(advance, 0);
  43057. breakTextRun = textContentItem.textRunBreakAllowed &&
  43058. advance > textContentItem.fakeMultiSpaceMax;
  43059. if (!breakTextRun) {
  43060. // Value needs to be subtracted from width to paint left.
  43061. textContentItem.width += offset;
  43062. }
  43063. }
  43064. if (breakTextRun) {
  43065. flushTextContentItem();
  43066. } else if (advance > 0) {
  43067. addFakeSpaces(advance, textContentItem.str);
  43068. }
  43069. }
  43070. }
  43071. break;
  43072. case OPS.showText:
  43073. buildTextContentItem(args[0]);
  43074. break;
  43075. case OPS.nextLineShowText:
  43076. flushTextContentItem();
  43077. textState.carriageReturn();
  43078. buildTextContentItem(args[0]);
  43079. break;
  43080. case OPS.nextLineSetSpacingShowText:
  43081. flushTextContentItem();
  43082. textState.wordSpacing = args[0];
  43083. textState.charSpacing = args[1];
  43084. textState.carriageReturn();
  43085. buildTextContentItem(args[2]);
  43086. break;
  43087. case OPS.paintXObject:
  43088. flushTextContentItem();
  43089. if (args[0].code) {
  43090. break;
  43091. }
  43092. if (!xobjs) {
  43093. xobjs = (resources.get('XObject') || Dict.empty);
  43094. }
  43095. var name = args[0].name;
  43096. if (xobjsCache.key === name) {
  43097. if (xobjsCache.texts) {
  43098. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  43099. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  43100. }
  43101. break;
  43102. }
  43103. var xobj = xobjs.get(name);
  43104. if (!xobj) {
  43105. break;
  43106. }
  43107. assert(isStream(xobj), 'XObject should be a stream');
  43108. var type = xobj.dict.get('Subtype');
  43109. assert(isName(type),
  43110. 'XObject should have a Name subtype');
  43111. if ('Form' !== type.name) {
  43112. xobjsCache.key = name;
  43113. xobjsCache.texts = null;
  43114. break;
  43115. }
  43116. stateManager.save();
  43117. var matrix = xobj.dict.get('Matrix');
  43118. if (isArray(matrix) && matrix.length === 6) {
  43119. stateManager.transform(matrix);
  43120. }
  43121. return self.getTextContent(xobj, task,
  43122. xobj.dict.get('Resources') || resources, stateManager,
  43123. normalizeWhitespace).then(function (formTextContent) {
  43124. Util.appendToArray(textContent.items, formTextContent.items);
  43125. Util.extendObj(textContent.styles, formTextContent.styles);
  43126. stateManager.restore();
  43127. xobjsCache.key = name;
  43128. xobjsCache.texts = formTextContent;
  43129. next(resolve, reject);
  43130. }, reject);
  43131. case OPS.setGState:
  43132. flushTextContentItem();
  43133. var dictName = args[0];
  43134. var extGState = resources.get('ExtGState');
  43135. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43136. break;
  43137. }
  43138. var gsStateMap = extGState.get(dictName.name);
  43139. var gsStateFont = null;
  43140. for (var key in gsStateMap) {
  43141. if (key === 'Font') {
  43142. assert(!gsStateFont);
  43143. gsStateFont = gsStateMap[key];
  43144. }
  43145. }
  43146. if (gsStateFont) {
  43147. textState.fontSize = gsStateFont[1];
  43148. return handleSetFont(gsStateFont[0]).then(function() {
  43149. next(resolve, reject);
  43150. }, reject);
  43151. }
  43152. break;
  43153. } // switch
  43154. } // while
  43155. if (stop) {
  43156. deferred.then(function () {
  43157. next(resolve, reject);
  43158. }, reject);
  43159. return;
  43160. }
  43161. flushTextContentItem();
  43162. resolve(textContent);
  43163. });
  43164. },
  43165. extractDataStructures: function
  43166. partialEvaluatorExtractDataStructures(dict, baseDict,
  43167. xref, properties) {
  43168. // 9.10.2
  43169. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  43170. if (toUnicode) {
  43171. properties.toUnicode = this.readToUnicode(toUnicode);
  43172. }
  43173. if (properties.composite) {
  43174. // CIDSystemInfo helps to match CID to glyphs
  43175. var cidSystemInfo = dict.get('CIDSystemInfo');
  43176. if (isDict(cidSystemInfo)) {
  43177. properties.cidSystemInfo = {
  43178. registry: cidSystemInfo.get('Registry'),
  43179. ordering: cidSystemInfo.get('Ordering'),
  43180. supplement: cidSystemInfo.get('Supplement')
  43181. };
  43182. }
  43183. var cidToGidMap = dict.get('CIDToGIDMap');
  43184. if (isStream(cidToGidMap)) {
  43185. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  43186. }
  43187. }
  43188. // Based on 9.6.6 of the spec the encoding can come from multiple places
  43189. // and depends on the font type. The base encoding and differences are
  43190. // read here, but the encoding that is actually used is chosen during
  43191. // glyph mapping in the font.
  43192. // TODO: Loading the built in encoding in the font would allow the
  43193. // differences to be merged in here not require us to hold on to it.
  43194. var differences = [];
  43195. var baseEncodingName = null;
  43196. var encoding;
  43197. if (dict.has('Encoding')) {
  43198. encoding = dict.get('Encoding');
  43199. if (isDict(encoding)) {
  43200. baseEncodingName = encoding.get('BaseEncoding');
  43201. baseEncodingName = (isName(baseEncodingName) ?
  43202. baseEncodingName.name : null);
  43203. // Load the differences between the base and original
  43204. if (encoding.has('Differences')) {
  43205. var diffEncoding = encoding.get('Differences');
  43206. var index = 0;
  43207. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  43208. var data = xref.fetchIfRef(diffEncoding[j]);
  43209. if (isNum(data)) {
  43210. index = data;
  43211. } else if (isName(data)) {
  43212. differences[index++] = data.name;
  43213. } else {
  43214. error('Invalid entry in \'Differences\' array: ' + data);
  43215. }
  43216. }
  43217. }
  43218. } else if (isName(encoding)) {
  43219. baseEncodingName = encoding.name;
  43220. } else {
  43221. error('Encoding is not a Name nor a Dict');
  43222. }
  43223. // According to table 114 if the encoding is a named encoding it must be
  43224. // one of these predefined encodings.
  43225. if ((baseEncodingName !== 'MacRomanEncoding' &&
  43226. baseEncodingName !== 'MacExpertEncoding' &&
  43227. baseEncodingName !== 'WinAnsiEncoding')) {
  43228. baseEncodingName = null;
  43229. }
  43230. }
  43231. if (baseEncodingName) {
  43232. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  43233. } else {
  43234. encoding = (properties.type === 'TrueType' ?
  43235. WinAnsiEncoding : StandardEncoding);
  43236. // The Symbolic attribute can be misused for regular fonts
  43237. // Heuristic: we have to check if the font is a standard one also
  43238. if (!!(properties.flags & FontFlags.Symbolic)) {
  43239. encoding = MacRomanEncoding;
  43240. if (!properties.file) {
  43241. if (/Symbol/i.test(properties.name)) {
  43242. encoding = SymbolSetEncoding;
  43243. } else if (/Dingbats/i.test(properties.name)) {
  43244. encoding = ZapfDingbatsEncoding;
  43245. }
  43246. }
  43247. }
  43248. properties.defaultEncoding = encoding;
  43249. }
  43250. properties.differences = differences;
  43251. properties.baseEncodingName = baseEncodingName;
  43252. properties.dict = dict;
  43253. },
  43254. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  43255. var cmap, cmapObj = toUnicode;
  43256. if (isName(cmapObj)) {
  43257. cmap = CMapFactory.create(cmapObj,
  43258. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43259. if (cmap instanceof IdentityCMap) {
  43260. return new IdentityToUnicodeMap(0, 0xFFFF);
  43261. }
  43262. return new ToUnicodeMap(cmap.getMap());
  43263. } else if (isStream(cmapObj)) {
  43264. cmap = CMapFactory.create(cmapObj,
  43265. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43266. if (cmap instanceof IdentityCMap) {
  43267. return new IdentityToUnicodeMap(0, 0xFFFF);
  43268. }
  43269. var map = new Array(cmap.length);
  43270. // Convert UTF-16BE
  43271. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  43272. // to iterate over all keys.
  43273. cmap.forEach(function(charCode, token) {
  43274. var str = [];
  43275. for (var k = 0; k < token.length; k += 2) {
  43276. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43277. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  43278. str.push(w1);
  43279. continue;
  43280. }
  43281. k += 2;
  43282. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43283. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  43284. }
  43285. map[charCode] = String.fromCharCode.apply(String, str);
  43286. });
  43287. return new ToUnicodeMap(map);
  43288. }
  43289. return null;
  43290. },
  43291. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  43292. // Extract the encoding from the CIDToGIDMap
  43293. var glyphsData = cidToGidStream.getBytes();
  43294. // Set encoding 0 to later verify the font has an encoding
  43295. var result = [];
  43296. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  43297. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  43298. if (glyphID === 0) {
  43299. continue;
  43300. }
  43301. var code = j >> 1;
  43302. result[code] = glyphID;
  43303. }
  43304. return result;
  43305. },
  43306. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  43307. descriptor,
  43308. properties) {
  43309. var glyphsWidths = [];
  43310. var defaultWidth = 0;
  43311. var glyphsVMetrics = [];
  43312. var defaultVMetrics;
  43313. var i, ii, j, jj, start, code, widths;
  43314. if (properties.composite) {
  43315. defaultWidth = dict.get('DW') || 1000;
  43316. widths = dict.get('W');
  43317. if (widths) {
  43318. for (i = 0, ii = widths.length; i < ii; i++) {
  43319. start = widths[i++];
  43320. code = xref.fetchIfRef(widths[i]);
  43321. if (isArray(code)) {
  43322. for (j = 0, jj = code.length; j < jj; j++) {
  43323. glyphsWidths[start++] = code[j];
  43324. }
  43325. } else {
  43326. var width = widths[++i];
  43327. for (j = start; j <= code; j++) {
  43328. glyphsWidths[j] = width;
  43329. }
  43330. }
  43331. }
  43332. }
  43333. if (properties.vertical) {
  43334. var vmetrics = (dict.get('DW2') || [880, -1000]);
  43335. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  43336. vmetrics = dict.get('W2');
  43337. if (vmetrics) {
  43338. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  43339. start = vmetrics[i++];
  43340. code = xref.fetchIfRef(vmetrics[i]);
  43341. if (isArray(code)) {
  43342. for (j = 0, jj = code.length; j < jj; j++) {
  43343. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  43344. }
  43345. } else {
  43346. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  43347. for (j = start; j <= code; j++) {
  43348. glyphsVMetrics[j] = vmetric;
  43349. }
  43350. }
  43351. }
  43352. }
  43353. }
  43354. } else {
  43355. var firstChar = properties.firstChar;
  43356. widths = dict.get('Widths');
  43357. if (widths) {
  43358. j = firstChar;
  43359. for (i = 0, ii = widths.length; i < ii; i++) {
  43360. glyphsWidths[j++] = widths[i];
  43361. }
  43362. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  43363. } else {
  43364. // Trying get the BaseFont metrics (see comment above).
  43365. var baseFontName = dict.get('BaseFont');
  43366. if (isName(baseFontName)) {
  43367. var metrics = this.getBaseFontMetrics(baseFontName.name);
  43368. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  43369. properties);
  43370. defaultWidth = metrics.defaultWidth;
  43371. }
  43372. }
  43373. }
  43374. // Heuristic: detection of monospace font by checking all non-zero widths
  43375. var isMonospace = true;
  43376. var firstWidth = defaultWidth;
  43377. for (var glyph in glyphsWidths) {
  43378. var glyphWidth = glyphsWidths[glyph];
  43379. if (!glyphWidth) {
  43380. continue;
  43381. }
  43382. if (!firstWidth) {
  43383. firstWidth = glyphWidth;
  43384. continue;
  43385. }
  43386. if (firstWidth !== glyphWidth) {
  43387. isMonospace = false;
  43388. break;
  43389. }
  43390. }
  43391. if (isMonospace) {
  43392. properties.flags |= FontFlags.FixedPitch;
  43393. }
  43394. properties.defaultWidth = defaultWidth;
  43395. properties.widths = glyphsWidths;
  43396. properties.defaultVMetrics = defaultVMetrics;
  43397. properties.vmetrics = glyphsVMetrics;
  43398. },
  43399. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  43400. // Simulating descriptor flags attribute
  43401. var fontNameWoStyle = baseFontName.split('-')[0];
  43402. return (fontNameWoStyle in getSerifFonts()) ||
  43403. (fontNameWoStyle.search(/serif/gi) !== -1);
  43404. },
  43405. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  43406. var defaultWidth = 0;
  43407. var widths = [];
  43408. var monospace = false;
  43409. var stdFontMap = getStdFontMap();
  43410. var lookupName = (stdFontMap[name] || name);
  43411. var Metrics = getMetrics();
  43412. if (!(lookupName in Metrics)) {
  43413. // Use default fonts for looking up font metrics if the passed
  43414. // font is not a base font
  43415. if (this.isSerifFont(name)) {
  43416. lookupName = 'Times-Roman';
  43417. } else {
  43418. lookupName = 'Helvetica';
  43419. }
  43420. }
  43421. var glyphWidths = Metrics[lookupName];
  43422. if (isNum(glyphWidths)) {
  43423. defaultWidth = glyphWidths;
  43424. monospace = true;
  43425. } else {
  43426. widths = glyphWidths(); // expand lazy widths array
  43427. }
  43428. return {
  43429. defaultWidth: defaultWidth,
  43430. monospace: monospace,
  43431. widths: widths
  43432. };
  43433. },
  43434. buildCharCodeToWidth:
  43435. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  43436. properties) {
  43437. var widths = Object.create(null);
  43438. var differences = properties.differences;
  43439. var encoding = properties.defaultEncoding;
  43440. for (var charCode = 0; charCode < 256; charCode++) {
  43441. if (charCode in differences &&
  43442. widthsByGlyphName[differences[charCode]]) {
  43443. widths[charCode] = widthsByGlyphName[differences[charCode]];
  43444. continue;
  43445. }
  43446. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  43447. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  43448. continue;
  43449. }
  43450. }
  43451. return widths;
  43452. },
  43453. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  43454. var baseDict = dict;
  43455. var type = dict.get('Subtype');
  43456. assert(isName(type), 'invalid font Subtype');
  43457. var composite = false;
  43458. var uint8array;
  43459. if (type.name === 'Type0') {
  43460. // If font is a composite
  43461. // - get the descendant font
  43462. // - set the type according to the descendant font
  43463. // - get the FontDescriptor from the descendant font
  43464. var df = dict.get('DescendantFonts');
  43465. if (!df) {
  43466. error('Descendant fonts are not specified');
  43467. }
  43468. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  43469. type = dict.get('Subtype');
  43470. assert(isName(type), 'invalid font Subtype');
  43471. composite = true;
  43472. }
  43473. var descriptor = dict.get('FontDescriptor');
  43474. if (descriptor) {
  43475. var hash = new MurmurHash3_64();
  43476. var encoding = baseDict.getRaw('Encoding');
  43477. if (isName(encoding)) {
  43478. hash.update(encoding.name);
  43479. } else if (isRef(encoding)) {
  43480. hash.update(encoding.num + '_' + encoding.gen);
  43481. } else if (isDict(encoding)) {
  43482. var keys = encoding.getKeys();
  43483. for (var i = 0, ii = keys.length; i < ii; i++) {
  43484. var entry = encoding.getRaw(keys[i]);
  43485. if (isName(entry)) {
  43486. hash.update(entry.name);
  43487. } else if (isRef(entry)) {
  43488. hash.update(entry.num + '_' + entry.gen);
  43489. } else if (isArray(entry)) { // 'Differences' entry.
  43490. // Ideally we should check the contents of the array, but to avoid
  43491. // parsing it here and then again in |extractDataStructures|,
  43492. // we only use the array length for now (fixes bug1157493.pdf).
  43493. hash.update(entry.length.toString());
  43494. }
  43495. }
  43496. }
  43497. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  43498. if (isStream(toUnicode)) {
  43499. var stream = toUnicode.str || toUnicode;
  43500. uint8array = stream.buffer ?
  43501. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  43502. new Uint8Array(stream.bytes.buffer,
  43503. stream.start, stream.end - stream.start);
  43504. hash.update(uint8array);
  43505. } else if (isName(toUnicode)) {
  43506. hash.update(toUnicode.name);
  43507. }
  43508. var widths = dict.get('Widths') || baseDict.get('Widths');
  43509. if (widths) {
  43510. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  43511. hash.update(uint8array);
  43512. }
  43513. }
  43514. return {
  43515. descriptor: descriptor,
  43516. dict: dict,
  43517. baseDict: baseDict,
  43518. composite: composite,
  43519. type: type.name,
  43520. hash: hash ? hash.hexdigest() : ''
  43521. };
  43522. },
  43523. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  43524. xref) {
  43525. var baseDict = preEvaluatedFont.baseDict;
  43526. var dict = preEvaluatedFont.dict;
  43527. var composite = preEvaluatedFont.composite;
  43528. var descriptor = preEvaluatedFont.descriptor;
  43529. var type = preEvaluatedFont.type;
  43530. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  43531. var properties;
  43532. if (!descriptor) {
  43533. if (type === 'Type3') {
  43534. // FontDescriptor is only required for Type3 fonts when the document
  43535. // is a tagged pdf. Create a barbebones one to get by.
  43536. descriptor = new Dict(null);
  43537. descriptor.set('FontName', Name.get(type));
  43538. descriptor.set('FontBBox', dict.get('FontBBox'));
  43539. } else {
  43540. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  43541. // FontDescriptor was not required.
  43542. // This case is here for compatibility.
  43543. var baseFontName = dict.get('BaseFont');
  43544. if (!isName(baseFontName)) {
  43545. error('Base font is not specified');
  43546. }
  43547. // Using base font name as a font name.
  43548. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  43549. var metrics = this.getBaseFontMetrics(baseFontName);
  43550. // Simulating descriptor flags attribute
  43551. var fontNameWoStyle = baseFontName.split('-')[0];
  43552. var flags =
  43553. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  43554. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  43555. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  43556. FontFlags.Nonsymbolic);
  43557. properties = {
  43558. type: type,
  43559. name: baseFontName,
  43560. widths: metrics.widths,
  43561. defaultWidth: metrics.defaultWidth,
  43562. flags: flags,
  43563. firstChar: 0,
  43564. lastChar: maxCharIndex
  43565. };
  43566. this.extractDataStructures(dict, dict, xref, properties);
  43567. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  43568. properties);
  43569. return new Font(baseFontName, null, properties);
  43570. }
  43571. }
  43572. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  43573. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  43574. // to ignore this rule when a variant of a standart font is used.
  43575. // TODO Fill the width array depending on which of the base font this is
  43576. // a variant.
  43577. var firstChar = (dict.get('FirstChar') || 0);
  43578. var lastChar = (dict.get('LastChar') || maxCharIndex);
  43579. var fontName = descriptor.get('FontName');
  43580. var baseFont = dict.get('BaseFont');
  43581. // Some bad PDFs have a string as the font name.
  43582. if (isString(fontName)) {
  43583. fontName = Name.get(fontName);
  43584. }
  43585. if (isString(baseFont)) {
  43586. baseFont = Name.get(baseFont);
  43587. }
  43588. if (type !== 'Type3') {
  43589. var fontNameStr = fontName && fontName.name;
  43590. var baseFontStr = baseFont && baseFont.name;
  43591. if (fontNameStr !== baseFontStr) {
  43592. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  43593. '" but should be the same as the Font\'s BaseFont "' +
  43594. baseFontStr + '"');
  43595. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  43596. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  43597. if (fontNameStr && baseFontStr &&
  43598. baseFontStr.indexOf(fontNameStr) === 0) {
  43599. fontName = baseFont;
  43600. }
  43601. }
  43602. }
  43603. fontName = (fontName || baseFont);
  43604. assert(isName(fontName), 'invalid font name');
  43605. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  43606. if (fontFile) {
  43607. if (fontFile.dict) {
  43608. var subtype = fontFile.dict.get('Subtype');
  43609. if (subtype) {
  43610. subtype = subtype.name;
  43611. }
  43612. var length1 = fontFile.dict.get('Length1');
  43613. var length2 = fontFile.dict.get('Length2');
  43614. }
  43615. }
  43616. properties = {
  43617. type: type,
  43618. name: fontName.name,
  43619. subtype: subtype,
  43620. file: fontFile,
  43621. length1: length1,
  43622. length2: length2,
  43623. loadedName: baseDict.loadedName,
  43624. composite: composite,
  43625. wideChars: composite,
  43626. fixedPitch: false,
  43627. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  43628. firstChar: firstChar || 0,
  43629. lastChar: (lastChar || maxCharIndex),
  43630. bbox: descriptor.get('FontBBox'),
  43631. ascent: descriptor.get('Ascent'),
  43632. descent: descriptor.get('Descent'),
  43633. xHeight: descriptor.get('XHeight'),
  43634. capHeight: descriptor.get('CapHeight'),
  43635. flags: descriptor.get('Flags'),
  43636. italicAngle: descriptor.get('ItalicAngle'),
  43637. coded: false
  43638. };
  43639. if (composite) {
  43640. var cidEncoding = baseDict.get('Encoding');
  43641. if (isName(cidEncoding)) {
  43642. properties.cidEncoding = cidEncoding.name;
  43643. }
  43644. properties.cMap = CMapFactory.create(cidEncoding,
  43645. { url: PDFJS.cMapUrl, packed: PDFJS.cMapPacked }, null);
  43646. properties.vertical = properties.cMap.vertical;
  43647. }
  43648. this.extractDataStructures(dict, baseDict, xref, properties);
  43649. this.extractWidths(dict, xref, descriptor, properties);
  43650. if (type === 'Type3') {
  43651. properties.isType3Font = true;
  43652. }
  43653. return new Font(fontName.name, fontFile, properties);
  43654. }
  43655. };
  43656. return PartialEvaluator;
  43657. })();
  43658. var TranslatedFont = (function TranslatedFontClosure() {
  43659. function TranslatedFont(loadedName, font, dict) {
  43660. this.loadedName = loadedName;
  43661. this.font = font;
  43662. this.dict = dict;
  43663. this.type3Loaded = null;
  43664. this.sent = false;
  43665. }
  43666. TranslatedFont.prototype = {
  43667. send: function (handler) {
  43668. if (this.sent) {
  43669. return;
  43670. }
  43671. var fontData = this.font.exportData();
  43672. handler.send('commonobj', [
  43673. this.loadedName,
  43674. 'Font',
  43675. fontData
  43676. ]);
  43677. this.sent = true;
  43678. },
  43679. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  43680. assert(this.font.isType3Font);
  43681. if (this.type3Loaded) {
  43682. return this.type3Loaded;
  43683. }
  43684. var translatedFont = this.font;
  43685. var loadCharProcsPromise = Promise.resolve();
  43686. var charProcs = this.dict.get('CharProcs');
  43687. var fontResources = this.dict.get('Resources') || resources;
  43688. var charProcKeys = charProcs.getKeys();
  43689. var charProcOperatorList = Object.create(null);
  43690. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  43691. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  43692. var glyphStream = charProcs.get(key);
  43693. var operatorList = new OperatorList();
  43694. return evaluator.getOperatorList(glyphStream, task, fontResources,
  43695. operatorList).then(function () {
  43696. charProcOperatorList[key] = operatorList.getIR();
  43697. // Add the dependencies to the parent operator list so they are
  43698. // resolved before sub operator list is executed synchronously.
  43699. parentOperatorList.addDependencies(operatorList.dependencies);
  43700. }, function (reason) {
  43701. warn('Type3 font resource \"' + key + '\" is not available');
  43702. var operatorList = new OperatorList();
  43703. charProcOperatorList[key] = operatorList.getIR();
  43704. });
  43705. }.bind(this, charProcKeys[i]));
  43706. }
  43707. this.type3Loaded = loadCharProcsPromise.then(function () {
  43708. translatedFont.charProcOperatorList = charProcOperatorList;
  43709. });
  43710. return this.type3Loaded;
  43711. }
  43712. };
  43713. return TranslatedFont;
  43714. })();
  43715. var OperatorList = (function OperatorListClosure() {
  43716. var CHUNK_SIZE = 1000;
  43717. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  43718. function getTransfers(queue) {
  43719. var transfers = [];
  43720. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43721. for (var i = 0, ii = queue.length; i < ii; i++) {
  43722. switch (fnArray[i]) {
  43723. case OPS.paintInlineImageXObject:
  43724. case OPS.paintInlineImageXObjectGroup:
  43725. case OPS.paintImageMaskXObject:
  43726. var arg = argsArray[i][0]; // first param in imgData
  43727. if (!arg.cached) {
  43728. transfers.push(arg.data.buffer);
  43729. }
  43730. break;
  43731. }
  43732. }
  43733. return transfers;
  43734. }
  43735. function OperatorList(intent, messageHandler, pageIndex) {
  43736. this.messageHandler = messageHandler;
  43737. this.fnArray = [];
  43738. this.argsArray = [];
  43739. this.dependencies = Object.create(null);
  43740. this._totalLength = 0;
  43741. this.pageIndex = pageIndex;
  43742. this.intent = intent;
  43743. }
  43744. OperatorList.prototype = {
  43745. get length() {
  43746. return this.argsArray.length;
  43747. },
  43748. /**
  43749. * @returns {number} The total length of the entire operator list,
  43750. * since `this.length === 0` after flushing.
  43751. */
  43752. get totalLength() {
  43753. return (this._totalLength + this.length);
  43754. },
  43755. addOp: function(fn, args) {
  43756. this.fnArray.push(fn);
  43757. this.argsArray.push(args);
  43758. if (this.messageHandler) {
  43759. if (this.fnArray.length >= CHUNK_SIZE) {
  43760. this.flush();
  43761. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  43762. (fn === OPS.restore || fn === OPS.endText)) {
  43763. // heuristic to flush on boundary of restore or endText
  43764. this.flush();
  43765. }
  43766. }
  43767. },
  43768. addDependency: function(dependency) {
  43769. if (dependency in this.dependencies) {
  43770. return;
  43771. }
  43772. this.dependencies[dependency] = true;
  43773. this.addOp(OPS.dependency, [dependency]);
  43774. },
  43775. addDependencies: function(dependencies) {
  43776. for (var key in dependencies) {
  43777. this.addDependency(key);
  43778. }
  43779. },
  43780. addOpList: function(opList) {
  43781. Util.extendObj(this.dependencies, opList.dependencies);
  43782. for (var i = 0, ii = opList.length; i < ii; i++) {
  43783. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  43784. }
  43785. },
  43786. getIR: function() {
  43787. return {
  43788. fnArray: this.fnArray,
  43789. argsArray: this.argsArray,
  43790. length: this.length
  43791. };
  43792. },
  43793. flush: function(lastChunk) {
  43794. if (this.intent !== 'oplist') {
  43795. new QueueOptimizer().optimize(this);
  43796. }
  43797. var transfers = getTransfers(this);
  43798. var length = this.length;
  43799. this._totalLength += length;
  43800. this.messageHandler.send('RenderPageChunk', {
  43801. operatorList: {
  43802. fnArray: this.fnArray,
  43803. argsArray: this.argsArray,
  43804. lastChunk: lastChunk,
  43805. length: length
  43806. },
  43807. pageIndex: this.pageIndex,
  43808. intent: this.intent
  43809. }, transfers);
  43810. this.dependencies = Object.create(null);
  43811. this.fnArray.length = 0;
  43812. this.argsArray.length = 0;
  43813. }
  43814. };
  43815. return OperatorList;
  43816. })();
  43817. var StateManager = (function StateManagerClosure() {
  43818. function StateManager(initialState) {
  43819. this.state = initialState;
  43820. this.stateStack = [];
  43821. }
  43822. StateManager.prototype = {
  43823. save: function () {
  43824. var old = this.state;
  43825. this.stateStack.push(this.state);
  43826. this.state = old.clone();
  43827. },
  43828. restore: function () {
  43829. var prev = this.stateStack.pop();
  43830. if (prev) {
  43831. this.state = prev;
  43832. }
  43833. },
  43834. transform: function (args) {
  43835. this.state.ctm = Util.transform(this.state.ctm, args);
  43836. }
  43837. };
  43838. return StateManager;
  43839. })();
  43840. var TextState = (function TextStateClosure() {
  43841. function TextState() {
  43842. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43843. this.fontSize = 0;
  43844. this.font = null;
  43845. this.fontMatrix = FONT_IDENTITY_MATRIX;
  43846. this.textMatrix = IDENTITY_MATRIX.slice();
  43847. this.textLineMatrix = IDENTITY_MATRIX.slice();
  43848. this.charSpacing = 0;
  43849. this.wordSpacing = 0;
  43850. this.leading = 0;
  43851. this.textHScale = 1;
  43852. this.textRise = 0;
  43853. }
  43854. TextState.prototype = {
  43855. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43856. var m = this.textMatrix;
  43857. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43858. },
  43859. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  43860. var m = this.textLineMatrix;
  43861. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  43862. },
  43863. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  43864. var m = this.textMatrix;
  43865. m[4] = m[0] * x + m[2] * y + m[4];
  43866. m[5] = m[1] * x + m[3] * y + m[5];
  43867. },
  43868. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  43869. var m = this.textLineMatrix;
  43870. m[4] = m[0] * x + m[2] * y + m[4];
  43871. m[5] = m[1] * x + m[3] * y + m[5];
  43872. },
  43873. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  43874. // 9.4.4 Text Space Details
  43875. var tsm = [this.fontSize * this.textHScale, 0,
  43876. 0, this.fontSize,
  43877. 0, this.textRise];
  43878. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  43879. },
  43880. carriageReturn: function TextState_carriageReturn() {
  43881. this.translateTextLineMatrix(0, -this.leading);
  43882. this.textMatrix = this.textLineMatrix.slice();
  43883. },
  43884. clone: function TextState_clone() {
  43885. var clone = Object.create(this);
  43886. clone.textMatrix = this.textMatrix.slice();
  43887. clone.textLineMatrix = this.textLineMatrix.slice();
  43888. clone.fontMatrix = this.fontMatrix.slice();
  43889. return clone;
  43890. }
  43891. };
  43892. return TextState;
  43893. })();
  43894. var EvalState = (function EvalStateClosure() {
  43895. function EvalState() {
  43896. this.ctm = new Float32Array(IDENTITY_MATRIX);
  43897. this.font = null;
  43898. this.textRenderingMode = TextRenderingMode.FILL;
  43899. this.fillColorSpace = ColorSpace.singletons.gray;
  43900. this.strokeColorSpace = ColorSpace.singletons.gray;
  43901. }
  43902. EvalState.prototype = {
  43903. clone: function CanvasExtraState_clone() {
  43904. return Object.create(this);
  43905. },
  43906. };
  43907. return EvalState;
  43908. })();
  43909. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  43910. // Specifies properties for each command
  43911. //
  43912. // If variableArgs === true: [0, `numArgs`] expected
  43913. // If variableArgs === false: exactly `numArgs` expected
  43914. var getOPMap = getLookupTableFactory(function (t) {
  43915. // Graphic state
  43916. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  43917. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  43918. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  43919. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  43920. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  43921. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  43922. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  43923. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  43924. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  43925. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  43926. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  43927. // Path
  43928. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  43929. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  43930. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  43931. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  43932. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  43933. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  43934. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  43935. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  43936. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  43937. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  43938. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  43939. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  43940. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  43941. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  43942. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  43943. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  43944. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  43945. // Clipping
  43946. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  43947. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  43948. // Text
  43949. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  43950. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  43951. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  43952. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  43953. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  43954. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  43955. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  43956. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  43957. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  43958. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  43959. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  43960. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  43961. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  43962. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  43963. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  43964. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  43965. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  43966. variableArgs: false };
  43967. // Type3 fonts
  43968. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  43969. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  43970. variableArgs: false };
  43971. // Color
  43972. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  43973. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  43974. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  43975. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  43976. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  43977. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  43978. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  43979. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  43980. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  43981. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  43982. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  43983. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  43984. // Shading
  43985. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  43986. // Images
  43987. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  43988. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  43989. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  43990. // XObjects
  43991. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  43992. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  43993. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  43994. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  43995. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  43996. variableArgs: false };
  43997. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  43998. // Compatibility
  43999. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  44000. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  44001. // (reserved partial commands for the lexer)
  44002. t['BM'] = null;
  44003. t['BD'] = null;
  44004. t['true'] = null;
  44005. t['fa'] = null;
  44006. t['fal'] = null;
  44007. t['fals'] = null;
  44008. t['false'] = null;
  44009. t['nu'] = null;
  44010. t['nul'] = null;
  44011. t['null'] = null;
  44012. });
  44013. function EvaluatorPreprocessor(stream, xref, stateManager) {
  44014. this.opMap = getOPMap();
  44015. // TODO(mduan): pass array of knownCommands rather than this.opMap
  44016. // dictionary
  44017. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  44018. this.stateManager = stateManager;
  44019. this.nonProcessedArgs = [];
  44020. }
  44021. EvaluatorPreprocessor.prototype = {
  44022. get savedStatesDepth() {
  44023. return this.stateManager.stateStack.length;
  44024. },
  44025. // |operation| is an object with two fields:
  44026. //
  44027. // - |fn| is an out param.
  44028. //
  44029. // - |args| is an inout param. On entry, it should have one of two values.
  44030. //
  44031. // - An empty array. This indicates that the caller is providing the
  44032. // array in which the args will be stored in. The caller should use
  44033. // this value if it can reuse a single array for each call to read().
  44034. //
  44035. // - |null|. This indicates that the caller needs this function to create
  44036. // the array in which any args are stored in. If there are zero args,
  44037. // this function will leave |operation.args| as |null| (thus avoiding
  44038. // allocations that would occur if we used an empty array to represent
  44039. // zero arguments). Otherwise, it will replace |null| with a new array
  44040. // containing the arguments. The caller should use this value if it
  44041. // cannot reuse an array for each call to read().
  44042. //
  44043. // These two modes are present because this function is very hot and so
  44044. // avoiding allocations where possible is worthwhile.
  44045. //
  44046. read: function EvaluatorPreprocessor_read(operation) {
  44047. var args = operation.args;
  44048. while (true) {
  44049. var obj = this.parser.getObj();
  44050. if (isCmd(obj)) {
  44051. var cmd = obj.cmd;
  44052. // Check that the command is valid
  44053. var opSpec = this.opMap[cmd];
  44054. if (!opSpec) {
  44055. warn('Unknown command "' + cmd + '"');
  44056. continue;
  44057. }
  44058. var fn = opSpec.id;
  44059. var numArgs = opSpec.numArgs;
  44060. var argsLength = args !== null ? args.length : 0;
  44061. if (!opSpec.variableArgs) {
  44062. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  44063. if (argsLength !== numArgs) {
  44064. var nonProcessedArgs = this.nonProcessedArgs;
  44065. while (argsLength > numArgs) {
  44066. nonProcessedArgs.push(args.shift());
  44067. argsLength--;
  44068. }
  44069. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  44070. if (!args) {
  44071. args = [];
  44072. }
  44073. args.unshift(nonProcessedArgs.pop());
  44074. argsLength++;
  44075. }
  44076. }
  44077. if (argsLength < numArgs) {
  44078. // If we receive too few args, it's not possible to possible
  44079. // to execute the command, so skip the command
  44080. info('Command ' + fn + ': because expected ' +
  44081. numArgs + ' args, but received ' + argsLength +
  44082. ' args; skipping');
  44083. args = null;
  44084. continue;
  44085. }
  44086. } else if (argsLength > numArgs) {
  44087. info('Command ' + fn + ': expected [0,' + numArgs +
  44088. '] args, but received ' + argsLength + ' args');
  44089. }
  44090. // TODO figure out how to type-check vararg functions
  44091. this.preprocessCommand(fn, args);
  44092. operation.fn = fn;
  44093. operation.args = args;
  44094. return true;
  44095. } else {
  44096. if (isEOF(obj)) {
  44097. return false; // no more commands
  44098. }
  44099. // argument
  44100. if (obj !== null) {
  44101. if (!args) {
  44102. args = [];
  44103. }
  44104. args.push((obj instanceof Dict ? obj.getAll() : obj));
  44105. assert(args.length <= 33, 'Too many arguments');
  44106. }
  44107. }
  44108. }
  44109. },
  44110. preprocessCommand:
  44111. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  44112. switch (fn | 0) {
  44113. case OPS.save:
  44114. this.stateManager.save();
  44115. break;
  44116. case OPS.restore:
  44117. this.stateManager.restore();
  44118. break;
  44119. case OPS.transform:
  44120. this.stateManager.transform(args);
  44121. break;
  44122. }
  44123. }
  44124. };
  44125. return EvaluatorPreprocessor;
  44126. })();
  44127. var QueueOptimizer = (function QueueOptimizerClosure() {
  44128. function addState(parentState, pattern, fn) {
  44129. var state = parentState;
  44130. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  44131. var item = pattern[i];
  44132. state = (state[item] || (state[item] = []));
  44133. }
  44134. state[pattern[pattern.length - 1]] = fn;
  44135. }
  44136. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44137. argsArray) {
  44138. // Handles special case of mainly LaTeX documents which use image masks to
  44139. // draw lines with the current fill style.
  44140. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  44141. // have been found at iFirstSave.
  44142. var iFirstPIMXO = iFirstSave + 2;
  44143. for (var i = 0; i < count; i++) {
  44144. var arg = argsArray[iFirstPIMXO + 4 * i];
  44145. var imageMask = arg.length === 1 && arg[0];
  44146. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  44147. (!imageMask.data.length ||
  44148. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  44149. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  44150. continue;
  44151. }
  44152. break;
  44153. }
  44154. return count - i;
  44155. }
  44156. var InitialState = [];
  44157. // This replaces (save, transform, paintInlineImageXObject, restore)+
  44158. // sequences with one |paintInlineImageXObjectGroup| operation.
  44159. addState(InitialState,
  44160. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  44161. function foundInlineImageGroup(context) {
  44162. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  44163. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  44164. var MAX_WIDTH = 1000;
  44165. var IMAGE_PADDING = 1;
  44166. var fnArray = context.fnArray, argsArray = context.argsArray;
  44167. var curr = context.iCurr;
  44168. var iFirstSave = curr - 3;
  44169. var iFirstTransform = curr - 2;
  44170. var iFirstPIIXO = curr - 1;
  44171. // Look for the quartets.
  44172. var i = iFirstSave + 4;
  44173. var ii = fnArray.length;
  44174. while (i + 3 < ii) {
  44175. if (fnArray[i] !== OPS.save ||
  44176. fnArray[i + 1] !== OPS.transform ||
  44177. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  44178. fnArray[i + 3] !== OPS.restore) {
  44179. break; // ops don't match
  44180. }
  44181. i += 4;
  44182. }
  44183. // At this point, i is the index of the first op past the last valid
  44184. // quartet.
  44185. var count = Math.min((i - iFirstSave) / 4,
  44186. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  44187. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  44188. return i;
  44189. }
  44190. // assuming that heights of those image is too small (~1 pixel)
  44191. // packing as much as possible by lines
  44192. var maxX = 0;
  44193. var map = [], maxLineHeight = 0;
  44194. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  44195. var q;
  44196. for (q = 0; q < count; q++) {
  44197. var transform = argsArray[iFirstTransform + (q << 2)];
  44198. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  44199. if (currentX + img.width > MAX_WIDTH) {
  44200. // starting new line
  44201. maxX = Math.max(maxX, currentX);
  44202. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  44203. currentX = 0;
  44204. maxLineHeight = 0;
  44205. }
  44206. map.push({
  44207. transform: transform,
  44208. x: currentX, y: currentY,
  44209. w: img.width, h: img.height
  44210. });
  44211. currentX += img.width + 2 * IMAGE_PADDING;
  44212. maxLineHeight = Math.max(maxLineHeight, img.height);
  44213. }
  44214. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  44215. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  44216. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  44217. var imgRowSize = imgWidth << 2;
  44218. for (q = 0; q < count; q++) {
  44219. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  44220. // Copy image by lines and extends pixels into padding.
  44221. var rowSize = map[q].w << 2;
  44222. var dataOffset = 0;
  44223. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  44224. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  44225. for (var k = 0, kk = map[q].h; k < kk; k++) {
  44226. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  44227. dataOffset += rowSize;
  44228. offset += imgRowSize;
  44229. }
  44230. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  44231. while (offset >= 0) {
  44232. data[offset - 4] = data[offset];
  44233. data[offset - 3] = data[offset + 1];
  44234. data[offset - 2] = data[offset + 2];
  44235. data[offset - 1] = data[offset + 3];
  44236. data[offset + rowSize] = data[offset + rowSize - 4];
  44237. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  44238. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  44239. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  44240. offset -= imgRowSize;
  44241. }
  44242. }
  44243. // Replace queue items.
  44244. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  44245. argsArray.splice(iFirstSave, count * 4,
  44246. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  44247. data: imgData }, map]);
  44248. return iFirstSave + 1;
  44249. });
  44250. // This replaces (save, transform, paintImageMaskXObject, restore)+
  44251. // sequences with one |paintImageMaskXObjectGroup| or one
  44252. // |paintImageMaskXObjectRepeat| operation.
  44253. addState(InitialState,
  44254. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  44255. function foundImageMaskGroup(context) {
  44256. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  44257. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  44258. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  44259. var fnArray = context.fnArray, argsArray = context.argsArray;
  44260. var curr = context.iCurr;
  44261. var iFirstSave = curr - 3;
  44262. var iFirstTransform = curr - 2;
  44263. var iFirstPIMXO = curr - 1;
  44264. // Look for the quartets.
  44265. var i = iFirstSave + 4;
  44266. var ii = fnArray.length;
  44267. while (i + 3 < ii) {
  44268. if (fnArray[i] !== OPS.save ||
  44269. fnArray[i + 1] !== OPS.transform ||
  44270. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  44271. fnArray[i + 3] !== OPS.restore) {
  44272. break; // ops don't match
  44273. }
  44274. i += 4;
  44275. }
  44276. // At this point, i is the index of the first op past the last valid
  44277. // quartet.
  44278. var count = (i - iFirstSave) / 4;
  44279. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44280. argsArray);
  44281. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  44282. return i;
  44283. }
  44284. var q;
  44285. var isSameImage = false;
  44286. var iTransform, transformArgs;
  44287. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  44288. if (argsArray[iFirstTransform][1] === 0 &&
  44289. argsArray[iFirstTransform][2] === 0) {
  44290. isSameImage = true;
  44291. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44292. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44293. iTransform = iFirstTransform + 4;
  44294. var iPIMXO = iFirstPIMXO + 4;
  44295. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  44296. transformArgs = argsArray[iTransform];
  44297. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  44298. transformArgs[0] !== firstTransformArg0 ||
  44299. transformArgs[1] !== 0 ||
  44300. transformArgs[2] !== 0 ||
  44301. transformArgs[3] !== firstTransformArg3) {
  44302. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  44303. isSameImage = false;
  44304. } else {
  44305. count = q;
  44306. }
  44307. break; // different image or transform
  44308. }
  44309. }
  44310. }
  44311. if (isSameImage) {
  44312. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  44313. var positions = new Float32Array(count * 2);
  44314. iTransform = iFirstTransform;
  44315. for (q = 0; q < count; q++, iTransform += 4) {
  44316. transformArgs = argsArray[iTransform];
  44317. positions[(q << 1)] = transformArgs[4];
  44318. positions[(q << 1) + 1] = transformArgs[5];
  44319. }
  44320. // Replace queue items.
  44321. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  44322. argsArray.splice(iFirstSave, count * 4,
  44323. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  44324. } else {
  44325. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  44326. var images = [];
  44327. for (q = 0; q < count; q++) {
  44328. transformArgs = argsArray[iFirstTransform + (q << 2)];
  44329. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  44330. images.push({ data: maskParams.data, width: maskParams.width,
  44331. height: maskParams.height,
  44332. transform: transformArgs });
  44333. }
  44334. // Replace queue items.
  44335. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  44336. argsArray.splice(iFirstSave, count * 4, [images]);
  44337. }
  44338. return iFirstSave + 1;
  44339. });
  44340. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  44341. // with one paintImageXObjectRepeat operation, if the |transform| and
  44342. // |paintImageXObjectRepeat| ops are appropriate.
  44343. addState(InitialState,
  44344. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  44345. function (context) {
  44346. var MIN_IMAGES_IN_BLOCK = 3;
  44347. var MAX_IMAGES_IN_BLOCK = 1000;
  44348. var fnArray = context.fnArray, argsArray = context.argsArray;
  44349. var curr = context.iCurr;
  44350. var iFirstSave = curr - 3;
  44351. var iFirstTransform = curr - 2;
  44352. var iFirstPIXO = curr - 1;
  44353. var iFirstRestore = curr;
  44354. if (argsArray[iFirstTransform][1] !== 0 ||
  44355. argsArray[iFirstTransform][2] !== 0) {
  44356. return iFirstRestore + 1; // transform has the wrong form
  44357. }
  44358. // Look for the quartets.
  44359. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  44360. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44361. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44362. var i = iFirstSave + 4;
  44363. var ii = fnArray.length;
  44364. while (i + 3 < ii) {
  44365. if (fnArray[i] !== OPS.save ||
  44366. fnArray[i + 1] !== OPS.transform ||
  44367. fnArray[i + 2] !== OPS.paintImageXObject ||
  44368. fnArray[i + 3] !== OPS.restore) {
  44369. break; // ops don't match
  44370. }
  44371. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  44372. argsArray[i + 1][1] !== 0 ||
  44373. argsArray[i + 1][2] !== 0 ||
  44374. argsArray[i + 1][3] !== firstTransformArg3) {
  44375. break; // transforms don't match
  44376. }
  44377. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  44378. break; // images don't match
  44379. }
  44380. i += 4;
  44381. }
  44382. // At this point, i is the index of the first op past the last valid
  44383. // quartet.
  44384. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  44385. if (count < MIN_IMAGES_IN_BLOCK) {
  44386. return i;
  44387. }
  44388. // Extract the (x,y) positions from all of the matching transforms.
  44389. var positions = new Float32Array(count * 2);
  44390. var iTransform = iFirstTransform;
  44391. for (var q = 0; q < count; q++, iTransform += 4) {
  44392. var transformArgs = argsArray[iTransform];
  44393. positions[(q << 1)] = transformArgs[4];
  44394. positions[(q << 1) + 1] = transformArgs[5];
  44395. }
  44396. // Replace queue items.
  44397. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  44398. positions];
  44399. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  44400. argsArray.splice(iFirstSave, count * 4, args);
  44401. return iFirstSave + 1;
  44402. });
  44403. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  44404. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  44405. // sequences, if the font for each one is the same.
  44406. addState(InitialState,
  44407. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  44408. function (context) {
  44409. var MIN_CHARS_IN_BLOCK = 3;
  44410. var MAX_CHARS_IN_BLOCK = 1000;
  44411. var fnArray = context.fnArray, argsArray = context.argsArray;
  44412. var curr = context.iCurr;
  44413. var iFirstBeginText = curr - 4;
  44414. var iFirstSetFont = curr - 3;
  44415. var iFirstSetTextMatrix = curr - 2;
  44416. var iFirstShowText = curr - 1;
  44417. var iFirstEndText = curr;
  44418. // Look for the quintets.
  44419. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  44420. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  44421. var i = iFirstBeginText + 5;
  44422. var ii = fnArray.length;
  44423. while (i + 4 < ii) {
  44424. if (fnArray[i] !== OPS.beginText ||
  44425. fnArray[i + 1] !== OPS.setFont ||
  44426. fnArray[i + 2] !== OPS.setTextMatrix ||
  44427. fnArray[i + 3] !== OPS.showText ||
  44428. fnArray[i + 4] !== OPS.endText) {
  44429. break; // ops don't match
  44430. }
  44431. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  44432. argsArray[i + 1][1] !== firstSetFontArg1) {
  44433. break; // fonts don't match
  44434. }
  44435. i += 5;
  44436. }
  44437. // At this point, i is the index of the first op past the last valid
  44438. // quintet.
  44439. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  44440. if (count < MIN_CHARS_IN_BLOCK) {
  44441. return i;
  44442. }
  44443. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  44444. // showText, endText), include that as well. (E.g. <something> might be
  44445. // |dependency|.)
  44446. var iFirst = iFirstBeginText;
  44447. if (iFirstBeginText >= 4 &&
  44448. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  44449. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  44450. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  44451. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  44452. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  44453. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  44454. count++;
  44455. iFirst -= 5;
  44456. }
  44457. // Remove (endText, beginText, setFont) trios.
  44458. var iEndText = iFirst + 4;
  44459. for (var q = 1; q < count; q++) {
  44460. fnArray.splice(iEndText, 3);
  44461. argsArray.splice(iEndText, 3);
  44462. iEndText += 2;
  44463. }
  44464. return iEndText + 1;
  44465. });
  44466. function QueueOptimizer() {}
  44467. QueueOptimizer.prototype = {
  44468. optimize: function QueueOptimizer_optimize(queue) {
  44469. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44470. var context = {
  44471. iCurr: 0,
  44472. fnArray: fnArray,
  44473. argsArray: argsArray
  44474. };
  44475. var state;
  44476. var i = 0, ii = fnArray.length;
  44477. while (i < ii) {
  44478. state = (state || InitialState)[fnArray[i]];
  44479. if (typeof state === 'function') { // we found some handler
  44480. context.iCurr = i;
  44481. // state() returns the index of the first non-matching op (if we
  44482. // didn't match) or the first op past the modified ops (if we did
  44483. // match and replace).
  44484. i = state(context);
  44485. state = undefined; // reset the state machine
  44486. ii = context.fnArray.length;
  44487. } else {
  44488. i++;
  44489. }
  44490. }
  44491. }
  44492. };
  44493. return QueueOptimizer;
  44494. })();
  44495. exports.OperatorList = OperatorList;
  44496. exports.PartialEvaluator = PartialEvaluator;
  44497. }));
  44498. (function (root, factory) {
  44499. {
  44500. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  44501. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  44502. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  44503. }
  44504. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  44505. coreColorSpace, coreObj, coreEvaluator) {
  44506. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  44507. var AnnotationFlag = sharedUtil.AnnotationFlag;
  44508. var AnnotationType = sharedUtil.AnnotationType;
  44509. var OPS = sharedUtil.OPS;
  44510. var Util = sharedUtil.Util;
  44511. var isArray = sharedUtil.isArray;
  44512. var isInt = sharedUtil.isInt;
  44513. var isValidUrl = sharedUtil.isValidUrl;
  44514. var stringToBytes = sharedUtil.stringToBytes;
  44515. var stringToPDFString = sharedUtil.stringToPDFString;
  44516. var stringToUTF8String = sharedUtil.stringToUTF8String;
  44517. var warn = sharedUtil.warn;
  44518. var Dict = corePrimitives.Dict;
  44519. var isDict = corePrimitives.isDict;
  44520. var isName = corePrimitives.isName;
  44521. var Stream = coreStream.Stream;
  44522. var ColorSpace = coreColorSpace.ColorSpace;
  44523. var ObjectLoader = coreObj.ObjectLoader;
  44524. var OperatorList = coreEvaluator.OperatorList;
  44525. /**
  44526. * @class
  44527. * @alias AnnotationFactory
  44528. */
  44529. function AnnotationFactory() {}
  44530. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  44531. /**
  44532. * @param {XRef} xref
  44533. * @param {Object} ref
  44534. * @returns {Annotation}
  44535. */
  44536. create: function AnnotationFactory_create(xref, ref) {
  44537. var dict = xref.fetchIfRef(ref);
  44538. if (!isDict(dict)) {
  44539. return;
  44540. }
  44541. // Determine the annotation's subtype.
  44542. var subtype = dict.get('Subtype');
  44543. subtype = isName(subtype) ? subtype.name : '';
  44544. // Return the right annotation object based on the subtype and field type.
  44545. var parameters = {
  44546. dict: dict,
  44547. ref: ref
  44548. };
  44549. switch (subtype) {
  44550. case 'Link':
  44551. return new LinkAnnotation(parameters);
  44552. case 'Text':
  44553. return new TextAnnotation(parameters);
  44554. case 'Widget':
  44555. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44556. if (isName(fieldType) && fieldType.name === 'Tx') {
  44557. return new TextWidgetAnnotation(parameters);
  44558. }
  44559. return new WidgetAnnotation(parameters);
  44560. case 'Popup':
  44561. return new PopupAnnotation(parameters);
  44562. case 'Highlight':
  44563. return new HighlightAnnotation(parameters);
  44564. case 'Underline':
  44565. return new UnderlineAnnotation(parameters);
  44566. case 'Squiggly':
  44567. return new SquigglyAnnotation(parameters);
  44568. case 'StrikeOut':
  44569. return new StrikeOutAnnotation(parameters);
  44570. default:
  44571. warn('Unimplemented annotation type "' + subtype + '", ' +
  44572. 'falling back to base annotation');
  44573. return new Annotation(parameters);
  44574. }
  44575. }
  44576. };
  44577. var Annotation = (function AnnotationClosure() {
  44578. // 12.5.5: Algorithm: Appearance streams
  44579. function getTransformMatrix(rect, bbox, matrix) {
  44580. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  44581. var minX = bounds[0];
  44582. var minY = bounds[1];
  44583. var maxX = bounds[2];
  44584. var maxY = bounds[3];
  44585. if (minX === maxX || minY === maxY) {
  44586. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  44587. // just apply the transform for rect
  44588. return [1, 0, 0, 1, rect[0], rect[1]];
  44589. }
  44590. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  44591. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  44592. return [
  44593. xRatio,
  44594. 0,
  44595. 0,
  44596. yRatio,
  44597. rect[0] - minX * xRatio,
  44598. rect[1] - minY * yRatio
  44599. ];
  44600. }
  44601. function getDefaultAppearance(dict) {
  44602. var appearanceState = dict.get('AP');
  44603. if (!isDict(appearanceState)) {
  44604. return;
  44605. }
  44606. var appearance;
  44607. var appearances = appearanceState.get('N');
  44608. if (isDict(appearances)) {
  44609. var as = dict.get('AS');
  44610. if (as && appearances.has(as.name)) {
  44611. appearance = appearances.get(as.name);
  44612. }
  44613. } else {
  44614. appearance = appearances;
  44615. }
  44616. return appearance;
  44617. }
  44618. function Annotation(params) {
  44619. var dict = params.dict;
  44620. this.setFlags(dict.get('F'));
  44621. this.setRectangle(dict.get('Rect'));
  44622. this.setColor(dict.get('C'));
  44623. this.setBorderStyle(dict);
  44624. this.appearance = getDefaultAppearance(dict);
  44625. // Expose public properties using a data object.
  44626. this.data = {};
  44627. this.data.id = params.ref.toString();
  44628. this.data.subtype = dict.get('Subtype').name;
  44629. this.data.annotationFlags = this.flags;
  44630. this.data.rect = this.rectangle;
  44631. this.data.color = this.color;
  44632. this.data.borderStyle = this.borderStyle;
  44633. this.data.hasAppearance = !!this.appearance;
  44634. }
  44635. Annotation.prototype = {
  44636. /**
  44637. * @return {boolean}
  44638. */
  44639. get viewable() {
  44640. if (this.flags) {
  44641. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44642. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  44643. !this.hasFlag(AnnotationFlag.NOVIEW);
  44644. }
  44645. return true;
  44646. },
  44647. /**
  44648. * @return {boolean}
  44649. */
  44650. get printable() {
  44651. if (this.flags) {
  44652. return this.hasFlag(AnnotationFlag.PRINT) &&
  44653. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44654. !this.hasFlag(AnnotationFlag.HIDDEN);
  44655. }
  44656. return false;
  44657. },
  44658. /**
  44659. * Set the flags.
  44660. *
  44661. * @public
  44662. * @memberof Annotation
  44663. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  44664. * characteristics
  44665. * @see {@link shared/util.js}
  44666. */
  44667. setFlags: function Annotation_setFlags(flags) {
  44668. if (isInt(flags)) {
  44669. this.flags = flags;
  44670. } else {
  44671. this.flags = 0;
  44672. }
  44673. },
  44674. /**
  44675. * Check if a provided flag is set.
  44676. *
  44677. * @public
  44678. * @memberof Annotation
  44679. * @param {number} flag - Hexadecimal representation for an annotation
  44680. * characteristic
  44681. * @return {boolean}
  44682. * @see {@link shared/util.js}
  44683. */
  44684. hasFlag: function Annotation_hasFlag(flag) {
  44685. if (this.flags) {
  44686. return (this.flags & flag) > 0;
  44687. }
  44688. return false;
  44689. },
  44690. /**
  44691. * Set the rectangle.
  44692. *
  44693. * @public
  44694. * @memberof Annotation
  44695. * @param {Array} rectangle - The rectangle array with exactly four entries
  44696. */
  44697. setRectangle: function Annotation_setRectangle(rectangle) {
  44698. if (isArray(rectangle) && rectangle.length === 4) {
  44699. this.rectangle = Util.normalizeRect(rectangle);
  44700. } else {
  44701. this.rectangle = [0, 0, 0, 0];
  44702. }
  44703. },
  44704. /**
  44705. * Set the color and take care of color space conversion.
  44706. *
  44707. * @public
  44708. * @memberof Annotation
  44709. * @param {Array} color - The color array containing either 0
  44710. * (transparent), 1 (grayscale), 3 (RGB) or
  44711. * 4 (CMYK) elements
  44712. */
  44713. setColor: function Annotation_setColor(color) {
  44714. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  44715. if (!isArray(color)) {
  44716. this.color = rgbColor;
  44717. return;
  44718. }
  44719. switch (color.length) {
  44720. case 0: // Transparent, which we indicate with a null value
  44721. this.color = null;
  44722. break;
  44723. case 1: // Convert grayscale to RGB
  44724. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  44725. this.color = rgbColor;
  44726. break;
  44727. case 3: // Convert RGB percentages to RGB
  44728. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  44729. this.color = rgbColor;
  44730. break;
  44731. case 4: // Convert CMYK to RGB
  44732. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  44733. this.color = rgbColor;
  44734. break;
  44735. default:
  44736. this.color = rgbColor;
  44737. break;
  44738. }
  44739. },
  44740. /**
  44741. * Set the border style (as AnnotationBorderStyle object).
  44742. *
  44743. * @public
  44744. * @memberof Annotation
  44745. * @param {Dict} borderStyle - The border style dictionary
  44746. */
  44747. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  44748. this.borderStyle = new AnnotationBorderStyle();
  44749. if (!isDict(borderStyle)) {
  44750. return;
  44751. }
  44752. if (borderStyle.has('BS')) {
  44753. var dict = borderStyle.get('BS');
  44754. var dictType;
  44755. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  44756. dictType.name === 'Border')) {
  44757. this.borderStyle.setWidth(dict.get('W'));
  44758. this.borderStyle.setStyle(dict.get('S'));
  44759. this.borderStyle.setDashArray(dict.get('D'));
  44760. }
  44761. } else if (borderStyle.has('Border')) {
  44762. var array = borderStyle.get('Border');
  44763. if (isArray(array) && array.length >= 3) {
  44764. this.borderStyle.setHorizontalCornerRadius(array[0]);
  44765. this.borderStyle.setVerticalCornerRadius(array[1]);
  44766. this.borderStyle.setWidth(array[2]);
  44767. if (array.length === 4) { // Dash array available
  44768. this.borderStyle.setDashArray(array[3]);
  44769. }
  44770. }
  44771. } else {
  44772. // There are no border entries in the dictionary. According to the
  44773. // specification, we should draw a solid border of width 1 in that
  44774. // case, but Adobe Reader did not implement that part of the
  44775. // specification and instead draws no border at all, so we do the same.
  44776. // See also https://github.com/mozilla/pdf.js/issues/6179.
  44777. this.borderStyle.setWidth(0);
  44778. }
  44779. },
  44780. loadResources: function Annotation_loadResources(keys) {
  44781. return new Promise(function (resolve, reject) {
  44782. this.appearance.dict.getAsync('Resources').then(function (resources) {
  44783. if (!resources) {
  44784. resolve();
  44785. return;
  44786. }
  44787. var objectLoader = new ObjectLoader(resources.map,
  44788. keys,
  44789. resources.xref);
  44790. objectLoader.load().then(function() {
  44791. resolve(resources);
  44792. }, reject);
  44793. }, reject);
  44794. }.bind(this));
  44795. },
  44796. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  44797. if (!this.appearance) {
  44798. return Promise.resolve(new OperatorList());
  44799. }
  44800. var data = this.data;
  44801. var appearanceDict = this.appearance.dict;
  44802. var resourcesPromise = this.loadResources([
  44803. 'ExtGState',
  44804. 'ColorSpace',
  44805. 'Pattern',
  44806. 'Shading',
  44807. 'XObject',
  44808. 'Font'
  44809. // ProcSet
  44810. // Properties
  44811. ]);
  44812. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  44813. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  44814. var transform = getTransformMatrix(data.rect, bbox, matrix);
  44815. var self = this;
  44816. return resourcesPromise.then(function(resources) {
  44817. var opList = new OperatorList();
  44818. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  44819. return evaluator.getOperatorList(self.appearance, task,
  44820. resources, opList).
  44821. then(function () {
  44822. opList.addOp(OPS.endAnnotation, []);
  44823. self.appearance.reset();
  44824. return opList;
  44825. });
  44826. });
  44827. }
  44828. };
  44829. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  44830. annotations, opList, partialEvaluator, task, intent) {
  44831. var annotationPromises = [];
  44832. for (var i = 0, n = annotations.length; i < n; ++i) {
  44833. if ((intent === 'display' && annotations[i].viewable) ||
  44834. (intent === 'print' && annotations[i].printable)) {
  44835. annotationPromises.push(
  44836. annotations[i].getOperatorList(partialEvaluator, task));
  44837. }
  44838. }
  44839. return Promise.all(annotationPromises).then(function(operatorLists) {
  44840. opList.addOp(OPS.beginAnnotations, []);
  44841. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  44842. opList.addOpList(operatorLists[i]);
  44843. }
  44844. opList.addOp(OPS.endAnnotations, []);
  44845. });
  44846. };
  44847. return Annotation;
  44848. })();
  44849. /**
  44850. * Contains all data regarding an annotation's border style.
  44851. *
  44852. * @class
  44853. */
  44854. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  44855. /**
  44856. * @constructor
  44857. * @private
  44858. */
  44859. function AnnotationBorderStyle() {
  44860. this.width = 1;
  44861. this.style = AnnotationBorderStyleType.SOLID;
  44862. this.dashArray = [3];
  44863. this.horizontalCornerRadius = 0;
  44864. this.verticalCornerRadius = 0;
  44865. }
  44866. AnnotationBorderStyle.prototype = {
  44867. /**
  44868. * Set the width.
  44869. *
  44870. * @public
  44871. * @memberof AnnotationBorderStyle
  44872. * @param {integer} width - The width
  44873. */
  44874. setWidth: function AnnotationBorderStyle_setWidth(width) {
  44875. if (width === (width | 0)) {
  44876. this.width = width;
  44877. }
  44878. },
  44879. /**
  44880. * Set the style.
  44881. *
  44882. * @public
  44883. * @memberof AnnotationBorderStyle
  44884. * @param {Object} style - The style object
  44885. * @see {@link shared/util.js}
  44886. */
  44887. setStyle: function AnnotationBorderStyle_setStyle(style) {
  44888. if (!style) {
  44889. return;
  44890. }
  44891. switch (style.name) {
  44892. case 'S':
  44893. this.style = AnnotationBorderStyleType.SOLID;
  44894. break;
  44895. case 'D':
  44896. this.style = AnnotationBorderStyleType.DASHED;
  44897. break;
  44898. case 'B':
  44899. this.style = AnnotationBorderStyleType.BEVELED;
  44900. break;
  44901. case 'I':
  44902. this.style = AnnotationBorderStyleType.INSET;
  44903. break;
  44904. case 'U':
  44905. this.style = AnnotationBorderStyleType.UNDERLINE;
  44906. break;
  44907. default:
  44908. break;
  44909. }
  44910. },
  44911. /**
  44912. * Set the dash array.
  44913. *
  44914. * @public
  44915. * @memberof AnnotationBorderStyle
  44916. * @param {Array} dashArray - The dash array with at least one element
  44917. */
  44918. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  44919. // We validate the dash array, but we do not use it because CSS does not
  44920. // allow us to change spacing of dashes. For more information, visit
  44921. // http://www.w3.org/TR/css3-background/#the-border-style.
  44922. if (isArray(dashArray) && dashArray.length > 0) {
  44923. // According to the PDF specification: the elements in a dashArray
  44924. // shall be numbers that are nonnegative and not all equal to zero.
  44925. var isValid = true;
  44926. var allZeros = true;
  44927. for (var i = 0, len = dashArray.length; i < len; i++) {
  44928. var element = dashArray[i];
  44929. var validNumber = (+element >= 0);
  44930. if (!validNumber) {
  44931. isValid = false;
  44932. break;
  44933. } else if (element > 0) {
  44934. allZeros = false;
  44935. }
  44936. }
  44937. if (isValid && !allZeros) {
  44938. this.dashArray = dashArray;
  44939. } else {
  44940. this.width = 0; // Adobe behavior when the array is invalid.
  44941. }
  44942. } else if (dashArray) {
  44943. this.width = 0; // Adobe behavior when the array is invalid.
  44944. }
  44945. },
  44946. /**
  44947. * Set the horizontal corner radius (from a Border dictionary).
  44948. *
  44949. * @public
  44950. * @memberof AnnotationBorderStyle
  44951. * @param {integer} radius - The horizontal corner radius
  44952. */
  44953. setHorizontalCornerRadius:
  44954. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  44955. if (radius === (radius | 0)) {
  44956. this.horizontalCornerRadius = radius;
  44957. }
  44958. },
  44959. /**
  44960. * Set the vertical corner radius (from a Border dictionary).
  44961. *
  44962. * @public
  44963. * @memberof AnnotationBorderStyle
  44964. * @param {integer} radius - The vertical corner radius
  44965. */
  44966. setVerticalCornerRadius:
  44967. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  44968. if (radius === (radius | 0)) {
  44969. this.verticalCornerRadius = radius;
  44970. }
  44971. }
  44972. };
  44973. return AnnotationBorderStyle;
  44974. })();
  44975. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  44976. function WidgetAnnotation(params) {
  44977. Annotation.call(this, params);
  44978. var dict = params.dict;
  44979. var data = this.data;
  44980. data.annotationType = AnnotationType.WIDGET;
  44981. data.fieldValue = stringToPDFString(
  44982. Util.getInheritableProperty(dict, 'V') || '');
  44983. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  44984. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  44985. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44986. data.fieldType = isName(fieldType) ? fieldType.name : '';
  44987. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  44988. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  44989. // Hide unsupported Widget signatures.
  44990. if (data.fieldType === 'Sig') {
  44991. warn('unimplemented annotation type: Widget signature');
  44992. this.setFlags(AnnotationFlag.HIDDEN);
  44993. }
  44994. // Building the full field name by collecting the field and
  44995. // its ancestors 'T' data and joining them using '.'.
  44996. var fieldName = [];
  44997. var namedItem = dict;
  44998. var ref = params.ref;
  44999. while (namedItem) {
  45000. var parent = namedItem.get('Parent');
  45001. var parentRef = namedItem.getRaw('Parent');
  45002. var name = namedItem.get('T');
  45003. if (name) {
  45004. fieldName.unshift(stringToPDFString(name));
  45005. } else if (parent && ref) {
  45006. // The field name is absent, that means more than one field
  45007. // with the same name may exist. Replacing the empty name
  45008. // with the '`' plus index in the parent's 'Kids' array.
  45009. // This is not in the PDF spec but necessary to id the
  45010. // the input controls.
  45011. var kids = parent.get('Kids');
  45012. var j, jj;
  45013. for (j = 0, jj = kids.length; j < jj; j++) {
  45014. var kidRef = kids[j];
  45015. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  45016. break;
  45017. }
  45018. }
  45019. fieldName.unshift('`' + j);
  45020. }
  45021. namedItem = parent;
  45022. ref = parentRef;
  45023. }
  45024. data.fullName = fieldName.join('.');
  45025. }
  45026. Util.inherit(WidgetAnnotation, Annotation, {});
  45027. return WidgetAnnotation;
  45028. })();
  45029. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  45030. function TextWidgetAnnotation(params) {
  45031. WidgetAnnotation.call(this, params);
  45032. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  45033. this.data.hasHtml = !this.data.hasAppearance && !!this.data.fieldValue;
  45034. }
  45035. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  45036. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  45037. task) {
  45038. if (this.appearance) {
  45039. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  45040. }
  45041. var opList = new OperatorList();
  45042. var data = this.data;
  45043. // Even if there is an appearance stream, ignore it. This is the
  45044. // behaviour used by Adobe Reader.
  45045. if (!data.defaultAppearance) {
  45046. return Promise.resolve(opList);
  45047. }
  45048. var stream = new Stream(stringToBytes(data.defaultAppearance));
  45049. return evaluator.getOperatorList(stream, task,
  45050. this.fieldResources, opList).
  45051. then(function () {
  45052. return opList;
  45053. });
  45054. }
  45055. });
  45056. return TextWidgetAnnotation;
  45057. })();
  45058. var TextAnnotation = (function TextAnnotationClosure() {
  45059. var DEFAULT_ICON_SIZE = 22; // px
  45060. function TextAnnotation(parameters) {
  45061. Annotation.call(this, parameters);
  45062. this.data.annotationType = AnnotationType.TEXT;
  45063. this.data.hasHtml = true;
  45064. var dict = parameters.dict;
  45065. if (this.data.hasAppearance) {
  45066. this.data.name = 'NoIcon';
  45067. } else {
  45068. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  45069. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  45070. this.data.name = dict.has('Name') ? dict.get('Name').name : 'Note';
  45071. }
  45072. if (!dict.has('C')) {
  45073. // Fall back to the default background color.
  45074. this.data.color = null;
  45075. }
  45076. this.data.hasPopup = dict.has('Popup');
  45077. if (!this.data.hasPopup) {
  45078. // There is no associated Popup annotation, so the Text annotation
  45079. // must create its own popup.
  45080. this.data.title = stringToPDFString(dict.get('T') || '');
  45081. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  45082. this.data.hasHtml = (this.data.title || this.data.contents);
  45083. }
  45084. }
  45085. Util.inherit(TextAnnotation, Annotation, {});
  45086. return TextAnnotation;
  45087. })();
  45088. var LinkAnnotation = (function LinkAnnotationClosure() {
  45089. function LinkAnnotation(params) {
  45090. Annotation.call(this, params);
  45091. var dict = params.dict;
  45092. var data = this.data;
  45093. data.annotationType = AnnotationType.LINK;
  45094. data.hasHtml = true;
  45095. var action = dict.get('A');
  45096. if (action && isDict(action)) {
  45097. var linkType = action.get('S').name;
  45098. if (linkType === 'URI') {
  45099. var url = action.get('URI');
  45100. if (isName(url)) {
  45101. // Some bad PDFs do not put parentheses around relative URLs.
  45102. url = '/' + url.name;
  45103. } else if (url) {
  45104. url = addDefaultProtocolToUrl(url);
  45105. }
  45106. // TODO: pdf spec mentions urls can be relative to a Base
  45107. // entry in the dictionary.
  45108. if (!isValidUrl(url, false)) {
  45109. url = '';
  45110. }
  45111. // According to ISO 32000-1:2008, section 12.6.4.7,
  45112. // URI should to be encoded in 7-bit ASCII.
  45113. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  45114. try {
  45115. data.url = stringToUTF8String(url);
  45116. } catch (e) {
  45117. // Fall back to a simple copy.
  45118. data.url = url;
  45119. }
  45120. } else if (linkType === 'GoTo') {
  45121. data.dest = action.get('D');
  45122. } else if (linkType === 'GoToR') {
  45123. var urlDict = action.get('F');
  45124. if (isDict(urlDict)) {
  45125. // We assume that the 'url' is a Filspec dictionary
  45126. // and fetch the url without checking any further
  45127. url = urlDict.get('F') || '';
  45128. }
  45129. // TODO: pdf reference says that GoToR
  45130. // can also have 'NewWindow' attribute
  45131. if (!isValidUrl(url, false)) {
  45132. url = '';
  45133. }
  45134. data.url = url;
  45135. data.dest = action.get('D');
  45136. } else if (linkType === 'Named') {
  45137. data.action = action.get('N').name;
  45138. } else {
  45139. warn('unrecognized link type: ' + linkType);
  45140. }
  45141. } else if (dict.has('Dest')) {
  45142. // simple destination link
  45143. var dest = dict.get('Dest');
  45144. data.dest = isName(dest) ? dest.name : dest;
  45145. }
  45146. }
  45147. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  45148. function addDefaultProtocolToUrl(url) {
  45149. if (url && url.indexOf('www.') === 0) {
  45150. return ('http://' + url);
  45151. }
  45152. return url;
  45153. }
  45154. Util.inherit(LinkAnnotation, Annotation, {});
  45155. return LinkAnnotation;
  45156. })();
  45157. var PopupAnnotation = (function PopupAnnotationClosure() {
  45158. function PopupAnnotation(parameters) {
  45159. Annotation.call(this, parameters);
  45160. this.data.annotationType = AnnotationType.POPUP;
  45161. var dict = parameters.dict;
  45162. var parentItem = dict.get('Parent');
  45163. if (!parentItem) {
  45164. warn('Popup annotation has a missing or invalid parent annotation.');
  45165. return;
  45166. }
  45167. this.data.parentId = dict.getRaw('Parent').toString();
  45168. this.data.title = stringToPDFString(parentItem.get('T') || '');
  45169. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  45170. if (!parentItem.has('C')) {
  45171. // Fall back to the default background color.
  45172. this.data.color = null;
  45173. } else {
  45174. this.setColor(parentItem.get('C'));
  45175. this.data.color = this.color;
  45176. }
  45177. this.data.hasHtml = (this.data.title || this.data.contents);
  45178. }
  45179. Util.inherit(PopupAnnotation, Annotation, {});
  45180. return PopupAnnotation;
  45181. })();
  45182. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  45183. function HighlightAnnotation(parameters) {
  45184. Annotation.call(this, parameters);
  45185. this.data.annotationType = AnnotationType.HIGHLIGHT;
  45186. this.data.hasHtml = true;
  45187. // PDF viewers completely ignore any border styles.
  45188. this.data.borderStyle.setWidth(0);
  45189. }
  45190. Util.inherit(HighlightAnnotation, Annotation, {});
  45191. return HighlightAnnotation;
  45192. })();
  45193. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  45194. function UnderlineAnnotation(parameters) {
  45195. Annotation.call(this, parameters);
  45196. this.data.annotationType = AnnotationType.UNDERLINE;
  45197. this.data.hasHtml = true;
  45198. // PDF viewers completely ignore any border styles.
  45199. this.data.borderStyle.setWidth(0);
  45200. }
  45201. Util.inherit(UnderlineAnnotation, Annotation, {});
  45202. return UnderlineAnnotation;
  45203. })();
  45204. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  45205. function SquigglyAnnotation(parameters) {
  45206. Annotation.call(this, parameters);
  45207. this.data.annotationType = AnnotationType.SQUIGGLY;
  45208. this.data.hasHtml = true;
  45209. // PDF viewers completely ignore any border styles.
  45210. this.data.borderStyle.setWidth(0);
  45211. }
  45212. Util.inherit(SquigglyAnnotation, Annotation, {});
  45213. return SquigglyAnnotation;
  45214. })();
  45215. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  45216. function StrikeOutAnnotation(parameters) {
  45217. Annotation.call(this, parameters);
  45218. this.data.annotationType = AnnotationType.STRIKEOUT;
  45219. this.data.hasHtml = true;
  45220. // PDF viewers completely ignore any border styles.
  45221. this.data.borderStyle.setWidth(0);
  45222. }
  45223. Util.inherit(StrikeOutAnnotation, Annotation, {});
  45224. return StrikeOutAnnotation;
  45225. })();
  45226. exports.Annotation = Annotation;
  45227. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  45228. exports.AnnotationFactory = AnnotationFactory;
  45229. }));
  45230. (function (root, factory) {
  45231. {
  45232. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  45233. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  45234. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  45235. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  45236. }
  45237. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  45238. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  45239. var MissingDataException = sharedUtil.MissingDataException;
  45240. var Util = sharedUtil.Util;
  45241. var assert = sharedUtil.assert;
  45242. var error = sharedUtil.error;
  45243. var info = sharedUtil.info;
  45244. var isArray = sharedUtil.isArray;
  45245. var isArrayBuffer = sharedUtil.isArrayBuffer;
  45246. var isString = sharedUtil.isString;
  45247. var shadow = sharedUtil.shadow;
  45248. var stringToBytes = sharedUtil.stringToBytes;
  45249. var stringToPDFString = sharedUtil.stringToPDFString;
  45250. var warn = sharedUtil.warn;
  45251. var Dict = corePrimitives.Dict;
  45252. var isDict = corePrimitives.isDict;
  45253. var isName = corePrimitives.isName;
  45254. var isStream = corePrimitives.isStream;
  45255. var NullStream = coreStream.NullStream;
  45256. var Stream = coreStream.Stream;
  45257. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  45258. var Catalog = coreObj.Catalog;
  45259. var ObjectLoader = coreObj.ObjectLoader;
  45260. var XRef = coreObj.XRef;
  45261. var Lexer = coreParser.Lexer;
  45262. var Linearization = coreParser.Linearization;
  45263. var calculateMD5 = coreCrypto.calculateMD5;
  45264. var OperatorList = coreEvaluator.OperatorList;
  45265. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  45266. var Annotation = coreAnnotation.Annotation;
  45267. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  45268. var Page = (function PageClosure() {
  45269. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  45270. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  45271. this.pdfManager = pdfManager;
  45272. this.pageIndex = pageIndex;
  45273. this.pageDict = pageDict;
  45274. this.xref = xref;
  45275. this.ref = ref;
  45276. this.fontCache = fontCache;
  45277. this.idCounters = {
  45278. obj: 0
  45279. };
  45280. this.resourcesPromise = null;
  45281. }
  45282. Page.prototype = {
  45283. getPageProp: function Page_getPageProp(key) {
  45284. return this.pageDict.get(key);
  45285. },
  45286. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  45287. var dict = this.pageDict, valueArray = null, loopCount = 0;
  45288. var MAX_LOOP_COUNT = 100;
  45289. // Always walk up the entire parent chain, to be able to find
  45290. // e.g. \Resources placed on multiple levels of the tree.
  45291. while (dict) {
  45292. var value = dict.get(key);
  45293. if (value) {
  45294. if (!valueArray) {
  45295. valueArray = [];
  45296. }
  45297. valueArray.push(value);
  45298. }
  45299. if (++loopCount > MAX_LOOP_COUNT) {
  45300. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  45301. break;
  45302. }
  45303. dict = dict.get('Parent');
  45304. }
  45305. if (!valueArray) {
  45306. return Dict.empty;
  45307. }
  45308. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  45309. loopCount > MAX_LOOP_COUNT) {
  45310. return valueArray[0];
  45311. }
  45312. return Dict.merge(this.xref, valueArray);
  45313. },
  45314. get content() {
  45315. return this.getPageProp('Contents');
  45316. },
  45317. get resources() {
  45318. // For robustness: The spec states that a \Resources entry has to be
  45319. // present, but can be empty. Some document omit it still, in this case
  45320. // we return an empty dictionary.
  45321. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  45322. },
  45323. get mediaBox() {
  45324. var obj = this.getInheritedPageProp('MediaBox');
  45325. // Reset invalid media box to letter size.
  45326. if (!isArray(obj) || obj.length !== 4) {
  45327. obj = LETTER_SIZE_MEDIABOX;
  45328. }
  45329. return shadow(this, 'mediaBox', obj);
  45330. },
  45331. get view() {
  45332. var mediaBox = this.mediaBox;
  45333. var cropBox = this.getInheritedPageProp('CropBox');
  45334. if (!isArray(cropBox) || cropBox.length !== 4) {
  45335. return shadow(this, 'view', mediaBox);
  45336. }
  45337. // From the spec, 6th ed., p.963:
  45338. // "The crop, bleed, trim, and art boxes should not ordinarily
  45339. // extend beyond the boundaries of the media box. If they do, they are
  45340. // effectively reduced to their intersection with the media box."
  45341. cropBox = Util.intersect(cropBox, mediaBox);
  45342. if (!cropBox) {
  45343. return shadow(this, 'view', mediaBox);
  45344. }
  45345. return shadow(this, 'view', cropBox);
  45346. },
  45347. get rotate() {
  45348. var rotate = this.getInheritedPageProp('Rotate') || 0;
  45349. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  45350. if (rotate % 90 !== 0) {
  45351. rotate = 0;
  45352. } else if (rotate >= 360) {
  45353. rotate = rotate % 360;
  45354. } else if (rotate < 0) {
  45355. // The spec doesn't cover negatives, assume its counterclockwise
  45356. // rotation. The following is the other implementation of modulo.
  45357. rotate = ((rotate % 360) + 360) % 360;
  45358. }
  45359. return shadow(this, 'rotate', rotate);
  45360. },
  45361. getContentStream: function Page_getContentStream() {
  45362. var content = this.content;
  45363. var stream;
  45364. if (isArray(content)) {
  45365. // fetching items
  45366. var xref = this.xref;
  45367. var i, n = content.length;
  45368. var streams = [];
  45369. for (i = 0; i < n; ++i) {
  45370. streams.push(xref.fetchIfRef(content[i]));
  45371. }
  45372. stream = new StreamsSequenceStream(streams);
  45373. } else if (isStream(content)) {
  45374. stream = content;
  45375. } else {
  45376. // replacing non-existent page content with empty one
  45377. stream = new NullStream();
  45378. }
  45379. return stream;
  45380. },
  45381. loadResources: function Page_loadResources(keys) {
  45382. if (!this.resourcesPromise) {
  45383. // TODO: add async getInheritedPageProp and remove this.
  45384. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  45385. }
  45386. return this.resourcesPromise.then(function resourceSuccess() {
  45387. var objectLoader = new ObjectLoader(this.resources.map,
  45388. keys,
  45389. this.xref);
  45390. return objectLoader.load();
  45391. }.bind(this));
  45392. },
  45393. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  45394. var self = this;
  45395. var pdfManager = this.pdfManager;
  45396. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45397. []);
  45398. var resourcesPromise = this.loadResources([
  45399. 'ExtGState',
  45400. 'ColorSpace',
  45401. 'Pattern',
  45402. 'Shading',
  45403. 'XObject',
  45404. 'Font'
  45405. // ProcSet
  45406. // Properties
  45407. ]);
  45408. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  45409. handler, this.pageIndex,
  45410. 'p' + this.pageIndex + '_',
  45411. this.idCounters,
  45412. this.fontCache);
  45413. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  45414. var pageListPromise = dataPromises.then(function(data) {
  45415. var contentStream = data[0];
  45416. var opList = new OperatorList(intent, handler, self.pageIndex);
  45417. handler.send('StartRenderPage', {
  45418. transparency: partialEvaluator.hasBlendModes(self.resources),
  45419. pageIndex: self.pageIndex,
  45420. intent: intent
  45421. });
  45422. return partialEvaluator.getOperatorList(contentStream, task,
  45423. self.resources, opList).then(function () {
  45424. return opList;
  45425. });
  45426. });
  45427. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  45428. return Promise.all([pageListPromise, annotationsPromise]).then(
  45429. function(datas) {
  45430. var pageOpList = datas[0];
  45431. var annotations = datas[1];
  45432. if (annotations.length === 0) {
  45433. pageOpList.flush(true);
  45434. return pageOpList;
  45435. }
  45436. var annotationsReadyPromise = Annotation.appendToOperatorList(
  45437. annotations, pageOpList, partialEvaluator, task, intent);
  45438. return annotationsReadyPromise.then(function () {
  45439. pageOpList.flush(true);
  45440. return pageOpList;
  45441. });
  45442. });
  45443. },
  45444. extractTextContent: function Page_extractTextContent(task,
  45445. normalizeWhitespace) {
  45446. var handler = {
  45447. on: function nullHandlerOn() {},
  45448. send: function nullHandlerSend() {}
  45449. };
  45450. var self = this;
  45451. var pdfManager = this.pdfManager;
  45452. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45453. []);
  45454. var resourcesPromise = this.loadResources([
  45455. 'ExtGState',
  45456. 'XObject',
  45457. 'Font'
  45458. ]);
  45459. var dataPromises = Promise.all([contentStreamPromise,
  45460. resourcesPromise]);
  45461. return dataPromises.then(function(data) {
  45462. var contentStream = data[0];
  45463. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  45464. handler, self.pageIndex,
  45465. 'p' + self.pageIndex + '_',
  45466. self.idCounters,
  45467. self.fontCache);
  45468. return partialEvaluator.getTextContent(contentStream,
  45469. task,
  45470. self.resources,
  45471. /* stateManager = */ null,
  45472. normalizeWhitespace);
  45473. });
  45474. },
  45475. getAnnotationsData: function Page_getAnnotationsData(intent) {
  45476. var annotations = this.annotations;
  45477. var annotationsData = [];
  45478. for (var i = 0, n = annotations.length; i < n; ++i) {
  45479. if (intent) {
  45480. if (!(intent === 'display' && annotations[i].viewable) &&
  45481. !(intent === 'print' && annotations[i].printable)) {
  45482. continue;
  45483. }
  45484. }
  45485. annotationsData.push(annotations[i].data);
  45486. }
  45487. return annotationsData;
  45488. },
  45489. get annotations() {
  45490. var annotations = [];
  45491. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  45492. var annotationFactory = new AnnotationFactory();
  45493. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  45494. var annotationRef = annotationRefs[i];
  45495. var annotation = annotationFactory.create(this.xref, annotationRef);
  45496. if (annotation) {
  45497. annotations.push(annotation);
  45498. }
  45499. }
  45500. return shadow(this, 'annotations', annotations);
  45501. }
  45502. };
  45503. return Page;
  45504. })();
  45505. /**
  45506. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  45507. * `PDFDoc`, this one doesn't have any job management code.
  45508. * Right now there exists one PDFDocument on the main thread + one object
  45509. * for each worker. If there is no worker support enabled, there are two
  45510. * `PDFDocument` objects on the main thread created.
  45511. */
  45512. var PDFDocument = (function PDFDocumentClosure() {
  45513. var FINGERPRINT_FIRST_BYTES = 1024;
  45514. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  45515. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  45516. function PDFDocument(pdfManager, arg, password) {
  45517. if (isStream(arg)) {
  45518. init.call(this, pdfManager, arg, password);
  45519. } else if (isArrayBuffer(arg)) {
  45520. init.call(this, pdfManager, new Stream(arg), password);
  45521. } else {
  45522. error('PDFDocument: Unknown argument type');
  45523. }
  45524. }
  45525. function init(pdfManager, stream, password) {
  45526. assert(stream.length > 0, 'stream must have data');
  45527. this.pdfManager = pdfManager;
  45528. this.stream = stream;
  45529. var xref = new XRef(this.stream, password, pdfManager);
  45530. this.xref = xref;
  45531. }
  45532. function find(stream, needle, limit, backwards) {
  45533. var pos = stream.pos;
  45534. var end = stream.end;
  45535. var strBuf = [];
  45536. if (pos + limit > end) {
  45537. limit = end - pos;
  45538. }
  45539. for (var n = 0; n < limit; ++n) {
  45540. strBuf.push(String.fromCharCode(stream.getByte()));
  45541. }
  45542. var str = strBuf.join('');
  45543. stream.pos = pos;
  45544. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  45545. if (index === -1) {
  45546. return false; /* not found */
  45547. }
  45548. stream.pos += index;
  45549. return true; /* found */
  45550. }
  45551. var DocumentInfoValidators = {
  45552. get entries() {
  45553. // Lazily build this since all the validation functions below are not
  45554. // defined until after this file loads.
  45555. return shadow(this, 'entries', {
  45556. Title: isString,
  45557. Author: isString,
  45558. Subject: isString,
  45559. Keywords: isString,
  45560. Creator: isString,
  45561. Producer: isString,
  45562. CreationDate: isString,
  45563. ModDate: isString,
  45564. Trapped: isName
  45565. });
  45566. }
  45567. };
  45568. PDFDocument.prototype = {
  45569. parse: function PDFDocument_parse(recoveryMode) {
  45570. this.setup(recoveryMode);
  45571. var version = this.catalog.catDict.get('Version');
  45572. if (isName(version)) {
  45573. this.pdfFormatVersion = version.name;
  45574. }
  45575. try {
  45576. // checking if AcroForm is present
  45577. this.acroForm = this.catalog.catDict.get('AcroForm');
  45578. if (this.acroForm) {
  45579. this.xfa = this.acroForm.get('XFA');
  45580. var fields = this.acroForm.get('Fields');
  45581. if ((!fields || !isArray(fields) || fields.length === 0) &&
  45582. !this.xfa) {
  45583. // no fields and no XFA -- not a form (?)
  45584. this.acroForm = null;
  45585. }
  45586. }
  45587. } catch (ex) {
  45588. info('Something wrong with AcroForm entry');
  45589. this.acroForm = null;
  45590. }
  45591. },
  45592. get linearization() {
  45593. var linearization = null;
  45594. if (this.stream.length) {
  45595. try {
  45596. linearization = Linearization.create(this.stream);
  45597. } catch (err) {
  45598. if (err instanceof MissingDataException) {
  45599. throw err;
  45600. }
  45601. info(err);
  45602. }
  45603. }
  45604. // shadow the prototype getter with a data property
  45605. return shadow(this, 'linearization', linearization);
  45606. },
  45607. get startXRef() {
  45608. var stream = this.stream;
  45609. var startXRef = 0;
  45610. var linearization = this.linearization;
  45611. if (linearization) {
  45612. // Find end of first obj.
  45613. stream.reset();
  45614. if (find(stream, 'endobj', 1024)) {
  45615. startXRef = stream.pos + 6;
  45616. }
  45617. } else {
  45618. // Find startxref by jumping backward from the end of the file.
  45619. var step = 1024;
  45620. var found = false, pos = stream.end;
  45621. while (!found && pos > 0) {
  45622. pos -= step - 'startxref'.length;
  45623. if (pos < 0) {
  45624. pos = 0;
  45625. }
  45626. stream.pos = pos;
  45627. found = find(stream, 'startxref', step, true);
  45628. }
  45629. if (found) {
  45630. stream.skip(9);
  45631. var ch;
  45632. do {
  45633. ch = stream.getByte();
  45634. } while (Lexer.isSpace(ch));
  45635. var str = '';
  45636. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  45637. str += String.fromCharCode(ch);
  45638. ch = stream.getByte();
  45639. }
  45640. startXRef = parseInt(str, 10);
  45641. if (isNaN(startXRef)) {
  45642. startXRef = 0;
  45643. }
  45644. }
  45645. }
  45646. // shadow the prototype getter with a data property
  45647. return shadow(this, 'startXRef', startXRef);
  45648. },
  45649. get mainXRefEntriesOffset() {
  45650. var mainXRefEntriesOffset = 0;
  45651. var linearization = this.linearization;
  45652. if (linearization) {
  45653. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  45654. }
  45655. // shadow the prototype getter with a data property
  45656. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  45657. },
  45658. // Find the header, remove leading garbage and setup the stream
  45659. // starting from the header.
  45660. checkHeader: function PDFDocument_checkHeader() {
  45661. var stream = this.stream;
  45662. stream.reset();
  45663. if (find(stream, '%PDF-', 1024)) {
  45664. // Found the header, trim off any garbage before it.
  45665. stream.moveStart();
  45666. // Reading file format version
  45667. var MAX_VERSION_LENGTH = 12;
  45668. var version = '', ch;
  45669. while ((ch = stream.getByte()) > 0x20) { // SPACE
  45670. if (version.length >= MAX_VERSION_LENGTH) {
  45671. break;
  45672. }
  45673. version += String.fromCharCode(ch);
  45674. }
  45675. if (!this.pdfFormatVersion) {
  45676. // removing "%PDF-"-prefix
  45677. this.pdfFormatVersion = version.substring(5);
  45678. }
  45679. return;
  45680. }
  45681. // May not be a PDF file, continue anyway.
  45682. },
  45683. parseStartXRef: function PDFDocument_parseStartXRef() {
  45684. var startXRef = this.startXRef;
  45685. this.xref.setStartXRef(startXRef);
  45686. },
  45687. setup: function PDFDocument_setup(recoveryMode) {
  45688. this.xref.parse(recoveryMode);
  45689. var self = this;
  45690. var pageFactory = {
  45691. createPage: function (pageIndex, dict, ref, fontCache) {
  45692. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  45693. fontCache);
  45694. }
  45695. };
  45696. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  45697. },
  45698. get numPages() {
  45699. var linearization = this.linearization;
  45700. var num = linearization ? linearization.numPages : this.catalog.numPages;
  45701. // shadow the prototype getter
  45702. return shadow(this, 'numPages', num);
  45703. },
  45704. get documentInfo() {
  45705. var docInfo = {
  45706. PDFFormatVersion: this.pdfFormatVersion,
  45707. IsAcroFormPresent: !!this.acroForm,
  45708. IsXFAPresent: !!this.xfa
  45709. };
  45710. var infoDict;
  45711. try {
  45712. infoDict = this.xref.trailer.get('Info');
  45713. } catch (err) {
  45714. info('The document information dictionary is invalid.');
  45715. }
  45716. if (infoDict) {
  45717. var validEntries = DocumentInfoValidators.entries;
  45718. // Only fill the document info with valid entries from the spec.
  45719. for (var key in validEntries) {
  45720. if (infoDict.has(key)) {
  45721. var value = infoDict.get(key);
  45722. // Make sure the value conforms to the spec.
  45723. if (validEntries[key](value)) {
  45724. docInfo[key] = (typeof value !== 'string' ?
  45725. value : stringToPDFString(value));
  45726. } else {
  45727. info('Bad value in document info for "' + key + '"');
  45728. }
  45729. }
  45730. }
  45731. }
  45732. return shadow(this, 'documentInfo', docInfo);
  45733. },
  45734. get fingerprint() {
  45735. var xref = this.xref, hash, fileID = '';
  45736. var idArray = xref.trailer.get('ID');
  45737. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  45738. idArray[0] !== EMPTY_FINGERPRINT) {
  45739. hash = stringToBytes(idArray[0]);
  45740. } else {
  45741. if (this.stream.ensureRange) {
  45742. this.stream.ensureRange(0,
  45743. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  45744. }
  45745. hash = calculateMD5(this.stream.bytes.subarray(0,
  45746. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  45747. }
  45748. for (var i = 0, n = hash.length; i < n; i++) {
  45749. var hex = hash[i].toString(16);
  45750. fileID += hex.length === 1 ? '0' + hex : hex;
  45751. }
  45752. return shadow(this, 'fingerprint', fileID);
  45753. },
  45754. getPage: function PDFDocument_getPage(pageIndex) {
  45755. return this.catalog.getPage(pageIndex);
  45756. },
  45757. cleanup: function PDFDocument_cleanup() {
  45758. return this.catalog.cleanup();
  45759. }
  45760. };
  45761. return PDFDocument;
  45762. })();
  45763. exports.Page = Page;
  45764. exports.PDFDocument = PDFDocument;
  45765. }));
  45766. (function (root, factory) {
  45767. {
  45768. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  45769. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  45770. root.pdfjsCoreDocument);
  45771. }
  45772. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  45773. coreDocument) {
  45774. var NotImplementedException = sharedUtil.NotImplementedException;
  45775. var MissingDataException = sharedUtil.MissingDataException;
  45776. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45777. var Util = sharedUtil.Util;
  45778. var Stream = coreStream.Stream;
  45779. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  45780. var PDFDocument = coreDocument.PDFDocument;
  45781. var BasePdfManager = (function BasePdfManagerClosure() {
  45782. function BasePdfManager() {
  45783. throw new Error('Cannot initialize BaseManagerManager');
  45784. }
  45785. BasePdfManager.prototype = {
  45786. get docId() {
  45787. return this._docId;
  45788. },
  45789. onLoadedStream: function BasePdfManager_onLoadedStream() {
  45790. throw new NotImplementedException();
  45791. },
  45792. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  45793. return this.ensure(this.pdfDocument, prop, args);
  45794. },
  45795. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  45796. return this.ensure(this.pdfDocument.xref, prop, args);
  45797. },
  45798. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  45799. return this.ensure(this.pdfDocument.catalog, prop, args);
  45800. },
  45801. getPage: function BasePdfManager_getPage(pageIndex) {
  45802. return this.pdfDocument.getPage(pageIndex);
  45803. },
  45804. cleanup: function BasePdfManager_cleanup() {
  45805. return this.pdfDocument.cleanup();
  45806. },
  45807. ensure: function BasePdfManager_ensure(obj, prop, args) {
  45808. return new NotImplementedException();
  45809. },
  45810. requestRange: function BasePdfManager_requestRange(begin, end) {
  45811. return new NotImplementedException();
  45812. },
  45813. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  45814. return new NotImplementedException();
  45815. },
  45816. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  45817. return new NotImplementedException();
  45818. },
  45819. updatePassword: function BasePdfManager_updatePassword(password) {
  45820. this.pdfDocument.xref.password = this.password = password;
  45821. if (this._passwordChangedCapability) {
  45822. this._passwordChangedCapability.resolve();
  45823. }
  45824. },
  45825. passwordChanged: function BasePdfManager_passwordChanged() {
  45826. this._passwordChangedCapability = createPromiseCapability();
  45827. return this._passwordChangedCapability.promise;
  45828. },
  45829. terminate: function BasePdfManager_terminate() {
  45830. return new NotImplementedException();
  45831. }
  45832. };
  45833. return BasePdfManager;
  45834. })();
  45835. var LocalPdfManager = (function LocalPdfManagerClosure() {
  45836. function LocalPdfManager(docId, data, password) {
  45837. this._docId = docId;
  45838. var stream = new Stream(data);
  45839. this.pdfDocument = new PDFDocument(this, stream, password);
  45840. this._loadedStreamCapability = createPromiseCapability();
  45841. this._loadedStreamCapability.resolve(stream);
  45842. }
  45843. Util.inherit(LocalPdfManager, BasePdfManager, {
  45844. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  45845. return new Promise(function (resolve, reject) {
  45846. try {
  45847. var value = obj[prop];
  45848. var result;
  45849. if (typeof value === 'function') {
  45850. result = value.apply(obj, args);
  45851. } else {
  45852. result = value;
  45853. }
  45854. resolve(result);
  45855. } catch (e) {
  45856. reject(e);
  45857. }
  45858. });
  45859. },
  45860. requestRange: function LocalPdfManager_requestRange(begin, end) {
  45861. return Promise.resolve();
  45862. },
  45863. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  45864. return;
  45865. },
  45866. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  45867. return this._loadedStreamCapability.promise;
  45868. },
  45869. terminate: function LocalPdfManager_terminate() {
  45870. return;
  45871. }
  45872. });
  45873. return LocalPdfManager;
  45874. })();
  45875. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  45876. function NetworkPdfManager(docId, args, msgHandler) {
  45877. this._docId = docId;
  45878. this.msgHandler = msgHandler;
  45879. var params = {
  45880. msgHandler: msgHandler,
  45881. httpHeaders: args.httpHeaders,
  45882. withCredentials: args.withCredentials,
  45883. chunkedViewerLoading: args.chunkedViewerLoading,
  45884. disableAutoFetch: args.disableAutoFetch,
  45885. initialData: args.initialData
  45886. };
  45887. this.streamManager = new ChunkedStreamManager(args.length,
  45888. args.rangeChunkSize,
  45889. args.url, params);
  45890. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  45891. args.password);
  45892. }
  45893. Util.inherit(NetworkPdfManager, BasePdfManager, {
  45894. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  45895. var pdfManager = this;
  45896. return new Promise(function (resolve, reject) {
  45897. function ensureHelper() {
  45898. try {
  45899. var result;
  45900. var value = obj[prop];
  45901. if (typeof value === 'function') {
  45902. result = value.apply(obj, args);
  45903. } else {
  45904. result = value;
  45905. }
  45906. resolve(result);
  45907. } catch(e) {
  45908. if (!(e instanceof MissingDataException)) {
  45909. reject(e);
  45910. return;
  45911. }
  45912. pdfManager.streamManager.requestRange(e.begin, e.end).
  45913. then(ensureHelper, reject);
  45914. }
  45915. }
  45916. ensureHelper();
  45917. });
  45918. },
  45919. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  45920. return this.streamManager.requestRange(begin, end);
  45921. },
  45922. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  45923. this.streamManager.requestAllChunks();
  45924. },
  45925. sendProgressiveData:
  45926. function NetworkPdfManager_sendProgressiveData(chunk) {
  45927. this.streamManager.onReceiveData({ chunk: chunk });
  45928. },
  45929. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  45930. return this.streamManager.onLoadedStream();
  45931. },
  45932. terminate: function NetworkPdfManager_terminate() {
  45933. this.streamManager.abort();
  45934. }
  45935. });
  45936. return NetworkPdfManager;
  45937. })();
  45938. exports.LocalPdfManager = LocalPdfManager;
  45939. exports.NetworkPdfManager = NetworkPdfManager;
  45940. }));
  45941. (function (root, factory) {
  45942. {
  45943. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  45944. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager,
  45945. root.pdfjsSharedGlobal);
  45946. }
  45947. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager,
  45948. sharedGlobal) {
  45949. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  45950. var InvalidPDFException = sharedUtil.InvalidPDFException;
  45951. var MessageHandler = sharedUtil.MessageHandler;
  45952. var MissingPDFException = sharedUtil.MissingPDFException;
  45953. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  45954. var PasswordException = sharedUtil.PasswordException;
  45955. var PasswordResponses = sharedUtil.PasswordResponses;
  45956. var UnknownErrorException = sharedUtil.UnknownErrorException;
  45957. var XRefParseException = sharedUtil.XRefParseException;
  45958. var createPromiseCapability = sharedUtil.createPromiseCapability;
  45959. var error = sharedUtil.error;
  45960. var info = sharedUtil.info;
  45961. var isInt = sharedUtil.isInt;
  45962. var warn = sharedUtil.warn;
  45963. var Ref = corePrimitives.Ref;
  45964. var LocalPdfManager = corePdfManager.LocalPdfManager;
  45965. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  45966. var globalScope = sharedGlobal.globalScope;
  45967. var PDFJS = sharedGlobal.PDFJS;
  45968. var WorkerTask = (function WorkerTaskClosure() {
  45969. function WorkerTask(name) {
  45970. this.name = name;
  45971. this.terminated = false;
  45972. this._capability = createPromiseCapability();
  45973. }
  45974. WorkerTask.prototype = {
  45975. get finished() {
  45976. return this._capability.promise;
  45977. },
  45978. finish: function () {
  45979. this._capability.resolve();
  45980. },
  45981. terminate: function () {
  45982. this.terminated = true;
  45983. },
  45984. ensureNotTerminated: function () {
  45985. if (this.terminated) {
  45986. throw new Error('Worker task was terminated');
  45987. }
  45988. }
  45989. };
  45990. return WorkerTask;
  45991. })();
  45992. var WorkerMessageHandler = PDFJS.WorkerMessageHandler = {
  45993. setup: function wphSetup(handler, port) {
  45994. var testMessageProcessed = false;
  45995. handler.on('test', function wphSetupTest(data) {
  45996. if (testMessageProcessed) {
  45997. return; // we already processed 'test' message once
  45998. }
  45999. testMessageProcessed = true;
  46000. // check if Uint8Array can be sent to worker
  46001. if (!(data instanceof Uint8Array)) {
  46002. handler.send('test', 'main', false);
  46003. return;
  46004. }
  46005. // making sure postMessage transfers are working
  46006. var supportTransfers = data[0] === 255;
  46007. handler.postMessageTransfers = supportTransfers;
  46008. // check if the response property is supported by xhr
  46009. var xhr = new XMLHttpRequest();
  46010. var responseExists = 'response' in xhr;
  46011. // check if the property is actually implemented
  46012. try {
  46013. var dummy = xhr.responseType;
  46014. } catch (e) {
  46015. responseExists = false;
  46016. }
  46017. if (!responseExists) {
  46018. handler.send('test', false);
  46019. return;
  46020. }
  46021. handler.send('test', {
  46022. supportTypedArray: true,
  46023. supportTransfers: supportTransfers
  46024. });
  46025. });
  46026. handler.on('GetDocRequest', function wphSetupDoc(data) {
  46027. return WorkerMessageHandler.createDocumentHandler(data, port);
  46028. });
  46029. },
  46030. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  46031. // This context is actually holds references on pdfManager and handler,
  46032. // until the latter is destroyed.
  46033. var pdfManager;
  46034. var terminated = false;
  46035. var cancelXHRs = null;
  46036. var WorkerTasks = [];
  46037. var docId = docParams.docId;
  46038. var workerHandlerName = docParams.docId + '_worker';
  46039. var handler = new MessageHandler(workerHandlerName, docId, port);
  46040. function ensureNotTerminated() {
  46041. if (terminated) {
  46042. throw new Error('Worker was terminated');
  46043. }
  46044. }
  46045. function startWorkerTask(task) {
  46046. WorkerTasks.push(task);
  46047. }
  46048. function finishWorkerTask(task) {
  46049. task.finish();
  46050. var i = WorkerTasks.indexOf(task);
  46051. WorkerTasks.splice(i, 1);
  46052. }
  46053. function loadDocument(recoveryMode) {
  46054. var loadDocumentCapability = createPromiseCapability();
  46055. var parseSuccess = function parseSuccess() {
  46056. var numPagesPromise = pdfManager.ensureDoc('numPages');
  46057. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  46058. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  46059. Promise.all([numPagesPromise, fingerprintPromise,
  46060. encryptedPromise]).then(function onDocReady(results) {
  46061. var doc = {
  46062. numPages: results[0],
  46063. fingerprint: results[1],
  46064. encrypted: !!results[2],
  46065. };
  46066. loadDocumentCapability.resolve(doc);
  46067. },
  46068. parseFailure);
  46069. };
  46070. var parseFailure = function parseFailure(e) {
  46071. loadDocumentCapability.reject(e);
  46072. };
  46073. pdfManager.ensureDoc('checkHeader', []).then(function() {
  46074. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  46075. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  46076. parseSuccess, parseFailure);
  46077. }, parseFailure);
  46078. }, parseFailure);
  46079. return loadDocumentCapability.promise;
  46080. }
  46081. function getPdfManager(data) {
  46082. var pdfManagerCapability = createPromiseCapability();
  46083. var pdfManager;
  46084. var source = data.source;
  46085. var disableRange = data.disableRange;
  46086. if (source.data) {
  46087. try {
  46088. pdfManager = new LocalPdfManager(docId, source.data, source.password);
  46089. pdfManagerCapability.resolve(pdfManager);
  46090. } catch (ex) {
  46091. pdfManagerCapability.reject(ex);
  46092. }
  46093. return pdfManagerCapability.promise;
  46094. } else if (source.chunkedViewerLoading) {
  46095. try {
  46096. pdfManager = new NetworkPdfManager(docId, source, handler);
  46097. pdfManagerCapability.resolve(pdfManager);
  46098. } catch (ex) {
  46099. pdfManagerCapability.reject(ex);
  46100. }
  46101. return pdfManagerCapability.promise;
  46102. }
  46103. var networkManager = new NetworkManager(source.url, {
  46104. httpHeaders: source.httpHeaders,
  46105. withCredentials: source.withCredentials
  46106. });
  46107. var cachedChunks = [];
  46108. var fullRequestXhrId = networkManager.requestFull({
  46109. onHeadersReceived: function onHeadersReceived() {
  46110. if (disableRange) {
  46111. return;
  46112. }
  46113. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  46114. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  46115. return;
  46116. }
  46117. var contentEncoding =
  46118. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  46119. if (contentEncoding !== 'identity') {
  46120. return;
  46121. }
  46122. var length = fullRequestXhr.getResponseHeader('Content-Length');
  46123. length = parseInt(length, 10);
  46124. if (!isInt(length)) {
  46125. return;
  46126. }
  46127. source.length = length;
  46128. if (length <= 2 * source.rangeChunkSize) {
  46129. // The file size is smaller than the size of two chunks, so it does
  46130. // not make any sense to abort the request and retry with a range
  46131. // request.
  46132. return;
  46133. }
  46134. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  46135. // We can continue fetching when progressive loading is enabled,
  46136. // and we don't need the autoFetch feature.
  46137. source.disableAutoFetch = true;
  46138. } else {
  46139. // NOTE: by cancelling the full request, and then issuing range
  46140. // requests, there will be an issue for sites where you can only
  46141. // request the pdf once. However, if this is the case, then the
  46142. // server should not be returning that it can support range
  46143. // requests.
  46144. networkManager.abortRequest(fullRequestXhrId);
  46145. }
  46146. try {
  46147. pdfManager = new NetworkPdfManager(docId, source, handler);
  46148. pdfManagerCapability.resolve(pdfManager);
  46149. } catch (ex) {
  46150. pdfManagerCapability.reject(ex);
  46151. }
  46152. cancelXHRs = null;
  46153. },
  46154. onProgressiveData: source.disableStream ? null :
  46155. function onProgressiveData(chunk) {
  46156. if (!pdfManager) {
  46157. cachedChunks.push(chunk);
  46158. return;
  46159. }
  46160. pdfManager.sendProgressiveData(chunk);
  46161. },
  46162. onDone: function onDone(args) {
  46163. if (pdfManager) {
  46164. return; // already processed
  46165. }
  46166. var pdfFile;
  46167. if (args === null) {
  46168. // TODO add some streaming manager, e.g. for unknown length files.
  46169. // The data was returned in the onProgressiveData, combining...
  46170. var pdfFileLength = 0, pos = 0;
  46171. cachedChunks.forEach(function (chunk) {
  46172. pdfFileLength += chunk.byteLength;
  46173. });
  46174. if (source.length && pdfFileLength !== source.length) {
  46175. warn('reported HTTP length is different from actual');
  46176. }
  46177. var pdfFileArray = new Uint8Array(pdfFileLength);
  46178. cachedChunks.forEach(function (chunk) {
  46179. pdfFileArray.set(new Uint8Array(chunk), pos);
  46180. pos += chunk.byteLength;
  46181. });
  46182. pdfFile = pdfFileArray.buffer;
  46183. } else {
  46184. pdfFile = args.chunk;
  46185. }
  46186. // the data is array, instantiating directly from it
  46187. try {
  46188. pdfManager = new LocalPdfManager(docId, pdfFile, source.password);
  46189. pdfManagerCapability.resolve(pdfManager);
  46190. } catch (ex) {
  46191. pdfManagerCapability.reject(ex);
  46192. }
  46193. cancelXHRs = null;
  46194. },
  46195. onError: function onError(status) {
  46196. var exception;
  46197. if (status === 404 || status === 0 && /^file:/.test(source.url)) {
  46198. exception = new MissingPDFException('Missing PDF "' +
  46199. source.url + '".');
  46200. handler.send('MissingPDF', exception);
  46201. } else {
  46202. exception = new UnexpectedResponseException(
  46203. 'Unexpected server response (' + status +
  46204. ') while retrieving PDF "' + source.url + '".', status);
  46205. handler.send('UnexpectedResponse', exception);
  46206. }
  46207. cancelXHRs = null;
  46208. },
  46209. onProgress: function onProgress(evt) {
  46210. handler.send('DocProgress', {
  46211. loaded: evt.loaded,
  46212. total: evt.lengthComputable ? evt.total : source.length
  46213. });
  46214. }
  46215. });
  46216. cancelXHRs = function () {
  46217. networkManager.abortRequest(fullRequestXhrId);
  46218. };
  46219. return pdfManagerCapability.promise;
  46220. }
  46221. var setupDoc = function(data) {
  46222. var onSuccess = function(doc) {
  46223. ensureNotTerminated();
  46224. handler.send('GetDoc', { pdfInfo: doc });
  46225. };
  46226. var onFailure = function(e) {
  46227. if (e instanceof PasswordException) {
  46228. if (e.code === PasswordResponses.NEED_PASSWORD) {
  46229. handler.send('NeedPassword', e);
  46230. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  46231. handler.send('IncorrectPassword', e);
  46232. }
  46233. } else if (e instanceof InvalidPDFException) {
  46234. handler.send('InvalidPDF', e);
  46235. } else if (e instanceof MissingPDFException) {
  46236. handler.send('MissingPDF', e);
  46237. } else if (e instanceof UnexpectedResponseException) {
  46238. handler.send('UnexpectedResponse', e);
  46239. } else {
  46240. handler.send('UnknownError',
  46241. new UnknownErrorException(e.message, e.toString()));
  46242. }
  46243. };
  46244. ensureNotTerminated();
  46245. PDFJS.maxImageSize = data.maxImageSize === undefined ?
  46246. -1 : data.maxImageSize;
  46247. PDFJS.disableFontFace = data.disableFontFace;
  46248. PDFJS.disableCreateObjectURL = data.disableCreateObjectURL;
  46249. PDFJS.verbosity = data.verbosity;
  46250. PDFJS.cMapUrl = data.cMapUrl === undefined ?
  46251. null : data.cMapUrl;
  46252. PDFJS.cMapPacked = data.cMapPacked === true;
  46253. getPdfManager(data).then(function (newPdfManager) {
  46254. if (terminated) {
  46255. // We were in a process of setting up the manager, but it got
  46256. // terminated in the middle.
  46257. newPdfManager.terminate();
  46258. throw new Error('Worker was terminated');
  46259. }
  46260. pdfManager = newPdfManager;
  46261. handler.send('PDFManagerReady', null);
  46262. pdfManager.onLoadedStream().then(function(stream) {
  46263. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  46264. });
  46265. }).then(function pdfManagerReady() {
  46266. ensureNotTerminated();
  46267. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  46268. ensureNotTerminated();
  46269. // Try again with recoveryMode == true
  46270. if (!(ex instanceof XRefParseException)) {
  46271. if (ex instanceof PasswordException) {
  46272. // after password exception prepare to receive a new password
  46273. // to repeat loading
  46274. pdfManager.passwordChanged().then(pdfManagerReady);
  46275. }
  46276. onFailure(ex);
  46277. return;
  46278. }
  46279. pdfManager.requestLoadedStream();
  46280. pdfManager.onLoadedStream().then(function() {
  46281. ensureNotTerminated();
  46282. loadDocument(true).then(onSuccess, onFailure);
  46283. });
  46284. }, onFailure);
  46285. }, onFailure);
  46286. };
  46287. handler.on('GetPage', function wphSetupGetPage(data) {
  46288. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46289. var rotatePromise = pdfManager.ensure(page, 'rotate');
  46290. var refPromise = pdfManager.ensure(page, 'ref');
  46291. var viewPromise = pdfManager.ensure(page, 'view');
  46292. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  46293. function(results) {
  46294. return {
  46295. rotate: results[0],
  46296. ref: results[1],
  46297. view: results[2]
  46298. };
  46299. });
  46300. });
  46301. });
  46302. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  46303. var ref = new Ref(data.ref.num, data.ref.gen);
  46304. var catalog = pdfManager.pdfDocument.catalog;
  46305. return catalog.getPageIndex(ref);
  46306. });
  46307. handler.on('GetDestinations',
  46308. function wphSetupGetDestinations(data) {
  46309. return pdfManager.ensureCatalog('destinations');
  46310. }
  46311. );
  46312. handler.on('GetDestination',
  46313. function wphSetupGetDestination(data) {
  46314. return pdfManager.ensureCatalog('getDestination', [data.id]);
  46315. }
  46316. );
  46317. handler.on('GetPageLabels',
  46318. function wphSetupGetPageLabels(data) {
  46319. return pdfManager.ensureCatalog('pageLabels');
  46320. }
  46321. );
  46322. handler.on('GetAttachments',
  46323. function wphSetupGetAttachments(data) {
  46324. return pdfManager.ensureCatalog('attachments');
  46325. }
  46326. );
  46327. handler.on('GetJavaScript',
  46328. function wphSetupGetJavaScript(data) {
  46329. return pdfManager.ensureCatalog('javaScript');
  46330. }
  46331. );
  46332. handler.on('GetOutline',
  46333. function wphSetupGetOutline(data) {
  46334. return pdfManager.ensureCatalog('documentOutline');
  46335. }
  46336. );
  46337. handler.on('GetMetadata',
  46338. function wphSetupGetMetadata(data) {
  46339. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  46340. pdfManager.ensureCatalog('metadata')]);
  46341. }
  46342. );
  46343. handler.on('GetData', function wphSetupGetData(data) {
  46344. pdfManager.requestLoadedStream();
  46345. return pdfManager.onLoadedStream().then(function(stream) {
  46346. return stream.bytes;
  46347. });
  46348. });
  46349. handler.on('GetStats',
  46350. function wphSetupGetStats(data) {
  46351. return pdfManager.pdfDocument.xref.stats;
  46352. }
  46353. );
  46354. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  46355. pdfManager.updatePassword(data);
  46356. });
  46357. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  46358. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46359. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  46360. });
  46361. });
  46362. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  46363. var pageIndex = data.pageIndex;
  46364. pdfManager.getPage(pageIndex).then(function(page) {
  46365. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  46366. startWorkerTask(task);
  46367. var pageNum = pageIndex + 1;
  46368. var start = Date.now();
  46369. // Pre compile the pdf page and fetch the fonts/images.
  46370. page.getOperatorList(handler, task, data.intent).then(
  46371. function(operatorList) {
  46372. finishWorkerTask(task);
  46373. info('page=' + pageNum + ' - getOperatorList: time=' +
  46374. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  46375. }, function(e) {
  46376. finishWorkerTask(task);
  46377. if (task.terminated) {
  46378. return; // ignoring errors from the terminated thread
  46379. }
  46380. // For compatibility with older behavior, generating unknown
  46381. // unsupported feature notification on errors.
  46382. handler.send('UnsupportedFeature',
  46383. {featureId: UNSUPPORTED_FEATURES.unknown});
  46384. var minimumStackMessage =
  46385. 'worker.js: while trying to getPage() and getOperatorList()';
  46386. var wrappedException;
  46387. // Turn the error into an obj that can be serialized
  46388. if (typeof e === 'string') {
  46389. wrappedException = {
  46390. message: e,
  46391. stack: minimumStackMessage
  46392. };
  46393. } else if (typeof e === 'object') {
  46394. wrappedException = {
  46395. message: e.message || e.toString(),
  46396. stack: e.stack || minimumStackMessage
  46397. };
  46398. } else {
  46399. wrappedException = {
  46400. message: 'Unknown exception type: ' + (typeof e),
  46401. stack: minimumStackMessage
  46402. };
  46403. }
  46404. handler.send('PageError', {
  46405. pageNum: pageNum,
  46406. error: wrappedException,
  46407. intent: data.intent
  46408. });
  46409. });
  46410. });
  46411. }, this);
  46412. handler.on('GetTextContent', function wphExtractText(data) {
  46413. var pageIndex = data.pageIndex;
  46414. var normalizeWhitespace = data.normalizeWhitespace;
  46415. return pdfManager.getPage(pageIndex).then(function(page) {
  46416. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  46417. startWorkerTask(task);
  46418. var pageNum = pageIndex + 1;
  46419. var start = Date.now();
  46420. return page.extractTextContent(task, normalizeWhitespace).then(
  46421. function(textContent) {
  46422. finishWorkerTask(task);
  46423. info('text indexing: page=' + pageNum + ' - time=' +
  46424. (Date.now() - start) + 'ms');
  46425. return textContent;
  46426. }, function (reason) {
  46427. finishWorkerTask(task);
  46428. if (task.terminated) {
  46429. return; // ignoring errors from the terminated thread
  46430. }
  46431. throw reason;
  46432. });
  46433. });
  46434. });
  46435. handler.on('Cleanup', function wphCleanup(data) {
  46436. return pdfManager.cleanup();
  46437. });
  46438. handler.on('Terminate', function wphTerminate(data) {
  46439. terminated = true;
  46440. if (pdfManager) {
  46441. pdfManager.terminate();
  46442. pdfManager = null;
  46443. }
  46444. if (cancelXHRs) {
  46445. cancelXHRs();
  46446. }
  46447. var waitOn = [];
  46448. WorkerTasks.forEach(function (task) {
  46449. waitOn.push(task.finished);
  46450. task.terminate();
  46451. });
  46452. return Promise.all(waitOn).then(function () {
  46453. // Notice that even if we destroying handler, resolved response promise
  46454. // must be sent back.
  46455. handler.destroy();
  46456. handler = null;
  46457. });
  46458. });
  46459. handler.on('Ready', function wphReady(data) {
  46460. setupDoc(docParams);
  46461. docParams = null; // we don't need docParams anymore -- saving memory.
  46462. });
  46463. return workerHandlerName;
  46464. }
  46465. };
  46466. function initializeWorker() {
  46467. if (!('console' in globalScope)) {
  46468. var consoleTimer = {};
  46469. var workerConsole = {
  46470. log: function log() {
  46471. var args = Array.prototype.slice.call(arguments);
  46472. globalScope.postMessage({
  46473. targetName: 'main',
  46474. action: 'console_log',
  46475. data: args
  46476. });
  46477. },
  46478. error: function error() {
  46479. var args = Array.prototype.slice.call(arguments);
  46480. globalScope.postMessage({
  46481. targetName: 'main',
  46482. action: 'console_error',
  46483. data: args
  46484. });
  46485. throw 'pdf.js execution error';
  46486. },
  46487. time: function time(name) {
  46488. consoleTimer[name] = Date.now();
  46489. },
  46490. timeEnd: function timeEnd(name) {
  46491. var time = consoleTimer[name];
  46492. if (!time) {
  46493. error('Unknown timer name ' + name);
  46494. }
  46495. this.log('Timer:', name, Date.now() - time);
  46496. }
  46497. };
  46498. globalScope.console = workerConsole;
  46499. }
  46500. var handler = new MessageHandler('worker', 'main', self);
  46501. WorkerMessageHandler.setup(handler, self);
  46502. handler.send('ready', null);
  46503. }
  46504. // Worker thread (and not node.js)?
  46505. if (typeof window === 'undefined' &&
  46506. !(typeof module !== 'undefined' && module.require)) {
  46507. initializeWorker();
  46508. }
  46509. exports.WorkerTask = WorkerTask;
  46510. exports.WorkerMessageHandler = WorkerMessageHandler;
  46511. }));
  46512. }).call(pdfjsLibs);
  46513. exports.PDFJS = pdfjsLibs.pdfjsSharedGlobal.PDFJS;
  46514. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  46515. exports.PDFDataRangeTransport =
  46516. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  46517. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  46518. exports.AnnotationLayer =
  46519. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  46520. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  46521. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  46522. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  46523. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  46524. exports.UnexpectedResponseException =
  46525. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  46526. }));