pdf.combined.js 1.6 MB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421374223742337424374253742637427374283742937430374313743237433374343743537436374373743837439374403744137442374433744437445374463744737448374493745037451374523745337454374553745637457374583745937460374613746237463374643746537466374673746837469374703747137472374733747437475374763747737478374793748037481374823748337484374853748637487374883748937490374913749237493374943749537496374973749837499375003750137502375033750437505375063750737508375093751037511375123751337514375153751637517375183751937520375213752237523375243752537526375273752837529375303753137532375333753437535375363753737538375393754037541375423754337544375453754637547375483754937550375513755237553375543755537556375573755837559375603756137562375633756437565375663756737568375693757037571375723757337574375753757637577375783757937580375813758237583375843758537586375873758837589375903759137592375933759437595375963759737598375993760037601376023760337604376053760637607376083760937610376113761237613376143761537616376173761837619376203762137622376233762437625376263762737628376293763037631376323763337634376353763637637376383763937640376413764237643376443764537646376473764837649376503765137652376533765437655376563765737658376593766037661376623766337664376653766637667376683766937670376713767237673376743767537676376773767837679376803768137682376833768437685376863768737688376893769037691376923769337694376953769637697376983769937700377013770237703377043770537706377073770837709377103771137712377133771437715377163771737718377193772037721377223772337724377253772637727377283772937730377313773237733377343773537736377373773837739377403774137742377433774437745377463774737748377493775037751377523775337754377553775637757377583775937760377613776237763377643776537766377673776837769377703777137772377733777437775377763777737778377793778037781377823778337784377853778637787377883778937790377913779237793377943779537796377973779837799378003780137802378033780437805378063780737808378093781037811378123781337814378153781637817378183781937820378213782237823378243782537826378273782837829378303783137832378333783437835378363783737838378393784037841378423784337844378453784637847378483784937850378513785237853378543785537856378573785837859378603786137862378633786437865378663786737868378693787037871378723787337874378753787637877378783787937880378813788237883378843788537886378873788837889378903789137892378933789437895378963789737898378993790037901379023790337904379053790637907379083790937910379113791237913379143791537916379173791837919379203792137922379233792437925379263792737928379293793037931379323793337934379353793637937379383793937940379413794237943379443794537946379473794837949379503795137952379533795437955379563795737958379593796037961379623796337964379653796637967379683796937970379713797237973379743797537976379773797837979379803798137982379833798437985379863798737988379893799037991379923799337994379953799637997379983799938000380013800238003380043800538006380073800838009380103801138012380133801438015380163801738018380193802038021380223802338024380253802638027380283802938030380313803238033380343803538036380373803838039380403804138042380433804438045380463804738048380493805038051380523805338054380553805638057380583805938060380613806238063380643806538066380673806838069380703807138072380733807438075380763807738078380793808038081380823808338084380853808638087380883808938090380913809238093380943809538096380973809838099381003810138102381033810438105381063810738108381093811038111381123811338114381153811638117381183811938120381213812238123381243812538126381273812838129381303813138132381333813438135381363813738138381393814038141381423814338144381453814638147381483814938150381513815238153381543815538156381573815838159381603816138162381633816438165381663816738168381693817038171381723817338174381753817638177381783817938180381813818238183381843818538186381873818838189381903819138192381933819438195381963819738198381993820038201382023820338204382053820638207382083820938210382113821238213382143821538216382173821838219382203822138222382233822438225382263822738228382293823038231382323823338234382353823638237382383823938240382413824238243382443824538246382473824838249382503825138252382533825438255382563825738258382593826038261382623826338264382653826638267382683826938270382713827238273382743827538276382773827838279382803828138282382833828438285382863828738288382893829038291382923829338294382953829638297382983829938300383013830238303383043830538306383073830838309383103831138312383133831438315383163831738318383193832038321383223832338324383253832638327383283832938330383313833238333383343833538336383373833838339383403834138342383433834438345383463834738348383493835038351383523835338354383553835638357383583835938360383613836238363383643836538366383673836838369383703837138372383733837438375383763837738378383793838038381383823838338384383853838638387383883838938390383913839238393383943839538396383973839838399384003840138402384033840438405384063840738408384093841038411384123841338414384153841638417384183841938420384213842238423384243842538426384273842838429384303843138432384333843438435384363843738438384393844038441384423844338444384453844638447384483844938450384513845238453384543845538456384573845838459384603846138462384633846438465384663846738468384693847038471384723847338474384753847638477384783847938480384813848238483384843848538486384873848838489384903849138492384933849438495384963849738498384993850038501385023850338504385053850638507385083850938510385113851238513385143851538516385173851838519385203852138522385233852438525385263852738528385293853038531385323853338534385353853638537385383853938540385413854238543385443854538546385473854838549385503855138552385533855438555385563855738558385593856038561385623856338564385653856638567385683856938570385713857238573385743857538576385773857838579385803858138582385833858438585385863858738588385893859038591385923859338594385953859638597385983859938600386013860238603386043860538606386073860838609386103861138612386133861438615386163861738618386193862038621386223862338624386253862638627386283862938630386313863238633386343863538636386373863838639386403864138642386433864438645386463864738648386493865038651386523865338654386553865638657386583865938660386613866238663386643866538666386673866838669386703867138672386733867438675386763867738678386793868038681386823868338684386853868638687386883868938690386913869238693386943869538696386973869838699387003870138702387033870438705387063870738708387093871038711387123871338714387153871638717387183871938720387213872238723387243872538726387273872838729387303873138732387333873438735387363873738738387393874038741387423874338744387453874638747387483874938750387513875238753387543875538756387573875838759387603876138762387633876438765387663876738768387693877038771387723877338774387753877638777387783877938780387813878238783387843878538786387873878838789387903879138792387933879438795387963879738798387993880038801388023880338804388053880638807388083880938810388113881238813388143881538816388173881838819388203882138822388233882438825388263882738828388293883038831388323883338834388353883638837388383883938840388413884238843388443884538846388473884838849388503885138852388533885438855388563885738858388593886038861388623886338864388653886638867388683886938870388713887238873388743887538876388773887838879388803888138882388833888438885388863888738888388893889038891388923889338894388953889638897388983889938900389013890238903389043890538906389073890838909389103891138912389133891438915389163891738918389193892038921389223892338924389253892638927389283892938930389313893238933389343893538936389373893838939389403894138942389433894438945389463894738948389493895038951389523895338954389553895638957389583895938960389613896238963389643896538966389673896838969389703897138972389733897438975389763897738978389793898038981389823898338984389853898638987389883898938990389913899238993389943899538996389973899838999390003900139002390033900439005390063900739008390093901039011390123901339014390153901639017390183901939020390213902239023390243902539026390273902839029390303903139032390333903439035390363903739038390393904039041390423904339044390453904639047390483904939050390513905239053390543905539056390573905839059390603906139062390633906439065390663906739068390693907039071390723907339074390753907639077390783907939080390813908239083390843908539086390873908839089390903909139092390933909439095390963909739098390993910039101391023910339104391053910639107391083910939110391113911239113391143911539116391173911839119391203912139122391233912439125391263912739128391293913039131391323913339134391353913639137391383913939140391413914239143391443914539146391473914839149391503915139152391533915439155391563915739158391593916039161391623916339164391653916639167391683916939170391713917239173391743917539176391773917839179391803918139182391833918439185391863918739188391893919039191391923919339194391953919639197391983919939200392013920239203392043920539206392073920839209392103921139212392133921439215392163921739218392193922039221392223922339224392253922639227392283922939230392313923239233392343923539236392373923839239392403924139242392433924439245392463924739248392493925039251392523925339254392553925639257392583925939260392613926239263392643926539266392673926839269392703927139272392733927439275392763927739278392793928039281392823928339284392853928639287392883928939290392913929239293392943929539296392973929839299393003930139302393033930439305393063930739308393093931039311393123931339314393153931639317393183931939320393213932239323393243932539326393273932839329393303933139332393333933439335393363933739338393393934039341393423934339344393453934639347393483934939350393513935239353393543935539356393573935839359393603936139362393633936439365393663936739368393693937039371393723937339374393753937639377393783937939380393813938239383393843938539386393873938839389393903939139392393933939439395393963939739398393993940039401394023940339404394053940639407394083940939410394113941239413394143941539416394173941839419394203942139422394233942439425394263942739428394293943039431394323943339434394353943639437394383943939440394413944239443394443944539446394473944839449394503945139452394533945439455394563945739458394593946039461394623946339464394653946639467394683946939470394713947239473394743947539476394773947839479394803948139482394833948439485394863948739488394893949039491394923949339494394953949639497394983949939500395013950239503395043950539506395073950839509395103951139512395133951439515395163951739518395193952039521395223952339524395253952639527395283952939530395313953239533395343953539536395373953839539395403954139542395433954439545395463954739548395493955039551395523955339554395553955639557395583955939560395613956239563395643956539566395673956839569395703957139572395733957439575395763957739578395793958039581395823958339584395853958639587395883958939590395913959239593395943959539596395973959839599396003960139602396033960439605396063960739608396093961039611396123961339614396153961639617396183961939620396213962239623396243962539626396273962839629396303963139632396333963439635396363963739638396393964039641396423964339644396453964639647396483964939650396513965239653396543965539656396573965839659396603966139662396633966439665396663966739668396693967039671396723967339674396753967639677396783967939680396813968239683396843968539686396873968839689396903969139692396933969439695396963969739698396993970039701397023970339704397053970639707397083970939710397113971239713397143971539716397173971839719397203972139722397233972439725397263972739728397293973039731397323973339734397353973639737397383973939740397413974239743397443974539746397473974839749397503975139752397533975439755397563975739758397593976039761397623976339764397653976639767397683976939770397713977239773397743977539776397773977839779397803978139782397833978439785397863978739788397893979039791397923979339794397953979639797397983979939800398013980239803398043980539806398073980839809398103981139812398133981439815398163981739818398193982039821398223982339824398253982639827398283982939830398313983239833398343983539836398373983839839398403984139842398433984439845398463984739848398493985039851398523985339854398553985639857398583985939860398613986239863398643986539866398673986839869398703987139872398733987439875398763987739878398793988039881398823988339884398853988639887398883988939890398913989239893398943989539896398973989839899399003990139902399033990439905399063990739908399093991039911399123991339914399153991639917399183991939920399213992239923399243992539926399273992839929399303993139932399333993439935399363993739938399393994039941399423994339944399453994639947399483994939950399513995239953399543995539956399573995839959399603996139962399633996439965399663996739968399693997039971399723997339974399753997639977399783997939980399813998239983399843998539986399873998839989399903999139992399933999439995399963999739998399994000040001400024000340004400054000640007400084000940010400114001240013400144001540016400174001840019400204002140022400234002440025400264002740028400294003040031400324003340034400354003640037400384003940040400414004240043400444004540046400474004840049400504005140052400534005440055400564005740058400594006040061400624006340064400654006640067400684006940070400714007240073400744007540076400774007840079400804008140082400834008440085400864008740088400894009040091400924009340094400954009640097400984009940100401014010240103401044010540106401074010840109401104011140112401134011440115401164011740118401194012040121401224012340124401254012640127401284012940130401314013240133401344013540136401374013840139401404014140142401434014440145401464014740148401494015040151401524015340154401554015640157401584015940160401614016240163401644016540166401674016840169401704017140172401734017440175401764017740178401794018040181401824018340184401854018640187401884018940190401914019240193401944019540196401974019840199402004020140202402034020440205402064020740208402094021040211402124021340214402154021640217402184021940220402214022240223402244022540226402274022840229402304023140232402334023440235402364023740238402394024040241402424024340244402454024640247402484024940250402514025240253402544025540256402574025840259402604026140262402634026440265402664026740268402694027040271402724027340274402754027640277402784027940280402814028240283402844028540286402874028840289402904029140292402934029440295402964029740298402994030040301403024030340304403054030640307403084030940310403114031240313403144031540316403174031840319403204032140322403234032440325403264032740328403294033040331403324033340334403354033640337403384033940340403414034240343403444034540346403474034840349403504035140352403534035440355403564035740358403594036040361403624036340364403654036640367403684036940370403714037240373403744037540376403774037840379403804038140382403834038440385403864038740388403894039040391403924039340394403954039640397403984039940400404014040240403404044040540406404074040840409404104041140412404134041440415404164041740418404194042040421404224042340424404254042640427404284042940430404314043240433404344043540436404374043840439404404044140442404434044440445404464044740448404494045040451404524045340454404554045640457404584045940460404614046240463404644046540466404674046840469404704047140472404734047440475404764047740478404794048040481404824048340484404854048640487404884048940490404914049240493404944049540496404974049840499405004050140502405034050440505405064050740508405094051040511405124051340514405154051640517405184051940520405214052240523405244052540526405274052840529405304053140532405334053440535405364053740538405394054040541405424054340544405454054640547405484054940550405514055240553405544055540556405574055840559405604056140562405634056440565405664056740568405694057040571405724057340574405754057640577405784057940580405814058240583405844058540586405874058840589405904059140592405934059440595405964059740598405994060040601406024060340604406054060640607406084060940610406114061240613406144061540616406174061840619406204062140622406234062440625406264062740628406294063040631406324063340634406354063640637406384063940640406414064240643406444064540646406474064840649406504065140652406534065440655406564065740658406594066040661406624066340664406654066640667406684066940670406714067240673406744067540676406774067840679406804068140682406834068440685406864068740688406894069040691406924069340694406954069640697406984069940700407014070240703407044070540706407074070840709407104071140712407134071440715407164071740718407194072040721407224072340724407254072640727407284072940730407314073240733407344073540736407374073840739407404074140742407434074440745407464074740748407494075040751407524075340754407554075640757407584075940760407614076240763407644076540766407674076840769407704077140772407734077440775407764077740778407794078040781407824078340784407854078640787407884078940790407914079240793407944079540796407974079840799408004080140802408034080440805408064080740808408094081040811408124081340814408154081640817408184081940820408214082240823408244082540826408274082840829408304083140832408334083440835408364083740838408394084040841408424084340844408454084640847408484084940850408514085240853408544085540856408574085840859408604086140862408634086440865408664086740868408694087040871408724087340874408754087640877408784087940880408814088240883408844088540886408874088840889408904089140892408934089440895408964089740898408994090040901409024090340904409054090640907409084090940910409114091240913409144091540916409174091840919409204092140922409234092440925409264092740928409294093040931409324093340934409354093640937409384093940940409414094240943409444094540946409474094840949409504095140952409534095440955409564095740958409594096040961409624096340964409654096640967409684096940970409714097240973409744097540976409774097840979409804098140982409834098440985409864098740988409894099040991409924099340994409954099640997409984099941000410014100241003410044100541006410074100841009410104101141012410134101441015410164101741018410194102041021410224102341024410254102641027410284102941030410314103241033410344103541036410374103841039410404104141042410434104441045410464104741048410494105041051410524105341054410554105641057410584105941060410614106241063410644106541066410674106841069410704107141072410734107441075410764107741078410794108041081410824108341084410854108641087410884108941090410914109241093410944109541096410974109841099411004110141102411034110441105411064110741108411094111041111411124111341114411154111641117411184111941120411214112241123411244112541126411274112841129411304113141132411334113441135411364113741138411394114041141411424114341144411454114641147411484114941150411514115241153411544115541156411574115841159411604116141162411634116441165411664116741168411694117041171411724117341174411754117641177411784117941180411814118241183411844118541186411874118841189411904119141192411934119441195411964119741198411994120041201412024120341204412054120641207412084120941210412114121241213412144121541216412174121841219412204122141222412234122441225412264122741228412294123041231412324123341234412354123641237412384123941240412414124241243412444124541246412474124841249412504125141252412534125441255412564125741258412594126041261412624126341264412654126641267412684126941270412714127241273412744127541276412774127841279412804128141282412834128441285412864128741288412894129041291412924129341294412954129641297412984129941300413014130241303413044130541306413074130841309413104131141312413134131441315413164131741318413194132041321413224132341324413254132641327413284132941330413314133241333413344133541336413374133841339413404134141342413434134441345413464134741348413494135041351413524135341354413554135641357413584135941360413614136241363413644136541366413674136841369413704137141372413734137441375413764137741378413794138041381413824138341384413854138641387413884138941390413914139241393413944139541396413974139841399414004140141402414034140441405414064140741408414094141041411414124141341414414154141641417414184141941420414214142241423414244142541426414274142841429414304143141432414334143441435414364143741438414394144041441414424144341444414454144641447414484144941450414514145241453414544145541456414574145841459414604146141462414634146441465414664146741468414694147041471414724147341474414754147641477414784147941480414814148241483414844148541486414874148841489414904149141492414934149441495414964149741498414994150041501415024150341504415054150641507415084150941510415114151241513415144151541516415174151841519415204152141522415234152441525415264152741528415294153041531415324153341534415354153641537415384153941540415414154241543415444154541546415474154841549415504155141552415534155441555415564155741558415594156041561415624156341564415654156641567415684156941570415714157241573415744157541576415774157841579415804158141582415834158441585415864158741588415894159041591415924159341594415954159641597415984159941600416014160241603416044160541606416074160841609416104161141612416134161441615416164161741618416194162041621416224162341624416254162641627416284162941630416314163241633416344163541636416374163841639416404164141642416434164441645416464164741648416494165041651416524165341654416554165641657416584165941660416614166241663416644166541666416674166841669416704167141672416734167441675416764167741678416794168041681416824168341684416854168641687416884168941690416914169241693416944169541696416974169841699417004170141702417034170441705417064170741708417094171041711417124171341714417154171641717417184171941720417214172241723417244172541726417274172841729417304173141732417334173441735417364173741738417394174041741417424174341744417454174641747417484174941750417514175241753417544175541756417574175841759417604176141762417634176441765417664176741768417694177041771417724177341774417754177641777417784177941780417814178241783417844178541786417874178841789417904179141792417934179441795417964179741798417994180041801418024180341804418054180641807418084180941810418114181241813418144181541816418174181841819418204182141822418234182441825418264182741828418294183041831418324183341834418354183641837418384183941840418414184241843418444184541846418474184841849418504185141852418534185441855418564185741858418594186041861418624186341864418654186641867418684186941870418714187241873418744187541876418774187841879418804188141882418834188441885418864188741888418894189041891418924189341894418954189641897418984189941900419014190241903419044190541906419074190841909419104191141912419134191441915419164191741918419194192041921419224192341924419254192641927419284192941930419314193241933419344193541936419374193841939419404194141942419434194441945419464194741948419494195041951419524195341954419554195641957419584195941960419614196241963419644196541966419674196841969419704197141972419734197441975419764197741978419794198041981419824198341984419854198641987419884198941990419914199241993419944199541996419974199841999420004200142002420034200442005420064200742008420094201042011420124201342014420154201642017420184201942020420214202242023420244202542026420274202842029420304203142032420334203442035420364203742038420394204042041420424204342044420454204642047420484204942050420514205242053420544205542056420574205842059420604206142062420634206442065420664206742068420694207042071420724207342074420754207642077420784207942080420814208242083420844208542086420874208842089420904209142092420934209442095420964209742098420994210042101421024210342104421054210642107421084210942110421114211242113421144211542116421174211842119421204212142122421234212442125421264212742128421294213042131421324213342134421354213642137421384213942140421414214242143421444214542146421474214842149421504215142152421534215442155421564215742158421594216042161421624216342164421654216642167421684216942170421714217242173421744217542176421774217842179421804218142182421834218442185421864218742188421894219042191421924219342194421954219642197421984219942200422014220242203422044220542206422074220842209422104221142212422134221442215422164221742218422194222042221422224222342224422254222642227422284222942230422314223242233422344223542236422374223842239422404224142242422434224442245422464224742248422494225042251422524225342254422554225642257422584225942260422614226242263422644226542266422674226842269422704227142272422734227442275422764227742278422794228042281422824228342284422854228642287422884228942290422914229242293422944229542296422974229842299423004230142302423034230442305423064230742308423094231042311423124231342314423154231642317423184231942320423214232242323423244232542326423274232842329423304233142332423334233442335423364233742338423394234042341423424234342344423454234642347423484234942350423514235242353423544235542356423574235842359423604236142362423634236442365423664236742368423694237042371423724237342374423754237642377423784237942380423814238242383423844238542386423874238842389423904239142392423934239442395423964239742398423994240042401424024240342404424054240642407424084240942410424114241242413424144241542416424174241842419424204242142422424234242442425424264242742428424294243042431424324243342434424354243642437424384243942440424414244242443424444244542446424474244842449424504245142452424534245442455424564245742458424594246042461424624246342464424654246642467424684246942470424714247242473424744247542476424774247842479424804248142482424834248442485424864248742488424894249042491424924249342494424954249642497424984249942500425014250242503425044250542506425074250842509425104251142512425134251442515425164251742518425194252042521425224252342524425254252642527425284252942530425314253242533425344253542536425374253842539425404254142542425434254442545425464254742548425494255042551425524255342554425554255642557425584255942560425614256242563425644256542566425674256842569425704257142572425734257442575425764257742578425794258042581425824258342584425854258642587425884258942590425914259242593425944259542596425974259842599426004260142602426034260442605426064260742608426094261042611426124261342614426154261642617426184261942620426214262242623426244262542626426274262842629426304263142632426334263442635426364263742638426394264042641426424264342644426454264642647426484264942650426514265242653426544265542656426574265842659426604266142662426634266442665426664266742668426694267042671426724267342674426754267642677426784267942680426814268242683426844268542686426874268842689426904269142692426934269442695426964269742698426994270042701427024270342704427054270642707427084270942710427114271242713427144271542716427174271842719427204272142722427234272442725427264272742728427294273042731427324273342734427354273642737427384273942740427414274242743427444274542746427474274842749427504275142752427534275442755427564275742758427594276042761427624276342764427654276642767427684276942770427714277242773427744277542776427774277842779427804278142782427834278442785427864278742788427894279042791427924279342794427954279642797427984279942800428014280242803428044280542806428074280842809428104281142812428134281442815428164281742818428194282042821428224282342824428254282642827428284282942830428314283242833428344283542836428374283842839428404284142842428434284442845428464284742848428494285042851428524285342854428554285642857428584285942860428614286242863428644286542866428674286842869428704287142872428734287442875428764287742878428794288042881428824288342884428854288642887428884288942890428914289242893428944289542896428974289842899429004290142902429034290442905429064290742908429094291042911429124291342914429154291642917429184291942920429214292242923429244292542926429274292842929429304293142932429334293442935429364293742938429394294042941429424294342944429454294642947429484294942950429514295242953429544295542956429574295842959429604296142962429634296442965429664296742968429694297042971429724297342974429754297642977429784297942980429814298242983429844298542986429874298842989429904299142992429934299442995429964299742998429994300043001430024300343004430054300643007430084300943010430114301243013430144301543016430174301843019430204302143022430234302443025430264302743028430294303043031430324303343034430354303643037430384303943040430414304243043430444304543046430474304843049430504305143052430534305443055430564305743058430594306043061430624306343064430654306643067430684306943070430714307243073430744307543076430774307843079430804308143082430834308443085430864308743088430894309043091430924309343094430954309643097430984309943100431014310243103431044310543106431074310843109431104311143112431134311443115431164311743118431194312043121431224312343124431254312643127431284312943130431314313243133431344313543136431374313843139431404314143142431434314443145431464314743148431494315043151431524315343154431554315643157431584315943160431614316243163431644316543166431674316843169431704317143172431734317443175431764317743178431794318043181431824318343184431854318643187431884318943190431914319243193431944319543196431974319843199432004320143202432034320443205432064320743208432094321043211432124321343214432154321643217432184321943220432214322243223432244322543226432274322843229432304323143232432334323443235432364323743238432394324043241432424324343244432454324643247432484324943250432514325243253432544325543256432574325843259432604326143262432634326443265432664326743268432694327043271432724327343274432754327643277432784327943280432814328243283432844328543286432874328843289432904329143292432934329443295432964329743298432994330043301433024330343304433054330643307433084330943310433114331243313433144331543316433174331843319433204332143322433234332443325433264332743328433294333043331433324333343334433354333643337433384333943340433414334243343433444334543346433474334843349433504335143352433534335443355433564335743358433594336043361433624336343364433654336643367433684336943370433714337243373433744337543376433774337843379433804338143382433834338443385433864338743388433894339043391433924339343394433954339643397433984339943400434014340243403434044340543406434074340843409434104341143412434134341443415434164341743418434194342043421434224342343424434254342643427434284342943430434314343243433434344343543436434374343843439434404344143442434434344443445434464344743448434494345043451434524345343454434554345643457434584345943460434614346243463434644346543466434674346843469434704347143472434734347443475434764347743478434794348043481434824348343484434854348643487434884348943490434914349243493434944349543496434974349843499435004350143502435034350443505435064350743508435094351043511435124351343514435154351643517435184351943520435214352243523435244352543526435274352843529435304353143532435334353443535435364353743538435394354043541435424354343544435454354643547435484354943550435514355243553435544355543556435574355843559435604356143562435634356443565435664356743568435694357043571435724357343574435754357643577435784357943580435814358243583435844358543586435874358843589435904359143592435934359443595435964359743598435994360043601436024360343604436054360643607436084360943610436114361243613436144361543616436174361843619436204362143622436234362443625436264362743628436294363043631436324363343634436354363643637436384363943640436414364243643436444364543646436474364843649436504365143652436534365443655436564365743658436594366043661436624366343664436654366643667436684366943670436714367243673436744367543676436774367843679436804368143682436834368443685436864368743688436894369043691436924369343694436954369643697436984369943700437014370243703437044370543706437074370843709437104371143712437134371443715437164371743718437194372043721437224372343724437254372643727437284372943730437314373243733437344373543736437374373843739437404374143742437434374443745437464374743748437494375043751437524375343754437554375643757437584375943760437614376243763437644376543766437674376843769437704377143772437734377443775437764377743778437794378043781437824378343784437854378643787437884378943790437914379243793437944379543796437974379843799438004380143802438034380443805438064380743808438094381043811438124381343814438154381643817438184381943820438214382243823438244382543826438274382843829438304383143832438334383443835438364383743838438394384043841438424384343844438454384643847438484384943850438514385243853438544385543856438574385843859438604386143862438634386443865438664386743868438694387043871438724387343874438754387643877438784387943880438814388243883438844388543886438874388843889438904389143892438934389443895438964389743898438994390043901439024390343904439054390643907439084390943910439114391243913439144391543916439174391843919439204392143922439234392443925439264392743928439294393043931439324393343934439354393643937439384393943940439414394243943439444394543946439474394843949439504395143952439534395443955439564395743958439594396043961439624396343964439654396643967439684396943970439714397243973439744397543976439774397843979439804398143982439834398443985439864398743988439894399043991439924399343994439954399643997439984399944000440014400244003440044400544006440074400844009440104401144012440134401444015440164401744018440194402044021440224402344024440254402644027440284402944030440314403244033440344403544036440374403844039440404404144042440434404444045440464404744048440494405044051440524405344054440554405644057440584405944060440614406244063440644406544066440674406844069440704407144072440734407444075440764407744078440794408044081440824408344084440854408644087440884408944090440914409244093440944409544096440974409844099441004410144102441034410444105441064410744108441094411044111441124411344114441154411644117441184411944120441214412244123441244412544126441274412844129441304413144132441334413444135441364413744138441394414044141441424414344144441454414644147441484414944150441514415244153441544415544156441574415844159441604416144162441634416444165441664416744168441694417044171441724417344174441754417644177441784417944180441814418244183441844418544186441874418844189441904419144192441934419444195441964419744198441994420044201442024420344204442054420644207442084420944210442114421244213442144421544216442174421844219442204422144222442234422444225442264422744228442294423044231442324423344234442354423644237442384423944240442414424244243442444424544246442474424844249442504425144252442534425444255442564425744258442594426044261442624426344264442654426644267442684426944270442714427244273442744427544276442774427844279442804428144282442834428444285442864428744288442894429044291442924429344294442954429644297442984429944300443014430244303443044430544306443074430844309443104431144312443134431444315443164431744318443194432044321443224432344324443254432644327443284432944330443314433244333443344433544336443374433844339443404434144342443434434444345443464434744348443494435044351443524435344354443554435644357443584435944360443614436244363443644436544366443674436844369443704437144372443734437444375443764437744378443794438044381443824438344384443854438644387443884438944390443914439244393443944439544396443974439844399444004440144402444034440444405444064440744408444094441044411444124441344414444154441644417444184441944420444214442244423444244442544426444274442844429444304443144432444334443444435444364443744438444394444044441444424444344444444454444644447444484444944450444514445244453444544445544456444574445844459444604446144462444634446444465444664446744468444694447044471444724447344474444754447644477444784447944480444814448244483444844448544486444874448844489444904449144492444934449444495444964449744498444994450044501445024450344504445054450644507445084450944510445114451244513445144451544516445174451844519445204452144522445234452444525445264452744528445294453044531445324453344534445354453644537445384453944540445414454244543445444454544546445474454844549445504455144552445534455444555445564455744558445594456044561445624456344564445654456644567445684456944570445714457244573445744457544576445774457844579445804458144582445834458444585445864458744588445894459044591445924459344594445954459644597445984459944600446014460244603446044460544606446074460844609446104461144612446134461444615446164461744618446194462044621446224462344624446254462644627446284462944630446314463244633446344463544636446374463844639446404464144642446434464444645446464464744648446494465044651446524465344654446554465644657446584465944660446614466244663446644466544666446674466844669446704467144672446734467444675446764467744678446794468044681446824468344684446854468644687446884468944690446914469244693446944469544696446974469844699447004470144702447034470444705447064470744708447094471044711447124471344714447154471644717447184471944720447214472244723447244472544726447274472844729447304473144732447334473444735447364473744738447394474044741447424474344744447454474644747447484474944750447514475244753447544475544756447574475844759447604476144762447634476444765447664476744768447694477044771447724477344774447754477644777447784477944780447814478244783447844478544786447874478844789447904479144792447934479444795447964479744798447994480044801448024480344804448054480644807448084480944810448114481244813448144481544816448174481844819448204482144822448234482444825448264482744828448294483044831448324483344834448354483644837448384483944840448414484244843448444484544846448474484844849448504485144852448534485444855448564485744858448594486044861448624486344864448654486644867448684486944870448714487244873448744487544876448774487844879448804488144882448834488444885448864488744888448894489044891448924489344894448954489644897448984489944900449014490244903449044490544906449074490844909449104491144912449134491444915449164491744918449194492044921449224492344924449254492644927449284492944930449314493244933449344493544936449374493844939449404494144942449434494444945449464494744948449494495044951449524495344954449554495644957449584495944960449614496244963449644496544966449674496844969449704497144972449734497444975449764497744978449794498044981449824498344984449854498644987449884498944990449914499244993449944499544996449974499844999450004500145002450034500445005450064500745008450094501045011450124501345014450154501645017450184501945020450214502245023450244502545026450274502845029450304503145032450334503445035450364503745038450394504045041450424504345044450454504645047450484504945050450514505245053450544505545056450574505845059450604506145062450634506445065450664506745068450694507045071450724507345074450754507645077450784507945080450814508245083450844508545086450874508845089450904509145092450934509445095450964509745098450994510045101451024510345104451054510645107451084510945110451114511245113451144511545116451174511845119451204512145122451234512445125451264512745128451294513045131451324513345134451354513645137451384513945140451414514245143451444514545146451474514845149451504515145152451534515445155451564515745158451594516045161451624516345164451654516645167451684516945170451714517245173451744517545176451774517845179451804518145182451834518445185451864518745188451894519045191451924519345194451954519645197451984519945200452014520245203452044520545206452074520845209452104521145212452134521445215452164521745218452194522045221452224522345224452254522645227452284522945230452314523245233452344523545236452374523845239452404524145242452434524445245452464524745248452494525045251452524525345254452554525645257452584525945260452614526245263452644526545266452674526845269452704527145272452734527445275452764527745278452794528045281452824528345284452854528645287452884528945290452914529245293452944529545296452974529845299453004530145302453034530445305453064530745308453094531045311453124531345314453154531645317453184531945320453214532245323453244532545326453274532845329453304533145332453334533445335453364533745338453394534045341453424534345344453454534645347453484534945350453514535245353453544535545356453574535845359453604536145362453634536445365453664536745368453694537045371453724537345374453754537645377453784537945380453814538245383453844538545386453874538845389453904539145392453934539445395453964539745398453994540045401454024540345404454054540645407454084540945410454114541245413454144541545416454174541845419454204542145422454234542445425454264542745428454294543045431454324543345434454354543645437454384543945440454414544245443454444544545446454474544845449454504545145452454534545445455454564545745458454594546045461454624546345464454654546645467454684546945470454714547245473454744547545476454774547845479454804548145482454834548445485454864548745488454894549045491454924549345494454954549645497454984549945500455014550245503455044550545506455074550845509455104551145512455134551445515455164551745518455194552045521455224552345524455254552645527455284552945530455314553245533455344553545536455374553845539455404554145542455434554445545455464554745548455494555045551455524555345554455554555645557455584555945560455614556245563455644556545566455674556845569455704557145572455734557445575455764557745578455794558045581455824558345584455854558645587455884558945590455914559245593455944559545596455974559845599456004560145602456034560445605456064560745608456094561045611456124561345614456154561645617456184561945620456214562245623456244562545626456274562845629456304563145632456334563445635456364563745638456394564045641456424564345644456454564645647456484564945650456514565245653456544565545656456574565845659456604566145662456634566445665456664566745668456694567045671456724567345674456754567645677456784567945680456814568245683456844568545686456874568845689456904569145692456934569445695456964569745698456994570045701457024570345704457054570645707457084570945710457114571245713457144571545716457174571845719457204572145722457234572445725457264572745728457294573045731457324573345734457354573645737457384573945740457414574245743457444574545746457474574845749457504575145752457534575445755457564575745758457594576045761457624576345764457654576645767457684576945770457714577245773457744577545776457774577845779457804578145782457834578445785457864578745788457894579045791457924579345794457954579645797457984579945800458014580245803458044580545806458074580845809458104581145812458134581445815458164581745818458194582045821458224582345824458254582645827458284582945830458314583245833458344583545836458374583845839458404584145842458434584445845458464584745848458494585045851458524585345854458554585645857458584585945860458614586245863458644586545866458674586845869458704587145872458734587445875458764587745878458794588045881458824588345884458854588645887458884588945890458914589245893458944589545896458974589845899459004590145902459034590445905459064590745908459094591045911459124591345914459154591645917459184591945920459214592245923459244592545926459274592845929459304593145932459334593445935459364593745938459394594045941459424594345944459454594645947459484594945950459514595245953459544595545956459574595845959459604596145962459634596445965459664596745968459694597045971459724597345974459754597645977459784597945980459814598245983459844598545986459874598845989459904599145992459934599445995459964599745998459994600046001460024600346004460054600646007460084600946010460114601246013460144601546016460174601846019460204602146022460234602446025460264602746028460294603046031460324603346034460354603646037460384603946040460414604246043460444604546046460474604846049460504605146052460534605446055460564605746058460594606046061460624606346064460654606646067460684606946070460714607246073460744607546076460774607846079460804608146082460834608446085460864608746088460894609046091460924609346094460954609646097460984609946100461014610246103461044610546106461074610846109461104611146112461134611446115461164611746118461194612046121461224612346124461254612646127461284612946130461314613246133461344613546136461374613846139461404614146142461434614446145461464614746148461494615046151461524615346154461554615646157461584615946160461614616246163461644616546166461674616846169461704617146172461734617446175461764617746178461794618046181461824618346184461854618646187461884618946190461914619246193461944619546196461974619846199462004620146202462034620446205462064620746208462094621046211462124621346214462154621646217462184621946220462214622246223462244622546226462274622846229462304623146232462334623446235462364623746238462394624046241462424624346244462454624646247462484624946250462514625246253462544625546256462574625846259462604626146262462634626446265462664626746268462694627046271462724627346274462754627646277462784627946280462814628246283462844628546286462874628846289462904629146292462934629446295462964629746298462994630046301463024630346304463054630646307463084630946310463114631246313463144631546316463174631846319463204632146322463234632446325463264632746328463294633046331463324633346334463354633646337463384633946340463414634246343463444634546346463474634846349463504635146352463534635446355463564635746358463594636046361463624636346364463654636646367463684636946370463714637246373463744637546376463774637846379463804638146382463834638446385463864638746388463894639046391463924639346394463954639646397463984639946400464014640246403464044640546406464074640846409464104641146412464134641446415464164641746418464194642046421464224642346424464254642646427464284642946430464314643246433464344643546436464374643846439464404644146442464434644446445464464644746448464494645046451464524645346454464554645646457464584645946460464614646246463464644646546466464674646846469464704647146472464734647446475464764647746478464794648046481464824648346484464854648646487464884648946490464914649246493464944649546496464974649846499465004650146502465034650446505465064650746508465094651046511465124651346514465154651646517465184651946520465214652246523465244652546526465274652846529465304653146532465334653446535465364653746538465394654046541465424654346544465454654646547465484654946550465514655246553465544655546556465574655846559465604656146562465634656446565465664656746568465694657046571465724657346574465754657646577465784657946580465814658246583465844658546586465874658846589465904659146592465934659446595465964659746598465994660046601466024660346604466054660646607466084660946610466114661246613466144661546616466174661846619466204662146622466234662446625466264662746628466294663046631466324663346634466354663646637466384663946640466414664246643466444664546646466474664846649466504665146652466534665446655466564665746658466594666046661466624666346664466654666646667466684666946670466714667246673466744667546676466774667846679466804668146682466834668446685466864668746688466894669046691466924669346694466954669646697466984669946700467014670246703467044670546706467074670846709467104671146712467134671446715467164671746718467194672046721467224672346724467254672646727467284672946730467314673246733467344673546736467374673846739467404674146742467434674446745467464674746748467494675046751467524675346754467554675646757467584675946760467614676246763467644676546766467674676846769467704677146772467734677446775467764677746778467794678046781467824678346784467854678646787467884678946790467914679246793467944679546796467974679846799468004680146802468034680446805468064680746808468094681046811468124681346814468154681646817468184681946820468214682246823468244682546826468274682846829468304683146832468334683446835468364683746838468394684046841468424684346844468454684646847468484684946850468514685246853468544685546856468574685846859468604686146862468634686446865468664686746868468694687046871468724687346874468754687646877468784687946880468814688246883468844688546886468874688846889468904689146892468934689446895468964689746898468994690046901469024690346904469054690646907469084690946910469114691246913469144691546916469174691846919469204692146922469234692446925469264692746928469294693046931469324693346934469354693646937469384693946940469414694246943469444694546946469474694846949469504695146952469534695446955469564695746958469594696046961469624696346964469654696646967469684696946970469714697246973469744697546976469774697846979469804698146982469834698446985469864698746988469894699046991469924699346994469954699646997469984699947000470014700247003470044700547006470074700847009470104701147012470134701447015470164701747018470194702047021470224702347024470254702647027470284702947030470314703247033470344703547036470374703847039470404704147042470434704447045470464704747048470494705047051470524705347054470554705647057470584705947060470614706247063470644706547066470674706847069470704707147072470734707447075470764707747078470794708047081470824708347084470854708647087470884708947090470914709247093470944709547096470974709847099471004710147102471034710447105471064710747108471094711047111471124711347114471154711647117471184711947120471214712247123471244712547126471274712847129471304713147132471334713447135471364713747138471394714047141471424714347144471454714647147471484714947150471514715247153471544715547156471574715847159471604716147162471634716447165471664716747168471694717047171471724717347174471754717647177471784717947180471814718247183471844718547186471874718847189471904719147192471934719447195471964719747198471994720047201472024720347204472054720647207472084720947210472114721247213472144721547216472174721847219472204722147222472234722447225472264722747228472294723047231472324723347234472354723647237472384723947240472414724247243472444724547246472474724847249472504725147252472534725447255472564725747258472594726047261472624726347264472654726647267472684726947270472714727247273472744727547276472774727847279472804728147282472834728447285472864728747288472894729047291472924729347294472954729647297472984729947300473014730247303473044730547306473074730847309473104731147312473134731447315473164731747318473194732047321473224732347324473254732647327473284732947330473314733247333473344733547336473374733847339473404734147342473434734447345473464734747348473494735047351473524735347354473554735647357473584735947360473614736247363473644736547366473674736847369473704737147372473734737447375473764737747378473794738047381473824738347384473854738647387473884738947390473914739247393473944739547396473974739847399474004740147402474034740447405474064740747408474094741047411474124741347414474154741647417474184741947420474214742247423474244742547426474274742847429474304743147432474334743447435474364743747438474394744047441474424744347444474454744647447474484744947450474514745247453474544745547456474574745847459474604746147462474634746447465474664746747468474694747047471474724747347474474754747647477474784747947480474814748247483474844748547486474874748847489474904749147492474934749447495474964749747498474994750047501475024750347504475054750647507475084750947510475114751247513475144751547516475174751847519475204752147522475234752447525475264752747528475294753047531475324753347534475354753647537475384753947540475414754247543475444754547546475474754847549475504755147552475534755447555475564755747558475594756047561475624756347564475654756647567475684756947570475714757247573475744757547576475774757847579475804758147582475834758447585475864758747588475894759047591475924759347594475954759647597475984759947600476014760247603476044760547606476074760847609476104761147612476134761447615476164761747618476194762047621476224762347624476254762647627476284762947630476314763247633476344763547636476374763847639476404764147642476434764447645476464764747648476494765047651476524765347654476554765647657476584765947660476614766247663476644766547666476674766847669476704767147672476734767447675476764767747678476794768047681476824768347684476854768647687476884768947690476914769247693476944769547696476974769847699477004770147702477034770447705477064770747708477094771047711477124771347714477154771647717477184771947720477214772247723477244772547726477274772847729477304773147732477334773447735477364773747738477394774047741477424774347744477454774647747477484774947750477514775247753477544775547756477574775847759477604776147762477634776447765477664776747768477694777047771477724777347774477754777647777477784777947780477814778247783477844778547786477874778847789477904779147792477934779447795477964779747798477994780047801478024780347804478054780647807478084780947810478114781247813478144781547816478174781847819478204782147822478234782447825478264782747828478294783047831478324783347834478354783647837478384783947840478414784247843478444784547846478474784847849478504785147852478534785447855478564785747858478594786047861478624786347864478654786647867478684786947870478714787247873478744787547876478774787847879478804788147882478834788447885478864788747888478894789047891478924789347894478954789647897478984789947900479014790247903479044790547906479074790847909479104791147912479134791447915479164791747918479194792047921479224792347924479254792647927479284792947930479314793247933479344793547936479374793847939479404794147942479434794447945479464794747948479494795047951479524795347954479554795647957479584795947960479614796247963479644796547966479674796847969479704797147972479734797447975479764797747978479794798047981479824798347984479854798647987479884798947990479914799247993479944799547996479974799847999480004800148002480034800448005480064800748008480094801048011480124801348014480154801648017480184801948020480214802248023480244802548026480274802848029480304803148032480334803448035480364803748038480394804048041480424804348044480454804648047480484804948050480514805248053480544805548056480574805848059480604806148062480634806448065480664806748068480694807048071480724807348074480754807648077480784807948080480814808248083480844808548086480874808848089480904809148092480934809448095480964809748098480994810048101481024810348104481054810648107481084810948110481114811248113481144811548116481174811848119481204812148122481234812448125481264812748128481294813048131481324813348134481354813648137481384813948140481414814248143481444814548146481474814848149481504815148152481534815448155481564815748158481594816048161481624816348164481654816648167481684816948170481714817248173481744817548176481774817848179481804818148182481834818448185481864818748188481894819048191481924819348194481954819648197481984819948200482014820248203482044820548206482074820848209482104821148212482134821448215482164821748218482194822048221482224822348224482254822648227482284822948230482314823248233482344823548236482374823848239482404824148242482434824448245482464824748248482494825048251482524825348254482554825648257482584825948260482614826248263482644826548266482674826848269482704827148272482734827448275482764827748278482794828048281482824828348284482854828648287482884828948290482914829248293482944829548296482974829848299483004830148302483034830448305483064830748308483094831048311483124831348314483154831648317483184831948320483214832248323483244832548326483274832848329483304833148332483334833448335483364833748338483394834048341483424834348344483454834648347483484834948350483514835248353483544835548356483574835848359483604836148362483634836448365483664836748368483694837048371483724837348374483754837648377483784837948380483814838248383483844838548386483874838848389483904839148392483934839448395483964839748398483994840048401484024840348404484054840648407484084840948410484114841248413484144841548416484174841848419484204842148422484234842448425484264842748428484294843048431484324843348434484354843648437484384843948440484414844248443484444844548446484474844848449484504845148452484534845448455484564845748458484594846048461484624846348464484654846648467484684846948470484714847248473484744847548476484774847848479484804848148482484834848448485484864848748488484894849048491484924849348494484954849648497484984849948500485014850248503485044850548506485074850848509485104851148512485134851448515485164851748518485194852048521485224852348524485254852648527485284852948530485314853248533485344853548536485374853848539485404854148542485434854448545485464854748548485494855048551485524855348554485554855648557485584855948560485614856248563485644856548566485674856848569485704857148572485734857448575485764857748578485794858048581485824858348584485854858648587485884858948590485914859248593485944859548596485974859848599486004860148602486034860448605486064860748608486094861048611486124861348614486154861648617486184861948620486214862248623486244862548626486274862848629486304863148632486334863448635486364863748638486394864048641486424864348644486454864648647486484864948650486514865248653486544865548656486574865848659486604866148662486634866448665486664866748668486694867048671486724867348674486754867648677486784867948680486814868248683486844868548686486874868848689486904869148692486934869448695486964869748698486994870048701487024870348704487054870648707487084870948710487114871248713487144871548716487174871848719487204872148722487234872448725487264872748728487294873048731487324873348734487354873648737487384873948740487414874248743487444874548746487474874848749487504875148752487534875448755487564875748758487594876048761487624876348764487654876648767487684876948770487714877248773487744877548776487774877848779487804878148782487834878448785487864878748788487894879048791487924879348794487954879648797487984879948800488014880248803488044880548806488074880848809488104881148812488134881448815488164881748818488194882048821488224882348824488254882648827488284882948830488314883248833488344883548836488374883848839488404884148842488434884448845488464884748848488494885048851488524885348854488554885648857488584885948860488614886248863488644886548866488674886848869488704887148872488734887448875488764887748878488794888048881488824888348884488854888648887488884888948890488914889248893488944889548896488974889848899489004890148902489034890448905489064890748908489094891048911489124891348914489154891648917489184891948920489214892248923489244892548926489274892848929489304893148932489334893448935489364893748938489394894048941489424894348944489454894648947489484894948950489514895248953489544895548956489574895848959489604896148962489634896448965489664896748968489694897048971489724897348974489754897648977489784897948980489814898248983489844898548986489874898848989489904899148992489934899448995489964899748998489994900049001490024900349004490054900649007490084900949010490114901249013490144901549016490174901849019490204902149022490234902449025490264902749028490294903049031490324903349034490354903649037490384903949040490414904249043490444904549046490474904849049490504905149052490534905449055490564905749058490594906049061490624906349064490654906649067490684906949070490714907249073490744907549076490774907849079490804908149082490834908449085490864908749088490894909049091490924909349094490954909649097490984909949100491014910249103491044910549106491074910849109491104911149112491134911449115491164911749118491194912049121491224912349124491254912649127491284912949130491314913249133491344913549136491374913849139491404914149142491434914449145491464914749148491494915049151491524915349154491554915649157491584915949160491614916249163491644916549166491674916849169491704917149172491734917449175491764917749178491794918049181491824918349184491854918649187491884918949190491914919249193491944919549196491974919849199492004920149202492034920449205492064920749208492094921049211492124921349214492154921649217492184921949220492214922249223492244922549226492274922849229492304923149232492334923449235492364923749238492394924049241492424924349244492454924649247492484924949250492514925249253492544925549256492574925849259492604926149262492634926449265492664926749268492694927049271492724927349274492754927649277492784927949280492814928249283492844928549286492874928849289492904929149292492934929449295492964929749298492994930049301493024930349304493054930649307493084930949310493114931249313493144931549316493174931849319493204932149322493234932449325493264932749328493294933049331493324933349334493354933649337493384933949340493414934249343493444934549346493474934849349493504935149352493534935449355493564935749358493594936049361493624936349364493654936649367493684936949370493714937249373493744937549376493774937849379493804938149382493834938449385493864938749388493894939049391493924939349394493954939649397493984939949400494014940249403494044940549406494074940849409494104941149412494134941449415494164941749418494194942049421494224942349424494254942649427494284942949430494314943249433494344943549436494374943849439494404944149442494434944449445494464944749448494494945049451494524945349454494554945649457494584945949460494614946249463494644946549466494674946849469494704947149472494734947449475494764947749478494794948049481494824948349484494854948649487494884948949490494914949249493494944949549496494974949849499495004950149502495034950449505495064950749508495094951049511495124951349514495154951649517495184951949520495214952249523495244952549526495274952849529495304953149532495334953449535495364953749538495394954049541495424954349544495454954649547495484954949550495514955249553495544955549556495574955849559495604956149562495634956449565495664956749568495694957049571495724957349574495754957649577495784957949580495814958249583495844958549586495874958849589495904959149592495934959449595495964959749598495994960049601496024960349604496054960649607496084960949610496114961249613496144961549616496174961849619496204962149622496234962449625496264962749628496294963049631496324963349634496354963649637496384963949640496414964249643496444964549646496474964849649496504965149652496534965449655496564965749658496594966049661496624966349664496654966649667496684966949670496714967249673496744967549676496774967849679496804968149682496834968449685496864968749688496894969049691496924969349694496954969649697496984969949700497014970249703497044970549706497074970849709497104971149712497134971449715497164971749718497194972049721497224972349724497254972649727497284972949730497314973249733497344973549736497374973849739497404974149742497434974449745497464974749748497494975049751497524975349754497554975649757497584975949760497614976249763497644976549766497674976849769497704977149772497734977449775497764977749778497794978049781497824978349784497854978649787497884978949790497914979249793497944979549796497974979849799498004980149802498034980449805498064980749808498094981049811498124981349814498154981649817498184981949820498214982249823498244982549826498274982849829498304983149832498334983449835498364983749838498394984049841498424984349844498454984649847498484984949850498514985249853498544985549856498574985849859498604986149862498634986449865498664986749868498694987049871498724987349874498754987649877498784987949880498814988249883498844988549886498874988849889498904989149892498934989449895498964989749898498994990049901499024990349904499054990649907499084990949910499114991249913499144991549916499174991849919499204992149922499234992449925499264992749928499294993049931499324993349934499354993649937499384993949940499414994249943499444994549946499474994849949499504995149952499534995449955499564995749958499594996049961499624996349964499654996649967499684996949970499714997249973499744997549976499774997849979499804998149982499834998449985499864998749988499894999049991499924999349994499954999649997499984999950000500015000250003500045000550006500075000850009500105001150012500135001450015500165001750018500195002050021500225002350024500255002650027500285002950030500315003250033500345003550036500375003850039500405004150042500435004450045500465004750048500495005050051500525005350054500555005650057500585005950060500615006250063500645006550066500675006850069500705007150072500735007450075500765007750078500795008050081500825008350084500855008650087500885008950090500915009250093500945009550096500975009850099501005010150102501035010450105501065010750108501095011050111501125011350114501155011650117501185011950120501215012250123501245012550126501275012850129501305013150132501335013450135501365013750138501395014050141501425014350144501455014650147501485014950150501515015250153501545015550156501575015850159501605016150162501635016450165501665016750168501695017050171501725017350174501755017650177501785017950180501815018250183501845018550186501875018850189501905019150192501935019450195501965019750198501995020050201502025020350204502055020650207502085020950210502115021250213502145021550216502175021850219502205022150222502235022450225502265022750228502295023050231502325023350234502355023650237502385023950240502415024250243502445024550246502475024850249502505025150252502535025450255502565025750258502595026050261502625026350264502655026650267502685026950270502715027250273502745027550276502775027850279502805028150282502835028450285502865028750288502895029050291502925029350294502955029650297502985029950300503015030250303503045030550306503075030850309503105031150312503135031450315503165031750318503195032050321503225032350324503255032650327503285032950330503315033250333503345033550336503375033850339503405034150342503435034450345503465034750348503495035050351503525035350354503555035650357503585035950360503615036250363503645036550366503675036850369503705037150372503735037450375503765037750378503795038050381503825038350384503855038650387503885038950390503915039250393503945039550396503975039850399504005040150402504035040450405504065040750408504095041050411504125041350414504155041650417504185041950420504215042250423504245042550426504275042850429504305043150432504335043450435504365043750438504395044050441504425044350444504455044650447504485044950450504515045250453504545045550456504575045850459504605046150462504635046450465504665046750468504695047050471504725047350474504755047650477504785047950480504815048250483504845048550486504875048850489504905049150492504935049450495504965049750498504995050050501505025050350504505055050650507505085050950510505115051250513505145051550516505175051850519505205052150522505235052450525505265052750528505295053050531505325053350534505355053650537505385053950540505415054250543505445054550546505475054850549505505055150552505535055450555505565055750558505595056050561505625056350564505655056650567505685056950570505715057250573505745057550576505775057850579505805058150582505835058450585505865058750588505895059050591505925059350594505955059650597505985059950600506015060250603506045060550606506075060850609506105061150612506135061450615506165061750618506195062050621506225062350624506255062650627506285062950630506315063250633506345063550636506375063850639506405064150642506435064450645506465064750648506495065050651506525065350654506555065650657506585065950660506615066250663506645066550666506675066850669506705067150672506735067450675506765067750678506795068050681506825068350684506855068650687506885068950690506915069250693506945069550696506975069850699507005070150702507035070450705507065070750708507095071050711507125071350714507155071650717507185071950720507215072250723507245072550726507275072850729507305073150732507335073450735507365073750738507395074050741507425074350744507455074650747507485074950750507515075250753507545075550756507575075850759507605076150762507635076450765507665076750768507695077050771507725077350774507755077650777507785077950780507815078250783507845078550786507875078850789507905079150792507935079450795507965079750798507995080050801508025080350804508055080650807508085080950810508115081250813508145081550816508175081850819508205082150822508235082450825508265082750828508295083050831508325083350834508355083650837508385083950840508415084250843508445084550846508475084850849508505085150852508535085450855508565085750858508595086050861508625086350864508655086650867508685086950870508715087250873508745087550876508775087850879508805088150882508835088450885508865088750888508895089050891508925089350894508955089650897508985089950900509015090250903509045090550906509075090850909509105091150912509135091450915509165091750918509195092050921509225092350924509255092650927509285092950930509315093250933509345093550936509375093850939509405094150942509435094450945509465094750948509495095050951509525095350954509555095650957509585095950960509615096250963509645096550966509675096850969509705097150972509735097450975509765097750978509795098050981509825098350984509855098650987509885098950990509915099250993509945099550996509975099850999510005100151002510035100451005510065100751008510095101051011510125101351014510155101651017510185101951020510215102251023510245102551026510275102851029510305103151032510335103451035510365103751038510395104051041510425104351044510455104651047510485104951050510515105251053510545105551056510575105851059510605106151062510635106451065510665106751068510695107051071510725107351074510755107651077510785107951080510815108251083510845108551086510875108851089510905109151092510935109451095510965109751098510995110051101511025110351104511055110651107511085110951110511115111251113511145111551116511175111851119511205112151122511235112451125511265112751128511295113051131511325113351134511355113651137511385113951140511415114251143511445114551146511475114851149511505115151152511535115451155511565115751158511595116051161511625116351164511655116651167511685116951170511715117251173511745117551176511775117851179511805118151182511835118451185511865118751188511895119051191511925119351194511955119651197511985119951200512015120251203512045120551206512075120851209512105121151212512135121451215512165121751218512195122051221512225122351224512255122651227512285122951230512315123251233512345123551236512375123851239512405124151242512435124451245512465124751248512495125051251512525125351254
  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.201';
  30. var pdfjsBuild = '911a2ca';
  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.pdfjsCoreBidi = {}));
  203. }
  204. }(this, function (exports) {
  205. // Character types for symbols from 0000 to 00FF.
  206. var baseTypes = [
  207. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'S', 'B', 'S', 'WS',
  208. 'B', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  209. 'BN', 'BN', 'B', 'B', 'B', 'S', 'WS', 'ON', 'ON', 'ET', 'ET', 'ET', 'ON',
  210. 'ON', 'ON', 'ON', 'ON', 'ON', 'CS', 'ON', 'CS', 'ON', 'EN', 'EN', 'EN',
  211. 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'EN', 'ON', 'ON', 'ON', 'ON', 'ON',
  212. 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  213. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'ON', 'ON',
  214. 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  215. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  216. 'L', 'ON', 'ON', 'ON', 'ON', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'B', 'BN',
  217. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  218. 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN', 'BN',
  219. 'BN', 'CS', 'ON', 'ET', 'ET', 'ET', 'ET', 'ON', 'ON', 'ON', 'ON', 'L', 'ON',
  220. 'ON', 'ON', 'ON', 'ON', 'ET', 'ET', 'EN', 'EN', 'ON', 'L', 'ON', 'ON', 'ON',
  221. 'EN', 'L', 'ON', 'ON', 'ON', 'ON', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  222. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  223. 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  224. 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L',
  225. 'L', 'L', 'L', 'ON', 'L', 'L', 'L', 'L', 'L', 'L', 'L', 'L'
  226. ];
  227. // Character types for symbols from 0600 to 06FF
  228. var arabicTypes = [
  229. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  230. 'CS', 'AL', 'ON', 'ON', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL',
  231. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  232. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  233. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  234. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  235. 'AL', 'AL', 'AL', 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  236. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL',
  237. 'AL', 'AL', 'AL', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN', 'AN',
  238. 'AN', 'ET', 'AN', 'AN', 'AL', 'AL', 'AL', 'NSM', 'AL', 'AL', 'AL', 'AL',
  239. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  240. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  241. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  242. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  243. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  244. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  245. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  246. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  247. 'AL', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM',
  248. 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'NSM', 'ON', 'NSM',
  249. 'NSM', 'NSM', 'NSM', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL',
  250. 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL', 'AL'
  251. ];
  252. function isOdd(i) {
  253. return (i & 1) !== 0;
  254. }
  255. function isEven(i) {
  256. return (i & 1) === 0;
  257. }
  258. function findUnequal(arr, start, value) {
  259. for (var j = start, jj = arr.length; j < jj; ++j) {
  260. if (arr[j] !== value) {
  261. return j;
  262. }
  263. }
  264. return j;
  265. }
  266. function setValues(arr, start, end, value) {
  267. for (var j = start; j < end; ++j) {
  268. arr[j] = value;
  269. }
  270. }
  271. function reverseValues(arr, start, end) {
  272. for (var i = start, j = end - 1; i < j; ++i, --j) {
  273. var temp = arr[i];
  274. arr[i] = arr[j];
  275. arr[j] = temp;
  276. }
  277. }
  278. function createBidiText(str, isLTR, vertical) {
  279. return {
  280. str: str,
  281. dir: (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'))
  282. };
  283. }
  284. // These are used in bidi(), which is called frequently. We re-use them on
  285. // each call to avoid unnecessary allocations.
  286. var chars = [];
  287. var types = [];
  288. function bidi(str, startLevel, vertical) {
  289. var isLTR = true;
  290. var strLength = str.length;
  291. if (strLength === 0 || vertical) {
  292. return createBidiText(str, isLTR, vertical);
  293. }
  294. // Get types and fill arrays
  295. chars.length = strLength;
  296. types.length = strLength;
  297. var numBidi = 0;
  298. var i, ii;
  299. for (i = 0; i < strLength; ++i) {
  300. chars[i] = str.charAt(i);
  301. var charCode = str.charCodeAt(i);
  302. var charType = 'L';
  303. if (charCode <= 0x00ff) {
  304. charType = baseTypes[charCode];
  305. } else if (0x0590 <= charCode && charCode <= 0x05f4) {
  306. charType = 'R';
  307. } else if (0x0600 <= charCode && charCode <= 0x06ff) {
  308. charType = arabicTypes[charCode & 0xff];
  309. } else if (0x0700 <= charCode && charCode <= 0x08AC) {
  310. charType = 'AL';
  311. }
  312. if (charType === 'R' || charType === 'AL' || charType === 'AN') {
  313. numBidi++;
  314. }
  315. types[i] = charType;
  316. }
  317. // Detect the bidi method
  318. // - If there are no rtl characters then no bidi needed
  319. // - If less than 30% chars are rtl then string is primarily ltr
  320. // - If more than 30% chars are rtl then string is primarily rtl
  321. if (numBidi === 0) {
  322. isLTR = true;
  323. return createBidiText(str, isLTR);
  324. }
  325. if (startLevel === -1) {
  326. if ((strLength / numBidi) < 0.3) {
  327. isLTR = true;
  328. startLevel = 0;
  329. } else {
  330. isLTR = false;
  331. startLevel = 1;
  332. }
  333. }
  334. var levels = [];
  335. for (i = 0; i < strLength; ++i) {
  336. levels[i] = startLevel;
  337. }
  338. /*
  339. X1-X10: skip most of this, since we are NOT doing the embeddings.
  340. */
  341. var e = (isOdd(startLevel) ? 'R' : 'L');
  342. var sor = e;
  343. var eor = sor;
  344. /*
  345. W1. Examine each non-spacing mark (NSM) in the level run, and change the
  346. type of the NSM to the type of the previous character. If the NSM is at the
  347. start of the level run, it will get the type of sor.
  348. */
  349. var lastType = sor;
  350. for (i = 0; i < strLength; ++i) {
  351. if (types[i] === 'NSM') {
  352. types[i] = lastType;
  353. } else {
  354. lastType = types[i];
  355. }
  356. }
  357. /*
  358. W2. Search backwards from each instance of a European number until the
  359. first strong type (R, L, AL, or sor) is found. If an AL is found, change
  360. the type of the European number to Arabic number.
  361. */
  362. lastType = sor;
  363. var t;
  364. for (i = 0; i < strLength; ++i) {
  365. t = types[i];
  366. if (t === 'EN') {
  367. types[i] = (lastType === 'AL') ? 'AN' : 'EN';
  368. } else if (t === 'R' || t === 'L' || t === 'AL') {
  369. lastType = t;
  370. }
  371. }
  372. /*
  373. W3. Change all ALs to R.
  374. */
  375. for (i = 0; i < strLength; ++i) {
  376. t = types[i];
  377. if (t === 'AL') {
  378. types[i] = 'R';
  379. }
  380. }
  381. /*
  382. W4. A single European separator between two European numbers changes to a
  383. European number. A single common separator between two numbers of the same
  384. type changes to that type:
  385. */
  386. for (i = 1; i < strLength - 1; ++i) {
  387. if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
  388. types[i] = 'EN';
  389. }
  390. if (types[i] === 'CS' &&
  391. (types[i - 1] === 'EN' || types[i - 1] === 'AN') &&
  392. types[i + 1] === types[i - 1]) {
  393. types[i] = types[i - 1];
  394. }
  395. }
  396. /*
  397. W5. A sequence of European terminators adjacent to European numbers changes
  398. to all European numbers:
  399. */
  400. for (i = 0; i < strLength; ++i) {
  401. if (types[i] === 'EN') {
  402. // do before
  403. var j;
  404. for (j = i - 1; j >= 0; --j) {
  405. if (types[j] !== 'ET') {
  406. break;
  407. }
  408. types[j] = 'EN';
  409. }
  410. // do after
  411. for (j = i + 1; j < strLength; --j) {
  412. if (types[j] !== 'ET') {
  413. break;
  414. }
  415. types[j] = 'EN';
  416. }
  417. }
  418. }
  419. /*
  420. W6. Otherwise, separators and terminators change to Other Neutral:
  421. */
  422. for (i = 0; i < strLength; ++i) {
  423. t = types[i];
  424. if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') {
  425. types[i] = 'ON';
  426. }
  427. }
  428. /*
  429. W7. Search backwards from each instance of a European number until the
  430. first strong type (R, L, or sor) is found. If an L is found, then change
  431. the type of the European number to L.
  432. */
  433. lastType = sor;
  434. for (i = 0; i < strLength; ++i) {
  435. t = types[i];
  436. if (t === 'EN') {
  437. types[i] = ((lastType === 'L') ? 'L' : 'EN');
  438. } else if (t === 'R' || t === 'L') {
  439. lastType = t;
  440. }
  441. }
  442. /*
  443. N1. A sequence of neutrals takes the direction of the surrounding strong
  444. text if the text on both sides has the same direction. European and Arabic
  445. numbers are treated as though they were R. Start-of-level-run (sor) and
  446. end-of-level-run (eor) are used at level run boundaries.
  447. */
  448. for (i = 0; i < strLength; ++i) {
  449. if (types[i] === 'ON') {
  450. var end = findUnequal(types, i + 1, 'ON');
  451. var before = sor;
  452. if (i > 0) {
  453. before = types[i - 1];
  454. }
  455. var after = eor;
  456. if (end + 1 < strLength) {
  457. after = types[end + 1];
  458. }
  459. if (before !== 'L') {
  460. before = 'R';
  461. }
  462. if (after !== 'L') {
  463. after = 'R';
  464. }
  465. if (before === after) {
  466. setValues(types, i, end, before);
  467. }
  468. i = end - 1; // reset to end (-1 so next iteration is ok)
  469. }
  470. }
  471. /*
  472. N2. Any remaining neutrals take the embedding direction.
  473. */
  474. for (i = 0; i < strLength; ++i) {
  475. if (types[i] === 'ON') {
  476. types[i] = e;
  477. }
  478. }
  479. /*
  480. I1. For all characters with an even (left-to-right) embedding direction,
  481. those of type R go up one level and those of type AN or EN go up two
  482. levels.
  483. I2. For all characters with an odd (right-to-left) embedding direction,
  484. those of type L, EN or AN go up one level.
  485. */
  486. for (i = 0; i < strLength; ++i) {
  487. t = types[i];
  488. if (isEven(levels[i])) {
  489. if (t === 'R') {
  490. levels[i] += 1;
  491. } else if (t === 'AN' || t === 'EN') {
  492. levels[i] += 2;
  493. }
  494. } else { // isOdd
  495. if (t === 'L' || t === 'AN' || t === 'EN') {
  496. levels[i] += 1;
  497. }
  498. }
  499. }
  500. /*
  501. L1. On each line, reset the embedding level of the following characters to
  502. the paragraph embedding level:
  503. segment separators,
  504. paragraph separators,
  505. any sequence of whitespace characters preceding a segment separator or
  506. paragraph separator, and any sequence of white space characters at the end
  507. of the line.
  508. */
  509. // don't bother as text is only single line
  510. /*
  511. L2. From the highest level found in the text to the lowest odd level on
  512. each line, reverse any contiguous sequence of characters that are at that
  513. level or higher.
  514. */
  515. // find highest level & lowest odd level
  516. var highestLevel = -1;
  517. var lowestOddLevel = 99;
  518. var level;
  519. for (i = 0, ii = levels.length; i < ii; ++i) {
  520. level = levels[i];
  521. if (highestLevel < level) {
  522. highestLevel = level;
  523. }
  524. if (lowestOddLevel > level && isOdd(level)) {
  525. lowestOddLevel = level;
  526. }
  527. }
  528. // now reverse between those limits
  529. for (level = highestLevel; level >= lowestOddLevel; --level) {
  530. // find segments to reverse
  531. var start = -1;
  532. for (i = 0, ii = levels.length; i < ii; ++i) {
  533. if (levels[i] < level) {
  534. if (start >= 0) {
  535. reverseValues(chars, start, i);
  536. start = -1;
  537. }
  538. } else if (start < 0) {
  539. start = i;
  540. }
  541. }
  542. if (start >= 0) {
  543. reverseValues(chars, start, levels.length);
  544. }
  545. }
  546. /*
  547. L3. Combining marks applied to a right-to-left base character will at this
  548. point precede their base character. If the rendering engine expects them to
  549. follow the base characters in the final display process, then the ordering
  550. of the marks and the base character must be reversed.
  551. */
  552. // don't bother for now
  553. /*
  554. L4. A character that possesses the mirrored property as specified by
  555. Section 4.7, Mirrored, must be depicted by a mirrored glyph if the resolved
  556. directionality of that character is R.
  557. */
  558. // don't mirror as characters are already mirrored in the pdf
  559. // Finally, return string
  560. for (i = 0, ii = chars.length; i < ii; ++i) {
  561. var ch = chars[i];
  562. if (ch === '<' || ch === '>') {
  563. chars[i] = '';
  564. }
  565. }
  566. return createBidiText(chars.join(''), isLTR);
  567. }
  568. exports.bidi = bidi;
  569. }));
  570. (function (root, factory) {
  571. {
  572. factory((root.pdfjsCoreCharsets = {}));
  573. }
  574. }(this, function (exports) {
  575. var ISOAdobeCharset = [
  576. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar',
  577. 'percent', 'ampersand', 'quoteright', 'parenleft', 'parenright',
  578. 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash', 'zero',
  579. 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  580. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question',
  581. 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
  582. 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
  583. 'bracketleft', 'backslash', 'bracketright', 'asciicircum', 'underscore',
  584. 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
  585. 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
  586. 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  587. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  588. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  589. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  590. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase',
  591. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  592. 'perthousand', 'questiondown', 'grave', 'acute', 'circumflex', 'tilde',
  593. 'macron', 'breve', 'dotaccent', 'dieresis', 'ring', 'cedilla',
  594. 'hungarumlaut', 'ogonek', 'caron', 'emdash', 'AE', 'ordfeminine',
  595. 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae', 'dotlessi', 'lslash',
  596. 'oslash', 'oe', 'germandbls', 'onesuperior', 'logicalnot', 'mu',
  597. 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn', 'onequarter',
  598. 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters', 'twosuperior',
  599. 'registered', 'minus', 'eth', 'multiply', 'threesuperior', 'copyright',
  600. 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring', 'Atilde',
  601. 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave', 'Iacute',
  602. 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute', 'Ocircumflex',
  603. 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute', 'Ucircumflex',
  604. 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron', 'aacute',
  605. 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde', 'ccedilla',
  606. 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute', 'icircumflex',
  607. 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex', 'odieresis',
  608. 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex', 'udieresis',
  609. 'ugrave', 'yacute', 'ydieresis', 'zcaron'
  610. ];
  611. var ExpertCharset = [
  612. '.notdef', 'space', 'exclamsmall', 'Hungarumlautsmall', 'dollaroldstyle',
  613. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  614. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  615. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  616. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  617. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle',
  618. 'colon', 'semicolon', 'commasuperior', 'threequartersemdash',
  619. 'periodsuperior', 'questionsmall', 'asuperior', 'bsuperior',
  620. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  621. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  622. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  623. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  624. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  625. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  626. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  627. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  628. 'onefitted', 'rupiah', 'Tildesmall', 'exclamdownsmall', 'centoldstyle',
  629. 'Lslashsmall', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall',
  630. 'Brevesmall', 'Caronsmall', 'Dotaccentsmall', 'Macronsmall',
  631. 'figuredash', 'hypheninferior', 'Ogoneksmall', 'Ringsmall',
  632. 'Cedillasmall', 'onequarter', 'onehalf', 'threequarters',
  633. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  634. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  635. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  636. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  637. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  638. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  639. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  640. 'periodinferior', 'commainferior', 'Agravesmall', 'Aacutesmall',
  641. 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall', 'Aringsmall',
  642. 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  643. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  644. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  645. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  646. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  647. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  648. 'Ydieresissmall'
  649. ];
  650. var ExpertSubsetCharset = [
  651. '.notdef', 'space', 'dollaroldstyle', 'dollarsuperior',
  652. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  653. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction',
  654. 'zerooldstyle', 'oneoldstyle', 'twooldstyle', 'threeoldstyle',
  655. 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle',
  656. 'eightoldstyle', 'nineoldstyle', 'colon', 'semicolon', 'commasuperior',
  657. 'threequartersemdash', 'periodsuperior', 'asuperior', 'bsuperior',
  658. 'centsuperior', 'dsuperior', 'esuperior', 'isuperior', 'lsuperior',
  659. 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  660. 'tsuperior', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior',
  661. 'parenrightinferior', 'hyphensuperior', 'colonmonetary', 'onefitted',
  662. 'rupiah', 'centoldstyle', 'figuredash', 'hypheninferior', 'onequarter',
  663. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  664. 'seveneighths', 'onethird', 'twothirds', 'zerosuperior', 'onesuperior',
  665. 'twosuperior', 'threesuperior', 'foursuperior', 'fivesuperior',
  666. 'sixsuperior', 'sevensuperior', 'eightsuperior', 'ninesuperior',
  667. 'zeroinferior', 'oneinferior', 'twoinferior', 'threeinferior',
  668. 'fourinferior', 'fiveinferior', 'sixinferior', 'seveninferior',
  669. 'eightinferior', 'nineinferior', 'centinferior', 'dollarinferior',
  670. 'periodinferior', 'commainferior'
  671. ];
  672. exports.ISOAdobeCharset = ISOAdobeCharset;
  673. exports.ExpertCharset = ExpertCharset;
  674. exports.ExpertSubsetCharset = ExpertSubsetCharset;
  675. }));
  676. (function (root, factory) {
  677. {
  678. factory((root.pdfjsCoreEncodings = {}));
  679. }
  680. }(this, function (exports) {
  681. var ExpertEncoding = [
  682. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  683. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  684. 'space', 'exclamsmall', 'Hungarumlautsmall', '', 'dollaroldstyle',
  685. 'dollarsuperior', 'ampersandsmall', 'Acutesmall', 'parenleftsuperior',
  686. 'parenrightsuperior', 'twodotenleader', 'onedotenleader', 'comma',
  687. 'hyphen', 'period', 'fraction', 'zerooldstyle', 'oneoldstyle',
  688. 'twooldstyle', 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle',
  689. 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'colon',
  690. 'semicolon', 'commasuperior', 'threequartersemdash', 'periodsuperior',
  691. 'questionsmall', '', 'asuperior', 'bsuperior', 'centsuperior', 'dsuperior',
  692. 'esuperior', '', '', 'isuperior', '', '', 'lsuperior', 'msuperior',
  693. 'nsuperior', 'osuperior', '', '', 'rsuperior', 'ssuperior', 'tsuperior',
  694. '', 'ff', 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '',
  695. 'parenrightinferior', 'Circumflexsmall', 'hyphensuperior', 'Gravesmall',
  696. 'Asmall', 'Bsmall', 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall',
  697. 'Hsmall', 'Ismall', 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall',
  698. 'Osmall', 'Psmall', 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall',
  699. 'Vsmall', 'Wsmall', 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary',
  700. 'onefitted', 'rupiah', 'Tildesmall', '', '', '', '', '', '', '', '', '',
  701. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  702. '', '', '', '', '', '', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  703. '', '', 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall',
  704. 'Caronsmall', '', 'Dotaccentsmall', '', '', 'Macronsmall', '', '',
  705. 'figuredash', 'hypheninferior', '', '', 'Ogoneksmall', 'Ringsmall',
  706. 'Cedillasmall', '', '', '', 'onequarter', 'onehalf', 'threequarters',
  707. 'questiondownsmall', 'oneeighth', 'threeeighths', 'fiveeighths',
  708. 'seveneighths', 'onethird', 'twothirds', '', '', 'zerosuperior',
  709. 'onesuperior', 'twosuperior', 'threesuperior', 'foursuperior',
  710. 'fivesuperior', 'sixsuperior', 'sevensuperior', 'eightsuperior',
  711. 'ninesuperior', 'zeroinferior', 'oneinferior', 'twoinferior',
  712. 'threeinferior', 'fourinferior', 'fiveinferior', 'sixinferior',
  713. 'seveninferior', 'eightinferior', 'nineinferior', 'centinferior',
  714. 'dollarinferior', 'periodinferior', 'commainferior', 'Agravesmall',
  715. 'Aacutesmall', 'Acircumflexsmall', 'Atildesmall', 'Adieresissmall',
  716. 'Aringsmall', 'AEsmall', 'Ccedillasmall', 'Egravesmall', 'Eacutesmall',
  717. 'Ecircumflexsmall', 'Edieresissmall', 'Igravesmall', 'Iacutesmall',
  718. 'Icircumflexsmall', 'Idieresissmall', 'Ethsmall', 'Ntildesmall',
  719. 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall', 'Otildesmall',
  720. 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall', 'Uacutesmall',
  721. 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall', 'Thornsmall',
  722. 'Ydieresissmall'];
  723. var MacExpertEncoding = [
  724. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  725. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  726. 'space', 'exclamsmall', 'Hungarumlautsmall', 'centoldstyle',
  727. 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall', 'Acutesmall',
  728. 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  729. 'onedotenleader', 'comma', 'hyphen', 'period', 'fraction', 'zerooldstyle',
  730. 'oneoldstyle', 'twooldstyle', 'threeoldstyle', 'fouroldstyle',
  731. 'fiveoldstyle', 'sixoldstyle', 'sevenoldstyle', 'eightoldstyle',
  732. 'nineoldstyle', 'colon', 'semicolon', '', 'threequartersemdash', '',
  733. 'questionsmall', '', '', '', '', 'Ethsmall', '', '', 'onequarter',
  734. 'onehalf', 'threequarters', 'oneeighth', 'threeeighths', 'fiveeighths',
  735. 'seveneighths', 'onethird', 'twothirds', '', '', '', '', '', '', 'ff',
  736. 'fi', 'fl', 'ffi', 'ffl', 'parenleftinferior', '', 'parenrightinferior',
  737. 'Circumflexsmall', 'hypheninferior', 'Gravesmall', 'Asmall', 'Bsmall',
  738. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  739. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  740. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  741. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  742. 'Tildesmall', '', '', 'asuperior', 'centsuperior', '', '', '', '',
  743. 'Aacutesmall', 'Agravesmall', 'Acircumflexsmall', 'Adieresissmall',
  744. 'Atildesmall', 'Aringsmall', 'Ccedillasmall', 'Eacutesmall', 'Egravesmall',
  745. 'Ecircumflexsmall', 'Edieresissmall', 'Iacutesmall', 'Igravesmall',
  746. 'Icircumflexsmall', 'Idieresissmall', 'Ntildesmall', 'Oacutesmall',
  747. 'Ogravesmall', 'Ocircumflexsmall', 'Odieresissmall', 'Otildesmall',
  748. 'Uacutesmall', 'Ugravesmall', 'Ucircumflexsmall', 'Udieresissmall', '',
  749. 'eightsuperior', 'fourinferior', 'threeinferior', 'sixinferior',
  750. 'eightinferior', 'seveninferior', 'Scaronsmall', '', 'centinferior',
  751. 'twoinferior', '', 'Dieresissmall', '', 'Caronsmall', 'osuperior',
  752. 'fiveinferior', '', 'commainferior', 'periodinferior', 'Yacutesmall', '',
  753. 'dollarinferior', '', 'Thornsmall', '', 'nineinferior', 'zeroinferior',
  754. 'Zcaronsmall', 'AEsmall', 'Oslashsmall', 'questiondownsmall',
  755. 'oneinferior', 'Lslashsmall', '', '', '', '', '', '', 'Cedillasmall', '',
  756. '', '', '', '', 'OEsmall', 'figuredash', 'hyphensuperior', '', '', '', '',
  757. 'exclamdownsmall', '', 'Ydieresissmall', '', 'onesuperior', 'twosuperior',
  758. 'threesuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  759. 'sevensuperior', 'ninesuperior', 'zerosuperior', '', 'esuperior',
  760. 'rsuperior', 'tsuperior', '', '', 'isuperior', 'ssuperior', 'dsuperior',
  761. '', '', '', '', '', 'lsuperior', 'Ogoneksmall', 'Brevesmall',
  762. 'Macronsmall', 'bsuperior', 'nsuperior', 'msuperior', 'commasuperior',
  763. 'periodsuperior', 'Dotaccentsmall', 'Ringsmall'];
  764. var MacRomanEncoding = [
  765. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  766. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  767. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  768. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  769. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  770. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  771. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  772. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  773. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  774. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  775. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  776. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', '',
  777. 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde', 'Odieresis',
  778. 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis', 'atilde',
  779. 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  780. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute',
  781. 'ograve', 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave',
  782. 'ucircumflex', 'udieresis', 'dagger', 'degree', 'cent', 'sterling',
  783. 'section', 'bullet', 'paragraph', 'germandbls', 'registered', 'copyright',
  784. 'trademark', 'acute', 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity',
  785. 'plusminus', 'lessequal', 'greaterequal', 'yen', 'mu', 'partialdiff',
  786. 'summation', 'product', 'pi', 'integral', 'ordfeminine', 'ordmasculine',
  787. 'Omega', 'ae', 'oslash', 'questiondown', 'exclamdown', 'logicalnot',
  788. 'radical', 'florin', 'approxequal', 'Delta', 'guillemotleft',
  789. 'guillemotright', 'ellipsis', 'space', 'Agrave', 'Atilde', 'Otilde', 'OE',
  790. 'oe', 'endash', 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft',
  791. 'quoteright', 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction',
  792. 'currency', 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl',
  793. 'periodcentered', 'quotesinglbase', 'quotedblbase', 'perthousand',
  794. 'Acircumflex', 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute',
  795. 'Icircumflex', 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple',
  796. 'Ograve', 'Uacute', 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex',
  797. 'tilde', 'macron', 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut',
  798. 'ogonek', 'caron'];
  799. var StandardEncoding = [
  800. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  801. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  802. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  803. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  804. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  805. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  806. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  807. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  808. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  809. 'asciicircum', 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f',
  810. 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
  811. 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  812. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  813. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'exclamdown',
  814. 'cent', 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  815. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  816. 'guilsinglright', 'fi', 'fl', '', 'endash', 'dagger', 'daggerdbl',
  817. 'periodcentered', '', 'paragraph', 'bullet', 'quotesinglbase',
  818. 'quotedblbase', 'quotedblright', 'guillemotright', 'ellipsis',
  819. 'perthousand', '', 'questiondown', '', 'grave', 'acute', 'circumflex',
  820. 'tilde', 'macron', 'breve', 'dotaccent', 'dieresis', '', 'ring', 'cedilla',
  821. '', 'hungarumlaut', 'ogonek', 'caron', 'emdash', '', '', '', '', '', '',
  822. '', '', '', '', '', '', '', '', '', '', 'AE', '', 'ordfeminine', '', '',
  823. '', '', 'Lslash', 'Oslash', 'OE', 'ordmasculine', '', '', '', '', '', 'ae',
  824. '', '', '', 'dotlessi', '', '', 'lslash', 'oslash', 'oe', 'germandbls'];
  825. var WinAnsiEncoding = [
  826. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  827. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  828. 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  829. 'ampersand', 'quotesingle', 'parenleft', 'parenright', 'asterisk', 'plus',
  830. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three',
  831. 'four', 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon',
  832. 'less', 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F',
  833. 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
  834. 'V', 'W', 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright',
  835. 'asciicircum', 'underscore', 'grave', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
  836. 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
  837. 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright', 'asciitilde',
  838. 'bullet', 'Euro', 'bullet', 'quotesinglbase', 'florin', 'quotedblbase',
  839. 'ellipsis', 'dagger', 'daggerdbl', 'circumflex', 'perthousand', 'Scaron',
  840. 'guilsinglleft', 'OE', 'bullet', 'Zcaron', 'bullet', 'bullet', 'quoteleft',
  841. 'quoteright', 'quotedblleft', 'quotedblright', 'bullet', 'endash',
  842. 'emdash', 'tilde', 'trademark', 'scaron', 'guilsinglright', 'oe', 'bullet',
  843. 'zcaron', 'Ydieresis', 'space', 'exclamdown', 'cent', 'sterling',
  844. 'currency', 'yen', 'brokenbar', 'section', 'dieresis', 'copyright',
  845. 'ordfeminine', 'guillemotleft', 'logicalnot', 'hyphen', 'registered',
  846. 'macron', 'degree', 'plusminus', 'twosuperior', 'threesuperior', 'acute',
  847. 'mu', 'paragraph', 'periodcentered', 'cedilla', 'onesuperior',
  848. 'ordmasculine', 'guillemotright', 'onequarter', 'onehalf', 'threequarters',
  849. 'questiondown', 'Agrave', 'Aacute', 'Acircumflex', 'Atilde', 'Adieresis',
  850. 'Aring', 'AE', 'Ccedilla', 'Egrave', 'Eacute', 'Ecircumflex', 'Edieresis',
  851. 'Igrave', 'Iacute', 'Icircumflex', 'Idieresis', 'Eth', 'Ntilde', 'Ograve',
  852. 'Oacute', 'Ocircumflex', 'Otilde', 'Odieresis', 'multiply', 'Oslash',
  853. 'Ugrave', 'Uacute', 'Ucircumflex', 'Udieresis', 'Yacute', 'Thorn',
  854. 'germandbls', 'agrave', 'aacute', 'acircumflex', 'atilde', 'adieresis',
  855. 'aring', 'ae', 'ccedilla', 'egrave', 'eacute', 'ecircumflex', 'edieresis',
  856. 'igrave', 'iacute', 'icircumflex', 'idieresis', 'eth', 'ntilde', 'ograve',
  857. 'oacute', 'ocircumflex', 'otilde', 'odieresis', 'divide', 'oslash',
  858. 'ugrave', 'uacute', 'ucircumflex', 'udieresis', 'yacute', 'thorn',
  859. 'ydieresis'];
  860. var SymbolSetEncoding = [
  861. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  862. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  863. 'space', 'exclam', 'universal', 'numbersign', 'existential', 'percent',
  864. 'ampersand', 'suchthat', 'parenleft', 'parenright', 'asteriskmath', 'plus',
  865. 'comma', 'minus', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  866. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  867. 'equal', 'greater', 'question', 'congruent', 'Alpha', 'Beta', 'Chi',
  868. 'Delta', 'Epsilon', 'Phi', 'Gamma', 'Eta', 'Iota', 'theta1', 'Kappa',
  869. 'Lambda', 'Mu', 'Nu', 'Omicron', 'Pi', 'Theta', 'Rho', 'Sigma', 'Tau',
  870. 'Upsilon', 'sigma1', 'Omega', 'Xi', 'Psi', 'Zeta', 'bracketleft',
  871. 'therefore', 'bracketright', 'perpendicular', 'underscore', 'radicalex',
  872. 'alpha', 'beta', 'chi', 'delta', 'epsilon', 'phi', 'gamma', 'eta', 'iota',
  873. 'phi1', 'kappa', 'lambda', 'mu', 'nu', 'omicron', 'pi', 'theta', 'rho',
  874. 'sigma', 'tau', 'upsilon', 'omega1', 'omega', 'xi', 'psi', 'zeta',
  875. 'braceleft', 'bar', 'braceright', 'similar', '', '', '', '', '', '', '',
  876. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  877. '', '', '', '', '', '', '', 'Euro', 'Upsilon1', 'minute', 'lessequal',
  878. 'fraction', 'infinity', 'florin', 'club', 'diamond', 'heart', 'spade',
  879. 'arrowboth', 'arrowleft', 'arrowup', 'arrowright', 'arrowdown', 'degree',
  880. 'plusminus', 'second', 'greaterequal', 'multiply', 'proportional',
  881. 'partialdiff', 'bullet', 'divide', 'notequal', 'equivalence',
  882. 'approxequal', 'ellipsis', 'arrowvertex', 'arrowhorizex', 'carriagereturn',
  883. 'aleph', 'Ifraktur', 'Rfraktur', 'weierstrass', 'circlemultiply',
  884. 'circleplus', 'emptyset', 'intersection', 'union', 'propersuperset',
  885. 'reflexsuperset', 'notsubset', 'propersubset', 'reflexsubset', 'element',
  886. 'notelement', 'angle', 'gradient', 'registerserif', 'copyrightserif',
  887. 'trademarkserif', 'product', 'radical', 'dotmath', 'logicalnot',
  888. 'logicaland', 'logicalor', 'arrowdblboth', 'arrowdblleft', 'arrowdblup',
  889. 'arrowdblright', 'arrowdbldown', 'lozenge', 'angleleft', 'registersans',
  890. 'copyrightsans', 'trademarksans', 'summation', 'parenlefttp',
  891. 'parenleftex', 'parenleftbt', 'bracketlefttp', 'bracketleftex',
  892. 'bracketleftbt', 'bracelefttp', 'braceleftmid', 'braceleftbt', 'braceex',
  893. '', 'angleright', 'integral', 'integraltp', 'integralex', 'integralbt',
  894. 'parenrighttp', 'parenrightex', 'parenrightbt', 'bracketrighttp',
  895. 'bracketrightex', 'bracketrightbt', 'bracerighttp', 'bracerightmid',
  896. 'bracerightbt'];
  897. var ZapfDingbatsEncoding = [
  898. '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  899. '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  900. 'space', 'a1', 'a2', 'a202', 'a3', 'a4', 'a5', 'a119', 'a118', 'a117',
  901. 'a11', 'a12', 'a13', 'a14', 'a15', 'a16', 'a105', 'a17', 'a18', 'a19',
  902. 'a20', 'a21', 'a22', 'a23', 'a24', 'a25', 'a26', 'a27', 'a28', 'a6', 'a7',
  903. 'a8', 'a9', 'a10', 'a29', 'a30', 'a31', 'a32', 'a33', 'a34', 'a35', 'a36',
  904. 'a37', 'a38', 'a39', 'a40', 'a41', 'a42', 'a43', 'a44', 'a45', 'a46',
  905. 'a47', 'a48', 'a49', 'a50', 'a51', 'a52', 'a53', 'a54', 'a55', 'a56',
  906. 'a57', 'a58', 'a59', 'a60', 'a61', 'a62', 'a63', 'a64', 'a65', 'a66',
  907. 'a67', 'a68', 'a69', 'a70', 'a71', 'a72', 'a73', 'a74', 'a203', 'a75',
  908. 'a204', 'a76', 'a77', 'a78', 'a79', 'a81', 'a82', 'a83', 'a84', 'a97',
  909. 'a98', 'a99', 'a100', '', 'a89', 'a90', 'a93', 'a94', 'a91', 'a92', 'a205',
  910. 'a85', 'a206', 'a86', 'a87', 'a88', 'a95', 'a96', '', '', '', '', '', '',
  911. '', '', '', '', '', '', '', '', '', '', '', '', '', 'a101', 'a102', 'a103',
  912. 'a104', 'a106', 'a107', 'a108', 'a112', 'a111', 'a110', 'a109', 'a120',
  913. 'a121', 'a122', 'a123', 'a124', 'a125', 'a126', 'a127', 'a128', 'a129',
  914. 'a130', 'a131', 'a132', 'a133', 'a134', 'a135', 'a136', 'a137', 'a138',
  915. 'a139', 'a140', 'a141', 'a142', 'a143', 'a144', 'a145', 'a146', 'a147',
  916. 'a148', 'a149', 'a150', 'a151', 'a152', 'a153', 'a154', 'a155', 'a156',
  917. 'a157', 'a158', 'a159', 'a160', 'a161', 'a163', 'a164', 'a196', 'a165',
  918. 'a192', 'a166', 'a167', 'a168', 'a169', 'a170', 'a171', 'a172', 'a173',
  919. 'a162', 'a174', 'a175', 'a176', 'a177', 'a178', 'a179', 'a193', 'a180',
  920. 'a199', 'a181', 'a200', 'a182', '', 'a201', 'a183', 'a184', 'a197', 'a185',
  921. 'a194', 'a198', 'a186', 'a195', 'a187', 'a188', 'a189', 'a190', 'a191'];
  922. function getEncoding(encodingName) {
  923. switch (encodingName) {
  924. case 'WinAnsiEncoding':
  925. return WinAnsiEncoding;
  926. case 'StandardEncoding':
  927. return StandardEncoding;
  928. case 'MacRomanEncoding':
  929. return MacRomanEncoding;
  930. case 'SymbolSetEncoding':
  931. return SymbolSetEncoding;
  932. case 'ZapfDingbatsEncoding':
  933. return ZapfDingbatsEncoding;
  934. case 'ExpertEncoding':
  935. return ExpertEncoding;
  936. case 'MacExpertEncoding':
  937. return MacExpertEncoding;
  938. default:
  939. return null;
  940. }
  941. }
  942. exports.WinAnsiEncoding = WinAnsiEncoding;
  943. exports.StandardEncoding = StandardEncoding;
  944. exports.MacRomanEncoding = MacRomanEncoding;
  945. exports.SymbolSetEncoding = SymbolSetEncoding;
  946. exports.ZapfDingbatsEncoding = ZapfDingbatsEncoding;
  947. exports.ExpertEncoding = ExpertEncoding;
  948. exports.getEncoding = getEncoding;
  949. }));
  950. (function (root, factory) {
  951. {
  952. factory((root.pdfjsCoreJpg = {}));
  953. }
  954. }(this, function (exports) {
  955. /*
  956. This code was forked from https://github.com/notmasteryet/jpgjs. The original
  957. version was created by github user notmasteryet
  958. - The JPEG specification can be found in the ITU CCITT Recommendation T.81
  959. (www.w3.org/Graphics/JPEG/itu-t81.pdf)
  960. - The JFIF specification can be found in the JPEG File Interchange Format
  961. (www.w3.org/Graphics/JPEG/jfif3.pdf)
  962. - The Adobe Application-Specific JPEG markers in the Supporting the DCT Filters
  963. in PostScript Level 2, Technical Note #5116
  964. (partners.adobe.com/public/developer/en/ps/sdk/5116.DCT_Filter.pdf)
  965. */
  966. var JpegImage = (function jpegImage() {
  967. var dctZigZag = new Uint8Array([
  968. 0,
  969. 1, 8,
  970. 16, 9, 2,
  971. 3, 10, 17, 24,
  972. 32, 25, 18, 11, 4,
  973. 5, 12, 19, 26, 33, 40,
  974. 48, 41, 34, 27, 20, 13, 6,
  975. 7, 14, 21, 28, 35, 42, 49, 56,
  976. 57, 50, 43, 36, 29, 22, 15,
  977. 23, 30, 37, 44, 51, 58,
  978. 59, 52, 45, 38, 31,
  979. 39, 46, 53, 60,
  980. 61, 54, 47,
  981. 55, 62,
  982. 63
  983. ]);
  984. var dctCos1 = 4017; // cos(pi/16)
  985. var dctSin1 = 799; // sin(pi/16)
  986. var dctCos3 = 3406; // cos(3*pi/16)
  987. var dctSin3 = 2276; // sin(3*pi/16)
  988. var dctCos6 = 1567; // cos(6*pi/16)
  989. var dctSin6 = 3784; // sin(6*pi/16)
  990. var dctSqrt2 = 5793; // sqrt(2)
  991. var dctSqrt1d2 = 2896; // sqrt(2) / 2
  992. function constructor() {
  993. }
  994. function buildHuffmanTable(codeLengths, values) {
  995. var k = 0, code = [], i, j, length = 16;
  996. while (length > 0 && !codeLengths[length - 1]) {
  997. length--;
  998. }
  999. code.push({children: [], index: 0});
  1000. var p = code[0], q;
  1001. for (i = 0; i < length; i++) {
  1002. for (j = 0; j < codeLengths[i]; j++) {
  1003. p = code.pop();
  1004. p.children[p.index] = values[k];
  1005. while (p.index > 0) {
  1006. p = code.pop();
  1007. }
  1008. p.index++;
  1009. code.push(p);
  1010. while (code.length <= i) {
  1011. code.push(q = {children: [], index: 0});
  1012. p.children[p.index] = q.children;
  1013. p = q;
  1014. }
  1015. k++;
  1016. }
  1017. if (i + 1 < length) {
  1018. // p here points to last code
  1019. code.push(q = {children: [], index: 0});
  1020. p.children[p.index] = q.children;
  1021. p = q;
  1022. }
  1023. }
  1024. return code[0].children;
  1025. }
  1026. function getBlockBufferOffset(component, row, col) {
  1027. return 64 * ((component.blocksPerLine + 1) * row + col);
  1028. }
  1029. function decodeScan(data, offset, frame, components, resetInterval,
  1030. spectralStart, spectralEnd, successivePrev, successive) {
  1031. var mcusPerLine = frame.mcusPerLine;
  1032. var progressive = frame.progressive;
  1033. var startOffset = offset, bitsData = 0, bitsCount = 0;
  1034. function readBit() {
  1035. if (bitsCount > 0) {
  1036. bitsCount--;
  1037. return (bitsData >> bitsCount) & 1;
  1038. }
  1039. bitsData = data[offset++];
  1040. if (bitsData === 0xFF) {
  1041. var nextByte = data[offset++];
  1042. if (nextByte) {
  1043. throw 'unexpected marker: ' +
  1044. ((bitsData << 8) | nextByte).toString(16);
  1045. }
  1046. // unstuff 0
  1047. }
  1048. bitsCount = 7;
  1049. return bitsData >>> 7;
  1050. }
  1051. function decodeHuffman(tree) {
  1052. var node = tree;
  1053. while (true) {
  1054. node = node[readBit()];
  1055. if (typeof node === 'number') {
  1056. return node;
  1057. }
  1058. if (typeof node !== 'object') {
  1059. throw 'invalid huffman sequence';
  1060. }
  1061. }
  1062. }
  1063. function receive(length) {
  1064. var n = 0;
  1065. while (length > 0) {
  1066. n = (n << 1) | readBit();
  1067. length--;
  1068. }
  1069. return n;
  1070. }
  1071. function receiveAndExtend(length) {
  1072. if (length === 1) {
  1073. return readBit() === 1 ? 1 : -1;
  1074. }
  1075. var n = receive(length);
  1076. if (n >= 1 << (length - 1)) {
  1077. return n;
  1078. }
  1079. return n + (-1 << length) + 1;
  1080. }
  1081. function decodeBaseline(component, offset) {
  1082. var t = decodeHuffman(component.huffmanTableDC);
  1083. var diff = t === 0 ? 0 : receiveAndExtend(t);
  1084. component.blockData[offset] = (component.pred += diff);
  1085. var k = 1;
  1086. while (k < 64) {
  1087. var rs = decodeHuffman(component.huffmanTableAC);
  1088. var s = rs & 15, r = rs >> 4;
  1089. if (s === 0) {
  1090. if (r < 15) {
  1091. break;
  1092. }
  1093. k += 16;
  1094. continue;
  1095. }
  1096. k += r;
  1097. var z = dctZigZag[k];
  1098. component.blockData[offset + z] = receiveAndExtend(s);
  1099. k++;
  1100. }
  1101. }
  1102. function decodeDCFirst(component, offset) {
  1103. var t = decodeHuffman(component.huffmanTableDC);
  1104. var diff = t === 0 ? 0 : (receiveAndExtend(t) << successive);
  1105. component.blockData[offset] = (component.pred += diff);
  1106. }
  1107. function decodeDCSuccessive(component, offset) {
  1108. component.blockData[offset] |= readBit() << successive;
  1109. }
  1110. var eobrun = 0;
  1111. function decodeACFirst(component, offset) {
  1112. if (eobrun > 0) {
  1113. eobrun--;
  1114. return;
  1115. }
  1116. var k = spectralStart, e = spectralEnd;
  1117. while (k <= e) {
  1118. var rs = decodeHuffman(component.huffmanTableAC);
  1119. var s = rs & 15, r = rs >> 4;
  1120. if (s === 0) {
  1121. if (r < 15) {
  1122. eobrun = receive(r) + (1 << r) - 1;
  1123. break;
  1124. }
  1125. k += 16;
  1126. continue;
  1127. }
  1128. k += r;
  1129. var z = dctZigZag[k];
  1130. component.blockData[offset + z] =
  1131. receiveAndExtend(s) * (1 << successive);
  1132. k++;
  1133. }
  1134. }
  1135. var successiveACState = 0, successiveACNextValue;
  1136. function decodeACSuccessive(component, offset) {
  1137. var k = spectralStart;
  1138. var e = spectralEnd;
  1139. var r = 0;
  1140. var s;
  1141. var rs;
  1142. while (k <= e) {
  1143. var z = dctZigZag[k];
  1144. switch (successiveACState) {
  1145. case 0: // initial state
  1146. rs = decodeHuffman(component.huffmanTableAC);
  1147. s = rs & 15;
  1148. r = rs >> 4;
  1149. if (s === 0) {
  1150. if (r < 15) {
  1151. eobrun = receive(r) + (1 << r);
  1152. successiveACState = 4;
  1153. } else {
  1154. r = 16;
  1155. successiveACState = 1;
  1156. }
  1157. } else {
  1158. if (s !== 1) {
  1159. throw 'invalid ACn encoding';
  1160. }
  1161. successiveACNextValue = receiveAndExtend(s);
  1162. successiveACState = r ? 2 : 3;
  1163. }
  1164. continue;
  1165. case 1: // skipping r zero items
  1166. case 2:
  1167. if (component.blockData[offset + z]) {
  1168. component.blockData[offset + z] += (readBit() << successive);
  1169. } else {
  1170. r--;
  1171. if (r === 0) {
  1172. successiveACState = successiveACState === 2 ? 3 : 0;
  1173. }
  1174. }
  1175. break;
  1176. case 3: // set value for a zero item
  1177. if (component.blockData[offset + z]) {
  1178. component.blockData[offset + z] += (readBit() << successive);
  1179. } else {
  1180. component.blockData[offset + z] =
  1181. successiveACNextValue << successive;
  1182. successiveACState = 0;
  1183. }
  1184. break;
  1185. case 4: // eob
  1186. if (component.blockData[offset + z]) {
  1187. component.blockData[offset + z] += (readBit() << successive);
  1188. }
  1189. break;
  1190. }
  1191. k++;
  1192. }
  1193. if (successiveACState === 4) {
  1194. eobrun--;
  1195. if (eobrun === 0) {
  1196. successiveACState = 0;
  1197. }
  1198. }
  1199. }
  1200. function decodeMcu(component, decode, mcu, row, col) {
  1201. var mcuRow = (mcu / mcusPerLine) | 0;
  1202. var mcuCol = mcu % mcusPerLine;
  1203. var blockRow = mcuRow * component.v + row;
  1204. var blockCol = mcuCol * component.h + col;
  1205. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1206. decode(component, offset);
  1207. }
  1208. function decodeBlock(component, decode, mcu) {
  1209. var blockRow = (mcu / component.blocksPerLine) | 0;
  1210. var blockCol = mcu % component.blocksPerLine;
  1211. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1212. decode(component, offset);
  1213. }
  1214. var componentsLength = components.length;
  1215. var component, i, j, k, n;
  1216. var decodeFn;
  1217. if (progressive) {
  1218. if (spectralStart === 0) {
  1219. decodeFn = successivePrev === 0 ? decodeDCFirst : decodeDCSuccessive;
  1220. } else {
  1221. decodeFn = successivePrev === 0 ? decodeACFirst : decodeACSuccessive;
  1222. }
  1223. } else {
  1224. decodeFn = decodeBaseline;
  1225. }
  1226. var mcu = 0, marker;
  1227. var mcuExpected;
  1228. if (componentsLength === 1) {
  1229. mcuExpected = components[0].blocksPerLine * components[0].blocksPerColumn;
  1230. } else {
  1231. mcuExpected = mcusPerLine * frame.mcusPerColumn;
  1232. }
  1233. if (!resetInterval) {
  1234. resetInterval = mcuExpected;
  1235. }
  1236. var h, v;
  1237. while (mcu < mcuExpected) {
  1238. // reset interval stuff
  1239. for (i = 0; i < componentsLength; i++) {
  1240. components[i].pred = 0;
  1241. }
  1242. eobrun = 0;
  1243. if (componentsLength === 1) {
  1244. component = components[0];
  1245. for (n = 0; n < resetInterval; n++) {
  1246. decodeBlock(component, decodeFn, mcu);
  1247. mcu++;
  1248. }
  1249. } else {
  1250. for (n = 0; n < resetInterval; n++) {
  1251. for (i = 0; i < componentsLength; i++) {
  1252. component = components[i];
  1253. h = component.h;
  1254. v = component.v;
  1255. for (j = 0; j < v; j++) {
  1256. for (k = 0; k < h; k++) {
  1257. decodeMcu(component, decodeFn, mcu, j, k);
  1258. }
  1259. }
  1260. }
  1261. mcu++;
  1262. }
  1263. }
  1264. // find marker
  1265. bitsCount = 0;
  1266. marker = (data[offset] << 8) | data[offset + 1];
  1267. if (marker <= 0xFF00) {
  1268. throw 'marker was not found';
  1269. }
  1270. if (marker >= 0xFFD0 && marker <= 0xFFD7) { // RSTx
  1271. offset += 2;
  1272. } else {
  1273. break;
  1274. }
  1275. }
  1276. return offset - startOffset;
  1277. }
  1278. // A port of poppler's IDCT method which in turn is taken from:
  1279. // Christoph Loeffler, Adriaan Ligtenberg, George S. Moschytz,
  1280. // 'Practical Fast 1-D DCT Algorithms with 11 Multiplications',
  1281. // IEEE Intl. Conf. on Acoustics, Speech & Signal Processing, 1989,
  1282. // 988-991.
  1283. function quantizeAndInverse(component, blockBufferOffset, p) {
  1284. var qt = component.quantizationTable, blockData = component.blockData;
  1285. var v0, v1, v2, v3, v4, v5, v6, v7;
  1286. var p0, p1, p2, p3, p4, p5, p6, p7;
  1287. var t;
  1288. // inverse DCT on rows
  1289. for (var row = 0; row < 64; row += 8) {
  1290. // gather block data
  1291. p0 = blockData[blockBufferOffset + row];
  1292. p1 = blockData[blockBufferOffset + row + 1];
  1293. p2 = blockData[blockBufferOffset + row + 2];
  1294. p3 = blockData[blockBufferOffset + row + 3];
  1295. p4 = blockData[blockBufferOffset + row + 4];
  1296. p5 = blockData[blockBufferOffset + row + 5];
  1297. p6 = blockData[blockBufferOffset + row + 6];
  1298. p7 = blockData[blockBufferOffset + row + 7];
  1299. // dequant p0
  1300. p0 *= qt[row];
  1301. // check for all-zero AC coefficients
  1302. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  1303. t = (dctSqrt2 * p0 + 512) >> 10;
  1304. p[row] = t;
  1305. p[row + 1] = t;
  1306. p[row + 2] = t;
  1307. p[row + 3] = t;
  1308. p[row + 4] = t;
  1309. p[row + 5] = t;
  1310. p[row + 6] = t;
  1311. p[row + 7] = t;
  1312. continue;
  1313. }
  1314. // dequant p1 ... p7
  1315. p1 *= qt[row + 1];
  1316. p2 *= qt[row + 2];
  1317. p3 *= qt[row + 3];
  1318. p4 *= qt[row + 4];
  1319. p5 *= qt[row + 5];
  1320. p6 *= qt[row + 6];
  1321. p7 *= qt[row + 7];
  1322. // stage 4
  1323. v0 = (dctSqrt2 * p0 + 128) >> 8;
  1324. v1 = (dctSqrt2 * p4 + 128) >> 8;
  1325. v2 = p2;
  1326. v3 = p6;
  1327. v4 = (dctSqrt1d2 * (p1 - p7) + 128) >> 8;
  1328. v7 = (dctSqrt1d2 * (p1 + p7) + 128) >> 8;
  1329. v5 = p3 << 4;
  1330. v6 = p5 << 4;
  1331. // stage 3
  1332. v0 = (v0 + v1 + 1) >> 1;
  1333. v1 = v0 - v1;
  1334. t = (v2 * dctSin6 + v3 * dctCos6 + 128) >> 8;
  1335. v2 = (v2 * dctCos6 - v3 * dctSin6 + 128) >> 8;
  1336. v3 = t;
  1337. v4 = (v4 + v6 + 1) >> 1;
  1338. v6 = v4 - v6;
  1339. v7 = (v7 + v5 + 1) >> 1;
  1340. v5 = v7 - v5;
  1341. // stage 2
  1342. v0 = (v0 + v3 + 1) >> 1;
  1343. v3 = v0 - v3;
  1344. v1 = (v1 + v2 + 1) >> 1;
  1345. v2 = v1 - v2;
  1346. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  1347. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  1348. v7 = t;
  1349. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  1350. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  1351. v6 = t;
  1352. // stage 1
  1353. p[row] = v0 + v7;
  1354. p[row + 7] = v0 - v7;
  1355. p[row + 1] = v1 + v6;
  1356. p[row + 6] = v1 - v6;
  1357. p[row + 2] = v2 + v5;
  1358. p[row + 5] = v2 - v5;
  1359. p[row + 3] = v3 + v4;
  1360. p[row + 4] = v3 - v4;
  1361. }
  1362. // inverse DCT on columns
  1363. for (var col = 0; col < 8; ++col) {
  1364. p0 = p[col];
  1365. p1 = p[col + 8];
  1366. p2 = p[col + 16];
  1367. p3 = p[col + 24];
  1368. p4 = p[col + 32];
  1369. p5 = p[col + 40];
  1370. p6 = p[col + 48];
  1371. p7 = p[col + 56];
  1372. // check for all-zero AC coefficients
  1373. if ((p1 | p2 | p3 | p4 | p5 | p6 | p7) === 0) {
  1374. t = (dctSqrt2 * p0 + 8192) >> 14;
  1375. // convert to 8 bit
  1376. t = (t < -2040) ? 0 : (t >= 2024) ? 255 : (t + 2056) >> 4;
  1377. blockData[blockBufferOffset + col] = t;
  1378. blockData[blockBufferOffset + col + 8] = t;
  1379. blockData[blockBufferOffset + col + 16] = t;
  1380. blockData[blockBufferOffset + col + 24] = t;
  1381. blockData[blockBufferOffset + col + 32] = t;
  1382. blockData[blockBufferOffset + col + 40] = t;
  1383. blockData[blockBufferOffset + col + 48] = t;
  1384. blockData[blockBufferOffset + col + 56] = t;
  1385. continue;
  1386. }
  1387. // stage 4
  1388. v0 = (dctSqrt2 * p0 + 2048) >> 12;
  1389. v1 = (dctSqrt2 * p4 + 2048) >> 12;
  1390. v2 = p2;
  1391. v3 = p6;
  1392. v4 = (dctSqrt1d2 * (p1 - p7) + 2048) >> 12;
  1393. v7 = (dctSqrt1d2 * (p1 + p7) + 2048) >> 12;
  1394. v5 = p3;
  1395. v6 = p5;
  1396. // stage 3
  1397. // Shift v0 by 128.5 << 5 here, so we don't need to shift p0...p7 when
  1398. // converting to UInt8 range later.
  1399. v0 = ((v0 + v1 + 1) >> 1) + 4112;
  1400. v1 = v0 - v1;
  1401. t = (v2 * dctSin6 + v3 * dctCos6 + 2048) >> 12;
  1402. v2 = (v2 * dctCos6 - v3 * dctSin6 + 2048) >> 12;
  1403. v3 = t;
  1404. v4 = (v4 + v6 + 1) >> 1;
  1405. v6 = v4 - v6;
  1406. v7 = (v7 + v5 + 1) >> 1;
  1407. v5 = v7 - v5;
  1408. // stage 2
  1409. v0 = (v0 + v3 + 1) >> 1;
  1410. v3 = v0 - v3;
  1411. v1 = (v1 + v2 + 1) >> 1;
  1412. v2 = v1 - v2;
  1413. t = (v4 * dctSin3 + v7 * dctCos3 + 2048) >> 12;
  1414. v4 = (v4 * dctCos3 - v7 * dctSin3 + 2048) >> 12;
  1415. v7 = t;
  1416. t = (v5 * dctSin1 + v6 * dctCos1 + 2048) >> 12;
  1417. v5 = (v5 * dctCos1 - v6 * dctSin1 + 2048) >> 12;
  1418. v6 = t;
  1419. // stage 1
  1420. p0 = v0 + v7;
  1421. p7 = v0 - v7;
  1422. p1 = v1 + v6;
  1423. p6 = v1 - v6;
  1424. p2 = v2 + v5;
  1425. p5 = v2 - v5;
  1426. p3 = v3 + v4;
  1427. p4 = v3 - v4;
  1428. // convert to 8-bit integers
  1429. p0 = (p0 < 16) ? 0 : (p0 >= 4080) ? 255 : p0 >> 4;
  1430. p1 = (p1 < 16) ? 0 : (p1 >= 4080) ? 255 : p1 >> 4;
  1431. p2 = (p2 < 16) ? 0 : (p2 >= 4080) ? 255 : p2 >> 4;
  1432. p3 = (p3 < 16) ? 0 : (p3 >= 4080) ? 255 : p3 >> 4;
  1433. p4 = (p4 < 16) ? 0 : (p4 >= 4080) ? 255 : p4 >> 4;
  1434. p5 = (p5 < 16) ? 0 : (p5 >= 4080) ? 255 : p5 >> 4;
  1435. p6 = (p6 < 16) ? 0 : (p6 >= 4080) ? 255 : p6 >> 4;
  1436. p7 = (p7 < 16) ? 0 : (p7 >= 4080) ? 255 : p7 >> 4;
  1437. // store block data
  1438. blockData[blockBufferOffset + col] = p0;
  1439. blockData[blockBufferOffset + col + 8] = p1;
  1440. blockData[blockBufferOffset + col + 16] = p2;
  1441. blockData[blockBufferOffset + col + 24] = p3;
  1442. blockData[blockBufferOffset + col + 32] = p4;
  1443. blockData[blockBufferOffset + col + 40] = p5;
  1444. blockData[blockBufferOffset + col + 48] = p6;
  1445. blockData[blockBufferOffset + col + 56] = p7;
  1446. }
  1447. }
  1448. function buildComponentData(frame, component) {
  1449. var blocksPerLine = component.blocksPerLine;
  1450. var blocksPerColumn = component.blocksPerColumn;
  1451. var computationBuffer = new Int16Array(64);
  1452. for (var blockRow = 0; blockRow < blocksPerColumn; blockRow++) {
  1453. for (var blockCol = 0; blockCol < blocksPerLine; blockCol++) {
  1454. var offset = getBlockBufferOffset(component, blockRow, blockCol);
  1455. quantizeAndInverse(component, offset, computationBuffer);
  1456. }
  1457. }
  1458. return component.blockData;
  1459. }
  1460. function clamp0to255(a) {
  1461. return a <= 0 ? 0 : a >= 255 ? 255 : a;
  1462. }
  1463. constructor.prototype = {
  1464. parse: function parse(data) {
  1465. function readUint16() {
  1466. var value = (data[offset] << 8) | data[offset + 1];
  1467. offset += 2;
  1468. return value;
  1469. }
  1470. function readDataBlock() {
  1471. var length = readUint16();
  1472. var array = data.subarray(offset, offset + length - 2);
  1473. offset += array.length;
  1474. return array;
  1475. }
  1476. function prepareComponents(frame) {
  1477. var mcusPerLine = Math.ceil(frame.samplesPerLine / 8 / frame.maxH);
  1478. var mcusPerColumn = Math.ceil(frame.scanLines / 8 / frame.maxV);
  1479. for (var i = 0; i < frame.components.length; i++) {
  1480. component = frame.components[i];
  1481. var blocksPerLine = Math.ceil(Math.ceil(frame.samplesPerLine / 8) *
  1482. component.h / frame.maxH);
  1483. var blocksPerColumn = Math.ceil(Math.ceil(frame.scanLines / 8) *
  1484. component.v / frame.maxV);
  1485. var blocksPerLineForMcu = mcusPerLine * component.h;
  1486. var blocksPerColumnForMcu = mcusPerColumn * component.v;
  1487. var blocksBufferSize = 64 * blocksPerColumnForMcu *
  1488. (blocksPerLineForMcu + 1);
  1489. component.blockData = new Int16Array(blocksBufferSize);
  1490. component.blocksPerLine = blocksPerLine;
  1491. component.blocksPerColumn = blocksPerColumn;
  1492. }
  1493. frame.mcusPerLine = mcusPerLine;
  1494. frame.mcusPerColumn = mcusPerColumn;
  1495. }
  1496. var offset = 0;
  1497. var jfif = null;
  1498. var adobe = null;
  1499. var frame, resetInterval;
  1500. var quantizationTables = [];
  1501. var huffmanTablesAC = [], huffmanTablesDC = [];
  1502. var fileMarker = readUint16();
  1503. if (fileMarker !== 0xFFD8) { // SOI (Start of Image)
  1504. throw 'SOI not found';
  1505. }
  1506. fileMarker = readUint16();
  1507. while (fileMarker !== 0xFFD9) { // EOI (End of image)
  1508. var i, j, l;
  1509. switch(fileMarker) {
  1510. case 0xFFE0: // APP0 (Application Specific)
  1511. case 0xFFE1: // APP1
  1512. case 0xFFE2: // APP2
  1513. case 0xFFE3: // APP3
  1514. case 0xFFE4: // APP4
  1515. case 0xFFE5: // APP5
  1516. case 0xFFE6: // APP6
  1517. case 0xFFE7: // APP7
  1518. case 0xFFE8: // APP8
  1519. case 0xFFE9: // APP9
  1520. case 0xFFEA: // APP10
  1521. case 0xFFEB: // APP11
  1522. case 0xFFEC: // APP12
  1523. case 0xFFED: // APP13
  1524. case 0xFFEE: // APP14
  1525. case 0xFFEF: // APP15
  1526. case 0xFFFE: // COM (Comment)
  1527. var appData = readDataBlock();
  1528. if (fileMarker === 0xFFE0) {
  1529. if (appData[0] === 0x4A && appData[1] === 0x46 &&
  1530. appData[2] === 0x49 && appData[3] === 0x46 &&
  1531. appData[4] === 0) { // 'JFIF\x00'
  1532. jfif = {
  1533. version: { major: appData[5], minor: appData[6] },
  1534. densityUnits: appData[7],
  1535. xDensity: (appData[8] << 8) | appData[9],
  1536. yDensity: (appData[10] << 8) | appData[11],
  1537. thumbWidth: appData[12],
  1538. thumbHeight: appData[13],
  1539. thumbData: appData.subarray(14, 14 +
  1540. 3 * appData[12] * appData[13])
  1541. };
  1542. }
  1543. }
  1544. // TODO APP1 - Exif
  1545. if (fileMarker === 0xFFEE) {
  1546. if (appData[0] === 0x41 && appData[1] === 0x64 &&
  1547. appData[2] === 0x6F && appData[3] === 0x62 &&
  1548. appData[4] === 0x65) { // 'Adobe'
  1549. adobe = {
  1550. version: (appData[5] << 8) | appData[6],
  1551. flags0: (appData[7] << 8) | appData[8],
  1552. flags1: (appData[9] << 8) | appData[10],
  1553. transformCode: appData[11]
  1554. };
  1555. }
  1556. }
  1557. break;
  1558. case 0xFFDB: // DQT (Define Quantization Tables)
  1559. var quantizationTablesLength = readUint16();
  1560. var quantizationTablesEnd = quantizationTablesLength + offset - 2;
  1561. var z;
  1562. while (offset < quantizationTablesEnd) {
  1563. var quantizationTableSpec = data[offset++];
  1564. var tableData = new Uint16Array(64);
  1565. if ((quantizationTableSpec >> 4) === 0) { // 8 bit values
  1566. for (j = 0; j < 64; j++) {
  1567. z = dctZigZag[j];
  1568. tableData[z] = data[offset++];
  1569. }
  1570. } else if ((quantizationTableSpec >> 4) === 1) { //16 bit
  1571. for (j = 0; j < 64; j++) {
  1572. z = dctZigZag[j];
  1573. tableData[z] = readUint16();
  1574. }
  1575. } else {
  1576. throw 'DQT: invalid table spec';
  1577. }
  1578. quantizationTables[quantizationTableSpec & 15] = tableData;
  1579. }
  1580. break;
  1581. case 0xFFC0: // SOF0 (Start of Frame, Baseline DCT)
  1582. case 0xFFC1: // SOF1 (Start of Frame, Extended DCT)
  1583. case 0xFFC2: // SOF2 (Start of Frame, Progressive DCT)
  1584. if (frame) {
  1585. throw 'Only single frame JPEGs supported';
  1586. }
  1587. readUint16(); // skip data length
  1588. frame = {};
  1589. frame.extended = (fileMarker === 0xFFC1);
  1590. frame.progressive = (fileMarker === 0xFFC2);
  1591. frame.precision = data[offset++];
  1592. frame.scanLines = readUint16();
  1593. frame.samplesPerLine = readUint16();
  1594. frame.components = [];
  1595. frame.componentIds = {};
  1596. var componentsCount = data[offset++], componentId;
  1597. var maxH = 0, maxV = 0;
  1598. for (i = 0; i < componentsCount; i++) {
  1599. componentId = data[offset];
  1600. var h = data[offset + 1] >> 4;
  1601. var v = data[offset + 1] & 15;
  1602. if (maxH < h) {
  1603. maxH = h;
  1604. }
  1605. if (maxV < v) {
  1606. maxV = v;
  1607. }
  1608. var qId = data[offset + 2];
  1609. l = frame.components.push({
  1610. h: h,
  1611. v: v,
  1612. quantizationTable: quantizationTables[qId]
  1613. });
  1614. frame.componentIds[componentId] = l - 1;
  1615. offset += 3;
  1616. }
  1617. frame.maxH = maxH;
  1618. frame.maxV = maxV;
  1619. prepareComponents(frame);
  1620. break;
  1621. case 0xFFC4: // DHT (Define Huffman Tables)
  1622. var huffmanLength = readUint16();
  1623. for (i = 2; i < huffmanLength;) {
  1624. var huffmanTableSpec = data[offset++];
  1625. var codeLengths = new Uint8Array(16);
  1626. var codeLengthSum = 0;
  1627. for (j = 0; j < 16; j++, offset++) {
  1628. codeLengthSum += (codeLengths[j] = data[offset]);
  1629. }
  1630. var huffmanValues = new Uint8Array(codeLengthSum);
  1631. for (j = 0; j < codeLengthSum; j++, offset++) {
  1632. huffmanValues[j] = data[offset];
  1633. }
  1634. i += 17 + codeLengthSum;
  1635. ((huffmanTableSpec >> 4) === 0 ?
  1636. huffmanTablesDC : huffmanTablesAC)[huffmanTableSpec & 15] =
  1637. buildHuffmanTable(codeLengths, huffmanValues);
  1638. }
  1639. break;
  1640. case 0xFFDD: // DRI (Define Restart Interval)
  1641. readUint16(); // skip data length
  1642. resetInterval = readUint16();
  1643. break;
  1644. case 0xFFDA: // SOS (Start of Scan)
  1645. var scanLength = readUint16();
  1646. var selectorsCount = data[offset++];
  1647. var components = [], component;
  1648. for (i = 0; i < selectorsCount; i++) {
  1649. var componentIndex = frame.componentIds[data[offset++]];
  1650. component = frame.components[componentIndex];
  1651. var tableSpec = data[offset++];
  1652. component.huffmanTableDC = huffmanTablesDC[tableSpec >> 4];
  1653. component.huffmanTableAC = huffmanTablesAC[tableSpec & 15];
  1654. components.push(component);
  1655. }
  1656. var spectralStart = data[offset++];
  1657. var spectralEnd = data[offset++];
  1658. var successiveApproximation = data[offset++];
  1659. var processed = decodeScan(data, offset,
  1660. frame, components, resetInterval,
  1661. spectralStart, spectralEnd,
  1662. successiveApproximation >> 4, successiveApproximation & 15);
  1663. offset += processed;
  1664. break;
  1665. case 0xFFFF: // Fill bytes
  1666. if (data[offset] !== 0xFF) { // Avoid skipping a valid marker.
  1667. offset--;
  1668. }
  1669. break;
  1670. default:
  1671. if (data[offset - 3] === 0xFF &&
  1672. data[offset - 2] >= 0xC0 && data[offset - 2] <= 0xFE) {
  1673. // could be incorrect encoding -- last 0xFF byte of the previous
  1674. // block was eaten by the encoder
  1675. offset -= 3;
  1676. break;
  1677. }
  1678. throw 'unknown JPEG marker ' + fileMarker.toString(16);
  1679. }
  1680. fileMarker = readUint16();
  1681. }
  1682. this.width = frame.samplesPerLine;
  1683. this.height = frame.scanLines;
  1684. this.jfif = jfif;
  1685. this.adobe = adobe;
  1686. this.components = [];
  1687. for (i = 0; i < frame.components.length; i++) {
  1688. component = frame.components[i];
  1689. this.components.push({
  1690. output: buildComponentData(frame, component),
  1691. scaleX: component.h / frame.maxH,
  1692. scaleY: component.v / frame.maxV,
  1693. blocksPerLine: component.blocksPerLine,
  1694. blocksPerColumn: component.blocksPerColumn
  1695. });
  1696. }
  1697. this.numComponents = this.components.length;
  1698. },
  1699. _getLinearizedBlockData: function getLinearizedBlockData(width, height) {
  1700. var scaleX = this.width / width, scaleY = this.height / height;
  1701. var component, componentScaleX, componentScaleY, blocksPerScanline;
  1702. var x, y, i, j, k;
  1703. var index;
  1704. var offset = 0;
  1705. var output;
  1706. var numComponents = this.components.length;
  1707. var dataLength = width * height * numComponents;
  1708. var data = new Uint8Array(dataLength);
  1709. var xScaleBlockOffset = new Uint32Array(width);
  1710. var mask3LSB = 0xfffffff8; // used to clear the 3 LSBs
  1711. for (i = 0; i < numComponents; i++) {
  1712. component = this.components[i];
  1713. componentScaleX = component.scaleX * scaleX;
  1714. componentScaleY = component.scaleY * scaleY;
  1715. offset = i;
  1716. output = component.output;
  1717. blocksPerScanline = (component.blocksPerLine + 1) << 3;
  1718. // precalculate the xScaleBlockOffset
  1719. for (x = 0; x < width; x++) {
  1720. j = 0 | (x * componentScaleX);
  1721. xScaleBlockOffset[x] = ((j & mask3LSB) << 3) | (j & 7);
  1722. }
  1723. // linearize the blocks of the component
  1724. for (y = 0; y < height; y++) {
  1725. j = 0 | (y * componentScaleY);
  1726. index = blocksPerScanline * (j & mask3LSB) | ((j & 7) << 3);
  1727. for (x = 0; x < width; x++) {
  1728. data[offset] = output[index + xScaleBlockOffset[x]];
  1729. offset += numComponents;
  1730. }
  1731. }
  1732. }
  1733. // decodeTransform contains pairs of multiplier (-256..256) and additive
  1734. var transform = this.decodeTransform;
  1735. if (transform) {
  1736. for (i = 0; i < dataLength;) {
  1737. for (j = 0, k = 0; j < numComponents; j++, i++, k += 2) {
  1738. data[i] = ((data[i] * transform[k]) >> 8) + transform[k + 1];
  1739. }
  1740. }
  1741. }
  1742. return data;
  1743. },
  1744. _isColorConversionNeeded: function isColorConversionNeeded() {
  1745. if (this.adobe && this.adobe.transformCode) {
  1746. // The adobe transform marker overrides any previous setting
  1747. return true;
  1748. } else if (this.numComponents === 3) {
  1749. return true;
  1750. } else {
  1751. return false;
  1752. }
  1753. },
  1754. _convertYccToRgb: function convertYccToRgb(data) {
  1755. var Y, Cb, Cr;
  1756. for (var i = 0, length = data.length; i < length; i += 3) {
  1757. Y = data[i ];
  1758. Cb = data[i + 1];
  1759. Cr = data[i + 2];
  1760. data[i ] = clamp0to255(Y - 179.456 + 1.402 * Cr);
  1761. data[i + 1] = clamp0to255(Y + 135.459 - 0.344 * Cb - 0.714 * Cr);
  1762. data[i + 2] = clamp0to255(Y - 226.816 + 1.772 * Cb);
  1763. }
  1764. return data;
  1765. },
  1766. _convertYcckToRgb: function convertYcckToRgb(data) {
  1767. var Y, Cb, Cr, k;
  1768. var offset = 0;
  1769. for (var i = 0, length = data.length; i < length; i += 4) {
  1770. Y = data[i];
  1771. Cb = data[i + 1];
  1772. Cr = data[i + 2];
  1773. k = data[i + 3];
  1774. var r = -122.67195406894 +
  1775. Cb * (-6.60635669420364e-5 * Cb + 0.000437130475926232 * Cr -
  1776. 5.4080610064599e-5 * Y + 0.00048449797120281 * k -
  1777. 0.154362151871126) +
  1778. Cr * (-0.000957964378445773 * Cr + 0.000817076911346625 * Y -
  1779. 0.00477271405408747 * k + 1.53380253221734) +
  1780. Y * (0.000961250184130688 * Y - 0.00266257332283933 * k +
  1781. 0.48357088451265) +
  1782. k * (-0.000336197177618394 * k + 0.484791561490776);
  1783. var g = 107.268039397724 +
  1784. Cb * (2.19927104525741e-5 * Cb - 0.000640992018297945 * Cr +
  1785. 0.000659397001245577 * Y + 0.000426105652938837 * k -
  1786. 0.176491792462875) +
  1787. Cr * (-0.000778269941513683 * Cr + 0.00130872261408275 * Y +
  1788. 0.000770482631801132 * k - 0.151051492775562) +
  1789. Y * (0.00126935368114843 * Y - 0.00265090189010898 * k +
  1790. 0.25802910206845) +
  1791. k * (-0.000318913117588328 * k - 0.213742400323665);
  1792. var b = -20.810012546947 +
  1793. Cb * (-0.000570115196973677 * Cb - 2.63409051004589e-5 * Cr +
  1794. 0.0020741088115012 * Y - 0.00288260236853442 * k +
  1795. 0.814272968359295) +
  1796. Cr * (-1.53496057440975e-5 * Cr - 0.000132689043961446 * Y +
  1797. 0.000560833691242812 * k - 0.195152027534049) +
  1798. Y * (0.00174418132927582 * Y - 0.00255243321439347 * k +
  1799. 0.116935020465145) +
  1800. k * (-0.000343531996510555 * k + 0.24165260232407);
  1801. data[offset++] = clamp0to255(r);
  1802. data[offset++] = clamp0to255(g);
  1803. data[offset++] = clamp0to255(b);
  1804. }
  1805. return data;
  1806. },
  1807. _convertYcckToCmyk: function convertYcckToCmyk(data) {
  1808. var Y, Cb, Cr;
  1809. for (var i = 0, length = data.length; i < length; i += 4) {
  1810. Y = data[i];
  1811. Cb = data[i + 1];
  1812. Cr = data[i + 2];
  1813. data[i ] = clamp0to255(434.456 - Y - 1.402 * Cr);
  1814. data[i + 1] = clamp0to255(119.541 - Y + 0.344 * Cb + 0.714 * Cr);
  1815. data[i + 2] = clamp0to255(481.816 - Y - 1.772 * Cb);
  1816. // K in data[i + 3] is unchanged
  1817. }
  1818. return data;
  1819. },
  1820. _convertCmykToRgb: function convertCmykToRgb(data) {
  1821. var c, m, y, k;
  1822. var offset = 0;
  1823. var min = -255 * 255 * 255;
  1824. var scale = 1 / 255 / 255;
  1825. for (var i = 0, length = data.length; i < length; i += 4) {
  1826. c = data[i];
  1827. m = data[i + 1];
  1828. y = data[i + 2];
  1829. k = data[i + 3];
  1830. var r =
  1831. c * (-4.387332384609988 * c + 54.48615194189176 * m +
  1832. 18.82290502165302 * y + 212.25662451639585 * k -
  1833. 72734.4411664936) +
  1834. m * (1.7149763477362134 * m - 5.6096736904047315 * y -
  1835. 17.873870861415444 * k - 1401.7366389350734) +
  1836. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  1837. 4465.541406466231) -
  1838. k * (21.86122147463605 * k + 48317.86113160301);
  1839. var g =
  1840. c * (8.841041422036149 * c + 60.118027045597366 * m +
  1841. 6.871425592049007 * y + 31.159100130055922 * k -
  1842. 20220.756542821975) +
  1843. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  1844. 131.35250912493976 * k - 48691.05921601825) +
  1845. y * (4.444339102852739 * y + 9.8632861493405 * k -
  1846. 6341.191035517494) -
  1847. k * (20.737325471181034 * k + 47890.15695978492);
  1848. var b =
  1849. c * (0.8842522430003296 * c + 8.078677503112928 * m +
  1850. 30.89978309703729 * y - 0.23883238689178934 * k -
  1851. 3616.812083916688) +
  1852. m * (10.49593273432072 * m + 63.02378494754052 * y +
  1853. 50.606957656360734 * k - 28620.90484698408) +
  1854. y * (0.03296041114873217 * y + 115.60384449646641 * k -
  1855. 49363.43385999684) -
  1856. k * (22.33816807309886 * k + 45932.16563550634);
  1857. data[offset++] = r >= 0 ? 255 : r <= min ? 0 : 255 + r * scale | 0;
  1858. data[offset++] = g >= 0 ? 255 : g <= min ? 0 : 255 + g * scale | 0;
  1859. data[offset++] = b >= 0 ? 255 : b <= min ? 0 : 255 + b * scale | 0;
  1860. }
  1861. return data;
  1862. },
  1863. getData: function getData(width, height, forceRGBoutput) {
  1864. if (this.numComponents > 4) {
  1865. throw 'Unsupported color mode';
  1866. }
  1867. // type of data: Uint8Array(width * height * numComponents)
  1868. var data = this._getLinearizedBlockData(width, height);
  1869. if (this.numComponents === 1 && forceRGBoutput) {
  1870. var dataLength = data.length;
  1871. var rgbData = new Uint8Array(dataLength * 3);
  1872. var offset = 0;
  1873. for (var i = 0; i < dataLength; i++) {
  1874. var grayColor = data[i];
  1875. rgbData[offset++] = grayColor;
  1876. rgbData[offset++] = grayColor;
  1877. rgbData[offset++] = grayColor;
  1878. }
  1879. return rgbData;
  1880. } else if (this.numComponents === 3) {
  1881. return this._convertYccToRgb(data);
  1882. } else if (this.numComponents === 4) {
  1883. if (this._isColorConversionNeeded()) {
  1884. if (forceRGBoutput) {
  1885. return this._convertYcckToRgb(data);
  1886. } else {
  1887. return this._convertYcckToCmyk(data);
  1888. }
  1889. } else if (forceRGBoutput) {
  1890. return this._convertCmykToRgb(data);
  1891. }
  1892. }
  1893. return data;
  1894. }
  1895. };
  1896. return constructor;
  1897. })();
  1898. exports.JpegImage = JpegImage;
  1899. }));
  1900. (function (root, factory) {
  1901. {
  1902. factory((root.pdfjsSharedUtil = {}));
  1903. }
  1904. }(this, function (exports) {
  1905. var globalScope = (typeof window !== 'undefined') ? window :
  1906. (typeof global !== 'undefined') ? global :
  1907. (typeof self !== 'undefined') ? self : this;
  1908. var FONT_IDENTITY_MATRIX = [0.001, 0, 0, 0.001, 0, 0];
  1909. var TextRenderingMode = {
  1910. FILL: 0,
  1911. STROKE: 1,
  1912. FILL_STROKE: 2,
  1913. INVISIBLE: 3,
  1914. FILL_ADD_TO_PATH: 4,
  1915. STROKE_ADD_TO_PATH: 5,
  1916. FILL_STROKE_ADD_TO_PATH: 6,
  1917. ADD_TO_PATH: 7,
  1918. FILL_STROKE_MASK: 3,
  1919. ADD_TO_PATH_FLAG: 4
  1920. };
  1921. var ImageKind = {
  1922. GRAYSCALE_1BPP: 1,
  1923. RGB_24BPP: 2,
  1924. RGBA_32BPP: 3
  1925. };
  1926. var AnnotationType = {
  1927. TEXT: 1,
  1928. LINK: 2,
  1929. FREETEXT: 3,
  1930. LINE: 4,
  1931. SQUARE: 5,
  1932. CIRCLE: 6,
  1933. POLYGON: 7,
  1934. POLYLINE: 8,
  1935. HIGHLIGHT: 9,
  1936. UNDERLINE: 10,
  1937. SQUIGGLY: 11,
  1938. STRIKEOUT: 12,
  1939. STAMP: 13,
  1940. CARET: 14,
  1941. INK: 15,
  1942. POPUP: 16,
  1943. FILEATTACHMENT: 17,
  1944. SOUND: 18,
  1945. MOVIE: 19,
  1946. WIDGET: 20,
  1947. SCREEN: 21,
  1948. PRINTERMARK: 22,
  1949. TRAPNET: 23,
  1950. WATERMARK: 24,
  1951. THREED: 25,
  1952. REDACT: 26
  1953. };
  1954. var AnnotationFlag = {
  1955. INVISIBLE: 0x01,
  1956. HIDDEN: 0x02,
  1957. PRINT: 0x04,
  1958. NOZOOM: 0x08,
  1959. NOROTATE: 0x10,
  1960. NOVIEW: 0x20,
  1961. READONLY: 0x40,
  1962. LOCKED: 0x80,
  1963. TOGGLENOVIEW: 0x100,
  1964. LOCKEDCONTENTS: 0x200
  1965. };
  1966. var AnnotationBorderStyleType = {
  1967. SOLID: 1,
  1968. DASHED: 2,
  1969. BEVELED: 3,
  1970. INSET: 4,
  1971. UNDERLINE: 5
  1972. };
  1973. var StreamType = {
  1974. UNKNOWN: 0,
  1975. FLATE: 1,
  1976. LZW: 2,
  1977. DCT: 3,
  1978. JPX: 4,
  1979. JBIG: 5,
  1980. A85: 6,
  1981. AHX: 7,
  1982. CCF: 8,
  1983. RL: 9
  1984. };
  1985. var FontType = {
  1986. UNKNOWN: 0,
  1987. TYPE1: 1,
  1988. TYPE1C: 2,
  1989. CIDFONTTYPE0: 3,
  1990. CIDFONTTYPE0C: 4,
  1991. TRUETYPE: 5,
  1992. CIDFONTTYPE2: 6,
  1993. TYPE3: 7,
  1994. OPENTYPE: 8,
  1995. TYPE0: 9,
  1996. MMTYPE1: 10
  1997. };
  1998. var VERBOSITY_LEVELS = {
  1999. errors: 0,
  2000. warnings: 1,
  2001. infos: 5
  2002. };
  2003. // All the possible operations for an operator list.
  2004. var OPS = {
  2005. // Intentionally start from 1 so it is easy to spot bad operators that will be
  2006. // 0's.
  2007. dependency: 1,
  2008. setLineWidth: 2,
  2009. setLineCap: 3,
  2010. setLineJoin: 4,
  2011. setMiterLimit: 5,
  2012. setDash: 6,
  2013. setRenderingIntent: 7,
  2014. setFlatness: 8,
  2015. setGState: 9,
  2016. save: 10,
  2017. restore: 11,
  2018. transform: 12,
  2019. moveTo: 13,
  2020. lineTo: 14,
  2021. curveTo: 15,
  2022. curveTo2: 16,
  2023. curveTo3: 17,
  2024. closePath: 18,
  2025. rectangle: 19,
  2026. stroke: 20,
  2027. closeStroke: 21,
  2028. fill: 22,
  2029. eoFill: 23,
  2030. fillStroke: 24,
  2031. eoFillStroke: 25,
  2032. closeFillStroke: 26,
  2033. closeEOFillStroke: 27,
  2034. endPath: 28,
  2035. clip: 29,
  2036. eoClip: 30,
  2037. beginText: 31,
  2038. endText: 32,
  2039. setCharSpacing: 33,
  2040. setWordSpacing: 34,
  2041. setHScale: 35,
  2042. setLeading: 36,
  2043. setFont: 37,
  2044. setTextRenderingMode: 38,
  2045. setTextRise: 39,
  2046. moveText: 40,
  2047. setLeadingMoveText: 41,
  2048. setTextMatrix: 42,
  2049. nextLine: 43,
  2050. showText: 44,
  2051. showSpacedText: 45,
  2052. nextLineShowText: 46,
  2053. nextLineSetSpacingShowText: 47,
  2054. setCharWidth: 48,
  2055. setCharWidthAndBounds: 49,
  2056. setStrokeColorSpace: 50,
  2057. setFillColorSpace: 51,
  2058. setStrokeColor: 52,
  2059. setStrokeColorN: 53,
  2060. setFillColor: 54,
  2061. setFillColorN: 55,
  2062. setStrokeGray: 56,
  2063. setFillGray: 57,
  2064. setStrokeRGBColor: 58,
  2065. setFillRGBColor: 59,
  2066. setStrokeCMYKColor: 60,
  2067. setFillCMYKColor: 61,
  2068. shadingFill: 62,
  2069. beginInlineImage: 63,
  2070. beginImageData: 64,
  2071. endInlineImage: 65,
  2072. paintXObject: 66,
  2073. markPoint: 67,
  2074. markPointProps: 68,
  2075. beginMarkedContent: 69,
  2076. beginMarkedContentProps: 70,
  2077. endMarkedContent: 71,
  2078. beginCompat: 72,
  2079. endCompat: 73,
  2080. paintFormXObjectBegin: 74,
  2081. paintFormXObjectEnd: 75,
  2082. beginGroup: 76,
  2083. endGroup: 77,
  2084. beginAnnotations: 78,
  2085. endAnnotations: 79,
  2086. beginAnnotation: 80,
  2087. endAnnotation: 81,
  2088. paintJpegXObject: 82,
  2089. paintImageMaskXObject: 83,
  2090. paintImageMaskXObjectGroup: 84,
  2091. paintImageXObject: 85,
  2092. paintInlineImageXObject: 86,
  2093. paintInlineImageXObjectGroup: 87,
  2094. paintImageXObjectRepeat: 88,
  2095. paintImageMaskXObjectRepeat: 89,
  2096. paintSolidColorImageMask: 90,
  2097. constructPath: 91
  2098. };
  2099. var verbosity = VERBOSITY_LEVELS.warnings;
  2100. function setVerbosityLevel(level) {
  2101. verbosity = level;
  2102. }
  2103. function getVerbosityLevel() {
  2104. return verbosity;
  2105. }
  2106. // A notice for devs. These are good for things that are helpful to devs, such
  2107. // as warning that Workers were disabled, which is important to devs but not
  2108. // end users.
  2109. function info(msg) {
  2110. if (verbosity >= VERBOSITY_LEVELS.infos) {
  2111. console.log('Info: ' + msg);
  2112. }
  2113. }
  2114. // Non-fatal warnings.
  2115. function warn(msg) {
  2116. if (verbosity >= VERBOSITY_LEVELS.warnings) {
  2117. console.log('Warning: ' + msg);
  2118. }
  2119. }
  2120. // Deprecated API function -- display regardless of the PDFJS.verbosity setting.
  2121. function deprecated(details) {
  2122. console.log('Deprecated API usage: ' + details);
  2123. }
  2124. // Fatal errors that should trigger the fallback UI and halt execution by
  2125. // throwing an exception.
  2126. function error(msg) {
  2127. if (verbosity >= VERBOSITY_LEVELS.errors) {
  2128. console.log('Error: ' + msg);
  2129. console.log(backtrace());
  2130. }
  2131. throw new Error(msg);
  2132. }
  2133. function backtrace() {
  2134. try {
  2135. throw new Error();
  2136. } catch (e) {
  2137. return e.stack ? e.stack.split('\n').slice(2).join('\n') : '';
  2138. }
  2139. }
  2140. function assert(cond, msg) {
  2141. if (!cond) {
  2142. error(msg);
  2143. }
  2144. }
  2145. var UNSUPPORTED_FEATURES = {
  2146. unknown: 'unknown',
  2147. forms: 'forms',
  2148. javaScript: 'javaScript',
  2149. smask: 'smask',
  2150. shadingPattern: 'shadingPattern',
  2151. font: 'font'
  2152. };
  2153. // Combines two URLs. The baseUrl shall be absolute URL. If the url is an
  2154. // absolute URL, it will be returned as is.
  2155. function combineUrl(baseUrl, url) {
  2156. if (!url) {
  2157. return baseUrl;
  2158. }
  2159. return new URL(url, baseUrl).href;
  2160. }
  2161. // Checks if URLs have the same origin. For non-HTTP based URLs, returns false.
  2162. function isSameOrigin(baseUrl, otherUrl) {
  2163. try {
  2164. var base = new URL(baseUrl);
  2165. if (!base.origin || base.origin === 'null') {
  2166. return false; // non-HTTP url
  2167. }
  2168. } catch (e) {
  2169. return false;
  2170. }
  2171. var other = new URL(otherUrl, base);
  2172. return base.origin === other.origin;
  2173. }
  2174. // Validates if URL is safe and allowed, e.g. to avoid XSS.
  2175. function isValidUrl(url, allowRelative) {
  2176. if (!url) {
  2177. return false;
  2178. }
  2179. // RFC 3986 (http://tools.ietf.org/html/rfc3986#section-3.1)
  2180. // scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
  2181. var protocol = /^[a-z][a-z0-9+\-.]*(?=:)/i.exec(url);
  2182. if (!protocol) {
  2183. return allowRelative;
  2184. }
  2185. protocol = protocol[0].toLowerCase();
  2186. switch (protocol) {
  2187. case 'http':
  2188. case 'https':
  2189. case 'ftp':
  2190. case 'mailto':
  2191. case 'tel':
  2192. return true;
  2193. default:
  2194. return false;
  2195. }
  2196. }
  2197. function shadow(obj, prop, value) {
  2198. Object.defineProperty(obj, prop, { value: value,
  2199. enumerable: true,
  2200. configurable: true,
  2201. writable: false });
  2202. return value;
  2203. }
  2204. function getLookupTableFactory(initializer) {
  2205. var lookup;
  2206. return function () {
  2207. if (initializer) {
  2208. lookup = Object.create(null);
  2209. initializer(lookup);
  2210. initializer = null;
  2211. }
  2212. return lookup;
  2213. };
  2214. }
  2215. var PasswordResponses = {
  2216. NEED_PASSWORD: 1,
  2217. INCORRECT_PASSWORD: 2
  2218. };
  2219. var PasswordException = (function PasswordExceptionClosure() {
  2220. function PasswordException(msg, code) {
  2221. this.name = 'PasswordException';
  2222. this.message = msg;
  2223. this.code = code;
  2224. }
  2225. PasswordException.prototype = new Error();
  2226. PasswordException.constructor = PasswordException;
  2227. return PasswordException;
  2228. })();
  2229. var UnknownErrorException = (function UnknownErrorExceptionClosure() {
  2230. function UnknownErrorException(msg, details) {
  2231. this.name = 'UnknownErrorException';
  2232. this.message = msg;
  2233. this.details = details;
  2234. }
  2235. UnknownErrorException.prototype = new Error();
  2236. UnknownErrorException.constructor = UnknownErrorException;
  2237. return UnknownErrorException;
  2238. })();
  2239. var InvalidPDFException = (function InvalidPDFExceptionClosure() {
  2240. function InvalidPDFException(msg) {
  2241. this.name = 'InvalidPDFException';
  2242. this.message = msg;
  2243. }
  2244. InvalidPDFException.prototype = new Error();
  2245. InvalidPDFException.constructor = InvalidPDFException;
  2246. return InvalidPDFException;
  2247. })();
  2248. var MissingPDFException = (function MissingPDFExceptionClosure() {
  2249. function MissingPDFException(msg) {
  2250. this.name = 'MissingPDFException';
  2251. this.message = msg;
  2252. }
  2253. MissingPDFException.prototype = new Error();
  2254. MissingPDFException.constructor = MissingPDFException;
  2255. return MissingPDFException;
  2256. })();
  2257. var UnexpectedResponseException =
  2258. (function UnexpectedResponseExceptionClosure() {
  2259. function UnexpectedResponseException(msg, status) {
  2260. this.name = 'UnexpectedResponseException';
  2261. this.message = msg;
  2262. this.status = status;
  2263. }
  2264. UnexpectedResponseException.prototype = new Error();
  2265. UnexpectedResponseException.constructor = UnexpectedResponseException;
  2266. return UnexpectedResponseException;
  2267. })();
  2268. var NotImplementedException = (function NotImplementedExceptionClosure() {
  2269. function NotImplementedException(msg) {
  2270. this.message = msg;
  2271. }
  2272. NotImplementedException.prototype = new Error();
  2273. NotImplementedException.prototype.name = 'NotImplementedException';
  2274. NotImplementedException.constructor = NotImplementedException;
  2275. return NotImplementedException;
  2276. })();
  2277. var MissingDataException = (function MissingDataExceptionClosure() {
  2278. function MissingDataException(begin, end) {
  2279. this.begin = begin;
  2280. this.end = end;
  2281. this.message = 'Missing data [' + begin + ', ' + end + ')';
  2282. }
  2283. MissingDataException.prototype = new Error();
  2284. MissingDataException.prototype.name = 'MissingDataException';
  2285. MissingDataException.constructor = MissingDataException;
  2286. return MissingDataException;
  2287. })();
  2288. var XRefParseException = (function XRefParseExceptionClosure() {
  2289. function XRefParseException(msg) {
  2290. this.message = msg;
  2291. }
  2292. XRefParseException.prototype = new Error();
  2293. XRefParseException.prototype.name = 'XRefParseException';
  2294. XRefParseException.constructor = XRefParseException;
  2295. return XRefParseException;
  2296. })();
  2297. var NullCharactersRegExp = /\x00/g;
  2298. function removeNullCharacters(str) {
  2299. if (typeof str !== 'string') {
  2300. warn('The argument for removeNullCharacters must be a string.');
  2301. return str;
  2302. }
  2303. return str.replace(NullCharactersRegExp, '');
  2304. }
  2305. function bytesToString(bytes) {
  2306. assert(bytes !== null && typeof bytes === 'object' &&
  2307. bytes.length !== undefined, 'Invalid argument for bytesToString');
  2308. var length = bytes.length;
  2309. var MAX_ARGUMENT_COUNT = 8192;
  2310. if (length < MAX_ARGUMENT_COUNT) {
  2311. return String.fromCharCode.apply(null, bytes);
  2312. }
  2313. var strBuf = [];
  2314. for (var i = 0; i < length; i += MAX_ARGUMENT_COUNT) {
  2315. var chunkEnd = Math.min(i + MAX_ARGUMENT_COUNT, length);
  2316. var chunk = bytes.subarray(i, chunkEnd);
  2317. strBuf.push(String.fromCharCode.apply(null, chunk));
  2318. }
  2319. return strBuf.join('');
  2320. }
  2321. function stringToBytes(str) {
  2322. assert(typeof str === 'string', 'Invalid argument for stringToBytes');
  2323. var length = str.length;
  2324. var bytes = new Uint8Array(length);
  2325. for (var i = 0; i < length; ++i) {
  2326. bytes[i] = str.charCodeAt(i) & 0xFF;
  2327. }
  2328. return bytes;
  2329. }
  2330. /**
  2331. * Gets length of the array (Array, Uint8Array, or string) in bytes.
  2332. * @param {Array|Uint8Array|string} arr
  2333. * @returns {number}
  2334. */
  2335. function arrayByteLength(arr) {
  2336. if (arr.length !== undefined) {
  2337. return arr.length;
  2338. }
  2339. assert(arr.byteLength !== undefined);
  2340. return arr.byteLength;
  2341. }
  2342. /**
  2343. * Combines array items (arrays) into single Uint8Array object.
  2344. * @param {Array} arr - the array of the arrays (Array, Uint8Array, or string).
  2345. * @returns {Uint8Array}
  2346. */
  2347. function arraysToBytes(arr) {
  2348. // Shortcut: if first and only item is Uint8Array, return it.
  2349. if (arr.length === 1 && (arr[0] instanceof Uint8Array)) {
  2350. return arr[0];
  2351. }
  2352. var resultLength = 0;
  2353. var i, ii = arr.length;
  2354. var item, itemLength ;
  2355. for (i = 0; i < ii; i++) {
  2356. item = arr[i];
  2357. itemLength = arrayByteLength(item);
  2358. resultLength += itemLength;
  2359. }
  2360. var pos = 0;
  2361. var data = new Uint8Array(resultLength);
  2362. for (i = 0; i < ii; i++) {
  2363. item = arr[i];
  2364. if (!(item instanceof Uint8Array)) {
  2365. if (typeof item === 'string') {
  2366. item = stringToBytes(item);
  2367. } else {
  2368. item = new Uint8Array(item);
  2369. }
  2370. }
  2371. itemLength = item.byteLength;
  2372. data.set(item, pos);
  2373. pos += itemLength;
  2374. }
  2375. return data;
  2376. }
  2377. function string32(value) {
  2378. return String.fromCharCode((value >> 24) & 0xff, (value >> 16) & 0xff,
  2379. (value >> 8) & 0xff, value & 0xff);
  2380. }
  2381. function log2(x) {
  2382. var n = 1, i = 0;
  2383. while (x > n) {
  2384. n <<= 1;
  2385. i++;
  2386. }
  2387. return i;
  2388. }
  2389. function readInt8(data, start) {
  2390. return (data[start] << 24) >> 24;
  2391. }
  2392. function readUint16(data, offset) {
  2393. return (data[offset] << 8) | data[offset + 1];
  2394. }
  2395. function readUint32(data, offset) {
  2396. return ((data[offset] << 24) | (data[offset + 1] << 16) |
  2397. (data[offset + 2] << 8) | data[offset + 3]) >>> 0;
  2398. }
  2399. // Lazy test the endianness of the platform
  2400. // NOTE: This will be 'true' for simulated TypedArrays
  2401. function isLittleEndian() {
  2402. var buffer8 = new Uint8Array(2);
  2403. buffer8[0] = 1;
  2404. var buffer16 = new Uint16Array(buffer8.buffer);
  2405. return (buffer16[0] === 1);
  2406. }
  2407. var Uint32ArrayView = (function Uint32ArrayViewClosure() {
  2408. function Uint32ArrayView(buffer, length) {
  2409. this.buffer = buffer;
  2410. this.byteLength = buffer.length;
  2411. this.length = length === undefined ? (this.byteLength >> 2) : length;
  2412. ensureUint32ArrayViewProps(this.length);
  2413. }
  2414. Uint32ArrayView.prototype = Object.create(null);
  2415. var uint32ArrayViewSetters = 0;
  2416. function createUint32ArrayProp(index) {
  2417. return {
  2418. get: function () {
  2419. var buffer = this.buffer, offset = index << 2;
  2420. return (buffer[offset] | (buffer[offset + 1] << 8) |
  2421. (buffer[offset + 2] << 16) | (buffer[offset + 3] << 24)) >>> 0;
  2422. },
  2423. set: function (value) {
  2424. var buffer = this.buffer, offset = index << 2;
  2425. buffer[offset] = value & 255;
  2426. buffer[offset + 1] = (value >> 8) & 255;
  2427. buffer[offset + 2] = (value >> 16) & 255;
  2428. buffer[offset + 3] = (value >>> 24) & 255;
  2429. }
  2430. };
  2431. }
  2432. function ensureUint32ArrayViewProps(length) {
  2433. while (uint32ArrayViewSetters < length) {
  2434. Object.defineProperty(Uint32ArrayView.prototype,
  2435. uint32ArrayViewSetters,
  2436. createUint32ArrayProp(uint32ArrayViewSetters));
  2437. uint32ArrayViewSetters++;
  2438. }
  2439. }
  2440. return Uint32ArrayView;
  2441. })();
  2442. exports.Uint32ArrayView = Uint32ArrayView;
  2443. var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
  2444. var Util = (function UtilClosure() {
  2445. function Util() {}
  2446. var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
  2447. // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
  2448. // creating many intermediate strings.
  2449. Util.makeCssRgb = function Util_makeCssRgb(r, g, b) {
  2450. rgbBuf[1] = r;
  2451. rgbBuf[3] = g;
  2452. rgbBuf[5] = b;
  2453. return rgbBuf.join('');
  2454. };
  2455. // Concatenates two transformation matrices together and returns the result.
  2456. Util.transform = function Util_transform(m1, m2) {
  2457. return [
  2458. m1[0] * m2[0] + m1[2] * m2[1],
  2459. m1[1] * m2[0] + m1[3] * m2[1],
  2460. m1[0] * m2[2] + m1[2] * m2[3],
  2461. m1[1] * m2[2] + m1[3] * m2[3],
  2462. m1[0] * m2[4] + m1[2] * m2[5] + m1[4],
  2463. m1[1] * m2[4] + m1[3] * m2[5] + m1[5]
  2464. ];
  2465. };
  2466. // For 2d affine transforms
  2467. Util.applyTransform = function Util_applyTransform(p, m) {
  2468. var xt = p[0] * m[0] + p[1] * m[2] + m[4];
  2469. var yt = p[0] * m[1] + p[1] * m[3] + m[5];
  2470. return [xt, yt];
  2471. };
  2472. Util.applyInverseTransform = function Util_applyInverseTransform(p, m) {
  2473. var d = m[0] * m[3] - m[1] * m[2];
  2474. var xt = (p[0] * m[3] - p[1] * m[2] + m[2] * m[5] - m[4] * m[3]) / d;
  2475. var yt = (-p[0] * m[1] + p[1] * m[0] + m[4] * m[1] - m[5] * m[0]) / d;
  2476. return [xt, yt];
  2477. };
  2478. // Applies the transform to the rectangle and finds the minimum axially
  2479. // aligned bounding box.
  2480. Util.getAxialAlignedBoundingBox =
  2481. function Util_getAxialAlignedBoundingBox(r, m) {
  2482. var p1 = Util.applyTransform(r, m);
  2483. var p2 = Util.applyTransform(r.slice(2, 4), m);
  2484. var p3 = Util.applyTransform([r[0], r[3]], m);
  2485. var p4 = Util.applyTransform([r[2], r[1]], m);
  2486. return [
  2487. Math.min(p1[0], p2[0], p3[0], p4[0]),
  2488. Math.min(p1[1], p2[1], p3[1], p4[1]),
  2489. Math.max(p1[0], p2[0], p3[0], p4[0]),
  2490. Math.max(p1[1], p2[1], p3[1], p4[1])
  2491. ];
  2492. };
  2493. Util.inverseTransform = function Util_inverseTransform(m) {
  2494. var d = m[0] * m[3] - m[1] * m[2];
  2495. return [m[3] / d, -m[1] / d, -m[2] / d, m[0] / d,
  2496. (m[2] * m[5] - m[4] * m[3]) / d, (m[4] * m[1] - m[5] * m[0]) / d];
  2497. };
  2498. // Apply a generic 3d matrix M on a 3-vector v:
  2499. // | a b c | | X |
  2500. // | d e f | x | Y |
  2501. // | g h i | | Z |
  2502. // M is assumed to be serialized as [a,b,c,d,e,f,g,h,i],
  2503. // with v as [X,Y,Z]
  2504. Util.apply3dTransform = function Util_apply3dTransform(m, v) {
  2505. return [
  2506. m[0] * v[0] + m[1] * v[1] + m[2] * v[2],
  2507. m[3] * v[0] + m[4] * v[1] + m[5] * v[2],
  2508. m[6] * v[0] + m[7] * v[1] + m[8] * v[2]
  2509. ];
  2510. };
  2511. // This calculation uses Singular Value Decomposition.
  2512. // The SVD can be represented with formula A = USV. We are interested in the
  2513. // matrix S here because it represents the scale values.
  2514. Util.singularValueDecompose2dScale =
  2515. function Util_singularValueDecompose2dScale(m) {
  2516. var transpose = [m[0], m[2], m[1], m[3]];
  2517. // Multiply matrix m with its transpose.
  2518. var a = m[0] * transpose[0] + m[1] * transpose[2];
  2519. var b = m[0] * transpose[1] + m[1] * transpose[3];
  2520. var c = m[2] * transpose[0] + m[3] * transpose[2];
  2521. var d = m[2] * transpose[1] + m[3] * transpose[3];
  2522. // Solve the second degree polynomial to get roots.
  2523. var first = (a + d) / 2;
  2524. var second = Math.sqrt((a + d) * (a + d) - 4 * (a * d - c * b)) / 2;
  2525. var sx = first + second || 1;
  2526. var sy = first - second || 1;
  2527. // Scale values are the square roots of the eigenvalues.
  2528. return [Math.sqrt(sx), Math.sqrt(sy)];
  2529. };
  2530. // Normalize rectangle rect=[x1, y1, x2, y2] so that (x1,y1) < (x2,y2)
  2531. // For coordinate systems whose origin lies in the bottom-left, this
  2532. // means normalization to (BL,TR) ordering. For systems with origin in the
  2533. // top-left, this means (TL,BR) ordering.
  2534. Util.normalizeRect = function Util_normalizeRect(rect) {
  2535. var r = rect.slice(0); // clone rect
  2536. if (rect[0] > rect[2]) {
  2537. r[0] = rect[2];
  2538. r[2] = rect[0];
  2539. }
  2540. if (rect[1] > rect[3]) {
  2541. r[1] = rect[3];
  2542. r[3] = rect[1];
  2543. }
  2544. return r;
  2545. };
  2546. // Returns a rectangle [x1, y1, x2, y2] corresponding to the
  2547. // intersection of rect1 and rect2. If no intersection, returns 'false'
  2548. // The rectangle coordinates of rect1, rect2 should be [x1, y1, x2, y2]
  2549. Util.intersect = function Util_intersect(rect1, rect2) {
  2550. function compare(a, b) {
  2551. return a - b;
  2552. }
  2553. // Order points along the axes
  2554. var orderedX = [rect1[0], rect1[2], rect2[0], rect2[2]].sort(compare),
  2555. orderedY = [rect1[1], rect1[3], rect2[1], rect2[3]].sort(compare),
  2556. result = [];
  2557. rect1 = Util.normalizeRect(rect1);
  2558. rect2 = Util.normalizeRect(rect2);
  2559. // X: first and second points belong to different rectangles?
  2560. if ((orderedX[0] === rect1[0] && orderedX[1] === rect2[0]) ||
  2561. (orderedX[0] === rect2[0] && orderedX[1] === rect1[0])) {
  2562. // Intersection must be between second and third points
  2563. result[0] = orderedX[1];
  2564. result[2] = orderedX[2];
  2565. } else {
  2566. return false;
  2567. }
  2568. // Y: first and second points belong to different rectangles?
  2569. if ((orderedY[0] === rect1[1] && orderedY[1] === rect2[1]) ||
  2570. (orderedY[0] === rect2[1] && orderedY[1] === rect1[1])) {
  2571. // Intersection must be between second and third points
  2572. result[1] = orderedY[1];
  2573. result[3] = orderedY[2];
  2574. } else {
  2575. return false;
  2576. }
  2577. return result;
  2578. };
  2579. Util.sign = function Util_sign(num) {
  2580. return num < 0 ? -1 : 1;
  2581. };
  2582. var ROMAN_NUMBER_MAP = [
  2583. '', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM',
  2584. '', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC',
  2585. '', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'
  2586. ];
  2587. /**
  2588. * Converts positive integers to (upper case) Roman numerals.
  2589. * @param {integer} number - The number that should be converted.
  2590. * @param {boolean} lowerCase - Indicates if the result should be converted
  2591. * to lower case letters. The default is false.
  2592. * @return {string} The resulting Roman number.
  2593. */
  2594. Util.toRoman = function Util_toRoman(number, lowerCase) {
  2595. assert(isInt(number) && number > 0,
  2596. 'The number should be a positive integer.');
  2597. var pos, romanBuf = [];
  2598. // Thousands
  2599. while (number >= 1000) {
  2600. number -= 1000;
  2601. romanBuf.push('M');
  2602. }
  2603. // Hundreds
  2604. pos = (number / 100) | 0;
  2605. number %= 100;
  2606. romanBuf.push(ROMAN_NUMBER_MAP[pos]);
  2607. // Tens
  2608. pos = (number / 10) | 0;
  2609. number %= 10;
  2610. romanBuf.push(ROMAN_NUMBER_MAP[10 + pos]);
  2611. // Ones
  2612. romanBuf.push(ROMAN_NUMBER_MAP[20 + number]);
  2613. var romanStr = romanBuf.join('');
  2614. return (lowerCase ? romanStr.toLowerCase() : romanStr);
  2615. };
  2616. Util.appendToArray = function Util_appendToArray(arr1, arr2) {
  2617. Array.prototype.push.apply(arr1, arr2);
  2618. };
  2619. Util.prependToArray = function Util_prependToArray(arr1, arr2) {
  2620. Array.prototype.unshift.apply(arr1, arr2);
  2621. };
  2622. Util.extendObj = function extendObj(obj1, obj2) {
  2623. for (var key in obj2) {
  2624. obj1[key] = obj2[key];
  2625. }
  2626. };
  2627. Util.getInheritableProperty = function Util_getInheritableProperty(dict,
  2628. name) {
  2629. while (dict && !dict.has(name)) {
  2630. dict = dict.get('Parent');
  2631. }
  2632. if (!dict) {
  2633. return null;
  2634. }
  2635. return dict.get(name);
  2636. };
  2637. Util.inherit = function Util_inherit(sub, base, prototype) {
  2638. sub.prototype = Object.create(base.prototype);
  2639. sub.prototype.constructor = sub;
  2640. for (var prop in prototype) {
  2641. sub.prototype[prop] = prototype[prop];
  2642. }
  2643. };
  2644. Util.loadScript = function Util_loadScript(src, callback) {
  2645. var script = document.createElement('script');
  2646. var loaded = false;
  2647. script.setAttribute('src', src);
  2648. if (callback) {
  2649. script.onload = function() {
  2650. if (!loaded) {
  2651. callback();
  2652. }
  2653. loaded = true;
  2654. };
  2655. }
  2656. document.getElementsByTagName('head')[0].appendChild(script);
  2657. };
  2658. return Util;
  2659. })();
  2660. /**
  2661. * PDF page viewport created based on scale, rotation and offset.
  2662. * @class
  2663. * @alias PDFJS.PageViewport
  2664. */
  2665. var PageViewport = (function PageViewportClosure() {
  2666. /**
  2667. * @constructor
  2668. * @private
  2669. * @param viewBox {Array} xMin, yMin, xMax and yMax coordinates.
  2670. * @param scale {number} scale of the viewport.
  2671. * @param rotation {number} rotations of the viewport in degrees.
  2672. * @param offsetX {number} offset X
  2673. * @param offsetY {number} offset Y
  2674. * @param dontFlip {boolean} if true, axis Y will not be flipped.
  2675. */
  2676. function PageViewport(viewBox, scale, rotation, offsetX, offsetY, dontFlip) {
  2677. this.viewBox = viewBox;
  2678. this.scale = scale;
  2679. this.rotation = rotation;
  2680. this.offsetX = offsetX;
  2681. this.offsetY = offsetY;
  2682. // creating transform to convert pdf coordinate system to the normal
  2683. // canvas like coordinates taking in account scale and rotation
  2684. var centerX = (viewBox[2] + viewBox[0]) / 2;
  2685. var centerY = (viewBox[3] + viewBox[1]) / 2;
  2686. var rotateA, rotateB, rotateC, rotateD;
  2687. rotation = rotation % 360;
  2688. rotation = rotation < 0 ? rotation + 360 : rotation;
  2689. switch (rotation) {
  2690. case 180:
  2691. rotateA = -1; rotateB = 0; rotateC = 0; rotateD = 1;
  2692. break;
  2693. case 90:
  2694. rotateA = 0; rotateB = 1; rotateC = 1; rotateD = 0;
  2695. break;
  2696. case 270:
  2697. rotateA = 0; rotateB = -1; rotateC = -1; rotateD = 0;
  2698. break;
  2699. //case 0:
  2700. default:
  2701. rotateA = 1; rotateB = 0; rotateC = 0; rotateD = -1;
  2702. break;
  2703. }
  2704. if (dontFlip) {
  2705. rotateC = -rotateC; rotateD = -rotateD;
  2706. }
  2707. var offsetCanvasX, offsetCanvasY;
  2708. var width, height;
  2709. if (rotateA === 0) {
  2710. offsetCanvasX = Math.abs(centerY - viewBox[1]) * scale + offsetX;
  2711. offsetCanvasY = Math.abs(centerX - viewBox[0]) * scale + offsetY;
  2712. width = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2713. height = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2714. } else {
  2715. offsetCanvasX = Math.abs(centerX - viewBox[0]) * scale + offsetX;
  2716. offsetCanvasY = Math.abs(centerY - viewBox[1]) * scale + offsetY;
  2717. width = Math.abs(viewBox[2] - viewBox[0]) * scale;
  2718. height = Math.abs(viewBox[3] - viewBox[1]) * scale;
  2719. }
  2720. // creating transform for the following operations:
  2721. // translate(-centerX, -centerY), rotate and flip vertically,
  2722. // scale, and translate(offsetCanvasX, offsetCanvasY)
  2723. this.transform = [
  2724. rotateA * scale,
  2725. rotateB * scale,
  2726. rotateC * scale,
  2727. rotateD * scale,
  2728. offsetCanvasX - rotateA * scale * centerX - rotateC * scale * centerY,
  2729. offsetCanvasY - rotateB * scale * centerX - rotateD * scale * centerY
  2730. ];
  2731. this.width = width;
  2732. this.height = height;
  2733. this.fontScale = scale;
  2734. }
  2735. PageViewport.prototype = /** @lends PDFJS.PageViewport.prototype */ {
  2736. /**
  2737. * Clones viewport with additional properties.
  2738. * @param args {Object} (optional) If specified, may contain the 'scale' or
  2739. * 'rotation' properties to override the corresponding properties in
  2740. * the cloned viewport.
  2741. * @returns {PDFJS.PageViewport} Cloned viewport.
  2742. */
  2743. clone: function PageViewPort_clone(args) {
  2744. args = args || {};
  2745. var scale = 'scale' in args ? args.scale : this.scale;
  2746. var rotation = 'rotation' in args ? args.rotation : this.rotation;
  2747. return new PageViewport(this.viewBox.slice(), scale, rotation,
  2748. this.offsetX, this.offsetY, args.dontFlip);
  2749. },
  2750. /**
  2751. * Converts PDF point to the viewport coordinates. For examples, useful for
  2752. * converting PDF location into canvas pixel coordinates.
  2753. * @param x {number} X coordinate.
  2754. * @param y {number} Y coordinate.
  2755. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2756. * point in the viewport coordinate space.
  2757. * @see {@link convertToPdfPoint}
  2758. * @see {@link convertToViewportRectangle}
  2759. */
  2760. convertToViewportPoint: function PageViewport_convertToViewportPoint(x, y) {
  2761. return Util.applyTransform([x, y], this.transform);
  2762. },
  2763. /**
  2764. * Converts PDF rectangle to the viewport coordinates.
  2765. * @param rect {Array} xMin, yMin, xMax and yMax coordinates.
  2766. * @returns {Array} Contains corresponding coordinates of the rectangle
  2767. * in the viewport coordinate space.
  2768. * @see {@link convertToViewportPoint}
  2769. */
  2770. convertToViewportRectangle:
  2771. function PageViewport_convertToViewportRectangle(rect) {
  2772. var tl = Util.applyTransform([rect[0], rect[1]], this.transform);
  2773. var br = Util.applyTransform([rect[2], rect[3]], this.transform);
  2774. return [tl[0], tl[1], br[0], br[1]];
  2775. },
  2776. /**
  2777. * Converts viewport coordinates to the PDF location. For examples, useful
  2778. * for converting canvas pixel location into PDF one.
  2779. * @param x {number} X coordinate.
  2780. * @param y {number} Y coordinate.
  2781. * @returns {Object} Object that contains 'x' and 'y' properties of the
  2782. * point in the PDF coordinate space.
  2783. * @see {@link convertToViewportPoint}
  2784. */
  2785. convertToPdfPoint: function PageViewport_convertToPdfPoint(x, y) {
  2786. return Util.applyInverseTransform([x, y], this.transform);
  2787. }
  2788. };
  2789. return PageViewport;
  2790. })();
  2791. var PDFStringTranslateTable = [
  2792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  2793. 0x2D8, 0x2C7, 0x2C6, 0x2D9, 0x2DD, 0x2DB, 0x2DA, 0x2DC, 0, 0, 0, 0, 0, 0, 0,
  2794. 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,
  2795. 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,
  2796. 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,
  2797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x2022, 0x2020, 0x2021, 0x2026, 0x2014,
  2798. 0x2013, 0x192, 0x2044, 0x2039, 0x203A, 0x2212, 0x2030, 0x201E, 0x201C,
  2799. 0x201D, 0x2018, 0x2019, 0x201A, 0x2122, 0xFB01, 0xFB02, 0x141, 0x152, 0x160,
  2800. 0x178, 0x17D, 0x131, 0x142, 0x153, 0x161, 0x17E, 0, 0x20AC
  2801. ];
  2802. function stringToPDFString(str) {
  2803. var i, n = str.length, strBuf = [];
  2804. if (str[0] === '\xFE' && str[1] === '\xFF') {
  2805. // UTF16BE BOM
  2806. for (i = 2; i < n; i += 2) {
  2807. strBuf.push(String.fromCharCode(
  2808. (str.charCodeAt(i) << 8) | str.charCodeAt(i + 1)));
  2809. }
  2810. } else {
  2811. for (i = 0; i < n; ++i) {
  2812. var code = PDFStringTranslateTable[str.charCodeAt(i)];
  2813. strBuf.push(code ? String.fromCharCode(code) : str.charAt(i));
  2814. }
  2815. }
  2816. return strBuf.join('');
  2817. }
  2818. function stringToUTF8String(str) {
  2819. return decodeURIComponent(escape(str));
  2820. }
  2821. function utf8StringToString(str) {
  2822. return unescape(encodeURIComponent(str));
  2823. }
  2824. function isEmptyObj(obj) {
  2825. for (var key in obj) {
  2826. return false;
  2827. }
  2828. return true;
  2829. }
  2830. function isBool(v) {
  2831. return typeof v === 'boolean';
  2832. }
  2833. function isInt(v) {
  2834. return typeof v === 'number' && ((v | 0) === v);
  2835. }
  2836. function isNum(v) {
  2837. return typeof v === 'number';
  2838. }
  2839. function isString(v) {
  2840. return typeof v === 'string';
  2841. }
  2842. function isArray(v) {
  2843. return v instanceof Array;
  2844. }
  2845. function isArrayBuffer(v) {
  2846. return typeof v === 'object' && v !== null && v.byteLength !== undefined;
  2847. }
  2848. /**
  2849. * Promise Capability object.
  2850. *
  2851. * @typedef {Object} PromiseCapability
  2852. * @property {Promise} promise - A promise object.
  2853. * @property {function} resolve - Fullfills the promise.
  2854. * @property {function} reject - Rejects the promise.
  2855. */
  2856. /**
  2857. * Creates a promise capability object.
  2858. * @alias PDFJS.createPromiseCapability
  2859. *
  2860. * @return {PromiseCapability} A capability object contains:
  2861. * - a Promise, resolve and reject methods.
  2862. */
  2863. function createPromiseCapability() {
  2864. var capability = {};
  2865. capability.promise = new Promise(function (resolve, reject) {
  2866. capability.resolve = resolve;
  2867. capability.reject = reject;
  2868. });
  2869. return capability;
  2870. }
  2871. /**
  2872. * Polyfill for Promises:
  2873. * The following promise implementation tries to generally implement the
  2874. * Promise/A+ spec. Some notable differences from other promise libaries are:
  2875. * - There currently isn't a seperate deferred and promise object.
  2876. * - Unhandled rejections eventually show an error if they aren't handled.
  2877. *
  2878. * Based off of the work in:
  2879. * https://bugzilla.mozilla.org/show_bug.cgi?id=810490
  2880. */
  2881. (function PromiseClosure() {
  2882. if (globalScope.Promise) {
  2883. // Promises existing in the DOM/Worker, checking presence of all/resolve
  2884. if (typeof globalScope.Promise.all !== 'function') {
  2885. globalScope.Promise.all = function (iterable) {
  2886. var count = 0, results = [], resolve, reject;
  2887. var promise = new globalScope.Promise(function (resolve_, reject_) {
  2888. resolve = resolve_;
  2889. reject = reject_;
  2890. });
  2891. iterable.forEach(function (p, i) {
  2892. count++;
  2893. p.then(function (result) {
  2894. results[i] = result;
  2895. count--;
  2896. if (count === 0) {
  2897. resolve(results);
  2898. }
  2899. }, reject);
  2900. });
  2901. if (count === 0) {
  2902. resolve(results);
  2903. }
  2904. return promise;
  2905. };
  2906. }
  2907. if (typeof globalScope.Promise.resolve !== 'function') {
  2908. globalScope.Promise.resolve = function (value) {
  2909. return new globalScope.Promise(function (resolve) { resolve(value); });
  2910. };
  2911. }
  2912. if (typeof globalScope.Promise.reject !== 'function') {
  2913. globalScope.Promise.reject = function (reason) {
  2914. return new globalScope.Promise(function (resolve, reject) {
  2915. reject(reason);
  2916. });
  2917. };
  2918. }
  2919. if (typeof globalScope.Promise.prototype.catch !== 'function') {
  2920. globalScope.Promise.prototype.catch = function (onReject) {
  2921. return globalScope.Promise.prototype.then(undefined, onReject);
  2922. };
  2923. }
  2924. return;
  2925. }
  2926. var STATUS_PENDING = 0;
  2927. var STATUS_RESOLVED = 1;
  2928. var STATUS_REJECTED = 2;
  2929. // In an attempt to avoid silent exceptions, unhandled rejections are
  2930. // tracked and if they aren't handled in a certain amount of time an
  2931. // error is logged.
  2932. var REJECTION_TIMEOUT = 500;
  2933. var HandlerManager = {
  2934. handlers: [],
  2935. running: false,
  2936. unhandledRejections: [],
  2937. pendingRejectionCheck: false,
  2938. scheduleHandlers: function scheduleHandlers(promise) {
  2939. if (promise._status === STATUS_PENDING) {
  2940. return;
  2941. }
  2942. this.handlers = this.handlers.concat(promise._handlers);
  2943. promise._handlers = [];
  2944. if (this.running) {
  2945. return;
  2946. }
  2947. this.running = true;
  2948. setTimeout(this.runHandlers.bind(this), 0);
  2949. },
  2950. runHandlers: function runHandlers() {
  2951. var RUN_TIMEOUT = 1; // ms
  2952. var timeoutAt = Date.now() + RUN_TIMEOUT;
  2953. while (this.handlers.length > 0) {
  2954. var handler = this.handlers.shift();
  2955. var nextStatus = handler.thisPromise._status;
  2956. var nextValue = handler.thisPromise._value;
  2957. try {
  2958. if (nextStatus === STATUS_RESOLVED) {
  2959. if (typeof handler.onResolve === 'function') {
  2960. nextValue = handler.onResolve(nextValue);
  2961. }
  2962. } else if (typeof handler.onReject === 'function') {
  2963. nextValue = handler.onReject(nextValue);
  2964. nextStatus = STATUS_RESOLVED;
  2965. if (handler.thisPromise._unhandledRejection) {
  2966. this.removeUnhandeledRejection(handler.thisPromise);
  2967. }
  2968. }
  2969. } catch (ex) {
  2970. nextStatus = STATUS_REJECTED;
  2971. nextValue = ex;
  2972. }
  2973. handler.nextPromise._updateStatus(nextStatus, nextValue);
  2974. if (Date.now() >= timeoutAt) {
  2975. break;
  2976. }
  2977. }
  2978. if (this.handlers.length > 0) {
  2979. setTimeout(this.runHandlers.bind(this), 0);
  2980. return;
  2981. }
  2982. this.running = false;
  2983. },
  2984. addUnhandledRejection: function addUnhandledRejection(promise) {
  2985. this.unhandledRejections.push({
  2986. promise: promise,
  2987. time: Date.now()
  2988. });
  2989. this.scheduleRejectionCheck();
  2990. },
  2991. removeUnhandeledRejection: function removeUnhandeledRejection(promise) {
  2992. promise._unhandledRejection = false;
  2993. for (var i = 0; i < this.unhandledRejections.length; i++) {
  2994. if (this.unhandledRejections[i].promise === promise) {
  2995. this.unhandledRejections.splice(i);
  2996. i--;
  2997. }
  2998. }
  2999. },
  3000. scheduleRejectionCheck: function scheduleRejectionCheck() {
  3001. if (this.pendingRejectionCheck) {
  3002. return;
  3003. }
  3004. this.pendingRejectionCheck = true;
  3005. setTimeout(function rejectionCheck() {
  3006. this.pendingRejectionCheck = false;
  3007. var now = Date.now();
  3008. for (var i = 0; i < this.unhandledRejections.length; i++) {
  3009. if (now - this.unhandledRejections[i].time > REJECTION_TIMEOUT) {
  3010. var unhandled = this.unhandledRejections[i].promise._value;
  3011. var msg = 'Unhandled rejection: ' + unhandled;
  3012. if (unhandled.stack) {
  3013. msg += '\n' + unhandled.stack;
  3014. }
  3015. warn(msg);
  3016. this.unhandledRejections.splice(i);
  3017. i--;
  3018. }
  3019. }
  3020. if (this.unhandledRejections.length) {
  3021. this.scheduleRejectionCheck();
  3022. }
  3023. }.bind(this), REJECTION_TIMEOUT);
  3024. }
  3025. };
  3026. function Promise(resolver) {
  3027. this._status = STATUS_PENDING;
  3028. this._handlers = [];
  3029. try {
  3030. resolver.call(this, this._resolve.bind(this), this._reject.bind(this));
  3031. } catch (e) {
  3032. this._reject(e);
  3033. }
  3034. }
  3035. /**
  3036. * Builds a promise that is resolved when all the passed in promises are
  3037. * resolved.
  3038. * @param {array} array of data and/or promises to wait for.
  3039. * @return {Promise} New dependant promise.
  3040. */
  3041. Promise.all = function Promise_all(promises) {
  3042. var resolveAll, rejectAll;
  3043. var deferred = new Promise(function (resolve, reject) {
  3044. resolveAll = resolve;
  3045. rejectAll = reject;
  3046. });
  3047. var unresolved = promises.length;
  3048. var results = [];
  3049. if (unresolved === 0) {
  3050. resolveAll(results);
  3051. return deferred;
  3052. }
  3053. function reject(reason) {
  3054. if (deferred._status === STATUS_REJECTED) {
  3055. return;
  3056. }
  3057. results = [];
  3058. rejectAll(reason);
  3059. }
  3060. for (var i = 0, ii = promises.length; i < ii; ++i) {
  3061. var promise = promises[i];
  3062. var resolve = (function(i) {
  3063. return function(value) {
  3064. if (deferred._status === STATUS_REJECTED) {
  3065. return;
  3066. }
  3067. results[i] = value;
  3068. unresolved--;
  3069. if (unresolved === 0) {
  3070. resolveAll(results);
  3071. }
  3072. };
  3073. })(i);
  3074. if (Promise.isPromise(promise)) {
  3075. promise.then(resolve, reject);
  3076. } else {
  3077. resolve(promise);
  3078. }
  3079. }
  3080. return deferred;
  3081. };
  3082. /**
  3083. * Checks if the value is likely a promise (has a 'then' function).
  3084. * @return {boolean} true if value is thenable
  3085. */
  3086. Promise.isPromise = function Promise_isPromise(value) {
  3087. return value && typeof value.then === 'function';
  3088. };
  3089. /**
  3090. * Creates resolved promise
  3091. * @param value resolve value
  3092. * @returns {Promise}
  3093. */
  3094. Promise.resolve = function Promise_resolve(value) {
  3095. return new Promise(function (resolve) { resolve(value); });
  3096. };
  3097. /**
  3098. * Creates rejected promise
  3099. * @param reason rejection value
  3100. * @returns {Promise}
  3101. */
  3102. Promise.reject = function Promise_reject(reason) {
  3103. return new Promise(function (resolve, reject) { reject(reason); });
  3104. };
  3105. Promise.prototype = {
  3106. _status: null,
  3107. _value: null,
  3108. _handlers: null,
  3109. _unhandledRejection: null,
  3110. _updateStatus: function Promise__updateStatus(status, value) {
  3111. if (this._status === STATUS_RESOLVED ||
  3112. this._status === STATUS_REJECTED) {
  3113. return;
  3114. }
  3115. if (status === STATUS_RESOLVED &&
  3116. Promise.isPromise(value)) {
  3117. value.then(this._updateStatus.bind(this, STATUS_RESOLVED),
  3118. this._updateStatus.bind(this, STATUS_REJECTED));
  3119. return;
  3120. }
  3121. this._status = status;
  3122. this._value = value;
  3123. if (status === STATUS_REJECTED && this._handlers.length === 0) {
  3124. this._unhandledRejection = true;
  3125. HandlerManager.addUnhandledRejection(this);
  3126. }
  3127. HandlerManager.scheduleHandlers(this);
  3128. },
  3129. _resolve: function Promise_resolve(value) {
  3130. this._updateStatus(STATUS_RESOLVED, value);
  3131. },
  3132. _reject: function Promise_reject(reason) {
  3133. this._updateStatus(STATUS_REJECTED, reason);
  3134. },
  3135. then: function Promise_then(onResolve, onReject) {
  3136. var nextPromise = new Promise(function (resolve, reject) {
  3137. this.resolve = resolve;
  3138. this.reject = reject;
  3139. });
  3140. this._handlers.push({
  3141. thisPromise: this,
  3142. onResolve: onResolve,
  3143. onReject: onReject,
  3144. nextPromise: nextPromise
  3145. });
  3146. HandlerManager.scheduleHandlers(this);
  3147. return nextPromise;
  3148. },
  3149. catch: function Promise_catch(onReject) {
  3150. return this.then(undefined, onReject);
  3151. }
  3152. };
  3153. globalScope.Promise = Promise;
  3154. })();
  3155. var StatTimer = (function StatTimerClosure() {
  3156. function rpad(str, pad, length) {
  3157. while (str.length < length) {
  3158. str += pad;
  3159. }
  3160. return str;
  3161. }
  3162. function StatTimer() {
  3163. this.started = Object.create(null);
  3164. this.times = [];
  3165. this.enabled = true;
  3166. }
  3167. StatTimer.prototype = {
  3168. time: function StatTimer_time(name) {
  3169. if (!this.enabled) {
  3170. return;
  3171. }
  3172. if (name in this.started) {
  3173. warn('Timer is already running for ' + name);
  3174. }
  3175. this.started[name] = Date.now();
  3176. },
  3177. timeEnd: function StatTimer_timeEnd(name) {
  3178. if (!this.enabled) {
  3179. return;
  3180. }
  3181. if (!(name in this.started)) {
  3182. warn('Timer has not been started for ' + name);
  3183. }
  3184. this.times.push({
  3185. 'name': name,
  3186. 'start': this.started[name],
  3187. 'end': Date.now()
  3188. });
  3189. // Remove timer from started so it can be called again.
  3190. delete this.started[name];
  3191. },
  3192. toString: function StatTimer_toString() {
  3193. var i, ii;
  3194. var times = this.times;
  3195. var out = '';
  3196. // Find the longest name for padding purposes.
  3197. var longest = 0;
  3198. for (i = 0, ii = times.length; i < ii; ++i) {
  3199. var name = times[i]['name'];
  3200. if (name.length > longest) {
  3201. longest = name.length;
  3202. }
  3203. }
  3204. for (i = 0, ii = times.length; i < ii; ++i) {
  3205. var span = times[i];
  3206. var duration = span.end - span.start;
  3207. out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
  3208. }
  3209. return out;
  3210. }
  3211. };
  3212. return StatTimer;
  3213. })();
  3214. var createBlob = function createBlob(data, contentType) {
  3215. if (typeof Blob !== 'undefined') {
  3216. return new Blob([data], { type: contentType });
  3217. }
  3218. // Blob builder is deprecated in FF14 and removed in FF18.
  3219. var bb = new MozBlobBuilder();
  3220. bb.append(data);
  3221. return bb.getBlob(contentType);
  3222. };
  3223. var createObjectURL = (function createObjectURLClosure() {
  3224. // Blob/createObjectURL is not available, falling back to data schema.
  3225. var digits =
  3226. 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
  3227. return function createObjectURL(data, contentType, forceDataSchema) {
  3228. if (!forceDataSchema &&
  3229. typeof URL !== 'undefined' && URL.createObjectURL) {
  3230. var blob = createBlob(data, contentType);
  3231. return URL.createObjectURL(blob);
  3232. }
  3233. var buffer = 'data:' + contentType + ';base64,';
  3234. for (var i = 0, ii = data.length; i < ii; i += 3) {
  3235. var b1 = data[i] & 0xFF;
  3236. var b2 = data[i + 1] & 0xFF;
  3237. var b3 = data[i + 2] & 0xFF;
  3238. var d1 = b1 >> 2, d2 = ((b1 & 3) << 4) | (b2 >> 4);
  3239. var d3 = i + 1 < ii ? ((b2 & 0xF) << 2) | (b3 >> 6) : 64;
  3240. var d4 = i + 2 < ii ? (b3 & 0x3F) : 64;
  3241. buffer += digits[d1] + digits[d2] + digits[d3] + digits[d4];
  3242. }
  3243. return buffer;
  3244. };
  3245. })();
  3246. function MessageHandler(sourceName, targetName, comObj) {
  3247. this.sourceName = sourceName;
  3248. this.targetName = targetName;
  3249. this.comObj = comObj;
  3250. this.callbackIndex = 1;
  3251. this.postMessageTransfers = true;
  3252. var callbacksCapabilities = this.callbacksCapabilities = Object.create(null);
  3253. var ah = this.actionHandler = Object.create(null);
  3254. this._onComObjOnMessage = function messageHandlerComObjOnMessage(event) {
  3255. var data = event.data;
  3256. if (data.targetName !== this.sourceName) {
  3257. return;
  3258. }
  3259. if (data.isReply) {
  3260. var callbackId = data.callbackId;
  3261. if (data.callbackId in callbacksCapabilities) {
  3262. var callback = callbacksCapabilities[callbackId];
  3263. delete callbacksCapabilities[callbackId];
  3264. if ('error' in data) {
  3265. callback.reject(data.error);
  3266. } else {
  3267. callback.resolve(data.data);
  3268. }
  3269. } else {
  3270. error('Cannot resolve callback ' + callbackId);
  3271. }
  3272. } else if (data.action in ah) {
  3273. var action = ah[data.action];
  3274. if (data.callbackId) {
  3275. var sourceName = this.sourceName;
  3276. var targetName = data.sourceName;
  3277. Promise.resolve().then(function () {
  3278. return action[0].call(action[1], data.data);
  3279. }).then(function (result) {
  3280. comObj.postMessage({
  3281. sourceName: sourceName,
  3282. targetName: targetName,
  3283. isReply: true,
  3284. callbackId: data.callbackId,
  3285. data: result
  3286. });
  3287. }, function (reason) {
  3288. if (reason instanceof Error) {
  3289. // Serialize error to avoid "DataCloneError"
  3290. reason = reason + '';
  3291. }
  3292. comObj.postMessage({
  3293. sourceName: sourceName,
  3294. targetName: targetName,
  3295. isReply: true,
  3296. callbackId: data.callbackId,
  3297. error: reason
  3298. });
  3299. });
  3300. } else {
  3301. action[0].call(action[1], data.data);
  3302. }
  3303. } else {
  3304. error('Unknown action from worker: ' + data.action);
  3305. }
  3306. }.bind(this);
  3307. comObj.addEventListener('message', this._onComObjOnMessage);
  3308. }
  3309. MessageHandler.prototype = {
  3310. on: function messageHandlerOn(actionName, handler, scope) {
  3311. var ah = this.actionHandler;
  3312. if (ah[actionName]) {
  3313. error('There is already an actionName called "' + actionName + '"');
  3314. }
  3315. ah[actionName] = [handler, scope];
  3316. },
  3317. /**
  3318. * Sends a message to the comObj to invoke the action with the supplied data.
  3319. * @param {String} actionName Action to call.
  3320. * @param {JSON} data JSON data to send.
  3321. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers
  3322. */
  3323. send: function messageHandlerSend(actionName, data, transfers) {
  3324. var message = {
  3325. sourceName: this.sourceName,
  3326. targetName: this.targetName,
  3327. action: actionName,
  3328. data: data
  3329. };
  3330. this.postMessage(message, transfers);
  3331. },
  3332. /**
  3333. * Sends a message to the comObj to invoke the action with the supplied data.
  3334. * Expects that other side will callback with the response.
  3335. * @param {String} actionName Action to call.
  3336. * @param {JSON} data JSON data to send.
  3337. * @param {Array} [transfers] Optional list of transfers/ArrayBuffers.
  3338. * @returns {Promise} Promise to be resolved with response data.
  3339. */
  3340. sendWithPromise:
  3341. function messageHandlerSendWithPromise(actionName, data, transfers) {
  3342. var callbackId = this.callbackIndex++;
  3343. var message = {
  3344. sourceName: this.sourceName,
  3345. targetName: this.targetName,
  3346. action: actionName,
  3347. data: data,
  3348. callbackId: callbackId
  3349. };
  3350. var capability = createPromiseCapability();
  3351. this.callbacksCapabilities[callbackId] = capability;
  3352. try {
  3353. this.postMessage(message, transfers);
  3354. } catch (e) {
  3355. capability.reject(e);
  3356. }
  3357. return capability.promise;
  3358. },
  3359. /**
  3360. * Sends raw message to the comObj.
  3361. * @private
  3362. * @param message {Object} Raw message.
  3363. * @param transfers List of transfers/ArrayBuffers, or undefined.
  3364. */
  3365. postMessage: function (message, transfers) {
  3366. if (transfers && this.postMessageTransfers) {
  3367. this.comObj.postMessage(message, transfers);
  3368. } else {
  3369. this.comObj.postMessage(message);
  3370. }
  3371. },
  3372. destroy: function () {
  3373. this.comObj.removeEventListener('message', this._onComObjOnMessage);
  3374. }
  3375. };
  3376. function loadJpegStream(id, imageUrl, objs) {
  3377. var img = new Image();
  3378. img.onload = (function loadJpegStream_onloadClosure() {
  3379. objs.resolve(id, img);
  3380. });
  3381. img.onerror = (function loadJpegStream_onerrorClosure() {
  3382. objs.resolve(id, null);
  3383. warn('Error during JPEG image loading');
  3384. });
  3385. img.src = imageUrl;
  3386. }
  3387. // Polyfill from https://github.com/Polymer/URL
  3388. /* Any copyright is dedicated to the Public Domain.
  3389. * http://creativecommons.org/publicdomain/zero/1.0/ */
  3390. (function checkURLConstructor(scope) {
  3391. /* jshint ignore:start */
  3392. // feature detect for URL constructor
  3393. var hasWorkingUrl = false;
  3394. try {
  3395. if (typeof URL === 'function' &&
  3396. typeof URL.prototype === 'object' &&
  3397. ('origin' in URL.prototype)) {
  3398. var u = new URL('b', 'http://a');
  3399. u.pathname = 'c%20d';
  3400. hasWorkingUrl = u.href === 'http://a/c%20d';
  3401. }
  3402. } catch(e) { }
  3403. if (hasWorkingUrl)
  3404. return;
  3405. var relative = Object.create(null);
  3406. relative['ftp'] = 21;
  3407. relative['file'] = 0;
  3408. relative['gopher'] = 70;
  3409. relative['http'] = 80;
  3410. relative['https'] = 443;
  3411. relative['ws'] = 80;
  3412. relative['wss'] = 443;
  3413. var relativePathDotMapping = Object.create(null);
  3414. relativePathDotMapping['%2e'] = '.';
  3415. relativePathDotMapping['.%2e'] = '..';
  3416. relativePathDotMapping['%2e.'] = '..';
  3417. relativePathDotMapping['%2e%2e'] = '..';
  3418. function isRelativeScheme(scheme) {
  3419. return relative[scheme] !== undefined;
  3420. }
  3421. function invalid() {
  3422. clear.call(this);
  3423. this._isInvalid = true;
  3424. }
  3425. function IDNAToASCII(h) {
  3426. if ('' == h) {
  3427. invalid.call(this)
  3428. }
  3429. // XXX
  3430. return h.toLowerCase()
  3431. }
  3432. function percentEscape(c) {
  3433. var unicode = c.charCodeAt(0);
  3434. if (unicode > 0x20 &&
  3435. unicode < 0x7F &&
  3436. // " # < > ? `
  3437. [0x22, 0x23, 0x3C, 0x3E, 0x3F, 0x60].indexOf(unicode) == -1
  3438. ) {
  3439. return c;
  3440. }
  3441. return encodeURIComponent(c);
  3442. }
  3443. function percentEscapeQuery(c) {
  3444. // XXX This actually needs to encode c using encoding and then
  3445. // convert the bytes one-by-one.
  3446. var unicode = c.charCodeAt(0);
  3447. if (unicode > 0x20 &&
  3448. unicode < 0x7F &&
  3449. // " # < > ` (do not escape '?')
  3450. [0x22, 0x23, 0x3C, 0x3E, 0x60].indexOf(unicode) == -1
  3451. ) {
  3452. return c;
  3453. }
  3454. return encodeURIComponent(c);
  3455. }
  3456. var EOF = undefined,
  3457. ALPHA = /[a-zA-Z]/,
  3458. ALPHANUMERIC = /[a-zA-Z0-9\+\-\.]/;
  3459. function parse(input, stateOverride, base) {
  3460. function err(message) {
  3461. errors.push(message)
  3462. }
  3463. var state = stateOverride || 'scheme start',
  3464. cursor = 0,
  3465. buffer = '',
  3466. seenAt = false,
  3467. seenBracket = false,
  3468. errors = [];
  3469. loop: while ((input[cursor - 1] != EOF || cursor == 0) && !this._isInvalid) {
  3470. var c = input[cursor];
  3471. switch (state) {
  3472. case 'scheme start':
  3473. if (c && ALPHA.test(c)) {
  3474. buffer += c.toLowerCase(); // ASCII-safe
  3475. state = 'scheme';
  3476. } else if (!stateOverride) {
  3477. buffer = '';
  3478. state = 'no scheme';
  3479. continue;
  3480. } else {
  3481. err('Invalid scheme.');
  3482. break loop;
  3483. }
  3484. break;
  3485. case 'scheme':
  3486. if (c && ALPHANUMERIC.test(c)) {
  3487. buffer += c.toLowerCase(); // ASCII-safe
  3488. } else if (':' == c) {
  3489. this._scheme = buffer;
  3490. buffer = '';
  3491. if (stateOverride) {
  3492. break loop;
  3493. }
  3494. if (isRelativeScheme(this._scheme)) {
  3495. this._isRelative = true;
  3496. }
  3497. if ('file' == this._scheme) {
  3498. state = 'relative';
  3499. } else if (this._isRelative && base && base._scheme == this._scheme) {
  3500. state = 'relative or authority';
  3501. } else if (this._isRelative) {
  3502. state = 'authority first slash';
  3503. } else {
  3504. state = 'scheme data';
  3505. }
  3506. } else if (!stateOverride) {
  3507. buffer = '';
  3508. cursor = 0;
  3509. state = 'no scheme';
  3510. continue;
  3511. } else if (EOF == c) {
  3512. break loop;
  3513. } else {
  3514. err('Code point not allowed in scheme: ' + c)
  3515. break loop;
  3516. }
  3517. break;
  3518. case 'scheme data':
  3519. if ('?' == c) {
  3520. this._query = '?';
  3521. state = 'query';
  3522. } else if ('#' == c) {
  3523. this._fragment = '#';
  3524. state = 'fragment';
  3525. } else {
  3526. // XXX error handling
  3527. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3528. this._schemeData += percentEscape(c);
  3529. }
  3530. }
  3531. break;
  3532. case 'no scheme':
  3533. if (!base || !(isRelativeScheme(base._scheme))) {
  3534. err('Missing scheme.');
  3535. invalid.call(this);
  3536. } else {
  3537. state = 'relative';
  3538. continue;
  3539. }
  3540. break;
  3541. case 'relative or authority':
  3542. if ('/' == c && '/' == input[cursor+1]) {
  3543. state = 'authority ignore slashes';
  3544. } else {
  3545. err('Expected /, got: ' + c);
  3546. state = 'relative';
  3547. continue
  3548. }
  3549. break;
  3550. case 'relative':
  3551. this._isRelative = true;
  3552. if ('file' != this._scheme)
  3553. this._scheme = base._scheme;
  3554. if (EOF == c) {
  3555. this._host = base._host;
  3556. this._port = base._port;
  3557. this._path = base._path.slice();
  3558. this._query = base._query;
  3559. this._username = base._username;
  3560. this._password = base._password;
  3561. break loop;
  3562. } else if ('/' == c || '\\' == c) {
  3563. if ('\\' == c)
  3564. err('\\ is an invalid code point.');
  3565. state = 'relative slash';
  3566. } else if ('?' == c) {
  3567. this._host = base._host;
  3568. this._port = base._port;
  3569. this._path = base._path.slice();
  3570. this._query = '?';
  3571. this._username = base._username;
  3572. this._password = base._password;
  3573. state = 'query';
  3574. } else if ('#' == c) {
  3575. this._host = base._host;
  3576. this._port = base._port;
  3577. this._path = base._path.slice();
  3578. this._query = base._query;
  3579. this._fragment = '#';
  3580. this._username = base._username;
  3581. this._password = base._password;
  3582. state = 'fragment';
  3583. } else {
  3584. var nextC = input[cursor+1]
  3585. var nextNextC = input[cursor+2]
  3586. if (
  3587. 'file' != this._scheme || !ALPHA.test(c) ||
  3588. (nextC != ':' && nextC != '|') ||
  3589. (EOF != nextNextC && '/' != nextNextC && '\\' != nextNextC && '?' != nextNextC && '#' != nextNextC)) {
  3590. this._host = base._host;
  3591. this._port = base._port;
  3592. this._username = base._username;
  3593. this._password = base._password;
  3594. this._path = base._path.slice();
  3595. this._path.pop();
  3596. }
  3597. state = 'relative path';
  3598. continue;
  3599. }
  3600. break;
  3601. case 'relative slash':
  3602. if ('/' == c || '\\' == c) {
  3603. if ('\\' == c) {
  3604. err('\\ is an invalid code point.');
  3605. }
  3606. if ('file' == this._scheme) {
  3607. state = 'file host';
  3608. } else {
  3609. state = 'authority ignore slashes';
  3610. }
  3611. } else {
  3612. if ('file' != this._scheme) {
  3613. this._host = base._host;
  3614. this._port = base._port;
  3615. this._username = base._username;
  3616. this._password = base._password;
  3617. }
  3618. state = 'relative path';
  3619. continue;
  3620. }
  3621. break;
  3622. case 'authority first slash':
  3623. if ('/' == c) {
  3624. state = 'authority second slash';
  3625. } else {
  3626. err("Expected '/', got: " + c);
  3627. state = 'authority ignore slashes';
  3628. continue;
  3629. }
  3630. break;
  3631. case 'authority second slash':
  3632. state = 'authority ignore slashes';
  3633. if ('/' != c) {
  3634. err("Expected '/', got: " + c);
  3635. continue;
  3636. }
  3637. break;
  3638. case 'authority ignore slashes':
  3639. if ('/' != c && '\\' != c) {
  3640. state = 'authority';
  3641. continue;
  3642. } else {
  3643. err('Expected authority, got: ' + c);
  3644. }
  3645. break;
  3646. case 'authority':
  3647. if ('@' == c) {
  3648. if (seenAt) {
  3649. err('@ already seen.');
  3650. buffer += '%40';
  3651. }
  3652. seenAt = true;
  3653. for (var i = 0; i < buffer.length; i++) {
  3654. var cp = buffer[i];
  3655. if ('\t' == cp || '\n' == cp || '\r' == cp) {
  3656. err('Invalid whitespace in authority.');
  3657. continue;
  3658. }
  3659. // XXX check URL code points
  3660. if (':' == cp && null === this._password) {
  3661. this._password = '';
  3662. continue;
  3663. }
  3664. var tempC = percentEscape(cp);
  3665. (null !== this._password) ? this._password += tempC : this._username += tempC;
  3666. }
  3667. buffer = '';
  3668. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3669. cursor -= buffer.length;
  3670. buffer = '';
  3671. state = 'host';
  3672. continue;
  3673. } else {
  3674. buffer += c;
  3675. }
  3676. break;
  3677. case 'file host':
  3678. if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3679. if (buffer.length == 2 && ALPHA.test(buffer[0]) && (buffer[1] == ':' || buffer[1] == '|')) {
  3680. state = 'relative path';
  3681. } else if (buffer.length == 0) {
  3682. state = 'relative path start';
  3683. } else {
  3684. this._host = IDNAToASCII.call(this, buffer);
  3685. buffer = '';
  3686. state = 'relative path start';
  3687. }
  3688. continue;
  3689. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3690. err('Invalid whitespace in file host.');
  3691. } else {
  3692. buffer += c;
  3693. }
  3694. break;
  3695. case 'host':
  3696. case 'hostname':
  3697. if (':' == c && !seenBracket) {
  3698. // XXX host parsing
  3699. this._host = IDNAToASCII.call(this, buffer);
  3700. buffer = '';
  3701. state = 'port';
  3702. if ('hostname' == stateOverride) {
  3703. break loop;
  3704. }
  3705. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c) {
  3706. this._host = IDNAToASCII.call(this, buffer);
  3707. buffer = '';
  3708. state = 'relative path start';
  3709. if (stateOverride) {
  3710. break loop;
  3711. }
  3712. continue;
  3713. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3714. if ('[' == c) {
  3715. seenBracket = true;
  3716. } else if (']' == c) {
  3717. seenBracket = false;
  3718. }
  3719. buffer += c;
  3720. } else {
  3721. err('Invalid code point in host/hostname: ' + c);
  3722. }
  3723. break;
  3724. case 'port':
  3725. if (/[0-9]/.test(c)) {
  3726. buffer += c;
  3727. } else if (EOF == c || '/' == c || '\\' == c || '?' == c || '#' == c || stateOverride) {
  3728. if ('' != buffer) {
  3729. var temp = parseInt(buffer, 10);
  3730. if (temp != relative[this._scheme]) {
  3731. this._port = temp + '';
  3732. }
  3733. buffer = '';
  3734. }
  3735. if (stateOverride) {
  3736. break loop;
  3737. }
  3738. state = 'relative path start';
  3739. continue;
  3740. } else if ('\t' == c || '\n' == c || '\r' == c) {
  3741. err('Invalid code point in port: ' + c);
  3742. } else {
  3743. invalid.call(this);
  3744. }
  3745. break;
  3746. case 'relative path start':
  3747. if ('\\' == c)
  3748. err("'\\' not allowed in path.");
  3749. state = 'relative path';
  3750. if ('/' != c && '\\' != c) {
  3751. continue;
  3752. }
  3753. break;
  3754. case 'relative path':
  3755. if (EOF == c || '/' == c || '\\' == c || (!stateOverride && ('?' == c || '#' == c))) {
  3756. if ('\\' == c) {
  3757. err('\\ not allowed in relative path.');
  3758. }
  3759. var tmp;
  3760. if (tmp = relativePathDotMapping[buffer.toLowerCase()]) {
  3761. buffer = tmp;
  3762. }
  3763. if ('..' == buffer) {
  3764. this._path.pop();
  3765. if ('/' != c && '\\' != c) {
  3766. this._path.push('');
  3767. }
  3768. } else if ('.' == buffer && '/' != c && '\\' != c) {
  3769. this._path.push('');
  3770. } else if ('.' != buffer) {
  3771. if ('file' == this._scheme && this._path.length == 0 && buffer.length == 2 && ALPHA.test(buffer[0]) && buffer[1] == '|') {
  3772. buffer = buffer[0] + ':';
  3773. }
  3774. this._path.push(buffer);
  3775. }
  3776. buffer = '';
  3777. if ('?' == c) {
  3778. this._query = '?';
  3779. state = 'query';
  3780. } else if ('#' == c) {
  3781. this._fragment = '#';
  3782. state = 'fragment';
  3783. }
  3784. } else if ('\t' != c && '\n' != c && '\r' != c) {
  3785. buffer += percentEscape(c);
  3786. }
  3787. break;
  3788. case 'query':
  3789. if (!stateOverride && '#' == c) {
  3790. this._fragment = '#';
  3791. state = 'fragment';
  3792. } else if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3793. this._query += percentEscapeQuery(c);
  3794. }
  3795. break;
  3796. case 'fragment':
  3797. if (EOF != c && '\t' != c && '\n' != c && '\r' != c) {
  3798. this._fragment += c;
  3799. }
  3800. break;
  3801. }
  3802. cursor++;
  3803. }
  3804. }
  3805. function clear() {
  3806. this._scheme = '';
  3807. this._schemeData = '';
  3808. this._username = '';
  3809. this._password = null;
  3810. this._host = '';
  3811. this._port = '';
  3812. this._path = [];
  3813. this._query = '';
  3814. this._fragment = '';
  3815. this._isInvalid = false;
  3816. this._isRelative = false;
  3817. }
  3818. // Does not process domain names or IP addresses.
  3819. // Does not handle encoding for the query parameter.
  3820. function jURL(url, base /* , encoding */) {
  3821. if (base !== undefined && !(base instanceof jURL))
  3822. base = new jURL(String(base));
  3823. this._url = url;
  3824. clear.call(this);
  3825. var input = url.replace(/^[ \t\r\n\f]+|[ \t\r\n\f]+$/g, '');
  3826. // encoding = encoding || 'utf-8'
  3827. parse.call(this, input, null, base);
  3828. }
  3829. jURL.prototype = {
  3830. toString: function() {
  3831. return this.href;
  3832. },
  3833. get href() {
  3834. if (this._isInvalid)
  3835. return this._url;
  3836. var authority = '';
  3837. if ('' != this._username || null != this._password) {
  3838. authority = this._username +
  3839. (null != this._password ? ':' + this._password : '') + '@';
  3840. }
  3841. return this.protocol +
  3842. (this._isRelative ? '//' + authority + this.host : '') +
  3843. this.pathname + this._query + this._fragment;
  3844. },
  3845. set href(href) {
  3846. clear.call(this);
  3847. parse.call(this, href);
  3848. },
  3849. get protocol() {
  3850. return this._scheme + ':';
  3851. },
  3852. set protocol(protocol) {
  3853. if (this._isInvalid)
  3854. return;
  3855. parse.call(this, protocol + ':', 'scheme start');
  3856. },
  3857. get host() {
  3858. return this._isInvalid ? '' : this._port ?
  3859. this._host + ':' + this._port : this._host;
  3860. },
  3861. set host(host) {
  3862. if (this._isInvalid || !this._isRelative)
  3863. return;
  3864. parse.call(this, host, 'host');
  3865. },
  3866. get hostname() {
  3867. return this._host;
  3868. },
  3869. set hostname(hostname) {
  3870. if (this._isInvalid || !this._isRelative)
  3871. return;
  3872. parse.call(this, hostname, 'hostname');
  3873. },
  3874. get port() {
  3875. return this._port;
  3876. },
  3877. set port(port) {
  3878. if (this._isInvalid || !this._isRelative)
  3879. return;
  3880. parse.call(this, port, 'port');
  3881. },
  3882. get pathname() {
  3883. return this._isInvalid ? '' : this._isRelative ?
  3884. '/' + this._path.join('/') : this._schemeData;
  3885. },
  3886. set pathname(pathname) {
  3887. if (this._isInvalid || !this._isRelative)
  3888. return;
  3889. this._path = [];
  3890. parse.call(this, pathname, 'relative path start');
  3891. },
  3892. get search() {
  3893. return this._isInvalid || !this._query || '?' == this._query ?
  3894. '' : this._query;
  3895. },
  3896. set search(search) {
  3897. if (this._isInvalid || !this._isRelative)
  3898. return;
  3899. this._query = '?';
  3900. if ('?' == search[0])
  3901. search = search.slice(1);
  3902. parse.call(this, search, 'query');
  3903. },
  3904. get hash() {
  3905. return this._isInvalid || !this._fragment || '#' == this._fragment ?
  3906. '' : this._fragment;
  3907. },
  3908. set hash(hash) {
  3909. if (this._isInvalid)
  3910. return;
  3911. this._fragment = '#';
  3912. if ('#' == hash[0])
  3913. hash = hash.slice(1);
  3914. parse.call(this, hash, 'fragment');
  3915. },
  3916. get origin() {
  3917. var host;
  3918. if (this._isInvalid || !this._scheme) {
  3919. return '';
  3920. }
  3921. // javascript: Gecko returns String(""), WebKit/Blink String("null")
  3922. // Gecko throws error for "data://"
  3923. // data: Gecko returns "", Blink returns "data://", WebKit returns "null"
  3924. // Gecko returns String("") for file: mailto:
  3925. // WebKit/Blink returns String("SCHEME://") for file: mailto:
  3926. switch (this._scheme) {
  3927. case 'data':
  3928. case 'file':
  3929. case 'javascript':
  3930. case 'mailto':
  3931. return 'null';
  3932. }
  3933. host = this.host;
  3934. if (!host) {
  3935. return '';
  3936. }
  3937. return this._scheme + '://' + host;
  3938. }
  3939. };
  3940. // Copy over the static methods
  3941. var OriginalURL = scope.URL;
  3942. if (OriginalURL) {
  3943. jURL.createObjectURL = function(blob) {
  3944. // IE extension allows a second optional options argument.
  3945. // http://msdn.microsoft.com/en-us/library/ie/hh772302(v=vs.85).aspx
  3946. return OriginalURL.createObjectURL.apply(OriginalURL, arguments);
  3947. };
  3948. jURL.revokeObjectURL = function(url) {
  3949. OriginalURL.revokeObjectURL(url);
  3950. };
  3951. }
  3952. scope.URL = jURL;
  3953. /* jshint ignore:end */
  3954. })(globalScope);
  3955. exports.FONT_IDENTITY_MATRIX = FONT_IDENTITY_MATRIX;
  3956. exports.IDENTITY_MATRIX = IDENTITY_MATRIX;
  3957. exports.OPS = OPS;
  3958. exports.VERBOSITY_LEVELS = VERBOSITY_LEVELS;
  3959. exports.UNSUPPORTED_FEATURES = UNSUPPORTED_FEATURES;
  3960. exports.AnnotationBorderStyleType = AnnotationBorderStyleType;
  3961. exports.AnnotationFlag = AnnotationFlag;
  3962. exports.AnnotationType = AnnotationType;
  3963. exports.FontType = FontType;
  3964. exports.ImageKind = ImageKind;
  3965. exports.InvalidPDFException = InvalidPDFException;
  3966. exports.MessageHandler = MessageHandler;
  3967. exports.MissingDataException = MissingDataException;
  3968. exports.MissingPDFException = MissingPDFException;
  3969. exports.NotImplementedException = NotImplementedException;
  3970. exports.PageViewport = PageViewport;
  3971. exports.PasswordException = PasswordException;
  3972. exports.PasswordResponses = PasswordResponses;
  3973. exports.StatTimer = StatTimer;
  3974. exports.StreamType = StreamType;
  3975. exports.TextRenderingMode = TextRenderingMode;
  3976. exports.UnexpectedResponseException = UnexpectedResponseException;
  3977. exports.UnknownErrorException = UnknownErrorException;
  3978. exports.Util = Util;
  3979. exports.XRefParseException = XRefParseException;
  3980. exports.arrayByteLength = arrayByteLength;
  3981. exports.arraysToBytes = arraysToBytes;
  3982. exports.assert = assert;
  3983. exports.bytesToString = bytesToString;
  3984. exports.combineUrl = combineUrl;
  3985. exports.createBlob = createBlob;
  3986. exports.createPromiseCapability = createPromiseCapability;
  3987. exports.createObjectURL = createObjectURL;
  3988. exports.deprecated = deprecated;
  3989. exports.error = error;
  3990. exports.getLookupTableFactory = getLookupTableFactory;
  3991. exports.getVerbosityLevel = getVerbosityLevel;
  3992. exports.globalScope = globalScope;
  3993. exports.info = info;
  3994. exports.isArray = isArray;
  3995. exports.isArrayBuffer = isArrayBuffer;
  3996. exports.isBool = isBool;
  3997. exports.isEmptyObj = isEmptyObj;
  3998. exports.isInt = isInt;
  3999. exports.isNum = isNum;
  4000. exports.isString = isString;
  4001. exports.isSameOrigin = isSameOrigin;
  4002. exports.isValidUrl = isValidUrl;
  4003. exports.isLittleEndian = isLittleEndian;
  4004. exports.loadJpegStream = loadJpegStream;
  4005. exports.log2 = log2;
  4006. exports.readInt8 = readInt8;
  4007. exports.readUint16 = readUint16;
  4008. exports.readUint32 = readUint32;
  4009. exports.removeNullCharacters = removeNullCharacters;
  4010. exports.setVerbosityLevel = setVerbosityLevel;
  4011. exports.shadow = shadow;
  4012. exports.string32 = string32;
  4013. exports.stringToBytes = stringToBytes;
  4014. exports.stringToPDFString = stringToPDFString;
  4015. exports.stringToUTF8String = stringToUTF8String;
  4016. exports.utf8StringToString = utf8StringToString;
  4017. exports.warn = warn;
  4018. }));
  4019. (function (root, factory) {
  4020. {
  4021. factory((root.pdfjsCoreCFFParser = {}), root.pdfjsSharedUtil,
  4022. root.pdfjsCoreCharsets, root.pdfjsCoreEncodings);
  4023. }
  4024. }(this, function (exports, sharedUtil, coreCharsets, coreEncodings) {
  4025. var error = sharedUtil.error;
  4026. var info = sharedUtil.info;
  4027. var bytesToString = sharedUtil.bytesToString;
  4028. var warn = sharedUtil.warn;
  4029. var isArray = sharedUtil.isArray;
  4030. var Util = sharedUtil.Util;
  4031. var stringToBytes = sharedUtil.stringToBytes;
  4032. var assert = sharedUtil.assert;
  4033. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  4034. var ExpertCharset = coreCharsets.ExpertCharset;
  4035. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  4036. var StandardEncoding = coreEncodings.StandardEncoding;
  4037. var ExpertEncoding = coreEncodings.ExpertEncoding;
  4038. // Maximum subroutine call depth of type 2 chartrings. Matches OTS.
  4039. var MAX_SUBR_NESTING = 10;
  4040. /**
  4041. * The CFF class takes a Type1 file and wrap it into a
  4042. * 'Compact Font Format' which itself embed Type2 charstrings.
  4043. */
  4044. var CFFStandardStrings = [
  4045. '.notdef', 'space', 'exclam', 'quotedbl', 'numbersign', 'dollar', 'percent',
  4046. 'ampersand', 'quoteright', 'parenleft', 'parenright', 'asterisk', 'plus',
  4047. 'comma', 'hyphen', 'period', 'slash', 'zero', 'one', 'two', 'three', 'four',
  4048. 'five', 'six', 'seven', 'eight', 'nine', 'colon', 'semicolon', 'less',
  4049. 'equal', 'greater', 'question', 'at', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  4050. 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
  4051. 'X', 'Y', 'Z', 'bracketleft', 'backslash', 'bracketright', 'asciicircum',
  4052. 'underscore', 'quoteleft', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
  4053. 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
  4054. 'z', 'braceleft', 'bar', 'braceright', 'asciitilde', 'exclamdown', 'cent',
  4055. 'sterling', 'fraction', 'yen', 'florin', 'section', 'currency',
  4056. 'quotesingle', 'quotedblleft', 'guillemotleft', 'guilsinglleft',
  4057. 'guilsinglright', 'fi', 'fl', 'endash', 'dagger', 'daggerdbl',
  4058. 'periodcentered', 'paragraph', 'bullet', 'quotesinglbase', 'quotedblbase',
  4059. 'quotedblright', 'guillemotright', 'ellipsis', 'perthousand', 'questiondown',
  4060. 'grave', 'acute', 'circumflex', 'tilde', 'macron', 'breve', 'dotaccent',
  4061. 'dieresis', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron', 'emdash',
  4062. 'AE', 'ordfeminine', 'Lslash', 'Oslash', 'OE', 'ordmasculine', 'ae',
  4063. 'dotlessi', 'lslash', 'oslash', 'oe', 'germandbls', 'onesuperior',
  4064. 'logicalnot', 'mu', 'trademark', 'Eth', 'onehalf', 'plusminus', 'Thorn',
  4065. 'onequarter', 'divide', 'brokenbar', 'degree', 'thorn', 'threequarters',
  4066. 'twosuperior', 'registered', 'minus', 'eth', 'multiply', 'threesuperior',
  4067. 'copyright', 'Aacute', 'Acircumflex', 'Adieresis', 'Agrave', 'Aring',
  4068. 'Atilde', 'Ccedilla', 'Eacute', 'Ecircumflex', 'Edieresis', 'Egrave',
  4069. 'Iacute', 'Icircumflex', 'Idieresis', 'Igrave', 'Ntilde', 'Oacute',
  4070. 'Ocircumflex', 'Odieresis', 'Ograve', 'Otilde', 'Scaron', 'Uacute',
  4071. 'Ucircumflex', 'Udieresis', 'Ugrave', 'Yacute', 'Ydieresis', 'Zcaron',
  4072. 'aacute', 'acircumflex', 'adieresis', 'agrave', 'aring', 'atilde',
  4073. 'ccedilla', 'eacute', 'ecircumflex', 'edieresis', 'egrave', 'iacute',
  4074. 'icircumflex', 'idieresis', 'igrave', 'ntilde', 'oacute', 'ocircumflex',
  4075. 'odieresis', 'ograve', 'otilde', 'scaron', 'uacute', 'ucircumflex',
  4076. 'udieresis', 'ugrave', 'yacute', 'ydieresis', 'zcaron', 'exclamsmall',
  4077. 'Hungarumlautsmall', 'dollaroldstyle', 'dollarsuperior', 'ampersandsmall',
  4078. 'Acutesmall', 'parenleftsuperior', 'parenrightsuperior', 'twodotenleader',
  4079. 'onedotenleader', 'zerooldstyle', 'oneoldstyle', 'twooldstyle',
  4080. 'threeoldstyle', 'fouroldstyle', 'fiveoldstyle', 'sixoldstyle',
  4081. 'sevenoldstyle', 'eightoldstyle', 'nineoldstyle', 'commasuperior',
  4082. 'threequartersemdash', 'periodsuperior', 'questionsmall', 'asuperior',
  4083. 'bsuperior', 'centsuperior', 'dsuperior', 'esuperior', 'isuperior',
  4084. 'lsuperior', 'msuperior', 'nsuperior', 'osuperior', 'rsuperior', 'ssuperior',
  4085. 'tsuperior', 'ff', 'ffi', 'ffl', 'parenleftinferior', 'parenrightinferior',
  4086. 'Circumflexsmall', 'hyphensuperior', 'Gravesmall', 'Asmall', 'Bsmall',
  4087. 'Csmall', 'Dsmall', 'Esmall', 'Fsmall', 'Gsmall', 'Hsmall', 'Ismall',
  4088. 'Jsmall', 'Ksmall', 'Lsmall', 'Msmall', 'Nsmall', 'Osmall', 'Psmall',
  4089. 'Qsmall', 'Rsmall', 'Ssmall', 'Tsmall', 'Usmall', 'Vsmall', 'Wsmall',
  4090. 'Xsmall', 'Ysmall', 'Zsmall', 'colonmonetary', 'onefitted', 'rupiah',
  4091. 'Tildesmall', 'exclamdownsmall', 'centoldstyle', 'Lslashsmall',
  4092. 'Scaronsmall', 'Zcaronsmall', 'Dieresissmall', 'Brevesmall', 'Caronsmall',
  4093. 'Dotaccentsmall', 'Macronsmall', 'figuredash', 'hypheninferior',
  4094. 'Ogoneksmall', 'Ringsmall', 'Cedillasmall', 'questiondownsmall', 'oneeighth',
  4095. 'threeeighths', 'fiveeighths', 'seveneighths', 'onethird', 'twothirds',
  4096. 'zerosuperior', 'foursuperior', 'fivesuperior', 'sixsuperior',
  4097. 'sevensuperior', 'eightsuperior', 'ninesuperior', 'zeroinferior',
  4098. 'oneinferior', 'twoinferior', 'threeinferior', 'fourinferior',
  4099. 'fiveinferior', 'sixinferior', 'seveninferior', 'eightinferior',
  4100. 'nineinferior', 'centinferior', 'dollarinferior', 'periodinferior',
  4101. 'commainferior', 'Agravesmall', 'Aacutesmall', 'Acircumflexsmall',
  4102. 'Atildesmall', 'Adieresissmall', 'Aringsmall', 'AEsmall', 'Ccedillasmall',
  4103. 'Egravesmall', 'Eacutesmall', 'Ecircumflexsmall', 'Edieresissmall',
  4104. 'Igravesmall', 'Iacutesmall', 'Icircumflexsmall', 'Idieresissmall',
  4105. 'Ethsmall', 'Ntildesmall', 'Ogravesmall', 'Oacutesmall', 'Ocircumflexsmall',
  4106. 'Otildesmall', 'Odieresissmall', 'OEsmall', 'Oslashsmall', 'Ugravesmall',
  4107. 'Uacutesmall', 'Ucircumflexsmall', 'Udieresissmall', 'Yacutesmall',
  4108. 'Thornsmall', 'Ydieresissmall', '001.000', '001.001', '001.002', '001.003',
  4109. 'Black', 'Bold', 'Book', 'Light', 'Medium', 'Regular', 'Roman', 'Semibold'
  4110. ];
  4111. var CFFParser = (function CFFParserClosure() {
  4112. var CharstringValidationData = [
  4113. null,
  4114. { id: 'hstem', min: 2, stackClearing: true, stem: true },
  4115. null,
  4116. { id: 'vstem', min: 2, stackClearing: true, stem: true },
  4117. { id: 'vmoveto', min: 1, stackClearing: true },
  4118. { id: 'rlineto', min: 2, resetStack: true },
  4119. { id: 'hlineto', min: 1, resetStack: true },
  4120. { id: 'vlineto', min: 1, resetStack: true },
  4121. { id: 'rrcurveto', min: 6, resetStack: true },
  4122. null,
  4123. { id: 'callsubr', min: 1, undefStack: true },
  4124. { id: 'return', min: 0, undefStack: true },
  4125. null, // 12
  4126. null,
  4127. { id: 'endchar', min: 0, stackClearing: true },
  4128. null,
  4129. null,
  4130. null,
  4131. { id: 'hstemhm', min: 2, stackClearing: true, stem: true },
  4132. { id: 'hintmask', min: 0, stackClearing: true },
  4133. { id: 'cntrmask', min: 0, stackClearing: true },
  4134. { id: 'rmoveto', min: 2, stackClearing: true },
  4135. { id: 'hmoveto', min: 1, stackClearing: true },
  4136. { id: 'vstemhm', min: 2, stackClearing: true, stem: true },
  4137. { id: 'rcurveline', min: 8, resetStack: true },
  4138. { id: 'rlinecurve', min: 8, resetStack: true },
  4139. { id: 'vvcurveto', min: 4, resetStack: true },
  4140. { id: 'hhcurveto', min: 4, resetStack: true },
  4141. null, // shortint
  4142. { id: 'callgsubr', min: 1, undefStack: true },
  4143. { id: 'vhcurveto', min: 4, resetStack: true },
  4144. { id: 'hvcurveto', min: 4, resetStack: true }
  4145. ];
  4146. var CharstringValidationData12 = [
  4147. null,
  4148. null,
  4149. null,
  4150. { id: 'and', min: 2, stackDelta: -1 },
  4151. { id: 'or', min: 2, stackDelta: -1 },
  4152. { id: 'not', min: 1, stackDelta: 0 },
  4153. null,
  4154. null,
  4155. null,
  4156. { id: 'abs', min: 1, stackDelta: 0 },
  4157. { id: 'add', min: 2, stackDelta: -1,
  4158. stackFn: function stack_div(stack, index) {
  4159. stack[index - 2] = stack[index - 2] + stack[index - 1];
  4160. }
  4161. },
  4162. { id: 'sub', min: 2, stackDelta: -1,
  4163. stackFn: function stack_div(stack, index) {
  4164. stack[index - 2] = stack[index - 2] - stack[index - 1];
  4165. }
  4166. },
  4167. { id: 'div', min: 2, stackDelta: -1,
  4168. stackFn: function stack_div(stack, index) {
  4169. stack[index - 2] = stack[index - 2] / stack[index - 1];
  4170. }
  4171. },
  4172. null,
  4173. { id: 'neg', min: 1, stackDelta: 0,
  4174. stackFn: function stack_div(stack, index) {
  4175. stack[index - 1] = -stack[index - 1];
  4176. }
  4177. },
  4178. { id: 'eq', min: 2, stackDelta: -1 },
  4179. null,
  4180. null,
  4181. { id: 'drop', min: 1, stackDelta: -1 },
  4182. null,
  4183. { id: 'put', min: 2, stackDelta: -2 },
  4184. { id: 'get', min: 1, stackDelta: 0 },
  4185. { id: 'ifelse', min: 4, stackDelta: -3 },
  4186. { id: 'random', min: 0, stackDelta: 1 },
  4187. { id: 'mul', min: 2, stackDelta: -1,
  4188. stackFn: function stack_div(stack, index) {
  4189. stack[index - 2] = stack[index - 2] * stack[index - 1];
  4190. }
  4191. },
  4192. null,
  4193. { id: 'sqrt', min: 1, stackDelta: 0 },
  4194. { id: 'dup', min: 1, stackDelta: 1 },
  4195. { id: 'exch', min: 2, stackDelta: 0 },
  4196. { id: 'index', min: 2, stackDelta: 0 },
  4197. { id: 'roll', min: 3, stackDelta: -2 },
  4198. null,
  4199. null,
  4200. null,
  4201. { id: 'hflex', min: 7, resetStack: true },
  4202. { id: 'flex', min: 13, resetStack: true },
  4203. { id: 'hflex1', min: 9, resetStack: true },
  4204. { id: 'flex1', min: 11, resetStack: true }
  4205. ];
  4206. function CFFParser(file, properties, seacAnalysisEnabled) {
  4207. this.bytes = file.getBytes();
  4208. this.properties = properties;
  4209. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  4210. }
  4211. CFFParser.prototype = {
  4212. parse: function CFFParser_parse() {
  4213. var properties = this.properties;
  4214. var cff = new CFF();
  4215. this.cff = cff;
  4216. // The first five sections must be in order, all the others are reached
  4217. // via offsets contained in one of the below.
  4218. var header = this.parseHeader();
  4219. var nameIndex = this.parseIndex(header.endPos);
  4220. var topDictIndex = this.parseIndex(nameIndex.endPos);
  4221. var stringIndex = this.parseIndex(topDictIndex.endPos);
  4222. var globalSubrIndex = this.parseIndex(stringIndex.endPos);
  4223. var topDictParsed = this.parseDict(topDictIndex.obj.get(0));
  4224. var topDict = this.createDict(CFFTopDict, topDictParsed, cff.strings);
  4225. cff.header = header.obj;
  4226. cff.names = this.parseNameIndex(nameIndex.obj);
  4227. cff.strings = this.parseStringIndex(stringIndex.obj);
  4228. cff.topDict = topDict;
  4229. cff.globalSubrIndex = globalSubrIndex.obj;
  4230. this.parsePrivateDict(cff.topDict);
  4231. cff.isCIDFont = topDict.hasName('ROS');
  4232. var charStringOffset = topDict.getByName('CharStrings');
  4233. var charStringIndex = this.parseIndex(charStringOffset).obj;
  4234. var fontMatrix = topDict.getByName('FontMatrix');
  4235. if (fontMatrix) {
  4236. properties.fontMatrix = fontMatrix;
  4237. }
  4238. var fontBBox = topDict.getByName('FontBBox');
  4239. if (fontBBox) {
  4240. // adjusting ascent/descent
  4241. properties.ascent = fontBBox[3];
  4242. properties.descent = fontBBox[1];
  4243. properties.ascentScaled = true;
  4244. }
  4245. var charset, encoding;
  4246. if (cff.isCIDFont) {
  4247. var fdArrayIndex = this.parseIndex(topDict.getByName('FDArray')).obj;
  4248. for (var i = 0, ii = fdArrayIndex.count; i < ii; ++i) {
  4249. var dictRaw = fdArrayIndex.get(i);
  4250. var fontDict = this.createDict(CFFTopDict, this.parseDict(dictRaw),
  4251. cff.strings);
  4252. this.parsePrivateDict(fontDict);
  4253. cff.fdArray.push(fontDict);
  4254. }
  4255. // cid fonts don't have an encoding
  4256. encoding = null;
  4257. charset = this.parseCharsets(topDict.getByName('charset'),
  4258. charStringIndex.count, cff.strings, true);
  4259. cff.fdSelect = this.parseFDSelect(topDict.getByName('FDSelect'),
  4260. charStringIndex.count);
  4261. } else {
  4262. charset = this.parseCharsets(topDict.getByName('charset'),
  4263. charStringIndex.count, cff.strings, false);
  4264. encoding = this.parseEncoding(topDict.getByName('Encoding'),
  4265. properties,
  4266. cff.strings, charset.charset);
  4267. }
  4268. cff.charset = charset;
  4269. cff.encoding = encoding;
  4270. var charStringsAndSeacs = this.parseCharStrings(
  4271. charStringIndex,
  4272. topDict.privateDict.subrsIndex,
  4273. globalSubrIndex.obj,
  4274. cff.fdSelect,
  4275. cff.fdArray);
  4276. cff.charStrings = charStringsAndSeacs.charStrings;
  4277. cff.seacs = charStringsAndSeacs.seacs;
  4278. cff.widths = charStringsAndSeacs.widths;
  4279. return cff;
  4280. },
  4281. parseHeader: function CFFParser_parseHeader() {
  4282. var bytes = this.bytes;
  4283. var bytesLength = bytes.length;
  4284. var offset = 0;
  4285. // Prevent an infinite loop, by checking that the offset is within the
  4286. // bounds of the bytes array. Necessary in empty, or invalid, font files.
  4287. while (offset < bytesLength && bytes[offset] !== 1) {
  4288. ++offset;
  4289. }
  4290. if (offset >= bytesLength) {
  4291. error('Invalid CFF header');
  4292. } else if (offset !== 0) {
  4293. info('cff data is shifted');
  4294. bytes = bytes.subarray(offset);
  4295. this.bytes = bytes;
  4296. }
  4297. var major = bytes[0];
  4298. var minor = bytes[1];
  4299. var hdrSize = bytes[2];
  4300. var offSize = bytes[3];
  4301. var header = new CFFHeader(major, minor, hdrSize, offSize);
  4302. return { obj: header, endPos: hdrSize };
  4303. },
  4304. parseDict: function CFFParser_parseDict(dict) {
  4305. var pos = 0;
  4306. function parseOperand() {
  4307. var value = dict[pos++];
  4308. if (value === 30) {
  4309. return parseFloatOperand(pos);
  4310. } else if (value === 28) {
  4311. value = dict[pos++];
  4312. value = ((value << 24) | (dict[pos++] << 16)) >> 16;
  4313. return value;
  4314. } else if (value === 29) {
  4315. value = dict[pos++];
  4316. value = (value << 8) | dict[pos++];
  4317. value = (value << 8) | dict[pos++];
  4318. value = (value << 8) | dict[pos++];
  4319. return value;
  4320. } else if (value >= 32 && value <= 246) {
  4321. return value - 139;
  4322. } else if (value >= 247 && value <= 250) {
  4323. return ((value - 247) * 256) + dict[pos++] + 108;
  4324. } else if (value >= 251 && value <= 254) {
  4325. return -((value - 251) * 256) - dict[pos++] - 108;
  4326. } else {
  4327. error('255 is not a valid DICT command');
  4328. }
  4329. return -1;
  4330. }
  4331. function parseFloatOperand() {
  4332. var str = '';
  4333. var eof = 15;
  4334. var lookup = ['0', '1', '2', '3', '4', '5', '6', '7', '8',
  4335. '9', '.', 'E', 'E-', null, '-'];
  4336. var length = dict.length;
  4337. while (pos < length) {
  4338. var b = dict[pos++];
  4339. var b1 = b >> 4;
  4340. var b2 = b & 15;
  4341. if (b1 === eof) {
  4342. break;
  4343. }
  4344. str += lookup[b1];
  4345. if (b2 === eof) {
  4346. break;
  4347. }
  4348. str += lookup[b2];
  4349. }
  4350. return parseFloat(str);
  4351. }
  4352. var operands = [];
  4353. var entries = [];
  4354. pos = 0;
  4355. var end = dict.length;
  4356. while (pos < end) {
  4357. var b = dict[pos];
  4358. if (b <= 21) {
  4359. if (b === 12) {
  4360. b = (b << 8) | dict[++pos];
  4361. }
  4362. entries.push([b, operands]);
  4363. operands = [];
  4364. ++pos;
  4365. } else {
  4366. operands.push(parseOperand());
  4367. }
  4368. }
  4369. return entries;
  4370. },
  4371. parseIndex: function CFFParser_parseIndex(pos) {
  4372. var cffIndex = new CFFIndex();
  4373. var bytes = this.bytes;
  4374. var count = (bytes[pos++] << 8) | bytes[pos++];
  4375. var offsets = [];
  4376. var end = pos;
  4377. var i, ii;
  4378. if (count !== 0) {
  4379. var offsetSize = bytes[pos++];
  4380. // add 1 for offset to determine size of last object
  4381. var startPos = pos + ((count + 1) * offsetSize) - 1;
  4382. for (i = 0, ii = count + 1; i < ii; ++i) {
  4383. var offset = 0;
  4384. for (var j = 0; j < offsetSize; ++j) {
  4385. offset <<= 8;
  4386. offset += bytes[pos++];
  4387. }
  4388. offsets.push(startPos + offset);
  4389. }
  4390. end = offsets[count];
  4391. }
  4392. for (i = 0, ii = offsets.length - 1; i < ii; ++i) {
  4393. var offsetStart = offsets[i];
  4394. var offsetEnd = offsets[i + 1];
  4395. cffIndex.add(bytes.subarray(offsetStart, offsetEnd));
  4396. }
  4397. return {obj: cffIndex, endPos: end};
  4398. },
  4399. parseNameIndex: function CFFParser_parseNameIndex(index) {
  4400. var names = [];
  4401. for (var i = 0, ii = index.count; i < ii; ++i) {
  4402. var name = index.get(i);
  4403. // OTS doesn't allow names to be over 127 characters.
  4404. var length = Math.min(name.length, 127);
  4405. var data = [];
  4406. // OTS also only permits certain characters in the name.
  4407. for (var j = 0; j < length; ++j) {
  4408. var c = name[j];
  4409. if (j === 0 && c === 0) {
  4410. data[j] = c;
  4411. continue;
  4412. }
  4413. if ((c < 33 || c > 126) || c === 91 /* [ */ || c === 93 /* ] */ ||
  4414. c === 40 /* ( */ || c === 41 /* ) */ || c === 123 /* { */ ||
  4415. c === 125 /* } */ || c === 60 /* < */ || c === 62 /* > */ ||
  4416. c === 47 /* / */ || c === 37 /* % */ || c === 35 /* # */) {
  4417. data[j] = 95;
  4418. continue;
  4419. }
  4420. data[j] = c;
  4421. }
  4422. names.push(bytesToString(data));
  4423. }
  4424. return names;
  4425. },
  4426. parseStringIndex: function CFFParser_parseStringIndex(index) {
  4427. var strings = new CFFStrings();
  4428. for (var i = 0, ii = index.count; i < ii; ++i) {
  4429. var data = index.get(i);
  4430. strings.add(bytesToString(data));
  4431. }
  4432. return strings;
  4433. },
  4434. createDict: function CFFParser_createDict(Type, dict, strings) {
  4435. var cffDict = new Type(strings);
  4436. for (var i = 0, ii = dict.length; i < ii; ++i) {
  4437. var pair = dict[i];
  4438. var key = pair[0];
  4439. var value = pair[1];
  4440. cffDict.setByKey(key, value);
  4441. }
  4442. return cffDict;
  4443. },
  4444. parseCharString: function CFFParser_parseCharString(state, data,
  4445. localSubrIndex,
  4446. globalSubrIndex) {
  4447. if (state.callDepth > MAX_SUBR_NESTING) {
  4448. return false;
  4449. }
  4450. var stackSize = state.stackSize;
  4451. var stack = state.stack;
  4452. var length = data.length;
  4453. for (var j = 0; j < length;) {
  4454. var value = data[j++];
  4455. var validationCommand = null;
  4456. if (value === 12) {
  4457. var q = data[j++];
  4458. if (q === 0) {
  4459. // The CFF specification state that the 'dotsection' command
  4460. // (12, 0) is deprecated and treated as a no-op, but all Type2
  4461. // charstrings processors should support them. Unfortunately
  4462. // the font sanitizer don't. As a workaround the sequence (12, 0)
  4463. // is replaced by a useless (0, hmoveto).
  4464. data[j - 2] = 139;
  4465. data[j - 1] = 22;
  4466. stackSize = 0;
  4467. } else {
  4468. validationCommand = CharstringValidationData12[q];
  4469. }
  4470. } else if (value === 28) { // number (16 bit)
  4471. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16)) >> 16;
  4472. j += 2;
  4473. stackSize++;
  4474. } else if (value === 14) {
  4475. if (stackSize >= 4) {
  4476. stackSize -= 4;
  4477. if (this.seacAnalysisEnabled) {
  4478. state.seac = stack.slice(stackSize, stackSize + 4);
  4479. return false;
  4480. }
  4481. }
  4482. validationCommand = CharstringValidationData[value];
  4483. } else if (value >= 32 && value <= 246) { // number
  4484. stack[stackSize] = value - 139;
  4485. stackSize++;
  4486. } else if (value >= 247 && value <= 254) { // number (+1 bytes)
  4487. stack[stackSize] = (value < 251 ?
  4488. ((value - 247) << 8) + data[j] + 108 :
  4489. -((value - 251) << 8) - data[j] - 108);
  4490. j++;
  4491. stackSize++;
  4492. } else if (value === 255) { // number (32 bit)
  4493. stack[stackSize] = ((data[j] << 24) | (data[j + 1] << 16) |
  4494. (data[j + 2] << 8) | data[j + 3]) / 65536;
  4495. j += 4;
  4496. stackSize++;
  4497. } else if (value === 19 || value === 20) {
  4498. state.hints += stackSize >> 1;
  4499. // skipping right amount of hints flag data
  4500. j += (state.hints + 7) >> 3;
  4501. stackSize %= 2;
  4502. validationCommand = CharstringValidationData[value];
  4503. } else if (value === 10 || value === 29) {
  4504. var subrsIndex;
  4505. if (value === 10) {
  4506. subrsIndex = localSubrIndex;
  4507. } else {
  4508. subrsIndex = globalSubrIndex;
  4509. }
  4510. if (!subrsIndex) {
  4511. validationCommand = CharstringValidationData[value];
  4512. warn('Missing subrsIndex for ' + validationCommand.id);
  4513. return false;
  4514. }
  4515. var bias = 32768;
  4516. if (subrsIndex.count < 1240) {
  4517. bias = 107;
  4518. } else if (subrsIndex.count < 33900) {
  4519. bias = 1131;
  4520. }
  4521. var subrNumber = stack[--stackSize] + bias;
  4522. if (subrNumber < 0 || subrNumber >= subrsIndex.count) {
  4523. validationCommand = CharstringValidationData[value];
  4524. warn('Out of bounds subrIndex for ' + validationCommand.id);
  4525. return false;
  4526. }
  4527. state.stackSize = stackSize;
  4528. state.callDepth++;
  4529. var valid = this.parseCharString(state, subrsIndex.get(subrNumber),
  4530. localSubrIndex, globalSubrIndex);
  4531. if (!valid) {
  4532. return false;
  4533. }
  4534. state.callDepth--;
  4535. stackSize = state.stackSize;
  4536. continue;
  4537. } else if (value === 11) {
  4538. state.stackSize = stackSize;
  4539. return true;
  4540. } else {
  4541. validationCommand = CharstringValidationData[value];
  4542. }
  4543. if (validationCommand) {
  4544. if (validationCommand.stem) {
  4545. state.hints += stackSize >> 1;
  4546. }
  4547. if ('min' in validationCommand) {
  4548. if (!state.undefStack && stackSize < validationCommand.min) {
  4549. warn('Not enough parameters for ' + validationCommand.id +
  4550. '; actual: ' + stackSize +
  4551. ', expected: ' + validationCommand.min);
  4552. return false;
  4553. }
  4554. }
  4555. if (state.firstStackClearing && validationCommand.stackClearing) {
  4556. state.firstStackClearing = false;
  4557. // the optional character width can be found before the first
  4558. // stack-clearing command arguments
  4559. stackSize -= validationCommand.min;
  4560. if (stackSize >= 2 && validationCommand.stem) {
  4561. // there are even amount of arguments for stem commands
  4562. stackSize %= 2;
  4563. } else if (stackSize > 1) {
  4564. warn('Found too many parameters for stack-clearing command');
  4565. }
  4566. if (stackSize > 0 && stack[stackSize - 1] >= 0) {
  4567. state.width = stack[stackSize - 1];
  4568. }
  4569. }
  4570. if ('stackDelta' in validationCommand) {
  4571. if ('stackFn' in validationCommand) {
  4572. validationCommand.stackFn(stack, stackSize);
  4573. }
  4574. stackSize += validationCommand.stackDelta;
  4575. } else if (validationCommand.stackClearing) {
  4576. stackSize = 0;
  4577. } else if (validationCommand.resetStack) {
  4578. stackSize = 0;
  4579. state.undefStack = false;
  4580. } else if (validationCommand.undefStack) {
  4581. stackSize = 0;
  4582. state.undefStack = true;
  4583. state.firstStackClearing = false;
  4584. }
  4585. }
  4586. }
  4587. state.stackSize = stackSize;
  4588. return true;
  4589. },
  4590. parseCharStrings: function CFFParser_parseCharStrings(charStrings,
  4591. localSubrIndex,
  4592. globalSubrIndex,
  4593. fdSelect,
  4594. fdArray) {
  4595. var seacs = [];
  4596. var widths = [];
  4597. var count = charStrings.count;
  4598. for (var i = 0; i < count; i++) {
  4599. var charstring = charStrings.get(i);
  4600. var state = {
  4601. callDepth: 0,
  4602. stackSize: 0,
  4603. stack: [],
  4604. undefStack: true,
  4605. hints: 0,
  4606. firstStackClearing: true,
  4607. seac: null,
  4608. width: null
  4609. };
  4610. var valid = true;
  4611. var localSubrToUse = null;
  4612. if (fdSelect && fdArray.length) {
  4613. var fdIndex = fdSelect.getFDIndex(i);
  4614. if (fdIndex === -1) {
  4615. warn('Glyph index is not in fd select.');
  4616. valid = false;
  4617. }
  4618. if (fdIndex >= fdArray.length) {
  4619. warn('Invalid fd index for glyph index.');
  4620. valid = false;
  4621. }
  4622. if (valid) {
  4623. localSubrToUse = fdArray[fdIndex].privateDict.subrsIndex;
  4624. }
  4625. } else if (localSubrIndex) {
  4626. localSubrToUse = localSubrIndex;
  4627. }
  4628. if (valid) {
  4629. valid = this.parseCharString(state, charstring, localSubrToUse,
  4630. globalSubrIndex);
  4631. }
  4632. if (state.width !== null) {
  4633. widths[i] = state.width;
  4634. }
  4635. if (state.seac !== null) {
  4636. seacs[i] = state.seac;
  4637. }
  4638. if (!valid) {
  4639. // resetting invalid charstring to single 'endchar'
  4640. charStrings.set(i, new Uint8Array([14]));
  4641. }
  4642. }
  4643. return { charStrings: charStrings, seacs: seacs, widths: widths };
  4644. },
  4645. emptyPrivateDictionary:
  4646. function CFFParser_emptyPrivateDictionary(parentDict) {
  4647. var privateDict = this.createDict(CFFPrivateDict, [],
  4648. parentDict.strings);
  4649. parentDict.setByKey(18, [0, 0]);
  4650. parentDict.privateDict = privateDict;
  4651. },
  4652. parsePrivateDict: function CFFParser_parsePrivateDict(parentDict) {
  4653. // no private dict, do nothing
  4654. if (!parentDict.hasName('Private')) {
  4655. this.emptyPrivateDictionary(parentDict);
  4656. return;
  4657. }
  4658. var privateOffset = parentDict.getByName('Private');
  4659. // make sure the params are formatted correctly
  4660. if (!isArray(privateOffset) || privateOffset.length !== 2) {
  4661. parentDict.removeByName('Private');
  4662. return;
  4663. }
  4664. var size = privateOffset[0];
  4665. var offset = privateOffset[1];
  4666. // remove empty dicts or ones that refer to invalid location
  4667. if (size === 0 || offset >= this.bytes.length) {
  4668. this.emptyPrivateDictionary(parentDict);
  4669. return;
  4670. }
  4671. var privateDictEnd = offset + size;
  4672. var dictData = this.bytes.subarray(offset, privateDictEnd);
  4673. var dict = this.parseDict(dictData);
  4674. var privateDict = this.createDict(CFFPrivateDict, dict,
  4675. parentDict.strings);
  4676. parentDict.privateDict = privateDict;
  4677. // Parse the Subrs index also since it's relative to the private dict.
  4678. if (!privateDict.getByName('Subrs')) {
  4679. return;
  4680. }
  4681. var subrsOffset = privateDict.getByName('Subrs');
  4682. var relativeOffset = offset + subrsOffset;
  4683. // Validate the offset.
  4684. if (subrsOffset === 0 || relativeOffset >= this.bytes.length) {
  4685. this.emptyPrivateDictionary(parentDict);
  4686. return;
  4687. }
  4688. var subrsIndex = this.parseIndex(relativeOffset);
  4689. privateDict.subrsIndex = subrsIndex.obj;
  4690. },
  4691. parseCharsets: function CFFParser_parseCharsets(pos, length, strings, cid) {
  4692. if (pos === 0) {
  4693. return new CFFCharset(true, CFFCharsetPredefinedTypes.ISO_ADOBE,
  4694. ISOAdobeCharset);
  4695. } else if (pos === 1) {
  4696. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT,
  4697. ExpertCharset);
  4698. } else if (pos === 2) {
  4699. return new CFFCharset(true, CFFCharsetPredefinedTypes.EXPERT_SUBSET,
  4700. ExpertSubsetCharset);
  4701. }
  4702. var bytes = this.bytes;
  4703. var start = pos;
  4704. var format = bytes[pos++];
  4705. var charset = ['.notdef'];
  4706. var id, count, i;
  4707. // subtract 1 for the .notdef glyph
  4708. length -= 1;
  4709. switch (format) {
  4710. case 0:
  4711. for (i = 0; i < length; i++) {
  4712. id = (bytes[pos++] << 8) | bytes[pos++];
  4713. charset.push(cid ? id : strings.get(id));
  4714. }
  4715. break;
  4716. case 1:
  4717. while (charset.length <= length) {
  4718. id = (bytes[pos++] << 8) | bytes[pos++];
  4719. count = bytes[pos++];
  4720. for (i = 0; i <= count; i++) {
  4721. charset.push(cid ? id++ : strings.get(id++));
  4722. }
  4723. }
  4724. break;
  4725. case 2:
  4726. while (charset.length <= length) {
  4727. id = (bytes[pos++] << 8) | bytes[pos++];
  4728. count = (bytes[pos++] << 8) | bytes[pos++];
  4729. for (i = 0; i <= count; i++) {
  4730. charset.push(cid ? id++ : strings.get(id++));
  4731. }
  4732. }
  4733. break;
  4734. default:
  4735. error('Unknown charset format');
  4736. }
  4737. // Raw won't be needed if we actually compile the charset.
  4738. var end = pos;
  4739. var raw = bytes.subarray(start, end);
  4740. return new CFFCharset(false, format, charset, raw);
  4741. },
  4742. parseEncoding: function CFFParser_parseEncoding(pos,
  4743. properties,
  4744. strings,
  4745. charset) {
  4746. var encoding = Object.create(null);
  4747. var bytes = this.bytes;
  4748. var predefined = false;
  4749. var hasSupplement = false;
  4750. var format, i, ii;
  4751. var raw = null;
  4752. function readSupplement() {
  4753. var supplementsCount = bytes[pos++];
  4754. for (i = 0; i < supplementsCount; i++) {
  4755. var code = bytes[pos++];
  4756. var sid = (bytes[pos++] << 8) + (bytes[pos++] & 0xff);
  4757. encoding[code] = charset.indexOf(strings.get(sid));
  4758. }
  4759. }
  4760. if (pos === 0 || pos === 1) {
  4761. predefined = true;
  4762. format = pos;
  4763. var baseEncoding = pos ? ExpertEncoding : StandardEncoding;
  4764. for (i = 0, ii = charset.length; i < ii; i++) {
  4765. var index = baseEncoding.indexOf(charset[i]);
  4766. if (index !== -1) {
  4767. encoding[index] = i;
  4768. }
  4769. }
  4770. } else {
  4771. var dataStart = pos;
  4772. format = bytes[pos++];
  4773. switch (format & 0x7f) {
  4774. case 0:
  4775. var glyphsCount = bytes[pos++];
  4776. for (i = 1; i <= glyphsCount; i++) {
  4777. encoding[bytes[pos++]] = i;
  4778. }
  4779. break;
  4780. case 1:
  4781. var rangesCount = bytes[pos++];
  4782. var gid = 1;
  4783. for (i = 0; i < rangesCount; i++) {
  4784. var start = bytes[pos++];
  4785. var left = bytes[pos++];
  4786. for (var j = start; j <= start + left; j++) {
  4787. encoding[j] = gid++;
  4788. }
  4789. }
  4790. break;
  4791. default:
  4792. error('Unknow encoding format: ' + format + ' in CFF');
  4793. break;
  4794. }
  4795. var dataEnd = pos;
  4796. if (format & 0x80) {
  4797. // The font sanitizer does not support CFF encoding with a
  4798. // supplement, since the encoding is not really used to map
  4799. // between gid to glyph, let's overwrite what is declared in
  4800. // the top dictionary to let the sanitizer think the font use
  4801. // StandardEncoding, that's a lie but that's ok.
  4802. bytes[dataStart] &= 0x7f;
  4803. readSupplement();
  4804. hasSupplement = true;
  4805. }
  4806. raw = bytes.subarray(dataStart, dataEnd);
  4807. }
  4808. format = format & 0x7f;
  4809. return new CFFEncoding(predefined, format, encoding, raw);
  4810. },
  4811. parseFDSelect: function CFFParser_parseFDSelect(pos, length) {
  4812. var start = pos;
  4813. var bytes = this.bytes;
  4814. var format = bytes[pos++];
  4815. var fdSelect = [];
  4816. var i;
  4817. switch (format) {
  4818. case 0:
  4819. for (i = 0; i < length; ++i) {
  4820. var id = bytes[pos++];
  4821. fdSelect.push(id);
  4822. }
  4823. break;
  4824. case 3:
  4825. var rangesCount = (bytes[pos++] << 8) | bytes[pos++];
  4826. for (i = 0; i < rangesCount; ++i) {
  4827. var first = (bytes[pos++] << 8) | bytes[pos++];
  4828. var fdIndex = bytes[pos++];
  4829. var next = (bytes[pos] << 8) | bytes[pos + 1];
  4830. for (var j = first; j < next; ++j) {
  4831. fdSelect.push(fdIndex);
  4832. }
  4833. }
  4834. // Advance past the sentinel(next).
  4835. pos += 2;
  4836. break;
  4837. default:
  4838. error('Unknown fdselect format ' + format);
  4839. break;
  4840. }
  4841. var end = pos;
  4842. return new CFFFDSelect(fdSelect, bytes.subarray(start, end));
  4843. }
  4844. };
  4845. return CFFParser;
  4846. })();
  4847. // Compact Font Format
  4848. var CFF = (function CFFClosure() {
  4849. function CFF() {
  4850. this.header = null;
  4851. this.names = [];
  4852. this.topDict = null;
  4853. this.strings = new CFFStrings();
  4854. this.globalSubrIndex = null;
  4855. // The following could really be per font, but since we only have one font
  4856. // store them here.
  4857. this.encoding = null;
  4858. this.charset = null;
  4859. this.charStrings = null;
  4860. this.fdArray = [];
  4861. this.fdSelect = null;
  4862. this.isCIDFont = false;
  4863. }
  4864. return CFF;
  4865. })();
  4866. var CFFHeader = (function CFFHeaderClosure() {
  4867. function CFFHeader(major, minor, hdrSize, offSize) {
  4868. this.major = major;
  4869. this.minor = minor;
  4870. this.hdrSize = hdrSize;
  4871. this.offSize = offSize;
  4872. }
  4873. return CFFHeader;
  4874. })();
  4875. var CFFStrings = (function CFFStringsClosure() {
  4876. function CFFStrings() {
  4877. this.strings = [];
  4878. }
  4879. CFFStrings.prototype = {
  4880. get: function CFFStrings_get(index) {
  4881. if (index >= 0 && index <= 390) {
  4882. return CFFStandardStrings[index];
  4883. }
  4884. if (index - 391 <= this.strings.length) {
  4885. return this.strings[index - 391];
  4886. }
  4887. return CFFStandardStrings[0];
  4888. },
  4889. add: function CFFStrings_add(value) {
  4890. this.strings.push(value);
  4891. },
  4892. get count() {
  4893. return this.strings.length;
  4894. }
  4895. };
  4896. return CFFStrings;
  4897. })();
  4898. var CFFIndex = (function CFFIndexClosure() {
  4899. function CFFIndex() {
  4900. this.objects = [];
  4901. this.length = 0;
  4902. }
  4903. CFFIndex.prototype = {
  4904. add: function CFFIndex_add(data) {
  4905. this.length += data.length;
  4906. this.objects.push(data);
  4907. },
  4908. set: function CFFIndex_set(index, data) {
  4909. this.length += data.length - this.objects[index].length;
  4910. this.objects[index] = data;
  4911. },
  4912. get: function CFFIndex_get(index) {
  4913. return this.objects[index];
  4914. },
  4915. get count() {
  4916. return this.objects.length;
  4917. }
  4918. };
  4919. return CFFIndex;
  4920. })();
  4921. var CFFDict = (function CFFDictClosure() {
  4922. function CFFDict(tables, strings) {
  4923. this.keyToNameMap = tables.keyToNameMap;
  4924. this.nameToKeyMap = tables.nameToKeyMap;
  4925. this.defaults = tables.defaults;
  4926. this.types = tables.types;
  4927. this.opcodes = tables.opcodes;
  4928. this.order = tables.order;
  4929. this.strings = strings;
  4930. this.values = Object.create(null);
  4931. }
  4932. CFFDict.prototype = {
  4933. // value should always be an array
  4934. setByKey: function CFFDict_setByKey(key, value) {
  4935. if (!(key in this.keyToNameMap)) {
  4936. return false;
  4937. }
  4938. // ignore empty values
  4939. if (value.length === 0) {
  4940. return true;
  4941. }
  4942. var type = this.types[key];
  4943. // remove the array wrapping these types of values
  4944. if (type === 'num' || type === 'sid' || type === 'offset') {
  4945. value = value[0];
  4946. }
  4947. this.values[key] = value;
  4948. return true;
  4949. },
  4950. setByName: function CFFDict_setByName(name, value) {
  4951. if (!(name in this.nameToKeyMap)) {
  4952. error('Invalid dictionary name "' + name + '"');
  4953. }
  4954. this.values[this.nameToKeyMap[name]] = value;
  4955. },
  4956. hasName: function CFFDict_hasName(name) {
  4957. return this.nameToKeyMap[name] in this.values;
  4958. },
  4959. getByName: function CFFDict_getByName(name) {
  4960. if (!(name in this.nameToKeyMap)) {
  4961. error('Invalid dictionary name "' + name + '"');
  4962. }
  4963. var key = this.nameToKeyMap[name];
  4964. if (!(key in this.values)) {
  4965. return this.defaults[key];
  4966. }
  4967. return this.values[key];
  4968. },
  4969. removeByName: function CFFDict_removeByName(name) {
  4970. delete this.values[this.nameToKeyMap[name]];
  4971. }
  4972. };
  4973. CFFDict.createTables = function CFFDict_createTables(layout) {
  4974. var tables = {
  4975. keyToNameMap: {},
  4976. nameToKeyMap: {},
  4977. defaults: {},
  4978. types: {},
  4979. opcodes: {},
  4980. order: []
  4981. };
  4982. for (var i = 0, ii = layout.length; i < ii; ++i) {
  4983. var entry = layout[i];
  4984. var key = isArray(entry[0]) ? (entry[0][0] << 8) + entry[0][1] : entry[0];
  4985. tables.keyToNameMap[key] = entry[1];
  4986. tables.nameToKeyMap[entry[1]] = key;
  4987. tables.types[key] = entry[2];
  4988. tables.defaults[key] = entry[3];
  4989. tables.opcodes[key] = isArray(entry[0]) ? entry[0] : [entry[0]];
  4990. tables.order.push(key);
  4991. }
  4992. return tables;
  4993. };
  4994. return CFFDict;
  4995. })();
  4996. var CFFTopDict = (function CFFTopDictClosure() {
  4997. var layout = [
  4998. [[12, 30], 'ROS', ['sid', 'sid', 'num'], null],
  4999. [[12, 20], 'SyntheticBase', 'num', null],
  5000. [0, 'version', 'sid', null],
  5001. [1, 'Notice', 'sid', null],
  5002. [[12, 0], 'Copyright', 'sid', null],
  5003. [2, 'FullName', 'sid', null],
  5004. [3, 'FamilyName', 'sid', null],
  5005. [4, 'Weight', 'sid', null],
  5006. [[12, 1], 'isFixedPitch', 'num', 0],
  5007. [[12, 2], 'ItalicAngle', 'num', 0],
  5008. [[12, 3], 'UnderlinePosition', 'num', -100],
  5009. [[12, 4], 'UnderlineThickness', 'num', 50],
  5010. [[12, 5], 'PaintType', 'num', 0],
  5011. [[12, 6], 'CharstringType', 'num', 2],
  5012. [[12, 7], 'FontMatrix', ['num', 'num', 'num', 'num', 'num', 'num'],
  5013. [0.001, 0, 0, 0.001, 0, 0]],
  5014. [13, 'UniqueID', 'num', null],
  5015. [5, 'FontBBox', ['num', 'num', 'num', 'num'], [0, 0, 0, 0]],
  5016. [[12, 8], 'StrokeWidth', 'num', 0],
  5017. [14, 'XUID', 'array', null],
  5018. [15, 'charset', 'offset', 0],
  5019. [16, 'Encoding', 'offset', 0],
  5020. [17, 'CharStrings', 'offset', 0],
  5021. [18, 'Private', ['offset', 'offset'], null],
  5022. [[12, 21], 'PostScript', 'sid', null],
  5023. [[12, 22], 'BaseFontName', 'sid', null],
  5024. [[12, 23], 'BaseFontBlend', 'delta', null],
  5025. [[12, 31], 'CIDFontVersion', 'num', 0],
  5026. [[12, 32], 'CIDFontRevision', 'num', 0],
  5027. [[12, 33], 'CIDFontType', 'num', 0],
  5028. [[12, 34], 'CIDCount', 'num', 8720],
  5029. [[12, 35], 'UIDBase', 'num', null],
  5030. // XXX: CID Fonts on DirectWrite 6.1 only seem to work if FDSelect comes
  5031. // before FDArray.
  5032. [[12, 37], 'FDSelect', 'offset', null],
  5033. [[12, 36], 'FDArray', 'offset', null],
  5034. [[12, 38], 'FontName', 'sid', null]
  5035. ];
  5036. var tables = null;
  5037. function CFFTopDict(strings) {
  5038. if (tables === null) {
  5039. tables = CFFDict.createTables(layout);
  5040. }
  5041. CFFDict.call(this, tables, strings);
  5042. this.privateDict = null;
  5043. }
  5044. CFFTopDict.prototype = Object.create(CFFDict.prototype);
  5045. return CFFTopDict;
  5046. })();
  5047. var CFFPrivateDict = (function CFFPrivateDictClosure() {
  5048. var layout = [
  5049. [6, 'BlueValues', 'delta', null],
  5050. [7, 'OtherBlues', 'delta', null],
  5051. [8, 'FamilyBlues', 'delta', null],
  5052. [9, 'FamilyOtherBlues', 'delta', null],
  5053. [[12, 9], 'BlueScale', 'num', 0.039625],
  5054. [[12, 10], 'BlueShift', 'num', 7],
  5055. [[12, 11], 'BlueFuzz', 'num', 1],
  5056. [10, 'StdHW', 'num', null],
  5057. [11, 'StdVW', 'num', null],
  5058. [[12, 12], 'StemSnapH', 'delta', null],
  5059. [[12, 13], 'StemSnapV', 'delta', null],
  5060. [[12, 14], 'ForceBold', 'num', 0],
  5061. [[12, 17], 'LanguageGroup', 'num', 0],
  5062. [[12, 18], 'ExpansionFactor', 'num', 0.06],
  5063. [[12, 19], 'initialRandomSeed', 'num', 0],
  5064. [20, 'defaultWidthX', 'num', 0],
  5065. [21, 'nominalWidthX', 'num', 0],
  5066. [19, 'Subrs', 'offset', null]
  5067. ];
  5068. var tables = null;
  5069. function CFFPrivateDict(strings) {
  5070. if (tables === null) {
  5071. tables = CFFDict.createTables(layout);
  5072. }
  5073. CFFDict.call(this, tables, strings);
  5074. this.subrsIndex = null;
  5075. }
  5076. CFFPrivateDict.prototype = Object.create(CFFDict.prototype);
  5077. return CFFPrivateDict;
  5078. })();
  5079. var CFFCharsetPredefinedTypes = {
  5080. ISO_ADOBE: 0,
  5081. EXPERT: 1,
  5082. EXPERT_SUBSET: 2
  5083. };
  5084. var CFFCharset = (function CFFCharsetClosure() {
  5085. function CFFCharset(predefined, format, charset, raw) {
  5086. this.predefined = predefined;
  5087. this.format = format;
  5088. this.charset = charset;
  5089. this.raw = raw;
  5090. }
  5091. return CFFCharset;
  5092. })();
  5093. var CFFEncoding = (function CFFEncodingClosure() {
  5094. function CFFEncoding(predefined, format, encoding, raw) {
  5095. this.predefined = predefined;
  5096. this.format = format;
  5097. this.encoding = encoding;
  5098. this.raw = raw;
  5099. }
  5100. return CFFEncoding;
  5101. })();
  5102. var CFFFDSelect = (function CFFFDSelectClosure() {
  5103. function CFFFDSelect(fdSelect, raw) {
  5104. this.fdSelect = fdSelect;
  5105. this.raw = raw;
  5106. }
  5107. CFFFDSelect.prototype = {
  5108. getFDIndex: function CFFFDSelect_get(glyphIndex) {
  5109. if (glyphIndex < 0 || glyphIndex >= this.fdSelect.length) {
  5110. return -1;
  5111. }
  5112. return this.fdSelect[glyphIndex];
  5113. }
  5114. };
  5115. return CFFFDSelect;
  5116. })();
  5117. // Helper class to keep track of where an offset is within the data and helps
  5118. // filling in that offset once it's known.
  5119. var CFFOffsetTracker = (function CFFOffsetTrackerClosure() {
  5120. function CFFOffsetTracker() {
  5121. this.offsets = Object.create(null);
  5122. }
  5123. CFFOffsetTracker.prototype = {
  5124. isTracking: function CFFOffsetTracker_isTracking(key) {
  5125. return key in this.offsets;
  5126. },
  5127. track: function CFFOffsetTracker_track(key, location) {
  5128. if (key in this.offsets) {
  5129. error('Already tracking location of ' + key);
  5130. }
  5131. this.offsets[key] = location;
  5132. },
  5133. offset: function CFFOffsetTracker_offset(value) {
  5134. for (var key in this.offsets) {
  5135. this.offsets[key] += value;
  5136. }
  5137. },
  5138. setEntryLocation: function CFFOffsetTracker_setEntryLocation(key,
  5139. values,
  5140. output) {
  5141. if (!(key in this.offsets)) {
  5142. error('Not tracking location of ' + key);
  5143. }
  5144. var data = output.data;
  5145. var dataOffset = this.offsets[key];
  5146. var size = 5;
  5147. for (var i = 0, ii = values.length; i < ii; ++i) {
  5148. var offset0 = i * size + dataOffset;
  5149. var offset1 = offset0 + 1;
  5150. var offset2 = offset0 + 2;
  5151. var offset3 = offset0 + 3;
  5152. var offset4 = offset0 + 4;
  5153. // It's easy to screw up offsets so perform this sanity check.
  5154. if (data[offset0] !== 0x1d || data[offset1] !== 0 ||
  5155. data[offset2] !== 0 || data[offset3] !== 0 || data[offset4] !== 0) {
  5156. error('writing to an offset that is not empty');
  5157. }
  5158. var value = values[i];
  5159. data[offset0] = 0x1d;
  5160. data[offset1] = (value >> 24) & 0xFF;
  5161. data[offset2] = (value >> 16) & 0xFF;
  5162. data[offset3] = (value >> 8) & 0xFF;
  5163. data[offset4] = value & 0xFF;
  5164. }
  5165. }
  5166. };
  5167. return CFFOffsetTracker;
  5168. })();
  5169. // Takes a CFF and converts it to the binary representation.
  5170. var CFFCompiler = (function CFFCompilerClosure() {
  5171. function CFFCompiler(cff) {
  5172. this.cff = cff;
  5173. }
  5174. CFFCompiler.prototype = {
  5175. compile: function CFFCompiler_compile() {
  5176. var cff = this.cff;
  5177. var output = {
  5178. data: [],
  5179. length: 0,
  5180. add: function CFFCompiler_add(data) {
  5181. this.data = this.data.concat(data);
  5182. this.length = this.data.length;
  5183. }
  5184. };
  5185. // Compile the five entries that must be in order.
  5186. var header = this.compileHeader(cff.header);
  5187. output.add(header);
  5188. var nameIndex = this.compileNameIndex(cff.names);
  5189. output.add(nameIndex);
  5190. if (cff.isCIDFont) {
  5191. // The spec is unclear on how font matrices should relate to each other
  5192. // when there is one in the main top dict and the sub top dicts.
  5193. // Windows handles this differently than linux and osx so we have to
  5194. // normalize to work on all.
  5195. // Rules based off of some mailing list discussions:
  5196. // - If main font has a matrix and subfont doesn't, use the main matrix.
  5197. // - If no main font matrix and there is a subfont matrix, use the
  5198. // subfont matrix.
  5199. // - If both have matrices, concat together.
  5200. // - If neither have matrices, use default.
  5201. // To make this work on all platforms we move the top matrix into each
  5202. // sub top dict and concat if necessary.
  5203. if (cff.topDict.hasName('FontMatrix')) {
  5204. var base = cff.topDict.getByName('FontMatrix');
  5205. cff.topDict.removeByName('FontMatrix');
  5206. for (var i = 0, ii = cff.fdArray.length; i < ii; i++) {
  5207. var subDict = cff.fdArray[i];
  5208. var matrix = base.slice(0);
  5209. if (subDict.hasName('FontMatrix')) {
  5210. matrix = Util.transform(matrix, subDict.getByName('FontMatrix'));
  5211. }
  5212. subDict.setByName('FontMatrix', matrix);
  5213. }
  5214. }
  5215. }
  5216. var compiled = this.compileTopDicts([cff.topDict],
  5217. output.length,
  5218. cff.isCIDFont);
  5219. output.add(compiled.output);
  5220. var topDictTracker = compiled.trackers[0];
  5221. var stringIndex = this.compileStringIndex(cff.strings.strings);
  5222. output.add(stringIndex);
  5223. var globalSubrIndex = this.compileIndex(cff.globalSubrIndex);
  5224. output.add(globalSubrIndex);
  5225. // Now start on the other entries that have no specfic order.
  5226. if (cff.encoding && cff.topDict.hasName('Encoding')) {
  5227. if (cff.encoding.predefined) {
  5228. topDictTracker.setEntryLocation('Encoding', [cff.encoding.format],
  5229. output);
  5230. } else {
  5231. var encoding = this.compileEncoding(cff.encoding);
  5232. topDictTracker.setEntryLocation('Encoding', [output.length], output);
  5233. output.add(encoding);
  5234. }
  5235. }
  5236. if (cff.charset && cff.topDict.hasName('charset')) {
  5237. if (cff.charset.predefined) {
  5238. topDictTracker.setEntryLocation('charset', [cff.charset.format],
  5239. output);
  5240. } else {
  5241. var charset = this.compileCharset(cff.charset);
  5242. topDictTracker.setEntryLocation('charset', [output.length], output);
  5243. output.add(charset);
  5244. }
  5245. }
  5246. var charStrings = this.compileCharStrings(cff.charStrings);
  5247. topDictTracker.setEntryLocation('CharStrings', [output.length], output);
  5248. output.add(charStrings);
  5249. if (cff.isCIDFont) {
  5250. // For some reason FDSelect must be in front of FDArray on windows. OSX
  5251. // and linux don't seem to care.
  5252. topDictTracker.setEntryLocation('FDSelect', [output.length], output);
  5253. var fdSelect = this.compileFDSelect(cff.fdSelect.raw);
  5254. output.add(fdSelect);
  5255. // It is unclear if the sub font dictionary can have CID related
  5256. // dictionary keys, but the sanitizer doesn't like them so remove them.
  5257. compiled = this.compileTopDicts(cff.fdArray, output.length, true);
  5258. topDictTracker.setEntryLocation('FDArray', [output.length], output);
  5259. output.add(compiled.output);
  5260. var fontDictTrackers = compiled.trackers;
  5261. this.compilePrivateDicts(cff.fdArray, fontDictTrackers, output);
  5262. }
  5263. this.compilePrivateDicts([cff.topDict], [topDictTracker], output);
  5264. // If the font data ends with INDEX whose object data is zero-length,
  5265. // the sanitizer will bail out. Add a dummy byte to avoid that.
  5266. output.add([0]);
  5267. return output.data;
  5268. },
  5269. encodeNumber: function CFFCompiler_encodeNumber(value) {
  5270. if (parseFloat(value) === parseInt(value, 10) && !isNaN(value)) { // isInt
  5271. return this.encodeInteger(value);
  5272. } else {
  5273. return this.encodeFloat(value);
  5274. }
  5275. },
  5276. encodeFloat: function CFFCompiler_encodeFloat(num) {
  5277. var value = num.toString();
  5278. // rounding inaccurate doubles
  5279. var m = /\.(\d*?)(?:9{5,20}|0{5,20})\d{0,2}(?:e(.+)|$)/.exec(value);
  5280. if (m) {
  5281. var epsilon = parseFloat('1e' + ((m[2] ? +m[2] : 0) + m[1].length));
  5282. value = (Math.round(num * epsilon) / epsilon).toString();
  5283. }
  5284. var nibbles = '';
  5285. var i, ii;
  5286. for (i = 0, ii = value.length; i < ii; ++i) {
  5287. var a = value[i];
  5288. if (a === 'e') {
  5289. nibbles += value[++i] === '-' ? 'c' : 'b';
  5290. } else if (a === '.') {
  5291. nibbles += 'a';
  5292. } else if (a === '-') {
  5293. nibbles += 'e';
  5294. } else {
  5295. nibbles += a;
  5296. }
  5297. }
  5298. nibbles += (nibbles.length & 1) ? 'f' : 'ff';
  5299. var out = [30];
  5300. for (i = 0, ii = nibbles.length; i < ii; i += 2) {
  5301. out.push(parseInt(nibbles.substr(i, 2), 16));
  5302. }
  5303. return out;
  5304. },
  5305. encodeInteger: function CFFCompiler_encodeInteger(value) {
  5306. var code;
  5307. if (value >= -107 && value <= 107) {
  5308. code = [value + 139];
  5309. } else if (value >= 108 && value <= 1131) {
  5310. value = [value - 108];
  5311. code = [(value >> 8) + 247, value & 0xFF];
  5312. } else if (value >= -1131 && value <= -108) {
  5313. value = -value - 108;
  5314. code = [(value >> 8) + 251, value & 0xFF];
  5315. } else if (value >= -32768 && value <= 32767) {
  5316. code = [0x1c, (value >> 8) & 0xFF, value & 0xFF];
  5317. } else {
  5318. code = [0x1d,
  5319. (value >> 24) & 0xFF,
  5320. (value >> 16) & 0xFF,
  5321. (value >> 8) & 0xFF,
  5322. value & 0xFF];
  5323. }
  5324. return code;
  5325. },
  5326. compileHeader: function CFFCompiler_compileHeader(header) {
  5327. return [
  5328. header.major,
  5329. header.minor,
  5330. header.hdrSize,
  5331. header.offSize
  5332. ];
  5333. },
  5334. compileNameIndex: function CFFCompiler_compileNameIndex(names) {
  5335. var nameIndex = new CFFIndex();
  5336. for (var i = 0, ii = names.length; i < ii; ++i) {
  5337. nameIndex.add(stringToBytes(names[i]));
  5338. }
  5339. return this.compileIndex(nameIndex);
  5340. },
  5341. compileTopDicts: function CFFCompiler_compileTopDicts(dicts,
  5342. length,
  5343. removeCidKeys) {
  5344. var fontDictTrackers = [];
  5345. var fdArrayIndex = new CFFIndex();
  5346. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  5347. var fontDict = dicts[i];
  5348. if (removeCidKeys) {
  5349. fontDict.removeByName('CIDFontVersion');
  5350. fontDict.removeByName('CIDFontRevision');
  5351. fontDict.removeByName('CIDFontType');
  5352. fontDict.removeByName('CIDCount');
  5353. fontDict.removeByName('UIDBase');
  5354. }
  5355. var fontDictTracker = new CFFOffsetTracker();
  5356. var fontDictData = this.compileDict(fontDict, fontDictTracker);
  5357. fontDictTrackers.push(fontDictTracker);
  5358. fdArrayIndex.add(fontDictData);
  5359. fontDictTracker.offset(length);
  5360. }
  5361. fdArrayIndex = this.compileIndex(fdArrayIndex, fontDictTrackers);
  5362. return {
  5363. trackers: fontDictTrackers,
  5364. output: fdArrayIndex
  5365. };
  5366. },
  5367. compilePrivateDicts: function CFFCompiler_compilePrivateDicts(dicts,
  5368. trackers,
  5369. output) {
  5370. for (var i = 0, ii = dicts.length; i < ii; ++i) {
  5371. var fontDict = dicts[i];
  5372. assert(fontDict.privateDict && fontDict.hasName('Private'),
  5373. 'There must be an private dictionary.');
  5374. var privateDict = fontDict.privateDict;
  5375. var privateDictTracker = new CFFOffsetTracker();
  5376. var privateDictData = this.compileDict(privateDict, privateDictTracker);
  5377. var outputLength = output.length;
  5378. privateDictTracker.offset(outputLength);
  5379. if (!privateDictData.length) {
  5380. // The private dictionary was empty, set the output length to zero to
  5381. // ensure the offset length isn't out of bounds in the eyes of the
  5382. // sanitizer.
  5383. outputLength = 0;
  5384. }
  5385. trackers[i].setEntryLocation('Private',
  5386. [privateDictData.length, outputLength],
  5387. output);
  5388. output.add(privateDictData);
  5389. if (privateDict.subrsIndex && privateDict.hasName('Subrs')) {
  5390. var subrs = this.compileIndex(privateDict.subrsIndex);
  5391. privateDictTracker.setEntryLocation('Subrs', [privateDictData.length],
  5392. output);
  5393. output.add(subrs);
  5394. }
  5395. }
  5396. },
  5397. compileDict: function CFFCompiler_compileDict(dict, offsetTracker) {
  5398. var out = [];
  5399. // The dictionary keys must be in a certain order.
  5400. var order = dict.order;
  5401. for (var i = 0; i < order.length; ++i) {
  5402. var key = order[i];
  5403. if (!(key in dict.values)) {
  5404. continue;
  5405. }
  5406. var values = dict.values[key];
  5407. var types = dict.types[key];
  5408. if (!isArray(types)) {
  5409. types = [types];
  5410. }
  5411. if (!isArray(values)) {
  5412. values = [values];
  5413. }
  5414. // Remove any empty dict values.
  5415. if (values.length === 0) {
  5416. continue;
  5417. }
  5418. for (var j = 0, jj = types.length; j < jj; ++j) {
  5419. var type = types[j];
  5420. var value = values[j];
  5421. switch (type) {
  5422. case 'num':
  5423. case 'sid':
  5424. out = out.concat(this.encodeNumber(value));
  5425. break;
  5426. case 'offset':
  5427. // For offsets we just insert a 32bit integer so we don't have to
  5428. // deal with figuring out the length of the offset when it gets
  5429. // replaced later on by the compiler.
  5430. var name = dict.keyToNameMap[key];
  5431. // Some offsets have the offset and the length, so just record the
  5432. // position of the first one.
  5433. if (!offsetTracker.isTracking(name)) {
  5434. offsetTracker.track(name, out.length);
  5435. }
  5436. out = out.concat([0x1d, 0, 0, 0, 0]);
  5437. break;
  5438. case 'array':
  5439. case 'delta':
  5440. out = out.concat(this.encodeNumber(value));
  5441. for (var k = 1, kk = values.length; k < kk; ++k) {
  5442. out = out.concat(this.encodeNumber(values[k]));
  5443. }
  5444. break;
  5445. default:
  5446. error('Unknown data type of ' + type);
  5447. break;
  5448. }
  5449. }
  5450. out = out.concat(dict.opcodes[key]);
  5451. }
  5452. return out;
  5453. },
  5454. compileStringIndex: function CFFCompiler_compileStringIndex(strings) {
  5455. var stringIndex = new CFFIndex();
  5456. for (var i = 0, ii = strings.length; i < ii; ++i) {
  5457. stringIndex.add(stringToBytes(strings[i]));
  5458. }
  5459. return this.compileIndex(stringIndex);
  5460. },
  5461. compileGlobalSubrIndex: function CFFCompiler_compileGlobalSubrIndex() {
  5462. var globalSubrIndex = this.cff.globalSubrIndex;
  5463. this.out.writeByteArray(this.compileIndex(globalSubrIndex));
  5464. },
  5465. compileCharStrings: function CFFCompiler_compileCharStrings(charStrings) {
  5466. return this.compileIndex(charStrings);
  5467. },
  5468. compileCharset: function CFFCompiler_compileCharset(charset) {
  5469. return this.compileTypedArray(charset.raw);
  5470. },
  5471. compileEncoding: function CFFCompiler_compileEncoding(encoding) {
  5472. return this.compileTypedArray(encoding.raw);
  5473. },
  5474. compileFDSelect: function CFFCompiler_compileFDSelect(fdSelect) {
  5475. return this.compileTypedArray(fdSelect);
  5476. },
  5477. compileTypedArray: function CFFCompiler_compileTypedArray(data) {
  5478. var out = [];
  5479. for (var i = 0, ii = data.length; i < ii; ++i) {
  5480. out[i] = data[i];
  5481. }
  5482. return out;
  5483. },
  5484. compileIndex: function CFFCompiler_compileIndex(index, trackers) {
  5485. trackers = trackers || [];
  5486. var objects = index.objects;
  5487. // First 2 bytes contains the number of objects contained into this index
  5488. var count = objects.length;
  5489. // If there is no object, just create an index. This technically
  5490. // should just be [0, 0] but OTS has an issue with that.
  5491. if (count === 0) {
  5492. return [0, 0, 0];
  5493. }
  5494. var data = [(count >> 8) & 0xFF, count & 0xff];
  5495. var lastOffset = 1, i;
  5496. for (i = 0; i < count; ++i) {
  5497. lastOffset += objects[i].length;
  5498. }
  5499. var offsetSize;
  5500. if (lastOffset < 0x100) {
  5501. offsetSize = 1;
  5502. } else if (lastOffset < 0x10000) {
  5503. offsetSize = 2;
  5504. } else if (lastOffset < 0x1000000) {
  5505. offsetSize = 3;
  5506. } else {
  5507. offsetSize = 4;
  5508. }
  5509. // Next byte contains the offset size use to reference object in the file
  5510. data.push(offsetSize);
  5511. // Add another offset after this one because we need a new offset
  5512. var relativeOffset = 1;
  5513. for (i = 0; i < count + 1; i++) {
  5514. if (offsetSize === 1) {
  5515. data.push(relativeOffset & 0xFF);
  5516. } else if (offsetSize === 2) {
  5517. data.push((relativeOffset >> 8) & 0xFF,
  5518. relativeOffset & 0xFF);
  5519. } else if (offsetSize === 3) {
  5520. data.push((relativeOffset >> 16) & 0xFF,
  5521. (relativeOffset >> 8) & 0xFF,
  5522. relativeOffset & 0xFF);
  5523. } else {
  5524. data.push((relativeOffset >>> 24) & 0xFF,
  5525. (relativeOffset >> 16) & 0xFF,
  5526. (relativeOffset >> 8) & 0xFF,
  5527. relativeOffset & 0xFF);
  5528. }
  5529. if (objects[i]) {
  5530. relativeOffset += objects[i].length;
  5531. }
  5532. }
  5533. for (i = 0; i < count; i++) {
  5534. // Notify the tracker where the object will be offset in the data.
  5535. if (trackers[i]) {
  5536. trackers[i].offset(data.length);
  5537. }
  5538. for (var j = 0, jj = objects[i].length; j < jj; j++) {
  5539. data.push(objects[i][j]);
  5540. }
  5541. }
  5542. return data;
  5543. }
  5544. };
  5545. return CFFCompiler;
  5546. })();
  5547. exports.CFFStandardStrings = CFFStandardStrings;
  5548. exports.CFFParser = CFFParser;
  5549. exports.CFF = CFF;
  5550. exports.CFFHeader = CFFHeader;
  5551. exports.CFFStrings = CFFStrings;
  5552. exports.CFFIndex = CFFIndex;
  5553. exports.CFFCharset = CFFCharset;
  5554. exports.CFFTopDict = CFFTopDict;
  5555. exports.CFFPrivateDict = CFFPrivateDict;
  5556. exports.CFFCompiler = CFFCompiler;
  5557. }));
  5558. (function (root, factory) {
  5559. {
  5560. factory((root.pdfjsCoreChunkedStream = {}), root.pdfjsSharedUtil);
  5561. }
  5562. }(this, function (exports, sharedUtil) {
  5563. var MissingDataException = sharedUtil.MissingDataException;
  5564. var arrayByteLength = sharedUtil.arrayByteLength;
  5565. var arraysToBytes = sharedUtil.arraysToBytes;
  5566. var assert = sharedUtil.assert;
  5567. var createPromiseCapability = sharedUtil.createPromiseCapability;
  5568. var isInt = sharedUtil.isInt;
  5569. var isEmptyObj = sharedUtil.isEmptyObj;
  5570. var ChunkedStream = (function ChunkedStreamClosure() {
  5571. function ChunkedStream(length, chunkSize, manager) {
  5572. this.bytes = new Uint8Array(length);
  5573. this.start = 0;
  5574. this.pos = 0;
  5575. this.end = length;
  5576. this.chunkSize = chunkSize;
  5577. this.loadedChunks = [];
  5578. this.numChunksLoaded = 0;
  5579. this.numChunks = Math.ceil(length / chunkSize);
  5580. this.manager = manager;
  5581. this.progressiveDataLength = 0;
  5582. this.lastSuccessfulEnsureByteChunk = -1; // a single-entry cache
  5583. }
  5584. // required methods for a stream. if a particular stream does not
  5585. // implement these, an error should be thrown
  5586. ChunkedStream.prototype = {
  5587. getMissingChunks: function ChunkedStream_getMissingChunks() {
  5588. var chunks = [];
  5589. for (var chunk = 0, n = this.numChunks; chunk < n; ++chunk) {
  5590. if (!this.loadedChunks[chunk]) {
  5591. chunks.push(chunk);
  5592. }
  5593. }
  5594. return chunks;
  5595. },
  5596. getBaseStreams: function ChunkedStream_getBaseStreams() {
  5597. return [this];
  5598. },
  5599. allChunksLoaded: function ChunkedStream_allChunksLoaded() {
  5600. return this.numChunksLoaded === this.numChunks;
  5601. },
  5602. onReceiveData: function ChunkedStream_onReceiveData(begin, chunk) {
  5603. var end = begin + chunk.byteLength;
  5604. assert(begin % this.chunkSize === 0, 'Bad begin offset: ' + begin);
  5605. // Using this.length is inaccurate here since this.start can be moved
  5606. // See ChunkedStream.moveStart()
  5607. var length = this.bytes.length;
  5608. assert(end % this.chunkSize === 0 || end === length,
  5609. 'Bad end offset: ' + end);
  5610. this.bytes.set(new Uint8Array(chunk), begin);
  5611. var chunkSize = this.chunkSize;
  5612. var beginChunk = Math.floor(begin / chunkSize);
  5613. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5614. var curChunk;
  5615. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5616. if (!this.loadedChunks[curChunk]) {
  5617. this.loadedChunks[curChunk] = true;
  5618. ++this.numChunksLoaded;
  5619. }
  5620. }
  5621. },
  5622. onReceiveProgressiveData:
  5623. function ChunkedStream_onReceiveProgressiveData(data) {
  5624. var position = this.progressiveDataLength;
  5625. var beginChunk = Math.floor(position / this.chunkSize);
  5626. this.bytes.set(new Uint8Array(data), position);
  5627. position += data.byteLength;
  5628. this.progressiveDataLength = position;
  5629. var endChunk = position >= this.end ? this.numChunks :
  5630. Math.floor(position / this.chunkSize);
  5631. var curChunk;
  5632. for (curChunk = beginChunk; curChunk < endChunk; ++curChunk) {
  5633. if (!this.loadedChunks[curChunk]) {
  5634. this.loadedChunks[curChunk] = true;
  5635. ++this.numChunksLoaded;
  5636. }
  5637. }
  5638. },
  5639. ensureByte: function ChunkedStream_ensureByte(pos) {
  5640. var chunk = Math.floor(pos / this.chunkSize);
  5641. if (chunk === this.lastSuccessfulEnsureByteChunk) {
  5642. return;
  5643. }
  5644. if (!this.loadedChunks[chunk]) {
  5645. throw new MissingDataException(pos, pos + 1);
  5646. }
  5647. this.lastSuccessfulEnsureByteChunk = chunk;
  5648. },
  5649. ensureRange: function ChunkedStream_ensureRange(begin, end) {
  5650. if (begin >= end) {
  5651. return;
  5652. }
  5653. if (end <= this.progressiveDataLength) {
  5654. return;
  5655. }
  5656. var chunkSize = this.chunkSize;
  5657. var beginChunk = Math.floor(begin / chunkSize);
  5658. var endChunk = Math.floor((end - 1) / chunkSize) + 1;
  5659. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5660. if (!this.loadedChunks[chunk]) {
  5661. throw new MissingDataException(begin, end);
  5662. }
  5663. }
  5664. },
  5665. nextEmptyChunk: function ChunkedStream_nextEmptyChunk(beginChunk) {
  5666. var chunk, numChunks = this.numChunks;
  5667. for (var i = 0; i < numChunks; ++i) {
  5668. chunk = (beginChunk + i) % numChunks; // Wrap around to beginning
  5669. if (!this.loadedChunks[chunk]) {
  5670. return chunk;
  5671. }
  5672. }
  5673. return null;
  5674. },
  5675. hasChunk: function ChunkedStream_hasChunk(chunk) {
  5676. return !!this.loadedChunks[chunk];
  5677. },
  5678. get length() {
  5679. return this.end - this.start;
  5680. },
  5681. get isEmpty() {
  5682. return this.length === 0;
  5683. },
  5684. getByte: function ChunkedStream_getByte() {
  5685. var pos = this.pos;
  5686. if (pos >= this.end) {
  5687. return -1;
  5688. }
  5689. this.ensureByte(pos);
  5690. return this.bytes[this.pos++];
  5691. },
  5692. getUint16: function ChunkedStream_getUint16() {
  5693. var b0 = this.getByte();
  5694. var b1 = this.getByte();
  5695. if (b0 === -1 || b1 === -1) {
  5696. return -1;
  5697. }
  5698. return (b0 << 8) + b1;
  5699. },
  5700. getInt32: function ChunkedStream_getInt32() {
  5701. var b0 = this.getByte();
  5702. var b1 = this.getByte();
  5703. var b2 = this.getByte();
  5704. var b3 = this.getByte();
  5705. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  5706. },
  5707. // returns subarray of original buffer
  5708. // should only be read
  5709. getBytes: function ChunkedStream_getBytes(length) {
  5710. var bytes = this.bytes;
  5711. var pos = this.pos;
  5712. var strEnd = this.end;
  5713. if (!length) {
  5714. this.ensureRange(pos, strEnd);
  5715. return bytes.subarray(pos, strEnd);
  5716. }
  5717. var end = pos + length;
  5718. if (end > strEnd) {
  5719. end = strEnd;
  5720. }
  5721. this.ensureRange(pos, end);
  5722. this.pos = end;
  5723. return bytes.subarray(pos, end);
  5724. },
  5725. peekByte: function ChunkedStream_peekByte() {
  5726. var peekedByte = this.getByte();
  5727. this.pos--;
  5728. return peekedByte;
  5729. },
  5730. peekBytes: function ChunkedStream_peekBytes(length) {
  5731. var bytes = this.getBytes(length);
  5732. this.pos -= bytes.length;
  5733. return bytes;
  5734. },
  5735. getByteRange: function ChunkedStream_getBytes(begin, end) {
  5736. this.ensureRange(begin, end);
  5737. return this.bytes.subarray(begin, end);
  5738. },
  5739. skip: function ChunkedStream_skip(n) {
  5740. if (!n) {
  5741. n = 1;
  5742. }
  5743. this.pos += n;
  5744. },
  5745. reset: function ChunkedStream_reset() {
  5746. this.pos = this.start;
  5747. },
  5748. moveStart: function ChunkedStream_moveStart() {
  5749. this.start = this.pos;
  5750. },
  5751. makeSubStream: function ChunkedStream_makeSubStream(start, length, dict) {
  5752. this.ensureRange(start, start + length);
  5753. function ChunkedStreamSubstream() {}
  5754. ChunkedStreamSubstream.prototype = Object.create(this);
  5755. ChunkedStreamSubstream.prototype.getMissingChunks = function() {
  5756. var chunkSize = this.chunkSize;
  5757. var beginChunk = Math.floor(this.start / chunkSize);
  5758. var endChunk = Math.floor((this.end - 1) / chunkSize) + 1;
  5759. var missingChunks = [];
  5760. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5761. if (!this.loadedChunks[chunk]) {
  5762. missingChunks.push(chunk);
  5763. }
  5764. }
  5765. return missingChunks;
  5766. };
  5767. var subStream = new ChunkedStreamSubstream();
  5768. subStream.pos = subStream.start = start;
  5769. subStream.end = start + length || this.end;
  5770. subStream.dict = dict;
  5771. return subStream;
  5772. },
  5773. isStream: true
  5774. };
  5775. return ChunkedStream;
  5776. })();
  5777. var ChunkedStreamManager = (function ChunkedStreamManagerClosure() {
  5778. function ChunkedStreamManager(pdfNetworkStream, args) {
  5779. var chunkSize = args.rangeChunkSize;
  5780. var length = args.length;
  5781. this.stream = new ChunkedStream(length, chunkSize, this);
  5782. this.length = length;
  5783. this.chunkSize = chunkSize;
  5784. this.pdfNetworkStream = pdfNetworkStream;
  5785. this.url = args.url;
  5786. this.disableAutoFetch = args.disableAutoFetch;
  5787. this.msgHandler = args.msgHandler;
  5788. this.currRequestId = 0;
  5789. this.chunksNeededByRequest = Object.create(null);
  5790. this.requestsByChunk = Object.create(null);
  5791. this.promisesByRequest = Object.create(null);
  5792. this.progressiveDataLength = 0;
  5793. this.aborted = false;
  5794. this._loadedStreamCapability = createPromiseCapability();
  5795. }
  5796. ChunkedStreamManager.prototype = {
  5797. onLoadedStream: function ChunkedStreamManager_getLoadedStream() {
  5798. return this._loadedStreamCapability.promise;
  5799. },
  5800. sendRequest: function ChunkedStreamManager_sendRequest(begin, end) {
  5801. var rangeReader = this.pdfNetworkStream.getRangeReader(begin, end);
  5802. if (!rangeReader.isStreamingSupported) {
  5803. rangeReader.onProgress = this.onProgress.bind(this);
  5804. }
  5805. var chunks = [], loaded = 0;
  5806. var manager = this;
  5807. var promise = new Promise(function (resolve, reject) {
  5808. var readChunk = function (chunk) {
  5809. try {
  5810. if (!chunk.done) {
  5811. var data = chunk.value;
  5812. chunks.push(data);
  5813. loaded += arrayByteLength(data);
  5814. if (rangeReader.isStreamingSupported) {
  5815. manager.onProgress({loaded: loaded});
  5816. }
  5817. rangeReader.read().then(readChunk, reject);
  5818. return;
  5819. }
  5820. var chunkData = arraysToBytes(chunks);
  5821. chunks = null;
  5822. resolve(chunkData);
  5823. } catch (e) {
  5824. reject(e);
  5825. }
  5826. };
  5827. rangeReader.read().then(readChunk, reject);
  5828. });
  5829. promise.then(function (data) {
  5830. if (this.aborted) {
  5831. return; // ignoring any data after abort
  5832. }
  5833. this.onReceiveData({chunk: data, begin: begin});
  5834. }.bind(this));
  5835. // TODO check errors
  5836. },
  5837. // Get all the chunks that are not yet loaded and groups them into
  5838. // contiguous ranges to load in as few requests as possible
  5839. requestAllChunks: function ChunkedStreamManager_requestAllChunks() {
  5840. var missingChunks = this.stream.getMissingChunks();
  5841. this._requestChunks(missingChunks);
  5842. return this._loadedStreamCapability.promise;
  5843. },
  5844. _requestChunks: function ChunkedStreamManager_requestChunks(chunks) {
  5845. var requestId = this.currRequestId++;
  5846. var i, ii;
  5847. var chunksNeeded = Object.create(null);
  5848. this.chunksNeededByRequest[requestId] = chunksNeeded;
  5849. for (i = 0, ii = chunks.length; i < ii; i++) {
  5850. if (!this.stream.hasChunk(chunks[i])) {
  5851. chunksNeeded[chunks[i]] = true;
  5852. }
  5853. }
  5854. if (isEmptyObj(chunksNeeded)) {
  5855. return Promise.resolve();
  5856. }
  5857. var capability = createPromiseCapability();
  5858. this.promisesByRequest[requestId] = capability;
  5859. var chunksToRequest = [];
  5860. for (var chunk in chunksNeeded) {
  5861. chunk = chunk | 0;
  5862. if (!(chunk in this.requestsByChunk)) {
  5863. this.requestsByChunk[chunk] = [];
  5864. chunksToRequest.push(chunk);
  5865. }
  5866. this.requestsByChunk[chunk].push(requestId);
  5867. }
  5868. if (!chunksToRequest.length) {
  5869. return capability.promise;
  5870. }
  5871. var groupedChunksToRequest = this.groupChunks(chunksToRequest);
  5872. for (i = 0; i < groupedChunksToRequest.length; ++i) {
  5873. var groupedChunk = groupedChunksToRequest[i];
  5874. var begin = groupedChunk.beginChunk * this.chunkSize;
  5875. var end = Math.min(groupedChunk.endChunk * this.chunkSize, this.length);
  5876. this.sendRequest(begin, end);
  5877. }
  5878. return capability.promise;
  5879. },
  5880. getStream: function ChunkedStreamManager_getStream() {
  5881. return this.stream;
  5882. },
  5883. // Loads any chunks in the requested range that are not yet loaded
  5884. requestRange: function ChunkedStreamManager_requestRange(begin, end) {
  5885. end = Math.min(end, this.length);
  5886. var beginChunk = this.getBeginChunk(begin);
  5887. var endChunk = this.getEndChunk(end);
  5888. var chunks = [];
  5889. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5890. chunks.push(chunk);
  5891. }
  5892. return this._requestChunks(chunks);
  5893. },
  5894. requestRanges: function ChunkedStreamManager_requestRanges(ranges) {
  5895. ranges = ranges || [];
  5896. var chunksToRequest = [];
  5897. for (var i = 0; i < ranges.length; i++) {
  5898. var beginChunk = this.getBeginChunk(ranges[i].begin);
  5899. var endChunk = this.getEndChunk(ranges[i].end);
  5900. for (var chunk = beginChunk; chunk < endChunk; ++chunk) {
  5901. if (chunksToRequest.indexOf(chunk) < 0) {
  5902. chunksToRequest.push(chunk);
  5903. }
  5904. }
  5905. }
  5906. chunksToRequest.sort(function(a, b) { return a - b; });
  5907. return this._requestChunks(chunksToRequest);
  5908. },
  5909. // Groups a sorted array of chunks into as few contiguous larger
  5910. // chunks as possible
  5911. groupChunks: function ChunkedStreamManager_groupChunks(chunks) {
  5912. var groupedChunks = [];
  5913. var beginChunk = -1;
  5914. var prevChunk = -1;
  5915. for (var i = 0; i < chunks.length; ++i) {
  5916. var chunk = chunks[i];
  5917. if (beginChunk < 0) {
  5918. beginChunk = chunk;
  5919. }
  5920. if (prevChunk >= 0 && prevChunk + 1 !== chunk) {
  5921. groupedChunks.push({ beginChunk: beginChunk,
  5922. endChunk: prevChunk + 1 });
  5923. beginChunk = chunk;
  5924. }
  5925. if (i + 1 === chunks.length) {
  5926. groupedChunks.push({ beginChunk: beginChunk,
  5927. endChunk: chunk + 1 });
  5928. }
  5929. prevChunk = chunk;
  5930. }
  5931. return groupedChunks;
  5932. },
  5933. onProgress: function ChunkedStreamManager_onProgress(args) {
  5934. var bytesLoaded = (this.stream.numChunksLoaded * this.chunkSize +
  5935. args.loaded);
  5936. this.msgHandler.send('DocProgress', {
  5937. loaded: bytesLoaded,
  5938. total: this.length
  5939. });
  5940. },
  5941. onReceiveData: function ChunkedStreamManager_onReceiveData(args) {
  5942. var chunk = args.chunk;
  5943. var isProgressive = args.begin === undefined;
  5944. var begin = isProgressive ? this.progressiveDataLength : args.begin;
  5945. var end = begin + chunk.byteLength;
  5946. var beginChunk = Math.floor(begin / this.chunkSize);
  5947. var endChunk = end < this.length ? Math.floor(end / this.chunkSize) :
  5948. Math.ceil(end / this.chunkSize);
  5949. if (isProgressive) {
  5950. this.stream.onReceiveProgressiveData(chunk);
  5951. this.progressiveDataLength = end;
  5952. } else {
  5953. this.stream.onReceiveData(begin, chunk);
  5954. }
  5955. if (this.stream.allChunksLoaded()) {
  5956. this._loadedStreamCapability.resolve(this.stream);
  5957. }
  5958. var loadedRequests = [];
  5959. var i, requestId;
  5960. for (chunk = beginChunk; chunk < endChunk; ++chunk) {
  5961. // The server might return more chunks than requested
  5962. var requestIds = this.requestsByChunk[chunk] || [];
  5963. delete this.requestsByChunk[chunk];
  5964. for (i = 0; i < requestIds.length; ++i) {
  5965. requestId = requestIds[i];
  5966. var chunksNeeded = this.chunksNeededByRequest[requestId];
  5967. if (chunk in chunksNeeded) {
  5968. delete chunksNeeded[chunk];
  5969. }
  5970. if (!isEmptyObj(chunksNeeded)) {
  5971. continue;
  5972. }
  5973. loadedRequests.push(requestId);
  5974. }
  5975. }
  5976. // If there are no pending requests, automatically fetch the next
  5977. // unfetched chunk of the PDF
  5978. if (!this.disableAutoFetch && isEmptyObj(this.requestsByChunk)) {
  5979. var nextEmptyChunk;
  5980. if (this.stream.numChunksLoaded === 1) {
  5981. // This is a special optimization so that after fetching the first
  5982. // chunk, rather than fetching the second chunk, we fetch the last
  5983. // chunk.
  5984. var lastChunk = this.stream.numChunks - 1;
  5985. if (!this.stream.hasChunk(lastChunk)) {
  5986. nextEmptyChunk = lastChunk;
  5987. }
  5988. } else {
  5989. nextEmptyChunk = this.stream.nextEmptyChunk(endChunk);
  5990. }
  5991. if (isInt(nextEmptyChunk)) {
  5992. this._requestChunks([nextEmptyChunk]);
  5993. }
  5994. }
  5995. for (i = 0; i < loadedRequests.length; ++i) {
  5996. requestId = loadedRequests[i];
  5997. var capability = this.promisesByRequest[requestId];
  5998. delete this.promisesByRequest[requestId];
  5999. capability.resolve();
  6000. }
  6001. this.msgHandler.send('DocProgress', {
  6002. loaded: this.stream.numChunksLoaded * this.chunkSize,
  6003. total: this.length
  6004. });
  6005. },
  6006. onError: function ChunkedStreamManager_onError(err) {
  6007. this._loadedStreamCapability.reject(err);
  6008. },
  6009. getBeginChunk: function ChunkedStreamManager_getBeginChunk(begin) {
  6010. var chunk = Math.floor(begin / this.chunkSize);
  6011. return chunk;
  6012. },
  6013. getEndChunk: function ChunkedStreamManager_getEndChunk(end) {
  6014. var chunk = Math.floor((end - 1) / this.chunkSize) + 1;
  6015. return chunk;
  6016. },
  6017. abort: function ChunkedStreamManager_abort() {
  6018. this.aborted = true;
  6019. if (this.pdfNetworkStream) {
  6020. this.pdfNetworkStream.cancelAllRequests('abort');
  6021. }
  6022. for(var requestId in this.promisesByRequest) {
  6023. var capability = this.promisesByRequest[requestId];
  6024. capability.reject(new Error('Request was aborted'));
  6025. }
  6026. }
  6027. };
  6028. return ChunkedStreamManager;
  6029. })();
  6030. exports.ChunkedStream = ChunkedStream;
  6031. exports.ChunkedStreamManager = ChunkedStreamManager;
  6032. }));
  6033. (function (root, factory) {
  6034. {
  6035. factory((root.pdfjsCoreGlyphList = {}), root.pdfjsSharedUtil);
  6036. }
  6037. }(this, function (exports, sharedUtil) {
  6038. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  6039. var getGlyphsUnicode = getLookupTableFactory(function (t) {
  6040. t['A'] = 0x0041;
  6041. t['AE'] = 0x00C6;
  6042. t['AEacute'] = 0x01FC;
  6043. t['AEmacron'] = 0x01E2;
  6044. t['AEsmall'] = 0xF7E6;
  6045. t['Aacute'] = 0x00C1;
  6046. t['Aacutesmall'] = 0xF7E1;
  6047. t['Abreve'] = 0x0102;
  6048. t['Abreveacute'] = 0x1EAE;
  6049. t['Abrevecyrillic'] = 0x04D0;
  6050. t['Abrevedotbelow'] = 0x1EB6;
  6051. t['Abrevegrave'] = 0x1EB0;
  6052. t['Abrevehookabove'] = 0x1EB2;
  6053. t['Abrevetilde'] = 0x1EB4;
  6054. t['Acaron'] = 0x01CD;
  6055. t['Acircle'] = 0x24B6;
  6056. t['Acircumflex'] = 0x00C2;
  6057. t['Acircumflexacute'] = 0x1EA4;
  6058. t['Acircumflexdotbelow'] = 0x1EAC;
  6059. t['Acircumflexgrave'] = 0x1EA6;
  6060. t['Acircumflexhookabove'] = 0x1EA8;
  6061. t['Acircumflexsmall'] = 0xF7E2;
  6062. t['Acircumflextilde'] = 0x1EAA;
  6063. t['Acute'] = 0xF6C9;
  6064. t['Acutesmall'] = 0xF7B4;
  6065. t['Acyrillic'] = 0x0410;
  6066. t['Adblgrave'] = 0x0200;
  6067. t['Adieresis'] = 0x00C4;
  6068. t['Adieresiscyrillic'] = 0x04D2;
  6069. t['Adieresismacron'] = 0x01DE;
  6070. t['Adieresissmall'] = 0xF7E4;
  6071. t['Adotbelow'] = 0x1EA0;
  6072. t['Adotmacron'] = 0x01E0;
  6073. t['Agrave'] = 0x00C0;
  6074. t['Agravesmall'] = 0xF7E0;
  6075. t['Ahookabove'] = 0x1EA2;
  6076. t['Aiecyrillic'] = 0x04D4;
  6077. t['Ainvertedbreve'] = 0x0202;
  6078. t['Alpha'] = 0x0391;
  6079. t['Alphatonos'] = 0x0386;
  6080. t['Amacron'] = 0x0100;
  6081. t['Amonospace'] = 0xFF21;
  6082. t['Aogonek'] = 0x0104;
  6083. t['Aring'] = 0x00C5;
  6084. t['Aringacute'] = 0x01FA;
  6085. t['Aringbelow'] = 0x1E00;
  6086. t['Aringsmall'] = 0xF7E5;
  6087. t['Asmall'] = 0xF761;
  6088. t['Atilde'] = 0x00C3;
  6089. t['Atildesmall'] = 0xF7E3;
  6090. t['Aybarmenian'] = 0x0531;
  6091. t['B'] = 0x0042;
  6092. t['Bcircle'] = 0x24B7;
  6093. t['Bdotaccent'] = 0x1E02;
  6094. t['Bdotbelow'] = 0x1E04;
  6095. t['Becyrillic'] = 0x0411;
  6096. t['Benarmenian'] = 0x0532;
  6097. t['Beta'] = 0x0392;
  6098. t['Bhook'] = 0x0181;
  6099. t['Blinebelow'] = 0x1E06;
  6100. t['Bmonospace'] = 0xFF22;
  6101. t['Brevesmall'] = 0xF6F4;
  6102. t['Bsmall'] = 0xF762;
  6103. t['Btopbar'] = 0x0182;
  6104. t['C'] = 0x0043;
  6105. t['Caarmenian'] = 0x053E;
  6106. t['Cacute'] = 0x0106;
  6107. t['Caron'] = 0xF6CA;
  6108. t['Caronsmall'] = 0xF6F5;
  6109. t['Ccaron'] = 0x010C;
  6110. t['Ccedilla'] = 0x00C7;
  6111. t['Ccedillaacute'] = 0x1E08;
  6112. t['Ccedillasmall'] = 0xF7E7;
  6113. t['Ccircle'] = 0x24B8;
  6114. t['Ccircumflex'] = 0x0108;
  6115. t['Cdot'] = 0x010A;
  6116. t['Cdotaccent'] = 0x010A;
  6117. t['Cedillasmall'] = 0xF7B8;
  6118. t['Chaarmenian'] = 0x0549;
  6119. t['Cheabkhasiancyrillic'] = 0x04BC;
  6120. t['Checyrillic'] = 0x0427;
  6121. t['Chedescenderabkhasiancyrillic'] = 0x04BE;
  6122. t['Chedescendercyrillic'] = 0x04B6;
  6123. t['Chedieresiscyrillic'] = 0x04F4;
  6124. t['Cheharmenian'] = 0x0543;
  6125. t['Chekhakassiancyrillic'] = 0x04CB;
  6126. t['Cheverticalstrokecyrillic'] = 0x04B8;
  6127. t['Chi'] = 0x03A7;
  6128. t['Chook'] = 0x0187;
  6129. t['Circumflexsmall'] = 0xF6F6;
  6130. t['Cmonospace'] = 0xFF23;
  6131. t['Coarmenian'] = 0x0551;
  6132. t['Csmall'] = 0xF763;
  6133. t['D'] = 0x0044;
  6134. t['DZ'] = 0x01F1;
  6135. t['DZcaron'] = 0x01C4;
  6136. t['Daarmenian'] = 0x0534;
  6137. t['Dafrican'] = 0x0189;
  6138. t['Dcaron'] = 0x010E;
  6139. t['Dcedilla'] = 0x1E10;
  6140. t['Dcircle'] = 0x24B9;
  6141. t['Dcircumflexbelow'] = 0x1E12;
  6142. t['Dcroat'] = 0x0110;
  6143. t['Ddotaccent'] = 0x1E0A;
  6144. t['Ddotbelow'] = 0x1E0C;
  6145. t['Decyrillic'] = 0x0414;
  6146. t['Deicoptic'] = 0x03EE;
  6147. t['Delta'] = 0x2206;
  6148. t['Deltagreek'] = 0x0394;
  6149. t['Dhook'] = 0x018A;
  6150. t['Dieresis'] = 0xF6CB;
  6151. t['DieresisAcute'] = 0xF6CC;
  6152. t['DieresisGrave'] = 0xF6CD;
  6153. t['Dieresissmall'] = 0xF7A8;
  6154. t['Digammagreek'] = 0x03DC;
  6155. t['Djecyrillic'] = 0x0402;
  6156. t['Dlinebelow'] = 0x1E0E;
  6157. t['Dmonospace'] = 0xFF24;
  6158. t['Dotaccentsmall'] = 0xF6F7;
  6159. t['Dslash'] = 0x0110;
  6160. t['Dsmall'] = 0xF764;
  6161. t['Dtopbar'] = 0x018B;
  6162. t['Dz'] = 0x01F2;
  6163. t['Dzcaron'] = 0x01C5;
  6164. t['Dzeabkhasiancyrillic'] = 0x04E0;
  6165. t['Dzecyrillic'] = 0x0405;
  6166. t['Dzhecyrillic'] = 0x040F;
  6167. t['E'] = 0x0045;
  6168. t['Eacute'] = 0x00C9;
  6169. t['Eacutesmall'] = 0xF7E9;
  6170. t['Ebreve'] = 0x0114;
  6171. t['Ecaron'] = 0x011A;
  6172. t['Ecedillabreve'] = 0x1E1C;
  6173. t['Echarmenian'] = 0x0535;
  6174. t['Ecircle'] = 0x24BA;
  6175. t['Ecircumflex'] = 0x00CA;
  6176. t['Ecircumflexacute'] = 0x1EBE;
  6177. t['Ecircumflexbelow'] = 0x1E18;
  6178. t['Ecircumflexdotbelow'] = 0x1EC6;
  6179. t['Ecircumflexgrave'] = 0x1EC0;
  6180. t['Ecircumflexhookabove'] = 0x1EC2;
  6181. t['Ecircumflexsmall'] = 0xF7EA;
  6182. t['Ecircumflextilde'] = 0x1EC4;
  6183. t['Ecyrillic'] = 0x0404;
  6184. t['Edblgrave'] = 0x0204;
  6185. t['Edieresis'] = 0x00CB;
  6186. t['Edieresissmall'] = 0xF7EB;
  6187. t['Edot'] = 0x0116;
  6188. t['Edotaccent'] = 0x0116;
  6189. t['Edotbelow'] = 0x1EB8;
  6190. t['Efcyrillic'] = 0x0424;
  6191. t['Egrave'] = 0x00C8;
  6192. t['Egravesmall'] = 0xF7E8;
  6193. t['Eharmenian'] = 0x0537;
  6194. t['Ehookabove'] = 0x1EBA;
  6195. t['Eightroman'] = 0x2167;
  6196. t['Einvertedbreve'] = 0x0206;
  6197. t['Eiotifiedcyrillic'] = 0x0464;
  6198. t['Elcyrillic'] = 0x041B;
  6199. t['Elevenroman'] = 0x216A;
  6200. t['Emacron'] = 0x0112;
  6201. t['Emacronacute'] = 0x1E16;
  6202. t['Emacrongrave'] = 0x1E14;
  6203. t['Emcyrillic'] = 0x041C;
  6204. t['Emonospace'] = 0xFF25;
  6205. t['Encyrillic'] = 0x041D;
  6206. t['Endescendercyrillic'] = 0x04A2;
  6207. t['Eng'] = 0x014A;
  6208. t['Enghecyrillic'] = 0x04A4;
  6209. t['Enhookcyrillic'] = 0x04C7;
  6210. t['Eogonek'] = 0x0118;
  6211. t['Eopen'] = 0x0190;
  6212. t['Epsilon'] = 0x0395;
  6213. t['Epsilontonos'] = 0x0388;
  6214. t['Ercyrillic'] = 0x0420;
  6215. t['Ereversed'] = 0x018E;
  6216. t['Ereversedcyrillic'] = 0x042D;
  6217. t['Escyrillic'] = 0x0421;
  6218. t['Esdescendercyrillic'] = 0x04AA;
  6219. t['Esh'] = 0x01A9;
  6220. t['Esmall'] = 0xF765;
  6221. t['Eta'] = 0x0397;
  6222. t['Etarmenian'] = 0x0538;
  6223. t['Etatonos'] = 0x0389;
  6224. t['Eth'] = 0x00D0;
  6225. t['Ethsmall'] = 0xF7F0;
  6226. t['Etilde'] = 0x1EBC;
  6227. t['Etildebelow'] = 0x1E1A;
  6228. t['Euro'] = 0x20AC;
  6229. t['Ezh'] = 0x01B7;
  6230. t['Ezhcaron'] = 0x01EE;
  6231. t['Ezhreversed'] = 0x01B8;
  6232. t['F'] = 0x0046;
  6233. t['Fcircle'] = 0x24BB;
  6234. t['Fdotaccent'] = 0x1E1E;
  6235. t['Feharmenian'] = 0x0556;
  6236. t['Feicoptic'] = 0x03E4;
  6237. t['Fhook'] = 0x0191;
  6238. t['Fitacyrillic'] = 0x0472;
  6239. t['Fiveroman'] = 0x2164;
  6240. t['Fmonospace'] = 0xFF26;
  6241. t['Fourroman'] = 0x2163;
  6242. t['Fsmall'] = 0xF766;
  6243. t['G'] = 0x0047;
  6244. t['GBsquare'] = 0x3387;
  6245. t['Gacute'] = 0x01F4;
  6246. t['Gamma'] = 0x0393;
  6247. t['Gammaafrican'] = 0x0194;
  6248. t['Gangiacoptic'] = 0x03EA;
  6249. t['Gbreve'] = 0x011E;
  6250. t['Gcaron'] = 0x01E6;
  6251. t['Gcedilla'] = 0x0122;
  6252. t['Gcircle'] = 0x24BC;
  6253. t['Gcircumflex'] = 0x011C;
  6254. t['Gcommaaccent'] = 0x0122;
  6255. t['Gdot'] = 0x0120;
  6256. t['Gdotaccent'] = 0x0120;
  6257. t['Gecyrillic'] = 0x0413;
  6258. t['Ghadarmenian'] = 0x0542;
  6259. t['Ghemiddlehookcyrillic'] = 0x0494;
  6260. t['Ghestrokecyrillic'] = 0x0492;
  6261. t['Gheupturncyrillic'] = 0x0490;
  6262. t['Ghook'] = 0x0193;
  6263. t['Gimarmenian'] = 0x0533;
  6264. t['Gjecyrillic'] = 0x0403;
  6265. t['Gmacron'] = 0x1E20;
  6266. t['Gmonospace'] = 0xFF27;
  6267. t['Grave'] = 0xF6CE;
  6268. t['Gravesmall'] = 0xF760;
  6269. t['Gsmall'] = 0xF767;
  6270. t['Gsmallhook'] = 0x029B;
  6271. t['Gstroke'] = 0x01E4;
  6272. t['H'] = 0x0048;
  6273. t['H18533'] = 0x25CF;
  6274. t['H18543'] = 0x25AA;
  6275. t['H18551'] = 0x25AB;
  6276. t['H22073'] = 0x25A1;
  6277. t['HPsquare'] = 0x33CB;
  6278. t['Haabkhasiancyrillic'] = 0x04A8;
  6279. t['Hadescendercyrillic'] = 0x04B2;
  6280. t['Hardsigncyrillic'] = 0x042A;
  6281. t['Hbar'] = 0x0126;
  6282. t['Hbrevebelow'] = 0x1E2A;
  6283. t['Hcedilla'] = 0x1E28;
  6284. t['Hcircle'] = 0x24BD;
  6285. t['Hcircumflex'] = 0x0124;
  6286. t['Hdieresis'] = 0x1E26;
  6287. t['Hdotaccent'] = 0x1E22;
  6288. t['Hdotbelow'] = 0x1E24;
  6289. t['Hmonospace'] = 0xFF28;
  6290. t['Hoarmenian'] = 0x0540;
  6291. t['Horicoptic'] = 0x03E8;
  6292. t['Hsmall'] = 0xF768;
  6293. t['Hungarumlaut'] = 0xF6CF;
  6294. t['Hungarumlautsmall'] = 0xF6F8;
  6295. t['Hzsquare'] = 0x3390;
  6296. t['I'] = 0x0049;
  6297. t['IAcyrillic'] = 0x042F;
  6298. t['IJ'] = 0x0132;
  6299. t['IUcyrillic'] = 0x042E;
  6300. t['Iacute'] = 0x00CD;
  6301. t['Iacutesmall'] = 0xF7ED;
  6302. t['Ibreve'] = 0x012C;
  6303. t['Icaron'] = 0x01CF;
  6304. t['Icircle'] = 0x24BE;
  6305. t['Icircumflex'] = 0x00CE;
  6306. t['Icircumflexsmall'] = 0xF7EE;
  6307. t['Icyrillic'] = 0x0406;
  6308. t['Idblgrave'] = 0x0208;
  6309. t['Idieresis'] = 0x00CF;
  6310. t['Idieresisacute'] = 0x1E2E;
  6311. t['Idieresiscyrillic'] = 0x04E4;
  6312. t['Idieresissmall'] = 0xF7EF;
  6313. t['Idot'] = 0x0130;
  6314. t['Idotaccent'] = 0x0130;
  6315. t['Idotbelow'] = 0x1ECA;
  6316. t['Iebrevecyrillic'] = 0x04D6;
  6317. t['Iecyrillic'] = 0x0415;
  6318. t['Ifraktur'] = 0x2111;
  6319. t['Igrave'] = 0x00CC;
  6320. t['Igravesmall'] = 0xF7EC;
  6321. t['Ihookabove'] = 0x1EC8;
  6322. t['Iicyrillic'] = 0x0418;
  6323. t['Iinvertedbreve'] = 0x020A;
  6324. t['Iishortcyrillic'] = 0x0419;
  6325. t['Imacron'] = 0x012A;
  6326. t['Imacroncyrillic'] = 0x04E2;
  6327. t['Imonospace'] = 0xFF29;
  6328. t['Iniarmenian'] = 0x053B;
  6329. t['Iocyrillic'] = 0x0401;
  6330. t['Iogonek'] = 0x012E;
  6331. t['Iota'] = 0x0399;
  6332. t['Iotaafrican'] = 0x0196;
  6333. t['Iotadieresis'] = 0x03AA;
  6334. t['Iotatonos'] = 0x038A;
  6335. t['Ismall'] = 0xF769;
  6336. t['Istroke'] = 0x0197;
  6337. t['Itilde'] = 0x0128;
  6338. t['Itildebelow'] = 0x1E2C;
  6339. t['Izhitsacyrillic'] = 0x0474;
  6340. t['Izhitsadblgravecyrillic'] = 0x0476;
  6341. t['J'] = 0x004A;
  6342. t['Jaarmenian'] = 0x0541;
  6343. t['Jcircle'] = 0x24BF;
  6344. t['Jcircumflex'] = 0x0134;
  6345. t['Jecyrillic'] = 0x0408;
  6346. t['Jheharmenian'] = 0x054B;
  6347. t['Jmonospace'] = 0xFF2A;
  6348. t['Jsmall'] = 0xF76A;
  6349. t['K'] = 0x004B;
  6350. t['KBsquare'] = 0x3385;
  6351. t['KKsquare'] = 0x33CD;
  6352. t['Kabashkircyrillic'] = 0x04A0;
  6353. t['Kacute'] = 0x1E30;
  6354. t['Kacyrillic'] = 0x041A;
  6355. t['Kadescendercyrillic'] = 0x049A;
  6356. t['Kahookcyrillic'] = 0x04C3;
  6357. t['Kappa'] = 0x039A;
  6358. t['Kastrokecyrillic'] = 0x049E;
  6359. t['Kaverticalstrokecyrillic'] = 0x049C;
  6360. t['Kcaron'] = 0x01E8;
  6361. t['Kcedilla'] = 0x0136;
  6362. t['Kcircle'] = 0x24C0;
  6363. t['Kcommaaccent'] = 0x0136;
  6364. t['Kdotbelow'] = 0x1E32;
  6365. t['Keharmenian'] = 0x0554;
  6366. t['Kenarmenian'] = 0x053F;
  6367. t['Khacyrillic'] = 0x0425;
  6368. t['Kheicoptic'] = 0x03E6;
  6369. t['Khook'] = 0x0198;
  6370. t['Kjecyrillic'] = 0x040C;
  6371. t['Klinebelow'] = 0x1E34;
  6372. t['Kmonospace'] = 0xFF2B;
  6373. t['Koppacyrillic'] = 0x0480;
  6374. t['Koppagreek'] = 0x03DE;
  6375. t['Ksicyrillic'] = 0x046E;
  6376. t['Ksmall'] = 0xF76B;
  6377. t['L'] = 0x004C;
  6378. t['LJ'] = 0x01C7;
  6379. t['LL'] = 0xF6BF;
  6380. t['Lacute'] = 0x0139;
  6381. t['Lambda'] = 0x039B;
  6382. t['Lcaron'] = 0x013D;
  6383. t['Lcedilla'] = 0x013B;
  6384. t['Lcircle'] = 0x24C1;
  6385. t['Lcircumflexbelow'] = 0x1E3C;
  6386. t['Lcommaaccent'] = 0x013B;
  6387. t['Ldot'] = 0x013F;
  6388. t['Ldotaccent'] = 0x013F;
  6389. t['Ldotbelow'] = 0x1E36;
  6390. t['Ldotbelowmacron'] = 0x1E38;
  6391. t['Liwnarmenian'] = 0x053C;
  6392. t['Lj'] = 0x01C8;
  6393. t['Ljecyrillic'] = 0x0409;
  6394. t['Llinebelow'] = 0x1E3A;
  6395. t['Lmonospace'] = 0xFF2C;
  6396. t['Lslash'] = 0x0141;
  6397. t['Lslashsmall'] = 0xF6F9;
  6398. t['Lsmall'] = 0xF76C;
  6399. t['M'] = 0x004D;
  6400. t['MBsquare'] = 0x3386;
  6401. t['Macron'] = 0xF6D0;
  6402. t['Macronsmall'] = 0xF7AF;
  6403. t['Macute'] = 0x1E3E;
  6404. t['Mcircle'] = 0x24C2;
  6405. t['Mdotaccent'] = 0x1E40;
  6406. t['Mdotbelow'] = 0x1E42;
  6407. t['Menarmenian'] = 0x0544;
  6408. t['Mmonospace'] = 0xFF2D;
  6409. t['Msmall'] = 0xF76D;
  6410. t['Mturned'] = 0x019C;
  6411. t['Mu'] = 0x039C;
  6412. t['N'] = 0x004E;
  6413. t['NJ'] = 0x01CA;
  6414. t['Nacute'] = 0x0143;
  6415. t['Ncaron'] = 0x0147;
  6416. t['Ncedilla'] = 0x0145;
  6417. t['Ncircle'] = 0x24C3;
  6418. t['Ncircumflexbelow'] = 0x1E4A;
  6419. t['Ncommaaccent'] = 0x0145;
  6420. t['Ndotaccent'] = 0x1E44;
  6421. t['Ndotbelow'] = 0x1E46;
  6422. t['Nhookleft'] = 0x019D;
  6423. t['Nineroman'] = 0x2168;
  6424. t['Nj'] = 0x01CB;
  6425. t['Njecyrillic'] = 0x040A;
  6426. t['Nlinebelow'] = 0x1E48;
  6427. t['Nmonospace'] = 0xFF2E;
  6428. t['Nowarmenian'] = 0x0546;
  6429. t['Nsmall'] = 0xF76E;
  6430. t['Ntilde'] = 0x00D1;
  6431. t['Ntildesmall'] = 0xF7F1;
  6432. t['Nu'] = 0x039D;
  6433. t['O'] = 0x004F;
  6434. t['OE'] = 0x0152;
  6435. t['OEsmall'] = 0xF6FA;
  6436. t['Oacute'] = 0x00D3;
  6437. t['Oacutesmall'] = 0xF7F3;
  6438. t['Obarredcyrillic'] = 0x04E8;
  6439. t['Obarreddieresiscyrillic'] = 0x04EA;
  6440. t['Obreve'] = 0x014E;
  6441. t['Ocaron'] = 0x01D1;
  6442. t['Ocenteredtilde'] = 0x019F;
  6443. t['Ocircle'] = 0x24C4;
  6444. t['Ocircumflex'] = 0x00D4;
  6445. t['Ocircumflexacute'] = 0x1ED0;
  6446. t['Ocircumflexdotbelow'] = 0x1ED8;
  6447. t['Ocircumflexgrave'] = 0x1ED2;
  6448. t['Ocircumflexhookabove'] = 0x1ED4;
  6449. t['Ocircumflexsmall'] = 0xF7F4;
  6450. t['Ocircumflextilde'] = 0x1ED6;
  6451. t['Ocyrillic'] = 0x041E;
  6452. t['Odblacute'] = 0x0150;
  6453. t['Odblgrave'] = 0x020C;
  6454. t['Odieresis'] = 0x00D6;
  6455. t['Odieresiscyrillic'] = 0x04E6;
  6456. t['Odieresissmall'] = 0xF7F6;
  6457. t['Odotbelow'] = 0x1ECC;
  6458. t['Ogoneksmall'] = 0xF6FB;
  6459. t['Ograve'] = 0x00D2;
  6460. t['Ogravesmall'] = 0xF7F2;
  6461. t['Oharmenian'] = 0x0555;
  6462. t['Ohm'] = 0x2126;
  6463. t['Ohookabove'] = 0x1ECE;
  6464. t['Ohorn'] = 0x01A0;
  6465. t['Ohornacute'] = 0x1EDA;
  6466. t['Ohorndotbelow'] = 0x1EE2;
  6467. t['Ohorngrave'] = 0x1EDC;
  6468. t['Ohornhookabove'] = 0x1EDE;
  6469. t['Ohorntilde'] = 0x1EE0;
  6470. t['Ohungarumlaut'] = 0x0150;
  6471. t['Oi'] = 0x01A2;
  6472. t['Oinvertedbreve'] = 0x020E;
  6473. t['Omacron'] = 0x014C;
  6474. t['Omacronacute'] = 0x1E52;
  6475. t['Omacrongrave'] = 0x1E50;
  6476. t['Omega'] = 0x2126;
  6477. t['Omegacyrillic'] = 0x0460;
  6478. t['Omegagreek'] = 0x03A9;
  6479. t['Omegaroundcyrillic'] = 0x047A;
  6480. t['Omegatitlocyrillic'] = 0x047C;
  6481. t['Omegatonos'] = 0x038F;
  6482. t['Omicron'] = 0x039F;
  6483. t['Omicrontonos'] = 0x038C;
  6484. t['Omonospace'] = 0xFF2F;
  6485. t['Oneroman'] = 0x2160;
  6486. t['Oogonek'] = 0x01EA;
  6487. t['Oogonekmacron'] = 0x01EC;
  6488. t['Oopen'] = 0x0186;
  6489. t['Oslash'] = 0x00D8;
  6490. t['Oslashacute'] = 0x01FE;
  6491. t['Oslashsmall'] = 0xF7F8;
  6492. t['Osmall'] = 0xF76F;
  6493. t['Ostrokeacute'] = 0x01FE;
  6494. t['Otcyrillic'] = 0x047E;
  6495. t['Otilde'] = 0x00D5;
  6496. t['Otildeacute'] = 0x1E4C;
  6497. t['Otildedieresis'] = 0x1E4E;
  6498. t['Otildesmall'] = 0xF7F5;
  6499. t['P'] = 0x0050;
  6500. t['Pacute'] = 0x1E54;
  6501. t['Pcircle'] = 0x24C5;
  6502. t['Pdotaccent'] = 0x1E56;
  6503. t['Pecyrillic'] = 0x041F;
  6504. t['Peharmenian'] = 0x054A;
  6505. t['Pemiddlehookcyrillic'] = 0x04A6;
  6506. t['Phi'] = 0x03A6;
  6507. t['Phook'] = 0x01A4;
  6508. t['Pi'] = 0x03A0;
  6509. t['Piwrarmenian'] = 0x0553;
  6510. t['Pmonospace'] = 0xFF30;
  6511. t['Psi'] = 0x03A8;
  6512. t['Psicyrillic'] = 0x0470;
  6513. t['Psmall'] = 0xF770;
  6514. t['Q'] = 0x0051;
  6515. t['Qcircle'] = 0x24C6;
  6516. t['Qmonospace'] = 0xFF31;
  6517. t['Qsmall'] = 0xF771;
  6518. t['R'] = 0x0052;
  6519. t['Raarmenian'] = 0x054C;
  6520. t['Racute'] = 0x0154;
  6521. t['Rcaron'] = 0x0158;
  6522. t['Rcedilla'] = 0x0156;
  6523. t['Rcircle'] = 0x24C7;
  6524. t['Rcommaaccent'] = 0x0156;
  6525. t['Rdblgrave'] = 0x0210;
  6526. t['Rdotaccent'] = 0x1E58;
  6527. t['Rdotbelow'] = 0x1E5A;
  6528. t['Rdotbelowmacron'] = 0x1E5C;
  6529. t['Reharmenian'] = 0x0550;
  6530. t['Rfraktur'] = 0x211C;
  6531. t['Rho'] = 0x03A1;
  6532. t['Ringsmall'] = 0xF6FC;
  6533. t['Rinvertedbreve'] = 0x0212;
  6534. t['Rlinebelow'] = 0x1E5E;
  6535. t['Rmonospace'] = 0xFF32;
  6536. t['Rsmall'] = 0xF772;
  6537. t['Rsmallinverted'] = 0x0281;
  6538. t['Rsmallinvertedsuperior'] = 0x02B6;
  6539. t['S'] = 0x0053;
  6540. t['SF010000'] = 0x250C;
  6541. t['SF020000'] = 0x2514;
  6542. t['SF030000'] = 0x2510;
  6543. t['SF040000'] = 0x2518;
  6544. t['SF050000'] = 0x253C;
  6545. t['SF060000'] = 0x252C;
  6546. t['SF070000'] = 0x2534;
  6547. t['SF080000'] = 0x251C;
  6548. t['SF090000'] = 0x2524;
  6549. t['SF100000'] = 0x2500;
  6550. t['SF110000'] = 0x2502;
  6551. t['SF190000'] = 0x2561;
  6552. t['SF200000'] = 0x2562;
  6553. t['SF210000'] = 0x2556;
  6554. t['SF220000'] = 0x2555;
  6555. t['SF230000'] = 0x2563;
  6556. t['SF240000'] = 0x2551;
  6557. t['SF250000'] = 0x2557;
  6558. t['SF260000'] = 0x255D;
  6559. t['SF270000'] = 0x255C;
  6560. t['SF280000'] = 0x255B;
  6561. t['SF360000'] = 0x255E;
  6562. t['SF370000'] = 0x255F;
  6563. t['SF380000'] = 0x255A;
  6564. t['SF390000'] = 0x2554;
  6565. t['SF400000'] = 0x2569;
  6566. t['SF410000'] = 0x2566;
  6567. t['SF420000'] = 0x2560;
  6568. t['SF430000'] = 0x2550;
  6569. t['SF440000'] = 0x256C;
  6570. t['SF450000'] = 0x2567;
  6571. t['SF460000'] = 0x2568;
  6572. t['SF470000'] = 0x2564;
  6573. t['SF480000'] = 0x2565;
  6574. t['SF490000'] = 0x2559;
  6575. t['SF500000'] = 0x2558;
  6576. t['SF510000'] = 0x2552;
  6577. t['SF520000'] = 0x2553;
  6578. t['SF530000'] = 0x256B;
  6579. t['SF540000'] = 0x256A;
  6580. t['Sacute'] = 0x015A;
  6581. t['Sacutedotaccent'] = 0x1E64;
  6582. t['Sampigreek'] = 0x03E0;
  6583. t['Scaron'] = 0x0160;
  6584. t['Scarondotaccent'] = 0x1E66;
  6585. t['Scaronsmall'] = 0xF6FD;
  6586. t['Scedilla'] = 0x015E;
  6587. t['Schwa'] = 0x018F;
  6588. t['Schwacyrillic'] = 0x04D8;
  6589. t['Schwadieresiscyrillic'] = 0x04DA;
  6590. t['Scircle'] = 0x24C8;
  6591. t['Scircumflex'] = 0x015C;
  6592. t['Scommaaccent'] = 0x0218;
  6593. t['Sdotaccent'] = 0x1E60;
  6594. t['Sdotbelow'] = 0x1E62;
  6595. t['Sdotbelowdotaccent'] = 0x1E68;
  6596. t['Seharmenian'] = 0x054D;
  6597. t['Sevenroman'] = 0x2166;
  6598. t['Shaarmenian'] = 0x0547;
  6599. t['Shacyrillic'] = 0x0428;
  6600. t['Shchacyrillic'] = 0x0429;
  6601. t['Sheicoptic'] = 0x03E2;
  6602. t['Shhacyrillic'] = 0x04BA;
  6603. t['Shimacoptic'] = 0x03EC;
  6604. t['Sigma'] = 0x03A3;
  6605. t['Sixroman'] = 0x2165;
  6606. t['Smonospace'] = 0xFF33;
  6607. t['Softsigncyrillic'] = 0x042C;
  6608. t['Ssmall'] = 0xF773;
  6609. t['Stigmagreek'] = 0x03DA;
  6610. t['T'] = 0x0054;
  6611. t['Tau'] = 0x03A4;
  6612. t['Tbar'] = 0x0166;
  6613. t['Tcaron'] = 0x0164;
  6614. t['Tcedilla'] = 0x0162;
  6615. t['Tcircle'] = 0x24C9;
  6616. t['Tcircumflexbelow'] = 0x1E70;
  6617. t['Tcommaaccent'] = 0x0162;
  6618. t['Tdotaccent'] = 0x1E6A;
  6619. t['Tdotbelow'] = 0x1E6C;
  6620. t['Tecyrillic'] = 0x0422;
  6621. t['Tedescendercyrillic'] = 0x04AC;
  6622. t['Tenroman'] = 0x2169;
  6623. t['Tetsecyrillic'] = 0x04B4;
  6624. t['Theta'] = 0x0398;
  6625. t['Thook'] = 0x01AC;
  6626. t['Thorn'] = 0x00DE;
  6627. t['Thornsmall'] = 0xF7FE;
  6628. t['Threeroman'] = 0x2162;
  6629. t['Tildesmall'] = 0xF6FE;
  6630. t['Tiwnarmenian'] = 0x054F;
  6631. t['Tlinebelow'] = 0x1E6E;
  6632. t['Tmonospace'] = 0xFF34;
  6633. t['Toarmenian'] = 0x0539;
  6634. t['Tonefive'] = 0x01BC;
  6635. t['Tonesix'] = 0x0184;
  6636. t['Tonetwo'] = 0x01A7;
  6637. t['Tretroflexhook'] = 0x01AE;
  6638. t['Tsecyrillic'] = 0x0426;
  6639. t['Tshecyrillic'] = 0x040B;
  6640. t['Tsmall'] = 0xF774;
  6641. t['Twelveroman'] = 0x216B;
  6642. t['Tworoman'] = 0x2161;
  6643. t['U'] = 0x0055;
  6644. t['Uacute'] = 0x00DA;
  6645. t['Uacutesmall'] = 0xF7FA;
  6646. t['Ubreve'] = 0x016C;
  6647. t['Ucaron'] = 0x01D3;
  6648. t['Ucircle'] = 0x24CA;
  6649. t['Ucircumflex'] = 0x00DB;
  6650. t['Ucircumflexbelow'] = 0x1E76;
  6651. t['Ucircumflexsmall'] = 0xF7FB;
  6652. t['Ucyrillic'] = 0x0423;
  6653. t['Udblacute'] = 0x0170;
  6654. t['Udblgrave'] = 0x0214;
  6655. t['Udieresis'] = 0x00DC;
  6656. t['Udieresisacute'] = 0x01D7;
  6657. t['Udieresisbelow'] = 0x1E72;
  6658. t['Udieresiscaron'] = 0x01D9;
  6659. t['Udieresiscyrillic'] = 0x04F0;
  6660. t['Udieresisgrave'] = 0x01DB;
  6661. t['Udieresismacron'] = 0x01D5;
  6662. t['Udieresissmall'] = 0xF7FC;
  6663. t['Udotbelow'] = 0x1EE4;
  6664. t['Ugrave'] = 0x00D9;
  6665. t['Ugravesmall'] = 0xF7F9;
  6666. t['Uhookabove'] = 0x1EE6;
  6667. t['Uhorn'] = 0x01AF;
  6668. t['Uhornacute'] = 0x1EE8;
  6669. t['Uhorndotbelow'] = 0x1EF0;
  6670. t['Uhorngrave'] = 0x1EEA;
  6671. t['Uhornhookabove'] = 0x1EEC;
  6672. t['Uhorntilde'] = 0x1EEE;
  6673. t['Uhungarumlaut'] = 0x0170;
  6674. t['Uhungarumlautcyrillic'] = 0x04F2;
  6675. t['Uinvertedbreve'] = 0x0216;
  6676. t['Ukcyrillic'] = 0x0478;
  6677. t['Umacron'] = 0x016A;
  6678. t['Umacroncyrillic'] = 0x04EE;
  6679. t['Umacrondieresis'] = 0x1E7A;
  6680. t['Umonospace'] = 0xFF35;
  6681. t['Uogonek'] = 0x0172;
  6682. t['Upsilon'] = 0x03A5;
  6683. t['Upsilon1'] = 0x03D2;
  6684. t['Upsilonacutehooksymbolgreek'] = 0x03D3;
  6685. t['Upsilonafrican'] = 0x01B1;
  6686. t['Upsilondieresis'] = 0x03AB;
  6687. t['Upsilondieresishooksymbolgreek'] = 0x03D4;
  6688. t['Upsilonhooksymbol'] = 0x03D2;
  6689. t['Upsilontonos'] = 0x038E;
  6690. t['Uring'] = 0x016E;
  6691. t['Ushortcyrillic'] = 0x040E;
  6692. t['Usmall'] = 0xF775;
  6693. t['Ustraightcyrillic'] = 0x04AE;
  6694. t['Ustraightstrokecyrillic'] = 0x04B0;
  6695. t['Utilde'] = 0x0168;
  6696. t['Utildeacute'] = 0x1E78;
  6697. t['Utildebelow'] = 0x1E74;
  6698. t['V'] = 0x0056;
  6699. t['Vcircle'] = 0x24CB;
  6700. t['Vdotbelow'] = 0x1E7E;
  6701. t['Vecyrillic'] = 0x0412;
  6702. t['Vewarmenian'] = 0x054E;
  6703. t['Vhook'] = 0x01B2;
  6704. t['Vmonospace'] = 0xFF36;
  6705. t['Voarmenian'] = 0x0548;
  6706. t['Vsmall'] = 0xF776;
  6707. t['Vtilde'] = 0x1E7C;
  6708. t['W'] = 0x0057;
  6709. t['Wacute'] = 0x1E82;
  6710. t['Wcircle'] = 0x24CC;
  6711. t['Wcircumflex'] = 0x0174;
  6712. t['Wdieresis'] = 0x1E84;
  6713. t['Wdotaccent'] = 0x1E86;
  6714. t['Wdotbelow'] = 0x1E88;
  6715. t['Wgrave'] = 0x1E80;
  6716. t['Wmonospace'] = 0xFF37;
  6717. t['Wsmall'] = 0xF777;
  6718. t['X'] = 0x0058;
  6719. t['Xcircle'] = 0x24CD;
  6720. t['Xdieresis'] = 0x1E8C;
  6721. t['Xdotaccent'] = 0x1E8A;
  6722. t['Xeharmenian'] = 0x053D;
  6723. t['Xi'] = 0x039E;
  6724. t['Xmonospace'] = 0xFF38;
  6725. t['Xsmall'] = 0xF778;
  6726. t['Y'] = 0x0059;
  6727. t['Yacute'] = 0x00DD;
  6728. t['Yacutesmall'] = 0xF7FD;
  6729. t['Yatcyrillic'] = 0x0462;
  6730. t['Ycircle'] = 0x24CE;
  6731. t['Ycircumflex'] = 0x0176;
  6732. t['Ydieresis'] = 0x0178;
  6733. t['Ydieresissmall'] = 0xF7FF;
  6734. t['Ydotaccent'] = 0x1E8E;
  6735. t['Ydotbelow'] = 0x1EF4;
  6736. t['Yericyrillic'] = 0x042B;
  6737. t['Yerudieresiscyrillic'] = 0x04F8;
  6738. t['Ygrave'] = 0x1EF2;
  6739. t['Yhook'] = 0x01B3;
  6740. t['Yhookabove'] = 0x1EF6;
  6741. t['Yiarmenian'] = 0x0545;
  6742. t['Yicyrillic'] = 0x0407;
  6743. t['Yiwnarmenian'] = 0x0552;
  6744. t['Ymonospace'] = 0xFF39;
  6745. t['Ysmall'] = 0xF779;
  6746. t['Ytilde'] = 0x1EF8;
  6747. t['Yusbigcyrillic'] = 0x046A;
  6748. t['Yusbigiotifiedcyrillic'] = 0x046C;
  6749. t['Yuslittlecyrillic'] = 0x0466;
  6750. t['Yuslittleiotifiedcyrillic'] = 0x0468;
  6751. t['Z'] = 0x005A;
  6752. t['Zaarmenian'] = 0x0536;
  6753. t['Zacute'] = 0x0179;
  6754. t['Zcaron'] = 0x017D;
  6755. t['Zcaronsmall'] = 0xF6FF;
  6756. t['Zcircle'] = 0x24CF;
  6757. t['Zcircumflex'] = 0x1E90;
  6758. t['Zdot'] = 0x017B;
  6759. t['Zdotaccent'] = 0x017B;
  6760. t['Zdotbelow'] = 0x1E92;
  6761. t['Zecyrillic'] = 0x0417;
  6762. t['Zedescendercyrillic'] = 0x0498;
  6763. t['Zedieresiscyrillic'] = 0x04DE;
  6764. t['Zeta'] = 0x0396;
  6765. t['Zhearmenian'] = 0x053A;
  6766. t['Zhebrevecyrillic'] = 0x04C1;
  6767. t['Zhecyrillic'] = 0x0416;
  6768. t['Zhedescendercyrillic'] = 0x0496;
  6769. t['Zhedieresiscyrillic'] = 0x04DC;
  6770. t['Zlinebelow'] = 0x1E94;
  6771. t['Zmonospace'] = 0xFF3A;
  6772. t['Zsmall'] = 0xF77A;
  6773. t['Zstroke'] = 0x01B5;
  6774. t['a'] = 0x0061;
  6775. t['aabengali'] = 0x0986;
  6776. t['aacute'] = 0x00E1;
  6777. t['aadeva'] = 0x0906;
  6778. t['aagujarati'] = 0x0A86;
  6779. t['aagurmukhi'] = 0x0A06;
  6780. t['aamatragurmukhi'] = 0x0A3E;
  6781. t['aarusquare'] = 0x3303;
  6782. t['aavowelsignbengali'] = 0x09BE;
  6783. t['aavowelsigndeva'] = 0x093E;
  6784. t['aavowelsigngujarati'] = 0x0ABE;
  6785. t['abbreviationmarkarmenian'] = 0x055F;
  6786. t['abbreviationsigndeva'] = 0x0970;
  6787. t['abengali'] = 0x0985;
  6788. t['abopomofo'] = 0x311A;
  6789. t['abreve'] = 0x0103;
  6790. t['abreveacute'] = 0x1EAF;
  6791. t['abrevecyrillic'] = 0x04D1;
  6792. t['abrevedotbelow'] = 0x1EB7;
  6793. t['abrevegrave'] = 0x1EB1;
  6794. t['abrevehookabove'] = 0x1EB3;
  6795. t['abrevetilde'] = 0x1EB5;
  6796. t['acaron'] = 0x01CE;
  6797. t['acircle'] = 0x24D0;
  6798. t['acircumflex'] = 0x00E2;
  6799. t['acircumflexacute'] = 0x1EA5;
  6800. t['acircumflexdotbelow'] = 0x1EAD;
  6801. t['acircumflexgrave'] = 0x1EA7;
  6802. t['acircumflexhookabove'] = 0x1EA9;
  6803. t['acircumflextilde'] = 0x1EAB;
  6804. t['acute'] = 0x00B4;
  6805. t['acutebelowcmb'] = 0x0317;
  6806. t['acutecmb'] = 0x0301;
  6807. t['acutecomb'] = 0x0301;
  6808. t['acutedeva'] = 0x0954;
  6809. t['acutelowmod'] = 0x02CF;
  6810. t['acutetonecmb'] = 0x0341;
  6811. t['acyrillic'] = 0x0430;
  6812. t['adblgrave'] = 0x0201;
  6813. t['addakgurmukhi'] = 0x0A71;
  6814. t['adeva'] = 0x0905;
  6815. t['adieresis'] = 0x00E4;
  6816. t['adieresiscyrillic'] = 0x04D3;
  6817. t['adieresismacron'] = 0x01DF;
  6818. t['adotbelow'] = 0x1EA1;
  6819. t['adotmacron'] = 0x01E1;
  6820. t['ae'] = 0x00E6;
  6821. t['aeacute'] = 0x01FD;
  6822. t['aekorean'] = 0x3150;
  6823. t['aemacron'] = 0x01E3;
  6824. t['afii00208'] = 0x2015;
  6825. t['afii08941'] = 0x20A4;
  6826. t['afii10017'] = 0x0410;
  6827. t['afii10018'] = 0x0411;
  6828. t['afii10019'] = 0x0412;
  6829. t['afii10020'] = 0x0413;
  6830. t['afii10021'] = 0x0414;
  6831. t['afii10022'] = 0x0415;
  6832. t['afii10023'] = 0x0401;
  6833. t['afii10024'] = 0x0416;
  6834. t['afii10025'] = 0x0417;
  6835. t['afii10026'] = 0x0418;
  6836. t['afii10027'] = 0x0419;
  6837. t['afii10028'] = 0x041A;
  6838. t['afii10029'] = 0x041B;
  6839. t['afii10030'] = 0x041C;
  6840. t['afii10031'] = 0x041D;
  6841. t['afii10032'] = 0x041E;
  6842. t['afii10033'] = 0x041F;
  6843. t['afii10034'] = 0x0420;
  6844. t['afii10035'] = 0x0421;
  6845. t['afii10036'] = 0x0422;
  6846. t['afii10037'] = 0x0423;
  6847. t['afii10038'] = 0x0424;
  6848. t['afii10039'] = 0x0425;
  6849. t['afii10040'] = 0x0426;
  6850. t['afii10041'] = 0x0427;
  6851. t['afii10042'] = 0x0428;
  6852. t['afii10043'] = 0x0429;
  6853. t['afii10044'] = 0x042A;
  6854. t['afii10045'] = 0x042B;
  6855. t['afii10046'] = 0x042C;
  6856. t['afii10047'] = 0x042D;
  6857. t['afii10048'] = 0x042E;
  6858. t['afii10049'] = 0x042F;
  6859. t['afii10050'] = 0x0490;
  6860. t['afii10051'] = 0x0402;
  6861. t['afii10052'] = 0x0403;
  6862. t['afii10053'] = 0x0404;
  6863. t['afii10054'] = 0x0405;
  6864. t['afii10055'] = 0x0406;
  6865. t['afii10056'] = 0x0407;
  6866. t['afii10057'] = 0x0408;
  6867. t['afii10058'] = 0x0409;
  6868. t['afii10059'] = 0x040A;
  6869. t['afii10060'] = 0x040B;
  6870. t['afii10061'] = 0x040C;
  6871. t['afii10062'] = 0x040E;
  6872. t['afii10063'] = 0xF6C4;
  6873. t['afii10064'] = 0xF6C5;
  6874. t['afii10065'] = 0x0430;
  6875. t['afii10066'] = 0x0431;
  6876. t['afii10067'] = 0x0432;
  6877. t['afii10068'] = 0x0433;
  6878. t['afii10069'] = 0x0434;
  6879. t['afii10070'] = 0x0435;
  6880. t['afii10071'] = 0x0451;
  6881. t['afii10072'] = 0x0436;
  6882. t['afii10073'] = 0x0437;
  6883. t['afii10074'] = 0x0438;
  6884. t['afii10075'] = 0x0439;
  6885. t['afii10076'] = 0x043A;
  6886. t['afii10077'] = 0x043B;
  6887. t['afii10078'] = 0x043C;
  6888. t['afii10079'] = 0x043D;
  6889. t['afii10080'] = 0x043E;
  6890. t['afii10081'] = 0x043F;
  6891. t['afii10082'] = 0x0440;
  6892. t['afii10083'] = 0x0441;
  6893. t['afii10084'] = 0x0442;
  6894. t['afii10085'] = 0x0443;
  6895. t['afii10086'] = 0x0444;
  6896. t['afii10087'] = 0x0445;
  6897. t['afii10088'] = 0x0446;
  6898. t['afii10089'] = 0x0447;
  6899. t['afii10090'] = 0x0448;
  6900. t['afii10091'] = 0x0449;
  6901. t['afii10092'] = 0x044A;
  6902. t['afii10093'] = 0x044B;
  6903. t['afii10094'] = 0x044C;
  6904. t['afii10095'] = 0x044D;
  6905. t['afii10096'] = 0x044E;
  6906. t['afii10097'] = 0x044F;
  6907. t['afii10098'] = 0x0491;
  6908. t['afii10099'] = 0x0452;
  6909. t['afii10100'] = 0x0453;
  6910. t['afii10101'] = 0x0454;
  6911. t['afii10102'] = 0x0455;
  6912. t['afii10103'] = 0x0456;
  6913. t['afii10104'] = 0x0457;
  6914. t['afii10105'] = 0x0458;
  6915. t['afii10106'] = 0x0459;
  6916. t['afii10107'] = 0x045A;
  6917. t['afii10108'] = 0x045B;
  6918. t['afii10109'] = 0x045C;
  6919. t['afii10110'] = 0x045E;
  6920. t['afii10145'] = 0x040F;
  6921. t['afii10146'] = 0x0462;
  6922. t['afii10147'] = 0x0472;
  6923. t['afii10148'] = 0x0474;
  6924. t['afii10192'] = 0xF6C6;
  6925. t['afii10193'] = 0x045F;
  6926. t['afii10194'] = 0x0463;
  6927. t['afii10195'] = 0x0473;
  6928. t['afii10196'] = 0x0475;
  6929. t['afii10831'] = 0xF6C7;
  6930. t['afii10832'] = 0xF6C8;
  6931. t['afii10846'] = 0x04D9;
  6932. t['afii299'] = 0x200E;
  6933. t['afii300'] = 0x200F;
  6934. t['afii301'] = 0x200D;
  6935. t['afii57381'] = 0x066A;
  6936. t['afii57388'] = 0x060C;
  6937. t['afii57392'] = 0x0660;
  6938. t['afii57393'] = 0x0661;
  6939. t['afii57394'] = 0x0662;
  6940. t['afii57395'] = 0x0663;
  6941. t['afii57396'] = 0x0664;
  6942. t['afii57397'] = 0x0665;
  6943. t['afii57398'] = 0x0666;
  6944. t['afii57399'] = 0x0667;
  6945. t['afii57400'] = 0x0668;
  6946. t['afii57401'] = 0x0669;
  6947. t['afii57403'] = 0x061B;
  6948. t['afii57407'] = 0x061F;
  6949. t['afii57409'] = 0x0621;
  6950. t['afii57410'] = 0x0622;
  6951. t['afii57411'] = 0x0623;
  6952. t['afii57412'] = 0x0624;
  6953. t['afii57413'] = 0x0625;
  6954. t['afii57414'] = 0x0626;
  6955. t['afii57415'] = 0x0627;
  6956. t['afii57416'] = 0x0628;
  6957. t['afii57417'] = 0x0629;
  6958. t['afii57418'] = 0x062A;
  6959. t['afii57419'] = 0x062B;
  6960. t['afii57420'] = 0x062C;
  6961. t['afii57421'] = 0x062D;
  6962. t['afii57422'] = 0x062E;
  6963. t['afii57423'] = 0x062F;
  6964. t['afii57424'] = 0x0630;
  6965. t['afii57425'] = 0x0631;
  6966. t['afii57426'] = 0x0632;
  6967. t['afii57427'] = 0x0633;
  6968. t['afii57428'] = 0x0634;
  6969. t['afii57429'] = 0x0635;
  6970. t['afii57430'] = 0x0636;
  6971. t['afii57431'] = 0x0637;
  6972. t['afii57432'] = 0x0638;
  6973. t['afii57433'] = 0x0639;
  6974. t['afii57434'] = 0x063A;
  6975. t['afii57440'] = 0x0640;
  6976. t['afii57441'] = 0x0641;
  6977. t['afii57442'] = 0x0642;
  6978. t['afii57443'] = 0x0643;
  6979. t['afii57444'] = 0x0644;
  6980. t['afii57445'] = 0x0645;
  6981. t['afii57446'] = 0x0646;
  6982. t['afii57448'] = 0x0648;
  6983. t['afii57449'] = 0x0649;
  6984. t['afii57450'] = 0x064A;
  6985. t['afii57451'] = 0x064B;
  6986. t['afii57452'] = 0x064C;
  6987. t['afii57453'] = 0x064D;
  6988. t['afii57454'] = 0x064E;
  6989. t['afii57455'] = 0x064F;
  6990. t['afii57456'] = 0x0650;
  6991. t['afii57457'] = 0x0651;
  6992. t['afii57458'] = 0x0652;
  6993. t['afii57470'] = 0x0647;
  6994. t['afii57505'] = 0x06A4;
  6995. t['afii57506'] = 0x067E;
  6996. t['afii57507'] = 0x0686;
  6997. t['afii57508'] = 0x0698;
  6998. t['afii57509'] = 0x06AF;
  6999. t['afii57511'] = 0x0679;
  7000. t['afii57512'] = 0x0688;
  7001. t['afii57513'] = 0x0691;
  7002. t['afii57514'] = 0x06BA;
  7003. t['afii57519'] = 0x06D2;
  7004. t['afii57534'] = 0x06D5;
  7005. t['afii57636'] = 0x20AA;
  7006. t['afii57645'] = 0x05BE;
  7007. t['afii57658'] = 0x05C3;
  7008. t['afii57664'] = 0x05D0;
  7009. t['afii57665'] = 0x05D1;
  7010. t['afii57666'] = 0x05D2;
  7011. t['afii57667'] = 0x05D3;
  7012. t['afii57668'] = 0x05D4;
  7013. t['afii57669'] = 0x05D5;
  7014. t['afii57670'] = 0x05D6;
  7015. t['afii57671'] = 0x05D7;
  7016. t['afii57672'] = 0x05D8;
  7017. t['afii57673'] = 0x05D9;
  7018. t['afii57674'] = 0x05DA;
  7019. t['afii57675'] = 0x05DB;
  7020. t['afii57676'] = 0x05DC;
  7021. t['afii57677'] = 0x05DD;
  7022. t['afii57678'] = 0x05DE;
  7023. t['afii57679'] = 0x05DF;
  7024. t['afii57680'] = 0x05E0;
  7025. t['afii57681'] = 0x05E1;
  7026. t['afii57682'] = 0x05E2;
  7027. t['afii57683'] = 0x05E3;
  7028. t['afii57684'] = 0x05E4;
  7029. t['afii57685'] = 0x05E5;
  7030. t['afii57686'] = 0x05E6;
  7031. t['afii57687'] = 0x05E7;
  7032. t['afii57688'] = 0x05E8;
  7033. t['afii57689'] = 0x05E9;
  7034. t['afii57690'] = 0x05EA;
  7035. t['afii57694'] = 0xFB2A;
  7036. t['afii57695'] = 0xFB2B;
  7037. t['afii57700'] = 0xFB4B;
  7038. t['afii57705'] = 0xFB1F;
  7039. t['afii57716'] = 0x05F0;
  7040. t['afii57717'] = 0x05F1;
  7041. t['afii57718'] = 0x05F2;
  7042. t['afii57723'] = 0xFB35;
  7043. t['afii57793'] = 0x05B4;
  7044. t['afii57794'] = 0x05B5;
  7045. t['afii57795'] = 0x05B6;
  7046. t['afii57796'] = 0x05BB;
  7047. t['afii57797'] = 0x05B8;
  7048. t['afii57798'] = 0x05B7;
  7049. t['afii57799'] = 0x05B0;
  7050. t['afii57800'] = 0x05B2;
  7051. t['afii57801'] = 0x05B1;
  7052. t['afii57802'] = 0x05B3;
  7053. t['afii57803'] = 0x05C2;
  7054. t['afii57804'] = 0x05C1;
  7055. t['afii57806'] = 0x05B9;
  7056. t['afii57807'] = 0x05BC;
  7057. t['afii57839'] = 0x05BD;
  7058. t['afii57841'] = 0x05BF;
  7059. t['afii57842'] = 0x05C0;
  7060. t['afii57929'] = 0x02BC;
  7061. t['afii61248'] = 0x2105;
  7062. t['afii61289'] = 0x2113;
  7063. t['afii61352'] = 0x2116;
  7064. t['afii61573'] = 0x202C;
  7065. t['afii61574'] = 0x202D;
  7066. t['afii61575'] = 0x202E;
  7067. t['afii61664'] = 0x200C;
  7068. t['afii63167'] = 0x066D;
  7069. t['afii64937'] = 0x02BD;
  7070. t['agrave'] = 0x00E0;
  7071. t['agujarati'] = 0x0A85;
  7072. t['agurmukhi'] = 0x0A05;
  7073. t['ahiragana'] = 0x3042;
  7074. t['ahookabove'] = 0x1EA3;
  7075. t['aibengali'] = 0x0990;
  7076. t['aibopomofo'] = 0x311E;
  7077. t['aideva'] = 0x0910;
  7078. t['aiecyrillic'] = 0x04D5;
  7079. t['aigujarati'] = 0x0A90;
  7080. t['aigurmukhi'] = 0x0A10;
  7081. t['aimatragurmukhi'] = 0x0A48;
  7082. t['ainarabic'] = 0x0639;
  7083. t['ainfinalarabic'] = 0xFECA;
  7084. t['aininitialarabic'] = 0xFECB;
  7085. t['ainmedialarabic'] = 0xFECC;
  7086. t['ainvertedbreve'] = 0x0203;
  7087. t['aivowelsignbengali'] = 0x09C8;
  7088. t['aivowelsigndeva'] = 0x0948;
  7089. t['aivowelsigngujarati'] = 0x0AC8;
  7090. t['akatakana'] = 0x30A2;
  7091. t['akatakanahalfwidth'] = 0xFF71;
  7092. t['akorean'] = 0x314F;
  7093. t['alef'] = 0x05D0;
  7094. t['alefarabic'] = 0x0627;
  7095. t['alefdageshhebrew'] = 0xFB30;
  7096. t['aleffinalarabic'] = 0xFE8E;
  7097. t['alefhamzaabovearabic'] = 0x0623;
  7098. t['alefhamzaabovefinalarabic'] = 0xFE84;
  7099. t['alefhamzabelowarabic'] = 0x0625;
  7100. t['alefhamzabelowfinalarabic'] = 0xFE88;
  7101. t['alefhebrew'] = 0x05D0;
  7102. t['aleflamedhebrew'] = 0xFB4F;
  7103. t['alefmaddaabovearabic'] = 0x0622;
  7104. t['alefmaddaabovefinalarabic'] = 0xFE82;
  7105. t['alefmaksuraarabic'] = 0x0649;
  7106. t['alefmaksurafinalarabic'] = 0xFEF0;
  7107. t['alefmaksurainitialarabic'] = 0xFEF3;
  7108. t['alefmaksuramedialarabic'] = 0xFEF4;
  7109. t['alefpatahhebrew'] = 0xFB2E;
  7110. t['alefqamatshebrew'] = 0xFB2F;
  7111. t['aleph'] = 0x2135;
  7112. t['allequal'] = 0x224C;
  7113. t['alpha'] = 0x03B1;
  7114. t['alphatonos'] = 0x03AC;
  7115. t['amacron'] = 0x0101;
  7116. t['amonospace'] = 0xFF41;
  7117. t['ampersand'] = 0x0026;
  7118. t['ampersandmonospace'] = 0xFF06;
  7119. t['ampersandsmall'] = 0xF726;
  7120. t['amsquare'] = 0x33C2;
  7121. t['anbopomofo'] = 0x3122;
  7122. t['angbopomofo'] = 0x3124;
  7123. t['angbracketleft'] = 0x3008; // Glyph is missing from Adobe's original list.
  7124. t['angbracketright'] = 0x3009; // Glyph is missing from Adobe's original list.
  7125. t['angkhankhuthai'] = 0x0E5A;
  7126. t['angle'] = 0x2220;
  7127. t['anglebracketleft'] = 0x3008;
  7128. t['anglebracketleftvertical'] = 0xFE3F;
  7129. t['anglebracketright'] = 0x3009;
  7130. t['anglebracketrightvertical'] = 0xFE40;
  7131. t['angleleft'] = 0x2329;
  7132. t['angleright'] = 0x232A;
  7133. t['angstrom'] = 0x212B;
  7134. t['anoteleia'] = 0x0387;
  7135. t['anudattadeva'] = 0x0952;
  7136. t['anusvarabengali'] = 0x0982;
  7137. t['anusvaradeva'] = 0x0902;
  7138. t['anusvaragujarati'] = 0x0A82;
  7139. t['aogonek'] = 0x0105;
  7140. t['apaatosquare'] = 0x3300;
  7141. t['aparen'] = 0x249C;
  7142. t['apostrophearmenian'] = 0x055A;
  7143. t['apostrophemod'] = 0x02BC;
  7144. t['apple'] = 0xF8FF;
  7145. t['approaches'] = 0x2250;
  7146. t['approxequal'] = 0x2248;
  7147. t['approxequalorimage'] = 0x2252;
  7148. t['approximatelyequal'] = 0x2245;
  7149. t['araeaekorean'] = 0x318E;
  7150. t['araeakorean'] = 0x318D;
  7151. t['arc'] = 0x2312;
  7152. t['arighthalfring'] = 0x1E9A;
  7153. t['aring'] = 0x00E5;
  7154. t['aringacute'] = 0x01FB;
  7155. t['aringbelow'] = 0x1E01;
  7156. t['arrowboth'] = 0x2194;
  7157. t['arrowdashdown'] = 0x21E3;
  7158. t['arrowdashleft'] = 0x21E0;
  7159. t['arrowdashright'] = 0x21E2;
  7160. t['arrowdashup'] = 0x21E1;
  7161. t['arrowdblboth'] = 0x21D4;
  7162. t['arrowdbldown'] = 0x21D3;
  7163. t['arrowdblleft'] = 0x21D0;
  7164. t['arrowdblright'] = 0x21D2;
  7165. t['arrowdblup'] = 0x21D1;
  7166. t['arrowdown'] = 0x2193;
  7167. t['arrowdownleft'] = 0x2199;
  7168. t['arrowdownright'] = 0x2198;
  7169. t['arrowdownwhite'] = 0x21E9;
  7170. t['arrowheaddownmod'] = 0x02C5;
  7171. t['arrowheadleftmod'] = 0x02C2;
  7172. t['arrowheadrightmod'] = 0x02C3;
  7173. t['arrowheadupmod'] = 0x02C4;
  7174. t['arrowhorizex'] = 0xF8E7;
  7175. t['arrowleft'] = 0x2190;
  7176. t['arrowleftdbl'] = 0x21D0;
  7177. t['arrowleftdblstroke'] = 0x21CD;
  7178. t['arrowleftoverright'] = 0x21C6;
  7179. t['arrowleftwhite'] = 0x21E6;
  7180. t['arrowright'] = 0x2192;
  7181. t['arrowrightdblstroke'] = 0x21CF;
  7182. t['arrowrightheavy'] = 0x279E;
  7183. t['arrowrightoverleft'] = 0x21C4;
  7184. t['arrowrightwhite'] = 0x21E8;
  7185. t['arrowtableft'] = 0x21E4;
  7186. t['arrowtabright'] = 0x21E5;
  7187. t['arrowup'] = 0x2191;
  7188. t['arrowupdn'] = 0x2195;
  7189. t['arrowupdnbse'] = 0x21A8;
  7190. t['arrowupdownbase'] = 0x21A8;
  7191. t['arrowupleft'] = 0x2196;
  7192. t['arrowupleftofdown'] = 0x21C5;
  7193. t['arrowupright'] = 0x2197;
  7194. t['arrowupwhite'] = 0x21E7;
  7195. t['arrowvertex'] = 0xF8E6;
  7196. t['asciicircum'] = 0x005E;
  7197. t['asciicircummonospace'] = 0xFF3E;
  7198. t['asciitilde'] = 0x007E;
  7199. t['asciitildemonospace'] = 0xFF5E;
  7200. t['ascript'] = 0x0251;
  7201. t['ascriptturned'] = 0x0252;
  7202. t['asmallhiragana'] = 0x3041;
  7203. t['asmallkatakana'] = 0x30A1;
  7204. t['asmallkatakanahalfwidth'] = 0xFF67;
  7205. t['asterisk'] = 0x002A;
  7206. t['asteriskaltonearabic'] = 0x066D;
  7207. t['asteriskarabic'] = 0x066D;
  7208. t['asteriskmath'] = 0x2217;
  7209. t['asteriskmonospace'] = 0xFF0A;
  7210. t['asterisksmall'] = 0xFE61;
  7211. t['asterism'] = 0x2042;
  7212. t['asuperior'] = 0xF6E9;
  7213. t['asymptoticallyequal'] = 0x2243;
  7214. t['at'] = 0x0040;
  7215. t['atilde'] = 0x00E3;
  7216. t['atmonospace'] = 0xFF20;
  7217. t['atsmall'] = 0xFE6B;
  7218. t['aturned'] = 0x0250;
  7219. t['aubengali'] = 0x0994;
  7220. t['aubopomofo'] = 0x3120;
  7221. t['audeva'] = 0x0914;
  7222. t['augujarati'] = 0x0A94;
  7223. t['augurmukhi'] = 0x0A14;
  7224. t['aulengthmarkbengali'] = 0x09D7;
  7225. t['aumatragurmukhi'] = 0x0A4C;
  7226. t['auvowelsignbengali'] = 0x09CC;
  7227. t['auvowelsigndeva'] = 0x094C;
  7228. t['auvowelsigngujarati'] = 0x0ACC;
  7229. t['avagrahadeva'] = 0x093D;
  7230. t['aybarmenian'] = 0x0561;
  7231. t['ayin'] = 0x05E2;
  7232. t['ayinaltonehebrew'] = 0xFB20;
  7233. t['ayinhebrew'] = 0x05E2;
  7234. t['b'] = 0x0062;
  7235. t['babengali'] = 0x09AC;
  7236. t['backslash'] = 0x005C;
  7237. t['backslashmonospace'] = 0xFF3C;
  7238. t['badeva'] = 0x092C;
  7239. t['bagujarati'] = 0x0AAC;
  7240. t['bagurmukhi'] = 0x0A2C;
  7241. t['bahiragana'] = 0x3070;
  7242. t['bahtthai'] = 0x0E3F;
  7243. t['bakatakana'] = 0x30D0;
  7244. t['bar'] = 0x007C;
  7245. t['barmonospace'] = 0xFF5C;
  7246. t['bbopomofo'] = 0x3105;
  7247. t['bcircle'] = 0x24D1;
  7248. t['bdotaccent'] = 0x1E03;
  7249. t['bdotbelow'] = 0x1E05;
  7250. t['beamedsixteenthnotes'] = 0x266C;
  7251. t['because'] = 0x2235;
  7252. t['becyrillic'] = 0x0431;
  7253. t['beharabic'] = 0x0628;
  7254. t['behfinalarabic'] = 0xFE90;
  7255. t['behinitialarabic'] = 0xFE91;
  7256. t['behiragana'] = 0x3079;
  7257. t['behmedialarabic'] = 0xFE92;
  7258. t['behmeeminitialarabic'] = 0xFC9F;
  7259. t['behmeemisolatedarabic'] = 0xFC08;
  7260. t['behnoonfinalarabic'] = 0xFC6D;
  7261. t['bekatakana'] = 0x30D9;
  7262. t['benarmenian'] = 0x0562;
  7263. t['bet'] = 0x05D1;
  7264. t['beta'] = 0x03B2;
  7265. t['betasymbolgreek'] = 0x03D0;
  7266. t['betdagesh'] = 0xFB31;
  7267. t['betdageshhebrew'] = 0xFB31;
  7268. t['bethebrew'] = 0x05D1;
  7269. t['betrafehebrew'] = 0xFB4C;
  7270. t['bhabengali'] = 0x09AD;
  7271. t['bhadeva'] = 0x092D;
  7272. t['bhagujarati'] = 0x0AAD;
  7273. t['bhagurmukhi'] = 0x0A2D;
  7274. t['bhook'] = 0x0253;
  7275. t['bihiragana'] = 0x3073;
  7276. t['bikatakana'] = 0x30D3;
  7277. t['bilabialclick'] = 0x0298;
  7278. t['bindigurmukhi'] = 0x0A02;
  7279. t['birusquare'] = 0x3331;
  7280. t['blackcircle'] = 0x25CF;
  7281. t['blackdiamond'] = 0x25C6;
  7282. t['blackdownpointingtriangle'] = 0x25BC;
  7283. t['blackleftpointingpointer'] = 0x25C4;
  7284. t['blackleftpointingtriangle'] = 0x25C0;
  7285. t['blacklenticularbracketleft'] = 0x3010;
  7286. t['blacklenticularbracketleftvertical'] = 0xFE3B;
  7287. t['blacklenticularbracketright'] = 0x3011;
  7288. t['blacklenticularbracketrightvertical'] = 0xFE3C;
  7289. t['blacklowerlefttriangle'] = 0x25E3;
  7290. t['blacklowerrighttriangle'] = 0x25E2;
  7291. t['blackrectangle'] = 0x25AC;
  7292. t['blackrightpointingpointer'] = 0x25BA;
  7293. t['blackrightpointingtriangle'] = 0x25B6;
  7294. t['blacksmallsquare'] = 0x25AA;
  7295. t['blacksmilingface'] = 0x263B;
  7296. t['blacksquare'] = 0x25A0;
  7297. t['blackstar'] = 0x2605;
  7298. t['blackupperlefttriangle'] = 0x25E4;
  7299. t['blackupperrighttriangle'] = 0x25E5;
  7300. t['blackuppointingsmalltriangle'] = 0x25B4;
  7301. t['blackuppointingtriangle'] = 0x25B2;
  7302. t['blank'] = 0x2423;
  7303. t['blinebelow'] = 0x1E07;
  7304. t['block'] = 0x2588;
  7305. t['bmonospace'] = 0xFF42;
  7306. t['bobaimaithai'] = 0x0E1A;
  7307. t['bohiragana'] = 0x307C;
  7308. t['bokatakana'] = 0x30DC;
  7309. t['bparen'] = 0x249D;
  7310. t['bqsquare'] = 0x33C3;
  7311. t['braceex'] = 0xF8F4;
  7312. t['braceleft'] = 0x007B;
  7313. t['braceleftbt'] = 0xF8F3;
  7314. t['braceleftmid'] = 0xF8F2;
  7315. t['braceleftmonospace'] = 0xFF5B;
  7316. t['braceleftsmall'] = 0xFE5B;
  7317. t['bracelefttp'] = 0xF8F1;
  7318. t['braceleftvertical'] = 0xFE37;
  7319. t['braceright'] = 0x007D;
  7320. t['bracerightbt'] = 0xF8FE;
  7321. t['bracerightmid'] = 0xF8FD;
  7322. t['bracerightmonospace'] = 0xFF5D;
  7323. t['bracerightsmall'] = 0xFE5C;
  7324. t['bracerighttp'] = 0xF8FC;
  7325. t['bracerightvertical'] = 0xFE38;
  7326. t['bracketleft'] = 0x005B;
  7327. t['bracketleftbt'] = 0xF8F0;
  7328. t['bracketleftex'] = 0xF8EF;
  7329. t['bracketleftmonospace'] = 0xFF3B;
  7330. t['bracketlefttp'] = 0xF8EE;
  7331. t['bracketright'] = 0x005D;
  7332. t['bracketrightbt'] = 0xF8FB;
  7333. t['bracketrightex'] = 0xF8FA;
  7334. t['bracketrightmonospace'] = 0xFF3D;
  7335. t['bracketrighttp'] = 0xF8F9;
  7336. t['breve'] = 0x02D8;
  7337. t['brevebelowcmb'] = 0x032E;
  7338. t['brevecmb'] = 0x0306;
  7339. t['breveinvertedbelowcmb'] = 0x032F;
  7340. t['breveinvertedcmb'] = 0x0311;
  7341. t['breveinverteddoublecmb'] = 0x0361;
  7342. t['bridgebelowcmb'] = 0x032A;
  7343. t['bridgeinvertedbelowcmb'] = 0x033A;
  7344. t['brokenbar'] = 0x00A6;
  7345. t['bstroke'] = 0x0180;
  7346. t['bsuperior'] = 0xF6EA;
  7347. t['btopbar'] = 0x0183;
  7348. t['buhiragana'] = 0x3076;
  7349. t['bukatakana'] = 0x30D6;
  7350. t['bullet'] = 0x2022;
  7351. t['bulletinverse'] = 0x25D8;
  7352. t['bulletoperator'] = 0x2219;
  7353. t['bullseye'] = 0x25CE;
  7354. t['c'] = 0x0063;
  7355. t['caarmenian'] = 0x056E;
  7356. t['cabengali'] = 0x099A;
  7357. t['cacute'] = 0x0107;
  7358. t['cadeva'] = 0x091A;
  7359. t['cagujarati'] = 0x0A9A;
  7360. t['cagurmukhi'] = 0x0A1A;
  7361. t['calsquare'] = 0x3388;
  7362. t['candrabindubengali'] = 0x0981;
  7363. t['candrabinducmb'] = 0x0310;
  7364. t['candrabindudeva'] = 0x0901;
  7365. t['candrabindugujarati'] = 0x0A81;
  7366. t['capslock'] = 0x21EA;
  7367. t['careof'] = 0x2105;
  7368. t['caron'] = 0x02C7;
  7369. t['caronbelowcmb'] = 0x032C;
  7370. t['caroncmb'] = 0x030C;
  7371. t['carriagereturn'] = 0x21B5;
  7372. t['cbopomofo'] = 0x3118;
  7373. t['ccaron'] = 0x010D;
  7374. t['ccedilla'] = 0x00E7;
  7375. t['ccedillaacute'] = 0x1E09;
  7376. t['ccircle'] = 0x24D2;
  7377. t['ccircumflex'] = 0x0109;
  7378. t['ccurl'] = 0x0255;
  7379. t['cdot'] = 0x010B;
  7380. t['cdotaccent'] = 0x010B;
  7381. t['cdsquare'] = 0x33C5;
  7382. t['cedilla'] = 0x00B8;
  7383. t['cedillacmb'] = 0x0327;
  7384. t['cent'] = 0x00A2;
  7385. t['centigrade'] = 0x2103;
  7386. t['centinferior'] = 0xF6DF;
  7387. t['centmonospace'] = 0xFFE0;
  7388. t['centoldstyle'] = 0xF7A2;
  7389. t['centsuperior'] = 0xF6E0;
  7390. t['chaarmenian'] = 0x0579;
  7391. t['chabengali'] = 0x099B;
  7392. t['chadeva'] = 0x091B;
  7393. t['chagujarati'] = 0x0A9B;
  7394. t['chagurmukhi'] = 0x0A1B;
  7395. t['chbopomofo'] = 0x3114;
  7396. t['cheabkhasiancyrillic'] = 0x04BD;
  7397. t['checkmark'] = 0x2713;
  7398. t['checyrillic'] = 0x0447;
  7399. t['chedescenderabkhasiancyrillic'] = 0x04BF;
  7400. t['chedescendercyrillic'] = 0x04B7;
  7401. t['chedieresiscyrillic'] = 0x04F5;
  7402. t['cheharmenian'] = 0x0573;
  7403. t['chekhakassiancyrillic'] = 0x04CC;
  7404. t['cheverticalstrokecyrillic'] = 0x04B9;
  7405. t['chi'] = 0x03C7;
  7406. t['chieuchacirclekorean'] = 0x3277;
  7407. t['chieuchaparenkorean'] = 0x3217;
  7408. t['chieuchcirclekorean'] = 0x3269;
  7409. t['chieuchkorean'] = 0x314A;
  7410. t['chieuchparenkorean'] = 0x3209;
  7411. t['chochangthai'] = 0x0E0A;
  7412. t['chochanthai'] = 0x0E08;
  7413. t['chochingthai'] = 0x0E09;
  7414. t['chochoethai'] = 0x0E0C;
  7415. t['chook'] = 0x0188;
  7416. t['cieucacirclekorean'] = 0x3276;
  7417. t['cieucaparenkorean'] = 0x3216;
  7418. t['cieuccirclekorean'] = 0x3268;
  7419. t['cieuckorean'] = 0x3148;
  7420. t['cieucparenkorean'] = 0x3208;
  7421. t['cieucuparenkorean'] = 0x321C;
  7422. t['circle'] = 0x25CB;
  7423. t['circlecopyrt'] = 0x00A9; // Glyph is missing from Adobe's original list.
  7424. t['circlemultiply'] = 0x2297;
  7425. t['circleot'] = 0x2299;
  7426. t['circleplus'] = 0x2295;
  7427. t['circlepostalmark'] = 0x3036;
  7428. t['circlewithlefthalfblack'] = 0x25D0;
  7429. t['circlewithrighthalfblack'] = 0x25D1;
  7430. t['circumflex'] = 0x02C6;
  7431. t['circumflexbelowcmb'] = 0x032D;
  7432. t['circumflexcmb'] = 0x0302;
  7433. t['clear'] = 0x2327;
  7434. t['clickalveolar'] = 0x01C2;
  7435. t['clickdental'] = 0x01C0;
  7436. t['clicklateral'] = 0x01C1;
  7437. t['clickretroflex'] = 0x01C3;
  7438. t['club'] = 0x2663;
  7439. t['clubsuitblack'] = 0x2663;
  7440. t['clubsuitwhite'] = 0x2667;
  7441. t['cmcubedsquare'] = 0x33A4;
  7442. t['cmonospace'] = 0xFF43;
  7443. t['cmsquaredsquare'] = 0x33A0;
  7444. t['coarmenian'] = 0x0581;
  7445. t['colon'] = 0x003A;
  7446. t['colonmonetary'] = 0x20A1;
  7447. t['colonmonospace'] = 0xFF1A;
  7448. t['colonsign'] = 0x20A1;
  7449. t['colonsmall'] = 0xFE55;
  7450. t['colontriangularhalfmod'] = 0x02D1;
  7451. t['colontriangularmod'] = 0x02D0;
  7452. t['comma'] = 0x002C;
  7453. t['commaabovecmb'] = 0x0313;
  7454. t['commaaboverightcmb'] = 0x0315;
  7455. t['commaaccent'] = 0xF6C3;
  7456. t['commaarabic'] = 0x060C;
  7457. t['commaarmenian'] = 0x055D;
  7458. t['commainferior'] = 0xF6E1;
  7459. t['commamonospace'] = 0xFF0C;
  7460. t['commareversedabovecmb'] = 0x0314;
  7461. t['commareversedmod'] = 0x02BD;
  7462. t['commasmall'] = 0xFE50;
  7463. t['commasuperior'] = 0xF6E2;
  7464. t['commaturnedabovecmb'] = 0x0312;
  7465. t['commaturnedmod'] = 0x02BB;
  7466. t['compass'] = 0x263C;
  7467. t['congruent'] = 0x2245;
  7468. t['contourintegral'] = 0x222E;
  7469. t['control'] = 0x2303;
  7470. t['controlACK'] = 0x0006;
  7471. t['controlBEL'] = 0x0007;
  7472. t['controlBS'] = 0x0008;
  7473. t['controlCAN'] = 0x0018;
  7474. t['controlCR'] = 0x000D;
  7475. t['controlDC1'] = 0x0011;
  7476. t['controlDC2'] = 0x0012;
  7477. t['controlDC3'] = 0x0013;
  7478. t['controlDC4'] = 0x0014;
  7479. t['controlDEL'] = 0x007F;
  7480. t['controlDLE'] = 0x0010;
  7481. t['controlEM'] = 0x0019;
  7482. t['controlENQ'] = 0x0005;
  7483. t['controlEOT'] = 0x0004;
  7484. t['controlESC'] = 0x001B;
  7485. t['controlETB'] = 0x0017;
  7486. t['controlETX'] = 0x0003;
  7487. t['controlFF'] = 0x000C;
  7488. t['controlFS'] = 0x001C;
  7489. t['controlGS'] = 0x001D;
  7490. t['controlHT'] = 0x0009;
  7491. t['controlLF'] = 0x000A;
  7492. t['controlNAK'] = 0x0015;
  7493. t['controlRS'] = 0x001E;
  7494. t['controlSI'] = 0x000F;
  7495. t['controlSO'] = 0x000E;
  7496. t['controlSOT'] = 0x0002;
  7497. t['controlSTX'] = 0x0001;
  7498. t['controlSUB'] = 0x001A;
  7499. t['controlSYN'] = 0x0016;
  7500. t['controlUS'] = 0x001F;
  7501. t['controlVT'] = 0x000B;
  7502. t['copyright'] = 0x00A9;
  7503. t['copyrightsans'] = 0xF8E9;
  7504. t['copyrightserif'] = 0xF6D9;
  7505. t['cornerbracketleft'] = 0x300C;
  7506. t['cornerbracketlefthalfwidth'] = 0xFF62;
  7507. t['cornerbracketleftvertical'] = 0xFE41;
  7508. t['cornerbracketright'] = 0x300D;
  7509. t['cornerbracketrighthalfwidth'] = 0xFF63;
  7510. t['cornerbracketrightvertical'] = 0xFE42;
  7511. t['corporationsquare'] = 0x337F;
  7512. t['cosquare'] = 0x33C7;
  7513. t['coverkgsquare'] = 0x33C6;
  7514. t['cparen'] = 0x249E;
  7515. t['cruzeiro'] = 0x20A2;
  7516. t['cstretched'] = 0x0297;
  7517. t['curlyand'] = 0x22CF;
  7518. t['curlyor'] = 0x22CE;
  7519. t['currency'] = 0x00A4;
  7520. t['cyrBreve'] = 0xF6D1;
  7521. t['cyrFlex'] = 0xF6D2;
  7522. t['cyrbreve'] = 0xF6D4;
  7523. t['cyrflex'] = 0xF6D5;
  7524. t['d'] = 0x0064;
  7525. t['daarmenian'] = 0x0564;
  7526. t['dabengali'] = 0x09A6;
  7527. t['dadarabic'] = 0x0636;
  7528. t['dadeva'] = 0x0926;
  7529. t['dadfinalarabic'] = 0xFEBE;
  7530. t['dadinitialarabic'] = 0xFEBF;
  7531. t['dadmedialarabic'] = 0xFEC0;
  7532. t['dagesh'] = 0x05BC;
  7533. t['dageshhebrew'] = 0x05BC;
  7534. t['dagger'] = 0x2020;
  7535. t['daggerdbl'] = 0x2021;
  7536. t['dagujarati'] = 0x0AA6;
  7537. t['dagurmukhi'] = 0x0A26;
  7538. t['dahiragana'] = 0x3060;
  7539. t['dakatakana'] = 0x30C0;
  7540. t['dalarabic'] = 0x062F;
  7541. t['dalet'] = 0x05D3;
  7542. t['daletdagesh'] = 0xFB33;
  7543. t['daletdageshhebrew'] = 0xFB33;
  7544. t['dalethebrew'] = 0x05D3;
  7545. t['dalfinalarabic'] = 0xFEAA;
  7546. t['dammaarabic'] = 0x064F;
  7547. t['dammalowarabic'] = 0x064F;
  7548. t['dammatanaltonearabic'] = 0x064C;
  7549. t['dammatanarabic'] = 0x064C;
  7550. t['danda'] = 0x0964;
  7551. t['dargahebrew'] = 0x05A7;
  7552. t['dargalefthebrew'] = 0x05A7;
  7553. t['dasiapneumatacyrilliccmb'] = 0x0485;
  7554. t['dblGrave'] = 0xF6D3;
  7555. t['dblanglebracketleft'] = 0x300A;
  7556. t['dblanglebracketleftvertical'] = 0xFE3D;
  7557. t['dblanglebracketright'] = 0x300B;
  7558. t['dblanglebracketrightvertical'] = 0xFE3E;
  7559. t['dblarchinvertedbelowcmb'] = 0x032B;
  7560. t['dblarrowleft'] = 0x21D4;
  7561. t['dblarrowright'] = 0x21D2;
  7562. t['dbldanda'] = 0x0965;
  7563. t['dblgrave'] = 0xF6D6;
  7564. t['dblgravecmb'] = 0x030F;
  7565. t['dblintegral'] = 0x222C;
  7566. t['dbllowline'] = 0x2017;
  7567. t['dbllowlinecmb'] = 0x0333;
  7568. t['dbloverlinecmb'] = 0x033F;
  7569. t['dblprimemod'] = 0x02BA;
  7570. t['dblverticalbar'] = 0x2016;
  7571. t['dblverticallineabovecmb'] = 0x030E;
  7572. t['dbopomofo'] = 0x3109;
  7573. t['dbsquare'] = 0x33C8;
  7574. t['dcaron'] = 0x010F;
  7575. t['dcedilla'] = 0x1E11;
  7576. t['dcircle'] = 0x24D3;
  7577. t['dcircumflexbelow'] = 0x1E13;
  7578. t['dcroat'] = 0x0111;
  7579. t['ddabengali'] = 0x09A1;
  7580. t['ddadeva'] = 0x0921;
  7581. t['ddagujarati'] = 0x0AA1;
  7582. t['ddagurmukhi'] = 0x0A21;
  7583. t['ddalarabic'] = 0x0688;
  7584. t['ddalfinalarabic'] = 0xFB89;
  7585. t['dddhadeva'] = 0x095C;
  7586. t['ddhabengali'] = 0x09A2;
  7587. t['ddhadeva'] = 0x0922;
  7588. t['ddhagujarati'] = 0x0AA2;
  7589. t['ddhagurmukhi'] = 0x0A22;
  7590. t['ddotaccent'] = 0x1E0B;
  7591. t['ddotbelow'] = 0x1E0D;
  7592. t['decimalseparatorarabic'] = 0x066B;
  7593. t['decimalseparatorpersian'] = 0x066B;
  7594. t['decyrillic'] = 0x0434;
  7595. t['degree'] = 0x00B0;
  7596. t['dehihebrew'] = 0x05AD;
  7597. t['dehiragana'] = 0x3067;
  7598. t['deicoptic'] = 0x03EF;
  7599. t['dekatakana'] = 0x30C7;
  7600. t['deleteleft'] = 0x232B;
  7601. t['deleteright'] = 0x2326;
  7602. t['delta'] = 0x03B4;
  7603. t['deltaturned'] = 0x018D;
  7604. t['denominatorminusonenumeratorbengali'] = 0x09F8;
  7605. t['dezh'] = 0x02A4;
  7606. t['dhabengali'] = 0x09A7;
  7607. t['dhadeva'] = 0x0927;
  7608. t['dhagujarati'] = 0x0AA7;
  7609. t['dhagurmukhi'] = 0x0A27;
  7610. t['dhook'] = 0x0257;
  7611. t['dialytikatonos'] = 0x0385;
  7612. t['dialytikatonoscmb'] = 0x0344;
  7613. t['diamond'] = 0x2666;
  7614. t['diamondsuitwhite'] = 0x2662;
  7615. t['dieresis'] = 0x00A8;
  7616. t['dieresisacute'] = 0xF6D7;
  7617. t['dieresisbelowcmb'] = 0x0324;
  7618. t['dieresiscmb'] = 0x0308;
  7619. t['dieresisgrave'] = 0xF6D8;
  7620. t['dieresistonos'] = 0x0385;
  7621. t['dihiragana'] = 0x3062;
  7622. t['dikatakana'] = 0x30C2;
  7623. t['dittomark'] = 0x3003;
  7624. t['divide'] = 0x00F7;
  7625. t['divides'] = 0x2223;
  7626. t['divisionslash'] = 0x2215;
  7627. t['djecyrillic'] = 0x0452;
  7628. t['dkshade'] = 0x2593;
  7629. t['dlinebelow'] = 0x1E0F;
  7630. t['dlsquare'] = 0x3397;
  7631. t['dmacron'] = 0x0111;
  7632. t['dmonospace'] = 0xFF44;
  7633. t['dnblock'] = 0x2584;
  7634. t['dochadathai'] = 0x0E0E;
  7635. t['dodekthai'] = 0x0E14;
  7636. t['dohiragana'] = 0x3069;
  7637. t['dokatakana'] = 0x30C9;
  7638. t['dollar'] = 0x0024;
  7639. t['dollarinferior'] = 0xF6E3;
  7640. t['dollarmonospace'] = 0xFF04;
  7641. t['dollaroldstyle'] = 0xF724;
  7642. t['dollarsmall'] = 0xFE69;
  7643. t['dollarsuperior'] = 0xF6E4;
  7644. t['dong'] = 0x20AB;
  7645. t['dorusquare'] = 0x3326;
  7646. t['dotaccent'] = 0x02D9;
  7647. t['dotaccentcmb'] = 0x0307;
  7648. t['dotbelowcmb'] = 0x0323;
  7649. t['dotbelowcomb'] = 0x0323;
  7650. t['dotkatakana'] = 0x30FB;
  7651. t['dotlessi'] = 0x0131;
  7652. t['dotlessj'] = 0xF6BE;
  7653. t['dotlessjstrokehook'] = 0x0284;
  7654. t['dotmath'] = 0x22C5;
  7655. t['dottedcircle'] = 0x25CC;
  7656. t['doubleyodpatah'] = 0xFB1F;
  7657. t['doubleyodpatahhebrew'] = 0xFB1F;
  7658. t['downtackbelowcmb'] = 0x031E;
  7659. t['downtackmod'] = 0x02D5;
  7660. t['dparen'] = 0x249F;
  7661. t['dsuperior'] = 0xF6EB;
  7662. t['dtail'] = 0x0256;
  7663. t['dtopbar'] = 0x018C;
  7664. t['duhiragana'] = 0x3065;
  7665. t['dukatakana'] = 0x30C5;
  7666. t['dz'] = 0x01F3;
  7667. t['dzaltone'] = 0x02A3;
  7668. t['dzcaron'] = 0x01C6;
  7669. t['dzcurl'] = 0x02A5;
  7670. t['dzeabkhasiancyrillic'] = 0x04E1;
  7671. t['dzecyrillic'] = 0x0455;
  7672. t['dzhecyrillic'] = 0x045F;
  7673. t['e'] = 0x0065;
  7674. t['eacute'] = 0x00E9;
  7675. t['earth'] = 0x2641;
  7676. t['ebengali'] = 0x098F;
  7677. t['ebopomofo'] = 0x311C;
  7678. t['ebreve'] = 0x0115;
  7679. t['ecandradeva'] = 0x090D;
  7680. t['ecandragujarati'] = 0x0A8D;
  7681. t['ecandravowelsigndeva'] = 0x0945;
  7682. t['ecandravowelsigngujarati'] = 0x0AC5;
  7683. t['ecaron'] = 0x011B;
  7684. t['ecedillabreve'] = 0x1E1D;
  7685. t['echarmenian'] = 0x0565;
  7686. t['echyiwnarmenian'] = 0x0587;
  7687. t['ecircle'] = 0x24D4;
  7688. t['ecircumflex'] = 0x00EA;
  7689. t['ecircumflexacute'] = 0x1EBF;
  7690. t['ecircumflexbelow'] = 0x1E19;
  7691. t['ecircumflexdotbelow'] = 0x1EC7;
  7692. t['ecircumflexgrave'] = 0x1EC1;
  7693. t['ecircumflexhookabove'] = 0x1EC3;
  7694. t['ecircumflextilde'] = 0x1EC5;
  7695. t['ecyrillic'] = 0x0454;
  7696. t['edblgrave'] = 0x0205;
  7697. t['edeva'] = 0x090F;
  7698. t['edieresis'] = 0x00EB;
  7699. t['edot'] = 0x0117;
  7700. t['edotaccent'] = 0x0117;
  7701. t['edotbelow'] = 0x1EB9;
  7702. t['eegurmukhi'] = 0x0A0F;
  7703. t['eematragurmukhi'] = 0x0A47;
  7704. t['efcyrillic'] = 0x0444;
  7705. t['egrave'] = 0x00E8;
  7706. t['egujarati'] = 0x0A8F;
  7707. t['eharmenian'] = 0x0567;
  7708. t['ehbopomofo'] = 0x311D;
  7709. t['ehiragana'] = 0x3048;
  7710. t['ehookabove'] = 0x1EBB;
  7711. t['eibopomofo'] = 0x311F;
  7712. t['eight'] = 0x0038;
  7713. t['eightarabic'] = 0x0668;
  7714. t['eightbengali'] = 0x09EE;
  7715. t['eightcircle'] = 0x2467;
  7716. t['eightcircleinversesansserif'] = 0x2791;
  7717. t['eightdeva'] = 0x096E;
  7718. t['eighteencircle'] = 0x2471;
  7719. t['eighteenparen'] = 0x2485;
  7720. t['eighteenperiod'] = 0x2499;
  7721. t['eightgujarati'] = 0x0AEE;
  7722. t['eightgurmukhi'] = 0x0A6E;
  7723. t['eighthackarabic'] = 0x0668;
  7724. t['eighthangzhou'] = 0x3028;
  7725. t['eighthnotebeamed'] = 0x266B;
  7726. t['eightideographicparen'] = 0x3227;
  7727. t['eightinferior'] = 0x2088;
  7728. t['eightmonospace'] = 0xFF18;
  7729. t['eightoldstyle'] = 0xF738;
  7730. t['eightparen'] = 0x247B;
  7731. t['eightperiod'] = 0x248F;
  7732. t['eightpersian'] = 0x06F8;
  7733. t['eightroman'] = 0x2177;
  7734. t['eightsuperior'] = 0x2078;
  7735. t['eightthai'] = 0x0E58;
  7736. t['einvertedbreve'] = 0x0207;
  7737. t['eiotifiedcyrillic'] = 0x0465;
  7738. t['ekatakana'] = 0x30A8;
  7739. t['ekatakanahalfwidth'] = 0xFF74;
  7740. t['ekonkargurmukhi'] = 0x0A74;
  7741. t['ekorean'] = 0x3154;
  7742. t['elcyrillic'] = 0x043B;
  7743. t['element'] = 0x2208;
  7744. t['elevencircle'] = 0x246A;
  7745. t['elevenparen'] = 0x247E;
  7746. t['elevenperiod'] = 0x2492;
  7747. t['elevenroman'] = 0x217A;
  7748. t['ellipsis'] = 0x2026;
  7749. t['ellipsisvertical'] = 0x22EE;
  7750. t['emacron'] = 0x0113;
  7751. t['emacronacute'] = 0x1E17;
  7752. t['emacrongrave'] = 0x1E15;
  7753. t['emcyrillic'] = 0x043C;
  7754. t['emdash'] = 0x2014;
  7755. t['emdashvertical'] = 0xFE31;
  7756. t['emonospace'] = 0xFF45;
  7757. t['emphasismarkarmenian'] = 0x055B;
  7758. t['emptyset'] = 0x2205;
  7759. t['enbopomofo'] = 0x3123;
  7760. t['encyrillic'] = 0x043D;
  7761. t['endash'] = 0x2013;
  7762. t['endashvertical'] = 0xFE32;
  7763. t['endescendercyrillic'] = 0x04A3;
  7764. t['eng'] = 0x014B;
  7765. t['engbopomofo'] = 0x3125;
  7766. t['enghecyrillic'] = 0x04A5;
  7767. t['enhookcyrillic'] = 0x04C8;
  7768. t['enspace'] = 0x2002;
  7769. t['eogonek'] = 0x0119;
  7770. t['eokorean'] = 0x3153;
  7771. t['eopen'] = 0x025B;
  7772. t['eopenclosed'] = 0x029A;
  7773. t['eopenreversed'] = 0x025C;
  7774. t['eopenreversedclosed'] = 0x025E;
  7775. t['eopenreversedhook'] = 0x025D;
  7776. t['eparen'] = 0x24A0;
  7777. t['epsilon'] = 0x03B5;
  7778. t['epsilontonos'] = 0x03AD;
  7779. t['equal'] = 0x003D;
  7780. t['equalmonospace'] = 0xFF1D;
  7781. t['equalsmall'] = 0xFE66;
  7782. t['equalsuperior'] = 0x207C;
  7783. t['equivalence'] = 0x2261;
  7784. t['erbopomofo'] = 0x3126;
  7785. t['ercyrillic'] = 0x0440;
  7786. t['ereversed'] = 0x0258;
  7787. t['ereversedcyrillic'] = 0x044D;
  7788. t['escyrillic'] = 0x0441;
  7789. t['esdescendercyrillic'] = 0x04AB;
  7790. t['esh'] = 0x0283;
  7791. t['eshcurl'] = 0x0286;
  7792. t['eshortdeva'] = 0x090E;
  7793. t['eshortvowelsigndeva'] = 0x0946;
  7794. t['eshreversedloop'] = 0x01AA;
  7795. t['eshsquatreversed'] = 0x0285;
  7796. t['esmallhiragana'] = 0x3047;
  7797. t['esmallkatakana'] = 0x30A7;
  7798. t['esmallkatakanahalfwidth'] = 0xFF6A;
  7799. t['estimated'] = 0x212E;
  7800. t['esuperior'] = 0xF6EC;
  7801. t['eta'] = 0x03B7;
  7802. t['etarmenian'] = 0x0568;
  7803. t['etatonos'] = 0x03AE;
  7804. t['eth'] = 0x00F0;
  7805. t['etilde'] = 0x1EBD;
  7806. t['etildebelow'] = 0x1E1B;
  7807. t['etnahtafoukhhebrew'] = 0x0591;
  7808. t['etnahtafoukhlefthebrew'] = 0x0591;
  7809. t['etnahtahebrew'] = 0x0591;
  7810. t['etnahtalefthebrew'] = 0x0591;
  7811. t['eturned'] = 0x01DD;
  7812. t['eukorean'] = 0x3161;
  7813. t['euro'] = 0x20AC;
  7814. t['evowelsignbengali'] = 0x09C7;
  7815. t['evowelsigndeva'] = 0x0947;
  7816. t['evowelsigngujarati'] = 0x0AC7;
  7817. t['exclam'] = 0x0021;
  7818. t['exclamarmenian'] = 0x055C;
  7819. t['exclamdbl'] = 0x203C;
  7820. t['exclamdown'] = 0x00A1;
  7821. t['exclamdownsmall'] = 0xF7A1;
  7822. t['exclammonospace'] = 0xFF01;
  7823. t['exclamsmall'] = 0xF721;
  7824. t['existential'] = 0x2203;
  7825. t['ezh'] = 0x0292;
  7826. t['ezhcaron'] = 0x01EF;
  7827. t['ezhcurl'] = 0x0293;
  7828. t['ezhreversed'] = 0x01B9;
  7829. t['ezhtail'] = 0x01BA;
  7830. t['f'] = 0x0066;
  7831. t['fadeva'] = 0x095E;
  7832. t['fagurmukhi'] = 0x0A5E;
  7833. t['fahrenheit'] = 0x2109;
  7834. t['fathaarabic'] = 0x064E;
  7835. t['fathalowarabic'] = 0x064E;
  7836. t['fathatanarabic'] = 0x064B;
  7837. t['fbopomofo'] = 0x3108;
  7838. t['fcircle'] = 0x24D5;
  7839. t['fdotaccent'] = 0x1E1F;
  7840. t['feharabic'] = 0x0641;
  7841. t['feharmenian'] = 0x0586;
  7842. t['fehfinalarabic'] = 0xFED2;
  7843. t['fehinitialarabic'] = 0xFED3;
  7844. t['fehmedialarabic'] = 0xFED4;
  7845. t['feicoptic'] = 0x03E5;
  7846. t['female'] = 0x2640;
  7847. t['ff'] = 0xFB00;
  7848. t['ffi'] = 0xFB03;
  7849. t['ffl'] = 0xFB04;
  7850. t['fi'] = 0xFB01;
  7851. t['fifteencircle'] = 0x246E;
  7852. t['fifteenparen'] = 0x2482;
  7853. t['fifteenperiod'] = 0x2496;
  7854. t['figuredash'] = 0x2012;
  7855. t['filledbox'] = 0x25A0;
  7856. t['filledrect'] = 0x25AC;
  7857. t['finalkaf'] = 0x05DA;
  7858. t['finalkafdagesh'] = 0xFB3A;
  7859. t['finalkafdageshhebrew'] = 0xFB3A;
  7860. t['finalkafhebrew'] = 0x05DA;
  7861. t['finalmem'] = 0x05DD;
  7862. t['finalmemhebrew'] = 0x05DD;
  7863. t['finalnun'] = 0x05DF;
  7864. t['finalnunhebrew'] = 0x05DF;
  7865. t['finalpe'] = 0x05E3;
  7866. t['finalpehebrew'] = 0x05E3;
  7867. t['finaltsadi'] = 0x05E5;
  7868. t['finaltsadihebrew'] = 0x05E5;
  7869. t['firsttonechinese'] = 0x02C9;
  7870. t['fisheye'] = 0x25C9;
  7871. t['fitacyrillic'] = 0x0473;
  7872. t['five'] = 0x0035;
  7873. t['fivearabic'] = 0x0665;
  7874. t['fivebengali'] = 0x09EB;
  7875. t['fivecircle'] = 0x2464;
  7876. t['fivecircleinversesansserif'] = 0x278E;
  7877. t['fivedeva'] = 0x096B;
  7878. t['fiveeighths'] = 0x215D;
  7879. t['fivegujarati'] = 0x0AEB;
  7880. t['fivegurmukhi'] = 0x0A6B;
  7881. t['fivehackarabic'] = 0x0665;
  7882. t['fivehangzhou'] = 0x3025;
  7883. t['fiveideographicparen'] = 0x3224;
  7884. t['fiveinferior'] = 0x2085;
  7885. t['fivemonospace'] = 0xFF15;
  7886. t['fiveoldstyle'] = 0xF735;
  7887. t['fiveparen'] = 0x2478;
  7888. t['fiveperiod'] = 0x248C;
  7889. t['fivepersian'] = 0x06F5;
  7890. t['fiveroman'] = 0x2174;
  7891. t['fivesuperior'] = 0x2075;
  7892. t['fivethai'] = 0x0E55;
  7893. t['fl'] = 0xFB02;
  7894. t['florin'] = 0x0192;
  7895. t['fmonospace'] = 0xFF46;
  7896. t['fmsquare'] = 0x3399;
  7897. t['fofanthai'] = 0x0E1F;
  7898. t['fofathai'] = 0x0E1D;
  7899. t['fongmanthai'] = 0x0E4F;
  7900. t['forall'] = 0x2200;
  7901. t['four'] = 0x0034;
  7902. t['fourarabic'] = 0x0664;
  7903. t['fourbengali'] = 0x09EA;
  7904. t['fourcircle'] = 0x2463;
  7905. t['fourcircleinversesansserif'] = 0x278D;
  7906. t['fourdeva'] = 0x096A;
  7907. t['fourgujarati'] = 0x0AEA;
  7908. t['fourgurmukhi'] = 0x0A6A;
  7909. t['fourhackarabic'] = 0x0664;
  7910. t['fourhangzhou'] = 0x3024;
  7911. t['fourideographicparen'] = 0x3223;
  7912. t['fourinferior'] = 0x2084;
  7913. t['fourmonospace'] = 0xFF14;
  7914. t['fournumeratorbengali'] = 0x09F7;
  7915. t['fouroldstyle'] = 0xF734;
  7916. t['fourparen'] = 0x2477;
  7917. t['fourperiod'] = 0x248B;
  7918. t['fourpersian'] = 0x06F4;
  7919. t['fourroman'] = 0x2173;
  7920. t['foursuperior'] = 0x2074;
  7921. t['fourteencircle'] = 0x246D;
  7922. t['fourteenparen'] = 0x2481;
  7923. t['fourteenperiod'] = 0x2495;
  7924. t['fourthai'] = 0x0E54;
  7925. t['fourthtonechinese'] = 0x02CB;
  7926. t['fparen'] = 0x24A1;
  7927. t['fraction'] = 0x2044;
  7928. t['franc'] = 0x20A3;
  7929. t['g'] = 0x0067;
  7930. t['gabengali'] = 0x0997;
  7931. t['gacute'] = 0x01F5;
  7932. t['gadeva'] = 0x0917;
  7933. t['gafarabic'] = 0x06AF;
  7934. t['gaffinalarabic'] = 0xFB93;
  7935. t['gafinitialarabic'] = 0xFB94;
  7936. t['gafmedialarabic'] = 0xFB95;
  7937. t['gagujarati'] = 0x0A97;
  7938. t['gagurmukhi'] = 0x0A17;
  7939. t['gahiragana'] = 0x304C;
  7940. t['gakatakana'] = 0x30AC;
  7941. t['gamma'] = 0x03B3;
  7942. t['gammalatinsmall'] = 0x0263;
  7943. t['gammasuperior'] = 0x02E0;
  7944. t['gangiacoptic'] = 0x03EB;
  7945. t['gbopomofo'] = 0x310D;
  7946. t['gbreve'] = 0x011F;
  7947. t['gcaron'] = 0x01E7;
  7948. t['gcedilla'] = 0x0123;
  7949. t['gcircle'] = 0x24D6;
  7950. t['gcircumflex'] = 0x011D;
  7951. t['gcommaaccent'] = 0x0123;
  7952. t['gdot'] = 0x0121;
  7953. t['gdotaccent'] = 0x0121;
  7954. t['gecyrillic'] = 0x0433;
  7955. t['gehiragana'] = 0x3052;
  7956. t['gekatakana'] = 0x30B2;
  7957. t['geometricallyequal'] = 0x2251;
  7958. t['gereshaccenthebrew'] = 0x059C;
  7959. t['gereshhebrew'] = 0x05F3;
  7960. t['gereshmuqdamhebrew'] = 0x059D;
  7961. t['germandbls'] = 0x00DF;
  7962. t['gershayimaccenthebrew'] = 0x059E;
  7963. t['gershayimhebrew'] = 0x05F4;
  7964. t['getamark'] = 0x3013;
  7965. t['ghabengali'] = 0x0998;
  7966. t['ghadarmenian'] = 0x0572;
  7967. t['ghadeva'] = 0x0918;
  7968. t['ghagujarati'] = 0x0A98;
  7969. t['ghagurmukhi'] = 0x0A18;
  7970. t['ghainarabic'] = 0x063A;
  7971. t['ghainfinalarabic'] = 0xFECE;
  7972. t['ghaininitialarabic'] = 0xFECF;
  7973. t['ghainmedialarabic'] = 0xFED0;
  7974. t['ghemiddlehookcyrillic'] = 0x0495;
  7975. t['ghestrokecyrillic'] = 0x0493;
  7976. t['gheupturncyrillic'] = 0x0491;
  7977. t['ghhadeva'] = 0x095A;
  7978. t['ghhagurmukhi'] = 0x0A5A;
  7979. t['ghook'] = 0x0260;
  7980. t['ghzsquare'] = 0x3393;
  7981. t['gihiragana'] = 0x304E;
  7982. t['gikatakana'] = 0x30AE;
  7983. t['gimarmenian'] = 0x0563;
  7984. t['gimel'] = 0x05D2;
  7985. t['gimeldagesh'] = 0xFB32;
  7986. t['gimeldageshhebrew'] = 0xFB32;
  7987. t['gimelhebrew'] = 0x05D2;
  7988. t['gjecyrillic'] = 0x0453;
  7989. t['glottalinvertedstroke'] = 0x01BE;
  7990. t['glottalstop'] = 0x0294;
  7991. t['glottalstopinverted'] = 0x0296;
  7992. t['glottalstopmod'] = 0x02C0;
  7993. t['glottalstopreversed'] = 0x0295;
  7994. t['glottalstopreversedmod'] = 0x02C1;
  7995. t['glottalstopreversedsuperior'] = 0x02E4;
  7996. t['glottalstopstroke'] = 0x02A1;
  7997. t['glottalstopstrokereversed'] = 0x02A2;
  7998. t['gmacron'] = 0x1E21;
  7999. t['gmonospace'] = 0xFF47;
  8000. t['gohiragana'] = 0x3054;
  8001. t['gokatakana'] = 0x30B4;
  8002. t['gparen'] = 0x24A2;
  8003. t['gpasquare'] = 0x33AC;
  8004. t['gradient'] = 0x2207;
  8005. t['grave'] = 0x0060;
  8006. t['gravebelowcmb'] = 0x0316;
  8007. t['gravecmb'] = 0x0300;
  8008. t['gravecomb'] = 0x0300;
  8009. t['gravedeva'] = 0x0953;
  8010. t['gravelowmod'] = 0x02CE;
  8011. t['gravemonospace'] = 0xFF40;
  8012. t['gravetonecmb'] = 0x0340;
  8013. t['greater'] = 0x003E;
  8014. t['greaterequal'] = 0x2265;
  8015. t['greaterequalorless'] = 0x22DB;
  8016. t['greatermonospace'] = 0xFF1E;
  8017. t['greaterorequivalent'] = 0x2273;
  8018. t['greaterorless'] = 0x2277;
  8019. t['greateroverequal'] = 0x2267;
  8020. t['greatersmall'] = 0xFE65;
  8021. t['gscript'] = 0x0261;
  8022. t['gstroke'] = 0x01E5;
  8023. t['guhiragana'] = 0x3050;
  8024. t['guillemotleft'] = 0x00AB;
  8025. t['guillemotright'] = 0x00BB;
  8026. t['guilsinglleft'] = 0x2039;
  8027. t['guilsinglright'] = 0x203A;
  8028. t['gukatakana'] = 0x30B0;
  8029. t['guramusquare'] = 0x3318;
  8030. t['gysquare'] = 0x33C9;
  8031. t['h'] = 0x0068;
  8032. t['haabkhasiancyrillic'] = 0x04A9;
  8033. t['haaltonearabic'] = 0x06C1;
  8034. t['habengali'] = 0x09B9;
  8035. t['hadescendercyrillic'] = 0x04B3;
  8036. t['hadeva'] = 0x0939;
  8037. t['hagujarati'] = 0x0AB9;
  8038. t['hagurmukhi'] = 0x0A39;
  8039. t['haharabic'] = 0x062D;
  8040. t['hahfinalarabic'] = 0xFEA2;
  8041. t['hahinitialarabic'] = 0xFEA3;
  8042. t['hahiragana'] = 0x306F;
  8043. t['hahmedialarabic'] = 0xFEA4;
  8044. t['haitusquare'] = 0x332A;
  8045. t['hakatakana'] = 0x30CF;
  8046. t['hakatakanahalfwidth'] = 0xFF8A;
  8047. t['halantgurmukhi'] = 0x0A4D;
  8048. t['hamzaarabic'] = 0x0621;
  8049. t['hamzalowarabic'] = 0x0621;
  8050. t['hangulfiller'] = 0x3164;
  8051. t['hardsigncyrillic'] = 0x044A;
  8052. t['harpoonleftbarbup'] = 0x21BC;
  8053. t['harpoonrightbarbup'] = 0x21C0;
  8054. t['hasquare'] = 0x33CA;
  8055. t['hatafpatah'] = 0x05B2;
  8056. t['hatafpatah16'] = 0x05B2;
  8057. t['hatafpatah23'] = 0x05B2;
  8058. t['hatafpatah2f'] = 0x05B2;
  8059. t['hatafpatahhebrew'] = 0x05B2;
  8060. t['hatafpatahnarrowhebrew'] = 0x05B2;
  8061. t['hatafpatahquarterhebrew'] = 0x05B2;
  8062. t['hatafpatahwidehebrew'] = 0x05B2;
  8063. t['hatafqamats'] = 0x05B3;
  8064. t['hatafqamats1b'] = 0x05B3;
  8065. t['hatafqamats28'] = 0x05B3;
  8066. t['hatafqamats34'] = 0x05B3;
  8067. t['hatafqamatshebrew'] = 0x05B3;
  8068. t['hatafqamatsnarrowhebrew'] = 0x05B3;
  8069. t['hatafqamatsquarterhebrew'] = 0x05B3;
  8070. t['hatafqamatswidehebrew'] = 0x05B3;
  8071. t['hatafsegol'] = 0x05B1;
  8072. t['hatafsegol17'] = 0x05B1;
  8073. t['hatafsegol24'] = 0x05B1;
  8074. t['hatafsegol30'] = 0x05B1;
  8075. t['hatafsegolhebrew'] = 0x05B1;
  8076. t['hatafsegolnarrowhebrew'] = 0x05B1;
  8077. t['hatafsegolquarterhebrew'] = 0x05B1;
  8078. t['hatafsegolwidehebrew'] = 0x05B1;
  8079. t['hbar'] = 0x0127;
  8080. t['hbopomofo'] = 0x310F;
  8081. t['hbrevebelow'] = 0x1E2B;
  8082. t['hcedilla'] = 0x1E29;
  8083. t['hcircle'] = 0x24D7;
  8084. t['hcircumflex'] = 0x0125;
  8085. t['hdieresis'] = 0x1E27;
  8086. t['hdotaccent'] = 0x1E23;
  8087. t['hdotbelow'] = 0x1E25;
  8088. t['he'] = 0x05D4;
  8089. t['heart'] = 0x2665;
  8090. t['heartsuitblack'] = 0x2665;
  8091. t['heartsuitwhite'] = 0x2661;
  8092. t['hedagesh'] = 0xFB34;
  8093. t['hedageshhebrew'] = 0xFB34;
  8094. t['hehaltonearabic'] = 0x06C1;
  8095. t['heharabic'] = 0x0647;
  8096. t['hehebrew'] = 0x05D4;
  8097. t['hehfinalaltonearabic'] = 0xFBA7;
  8098. t['hehfinalalttwoarabic'] = 0xFEEA;
  8099. t['hehfinalarabic'] = 0xFEEA;
  8100. t['hehhamzaabovefinalarabic'] = 0xFBA5;
  8101. t['hehhamzaaboveisolatedarabic'] = 0xFBA4;
  8102. t['hehinitialaltonearabic'] = 0xFBA8;
  8103. t['hehinitialarabic'] = 0xFEEB;
  8104. t['hehiragana'] = 0x3078;
  8105. t['hehmedialaltonearabic'] = 0xFBA9;
  8106. t['hehmedialarabic'] = 0xFEEC;
  8107. t['heiseierasquare'] = 0x337B;
  8108. t['hekatakana'] = 0x30D8;
  8109. t['hekatakanahalfwidth'] = 0xFF8D;
  8110. t['hekutaarusquare'] = 0x3336;
  8111. t['henghook'] = 0x0267;
  8112. t['herutusquare'] = 0x3339;
  8113. t['het'] = 0x05D7;
  8114. t['hethebrew'] = 0x05D7;
  8115. t['hhook'] = 0x0266;
  8116. t['hhooksuperior'] = 0x02B1;
  8117. t['hieuhacirclekorean'] = 0x327B;
  8118. t['hieuhaparenkorean'] = 0x321B;
  8119. t['hieuhcirclekorean'] = 0x326D;
  8120. t['hieuhkorean'] = 0x314E;
  8121. t['hieuhparenkorean'] = 0x320D;
  8122. t['hihiragana'] = 0x3072;
  8123. t['hikatakana'] = 0x30D2;
  8124. t['hikatakanahalfwidth'] = 0xFF8B;
  8125. t['hiriq'] = 0x05B4;
  8126. t['hiriq14'] = 0x05B4;
  8127. t['hiriq21'] = 0x05B4;
  8128. t['hiriq2d'] = 0x05B4;
  8129. t['hiriqhebrew'] = 0x05B4;
  8130. t['hiriqnarrowhebrew'] = 0x05B4;
  8131. t['hiriqquarterhebrew'] = 0x05B4;
  8132. t['hiriqwidehebrew'] = 0x05B4;
  8133. t['hlinebelow'] = 0x1E96;
  8134. t['hmonospace'] = 0xFF48;
  8135. t['hoarmenian'] = 0x0570;
  8136. t['hohipthai'] = 0x0E2B;
  8137. t['hohiragana'] = 0x307B;
  8138. t['hokatakana'] = 0x30DB;
  8139. t['hokatakanahalfwidth'] = 0xFF8E;
  8140. t['holam'] = 0x05B9;
  8141. t['holam19'] = 0x05B9;
  8142. t['holam26'] = 0x05B9;
  8143. t['holam32'] = 0x05B9;
  8144. t['holamhebrew'] = 0x05B9;
  8145. t['holamnarrowhebrew'] = 0x05B9;
  8146. t['holamquarterhebrew'] = 0x05B9;
  8147. t['holamwidehebrew'] = 0x05B9;
  8148. t['honokhukthai'] = 0x0E2E;
  8149. t['hookabovecomb'] = 0x0309;
  8150. t['hookcmb'] = 0x0309;
  8151. t['hookpalatalizedbelowcmb'] = 0x0321;
  8152. t['hookretroflexbelowcmb'] = 0x0322;
  8153. t['hoonsquare'] = 0x3342;
  8154. t['horicoptic'] = 0x03E9;
  8155. t['horizontalbar'] = 0x2015;
  8156. t['horncmb'] = 0x031B;
  8157. t['hotsprings'] = 0x2668;
  8158. t['house'] = 0x2302;
  8159. t['hparen'] = 0x24A3;
  8160. t['hsuperior'] = 0x02B0;
  8161. t['hturned'] = 0x0265;
  8162. t['huhiragana'] = 0x3075;
  8163. t['huiitosquare'] = 0x3333;
  8164. t['hukatakana'] = 0x30D5;
  8165. t['hukatakanahalfwidth'] = 0xFF8C;
  8166. t['hungarumlaut'] = 0x02DD;
  8167. t['hungarumlautcmb'] = 0x030B;
  8168. t['hv'] = 0x0195;
  8169. t['hyphen'] = 0x002D;
  8170. t['hypheninferior'] = 0xF6E5;
  8171. t['hyphenmonospace'] = 0xFF0D;
  8172. t['hyphensmall'] = 0xFE63;
  8173. t['hyphensuperior'] = 0xF6E6;
  8174. t['hyphentwo'] = 0x2010;
  8175. t['i'] = 0x0069;
  8176. t['iacute'] = 0x00ED;
  8177. t['iacyrillic'] = 0x044F;
  8178. t['ibengali'] = 0x0987;
  8179. t['ibopomofo'] = 0x3127;
  8180. t['ibreve'] = 0x012D;
  8181. t['icaron'] = 0x01D0;
  8182. t['icircle'] = 0x24D8;
  8183. t['icircumflex'] = 0x00EE;
  8184. t['icyrillic'] = 0x0456;
  8185. t['idblgrave'] = 0x0209;
  8186. t['ideographearthcircle'] = 0x328F;
  8187. t['ideographfirecircle'] = 0x328B;
  8188. t['ideographicallianceparen'] = 0x323F;
  8189. t['ideographiccallparen'] = 0x323A;
  8190. t['ideographiccentrecircle'] = 0x32A5;
  8191. t['ideographicclose'] = 0x3006;
  8192. t['ideographiccomma'] = 0x3001;
  8193. t['ideographiccommaleft'] = 0xFF64;
  8194. t['ideographiccongratulationparen'] = 0x3237;
  8195. t['ideographiccorrectcircle'] = 0x32A3;
  8196. t['ideographicearthparen'] = 0x322F;
  8197. t['ideographicenterpriseparen'] = 0x323D;
  8198. t['ideographicexcellentcircle'] = 0x329D;
  8199. t['ideographicfestivalparen'] = 0x3240;
  8200. t['ideographicfinancialcircle'] = 0x3296;
  8201. t['ideographicfinancialparen'] = 0x3236;
  8202. t['ideographicfireparen'] = 0x322B;
  8203. t['ideographichaveparen'] = 0x3232;
  8204. t['ideographichighcircle'] = 0x32A4;
  8205. t['ideographiciterationmark'] = 0x3005;
  8206. t['ideographiclaborcircle'] = 0x3298;
  8207. t['ideographiclaborparen'] = 0x3238;
  8208. t['ideographicleftcircle'] = 0x32A7;
  8209. t['ideographiclowcircle'] = 0x32A6;
  8210. t['ideographicmedicinecircle'] = 0x32A9;
  8211. t['ideographicmetalparen'] = 0x322E;
  8212. t['ideographicmoonparen'] = 0x322A;
  8213. t['ideographicnameparen'] = 0x3234;
  8214. t['ideographicperiod'] = 0x3002;
  8215. t['ideographicprintcircle'] = 0x329E;
  8216. t['ideographicreachparen'] = 0x3243;
  8217. t['ideographicrepresentparen'] = 0x3239;
  8218. t['ideographicresourceparen'] = 0x323E;
  8219. t['ideographicrightcircle'] = 0x32A8;
  8220. t['ideographicsecretcircle'] = 0x3299;
  8221. t['ideographicselfparen'] = 0x3242;
  8222. t['ideographicsocietyparen'] = 0x3233;
  8223. t['ideographicspace'] = 0x3000;
  8224. t['ideographicspecialparen'] = 0x3235;
  8225. t['ideographicstockparen'] = 0x3231;
  8226. t['ideographicstudyparen'] = 0x323B;
  8227. t['ideographicsunparen'] = 0x3230;
  8228. t['ideographicsuperviseparen'] = 0x323C;
  8229. t['ideographicwaterparen'] = 0x322C;
  8230. t['ideographicwoodparen'] = 0x322D;
  8231. t['ideographiczero'] = 0x3007;
  8232. t['ideographmetalcircle'] = 0x328E;
  8233. t['ideographmooncircle'] = 0x328A;
  8234. t['ideographnamecircle'] = 0x3294;
  8235. t['ideographsuncircle'] = 0x3290;
  8236. t['ideographwatercircle'] = 0x328C;
  8237. t['ideographwoodcircle'] = 0x328D;
  8238. t['ideva'] = 0x0907;
  8239. t['idieresis'] = 0x00EF;
  8240. t['idieresisacute'] = 0x1E2F;
  8241. t['idieresiscyrillic'] = 0x04E5;
  8242. t['idotbelow'] = 0x1ECB;
  8243. t['iebrevecyrillic'] = 0x04D7;
  8244. t['iecyrillic'] = 0x0435;
  8245. t['ieungacirclekorean'] = 0x3275;
  8246. t['ieungaparenkorean'] = 0x3215;
  8247. t['ieungcirclekorean'] = 0x3267;
  8248. t['ieungkorean'] = 0x3147;
  8249. t['ieungparenkorean'] = 0x3207;
  8250. t['igrave'] = 0x00EC;
  8251. t['igujarati'] = 0x0A87;
  8252. t['igurmukhi'] = 0x0A07;
  8253. t['ihiragana'] = 0x3044;
  8254. t['ihookabove'] = 0x1EC9;
  8255. t['iibengali'] = 0x0988;
  8256. t['iicyrillic'] = 0x0438;
  8257. t['iideva'] = 0x0908;
  8258. t['iigujarati'] = 0x0A88;
  8259. t['iigurmukhi'] = 0x0A08;
  8260. t['iimatragurmukhi'] = 0x0A40;
  8261. t['iinvertedbreve'] = 0x020B;
  8262. t['iishortcyrillic'] = 0x0439;
  8263. t['iivowelsignbengali'] = 0x09C0;
  8264. t['iivowelsigndeva'] = 0x0940;
  8265. t['iivowelsigngujarati'] = 0x0AC0;
  8266. t['ij'] = 0x0133;
  8267. t['ikatakana'] = 0x30A4;
  8268. t['ikatakanahalfwidth'] = 0xFF72;
  8269. t['ikorean'] = 0x3163;
  8270. t['ilde'] = 0x02DC;
  8271. t['iluyhebrew'] = 0x05AC;
  8272. t['imacron'] = 0x012B;
  8273. t['imacroncyrillic'] = 0x04E3;
  8274. t['imageorapproximatelyequal'] = 0x2253;
  8275. t['imatragurmukhi'] = 0x0A3F;
  8276. t['imonospace'] = 0xFF49;
  8277. t['increment'] = 0x2206;
  8278. t['infinity'] = 0x221E;
  8279. t['iniarmenian'] = 0x056B;
  8280. t['integral'] = 0x222B;
  8281. t['integralbottom'] = 0x2321;
  8282. t['integralbt'] = 0x2321;
  8283. t['integralex'] = 0xF8F5;
  8284. t['integraltop'] = 0x2320;
  8285. t['integraltp'] = 0x2320;
  8286. t['intersection'] = 0x2229;
  8287. t['intisquare'] = 0x3305;
  8288. t['invbullet'] = 0x25D8;
  8289. t['invcircle'] = 0x25D9;
  8290. t['invsmileface'] = 0x263B;
  8291. t['iocyrillic'] = 0x0451;
  8292. t['iogonek'] = 0x012F;
  8293. t['iota'] = 0x03B9;
  8294. t['iotadieresis'] = 0x03CA;
  8295. t['iotadieresistonos'] = 0x0390;
  8296. t['iotalatin'] = 0x0269;
  8297. t['iotatonos'] = 0x03AF;
  8298. t['iparen'] = 0x24A4;
  8299. t['irigurmukhi'] = 0x0A72;
  8300. t['ismallhiragana'] = 0x3043;
  8301. t['ismallkatakana'] = 0x30A3;
  8302. t['ismallkatakanahalfwidth'] = 0xFF68;
  8303. t['issharbengali'] = 0x09FA;
  8304. t['istroke'] = 0x0268;
  8305. t['isuperior'] = 0xF6ED;
  8306. t['iterationhiragana'] = 0x309D;
  8307. t['iterationkatakana'] = 0x30FD;
  8308. t['itilde'] = 0x0129;
  8309. t['itildebelow'] = 0x1E2D;
  8310. t['iubopomofo'] = 0x3129;
  8311. t['iucyrillic'] = 0x044E;
  8312. t['ivowelsignbengali'] = 0x09BF;
  8313. t['ivowelsigndeva'] = 0x093F;
  8314. t['ivowelsigngujarati'] = 0x0ABF;
  8315. t['izhitsacyrillic'] = 0x0475;
  8316. t['izhitsadblgravecyrillic'] = 0x0477;
  8317. t['j'] = 0x006A;
  8318. t['jaarmenian'] = 0x0571;
  8319. t['jabengali'] = 0x099C;
  8320. t['jadeva'] = 0x091C;
  8321. t['jagujarati'] = 0x0A9C;
  8322. t['jagurmukhi'] = 0x0A1C;
  8323. t['jbopomofo'] = 0x3110;
  8324. t['jcaron'] = 0x01F0;
  8325. t['jcircle'] = 0x24D9;
  8326. t['jcircumflex'] = 0x0135;
  8327. t['jcrossedtail'] = 0x029D;
  8328. t['jdotlessstroke'] = 0x025F;
  8329. t['jecyrillic'] = 0x0458;
  8330. t['jeemarabic'] = 0x062C;
  8331. t['jeemfinalarabic'] = 0xFE9E;
  8332. t['jeeminitialarabic'] = 0xFE9F;
  8333. t['jeemmedialarabic'] = 0xFEA0;
  8334. t['jeharabic'] = 0x0698;
  8335. t['jehfinalarabic'] = 0xFB8B;
  8336. t['jhabengali'] = 0x099D;
  8337. t['jhadeva'] = 0x091D;
  8338. t['jhagujarati'] = 0x0A9D;
  8339. t['jhagurmukhi'] = 0x0A1D;
  8340. t['jheharmenian'] = 0x057B;
  8341. t['jis'] = 0x3004;
  8342. t['jmonospace'] = 0xFF4A;
  8343. t['jparen'] = 0x24A5;
  8344. t['jsuperior'] = 0x02B2;
  8345. t['k'] = 0x006B;
  8346. t['kabashkircyrillic'] = 0x04A1;
  8347. t['kabengali'] = 0x0995;
  8348. t['kacute'] = 0x1E31;
  8349. t['kacyrillic'] = 0x043A;
  8350. t['kadescendercyrillic'] = 0x049B;
  8351. t['kadeva'] = 0x0915;
  8352. t['kaf'] = 0x05DB;
  8353. t['kafarabic'] = 0x0643;
  8354. t['kafdagesh'] = 0xFB3B;
  8355. t['kafdageshhebrew'] = 0xFB3B;
  8356. t['kaffinalarabic'] = 0xFEDA;
  8357. t['kafhebrew'] = 0x05DB;
  8358. t['kafinitialarabic'] = 0xFEDB;
  8359. t['kafmedialarabic'] = 0xFEDC;
  8360. t['kafrafehebrew'] = 0xFB4D;
  8361. t['kagujarati'] = 0x0A95;
  8362. t['kagurmukhi'] = 0x0A15;
  8363. t['kahiragana'] = 0x304B;
  8364. t['kahookcyrillic'] = 0x04C4;
  8365. t['kakatakana'] = 0x30AB;
  8366. t['kakatakanahalfwidth'] = 0xFF76;
  8367. t['kappa'] = 0x03BA;
  8368. t['kappasymbolgreek'] = 0x03F0;
  8369. t['kapyeounmieumkorean'] = 0x3171;
  8370. t['kapyeounphieuphkorean'] = 0x3184;
  8371. t['kapyeounpieupkorean'] = 0x3178;
  8372. t['kapyeounssangpieupkorean'] = 0x3179;
  8373. t['karoriisquare'] = 0x330D;
  8374. t['kashidaautoarabic'] = 0x0640;
  8375. t['kashidaautonosidebearingarabic'] = 0x0640;
  8376. t['kasmallkatakana'] = 0x30F5;
  8377. t['kasquare'] = 0x3384;
  8378. t['kasraarabic'] = 0x0650;
  8379. t['kasratanarabic'] = 0x064D;
  8380. t['kastrokecyrillic'] = 0x049F;
  8381. t['katahiraprolongmarkhalfwidth'] = 0xFF70;
  8382. t['kaverticalstrokecyrillic'] = 0x049D;
  8383. t['kbopomofo'] = 0x310E;
  8384. t['kcalsquare'] = 0x3389;
  8385. t['kcaron'] = 0x01E9;
  8386. t['kcedilla'] = 0x0137;
  8387. t['kcircle'] = 0x24DA;
  8388. t['kcommaaccent'] = 0x0137;
  8389. t['kdotbelow'] = 0x1E33;
  8390. t['keharmenian'] = 0x0584;
  8391. t['kehiragana'] = 0x3051;
  8392. t['kekatakana'] = 0x30B1;
  8393. t['kekatakanahalfwidth'] = 0xFF79;
  8394. t['kenarmenian'] = 0x056F;
  8395. t['kesmallkatakana'] = 0x30F6;
  8396. t['kgreenlandic'] = 0x0138;
  8397. t['khabengali'] = 0x0996;
  8398. t['khacyrillic'] = 0x0445;
  8399. t['khadeva'] = 0x0916;
  8400. t['khagujarati'] = 0x0A96;
  8401. t['khagurmukhi'] = 0x0A16;
  8402. t['khaharabic'] = 0x062E;
  8403. t['khahfinalarabic'] = 0xFEA6;
  8404. t['khahinitialarabic'] = 0xFEA7;
  8405. t['khahmedialarabic'] = 0xFEA8;
  8406. t['kheicoptic'] = 0x03E7;
  8407. t['khhadeva'] = 0x0959;
  8408. t['khhagurmukhi'] = 0x0A59;
  8409. t['khieukhacirclekorean'] = 0x3278;
  8410. t['khieukhaparenkorean'] = 0x3218;
  8411. t['khieukhcirclekorean'] = 0x326A;
  8412. t['khieukhkorean'] = 0x314B;
  8413. t['khieukhparenkorean'] = 0x320A;
  8414. t['khokhaithai'] = 0x0E02;
  8415. t['khokhonthai'] = 0x0E05;
  8416. t['khokhuatthai'] = 0x0E03;
  8417. t['khokhwaithai'] = 0x0E04;
  8418. t['khomutthai'] = 0x0E5B;
  8419. t['khook'] = 0x0199;
  8420. t['khorakhangthai'] = 0x0E06;
  8421. t['khzsquare'] = 0x3391;
  8422. t['kihiragana'] = 0x304D;
  8423. t['kikatakana'] = 0x30AD;
  8424. t['kikatakanahalfwidth'] = 0xFF77;
  8425. t['kiroguramusquare'] = 0x3315;
  8426. t['kiromeetorusquare'] = 0x3316;
  8427. t['kirosquare'] = 0x3314;
  8428. t['kiyeokacirclekorean'] = 0x326E;
  8429. t['kiyeokaparenkorean'] = 0x320E;
  8430. t['kiyeokcirclekorean'] = 0x3260;
  8431. t['kiyeokkorean'] = 0x3131;
  8432. t['kiyeokparenkorean'] = 0x3200;
  8433. t['kiyeoksioskorean'] = 0x3133;
  8434. t['kjecyrillic'] = 0x045C;
  8435. t['klinebelow'] = 0x1E35;
  8436. t['klsquare'] = 0x3398;
  8437. t['kmcubedsquare'] = 0x33A6;
  8438. t['kmonospace'] = 0xFF4B;
  8439. t['kmsquaredsquare'] = 0x33A2;
  8440. t['kohiragana'] = 0x3053;
  8441. t['kohmsquare'] = 0x33C0;
  8442. t['kokaithai'] = 0x0E01;
  8443. t['kokatakana'] = 0x30B3;
  8444. t['kokatakanahalfwidth'] = 0xFF7A;
  8445. t['kooposquare'] = 0x331E;
  8446. t['koppacyrillic'] = 0x0481;
  8447. t['koreanstandardsymbol'] = 0x327F;
  8448. t['koroniscmb'] = 0x0343;
  8449. t['kparen'] = 0x24A6;
  8450. t['kpasquare'] = 0x33AA;
  8451. t['ksicyrillic'] = 0x046F;
  8452. t['ktsquare'] = 0x33CF;
  8453. t['kturned'] = 0x029E;
  8454. t['kuhiragana'] = 0x304F;
  8455. t['kukatakana'] = 0x30AF;
  8456. t['kukatakanahalfwidth'] = 0xFF78;
  8457. t['kvsquare'] = 0x33B8;
  8458. t['kwsquare'] = 0x33BE;
  8459. t['l'] = 0x006C;
  8460. t['labengali'] = 0x09B2;
  8461. t['lacute'] = 0x013A;
  8462. t['ladeva'] = 0x0932;
  8463. t['lagujarati'] = 0x0AB2;
  8464. t['lagurmukhi'] = 0x0A32;
  8465. t['lakkhangyaothai'] = 0x0E45;
  8466. t['lamaleffinalarabic'] = 0xFEFC;
  8467. t['lamalefhamzaabovefinalarabic'] = 0xFEF8;
  8468. t['lamalefhamzaaboveisolatedarabic'] = 0xFEF7;
  8469. t['lamalefhamzabelowfinalarabic'] = 0xFEFA;
  8470. t['lamalefhamzabelowisolatedarabic'] = 0xFEF9;
  8471. t['lamalefisolatedarabic'] = 0xFEFB;
  8472. t['lamalefmaddaabovefinalarabic'] = 0xFEF6;
  8473. t['lamalefmaddaaboveisolatedarabic'] = 0xFEF5;
  8474. t['lamarabic'] = 0x0644;
  8475. t['lambda'] = 0x03BB;
  8476. t['lambdastroke'] = 0x019B;
  8477. t['lamed'] = 0x05DC;
  8478. t['lameddagesh'] = 0xFB3C;
  8479. t['lameddageshhebrew'] = 0xFB3C;
  8480. t['lamedhebrew'] = 0x05DC;
  8481. t['lamfinalarabic'] = 0xFEDE;
  8482. t['lamhahinitialarabic'] = 0xFCCA;
  8483. t['laminitialarabic'] = 0xFEDF;
  8484. t['lamjeeminitialarabic'] = 0xFCC9;
  8485. t['lamkhahinitialarabic'] = 0xFCCB;
  8486. t['lamlamhehisolatedarabic'] = 0xFDF2;
  8487. t['lammedialarabic'] = 0xFEE0;
  8488. t['lammeemhahinitialarabic'] = 0xFD88;
  8489. t['lammeeminitialarabic'] = 0xFCCC;
  8490. t['largecircle'] = 0x25EF;
  8491. t['lbar'] = 0x019A;
  8492. t['lbelt'] = 0x026C;
  8493. t['lbopomofo'] = 0x310C;
  8494. t['lcaron'] = 0x013E;
  8495. t['lcedilla'] = 0x013C;
  8496. t['lcircle'] = 0x24DB;
  8497. t['lcircumflexbelow'] = 0x1E3D;
  8498. t['lcommaaccent'] = 0x013C;
  8499. t['ldot'] = 0x0140;
  8500. t['ldotaccent'] = 0x0140;
  8501. t['ldotbelow'] = 0x1E37;
  8502. t['ldotbelowmacron'] = 0x1E39;
  8503. t['leftangleabovecmb'] = 0x031A;
  8504. t['lefttackbelowcmb'] = 0x0318;
  8505. t['less'] = 0x003C;
  8506. t['lessequal'] = 0x2264;
  8507. t['lessequalorgreater'] = 0x22DA;
  8508. t['lessmonospace'] = 0xFF1C;
  8509. t['lessorequivalent'] = 0x2272;
  8510. t['lessorgreater'] = 0x2276;
  8511. t['lessoverequal'] = 0x2266;
  8512. t['lesssmall'] = 0xFE64;
  8513. t['lezh'] = 0x026E;
  8514. t['lfblock'] = 0x258C;
  8515. t['lhookretroflex'] = 0x026D;
  8516. t['lira'] = 0x20A4;
  8517. t['liwnarmenian'] = 0x056C;
  8518. t['lj'] = 0x01C9;
  8519. t['ljecyrillic'] = 0x0459;
  8520. t['ll'] = 0xF6C0;
  8521. t['lladeva'] = 0x0933;
  8522. t['llagujarati'] = 0x0AB3;
  8523. t['llinebelow'] = 0x1E3B;
  8524. t['llladeva'] = 0x0934;
  8525. t['llvocalicbengali'] = 0x09E1;
  8526. t['llvocalicdeva'] = 0x0961;
  8527. t['llvocalicvowelsignbengali'] = 0x09E3;
  8528. t['llvocalicvowelsigndeva'] = 0x0963;
  8529. t['lmiddletilde'] = 0x026B;
  8530. t['lmonospace'] = 0xFF4C;
  8531. t['lmsquare'] = 0x33D0;
  8532. t['lochulathai'] = 0x0E2C;
  8533. t['logicaland'] = 0x2227;
  8534. t['logicalnot'] = 0x00AC;
  8535. t['logicalnotreversed'] = 0x2310;
  8536. t['logicalor'] = 0x2228;
  8537. t['lolingthai'] = 0x0E25;
  8538. t['longs'] = 0x017F;
  8539. t['lowlinecenterline'] = 0xFE4E;
  8540. t['lowlinecmb'] = 0x0332;
  8541. t['lowlinedashed'] = 0xFE4D;
  8542. t['lozenge'] = 0x25CA;
  8543. t['lparen'] = 0x24A7;
  8544. t['lslash'] = 0x0142;
  8545. t['lsquare'] = 0x2113;
  8546. t['lsuperior'] = 0xF6EE;
  8547. t['ltshade'] = 0x2591;
  8548. t['luthai'] = 0x0E26;
  8549. t['lvocalicbengali'] = 0x098C;
  8550. t['lvocalicdeva'] = 0x090C;
  8551. t['lvocalicvowelsignbengali'] = 0x09E2;
  8552. t['lvocalicvowelsigndeva'] = 0x0962;
  8553. t['lxsquare'] = 0x33D3;
  8554. t['m'] = 0x006D;
  8555. t['mabengali'] = 0x09AE;
  8556. t['macron'] = 0x00AF;
  8557. t['macronbelowcmb'] = 0x0331;
  8558. t['macroncmb'] = 0x0304;
  8559. t['macronlowmod'] = 0x02CD;
  8560. t['macronmonospace'] = 0xFFE3;
  8561. t['macute'] = 0x1E3F;
  8562. t['madeva'] = 0x092E;
  8563. t['magujarati'] = 0x0AAE;
  8564. t['magurmukhi'] = 0x0A2E;
  8565. t['mahapakhhebrew'] = 0x05A4;
  8566. t['mahapakhlefthebrew'] = 0x05A4;
  8567. t['mahiragana'] = 0x307E;
  8568. t['maichattawalowleftthai'] = 0xF895;
  8569. t['maichattawalowrightthai'] = 0xF894;
  8570. t['maichattawathai'] = 0x0E4B;
  8571. t['maichattawaupperleftthai'] = 0xF893;
  8572. t['maieklowleftthai'] = 0xF88C;
  8573. t['maieklowrightthai'] = 0xF88B;
  8574. t['maiekthai'] = 0x0E48;
  8575. t['maiekupperleftthai'] = 0xF88A;
  8576. t['maihanakatleftthai'] = 0xF884;
  8577. t['maihanakatthai'] = 0x0E31;
  8578. t['maitaikhuleftthai'] = 0xF889;
  8579. t['maitaikhuthai'] = 0x0E47;
  8580. t['maitholowleftthai'] = 0xF88F;
  8581. t['maitholowrightthai'] = 0xF88E;
  8582. t['maithothai'] = 0x0E49;
  8583. t['maithoupperleftthai'] = 0xF88D;
  8584. t['maitrilowleftthai'] = 0xF892;
  8585. t['maitrilowrightthai'] = 0xF891;
  8586. t['maitrithai'] = 0x0E4A;
  8587. t['maitriupperleftthai'] = 0xF890;
  8588. t['maiyamokthai'] = 0x0E46;
  8589. t['makatakana'] = 0x30DE;
  8590. t['makatakanahalfwidth'] = 0xFF8F;
  8591. t['male'] = 0x2642;
  8592. t['mansyonsquare'] = 0x3347;
  8593. t['maqafhebrew'] = 0x05BE;
  8594. t['mars'] = 0x2642;
  8595. t['masoracirclehebrew'] = 0x05AF;
  8596. t['masquare'] = 0x3383;
  8597. t['mbopomofo'] = 0x3107;
  8598. t['mbsquare'] = 0x33D4;
  8599. t['mcircle'] = 0x24DC;
  8600. t['mcubedsquare'] = 0x33A5;
  8601. t['mdotaccent'] = 0x1E41;
  8602. t['mdotbelow'] = 0x1E43;
  8603. t['meemarabic'] = 0x0645;
  8604. t['meemfinalarabic'] = 0xFEE2;
  8605. t['meeminitialarabic'] = 0xFEE3;
  8606. t['meemmedialarabic'] = 0xFEE4;
  8607. t['meemmeeminitialarabic'] = 0xFCD1;
  8608. t['meemmeemisolatedarabic'] = 0xFC48;
  8609. t['meetorusquare'] = 0x334D;
  8610. t['mehiragana'] = 0x3081;
  8611. t['meizierasquare'] = 0x337E;
  8612. t['mekatakana'] = 0x30E1;
  8613. t['mekatakanahalfwidth'] = 0xFF92;
  8614. t['mem'] = 0x05DE;
  8615. t['memdagesh'] = 0xFB3E;
  8616. t['memdageshhebrew'] = 0xFB3E;
  8617. t['memhebrew'] = 0x05DE;
  8618. t['menarmenian'] = 0x0574;
  8619. t['merkhahebrew'] = 0x05A5;
  8620. t['merkhakefulahebrew'] = 0x05A6;
  8621. t['merkhakefulalefthebrew'] = 0x05A6;
  8622. t['merkhalefthebrew'] = 0x05A5;
  8623. t['mhook'] = 0x0271;
  8624. t['mhzsquare'] = 0x3392;
  8625. t['middledotkatakanahalfwidth'] = 0xFF65;
  8626. t['middot'] = 0x00B7;
  8627. t['mieumacirclekorean'] = 0x3272;
  8628. t['mieumaparenkorean'] = 0x3212;
  8629. t['mieumcirclekorean'] = 0x3264;
  8630. t['mieumkorean'] = 0x3141;
  8631. t['mieumpansioskorean'] = 0x3170;
  8632. t['mieumparenkorean'] = 0x3204;
  8633. t['mieumpieupkorean'] = 0x316E;
  8634. t['mieumsioskorean'] = 0x316F;
  8635. t['mihiragana'] = 0x307F;
  8636. t['mikatakana'] = 0x30DF;
  8637. t['mikatakanahalfwidth'] = 0xFF90;
  8638. t['minus'] = 0x2212;
  8639. t['minusbelowcmb'] = 0x0320;
  8640. t['minuscircle'] = 0x2296;
  8641. t['minusmod'] = 0x02D7;
  8642. t['minusplus'] = 0x2213;
  8643. t['minute'] = 0x2032;
  8644. t['miribaarusquare'] = 0x334A;
  8645. t['mirisquare'] = 0x3349;
  8646. t['mlonglegturned'] = 0x0270;
  8647. t['mlsquare'] = 0x3396;
  8648. t['mmcubedsquare'] = 0x33A3;
  8649. t['mmonospace'] = 0xFF4D;
  8650. t['mmsquaredsquare'] = 0x339F;
  8651. t['mohiragana'] = 0x3082;
  8652. t['mohmsquare'] = 0x33C1;
  8653. t['mokatakana'] = 0x30E2;
  8654. t['mokatakanahalfwidth'] = 0xFF93;
  8655. t['molsquare'] = 0x33D6;
  8656. t['momathai'] = 0x0E21;
  8657. t['moverssquare'] = 0x33A7;
  8658. t['moverssquaredsquare'] = 0x33A8;
  8659. t['mparen'] = 0x24A8;
  8660. t['mpasquare'] = 0x33AB;
  8661. t['mssquare'] = 0x33B3;
  8662. t['msuperior'] = 0xF6EF;
  8663. t['mturned'] = 0x026F;
  8664. t['mu'] = 0x00B5;
  8665. t['mu1'] = 0x00B5;
  8666. t['muasquare'] = 0x3382;
  8667. t['muchgreater'] = 0x226B;
  8668. t['muchless'] = 0x226A;
  8669. t['mufsquare'] = 0x338C;
  8670. t['mugreek'] = 0x03BC;
  8671. t['mugsquare'] = 0x338D;
  8672. t['muhiragana'] = 0x3080;
  8673. t['mukatakana'] = 0x30E0;
  8674. t['mukatakanahalfwidth'] = 0xFF91;
  8675. t['mulsquare'] = 0x3395;
  8676. t['multiply'] = 0x00D7;
  8677. t['mumsquare'] = 0x339B;
  8678. t['munahhebrew'] = 0x05A3;
  8679. t['munahlefthebrew'] = 0x05A3;
  8680. t['musicalnote'] = 0x266A;
  8681. t['musicalnotedbl'] = 0x266B;
  8682. t['musicflatsign'] = 0x266D;
  8683. t['musicsharpsign'] = 0x266F;
  8684. t['mussquare'] = 0x33B2;
  8685. t['muvsquare'] = 0x33B6;
  8686. t['muwsquare'] = 0x33BC;
  8687. t['mvmegasquare'] = 0x33B9;
  8688. t['mvsquare'] = 0x33B7;
  8689. t['mwmegasquare'] = 0x33BF;
  8690. t['mwsquare'] = 0x33BD;
  8691. t['n'] = 0x006E;
  8692. t['nabengali'] = 0x09A8;
  8693. t['nabla'] = 0x2207;
  8694. t['nacute'] = 0x0144;
  8695. t['nadeva'] = 0x0928;
  8696. t['nagujarati'] = 0x0AA8;
  8697. t['nagurmukhi'] = 0x0A28;
  8698. t['nahiragana'] = 0x306A;
  8699. t['nakatakana'] = 0x30CA;
  8700. t['nakatakanahalfwidth'] = 0xFF85;
  8701. t['napostrophe'] = 0x0149;
  8702. t['nasquare'] = 0x3381;
  8703. t['nbopomofo'] = 0x310B;
  8704. t['nbspace'] = 0x00A0;
  8705. t['ncaron'] = 0x0148;
  8706. t['ncedilla'] = 0x0146;
  8707. t['ncircle'] = 0x24DD;
  8708. t['ncircumflexbelow'] = 0x1E4B;
  8709. t['ncommaaccent'] = 0x0146;
  8710. t['ndotaccent'] = 0x1E45;
  8711. t['ndotbelow'] = 0x1E47;
  8712. t['nehiragana'] = 0x306D;
  8713. t['nekatakana'] = 0x30CD;
  8714. t['nekatakanahalfwidth'] = 0xFF88;
  8715. t['newsheqelsign'] = 0x20AA;
  8716. t['nfsquare'] = 0x338B;
  8717. t['ngabengali'] = 0x0999;
  8718. t['ngadeva'] = 0x0919;
  8719. t['ngagujarati'] = 0x0A99;
  8720. t['ngagurmukhi'] = 0x0A19;
  8721. t['ngonguthai'] = 0x0E07;
  8722. t['nhiragana'] = 0x3093;
  8723. t['nhookleft'] = 0x0272;
  8724. t['nhookretroflex'] = 0x0273;
  8725. t['nieunacirclekorean'] = 0x326F;
  8726. t['nieunaparenkorean'] = 0x320F;
  8727. t['nieuncieuckorean'] = 0x3135;
  8728. t['nieuncirclekorean'] = 0x3261;
  8729. t['nieunhieuhkorean'] = 0x3136;
  8730. t['nieunkorean'] = 0x3134;
  8731. t['nieunpansioskorean'] = 0x3168;
  8732. t['nieunparenkorean'] = 0x3201;
  8733. t['nieunsioskorean'] = 0x3167;
  8734. t['nieuntikeutkorean'] = 0x3166;
  8735. t['nihiragana'] = 0x306B;
  8736. t['nikatakana'] = 0x30CB;
  8737. t['nikatakanahalfwidth'] = 0xFF86;
  8738. t['nikhahitleftthai'] = 0xF899;
  8739. t['nikhahitthai'] = 0x0E4D;
  8740. t['nine'] = 0x0039;
  8741. t['ninearabic'] = 0x0669;
  8742. t['ninebengali'] = 0x09EF;
  8743. t['ninecircle'] = 0x2468;
  8744. t['ninecircleinversesansserif'] = 0x2792;
  8745. t['ninedeva'] = 0x096F;
  8746. t['ninegujarati'] = 0x0AEF;
  8747. t['ninegurmukhi'] = 0x0A6F;
  8748. t['ninehackarabic'] = 0x0669;
  8749. t['ninehangzhou'] = 0x3029;
  8750. t['nineideographicparen'] = 0x3228;
  8751. t['nineinferior'] = 0x2089;
  8752. t['ninemonospace'] = 0xFF19;
  8753. t['nineoldstyle'] = 0xF739;
  8754. t['nineparen'] = 0x247C;
  8755. t['nineperiod'] = 0x2490;
  8756. t['ninepersian'] = 0x06F9;
  8757. t['nineroman'] = 0x2178;
  8758. t['ninesuperior'] = 0x2079;
  8759. t['nineteencircle'] = 0x2472;
  8760. t['nineteenparen'] = 0x2486;
  8761. t['nineteenperiod'] = 0x249A;
  8762. t['ninethai'] = 0x0E59;
  8763. t['nj'] = 0x01CC;
  8764. t['njecyrillic'] = 0x045A;
  8765. t['nkatakana'] = 0x30F3;
  8766. t['nkatakanahalfwidth'] = 0xFF9D;
  8767. t['nlegrightlong'] = 0x019E;
  8768. t['nlinebelow'] = 0x1E49;
  8769. t['nmonospace'] = 0xFF4E;
  8770. t['nmsquare'] = 0x339A;
  8771. t['nnabengali'] = 0x09A3;
  8772. t['nnadeva'] = 0x0923;
  8773. t['nnagujarati'] = 0x0AA3;
  8774. t['nnagurmukhi'] = 0x0A23;
  8775. t['nnnadeva'] = 0x0929;
  8776. t['nohiragana'] = 0x306E;
  8777. t['nokatakana'] = 0x30CE;
  8778. t['nokatakanahalfwidth'] = 0xFF89;
  8779. t['nonbreakingspace'] = 0x00A0;
  8780. t['nonenthai'] = 0x0E13;
  8781. t['nonuthai'] = 0x0E19;
  8782. t['noonarabic'] = 0x0646;
  8783. t['noonfinalarabic'] = 0xFEE6;
  8784. t['noonghunnaarabic'] = 0x06BA;
  8785. t['noonghunnafinalarabic'] = 0xFB9F;
  8786. t['nooninitialarabic'] = 0xFEE7;
  8787. t['noonjeeminitialarabic'] = 0xFCD2;
  8788. t['noonjeemisolatedarabic'] = 0xFC4B;
  8789. t['noonmedialarabic'] = 0xFEE8;
  8790. t['noonmeeminitialarabic'] = 0xFCD5;
  8791. t['noonmeemisolatedarabic'] = 0xFC4E;
  8792. t['noonnoonfinalarabic'] = 0xFC8D;
  8793. t['notcontains'] = 0x220C;
  8794. t['notelement'] = 0x2209;
  8795. t['notelementof'] = 0x2209;
  8796. t['notequal'] = 0x2260;
  8797. t['notgreater'] = 0x226F;
  8798. t['notgreaternorequal'] = 0x2271;
  8799. t['notgreaternorless'] = 0x2279;
  8800. t['notidentical'] = 0x2262;
  8801. t['notless'] = 0x226E;
  8802. t['notlessnorequal'] = 0x2270;
  8803. t['notparallel'] = 0x2226;
  8804. t['notprecedes'] = 0x2280;
  8805. t['notsubset'] = 0x2284;
  8806. t['notsucceeds'] = 0x2281;
  8807. t['notsuperset'] = 0x2285;
  8808. t['nowarmenian'] = 0x0576;
  8809. t['nparen'] = 0x24A9;
  8810. t['nssquare'] = 0x33B1;
  8811. t['nsuperior'] = 0x207F;
  8812. t['ntilde'] = 0x00F1;
  8813. t['nu'] = 0x03BD;
  8814. t['nuhiragana'] = 0x306C;
  8815. t['nukatakana'] = 0x30CC;
  8816. t['nukatakanahalfwidth'] = 0xFF87;
  8817. t['nuktabengali'] = 0x09BC;
  8818. t['nuktadeva'] = 0x093C;
  8819. t['nuktagujarati'] = 0x0ABC;
  8820. t['nuktagurmukhi'] = 0x0A3C;
  8821. t['numbersign'] = 0x0023;
  8822. t['numbersignmonospace'] = 0xFF03;
  8823. t['numbersignsmall'] = 0xFE5F;
  8824. t['numeralsigngreek'] = 0x0374;
  8825. t['numeralsignlowergreek'] = 0x0375;
  8826. t['numero'] = 0x2116;
  8827. t['nun'] = 0x05E0;
  8828. t['nundagesh'] = 0xFB40;
  8829. t['nundageshhebrew'] = 0xFB40;
  8830. t['nunhebrew'] = 0x05E0;
  8831. t['nvsquare'] = 0x33B5;
  8832. t['nwsquare'] = 0x33BB;
  8833. t['nyabengali'] = 0x099E;
  8834. t['nyadeva'] = 0x091E;
  8835. t['nyagujarati'] = 0x0A9E;
  8836. t['nyagurmukhi'] = 0x0A1E;
  8837. t['o'] = 0x006F;
  8838. t['oacute'] = 0x00F3;
  8839. t['oangthai'] = 0x0E2D;
  8840. t['obarred'] = 0x0275;
  8841. t['obarredcyrillic'] = 0x04E9;
  8842. t['obarreddieresiscyrillic'] = 0x04EB;
  8843. t['obengali'] = 0x0993;
  8844. t['obopomofo'] = 0x311B;
  8845. t['obreve'] = 0x014F;
  8846. t['ocandradeva'] = 0x0911;
  8847. t['ocandragujarati'] = 0x0A91;
  8848. t['ocandravowelsigndeva'] = 0x0949;
  8849. t['ocandravowelsigngujarati'] = 0x0AC9;
  8850. t['ocaron'] = 0x01D2;
  8851. t['ocircle'] = 0x24DE;
  8852. t['ocircumflex'] = 0x00F4;
  8853. t['ocircumflexacute'] = 0x1ED1;
  8854. t['ocircumflexdotbelow'] = 0x1ED9;
  8855. t['ocircumflexgrave'] = 0x1ED3;
  8856. t['ocircumflexhookabove'] = 0x1ED5;
  8857. t['ocircumflextilde'] = 0x1ED7;
  8858. t['ocyrillic'] = 0x043E;
  8859. t['odblacute'] = 0x0151;
  8860. t['odblgrave'] = 0x020D;
  8861. t['odeva'] = 0x0913;
  8862. t['odieresis'] = 0x00F6;
  8863. t['odieresiscyrillic'] = 0x04E7;
  8864. t['odotbelow'] = 0x1ECD;
  8865. t['oe'] = 0x0153;
  8866. t['oekorean'] = 0x315A;
  8867. t['ogonek'] = 0x02DB;
  8868. t['ogonekcmb'] = 0x0328;
  8869. t['ograve'] = 0x00F2;
  8870. t['ogujarati'] = 0x0A93;
  8871. t['oharmenian'] = 0x0585;
  8872. t['ohiragana'] = 0x304A;
  8873. t['ohookabove'] = 0x1ECF;
  8874. t['ohorn'] = 0x01A1;
  8875. t['ohornacute'] = 0x1EDB;
  8876. t['ohorndotbelow'] = 0x1EE3;
  8877. t['ohorngrave'] = 0x1EDD;
  8878. t['ohornhookabove'] = 0x1EDF;
  8879. t['ohorntilde'] = 0x1EE1;
  8880. t['ohungarumlaut'] = 0x0151;
  8881. t['oi'] = 0x01A3;
  8882. t['oinvertedbreve'] = 0x020F;
  8883. t['okatakana'] = 0x30AA;
  8884. t['okatakanahalfwidth'] = 0xFF75;
  8885. t['okorean'] = 0x3157;
  8886. t['olehebrew'] = 0x05AB;
  8887. t['omacron'] = 0x014D;
  8888. t['omacronacute'] = 0x1E53;
  8889. t['omacrongrave'] = 0x1E51;
  8890. t['omdeva'] = 0x0950;
  8891. t['omega'] = 0x03C9;
  8892. t['omega1'] = 0x03D6;
  8893. t['omegacyrillic'] = 0x0461;
  8894. t['omegalatinclosed'] = 0x0277;
  8895. t['omegaroundcyrillic'] = 0x047B;
  8896. t['omegatitlocyrillic'] = 0x047D;
  8897. t['omegatonos'] = 0x03CE;
  8898. t['omgujarati'] = 0x0AD0;
  8899. t['omicron'] = 0x03BF;
  8900. t['omicrontonos'] = 0x03CC;
  8901. t['omonospace'] = 0xFF4F;
  8902. t['one'] = 0x0031;
  8903. t['onearabic'] = 0x0661;
  8904. t['onebengali'] = 0x09E7;
  8905. t['onecircle'] = 0x2460;
  8906. t['onecircleinversesansserif'] = 0x278A;
  8907. t['onedeva'] = 0x0967;
  8908. t['onedotenleader'] = 0x2024;
  8909. t['oneeighth'] = 0x215B;
  8910. t['onefitted'] = 0xF6DC;
  8911. t['onegujarati'] = 0x0AE7;
  8912. t['onegurmukhi'] = 0x0A67;
  8913. t['onehackarabic'] = 0x0661;
  8914. t['onehalf'] = 0x00BD;
  8915. t['onehangzhou'] = 0x3021;
  8916. t['oneideographicparen'] = 0x3220;
  8917. t['oneinferior'] = 0x2081;
  8918. t['onemonospace'] = 0xFF11;
  8919. t['onenumeratorbengali'] = 0x09F4;
  8920. t['oneoldstyle'] = 0xF731;
  8921. t['oneparen'] = 0x2474;
  8922. t['oneperiod'] = 0x2488;
  8923. t['onepersian'] = 0x06F1;
  8924. t['onequarter'] = 0x00BC;
  8925. t['oneroman'] = 0x2170;
  8926. t['onesuperior'] = 0x00B9;
  8927. t['onethai'] = 0x0E51;
  8928. t['onethird'] = 0x2153;
  8929. t['oogonek'] = 0x01EB;
  8930. t['oogonekmacron'] = 0x01ED;
  8931. t['oogurmukhi'] = 0x0A13;
  8932. t['oomatragurmukhi'] = 0x0A4B;
  8933. t['oopen'] = 0x0254;
  8934. t['oparen'] = 0x24AA;
  8935. t['openbullet'] = 0x25E6;
  8936. t['option'] = 0x2325;
  8937. t['ordfeminine'] = 0x00AA;
  8938. t['ordmasculine'] = 0x00BA;
  8939. t['orthogonal'] = 0x221F;
  8940. t['oshortdeva'] = 0x0912;
  8941. t['oshortvowelsigndeva'] = 0x094A;
  8942. t['oslash'] = 0x00F8;
  8943. t['oslashacute'] = 0x01FF;
  8944. t['osmallhiragana'] = 0x3049;
  8945. t['osmallkatakana'] = 0x30A9;
  8946. t['osmallkatakanahalfwidth'] = 0xFF6B;
  8947. t['ostrokeacute'] = 0x01FF;
  8948. t['osuperior'] = 0xF6F0;
  8949. t['otcyrillic'] = 0x047F;
  8950. t['otilde'] = 0x00F5;
  8951. t['otildeacute'] = 0x1E4D;
  8952. t['otildedieresis'] = 0x1E4F;
  8953. t['oubopomofo'] = 0x3121;
  8954. t['overline'] = 0x203E;
  8955. t['overlinecenterline'] = 0xFE4A;
  8956. t['overlinecmb'] = 0x0305;
  8957. t['overlinedashed'] = 0xFE49;
  8958. t['overlinedblwavy'] = 0xFE4C;
  8959. t['overlinewavy'] = 0xFE4B;
  8960. t['overscore'] = 0x00AF;
  8961. t['ovowelsignbengali'] = 0x09CB;
  8962. t['ovowelsigndeva'] = 0x094B;
  8963. t['ovowelsigngujarati'] = 0x0ACB;
  8964. t['p'] = 0x0070;
  8965. t['paampssquare'] = 0x3380;
  8966. t['paasentosquare'] = 0x332B;
  8967. t['pabengali'] = 0x09AA;
  8968. t['pacute'] = 0x1E55;
  8969. t['padeva'] = 0x092A;
  8970. t['pagedown'] = 0x21DF;
  8971. t['pageup'] = 0x21DE;
  8972. t['pagujarati'] = 0x0AAA;
  8973. t['pagurmukhi'] = 0x0A2A;
  8974. t['pahiragana'] = 0x3071;
  8975. t['paiyannoithai'] = 0x0E2F;
  8976. t['pakatakana'] = 0x30D1;
  8977. t['palatalizationcyrilliccmb'] = 0x0484;
  8978. t['palochkacyrillic'] = 0x04C0;
  8979. t['pansioskorean'] = 0x317F;
  8980. t['paragraph'] = 0x00B6;
  8981. t['parallel'] = 0x2225;
  8982. t['parenleft'] = 0x0028;
  8983. t['parenleftaltonearabic'] = 0xFD3E;
  8984. t['parenleftbt'] = 0xF8ED;
  8985. t['parenleftex'] = 0xF8EC;
  8986. t['parenleftinferior'] = 0x208D;
  8987. t['parenleftmonospace'] = 0xFF08;
  8988. t['parenleftsmall'] = 0xFE59;
  8989. t['parenleftsuperior'] = 0x207D;
  8990. t['parenlefttp'] = 0xF8EB;
  8991. t['parenleftvertical'] = 0xFE35;
  8992. t['parenright'] = 0x0029;
  8993. t['parenrightaltonearabic'] = 0xFD3F;
  8994. t['parenrightbt'] = 0xF8F8;
  8995. t['parenrightex'] = 0xF8F7;
  8996. t['parenrightinferior'] = 0x208E;
  8997. t['parenrightmonospace'] = 0xFF09;
  8998. t['parenrightsmall'] = 0xFE5A;
  8999. t['parenrightsuperior'] = 0x207E;
  9000. t['parenrighttp'] = 0xF8F6;
  9001. t['parenrightvertical'] = 0xFE36;
  9002. t['partialdiff'] = 0x2202;
  9003. t['paseqhebrew'] = 0x05C0;
  9004. t['pashtahebrew'] = 0x0599;
  9005. t['pasquare'] = 0x33A9;
  9006. t['patah'] = 0x05B7;
  9007. t['patah11'] = 0x05B7;
  9008. t['patah1d'] = 0x05B7;
  9009. t['patah2a'] = 0x05B7;
  9010. t['patahhebrew'] = 0x05B7;
  9011. t['patahnarrowhebrew'] = 0x05B7;
  9012. t['patahquarterhebrew'] = 0x05B7;
  9013. t['patahwidehebrew'] = 0x05B7;
  9014. t['pazerhebrew'] = 0x05A1;
  9015. t['pbopomofo'] = 0x3106;
  9016. t['pcircle'] = 0x24DF;
  9017. t['pdotaccent'] = 0x1E57;
  9018. t['pe'] = 0x05E4;
  9019. t['pecyrillic'] = 0x043F;
  9020. t['pedagesh'] = 0xFB44;
  9021. t['pedageshhebrew'] = 0xFB44;
  9022. t['peezisquare'] = 0x333B;
  9023. t['pefinaldageshhebrew'] = 0xFB43;
  9024. t['peharabic'] = 0x067E;
  9025. t['peharmenian'] = 0x057A;
  9026. t['pehebrew'] = 0x05E4;
  9027. t['pehfinalarabic'] = 0xFB57;
  9028. t['pehinitialarabic'] = 0xFB58;
  9029. t['pehiragana'] = 0x307A;
  9030. t['pehmedialarabic'] = 0xFB59;
  9031. t['pekatakana'] = 0x30DA;
  9032. t['pemiddlehookcyrillic'] = 0x04A7;
  9033. t['perafehebrew'] = 0xFB4E;
  9034. t['percent'] = 0x0025;
  9035. t['percentarabic'] = 0x066A;
  9036. t['percentmonospace'] = 0xFF05;
  9037. t['percentsmall'] = 0xFE6A;
  9038. t['period'] = 0x002E;
  9039. t['periodarmenian'] = 0x0589;
  9040. t['periodcentered'] = 0x00B7;
  9041. t['periodhalfwidth'] = 0xFF61;
  9042. t['periodinferior'] = 0xF6E7;
  9043. t['periodmonospace'] = 0xFF0E;
  9044. t['periodsmall'] = 0xFE52;
  9045. t['periodsuperior'] = 0xF6E8;
  9046. t['perispomenigreekcmb'] = 0x0342;
  9047. t['perpendicular'] = 0x22A5;
  9048. t['perthousand'] = 0x2030;
  9049. t['peseta'] = 0x20A7;
  9050. t['pfsquare'] = 0x338A;
  9051. t['phabengali'] = 0x09AB;
  9052. t['phadeva'] = 0x092B;
  9053. t['phagujarati'] = 0x0AAB;
  9054. t['phagurmukhi'] = 0x0A2B;
  9055. t['phi'] = 0x03C6;
  9056. t['phi1'] = 0x03D5;
  9057. t['phieuphacirclekorean'] = 0x327A;
  9058. t['phieuphaparenkorean'] = 0x321A;
  9059. t['phieuphcirclekorean'] = 0x326C;
  9060. t['phieuphkorean'] = 0x314D;
  9061. t['phieuphparenkorean'] = 0x320C;
  9062. t['philatin'] = 0x0278;
  9063. t['phinthuthai'] = 0x0E3A;
  9064. t['phisymbolgreek'] = 0x03D5;
  9065. t['phook'] = 0x01A5;
  9066. t['phophanthai'] = 0x0E1E;
  9067. t['phophungthai'] = 0x0E1C;
  9068. t['phosamphaothai'] = 0x0E20;
  9069. t['pi'] = 0x03C0;
  9070. t['pieupacirclekorean'] = 0x3273;
  9071. t['pieupaparenkorean'] = 0x3213;
  9072. t['pieupcieuckorean'] = 0x3176;
  9073. t['pieupcirclekorean'] = 0x3265;
  9074. t['pieupkiyeokkorean'] = 0x3172;
  9075. t['pieupkorean'] = 0x3142;
  9076. t['pieupparenkorean'] = 0x3205;
  9077. t['pieupsioskiyeokkorean'] = 0x3174;
  9078. t['pieupsioskorean'] = 0x3144;
  9079. t['pieupsiostikeutkorean'] = 0x3175;
  9080. t['pieupthieuthkorean'] = 0x3177;
  9081. t['pieuptikeutkorean'] = 0x3173;
  9082. t['pihiragana'] = 0x3074;
  9083. t['pikatakana'] = 0x30D4;
  9084. t['pisymbolgreek'] = 0x03D6;
  9085. t['piwrarmenian'] = 0x0583;
  9086. t['plus'] = 0x002B;
  9087. t['plusbelowcmb'] = 0x031F;
  9088. t['pluscircle'] = 0x2295;
  9089. t['plusminus'] = 0x00B1;
  9090. t['plusmod'] = 0x02D6;
  9091. t['plusmonospace'] = 0xFF0B;
  9092. t['plussmall'] = 0xFE62;
  9093. t['plussuperior'] = 0x207A;
  9094. t['pmonospace'] = 0xFF50;
  9095. t['pmsquare'] = 0x33D8;
  9096. t['pohiragana'] = 0x307D;
  9097. t['pointingindexdownwhite'] = 0x261F;
  9098. t['pointingindexleftwhite'] = 0x261C;
  9099. t['pointingindexrightwhite'] = 0x261E;
  9100. t['pointingindexupwhite'] = 0x261D;
  9101. t['pokatakana'] = 0x30DD;
  9102. t['poplathai'] = 0x0E1B;
  9103. t['postalmark'] = 0x3012;
  9104. t['postalmarkface'] = 0x3020;
  9105. t['pparen'] = 0x24AB;
  9106. t['precedes'] = 0x227A;
  9107. t['prescription'] = 0x211E;
  9108. t['primemod'] = 0x02B9;
  9109. t['primereversed'] = 0x2035;
  9110. t['product'] = 0x220F;
  9111. t['projective'] = 0x2305;
  9112. t['prolongedkana'] = 0x30FC;
  9113. t['propellor'] = 0x2318;
  9114. t['propersubset'] = 0x2282;
  9115. t['propersuperset'] = 0x2283;
  9116. t['proportion'] = 0x2237;
  9117. t['proportional'] = 0x221D;
  9118. t['psi'] = 0x03C8;
  9119. t['psicyrillic'] = 0x0471;
  9120. t['psilipneumatacyrilliccmb'] = 0x0486;
  9121. t['pssquare'] = 0x33B0;
  9122. t['puhiragana'] = 0x3077;
  9123. t['pukatakana'] = 0x30D7;
  9124. t['pvsquare'] = 0x33B4;
  9125. t['pwsquare'] = 0x33BA;
  9126. t['q'] = 0x0071;
  9127. t['qadeva'] = 0x0958;
  9128. t['qadmahebrew'] = 0x05A8;
  9129. t['qafarabic'] = 0x0642;
  9130. t['qaffinalarabic'] = 0xFED6;
  9131. t['qafinitialarabic'] = 0xFED7;
  9132. t['qafmedialarabic'] = 0xFED8;
  9133. t['qamats'] = 0x05B8;
  9134. t['qamats10'] = 0x05B8;
  9135. t['qamats1a'] = 0x05B8;
  9136. t['qamats1c'] = 0x05B8;
  9137. t['qamats27'] = 0x05B8;
  9138. t['qamats29'] = 0x05B8;
  9139. t['qamats33'] = 0x05B8;
  9140. t['qamatsde'] = 0x05B8;
  9141. t['qamatshebrew'] = 0x05B8;
  9142. t['qamatsnarrowhebrew'] = 0x05B8;
  9143. t['qamatsqatanhebrew'] = 0x05B8;
  9144. t['qamatsqatannarrowhebrew'] = 0x05B8;
  9145. t['qamatsqatanquarterhebrew'] = 0x05B8;
  9146. t['qamatsqatanwidehebrew'] = 0x05B8;
  9147. t['qamatsquarterhebrew'] = 0x05B8;
  9148. t['qamatswidehebrew'] = 0x05B8;
  9149. t['qarneyparahebrew'] = 0x059F;
  9150. t['qbopomofo'] = 0x3111;
  9151. t['qcircle'] = 0x24E0;
  9152. t['qhook'] = 0x02A0;
  9153. t['qmonospace'] = 0xFF51;
  9154. t['qof'] = 0x05E7;
  9155. t['qofdagesh'] = 0xFB47;
  9156. t['qofdageshhebrew'] = 0xFB47;
  9157. t['qofhebrew'] = 0x05E7;
  9158. t['qparen'] = 0x24AC;
  9159. t['quarternote'] = 0x2669;
  9160. t['qubuts'] = 0x05BB;
  9161. t['qubuts18'] = 0x05BB;
  9162. t['qubuts25'] = 0x05BB;
  9163. t['qubuts31'] = 0x05BB;
  9164. t['qubutshebrew'] = 0x05BB;
  9165. t['qubutsnarrowhebrew'] = 0x05BB;
  9166. t['qubutsquarterhebrew'] = 0x05BB;
  9167. t['qubutswidehebrew'] = 0x05BB;
  9168. t['question'] = 0x003F;
  9169. t['questionarabic'] = 0x061F;
  9170. t['questionarmenian'] = 0x055E;
  9171. t['questiondown'] = 0x00BF;
  9172. t['questiondownsmall'] = 0xF7BF;
  9173. t['questiongreek'] = 0x037E;
  9174. t['questionmonospace'] = 0xFF1F;
  9175. t['questionsmall'] = 0xF73F;
  9176. t['quotedbl'] = 0x0022;
  9177. t['quotedblbase'] = 0x201E;
  9178. t['quotedblleft'] = 0x201C;
  9179. t['quotedblmonospace'] = 0xFF02;
  9180. t['quotedblprime'] = 0x301E;
  9181. t['quotedblprimereversed'] = 0x301D;
  9182. t['quotedblright'] = 0x201D;
  9183. t['quoteleft'] = 0x2018;
  9184. t['quoteleftreversed'] = 0x201B;
  9185. t['quotereversed'] = 0x201B;
  9186. t['quoteright'] = 0x2019;
  9187. t['quoterightn'] = 0x0149;
  9188. t['quotesinglbase'] = 0x201A;
  9189. t['quotesingle'] = 0x0027;
  9190. t['quotesinglemonospace'] = 0xFF07;
  9191. t['r'] = 0x0072;
  9192. t['raarmenian'] = 0x057C;
  9193. t['rabengali'] = 0x09B0;
  9194. t['racute'] = 0x0155;
  9195. t['radeva'] = 0x0930;
  9196. t['radical'] = 0x221A;
  9197. t['radicalex'] = 0xF8E5;
  9198. t['radoverssquare'] = 0x33AE;
  9199. t['radoverssquaredsquare'] = 0x33AF;
  9200. t['radsquare'] = 0x33AD;
  9201. t['rafe'] = 0x05BF;
  9202. t['rafehebrew'] = 0x05BF;
  9203. t['ragujarati'] = 0x0AB0;
  9204. t['ragurmukhi'] = 0x0A30;
  9205. t['rahiragana'] = 0x3089;
  9206. t['rakatakana'] = 0x30E9;
  9207. t['rakatakanahalfwidth'] = 0xFF97;
  9208. t['ralowerdiagonalbengali'] = 0x09F1;
  9209. t['ramiddlediagonalbengali'] = 0x09F0;
  9210. t['ramshorn'] = 0x0264;
  9211. t['ratio'] = 0x2236;
  9212. t['rbopomofo'] = 0x3116;
  9213. t['rcaron'] = 0x0159;
  9214. t['rcedilla'] = 0x0157;
  9215. t['rcircle'] = 0x24E1;
  9216. t['rcommaaccent'] = 0x0157;
  9217. t['rdblgrave'] = 0x0211;
  9218. t['rdotaccent'] = 0x1E59;
  9219. t['rdotbelow'] = 0x1E5B;
  9220. t['rdotbelowmacron'] = 0x1E5D;
  9221. t['referencemark'] = 0x203B;
  9222. t['reflexsubset'] = 0x2286;
  9223. t['reflexsuperset'] = 0x2287;
  9224. t['registered'] = 0x00AE;
  9225. t['registersans'] = 0xF8E8;
  9226. t['registerserif'] = 0xF6DA;
  9227. t['reharabic'] = 0x0631;
  9228. t['reharmenian'] = 0x0580;
  9229. t['rehfinalarabic'] = 0xFEAE;
  9230. t['rehiragana'] = 0x308C;
  9231. t['rekatakana'] = 0x30EC;
  9232. t['rekatakanahalfwidth'] = 0xFF9A;
  9233. t['resh'] = 0x05E8;
  9234. t['reshdageshhebrew'] = 0xFB48;
  9235. t['reshhebrew'] = 0x05E8;
  9236. t['reversedtilde'] = 0x223D;
  9237. t['reviahebrew'] = 0x0597;
  9238. t['reviamugrashhebrew'] = 0x0597;
  9239. t['revlogicalnot'] = 0x2310;
  9240. t['rfishhook'] = 0x027E;
  9241. t['rfishhookreversed'] = 0x027F;
  9242. t['rhabengali'] = 0x09DD;
  9243. t['rhadeva'] = 0x095D;
  9244. t['rho'] = 0x03C1;
  9245. t['rhook'] = 0x027D;
  9246. t['rhookturned'] = 0x027B;
  9247. t['rhookturnedsuperior'] = 0x02B5;
  9248. t['rhosymbolgreek'] = 0x03F1;
  9249. t['rhotichookmod'] = 0x02DE;
  9250. t['rieulacirclekorean'] = 0x3271;
  9251. t['rieulaparenkorean'] = 0x3211;
  9252. t['rieulcirclekorean'] = 0x3263;
  9253. t['rieulhieuhkorean'] = 0x3140;
  9254. t['rieulkiyeokkorean'] = 0x313A;
  9255. t['rieulkiyeoksioskorean'] = 0x3169;
  9256. t['rieulkorean'] = 0x3139;
  9257. t['rieulmieumkorean'] = 0x313B;
  9258. t['rieulpansioskorean'] = 0x316C;
  9259. t['rieulparenkorean'] = 0x3203;
  9260. t['rieulphieuphkorean'] = 0x313F;
  9261. t['rieulpieupkorean'] = 0x313C;
  9262. t['rieulpieupsioskorean'] = 0x316B;
  9263. t['rieulsioskorean'] = 0x313D;
  9264. t['rieulthieuthkorean'] = 0x313E;
  9265. t['rieultikeutkorean'] = 0x316A;
  9266. t['rieulyeorinhieuhkorean'] = 0x316D;
  9267. t['rightangle'] = 0x221F;
  9268. t['righttackbelowcmb'] = 0x0319;
  9269. t['righttriangle'] = 0x22BF;
  9270. t['rihiragana'] = 0x308A;
  9271. t['rikatakana'] = 0x30EA;
  9272. t['rikatakanahalfwidth'] = 0xFF98;
  9273. t['ring'] = 0x02DA;
  9274. t['ringbelowcmb'] = 0x0325;
  9275. t['ringcmb'] = 0x030A;
  9276. t['ringhalfleft'] = 0x02BF;
  9277. t['ringhalfleftarmenian'] = 0x0559;
  9278. t['ringhalfleftbelowcmb'] = 0x031C;
  9279. t['ringhalfleftcentered'] = 0x02D3;
  9280. t['ringhalfright'] = 0x02BE;
  9281. t['ringhalfrightbelowcmb'] = 0x0339;
  9282. t['ringhalfrightcentered'] = 0x02D2;
  9283. t['rinvertedbreve'] = 0x0213;
  9284. t['rittorusquare'] = 0x3351;
  9285. t['rlinebelow'] = 0x1E5F;
  9286. t['rlongleg'] = 0x027C;
  9287. t['rlonglegturned'] = 0x027A;
  9288. t['rmonospace'] = 0xFF52;
  9289. t['rohiragana'] = 0x308D;
  9290. t['rokatakana'] = 0x30ED;
  9291. t['rokatakanahalfwidth'] = 0xFF9B;
  9292. t['roruathai'] = 0x0E23;
  9293. t['rparen'] = 0x24AD;
  9294. t['rrabengali'] = 0x09DC;
  9295. t['rradeva'] = 0x0931;
  9296. t['rragurmukhi'] = 0x0A5C;
  9297. t['rreharabic'] = 0x0691;
  9298. t['rrehfinalarabic'] = 0xFB8D;
  9299. t['rrvocalicbengali'] = 0x09E0;
  9300. t['rrvocalicdeva'] = 0x0960;
  9301. t['rrvocalicgujarati'] = 0x0AE0;
  9302. t['rrvocalicvowelsignbengali'] = 0x09C4;
  9303. t['rrvocalicvowelsigndeva'] = 0x0944;
  9304. t['rrvocalicvowelsigngujarati'] = 0x0AC4;
  9305. t['rsuperior'] = 0xF6F1;
  9306. t['rtblock'] = 0x2590;
  9307. t['rturned'] = 0x0279;
  9308. t['rturnedsuperior'] = 0x02B4;
  9309. t['ruhiragana'] = 0x308B;
  9310. t['rukatakana'] = 0x30EB;
  9311. t['rukatakanahalfwidth'] = 0xFF99;
  9312. t['rupeemarkbengali'] = 0x09F2;
  9313. t['rupeesignbengali'] = 0x09F3;
  9314. t['rupiah'] = 0xF6DD;
  9315. t['ruthai'] = 0x0E24;
  9316. t['rvocalicbengali'] = 0x098B;
  9317. t['rvocalicdeva'] = 0x090B;
  9318. t['rvocalicgujarati'] = 0x0A8B;
  9319. t['rvocalicvowelsignbengali'] = 0x09C3;
  9320. t['rvocalicvowelsigndeva'] = 0x0943;
  9321. t['rvocalicvowelsigngujarati'] = 0x0AC3;
  9322. t['s'] = 0x0073;
  9323. t['sabengali'] = 0x09B8;
  9324. t['sacute'] = 0x015B;
  9325. t['sacutedotaccent'] = 0x1E65;
  9326. t['sadarabic'] = 0x0635;
  9327. t['sadeva'] = 0x0938;
  9328. t['sadfinalarabic'] = 0xFEBA;
  9329. t['sadinitialarabic'] = 0xFEBB;
  9330. t['sadmedialarabic'] = 0xFEBC;
  9331. t['sagujarati'] = 0x0AB8;
  9332. t['sagurmukhi'] = 0x0A38;
  9333. t['sahiragana'] = 0x3055;
  9334. t['sakatakana'] = 0x30B5;
  9335. t['sakatakanahalfwidth'] = 0xFF7B;
  9336. t['sallallahoualayhewasallamarabic'] = 0xFDFA;
  9337. t['samekh'] = 0x05E1;
  9338. t['samekhdagesh'] = 0xFB41;
  9339. t['samekhdageshhebrew'] = 0xFB41;
  9340. t['samekhhebrew'] = 0x05E1;
  9341. t['saraaathai'] = 0x0E32;
  9342. t['saraaethai'] = 0x0E41;
  9343. t['saraaimaimalaithai'] = 0x0E44;
  9344. t['saraaimaimuanthai'] = 0x0E43;
  9345. t['saraamthai'] = 0x0E33;
  9346. t['saraathai'] = 0x0E30;
  9347. t['saraethai'] = 0x0E40;
  9348. t['saraiileftthai'] = 0xF886;
  9349. t['saraiithai'] = 0x0E35;
  9350. t['saraileftthai'] = 0xF885;
  9351. t['saraithai'] = 0x0E34;
  9352. t['saraothai'] = 0x0E42;
  9353. t['saraueeleftthai'] = 0xF888;
  9354. t['saraueethai'] = 0x0E37;
  9355. t['saraueleftthai'] = 0xF887;
  9356. t['sarauethai'] = 0x0E36;
  9357. t['sarauthai'] = 0x0E38;
  9358. t['sarauuthai'] = 0x0E39;
  9359. t['sbopomofo'] = 0x3119;
  9360. t['scaron'] = 0x0161;
  9361. t['scarondotaccent'] = 0x1E67;
  9362. t['scedilla'] = 0x015F;
  9363. t['schwa'] = 0x0259;
  9364. t['schwacyrillic'] = 0x04D9;
  9365. t['schwadieresiscyrillic'] = 0x04DB;
  9366. t['schwahook'] = 0x025A;
  9367. t['scircle'] = 0x24E2;
  9368. t['scircumflex'] = 0x015D;
  9369. t['scommaaccent'] = 0x0219;
  9370. t['sdotaccent'] = 0x1E61;
  9371. t['sdotbelow'] = 0x1E63;
  9372. t['sdotbelowdotaccent'] = 0x1E69;
  9373. t['seagullbelowcmb'] = 0x033C;
  9374. t['second'] = 0x2033;
  9375. t['secondtonechinese'] = 0x02CA;
  9376. t['section'] = 0x00A7;
  9377. t['seenarabic'] = 0x0633;
  9378. t['seenfinalarabic'] = 0xFEB2;
  9379. t['seeninitialarabic'] = 0xFEB3;
  9380. t['seenmedialarabic'] = 0xFEB4;
  9381. t['segol'] = 0x05B6;
  9382. t['segol13'] = 0x05B6;
  9383. t['segol1f'] = 0x05B6;
  9384. t['segol2c'] = 0x05B6;
  9385. t['segolhebrew'] = 0x05B6;
  9386. t['segolnarrowhebrew'] = 0x05B6;
  9387. t['segolquarterhebrew'] = 0x05B6;
  9388. t['segoltahebrew'] = 0x0592;
  9389. t['segolwidehebrew'] = 0x05B6;
  9390. t['seharmenian'] = 0x057D;
  9391. t['sehiragana'] = 0x305B;
  9392. t['sekatakana'] = 0x30BB;
  9393. t['sekatakanahalfwidth'] = 0xFF7E;
  9394. t['semicolon'] = 0x003B;
  9395. t['semicolonarabic'] = 0x061B;
  9396. t['semicolonmonospace'] = 0xFF1B;
  9397. t['semicolonsmall'] = 0xFE54;
  9398. t['semivoicedmarkkana'] = 0x309C;
  9399. t['semivoicedmarkkanahalfwidth'] = 0xFF9F;
  9400. t['sentisquare'] = 0x3322;
  9401. t['sentosquare'] = 0x3323;
  9402. t['seven'] = 0x0037;
  9403. t['sevenarabic'] = 0x0667;
  9404. t['sevenbengali'] = 0x09ED;
  9405. t['sevencircle'] = 0x2466;
  9406. t['sevencircleinversesansserif'] = 0x2790;
  9407. t['sevendeva'] = 0x096D;
  9408. t['seveneighths'] = 0x215E;
  9409. t['sevengujarati'] = 0x0AED;
  9410. t['sevengurmukhi'] = 0x0A6D;
  9411. t['sevenhackarabic'] = 0x0667;
  9412. t['sevenhangzhou'] = 0x3027;
  9413. t['sevenideographicparen'] = 0x3226;
  9414. t['seveninferior'] = 0x2087;
  9415. t['sevenmonospace'] = 0xFF17;
  9416. t['sevenoldstyle'] = 0xF737;
  9417. t['sevenparen'] = 0x247A;
  9418. t['sevenperiod'] = 0x248E;
  9419. t['sevenpersian'] = 0x06F7;
  9420. t['sevenroman'] = 0x2176;
  9421. t['sevensuperior'] = 0x2077;
  9422. t['seventeencircle'] = 0x2470;
  9423. t['seventeenparen'] = 0x2484;
  9424. t['seventeenperiod'] = 0x2498;
  9425. t['seventhai'] = 0x0E57;
  9426. t['sfthyphen'] = 0x00AD;
  9427. t['shaarmenian'] = 0x0577;
  9428. t['shabengali'] = 0x09B6;
  9429. t['shacyrillic'] = 0x0448;
  9430. t['shaddaarabic'] = 0x0651;
  9431. t['shaddadammaarabic'] = 0xFC61;
  9432. t['shaddadammatanarabic'] = 0xFC5E;
  9433. t['shaddafathaarabic'] = 0xFC60;
  9434. t['shaddakasraarabic'] = 0xFC62;
  9435. t['shaddakasratanarabic'] = 0xFC5F;
  9436. t['shade'] = 0x2592;
  9437. t['shadedark'] = 0x2593;
  9438. t['shadelight'] = 0x2591;
  9439. t['shademedium'] = 0x2592;
  9440. t['shadeva'] = 0x0936;
  9441. t['shagujarati'] = 0x0AB6;
  9442. t['shagurmukhi'] = 0x0A36;
  9443. t['shalshelethebrew'] = 0x0593;
  9444. t['shbopomofo'] = 0x3115;
  9445. t['shchacyrillic'] = 0x0449;
  9446. t['sheenarabic'] = 0x0634;
  9447. t['sheenfinalarabic'] = 0xFEB6;
  9448. t['sheeninitialarabic'] = 0xFEB7;
  9449. t['sheenmedialarabic'] = 0xFEB8;
  9450. t['sheicoptic'] = 0x03E3;
  9451. t['sheqel'] = 0x20AA;
  9452. t['sheqelhebrew'] = 0x20AA;
  9453. t['sheva'] = 0x05B0;
  9454. t['sheva115'] = 0x05B0;
  9455. t['sheva15'] = 0x05B0;
  9456. t['sheva22'] = 0x05B0;
  9457. t['sheva2e'] = 0x05B0;
  9458. t['shevahebrew'] = 0x05B0;
  9459. t['shevanarrowhebrew'] = 0x05B0;
  9460. t['shevaquarterhebrew'] = 0x05B0;
  9461. t['shevawidehebrew'] = 0x05B0;
  9462. t['shhacyrillic'] = 0x04BB;
  9463. t['shimacoptic'] = 0x03ED;
  9464. t['shin'] = 0x05E9;
  9465. t['shindagesh'] = 0xFB49;
  9466. t['shindageshhebrew'] = 0xFB49;
  9467. t['shindageshshindot'] = 0xFB2C;
  9468. t['shindageshshindothebrew'] = 0xFB2C;
  9469. t['shindageshsindot'] = 0xFB2D;
  9470. t['shindageshsindothebrew'] = 0xFB2D;
  9471. t['shindothebrew'] = 0x05C1;
  9472. t['shinhebrew'] = 0x05E9;
  9473. t['shinshindot'] = 0xFB2A;
  9474. t['shinshindothebrew'] = 0xFB2A;
  9475. t['shinsindot'] = 0xFB2B;
  9476. t['shinsindothebrew'] = 0xFB2B;
  9477. t['shook'] = 0x0282;
  9478. t['sigma'] = 0x03C3;
  9479. t['sigma1'] = 0x03C2;
  9480. t['sigmafinal'] = 0x03C2;
  9481. t['sigmalunatesymbolgreek'] = 0x03F2;
  9482. t['sihiragana'] = 0x3057;
  9483. t['sikatakana'] = 0x30B7;
  9484. t['sikatakanahalfwidth'] = 0xFF7C;
  9485. t['siluqhebrew'] = 0x05BD;
  9486. t['siluqlefthebrew'] = 0x05BD;
  9487. t['similar'] = 0x223C;
  9488. t['sindothebrew'] = 0x05C2;
  9489. t['siosacirclekorean'] = 0x3274;
  9490. t['siosaparenkorean'] = 0x3214;
  9491. t['sioscieuckorean'] = 0x317E;
  9492. t['sioscirclekorean'] = 0x3266;
  9493. t['sioskiyeokkorean'] = 0x317A;
  9494. t['sioskorean'] = 0x3145;
  9495. t['siosnieunkorean'] = 0x317B;
  9496. t['siosparenkorean'] = 0x3206;
  9497. t['siospieupkorean'] = 0x317D;
  9498. t['siostikeutkorean'] = 0x317C;
  9499. t['six'] = 0x0036;
  9500. t['sixarabic'] = 0x0666;
  9501. t['sixbengali'] = 0x09EC;
  9502. t['sixcircle'] = 0x2465;
  9503. t['sixcircleinversesansserif'] = 0x278F;
  9504. t['sixdeva'] = 0x096C;
  9505. t['sixgujarati'] = 0x0AEC;
  9506. t['sixgurmukhi'] = 0x0A6C;
  9507. t['sixhackarabic'] = 0x0666;
  9508. t['sixhangzhou'] = 0x3026;
  9509. t['sixideographicparen'] = 0x3225;
  9510. t['sixinferior'] = 0x2086;
  9511. t['sixmonospace'] = 0xFF16;
  9512. t['sixoldstyle'] = 0xF736;
  9513. t['sixparen'] = 0x2479;
  9514. t['sixperiod'] = 0x248D;
  9515. t['sixpersian'] = 0x06F6;
  9516. t['sixroman'] = 0x2175;
  9517. t['sixsuperior'] = 0x2076;
  9518. t['sixteencircle'] = 0x246F;
  9519. t['sixteencurrencydenominatorbengali'] = 0x09F9;
  9520. t['sixteenparen'] = 0x2483;
  9521. t['sixteenperiod'] = 0x2497;
  9522. t['sixthai'] = 0x0E56;
  9523. t['slash'] = 0x002F;
  9524. t['slashmonospace'] = 0xFF0F;
  9525. t['slong'] = 0x017F;
  9526. t['slongdotaccent'] = 0x1E9B;
  9527. t['smileface'] = 0x263A;
  9528. t['smonospace'] = 0xFF53;
  9529. t['sofpasuqhebrew'] = 0x05C3;
  9530. t['softhyphen'] = 0x00AD;
  9531. t['softsigncyrillic'] = 0x044C;
  9532. t['sohiragana'] = 0x305D;
  9533. t['sokatakana'] = 0x30BD;
  9534. t['sokatakanahalfwidth'] = 0xFF7F;
  9535. t['soliduslongoverlaycmb'] = 0x0338;
  9536. t['solidusshortoverlaycmb'] = 0x0337;
  9537. t['sorusithai'] = 0x0E29;
  9538. t['sosalathai'] = 0x0E28;
  9539. t['sosothai'] = 0x0E0B;
  9540. t['sosuathai'] = 0x0E2A;
  9541. t['space'] = 0x0020;
  9542. t['spacehackarabic'] = 0x0020;
  9543. t['spade'] = 0x2660;
  9544. t['spadesuitblack'] = 0x2660;
  9545. t['spadesuitwhite'] = 0x2664;
  9546. t['sparen'] = 0x24AE;
  9547. t['squarebelowcmb'] = 0x033B;
  9548. t['squarecc'] = 0x33C4;
  9549. t['squarecm'] = 0x339D;
  9550. t['squarediagonalcrosshatchfill'] = 0x25A9;
  9551. t['squarehorizontalfill'] = 0x25A4;
  9552. t['squarekg'] = 0x338F;
  9553. t['squarekm'] = 0x339E;
  9554. t['squarekmcapital'] = 0x33CE;
  9555. t['squareln'] = 0x33D1;
  9556. t['squarelog'] = 0x33D2;
  9557. t['squaremg'] = 0x338E;
  9558. t['squaremil'] = 0x33D5;
  9559. t['squaremm'] = 0x339C;
  9560. t['squaremsquared'] = 0x33A1;
  9561. t['squareorthogonalcrosshatchfill'] = 0x25A6;
  9562. t['squareupperlefttolowerrightfill'] = 0x25A7;
  9563. t['squareupperrighttolowerleftfill'] = 0x25A8;
  9564. t['squareverticalfill'] = 0x25A5;
  9565. t['squarewhitewithsmallblack'] = 0x25A3;
  9566. t['srsquare'] = 0x33DB;
  9567. t['ssabengali'] = 0x09B7;
  9568. t['ssadeva'] = 0x0937;
  9569. t['ssagujarati'] = 0x0AB7;
  9570. t['ssangcieuckorean'] = 0x3149;
  9571. t['ssanghieuhkorean'] = 0x3185;
  9572. t['ssangieungkorean'] = 0x3180;
  9573. t['ssangkiyeokkorean'] = 0x3132;
  9574. t['ssangnieunkorean'] = 0x3165;
  9575. t['ssangpieupkorean'] = 0x3143;
  9576. t['ssangsioskorean'] = 0x3146;
  9577. t['ssangtikeutkorean'] = 0x3138;
  9578. t['ssuperior'] = 0xF6F2;
  9579. t['sterling'] = 0x00A3;
  9580. t['sterlingmonospace'] = 0xFFE1;
  9581. t['strokelongoverlaycmb'] = 0x0336;
  9582. t['strokeshortoverlaycmb'] = 0x0335;
  9583. t['subset'] = 0x2282;
  9584. t['subsetnotequal'] = 0x228A;
  9585. t['subsetorequal'] = 0x2286;
  9586. t['succeeds'] = 0x227B;
  9587. t['suchthat'] = 0x220B;
  9588. t['suhiragana'] = 0x3059;
  9589. t['sukatakana'] = 0x30B9;
  9590. t['sukatakanahalfwidth'] = 0xFF7D;
  9591. t['sukunarabic'] = 0x0652;
  9592. t['summation'] = 0x2211;
  9593. t['sun'] = 0x263C;
  9594. t['superset'] = 0x2283;
  9595. t['supersetnotequal'] = 0x228B;
  9596. t['supersetorequal'] = 0x2287;
  9597. t['svsquare'] = 0x33DC;
  9598. t['syouwaerasquare'] = 0x337C;
  9599. t['t'] = 0x0074;
  9600. t['tabengali'] = 0x09A4;
  9601. t['tackdown'] = 0x22A4;
  9602. t['tackleft'] = 0x22A3;
  9603. t['tadeva'] = 0x0924;
  9604. t['tagujarati'] = 0x0AA4;
  9605. t['tagurmukhi'] = 0x0A24;
  9606. t['taharabic'] = 0x0637;
  9607. t['tahfinalarabic'] = 0xFEC2;
  9608. t['tahinitialarabic'] = 0xFEC3;
  9609. t['tahiragana'] = 0x305F;
  9610. t['tahmedialarabic'] = 0xFEC4;
  9611. t['taisyouerasquare'] = 0x337D;
  9612. t['takatakana'] = 0x30BF;
  9613. t['takatakanahalfwidth'] = 0xFF80;
  9614. t['tatweelarabic'] = 0x0640;
  9615. t['tau'] = 0x03C4;
  9616. t['tav'] = 0x05EA;
  9617. t['tavdages'] = 0xFB4A;
  9618. t['tavdagesh'] = 0xFB4A;
  9619. t['tavdageshhebrew'] = 0xFB4A;
  9620. t['tavhebrew'] = 0x05EA;
  9621. t['tbar'] = 0x0167;
  9622. t['tbopomofo'] = 0x310A;
  9623. t['tcaron'] = 0x0165;
  9624. t['tccurl'] = 0x02A8;
  9625. t['tcedilla'] = 0x0163;
  9626. t['tcheharabic'] = 0x0686;
  9627. t['tchehfinalarabic'] = 0xFB7B;
  9628. t['tchehinitialarabic'] = 0xFB7C;
  9629. t['tchehmedialarabic'] = 0xFB7D;
  9630. t['tcircle'] = 0x24E3;
  9631. t['tcircumflexbelow'] = 0x1E71;
  9632. t['tcommaaccent'] = 0x0163;
  9633. t['tdieresis'] = 0x1E97;
  9634. t['tdotaccent'] = 0x1E6B;
  9635. t['tdotbelow'] = 0x1E6D;
  9636. t['tecyrillic'] = 0x0442;
  9637. t['tedescendercyrillic'] = 0x04AD;
  9638. t['teharabic'] = 0x062A;
  9639. t['tehfinalarabic'] = 0xFE96;
  9640. t['tehhahinitialarabic'] = 0xFCA2;
  9641. t['tehhahisolatedarabic'] = 0xFC0C;
  9642. t['tehinitialarabic'] = 0xFE97;
  9643. t['tehiragana'] = 0x3066;
  9644. t['tehjeeminitialarabic'] = 0xFCA1;
  9645. t['tehjeemisolatedarabic'] = 0xFC0B;
  9646. t['tehmarbutaarabic'] = 0x0629;
  9647. t['tehmarbutafinalarabic'] = 0xFE94;
  9648. t['tehmedialarabic'] = 0xFE98;
  9649. t['tehmeeminitialarabic'] = 0xFCA4;
  9650. t['tehmeemisolatedarabic'] = 0xFC0E;
  9651. t['tehnoonfinalarabic'] = 0xFC73;
  9652. t['tekatakana'] = 0x30C6;
  9653. t['tekatakanahalfwidth'] = 0xFF83;
  9654. t['telephone'] = 0x2121;
  9655. t['telephoneblack'] = 0x260E;
  9656. t['telishagedolahebrew'] = 0x05A0;
  9657. t['telishaqetanahebrew'] = 0x05A9;
  9658. t['tencircle'] = 0x2469;
  9659. t['tenideographicparen'] = 0x3229;
  9660. t['tenparen'] = 0x247D;
  9661. t['tenperiod'] = 0x2491;
  9662. t['tenroman'] = 0x2179;
  9663. t['tesh'] = 0x02A7;
  9664. t['tet'] = 0x05D8;
  9665. t['tetdagesh'] = 0xFB38;
  9666. t['tetdageshhebrew'] = 0xFB38;
  9667. t['tethebrew'] = 0x05D8;
  9668. t['tetsecyrillic'] = 0x04B5;
  9669. t['tevirhebrew'] = 0x059B;
  9670. t['tevirlefthebrew'] = 0x059B;
  9671. t['thabengali'] = 0x09A5;
  9672. t['thadeva'] = 0x0925;
  9673. t['thagujarati'] = 0x0AA5;
  9674. t['thagurmukhi'] = 0x0A25;
  9675. t['thalarabic'] = 0x0630;
  9676. t['thalfinalarabic'] = 0xFEAC;
  9677. t['thanthakhatlowleftthai'] = 0xF898;
  9678. t['thanthakhatlowrightthai'] = 0xF897;
  9679. t['thanthakhatthai'] = 0x0E4C;
  9680. t['thanthakhatupperleftthai'] = 0xF896;
  9681. t['theharabic'] = 0x062B;
  9682. t['thehfinalarabic'] = 0xFE9A;
  9683. t['thehinitialarabic'] = 0xFE9B;
  9684. t['thehmedialarabic'] = 0xFE9C;
  9685. t['thereexists'] = 0x2203;
  9686. t['therefore'] = 0x2234;
  9687. t['theta'] = 0x03B8;
  9688. t['theta1'] = 0x03D1;
  9689. t['thetasymbolgreek'] = 0x03D1;
  9690. t['thieuthacirclekorean'] = 0x3279;
  9691. t['thieuthaparenkorean'] = 0x3219;
  9692. t['thieuthcirclekorean'] = 0x326B;
  9693. t['thieuthkorean'] = 0x314C;
  9694. t['thieuthparenkorean'] = 0x320B;
  9695. t['thirteencircle'] = 0x246C;
  9696. t['thirteenparen'] = 0x2480;
  9697. t['thirteenperiod'] = 0x2494;
  9698. t['thonangmonthothai'] = 0x0E11;
  9699. t['thook'] = 0x01AD;
  9700. t['thophuthaothai'] = 0x0E12;
  9701. t['thorn'] = 0x00FE;
  9702. t['thothahanthai'] = 0x0E17;
  9703. t['thothanthai'] = 0x0E10;
  9704. t['thothongthai'] = 0x0E18;
  9705. t['thothungthai'] = 0x0E16;
  9706. t['thousandcyrillic'] = 0x0482;
  9707. t['thousandsseparatorarabic'] = 0x066C;
  9708. t['thousandsseparatorpersian'] = 0x066C;
  9709. t['three'] = 0x0033;
  9710. t['threearabic'] = 0x0663;
  9711. t['threebengali'] = 0x09E9;
  9712. t['threecircle'] = 0x2462;
  9713. t['threecircleinversesansserif'] = 0x278C;
  9714. t['threedeva'] = 0x0969;
  9715. t['threeeighths'] = 0x215C;
  9716. t['threegujarati'] = 0x0AE9;
  9717. t['threegurmukhi'] = 0x0A69;
  9718. t['threehackarabic'] = 0x0663;
  9719. t['threehangzhou'] = 0x3023;
  9720. t['threeideographicparen'] = 0x3222;
  9721. t['threeinferior'] = 0x2083;
  9722. t['threemonospace'] = 0xFF13;
  9723. t['threenumeratorbengali'] = 0x09F6;
  9724. t['threeoldstyle'] = 0xF733;
  9725. t['threeparen'] = 0x2476;
  9726. t['threeperiod'] = 0x248A;
  9727. t['threepersian'] = 0x06F3;
  9728. t['threequarters'] = 0x00BE;
  9729. t['threequartersemdash'] = 0xF6DE;
  9730. t['threeroman'] = 0x2172;
  9731. t['threesuperior'] = 0x00B3;
  9732. t['threethai'] = 0x0E53;
  9733. t['thzsquare'] = 0x3394;
  9734. t['tihiragana'] = 0x3061;
  9735. t['tikatakana'] = 0x30C1;
  9736. t['tikatakanahalfwidth'] = 0xFF81;
  9737. t['tikeutacirclekorean'] = 0x3270;
  9738. t['tikeutaparenkorean'] = 0x3210;
  9739. t['tikeutcirclekorean'] = 0x3262;
  9740. t['tikeutkorean'] = 0x3137;
  9741. t['tikeutparenkorean'] = 0x3202;
  9742. t['tilde'] = 0x02DC;
  9743. t['tildebelowcmb'] = 0x0330;
  9744. t['tildecmb'] = 0x0303;
  9745. t['tildecomb'] = 0x0303;
  9746. t['tildedoublecmb'] = 0x0360;
  9747. t['tildeoperator'] = 0x223C;
  9748. t['tildeoverlaycmb'] = 0x0334;
  9749. t['tildeverticalcmb'] = 0x033E;
  9750. t['timescircle'] = 0x2297;
  9751. t['tipehahebrew'] = 0x0596;
  9752. t['tipehalefthebrew'] = 0x0596;
  9753. t['tippigurmukhi'] = 0x0A70;
  9754. t['titlocyrilliccmb'] = 0x0483;
  9755. t['tiwnarmenian'] = 0x057F;
  9756. t['tlinebelow'] = 0x1E6F;
  9757. t['tmonospace'] = 0xFF54;
  9758. t['toarmenian'] = 0x0569;
  9759. t['tohiragana'] = 0x3068;
  9760. t['tokatakana'] = 0x30C8;
  9761. t['tokatakanahalfwidth'] = 0xFF84;
  9762. t['tonebarextrahighmod'] = 0x02E5;
  9763. t['tonebarextralowmod'] = 0x02E9;
  9764. t['tonebarhighmod'] = 0x02E6;
  9765. t['tonebarlowmod'] = 0x02E8;
  9766. t['tonebarmidmod'] = 0x02E7;
  9767. t['tonefive'] = 0x01BD;
  9768. t['tonesix'] = 0x0185;
  9769. t['tonetwo'] = 0x01A8;
  9770. t['tonos'] = 0x0384;
  9771. t['tonsquare'] = 0x3327;
  9772. t['topatakthai'] = 0x0E0F;
  9773. t['tortoiseshellbracketleft'] = 0x3014;
  9774. t['tortoiseshellbracketleftsmall'] = 0xFE5D;
  9775. t['tortoiseshellbracketleftvertical'] = 0xFE39;
  9776. t['tortoiseshellbracketright'] = 0x3015;
  9777. t['tortoiseshellbracketrightsmall'] = 0xFE5E;
  9778. t['tortoiseshellbracketrightvertical'] = 0xFE3A;
  9779. t['totaothai'] = 0x0E15;
  9780. t['tpalatalhook'] = 0x01AB;
  9781. t['tparen'] = 0x24AF;
  9782. t['trademark'] = 0x2122;
  9783. t['trademarksans'] = 0xF8EA;
  9784. t['trademarkserif'] = 0xF6DB;
  9785. t['tretroflexhook'] = 0x0288;
  9786. t['triagdn'] = 0x25BC;
  9787. t['triaglf'] = 0x25C4;
  9788. t['triagrt'] = 0x25BA;
  9789. t['triagup'] = 0x25B2;
  9790. t['ts'] = 0x02A6;
  9791. t['tsadi'] = 0x05E6;
  9792. t['tsadidagesh'] = 0xFB46;
  9793. t['tsadidageshhebrew'] = 0xFB46;
  9794. t['tsadihebrew'] = 0x05E6;
  9795. t['tsecyrillic'] = 0x0446;
  9796. t['tsere'] = 0x05B5;
  9797. t['tsere12'] = 0x05B5;
  9798. t['tsere1e'] = 0x05B5;
  9799. t['tsere2b'] = 0x05B5;
  9800. t['tserehebrew'] = 0x05B5;
  9801. t['tserenarrowhebrew'] = 0x05B5;
  9802. t['tserequarterhebrew'] = 0x05B5;
  9803. t['tserewidehebrew'] = 0x05B5;
  9804. t['tshecyrillic'] = 0x045B;
  9805. t['tsuperior'] = 0xF6F3;
  9806. t['ttabengali'] = 0x099F;
  9807. t['ttadeva'] = 0x091F;
  9808. t['ttagujarati'] = 0x0A9F;
  9809. t['ttagurmukhi'] = 0x0A1F;
  9810. t['tteharabic'] = 0x0679;
  9811. t['ttehfinalarabic'] = 0xFB67;
  9812. t['ttehinitialarabic'] = 0xFB68;
  9813. t['ttehmedialarabic'] = 0xFB69;
  9814. t['tthabengali'] = 0x09A0;
  9815. t['tthadeva'] = 0x0920;
  9816. t['tthagujarati'] = 0x0AA0;
  9817. t['tthagurmukhi'] = 0x0A20;
  9818. t['tturned'] = 0x0287;
  9819. t['tuhiragana'] = 0x3064;
  9820. t['tukatakana'] = 0x30C4;
  9821. t['tukatakanahalfwidth'] = 0xFF82;
  9822. t['tusmallhiragana'] = 0x3063;
  9823. t['tusmallkatakana'] = 0x30C3;
  9824. t['tusmallkatakanahalfwidth'] = 0xFF6F;
  9825. t['twelvecircle'] = 0x246B;
  9826. t['twelveparen'] = 0x247F;
  9827. t['twelveperiod'] = 0x2493;
  9828. t['twelveroman'] = 0x217B;
  9829. t['twentycircle'] = 0x2473;
  9830. t['twentyhangzhou'] = 0x5344;
  9831. t['twentyparen'] = 0x2487;
  9832. t['twentyperiod'] = 0x249B;
  9833. t['two'] = 0x0032;
  9834. t['twoarabic'] = 0x0662;
  9835. t['twobengali'] = 0x09E8;
  9836. t['twocircle'] = 0x2461;
  9837. t['twocircleinversesansserif'] = 0x278B;
  9838. t['twodeva'] = 0x0968;
  9839. t['twodotenleader'] = 0x2025;
  9840. t['twodotleader'] = 0x2025;
  9841. t['twodotleadervertical'] = 0xFE30;
  9842. t['twogujarati'] = 0x0AE8;
  9843. t['twogurmukhi'] = 0x0A68;
  9844. t['twohackarabic'] = 0x0662;
  9845. t['twohangzhou'] = 0x3022;
  9846. t['twoideographicparen'] = 0x3221;
  9847. t['twoinferior'] = 0x2082;
  9848. t['twomonospace'] = 0xFF12;
  9849. t['twonumeratorbengali'] = 0x09F5;
  9850. t['twooldstyle'] = 0xF732;
  9851. t['twoparen'] = 0x2475;
  9852. t['twoperiod'] = 0x2489;
  9853. t['twopersian'] = 0x06F2;
  9854. t['tworoman'] = 0x2171;
  9855. t['twostroke'] = 0x01BB;
  9856. t['twosuperior'] = 0x00B2;
  9857. t['twothai'] = 0x0E52;
  9858. t['twothirds'] = 0x2154;
  9859. t['u'] = 0x0075;
  9860. t['uacute'] = 0x00FA;
  9861. t['ubar'] = 0x0289;
  9862. t['ubengali'] = 0x0989;
  9863. t['ubopomofo'] = 0x3128;
  9864. t['ubreve'] = 0x016D;
  9865. t['ucaron'] = 0x01D4;
  9866. t['ucircle'] = 0x24E4;
  9867. t['ucircumflex'] = 0x00FB;
  9868. t['ucircumflexbelow'] = 0x1E77;
  9869. t['ucyrillic'] = 0x0443;
  9870. t['udattadeva'] = 0x0951;
  9871. t['udblacute'] = 0x0171;
  9872. t['udblgrave'] = 0x0215;
  9873. t['udeva'] = 0x0909;
  9874. t['udieresis'] = 0x00FC;
  9875. t['udieresisacute'] = 0x01D8;
  9876. t['udieresisbelow'] = 0x1E73;
  9877. t['udieresiscaron'] = 0x01DA;
  9878. t['udieresiscyrillic'] = 0x04F1;
  9879. t['udieresisgrave'] = 0x01DC;
  9880. t['udieresismacron'] = 0x01D6;
  9881. t['udotbelow'] = 0x1EE5;
  9882. t['ugrave'] = 0x00F9;
  9883. t['ugujarati'] = 0x0A89;
  9884. t['ugurmukhi'] = 0x0A09;
  9885. t['uhiragana'] = 0x3046;
  9886. t['uhookabove'] = 0x1EE7;
  9887. t['uhorn'] = 0x01B0;
  9888. t['uhornacute'] = 0x1EE9;
  9889. t['uhorndotbelow'] = 0x1EF1;
  9890. t['uhorngrave'] = 0x1EEB;
  9891. t['uhornhookabove'] = 0x1EED;
  9892. t['uhorntilde'] = 0x1EEF;
  9893. t['uhungarumlaut'] = 0x0171;
  9894. t['uhungarumlautcyrillic'] = 0x04F3;
  9895. t['uinvertedbreve'] = 0x0217;
  9896. t['ukatakana'] = 0x30A6;
  9897. t['ukatakanahalfwidth'] = 0xFF73;
  9898. t['ukcyrillic'] = 0x0479;
  9899. t['ukorean'] = 0x315C;
  9900. t['umacron'] = 0x016B;
  9901. t['umacroncyrillic'] = 0x04EF;
  9902. t['umacrondieresis'] = 0x1E7B;
  9903. t['umatragurmukhi'] = 0x0A41;
  9904. t['umonospace'] = 0xFF55;
  9905. t['underscore'] = 0x005F;
  9906. t['underscoredbl'] = 0x2017;
  9907. t['underscoremonospace'] = 0xFF3F;
  9908. t['underscorevertical'] = 0xFE33;
  9909. t['underscorewavy'] = 0xFE4F;
  9910. t['union'] = 0x222A;
  9911. t['universal'] = 0x2200;
  9912. t['uogonek'] = 0x0173;
  9913. t['uparen'] = 0x24B0;
  9914. t['upblock'] = 0x2580;
  9915. t['upperdothebrew'] = 0x05C4;
  9916. t['upsilon'] = 0x03C5;
  9917. t['upsilondieresis'] = 0x03CB;
  9918. t['upsilondieresistonos'] = 0x03B0;
  9919. t['upsilonlatin'] = 0x028A;
  9920. t['upsilontonos'] = 0x03CD;
  9921. t['uptackbelowcmb'] = 0x031D;
  9922. t['uptackmod'] = 0x02D4;
  9923. t['uragurmukhi'] = 0x0A73;
  9924. t['uring'] = 0x016F;
  9925. t['ushortcyrillic'] = 0x045E;
  9926. t['usmallhiragana'] = 0x3045;
  9927. t['usmallkatakana'] = 0x30A5;
  9928. t['usmallkatakanahalfwidth'] = 0xFF69;
  9929. t['ustraightcyrillic'] = 0x04AF;
  9930. t['ustraightstrokecyrillic'] = 0x04B1;
  9931. t['utilde'] = 0x0169;
  9932. t['utildeacute'] = 0x1E79;
  9933. t['utildebelow'] = 0x1E75;
  9934. t['uubengali'] = 0x098A;
  9935. t['uudeva'] = 0x090A;
  9936. t['uugujarati'] = 0x0A8A;
  9937. t['uugurmukhi'] = 0x0A0A;
  9938. t['uumatragurmukhi'] = 0x0A42;
  9939. t['uuvowelsignbengali'] = 0x09C2;
  9940. t['uuvowelsigndeva'] = 0x0942;
  9941. t['uuvowelsigngujarati'] = 0x0AC2;
  9942. t['uvowelsignbengali'] = 0x09C1;
  9943. t['uvowelsigndeva'] = 0x0941;
  9944. t['uvowelsigngujarati'] = 0x0AC1;
  9945. t['v'] = 0x0076;
  9946. t['vadeva'] = 0x0935;
  9947. t['vagujarati'] = 0x0AB5;
  9948. t['vagurmukhi'] = 0x0A35;
  9949. t['vakatakana'] = 0x30F7;
  9950. t['vav'] = 0x05D5;
  9951. t['vavdagesh'] = 0xFB35;
  9952. t['vavdagesh65'] = 0xFB35;
  9953. t['vavdageshhebrew'] = 0xFB35;
  9954. t['vavhebrew'] = 0x05D5;
  9955. t['vavholam'] = 0xFB4B;
  9956. t['vavholamhebrew'] = 0xFB4B;
  9957. t['vavvavhebrew'] = 0x05F0;
  9958. t['vavyodhebrew'] = 0x05F1;
  9959. t['vcircle'] = 0x24E5;
  9960. t['vdotbelow'] = 0x1E7F;
  9961. t['vecyrillic'] = 0x0432;
  9962. t['veharabic'] = 0x06A4;
  9963. t['vehfinalarabic'] = 0xFB6B;
  9964. t['vehinitialarabic'] = 0xFB6C;
  9965. t['vehmedialarabic'] = 0xFB6D;
  9966. t['vekatakana'] = 0x30F9;
  9967. t['venus'] = 0x2640;
  9968. t['verticalbar'] = 0x007C;
  9969. t['verticallineabovecmb'] = 0x030D;
  9970. t['verticallinebelowcmb'] = 0x0329;
  9971. t['verticallinelowmod'] = 0x02CC;
  9972. t['verticallinemod'] = 0x02C8;
  9973. t['vewarmenian'] = 0x057E;
  9974. t['vhook'] = 0x028B;
  9975. t['vikatakana'] = 0x30F8;
  9976. t['viramabengali'] = 0x09CD;
  9977. t['viramadeva'] = 0x094D;
  9978. t['viramagujarati'] = 0x0ACD;
  9979. t['visargabengali'] = 0x0983;
  9980. t['visargadeva'] = 0x0903;
  9981. t['visargagujarati'] = 0x0A83;
  9982. t['vmonospace'] = 0xFF56;
  9983. t['voarmenian'] = 0x0578;
  9984. t['voicediterationhiragana'] = 0x309E;
  9985. t['voicediterationkatakana'] = 0x30FE;
  9986. t['voicedmarkkana'] = 0x309B;
  9987. t['voicedmarkkanahalfwidth'] = 0xFF9E;
  9988. t['vokatakana'] = 0x30FA;
  9989. t['vparen'] = 0x24B1;
  9990. t['vtilde'] = 0x1E7D;
  9991. t['vturned'] = 0x028C;
  9992. t['vuhiragana'] = 0x3094;
  9993. t['vukatakana'] = 0x30F4;
  9994. t['w'] = 0x0077;
  9995. t['wacute'] = 0x1E83;
  9996. t['waekorean'] = 0x3159;
  9997. t['wahiragana'] = 0x308F;
  9998. t['wakatakana'] = 0x30EF;
  9999. t['wakatakanahalfwidth'] = 0xFF9C;
  10000. t['wakorean'] = 0x3158;
  10001. t['wasmallhiragana'] = 0x308E;
  10002. t['wasmallkatakana'] = 0x30EE;
  10003. t['wattosquare'] = 0x3357;
  10004. t['wavedash'] = 0x301C;
  10005. t['wavyunderscorevertical'] = 0xFE34;
  10006. t['wawarabic'] = 0x0648;
  10007. t['wawfinalarabic'] = 0xFEEE;
  10008. t['wawhamzaabovearabic'] = 0x0624;
  10009. t['wawhamzaabovefinalarabic'] = 0xFE86;
  10010. t['wbsquare'] = 0x33DD;
  10011. t['wcircle'] = 0x24E6;
  10012. t['wcircumflex'] = 0x0175;
  10013. t['wdieresis'] = 0x1E85;
  10014. t['wdotaccent'] = 0x1E87;
  10015. t['wdotbelow'] = 0x1E89;
  10016. t['wehiragana'] = 0x3091;
  10017. t['weierstrass'] = 0x2118;
  10018. t['wekatakana'] = 0x30F1;
  10019. t['wekorean'] = 0x315E;
  10020. t['weokorean'] = 0x315D;
  10021. t['wgrave'] = 0x1E81;
  10022. t['whitebullet'] = 0x25E6;
  10023. t['whitecircle'] = 0x25CB;
  10024. t['whitecircleinverse'] = 0x25D9;
  10025. t['whitecornerbracketleft'] = 0x300E;
  10026. t['whitecornerbracketleftvertical'] = 0xFE43;
  10027. t['whitecornerbracketright'] = 0x300F;
  10028. t['whitecornerbracketrightvertical'] = 0xFE44;
  10029. t['whitediamond'] = 0x25C7;
  10030. t['whitediamondcontainingblacksmalldiamond'] = 0x25C8;
  10031. t['whitedownpointingsmalltriangle'] = 0x25BF;
  10032. t['whitedownpointingtriangle'] = 0x25BD;
  10033. t['whiteleftpointingsmalltriangle'] = 0x25C3;
  10034. t['whiteleftpointingtriangle'] = 0x25C1;
  10035. t['whitelenticularbracketleft'] = 0x3016;
  10036. t['whitelenticularbracketright'] = 0x3017;
  10037. t['whiterightpointingsmalltriangle'] = 0x25B9;
  10038. t['whiterightpointingtriangle'] = 0x25B7;
  10039. t['whitesmallsquare'] = 0x25AB;
  10040. t['whitesmilingface'] = 0x263A;
  10041. t['whitesquare'] = 0x25A1;
  10042. t['whitestar'] = 0x2606;
  10043. t['whitetelephone'] = 0x260F;
  10044. t['whitetortoiseshellbracketleft'] = 0x3018;
  10045. t['whitetortoiseshellbracketright'] = 0x3019;
  10046. t['whiteuppointingsmalltriangle'] = 0x25B5;
  10047. t['whiteuppointingtriangle'] = 0x25B3;
  10048. t['wihiragana'] = 0x3090;
  10049. t['wikatakana'] = 0x30F0;
  10050. t['wikorean'] = 0x315F;
  10051. t['wmonospace'] = 0xFF57;
  10052. t['wohiragana'] = 0x3092;
  10053. t['wokatakana'] = 0x30F2;
  10054. t['wokatakanahalfwidth'] = 0xFF66;
  10055. t['won'] = 0x20A9;
  10056. t['wonmonospace'] = 0xFFE6;
  10057. t['wowaenthai'] = 0x0E27;
  10058. t['wparen'] = 0x24B2;
  10059. t['wring'] = 0x1E98;
  10060. t['wsuperior'] = 0x02B7;
  10061. t['wturned'] = 0x028D;
  10062. t['wynn'] = 0x01BF;
  10063. t['x'] = 0x0078;
  10064. t['xabovecmb'] = 0x033D;
  10065. t['xbopomofo'] = 0x3112;
  10066. t['xcircle'] = 0x24E7;
  10067. t['xdieresis'] = 0x1E8D;
  10068. t['xdotaccent'] = 0x1E8B;
  10069. t['xeharmenian'] = 0x056D;
  10070. t['xi'] = 0x03BE;
  10071. t['xmonospace'] = 0xFF58;
  10072. t['xparen'] = 0x24B3;
  10073. t['xsuperior'] = 0x02E3;
  10074. t['y'] = 0x0079;
  10075. t['yaadosquare'] = 0x334E;
  10076. t['yabengali'] = 0x09AF;
  10077. t['yacute'] = 0x00FD;
  10078. t['yadeva'] = 0x092F;
  10079. t['yaekorean'] = 0x3152;
  10080. t['yagujarati'] = 0x0AAF;
  10081. t['yagurmukhi'] = 0x0A2F;
  10082. t['yahiragana'] = 0x3084;
  10083. t['yakatakana'] = 0x30E4;
  10084. t['yakatakanahalfwidth'] = 0xFF94;
  10085. t['yakorean'] = 0x3151;
  10086. t['yamakkanthai'] = 0x0E4E;
  10087. t['yasmallhiragana'] = 0x3083;
  10088. t['yasmallkatakana'] = 0x30E3;
  10089. t['yasmallkatakanahalfwidth'] = 0xFF6C;
  10090. t['yatcyrillic'] = 0x0463;
  10091. t['ycircle'] = 0x24E8;
  10092. t['ycircumflex'] = 0x0177;
  10093. t['ydieresis'] = 0x00FF;
  10094. t['ydotaccent'] = 0x1E8F;
  10095. t['ydotbelow'] = 0x1EF5;
  10096. t['yeharabic'] = 0x064A;
  10097. t['yehbarreearabic'] = 0x06D2;
  10098. t['yehbarreefinalarabic'] = 0xFBAF;
  10099. t['yehfinalarabic'] = 0xFEF2;
  10100. t['yehhamzaabovearabic'] = 0x0626;
  10101. t['yehhamzaabovefinalarabic'] = 0xFE8A;
  10102. t['yehhamzaaboveinitialarabic'] = 0xFE8B;
  10103. t['yehhamzaabovemedialarabic'] = 0xFE8C;
  10104. t['yehinitialarabic'] = 0xFEF3;
  10105. t['yehmedialarabic'] = 0xFEF4;
  10106. t['yehmeeminitialarabic'] = 0xFCDD;
  10107. t['yehmeemisolatedarabic'] = 0xFC58;
  10108. t['yehnoonfinalarabic'] = 0xFC94;
  10109. t['yehthreedotsbelowarabic'] = 0x06D1;
  10110. t['yekorean'] = 0x3156;
  10111. t['yen'] = 0x00A5;
  10112. t['yenmonospace'] = 0xFFE5;
  10113. t['yeokorean'] = 0x3155;
  10114. t['yeorinhieuhkorean'] = 0x3186;
  10115. t['yerahbenyomohebrew'] = 0x05AA;
  10116. t['yerahbenyomolefthebrew'] = 0x05AA;
  10117. t['yericyrillic'] = 0x044B;
  10118. t['yerudieresiscyrillic'] = 0x04F9;
  10119. t['yesieungkorean'] = 0x3181;
  10120. t['yesieungpansioskorean'] = 0x3183;
  10121. t['yesieungsioskorean'] = 0x3182;
  10122. t['yetivhebrew'] = 0x059A;
  10123. t['ygrave'] = 0x1EF3;
  10124. t['yhook'] = 0x01B4;
  10125. t['yhookabove'] = 0x1EF7;
  10126. t['yiarmenian'] = 0x0575;
  10127. t['yicyrillic'] = 0x0457;
  10128. t['yikorean'] = 0x3162;
  10129. t['yinyang'] = 0x262F;
  10130. t['yiwnarmenian'] = 0x0582;
  10131. t['ymonospace'] = 0xFF59;
  10132. t['yod'] = 0x05D9;
  10133. t['yoddagesh'] = 0xFB39;
  10134. t['yoddageshhebrew'] = 0xFB39;
  10135. t['yodhebrew'] = 0x05D9;
  10136. t['yodyodhebrew'] = 0x05F2;
  10137. t['yodyodpatahhebrew'] = 0xFB1F;
  10138. t['yohiragana'] = 0x3088;
  10139. t['yoikorean'] = 0x3189;
  10140. t['yokatakana'] = 0x30E8;
  10141. t['yokatakanahalfwidth'] = 0xFF96;
  10142. t['yokorean'] = 0x315B;
  10143. t['yosmallhiragana'] = 0x3087;
  10144. t['yosmallkatakana'] = 0x30E7;
  10145. t['yosmallkatakanahalfwidth'] = 0xFF6E;
  10146. t['yotgreek'] = 0x03F3;
  10147. t['yoyaekorean'] = 0x3188;
  10148. t['yoyakorean'] = 0x3187;
  10149. t['yoyakthai'] = 0x0E22;
  10150. t['yoyingthai'] = 0x0E0D;
  10151. t['yparen'] = 0x24B4;
  10152. t['ypogegrammeni'] = 0x037A;
  10153. t['ypogegrammenigreekcmb'] = 0x0345;
  10154. t['yr'] = 0x01A6;
  10155. t['yring'] = 0x1E99;
  10156. t['ysuperior'] = 0x02B8;
  10157. t['ytilde'] = 0x1EF9;
  10158. t['yturned'] = 0x028E;
  10159. t['yuhiragana'] = 0x3086;
  10160. t['yuikorean'] = 0x318C;
  10161. t['yukatakana'] = 0x30E6;
  10162. t['yukatakanahalfwidth'] = 0xFF95;
  10163. t['yukorean'] = 0x3160;
  10164. t['yusbigcyrillic'] = 0x046B;
  10165. t['yusbigiotifiedcyrillic'] = 0x046D;
  10166. t['yuslittlecyrillic'] = 0x0467;
  10167. t['yuslittleiotifiedcyrillic'] = 0x0469;
  10168. t['yusmallhiragana'] = 0x3085;
  10169. t['yusmallkatakana'] = 0x30E5;
  10170. t['yusmallkatakanahalfwidth'] = 0xFF6D;
  10171. t['yuyekorean'] = 0x318B;
  10172. t['yuyeokorean'] = 0x318A;
  10173. t['yyabengali'] = 0x09DF;
  10174. t['yyadeva'] = 0x095F;
  10175. t['z'] = 0x007A;
  10176. t['zaarmenian'] = 0x0566;
  10177. t['zacute'] = 0x017A;
  10178. t['zadeva'] = 0x095B;
  10179. t['zagurmukhi'] = 0x0A5B;
  10180. t['zaharabic'] = 0x0638;
  10181. t['zahfinalarabic'] = 0xFEC6;
  10182. t['zahinitialarabic'] = 0xFEC7;
  10183. t['zahiragana'] = 0x3056;
  10184. t['zahmedialarabic'] = 0xFEC8;
  10185. t['zainarabic'] = 0x0632;
  10186. t['zainfinalarabic'] = 0xFEB0;
  10187. t['zakatakana'] = 0x30B6;
  10188. t['zaqefgadolhebrew'] = 0x0595;
  10189. t['zaqefqatanhebrew'] = 0x0594;
  10190. t['zarqahebrew'] = 0x0598;
  10191. t['zayin'] = 0x05D6;
  10192. t['zayindagesh'] = 0xFB36;
  10193. t['zayindageshhebrew'] = 0xFB36;
  10194. t['zayinhebrew'] = 0x05D6;
  10195. t['zbopomofo'] = 0x3117;
  10196. t['zcaron'] = 0x017E;
  10197. t['zcircle'] = 0x24E9;
  10198. t['zcircumflex'] = 0x1E91;
  10199. t['zcurl'] = 0x0291;
  10200. t['zdot'] = 0x017C;
  10201. t['zdotaccent'] = 0x017C;
  10202. t['zdotbelow'] = 0x1E93;
  10203. t['zecyrillic'] = 0x0437;
  10204. t['zedescendercyrillic'] = 0x0499;
  10205. t['zedieresiscyrillic'] = 0x04DF;
  10206. t['zehiragana'] = 0x305C;
  10207. t['zekatakana'] = 0x30BC;
  10208. t['zero'] = 0x0030;
  10209. t['zeroarabic'] = 0x0660;
  10210. t['zerobengali'] = 0x09E6;
  10211. t['zerodeva'] = 0x0966;
  10212. t['zerogujarati'] = 0x0AE6;
  10213. t['zerogurmukhi'] = 0x0A66;
  10214. t['zerohackarabic'] = 0x0660;
  10215. t['zeroinferior'] = 0x2080;
  10216. t['zeromonospace'] = 0xFF10;
  10217. t['zerooldstyle'] = 0xF730;
  10218. t['zeropersian'] = 0x06F0;
  10219. t['zerosuperior'] = 0x2070;
  10220. t['zerothai'] = 0x0E50;
  10221. t['zerowidthjoiner'] = 0xFEFF;
  10222. t['zerowidthnonjoiner'] = 0x200C;
  10223. t['zerowidthspace'] = 0x200B;
  10224. t['zeta'] = 0x03B6;
  10225. t['zhbopomofo'] = 0x3113;
  10226. t['zhearmenian'] = 0x056A;
  10227. t['zhebrevecyrillic'] = 0x04C2;
  10228. t['zhecyrillic'] = 0x0436;
  10229. t['zhedescendercyrillic'] = 0x0497;
  10230. t['zhedieresiscyrillic'] = 0x04DD;
  10231. t['zihiragana'] = 0x3058;
  10232. t['zikatakana'] = 0x30B8;
  10233. t['zinorhebrew'] = 0x05AE;
  10234. t['zlinebelow'] = 0x1E95;
  10235. t['zmonospace'] = 0xFF5A;
  10236. t['zohiragana'] = 0x305E;
  10237. t['zokatakana'] = 0x30BE;
  10238. t['zparen'] = 0x24B5;
  10239. t['zretroflexhook'] = 0x0290;
  10240. t['zstroke'] = 0x01B6;
  10241. t['zuhiragana'] = 0x305A;
  10242. t['zukatakana'] = 0x30BA;
  10243. t['.notdef'] = 0x0000;
  10244. });
  10245. var getDingbatsGlyphsUnicode = getLookupTableFactory(function (t) {
  10246. t['space'] = 0x0020;
  10247. t['a1'] = 0x2701;
  10248. t['a2'] = 0x2702;
  10249. t['a202'] = 0x2703;
  10250. t['a3'] = 0x2704;
  10251. t['a4'] = 0x260E;
  10252. t['a5'] = 0x2706;
  10253. t['a119'] = 0x2707;
  10254. t['a118'] = 0x2708;
  10255. t['a117'] = 0x2709;
  10256. t['a11'] = 0x261B;
  10257. t['a12'] = 0x261E;
  10258. t['a13'] = 0x270C;
  10259. t['a14'] = 0x270D;
  10260. t['a15'] = 0x270E;
  10261. t['a16'] = 0x270F;
  10262. t['a105'] = 0x2710;
  10263. t['a17'] = 0x2711;
  10264. t['a18'] = 0x2712;
  10265. t['a19'] = 0x2713;
  10266. t['a20'] = 0x2714;
  10267. t['a21'] = 0x2715;
  10268. t['a22'] = 0x2716;
  10269. t['a23'] = 0x2717;
  10270. t['a24'] = 0x2718;
  10271. t['a25'] = 0x2719;
  10272. t['a26'] = 0x271A;
  10273. t['a27'] = 0x271B;
  10274. t['a28'] = 0x271C;
  10275. t['a6'] = 0x271D;
  10276. t['a7'] = 0x271E;
  10277. t['a8'] = 0x271F;
  10278. t['a9'] = 0x2720;
  10279. t['a10'] = 0x2721;
  10280. t['a29'] = 0x2722;
  10281. t['a30'] = 0x2723;
  10282. t['a31'] = 0x2724;
  10283. t['a32'] = 0x2725;
  10284. t['a33'] = 0x2726;
  10285. t['a34'] = 0x2727;
  10286. t['a35'] = 0x2605;
  10287. t['a36'] = 0x2729;
  10288. t['a37'] = 0x272A;
  10289. t['a38'] = 0x272B;
  10290. t['a39'] = 0x272C;
  10291. t['a40'] = 0x272D;
  10292. t['a41'] = 0x272E;
  10293. t['a42'] = 0x272F;
  10294. t['a43'] = 0x2730;
  10295. t['a44'] = 0x2731;
  10296. t['a45'] = 0x2732;
  10297. t['a46'] = 0x2733;
  10298. t['a47'] = 0x2734;
  10299. t['a48'] = 0x2735;
  10300. t['a49'] = 0x2736;
  10301. t['a50'] = 0x2737;
  10302. t['a51'] = 0x2738;
  10303. t['a52'] = 0x2739;
  10304. t['a53'] = 0x273A;
  10305. t['a54'] = 0x273B;
  10306. t['a55'] = 0x273C;
  10307. t['a56'] = 0x273D;
  10308. t['a57'] = 0x273E;
  10309. t['a58'] = 0x273F;
  10310. t['a59'] = 0x2740;
  10311. t['a60'] = 0x2741;
  10312. t['a61'] = 0x2742;
  10313. t['a62'] = 0x2743;
  10314. t['a63'] = 0x2744;
  10315. t['a64'] = 0x2745;
  10316. t['a65'] = 0x2746;
  10317. t['a66'] = 0x2747;
  10318. t['a67'] = 0x2748;
  10319. t['a68'] = 0x2749;
  10320. t['a69'] = 0x274A;
  10321. t['a70'] = 0x274B;
  10322. t['a71'] = 0x25CF;
  10323. t['a72'] = 0x274D;
  10324. t['a73'] = 0x25A0;
  10325. t['a74'] = 0x274F;
  10326. t['a203'] = 0x2750;
  10327. t['a75'] = 0x2751;
  10328. t['a204'] = 0x2752;
  10329. t['a76'] = 0x25B2;
  10330. t['a77'] = 0x25BC;
  10331. t['a78'] = 0x25C6;
  10332. t['a79'] = 0x2756;
  10333. t['a81'] = 0x25D7;
  10334. t['a82'] = 0x2758;
  10335. t['a83'] = 0x2759;
  10336. t['a84'] = 0x275A;
  10337. t['a97'] = 0x275B;
  10338. t['a98'] = 0x275C;
  10339. t['a99'] = 0x275D;
  10340. t['a100'] = 0x275E;
  10341. t['a101'] = 0x2761;
  10342. t['a102'] = 0x2762;
  10343. t['a103'] = 0x2763;
  10344. t['a104'] = 0x2764;
  10345. t['a106'] = 0x2765;
  10346. t['a107'] = 0x2766;
  10347. t['a108'] = 0x2767;
  10348. t['a112'] = 0x2663;
  10349. t['a111'] = 0x2666;
  10350. t['a110'] = 0x2665;
  10351. t['a109'] = 0x2660;
  10352. t['a120'] = 0x2460;
  10353. t['a121'] = 0x2461;
  10354. t['a122'] = 0x2462;
  10355. t['a123'] = 0x2463;
  10356. t['a124'] = 0x2464;
  10357. t['a125'] = 0x2465;
  10358. t['a126'] = 0x2466;
  10359. t['a127'] = 0x2467;
  10360. t['a128'] = 0x2468;
  10361. t['a129'] = 0x2469;
  10362. t['a130'] = 0x2776;
  10363. t['a131'] = 0x2777;
  10364. t['a132'] = 0x2778;
  10365. t['a133'] = 0x2779;
  10366. t['a134'] = 0x277A;
  10367. t['a135'] = 0x277B;
  10368. t['a136'] = 0x277C;
  10369. t['a137'] = 0x277D;
  10370. t['a138'] = 0x277E;
  10371. t['a139'] = 0x277F;
  10372. t['a140'] = 0x2780;
  10373. t['a141'] = 0x2781;
  10374. t['a142'] = 0x2782;
  10375. t['a143'] = 0x2783;
  10376. t['a144'] = 0x2784;
  10377. t['a145'] = 0x2785;
  10378. t['a146'] = 0x2786;
  10379. t['a147'] = 0x2787;
  10380. t['a148'] = 0x2788;
  10381. t['a149'] = 0x2789;
  10382. t['a150'] = 0x278A;
  10383. t['a151'] = 0x278B;
  10384. t['a152'] = 0x278C;
  10385. t['a153'] = 0x278D;
  10386. t['a154'] = 0x278E;
  10387. t['a155'] = 0x278F;
  10388. t['a156'] = 0x2790;
  10389. t['a157'] = 0x2791;
  10390. t['a158'] = 0x2792;
  10391. t['a159'] = 0x2793;
  10392. t['a160'] = 0x2794;
  10393. t['a161'] = 0x2192;
  10394. t['a163'] = 0x2194;
  10395. t['a164'] = 0x2195;
  10396. t['a196'] = 0x2798;
  10397. t['a165'] = 0x2799;
  10398. t['a192'] = 0x279A;
  10399. t['a166'] = 0x279B;
  10400. t['a167'] = 0x279C;
  10401. t['a168'] = 0x279D;
  10402. t['a169'] = 0x279E;
  10403. t['a170'] = 0x279F;
  10404. t['a171'] = 0x27A0;
  10405. t['a172'] = 0x27A1;
  10406. t['a173'] = 0x27A2;
  10407. t['a162'] = 0x27A3;
  10408. t['a174'] = 0x27A4;
  10409. t['a175'] = 0x27A5;
  10410. t['a176'] = 0x27A6;
  10411. t['a177'] = 0x27A7;
  10412. t['a178'] = 0x27A8;
  10413. t['a179'] = 0x27A9;
  10414. t['a193'] = 0x27AA;
  10415. t['a180'] = 0x27AB;
  10416. t['a199'] = 0x27AC;
  10417. t['a181'] = 0x27AD;
  10418. t['a200'] = 0x27AE;
  10419. t['a182'] = 0x27AF;
  10420. t['a201'] = 0x27B1;
  10421. t['a183'] = 0x27B2;
  10422. t['a184'] = 0x27B3;
  10423. t['a197'] = 0x27B4;
  10424. t['a185'] = 0x27B5;
  10425. t['a194'] = 0x27B6;
  10426. t['a198'] = 0x27B7;
  10427. t['a186'] = 0x27B8;
  10428. t['a195'] = 0x27B9;
  10429. t['a187'] = 0x27BA;
  10430. t['a188'] = 0x27BB;
  10431. t['a189'] = 0x27BC;
  10432. t['a190'] = 0x27BD;
  10433. t['a191'] = 0x27BE;
  10434. t['a89'] = 0x2768; // 0xF8D7
  10435. t['a90'] = 0x2769; // 0xF8D8
  10436. t['a93'] = 0x276A; // 0xF8D9
  10437. t['a94'] = 0x276B; // 0xF8DA
  10438. t['a91'] = 0x276C; // 0xF8DB
  10439. t['a92'] = 0x276D; // 0xF8DC
  10440. t['a205'] = 0x276E; // 0xF8DD
  10441. t['a85'] = 0x276F; // 0xF8DE
  10442. t['a206'] = 0x2770; // 0xF8DF
  10443. t['a86'] = 0x2771; // 0xF8E0
  10444. t['a87'] = 0x2772; // 0xF8E1
  10445. t['a88'] = 0x2773; // 0xF8E2
  10446. t['a95'] = 0x2774; // 0xF8E3
  10447. t['a96'] = 0x2775; // 0xF8E4
  10448. t['.notdef'] = 0x0000;
  10449. });
  10450. exports.getGlyphsUnicode = getGlyphsUnicode;
  10451. exports.getDingbatsGlyphsUnicode = getDingbatsGlyphsUnicode;
  10452. }));
  10453. (function (root, factory) {
  10454. {
  10455. factory((root.pdfjsCoreJbig2 = {}), root.pdfjsSharedUtil,
  10456. root.pdfjsCoreArithmeticDecoder);
  10457. }
  10458. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  10459. var error = sharedUtil.error;
  10460. var log2 = sharedUtil.log2;
  10461. var readInt8 = sharedUtil.readInt8;
  10462. var readUint16 = sharedUtil.readUint16;
  10463. var readUint32 = sharedUtil.readUint32;
  10464. var shadow = sharedUtil.shadow;
  10465. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  10466. var Jbig2Image = (function Jbig2ImageClosure() {
  10467. // Utility data structures
  10468. function ContextCache() {}
  10469. ContextCache.prototype = {
  10470. getContexts: function(id) {
  10471. if (id in this) {
  10472. return this[id];
  10473. }
  10474. return (this[id] = new Int8Array(1 << 16));
  10475. }
  10476. };
  10477. function DecodingContext(data, start, end) {
  10478. this.data = data;
  10479. this.start = start;
  10480. this.end = end;
  10481. }
  10482. DecodingContext.prototype = {
  10483. get decoder() {
  10484. var decoder = new ArithmeticDecoder(this.data, this.start, this.end);
  10485. return shadow(this, 'decoder', decoder);
  10486. },
  10487. get contextCache() {
  10488. var cache = new ContextCache();
  10489. return shadow(this, 'contextCache', cache);
  10490. }
  10491. };
  10492. // Annex A. Arithmetic Integer Decoding Procedure
  10493. // A.2 Procedure for decoding values
  10494. function decodeInteger(contextCache, procedure, decoder) {
  10495. var contexts = contextCache.getContexts(procedure);
  10496. var prev = 1;
  10497. function readBits(length) {
  10498. var v = 0;
  10499. for (var i = 0; i < length; i++) {
  10500. var bit = decoder.readBit(contexts, prev);
  10501. prev = (prev < 256 ? (prev << 1) | bit :
  10502. (((prev << 1) | bit) & 511) | 256);
  10503. v = (v << 1) | bit;
  10504. }
  10505. return v >>> 0;
  10506. }
  10507. var sign = readBits(1);
  10508. var value = readBits(1) ?
  10509. (readBits(1) ?
  10510. (readBits(1) ?
  10511. (readBits(1) ?
  10512. (readBits(1) ?
  10513. (readBits(32) + 4436) :
  10514. readBits(12) + 340) :
  10515. readBits(8) + 84) :
  10516. readBits(6) + 20) :
  10517. readBits(4) + 4) :
  10518. readBits(2);
  10519. return (sign === 0 ? value : (value > 0 ? -value : null));
  10520. }
  10521. // A.3 The IAID decoding procedure
  10522. function decodeIAID(contextCache, decoder, codeLength) {
  10523. var contexts = contextCache.getContexts('IAID');
  10524. var prev = 1;
  10525. for (var i = 0; i < codeLength; i++) {
  10526. var bit = decoder.readBit(contexts, prev);
  10527. prev = (prev << 1) | bit;
  10528. }
  10529. if (codeLength < 31) {
  10530. return prev & ((1 << codeLength) - 1);
  10531. }
  10532. return prev & 0x7FFFFFFF;
  10533. }
  10534. // 7.3 Segment types
  10535. var SegmentTypes = [
  10536. 'SymbolDictionary', null, null, null, 'IntermediateTextRegion', null,
  10537. 'ImmediateTextRegion', 'ImmediateLosslessTextRegion', null, null, null,
  10538. null, null, null, null, null, 'patternDictionary', null, null, null,
  10539. 'IntermediateHalftoneRegion', null, 'ImmediateHalftoneRegion',
  10540. 'ImmediateLosslessHalftoneRegion', null, null, null, null, null, null, null,
  10541. null, null, null, null, null, 'IntermediateGenericRegion', null,
  10542. 'ImmediateGenericRegion', 'ImmediateLosslessGenericRegion',
  10543. 'IntermediateGenericRefinementRegion', null,
  10544. 'ImmediateGenericRefinementRegion',
  10545. 'ImmediateLosslessGenericRefinementRegion', null, null, null, null,
  10546. 'PageInformation', 'EndOfPage', 'EndOfStripe', 'EndOfFile', 'Profiles',
  10547. 'Tables', null, null, null, null, null, null, null, null,
  10548. 'Extension'
  10549. ];
  10550. var CodingTemplates = [
  10551. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  10552. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: 2, y: -1},
  10553. {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  10554. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: 2, y: -2},
  10555. {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1},
  10556. {x: 2, y: -1}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}],
  10557. [{x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}, {x: -2, y: -1},
  10558. {x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -2, y: 0},
  10559. {x: -1, y: 0}],
  10560. [{x: -3, y: -1}, {x: -2, y: -1}, {x: -1, y: -1}, {x: 0, y: -1},
  10561. {x: 1, y: -1}, {x: -4, y: 0}, {x: -3, y: 0}, {x: -2, y: 0}, {x: -1, y: 0}]
  10562. ];
  10563. var RefinementTemplates = [
  10564. {
  10565. coding: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  10566. reference: [{x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}, {x: 0, y: 0},
  10567. {x: 1, y: 0}, {x: -1, y: 1}, {x: 0, y: 1}, {x: 1, y: 1}]
  10568. },
  10569. {
  10570. coding: [{x: -1, y: -1}, {x: 0, y: -1}, {x: 1, y: -1}, {x: -1, y: 0}],
  10571. reference: [{x: 0, y: -1}, {x: -1, y: 0}, {x: 0, y: 0}, {x: 1, y: 0},
  10572. {x: 0, y: 1}, {x: 1, y: 1}]
  10573. }
  10574. ];
  10575. // See 6.2.5.7 Decoding the bitmap.
  10576. var ReusedContexts = [
  10577. 0x9B25, // 10011 0110010 0101
  10578. 0x0795, // 0011 110010 101
  10579. 0x00E5, // 001 11001 01
  10580. 0x0195 // 011001 0101
  10581. ];
  10582. var RefinementReusedContexts = [
  10583. 0x0020, // '000' + '0' (coding) + '00010000' + '0' (reference)
  10584. 0x0008 // '0000' + '001000'
  10585. ];
  10586. function decodeBitmapTemplate0(width, height, decodingContext) {
  10587. var decoder = decodingContext.decoder;
  10588. var contexts = decodingContext.contextCache.getContexts('GB');
  10589. var contextLabel, i, j, pixel, row, row1, row2, bitmap = [];
  10590. // ...ooooo....
  10591. // ..ooooooo... Context template for current pixel (X)
  10592. // .ooooX...... (concatenate values of 'o'-pixels to get contextLabel)
  10593. var OLD_PIXEL_MASK = 0x7BF7; // 01111 0111111 0111
  10594. for (i = 0; i < height; i++) {
  10595. row = bitmap[i] = new Uint8Array(width);
  10596. row1 = (i < 1) ? row : bitmap[i - 1];
  10597. row2 = (i < 2) ? row : bitmap[i - 2];
  10598. // At the beginning of each row:
  10599. // Fill contextLabel with pixels that are above/right of (X)
  10600. contextLabel = (row2[0] << 13) | (row2[1] << 12) | (row2[2] << 11) |
  10601. (row1[0] << 7) | (row1[1] << 6) | (row1[2] << 5) |
  10602. (row1[3] << 4);
  10603. for (j = 0; j < width; j++) {
  10604. row[j] = pixel = decoder.readBit(contexts, contextLabel);
  10605. // At each pixel: Clear contextLabel pixels that are shifted
  10606. // out of the context, then add new ones.
  10607. contextLabel = ((contextLabel & OLD_PIXEL_MASK) << 1) |
  10608. (j + 3 < width ? row2[j + 3] << 11 : 0) |
  10609. (j + 4 < width ? row1[j + 4] << 4 : 0) | pixel;
  10610. }
  10611. }
  10612. return bitmap;
  10613. }
  10614. // 6.2 Generic Region Decoding Procedure
  10615. function decodeBitmap(mmr, width, height, templateIndex, prediction, skip, at,
  10616. decodingContext) {
  10617. if (mmr) {
  10618. error('JBIG2 error: MMR encoding is not supported');
  10619. }
  10620. // Use optimized version for the most common case
  10621. if (templateIndex === 0 && !skip && !prediction && at.length === 4 &&
  10622. at[0].x === 3 && at[0].y === -1 && at[1].x === -3 && at[1].y === -1 &&
  10623. at[2].x === 2 && at[2].y === -2 && at[3].x === -2 && at[3].y === -2) {
  10624. return decodeBitmapTemplate0(width, height, decodingContext);
  10625. }
  10626. var useskip = !!skip;
  10627. var template = CodingTemplates[templateIndex].concat(at);
  10628. // Sorting is non-standard, and it is not required. But sorting increases
  10629. // the number of template bits that can be reused from the previous
  10630. // contextLabel in the main loop.
  10631. template.sort(function (a, b) {
  10632. return (a.y - b.y) || (a.x - b.x);
  10633. });
  10634. var templateLength = template.length;
  10635. var templateX = new Int8Array(templateLength);
  10636. var templateY = new Int8Array(templateLength);
  10637. var changingTemplateEntries = [];
  10638. var reuseMask = 0, minX = 0, maxX = 0, minY = 0;
  10639. var c, k;
  10640. for (k = 0; k < templateLength; k++) {
  10641. templateX[k] = template[k].x;
  10642. templateY[k] = template[k].y;
  10643. minX = Math.min(minX, template[k].x);
  10644. maxX = Math.max(maxX, template[k].x);
  10645. minY = Math.min(minY, template[k].y);
  10646. // Check if the template pixel appears in two consecutive context labels,
  10647. // so it can be reused. Otherwise, we add it to the list of changing
  10648. // template entries.
  10649. if (k < templateLength - 1 &&
  10650. template[k].y === template[k + 1].y &&
  10651. template[k].x === template[k + 1].x - 1) {
  10652. reuseMask |= 1 << (templateLength - 1 - k);
  10653. } else {
  10654. changingTemplateEntries.push(k);
  10655. }
  10656. }
  10657. var changingEntriesLength = changingTemplateEntries.length;
  10658. var changingTemplateX = new Int8Array(changingEntriesLength);
  10659. var changingTemplateY = new Int8Array(changingEntriesLength);
  10660. var changingTemplateBit = new Uint16Array(changingEntriesLength);
  10661. for (c = 0; c < changingEntriesLength; c++) {
  10662. k = changingTemplateEntries[c];
  10663. changingTemplateX[c] = template[k].x;
  10664. changingTemplateY[c] = template[k].y;
  10665. changingTemplateBit[c] = 1 << (templateLength - 1 - k);
  10666. }
  10667. // Get the safe bounding box edges from the width, height, minX, maxX, minY
  10668. var sbb_left = -minX;
  10669. var sbb_top = -minY;
  10670. var sbb_right = width - maxX;
  10671. var pseudoPixelContext = ReusedContexts[templateIndex];
  10672. var row = new Uint8Array(width);
  10673. var bitmap = [];
  10674. var decoder = decodingContext.decoder;
  10675. var contexts = decodingContext.contextCache.getContexts('GB');
  10676. var ltp = 0, j, i0, j0, contextLabel = 0, bit, shift;
  10677. for (var i = 0; i < height; i++) {
  10678. if (prediction) {
  10679. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  10680. ltp ^= sltp;
  10681. if (ltp) {
  10682. bitmap.push(row); // duplicate previous row
  10683. continue;
  10684. }
  10685. }
  10686. row = new Uint8Array(row);
  10687. bitmap.push(row);
  10688. for (j = 0; j < width; j++) {
  10689. if (useskip && skip[i][j]) {
  10690. row[j] = 0;
  10691. continue;
  10692. }
  10693. // Are we in the middle of a scanline, so we can reuse contextLabel
  10694. // bits?
  10695. if (j >= sbb_left && j < sbb_right && i >= sbb_top) {
  10696. // If yes, we can just shift the bits that are reusable and only
  10697. // fetch the remaining ones.
  10698. contextLabel = (contextLabel << 1) & reuseMask;
  10699. for (k = 0; k < changingEntriesLength; k++) {
  10700. i0 = i + changingTemplateY[k];
  10701. j0 = j + changingTemplateX[k];
  10702. bit = bitmap[i0][j0];
  10703. if (bit) {
  10704. bit = changingTemplateBit[k];
  10705. contextLabel |= bit;
  10706. }
  10707. }
  10708. } else {
  10709. // compute the contextLabel from scratch
  10710. contextLabel = 0;
  10711. shift = templateLength - 1;
  10712. for (k = 0; k < templateLength; k++, shift--) {
  10713. j0 = j + templateX[k];
  10714. if (j0 >= 0 && j0 < width) {
  10715. i0 = i + templateY[k];
  10716. if (i0 >= 0) {
  10717. bit = bitmap[i0][j0];
  10718. if (bit) {
  10719. contextLabel |= bit << shift;
  10720. }
  10721. }
  10722. }
  10723. }
  10724. }
  10725. var pixel = decoder.readBit(contexts, contextLabel);
  10726. row[j] = pixel;
  10727. }
  10728. }
  10729. return bitmap;
  10730. }
  10731. // 6.3.2 Generic Refinement Region Decoding Procedure
  10732. function decodeRefinement(width, height, templateIndex, referenceBitmap,
  10733. offsetX, offsetY, prediction, at,
  10734. decodingContext) {
  10735. var codingTemplate = RefinementTemplates[templateIndex].coding;
  10736. if (templateIndex === 0) {
  10737. codingTemplate = codingTemplate.concat([at[0]]);
  10738. }
  10739. var codingTemplateLength = codingTemplate.length;
  10740. var codingTemplateX = new Int32Array(codingTemplateLength);
  10741. var codingTemplateY = new Int32Array(codingTemplateLength);
  10742. var k;
  10743. for (k = 0; k < codingTemplateLength; k++) {
  10744. codingTemplateX[k] = codingTemplate[k].x;
  10745. codingTemplateY[k] = codingTemplate[k].y;
  10746. }
  10747. var referenceTemplate = RefinementTemplates[templateIndex].reference;
  10748. if (templateIndex === 0) {
  10749. referenceTemplate = referenceTemplate.concat([at[1]]);
  10750. }
  10751. var referenceTemplateLength = referenceTemplate.length;
  10752. var referenceTemplateX = new Int32Array(referenceTemplateLength);
  10753. var referenceTemplateY = new Int32Array(referenceTemplateLength);
  10754. for (k = 0; k < referenceTemplateLength; k++) {
  10755. referenceTemplateX[k] = referenceTemplate[k].x;
  10756. referenceTemplateY[k] = referenceTemplate[k].y;
  10757. }
  10758. var referenceWidth = referenceBitmap[0].length;
  10759. var referenceHeight = referenceBitmap.length;
  10760. var pseudoPixelContext = RefinementReusedContexts[templateIndex];
  10761. var bitmap = [];
  10762. var decoder = decodingContext.decoder;
  10763. var contexts = decodingContext.contextCache.getContexts('GR');
  10764. var ltp = 0;
  10765. for (var i = 0; i < height; i++) {
  10766. if (prediction) {
  10767. var sltp = decoder.readBit(contexts, pseudoPixelContext);
  10768. ltp ^= sltp;
  10769. if (ltp) {
  10770. error('JBIG2 error: prediction is not supported');
  10771. }
  10772. }
  10773. var row = new Uint8Array(width);
  10774. bitmap.push(row);
  10775. for (var j = 0; j < width; j++) {
  10776. var i0, j0;
  10777. var contextLabel = 0;
  10778. for (k = 0; k < codingTemplateLength; k++) {
  10779. i0 = i + codingTemplateY[k];
  10780. j0 = j + codingTemplateX[k];
  10781. if (i0 < 0 || j0 < 0 || j0 >= width) {
  10782. contextLabel <<= 1; // out of bound pixel
  10783. } else {
  10784. contextLabel = (contextLabel << 1) | bitmap[i0][j0];
  10785. }
  10786. }
  10787. for (k = 0; k < referenceTemplateLength; k++) {
  10788. i0 = i + referenceTemplateY[k] + offsetY;
  10789. j0 = j + referenceTemplateX[k] + offsetX;
  10790. if (i0 < 0 || i0 >= referenceHeight || j0 < 0 ||
  10791. j0 >= referenceWidth) {
  10792. contextLabel <<= 1; // out of bound pixel
  10793. } else {
  10794. contextLabel = (contextLabel << 1) | referenceBitmap[i0][j0];
  10795. }
  10796. }
  10797. var pixel = decoder.readBit(contexts, contextLabel);
  10798. row[j] = pixel;
  10799. }
  10800. }
  10801. return bitmap;
  10802. }
  10803. // 6.5.5 Decoding the symbol dictionary
  10804. function decodeSymbolDictionary(huffman, refinement, symbols,
  10805. numberOfNewSymbols, numberOfExportedSymbols,
  10806. huffmanTables, templateIndex, at,
  10807. refinementTemplateIndex, refinementAt,
  10808. decodingContext) {
  10809. if (huffman) {
  10810. error('JBIG2 error: huffman is not supported');
  10811. }
  10812. var newSymbols = [];
  10813. var currentHeight = 0;
  10814. var symbolCodeLength = log2(symbols.length + numberOfNewSymbols);
  10815. var decoder = decodingContext.decoder;
  10816. var contextCache = decodingContext.contextCache;
  10817. while (newSymbols.length < numberOfNewSymbols) {
  10818. var deltaHeight = decodeInteger(contextCache, 'IADH', decoder); // 6.5.6
  10819. currentHeight += deltaHeight;
  10820. var currentWidth = 0;
  10821. var totalWidth = 0;
  10822. while (true) {
  10823. var deltaWidth = decodeInteger(contextCache, 'IADW', decoder); // 6.5.7
  10824. if (deltaWidth === null) {
  10825. break; // OOB
  10826. }
  10827. currentWidth += deltaWidth;
  10828. totalWidth += currentWidth;
  10829. var bitmap;
  10830. if (refinement) {
  10831. // 6.5.8.2 Refinement/aggregate-coded symbol bitmap
  10832. var numberOfInstances = decodeInteger(contextCache, 'IAAI', decoder);
  10833. if (numberOfInstances > 1) {
  10834. bitmap = decodeTextRegion(huffman, refinement,
  10835. currentWidth, currentHeight, 0,
  10836. numberOfInstances, 1, //strip size
  10837. symbols.concat(newSymbols),
  10838. symbolCodeLength,
  10839. 0, //transposed
  10840. 0, //ds offset
  10841. 1, //top left 7.4.3.1.1
  10842. 0, //OR operator
  10843. huffmanTables,
  10844. refinementTemplateIndex, refinementAt,
  10845. decodingContext);
  10846. } else {
  10847. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10848. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10849. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10850. var symbol = (symbolId < symbols.length ? symbols[symbolId] :
  10851. newSymbols[symbolId - symbols.length]);
  10852. bitmap = decodeRefinement(currentWidth, currentHeight,
  10853. refinementTemplateIndex, symbol, rdx, rdy, false, refinementAt,
  10854. decodingContext);
  10855. }
  10856. } else {
  10857. // 6.5.8.1 Direct-coded symbol bitmap
  10858. bitmap = decodeBitmap(false, currentWidth, currentHeight,
  10859. templateIndex, false, null, at, decodingContext);
  10860. }
  10861. newSymbols.push(bitmap);
  10862. }
  10863. }
  10864. // 6.5.10 Exported symbols
  10865. var exportedSymbols = [];
  10866. var flags = [], currentFlag = false;
  10867. var totalSymbolsLength = symbols.length + numberOfNewSymbols;
  10868. while (flags.length < totalSymbolsLength) {
  10869. var runLength = decodeInteger(contextCache, 'IAEX', decoder);
  10870. while (runLength--) {
  10871. flags.push(currentFlag);
  10872. }
  10873. currentFlag = !currentFlag;
  10874. }
  10875. for (var i = 0, ii = symbols.length; i < ii; i++) {
  10876. if (flags[i]) {
  10877. exportedSymbols.push(symbols[i]);
  10878. }
  10879. }
  10880. for (var j = 0; j < numberOfNewSymbols; i++, j++) {
  10881. if (flags[i]) {
  10882. exportedSymbols.push(newSymbols[j]);
  10883. }
  10884. }
  10885. return exportedSymbols;
  10886. }
  10887. function decodeTextRegion(huffman, refinement, width, height,
  10888. defaultPixelValue, numberOfSymbolInstances,
  10889. stripSize, inputSymbols, symbolCodeLength,
  10890. transposed, dsOffset, referenceCorner,
  10891. combinationOperator, huffmanTables,
  10892. refinementTemplateIndex, refinementAt,
  10893. decodingContext) {
  10894. if (huffman) {
  10895. error('JBIG2 error: huffman is not supported');
  10896. }
  10897. // Prepare bitmap
  10898. var bitmap = [];
  10899. var i, row;
  10900. for (i = 0; i < height; i++) {
  10901. row = new Uint8Array(width);
  10902. if (defaultPixelValue) {
  10903. for (var j = 0; j < width; j++) {
  10904. row[j] = defaultPixelValue;
  10905. }
  10906. }
  10907. bitmap.push(row);
  10908. }
  10909. var decoder = decodingContext.decoder;
  10910. var contextCache = decodingContext.contextCache;
  10911. var stripT = -decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10912. var firstS = 0;
  10913. i = 0;
  10914. while (i < numberOfSymbolInstances) {
  10915. var deltaT = decodeInteger(contextCache, 'IADT', decoder); // 6.4.6
  10916. stripT += deltaT;
  10917. var deltaFirstS = decodeInteger(contextCache, 'IAFS', decoder); // 6.4.7
  10918. firstS += deltaFirstS;
  10919. var currentS = firstS;
  10920. do {
  10921. var currentT = (stripSize === 1 ? 0 :
  10922. decodeInteger(contextCache, 'IAIT', decoder)); // 6.4.9
  10923. var t = stripSize * stripT + currentT;
  10924. var symbolId = decodeIAID(contextCache, decoder, symbolCodeLength);
  10925. var applyRefinement = (refinement &&
  10926. decodeInteger(contextCache, 'IARI', decoder));
  10927. var symbolBitmap = inputSymbols[symbolId];
  10928. var symbolWidth = symbolBitmap[0].length;
  10929. var symbolHeight = symbolBitmap.length;
  10930. if (applyRefinement) {
  10931. var rdw = decodeInteger(contextCache, 'IARDW', decoder); // 6.4.11.1
  10932. var rdh = decodeInteger(contextCache, 'IARDH', decoder); // 6.4.11.2
  10933. var rdx = decodeInteger(contextCache, 'IARDX', decoder); // 6.4.11.3
  10934. var rdy = decodeInteger(contextCache, 'IARDY', decoder); // 6.4.11.4
  10935. symbolWidth += rdw;
  10936. symbolHeight += rdh;
  10937. symbolBitmap = decodeRefinement(symbolWidth, symbolHeight,
  10938. refinementTemplateIndex, symbolBitmap, (rdw >> 1) + rdx,
  10939. (rdh >> 1) + rdy, false, refinementAt,
  10940. decodingContext);
  10941. }
  10942. var offsetT = t - ((referenceCorner & 1) ? 0 : symbolHeight);
  10943. var offsetS = currentS - ((referenceCorner & 2) ? symbolWidth : 0);
  10944. var s2, t2, symbolRow;
  10945. if (transposed) {
  10946. // Place Symbol Bitmap from T1,S1
  10947. for (s2 = 0; s2 < symbolHeight; s2++) {
  10948. row = bitmap[offsetS + s2];
  10949. if (!row) {
  10950. continue;
  10951. }
  10952. symbolRow = symbolBitmap[s2];
  10953. // To ignore Parts of Symbol bitmap which goes
  10954. // outside bitmap region
  10955. var maxWidth = Math.min(width - offsetT, symbolWidth);
  10956. switch (combinationOperator) {
  10957. case 0: // OR
  10958. for (t2 = 0; t2 < maxWidth; t2++) {
  10959. row[offsetT + t2] |= symbolRow[t2];
  10960. }
  10961. break;
  10962. case 2: // XOR
  10963. for (t2 = 0; t2 < maxWidth; t2++) {
  10964. row[offsetT + t2] ^= symbolRow[t2];
  10965. }
  10966. break;
  10967. default:
  10968. error('JBIG2 error: operator ' + combinationOperator +
  10969. ' is not supported');
  10970. }
  10971. }
  10972. currentS += symbolHeight - 1;
  10973. } else {
  10974. for (t2 = 0; t2 < symbolHeight; t2++) {
  10975. row = bitmap[offsetT + t2];
  10976. if (!row) {
  10977. continue;
  10978. }
  10979. symbolRow = symbolBitmap[t2];
  10980. switch (combinationOperator) {
  10981. case 0: // OR
  10982. for (s2 = 0; s2 < symbolWidth; s2++) {
  10983. row[offsetS + s2] |= symbolRow[s2];
  10984. }
  10985. break;
  10986. case 2: // XOR
  10987. for (s2 = 0; s2 < symbolWidth; s2++) {
  10988. row[offsetS + s2] ^= symbolRow[s2];
  10989. }
  10990. break;
  10991. default:
  10992. error('JBIG2 error: operator ' + combinationOperator +
  10993. ' is not supported');
  10994. }
  10995. }
  10996. currentS += symbolWidth - 1;
  10997. }
  10998. i++;
  10999. var deltaS = decodeInteger(contextCache, 'IADS', decoder); // 6.4.8
  11000. if (deltaS === null) {
  11001. break; // OOB
  11002. }
  11003. currentS += deltaS + dsOffset;
  11004. } while (true);
  11005. }
  11006. return bitmap;
  11007. }
  11008. function readSegmentHeader(data, start) {
  11009. var segmentHeader = {};
  11010. segmentHeader.number = readUint32(data, start);
  11011. var flags = data[start + 4];
  11012. var segmentType = flags & 0x3F;
  11013. if (!SegmentTypes[segmentType]) {
  11014. error('JBIG2 error: invalid segment type: ' + segmentType);
  11015. }
  11016. segmentHeader.type = segmentType;
  11017. segmentHeader.typeName = SegmentTypes[segmentType];
  11018. segmentHeader.deferredNonRetain = !!(flags & 0x80);
  11019. var pageAssociationFieldSize = !!(flags & 0x40);
  11020. var referredFlags = data[start + 5];
  11021. var referredToCount = (referredFlags >> 5) & 7;
  11022. var retainBits = [referredFlags & 31];
  11023. var position = start + 6;
  11024. if (referredFlags === 7) {
  11025. referredToCount = readUint32(data, position - 1) & 0x1FFFFFFF;
  11026. position += 3;
  11027. var bytes = (referredToCount + 7) >> 3;
  11028. retainBits[0] = data[position++];
  11029. while (--bytes > 0) {
  11030. retainBits.push(data[position++]);
  11031. }
  11032. } else if (referredFlags === 5 || referredFlags === 6) {
  11033. error('JBIG2 error: invalid referred-to flags');
  11034. }
  11035. segmentHeader.retainBits = retainBits;
  11036. var referredToSegmentNumberSize = (segmentHeader.number <= 256 ? 1 :
  11037. (segmentHeader.number <= 65536 ? 2 : 4));
  11038. var referredTo = [];
  11039. var i, ii;
  11040. for (i = 0; i < referredToCount; i++) {
  11041. var number = (referredToSegmentNumberSize === 1 ? data[position] :
  11042. (referredToSegmentNumberSize === 2 ? readUint16(data, position) :
  11043. readUint32(data, position)));
  11044. referredTo.push(number);
  11045. position += referredToSegmentNumberSize;
  11046. }
  11047. segmentHeader.referredTo = referredTo;
  11048. if (!pageAssociationFieldSize) {
  11049. segmentHeader.pageAssociation = data[position++];
  11050. } else {
  11051. segmentHeader.pageAssociation = readUint32(data, position);
  11052. position += 4;
  11053. }
  11054. segmentHeader.length = readUint32(data, position);
  11055. position += 4;
  11056. if (segmentHeader.length === 0xFFFFFFFF) {
  11057. // 7.2.7 Segment data length, unknown segment length
  11058. if (segmentType === 38) { // ImmediateGenericRegion
  11059. var genericRegionInfo = readRegionSegmentInformation(data, position);
  11060. var genericRegionSegmentFlags = data[position +
  11061. RegionSegmentInformationFieldLength];
  11062. var genericRegionMmr = !!(genericRegionSegmentFlags & 1);
  11063. // searching for the segment end
  11064. var searchPatternLength = 6;
  11065. var searchPattern = new Uint8Array(searchPatternLength);
  11066. if (!genericRegionMmr) {
  11067. searchPattern[0] = 0xFF;
  11068. searchPattern[1] = 0xAC;
  11069. }
  11070. searchPattern[2] = (genericRegionInfo.height >>> 24) & 0xFF;
  11071. searchPattern[3] = (genericRegionInfo.height >> 16) & 0xFF;
  11072. searchPattern[4] = (genericRegionInfo.height >> 8) & 0xFF;
  11073. searchPattern[5] = genericRegionInfo.height & 0xFF;
  11074. for (i = position, ii = data.length; i < ii; i++) {
  11075. var j = 0;
  11076. while (j < searchPatternLength && searchPattern[j] === data[i + j]) {
  11077. j++;
  11078. }
  11079. if (j === searchPatternLength) {
  11080. segmentHeader.length = i + searchPatternLength;
  11081. break;
  11082. }
  11083. }
  11084. if (segmentHeader.length === 0xFFFFFFFF) {
  11085. error('JBIG2 error: segment end was not found');
  11086. }
  11087. } else {
  11088. error('JBIG2 error: invalid unknown segment length');
  11089. }
  11090. }
  11091. segmentHeader.headerEnd = position;
  11092. return segmentHeader;
  11093. }
  11094. function readSegments(header, data, start, end) {
  11095. var segments = [];
  11096. var position = start;
  11097. while (position < end) {
  11098. var segmentHeader = readSegmentHeader(data, position);
  11099. position = segmentHeader.headerEnd;
  11100. var segment = {
  11101. header: segmentHeader,
  11102. data: data
  11103. };
  11104. if (!header.randomAccess) {
  11105. segment.start = position;
  11106. position += segmentHeader.length;
  11107. segment.end = position;
  11108. }
  11109. segments.push(segment);
  11110. if (segmentHeader.type === 51) {
  11111. break; // end of file is found
  11112. }
  11113. }
  11114. if (header.randomAccess) {
  11115. for (var i = 0, ii = segments.length; i < ii; i++) {
  11116. segments[i].start = position;
  11117. position += segments[i].header.length;
  11118. segments[i].end = position;
  11119. }
  11120. }
  11121. return segments;
  11122. }
  11123. // 7.4.1 Region segment information field
  11124. function readRegionSegmentInformation(data, start) {
  11125. return {
  11126. width: readUint32(data, start),
  11127. height: readUint32(data, start + 4),
  11128. x: readUint32(data, start + 8),
  11129. y: readUint32(data, start + 12),
  11130. combinationOperator: data[start + 16] & 7
  11131. };
  11132. }
  11133. var RegionSegmentInformationFieldLength = 17;
  11134. function processSegment(segment, visitor) {
  11135. var header = segment.header;
  11136. var data = segment.data, position = segment.start, end = segment.end;
  11137. var args, at, i, atLength;
  11138. switch (header.type) {
  11139. case 0: // SymbolDictionary
  11140. // 7.4.2 Symbol dictionary segment syntax
  11141. var dictionary = {};
  11142. var dictionaryFlags = readUint16(data, position); // 7.4.2.1.1
  11143. dictionary.huffman = !!(dictionaryFlags & 1);
  11144. dictionary.refinement = !!(dictionaryFlags & 2);
  11145. dictionary.huffmanDHSelector = (dictionaryFlags >> 2) & 3;
  11146. dictionary.huffmanDWSelector = (dictionaryFlags >> 4) & 3;
  11147. dictionary.bitmapSizeSelector = (dictionaryFlags >> 6) & 1;
  11148. dictionary.aggregationInstancesSelector = (dictionaryFlags >> 7) & 1;
  11149. dictionary.bitmapCodingContextUsed = !!(dictionaryFlags & 256);
  11150. dictionary.bitmapCodingContextRetained = !!(dictionaryFlags & 512);
  11151. dictionary.template = (dictionaryFlags >> 10) & 3;
  11152. dictionary.refinementTemplate = (dictionaryFlags >> 12) & 1;
  11153. position += 2;
  11154. if (!dictionary.huffman) {
  11155. atLength = dictionary.template === 0 ? 4 : 1;
  11156. at = [];
  11157. for (i = 0; i < atLength; i++) {
  11158. at.push({
  11159. x: readInt8(data, position),
  11160. y: readInt8(data, position + 1)
  11161. });
  11162. position += 2;
  11163. }
  11164. dictionary.at = at;
  11165. }
  11166. if (dictionary.refinement && !dictionary.refinementTemplate) {
  11167. at = [];
  11168. for (i = 0; i < 2; i++) {
  11169. at.push({
  11170. x: readInt8(data, position),
  11171. y: readInt8(data, position + 1)
  11172. });
  11173. position += 2;
  11174. }
  11175. dictionary.refinementAt = at;
  11176. }
  11177. dictionary.numberOfExportedSymbols = readUint32(data, position);
  11178. position += 4;
  11179. dictionary.numberOfNewSymbols = readUint32(data, position);
  11180. position += 4;
  11181. args = [dictionary, header.number, header.referredTo,
  11182. data, position, end];
  11183. break;
  11184. case 6: // ImmediateTextRegion
  11185. case 7: // ImmediateLosslessTextRegion
  11186. var textRegion = {};
  11187. textRegion.info = readRegionSegmentInformation(data, position);
  11188. position += RegionSegmentInformationFieldLength;
  11189. var textRegionSegmentFlags = readUint16(data, position);
  11190. position += 2;
  11191. textRegion.huffman = !!(textRegionSegmentFlags & 1);
  11192. textRegion.refinement = !!(textRegionSegmentFlags & 2);
  11193. textRegion.stripSize = 1 << ((textRegionSegmentFlags >> 2) & 3);
  11194. textRegion.referenceCorner = (textRegionSegmentFlags >> 4) & 3;
  11195. textRegion.transposed = !!(textRegionSegmentFlags & 64);
  11196. textRegion.combinationOperator = (textRegionSegmentFlags >> 7) & 3;
  11197. textRegion.defaultPixelValue = (textRegionSegmentFlags >> 9) & 1;
  11198. textRegion.dsOffset = (textRegionSegmentFlags << 17) >> 27;
  11199. textRegion.refinementTemplate = (textRegionSegmentFlags >> 15) & 1;
  11200. if (textRegion.huffman) {
  11201. var textRegionHuffmanFlags = readUint16(data, position);
  11202. position += 2;
  11203. textRegion.huffmanFS = (textRegionHuffmanFlags) & 3;
  11204. textRegion.huffmanDS = (textRegionHuffmanFlags >> 2) & 3;
  11205. textRegion.huffmanDT = (textRegionHuffmanFlags >> 4) & 3;
  11206. textRegion.huffmanRefinementDW = (textRegionHuffmanFlags >> 6) & 3;
  11207. textRegion.huffmanRefinementDH = (textRegionHuffmanFlags >> 8) & 3;
  11208. textRegion.huffmanRefinementDX = (textRegionHuffmanFlags >> 10) & 3;
  11209. textRegion.huffmanRefinementDY = (textRegionHuffmanFlags >> 12) & 3;
  11210. textRegion.huffmanRefinementSizeSelector =
  11211. !!(textRegionHuffmanFlags & 14);
  11212. }
  11213. if (textRegion.refinement && !textRegion.refinementTemplate) {
  11214. at = [];
  11215. for (i = 0; i < 2; i++) {
  11216. at.push({
  11217. x: readInt8(data, position),
  11218. y: readInt8(data, position + 1)
  11219. });
  11220. position += 2;
  11221. }
  11222. textRegion.refinementAt = at;
  11223. }
  11224. textRegion.numberOfSymbolInstances = readUint32(data, position);
  11225. position += 4;
  11226. // TODO 7.4.3.1.7 Symbol ID Huffman table decoding
  11227. if (textRegion.huffman) {
  11228. error('JBIG2 error: huffman is not supported');
  11229. }
  11230. args = [textRegion, header.referredTo, data, position, end];
  11231. break;
  11232. case 38: // ImmediateGenericRegion
  11233. case 39: // ImmediateLosslessGenericRegion
  11234. var genericRegion = {};
  11235. genericRegion.info = readRegionSegmentInformation(data, position);
  11236. position += RegionSegmentInformationFieldLength;
  11237. var genericRegionSegmentFlags = data[position++];
  11238. genericRegion.mmr = !!(genericRegionSegmentFlags & 1);
  11239. genericRegion.template = (genericRegionSegmentFlags >> 1) & 3;
  11240. genericRegion.prediction = !!(genericRegionSegmentFlags & 8);
  11241. if (!genericRegion.mmr) {
  11242. atLength = genericRegion.template === 0 ? 4 : 1;
  11243. at = [];
  11244. for (i = 0; i < atLength; i++) {
  11245. at.push({
  11246. x: readInt8(data, position),
  11247. y: readInt8(data, position + 1)
  11248. });
  11249. position += 2;
  11250. }
  11251. genericRegion.at = at;
  11252. }
  11253. args = [genericRegion, data, position, end];
  11254. break;
  11255. case 48: // PageInformation
  11256. var pageInfo = {
  11257. width: readUint32(data, position),
  11258. height: readUint32(data, position + 4),
  11259. resolutionX: readUint32(data, position + 8),
  11260. resolutionY: readUint32(data, position + 12)
  11261. };
  11262. if (pageInfo.height === 0xFFFFFFFF) {
  11263. delete pageInfo.height;
  11264. }
  11265. var pageSegmentFlags = data[position + 16];
  11266. var pageStripingInformation = readUint16(data, position + 17);
  11267. pageInfo.lossless = !!(pageSegmentFlags & 1);
  11268. pageInfo.refinement = !!(pageSegmentFlags & 2);
  11269. pageInfo.defaultPixelValue = (pageSegmentFlags >> 2) & 1;
  11270. pageInfo.combinationOperator = (pageSegmentFlags >> 3) & 3;
  11271. pageInfo.requiresBuffer = !!(pageSegmentFlags & 32);
  11272. pageInfo.combinationOperatorOverride = !!(pageSegmentFlags & 64);
  11273. args = [pageInfo];
  11274. break;
  11275. case 49: // EndOfPage
  11276. break;
  11277. case 50: // EndOfStripe
  11278. break;
  11279. case 51: // EndOfFile
  11280. break;
  11281. case 62: // 7.4.15 defines 2 extension types which
  11282. // are comments and can be ignored.
  11283. break;
  11284. default:
  11285. error('JBIG2 error: segment type ' + header.typeName + '(' +
  11286. header.type + ') is not implemented');
  11287. }
  11288. var callbackName = 'on' + header.typeName;
  11289. if (callbackName in visitor) {
  11290. visitor[callbackName].apply(visitor, args);
  11291. }
  11292. }
  11293. function processSegments(segments, visitor) {
  11294. for (var i = 0, ii = segments.length; i < ii; i++) {
  11295. processSegment(segments[i], visitor);
  11296. }
  11297. }
  11298. function parseJbig2(data, start, end) {
  11299. var position = start;
  11300. if (data[position] !== 0x97 || data[position + 1] !== 0x4A ||
  11301. data[position + 2] !== 0x42 || data[position + 3] !== 0x32 ||
  11302. data[position + 4] !== 0x0D || data[position + 5] !== 0x0A ||
  11303. data[position + 6] !== 0x1A || data[position + 7] !== 0x0A) {
  11304. error('JBIG2 error: invalid header');
  11305. }
  11306. var header = {};
  11307. position += 8;
  11308. var flags = data[position++];
  11309. header.randomAccess = !(flags & 1);
  11310. if (!(flags & 2)) {
  11311. header.numberOfPages = readUint32(data, position);
  11312. position += 4;
  11313. }
  11314. var segments = readSegments(header, data, position, end);
  11315. error('Not implemented');
  11316. // processSegments(segments, new SimpleSegmentVisitor());
  11317. }
  11318. function parseJbig2Chunks(chunks) {
  11319. var visitor = new SimpleSegmentVisitor();
  11320. for (var i = 0, ii = chunks.length; i < ii; i++) {
  11321. var chunk = chunks[i];
  11322. var segments = readSegments({}, chunk.data, chunk.start, chunk.end);
  11323. processSegments(segments, visitor);
  11324. }
  11325. return visitor.buffer;
  11326. }
  11327. function SimpleSegmentVisitor() {}
  11328. SimpleSegmentVisitor.prototype = {
  11329. onPageInformation: function SimpleSegmentVisitor_onPageInformation(info) {
  11330. this.currentPageInfo = info;
  11331. var rowSize = (info.width + 7) >> 3;
  11332. var buffer = new Uint8Array(rowSize * info.height);
  11333. // The contents of ArrayBuffers are initialized to 0.
  11334. // Fill the buffer with 0xFF only if info.defaultPixelValue is set
  11335. if (info.defaultPixelValue) {
  11336. for (var i = 0, ii = buffer.length; i < ii; i++) {
  11337. buffer[i] = 0xFF;
  11338. }
  11339. }
  11340. this.buffer = buffer;
  11341. },
  11342. drawBitmap: function SimpleSegmentVisitor_drawBitmap(regionInfo, bitmap) {
  11343. var pageInfo = this.currentPageInfo;
  11344. var width = regionInfo.width, height = regionInfo.height;
  11345. var rowSize = (pageInfo.width + 7) >> 3;
  11346. var combinationOperator = pageInfo.combinationOperatorOverride ?
  11347. regionInfo.combinationOperator : pageInfo.combinationOperator;
  11348. var buffer = this.buffer;
  11349. var mask0 = 128 >> (regionInfo.x & 7);
  11350. var offset0 = regionInfo.y * rowSize + (regionInfo.x >> 3);
  11351. var i, j, mask, offset;
  11352. switch (combinationOperator) {
  11353. case 0: // OR
  11354. for (i = 0; i < height; i++) {
  11355. mask = mask0;
  11356. offset = offset0;
  11357. for (j = 0; j < width; j++) {
  11358. if (bitmap[i][j]) {
  11359. buffer[offset] |= mask;
  11360. }
  11361. mask >>= 1;
  11362. if (!mask) {
  11363. mask = 128;
  11364. offset++;
  11365. }
  11366. }
  11367. offset0 += rowSize;
  11368. }
  11369. break;
  11370. case 2: // XOR
  11371. for (i = 0; i < height; i++) {
  11372. mask = mask0;
  11373. offset = offset0;
  11374. for (j = 0; j < width; j++) {
  11375. if (bitmap[i][j]) {
  11376. buffer[offset] ^= mask;
  11377. }
  11378. mask >>= 1;
  11379. if (!mask) {
  11380. mask = 128;
  11381. offset++;
  11382. }
  11383. }
  11384. offset0 += rowSize;
  11385. }
  11386. break;
  11387. default:
  11388. error('JBIG2 error: operator ' + combinationOperator +
  11389. ' is not supported');
  11390. }
  11391. },
  11392. onImmediateGenericRegion:
  11393. function SimpleSegmentVisitor_onImmediateGenericRegion(region, data,
  11394. start, end) {
  11395. var regionInfo = region.info;
  11396. var decodingContext = new DecodingContext(data, start, end);
  11397. var bitmap = decodeBitmap(region.mmr, regionInfo.width, regionInfo.height,
  11398. region.template, region.prediction, null,
  11399. region.at, decodingContext);
  11400. this.drawBitmap(regionInfo, bitmap);
  11401. },
  11402. onImmediateLosslessGenericRegion:
  11403. function SimpleSegmentVisitor_onImmediateLosslessGenericRegion() {
  11404. this.onImmediateGenericRegion.apply(this, arguments);
  11405. },
  11406. onSymbolDictionary:
  11407. function SimpleSegmentVisitor_onSymbolDictionary(dictionary,
  11408. currentSegment,
  11409. referredSegments,
  11410. data, start, end) {
  11411. var huffmanTables;
  11412. if (dictionary.huffman) {
  11413. error('JBIG2 error: huffman is not supported');
  11414. }
  11415. // Combines exported symbols from all referred segments
  11416. var symbols = this.symbols;
  11417. if (!symbols) {
  11418. this.symbols = symbols = {};
  11419. }
  11420. var inputSymbols = [];
  11421. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  11422. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  11423. }
  11424. var decodingContext = new DecodingContext(data, start, end);
  11425. symbols[currentSegment] = decodeSymbolDictionary(dictionary.huffman,
  11426. dictionary.refinement, inputSymbols, dictionary.numberOfNewSymbols,
  11427. dictionary.numberOfExportedSymbols, huffmanTables,
  11428. dictionary.template, dictionary.at,
  11429. dictionary.refinementTemplate, dictionary.refinementAt,
  11430. decodingContext);
  11431. },
  11432. onImmediateTextRegion:
  11433. function SimpleSegmentVisitor_onImmediateTextRegion(region,
  11434. referredSegments,
  11435. data, start, end) {
  11436. var regionInfo = region.info;
  11437. var huffmanTables;
  11438. // Combines exported symbols from all referred segments
  11439. var symbols = this.symbols;
  11440. var inputSymbols = [];
  11441. for (var i = 0, ii = referredSegments.length; i < ii; i++) {
  11442. inputSymbols = inputSymbols.concat(symbols[referredSegments[i]]);
  11443. }
  11444. var symbolCodeLength = log2(inputSymbols.length);
  11445. var decodingContext = new DecodingContext(data, start, end);
  11446. var bitmap = decodeTextRegion(region.huffman, region.refinement,
  11447. regionInfo.width, regionInfo.height, region.defaultPixelValue,
  11448. region.numberOfSymbolInstances, region.stripSize, inputSymbols,
  11449. symbolCodeLength, region.transposed, region.dsOffset,
  11450. region.referenceCorner, region.combinationOperator, huffmanTables,
  11451. region.refinementTemplate, region.refinementAt, decodingContext);
  11452. this.drawBitmap(regionInfo, bitmap);
  11453. },
  11454. onImmediateLosslessTextRegion:
  11455. function SimpleSegmentVisitor_onImmediateLosslessTextRegion() {
  11456. this.onImmediateTextRegion.apply(this, arguments);
  11457. }
  11458. };
  11459. function Jbig2Image() {}
  11460. Jbig2Image.prototype = {
  11461. parseChunks: function Jbig2Image_parseChunks(chunks) {
  11462. return parseJbig2Chunks(chunks);
  11463. }
  11464. };
  11465. return Jbig2Image;
  11466. })();
  11467. exports.Jbig2Image = Jbig2Image;
  11468. }));
  11469. (function (root, factory) {
  11470. {
  11471. factory((root.pdfjsCoreJpx = {}), root.pdfjsSharedUtil,
  11472. root.pdfjsCoreArithmeticDecoder);
  11473. }
  11474. }(this, function (exports, sharedUtil, coreArithmeticDecoder) {
  11475. var info = sharedUtil.info;
  11476. var log2 = sharedUtil.log2;
  11477. var readUint16 = sharedUtil.readUint16;
  11478. var readUint32 = sharedUtil.readUint32;
  11479. var warn = sharedUtil.warn;
  11480. var ArithmeticDecoder = coreArithmeticDecoder.ArithmeticDecoder;
  11481. var JpxImage = (function JpxImageClosure() {
  11482. // Table E.1
  11483. var SubbandsGainLog2 = {
  11484. 'LL': 0,
  11485. 'LH': 1,
  11486. 'HL': 1,
  11487. 'HH': 2
  11488. };
  11489. function JpxImage() {
  11490. this.failOnCorruptedImage = false;
  11491. }
  11492. JpxImage.prototype = {
  11493. parse: function JpxImage_parse(data) {
  11494. var head = readUint16(data, 0);
  11495. // No box header, immediate start of codestream (SOC)
  11496. if (head === 0xFF4F) {
  11497. this.parseCodestream(data, 0, data.length);
  11498. return;
  11499. }
  11500. var position = 0, length = data.length;
  11501. while (position < length) {
  11502. var headerSize = 8;
  11503. var lbox = readUint32(data, position);
  11504. var tbox = readUint32(data, position + 4);
  11505. position += headerSize;
  11506. if (lbox === 1) {
  11507. // XLBox: read UInt64 according to spec.
  11508. // JavaScript's int precision of 53 bit should be sufficient here.
  11509. lbox = readUint32(data, position) * 4294967296 +
  11510. readUint32(data, position + 4);
  11511. position += 8;
  11512. headerSize += 8;
  11513. }
  11514. if (lbox === 0) {
  11515. lbox = length - position + headerSize;
  11516. }
  11517. if (lbox < headerSize) {
  11518. throw new Error('JPX Error: Invalid box field size');
  11519. }
  11520. var dataLength = lbox - headerSize;
  11521. var jumpDataLength = true;
  11522. switch (tbox) {
  11523. case 0x6A703268: // 'jp2h'
  11524. jumpDataLength = false; // parsing child boxes
  11525. break;
  11526. case 0x636F6C72: // 'colr'
  11527. // Colorspaces are not used, the CS from the PDF is used.
  11528. var method = data[position];
  11529. if (method === 1) {
  11530. // enumerated colorspace
  11531. var colorspace = readUint32(data, position + 3);
  11532. switch (colorspace) {
  11533. case 16: // this indicates a sRGB colorspace
  11534. case 17: // this indicates a grayscale colorspace
  11535. case 18: // this indicates a YUV colorspace
  11536. break;
  11537. default:
  11538. warn('Unknown colorspace ' + colorspace);
  11539. break;
  11540. }
  11541. } else if (method === 2) {
  11542. info('ICC profile not supported');
  11543. }
  11544. break;
  11545. case 0x6A703263: // 'jp2c'
  11546. this.parseCodestream(data, position, position + dataLength);
  11547. break;
  11548. case 0x6A502020: // 'jP\024\024'
  11549. if (0x0d0a870a !== readUint32(data, position)) {
  11550. warn('Invalid JP2 signature');
  11551. }
  11552. break;
  11553. // The following header types are valid but currently not used:
  11554. case 0x6A501A1A: // 'jP\032\032'
  11555. case 0x66747970: // 'ftyp'
  11556. case 0x72726571: // 'rreq'
  11557. case 0x72657320: // 'res '
  11558. case 0x69686472: // 'ihdr'
  11559. break;
  11560. default:
  11561. var headerType = String.fromCharCode((tbox >> 24) & 0xFF,
  11562. (tbox >> 16) & 0xFF,
  11563. (tbox >> 8) & 0xFF,
  11564. tbox & 0xFF);
  11565. warn('Unsupported header type ' + tbox + ' (' + headerType + ')');
  11566. break;
  11567. }
  11568. if (jumpDataLength) {
  11569. position += dataLength;
  11570. }
  11571. }
  11572. },
  11573. parseImageProperties: function JpxImage_parseImageProperties(stream) {
  11574. var newByte = stream.getByte();
  11575. while (newByte >= 0) {
  11576. var oldByte = newByte;
  11577. newByte = stream.getByte();
  11578. var code = (oldByte << 8) | newByte;
  11579. // Image and tile size (SIZ)
  11580. if (code === 0xFF51) {
  11581. stream.skip(4);
  11582. var Xsiz = stream.getInt32() >>> 0; // Byte 4
  11583. var Ysiz = stream.getInt32() >>> 0; // Byte 8
  11584. var XOsiz = stream.getInt32() >>> 0; // Byte 12
  11585. var YOsiz = stream.getInt32() >>> 0; // Byte 16
  11586. stream.skip(16);
  11587. var Csiz = stream.getUint16(); // Byte 36
  11588. this.width = Xsiz - XOsiz;
  11589. this.height = Ysiz - YOsiz;
  11590. this.componentsCount = Csiz;
  11591. // Results are always returned as Uint8Arrays
  11592. this.bitsPerComponent = 8;
  11593. return;
  11594. }
  11595. }
  11596. throw new Error('JPX Error: No size marker found in JPX stream');
  11597. },
  11598. parseCodestream: function JpxImage_parseCodestream(data, start, end) {
  11599. var context = {};
  11600. try {
  11601. var doNotRecover = false;
  11602. var position = start;
  11603. while (position + 1 < end) {
  11604. var code = readUint16(data, position);
  11605. position += 2;
  11606. var length = 0, j, sqcd, spqcds, spqcdSize, scalarExpounded, tile;
  11607. switch (code) {
  11608. case 0xFF4F: // Start of codestream (SOC)
  11609. context.mainHeader = true;
  11610. break;
  11611. case 0xFFD9: // End of codestream (EOC)
  11612. break;
  11613. case 0xFF51: // Image and tile size (SIZ)
  11614. length = readUint16(data, position);
  11615. var siz = {};
  11616. siz.Xsiz = readUint32(data, position + 4);
  11617. siz.Ysiz = readUint32(data, position + 8);
  11618. siz.XOsiz = readUint32(data, position + 12);
  11619. siz.YOsiz = readUint32(data, position + 16);
  11620. siz.XTsiz = readUint32(data, position + 20);
  11621. siz.YTsiz = readUint32(data, position + 24);
  11622. siz.XTOsiz = readUint32(data, position + 28);
  11623. siz.YTOsiz = readUint32(data, position + 32);
  11624. var componentsCount = readUint16(data, position + 36);
  11625. siz.Csiz = componentsCount;
  11626. var components = [];
  11627. j = position + 38;
  11628. for (var i = 0; i < componentsCount; i++) {
  11629. var component = {
  11630. precision: (data[j] & 0x7F) + 1,
  11631. isSigned: !!(data[j] & 0x80),
  11632. XRsiz: data[j + 1],
  11633. YRsiz: data[j + 1]
  11634. };
  11635. calculateComponentDimensions(component, siz);
  11636. components.push(component);
  11637. }
  11638. context.SIZ = siz;
  11639. context.components = components;
  11640. calculateTileGrids(context, components);
  11641. context.QCC = [];
  11642. context.COC = [];
  11643. break;
  11644. case 0xFF5C: // Quantization default (QCD)
  11645. length = readUint16(data, position);
  11646. var qcd = {};
  11647. j = position + 2;
  11648. sqcd = data[j++];
  11649. switch (sqcd & 0x1F) {
  11650. case 0:
  11651. spqcdSize = 8;
  11652. scalarExpounded = true;
  11653. break;
  11654. case 1:
  11655. spqcdSize = 16;
  11656. scalarExpounded = false;
  11657. break;
  11658. case 2:
  11659. spqcdSize = 16;
  11660. scalarExpounded = true;
  11661. break;
  11662. default:
  11663. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  11664. }
  11665. qcd.noQuantization = (spqcdSize === 8);
  11666. qcd.scalarExpounded = scalarExpounded;
  11667. qcd.guardBits = sqcd >> 5;
  11668. spqcds = [];
  11669. while (j < length + position) {
  11670. var spqcd = {};
  11671. if (spqcdSize === 8) {
  11672. spqcd.epsilon = data[j++] >> 3;
  11673. spqcd.mu = 0;
  11674. } else {
  11675. spqcd.epsilon = data[j] >> 3;
  11676. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11677. j += 2;
  11678. }
  11679. spqcds.push(spqcd);
  11680. }
  11681. qcd.SPqcds = spqcds;
  11682. if (context.mainHeader) {
  11683. context.QCD = qcd;
  11684. } else {
  11685. context.currentTile.QCD = qcd;
  11686. context.currentTile.QCC = [];
  11687. }
  11688. break;
  11689. case 0xFF5D: // Quantization component (QCC)
  11690. length = readUint16(data, position);
  11691. var qcc = {};
  11692. j = position + 2;
  11693. var cqcc;
  11694. if (context.SIZ.Csiz < 257) {
  11695. cqcc = data[j++];
  11696. } else {
  11697. cqcc = readUint16(data, j);
  11698. j += 2;
  11699. }
  11700. sqcd = data[j++];
  11701. switch (sqcd & 0x1F) {
  11702. case 0:
  11703. spqcdSize = 8;
  11704. scalarExpounded = true;
  11705. break;
  11706. case 1:
  11707. spqcdSize = 16;
  11708. scalarExpounded = false;
  11709. break;
  11710. case 2:
  11711. spqcdSize = 16;
  11712. scalarExpounded = true;
  11713. break;
  11714. default:
  11715. throw new Error('JPX Error: Invalid SQcd value ' + sqcd);
  11716. }
  11717. qcc.noQuantization = (spqcdSize === 8);
  11718. qcc.scalarExpounded = scalarExpounded;
  11719. qcc.guardBits = sqcd >> 5;
  11720. spqcds = [];
  11721. while (j < (length + position)) {
  11722. spqcd = {};
  11723. if (spqcdSize === 8) {
  11724. spqcd.epsilon = data[j++] >> 3;
  11725. spqcd.mu = 0;
  11726. } else {
  11727. spqcd.epsilon = data[j] >> 3;
  11728. spqcd.mu = ((data[j] & 0x7) << 8) | data[j + 1];
  11729. j += 2;
  11730. }
  11731. spqcds.push(spqcd);
  11732. }
  11733. qcc.SPqcds = spqcds;
  11734. if (context.mainHeader) {
  11735. context.QCC[cqcc] = qcc;
  11736. } else {
  11737. context.currentTile.QCC[cqcc] = qcc;
  11738. }
  11739. break;
  11740. case 0xFF52: // Coding style default (COD)
  11741. length = readUint16(data, position);
  11742. var cod = {};
  11743. j = position + 2;
  11744. var scod = data[j++];
  11745. cod.entropyCoderWithCustomPrecincts = !!(scod & 1);
  11746. cod.sopMarkerUsed = !!(scod & 2);
  11747. cod.ephMarkerUsed = !!(scod & 4);
  11748. cod.progressionOrder = data[j++];
  11749. cod.layersCount = readUint16(data, j);
  11750. j += 2;
  11751. cod.multipleComponentTransform = data[j++];
  11752. cod.decompositionLevelsCount = data[j++];
  11753. cod.xcb = (data[j++] & 0xF) + 2;
  11754. cod.ycb = (data[j++] & 0xF) + 2;
  11755. var blockStyle = data[j++];
  11756. cod.selectiveArithmeticCodingBypass = !!(blockStyle & 1);
  11757. cod.resetContextProbabilities = !!(blockStyle & 2);
  11758. cod.terminationOnEachCodingPass = !!(blockStyle & 4);
  11759. cod.verticalyStripe = !!(blockStyle & 8);
  11760. cod.predictableTermination = !!(blockStyle & 16);
  11761. cod.segmentationSymbolUsed = !!(blockStyle & 32);
  11762. cod.reversibleTransformation = data[j++];
  11763. if (cod.entropyCoderWithCustomPrecincts) {
  11764. var precinctsSizes = [];
  11765. while (j < length + position) {
  11766. var precinctsSize = data[j++];
  11767. precinctsSizes.push({
  11768. PPx: precinctsSize & 0xF,
  11769. PPy: precinctsSize >> 4
  11770. });
  11771. }
  11772. cod.precinctsSizes = precinctsSizes;
  11773. }
  11774. var unsupported = [];
  11775. if (cod.selectiveArithmeticCodingBypass) {
  11776. unsupported.push('selectiveArithmeticCodingBypass');
  11777. }
  11778. if (cod.resetContextProbabilities) {
  11779. unsupported.push('resetContextProbabilities');
  11780. }
  11781. if (cod.terminationOnEachCodingPass) {
  11782. unsupported.push('terminationOnEachCodingPass');
  11783. }
  11784. if (cod.verticalyStripe) {
  11785. unsupported.push('verticalyStripe');
  11786. }
  11787. if (cod.predictableTermination) {
  11788. unsupported.push('predictableTermination');
  11789. }
  11790. if (unsupported.length > 0) {
  11791. doNotRecover = true;
  11792. throw new Error('JPX Error: Unsupported COD options (' +
  11793. unsupported.join(', ') + ')');
  11794. }
  11795. if (context.mainHeader) {
  11796. context.COD = cod;
  11797. } else {
  11798. context.currentTile.COD = cod;
  11799. context.currentTile.COC = [];
  11800. }
  11801. break;
  11802. case 0xFF90: // Start of tile-part (SOT)
  11803. length = readUint16(data, position);
  11804. tile = {};
  11805. tile.index = readUint16(data, position + 2);
  11806. tile.length = readUint32(data, position + 4);
  11807. tile.dataEnd = tile.length + position - 2;
  11808. tile.partIndex = data[position + 8];
  11809. tile.partsCount = data[position + 9];
  11810. context.mainHeader = false;
  11811. if (tile.partIndex === 0) {
  11812. // reset component specific settings
  11813. tile.COD = context.COD;
  11814. tile.COC = context.COC.slice(0); // clone of the global COC
  11815. tile.QCD = context.QCD;
  11816. tile.QCC = context.QCC.slice(0); // clone of the global COC
  11817. }
  11818. context.currentTile = tile;
  11819. break;
  11820. case 0xFF93: // Start of data (SOD)
  11821. tile = context.currentTile;
  11822. if (tile.partIndex === 0) {
  11823. initializeTile(context, tile.index);
  11824. buildPackets(context);
  11825. }
  11826. // moving to the end of the data
  11827. length = tile.dataEnd - position;
  11828. parseTilePackets(context, data, position, length);
  11829. break;
  11830. case 0xFF55: // Tile-part lengths, main header (TLM)
  11831. case 0xFF57: // Packet length, main header (PLM)
  11832. case 0xFF58: // Packet length, tile-part header (PLT)
  11833. case 0xFF64: // Comment (COM)
  11834. length = readUint16(data, position);
  11835. // skipping content
  11836. break;
  11837. case 0xFF53: // Coding style component (COC)
  11838. throw new Error('JPX Error: Codestream code 0xFF53 (COC) is ' +
  11839. 'not implemented');
  11840. default:
  11841. throw new Error('JPX Error: Unknown codestream code: ' +
  11842. code.toString(16));
  11843. }
  11844. position += length;
  11845. }
  11846. } catch (e) {
  11847. if (doNotRecover || this.failOnCorruptedImage) {
  11848. throw e;
  11849. } else {
  11850. warn('Trying to recover from ' + e.message);
  11851. }
  11852. }
  11853. this.tiles = transformComponents(context);
  11854. this.width = context.SIZ.Xsiz - context.SIZ.XOsiz;
  11855. this.height = context.SIZ.Ysiz - context.SIZ.YOsiz;
  11856. this.componentsCount = context.SIZ.Csiz;
  11857. }
  11858. };
  11859. function calculateComponentDimensions(component, siz) {
  11860. // Section B.2 Component mapping
  11861. component.x0 = Math.ceil(siz.XOsiz / component.XRsiz);
  11862. component.x1 = Math.ceil(siz.Xsiz / component.XRsiz);
  11863. component.y0 = Math.ceil(siz.YOsiz / component.YRsiz);
  11864. component.y1 = Math.ceil(siz.Ysiz / component.YRsiz);
  11865. component.width = component.x1 - component.x0;
  11866. component.height = component.y1 - component.y0;
  11867. }
  11868. function calculateTileGrids(context, components) {
  11869. var siz = context.SIZ;
  11870. // Section B.3 Division into tile and tile-components
  11871. var tile, tiles = [];
  11872. var numXtiles = Math.ceil((siz.Xsiz - siz.XTOsiz) / siz.XTsiz);
  11873. var numYtiles = Math.ceil((siz.Ysiz - siz.YTOsiz) / siz.YTsiz);
  11874. for (var q = 0; q < numYtiles; q++) {
  11875. for (var p = 0; p < numXtiles; p++) {
  11876. tile = {};
  11877. tile.tx0 = Math.max(siz.XTOsiz + p * siz.XTsiz, siz.XOsiz);
  11878. tile.ty0 = Math.max(siz.YTOsiz + q * siz.YTsiz, siz.YOsiz);
  11879. tile.tx1 = Math.min(siz.XTOsiz + (p + 1) * siz.XTsiz, siz.Xsiz);
  11880. tile.ty1 = Math.min(siz.YTOsiz + (q + 1) * siz.YTsiz, siz.Ysiz);
  11881. tile.width = tile.tx1 - tile.tx0;
  11882. tile.height = tile.ty1 - tile.ty0;
  11883. tile.components = [];
  11884. tiles.push(tile);
  11885. }
  11886. }
  11887. context.tiles = tiles;
  11888. var componentsCount = siz.Csiz;
  11889. for (var i = 0, ii = componentsCount; i < ii; i++) {
  11890. var component = components[i];
  11891. for (var j = 0, jj = tiles.length; j < jj; j++) {
  11892. var tileComponent = {};
  11893. tile = tiles[j];
  11894. tileComponent.tcx0 = Math.ceil(tile.tx0 / component.XRsiz);
  11895. tileComponent.tcy0 = Math.ceil(tile.ty0 / component.YRsiz);
  11896. tileComponent.tcx1 = Math.ceil(tile.tx1 / component.XRsiz);
  11897. tileComponent.tcy1 = Math.ceil(tile.ty1 / component.YRsiz);
  11898. tileComponent.width = tileComponent.tcx1 - tileComponent.tcx0;
  11899. tileComponent.height = tileComponent.tcy1 - tileComponent.tcy0;
  11900. tile.components[i] = tileComponent;
  11901. }
  11902. }
  11903. }
  11904. function getBlocksDimensions(context, component, r) {
  11905. var codOrCoc = component.codingStyleParameters;
  11906. var result = {};
  11907. if (!codOrCoc.entropyCoderWithCustomPrecincts) {
  11908. result.PPx = 15;
  11909. result.PPy = 15;
  11910. } else {
  11911. result.PPx = codOrCoc.precinctsSizes[r].PPx;
  11912. result.PPy = codOrCoc.precinctsSizes[r].PPy;
  11913. }
  11914. // calculate codeblock size as described in section B.7
  11915. result.xcb_ = (r > 0 ? Math.min(codOrCoc.xcb, result.PPx - 1) :
  11916. Math.min(codOrCoc.xcb, result.PPx));
  11917. result.ycb_ = (r > 0 ? Math.min(codOrCoc.ycb, result.PPy - 1) :
  11918. Math.min(codOrCoc.ycb, result.PPy));
  11919. return result;
  11920. }
  11921. function buildPrecincts(context, resolution, dimensions) {
  11922. // Section B.6 Division resolution to precincts
  11923. var precinctWidth = 1 << dimensions.PPx;
  11924. var precinctHeight = 1 << dimensions.PPy;
  11925. // Jasper introduces codeblock groups for mapping each subband codeblocks
  11926. // to precincts. Precinct partition divides a resolution according to width
  11927. // and height parameters. The subband that belongs to the resolution level
  11928. // has a different size than the level, unless it is the zero resolution.
  11929. // From Jasper documentation: jpeg2000.pdf, section K: Tier-2 coding:
  11930. // The precinct partitioning for a particular subband is derived from a
  11931. // partitioning of its parent LL band (i.e., the LL band at the next higher
  11932. // resolution level)... The LL band associated with each resolution level is
  11933. // divided into precincts... Each of the resulting precinct regions is then
  11934. // mapped into its child subbands (if any) at the next lower resolution
  11935. // level. This is accomplished by using the coordinate transformation
  11936. // (u, v) = (ceil(x/2), ceil(y/2)) where (x, y) and (u, v) are the
  11937. // coordinates of a point in the LL band and child subband, respectively.
  11938. var isZeroRes = resolution.resLevel === 0;
  11939. var precinctWidthInSubband = 1 << (dimensions.PPx + (isZeroRes ? 0 : -1));
  11940. var precinctHeightInSubband = 1 << (dimensions.PPy + (isZeroRes ? 0 : -1));
  11941. var numprecinctswide = (resolution.trx1 > resolution.trx0 ?
  11942. Math.ceil(resolution.trx1 / precinctWidth) -
  11943. Math.floor(resolution.trx0 / precinctWidth) : 0);
  11944. var numprecinctshigh = (resolution.try1 > resolution.try0 ?
  11945. Math.ceil(resolution.try1 / precinctHeight) -
  11946. Math.floor(resolution.try0 / precinctHeight) : 0);
  11947. var numprecincts = numprecinctswide * numprecinctshigh;
  11948. resolution.precinctParameters = {
  11949. precinctWidth: precinctWidth,
  11950. precinctHeight: precinctHeight,
  11951. numprecinctswide: numprecinctswide,
  11952. numprecinctshigh: numprecinctshigh,
  11953. numprecincts: numprecincts,
  11954. precinctWidthInSubband: precinctWidthInSubband,
  11955. precinctHeightInSubband: precinctHeightInSubband
  11956. };
  11957. }
  11958. function buildCodeblocks(context, subband, dimensions) {
  11959. // Section B.7 Division sub-band into code-blocks
  11960. var xcb_ = dimensions.xcb_;
  11961. var ycb_ = dimensions.ycb_;
  11962. var codeblockWidth = 1 << xcb_;
  11963. var codeblockHeight = 1 << ycb_;
  11964. var cbx0 = subband.tbx0 >> xcb_;
  11965. var cby0 = subband.tby0 >> ycb_;
  11966. var cbx1 = (subband.tbx1 + codeblockWidth - 1) >> xcb_;
  11967. var cby1 = (subband.tby1 + codeblockHeight - 1) >> ycb_;
  11968. var precinctParameters = subband.resolution.precinctParameters;
  11969. var codeblocks = [];
  11970. var precincts = [];
  11971. var i, j, codeblock, precinctNumber;
  11972. for (j = cby0; j < cby1; j++) {
  11973. for (i = cbx0; i < cbx1; i++) {
  11974. codeblock = {
  11975. cbx: i,
  11976. cby: j,
  11977. tbx0: codeblockWidth * i,
  11978. tby0: codeblockHeight * j,
  11979. tbx1: codeblockWidth * (i + 1),
  11980. tby1: codeblockHeight * (j + 1)
  11981. };
  11982. codeblock.tbx0_ = Math.max(subband.tbx0, codeblock.tbx0);
  11983. codeblock.tby0_ = Math.max(subband.tby0, codeblock.tby0);
  11984. codeblock.tbx1_ = Math.min(subband.tbx1, codeblock.tbx1);
  11985. codeblock.tby1_ = Math.min(subband.tby1, codeblock.tby1);
  11986. // Calculate precinct number for this codeblock, codeblock position
  11987. // should be relative to its subband, use actual dimension and position
  11988. // See comment about codeblock group width and height
  11989. var pi = Math.floor((codeblock.tbx0_ - subband.tbx0) /
  11990. precinctParameters.precinctWidthInSubband);
  11991. var pj = Math.floor((codeblock.tby0_ - subband.tby0) /
  11992. precinctParameters.precinctHeightInSubband);
  11993. precinctNumber = pi + (pj * precinctParameters.numprecinctswide);
  11994. codeblock.precinctNumber = precinctNumber;
  11995. codeblock.subbandType = subband.type;
  11996. codeblock.Lblock = 3;
  11997. if (codeblock.tbx1_ <= codeblock.tbx0_ ||
  11998. codeblock.tby1_ <= codeblock.tby0_) {
  11999. continue;
  12000. }
  12001. codeblocks.push(codeblock);
  12002. // building precinct for the sub-band
  12003. var precinct = precincts[precinctNumber];
  12004. if (precinct !== undefined) {
  12005. if (i < precinct.cbxMin) {
  12006. precinct.cbxMin = i;
  12007. } else if (i > precinct.cbxMax) {
  12008. precinct.cbxMax = i;
  12009. }
  12010. if (j < precinct.cbyMin) {
  12011. precinct.cbxMin = j;
  12012. } else if (j > precinct.cbyMax) {
  12013. precinct.cbyMax = j;
  12014. }
  12015. } else {
  12016. precincts[precinctNumber] = precinct = {
  12017. cbxMin: i,
  12018. cbyMin: j,
  12019. cbxMax: i,
  12020. cbyMax: j
  12021. };
  12022. }
  12023. codeblock.precinct = precinct;
  12024. }
  12025. }
  12026. subband.codeblockParameters = {
  12027. codeblockWidth: xcb_,
  12028. codeblockHeight: ycb_,
  12029. numcodeblockwide: cbx1 - cbx0 + 1,
  12030. numcodeblockhigh: cby1 - cby0 + 1
  12031. };
  12032. subband.codeblocks = codeblocks;
  12033. subband.precincts = precincts;
  12034. }
  12035. function createPacket(resolution, precinctNumber, layerNumber) {
  12036. var precinctCodeblocks = [];
  12037. // Section B.10.8 Order of info in packet
  12038. var subbands = resolution.subbands;
  12039. // sub-bands already ordered in 'LL', 'HL', 'LH', and 'HH' sequence
  12040. for (var i = 0, ii = subbands.length; i < ii; i++) {
  12041. var subband = subbands[i];
  12042. var codeblocks = subband.codeblocks;
  12043. for (var j = 0, jj = codeblocks.length; j < jj; j++) {
  12044. var codeblock = codeblocks[j];
  12045. if (codeblock.precinctNumber !== precinctNumber) {
  12046. continue;
  12047. }
  12048. precinctCodeblocks.push(codeblock);
  12049. }
  12050. }
  12051. return {
  12052. layerNumber: layerNumber,
  12053. codeblocks: precinctCodeblocks
  12054. };
  12055. }
  12056. function LayerResolutionComponentPositionIterator(context) {
  12057. var siz = context.SIZ;
  12058. var tileIndex = context.currentTile.index;
  12059. var tile = context.tiles[tileIndex];
  12060. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12061. var componentsCount = siz.Csiz;
  12062. var maxDecompositionLevelsCount = 0;
  12063. for (var q = 0; q < componentsCount; q++) {
  12064. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12065. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12066. }
  12067. var l = 0, r = 0, i = 0, k = 0;
  12068. this.nextPacket = function JpxImage_nextPacket() {
  12069. // Section B.12.1.1 Layer-resolution-component-position
  12070. for (; l < layersCount; l++) {
  12071. for (; r <= maxDecompositionLevelsCount; r++) {
  12072. for (; i < componentsCount; i++) {
  12073. var component = tile.components[i];
  12074. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12075. continue;
  12076. }
  12077. var resolution = component.resolutions[r];
  12078. var numprecincts = resolution.precinctParameters.numprecincts;
  12079. for (; k < numprecincts;) {
  12080. var packet = createPacket(resolution, k, l);
  12081. k++;
  12082. return packet;
  12083. }
  12084. k = 0;
  12085. }
  12086. i = 0;
  12087. }
  12088. r = 0;
  12089. }
  12090. throw new Error('JPX Error: Out of packets');
  12091. };
  12092. }
  12093. function ResolutionLayerComponentPositionIterator(context) {
  12094. var siz = context.SIZ;
  12095. var tileIndex = context.currentTile.index;
  12096. var tile = context.tiles[tileIndex];
  12097. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12098. var componentsCount = siz.Csiz;
  12099. var maxDecompositionLevelsCount = 0;
  12100. for (var q = 0; q < componentsCount; q++) {
  12101. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12102. tile.components[q].codingStyleParameters.decompositionLevelsCount);
  12103. }
  12104. var r = 0, l = 0, i = 0, k = 0;
  12105. this.nextPacket = function JpxImage_nextPacket() {
  12106. // Section B.12.1.2 Resolution-layer-component-position
  12107. for (; r <= maxDecompositionLevelsCount; r++) {
  12108. for (; l < layersCount; l++) {
  12109. for (; i < componentsCount; i++) {
  12110. var component = tile.components[i];
  12111. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12112. continue;
  12113. }
  12114. var resolution = component.resolutions[r];
  12115. var numprecincts = resolution.precinctParameters.numprecincts;
  12116. for (; k < numprecincts;) {
  12117. var packet = createPacket(resolution, k, l);
  12118. k++;
  12119. return packet;
  12120. }
  12121. k = 0;
  12122. }
  12123. i = 0;
  12124. }
  12125. l = 0;
  12126. }
  12127. throw new Error('JPX Error: Out of packets');
  12128. };
  12129. }
  12130. function ResolutionPositionComponentLayerIterator(context) {
  12131. var siz = context.SIZ;
  12132. var tileIndex = context.currentTile.index;
  12133. var tile = context.tiles[tileIndex];
  12134. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12135. var componentsCount = siz.Csiz;
  12136. var l, r, c, p;
  12137. var maxDecompositionLevelsCount = 0;
  12138. for (c = 0; c < componentsCount; c++) {
  12139. var component = tile.components[c];
  12140. maxDecompositionLevelsCount = Math.max(maxDecompositionLevelsCount,
  12141. component.codingStyleParameters.decompositionLevelsCount);
  12142. }
  12143. var maxNumPrecinctsInLevel = new Int32Array(
  12144. maxDecompositionLevelsCount + 1);
  12145. for (r = 0; r <= maxDecompositionLevelsCount; ++r) {
  12146. var maxNumPrecincts = 0;
  12147. for (c = 0; c < componentsCount; ++c) {
  12148. var resolutions = tile.components[c].resolutions;
  12149. if (r < resolutions.length) {
  12150. maxNumPrecincts = Math.max(maxNumPrecincts,
  12151. resolutions[r].precinctParameters.numprecincts);
  12152. }
  12153. }
  12154. maxNumPrecinctsInLevel[r] = maxNumPrecincts;
  12155. }
  12156. l = 0;
  12157. r = 0;
  12158. c = 0;
  12159. p = 0;
  12160. this.nextPacket = function JpxImage_nextPacket() {
  12161. // Section B.12.1.3 Resolution-position-component-layer
  12162. for (; r <= maxDecompositionLevelsCount; r++) {
  12163. for (; p < maxNumPrecinctsInLevel[r]; p++) {
  12164. for (; c < componentsCount; c++) {
  12165. var component = tile.components[c];
  12166. if (r > component.codingStyleParameters.decompositionLevelsCount) {
  12167. continue;
  12168. }
  12169. var resolution = component.resolutions[r];
  12170. var numprecincts = resolution.precinctParameters.numprecincts;
  12171. if (p >= numprecincts) {
  12172. continue;
  12173. }
  12174. for (; l < layersCount;) {
  12175. var packet = createPacket(resolution, p, l);
  12176. l++;
  12177. return packet;
  12178. }
  12179. l = 0;
  12180. }
  12181. c = 0;
  12182. }
  12183. p = 0;
  12184. }
  12185. throw new Error('JPX Error: Out of packets');
  12186. };
  12187. }
  12188. function PositionComponentResolutionLayerIterator(context) {
  12189. var siz = context.SIZ;
  12190. var tileIndex = context.currentTile.index;
  12191. var tile = context.tiles[tileIndex];
  12192. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12193. var componentsCount = siz.Csiz;
  12194. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12195. var precinctsIterationSizes = precinctsSizes;
  12196. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12197. this.nextPacket = function JpxImage_nextPacket() {
  12198. // Section B.12.1.4 Position-component-resolution-layer
  12199. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12200. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12201. for (; c < componentsCount; c++) {
  12202. var component = tile.components[c];
  12203. var decompositionLevelsCount =
  12204. component.codingStyleParameters.decompositionLevelsCount;
  12205. for (; r <= decompositionLevelsCount; r++) {
  12206. var resolution = component.resolutions[r];
  12207. var sizeInImageScale =
  12208. precinctsSizes.components[c].resolutions[r];
  12209. var k = getPrecinctIndexIfExist(
  12210. px,
  12211. py,
  12212. sizeInImageScale,
  12213. precinctsIterationSizes,
  12214. resolution);
  12215. if (k === null) {
  12216. continue;
  12217. }
  12218. for (; l < layersCount;) {
  12219. var packet = createPacket(resolution, k, l);
  12220. l++;
  12221. return packet;
  12222. }
  12223. l = 0;
  12224. }
  12225. r = 0;
  12226. }
  12227. c = 0;
  12228. }
  12229. px = 0;
  12230. }
  12231. throw new Error('JPX Error: Out of packets');
  12232. };
  12233. }
  12234. function ComponentPositionResolutionLayerIterator(context) {
  12235. var siz = context.SIZ;
  12236. var tileIndex = context.currentTile.index;
  12237. var tile = context.tiles[tileIndex];
  12238. var layersCount = tile.codingStyleDefaultParameters.layersCount;
  12239. var componentsCount = siz.Csiz;
  12240. var precinctsSizes = getPrecinctSizesInImageScale(tile);
  12241. var l = 0, r = 0, c = 0, px = 0, py = 0;
  12242. this.nextPacket = function JpxImage_nextPacket() {
  12243. // Section B.12.1.5 Component-position-resolution-layer
  12244. for (; c < componentsCount; ++c) {
  12245. var component = tile.components[c];
  12246. var precinctsIterationSizes = precinctsSizes.components[c];
  12247. var decompositionLevelsCount =
  12248. component.codingStyleParameters.decompositionLevelsCount;
  12249. for (; py < precinctsIterationSizes.maxNumHigh; py++) {
  12250. for (; px < precinctsIterationSizes.maxNumWide; px++) {
  12251. for (; r <= decompositionLevelsCount; r++) {
  12252. var resolution = component.resolutions[r];
  12253. var sizeInImageScale = precinctsIterationSizes.resolutions[r];
  12254. var k = getPrecinctIndexIfExist(
  12255. px,
  12256. py,
  12257. sizeInImageScale,
  12258. precinctsIterationSizes,
  12259. resolution);
  12260. if (k === null) {
  12261. continue;
  12262. }
  12263. for (; l < layersCount;) {
  12264. var packet = createPacket(resolution, k, l);
  12265. l++;
  12266. return packet;
  12267. }
  12268. l = 0;
  12269. }
  12270. r = 0;
  12271. }
  12272. px = 0;
  12273. }
  12274. py = 0;
  12275. }
  12276. throw new Error('JPX Error: Out of packets');
  12277. };
  12278. }
  12279. function getPrecinctIndexIfExist(
  12280. pxIndex, pyIndex, sizeInImageScale, precinctIterationSizes, resolution) {
  12281. var posX = pxIndex * precinctIterationSizes.minWidth;
  12282. var posY = pyIndex * precinctIterationSizes.minHeight;
  12283. if (posX % sizeInImageScale.width !== 0 ||
  12284. posY % sizeInImageScale.height !== 0) {
  12285. return null;
  12286. }
  12287. var startPrecinctRowIndex =
  12288. (posY / sizeInImageScale.width) *
  12289. resolution.precinctParameters.numprecinctswide;
  12290. return (posX / sizeInImageScale.height) + startPrecinctRowIndex;
  12291. }
  12292. function getPrecinctSizesInImageScale(tile) {
  12293. var componentsCount = tile.components.length;
  12294. var minWidth = Number.MAX_VALUE;
  12295. var minHeight = Number.MAX_VALUE;
  12296. var maxNumWide = 0;
  12297. var maxNumHigh = 0;
  12298. var sizePerComponent = new Array(componentsCount);
  12299. for (var c = 0; c < componentsCount; c++) {
  12300. var component = tile.components[c];
  12301. var decompositionLevelsCount =
  12302. component.codingStyleParameters.decompositionLevelsCount;
  12303. var sizePerResolution = new Array(decompositionLevelsCount + 1);
  12304. var minWidthCurrentComponent = Number.MAX_VALUE;
  12305. var minHeightCurrentComponent = Number.MAX_VALUE;
  12306. var maxNumWideCurrentComponent = 0;
  12307. var maxNumHighCurrentComponent = 0;
  12308. var scale = 1;
  12309. for (var r = decompositionLevelsCount; r >= 0; --r) {
  12310. var resolution = component.resolutions[r];
  12311. var widthCurrentResolution =
  12312. scale * resolution.precinctParameters.precinctWidth;
  12313. var heightCurrentResolution =
  12314. scale * resolution.precinctParameters.precinctHeight;
  12315. minWidthCurrentComponent = Math.min(
  12316. minWidthCurrentComponent,
  12317. widthCurrentResolution);
  12318. minHeightCurrentComponent = Math.min(
  12319. minHeightCurrentComponent,
  12320. heightCurrentResolution);
  12321. maxNumWideCurrentComponent = Math.max(maxNumWideCurrentComponent,
  12322. resolution.precinctParameters.numprecinctswide);
  12323. maxNumHighCurrentComponent = Math.max(maxNumHighCurrentComponent,
  12324. resolution.precinctParameters.numprecinctshigh);
  12325. sizePerResolution[r] = {
  12326. width: widthCurrentResolution,
  12327. height: heightCurrentResolution
  12328. };
  12329. scale <<= 1;
  12330. }
  12331. minWidth = Math.min(minWidth, minWidthCurrentComponent);
  12332. minHeight = Math.min(minHeight, minHeightCurrentComponent);
  12333. maxNumWide = Math.max(maxNumWide, maxNumWideCurrentComponent);
  12334. maxNumHigh = Math.max(maxNumHigh, maxNumHighCurrentComponent);
  12335. sizePerComponent[c] = {
  12336. resolutions: sizePerResolution,
  12337. minWidth: minWidthCurrentComponent,
  12338. minHeight: minHeightCurrentComponent,
  12339. maxNumWide: maxNumWideCurrentComponent,
  12340. maxNumHigh: maxNumHighCurrentComponent
  12341. };
  12342. }
  12343. return {
  12344. components: sizePerComponent,
  12345. minWidth: minWidth,
  12346. minHeight: minHeight,
  12347. maxNumWide: maxNumWide,
  12348. maxNumHigh: maxNumHigh
  12349. };
  12350. }
  12351. function buildPackets(context) {
  12352. var siz = context.SIZ;
  12353. var tileIndex = context.currentTile.index;
  12354. var tile = context.tiles[tileIndex];
  12355. var componentsCount = siz.Csiz;
  12356. // Creating resolutions and sub-bands for each component
  12357. for (var c = 0; c < componentsCount; c++) {
  12358. var component = tile.components[c];
  12359. var decompositionLevelsCount =
  12360. component.codingStyleParameters.decompositionLevelsCount;
  12361. // Section B.5 Resolution levels and sub-bands
  12362. var resolutions = [];
  12363. var subbands = [];
  12364. for (var r = 0; r <= decompositionLevelsCount; r++) {
  12365. var blocksDimensions = getBlocksDimensions(context, component, r);
  12366. var resolution = {};
  12367. var scale = 1 << (decompositionLevelsCount - r);
  12368. resolution.trx0 = Math.ceil(component.tcx0 / scale);
  12369. resolution.try0 = Math.ceil(component.tcy0 / scale);
  12370. resolution.trx1 = Math.ceil(component.tcx1 / scale);
  12371. resolution.try1 = Math.ceil(component.tcy1 / scale);
  12372. resolution.resLevel = r;
  12373. buildPrecincts(context, resolution, blocksDimensions);
  12374. resolutions.push(resolution);
  12375. var subband;
  12376. if (r === 0) {
  12377. // one sub-band (LL) with last decomposition
  12378. subband = {};
  12379. subband.type = 'LL';
  12380. subband.tbx0 = Math.ceil(component.tcx0 / scale);
  12381. subband.tby0 = Math.ceil(component.tcy0 / scale);
  12382. subband.tbx1 = Math.ceil(component.tcx1 / scale);
  12383. subband.tby1 = Math.ceil(component.tcy1 / scale);
  12384. subband.resolution = resolution;
  12385. buildCodeblocks(context, subband, blocksDimensions);
  12386. subbands.push(subband);
  12387. resolution.subbands = [subband];
  12388. } else {
  12389. var bscale = 1 << (decompositionLevelsCount - r + 1);
  12390. var resolutionSubbands = [];
  12391. // three sub-bands (HL, LH and HH) with rest of decompositions
  12392. subband = {};
  12393. subband.type = 'HL';
  12394. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12395. subband.tby0 = Math.ceil(component.tcy0 / bscale);
  12396. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12397. subband.tby1 = Math.ceil(component.tcy1 / bscale);
  12398. subband.resolution = resolution;
  12399. buildCodeblocks(context, subband, blocksDimensions);
  12400. subbands.push(subband);
  12401. resolutionSubbands.push(subband);
  12402. subband = {};
  12403. subband.type = 'LH';
  12404. subband.tbx0 = Math.ceil(component.tcx0 / bscale);
  12405. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12406. subband.tbx1 = Math.ceil(component.tcx1 / bscale);
  12407. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12408. subband.resolution = resolution;
  12409. buildCodeblocks(context, subband, blocksDimensions);
  12410. subbands.push(subband);
  12411. resolutionSubbands.push(subband);
  12412. subband = {};
  12413. subband.type = 'HH';
  12414. subband.tbx0 = Math.ceil(component.tcx0 / bscale - 0.5);
  12415. subband.tby0 = Math.ceil(component.tcy0 / bscale - 0.5);
  12416. subband.tbx1 = Math.ceil(component.tcx1 / bscale - 0.5);
  12417. subband.tby1 = Math.ceil(component.tcy1 / bscale - 0.5);
  12418. subband.resolution = resolution;
  12419. buildCodeblocks(context, subband, blocksDimensions);
  12420. subbands.push(subband);
  12421. resolutionSubbands.push(subband);
  12422. resolution.subbands = resolutionSubbands;
  12423. }
  12424. }
  12425. component.resolutions = resolutions;
  12426. component.subbands = subbands;
  12427. }
  12428. // Generate the packets sequence
  12429. var progressionOrder = tile.codingStyleDefaultParameters.progressionOrder;
  12430. switch (progressionOrder) {
  12431. case 0:
  12432. tile.packetsIterator =
  12433. new LayerResolutionComponentPositionIterator(context);
  12434. break;
  12435. case 1:
  12436. tile.packetsIterator =
  12437. new ResolutionLayerComponentPositionIterator(context);
  12438. break;
  12439. case 2:
  12440. tile.packetsIterator =
  12441. new ResolutionPositionComponentLayerIterator(context);
  12442. break;
  12443. case 3:
  12444. tile.packetsIterator =
  12445. new PositionComponentResolutionLayerIterator(context);
  12446. break;
  12447. case 4:
  12448. tile.packetsIterator =
  12449. new ComponentPositionResolutionLayerIterator(context);
  12450. break;
  12451. default:
  12452. throw new Error('JPX Error: Unsupported progression order ' +
  12453. progressionOrder);
  12454. }
  12455. }
  12456. function parseTilePackets(context, data, offset, dataLength) {
  12457. var position = 0;
  12458. var buffer, bufferSize = 0, skipNextBit = false;
  12459. function readBits(count) {
  12460. while (bufferSize < count) {
  12461. var b = data[offset + position];
  12462. position++;
  12463. if (skipNextBit) {
  12464. buffer = (buffer << 7) | b;
  12465. bufferSize += 7;
  12466. skipNextBit = false;
  12467. } else {
  12468. buffer = (buffer << 8) | b;
  12469. bufferSize += 8;
  12470. }
  12471. if (b === 0xFF) {
  12472. skipNextBit = true;
  12473. }
  12474. }
  12475. bufferSize -= count;
  12476. return (buffer >>> bufferSize) & ((1 << count) - 1);
  12477. }
  12478. function skipMarkerIfEqual(value) {
  12479. if (data[offset + position - 1] === 0xFF &&
  12480. data[offset + position] === value) {
  12481. skipBytes(1);
  12482. return true;
  12483. } else if (data[offset + position] === 0xFF &&
  12484. data[offset + position + 1] === value) {
  12485. skipBytes(2);
  12486. return true;
  12487. }
  12488. return false;
  12489. }
  12490. function skipBytes(count) {
  12491. position += count;
  12492. }
  12493. function alignToByte() {
  12494. bufferSize = 0;
  12495. if (skipNextBit) {
  12496. position++;
  12497. skipNextBit = false;
  12498. }
  12499. }
  12500. function readCodingpasses() {
  12501. if (readBits(1) === 0) {
  12502. return 1;
  12503. }
  12504. if (readBits(1) === 0) {
  12505. return 2;
  12506. }
  12507. var value = readBits(2);
  12508. if (value < 3) {
  12509. return value + 3;
  12510. }
  12511. value = readBits(5);
  12512. if (value < 31) {
  12513. return value + 6;
  12514. }
  12515. value = readBits(7);
  12516. return value + 37;
  12517. }
  12518. var tileIndex = context.currentTile.index;
  12519. var tile = context.tiles[tileIndex];
  12520. var sopMarkerUsed = context.COD.sopMarkerUsed;
  12521. var ephMarkerUsed = context.COD.ephMarkerUsed;
  12522. var packetsIterator = tile.packetsIterator;
  12523. while (position < dataLength) {
  12524. alignToByte();
  12525. if (sopMarkerUsed && skipMarkerIfEqual(0x91)) {
  12526. // Skip also marker segment length and packet sequence ID
  12527. skipBytes(4);
  12528. }
  12529. var packet = packetsIterator.nextPacket();
  12530. if (!readBits(1)) {
  12531. continue;
  12532. }
  12533. var layerNumber = packet.layerNumber;
  12534. var queue = [], codeblock;
  12535. for (var i = 0, ii = packet.codeblocks.length; i < ii; i++) {
  12536. codeblock = packet.codeblocks[i];
  12537. var precinct = codeblock.precinct;
  12538. var codeblockColumn = codeblock.cbx - precinct.cbxMin;
  12539. var codeblockRow = codeblock.cby - precinct.cbyMin;
  12540. var codeblockIncluded = false;
  12541. var firstTimeInclusion = false;
  12542. var valueReady;
  12543. if (codeblock['included'] !== undefined) {
  12544. codeblockIncluded = !!readBits(1);
  12545. } else {
  12546. // reading inclusion tree
  12547. precinct = codeblock.precinct;
  12548. var inclusionTree, zeroBitPlanesTree;
  12549. if (precinct['inclusionTree'] !== undefined) {
  12550. inclusionTree = precinct.inclusionTree;
  12551. } else {
  12552. // building inclusion and zero bit-planes trees
  12553. var width = precinct.cbxMax - precinct.cbxMin + 1;
  12554. var height = precinct.cbyMax - precinct.cbyMin + 1;
  12555. inclusionTree = new InclusionTree(width, height, layerNumber);
  12556. zeroBitPlanesTree = new TagTree(width, height);
  12557. precinct.inclusionTree = inclusionTree;
  12558. precinct.zeroBitPlanesTree = zeroBitPlanesTree;
  12559. }
  12560. if (inclusionTree.reset(codeblockColumn, codeblockRow, layerNumber)) {
  12561. while (true) {
  12562. if (readBits(1)) {
  12563. valueReady = !inclusionTree.nextLevel();
  12564. if (valueReady) {
  12565. codeblock.included = true;
  12566. codeblockIncluded = firstTimeInclusion = true;
  12567. break;
  12568. }
  12569. } else {
  12570. inclusionTree.incrementValue(layerNumber);
  12571. break;
  12572. }
  12573. }
  12574. }
  12575. }
  12576. if (!codeblockIncluded) {
  12577. continue;
  12578. }
  12579. if (firstTimeInclusion) {
  12580. zeroBitPlanesTree = precinct.zeroBitPlanesTree;
  12581. zeroBitPlanesTree.reset(codeblockColumn, codeblockRow);
  12582. while (true) {
  12583. if (readBits(1)) {
  12584. valueReady = !zeroBitPlanesTree.nextLevel();
  12585. if (valueReady) {
  12586. break;
  12587. }
  12588. } else {
  12589. zeroBitPlanesTree.incrementValue();
  12590. }
  12591. }
  12592. codeblock.zeroBitPlanes = zeroBitPlanesTree.value;
  12593. }
  12594. var codingpasses = readCodingpasses();
  12595. while (readBits(1)) {
  12596. codeblock.Lblock++;
  12597. }
  12598. var codingpassesLog2 = log2(codingpasses);
  12599. // rounding down log2
  12600. var bits = ((codingpasses < (1 << codingpassesLog2)) ?
  12601. codingpassesLog2 - 1 : codingpassesLog2) + codeblock.Lblock;
  12602. var codedDataLength = readBits(bits);
  12603. queue.push({
  12604. codeblock: codeblock,
  12605. codingpasses: codingpasses,
  12606. dataLength: codedDataLength
  12607. });
  12608. }
  12609. alignToByte();
  12610. if (ephMarkerUsed) {
  12611. skipMarkerIfEqual(0x92);
  12612. }
  12613. while (queue.length > 0) {
  12614. var packetItem = queue.shift();
  12615. codeblock = packetItem.codeblock;
  12616. if (codeblock['data'] === undefined) {
  12617. codeblock.data = [];
  12618. }
  12619. codeblock.data.push({
  12620. data: data,
  12621. start: offset + position,
  12622. end: offset + position + packetItem.dataLength,
  12623. codingpasses: packetItem.codingpasses
  12624. });
  12625. position += packetItem.dataLength;
  12626. }
  12627. }
  12628. return position;
  12629. }
  12630. function copyCoefficients(coefficients, levelWidth, levelHeight, subband,
  12631. delta, mb, reversible, segmentationSymbolUsed) {
  12632. var x0 = subband.tbx0;
  12633. var y0 = subband.tby0;
  12634. var width = subband.tbx1 - subband.tbx0;
  12635. var codeblocks = subband.codeblocks;
  12636. var right = subband.type.charAt(0) === 'H' ? 1 : 0;
  12637. var bottom = subband.type.charAt(1) === 'H' ? levelWidth : 0;
  12638. for (var i = 0, ii = codeblocks.length; i < ii; ++i) {
  12639. var codeblock = codeblocks[i];
  12640. var blockWidth = codeblock.tbx1_ - codeblock.tbx0_;
  12641. var blockHeight = codeblock.tby1_ - codeblock.tby0_;
  12642. if (blockWidth === 0 || blockHeight === 0) {
  12643. continue;
  12644. }
  12645. if (codeblock['data'] === undefined) {
  12646. continue;
  12647. }
  12648. var bitModel, currentCodingpassType;
  12649. bitModel = new BitModel(blockWidth, blockHeight, codeblock.subbandType,
  12650. codeblock.zeroBitPlanes, mb);
  12651. currentCodingpassType = 2; // first bit plane starts from cleanup
  12652. // collect data
  12653. var data = codeblock.data, totalLength = 0, codingpasses = 0;
  12654. var j, jj, dataItem;
  12655. for (j = 0, jj = data.length; j < jj; j++) {
  12656. dataItem = data[j];
  12657. totalLength += dataItem.end - dataItem.start;
  12658. codingpasses += dataItem.codingpasses;
  12659. }
  12660. var encodedData = new Uint8Array(totalLength);
  12661. var position = 0;
  12662. for (j = 0, jj = data.length; j < jj; j++) {
  12663. dataItem = data[j];
  12664. var chunk = dataItem.data.subarray(dataItem.start, dataItem.end);
  12665. encodedData.set(chunk, position);
  12666. position += chunk.length;
  12667. }
  12668. // decoding the item
  12669. var decoder = new ArithmeticDecoder(encodedData, 0, totalLength);
  12670. bitModel.setDecoder(decoder);
  12671. for (j = 0; j < codingpasses; j++) {
  12672. switch (currentCodingpassType) {
  12673. case 0:
  12674. bitModel.runSignificancePropogationPass();
  12675. break;
  12676. case 1:
  12677. bitModel.runMagnitudeRefinementPass();
  12678. break;
  12679. case 2:
  12680. bitModel.runCleanupPass();
  12681. if (segmentationSymbolUsed) {
  12682. bitModel.checkSegmentationSymbol();
  12683. }
  12684. break;
  12685. }
  12686. currentCodingpassType = (currentCodingpassType + 1) % 3;
  12687. }
  12688. var offset = (codeblock.tbx0_ - x0) + (codeblock.tby0_ - y0) * width;
  12689. var sign = bitModel.coefficentsSign;
  12690. var magnitude = bitModel.coefficentsMagnitude;
  12691. var bitsDecoded = bitModel.bitsDecoded;
  12692. var magnitudeCorrection = reversible ? 0 : 0.5;
  12693. var k, n, nb;
  12694. position = 0;
  12695. // Do the interleaving of Section F.3.3 here, so we do not need
  12696. // to copy later. LL level is not interleaved, just copied.
  12697. var interleave = (subband.type !== 'LL');
  12698. for (j = 0; j < blockHeight; j++) {
  12699. var row = (offset / width) | 0; // row in the non-interleaved subband
  12700. var levelOffset = 2 * row * (levelWidth - width) + right + bottom;
  12701. for (k = 0; k < blockWidth; k++) {
  12702. n = magnitude[position];
  12703. if (n !== 0) {
  12704. n = (n + magnitudeCorrection) * delta;
  12705. if (sign[position] !== 0) {
  12706. n = -n;
  12707. }
  12708. nb = bitsDecoded[position];
  12709. var pos = interleave ? (levelOffset + (offset << 1)) : offset;
  12710. if (reversible && (nb >= mb)) {
  12711. coefficients[pos] = n;
  12712. } else {
  12713. coefficients[pos] = n * (1 << (mb - nb));
  12714. }
  12715. }
  12716. offset++;
  12717. position++;
  12718. }
  12719. offset += width - blockWidth;
  12720. }
  12721. }
  12722. }
  12723. function transformTile(context, tile, c) {
  12724. var component = tile.components[c];
  12725. var codingStyleParameters = component.codingStyleParameters;
  12726. var quantizationParameters = component.quantizationParameters;
  12727. var decompositionLevelsCount =
  12728. codingStyleParameters.decompositionLevelsCount;
  12729. var spqcds = quantizationParameters.SPqcds;
  12730. var scalarExpounded = quantizationParameters.scalarExpounded;
  12731. var guardBits = quantizationParameters.guardBits;
  12732. var segmentationSymbolUsed = codingStyleParameters.segmentationSymbolUsed;
  12733. var precision = context.components[c].precision;
  12734. var reversible = codingStyleParameters.reversibleTransformation;
  12735. var transform = (reversible ? new ReversibleTransform() :
  12736. new IrreversibleTransform());
  12737. var subbandCoefficients = [];
  12738. var b = 0;
  12739. for (var i = 0; i <= decompositionLevelsCount; i++) {
  12740. var resolution = component.resolutions[i];
  12741. var width = resolution.trx1 - resolution.trx0;
  12742. var height = resolution.try1 - resolution.try0;
  12743. // Allocate space for the whole sublevel.
  12744. var coefficients = new Float32Array(width * height);
  12745. for (var j = 0, jj = resolution.subbands.length; j < jj; j++) {
  12746. var mu, epsilon;
  12747. if (!scalarExpounded) {
  12748. // formula E-5
  12749. mu = spqcds[0].mu;
  12750. epsilon = spqcds[0].epsilon + (i > 0 ? 1 - i : 0);
  12751. } else {
  12752. mu = spqcds[b].mu;
  12753. epsilon = spqcds[b].epsilon;
  12754. b++;
  12755. }
  12756. var subband = resolution.subbands[j];
  12757. var gainLog2 = SubbandsGainLog2[subband.type];
  12758. // calulate quantization coefficient (Section E.1.1.1)
  12759. var delta = (reversible ? 1 :
  12760. Math.pow(2, precision + gainLog2 - epsilon) * (1 + mu / 2048));
  12761. var mb = (guardBits + epsilon - 1);
  12762. // In the first resolution level, copyCoefficients will fill the
  12763. // whole array with coefficients. In the succeding passes,
  12764. // copyCoefficients will consecutively fill in the values that belong
  12765. // to the interleaved positions of the HL, LH, and HH coefficients.
  12766. // The LL coefficients will then be interleaved in Transform.iterate().
  12767. copyCoefficients(coefficients, width, height, subband, delta, mb,
  12768. reversible, segmentationSymbolUsed);
  12769. }
  12770. subbandCoefficients.push({
  12771. width: width,
  12772. height: height,
  12773. items: coefficients
  12774. });
  12775. }
  12776. var result = transform.calculate(subbandCoefficients,
  12777. component.tcx0, component.tcy0);
  12778. return {
  12779. left: component.tcx0,
  12780. top: component.tcy0,
  12781. width: result.width,
  12782. height: result.height,
  12783. items: result.items
  12784. };
  12785. }
  12786. function transformComponents(context) {
  12787. var siz = context.SIZ;
  12788. var components = context.components;
  12789. var componentsCount = siz.Csiz;
  12790. var resultImages = [];
  12791. for (var i = 0, ii = context.tiles.length; i < ii; i++) {
  12792. var tile = context.tiles[i];
  12793. var transformedTiles = [];
  12794. var c;
  12795. for (c = 0; c < componentsCount; c++) {
  12796. transformedTiles[c] = transformTile(context, tile, c);
  12797. }
  12798. var tile0 = transformedTiles[0];
  12799. var out = new Uint8Array(tile0.items.length * componentsCount);
  12800. var result = {
  12801. left: tile0.left,
  12802. top: tile0.top,
  12803. width: tile0.width,
  12804. height: tile0.height,
  12805. items: out
  12806. };
  12807. // Section G.2.2 Inverse multi component transform
  12808. var shift, offset, max, min, maxK;
  12809. var pos = 0, j, jj, y0, y1, y2, r, g, b, k, val;
  12810. if (tile.codingStyleDefaultParameters.multipleComponentTransform) {
  12811. var fourComponents = componentsCount === 4;
  12812. var y0items = transformedTiles[0].items;
  12813. var y1items = transformedTiles[1].items;
  12814. var y2items = transformedTiles[2].items;
  12815. var y3items = fourComponents ? transformedTiles[3].items : null;
  12816. // HACK: The multiple component transform formulas below assume that
  12817. // all components have the same precision. With this in mind, we
  12818. // compute shift and offset only once.
  12819. shift = components[0].precision - 8;
  12820. offset = (128 << shift) + 0.5;
  12821. max = 255 * (1 << shift);
  12822. maxK = max * 0.5;
  12823. min = -maxK;
  12824. var component0 = tile.components[0];
  12825. var alpha01 = componentsCount - 3;
  12826. jj = y0items.length;
  12827. if (!component0.codingStyleParameters.reversibleTransformation) {
  12828. // inverse irreversible multiple component transform
  12829. for (j = 0; j < jj; j++, pos += alpha01) {
  12830. y0 = y0items[j] + offset;
  12831. y1 = y1items[j];
  12832. y2 = y2items[j];
  12833. r = y0 + 1.402 * y2;
  12834. g = y0 - 0.34413 * y1 - 0.71414 * y2;
  12835. b = y0 + 1.772 * y1;
  12836. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12837. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12838. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12839. }
  12840. } else {
  12841. // inverse reversible multiple component transform
  12842. for (j = 0; j < jj; j++, pos += alpha01) {
  12843. y0 = y0items[j] + offset;
  12844. y1 = y1items[j];
  12845. y2 = y2items[j];
  12846. g = y0 - ((y2 + y1) >> 2);
  12847. r = g + y2;
  12848. b = g + y1;
  12849. out[pos++] = r <= 0 ? 0 : r >= max ? 255 : r >> shift;
  12850. out[pos++] = g <= 0 ? 0 : g >= max ? 255 : g >> shift;
  12851. out[pos++] = b <= 0 ? 0 : b >= max ? 255 : b >> shift;
  12852. }
  12853. }
  12854. if (fourComponents) {
  12855. for (j = 0, pos = 3; j < jj; j++, pos += 4) {
  12856. k = y3items[j];
  12857. out[pos] = k <= min ? 0 : k >= maxK ? 255 : (k + offset) >> shift;
  12858. }
  12859. }
  12860. } else { // no multi-component transform
  12861. for (c = 0; c < componentsCount; c++) {
  12862. var items = transformedTiles[c].items;
  12863. shift = components[c].precision - 8;
  12864. offset = (128 << shift) + 0.5;
  12865. max = (127.5 * (1 << shift));
  12866. min = -max;
  12867. for (pos = c, j = 0, jj = items.length; j < jj; j++) {
  12868. val = items[j];
  12869. out[pos] = val <= min ? 0 :
  12870. val >= max ? 255 : (val + offset) >> shift;
  12871. pos += componentsCount;
  12872. }
  12873. }
  12874. }
  12875. resultImages.push(result);
  12876. }
  12877. return resultImages;
  12878. }
  12879. function initializeTile(context, tileIndex) {
  12880. var siz = context.SIZ;
  12881. var componentsCount = siz.Csiz;
  12882. var tile = context.tiles[tileIndex];
  12883. for (var c = 0; c < componentsCount; c++) {
  12884. var component = tile.components[c];
  12885. var qcdOrQcc = (context.currentTile.QCC[c] !== undefined ?
  12886. context.currentTile.QCC[c] : context.currentTile.QCD);
  12887. component.quantizationParameters = qcdOrQcc;
  12888. var codOrCoc = (context.currentTile.COC[c] !== undefined ?
  12889. context.currentTile.COC[c] : context.currentTile.COD);
  12890. component.codingStyleParameters = codOrCoc;
  12891. }
  12892. tile.codingStyleDefaultParameters = context.currentTile.COD;
  12893. }
  12894. // Section B.10.2 Tag trees
  12895. var TagTree = (function TagTreeClosure() {
  12896. function TagTree(width, height) {
  12897. var levelsLength = log2(Math.max(width, height)) + 1;
  12898. this.levels = [];
  12899. for (var i = 0; i < levelsLength; i++) {
  12900. var level = {
  12901. width: width,
  12902. height: height,
  12903. items: []
  12904. };
  12905. this.levels.push(level);
  12906. width = Math.ceil(width / 2);
  12907. height = Math.ceil(height / 2);
  12908. }
  12909. }
  12910. TagTree.prototype = {
  12911. reset: function TagTree_reset(i, j) {
  12912. var currentLevel = 0, value = 0, level;
  12913. while (currentLevel < this.levels.length) {
  12914. level = this.levels[currentLevel];
  12915. var index = i + j * level.width;
  12916. if (level.items[index] !== undefined) {
  12917. value = level.items[index];
  12918. break;
  12919. }
  12920. level.index = index;
  12921. i >>= 1;
  12922. j >>= 1;
  12923. currentLevel++;
  12924. }
  12925. currentLevel--;
  12926. level = this.levels[currentLevel];
  12927. level.items[level.index] = value;
  12928. this.currentLevel = currentLevel;
  12929. delete this.value;
  12930. },
  12931. incrementValue: function TagTree_incrementValue() {
  12932. var level = this.levels[this.currentLevel];
  12933. level.items[level.index]++;
  12934. },
  12935. nextLevel: function TagTree_nextLevel() {
  12936. var currentLevel = this.currentLevel;
  12937. var level = this.levels[currentLevel];
  12938. var value = level.items[level.index];
  12939. currentLevel--;
  12940. if (currentLevel < 0) {
  12941. this.value = value;
  12942. return false;
  12943. }
  12944. this.currentLevel = currentLevel;
  12945. level = this.levels[currentLevel];
  12946. level.items[level.index] = value;
  12947. return true;
  12948. }
  12949. };
  12950. return TagTree;
  12951. })();
  12952. var InclusionTree = (function InclusionTreeClosure() {
  12953. function InclusionTree(width, height, defaultValue) {
  12954. var levelsLength = log2(Math.max(width, height)) + 1;
  12955. this.levels = [];
  12956. for (var i = 0; i < levelsLength; i++) {
  12957. var items = new Uint8Array(width * height);
  12958. for (var j = 0, jj = items.length; j < jj; j++) {
  12959. items[j] = defaultValue;
  12960. }
  12961. var level = {
  12962. width: width,
  12963. height: height,
  12964. items: items
  12965. };
  12966. this.levels.push(level);
  12967. width = Math.ceil(width / 2);
  12968. height = Math.ceil(height / 2);
  12969. }
  12970. }
  12971. InclusionTree.prototype = {
  12972. reset: function InclusionTree_reset(i, j, stopValue) {
  12973. var currentLevel = 0;
  12974. while (currentLevel < this.levels.length) {
  12975. var level = this.levels[currentLevel];
  12976. var index = i + j * level.width;
  12977. level.index = index;
  12978. var value = level.items[index];
  12979. if (value === 0xFF) {
  12980. break;
  12981. }
  12982. if (value > stopValue) {
  12983. this.currentLevel = currentLevel;
  12984. // already know about this one, propagating the value to top levels
  12985. this.propagateValues();
  12986. return false;
  12987. }
  12988. i >>= 1;
  12989. j >>= 1;
  12990. currentLevel++;
  12991. }
  12992. this.currentLevel = currentLevel - 1;
  12993. return true;
  12994. },
  12995. incrementValue: function InclusionTree_incrementValue(stopValue) {
  12996. var level = this.levels[this.currentLevel];
  12997. level.items[level.index] = stopValue + 1;
  12998. this.propagateValues();
  12999. },
  13000. propagateValues: function InclusionTree_propagateValues() {
  13001. var levelIndex = this.currentLevel;
  13002. var level = this.levels[levelIndex];
  13003. var currentValue = level.items[level.index];
  13004. while (--levelIndex >= 0) {
  13005. level = this.levels[levelIndex];
  13006. level.items[level.index] = currentValue;
  13007. }
  13008. },
  13009. nextLevel: function InclusionTree_nextLevel() {
  13010. var currentLevel = this.currentLevel;
  13011. var level = this.levels[currentLevel];
  13012. var value = level.items[level.index];
  13013. level.items[level.index] = 0xFF;
  13014. currentLevel--;
  13015. if (currentLevel < 0) {
  13016. return false;
  13017. }
  13018. this.currentLevel = currentLevel;
  13019. level = this.levels[currentLevel];
  13020. level.items[level.index] = value;
  13021. return true;
  13022. }
  13023. };
  13024. return InclusionTree;
  13025. })();
  13026. // Section D. Coefficient bit modeling
  13027. var BitModel = (function BitModelClosure() {
  13028. var UNIFORM_CONTEXT = 17;
  13029. var RUNLENGTH_CONTEXT = 18;
  13030. // Table D-1
  13031. // The index is binary presentation: 0dddvvhh, ddd - sum of Di (0..4),
  13032. // vv - sum of Vi (0..2), and hh - sum of Hi (0..2)
  13033. var LLAndLHContextsLabel = new Uint8Array([
  13034. 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,
  13035. 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,
  13036. 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
  13037. ]);
  13038. var HLContextLabel = new Uint8Array([
  13039. 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,
  13040. 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,
  13041. 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
  13042. ]);
  13043. var HHContextLabel = new Uint8Array([
  13044. 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,
  13045. 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,
  13046. 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
  13047. ]);
  13048. function BitModel(width, height, subband, zeroBitPlanes, mb) {
  13049. this.width = width;
  13050. this.height = height;
  13051. this.contextLabelTable = (subband === 'HH' ? HHContextLabel :
  13052. (subband === 'HL' ? HLContextLabel : LLAndLHContextsLabel));
  13053. var coefficientCount = width * height;
  13054. // coefficients outside the encoding region treated as insignificant
  13055. // add border state cells for significanceState
  13056. this.neighborsSignificance = new Uint8Array(coefficientCount);
  13057. this.coefficentsSign = new Uint8Array(coefficientCount);
  13058. this.coefficentsMagnitude = mb > 14 ? new Uint32Array(coefficientCount) :
  13059. mb > 6 ? new Uint16Array(coefficientCount) :
  13060. new Uint8Array(coefficientCount);
  13061. this.processingFlags = new Uint8Array(coefficientCount);
  13062. var bitsDecoded = new Uint8Array(coefficientCount);
  13063. if (zeroBitPlanes !== 0) {
  13064. for (var i = 0; i < coefficientCount; i++) {
  13065. bitsDecoded[i] = zeroBitPlanes;
  13066. }
  13067. }
  13068. this.bitsDecoded = bitsDecoded;
  13069. this.reset();
  13070. }
  13071. BitModel.prototype = {
  13072. setDecoder: function BitModel_setDecoder(decoder) {
  13073. this.decoder = decoder;
  13074. },
  13075. reset: function BitModel_reset() {
  13076. // We have 17 contexts that are accessed via context labels,
  13077. // plus the uniform and runlength context.
  13078. this.contexts = new Int8Array(19);
  13079. // Contexts are packed into 1 byte:
  13080. // highest 7 bits carry the index, lowest bit carries mps
  13081. this.contexts[0] = (4 << 1) | 0;
  13082. this.contexts[UNIFORM_CONTEXT] = (46 << 1) | 0;
  13083. this.contexts[RUNLENGTH_CONTEXT] = (3 << 1) | 0;
  13084. },
  13085. setNeighborsSignificance:
  13086. function BitModel_setNeighborsSignificance(row, column, index) {
  13087. var neighborsSignificance = this.neighborsSignificance;
  13088. var width = this.width, height = this.height;
  13089. var left = (column > 0);
  13090. var right = (column + 1 < width);
  13091. var i;
  13092. if (row > 0) {
  13093. i = index - width;
  13094. if (left) {
  13095. neighborsSignificance[i - 1] += 0x10;
  13096. }
  13097. if (right) {
  13098. neighborsSignificance[i + 1] += 0x10;
  13099. }
  13100. neighborsSignificance[i] += 0x04;
  13101. }
  13102. if (row + 1 < height) {
  13103. i = index + width;
  13104. if (left) {
  13105. neighborsSignificance[i - 1] += 0x10;
  13106. }
  13107. if (right) {
  13108. neighborsSignificance[i + 1] += 0x10;
  13109. }
  13110. neighborsSignificance[i] += 0x04;
  13111. }
  13112. if (left) {
  13113. neighborsSignificance[index - 1] += 0x01;
  13114. }
  13115. if (right) {
  13116. neighborsSignificance[index + 1] += 0x01;
  13117. }
  13118. neighborsSignificance[index] |= 0x80;
  13119. },
  13120. runSignificancePropogationPass:
  13121. function BitModel_runSignificancePropogationPass() {
  13122. var decoder = this.decoder;
  13123. var width = this.width, height = this.height;
  13124. var coefficentsMagnitude = this.coefficentsMagnitude;
  13125. var coefficentsSign = this.coefficentsSign;
  13126. var neighborsSignificance = this.neighborsSignificance;
  13127. var processingFlags = this.processingFlags;
  13128. var contexts = this.contexts;
  13129. var labels = this.contextLabelTable;
  13130. var bitsDecoded = this.bitsDecoded;
  13131. var processedInverseMask = ~1;
  13132. var processedMask = 1;
  13133. var firstMagnitudeBitMask = 2;
  13134. for (var i0 = 0; i0 < height; i0 += 4) {
  13135. for (var j = 0; j < width; j++) {
  13136. var index = i0 * width + j;
  13137. for (var i1 = 0; i1 < 4; i1++, index += width) {
  13138. var i = i0 + i1;
  13139. if (i >= height) {
  13140. break;
  13141. }
  13142. // clear processed flag first
  13143. processingFlags[index] &= processedInverseMask;
  13144. if (coefficentsMagnitude[index] ||
  13145. !neighborsSignificance[index]) {
  13146. continue;
  13147. }
  13148. var contextLabel = labels[neighborsSignificance[index]];
  13149. var decision = decoder.readBit(contexts, contextLabel);
  13150. if (decision) {
  13151. var sign = this.decodeSignBit(i, j, index);
  13152. coefficentsSign[index] = sign;
  13153. coefficentsMagnitude[index] = 1;
  13154. this.setNeighborsSignificance(i, j, index);
  13155. processingFlags[index] |= firstMagnitudeBitMask;
  13156. }
  13157. bitsDecoded[index]++;
  13158. processingFlags[index] |= processedMask;
  13159. }
  13160. }
  13161. }
  13162. },
  13163. decodeSignBit: function BitModel_decodeSignBit(row, column, index) {
  13164. var width = this.width, height = this.height;
  13165. var coefficentsMagnitude = this.coefficentsMagnitude;
  13166. var coefficentsSign = this.coefficentsSign;
  13167. var contribution, sign0, sign1, significance1;
  13168. var contextLabel, decoded;
  13169. // calculate horizontal contribution
  13170. significance1 = (column > 0 && coefficentsMagnitude[index - 1] !== 0);
  13171. if (column + 1 < width && coefficentsMagnitude[index + 1] !== 0) {
  13172. sign1 = coefficentsSign[index + 1];
  13173. if (significance1) {
  13174. sign0 = coefficentsSign[index - 1];
  13175. contribution = 1 - sign1 - sign0;
  13176. } else {
  13177. contribution = 1 - sign1 - sign1;
  13178. }
  13179. } else if (significance1) {
  13180. sign0 = coefficentsSign[index - 1];
  13181. contribution = 1 - sign0 - sign0;
  13182. } else {
  13183. contribution = 0;
  13184. }
  13185. var horizontalContribution = 3 * contribution;
  13186. // calculate vertical contribution and combine with the horizontal
  13187. significance1 = (row > 0 && coefficentsMagnitude[index - width] !== 0);
  13188. if (row + 1 < height && coefficentsMagnitude[index + width] !== 0) {
  13189. sign1 = coefficentsSign[index + width];
  13190. if (significance1) {
  13191. sign0 = coefficentsSign[index - width];
  13192. contribution = 1 - sign1 - sign0 + horizontalContribution;
  13193. } else {
  13194. contribution = 1 - sign1 - sign1 + horizontalContribution;
  13195. }
  13196. } else if (significance1) {
  13197. sign0 = coefficentsSign[index - width];
  13198. contribution = 1 - sign0 - sign0 + horizontalContribution;
  13199. } else {
  13200. contribution = horizontalContribution;
  13201. }
  13202. if (contribution >= 0) {
  13203. contextLabel = 9 + contribution;
  13204. decoded = this.decoder.readBit(this.contexts, contextLabel);
  13205. } else {
  13206. contextLabel = 9 - contribution;
  13207. decoded = this.decoder.readBit(this.contexts, contextLabel) ^ 1;
  13208. }
  13209. return decoded;
  13210. },
  13211. runMagnitudeRefinementPass:
  13212. function BitModel_runMagnitudeRefinementPass() {
  13213. var decoder = this.decoder;
  13214. var width = this.width, height = this.height;
  13215. var coefficentsMagnitude = this.coefficentsMagnitude;
  13216. var neighborsSignificance = this.neighborsSignificance;
  13217. var contexts = this.contexts;
  13218. var bitsDecoded = this.bitsDecoded;
  13219. var processingFlags = this.processingFlags;
  13220. var processedMask = 1;
  13221. var firstMagnitudeBitMask = 2;
  13222. var length = width * height;
  13223. var width4 = width * 4;
  13224. for (var index0 = 0, indexNext; index0 < length; index0 = indexNext) {
  13225. indexNext = Math.min(length, index0 + width4);
  13226. for (var j = 0; j < width; j++) {
  13227. for (var index = index0 + j; index < indexNext; index += width) {
  13228. // significant but not those that have just become
  13229. if (!coefficentsMagnitude[index] ||
  13230. (processingFlags[index] & processedMask) !== 0) {
  13231. continue;
  13232. }
  13233. var contextLabel = 16;
  13234. if ((processingFlags[index] & firstMagnitudeBitMask) !== 0) {
  13235. processingFlags[index] ^= firstMagnitudeBitMask;
  13236. // first refinement
  13237. var significance = neighborsSignificance[index] & 127;
  13238. contextLabel = significance === 0 ? 15 : 14;
  13239. }
  13240. var bit = decoder.readBit(contexts, contextLabel);
  13241. coefficentsMagnitude[index] =
  13242. (coefficentsMagnitude[index] << 1) | bit;
  13243. bitsDecoded[index]++;
  13244. processingFlags[index] |= processedMask;
  13245. }
  13246. }
  13247. }
  13248. },
  13249. runCleanupPass: function BitModel_runCleanupPass() {
  13250. var decoder = this.decoder;
  13251. var width = this.width, height = this.height;
  13252. var neighborsSignificance = this.neighborsSignificance;
  13253. var coefficentsMagnitude = this.coefficentsMagnitude;
  13254. var coefficentsSign = this.coefficentsSign;
  13255. var contexts = this.contexts;
  13256. var labels = this.contextLabelTable;
  13257. var bitsDecoded = this.bitsDecoded;
  13258. var processingFlags = this.processingFlags;
  13259. var processedMask = 1;
  13260. var firstMagnitudeBitMask = 2;
  13261. var oneRowDown = width;
  13262. var twoRowsDown = width * 2;
  13263. var threeRowsDown = width * 3;
  13264. var iNext;
  13265. for (var i0 = 0; i0 < height; i0 = iNext) {
  13266. iNext = Math.min(i0 + 4, height);
  13267. var indexBase = i0 * width;
  13268. var checkAllEmpty = i0 + 3 < height;
  13269. for (var j = 0; j < width; j++) {
  13270. var index0 = indexBase + j;
  13271. // using the property: labels[neighborsSignificance[index]] === 0
  13272. // when neighborsSignificance[index] === 0
  13273. var allEmpty = (checkAllEmpty &&
  13274. processingFlags[index0] === 0 &&
  13275. processingFlags[index0 + oneRowDown] === 0 &&
  13276. processingFlags[index0 + twoRowsDown] === 0 &&
  13277. processingFlags[index0 + threeRowsDown] === 0 &&
  13278. neighborsSignificance[index0] === 0 &&
  13279. neighborsSignificance[index0 + oneRowDown] === 0 &&
  13280. neighborsSignificance[index0 + twoRowsDown] === 0 &&
  13281. neighborsSignificance[index0 + threeRowsDown] === 0);
  13282. var i1 = 0, index = index0;
  13283. var i = i0, sign;
  13284. if (allEmpty) {
  13285. var hasSignificantCoefficent =
  13286. decoder.readBit(contexts, RUNLENGTH_CONTEXT);
  13287. if (!hasSignificantCoefficent) {
  13288. bitsDecoded[index0]++;
  13289. bitsDecoded[index0 + oneRowDown]++;
  13290. bitsDecoded[index0 + twoRowsDown]++;
  13291. bitsDecoded[index0 + threeRowsDown]++;
  13292. continue; // next column
  13293. }
  13294. i1 = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13295. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13296. if (i1 !== 0) {
  13297. i = i0 + i1;
  13298. index += i1 * width;
  13299. }
  13300. sign = this.decodeSignBit(i, j, index);
  13301. coefficentsSign[index] = sign;
  13302. coefficentsMagnitude[index] = 1;
  13303. this.setNeighborsSignificance(i, j, index);
  13304. processingFlags[index] |= firstMagnitudeBitMask;
  13305. index = index0;
  13306. for (var i2 = i0; i2 <= i; i2++, index += width) {
  13307. bitsDecoded[index]++;
  13308. }
  13309. i1++;
  13310. }
  13311. for (i = i0 + i1; i < iNext; i++, index += width) {
  13312. if (coefficentsMagnitude[index] ||
  13313. (processingFlags[index] & processedMask) !== 0) {
  13314. continue;
  13315. }
  13316. var contextLabel = labels[neighborsSignificance[index]];
  13317. var decision = decoder.readBit(contexts, contextLabel);
  13318. if (decision === 1) {
  13319. sign = this.decodeSignBit(i, j, index);
  13320. coefficentsSign[index] = sign;
  13321. coefficentsMagnitude[index] = 1;
  13322. this.setNeighborsSignificance(i, j, index);
  13323. processingFlags[index] |= firstMagnitudeBitMask;
  13324. }
  13325. bitsDecoded[index]++;
  13326. }
  13327. }
  13328. }
  13329. },
  13330. checkSegmentationSymbol: function BitModel_checkSegmentationSymbol() {
  13331. var decoder = this.decoder;
  13332. var contexts = this.contexts;
  13333. var symbol = (decoder.readBit(contexts, UNIFORM_CONTEXT) << 3) |
  13334. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 2) |
  13335. (decoder.readBit(contexts, UNIFORM_CONTEXT) << 1) |
  13336. decoder.readBit(contexts, UNIFORM_CONTEXT);
  13337. if (symbol !== 0xA) {
  13338. throw new Error('JPX Error: Invalid segmentation symbol');
  13339. }
  13340. }
  13341. };
  13342. return BitModel;
  13343. })();
  13344. // Section F, Discrete wavelet transformation
  13345. var Transform = (function TransformClosure() {
  13346. function Transform() {}
  13347. Transform.prototype.calculate =
  13348. function transformCalculate(subbands, u0, v0) {
  13349. var ll = subbands[0];
  13350. for (var i = 1, ii = subbands.length; i < ii; i++) {
  13351. ll = this.iterate(ll, subbands[i], u0, v0);
  13352. }
  13353. return ll;
  13354. };
  13355. Transform.prototype.extend = function extend(buffer, offset, size) {
  13356. // Section F.3.7 extending... using max extension of 4
  13357. var i1 = offset - 1, j1 = offset + 1;
  13358. var i2 = offset + size - 2, j2 = offset + size;
  13359. buffer[i1--] = buffer[j1++];
  13360. buffer[j2++] = buffer[i2--];
  13361. buffer[i1--] = buffer[j1++];
  13362. buffer[j2++] = buffer[i2--];
  13363. buffer[i1--] = buffer[j1++];
  13364. buffer[j2++] = buffer[i2--];
  13365. buffer[i1] = buffer[j1];
  13366. buffer[j2] = buffer[i2];
  13367. };
  13368. Transform.prototype.iterate = function Transform_iterate(ll, hl_lh_hh,
  13369. u0, v0) {
  13370. var llWidth = ll.width, llHeight = ll.height, llItems = ll.items;
  13371. var width = hl_lh_hh.width;
  13372. var height = hl_lh_hh.height;
  13373. var items = hl_lh_hh.items;
  13374. var i, j, k, l, u, v;
  13375. // Interleave LL according to Section F.3.3
  13376. for (k = 0, i = 0; i < llHeight; i++) {
  13377. l = i * 2 * width;
  13378. for (j = 0; j < llWidth; j++, k++, l += 2) {
  13379. items[l] = llItems[k];
  13380. }
  13381. }
  13382. // The LL band is not needed anymore.
  13383. llItems = ll.items = null;
  13384. var bufferPadding = 4;
  13385. var rowBuffer = new Float32Array(width + 2 * bufferPadding);
  13386. // Section F.3.4 HOR_SR
  13387. if (width === 1) {
  13388. // if width = 1, when u0 even keep items as is, when odd divide by 2
  13389. if ((u0 & 1) !== 0) {
  13390. for (v = 0, k = 0; v < height; v++, k += width) {
  13391. items[k] *= 0.5;
  13392. }
  13393. }
  13394. } else {
  13395. for (v = 0, k = 0; v < height; v++, k += width) {
  13396. rowBuffer.set(items.subarray(k, k + width), bufferPadding);
  13397. this.extend(rowBuffer, bufferPadding, width);
  13398. this.filter(rowBuffer, bufferPadding, width);
  13399. items.set(
  13400. rowBuffer.subarray(bufferPadding, bufferPadding + width),
  13401. k);
  13402. }
  13403. }
  13404. // Accesses to the items array can take long, because it may not fit into
  13405. // CPU cache and has to be fetched from main memory. Since subsequent
  13406. // accesses to the items array are not local when reading columns, we
  13407. // have a cache miss every time. To reduce cache misses, get up to
  13408. // 'numBuffers' items at a time and store them into the individual
  13409. // buffers. The colBuffers should be small enough to fit into CPU cache.
  13410. var numBuffers = 16;
  13411. var colBuffers = [];
  13412. for (i = 0; i < numBuffers; i++) {
  13413. colBuffers.push(new Float32Array(height + 2 * bufferPadding));
  13414. }
  13415. var b, currentBuffer = 0;
  13416. ll = bufferPadding + height;
  13417. // Section F.3.5 VER_SR
  13418. if (height === 1) {
  13419. // if height = 1, when v0 even keep items as is, when odd divide by 2
  13420. if ((v0 & 1) !== 0) {
  13421. for (u = 0; u < width; u++) {
  13422. items[u] *= 0.5;
  13423. }
  13424. }
  13425. } else {
  13426. for (u = 0; u < width; u++) {
  13427. // if we ran out of buffers, copy several image columns at once
  13428. if (currentBuffer === 0) {
  13429. numBuffers = Math.min(width - u, numBuffers);
  13430. for (k = u, l = bufferPadding; l < ll; k += width, l++) {
  13431. for (b = 0; b < numBuffers; b++) {
  13432. colBuffers[b][l] = items[k + b];
  13433. }
  13434. }
  13435. currentBuffer = numBuffers;
  13436. }
  13437. currentBuffer--;
  13438. var buffer = colBuffers[currentBuffer];
  13439. this.extend(buffer, bufferPadding, height);
  13440. this.filter(buffer, bufferPadding, height);
  13441. // If this is last buffer in this group of buffers, flush all buffers.
  13442. if (currentBuffer === 0) {
  13443. k = u - numBuffers + 1;
  13444. for (l = bufferPadding; l < ll; k += width, l++) {
  13445. for (b = 0; b < numBuffers; b++) {
  13446. items[k + b] = colBuffers[b][l];
  13447. }
  13448. }
  13449. }
  13450. }
  13451. }
  13452. return {
  13453. width: width,
  13454. height: height,
  13455. items: items
  13456. };
  13457. };
  13458. return Transform;
  13459. })();
  13460. // Section 3.8.2 Irreversible 9-7 filter
  13461. var IrreversibleTransform = (function IrreversibleTransformClosure() {
  13462. function IrreversibleTransform() {
  13463. Transform.call(this);
  13464. }
  13465. IrreversibleTransform.prototype = Object.create(Transform.prototype);
  13466. IrreversibleTransform.prototype.filter =
  13467. function irreversibleTransformFilter(x, offset, length) {
  13468. var len = length >> 1;
  13469. offset = offset | 0;
  13470. var j, n, current, next;
  13471. var alpha = -1.586134342059924;
  13472. var beta = -0.052980118572961;
  13473. var gamma = 0.882911075530934;
  13474. var delta = 0.443506852043971;
  13475. var K = 1.230174104914001;
  13476. var K_ = 1 / K;
  13477. // step 1 is combined with step 3
  13478. // step 2
  13479. j = offset - 3;
  13480. for (n = len + 4; n--; j += 2) {
  13481. x[j] *= K_;
  13482. }
  13483. // step 1 & 3
  13484. j = offset - 2;
  13485. current = delta * x[j -1];
  13486. for (n = len + 3; n--; j += 2) {
  13487. next = delta * x[j + 1];
  13488. x[j] = K * x[j] - current - next;
  13489. if (n--) {
  13490. j += 2;
  13491. current = delta * x[j + 1];
  13492. x[j] = K * x[j] - current - next;
  13493. } else {
  13494. break;
  13495. }
  13496. }
  13497. // step 4
  13498. j = offset - 1;
  13499. current = gamma * x[j - 1];
  13500. for (n = len + 2; n--; j += 2) {
  13501. next = gamma * x[j + 1];
  13502. x[j] -= current + next;
  13503. if (n--) {
  13504. j += 2;
  13505. current = gamma * x[j + 1];
  13506. x[j] -= current + next;
  13507. } else {
  13508. break;
  13509. }
  13510. }
  13511. // step 5
  13512. j = offset;
  13513. current = beta * x[j - 1];
  13514. for (n = len + 1; n--; j += 2) {
  13515. next = beta * x[j + 1];
  13516. x[j] -= current + next;
  13517. if (n--) {
  13518. j += 2;
  13519. current = beta * x[j + 1];
  13520. x[j] -= current + next;
  13521. } else {
  13522. break;
  13523. }
  13524. }
  13525. // step 6
  13526. if (len !== 0) {
  13527. j = offset + 1;
  13528. current = alpha * x[j - 1];
  13529. for (n = len; n--; j += 2) {
  13530. next = alpha * x[j + 1];
  13531. x[j] -= current + next;
  13532. if (n--) {
  13533. j += 2;
  13534. current = alpha * x[j + 1];
  13535. x[j] -= current + next;
  13536. } else {
  13537. break;
  13538. }
  13539. }
  13540. }
  13541. };
  13542. return IrreversibleTransform;
  13543. })();
  13544. // Section 3.8.1 Reversible 5-3 filter
  13545. var ReversibleTransform = (function ReversibleTransformClosure() {
  13546. function ReversibleTransform() {
  13547. Transform.call(this);
  13548. }
  13549. ReversibleTransform.prototype = Object.create(Transform.prototype);
  13550. ReversibleTransform.prototype.filter =
  13551. function reversibleTransformFilter(x, offset, length) {
  13552. var len = length >> 1;
  13553. offset = offset | 0;
  13554. var j, n;
  13555. for (j = offset, n = len + 1; n--; j += 2) {
  13556. x[j] -= (x[j - 1] + x[j + 1] + 2) >> 2;
  13557. }
  13558. for (j = offset + 1, n = len; n--; j += 2) {
  13559. x[j] += (x[j - 1] + x[j + 1]) >> 1;
  13560. }
  13561. };
  13562. return ReversibleTransform;
  13563. })();
  13564. return JpxImage;
  13565. })();
  13566. exports.JpxImage = JpxImage;
  13567. }));
  13568. (function (root, factory) {
  13569. {
  13570. factory((root.pdfjsCoreMetrics = {}), root.pdfjsSharedUtil);
  13571. }
  13572. }(this, function (exports, sharedUtil) {
  13573. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  13574. // The Metrics object contains glyph widths (in glyph space units).
  13575. // As per PDF spec, for most fonts (Type 3 being an exception) a glyph
  13576. // space unit corresponds to 1/1000th of text space unit.
  13577. var getMetrics = getLookupTableFactory(function (t) {
  13578. t['Courier'] = 600;
  13579. t['Courier-Bold'] = 600;
  13580. t['Courier-BoldOblique'] = 600;
  13581. t['Courier-Oblique'] = 600;
  13582. t['Helvetica'] = getLookupTableFactory(function (t) {
  13583. t['space'] = 278;
  13584. t['exclam'] = 278;
  13585. t['quotedbl'] = 355;
  13586. t['numbersign'] = 556;
  13587. t['dollar'] = 556;
  13588. t['percent'] = 889;
  13589. t['ampersand'] = 667;
  13590. t['quoteright'] = 222;
  13591. t['parenleft'] = 333;
  13592. t['parenright'] = 333;
  13593. t['asterisk'] = 389;
  13594. t['plus'] = 584;
  13595. t['comma'] = 278;
  13596. t['hyphen'] = 333;
  13597. t['period'] = 278;
  13598. t['slash'] = 278;
  13599. t['zero'] = 556;
  13600. t['one'] = 556;
  13601. t['two'] = 556;
  13602. t['three'] = 556;
  13603. t['four'] = 556;
  13604. t['five'] = 556;
  13605. t['six'] = 556;
  13606. t['seven'] = 556;
  13607. t['eight'] = 556;
  13608. t['nine'] = 556;
  13609. t['colon'] = 278;
  13610. t['semicolon'] = 278;
  13611. t['less'] = 584;
  13612. t['equal'] = 584;
  13613. t['greater'] = 584;
  13614. t['question'] = 556;
  13615. t['at'] = 1015;
  13616. t['A'] = 667;
  13617. t['B'] = 667;
  13618. t['C'] = 722;
  13619. t['D'] = 722;
  13620. t['E'] = 667;
  13621. t['F'] = 611;
  13622. t['G'] = 778;
  13623. t['H'] = 722;
  13624. t['I'] = 278;
  13625. t['J'] = 500;
  13626. t['K'] = 667;
  13627. t['L'] = 556;
  13628. t['M'] = 833;
  13629. t['N'] = 722;
  13630. t['O'] = 778;
  13631. t['P'] = 667;
  13632. t['Q'] = 778;
  13633. t['R'] = 722;
  13634. t['S'] = 667;
  13635. t['T'] = 611;
  13636. t['U'] = 722;
  13637. t['V'] = 667;
  13638. t['W'] = 944;
  13639. t['X'] = 667;
  13640. t['Y'] = 667;
  13641. t['Z'] = 611;
  13642. t['bracketleft'] = 278;
  13643. t['backslash'] = 278;
  13644. t['bracketright'] = 278;
  13645. t['asciicircum'] = 469;
  13646. t['underscore'] = 556;
  13647. t['quoteleft'] = 222;
  13648. t['a'] = 556;
  13649. t['b'] = 556;
  13650. t['c'] = 500;
  13651. t['d'] = 556;
  13652. t['e'] = 556;
  13653. t['f'] = 278;
  13654. t['g'] = 556;
  13655. t['h'] = 556;
  13656. t['i'] = 222;
  13657. t['j'] = 222;
  13658. t['k'] = 500;
  13659. t['l'] = 222;
  13660. t['m'] = 833;
  13661. t['n'] = 556;
  13662. t['o'] = 556;
  13663. t['p'] = 556;
  13664. t['q'] = 556;
  13665. t['r'] = 333;
  13666. t['s'] = 500;
  13667. t['t'] = 278;
  13668. t['u'] = 556;
  13669. t['v'] = 500;
  13670. t['w'] = 722;
  13671. t['x'] = 500;
  13672. t['y'] = 500;
  13673. t['z'] = 500;
  13674. t['braceleft'] = 334;
  13675. t['bar'] = 260;
  13676. t['braceright'] = 334;
  13677. t['asciitilde'] = 584;
  13678. t['exclamdown'] = 333;
  13679. t['cent'] = 556;
  13680. t['sterling'] = 556;
  13681. t['fraction'] = 167;
  13682. t['yen'] = 556;
  13683. t['florin'] = 556;
  13684. t['section'] = 556;
  13685. t['currency'] = 556;
  13686. t['quotesingle'] = 191;
  13687. t['quotedblleft'] = 333;
  13688. t['guillemotleft'] = 556;
  13689. t['guilsinglleft'] = 333;
  13690. t['guilsinglright'] = 333;
  13691. t['fi'] = 500;
  13692. t['fl'] = 500;
  13693. t['endash'] = 556;
  13694. t['dagger'] = 556;
  13695. t['daggerdbl'] = 556;
  13696. t['periodcentered'] = 278;
  13697. t['paragraph'] = 537;
  13698. t['bullet'] = 350;
  13699. t['quotesinglbase'] = 222;
  13700. t['quotedblbase'] = 333;
  13701. t['quotedblright'] = 333;
  13702. t['guillemotright'] = 556;
  13703. t['ellipsis'] = 1000;
  13704. t['perthousand'] = 1000;
  13705. t['questiondown'] = 611;
  13706. t['grave'] = 333;
  13707. t['acute'] = 333;
  13708. t['circumflex'] = 333;
  13709. t['tilde'] = 333;
  13710. t['macron'] = 333;
  13711. t['breve'] = 333;
  13712. t['dotaccent'] = 333;
  13713. t['dieresis'] = 333;
  13714. t['ring'] = 333;
  13715. t['cedilla'] = 333;
  13716. t['hungarumlaut'] = 333;
  13717. t['ogonek'] = 333;
  13718. t['caron'] = 333;
  13719. t['emdash'] = 1000;
  13720. t['AE'] = 1000;
  13721. t['ordfeminine'] = 370;
  13722. t['Lslash'] = 556;
  13723. t['Oslash'] = 778;
  13724. t['OE'] = 1000;
  13725. t['ordmasculine'] = 365;
  13726. t['ae'] = 889;
  13727. t['dotlessi'] = 278;
  13728. t['lslash'] = 222;
  13729. t['oslash'] = 611;
  13730. t['oe'] = 944;
  13731. t['germandbls'] = 611;
  13732. t['Idieresis'] = 278;
  13733. t['eacute'] = 556;
  13734. t['abreve'] = 556;
  13735. t['uhungarumlaut'] = 556;
  13736. t['ecaron'] = 556;
  13737. t['Ydieresis'] = 667;
  13738. t['divide'] = 584;
  13739. t['Yacute'] = 667;
  13740. t['Acircumflex'] = 667;
  13741. t['aacute'] = 556;
  13742. t['Ucircumflex'] = 722;
  13743. t['yacute'] = 500;
  13744. t['scommaaccent'] = 500;
  13745. t['ecircumflex'] = 556;
  13746. t['Uring'] = 722;
  13747. t['Udieresis'] = 722;
  13748. t['aogonek'] = 556;
  13749. t['Uacute'] = 722;
  13750. t['uogonek'] = 556;
  13751. t['Edieresis'] = 667;
  13752. t['Dcroat'] = 722;
  13753. t['commaaccent'] = 250;
  13754. t['copyright'] = 737;
  13755. t['Emacron'] = 667;
  13756. t['ccaron'] = 500;
  13757. t['aring'] = 556;
  13758. t['Ncommaaccent'] = 722;
  13759. t['lacute'] = 222;
  13760. t['agrave'] = 556;
  13761. t['Tcommaaccent'] = 611;
  13762. t['Cacute'] = 722;
  13763. t['atilde'] = 556;
  13764. t['Edotaccent'] = 667;
  13765. t['scaron'] = 500;
  13766. t['scedilla'] = 500;
  13767. t['iacute'] = 278;
  13768. t['lozenge'] = 471;
  13769. t['Rcaron'] = 722;
  13770. t['Gcommaaccent'] = 778;
  13771. t['ucircumflex'] = 556;
  13772. t['acircumflex'] = 556;
  13773. t['Amacron'] = 667;
  13774. t['rcaron'] = 333;
  13775. t['ccedilla'] = 500;
  13776. t['Zdotaccent'] = 611;
  13777. t['Thorn'] = 667;
  13778. t['Omacron'] = 778;
  13779. t['Racute'] = 722;
  13780. t['Sacute'] = 667;
  13781. t['dcaron'] = 643;
  13782. t['Umacron'] = 722;
  13783. t['uring'] = 556;
  13784. t['threesuperior'] = 333;
  13785. t['Ograve'] = 778;
  13786. t['Agrave'] = 667;
  13787. t['Abreve'] = 667;
  13788. t['multiply'] = 584;
  13789. t['uacute'] = 556;
  13790. t['Tcaron'] = 611;
  13791. t['partialdiff'] = 476;
  13792. t['ydieresis'] = 500;
  13793. t['Nacute'] = 722;
  13794. t['icircumflex'] = 278;
  13795. t['Ecircumflex'] = 667;
  13796. t['adieresis'] = 556;
  13797. t['edieresis'] = 556;
  13798. t['cacute'] = 500;
  13799. t['nacute'] = 556;
  13800. t['umacron'] = 556;
  13801. t['Ncaron'] = 722;
  13802. t['Iacute'] = 278;
  13803. t['plusminus'] = 584;
  13804. t['brokenbar'] = 260;
  13805. t['registered'] = 737;
  13806. t['Gbreve'] = 778;
  13807. t['Idotaccent'] = 278;
  13808. t['summation'] = 600;
  13809. t['Egrave'] = 667;
  13810. t['racute'] = 333;
  13811. t['omacron'] = 556;
  13812. t['Zacute'] = 611;
  13813. t['Zcaron'] = 611;
  13814. t['greaterequal'] = 549;
  13815. t['Eth'] = 722;
  13816. t['Ccedilla'] = 722;
  13817. t['lcommaaccent'] = 222;
  13818. t['tcaron'] = 317;
  13819. t['eogonek'] = 556;
  13820. t['Uogonek'] = 722;
  13821. t['Aacute'] = 667;
  13822. t['Adieresis'] = 667;
  13823. t['egrave'] = 556;
  13824. t['zacute'] = 500;
  13825. t['iogonek'] = 222;
  13826. t['Oacute'] = 778;
  13827. t['oacute'] = 556;
  13828. t['amacron'] = 556;
  13829. t['sacute'] = 500;
  13830. t['idieresis'] = 278;
  13831. t['Ocircumflex'] = 778;
  13832. t['Ugrave'] = 722;
  13833. t['Delta'] = 612;
  13834. t['thorn'] = 556;
  13835. t['twosuperior'] = 333;
  13836. t['Odieresis'] = 778;
  13837. t['mu'] = 556;
  13838. t['igrave'] = 278;
  13839. t['ohungarumlaut'] = 556;
  13840. t['Eogonek'] = 667;
  13841. t['dcroat'] = 556;
  13842. t['threequarters'] = 834;
  13843. t['Scedilla'] = 667;
  13844. t['lcaron'] = 299;
  13845. t['Kcommaaccent'] = 667;
  13846. t['Lacute'] = 556;
  13847. t['trademark'] = 1000;
  13848. t['edotaccent'] = 556;
  13849. t['Igrave'] = 278;
  13850. t['Imacron'] = 278;
  13851. t['Lcaron'] = 556;
  13852. t['onehalf'] = 834;
  13853. t['lessequal'] = 549;
  13854. t['ocircumflex'] = 556;
  13855. t['ntilde'] = 556;
  13856. t['Uhungarumlaut'] = 722;
  13857. t['Eacute'] = 667;
  13858. t['emacron'] = 556;
  13859. t['gbreve'] = 556;
  13860. t['onequarter'] = 834;
  13861. t['Scaron'] = 667;
  13862. t['Scommaaccent'] = 667;
  13863. t['Ohungarumlaut'] = 778;
  13864. t['degree'] = 400;
  13865. t['ograve'] = 556;
  13866. t['Ccaron'] = 722;
  13867. t['ugrave'] = 556;
  13868. t['radical'] = 453;
  13869. t['Dcaron'] = 722;
  13870. t['rcommaaccent'] = 333;
  13871. t['Ntilde'] = 722;
  13872. t['otilde'] = 556;
  13873. t['Rcommaaccent'] = 722;
  13874. t['Lcommaaccent'] = 556;
  13875. t['Atilde'] = 667;
  13876. t['Aogonek'] = 667;
  13877. t['Aring'] = 667;
  13878. t['Otilde'] = 778;
  13879. t['zdotaccent'] = 500;
  13880. t['Ecaron'] = 667;
  13881. t['Iogonek'] = 278;
  13882. t['kcommaaccent'] = 500;
  13883. t['minus'] = 584;
  13884. t['Icircumflex'] = 278;
  13885. t['ncaron'] = 556;
  13886. t['tcommaaccent'] = 278;
  13887. t['logicalnot'] = 584;
  13888. t['odieresis'] = 556;
  13889. t['udieresis'] = 556;
  13890. t['notequal'] = 549;
  13891. t['gcommaaccent'] = 556;
  13892. t['eth'] = 556;
  13893. t['zcaron'] = 500;
  13894. t['ncommaaccent'] = 556;
  13895. t['onesuperior'] = 333;
  13896. t['imacron'] = 278;
  13897. t['Euro'] = 556;
  13898. });
  13899. t['Helvetica-Bold'] = getLookupTableFactory(function (t) {
  13900. t['space'] = 278;
  13901. t['exclam'] = 333;
  13902. t['quotedbl'] = 474;
  13903. t['numbersign'] = 556;
  13904. t['dollar'] = 556;
  13905. t['percent'] = 889;
  13906. t['ampersand'] = 722;
  13907. t['quoteright'] = 278;
  13908. t['parenleft'] = 333;
  13909. t['parenright'] = 333;
  13910. t['asterisk'] = 389;
  13911. t['plus'] = 584;
  13912. t['comma'] = 278;
  13913. t['hyphen'] = 333;
  13914. t['period'] = 278;
  13915. t['slash'] = 278;
  13916. t['zero'] = 556;
  13917. t['one'] = 556;
  13918. t['two'] = 556;
  13919. t['three'] = 556;
  13920. t['four'] = 556;
  13921. t['five'] = 556;
  13922. t['six'] = 556;
  13923. t['seven'] = 556;
  13924. t['eight'] = 556;
  13925. t['nine'] = 556;
  13926. t['colon'] = 333;
  13927. t['semicolon'] = 333;
  13928. t['less'] = 584;
  13929. t['equal'] = 584;
  13930. t['greater'] = 584;
  13931. t['question'] = 611;
  13932. t['at'] = 975;
  13933. t['A'] = 722;
  13934. t['B'] = 722;
  13935. t['C'] = 722;
  13936. t['D'] = 722;
  13937. t['E'] = 667;
  13938. t['F'] = 611;
  13939. t['G'] = 778;
  13940. t['H'] = 722;
  13941. t['I'] = 278;
  13942. t['J'] = 556;
  13943. t['K'] = 722;
  13944. t['L'] = 611;
  13945. t['M'] = 833;
  13946. t['N'] = 722;
  13947. t['O'] = 778;
  13948. t['P'] = 667;
  13949. t['Q'] = 778;
  13950. t['R'] = 722;
  13951. t['S'] = 667;
  13952. t['T'] = 611;
  13953. t['U'] = 722;
  13954. t['V'] = 667;
  13955. t['W'] = 944;
  13956. t['X'] = 667;
  13957. t['Y'] = 667;
  13958. t['Z'] = 611;
  13959. t['bracketleft'] = 333;
  13960. t['backslash'] = 278;
  13961. t['bracketright'] = 333;
  13962. t['asciicircum'] = 584;
  13963. t['underscore'] = 556;
  13964. t['quoteleft'] = 278;
  13965. t['a'] = 556;
  13966. t['b'] = 611;
  13967. t['c'] = 556;
  13968. t['d'] = 611;
  13969. t['e'] = 556;
  13970. t['f'] = 333;
  13971. t['g'] = 611;
  13972. t['h'] = 611;
  13973. t['i'] = 278;
  13974. t['j'] = 278;
  13975. t['k'] = 556;
  13976. t['l'] = 278;
  13977. t['m'] = 889;
  13978. t['n'] = 611;
  13979. t['o'] = 611;
  13980. t['p'] = 611;
  13981. t['q'] = 611;
  13982. t['r'] = 389;
  13983. t['s'] = 556;
  13984. t['t'] = 333;
  13985. t['u'] = 611;
  13986. t['v'] = 556;
  13987. t['w'] = 778;
  13988. t['x'] = 556;
  13989. t['y'] = 556;
  13990. t['z'] = 500;
  13991. t['braceleft'] = 389;
  13992. t['bar'] = 280;
  13993. t['braceright'] = 389;
  13994. t['asciitilde'] = 584;
  13995. t['exclamdown'] = 333;
  13996. t['cent'] = 556;
  13997. t['sterling'] = 556;
  13998. t['fraction'] = 167;
  13999. t['yen'] = 556;
  14000. t['florin'] = 556;
  14001. t['section'] = 556;
  14002. t['currency'] = 556;
  14003. t['quotesingle'] = 238;
  14004. t['quotedblleft'] = 500;
  14005. t['guillemotleft'] = 556;
  14006. t['guilsinglleft'] = 333;
  14007. t['guilsinglright'] = 333;
  14008. t['fi'] = 611;
  14009. t['fl'] = 611;
  14010. t['endash'] = 556;
  14011. t['dagger'] = 556;
  14012. t['daggerdbl'] = 556;
  14013. t['periodcentered'] = 278;
  14014. t['paragraph'] = 556;
  14015. t['bullet'] = 350;
  14016. t['quotesinglbase'] = 278;
  14017. t['quotedblbase'] = 500;
  14018. t['quotedblright'] = 500;
  14019. t['guillemotright'] = 556;
  14020. t['ellipsis'] = 1000;
  14021. t['perthousand'] = 1000;
  14022. t['questiondown'] = 611;
  14023. t['grave'] = 333;
  14024. t['acute'] = 333;
  14025. t['circumflex'] = 333;
  14026. t['tilde'] = 333;
  14027. t['macron'] = 333;
  14028. t['breve'] = 333;
  14029. t['dotaccent'] = 333;
  14030. t['dieresis'] = 333;
  14031. t['ring'] = 333;
  14032. t['cedilla'] = 333;
  14033. t['hungarumlaut'] = 333;
  14034. t['ogonek'] = 333;
  14035. t['caron'] = 333;
  14036. t['emdash'] = 1000;
  14037. t['AE'] = 1000;
  14038. t['ordfeminine'] = 370;
  14039. t['Lslash'] = 611;
  14040. t['Oslash'] = 778;
  14041. t['OE'] = 1000;
  14042. t['ordmasculine'] = 365;
  14043. t['ae'] = 889;
  14044. t['dotlessi'] = 278;
  14045. t['lslash'] = 278;
  14046. t['oslash'] = 611;
  14047. t['oe'] = 944;
  14048. t['germandbls'] = 611;
  14049. t['Idieresis'] = 278;
  14050. t['eacute'] = 556;
  14051. t['abreve'] = 556;
  14052. t['uhungarumlaut'] = 611;
  14053. t['ecaron'] = 556;
  14054. t['Ydieresis'] = 667;
  14055. t['divide'] = 584;
  14056. t['Yacute'] = 667;
  14057. t['Acircumflex'] = 722;
  14058. t['aacute'] = 556;
  14059. t['Ucircumflex'] = 722;
  14060. t['yacute'] = 556;
  14061. t['scommaaccent'] = 556;
  14062. t['ecircumflex'] = 556;
  14063. t['Uring'] = 722;
  14064. t['Udieresis'] = 722;
  14065. t['aogonek'] = 556;
  14066. t['Uacute'] = 722;
  14067. t['uogonek'] = 611;
  14068. t['Edieresis'] = 667;
  14069. t['Dcroat'] = 722;
  14070. t['commaaccent'] = 250;
  14071. t['copyright'] = 737;
  14072. t['Emacron'] = 667;
  14073. t['ccaron'] = 556;
  14074. t['aring'] = 556;
  14075. t['Ncommaaccent'] = 722;
  14076. t['lacute'] = 278;
  14077. t['agrave'] = 556;
  14078. t['Tcommaaccent'] = 611;
  14079. t['Cacute'] = 722;
  14080. t['atilde'] = 556;
  14081. t['Edotaccent'] = 667;
  14082. t['scaron'] = 556;
  14083. t['scedilla'] = 556;
  14084. t['iacute'] = 278;
  14085. t['lozenge'] = 494;
  14086. t['Rcaron'] = 722;
  14087. t['Gcommaaccent'] = 778;
  14088. t['ucircumflex'] = 611;
  14089. t['acircumflex'] = 556;
  14090. t['Amacron'] = 722;
  14091. t['rcaron'] = 389;
  14092. t['ccedilla'] = 556;
  14093. t['Zdotaccent'] = 611;
  14094. t['Thorn'] = 667;
  14095. t['Omacron'] = 778;
  14096. t['Racute'] = 722;
  14097. t['Sacute'] = 667;
  14098. t['dcaron'] = 743;
  14099. t['Umacron'] = 722;
  14100. t['uring'] = 611;
  14101. t['threesuperior'] = 333;
  14102. t['Ograve'] = 778;
  14103. t['Agrave'] = 722;
  14104. t['Abreve'] = 722;
  14105. t['multiply'] = 584;
  14106. t['uacute'] = 611;
  14107. t['Tcaron'] = 611;
  14108. t['partialdiff'] = 494;
  14109. t['ydieresis'] = 556;
  14110. t['Nacute'] = 722;
  14111. t['icircumflex'] = 278;
  14112. t['Ecircumflex'] = 667;
  14113. t['adieresis'] = 556;
  14114. t['edieresis'] = 556;
  14115. t['cacute'] = 556;
  14116. t['nacute'] = 611;
  14117. t['umacron'] = 611;
  14118. t['Ncaron'] = 722;
  14119. t['Iacute'] = 278;
  14120. t['plusminus'] = 584;
  14121. t['brokenbar'] = 280;
  14122. t['registered'] = 737;
  14123. t['Gbreve'] = 778;
  14124. t['Idotaccent'] = 278;
  14125. t['summation'] = 600;
  14126. t['Egrave'] = 667;
  14127. t['racute'] = 389;
  14128. t['omacron'] = 611;
  14129. t['Zacute'] = 611;
  14130. t['Zcaron'] = 611;
  14131. t['greaterequal'] = 549;
  14132. t['Eth'] = 722;
  14133. t['Ccedilla'] = 722;
  14134. t['lcommaaccent'] = 278;
  14135. t['tcaron'] = 389;
  14136. t['eogonek'] = 556;
  14137. t['Uogonek'] = 722;
  14138. t['Aacute'] = 722;
  14139. t['Adieresis'] = 722;
  14140. t['egrave'] = 556;
  14141. t['zacute'] = 500;
  14142. t['iogonek'] = 278;
  14143. t['Oacute'] = 778;
  14144. t['oacute'] = 611;
  14145. t['amacron'] = 556;
  14146. t['sacute'] = 556;
  14147. t['idieresis'] = 278;
  14148. t['Ocircumflex'] = 778;
  14149. t['Ugrave'] = 722;
  14150. t['Delta'] = 612;
  14151. t['thorn'] = 611;
  14152. t['twosuperior'] = 333;
  14153. t['Odieresis'] = 778;
  14154. t['mu'] = 611;
  14155. t['igrave'] = 278;
  14156. t['ohungarumlaut'] = 611;
  14157. t['Eogonek'] = 667;
  14158. t['dcroat'] = 611;
  14159. t['threequarters'] = 834;
  14160. t['Scedilla'] = 667;
  14161. t['lcaron'] = 400;
  14162. t['Kcommaaccent'] = 722;
  14163. t['Lacute'] = 611;
  14164. t['trademark'] = 1000;
  14165. t['edotaccent'] = 556;
  14166. t['Igrave'] = 278;
  14167. t['Imacron'] = 278;
  14168. t['Lcaron'] = 611;
  14169. t['onehalf'] = 834;
  14170. t['lessequal'] = 549;
  14171. t['ocircumflex'] = 611;
  14172. t['ntilde'] = 611;
  14173. t['Uhungarumlaut'] = 722;
  14174. t['Eacute'] = 667;
  14175. t['emacron'] = 556;
  14176. t['gbreve'] = 611;
  14177. t['onequarter'] = 834;
  14178. t['Scaron'] = 667;
  14179. t['Scommaaccent'] = 667;
  14180. t['Ohungarumlaut'] = 778;
  14181. t['degree'] = 400;
  14182. t['ograve'] = 611;
  14183. t['Ccaron'] = 722;
  14184. t['ugrave'] = 611;
  14185. t['radical'] = 549;
  14186. t['Dcaron'] = 722;
  14187. t['rcommaaccent'] = 389;
  14188. t['Ntilde'] = 722;
  14189. t['otilde'] = 611;
  14190. t['Rcommaaccent'] = 722;
  14191. t['Lcommaaccent'] = 611;
  14192. t['Atilde'] = 722;
  14193. t['Aogonek'] = 722;
  14194. t['Aring'] = 722;
  14195. t['Otilde'] = 778;
  14196. t['zdotaccent'] = 500;
  14197. t['Ecaron'] = 667;
  14198. t['Iogonek'] = 278;
  14199. t['kcommaaccent'] = 556;
  14200. t['minus'] = 584;
  14201. t['Icircumflex'] = 278;
  14202. t['ncaron'] = 611;
  14203. t['tcommaaccent'] = 333;
  14204. t['logicalnot'] = 584;
  14205. t['odieresis'] = 611;
  14206. t['udieresis'] = 611;
  14207. t['notequal'] = 549;
  14208. t['gcommaaccent'] = 611;
  14209. t['eth'] = 611;
  14210. t['zcaron'] = 500;
  14211. t['ncommaaccent'] = 611;
  14212. t['onesuperior'] = 333;
  14213. t['imacron'] = 278;
  14214. t['Euro'] = 556;
  14215. });
  14216. t['Helvetica-BoldOblique'] = getLookupTableFactory(function (t) {
  14217. t['space'] = 278;
  14218. t['exclam'] = 333;
  14219. t['quotedbl'] = 474;
  14220. t['numbersign'] = 556;
  14221. t['dollar'] = 556;
  14222. t['percent'] = 889;
  14223. t['ampersand'] = 722;
  14224. t['quoteright'] = 278;
  14225. t['parenleft'] = 333;
  14226. t['parenright'] = 333;
  14227. t['asterisk'] = 389;
  14228. t['plus'] = 584;
  14229. t['comma'] = 278;
  14230. t['hyphen'] = 333;
  14231. t['period'] = 278;
  14232. t['slash'] = 278;
  14233. t['zero'] = 556;
  14234. t['one'] = 556;
  14235. t['two'] = 556;
  14236. t['three'] = 556;
  14237. t['four'] = 556;
  14238. t['five'] = 556;
  14239. t['six'] = 556;
  14240. t['seven'] = 556;
  14241. t['eight'] = 556;
  14242. t['nine'] = 556;
  14243. t['colon'] = 333;
  14244. t['semicolon'] = 333;
  14245. t['less'] = 584;
  14246. t['equal'] = 584;
  14247. t['greater'] = 584;
  14248. t['question'] = 611;
  14249. t['at'] = 975;
  14250. t['A'] = 722;
  14251. t['B'] = 722;
  14252. t['C'] = 722;
  14253. t['D'] = 722;
  14254. t['E'] = 667;
  14255. t['F'] = 611;
  14256. t['G'] = 778;
  14257. t['H'] = 722;
  14258. t['I'] = 278;
  14259. t['J'] = 556;
  14260. t['K'] = 722;
  14261. t['L'] = 611;
  14262. t['M'] = 833;
  14263. t['N'] = 722;
  14264. t['O'] = 778;
  14265. t['P'] = 667;
  14266. t['Q'] = 778;
  14267. t['R'] = 722;
  14268. t['S'] = 667;
  14269. t['T'] = 611;
  14270. t['U'] = 722;
  14271. t['V'] = 667;
  14272. t['W'] = 944;
  14273. t['X'] = 667;
  14274. t['Y'] = 667;
  14275. t['Z'] = 611;
  14276. t['bracketleft'] = 333;
  14277. t['backslash'] = 278;
  14278. t['bracketright'] = 333;
  14279. t['asciicircum'] = 584;
  14280. t['underscore'] = 556;
  14281. t['quoteleft'] = 278;
  14282. t['a'] = 556;
  14283. t['b'] = 611;
  14284. t['c'] = 556;
  14285. t['d'] = 611;
  14286. t['e'] = 556;
  14287. t['f'] = 333;
  14288. t['g'] = 611;
  14289. t['h'] = 611;
  14290. t['i'] = 278;
  14291. t['j'] = 278;
  14292. t['k'] = 556;
  14293. t['l'] = 278;
  14294. t['m'] = 889;
  14295. t['n'] = 611;
  14296. t['o'] = 611;
  14297. t['p'] = 611;
  14298. t['q'] = 611;
  14299. t['r'] = 389;
  14300. t['s'] = 556;
  14301. t['t'] = 333;
  14302. t['u'] = 611;
  14303. t['v'] = 556;
  14304. t['w'] = 778;
  14305. t['x'] = 556;
  14306. t['y'] = 556;
  14307. t['z'] = 500;
  14308. t['braceleft'] = 389;
  14309. t['bar'] = 280;
  14310. t['braceright'] = 389;
  14311. t['asciitilde'] = 584;
  14312. t['exclamdown'] = 333;
  14313. t['cent'] = 556;
  14314. t['sterling'] = 556;
  14315. t['fraction'] = 167;
  14316. t['yen'] = 556;
  14317. t['florin'] = 556;
  14318. t['section'] = 556;
  14319. t['currency'] = 556;
  14320. t['quotesingle'] = 238;
  14321. t['quotedblleft'] = 500;
  14322. t['guillemotleft'] = 556;
  14323. t['guilsinglleft'] = 333;
  14324. t['guilsinglright'] = 333;
  14325. t['fi'] = 611;
  14326. t['fl'] = 611;
  14327. t['endash'] = 556;
  14328. t['dagger'] = 556;
  14329. t['daggerdbl'] = 556;
  14330. t['periodcentered'] = 278;
  14331. t['paragraph'] = 556;
  14332. t['bullet'] = 350;
  14333. t['quotesinglbase'] = 278;
  14334. t['quotedblbase'] = 500;
  14335. t['quotedblright'] = 500;
  14336. t['guillemotright'] = 556;
  14337. t['ellipsis'] = 1000;
  14338. t['perthousand'] = 1000;
  14339. t['questiondown'] = 611;
  14340. t['grave'] = 333;
  14341. t['acute'] = 333;
  14342. t['circumflex'] = 333;
  14343. t['tilde'] = 333;
  14344. t['macron'] = 333;
  14345. t['breve'] = 333;
  14346. t['dotaccent'] = 333;
  14347. t['dieresis'] = 333;
  14348. t['ring'] = 333;
  14349. t['cedilla'] = 333;
  14350. t['hungarumlaut'] = 333;
  14351. t['ogonek'] = 333;
  14352. t['caron'] = 333;
  14353. t['emdash'] = 1000;
  14354. t['AE'] = 1000;
  14355. t['ordfeminine'] = 370;
  14356. t['Lslash'] = 611;
  14357. t['Oslash'] = 778;
  14358. t['OE'] = 1000;
  14359. t['ordmasculine'] = 365;
  14360. t['ae'] = 889;
  14361. t['dotlessi'] = 278;
  14362. t['lslash'] = 278;
  14363. t['oslash'] = 611;
  14364. t['oe'] = 944;
  14365. t['germandbls'] = 611;
  14366. t['Idieresis'] = 278;
  14367. t['eacute'] = 556;
  14368. t['abreve'] = 556;
  14369. t['uhungarumlaut'] = 611;
  14370. t['ecaron'] = 556;
  14371. t['Ydieresis'] = 667;
  14372. t['divide'] = 584;
  14373. t['Yacute'] = 667;
  14374. t['Acircumflex'] = 722;
  14375. t['aacute'] = 556;
  14376. t['Ucircumflex'] = 722;
  14377. t['yacute'] = 556;
  14378. t['scommaaccent'] = 556;
  14379. t['ecircumflex'] = 556;
  14380. t['Uring'] = 722;
  14381. t['Udieresis'] = 722;
  14382. t['aogonek'] = 556;
  14383. t['Uacute'] = 722;
  14384. t['uogonek'] = 611;
  14385. t['Edieresis'] = 667;
  14386. t['Dcroat'] = 722;
  14387. t['commaaccent'] = 250;
  14388. t['copyright'] = 737;
  14389. t['Emacron'] = 667;
  14390. t['ccaron'] = 556;
  14391. t['aring'] = 556;
  14392. t['Ncommaaccent'] = 722;
  14393. t['lacute'] = 278;
  14394. t['agrave'] = 556;
  14395. t['Tcommaaccent'] = 611;
  14396. t['Cacute'] = 722;
  14397. t['atilde'] = 556;
  14398. t['Edotaccent'] = 667;
  14399. t['scaron'] = 556;
  14400. t['scedilla'] = 556;
  14401. t['iacute'] = 278;
  14402. t['lozenge'] = 494;
  14403. t['Rcaron'] = 722;
  14404. t['Gcommaaccent'] = 778;
  14405. t['ucircumflex'] = 611;
  14406. t['acircumflex'] = 556;
  14407. t['Amacron'] = 722;
  14408. t['rcaron'] = 389;
  14409. t['ccedilla'] = 556;
  14410. t['Zdotaccent'] = 611;
  14411. t['Thorn'] = 667;
  14412. t['Omacron'] = 778;
  14413. t['Racute'] = 722;
  14414. t['Sacute'] = 667;
  14415. t['dcaron'] = 743;
  14416. t['Umacron'] = 722;
  14417. t['uring'] = 611;
  14418. t['threesuperior'] = 333;
  14419. t['Ograve'] = 778;
  14420. t['Agrave'] = 722;
  14421. t['Abreve'] = 722;
  14422. t['multiply'] = 584;
  14423. t['uacute'] = 611;
  14424. t['Tcaron'] = 611;
  14425. t['partialdiff'] = 494;
  14426. t['ydieresis'] = 556;
  14427. t['Nacute'] = 722;
  14428. t['icircumflex'] = 278;
  14429. t['Ecircumflex'] = 667;
  14430. t['adieresis'] = 556;
  14431. t['edieresis'] = 556;
  14432. t['cacute'] = 556;
  14433. t['nacute'] = 611;
  14434. t['umacron'] = 611;
  14435. t['Ncaron'] = 722;
  14436. t['Iacute'] = 278;
  14437. t['plusminus'] = 584;
  14438. t['brokenbar'] = 280;
  14439. t['registered'] = 737;
  14440. t['Gbreve'] = 778;
  14441. t['Idotaccent'] = 278;
  14442. t['summation'] = 600;
  14443. t['Egrave'] = 667;
  14444. t['racute'] = 389;
  14445. t['omacron'] = 611;
  14446. t['Zacute'] = 611;
  14447. t['Zcaron'] = 611;
  14448. t['greaterequal'] = 549;
  14449. t['Eth'] = 722;
  14450. t['Ccedilla'] = 722;
  14451. t['lcommaaccent'] = 278;
  14452. t['tcaron'] = 389;
  14453. t['eogonek'] = 556;
  14454. t['Uogonek'] = 722;
  14455. t['Aacute'] = 722;
  14456. t['Adieresis'] = 722;
  14457. t['egrave'] = 556;
  14458. t['zacute'] = 500;
  14459. t['iogonek'] = 278;
  14460. t['Oacute'] = 778;
  14461. t['oacute'] = 611;
  14462. t['amacron'] = 556;
  14463. t['sacute'] = 556;
  14464. t['idieresis'] = 278;
  14465. t['Ocircumflex'] = 778;
  14466. t['Ugrave'] = 722;
  14467. t['Delta'] = 612;
  14468. t['thorn'] = 611;
  14469. t['twosuperior'] = 333;
  14470. t['Odieresis'] = 778;
  14471. t['mu'] = 611;
  14472. t['igrave'] = 278;
  14473. t['ohungarumlaut'] = 611;
  14474. t['Eogonek'] = 667;
  14475. t['dcroat'] = 611;
  14476. t['threequarters'] = 834;
  14477. t['Scedilla'] = 667;
  14478. t['lcaron'] = 400;
  14479. t['Kcommaaccent'] = 722;
  14480. t['Lacute'] = 611;
  14481. t['trademark'] = 1000;
  14482. t['edotaccent'] = 556;
  14483. t['Igrave'] = 278;
  14484. t['Imacron'] = 278;
  14485. t['Lcaron'] = 611;
  14486. t['onehalf'] = 834;
  14487. t['lessequal'] = 549;
  14488. t['ocircumflex'] = 611;
  14489. t['ntilde'] = 611;
  14490. t['Uhungarumlaut'] = 722;
  14491. t['Eacute'] = 667;
  14492. t['emacron'] = 556;
  14493. t['gbreve'] = 611;
  14494. t['onequarter'] = 834;
  14495. t['Scaron'] = 667;
  14496. t['Scommaaccent'] = 667;
  14497. t['Ohungarumlaut'] = 778;
  14498. t['degree'] = 400;
  14499. t['ograve'] = 611;
  14500. t['Ccaron'] = 722;
  14501. t['ugrave'] = 611;
  14502. t['radical'] = 549;
  14503. t['Dcaron'] = 722;
  14504. t['rcommaaccent'] = 389;
  14505. t['Ntilde'] = 722;
  14506. t['otilde'] = 611;
  14507. t['Rcommaaccent'] = 722;
  14508. t['Lcommaaccent'] = 611;
  14509. t['Atilde'] = 722;
  14510. t['Aogonek'] = 722;
  14511. t['Aring'] = 722;
  14512. t['Otilde'] = 778;
  14513. t['zdotaccent'] = 500;
  14514. t['Ecaron'] = 667;
  14515. t['Iogonek'] = 278;
  14516. t['kcommaaccent'] = 556;
  14517. t['minus'] = 584;
  14518. t['Icircumflex'] = 278;
  14519. t['ncaron'] = 611;
  14520. t['tcommaaccent'] = 333;
  14521. t['logicalnot'] = 584;
  14522. t['odieresis'] = 611;
  14523. t['udieresis'] = 611;
  14524. t['notequal'] = 549;
  14525. t['gcommaaccent'] = 611;
  14526. t['eth'] = 611;
  14527. t['zcaron'] = 500;
  14528. t['ncommaaccent'] = 611;
  14529. t['onesuperior'] = 333;
  14530. t['imacron'] = 278;
  14531. t['Euro'] = 556;
  14532. });
  14533. t['Helvetica-Oblique'] = getLookupTableFactory(function (t) {
  14534. t['space'] = 278;
  14535. t['exclam'] = 278;
  14536. t['quotedbl'] = 355;
  14537. t['numbersign'] = 556;
  14538. t['dollar'] = 556;
  14539. t['percent'] = 889;
  14540. t['ampersand'] = 667;
  14541. t['quoteright'] = 222;
  14542. t['parenleft'] = 333;
  14543. t['parenright'] = 333;
  14544. t['asterisk'] = 389;
  14545. t['plus'] = 584;
  14546. t['comma'] = 278;
  14547. t['hyphen'] = 333;
  14548. t['period'] = 278;
  14549. t['slash'] = 278;
  14550. t['zero'] = 556;
  14551. t['one'] = 556;
  14552. t['two'] = 556;
  14553. t['three'] = 556;
  14554. t['four'] = 556;
  14555. t['five'] = 556;
  14556. t['six'] = 556;
  14557. t['seven'] = 556;
  14558. t['eight'] = 556;
  14559. t['nine'] = 556;
  14560. t['colon'] = 278;
  14561. t['semicolon'] = 278;
  14562. t['less'] = 584;
  14563. t['equal'] = 584;
  14564. t['greater'] = 584;
  14565. t['question'] = 556;
  14566. t['at'] = 1015;
  14567. t['A'] = 667;
  14568. t['B'] = 667;
  14569. t['C'] = 722;
  14570. t['D'] = 722;
  14571. t['E'] = 667;
  14572. t['F'] = 611;
  14573. t['G'] = 778;
  14574. t['H'] = 722;
  14575. t['I'] = 278;
  14576. t['J'] = 500;
  14577. t['K'] = 667;
  14578. t['L'] = 556;
  14579. t['M'] = 833;
  14580. t['N'] = 722;
  14581. t['O'] = 778;
  14582. t['P'] = 667;
  14583. t['Q'] = 778;
  14584. t['R'] = 722;
  14585. t['S'] = 667;
  14586. t['T'] = 611;
  14587. t['U'] = 722;
  14588. t['V'] = 667;
  14589. t['W'] = 944;
  14590. t['X'] = 667;
  14591. t['Y'] = 667;
  14592. t['Z'] = 611;
  14593. t['bracketleft'] = 278;
  14594. t['backslash'] = 278;
  14595. t['bracketright'] = 278;
  14596. t['asciicircum'] = 469;
  14597. t['underscore'] = 556;
  14598. t['quoteleft'] = 222;
  14599. t['a'] = 556;
  14600. t['b'] = 556;
  14601. t['c'] = 500;
  14602. t['d'] = 556;
  14603. t['e'] = 556;
  14604. t['f'] = 278;
  14605. t['g'] = 556;
  14606. t['h'] = 556;
  14607. t['i'] = 222;
  14608. t['j'] = 222;
  14609. t['k'] = 500;
  14610. t['l'] = 222;
  14611. t['m'] = 833;
  14612. t['n'] = 556;
  14613. t['o'] = 556;
  14614. t['p'] = 556;
  14615. t['q'] = 556;
  14616. t['r'] = 333;
  14617. t['s'] = 500;
  14618. t['t'] = 278;
  14619. t['u'] = 556;
  14620. t['v'] = 500;
  14621. t['w'] = 722;
  14622. t['x'] = 500;
  14623. t['y'] = 500;
  14624. t['z'] = 500;
  14625. t['braceleft'] = 334;
  14626. t['bar'] = 260;
  14627. t['braceright'] = 334;
  14628. t['asciitilde'] = 584;
  14629. t['exclamdown'] = 333;
  14630. t['cent'] = 556;
  14631. t['sterling'] = 556;
  14632. t['fraction'] = 167;
  14633. t['yen'] = 556;
  14634. t['florin'] = 556;
  14635. t['section'] = 556;
  14636. t['currency'] = 556;
  14637. t['quotesingle'] = 191;
  14638. t['quotedblleft'] = 333;
  14639. t['guillemotleft'] = 556;
  14640. t['guilsinglleft'] = 333;
  14641. t['guilsinglright'] = 333;
  14642. t['fi'] = 500;
  14643. t['fl'] = 500;
  14644. t['endash'] = 556;
  14645. t['dagger'] = 556;
  14646. t['daggerdbl'] = 556;
  14647. t['periodcentered'] = 278;
  14648. t['paragraph'] = 537;
  14649. t['bullet'] = 350;
  14650. t['quotesinglbase'] = 222;
  14651. t['quotedblbase'] = 333;
  14652. t['quotedblright'] = 333;
  14653. t['guillemotright'] = 556;
  14654. t['ellipsis'] = 1000;
  14655. t['perthousand'] = 1000;
  14656. t['questiondown'] = 611;
  14657. t['grave'] = 333;
  14658. t['acute'] = 333;
  14659. t['circumflex'] = 333;
  14660. t['tilde'] = 333;
  14661. t['macron'] = 333;
  14662. t['breve'] = 333;
  14663. t['dotaccent'] = 333;
  14664. t['dieresis'] = 333;
  14665. t['ring'] = 333;
  14666. t['cedilla'] = 333;
  14667. t['hungarumlaut'] = 333;
  14668. t['ogonek'] = 333;
  14669. t['caron'] = 333;
  14670. t['emdash'] = 1000;
  14671. t['AE'] = 1000;
  14672. t['ordfeminine'] = 370;
  14673. t['Lslash'] = 556;
  14674. t['Oslash'] = 778;
  14675. t['OE'] = 1000;
  14676. t['ordmasculine'] = 365;
  14677. t['ae'] = 889;
  14678. t['dotlessi'] = 278;
  14679. t['lslash'] = 222;
  14680. t['oslash'] = 611;
  14681. t['oe'] = 944;
  14682. t['germandbls'] = 611;
  14683. t['Idieresis'] = 278;
  14684. t['eacute'] = 556;
  14685. t['abreve'] = 556;
  14686. t['uhungarumlaut'] = 556;
  14687. t['ecaron'] = 556;
  14688. t['Ydieresis'] = 667;
  14689. t['divide'] = 584;
  14690. t['Yacute'] = 667;
  14691. t['Acircumflex'] = 667;
  14692. t['aacute'] = 556;
  14693. t['Ucircumflex'] = 722;
  14694. t['yacute'] = 500;
  14695. t['scommaaccent'] = 500;
  14696. t['ecircumflex'] = 556;
  14697. t['Uring'] = 722;
  14698. t['Udieresis'] = 722;
  14699. t['aogonek'] = 556;
  14700. t['Uacute'] = 722;
  14701. t['uogonek'] = 556;
  14702. t['Edieresis'] = 667;
  14703. t['Dcroat'] = 722;
  14704. t['commaaccent'] = 250;
  14705. t['copyright'] = 737;
  14706. t['Emacron'] = 667;
  14707. t['ccaron'] = 500;
  14708. t['aring'] = 556;
  14709. t['Ncommaaccent'] = 722;
  14710. t['lacute'] = 222;
  14711. t['agrave'] = 556;
  14712. t['Tcommaaccent'] = 611;
  14713. t['Cacute'] = 722;
  14714. t['atilde'] = 556;
  14715. t['Edotaccent'] = 667;
  14716. t['scaron'] = 500;
  14717. t['scedilla'] = 500;
  14718. t['iacute'] = 278;
  14719. t['lozenge'] = 471;
  14720. t['Rcaron'] = 722;
  14721. t['Gcommaaccent'] = 778;
  14722. t['ucircumflex'] = 556;
  14723. t['acircumflex'] = 556;
  14724. t['Amacron'] = 667;
  14725. t['rcaron'] = 333;
  14726. t['ccedilla'] = 500;
  14727. t['Zdotaccent'] = 611;
  14728. t['Thorn'] = 667;
  14729. t['Omacron'] = 778;
  14730. t['Racute'] = 722;
  14731. t['Sacute'] = 667;
  14732. t['dcaron'] = 643;
  14733. t['Umacron'] = 722;
  14734. t['uring'] = 556;
  14735. t['threesuperior'] = 333;
  14736. t['Ograve'] = 778;
  14737. t['Agrave'] = 667;
  14738. t['Abreve'] = 667;
  14739. t['multiply'] = 584;
  14740. t['uacute'] = 556;
  14741. t['Tcaron'] = 611;
  14742. t['partialdiff'] = 476;
  14743. t['ydieresis'] = 500;
  14744. t['Nacute'] = 722;
  14745. t['icircumflex'] = 278;
  14746. t['Ecircumflex'] = 667;
  14747. t['adieresis'] = 556;
  14748. t['edieresis'] = 556;
  14749. t['cacute'] = 500;
  14750. t['nacute'] = 556;
  14751. t['umacron'] = 556;
  14752. t['Ncaron'] = 722;
  14753. t['Iacute'] = 278;
  14754. t['plusminus'] = 584;
  14755. t['brokenbar'] = 260;
  14756. t['registered'] = 737;
  14757. t['Gbreve'] = 778;
  14758. t['Idotaccent'] = 278;
  14759. t['summation'] = 600;
  14760. t['Egrave'] = 667;
  14761. t['racute'] = 333;
  14762. t['omacron'] = 556;
  14763. t['Zacute'] = 611;
  14764. t['Zcaron'] = 611;
  14765. t['greaterequal'] = 549;
  14766. t['Eth'] = 722;
  14767. t['Ccedilla'] = 722;
  14768. t['lcommaaccent'] = 222;
  14769. t['tcaron'] = 317;
  14770. t['eogonek'] = 556;
  14771. t['Uogonek'] = 722;
  14772. t['Aacute'] = 667;
  14773. t['Adieresis'] = 667;
  14774. t['egrave'] = 556;
  14775. t['zacute'] = 500;
  14776. t['iogonek'] = 222;
  14777. t['Oacute'] = 778;
  14778. t['oacute'] = 556;
  14779. t['amacron'] = 556;
  14780. t['sacute'] = 500;
  14781. t['idieresis'] = 278;
  14782. t['Ocircumflex'] = 778;
  14783. t['Ugrave'] = 722;
  14784. t['Delta'] = 612;
  14785. t['thorn'] = 556;
  14786. t['twosuperior'] = 333;
  14787. t['Odieresis'] = 778;
  14788. t['mu'] = 556;
  14789. t['igrave'] = 278;
  14790. t['ohungarumlaut'] = 556;
  14791. t['Eogonek'] = 667;
  14792. t['dcroat'] = 556;
  14793. t['threequarters'] = 834;
  14794. t['Scedilla'] = 667;
  14795. t['lcaron'] = 299;
  14796. t['Kcommaaccent'] = 667;
  14797. t['Lacute'] = 556;
  14798. t['trademark'] = 1000;
  14799. t['edotaccent'] = 556;
  14800. t['Igrave'] = 278;
  14801. t['Imacron'] = 278;
  14802. t['Lcaron'] = 556;
  14803. t['onehalf'] = 834;
  14804. t['lessequal'] = 549;
  14805. t['ocircumflex'] = 556;
  14806. t['ntilde'] = 556;
  14807. t['Uhungarumlaut'] = 722;
  14808. t['Eacute'] = 667;
  14809. t['emacron'] = 556;
  14810. t['gbreve'] = 556;
  14811. t['onequarter'] = 834;
  14812. t['Scaron'] = 667;
  14813. t['Scommaaccent'] = 667;
  14814. t['Ohungarumlaut'] = 778;
  14815. t['degree'] = 400;
  14816. t['ograve'] = 556;
  14817. t['Ccaron'] = 722;
  14818. t['ugrave'] = 556;
  14819. t['radical'] = 453;
  14820. t['Dcaron'] = 722;
  14821. t['rcommaaccent'] = 333;
  14822. t['Ntilde'] = 722;
  14823. t['otilde'] = 556;
  14824. t['Rcommaaccent'] = 722;
  14825. t['Lcommaaccent'] = 556;
  14826. t['Atilde'] = 667;
  14827. t['Aogonek'] = 667;
  14828. t['Aring'] = 667;
  14829. t['Otilde'] = 778;
  14830. t['zdotaccent'] = 500;
  14831. t['Ecaron'] = 667;
  14832. t['Iogonek'] = 278;
  14833. t['kcommaaccent'] = 500;
  14834. t['minus'] = 584;
  14835. t['Icircumflex'] = 278;
  14836. t['ncaron'] = 556;
  14837. t['tcommaaccent'] = 278;
  14838. t['logicalnot'] = 584;
  14839. t['odieresis'] = 556;
  14840. t['udieresis'] = 556;
  14841. t['notequal'] = 549;
  14842. t['gcommaaccent'] = 556;
  14843. t['eth'] = 556;
  14844. t['zcaron'] = 500;
  14845. t['ncommaaccent'] = 556;
  14846. t['onesuperior'] = 333;
  14847. t['imacron'] = 278;
  14848. t['Euro'] = 556;
  14849. });
  14850. t['Symbol'] = getLookupTableFactory(function (t) {
  14851. t['space'] = 250;
  14852. t['exclam'] = 333;
  14853. t['universal'] = 713;
  14854. t['numbersign'] = 500;
  14855. t['existential'] = 549;
  14856. t['percent'] = 833;
  14857. t['ampersand'] = 778;
  14858. t['suchthat'] = 439;
  14859. t['parenleft'] = 333;
  14860. t['parenright'] = 333;
  14861. t['asteriskmath'] = 500;
  14862. t['plus'] = 549;
  14863. t['comma'] = 250;
  14864. t['minus'] = 549;
  14865. t['period'] = 250;
  14866. t['slash'] = 278;
  14867. t['zero'] = 500;
  14868. t['one'] = 500;
  14869. t['two'] = 500;
  14870. t['three'] = 500;
  14871. t['four'] = 500;
  14872. t['five'] = 500;
  14873. t['six'] = 500;
  14874. t['seven'] = 500;
  14875. t['eight'] = 500;
  14876. t['nine'] = 500;
  14877. t['colon'] = 278;
  14878. t['semicolon'] = 278;
  14879. t['less'] = 549;
  14880. t['equal'] = 549;
  14881. t['greater'] = 549;
  14882. t['question'] = 444;
  14883. t['congruent'] = 549;
  14884. t['Alpha'] = 722;
  14885. t['Beta'] = 667;
  14886. t['Chi'] = 722;
  14887. t['Delta'] = 612;
  14888. t['Epsilon'] = 611;
  14889. t['Phi'] = 763;
  14890. t['Gamma'] = 603;
  14891. t['Eta'] = 722;
  14892. t['Iota'] = 333;
  14893. t['theta1'] = 631;
  14894. t['Kappa'] = 722;
  14895. t['Lambda'] = 686;
  14896. t['Mu'] = 889;
  14897. t['Nu'] = 722;
  14898. t['Omicron'] = 722;
  14899. t['Pi'] = 768;
  14900. t['Theta'] = 741;
  14901. t['Rho'] = 556;
  14902. t['Sigma'] = 592;
  14903. t['Tau'] = 611;
  14904. t['Upsilon'] = 690;
  14905. t['sigma1'] = 439;
  14906. t['Omega'] = 768;
  14907. t['Xi'] = 645;
  14908. t['Psi'] = 795;
  14909. t['Zeta'] = 611;
  14910. t['bracketleft'] = 333;
  14911. t['therefore'] = 863;
  14912. t['bracketright'] = 333;
  14913. t['perpendicular'] = 658;
  14914. t['underscore'] = 500;
  14915. t['radicalex'] = 500;
  14916. t['alpha'] = 631;
  14917. t['beta'] = 549;
  14918. t['chi'] = 549;
  14919. t['delta'] = 494;
  14920. t['epsilon'] = 439;
  14921. t['phi'] = 521;
  14922. t['gamma'] = 411;
  14923. t['eta'] = 603;
  14924. t['iota'] = 329;
  14925. t['phi1'] = 603;
  14926. t['kappa'] = 549;
  14927. t['lambda'] = 549;
  14928. t['mu'] = 576;
  14929. t['nu'] = 521;
  14930. t['omicron'] = 549;
  14931. t['pi'] = 549;
  14932. t['theta'] = 521;
  14933. t['rho'] = 549;
  14934. t['sigma'] = 603;
  14935. t['tau'] = 439;
  14936. t['upsilon'] = 576;
  14937. t['omega1'] = 713;
  14938. t['omega'] = 686;
  14939. t['xi'] = 493;
  14940. t['psi'] = 686;
  14941. t['zeta'] = 494;
  14942. t['braceleft'] = 480;
  14943. t['bar'] = 200;
  14944. t['braceright'] = 480;
  14945. t['similar'] = 549;
  14946. t['Euro'] = 750;
  14947. t['Upsilon1'] = 620;
  14948. t['minute'] = 247;
  14949. t['lessequal'] = 549;
  14950. t['fraction'] = 167;
  14951. t['infinity'] = 713;
  14952. t['florin'] = 500;
  14953. t['club'] = 753;
  14954. t['diamond'] = 753;
  14955. t['heart'] = 753;
  14956. t['spade'] = 753;
  14957. t['arrowboth'] = 1042;
  14958. t['arrowleft'] = 987;
  14959. t['arrowup'] = 603;
  14960. t['arrowright'] = 987;
  14961. t['arrowdown'] = 603;
  14962. t['degree'] = 400;
  14963. t['plusminus'] = 549;
  14964. t['second'] = 411;
  14965. t['greaterequal'] = 549;
  14966. t['multiply'] = 549;
  14967. t['proportional'] = 713;
  14968. t['partialdiff'] = 494;
  14969. t['bullet'] = 460;
  14970. t['divide'] = 549;
  14971. t['notequal'] = 549;
  14972. t['equivalence'] = 549;
  14973. t['approxequal'] = 549;
  14974. t['ellipsis'] = 1000;
  14975. t['arrowvertex'] = 603;
  14976. t['arrowhorizex'] = 1000;
  14977. t['carriagereturn'] = 658;
  14978. t['aleph'] = 823;
  14979. t['Ifraktur'] = 686;
  14980. t['Rfraktur'] = 795;
  14981. t['weierstrass'] = 987;
  14982. t['circlemultiply'] = 768;
  14983. t['circleplus'] = 768;
  14984. t['emptyset'] = 823;
  14985. t['intersection'] = 768;
  14986. t['union'] = 768;
  14987. t['propersuperset'] = 713;
  14988. t['reflexsuperset'] = 713;
  14989. t['notsubset'] = 713;
  14990. t['propersubset'] = 713;
  14991. t['reflexsubset'] = 713;
  14992. t['element'] = 713;
  14993. t['notelement'] = 713;
  14994. t['angle'] = 768;
  14995. t['gradient'] = 713;
  14996. t['registerserif'] = 790;
  14997. t['copyrightserif'] = 790;
  14998. t['trademarkserif'] = 890;
  14999. t['product'] = 823;
  15000. t['radical'] = 549;
  15001. t['dotmath'] = 250;
  15002. t['logicalnot'] = 713;
  15003. t['logicaland'] = 603;
  15004. t['logicalor'] = 603;
  15005. t['arrowdblboth'] = 1042;
  15006. t['arrowdblleft'] = 987;
  15007. t['arrowdblup'] = 603;
  15008. t['arrowdblright'] = 987;
  15009. t['arrowdbldown'] = 603;
  15010. t['lozenge'] = 494;
  15011. t['angleleft'] = 329;
  15012. t['registersans'] = 790;
  15013. t['copyrightsans'] = 790;
  15014. t['trademarksans'] = 786;
  15015. t['summation'] = 713;
  15016. t['parenlefttp'] = 384;
  15017. t['parenleftex'] = 384;
  15018. t['parenleftbt'] = 384;
  15019. t['bracketlefttp'] = 384;
  15020. t['bracketleftex'] = 384;
  15021. t['bracketleftbt'] = 384;
  15022. t['bracelefttp'] = 494;
  15023. t['braceleftmid'] = 494;
  15024. t['braceleftbt'] = 494;
  15025. t['braceex'] = 494;
  15026. t['angleright'] = 329;
  15027. t['integral'] = 274;
  15028. t['integraltp'] = 686;
  15029. t['integralex'] = 686;
  15030. t['integralbt'] = 686;
  15031. t['parenrighttp'] = 384;
  15032. t['parenrightex'] = 384;
  15033. t['parenrightbt'] = 384;
  15034. t['bracketrighttp'] = 384;
  15035. t['bracketrightex'] = 384;
  15036. t['bracketrightbt'] = 384;
  15037. t['bracerighttp'] = 494;
  15038. t['bracerightmid'] = 494;
  15039. t['bracerightbt'] = 494;
  15040. t['apple'] = 790;
  15041. });
  15042. t['Times-Roman'] = getLookupTableFactory(function (t) {
  15043. t['space'] = 250;
  15044. t['exclam'] = 333;
  15045. t['quotedbl'] = 408;
  15046. t['numbersign'] = 500;
  15047. t['dollar'] = 500;
  15048. t['percent'] = 833;
  15049. t['ampersand'] = 778;
  15050. t['quoteright'] = 333;
  15051. t['parenleft'] = 333;
  15052. t['parenright'] = 333;
  15053. t['asterisk'] = 500;
  15054. t['plus'] = 564;
  15055. t['comma'] = 250;
  15056. t['hyphen'] = 333;
  15057. t['period'] = 250;
  15058. t['slash'] = 278;
  15059. t['zero'] = 500;
  15060. t['one'] = 500;
  15061. t['two'] = 500;
  15062. t['three'] = 500;
  15063. t['four'] = 500;
  15064. t['five'] = 500;
  15065. t['six'] = 500;
  15066. t['seven'] = 500;
  15067. t['eight'] = 500;
  15068. t['nine'] = 500;
  15069. t['colon'] = 278;
  15070. t['semicolon'] = 278;
  15071. t['less'] = 564;
  15072. t['equal'] = 564;
  15073. t['greater'] = 564;
  15074. t['question'] = 444;
  15075. t['at'] = 921;
  15076. t['A'] = 722;
  15077. t['B'] = 667;
  15078. t['C'] = 667;
  15079. t['D'] = 722;
  15080. t['E'] = 611;
  15081. t['F'] = 556;
  15082. t['G'] = 722;
  15083. t['H'] = 722;
  15084. t['I'] = 333;
  15085. t['J'] = 389;
  15086. t['K'] = 722;
  15087. t['L'] = 611;
  15088. t['M'] = 889;
  15089. t['N'] = 722;
  15090. t['O'] = 722;
  15091. t['P'] = 556;
  15092. t['Q'] = 722;
  15093. t['R'] = 667;
  15094. t['S'] = 556;
  15095. t['T'] = 611;
  15096. t['U'] = 722;
  15097. t['V'] = 722;
  15098. t['W'] = 944;
  15099. t['X'] = 722;
  15100. t['Y'] = 722;
  15101. t['Z'] = 611;
  15102. t['bracketleft'] = 333;
  15103. t['backslash'] = 278;
  15104. t['bracketright'] = 333;
  15105. t['asciicircum'] = 469;
  15106. t['underscore'] = 500;
  15107. t['quoteleft'] = 333;
  15108. t['a'] = 444;
  15109. t['b'] = 500;
  15110. t['c'] = 444;
  15111. t['d'] = 500;
  15112. t['e'] = 444;
  15113. t['f'] = 333;
  15114. t['g'] = 500;
  15115. t['h'] = 500;
  15116. t['i'] = 278;
  15117. t['j'] = 278;
  15118. t['k'] = 500;
  15119. t['l'] = 278;
  15120. t['m'] = 778;
  15121. t['n'] = 500;
  15122. t['o'] = 500;
  15123. t['p'] = 500;
  15124. t['q'] = 500;
  15125. t['r'] = 333;
  15126. t['s'] = 389;
  15127. t['t'] = 278;
  15128. t['u'] = 500;
  15129. t['v'] = 500;
  15130. t['w'] = 722;
  15131. t['x'] = 500;
  15132. t['y'] = 500;
  15133. t['z'] = 444;
  15134. t['braceleft'] = 480;
  15135. t['bar'] = 200;
  15136. t['braceright'] = 480;
  15137. t['asciitilde'] = 541;
  15138. t['exclamdown'] = 333;
  15139. t['cent'] = 500;
  15140. t['sterling'] = 500;
  15141. t['fraction'] = 167;
  15142. t['yen'] = 500;
  15143. t['florin'] = 500;
  15144. t['section'] = 500;
  15145. t['currency'] = 500;
  15146. t['quotesingle'] = 180;
  15147. t['quotedblleft'] = 444;
  15148. t['guillemotleft'] = 500;
  15149. t['guilsinglleft'] = 333;
  15150. t['guilsinglright'] = 333;
  15151. t['fi'] = 556;
  15152. t['fl'] = 556;
  15153. t['endash'] = 500;
  15154. t['dagger'] = 500;
  15155. t['daggerdbl'] = 500;
  15156. t['periodcentered'] = 250;
  15157. t['paragraph'] = 453;
  15158. t['bullet'] = 350;
  15159. t['quotesinglbase'] = 333;
  15160. t['quotedblbase'] = 444;
  15161. t['quotedblright'] = 444;
  15162. t['guillemotright'] = 500;
  15163. t['ellipsis'] = 1000;
  15164. t['perthousand'] = 1000;
  15165. t['questiondown'] = 444;
  15166. t['grave'] = 333;
  15167. t['acute'] = 333;
  15168. t['circumflex'] = 333;
  15169. t['tilde'] = 333;
  15170. t['macron'] = 333;
  15171. t['breve'] = 333;
  15172. t['dotaccent'] = 333;
  15173. t['dieresis'] = 333;
  15174. t['ring'] = 333;
  15175. t['cedilla'] = 333;
  15176. t['hungarumlaut'] = 333;
  15177. t['ogonek'] = 333;
  15178. t['caron'] = 333;
  15179. t['emdash'] = 1000;
  15180. t['AE'] = 889;
  15181. t['ordfeminine'] = 276;
  15182. t['Lslash'] = 611;
  15183. t['Oslash'] = 722;
  15184. t['OE'] = 889;
  15185. t['ordmasculine'] = 310;
  15186. t['ae'] = 667;
  15187. t['dotlessi'] = 278;
  15188. t['lslash'] = 278;
  15189. t['oslash'] = 500;
  15190. t['oe'] = 722;
  15191. t['germandbls'] = 500;
  15192. t['Idieresis'] = 333;
  15193. t['eacute'] = 444;
  15194. t['abreve'] = 444;
  15195. t['uhungarumlaut'] = 500;
  15196. t['ecaron'] = 444;
  15197. t['Ydieresis'] = 722;
  15198. t['divide'] = 564;
  15199. t['Yacute'] = 722;
  15200. t['Acircumflex'] = 722;
  15201. t['aacute'] = 444;
  15202. t['Ucircumflex'] = 722;
  15203. t['yacute'] = 500;
  15204. t['scommaaccent'] = 389;
  15205. t['ecircumflex'] = 444;
  15206. t['Uring'] = 722;
  15207. t['Udieresis'] = 722;
  15208. t['aogonek'] = 444;
  15209. t['Uacute'] = 722;
  15210. t['uogonek'] = 500;
  15211. t['Edieresis'] = 611;
  15212. t['Dcroat'] = 722;
  15213. t['commaaccent'] = 250;
  15214. t['copyright'] = 760;
  15215. t['Emacron'] = 611;
  15216. t['ccaron'] = 444;
  15217. t['aring'] = 444;
  15218. t['Ncommaaccent'] = 722;
  15219. t['lacute'] = 278;
  15220. t['agrave'] = 444;
  15221. t['Tcommaaccent'] = 611;
  15222. t['Cacute'] = 667;
  15223. t['atilde'] = 444;
  15224. t['Edotaccent'] = 611;
  15225. t['scaron'] = 389;
  15226. t['scedilla'] = 389;
  15227. t['iacute'] = 278;
  15228. t['lozenge'] = 471;
  15229. t['Rcaron'] = 667;
  15230. t['Gcommaaccent'] = 722;
  15231. t['ucircumflex'] = 500;
  15232. t['acircumflex'] = 444;
  15233. t['Amacron'] = 722;
  15234. t['rcaron'] = 333;
  15235. t['ccedilla'] = 444;
  15236. t['Zdotaccent'] = 611;
  15237. t['Thorn'] = 556;
  15238. t['Omacron'] = 722;
  15239. t['Racute'] = 667;
  15240. t['Sacute'] = 556;
  15241. t['dcaron'] = 588;
  15242. t['Umacron'] = 722;
  15243. t['uring'] = 500;
  15244. t['threesuperior'] = 300;
  15245. t['Ograve'] = 722;
  15246. t['Agrave'] = 722;
  15247. t['Abreve'] = 722;
  15248. t['multiply'] = 564;
  15249. t['uacute'] = 500;
  15250. t['Tcaron'] = 611;
  15251. t['partialdiff'] = 476;
  15252. t['ydieresis'] = 500;
  15253. t['Nacute'] = 722;
  15254. t['icircumflex'] = 278;
  15255. t['Ecircumflex'] = 611;
  15256. t['adieresis'] = 444;
  15257. t['edieresis'] = 444;
  15258. t['cacute'] = 444;
  15259. t['nacute'] = 500;
  15260. t['umacron'] = 500;
  15261. t['Ncaron'] = 722;
  15262. t['Iacute'] = 333;
  15263. t['plusminus'] = 564;
  15264. t['brokenbar'] = 200;
  15265. t['registered'] = 760;
  15266. t['Gbreve'] = 722;
  15267. t['Idotaccent'] = 333;
  15268. t['summation'] = 600;
  15269. t['Egrave'] = 611;
  15270. t['racute'] = 333;
  15271. t['omacron'] = 500;
  15272. t['Zacute'] = 611;
  15273. t['Zcaron'] = 611;
  15274. t['greaterequal'] = 549;
  15275. t['Eth'] = 722;
  15276. t['Ccedilla'] = 667;
  15277. t['lcommaaccent'] = 278;
  15278. t['tcaron'] = 326;
  15279. t['eogonek'] = 444;
  15280. t['Uogonek'] = 722;
  15281. t['Aacute'] = 722;
  15282. t['Adieresis'] = 722;
  15283. t['egrave'] = 444;
  15284. t['zacute'] = 444;
  15285. t['iogonek'] = 278;
  15286. t['Oacute'] = 722;
  15287. t['oacute'] = 500;
  15288. t['amacron'] = 444;
  15289. t['sacute'] = 389;
  15290. t['idieresis'] = 278;
  15291. t['Ocircumflex'] = 722;
  15292. t['Ugrave'] = 722;
  15293. t['Delta'] = 612;
  15294. t['thorn'] = 500;
  15295. t['twosuperior'] = 300;
  15296. t['Odieresis'] = 722;
  15297. t['mu'] = 500;
  15298. t['igrave'] = 278;
  15299. t['ohungarumlaut'] = 500;
  15300. t['Eogonek'] = 611;
  15301. t['dcroat'] = 500;
  15302. t['threequarters'] = 750;
  15303. t['Scedilla'] = 556;
  15304. t['lcaron'] = 344;
  15305. t['Kcommaaccent'] = 722;
  15306. t['Lacute'] = 611;
  15307. t['trademark'] = 980;
  15308. t['edotaccent'] = 444;
  15309. t['Igrave'] = 333;
  15310. t['Imacron'] = 333;
  15311. t['Lcaron'] = 611;
  15312. t['onehalf'] = 750;
  15313. t['lessequal'] = 549;
  15314. t['ocircumflex'] = 500;
  15315. t['ntilde'] = 500;
  15316. t['Uhungarumlaut'] = 722;
  15317. t['Eacute'] = 611;
  15318. t['emacron'] = 444;
  15319. t['gbreve'] = 500;
  15320. t['onequarter'] = 750;
  15321. t['Scaron'] = 556;
  15322. t['Scommaaccent'] = 556;
  15323. t['Ohungarumlaut'] = 722;
  15324. t['degree'] = 400;
  15325. t['ograve'] = 500;
  15326. t['Ccaron'] = 667;
  15327. t['ugrave'] = 500;
  15328. t['radical'] = 453;
  15329. t['Dcaron'] = 722;
  15330. t['rcommaaccent'] = 333;
  15331. t['Ntilde'] = 722;
  15332. t['otilde'] = 500;
  15333. t['Rcommaaccent'] = 667;
  15334. t['Lcommaaccent'] = 611;
  15335. t['Atilde'] = 722;
  15336. t['Aogonek'] = 722;
  15337. t['Aring'] = 722;
  15338. t['Otilde'] = 722;
  15339. t['zdotaccent'] = 444;
  15340. t['Ecaron'] = 611;
  15341. t['Iogonek'] = 333;
  15342. t['kcommaaccent'] = 500;
  15343. t['minus'] = 564;
  15344. t['Icircumflex'] = 333;
  15345. t['ncaron'] = 500;
  15346. t['tcommaaccent'] = 278;
  15347. t['logicalnot'] = 564;
  15348. t['odieresis'] = 500;
  15349. t['udieresis'] = 500;
  15350. t['notequal'] = 549;
  15351. t['gcommaaccent'] = 500;
  15352. t['eth'] = 500;
  15353. t['zcaron'] = 444;
  15354. t['ncommaaccent'] = 500;
  15355. t['onesuperior'] = 300;
  15356. t['imacron'] = 278;
  15357. t['Euro'] = 500;
  15358. });
  15359. t['Times-Bold'] = getLookupTableFactory(function (t) {
  15360. t['space'] = 250;
  15361. t['exclam'] = 333;
  15362. t['quotedbl'] = 555;
  15363. t['numbersign'] = 500;
  15364. t['dollar'] = 500;
  15365. t['percent'] = 1000;
  15366. t['ampersand'] = 833;
  15367. t['quoteright'] = 333;
  15368. t['parenleft'] = 333;
  15369. t['parenright'] = 333;
  15370. t['asterisk'] = 500;
  15371. t['plus'] = 570;
  15372. t['comma'] = 250;
  15373. t['hyphen'] = 333;
  15374. t['period'] = 250;
  15375. t['slash'] = 278;
  15376. t['zero'] = 500;
  15377. t['one'] = 500;
  15378. t['two'] = 500;
  15379. t['three'] = 500;
  15380. t['four'] = 500;
  15381. t['five'] = 500;
  15382. t['six'] = 500;
  15383. t['seven'] = 500;
  15384. t['eight'] = 500;
  15385. t['nine'] = 500;
  15386. t['colon'] = 333;
  15387. t['semicolon'] = 333;
  15388. t['less'] = 570;
  15389. t['equal'] = 570;
  15390. t['greater'] = 570;
  15391. t['question'] = 500;
  15392. t['at'] = 930;
  15393. t['A'] = 722;
  15394. t['B'] = 667;
  15395. t['C'] = 722;
  15396. t['D'] = 722;
  15397. t['E'] = 667;
  15398. t['F'] = 611;
  15399. t['G'] = 778;
  15400. t['H'] = 778;
  15401. t['I'] = 389;
  15402. t['J'] = 500;
  15403. t['K'] = 778;
  15404. t['L'] = 667;
  15405. t['M'] = 944;
  15406. t['N'] = 722;
  15407. t['O'] = 778;
  15408. t['P'] = 611;
  15409. t['Q'] = 778;
  15410. t['R'] = 722;
  15411. t['S'] = 556;
  15412. t['T'] = 667;
  15413. t['U'] = 722;
  15414. t['V'] = 722;
  15415. t['W'] = 1000;
  15416. t['X'] = 722;
  15417. t['Y'] = 722;
  15418. t['Z'] = 667;
  15419. t['bracketleft'] = 333;
  15420. t['backslash'] = 278;
  15421. t['bracketright'] = 333;
  15422. t['asciicircum'] = 581;
  15423. t['underscore'] = 500;
  15424. t['quoteleft'] = 333;
  15425. t['a'] = 500;
  15426. t['b'] = 556;
  15427. t['c'] = 444;
  15428. t['d'] = 556;
  15429. t['e'] = 444;
  15430. t['f'] = 333;
  15431. t['g'] = 500;
  15432. t['h'] = 556;
  15433. t['i'] = 278;
  15434. t['j'] = 333;
  15435. t['k'] = 556;
  15436. t['l'] = 278;
  15437. t['m'] = 833;
  15438. t['n'] = 556;
  15439. t['o'] = 500;
  15440. t['p'] = 556;
  15441. t['q'] = 556;
  15442. t['r'] = 444;
  15443. t['s'] = 389;
  15444. t['t'] = 333;
  15445. t['u'] = 556;
  15446. t['v'] = 500;
  15447. t['w'] = 722;
  15448. t['x'] = 500;
  15449. t['y'] = 500;
  15450. t['z'] = 444;
  15451. t['braceleft'] = 394;
  15452. t['bar'] = 220;
  15453. t['braceright'] = 394;
  15454. t['asciitilde'] = 520;
  15455. t['exclamdown'] = 333;
  15456. t['cent'] = 500;
  15457. t['sterling'] = 500;
  15458. t['fraction'] = 167;
  15459. t['yen'] = 500;
  15460. t['florin'] = 500;
  15461. t['section'] = 500;
  15462. t['currency'] = 500;
  15463. t['quotesingle'] = 278;
  15464. t['quotedblleft'] = 500;
  15465. t['guillemotleft'] = 500;
  15466. t['guilsinglleft'] = 333;
  15467. t['guilsinglright'] = 333;
  15468. t['fi'] = 556;
  15469. t['fl'] = 556;
  15470. t['endash'] = 500;
  15471. t['dagger'] = 500;
  15472. t['daggerdbl'] = 500;
  15473. t['periodcentered'] = 250;
  15474. t['paragraph'] = 540;
  15475. t['bullet'] = 350;
  15476. t['quotesinglbase'] = 333;
  15477. t['quotedblbase'] = 500;
  15478. t['quotedblright'] = 500;
  15479. t['guillemotright'] = 500;
  15480. t['ellipsis'] = 1000;
  15481. t['perthousand'] = 1000;
  15482. t['questiondown'] = 500;
  15483. t['grave'] = 333;
  15484. t['acute'] = 333;
  15485. t['circumflex'] = 333;
  15486. t['tilde'] = 333;
  15487. t['macron'] = 333;
  15488. t['breve'] = 333;
  15489. t['dotaccent'] = 333;
  15490. t['dieresis'] = 333;
  15491. t['ring'] = 333;
  15492. t['cedilla'] = 333;
  15493. t['hungarumlaut'] = 333;
  15494. t['ogonek'] = 333;
  15495. t['caron'] = 333;
  15496. t['emdash'] = 1000;
  15497. t['AE'] = 1000;
  15498. t['ordfeminine'] = 300;
  15499. t['Lslash'] = 667;
  15500. t['Oslash'] = 778;
  15501. t['OE'] = 1000;
  15502. t['ordmasculine'] = 330;
  15503. t['ae'] = 722;
  15504. t['dotlessi'] = 278;
  15505. t['lslash'] = 278;
  15506. t['oslash'] = 500;
  15507. t['oe'] = 722;
  15508. t['germandbls'] = 556;
  15509. t['Idieresis'] = 389;
  15510. t['eacute'] = 444;
  15511. t['abreve'] = 500;
  15512. t['uhungarumlaut'] = 556;
  15513. t['ecaron'] = 444;
  15514. t['Ydieresis'] = 722;
  15515. t['divide'] = 570;
  15516. t['Yacute'] = 722;
  15517. t['Acircumflex'] = 722;
  15518. t['aacute'] = 500;
  15519. t['Ucircumflex'] = 722;
  15520. t['yacute'] = 500;
  15521. t['scommaaccent'] = 389;
  15522. t['ecircumflex'] = 444;
  15523. t['Uring'] = 722;
  15524. t['Udieresis'] = 722;
  15525. t['aogonek'] = 500;
  15526. t['Uacute'] = 722;
  15527. t['uogonek'] = 556;
  15528. t['Edieresis'] = 667;
  15529. t['Dcroat'] = 722;
  15530. t['commaaccent'] = 250;
  15531. t['copyright'] = 747;
  15532. t['Emacron'] = 667;
  15533. t['ccaron'] = 444;
  15534. t['aring'] = 500;
  15535. t['Ncommaaccent'] = 722;
  15536. t['lacute'] = 278;
  15537. t['agrave'] = 500;
  15538. t['Tcommaaccent'] = 667;
  15539. t['Cacute'] = 722;
  15540. t['atilde'] = 500;
  15541. t['Edotaccent'] = 667;
  15542. t['scaron'] = 389;
  15543. t['scedilla'] = 389;
  15544. t['iacute'] = 278;
  15545. t['lozenge'] = 494;
  15546. t['Rcaron'] = 722;
  15547. t['Gcommaaccent'] = 778;
  15548. t['ucircumflex'] = 556;
  15549. t['acircumflex'] = 500;
  15550. t['Amacron'] = 722;
  15551. t['rcaron'] = 444;
  15552. t['ccedilla'] = 444;
  15553. t['Zdotaccent'] = 667;
  15554. t['Thorn'] = 611;
  15555. t['Omacron'] = 778;
  15556. t['Racute'] = 722;
  15557. t['Sacute'] = 556;
  15558. t['dcaron'] = 672;
  15559. t['Umacron'] = 722;
  15560. t['uring'] = 556;
  15561. t['threesuperior'] = 300;
  15562. t['Ograve'] = 778;
  15563. t['Agrave'] = 722;
  15564. t['Abreve'] = 722;
  15565. t['multiply'] = 570;
  15566. t['uacute'] = 556;
  15567. t['Tcaron'] = 667;
  15568. t['partialdiff'] = 494;
  15569. t['ydieresis'] = 500;
  15570. t['Nacute'] = 722;
  15571. t['icircumflex'] = 278;
  15572. t['Ecircumflex'] = 667;
  15573. t['adieresis'] = 500;
  15574. t['edieresis'] = 444;
  15575. t['cacute'] = 444;
  15576. t['nacute'] = 556;
  15577. t['umacron'] = 556;
  15578. t['Ncaron'] = 722;
  15579. t['Iacute'] = 389;
  15580. t['plusminus'] = 570;
  15581. t['brokenbar'] = 220;
  15582. t['registered'] = 747;
  15583. t['Gbreve'] = 778;
  15584. t['Idotaccent'] = 389;
  15585. t['summation'] = 600;
  15586. t['Egrave'] = 667;
  15587. t['racute'] = 444;
  15588. t['omacron'] = 500;
  15589. t['Zacute'] = 667;
  15590. t['Zcaron'] = 667;
  15591. t['greaterequal'] = 549;
  15592. t['Eth'] = 722;
  15593. t['Ccedilla'] = 722;
  15594. t['lcommaaccent'] = 278;
  15595. t['tcaron'] = 416;
  15596. t['eogonek'] = 444;
  15597. t['Uogonek'] = 722;
  15598. t['Aacute'] = 722;
  15599. t['Adieresis'] = 722;
  15600. t['egrave'] = 444;
  15601. t['zacute'] = 444;
  15602. t['iogonek'] = 278;
  15603. t['Oacute'] = 778;
  15604. t['oacute'] = 500;
  15605. t['amacron'] = 500;
  15606. t['sacute'] = 389;
  15607. t['idieresis'] = 278;
  15608. t['Ocircumflex'] = 778;
  15609. t['Ugrave'] = 722;
  15610. t['Delta'] = 612;
  15611. t['thorn'] = 556;
  15612. t['twosuperior'] = 300;
  15613. t['Odieresis'] = 778;
  15614. t['mu'] = 556;
  15615. t['igrave'] = 278;
  15616. t['ohungarumlaut'] = 500;
  15617. t['Eogonek'] = 667;
  15618. t['dcroat'] = 556;
  15619. t['threequarters'] = 750;
  15620. t['Scedilla'] = 556;
  15621. t['lcaron'] = 394;
  15622. t['Kcommaaccent'] = 778;
  15623. t['Lacute'] = 667;
  15624. t['trademark'] = 1000;
  15625. t['edotaccent'] = 444;
  15626. t['Igrave'] = 389;
  15627. t['Imacron'] = 389;
  15628. t['Lcaron'] = 667;
  15629. t['onehalf'] = 750;
  15630. t['lessequal'] = 549;
  15631. t['ocircumflex'] = 500;
  15632. t['ntilde'] = 556;
  15633. t['Uhungarumlaut'] = 722;
  15634. t['Eacute'] = 667;
  15635. t['emacron'] = 444;
  15636. t['gbreve'] = 500;
  15637. t['onequarter'] = 750;
  15638. t['Scaron'] = 556;
  15639. t['Scommaaccent'] = 556;
  15640. t['Ohungarumlaut'] = 778;
  15641. t['degree'] = 400;
  15642. t['ograve'] = 500;
  15643. t['Ccaron'] = 722;
  15644. t['ugrave'] = 556;
  15645. t['radical'] = 549;
  15646. t['Dcaron'] = 722;
  15647. t['rcommaaccent'] = 444;
  15648. t['Ntilde'] = 722;
  15649. t['otilde'] = 500;
  15650. t['Rcommaaccent'] = 722;
  15651. t['Lcommaaccent'] = 667;
  15652. t['Atilde'] = 722;
  15653. t['Aogonek'] = 722;
  15654. t['Aring'] = 722;
  15655. t['Otilde'] = 778;
  15656. t['zdotaccent'] = 444;
  15657. t['Ecaron'] = 667;
  15658. t['Iogonek'] = 389;
  15659. t['kcommaaccent'] = 556;
  15660. t['minus'] = 570;
  15661. t['Icircumflex'] = 389;
  15662. t['ncaron'] = 556;
  15663. t['tcommaaccent'] = 333;
  15664. t['logicalnot'] = 570;
  15665. t['odieresis'] = 500;
  15666. t['udieresis'] = 556;
  15667. t['notequal'] = 549;
  15668. t['gcommaaccent'] = 500;
  15669. t['eth'] = 500;
  15670. t['zcaron'] = 444;
  15671. t['ncommaaccent'] = 556;
  15672. t['onesuperior'] = 300;
  15673. t['imacron'] = 278;
  15674. t['Euro'] = 500;
  15675. });
  15676. t['Times-BoldItalic'] = getLookupTableFactory(function (t) {
  15677. t['space'] = 250;
  15678. t['exclam'] = 389;
  15679. t['quotedbl'] = 555;
  15680. t['numbersign'] = 500;
  15681. t['dollar'] = 500;
  15682. t['percent'] = 833;
  15683. t['ampersand'] = 778;
  15684. t['quoteright'] = 333;
  15685. t['parenleft'] = 333;
  15686. t['parenright'] = 333;
  15687. t['asterisk'] = 500;
  15688. t['plus'] = 570;
  15689. t['comma'] = 250;
  15690. t['hyphen'] = 333;
  15691. t['period'] = 250;
  15692. t['slash'] = 278;
  15693. t['zero'] = 500;
  15694. t['one'] = 500;
  15695. t['two'] = 500;
  15696. t['three'] = 500;
  15697. t['four'] = 500;
  15698. t['five'] = 500;
  15699. t['six'] = 500;
  15700. t['seven'] = 500;
  15701. t['eight'] = 500;
  15702. t['nine'] = 500;
  15703. t['colon'] = 333;
  15704. t['semicolon'] = 333;
  15705. t['less'] = 570;
  15706. t['equal'] = 570;
  15707. t['greater'] = 570;
  15708. t['question'] = 500;
  15709. t['at'] = 832;
  15710. t['A'] = 667;
  15711. t['B'] = 667;
  15712. t['C'] = 667;
  15713. t['D'] = 722;
  15714. t['E'] = 667;
  15715. t['F'] = 667;
  15716. t['G'] = 722;
  15717. t['H'] = 778;
  15718. t['I'] = 389;
  15719. t['J'] = 500;
  15720. t['K'] = 667;
  15721. t['L'] = 611;
  15722. t['M'] = 889;
  15723. t['N'] = 722;
  15724. t['O'] = 722;
  15725. t['P'] = 611;
  15726. t['Q'] = 722;
  15727. t['R'] = 667;
  15728. t['S'] = 556;
  15729. t['T'] = 611;
  15730. t['U'] = 722;
  15731. t['V'] = 667;
  15732. t['W'] = 889;
  15733. t['X'] = 667;
  15734. t['Y'] = 611;
  15735. t['Z'] = 611;
  15736. t['bracketleft'] = 333;
  15737. t['backslash'] = 278;
  15738. t['bracketright'] = 333;
  15739. t['asciicircum'] = 570;
  15740. t['underscore'] = 500;
  15741. t['quoteleft'] = 333;
  15742. t['a'] = 500;
  15743. t['b'] = 500;
  15744. t['c'] = 444;
  15745. t['d'] = 500;
  15746. t['e'] = 444;
  15747. t['f'] = 333;
  15748. t['g'] = 500;
  15749. t['h'] = 556;
  15750. t['i'] = 278;
  15751. t['j'] = 278;
  15752. t['k'] = 500;
  15753. t['l'] = 278;
  15754. t['m'] = 778;
  15755. t['n'] = 556;
  15756. t['o'] = 500;
  15757. t['p'] = 500;
  15758. t['q'] = 500;
  15759. t['r'] = 389;
  15760. t['s'] = 389;
  15761. t['t'] = 278;
  15762. t['u'] = 556;
  15763. t['v'] = 444;
  15764. t['w'] = 667;
  15765. t['x'] = 500;
  15766. t['y'] = 444;
  15767. t['z'] = 389;
  15768. t['braceleft'] = 348;
  15769. t['bar'] = 220;
  15770. t['braceright'] = 348;
  15771. t['asciitilde'] = 570;
  15772. t['exclamdown'] = 389;
  15773. t['cent'] = 500;
  15774. t['sterling'] = 500;
  15775. t['fraction'] = 167;
  15776. t['yen'] = 500;
  15777. t['florin'] = 500;
  15778. t['section'] = 500;
  15779. t['currency'] = 500;
  15780. t['quotesingle'] = 278;
  15781. t['quotedblleft'] = 500;
  15782. t['guillemotleft'] = 500;
  15783. t['guilsinglleft'] = 333;
  15784. t['guilsinglright'] = 333;
  15785. t['fi'] = 556;
  15786. t['fl'] = 556;
  15787. t['endash'] = 500;
  15788. t['dagger'] = 500;
  15789. t['daggerdbl'] = 500;
  15790. t['periodcentered'] = 250;
  15791. t['paragraph'] = 500;
  15792. t['bullet'] = 350;
  15793. t['quotesinglbase'] = 333;
  15794. t['quotedblbase'] = 500;
  15795. t['quotedblright'] = 500;
  15796. t['guillemotright'] = 500;
  15797. t['ellipsis'] = 1000;
  15798. t['perthousand'] = 1000;
  15799. t['questiondown'] = 500;
  15800. t['grave'] = 333;
  15801. t['acute'] = 333;
  15802. t['circumflex'] = 333;
  15803. t['tilde'] = 333;
  15804. t['macron'] = 333;
  15805. t['breve'] = 333;
  15806. t['dotaccent'] = 333;
  15807. t['dieresis'] = 333;
  15808. t['ring'] = 333;
  15809. t['cedilla'] = 333;
  15810. t['hungarumlaut'] = 333;
  15811. t['ogonek'] = 333;
  15812. t['caron'] = 333;
  15813. t['emdash'] = 1000;
  15814. t['AE'] = 944;
  15815. t['ordfeminine'] = 266;
  15816. t['Lslash'] = 611;
  15817. t['Oslash'] = 722;
  15818. t['OE'] = 944;
  15819. t['ordmasculine'] = 300;
  15820. t['ae'] = 722;
  15821. t['dotlessi'] = 278;
  15822. t['lslash'] = 278;
  15823. t['oslash'] = 500;
  15824. t['oe'] = 722;
  15825. t['germandbls'] = 500;
  15826. t['Idieresis'] = 389;
  15827. t['eacute'] = 444;
  15828. t['abreve'] = 500;
  15829. t['uhungarumlaut'] = 556;
  15830. t['ecaron'] = 444;
  15831. t['Ydieresis'] = 611;
  15832. t['divide'] = 570;
  15833. t['Yacute'] = 611;
  15834. t['Acircumflex'] = 667;
  15835. t['aacute'] = 500;
  15836. t['Ucircumflex'] = 722;
  15837. t['yacute'] = 444;
  15838. t['scommaaccent'] = 389;
  15839. t['ecircumflex'] = 444;
  15840. t['Uring'] = 722;
  15841. t['Udieresis'] = 722;
  15842. t['aogonek'] = 500;
  15843. t['Uacute'] = 722;
  15844. t['uogonek'] = 556;
  15845. t['Edieresis'] = 667;
  15846. t['Dcroat'] = 722;
  15847. t['commaaccent'] = 250;
  15848. t['copyright'] = 747;
  15849. t['Emacron'] = 667;
  15850. t['ccaron'] = 444;
  15851. t['aring'] = 500;
  15852. t['Ncommaaccent'] = 722;
  15853. t['lacute'] = 278;
  15854. t['agrave'] = 500;
  15855. t['Tcommaaccent'] = 611;
  15856. t['Cacute'] = 667;
  15857. t['atilde'] = 500;
  15858. t['Edotaccent'] = 667;
  15859. t['scaron'] = 389;
  15860. t['scedilla'] = 389;
  15861. t['iacute'] = 278;
  15862. t['lozenge'] = 494;
  15863. t['Rcaron'] = 667;
  15864. t['Gcommaaccent'] = 722;
  15865. t['ucircumflex'] = 556;
  15866. t['acircumflex'] = 500;
  15867. t['Amacron'] = 667;
  15868. t['rcaron'] = 389;
  15869. t['ccedilla'] = 444;
  15870. t['Zdotaccent'] = 611;
  15871. t['Thorn'] = 611;
  15872. t['Omacron'] = 722;
  15873. t['Racute'] = 667;
  15874. t['Sacute'] = 556;
  15875. t['dcaron'] = 608;
  15876. t['Umacron'] = 722;
  15877. t['uring'] = 556;
  15878. t['threesuperior'] = 300;
  15879. t['Ograve'] = 722;
  15880. t['Agrave'] = 667;
  15881. t['Abreve'] = 667;
  15882. t['multiply'] = 570;
  15883. t['uacute'] = 556;
  15884. t['Tcaron'] = 611;
  15885. t['partialdiff'] = 494;
  15886. t['ydieresis'] = 444;
  15887. t['Nacute'] = 722;
  15888. t['icircumflex'] = 278;
  15889. t['Ecircumflex'] = 667;
  15890. t['adieresis'] = 500;
  15891. t['edieresis'] = 444;
  15892. t['cacute'] = 444;
  15893. t['nacute'] = 556;
  15894. t['umacron'] = 556;
  15895. t['Ncaron'] = 722;
  15896. t['Iacute'] = 389;
  15897. t['plusminus'] = 570;
  15898. t['brokenbar'] = 220;
  15899. t['registered'] = 747;
  15900. t['Gbreve'] = 722;
  15901. t['Idotaccent'] = 389;
  15902. t['summation'] = 600;
  15903. t['Egrave'] = 667;
  15904. t['racute'] = 389;
  15905. t['omacron'] = 500;
  15906. t['Zacute'] = 611;
  15907. t['Zcaron'] = 611;
  15908. t['greaterequal'] = 549;
  15909. t['Eth'] = 722;
  15910. t['Ccedilla'] = 667;
  15911. t['lcommaaccent'] = 278;
  15912. t['tcaron'] = 366;
  15913. t['eogonek'] = 444;
  15914. t['Uogonek'] = 722;
  15915. t['Aacute'] = 667;
  15916. t['Adieresis'] = 667;
  15917. t['egrave'] = 444;
  15918. t['zacute'] = 389;
  15919. t['iogonek'] = 278;
  15920. t['Oacute'] = 722;
  15921. t['oacute'] = 500;
  15922. t['amacron'] = 500;
  15923. t['sacute'] = 389;
  15924. t['idieresis'] = 278;
  15925. t['Ocircumflex'] = 722;
  15926. t['Ugrave'] = 722;
  15927. t['Delta'] = 612;
  15928. t['thorn'] = 500;
  15929. t['twosuperior'] = 300;
  15930. t['Odieresis'] = 722;
  15931. t['mu'] = 576;
  15932. t['igrave'] = 278;
  15933. t['ohungarumlaut'] = 500;
  15934. t['Eogonek'] = 667;
  15935. t['dcroat'] = 500;
  15936. t['threequarters'] = 750;
  15937. t['Scedilla'] = 556;
  15938. t['lcaron'] = 382;
  15939. t['Kcommaaccent'] = 667;
  15940. t['Lacute'] = 611;
  15941. t['trademark'] = 1000;
  15942. t['edotaccent'] = 444;
  15943. t['Igrave'] = 389;
  15944. t['Imacron'] = 389;
  15945. t['Lcaron'] = 611;
  15946. t['onehalf'] = 750;
  15947. t['lessequal'] = 549;
  15948. t['ocircumflex'] = 500;
  15949. t['ntilde'] = 556;
  15950. t['Uhungarumlaut'] = 722;
  15951. t['Eacute'] = 667;
  15952. t['emacron'] = 444;
  15953. t['gbreve'] = 500;
  15954. t['onequarter'] = 750;
  15955. t['Scaron'] = 556;
  15956. t['Scommaaccent'] = 556;
  15957. t['Ohungarumlaut'] = 722;
  15958. t['degree'] = 400;
  15959. t['ograve'] = 500;
  15960. t['Ccaron'] = 667;
  15961. t['ugrave'] = 556;
  15962. t['radical'] = 549;
  15963. t['Dcaron'] = 722;
  15964. t['rcommaaccent'] = 389;
  15965. t['Ntilde'] = 722;
  15966. t['otilde'] = 500;
  15967. t['Rcommaaccent'] = 667;
  15968. t['Lcommaaccent'] = 611;
  15969. t['Atilde'] = 667;
  15970. t['Aogonek'] = 667;
  15971. t['Aring'] = 667;
  15972. t['Otilde'] = 722;
  15973. t['zdotaccent'] = 389;
  15974. t['Ecaron'] = 667;
  15975. t['Iogonek'] = 389;
  15976. t['kcommaaccent'] = 500;
  15977. t['minus'] = 606;
  15978. t['Icircumflex'] = 389;
  15979. t['ncaron'] = 556;
  15980. t['tcommaaccent'] = 278;
  15981. t['logicalnot'] = 606;
  15982. t['odieresis'] = 500;
  15983. t['udieresis'] = 556;
  15984. t['notequal'] = 549;
  15985. t['gcommaaccent'] = 500;
  15986. t['eth'] = 500;
  15987. t['zcaron'] = 389;
  15988. t['ncommaaccent'] = 556;
  15989. t['onesuperior'] = 300;
  15990. t['imacron'] = 278;
  15991. t['Euro'] = 500;
  15992. });
  15993. t['Times-Italic'] = getLookupTableFactory(function (t) {
  15994. t['space'] = 250;
  15995. t['exclam'] = 333;
  15996. t['quotedbl'] = 420;
  15997. t['numbersign'] = 500;
  15998. t['dollar'] = 500;
  15999. t['percent'] = 833;
  16000. t['ampersand'] = 778;
  16001. t['quoteright'] = 333;
  16002. t['parenleft'] = 333;
  16003. t['parenright'] = 333;
  16004. t['asterisk'] = 500;
  16005. t['plus'] = 675;
  16006. t['comma'] = 250;
  16007. t['hyphen'] = 333;
  16008. t['period'] = 250;
  16009. t['slash'] = 278;
  16010. t['zero'] = 500;
  16011. t['one'] = 500;
  16012. t['two'] = 500;
  16013. t['three'] = 500;
  16014. t['four'] = 500;
  16015. t['five'] = 500;
  16016. t['six'] = 500;
  16017. t['seven'] = 500;
  16018. t['eight'] = 500;
  16019. t['nine'] = 500;
  16020. t['colon'] = 333;
  16021. t['semicolon'] = 333;
  16022. t['less'] = 675;
  16023. t['equal'] = 675;
  16024. t['greater'] = 675;
  16025. t['question'] = 500;
  16026. t['at'] = 920;
  16027. t['A'] = 611;
  16028. t['B'] = 611;
  16029. t['C'] = 667;
  16030. t['D'] = 722;
  16031. t['E'] = 611;
  16032. t['F'] = 611;
  16033. t['G'] = 722;
  16034. t['H'] = 722;
  16035. t['I'] = 333;
  16036. t['J'] = 444;
  16037. t['K'] = 667;
  16038. t['L'] = 556;
  16039. t['M'] = 833;
  16040. t['N'] = 667;
  16041. t['O'] = 722;
  16042. t['P'] = 611;
  16043. t['Q'] = 722;
  16044. t['R'] = 611;
  16045. t['S'] = 500;
  16046. t['T'] = 556;
  16047. t['U'] = 722;
  16048. t['V'] = 611;
  16049. t['W'] = 833;
  16050. t['X'] = 611;
  16051. t['Y'] = 556;
  16052. t['Z'] = 556;
  16053. t['bracketleft'] = 389;
  16054. t['backslash'] = 278;
  16055. t['bracketright'] = 389;
  16056. t['asciicircum'] = 422;
  16057. t['underscore'] = 500;
  16058. t['quoteleft'] = 333;
  16059. t['a'] = 500;
  16060. t['b'] = 500;
  16061. t['c'] = 444;
  16062. t['d'] = 500;
  16063. t['e'] = 444;
  16064. t['f'] = 278;
  16065. t['g'] = 500;
  16066. t['h'] = 500;
  16067. t['i'] = 278;
  16068. t['j'] = 278;
  16069. t['k'] = 444;
  16070. t['l'] = 278;
  16071. t['m'] = 722;
  16072. t['n'] = 500;
  16073. t['o'] = 500;
  16074. t['p'] = 500;
  16075. t['q'] = 500;
  16076. t['r'] = 389;
  16077. t['s'] = 389;
  16078. t['t'] = 278;
  16079. t['u'] = 500;
  16080. t['v'] = 444;
  16081. t['w'] = 667;
  16082. t['x'] = 444;
  16083. t['y'] = 444;
  16084. t['z'] = 389;
  16085. t['braceleft'] = 400;
  16086. t['bar'] = 275;
  16087. t['braceright'] = 400;
  16088. t['asciitilde'] = 541;
  16089. t['exclamdown'] = 389;
  16090. t['cent'] = 500;
  16091. t['sterling'] = 500;
  16092. t['fraction'] = 167;
  16093. t['yen'] = 500;
  16094. t['florin'] = 500;
  16095. t['section'] = 500;
  16096. t['currency'] = 500;
  16097. t['quotesingle'] = 214;
  16098. t['quotedblleft'] = 556;
  16099. t['guillemotleft'] = 500;
  16100. t['guilsinglleft'] = 333;
  16101. t['guilsinglright'] = 333;
  16102. t['fi'] = 500;
  16103. t['fl'] = 500;
  16104. t['endash'] = 500;
  16105. t['dagger'] = 500;
  16106. t['daggerdbl'] = 500;
  16107. t['periodcentered'] = 250;
  16108. t['paragraph'] = 523;
  16109. t['bullet'] = 350;
  16110. t['quotesinglbase'] = 333;
  16111. t['quotedblbase'] = 556;
  16112. t['quotedblright'] = 556;
  16113. t['guillemotright'] = 500;
  16114. t['ellipsis'] = 889;
  16115. t['perthousand'] = 1000;
  16116. t['questiondown'] = 500;
  16117. t['grave'] = 333;
  16118. t['acute'] = 333;
  16119. t['circumflex'] = 333;
  16120. t['tilde'] = 333;
  16121. t['macron'] = 333;
  16122. t['breve'] = 333;
  16123. t['dotaccent'] = 333;
  16124. t['dieresis'] = 333;
  16125. t['ring'] = 333;
  16126. t['cedilla'] = 333;
  16127. t['hungarumlaut'] = 333;
  16128. t['ogonek'] = 333;
  16129. t['caron'] = 333;
  16130. t['emdash'] = 889;
  16131. t['AE'] = 889;
  16132. t['ordfeminine'] = 276;
  16133. t['Lslash'] = 556;
  16134. t['Oslash'] = 722;
  16135. t['OE'] = 944;
  16136. t['ordmasculine'] = 310;
  16137. t['ae'] = 667;
  16138. t['dotlessi'] = 278;
  16139. t['lslash'] = 278;
  16140. t['oslash'] = 500;
  16141. t['oe'] = 667;
  16142. t['germandbls'] = 500;
  16143. t['Idieresis'] = 333;
  16144. t['eacute'] = 444;
  16145. t['abreve'] = 500;
  16146. t['uhungarumlaut'] = 500;
  16147. t['ecaron'] = 444;
  16148. t['Ydieresis'] = 556;
  16149. t['divide'] = 675;
  16150. t['Yacute'] = 556;
  16151. t['Acircumflex'] = 611;
  16152. t['aacute'] = 500;
  16153. t['Ucircumflex'] = 722;
  16154. t['yacute'] = 444;
  16155. t['scommaaccent'] = 389;
  16156. t['ecircumflex'] = 444;
  16157. t['Uring'] = 722;
  16158. t['Udieresis'] = 722;
  16159. t['aogonek'] = 500;
  16160. t['Uacute'] = 722;
  16161. t['uogonek'] = 500;
  16162. t['Edieresis'] = 611;
  16163. t['Dcroat'] = 722;
  16164. t['commaaccent'] = 250;
  16165. t['copyright'] = 760;
  16166. t['Emacron'] = 611;
  16167. t['ccaron'] = 444;
  16168. t['aring'] = 500;
  16169. t['Ncommaaccent'] = 667;
  16170. t['lacute'] = 278;
  16171. t['agrave'] = 500;
  16172. t['Tcommaaccent'] = 556;
  16173. t['Cacute'] = 667;
  16174. t['atilde'] = 500;
  16175. t['Edotaccent'] = 611;
  16176. t['scaron'] = 389;
  16177. t['scedilla'] = 389;
  16178. t['iacute'] = 278;
  16179. t['lozenge'] = 471;
  16180. t['Rcaron'] = 611;
  16181. t['Gcommaaccent'] = 722;
  16182. t['ucircumflex'] = 500;
  16183. t['acircumflex'] = 500;
  16184. t['Amacron'] = 611;
  16185. t['rcaron'] = 389;
  16186. t['ccedilla'] = 444;
  16187. t['Zdotaccent'] = 556;
  16188. t['Thorn'] = 611;
  16189. t['Omacron'] = 722;
  16190. t['Racute'] = 611;
  16191. t['Sacute'] = 500;
  16192. t['dcaron'] = 544;
  16193. t['Umacron'] = 722;
  16194. t['uring'] = 500;
  16195. t['threesuperior'] = 300;
  16196. t['Ograve'] = 722;
  16197. t['Agrave'] = 611;
  16198. t['Abreve'] = 611;
  16199. t['multiply'] = 675;
  16200. t['uacute'] = 500;
  16201. t['Tcaron'] = 556;
  16202. t['partialdiff'] = 476;
  16203. t['ydieresis'] = 444;
  16204. t['Nacute'] = 667;
  16205. t['icircumflex'] = 278;
  16206. t['Ecircumflex'] = 611;
  16207. t['adieresis'] = 500;
  16208. t['edieresis'] = 444;
  16209. t['cacute'] = 444;
  16210. t['nacute'] = 500;
  16211. t['umacron'] = 500;
  16212. t['Ncaron'] = 667;
  16213. t['Iacute'] = 333;
  16214. t['plusminus'] = 675;
  16215. t['brokenbar'] = 275;
  16216. t['registered'] = 760;
  16217. t['Gbreve'] = 722;
  16218. t['Idotaccent'] = 333;
  16219. t['summation'] = 600;
  16220. t['Egrave'] = 611;
  16221. t['racute'] = 389;
  16222. t['omacron'] = 500;
  16223. t['Zacute'] = 556;
  16224. t['Zcaron'] = 556;
  16225. t['greaterequal'] = 549;
  16226. t['Eth'] = 722;
  16227. t['Ccedilla'] = 667;
  16228. t['lcommaaccent'] = 278;
  16229. t['tcaron'] = 300;
  16230. t['eogonek'] = 444;
  16231. t['Uogonek'] = 722;
  16232. t['Aacute'] = 611;
  16233. t['Adieresis'] = 611;
  16234. t['egrave'] = 444;
  16235. t['zacute'] = 389;
  16236. t['iogonek'] = 278;
  16237. t['Oacute'] = 722;
  16238. t['oacute'] = 500;
  16239. t['amacron'] = 500;
  16240. t['sacute'] = 389;
  16241. t['idieresis'] = 278;
  16242. t['Ocircumflex'] = 722;
  16243. t['Ugrave'] = 722;
  16244. t['Delta'] = 612;
  16245. t['thorn'] = 500;
  16246. t['twosuperior'] = 300;
  16247. t['Odieresis'] = 722;
  16248. t['mu'] = 500;
  16249. t['igrave'] = 278;
  16250. t['ohungarumlaut'] = 500;
  16251. t['Eogonek'] = 611;
  16252. t['dcroat'] = 500;
  16253. t['threequarters'] = 750;
  16254. t['Scedilla'] = 500;
  16255. t['lcaron'] = 300;
  16256. t['Kcommaaccent'] = 667;
  16257. t['Lacute'] = 556;
  16258. t['trademark'] = 980;
  16259. t['edotaccent'] = 444;
  16260. t['Igrave'] = 333;
  16261. t['Imacron'] = 333;
  16262. t['Lcaron'] = 611;
  16263. t['onehalf'] = 750;
  16264. t['lessequal'] = 549;
  16265. t['ocircumflex'] = 500;
  16266. t['ntilde'] = 500;
  16267. t['Uhungarumlaut'] = 722;
  16268. t['Eacute'] = 611;
  16269. t['emacron'] = 444;
  16270. t['gbreve'] = 500;
  16271. t['onequarter'] = 750;
  16272. t['Scaron'] = 500;
  16273. t['Scommaaccent'] = 500;
  16274. t['Ohungarumlaut'] = 722;
  16275. t['degree'] = 400;
  16276. t['ograve'] = 500;
  16277. t['Ccaron'] = 667;
  16278. t['ugrave'] = 500;
  16279. t['radical'] = 453;
  16280. t['Dcaron'] = 722;
  16281. t['rcommaaccent'] = 389;
  16282. t['Ntilde'] = 667;
  16283. t['otilde'] = 500;
  16284. t['Rcommaaccent'] = 611;
  16285. t['Lcommaaccent'] = 556;
  16286. t['Atilde'] = 611;
  16287. t['Aogonek'] = 611;
  16288. t['Aring'] = 611;
  16289. t['Otilde'] = 722;
  16290. t['zdotaccent'] = 389;
  16291. t['Ecaron'] = 611;
  16292. t['Iogonek'] = 333;
  16293. t['kcommaaccent'] = 444;
  16294. t['minus'] = 675;
  16295. t['Icircumflex'] = 333;
  16296. t['ncaron'] = 500;
  16297. t['tcommaaccent'] = 278;
  16298. t['logicalnot'] = 675;
  16299. t['odieresis'] = 500;
  16300. t['udieresis'] = 500;
  16301. t['notequal'] = 549;
  16302. t['gcommaaccent'] = 500;
  16303. t['eth'] = 500;
  16304. t['zcaron'] = 389;
  16305. t['ncommaaccent'] = 500;
  16306. t['onesuperior'] = 300;
  16307. t['imacron'] = 278;
  16308. t['Euro'] = 500;
  16309. });
  16310. t['ZapfDingbats'] = getLookupTableFactory(function (t) {
  16311. t['space'] = 278;
  16312. t['a1'] = 974;
  16313. t['a2'] = 961;
  16314. t['a202'] = 974;
  16315. t['a3'] = 980;
  16316. t['a4'] = 719;
  16317. t['a5'] = 789;
  16318. t['a119'] = 790;
  16319. t['a118'] = 791;
  16320. t['a117'] = 690;
  16321. t['a11'] = 960;
  16322. t['a12'] = 939;
  16323. t['a13'] = 549;
  16324. t['a14'] = 855;
  16325. t['a15'] = 911;
  16326. t['a16'] = 933;
  16327. t['a105'] = 911;
  16328. t['a17'] = 945;
  16329. t['a18'] = 974;
  16330. t['a19'] = 755;
  16331. t['a20'] = 846;
  16332. t['a21'] = 762;
  16333. t['a22'] = 761;
  16334. t['a23'] = 571;
  16335. t['a24'] = 677;
  16336. t['a25'] = 763;
  16337. t['a26'] = 760;
  16338. t['a27'] = 759;
  16339. t['a28'] = 754;
  16340. t['a6'] = 494;
  16341. t['a7'] = 552;
  16342. t['a8'] = 537;
  16343. t['a9'] = 577;
  16344. t['a10'] = 692;
  16345. t['a29'] = 786;
  16346. t['a30'] = 788;
  16347. t['a31'] = 788;
  16348. t['a32'] = 790;
  16349. t['a33'] = 793;
  16350. t['a34'] = 794;
  16351. t['a35'] = 816;
  16352. t['a36'] = 823;
  16353. t['a37'] = 789;
  16354. t['a38'] = 841;
  16355. t['a39'] = 823;
  16356. t['a40'] = 833;
  16357. t['a41'] = 816;
  16358. t['a42'] = 831;
  16359. t['a43'] = 923;
  16360. t['a44'] = 744;
  16361. t['a45'] = 723;
  16362. t['a46'] = 749;
  16363. t['a47'] = 790;
  16364. t['a48'] = 792;
  16365. t['a49'] = 695;
  16366. t['a50'] = 776;
  16367. t['a51'] = 768;
  16368. t['a52'] = 792;
  16369. t['a53'] = 759;
  16370. t['a54'] = 707;
  16371. t['a55'] = 708;
  16372. t['a56'] = 682;
  16373. t['a57'] = 701;
  16374. t['a58'] = 826;
  16375. t['a59'] = 815;
  16376. t['a60'] = 789;
  16377. t['a61'] = 789;
  16378. t['a62'] = 707;
  16379. t['a63'] = 687;
  16380. t['a64'] = 696;
  16381. t['a65'] = 689;
  16382. t['a66'] = 786;
  16383. t['a67'] = 787;
  16384. t['a68'] = 713;
  16385. t['a69'] = 791;
  16386. t['a70'] = 785;
  16387. t['a71'] = 791;
  16388. t['a72'] = 873;
  16389. t['a73'] = 761;
  16390. t['a74'] = 762;
  16391. t['a203'] = 762;
  16392. t['a75'] = 759;
  16393. t['a204'] = 759;
  16394. t['a76'] = 892;
  16395. t['a77'] = 892;
  16396. t['a78'] = 788;
  16397. t['a79'] = 784;
  16398. t['a81'] = 438;
  16399. t['a82'] = 138;
  16400. t['a83'] = 277;
  16401. t['a84'] = 415;
  16402. t['a97'] = 392;
  16403. t['a98'] = 392;
  16404. t['a99'] = 668;
  16405. t['a100'] = 668;
  16406. t['a89'] = 390;
  16407. t['a90'] = 390;
  16408. t['a93'] = 317;
  16409. t['a94'] = 317;
  16410. t['a91'] = 276;
  16411. t['a92'] = 276;
  16412. t['a205'] = 509;
  16413. t['a85'] = 509;
  16414. t['a206'] = 410;
  16415. t['a86'] = 410;
  16416. t['a87'] = 234;
  16417. t['a88'] = 234;
  16418. t['a95'] = 334;
  16419. t['a96'] = 334;
  16420. t['a101'] = 732;
  16421. t['a102'] = 544;
  16422. t['a103'] = 544;
  16423. t['a104'] = 910;
  16424. t['a106'] = 667;
  16425. t['a107'] = 760;
  16426. t['a108'] = 760;
  16427. t['a112'] = 776;
  16428. t['a111'] = 595;
  16429. t['a110'] = 694;
  16430. t['a109'] = 626;
  16431. t['a120'] = 788;
  16432. t['a121'] = 788;
  16433. t['a122'] = 788;
  16434. t['a123'] = 788;
  16435. t['a124'] = 788;
  16436. t['a125'] = 788;
  16437. t['a126'] = 788;
  16438. t['a127'] = 788;
  16439. t['a128'] = 788;
  16440. t['a129'] = 788;
  16441. t['a130'] = 788;
  16442. t['a131'] = 788;
  16443. t['a132'] = 788;
  16444. t['a133'] = 788;
  16445. t['a134'] = 788;
  16446. t['a135'] = 788;
  16447. t['a136'] = 788;
  16448. t['a137'] = 788;
  16449. t['a138'] = 788;
  16450. t['a139'] = 788;
  16451. t['a140'] = 788;
  16452. t['a141'] = 788;
  16453. t['a142'] = 788;
  16454. t['a143'] = 788;
  16455. t['a144'] = 788;
  16456. t['a145'] = 788;
  16457. t['a146'] = 788;
  16458. t['a147'] = 788;
  16459. t['a148'] = 788;
  16460. t['a149'] = 788;
  16461. t['a150'] = 788;
  16462. t['a151'] = 788;
  16463. t['a152'] = 788;
  16464. t['a153'] = 788;
  16465. t['a154'] = 788;
  16466. t['a155'] = 788;
  16467. t['a156'] = 788;
  16468. t['a157'] = 788;
  16469. t['a158'] = 788;
  16470. t['a159'] = 788;
  16471. t['a160'] = 894;
  16472. t['a161'] = 838;
  16473. t['a163'] = 1016;
  16474. t['a164'] = 458;
  16475. t['a196'] = 748;
  16476. t['a165'] = 924;
  16477. t['a192'] = 748;
  16478. t['a166'] = 918;
  16479. t['a167'] = 927;
  16480. t['a168'] = 928;
  16481. t['a169'] = 928;
  16482. t['a170'] = 834;
  16483. t['a171'] = 873;
  16484. t['a172'] = 828;
  16485. t['a173'] = 924;
  16486. t['a162'] = 924;
  16487. t['a174'] = 917;
  16488. t['a175'] = 930;
  16489. t['a176'] = 931;
  16490. t['a177'] = 463;
  16491. t['a178'] = 883;
  16492. t['a179'] = 836;
  16493. t['a193'] = 836;
  16494. t['a180'] = 867;
  16495. t['a199'] = 867;
  16496. t['a181'] = 696;
  16497. t['a200'] = 696;
  16498. t['a182'] = 874;
  16499. t['a201'] = 874;
  16500. t['a183'] = 760;
  16501. t['a184'] = 946;
  16502. t['a197'] = 771;
  16503. t['a185'] = 865;
  16504. t['a194'] = 771;
  16505. t['a198'] = 888;
  16506. t['a186'] = 967;
  16507. t['a195'] = 888;
  16508. t['a187'] = 831;
  16509. t['a188'] = 873;
  16510. t['a189'] = 927;
  16511. t['a190'] = 970;
  16512. t['a191'] = 918;
  16513. });
  16514. });
  16515. exports.getMetrics = getMetrics;
  16516. }));
  16517. (function (root, factory) {
  16518. {
  16519. factory((root.pdfjsCoreMurmurHash3 = {}), root.pdfjsSharedUtil);
  16520. }
  16521. }(this, function (exports, sharedUtil) {
  16522. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  16523. var MurmurHash3_64 = (function MurmurHash3_64Closure (seed) {
  16524. // Workaround for missing math precison in JS.
  16525. var MASK_HIGH = 0xffff0000;
  16526. var MASK_LOW = 0xffff;
  16527. function MurmurHash3_64 (seed) {
  16528. var SEED = 0xc3d2e1f0;
  16529. this.h1 = seed ? seed & 0xffffffff : SEED;
  16530. this.h2 = seed ? seed & 0xffffffff : SEED;
  16531. }
  16532. var alwaysUseUint32ArrayView = false;
  16533. // old webkits have issues with non-aligned arrays
  16534. try {
  16535. new Uint32Array(new Uint8Array(5).buffer, 0, 1);
  16536. } catch (e) {
  16537. alwaysUseUint32ArrayView = true;
  16538. }
  16539. MurmurHash3_64.prototype = {
  16540. update: function MurmurHash3_64_update(input) {
  16541. var useUint32ArrayView = alwaysUseUint32ArrayView;
  16542. var i;
  16543. if (typeof input === 'string') {
  16544. var data = new Uint8Array(input.length * 2);
  16545. var length = 0;
  16546. for (i = 0; i < input.length; i++) {
  16547. var code = input.charCodeAt(i);
  16548. if (code <= 0xff) {
  16549. data[length++] = code;
  16550. }
  16551. else {
  16552. data[length++] = code >>> 8;
  16553. data[length++] = code & 0xff;
  16554. }
  16555. }
  16556. } else if (input instanceof Uint8Array) {
  16557. data = input;
  16558. length = data.length;
  16559. } else if (typeof input === 'object' && ('length' in input)) {
  16560. // processing regular arrays as well, e.g. for IE9
  16561. data = input;
  16562. length = data.length;
  16563. useUint32ArrayView = true;
  16564. } else {
  16565. throw new Error('Wrong data format in MurmurHash3_64_update. ' +
  16566. 'Input must be a string or array.');
  16567. }
  16568. var blockCounts = length >> 2;
  16569. var tailLength = length - blockCounts * 4;
  16570. // we don't care about endianness here
  16571. var dataUint32 = useUint32ArrayView ?
  16572. new Uint32ArrayView(data, blockCounts) :
  16573. new Uint32Array(data.buffer, 0, blockCounts);
  16574. var k1 = 0;
  16575. var k2 = 0;
  16576. var h1 = this.h1;
  16577. var h2 = this.h2;
  16578. var C1 = 0xcc9e2d51;
  16579. var C2 = 0x1b873593;
  16580. var C1_LOW = C1 & MASK_LOW;
  16581. var C2_LOW = C2 & MASK_LOW;
  16582. for (i = 0; i < blockCounts; i++) {
  16583. if (i & 1) {
  16584. k1 = dataUint32[i];
  16585. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16586. k1 = k1 << 15 | k1 >>> 17;
  16587. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16588. h1 ^= k1;
  16589. h1 = h1 << 13 | h1 >>> 19;
  16590. h1 = h1 * 5 + 0xe6546b64;
  16591. } else {
  16592. k2 = dataUint32[i];
  16593. k2 = (k2 * C1 & MASK_HIGH) | (k2 * C1_LOW & MASK_LOW);
  16594. k2 = k2 << 15 | k2 >>> 17;
  16595. k2 = (k2 * C2 & MASK_HIGH) | (k2 * C2_LOW & MASK_LOW);
  16596. h2 ^= k2;
  16597. h2 = h2 << 13 | h2 >>> 19;
  16598. h2 = h2 * 5 + 0xe6546b64;
  16599. }
  16600. }
  16601. k1 = 0;
  16602. switch (tailLength) {
  16603. case 3:
  16604. k1 ^= data[blockCounts * 4 + 2] << 16;
  16605. /* falls through */
  16606. case 2:
  16607. k1 ^= data[blockCounts * 4 + 1] << 8;
  16608. /* falls through */
  16609. case 1:
  16610. k1 ^= data[blockCounts * 4];
  16611. /* falls through */
  16612. k1 = (k1 * C1 & MASK_HIGH) | (k1 * C1_LOW & MASK_LOW);
  16613. k1 = k1 << 15 | k1 >>> 17;
  16614. k1 = (k1 * C2 & MASK_HIGH) | (k1 * C2_LOW & MASK_LOW);
  16615. if (blockCounts & 1) {
  16616. h1 ^= k1;
  16617. } else {
  16618. h2 ^= k1;
  16619. }
  16620. }
  16621. this.h1 = h1;
  16622. this.h2 = h2;
  16623. return this;
  16624. },
  16625. hexdigest: function MurmurHash3_64_hexdigest () {
  16626. var h1 = this.h1;
  16627. var h2 = this.h2;
  16628. h1 ^= h2 >>> 1;
  16629. h1 = (h1 * 0xed558ccd & MASK_HIGH) | (h1 * 0x8ccd & MASK_LOW);
  16630. h2 = (h2 * 0xff51afd7 & MASK_HIGH) |
  16631. (((h2 << 16 | h1 >>> 16) * 0xafd7ed55 & MASK_HIGH) >>> 16);
  16632. h1 ^= h2 >>> 1;
  16633. h1 = (h1 * 0x1a85ec53 & MASK_HIGH) | (h1 * 0xec53 & MASK_LOW);
  16634. h2 = (h2 * 0xc4ceb9fe & MASK_HIGH) |
  16635. (((h2 << 16 | h1 >>> 16) * 0xb9fe1a85 & MASK_HIGH) >>> 16);
  16636. h1 ^= h2 >>> 1;
  16637. for (var i = 0, arr = [h1, h2], str = ''; i < arr.length; i++) {
  16638. var hex = (arr[i] >>> 0).toString(16);
  16639. while (hex.length < 8) {
  16640. hex = '0' + hex;
  16641. }
  16642. str += hex;
  16643. }
  16644. return str;
  16645. }
  16646. };
  16647. return MurmurHash3_64;
  16648. })();
  16649. exports.MurmurHash3_64 = MurmurHash3_64;
  16650. }));
  16651. (function (root, factory) {
  16652. {
  16653. factory((root.pdfjsCorePrimitives = {}), root.pdfjsSharedUtil);
  16654. }
  16655. }(this, function (exports, sharedUtil) {
  16656. var isArray = sharedUtil.isArray;
  16657. var Name = (function NameClosure() {
  16658. function Name(name) {
  16659. this.name = name;
  16660. }
  16661. Name.prototype = {};
  16662. var nameCache = Object.create(null);
  16663. Name.get = function Name_get(name) {
  16664. var nameValue = nameCache[name];
  16665. return (nameValue ? nameValue : (nameCache[name] = new Name(name)));
  16666. };
  16667. return Name;
  16668. })();
  16669. var Cmd = (function CmdClosure() {
  16670. function Cmd(cmd) {
  16671. this.cmd = cmd;
  16672. }
  16673. Cmd.prototype = {};
  16674. var cmdCache = Object.create(null);
  16675. Cmd.get = function Cmd_get(cmd) {
  16676. var cmdValue = cmdCache[cmd];
  16677. return (cmdValue ? cmdValue : (cmdCache[cmd] = new Cmd(cmd)));
  16678. };
  16679. return Cmd;
  16680. })();
  16681. var Dict = (function DictClosure() {
  16682. var nonSerializable = function nonSerializableClosure() {
  16683. return nonSerializable; // creating closure on some variable
  16684. };
  16685. // xref is optional
  16686. function Dict(xref) {
  16687. // Map should only be used internally, use functions below to access.
  16688. this.map = Object.create(null);
  16689. this.xref = xref;
  16690. this.objId = null;
  16691. this.__nonSerializable__ = nonSerializable; // disable cloning of the Dict
  16692. }
  16693. Dict.prototype = {
  16694. assignXref: function Dict_assignXref(newXref) {
  16695. this.xref = newXref;
  16696. },
  16697. // automatically dereferences Ref objects
  16698. get: function Dict_get(key1, key2, key3) {
  16699. var value;
  16700. var xref = this.xref;
  16701. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16702. typeof key2 === 'undefined') {
  16703. return xref ? xref.fetchIfRef(value) : value;
  16704. }
  16705. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16706. typeof key3 === 'undefined') {
  16707. return xref ? xref.fetchIfRef(value) : value;
  16708. }
  16709. value = this.map[key3] || null;
  16710. return xref ? xref.fetchIfRef(value) : value;
  16711. },
  16712. // Same as get(), but returns a promise and uses fetchIfRefAsync().
  16713. getAsync: function Dict_getAsync(key1, key2, key3) {
  16714. var value;
  16715. var xref = this.xref;
  16716. if (typeof (value = this.map[key1]) !== 'undefined' || key1 in this.map ||
  16717. typeof key2 === 'undefined') {
  16718. if (xref) {
  16719. return xref.fetchIfRefAsync(value);
  16720. }
  16721. return Promise.resolve(value);
  16722. }
  16723. if (typeof (value = this.map[key2]) !== 'undefined' || key2 in this.map ||
  16724. typeof key3 === 'undefined') {
  16725. if (xref) {
  16726. return xref.fetchIfRefAsync(value);
  16727. }
  16728. return Promise.resolve(value);
  16729. }
  16730. value = this.map[key3] || null;
  16731. if (xref) {
  16732. return xref.fetchIfRefAsync(value);
  16733. }
  16734. return Promise.resolve(value);
  16735. },
  16736. // Same as get(), but dereferences all elements if the result is an Array.
  16737. getArray: function Dict_getArray(key1, key2, key3) {
  16738. var value = this.get(key1, key2, key3);
  16739. var xref = this.xref;
  16740. if (!isArray(value) || !xref) {
  16741. return value;
  16742. }
  16743. value = value.slice(); // Ensure that we don't modify the Dict data.
  16744. for (var i = 0, ii = value.length; i < ii; i++) {
  16745. if (!isRef(value[i])) {
  16746. continue;
  16747. }
  16748. value[i] = xref.fetch(value[i]);
  16749. }
  16750. return value;
  16751. },
  16752. // no dereferencing
  16753. getRaw: function Dict_getRaw(key) {
  16754. return this.map[key];
  16755. },
  16756. getKeys: function Dict_getKeys() {
  16757. return Object.keys(this.map);
  16758. },
  16759. set: function Dict_set(key, value) {
  16760. this.map[key] = value;
  16761. },
  16762. has: function Dict_has(key) {
  16763. return key in this.map;
  16764. },
  16765. forEach: function Dict_forEach(callback) {
  16766. for (var key in this.map) {
  16767. callback(key, this.get(key));
  16768. }
  16769. }
  16770. };
  16771. Dict.empty = new Dict(null);
  16772. Dict.merge = function Dict_merge(xref, dictArray) {
  16773. var mergedDict = new Dict(xref);
  16774. for (var i = 0, ii = dictArray.length; i < ii; i++) {
  16775. var dict = dictArray[i];
  16776. if (!isDict(dict)) {
  16777. continue;
  16778. }
  16779. for (var keyName in dict.map) {
  16780. if (mergedDict.map[keyName]) {
  16781. continue;
  16782. }
  16783. mergedDict.map[keyName] = dict.map[keyName];
  16784. }
  16785. }
  16786. return mergedDict;
  16787. };
  16788. return Dict;
  16789. })();
  16790. var Ref = (function RefClosure() {
  16791. function Ref(num, gen) {
  16792. this.num = num;
  16793. this.gen = gen;
  16794. }
  16795. Ref.prototype = {
  16796. toString: function Ref_toString() {
  16797. // This function is hot, so we make the string as compact as possible.
  16798. // |this.gen| is almost always zero, so we treat that case specially.
  16799. var str = this.num + 'R';
  16800. if (this.gen !== 0) {
  16801. str += this.gen;
  16802. }
  16803. return str;
  16804. }
  16805. };
  16806. return Ref;
  16807. })();
  16808. // The reference is identified by number and generation.
  16809. // This structure stores only one instance of the reference.
  16810. var RefSet = (function RefSetClosure() {
  16811. function RefSet() {
  16812. this.dict = Object.create(null);
  16813. }
  16814. RefSet.prototype = {
  16815. has: function RefSet_has(ref) {
  16816. return ref.toString() in this.dict;
  16817. },
  16818. put: function RefSet_put(ref) {
  16819. this.dict[ref.toString()] = true;
  16820. },
  16821. remove: function RefSet_remove(ref) {
  16822. delete this.dict[ref.toString()];
  16823. }
  16824. };
  16825. return RefSet;
  16826. })();
  16827. var RefSetCache = (function RefSetCacheClosure() {
  16828. function RefSetCache() {
  16829. this.dict = Object.create(null);
  16830. }
  16831. RefSetCache.prototype = {
  16832. get: function RefSetCache_get(ref) {
  16833. return this.dict[ref.toString()];
  16834. },
  16835. has: function RefSetCache_has(ref) {
  16836. return ref.toString() in this.dict;
  16837. },
  16838. put: function RefSetCache_put(ref, obj) {
  16839. this.dict[ref.toString()] = obj;
  16840. },
  16841. putAlias: function RefSetCache_putAlias(ref, aliasRef) {
  16842. this.dict[ref.toString()] = this.get(aliasRef);
  16843. },
  16844. forEach: function RefSetCache_forEach(fn, thisArg) {
  16845. for (var i in this.dict) {
  16846. fn.call(thisArg, this.dict[i]);
  16847. }
  16848. },
  16849. clear: function RefSetCache_clear() {
  16850. this.dict = Object.create(null);
  16851. }
  16852. };
  16853. return RefSetCache;
  16854. })();
  16855. function isName(v) {
  16856. return v instanceof Name;
  16857. }
  16858. function isCmd(v, cmd) {
  16859. return v instanceof Cmd && (cmd === undefined || v.cmd === cmd);
  16860. }
  16861. function isDict(v, type) {
  16862. if (!(v instanceof Dict)) {
  16863. return false;
  16864. }
  16865. if (!type) {
  16866. return true;
  16867. }
  16868. var dictType = v.get('Type');
  16869. return isName(dictType) && dictType.name === type;
  16870. }
  16871. function isRef(v) {
  16872. return v instanceof Ref;
  16873. }
  16874. function isStream(v) {
  16875. return typeof v === 'object' && v !== null && v.getBytes !== undefined;
  16876. }
  16877. exports.Cmd = Cmd;
  16878. exports.Dict = Dict;
  16879. exports.Name = Name;
  16880. exports.Ref = Ref;
  16881. exports.RefSet = RefSet;
  16882. exports.RefSetCache = RefSetCache;
  16883. exports.isCmd = isCmd;
  16884. exports.isDict = isDict;
  16885. exports.isName = isName;
  16886. exports.isRef = isRef;
  16887. exports.isStream = isStream;
  16888. }));
  16889. (function (root, factory) {
  16890. {
  16891. factory((root.pdfjsCoreStandardFonts = {}), root.pdfjsSharedUtil);
  16892. }
  16893. }(this, function (exports, sharedUtil) {
  16894. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  16895. /**
  16896. * Hold a map of decoded fonts and of the standard fourteen Type1
  16897. * fonts and their acronyms.
  16898. */
  16899. var getStdFontMap = getLookupTableFactory(function (t) {
  16900. t['ArialNarrow'] = 'Helvetica';
  16901. t['ArialNarrow-Bold'] = 'Helvetica-Bold';
  16902. t['ArialNarrow-BoldItalic'] = 'Helvetica-BoldOblique';
  16903. t['ArialNarrow-Italic'] = 'Helvetica-Oblique';
  16904. t['ArialBlack'] = 'Helvetica';
  16905. t['ArialBlack-Bold'] = 'Helvetica-Bold';
  16906. t['ArialBlack-BoldItalic'] = 'Helvetica-BoldOblique';
  16907. t['ArialBlack-Italic'] = 'Helvetica-Oblique';
  16908. t['Arial'] = 'Helvetica';
  16909. t['Arial-Bold'] = 'Helvetica-Bold';
  16910. t['Arial-BoldItalic'] = 'Helvetica-BoldOblique';
  16911. t['Arial-Italic'] = 'Helvetica-Oblique';
  16912. t['Arial-BoldItalicMT'] = 'Helvetica-BoldOblique';
  16913. t['Arial-BoldMT'] = 'Helvetica-Bold';
  16914. t['Arial-ItalicMT'] = 'Helvetica-Oblique';
  16915. t['ArialMT'] = 'Helvetica';
  16916. t['Courier-Bold'] = 'Courier-Bold';
  16917. t['Courier-BoldItalic'] = 'Courier-BoldOblique';
  16918. t['Courier-Italic'] = 'Courier-Oblique';
  16919. t['CourierNew'] = 'Courier';
  16920. t['CourierNew-Bold'] = 'Courier-Bold';
  16921. t['CourierNew-BoldItalic'] = 'Courier-BoldOblique';
  16922. t['CourierNew-Italic'] = 'Courier-Oblique';
  16923. t['CourierNewPS-BoldItalicMT'] = 'Courier-BoldOblique';
  16924. t['CourierNewPS-BoldMT'] = 'Courier-Bold';
  16925. t['CourierNewPS-ItalicMT'] = 'Courier-Oblique';
  16926. t['CourierNewPSMT'] = 'Courier';
  16927. t['Helvetica'] = 'Helvetica';
  16928. t['Helvetica-Bold'] = 'Helvetica-Bold';
  16929. t['Helvetica-BoldItalic'] = 'Helvetica-BoldOblique';
  16930. t['Helvetica-BoldOblique'] = 'Helvetica-BoldOblique';
  16931. t['Helvetica-Italic'] = 'Helvetica-Oblique';
  16932. t['Helvetica-Oblique'] = 'Helvetica-Oblique';
  16933. t['Symbol-Bold'] = 'Symbol';
  16934. t['Symbol-BoldItalic'] = 'Symbol';
  16935. t['Symbol-Italic'] = 'Symbol';
  16936. t['TimesNewRoman'] = 'Times-Roman';
  16937. t['TimesNewRoman-Bold'] = 'Times-Bold';
  16938. t['TimesNewRoman-BoldItalic'] = 'Times-BoldItalic';
  16939. t['TimesNewRoman-Italic'] = 'Times-Italic';
  16940. t['TimesNewRomanPS'] = 'Times-Roman';
  16941. t['TimesNewRomanPS-Bold'] = 'Times-Bold';
  16942. t['TimesNewRomanPS-BoldItalic'] = 'Times-BoldItalic';
  16943. t['TimesNewRomanPS-BoldItalicMT'] = 'Times-BoldItalic';
  16944. t['TimesNewRomanPS-BoldMT'] = 'Times-Bold';
  16945. t['TimesNewRomanPS-Italic'] = 'Times-Italic';
  16946. t['TimesNewRomanPS-ItalicMT'] = 'Times-Italic';
  16947. t['TimesNewRomanPSMT'] = 'Times-Roman';
  16948. t['TimesNewRomanPSMT-Bold'] = 'Times-Bold';
  16949. t['TimesNewRomanPSMT-BoldItalic'] = 'Times-BoldItalic';
  16950. t['TimesNewRomanPSMT-Italic'] = 'Times-Italic';
  16951. });
  16952. /**
  16953. * Holds the map of the non-standard fonts that might be included as
  16954. * a standard fonts without glyph data.
  16955. */
  16956. var getNonStdFontMap = getLookupTableFactory(function (t) {
  16957. t['CenturyGothic'] = 'Helvetica';
  16958. t['CenturyGothic-Bold'] = 'Helvetica-Bold';
  16959. t['CenturyGothic-BoldItalic'] = 'Helvetica-BoldOblique';
  16960. t['CenturyGothic-Italic'] = 'Helvetica-Oblique';
  16961. t['ComicSansMS'] = 'Comic Sans MS';
  16962. t['ComicSansMS-Bold'] = 'Comic Sans MS-Bold';
  16963. t['ComicSansMS-BoldItalic'] = 'Comic Sans MS-BoldItalic';
  16964. t['ComicSansMS-Italic'] = 'Comic Sans MS-Italic';
  16965. t['LucidaConsole'] = 'Courier';
  16966. t['LucidaConsole-Bold'] = 'Courier-Bold';
  16967. t['LucidaConsole-BoldItalic'] = 'Courier-BoldOblique';
  16968. t['LucidaConsole-Italic'] = 'Courier-Oblique';
  16969. t['MS-Gothic'] = 'MS Gothic';
  16970. t['MS-Gothic-Bold'] = 'MS Gothic-Bold';
  16971. t['MS-Gothic-BoldItalic'] = 'MS Gothic-BoldItalic';
  16972. t['MS-Gothic-Italic'] = 'MS Gothic-Italic';
  16973. t['MS-Mincho'] = 'MS Mincho';
  16974. t['MS-Mincho-Bold'] = 'MS Mincho-Bold';
  16975. t['MS-Mincho-BoldItalic'] = 'MS Mincho-BoldItalic';
  16976. t['MS-Mincho-Italic'] = 'MS Mincho-Italic';
  16977. t['MS-PGothic'] = 'MS PGothic';
  16978. t['MS-PGothic-Bold'] = 'MS PGothic-Bold';
  16979. t['MS-PGothic-BoldItalic'] = 'MS PGothic-BoldItalic';
  16980. t['MS-PGothic-Italic'] = 'MS PGothic-Italic';
  16981. t['MS-PMincho'] = 'MS PMincho';
  16982. t['MS-PMincho-Bold'] = 'MS PMincho-Bold';
  16983. t['MS-PMincho-BoldItalic'] = 'MS PMincho-BoldItalic';
  16984. t['MS-PMincho-Italic'] = 'MS PMincho-Italic';
  16985. t['Wingdings'] = 'ZapfDingbats';
  16986. });
  16987. var getSerifFonts = getLookupTableFactory(function (t) {
  16988. t['Adobe Jenson'] = true;
  16989. t['Adobe Text'] = true;
  16990. t['Albertus'] = true;
  16991. t['Aldus'] = true;
  16992. t['Alexandria'] = true;
  16993. t['Algerian'] = true;
  16994. t['American Typewriter'] = true;
  16995. t['Antiqua'] = true;
  16996. t['Apex'] = true;
  16997. t['Arno'] = true;
  16998. t['Aster'] = true;
  16999. t['Aurora'] = true;
  17000. t['Baskerville'] = true;
  17001. t['Bell'] = true;
  17002. t['Bembo'] = true;
  17003. t['Bembo Schoolbook'] = true;
  17004. t['Benguiat'] = true;
  17005. t['Berkeley Old Style'] = true;
  17006. t['Bernhard Modern'] = true;
  17007. t['Berthold City'] = true;
  17008. t['Bodoni'] = true;
  17009. t['Bauer Bodoni'] = true;
  17010. t['Book Antiqua'] = true;
  17011. t['Bookman'] = true;
  17012. t['Bordeaux Roman'] = true;
  17013. t['Californian FB'] = true;
  17014. t['Calisto'] = true;
  17015. t['Calvert'] = true;
  17016. t['Capitals'] = true;
  17017. t['Cambria'] = true;
  17018. t['Cartier'] = true;
  17019. t['Caslon'] = true;
  17020. t['Catull'] = true;
  17021. t['Centaur'] = true;
  17022. t['Century Old Style'] = true;
  17023. t['Century Schoolbook'] = true;
  17024. t['Chaparral'] = true;
  17025. t['Charis SIL'] = true;
  17026. t['Cheltenham'] = true;
  17027. t['Cholla Slab'] = true;
  17028. t['Clarendon'] = true;
  17029. t['Clearface'] = true;
  17030. t['Cochin'] = true;
  17031. t['Colonna'] = true;
  17032. t['Computer Modern'] = true;
  17033. t['Concrete Roman'] = true;
  17034. t['Constantia'] = true;
  17035. t['Cooper Black'] = true;
  17036. t['Corona'] = true;
  17037. t['Ecotype'] = true;
  17038. t['Egyptienne'] = true;
  17039. t['Elephant'] = true;
  17040. t['Excelsior'] = true;
  17041. t['Fairfield'] = true;
  17042. t['FF Scala'] = true;
  17043. t['Folkard'] = true;
  17044. t['Footlight'] = true;
  17045. t['FreeSerif'] = true;
  17046. t['Friz Quadrata'] = true;
  17047. t['Garamond'] = true;
  17048. t['Gentium'] = true;
  17049. t['Georgia'] = true;
  17050. t['Gloucester'] = true;
  17051. t['Goudy Old Style'] = true;
  17052. t['Goudy Schoolbook'] = true;
  17053. t['Goudy Pro Font'] = true;
  17054. t['Granjon'] = true;
  17055. t['Guardian Egyptian'] = true;
  17056. t['Heather'] = true;
  17057. t['Hercules'] = true;
  17058. t['High Tower Text'] = true;
  17059. t['Hiroshige'] = true;
  17060. t['Hoefler Text'] = true;
  17061. t['Humana Serif'] = true;
  17062. t['Imprint'] = true;
  17063. t['Ionic No. 5'] = true;
  17064. t['Janson'] = true;
  17065. t['Joanna'] = true;
  17066. t['Korinna'] = true;
  17067. t['Lexicon'] = true;
  17068. t['Liberation Serif'] = true;
  17069. t['Linux Libertine'] = true;
  17070. t['Literaturnaya'] = true;
  17071. t['Lucida'] = true;
  17072. t['Lucida Bright'] = true;
  17073. t['Melior'] = true;
  17074. t['Memphis'] = true;
  17075. t['Miller'] = true;
  17076. t['Minion'] = true;
  17077. t['Modern'] = true;
  17078. t['Mona Lisa'] = true;
  17079. t['Mrs Eaves'] = true;
  17080. t['MS Serif'] = true;
  17081. t['Museo Slab'] = true;
  17082. t['New York'] = true;
  17083. t['Nimbus Roman'] = true;
  17084. t['NPS Rawlinson Roadway'] = true;
  17085. t['Palatino'] = true;
  17086. t['Perpetua'] = true;
  17087. t['Plantin'] = true;
  17088. t['Plantin Schoolbook'] = true;
  17089. t['Playbill'] = true;
  17090. t['Poor Richard'] = true;
  17091. t['Rawlinson Roadway'] = true;
  17092. t['Renault'] = true;
  17093. t['Requiem'] = true;
  17094. t['Rockwell'] = true;
  17095. t['Roman'] = true;
  17096. t['Rotis Serif'] = true;
  17097. t['Sabon'] = true;
  17098. t['Scala'] = true;
  17099. t['Seagull'] = true;
  17100. t['Sistina'] = true;
  17101. t['Souvenir'] = true;
  17102. t['STIX'] = true;
  17103. t['Stone Informal'] = true;
  17104. t['Stone Serif'] = true;
  17105. t['Sylfaen'] = true;
  17106. t['Times'] = true;
  17107. t['Trajan'] = true;
  17108. t['Trinité'] = true;
  17109. t['Trump Mediaeval'] = true;
  17110. t['Utopia'] = true;
  17111. t['Vale Type'] = true;
  17112. t['Bitstream Vera'] = true;
  17113. t['Vera Serif'] = true;
  17114. t['Versailles'] = true;
  17115. t['Wanted'] = true;
  17116. t['Weiss'] = true;
  17117. t['Wide Latin'] = true;
  17118. t['Windsor'] = true;
  17119. t['XITS'] = true;
  17120. });
  17121. var getSymbolsFonts = getLookupTableFactory(function (t) {
  17122. t['Dingbats'] = true;
  17123. t['Symbol'] = true;
  17124. t['ZapfDingbats'] = true;
  17125. });
  17126. // Glyph map for well-known standard fonts. Sometimes Ghostscript uses CID
  17127. // fonts, but does not embed the CID to GID mapping. The mapping is incomplete
  17128. // for all glyphs, but common for some set of the standard fonts.
  17129. var getGlyphMapForStandardFonts = getLookupTableFactory(function (t) {
  17130. t[2] = 10; t[3] = 32; t[4] = 33; t[5] = 34; t[6] = 35; t[7] = 36; t[8] = 37;
  17131. t[9] = 38; t[10] = 39; t[11] = 40; t[12] = 41; t[13] = 42; t[14] = 43;
  17132. t[15] = 44; t[16] = 45; t[17] = 46; t[18] = 47; t[19] = 48; t[20] = 49;
  17133. t[21] = 50; t[22] = 51; t[23] = 52; t[24] = 53; t[25] = 54; t[26] = 55;
  17134. t[27] = 56; t[28] = 57; t[29] = 58; t[30] = 894; t[31] = 60; t[32] = 61;
  17135. t[33] = 62; t[34] = 63; t[35] = 64; t[36] = 65; t[37] = 66; t[38] = 67;
  17136. t[39] = 68; t[40] = 69; t[41] = 70; t[42] = 71; t[43] = 72; t[44] = 73;
  17137. t[45] = 74; t[46] = 75; t[47] = 76; t[48] = 77; t[49] = 78; t[50] = 79;
  17138. t[51] = 80; t[52] = 81; t[53] = 82; t[54] = 83; t[55] = 84; t[56] = 85;
  17139. t[57] = 86; t[58] = 87; t[59] = 88; t[60] = 89; t[61] = 90; t[62] = 91;
  17140. t[63] = 92; t[64] = 93; t[65] = 94; t[66] = 95; t[67] = 96; t[68] = 97;
  17141. t[69] = 98; t[70] = 99; t[71] = 100; t[72] = 101; t[73] = 102; t[74] = 103;
  17142. t[75] = 104; t[76] = 105; t[77] = 106; t[78] = 107; t[79] = 108;
  17143. t[80] = 109; t[81] = 110; t[82] = 111; t[83] = 112; t[84] = 113;
  17144. t[85] = 114; t[86] = 115; t[87] = 116; t[88] = 117; t[89] = 118;
  17145. t[90] = 119; t[91] = 120; t[92] = 121; t[93] = 122; t[94] = 123;
  17146. t[95] = 124; t[96] = 125; t[97] = 126; t[98] = 196; t[99] = 197;
  17147. t[100] = 199; t[101] = 201; t[102] = 209; t[103] = 214; t[104] = 220;
  17148. t[105] = 225; t[106] = 224; t[107] = 226; t[108] = 228; t[109] = 227;
  17149. t[110] = 229; t[111] = 231; t[112] = 233; t[113] = 232; t[114] = 234;
  17150. t[115] = 235; t[116] = 237; t[117] = 236; t[118] = 238; t[119] = 239;
  17151. t[120] = 241; t[121] = 243; t[122] = 242; t[123] = 244; t[124] = 246;
  17152. t[125] = 245; t[126] = 250; t[127] = 249; t[128] = 251; t[129] = 252;
  17153. t[130] = 8224; t[131] = 176; t[132] = 162; t[133] = 163; t[134] = 167;
  17154. t[135] = 8226; t[136] = 182; t[137] = 223; t[138] = 174; t[139] = 169;
  17155. t[140] = 8482; t[141] = 180; t[142] = 168; t[143] = 8800; t[144] = 198;
  17156. t[145] = 216; t[146] = 8734; t[147] = 177; t[148] = 8804; t[149] = 8805;
  17157. t[150] = 165; t[151] = 181; t[152] = 8706; t[153] = 8721; t[154] = 8719;
  17158. t[156] = 8747; t[157] = 170; t[158] = 186; t[159] = 8486; t[160] = 230;
  17159. t[161] = 248; t[162] = 191; t[163] = 161; t[164] = 172; t[165] = 8730;
  17160. t[166] = 402; t[167] = 8776; t[168] = 8710; t[169] = 171; t[170] = 187;
  17161. t[171] = 8230; t[210] = 218; t[223] = 711; t[224] = 321; t[225] = 322;
  17162. t[227] = 353; t[229] = 382; t[234] = 253; t[252] = 263; t[253] = 268;
  17163. t[254] = 269; t[258] = 258; t[260] = 260; t[261] = 261; t[265] = 280;
  17164. t[266] = 281; t[268] = 283; t[269] = 313; t[275] = 323; t[276] = 324;
  17165. t[278] = 328; t[284] = 345; t[285] = 346; t[286] = 347; t[292] = 367;
  17166. t[295] = 377; t[296] = 378; t[298] = 380; t[305] = 963; t[306] = 964;
  17167. t[307] = 966; t[308] = 8215; t[309] = 8252; t[310] = 8319; t[311] = 8359;
  17168. t[312] = 8592; t[313] = 8593; t[337] = 9552; t[493] = 1039;
  17169. t[494] = 1040; t[705] = 1524; t[706] = 8362; t[710] = 64288; t[711] = 64298;
  17170. t[759] = 1617; t[761] = 1776; t[763] = 1778; t[775] = 1652; t[777] = 1764;
  17171. t[778] = 1780; t[779] = 1781; t[780] = 1782; t[782] = 771; t[783] = 64726;
  17172. t[786] = 8363; t[788] = 8532; t[790] = 768; t[791] = 769; t[792] = 768;
  17173. t[795] = 803; t[797] = 64336; t[798] = 64337; t[799] = 64342;
  17174. t[800] = 64343; t[801] = 64344; t[802] = 64345; t[803] = 64362;
  17175. t[804] = 64363; t[805] = 64364; t[2424] = 7821; t[2425] = 7822;
  17176. t[2426] = 7823; t[2427] = 7824; t[2428] = 7825; t[2429] = 7826;
  17177. t[2430] = 7827; t[2433] = 7682; t[2678] = 8045; t[2679] = 8046;
  17178. t[2830] = 1552; t[2838] = 686; t[2840] = 751; t[2842] = 753; t[2843] = 754;
  17179. t[2844] = 755; t[2846] = 757; t[2856] = 767; t[2857] = 848; t[2858] = 849;
  17180. t[2862] = 853; t[2863] = 854; t[2864] = 855; t[2865] = 861; t[2866] = 862;
  17181. t[2906] = 7460; t[2908] = 7462; t[2909] = 7463; t[2910] = 7464;
  17182. t[2912] = 7466; t[2913] = 7467; t[2914] = 7468; t[2916] = 7470;
  17183. t[2917] = 7471; t[2918] = 7472; t[2920] = 7474; t[2921] = 7475;
  17184. t[2922] = 7476; t[2924] = 7478; t[2925] = 7479; t[2926] = 7480;
  17185. t[2928] = 7482; t[2929] = 7483; t[2930] = 7484; t[2932] = 7486;
  17186. t[2933] = 7487; t[2934] = 7488; t[2936] = 7490; t[2937] = 7491;
  17187. t[2938] = 7492; t[2940] = 7494; t[2941] = 7495; t[2942] = 7496;
  17188. t[2944] = 7498; t[2946] = 7500; t[2948] = 7502; t[2950] = 7504;
  17189. t[2951] = 7505; t[2952] = 7506; t[2954] = 7508; t[2955] = 7509;
  17190. t[2956] = 7510; t[2958] = 7512; t[2959] = 7513; t[2960] = 7514;
  17191. t[2962] = 7516; t[2963] = 7517; t[2964] = 7518; t[2966] = 7520;
  17192. t[2967] = 7521; t[2968] = 7522; t[2970] = 7524; t[2971] = 7525;
  17193. t[2972] = 7526; t[2974] = 7528; t[2975] = 7529; t[2976] = 7530;
  17194. t[2978] = 1537; t[2979] = 1538; t[2980] = 1539; t[2982] = 1549;
  17195. t[2983] = 1551; t[2984] = 1552; t[2986] = 1554; t[2987] = 1555;
  17196. t[2988] = 1556; t[2990] = 1623; t[2991] = 1624; t[2995] = 1775;
  17197. t[2999] = 1791; t[3002] = 64290; t[3003] = 64291; t[3004] = 64292;
  17198. t[3006] = 64294; t[3007] = 64295; t[3008] = 64296; t[3011] = 1900;
  17199. t[3014] = 8223; t[3015] = 8244; t[3017] = 7532; t[3018] = 7533;
  17200. t[3019] = 7534; t[3075] = 7590; t[3076] = 7591; t[3079] = 7594;
  17201. t[3080] = 7595; t[3083] = 7598; t[3084] = 7599; t[3087] = 7602;
  17202. t[3088] = 7603; t[3091] = 7606; t[3092] = 7607; t[3095] = 7610;
  17203. t[3096] = 7611; t[3099] = 7614; t[3100] = 7615; t[3103] = 7618;
  17204. t[3104] = 7619; t[3107] = 8337; t[3108] = 8338; t[3116] = 1884;
  17205. t[3119] = 1885; t[3120] = 1885; t[3123] = 1886; t[3124] = 1886;
  17206. t[3127] = 1887; t[3128] = 1887; t[3131] = 1888; t[3132] = 1888;
  17207. t[3135] = 1889; t[3136] = 1889; t[3139] = 1890; t[3140] = 1890;
  17208. t[3143] = 1891; t[3144] = 1891; t[3147] = 1892; t[3148] = 1892;
  17209. t[3153] = 580; t[3154] = 581; t[3157] = 584; t[3158] = 585; t[3161] = 588;
  17210. t[3162] = 589; t[3165] = 891; t[3166] = 892; t[3169] = 1274; t[3170] = 1275;
  17211. t[3173] = 1278; t[3174] = 1279; t[3181] = 7622; t[3182] = 7623;
  17212. t[3282] = 11799; t[3316] = 578; t[3379] = 42785; t[3393] = 1159;
  17213. t[3416] = 8377;
  17214. });
  17215. // The glyph map for ArialBlack differs slightly from the glyph map used for
  17216. // other well-known standard fonts. Hence we use this (incomplete) CID to GID
  17217. // mapping to adjust the glyph map for non-embedded ArialBlack fonts.
  17218. var getSupplementalGlyphMapForArialBlack =
  17219. getLookupTableFactory(function (t) {
  17220. t[227] = 322; t[264] = 261; t[291] = 346;
  17221. });
  17222. exports.getStdFontMap = getStdFontMap;
  17223. exports.getNonStdFontMap = getNonStdFontMap;
  17224. exports.getSerifFonts = getSerifFonts;
  17225. exports.getSymbolsFonts = getSymbolsFonts;
  17226. exports.getGlyphMapForStandardFonts = getGlyphMapForStandardFonts;
  17227. exports.getSupplementalGlyphMapForArialBlack =
  17228. getSupplementalGlyphMapForArialBlack;
  17229. }));
  17230. (function (root, factory) {
  17231. {
  17232. factory((root.pdfjsCoreUnicode = {}), root.pdfjsSharedUtil);
  17233. }
  17234. }(this, function (exports, sharedUtil) {
  17235. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  17236. // Some characters, e.g. copyrightserif, are mapped to the private use area
  17237. // and might not be displayed using standard fonts. Mapping/hacking well-known
  17238. // chars to the similar equivalents in the normal characters range.
  17239. var getSpecialPUASymbols = getLookupTableFactory(function (t) {
  17240. t[63721] = 0x00A9; // copyrightsans (0xF8E9) => copyright
  17241. t[63193] = 0x00A9; // copyrightserif (0xF6D9) => copyright
  17242. t[63720] = 0x00AE; // registersans (0xF8E8) => registered
  17243. t[63194] = 0x00AE; // registerserif (0xF6DA) => registered
  17244. t[63722] = 0x2122; // trademarksans (0xF8EA) => trademark
  17245. t[63195] = 0x2122; // trademarkserif (0xF6DB) => trademark
  17246. t[63729] = 0x23A7; // bracelefttp (0xF8F1)
  17247. t[63730] = 0x23A8; // braceleftmid (0xF8F2)
  17248. t[63731] = 0x23A9; // braceleftbt (0xF8F3)
  17249. t[63740] = 0x23AB; // bracerighttp (0xF8FC)
  17250. t[63741] = 0x23AC; // bracerightmid (0xF8FD)
  17251. t[63742] = 0x23AD; // bracerightbt (0xF8FE)
  17252. t[63726] = 0x23A1; // bracketlefttp (0xF8EE)
  17253. t[63727] = 0x23A2; // bracketleftex (0xF8EF)
  17254. t[63728] = 0x23A3; // bracketleftbt (0xF8F0)
  17255. t[63737] = 0x23A4; // bracketrighttp (0xF8F9)
  17256. t[63738] = 0x23A5; // bracketrightex (0xF8FA)
  17257. t[63739] = 0x23A6; // bracketrightbt (0xF8FB)
  17258. t[63723] = 0x239B; // parenlefttp (0xF8EB)
  17259. t[63724] = 0x239C; // parenleftex (0xF8EC)
  17260. t[63725] = 0x239D; // parenleftbt (0xF8ED)
  17261. t[63734] = 0x239E; // parenrighttp (0xF8F6)
  17262. t[63735] = 0x239F; // parenrightex (0xF8F7)
  17263. t[63736] = 0x23A0; // parenrightbt (0xF8F8)
  17264. });
  17265. function mapSpecialUnicodeValues(code) {
  17266. if (code >= 0xFFF0 && code <= 0xFFFF) { // Specials unicode block.
  17267. return 0;
  17268. } else if (code >= 0xF600 && code <= 0xF8FF) {
  17269. return (getSpecialPUASymbols()[code] || code);
  17270. }
  17271. return code;
  17272. }
  17273. function getUnicodeForGlyph(name, glyphsUnicodeMap) {
  17274. var unicode = glyphsUnicodeMap[name];
  17275. if (unicode !== undefined) {
  17276. return unicode;
  17277. }
  17278. if (!name) {
  17279. return -1;
  17280. }
  17281. // Try to recover valid Unicode values from 'uniXXXX'/'uXXXX{XX}' glyphs.
  17282. if (name[0] === 'u') {
  17283. var nameLen = name.length, hexStr;
  17284. if (nameLen === 7 && name[1] === 'n' && name[2] === 'i') { // 'uniXXXX'
  17285. hexStr = name.substr(3);
  17286. } else if (nameLen >= 5 && nameLen <= 7) { // 'uXXXX{XX}'
  17287. hexStr = name.substr(1);
  17288. } else {
  17289. return -1;
  17290. }
  17291. // Check for upper-case hexadecimal characters, to avoid false positives.
  17292. if (hexStr === hexStr.toUpperCase()) {
  17293. unicode = parseInt(hexStr, 16);
  17294. if (unicode >= 0) {
  17295. return unicode;
  17296. }
  17297. }
  17298. }
  17299. return -1;
  17300. }
  17301. var UnicodeRanges = [
  17302. { 'begin': 0x0000, 'end': 0x007F }, // Basic Latin
  17303. { 'begin': 0x0080, 'end': 0x00FF }, // Latin-1 Supplement
  17304. { 'begin': 0x0100, 'end': 0x017F }, // Latin Extended-A
  17305. { 'begin': 0x0180, 'end': 0x024F }, // Latin Extended-B
  17306. { 'begin': 0x0250, 'end': 0x02AF }, // IPA Extensions
  17307. { 'begin': 0x02B0, 'end': 0x02FF }, // Spacing Modifier Letters
  17308. { 'begin': 0x0300, 'end': 0x036F }, // Combining Diacritical Marks
  17309. { 'begin': 0x0370, 'end': 0x03FF }, // Greek and Coptic
  17310. { 'begin': 0x2C80, 'end': 0x2CFF }, // Coptic
  17311. { 'begin': 0x0400, 'end': 0x04FF }, // Cyrillic
  17312. { 'begin': 0x0530, 'end': 0x058F }, // Armenian
  17313. { 'begin': 0x0590, 'end': 0x05FF }, // Hebrew
  17314. { 'begin': 0xA500, 'end': 0xA63F }, // Vai
  17315. { 'begin': 0x0600, 'end': 0x06FF }, // Arabic
  17316. { 'begin': 0x07C0, 'end': 0x07FF }, // NKo
  17317. { 'begin': 0x0900, 'end': 0x097F }, // Devanagari
  17318. { 'begin': 0x0980, 'end': 0x09FF }, // Bengali
  17319. { 'begin': 0x0A00, 'end': 0x0A7F }, // Gurmukhi
  17320. { 'begin': 0x0A80, 'end': 0x0AFF }, // Gujarati
  17321. { 'begin': 0x0B00, 'end': 0x0B7F }, // Oriya
  17322. { 'begin': 0x0B80, 'end': 0x0BFF }, // Tamil
  17323. { 'begin': 0x0C00, 'end': 0x0C7F }, // Telugu
  17324. { 'begin': 0x0C80, 'end': 0x0CFF }, // Kannada
  17325. { 'begin': 0x0D00, 'end': 0x0D7F }, // Malayalam
  17326. { 'begin': 0x0E00, 'end': 0x0E7F }, // Thai
  17327. { 'begin': 0x0E80, 'end': 0x0EFF }, // Lao
  17328. { 'begin': 0x10A0, 'end': 0x10FF }, // Georgian
  17329. { 'begin': 0x1B00, 'end': 0x1B7F }, // Balinese
  17330. { 'begin': 0x1100, 'end': 0x11FF }, // Hangul Jamo
  17331. { 'begin': 0x1E00, 'end': 0x1EFF }, // Latin Extended Additional
  17332. { 'begin': 0x1F00, 'end': 0x1FFF }, // Greek Extended
  17333. { 'begin': 0x2000, 'end': 0x206F }, // General Punctuation
  17334. { 'begin': 0x2070, 'end': 0x209F }, // Superscripts And Subscripts
  17335. { 'begin': 0x20A0, 'end': 0x20CF }, // Currency Symbol
  17336. { 'begin': 0x20D0, 'end': 0x20FF }, // Combining Diacritical Marks
  17337. { 'begin': 0x2100, 'end': 0x214F }, // Letterlike Symbols
  17338. { 'begin': 0x2150, 'end': 0x218F }, // Number Forms
  17339. { 'begin': 0x2190, 'end': 0x21FF }, // Arrows
  17340. { 'begin': 0x2200, 'end': 0x22FF }, // Mathematical Operators
  17341. { 'begin': 0x2300, 'end': 0x23FF }, // Miscellaneous Technical
  17342. { 'begin': 0x2400, 'end': 0x243F }, // Control Pictures
  17343. { 'begin': 0x2440, 'end': 0x245F }, // Optical Character Recognition
  17344. { 'begin': 0x2460, 'end': 0x24FF }, // Enclosed Alphanumerics
  17345. { 'begin': 0x2500, 'end': 0x257F }, // Box Drawing
  17346. { 'begin': 0x2580, 'end': 0x259F }, // Block Elements
  17347. { 'begin': 0x25A0, 'end': 0x25FF }, // Geometric Shapes
  17348. { 'begin': 0x2600, 'end': 0x26FF }, // Miscellaneous Symbols
  17349. { 'begin': 0x2700, 'end': 0x27BF }, // Dingbats
  17350. { 'begin': 0x3000, 'end': 0x303F }, // CJK Symbols And Punctuation
  17351. { 'begin': 0x3040, 'end': 0x309F }, // Hiragana
  17352. { 'begin': 0x30A0, 'end': 0x30FF }, // Katakana
  17353. { 'begin': 0x3100, 'end': 0x312F }, // Bopomofo
  17354. { 'begin': 0x3130, 'end': 0x318F }, // Hangul Compatibility Jamo
  17355. { 'begin': 0xA840, 'end': 0xA87F }, // Phags-pa
  17356. { 'begin': 0x3200, 'end': 0x32FF }, // Enclosed CJK Letters And Months
  17357. { 'begin': 0x3300, 'end': 0x33FF }, // CJK Compatibility
  17358. { 'begin': 0xAC00, 'end': 0xD7AF }, // Hangul Syllables
  17359. { 'begin': 0xD800, 'end': 0xDFFF }, // Non-Plane 0 *
  17360. { 'begin': 0x10900, 'end': 0x1091F }, // Phoenicia
  17361. { 'begin': 0x4E00, 'end': 0x9FFF }, // CJK Unified Ideographs
  17362. { 'begin': 0xE000, 'end': 0xF8FF }, // Private Use Area (plane 0)
  17363. { 'begin': 0x31C0, 'end': 0x31EF }, // CJK Strokes
  17364. { 'begin': 0xFB00, 'end': 0xFB4F }, // Alphabetic Presentation Forms
  17365. { 'begin': 0xFB50, 'end': 0xFDFF }, // Arabic Presentation Forms-A
  17366. { 'begin': 0xFE20, 'end': 0xFE2F }, // Combining Half Marks
  17367. { 'begin': 0xFE10, 'end': 0xFE1F }, // Vertical Forms
  17368. { 'begin': 0xFE50, 'end': 0xFE6F }, // Small Form Variants
  17369. { 'begin': 0xFE70, 'end': 0xFEFF }, // Arabic Presentation Forms-B
  17370. { 'begin': 0xFF00, 'end': 0xFFEF }, // Halfwidth And Fullwidth Forms
  17371. { 'begin': 0xFFF0, 'end': 0xFFFF }, // Specials
  17372. { 'begin': 0x0F00, 'end': 0x0FFF }, // Tibetan
  17373. { 'begin': 0x0700, 'end': 0x074F }, // Syriac
  17374. { 'begin': 0x0780, 'end': 0x07BF }, // Thaana
  17375. { 'begin': 0x0D80, 'end': 0x0DFF }, // Sinhala
  17376. { 'begin': 0x1000, 'end': 0x109F }, // Myanmar
  17377. { 'begin': 0x1200, 'end': 0x137F }, // Ethiopic
  17378. { 'begin': 0x13A0, 'end': 0x13FF }, // Cherokee
  17379. { 'begin': 0x1400, 'end': 0x167F }, // Unified Canadian Aboriginal Syllabics
  17380. { 'begin': 0x1680, 'end': 0x169F }, // Ogham
  17381. { 'begin': 0x16A0, 'end': 0x16FF }, // Runic
  17382. { 'begin': 0x1780, 'end': 0x17FF }, // Khmer
  17383. { 'begin': 0x1800, 'end': 0x18AF }, // Mongolian
  17384. { 'begin': 0x2800, 'end': 0x28FF }, // Braille Patterns
  17385. { 'begin': 0xA000, 'end': 0xA48F }, // Yi Syllables
  17386. { 'begin': 0x1700, 'end': 0x171F }, // Tagalog
  17387. { 'begin': 0x10300, 'end': 0x1032F }, // Old Italic
  17388. { 'begin': 0x10330, 'end': 0x1034F }, // Gothic
  17389. { 'begin': 0x10400, 'end': 0x1044F }, // Deseret
  17390. { 'begin': 0x1D000, 'end': 0x1D0FF }, // Byzantine Musical Symbols
  17391. { 'begin': 0x1D400, 'end': 0x1D7FF }, // Mathematical Alphanumeric Symbols
  17392. { 'begin': 0xFF000, 'end': 0xFFFFD }, // Private Use (plane 15)
  17393. { 'begin': 0xFE00, 'end': 0xFE0F }, // Variation Selectors
  17394. { 'begin': 0xE0000, 'end': 0xE007F }, // Tags
  17395. { 'begin': 0x1900, 'end': 0x194F }, // Limbu
  17396. { 'begin': 0x1950, 'end': 0x197F }, // Tai Le
  17397. { 'begin': 0x1980, 'end': 0x19DF }, // New Tai Lue
  17398. { 'begin': 0x1A00, 'end': 0x1A1F }, // Buginese
  17399. { 'begin': 0x2C00, 'end': 0x2C5F }, // Glagolitic
  17400. { 'begin': 0x2D30, 'end': 0x2D7F }, // Tifinagh
  17401. { 'begin': 0x4DC0, 'end': 0x4DFF }, // Yijing Hexagram Symbols
  17402. { 'begin': 0xA800, 'end': 0xA82F }, // Syloti Nagri
  17403. { 'begin': 0x10000, 'end': 0x1007F }, // Linear B Syllabary
  17404. { 'begin': 0x10140, 'end': 0x1018F }, // Ancient Greek Numbers
  17405. { 'begin': 0x10380, 'end': 0x1039F }, // Ugaritic
  17406. { 'begin': 0x103A0, 'end': 0x103DF }, // Old Persian
  17407. { 'begin': 0x10450, 'end': 0x1047F }, // Shavian
  17408. { 'begin': 0x10480, 'end': 0x104AF }, // Osmanya
  17409. { 'begin': 0x10800, 'end': 0x1083F }, // Cypriot Syllabary
  17410. { 'begin': 0x10A00, 'end': 0x10A5F }, // Kharoshthi
  17411. { 'begin': 0x1D300, 'end': 0x1D35F }, // Tai Xuan Jing Symbols
  17412. { 'begin': 0x12000, 'end': 0x123FF }, // Cuneiform
  17413. { 'begin': 0x1D360, 'end': 0x1D37F }, // Counting Rod Numerals
  17414. { 'begin': 0x1B80, 'end': 0x1BBF }, // Sundanese
  17415. { 'begin': 0x1C00, 'end': 0x1C4F }, // Lepcha
  17416. { 'begin': 0x1C50, 'end': 0x1C7F }, // Ol Chiki
  17417. { 'begin': 0xA880, 'end': 0xA8DF }, // Saurashtra
  17418. { 'begin': 0xA900, 'end': 0xA92F }, // Kayah Li
  17419. { 'begin': 0xA930, 'end': 0xA95F }, // Rejang
  17420. { 'begin': 0xAA00, 'end': 0xAA5F }, // Cham
  17421. { 'begin': 0x10190, 'end': 0x101CF }, // Ancient Symbols
  17422. { 'begin': 0x101D0, 'end': 0x101FF }, // Phaistos Disc
  17423. { 'begin': 0x102A0, 'end': 0x102DF }, // Carian
  17424. { 'begin': 0x1F030, 'end': 0x1F09F } // Domino Tiles
  17425. ];
  17426. function getUnicodeRangeFor(value) {
  17427. for (var i = 0, ii = UnicodeRanges.length; i < ii; i++) {
  17428. var range = UnicodeRanges[i];
  17429. if (value >= range.begin && value < range.end) {
  17430. return i;
  17431. }
  17432. }
  17433. return -1;
  17434. }
  17435. function isRTLRangeFor(value) {
  17436. var range = UnicodeRanges[13];
  17437. if (value >= range.begin && value < range.end) {
  17438. return true;
  17439. }
  17440. range = UnicodeRanges[11];
  17441. if (value >= range.begin && value < range.end) {
  17442. return true;
  17443. }
  17444. return false;
  17445. }
  17446. // The normalization table is obtained by filtering the Unicode characters
  17447. // database with <compat> entries.
  17448. var getNormalizedUnicodes = getLookupTableFactory(function (t) {
  17449. t['\u00A8'] = '\u0020\u0308';
  17450. t['\u00AF'] = '\u0020\u0304';
  17451. t['\u00B4'] = '\u0020\u0301';
  17452. t['\u00B5'] = '\u03BC';
  17453. t['\u00B8'] = '\u0020\u0327';
  17454. t['\u0132'] = '\u0049\u004A';
  17455. t['\u0133'] = '\u0069\u006A';
  17456. t['\u013F'] = '\u004C\u00B7';
  17457. t['\u0140'] = '\u006C\u00B7';
  17458. t['\u0149'] = '\u02BC\u006E';
  17459. t['\u017F'] = '\u0073';
  17460. t['\u01C4'] = '\u0044\u017D';
  17461. t['\u01C5'] = '\u0044\u017E';
  17462. t['\u01C6'] = '\u0064\u017E';
  17463. t['\u01C7'] = '\u004C\u004A';
  17464. t['\u01C8'] = '\u004C\u006A';
  17465. t['\u01C9'] = '\u006C\u006A';
  17466. t['\u01CA'] = '\u004E\u004A';
  17467. t['\u01CB'] = '\u004E\u006A';
  17468. t['\u01CC'] = '\u006E\u006A';
  17469. t['\u01F1'] = '\u0044\u005A';
  17470. t['\u01F2'] = '\u0044\u007A';
  17471. t['\u01F3'] = '\u0064\u007A';
  17472. t['\u02D8'] = '\u0020\u0306';
  17473. t['\u02D9'] = '\u0020\u0307';
  17474. t['\u02DA'] = '\u0020\u030A';
  17475. t['\u02DB'] = '\u0020\u0328';
  17476. t['\u02DC'] = '\u0020\u0303';
  17477. t['\u02DD'] = '\u0020\u030B';
  17478. t['\u037A'] = '\u0020\u0345';
  17479. t['\u0384'] = '\u0020\u0301';
  17480. t['\u03D0'] = '\u03B2';
  17481. t['\u03D1'] = '\u03B8';
  17482. t['\u03D2'] = '\u03A5';
  17483. t['\u03D5'] = '\u03C6';
  17484. t['\u03D6'] = '\u03C0';
  17485. t['\u03F0'] = '\u03BA';
  17486. t['\u03F1'] = '\u03C1';
  17487. t['\u03F2'] = '\u03C2';
  17488. t['\u03F4'] = '\u0398';
  17489. t['\u03F5'] = '\u03B5';
  17490. t['\u03F9'] = '\u03A3';
  17491. t['\u0587'] = '\u0565\u0582';
  17492. t['\u0675'] = '\u0627\u0674';
  17493. t['\u0676'] = '\u0648\u0674';
  17494. t['\u0677'] = '\u06C7\u0674';
  17495. t['\u0678'] = '\u064A\u0674';
  17496. t['\u0E33'] = '\u0E4D\u0E32';
  17497. t['\u0EB3'] = '\u0ECD\u0EB2';
  17498. t['\u0EDC'] = '\u0EAB\u0E99';
  17499. t['\u0EDD'] = '\u0EAB\u0EA1';
  17500. t['\u0F77'] = '\u0FB2\u0F81';
  17501. t['\u0F79'] = '\u0FB3\u0F81';
  17502. t['\u1E9A'] = '\u0061\u02BE';
  17503. t['\u1FBD'] = '\u0020\u0313';
  17504. t['\u1FBF'] = '\u0020\u0313';
  17505. t['\u1FC0'] = '\u0020\u0342';
  17506. t['\u1FFE'] = '\u0020\u0314';
  17507. t['\u2002'] = '\u0020';
  17508. t['\u2003'] = '\u0020';
  17509. t['\u2004'] = '\u0020';
  17510. t['\u2005'] = '\u0020';
  17511. t['\u2006'] = '\u0020';
  17512. t['\u2008'] = '\u0020';
  17513. t['\u2009'] = '\u0020';
  17514. t['\u200A'] = '\u0020';
  17515. t['\u2017'] = '\u0020\u0333';
  17516. t['\u2024'] = '\u002E';
  17517. t['\u2025'] = '\u002E\u002E';
  17518. t['\u2026'] = '\u002E\u002E\u002E';
  17519. t['\u2033'] = '\u2032\u2032';
  17520. t['\u2034'] = '\u2032\u2032\u2032';
  17521. t['\u2036'] = '\u2035\u2035';
  17522. t['\u2037'] = '\u2035\u2035\u2035';
  17523. t['\u203C'] = '\u0021\u0021';
  17524. t['\u203E'] = '\u0020\u0305';
  17525. t['\u2047'] = '\u003F\u003F';
  17526. t['\u2048'] = '\u003F\u0021';
  17527. t['\u2049'] = '\u0021\u003F';
  17528. t['\u2057'] = '\u2032\u2032\u2032\u2032';
  17529. t['\u205F'] = '\u0020';
  17530. t['\u20A8'] = '\u0052\u0073';
  17531. t['\u2100'] = '\u0061\u002F\u0063';
  17532. t['\u2101'] = '\u0061\u002F\u0073';
  17533. t['\u2103'] = '\u00B0\u0043';
  17534. t['\u2105'] = '\u0063\u002F\u006F';
  17535. t['\u2106'] = '\u0063\u002F\u0075';
  17536. t['\u2107'] = '\u0190';
  17537. t['\u2109'] = '\u00B0\u0046';
  17538. t['\u2116'] = '\u004E\u006F';
  17539. t['\u2121'] = '\u0054\u0045\u004C';
  17540. t['\u2135'] = '\u05D0';
  17541. t['\u2136'] = '\u05D1';
  17542. t['\u2137'] = '\u05D2';
  17543. t['\u2138'] = '\u05D3';
  17544. t['\u213B'] = '\u0046\u0041\u0058';
  17545. t['\u2160'] = '\u0049';
  17546. t['\u2161'] = '\u0049\u0049';
  17547. t['\u2162'] = '\u0049\u0049\u0049';
  17548. t['\u2163'] = '\u0049\u0056';
  17549. t['\u2164'] = '\u0056';
  17550. t['\u2165'] = '\u0056\u0049';
  17551. t['\u2166'] = '\u0056\u0049\u0049';
  17552. t['\u2167'] = '\u0056\u0049\u0049\u0049';
  17553. t['\u2168'] = '\u0049\u0058';
  17554. t['\u2169'] = '\u0058';
  17555. t['\u216A'] = '\u0058\u0049';
  17556. t['\u216B'] = '\u0058\u0049\u0049';
  17557. t['\u216C'] = '\u004C';
  17558. t['\u216D'] = '\u0043';
  17559. t['\u216E'] = '\u0044';
  17560. t['\u216F'] = '\u004D';
  17561. t['\u2170'] = '\u0069';
  17562. t['\u2171'] = '\u0069\u0069';
  17563. t['\u2172'] = '\u0069\u0069\u0069';
  17564. t['\u2173'] = '\u0069\u0076';
  17565. t['\u2174'] = '\u0076';
  17566. t['\u2175'] = '\u0076\u0069';
  17567. t['\u2176'] = '\u0076\u0069\u0069';
  17568. t['\u2177'] = '\u0076\u0069\u0069\u0069';
  17569. t['\u2178'] = '\u0069\u0078';
  17570. t['\u2179'] = '\u0078';
  17571. t['\u217A'] = '\u0078\u0069';
  17572. t['\u217B'] = '\u0078\u0069\u0069';
  17573. t['\u217C'] = '\u006C';
  17574. t['\u217D'] = '\u0063';
  17575. t['\u217E'] = '\u0064';
  17576. t['\u217F'] = '\u006D';
  17577. t['\u222C'] = '\u222B\u222B';
  17578. t['\u222D'] = '\u222B\u222B\u222B';
  17579. t['\u222F'] = '\u222E\u222E';
  17580. t['\u2230'] = '\u222E\u222E\u222E';
  17581. t['\u2474'] = '\u0028\u0031\u0029';
  17582. t['\u2475'] = '\u0028\u0032\u0029';
  17583. t['\u2476'] = '\u0028\u0033\u0029';
  17584. t['\u2477'] = '\u0028\u0034\u0029';
  17585. t['\u2478'] = '\u0028\u0035\u0029';
  17586. t['\u2479'] = '\u0028\u0036\u0029';
  17587. t['\u247A'] = '\u0028\u0037\u0029';
  17588. t['\u247B'] = '\u0028\u0038\u0029';
  17589. t['\u247C'] = '\u0028\u0039\u0029';
  17590. t['\u247D'] = '\u0028\u0031\u0030\u0029';
  17591. t['\u247E'] = '\u0028\u0031\u0031\u0029';
  17592. t['\u247F'] = '\u0028\u0031\u0032\u0029';
  17593. t['\u2480'] = '\u0028\u0031\u0033\u0029';
  17594. t['\u2481'] = '\u0028\u0031\u0034\u0029';
  17595. t['\u2482'] = '\u0028\u0031\u0035\u0029';
  17596. t['\u2483'] = '\u0028\u0031\u0036\u0029';
  17597. t['\u2484'] = '\u0028\u0031\u0037\u0029';
  17598. t['\u2485'] = '\u0028\u0031\u0038\u0029';
  17599. t['\u2486'] = '\u0028\u0031\u0039\u0029';
  17600. t['\u2487'] = '\u0028\u0032\u0030\u0029';
  17601. t['\u2488'] = '\u0031\u002E';
  17602. t['\u2489'] = '\u0032\u002E';
  17603. t['\u248A'] = '\u0033\u002E';
  17604. t['\u248B'] = '\u0034\u002E';
  17605. t['\u248C'] = '\u0035\u002E';
  17606. t['\u248D'] = '\u0036\u002E';
  17607. t['\u248E'] = '\u0037\u002E';
  17608. t['\u248F'] = '\u0038\u002E';
  17609. t['\u2490'] = '\u0039\u002E';
  17610. t['\u2491'] = '\u0031\u0030\u002E';
  17611. t['\u2492'] = '\u0031\u0031\u002E';
  17612. t['\u2493'] = '\u0031\u0032\u002E';
  17613. t['\u2494'] = '\u0031\u0033\u002E';
  17614. t['\u2495'] = '\u0031\u0034\u002E';
  17615. t['\u2496'] = '\u0031\u0035\u002E';
  17616. t['\u2497'] = '\u0031\u0036\u002E';
  17617. t['\u2498'] = '\u0031\u0037\u002E';
  17618. t['\u2499'] = '\u0031\u0038\u002E';
  17619. t['\u249A'] = '\u0031\u0039\u002E';
  17620. t['\u249B'] = '\u0032\u0030\u002E';
  17621. t['\u249C'] = '\u0028\u0061\u0029';
  17622. t['\u249D'] = '\u0028\u0062\u0029';
  17623. t['\u249E'] = '\u0028\u0063\u0029';
  17624. t['\u249F'] = '\u0028\u0064\u0029';
  17625. t['\u24A0'] = '\u0028\u0065\u0029';
  17626. t['\u24A1'] = '\u0028\u0066\u0029';
  17627. t['\u24A2'] = '\u0028\u0067\u0029';
  17628. t['\u24A3'] = '\u0028\u0068\u0029';
  17629. t['\u24A4'] = '\u0028\u0069\u0029';
  17630. t['\u24A5'] = '\u0028\u006A\u0029';
  17631. t['\u24A6'] = '\u0028\u006B\u0029';
  17632. t['\u24A7'] = '\u0028\u006C\u0029';
  17633. t['\u24A8'] = '\u0028\u006D\u0029';
  17634. t['\u24A9'] = '\u0028\u006E\u0029';
  17635. t['\u24AA'] = '\u0028\u006F\u0029';
  17636. t['\u24AB'] = '\u0028\u0070\u0029';
  17637. t['\u24AC'] = '\u0028\u0071\u0029';
  17638. t['\u24AD'] = '\u0028\u0072\u0029';
  17639. t['\u24AE'] = '\u0028\u0073\u0029';
  17640. t['\u24AF'] = '\u0028\u0074\u0029';
  17641. t['\u24B0'] = '\u0028\u0075\u0029';
  17642. t['\u24B1'] = '\u0028\u0076\u0029';
  17643. t['\u24B2'] = '\u0028\u0077\u0029';
  17644. t['\u24B3'] = '\u0028\u0078\u0029';
  17645. t['\u24B4'] = '\u0028\u0079\u0029';
  17646. t['\u24B5'] = '\u0028\u007A\u0029';
  17647. t['\u2A0C'] = '\u222B\u222B\u222B\u222B';
  17648. t['\u2A74'] = '\u003A\u003A\u003D';
  17649. t['\u2A75'] = '\u003D\u003D';
  17650. t['\u2A76'] = '\u003D\u003D\u003D';
  17651. t['\u2E9F'] = '\u6BCD';
  17652. t['\u2EF3'] = '\u9F9F';
  17653. t['\u2F00'] = '\u4E00';
  17654. t['\u2F01'] = '\u4E28';
  17655. t['\u2F02'] = '\u4E36';
  17656. t['\u2F03'] = '\u4E3F';
  17657. t['\u2F04'] = '\u4E59';
  17658. t['\u2F05'] = '\u4E85';
  17659. t['\u2F06'] = '\u4E8C';
  17660. t['\u2F07'] = '\u4EA0';
  17661. t['\u2F08'] = '\u4EBA';
  17662. t['\u2F09'] = '\u513F';
  17663. t['\u2F0A'] = '\u5165';
  17664. t['\u2F0B'] = '\u516B';
  17665. t['\u2F0C'] = '\u5182';
  17666. t['\u2F0D'] = '\u5196';
  17667. t['\u2F0E'] = '\u51AB';
  17668. t['\u2F0F'] = '\u51E0';
  17669. t['\u2F10'] = '\u51F5';
  17670. t['\u2F11'] = '\u5200';
  17671. t['\u2F12'] = '\u529B';
  17672. t['\u2F13'] = '\u52F9';
  17673. t['\u2F14'] = '\u5315';
  17674. t['\u2F15'] = '\u531A';
  17675. t['\u2F16'] = '\u5338';
  17676. t['\u2F17'] = '\u5341';
  17677. t['\u2F18'] = '\u535C';
  17678. t['\u2F19'] = '\u5369';
  17679. t['\u2F1A'] = '\u5382';
  17680. t['\u2F1B'] = '\u53B6';
  17681. t['\u2F1C'] = '\u53C8';
  17682. t['\u2F1D'] = '\u53E3';
  17683. t['\u2F1E'] = '\u56D7';
  17684. t['\u2F1F'] = '\u571F';
  17685. t['\u2F20'] = '\u58EB';
  17686. t['\u2F21'] = '\u5902';
  17687. t['\u2F22'] = '\u590A';
  17688. t['\u2F23'] = '\u5915';
  17689. t['\u2F24'] = '\u5927';
  17690. t['\u2F25'] = '\u5973';
  17691. t['\u2F26'] = '\u5B50';
  17692. t['\u2F27'] = '\u5B80';
  17693. t['\u2F28'] = '\u5BF8';
  17694. t['\u2F29'] = '\u5C0F';
  17695. t['\u2F2A'] = '\u5C22';
  17696. t['\u2F2B'] = '\u5C38';
  17697. t['\u2F2C'] = '\u5C6E';
  17698. t['\u2F2D'] = '\u5C71';
  17699. t['\u2F2E'] = '\u5DDB';
  17700. t['\u2F2F'] = '\u5DE5';
  17701. t['\u2F30'] = '\u5DF1';
  17702. t['\u2F31'] = '\u5DFE';
  17703. t['\u2F32'] = '\u5E72';
  17704. t['\u2F33'] = '\u5E7A';
  17705. t['\u2F34'] = '\u5E7F';
  17706. t['\u2F35'] = '\u5EF4';
  17707. t['\u2F36'] = '\u5EFE';
  17708. t['\u2F37'] = '\u5F0B';
  17709. t['\u2F38'] = '\u5F13';
  17710. t['\u2F39'] = '\u5F50';
  17711. t['\u2F3A'] = '\u5F61';
  17712. t['\u2F3B'] = '\u5F73';
  17713. t['\u2F3C'] = '\u5FC3';
  17714. t['\u2F3D'] = '\u6208';
  17715. t['\u2F3E'] = '\u6236';
  17716. t['\u2F3F'] = '\u624B';
  17717. t['\u2F40'] = '\u652F';
  17718. t['\u2F41'] = '\u6534';
  17719. t['\u2F42'] = '\u6587';
  17720. t['\u2F43'] = '\u6597';
  17721. t['\u2F44'] = '\u65A4';
  17722. t['\u2F45'] = '\u65B9';
  17723. t['\u2F46'] = '\u65E0';
  17724. t['\u2F47'] = '\u65E5';
  17725. t['\u2F48'] = '\u66F0';
  17726. t['\u2F49'] = '\u6708';
  17727. t['\u2F4A'] = '\u6728';
  17728. t['\u2F4B'] = '\u6B20';
  17729. t['\u2F4C'] = '\u6B62';
  17730. t['\u2F4D'] = '\u6B79';
  17731. t['\u2F4E'] = '\u6BB3';
  17732. t['\u2F4F'] = '\u6BCB';
  17733. t['\u2F50'] = '\u6BD4';
  17734. t['\u2F51'] = '\u6BDB';
  17735. t['\u2F52'] = '\u6C0F';
  17736. t['\u2F53'] = '\u6C14';
  17737. t['\u2F54'] = '\u6C34';
  17738. t['\u2F55'] = '\u706B';
  17739. t['\u2F56'] = '\u722A';
  17740. t['\u2F57'] = '\u7236';
  17741. t['\u2F58'] = '\u723B';
  17742. t['\u2F59'] = '\u723F';
  17743. t['\u2F5A'] = '\u7247';
  17744. t['\u2F5B'] = '\u7259';
  17745. t['\u2F5C'] = '\u725B';
  17746. t['\u2F5D'] = '\u72AC';
  17747. t['\u2F5E'] = '\u7384';
  17748. t['\u2F5F'] = '\u7389';
  17749. t['\u2F60'] = '\u74DC';
  17750. t['\u2F61'] = '\u74E6';
  17751. t['\u2F62'] = '\u7518';
  17752. t['\u2F63'] = '\u751F';
  17753. t['\u2F64'] = '\u7528';
  17754. t['\u2F65'] = '\u7530';
  17755. t['\u2F66'] = '\u758B';
  17756. t['\u2F67'] = '\u7592';
  17757. t['\u2F68'] = '\u7676';
  17758. t['\u2F69'] = '\u767D';
  17759. t['\u2F6A'] = '\u76AE';
  17760. t['\u2F6B'] = '\u76BF';
  17761. t['\u2F6C'] = '\u76EE';
  17762. t['\u2F6D'] = '\u77DB';
  17763. t['\u2F6E'] = '\u77E2';
  17764. t['\u2F6F'] = '\u77F3';
  17765. t['\u2F70'] = '\u793A';
  17766. t['\u2F71'] = '\u79B8';
  17767. t['\u2F72'] = '\u79BE';
  17768. t['\u2F73'] = '\u7A74';
  17769. t['\u2F74'] = '\u7ACB';
  17770. t['\u2F75'] = '\u7AF9';
  17771. t['\u2F76'] = '\u7C73';
  17772. t['\u2F77'] = '\u7CF8';
  17773. t['\u2F78'] = '\u7F36';
  17774. t['\u2F79'] = '\u7F51';
  17775. t['\u2F7A'] = '\u7F8A';
  17776. t['\u2F7B'] = '\u7FBD';
  17777. t['\u2F7C'] = '\u8001';
  17778. t['\u2F7D'] = '\u800C';
  17779. t['\u2F7E'] = '\u8012';
  17780. t['\u2F7F'] = '\u8033';
  17781. t['\u2F80'] = '\u807F';
  17782. t['\u2F81'] = '\u8089';
  17783. t['\u2F82'] = '\u81E3';
  17784. t['\u2F83'] = '\u81EA';
  17785. t['\u2F84'] = '\u81F3';
  17786. t['\u2F85'] = '\u81FC';
  17787. t['\u2F86'] = '\u820C';
  17788. t['\u2F87'] = '\u821B';
  17789. t['\u2F88'] = '\u821F';
  17790. t['\u2F89'] = '\u826E';
  17791. t['\u2F8A'] = '\u8272';
  17792. t['\u2F8B'] = '\u8278';
  17793. t['\u2F8C'] = '\u864D';
  17794. t['\u2F8D'] = '\u866B';
  17795. t['\u2F8E'] = '\u8840';
  17796. t['\u2F8F'] = '\u884C';
  17797. t['\u2F90'] = '\u8863';
  17798. t['\u2F91'] = '\u897E';
  17799. t['\u2F92'] = '\u898B';
  17800. t['\u2F93'] = '\u89D2';
  17801. t['\u2F94'] = '\u8A00';
  17802. t['\u2F95'] = '\u8C37';
  17803. t['\u2F96'] = '\u8C46';
  17804. t['\u2F97'] = '\u8C55';
  17805. t['\u2F98'] = '\u8C78';
  17806. t['\u2F99'] = '\u8C9D';
  17807. t['\u2F9A'] = '\u8D64';
  17808. t['\u2F9B'] = '\u8D70';
  17809. t['\u2F9C'] = '\u8DB3';
  17810. t['\u2F9D'] = '\u8EAB';
  17811. t['\u2F9E'] = '\u8ECA';
  17812. t['\u2F9F'] = '\u8F9B';
  17813. t['\u2FA0'] = '\u8FB0';
  17814. t['\u2FA1'] = '\u8FB5';
  17815. t['\u2FA2'] = '\u9091';
  17816. t['\u2FA3'] = '\u9149';
  17817. t['\u2FA4'] = '\u91C6';
  17818. t['\u2FA5'] = '\u91CC';
  17819. t['\u2FA6'] = '\u91D1';
  17820. t['\u2FA7'] = '\u9577';
  17821. t['\u2FA8'] = '\u9580';
  17822. t['\u2FA9'] = '\u961C';
  17823. t['\u2FAA'] = '\u96B6';
  17824. t['\u2FAB'] = '\u96B9';
  17825. t['\u2FAC'] = '\u96E8';
  17826. t['\u2FAD'] = '\u9751';
  17827. t['\u2FAE'] = '\u975E';
  17828. t['\u2FAF'] = '\u9762';
  17829. t['\u2FB0'] = '\u9769';
  17830. t['\u2FB1'] = '\u97CB';
  17831. t['\u2FB2'] = '\u97ED';
  17832. t['\u2FB3'] = '\u97F3';
  17833. t['\u2FB4'] = '\u9801';
  17834. t['\u2FB5'] = '\u98A8';
  17835. t['\u2FB6'] = '\u98DB';
  17836. t['\u2FB7'] = '\u98DF';
  17837. t['\u2FB8'] = '\u9996';
  17838. t['\u2FB9'] = '\u9999';
  17839. t['\u2FBA'] = '\u99AC';
  17840. t['\u2FBB'] = '\u9AA8';
  17841. t['\u2FBC'] = '\u9AD8';
  17842. t['\u2FBD'] = '\u9ADF';
  17843. t['\u2FBE'] = '\u9B25';
  17844. t['\u2FBF'] = '\u9B2F';
  17845. t['\u2FC0'] = '\u9B32';
  17846. t['\u2FC1'] = '\u9B3C';
  17847. t['\u2FC2'] = '\u9B5A';
  17848. t['\u2FC3'] = '\u9CE5';
  17849. t['\u2FC4'] = '\u9E75';
  17850. t['\u2FC5'] = '\u9E7F';
  17851. t['\u2FC6'] = '\u9EA5';
  17852. t['\u2FC7'] = '\u9EBB';
  17853. t['\u2FC8'] = '\u9EC3';
  17854. t['\u2FC9'] = '\u9ECD';
  17855. t['\u2FCA'] = '\u9ED1';
  17856. t['\u2FCB'] = '\u9EF9';
  17857. t['\u2FCC'] = '\u9EFD';
  17858. t['\u2FCD'] = '\u9F0E';
  17859. t['\u2FCE'] = '\u9F13';
  17860. t['\u2FCF'] = '\u9F20';
  17861. t['\u2FD0'] = '\u9F3B';
  17862. t['\u2FD1'] = '\u9F4A';
  17863. t['\u2FD2'] = '\u9F52';
  17864. t['\u2FD3'] = '\u9F8D';
  17865. t['\u2FD4'] = '\u9F9C';
  17866. t['\u2FD5'] = '\u9FA0';
  17867. t['\u3036'] = '\u3012';
  17868. t['\u3038'] = '\u5341';
  17869. t['\u3039'] = '\u5344';
  17870. t['\u303A'] = '\u5345';
  17871. t['\u309B'] = '\u0020\u3099';
  17872. t['\u309C'] = '\u0020\u309A';
  17873. t['\u3131'] = '\u1100';
  17874. t['\u3132'] = '\u1101';
  17875. t['\u3133'] = '\u11AA';
  17876. t['\u3134'] = '\u1102';
  17877. t['\u3135'] = '\u11AC';
  17878. t['\u3136'] = '\u11AD';
  17879. t['\u3137'] = '\u1103';
  17880. t['\u3138'] = '\u1104';
  17881. t['\u3139'] = '\u1105';
  17882. t['\u313A'] = '\u11B0';
  17883. t['\u313B'] = '\u11B1';
  17884. t['\u313C'] = '\u11B2';
  17885. t['\u313D'] = '\u11B3';
  17886. t['\u313E'] = '\u11B4';
  17887. t['\u313F'] = '\u11B5';
  17888. t['\u3140'] = '\u111A';
  17889. t['\u3141'] = '\u1106';
  17890. t['\u3142'] = '\u1107';
  17891. t['\u3143'] = '\u1108';
  17892. t['\u3144'] = '\u1121';
  17893. t['\u3145'] = '\u1109';
  17894. t['\u3146'] = '\u110A';
  17895. t['\u3147'] = '\u110B';
  17896. t['\u3148'] = '\u110C';
  17897. t['\u3149'] = '\u110D';
  17898. t['\u314A'] = '\u110E';
  17899. t['\u314B'] = '\u110F';
  17900. t['\u314C'] = '\u1110';
  17901. t['\u314D'] = '\u1111';
  17902. t['\u314E'] = '\u1112';
  17903. t['\u314F'] = '\u1161';
  17904. t['\u3150'] = '\u1162';
  17905. t['\u3151'] = '\u1163';
  17906. t['\u3152'] = '\u1164';
  17907. t['\u3153'] = '\u1165';
  17908. t['\u3154'] = '\u1166';
  17909. t['\u3155'] = '\u1167';
  17910. t['\u3156'] = '\u1168';
  17911. t['\u3157'] = '\u1169';
  17912. t['\u3158'] = '\u116A';
  17913. t['\u3159'] = '\u116B';
  17914. t['\u315A'] = '\u116C';
  17915. t['\u315B'] = '\u116D';
  17916. t['\u315C'] = '\u116E';
  17917. t['\u315D'] = '\u116F';
  17918. t['\u315E'] = '\u1170';
  17919. t['\u315F'] = '\u1171';
  17920. t['\u3160'] = '\u1172';
  17921. t['\u3161'] = '\u1173';
  17922. t['\u3162'] = '\u1174';
  17923. t['\u3163'] = '\u1175';
  17924. t['\u3164'] = '\u1160';
  17925. t['\u3165'] = '\u1114';
  17926. t['\u3166'] = '\u1115';
  17927. t['\u3167'] = '\u11C7';
  17928. t['\u3168'] = '\u11C8';
  17929. t['\u3169'] = '\u11CC';
  17930. t['\u316A'] = '\u11CE';
  17931. t['\u316B'] = '\u11D3';
  17932. t['\u316C'] = '\u11D7';
  17933. t['\u316D'] = '\u11D9';
  17934. t['\u316E'] = '\u111C';
  17935. t['\u316F'] = '\u11DD';
  17936. t['\u3170'] = '\u11DF';
  17937. t['\u3171'] = '\u111D';
  17938. t['\u3172'] = '\u111E';
  17939. t['\u3173'] = '\u1120';
  17940. t['\u3174'] = '\u1122';
  17941. t['\u3175'] = '\u1123';
  17942. t['\u3176'] = '\u1127';
  17943. t['\u3177'] = '\u1129';
  17944. t['\u3178'] = '\u112B';
  17945. t['\u3179'] = '\u112C';
  17946. t['\u317A'] = '\u112D';
  17947. t['\u317B'] = '\u112E';
  17948. t['\u317C'] = '\u112F';
  17949. t['\u317D'] = '\u1132';
  17950. t['\u317E'] = '\u1136';
  17951. t['\u317F'] = '\u1140';
  17952. t['\u3180'] = '\u1147';
  17953. t['\u3181'] = '\u114C';
  17954. t['\u3182'] = '\u11F1';
  17955. t['\u3183'] = '\u11F2';
  17956. t['\u3184'] = '\u1157';
  17957. t['\u3185'] = '\u1158';
  17958. t['\u3186'] = '\u1159';
  17959. t['\u3187'] = '\u1184';
  17960. t['\u3188'] = '\u1185';
  17961. t['\u3189'] = '\u1188';
  17962. t['\u318A'] = '\u1191';
  17963. t['\u318B'] = '\u1192';
  17964. t['\u318C'] = '\u1194';
  17965. t['\u318D'] = '\u119E';
  17966. t['\u318E'] = '\u11A1';
  17967. t['\u3200'] = '\u0028\u1100\u0029';
  17968. t['\u3201'] = '\u0028\u1102\u0029';
  17969. t['\u3202'] = '\u0028\u1103\u0029';
  17970. t['\u3203'] = '\u0028\u1105\u0029';
  17971. t['\u3204'] = '\u0028\u1106\u0029';
  17972. t['\u3205'] = '\u0028\u1107\u0029';
  17973. t['\u3206'] = '\u0028\u1109\u0029';
  17974. t['\u3207'] = '\u0028\u110B\u0029';
  17975. t['\u3208'] = '\u0028\u110C\u0029';
  17976. t['\u3209'] = '\u0028\u110E\u0029';
  17977. t['\u320A'] = '\u0028\u110F\u0029';
  17978. t['\u320B'] = '\u0028\u1110\u0029';
  17979. t['\u320C'] = '\u0028\u1111\u0029';
  17980. t['\u320D'] = '\u0028\u1112\u0029';
  17981. t['\u320E'] = '\u0028\u1100\u1161\u0029';
  17982. t['\u320F'] = '\u0028\u1102\u1161\u0029';
  17983. t['\u3210'] = '\u0028\u1103\u1161\u0029';
  17984. t['\u3211'] = '\u0028\u1105\u1161\u0029';
  17985. t['\u3212'] = '\u0028\u1106\u1161\u0029';
  17986. t['\u3213'] = '\u0028\u1107\u1161\u0029';
  17987. t['\u3214'] = '\u0028\u1109\u1161\u0029';
  17988. t['\u3215'] = '\u0028\u110B\u1161\u0029';
  17989. t['\u3216'] = '\u0028\u110C\u1161\u0029';
  17990. t['\u3217'] = '\u0028\u110E\u1161\u0029';
  17991. t['\u3218'] = '\u0028\u110F\u1161\u0029';
  17992. t['\u3219'] = '\u0028\u1110\u1161\u0029';
  17993. t['\u321A'] = '\u0028\u1111\u1161\u0029';
  17994. t['\u321B'] = '\u0028\u1112\u1161\u0029';
  17995. t['\u321C'] = '\u0028\u110C\u116E\u0029';
  17996. t['\u321D'] = '\u0028\u110B\u1169\u110C\u1165\u11AB\u0029';
  17997. t['\u321E'] = '\u0028\u110B\u1169\u1112\u116E\u0029';
  17998. t['\u3220'] = '\u0028\u4E00\u0029';
  17999. t['\u3221'] = '\u0028\u4E8C\u0029';
  18000. t['\u3222'] = '\u0028\u4E09\u0029';
  18001. t['\u3223'] = '\u0028\u56DB\u0029';
  18002. t['\u3224'] = '\u0028\u4E94\u0029';
  18003. t['\u3225'] = '\u0028\u516D\u0029';
  18004. t['\u3226'] = '\u0028\u4E03\u0029';
  18005. t['\u3227'] = '\u0028\u516B\u0029';
  18006. t['\u3228'] = '\u0028\u4E5D\u0029';
  18007. t['\u3229'] = '\u0028\u5341\u0029';
  18008. t['\u322A'] = '\u0028\u6708\u0029';
  18009. t['\u322B'] = '\u0028\u706B\u0029';
  18010. t['\u322C'] = '\u0028\u6C34\u0029';
  18011. t['\u322D'] = '\u0028\u6728\u0029';
  18012. t['\u322E'] = '\u0028\u91D1\u0029';
  18013. t['\u322F'] = '\u0028\u571F\u0029';
  18014. t['\u3230'] = '\u0028\u65E5\u0029';
  18015. t['\u3231'] = '\u0028\u682A\u0029';
  18016. t['\u3232'] = '\u0028\u6709\u0029';
  18017. t['\u3233'] = '\u0028\u793E\u0029';
  18018. t['\u3234'] = '\u0028\u540D\u0029';
  18019. t['\u3235'] = '\u0028\u7279\u0029';
  18020. t['\u3236'] = '\u0028\u8CA1\u0029';
  18021. t['\u3237'] = '\u0028\u795D\u0029';
  18022. t['\u3238'] = '\u0028\u52B4\u0029';
  18023. t['\u3239'] = '\u0028\u4EE3\u0029';
  18024. t['\u323A'] = '\u0028\u547C\u0029';
  18025. t['\u323B'] = '\u0028\u5B66\u0029';
  18026. t['\u323C'] = '\u0028\u76E3\u0029';
  18027. t['\u323D'] = '\u0028\u4F01\u0029';
  18028. t['\u323E'] = '\u0028\u8CC7\u0029';
  18029. t['\u323F'] = '\u0028\u5354\u0029';
  18030. t['\u3240'] = '\u0028\u796D\u0029';
  18031. t['\u3241'] = '\u0028\u4F11\u0029';
  18032. t['\u3242'] = '\u0028\u81EA\u0029';
  18033. t['\u3243'] = '\u0028\u81F3\u0029';
  18034. t['\u32C0'] = '\u0031\u6708';
  18035. t['\u32C1'] = '\u0032\u6708';
  18036. t['\u32C2'] = '\u0033\u6708';
  18037. t['\u32C3'] = '\u0034\u6708';
  18038. t['\u32C4'] = '\u0035\u6708';
  18039. t['\u32C5'] = '\u0036\u6708';
  18040. t['\u32C6'] = '\u0037\u6708';
  18041. t['\u32C7'] = '\u0038\u6708';
  18042. t['\u32C8'] = '\u0039\u6708';
  18043. t['\u32C9'] = '\u0031\u0030\u6708';
  18044. t['\u32CA'] = '\u0031\u0031\u6708';
  18045. t['\u32CB'] = '\u0031\u0032\u6708';
  18046. t['\u3358'] = '\u0030\u70B9';
  18047. t['\u3359'] = '\u0031\u70B9';
  18048. t['\u335A'] = '\u0032\u70B9';
  18049. t['\u335B'] = '\u0033\u70B9';
  18050. t['\u335C'] = '\u0034\u70B9';
  18051. t['\u335D'] = '\u0035\u70B9';
  18052. t['\u335E'] = '\u0036\u70B9';
  18053. t['\u335F'] = '\u0037\u70B9';
  18054. t['\u3360'] = '\u0038\u70B9';
  18055. t['\u3361'] = '\u0039\u70B9';
  18056. t['\u3362'] = '\u0031\u0030\u70B9';
  18057. t['\u3363'] = '\u0031\u0031\u70B9';
  18058. t['\u3364'] = '\u0031\u0032\u70B9';
  18059. t['\u3365'] = '\u0031\u0033\u70B9';
  18060. t['\u3366'] = '\u0031\u0034\u70B9';
  18061. t['\u3367'] = '\u0031\u0035\u70B9';
  18062. t['\u3368'] = '\u0031\u0036\u70B9';
  18063. t['\u3369'] = '\u0031\u0037\u70B9';
  18064. t['\u336A'] = '\u0031\u0038\u70B9';
  18065. t['\u336B'] = '\u0031\u0039\u70B9';
  18066. t['\u336C'] = '\u0032\u0030\u70B9';
  18067. t['\u336D'] = '\u0032\u0031\u70B9';
  18068. t['\u336E'] = '\u0032\u0032\u70B9';
  18069. t['\u336F'] = '\u0032\u0033\u70B9';
  18070. t['\u3370'] = '\u0032\u0034\u70B9';
  18071. t['\u33E0'] = '\u0031\u65E5';
  18072. t['\u33E1'] = '\u0032\u65E5';
  18073. t['\u33E2'] = '\u0033\u65E5';
  18074. t['\u33E3'] = '\u0034\u65E5';
  18075. t['\u33E4'] = '\u0035\u65E5';
  18076. t['\u33E5'] = '\u0036\u65E5';
  18077. t['\u33E6'] = '\u0037\u65E5';
  18078. t['\u33E7'] = '\u0038\u65E5';
  18079. t['\u33E8'] = '\u0039\u65E5';
  18080. t['\u33E9'] = '\u0031\u0030\u65E5';
  18081. t['\u33EA'] = '\u0031\u0031\u65E5';
  18082. t['\u33EB'] = '\u0031\u0032\u65E5';
  18083. t['\u33EC'] = '\u0031\u0033\u65E5';
  18084. t['\u33ED'] = '\u0031\u0034\u65E5';
  18085. t['\u33EE'] = '\u0031\u0035\u65E5';
  18086. t['\u33EF'] = '\u0031\u0036\u65E5';
  18087. t['\u33F0'] = '\u0031\u0037\u65E5';
  18088. t['\u33F1'] = '\u0031\u0038\u65E5';
  18089. t['\u33F2'] = '\u0031\u0039\u65E5';
  18090. t['\u33F3'] = '\u0032\u0030\u65E5';
  18091. t['\u33F4'] = '\u0032\u0031\u65E5';
  18092. t['\u33F5'] = '\u0032\u0032\u65E5';
  18093. t['\u33F6'] = '\u0032\u0033\u65E5';
  18094. t['\u33F7'] = '\u0032\u0034\u65E5';
  18095. t['\u33F8'] = '\u0032\u0035\u65E5';
  18096. t['\u33F9'] = '\u0032\u0036\u65E5';
  18097. t['\u33FA'] = '\u0032\u0037\u65E5';
  18098. t['\u33FB'] = '\u0032\u0038\u65E5';
  18099. t['\u33FC'] = '\u0032\u0039\u65E5';
  18100. t['\u33FD'] = '\u0033\u0030\u65E5';
  18101. t['\u33FE'] = '\u0033\u0031\u65E5';
  18102. t['\uFB00'] = '\u0066\u0066';
  18103. t['\uFB01'] = '\u0066\u0069';
  18104. t['\uFB02'] = '\u0066\u006C';
  18105. t['\uFB03'] = '\u0066\u0066\u0069';
  18106. t['\uFB04'] = '\u0066\u0066\u006C';
  18107. t['\uFB05'] = '\u017F\u0074';
  18108. t['\uFB06'] = '\u0073\u0074';
  18109. t['\uFB13'] = '\u0574\u0576';
  18110. t['\uFB14'] = '\u0574\u0565';
  18111. t['\uFB15'] = '\u0574\u056B';
  18112. t['\uFB16'] = '\u057E\u0576';
  18113. t['\uFB17'] = '\u0574\u056D';
  18114. t['\uFB4F'] = '\u05D0\u05DC';
  18115. t['\uFB50'] = '\u0671';
  18116. t['\uFB51'] = '\u0671';
  18117. t['\uFB52'] = '\u067B';
  18118. t['\uFB53'] = '\u067B';
  18119. t['\uFB54'] = '\u067B';
  18120. t['\uFB55'] = '\u067B';
  18121. t['\uFB56'] = '\u067E';
  18122. t['\uFB57'] = '\u067E';
  18123. t['\uFB58'] = '\u067E';
  18124. t['\uFB59'] = '\u067E';
  18125. t['\uFB5A'] = '\u0680';
  18126. t['\uFB5B'] = '\u0680';
  18127. t['\uFB5C'] = '\u0680';
  18128. t['\uFB5D'] = '\u0680';
  18129. t['\uFB5E'] = '\u067A';
  18130. t['\uFB5F'] = '\u067A';
  18131. t['\uFB60'] = '\u067A';
  18132. t['\uFB61'] = '\u067A';
  18133. t['\uFB62'] = '\u067F';
  18134. t['\uFB63'] = '\u067F';
  18135. t['\uFB64'] = '\u067F';
  18136. t['\uFB65'] = '\u067F';
  18137. t['\uFB66'] = '\u0679';
  18138. t['\uFB67'] = '\u0679';
  18139. t['\uFB68'] = '\u0679';
  18140. t['\uFB69'] = '\u0679';
  18141. t['\uFB6A'] = '\u06A4';
  18142. t['\uFB6B'] = '\u06A4';
  18143. t['\uFB6C'] = '\u06A4';
  18144. t['\uFB6D'] = '\u06A4';
  18145. t['\uFB6E'] = '\u06A6';
  18146. t['\uFB6F'] = '\u06A6';
  18147. t['\uFB70'] = '\u06A6';
  18148. t['\uFB71'] = '\u06A6';
  18149. t['\uFB72'] = '\u0684';
  18150. t['\uFB73'] = '\u0684';
  18151. t['\uFB74'] = '\u0684';
  18152. t['\uFB75'] = '\u0684';
  18153. t['\uFB76'] = '\u0683';
  18154. t['\uFB77'] = '\u0683';
  18155. t['\uFB78'] = '\u0683';
  18156. t['\uFB79'] = '\u0683';
  18157. t['\uFB7A'] = '\u0686';
  18158. t['\uFB7B'] = '\u0686';
  18159. t['\uFB7C'] = '\u0686';
  18160. t['\uFB7D'] = '\u0686';
  18161. t['\uFB7E'] = '\u0687';
  18162. t['\uFB7F'] = '\u0687';
  18163. t['\uFB80'] = '\u0687';
  18164. t['\uFB81'] = '\u0687';
  18165. t['\uFB82'] = '\u068D';
  18166. t['\uFB83'] = '\u068D';
  18167. t['\uFB84'] = '\u068C';
  18168. t['\uFB85'] = '\u068C';
  18169. t['\uFB86'] = '\u068E';
  18170. t['\uFB87'] = '\u068E';
  18171. t['\uFB88'] = '\u0688';
  18172. t['\uFB89'] = '\u0688';
  18173. t['\uFB8A'] = '\u0698';
  18174. t['\uFB8B'] = '\u0698';
  18175. t['\uFB8C'] = '\u0691';
  18176. t['\uFB8D'] = '\u0691';
  18177. t['\uFB8E'] = '\u06A9';
  18178. t['\uFB8F'] = '\u06A9';
  18179. t['\uFB90'] = '\u06A9';
  18180. t['\uFB91'] = '\u06A9';
  18181. t['\uFB92'] = '\u06AF';
  18182. t['\uFB93'] = '\u06AF';
  18183. t['\uFB94'] = '\u06AF';
  18184. t['\uFB95'] = '\u06AF';
  18185. t['\uFB96'] = '\u06B3';
  18186. t['\uFB97'] = '\u06B3';
  18187. t['\uFB98'] = '\u06B3';
  18188. t['\uFB99'] = '\u06B3';
  18189. t['\uFB9A'] = '\u06B1';
  18190. t['\uFB9B'] = '\u06B1';
  18191. t['\uFB9C'] = '\u06B1';
  18192. t['\uFB9D'] = '\u06B1';
  18193. t['\uFB9E'] = '\u06BA';
  18194. t['\uFB9F'] = '\u06BA';
  18195. t['\uFBA0'] = '\u06BB';
  18196. t['\uFBA1'] = '\u06BB';
  18197. t['\uFBA2'] = '\u06BB';
  18198. t['\uFBA3'] = '\u06BB';
  18199. t['\uFBA4'] = '\u06C0';
  18200. t['\uFBA5'] = '\u06C0';
  18201. t['\uFBA6'] = '\u06C1';
  18202. t['\uFBA7'] = '\u06C1';
  18203. t['\uFBA8'] = '\u06C1';
  18204. t['\uFBA9'] = '\u06C1';
  18205. t['\uFBAA'] = '\u06BE';
  18206. t['\uFBAB'] = '\u06BE';
  18207. t['\uFBAC'] = '\u06BE';
  18208. t['\uFBAD'] = '\u06BE';
  18209. t['\uFBAE'] = '\u06D2';
  18210. t['\uFBAF'] = '\u06D2';
  18211. t['\uFBB0'] = '\u06D3';
  18212. t['\uFBB1'] = '\u06D3';
  18213. t['\uFBD3'] = '\u06AD';
  18214. t['\uFBD4'] = '\u06AD';
  18215. t['\uFBD5'] = '\u06AD';
  18216. t['\uFBD6'] = '\u06AD';
  18217. t['\uFBD7'] = '\u06C7';
  18218. t['\uFBD8'] = '\u06C7';
  18219. t['\uFBD9'] = '\u06C6';
  18220. t['\uFBDA'] = '\u06C6';
  18221. t['\uFBDB'] = '\u06C8';
  18222. t['\uFBDC'] = '\u06C8';
  18223. t['\uFBDD'] = '\u0677';
  18224. t['\uFBDE'] = '\u06CB';
  18225. t['\uFBDF'] = '\u06CB';
  18226. t['\uFBE0'] = '\u06C5';
  18227. t['\uFBE1'] = '\u06C5';
  18228. t['\uFBE2'] = '\u06C9';
  18229. t['\uFBE3'] = '\u06C9';
  18230. t['\uFBE4'] = '\u06D0';
  18231. t['\uFBE5'] = '\u06D0';
  18232. t['\uFBE6'] = '\u06D0';
  18233. t['\uFBE7'] = '\u06D0';
  18234. t['\uFBE8'] = '\u0649';
  18235. t['\uFBE9'] = '\u0649';
  18236. t['\uFBEA'] = '\u0626\u0627';
  18237. t['\uFBEB'] = '\u0626\u0627';
  18238. t['\uFBEC'] = '\u0626\u06D5';
  18239. t['\uFBED'] = '\u0626\u06D5';
  18240. t['\uFBEE'] = '\u0626\u0648';
  18241. t['\uFBEF'] = '\u0626\u0648';
  18242. t['\uFBF0'] = '\u0626\u06C7';
  18243. t['\uFBF1'] = '\u0626\u06C7';
  18244. t['\uFBF2'] = '\u0626\u06C6';
  18245. t['\uFBF3'] = '\u0626\u06C6';
  18246. t['\uFBF4'] = '\u0626\u06C8';
  18247. t['\uFBF5'] = '\u0626\u06C8';
  18248. t['\uFBF6'] = '\u0626\u06D0';
  18249. t['\uFBF7'] = '\u0626\u06D0';
  18250. t['\uFBF8'] = '\u0626\u06D0';
  18251. t['\uFBF9'] = '\u0626\u0649';
  18252. t['\uFBFA'] = '\u0626\u0649';
  18253. t['\uFBFB'] = '\u0626\u0649';
  18254. t['\uFBFC'] = '\u06CC';
  18255. t['\uFBFD'] = '\u06CC';
  18256. t['\uFBFE'] = '\u06CC';
  18257. t['\uFBFF'] = '\u06CC';
  18258. t['\uFC00'] = '\u0626\u062C';
  18259. t['\uFC01'] = '\u0626\u062D';
  18260. t['\uFC02'] = '\u0626\u0645';
  18261. t['\uFC03'] = '\u0626\u0649';
  18262. t['\uFC04'] = '\u0626\u064A';
  18263. t['\uFC05'] = '\u0628\u062C';
  18264. t['\uFC06'] = '\u0628\u062D';
  18265. t['\uFC07'] = '\u0628\u062E';
  18266. t['\uFC08'] = '\u0628\u0645';
  18267. t['\uFC09'] = '\u0628\u0649';
  18268. t['\uFC0A'] = '\u0628\u064A';
  18269. t['\uFC0B'] = '\u062A\u062C';
  18270. t['\uFC0C'] = '\u062A\u062D';
  18271. t['\uFC0D'] = '\u062A\u062E';
  18272. t['\uFC0E'] = '\u062A\u0645';
  18273. t['\uFC0F'] = '\u062A\u0649';
  18274. t['\uFC10'] = '\u062A\u064A';
  18275. t['\uFC11'] = '\u062B\u062C';
  18276. t['\uFC12'] = '\u062B\u0645';
  18277. t['\uFC13'] = '\u062B\u0649';
  18278. t['\uFC14'] = '\u062B\u064A';
  18279. t['\uFC15'] = '\u062C\u062D';
  18280. t['\uFC16'] = '\u062C\u0645';
  18281. t['\uFC17'] = '\u062D\u062C';
  18282. t['\uFC18'] = '\u062D\u0645';
  18283. t['\uFC19'] = '\u062E\u062C';
  18284. t['\uFC1A'] = '\u062E\u062D';
  18285. t['\uFC1B'] = '\u062E\u0645';
  18286. t['\uFC1C'] = '\u0633\u062C';
  18287. t['\uFC1D'] = '\u0633\u062D';
  18288. t['\uFC1E'] = '\u0633\u062E';
  18289. t['\uFC1F'] = '\u0633\u0645';
  18290. t['\uFC20'] = '\u0635\u062D';
  18291. t['\uFC21'] = '\u0635\u0645';
  18292. t['\uFC22'] = '\u0636\u062C';
  18293. t['\uFC23'] = '\u0636\u062D';
  18294. t['\uFC24'] = '\u0636\u062E';
  18295. t['\uFC25'] = '\u0636\u0645';
  18296. t['\uFC26'] = '\u0637\u062D';
  18297. t['\uFC27'] = '\u0637\u0645';
  18298. t['\uFC28'] = '\u0638\u0645';
  18299. t['\uFC29'] = '\u0639\u062C';
  18300. t['\uFC2A'] = '\u0639\u0645';
  18301. t['\uFC2B'] = '\u063A\u062C';
  18302. t['\uFC2C'] = '\u063A\u0645';
  18303. t['\uFC2D'] = '\u0641\u062C';
  18304. t['\uFC2E'] = '\u0641\u062D';
  18305. t['\uFC2F'] = '\u0641\u062E';
  18306. t['\uFC30'] = '\u0641\u0645';
  18307. t['\uFC31'] = '\u0641\u0649';
  18308. t['\uFC32'] = '\u0641\u064A';
  18309. t['\uFC33'] = '\u0642\u062D';
  18310. t['\uFC34'] = '\u0642\u0645';
  18311. t['\uFC35'] = '\u0642\u0649';
  18312. t['\uFC36'] = '\u0642\u064A';
  18313. t['\uFC37'] = '\u0643\u0627';
  18314. t['\uFC38'] = '\u0643\u062C';
  18315. t['\uFC39'] = '\u0643\u062D';
  18316. t['\uFC3A'] = '\u0643\u062E';
  18317. t['\uFC3B'] = '\u0643\u0644';
  18318. t['\uFC3C'] = '\u0643\u0645';
  18319. t['\uFC3D'] = '\u0643\u0649';
  18320. t['\uFC3E'] = '\u0643\u064A';
  18321. t['\uFC3F'] = '\u0644\u062C';
  18322. t['\uFC40'] = '\u0644\u062D';
  18323. t['\uFC41'] = '\u0644\u062E';
  18324. t['\uFC42'] = '\u0644\u0645';
  18325. t['\uFC43'] = '\u0644\u0649';
  18326. t['\uFC44'] = '\u0644\u064A';
  18327. t['\uFC45'] = '\u0645\u062C';
  18328. t['\uFC46'] = '\u0645\u062D';
  18329. t['\uFC47'] = '\u0645\u062E';
  18330. t['\uFC48'] = '\u0645\u0645';
  18331. t['\uFC49'] = '\u0645\u0649';
  18332. t['\uFC4A'] = '\u0645\u064A';
  18333. t['\uFC4B'] = '\u0646\u062C';
  18334. t['\uFC4C'] = '\u0646\u062D';
  18335. t['\uFC4D'] = '\u0646\u062E';
  18336. t['\uFC4E'] = '\u0646\u0645';
  18337. t['\uFC4F'] = '\u0646\u0649';
  18338. t['\uFC50'] = '\u0646\u064A';
  18339. t['\uFC51'] = '\u0647\u062C';
  18340. t['\uFC52'] = '\u0647\u0645';
  18341. t['\uFC53'] = '\u0647\u0649';
  18342. t['\uFC54'] = '\u0647\u064A';
  18343. t['\uFC55'] = '\u064A\u062C';
  18344. t['\uFC56'] = '\u064A\u062D';
  18345. t['\uFC57'] = '\u064A\u062E';
  18346. t['\uFC58'] = '\u064A\u0645';
  18347. t['\uFC59'] = '\u064A\u0649';
  18348. t['\uFC5A'] = '\u064A\u064A';
  18349. t['\uFC5B'] = '\u0630\u0670';
  18350. t['\uFC5C'] = '\u0631\u0670';
  18351. t['\uFC5D'] = '\u0649\u0670';
  18352. t['\uFC5E'] = '\u0020\u064C\u0651';
  18353. t['\uFC5F'] = '\u0020\u064D\u0651';
  18354. t['\uFC60'] = '\u0020\u064E\u0651';
  18355. t['\uFC61'] = '\u0020\u064F\u0651';
  18356. t['\uFC62'] = '\u0020\u0650\u0651';
  18357. t['\uFC63'] = '\u0020\u0651\u0670';
  18358. t['\uFC64'] = '\u0626\u0631';
  18359. t['\uFC65'] = '\u0626\u0632';
  18360. t['\uFC66'] = '\u0626\u0645';
  18361. t['\uFC67'] = '\u0626\u0646';
  18362. t['\uFC68'] = '\u0626\u0649';
  18363. t['\uFC69'] = '\u0626\u064A';
  18364. t['\uFC6A'] = '\u0628\u0631';
  18365. t['\uFC6B'] = '\u0628\u0632';
  18366. t['\uFC6C'] = '\u0628\u0645';
  18367. t['\uFC6D'] = '\u0628\u0646';
  18368. t['\uFC6E'] = '\u0628\u0649';
  18369. t['\uFC6F'] = '\u0628\u064A';
  18370. t['\uFC70'] = '\u062A\u0631';
  18371. t['\uFC71'] = '\u062A\u0632';
  18372. t['\uFC72'] = '\u062A\u0645';
  18373. t['\uFC73'] = '\u062A\u0646';
  18374. t['\uFC74'] = '\u062A\u0649';
  18375. t['\uFC75'] = '\u062A\u064A';
  18376. t['\uFC76'] = '\u062B\u0631';
  18377. t['\uFC77'] = '\u062B\u0632';
  18378. t['\uFC78'] = '\u062B\u0645';
  18379. t['\uFC79'] = '\u062B\u0646';
  18380. t['\uFC7A'] = '\u062B\u0649';
  18381. t['\uFC7B'] = '\u062B\u064A';
  18382. t['\uFC7C'] = '\u0641\u0649';
  18383. t['\uFC7D'] = '\u0641\u064A';
  18384. t['\uFC7E'] = '\u0642\u0649';
  18385. t['\uFC7F'] = '\u0642\u064A';
  18386. t['\uFC80'] = '\u0643\u0627';
  18387. t['\uFC81'] = '\u0643\u0644';
  18388. t['\uFC82'] = '\u0643\u0645';
  18389. t['\uFC83'] = '\u0643\u0649';
  18390. t['\uFC84'] = '\u0643\u064A';
  18391. t['\uFC85'] = '\u0644\u0645';
  18392. t['\uFC86'] = '\u0644\u0649';
  18393. t['\uFC87'] = '\u0644\u064A';
  18394. t['\uFC88'] = '\u0645\u0627';
  18395. t['\uFC89'] = '\u0645\u0645';
  18396. t['\uFC8A'] = '\u0646\u0631';
  18397. t['\uFC8B'] = '\u0646\u0632';
  18398. t['\uFC8C'] = '\u0646\u0645';
  18399. t['\uFC8D'] = '\u0646\u0646';
  18400. t['\uFC8E'] = '\u0646\u0649';
  18401. t['\uFC8F'] = '\u0646\u064A';
  18402. t['\uFC90'] = '\u0649\u0670';
  18403. t['\uFC91'] = '\u064A\u0631';
  18404. t['\uFC92'] = '\u064A\u0632';
  18405. t['\uFC93'] = '\u064A\u0645';
  18406. t['\uFC94'] = '\u064A\u0646';
  18407. t['\uFC95'] = '\u064A\u0649';
  18408. t['\uFC96'] = '\u064A\u064A';
  18409. t['\uFC97'] = '\u0626\u062C';
  18410. t['\uFC98'] = '\u0626\u062D';
  18411. t['\uFC99'] = '\u0626\u062E';
  18412. t['\uFC9A'] = '\u0626\u0645';
  18413. t['\uFC9B'] = '\u0626\u0647';
  18414. t['\uFC9C'] = '\u0628\u062C';
  18415. t['\uFC9D'] = '\u0628\u062D';
  18416. t['\uFC9E'] = '\u0628\u062E';
  18417. t['\uFC9F'] = '\u0628\u0645';
  18418. t['\uFCA0'] = '\u0628\u0647';
  18419. t['\uFCA1'] = '\u062A\u062C';
  18420. t['\uFCA2'] = '\u062A\u062D';
  18421. t['\uFCA3'] = '\u062A\u062E';
  18422. t['\uFCA4'] = '\u062A\u0645';
  18423. t['\uFCA5'] = '\u062A\u0647';
  18424. t['\uFCA6'] = '\u062B\u0645';
  18425. t['\uFCA7'] = '\u062C\u062D';
  18426. t['\uFCA8'] = '\u062C\u0645';
  18427. t['\uFCA9'] = '\u062D\u062C';
  18428. t['\uFCAA'] = '\u062D\u0645';
  18429. t['\uFCAB'] = '\u062E\u062C';
  18430. t['\uFCAC'] = '\u062E\u0645';
  18431. t['\uFCAD'] = '\u0633\u062C';
  18432. t['\uFCAE'] = '\u0633\u062D';
  18433. t['\uFCAF'] = '\u0633\u062E';
  18434. t['\uFCB0'] = '\u0633\u0645';
  18435. t['\uFCB1'] = '\u0635\u062D';
  18436. t['\uFCB2'] = '\u0635\u062E';
  18437. t['\uFCB3'] = '\u0635\u0645';
  18438. t['\uFCB4'] = '\u0636\u062C';
  18439. t['\uFCB5'] = '\u0636\u062D';
  18440. t['\uFCB6'] = '\u0636\u062E';
  18441. t['\uFCB7'] = '\u0636\u0645';
  18442. t['\uFCB8'] = '\u0637\u062D';
  18443. t['\uFCB9'] = '\u0638\u0645';
  18444. t['\uFCBA'] = '\u0639\u062C';
  18445. t['\uFCBB'] = '\u0639\u0645';
  18446. t['\uFCBC'] = '\u063A\u062C';
  18447. t['\uFCBD'] = '\u063A\u0645';
  18448. t['\uFCBE'] = '\u0641\u062C';
  18449. t['\uFCBF'] = '\u0641\u062D';
  18450. t['\uFCC0'] = '\u0641\u062E';
  18451. t['\uFCC1'] = '\u0641\u0645';
  18452. t['\uFCC2'] = '\u0642\u062D';
  18453. t['\uFCC3'] = '\u0642\u0645';
  18454. t['\uFCC4'] = '\u0643\u062C';
  18455. t['\uFCC5'] = '\u0643\u062D';
  18456. t['\uFCC6'] = '\u0643\u062E';
  18457. t['\uFCC7'] = '\u0643\u0644';
  18458. t['\uFCC8'] = '\u0643\u0645';
  18459. t['\uFCC9'] = '\u0644\u062C';
  18460. t['\uFCCA'] = '\u0644\u062D';
  18461. t['\uFCCB'] = '\u0644\u062E';
  18462. t['\uFCCC'] = '\u0644\u0645';
  18463. t['\uFCCD'] = '\u0644\u0647';
  18464. t['\uFCCE'] = '\u0645\u062C';
  18465. t['\uFCCF'] = '\u0645\u062D';
  18466. t['\uFCD0'] = '\u0645\u062E';
  18467. t['\uFCD1'] = '\u0645\u0645';
  18468. t['\uFCD2'] = '\u0646\u062C';
  18469. t['\uFCD3'] = '\u0646\u062D';
  18470. t['\uFCD4'] = '\u0646\u062E';
  18471. t['\uFCD5'] = '\u0646\u0645';
  18472. t['\uFCD6'] = '\u0646\u0647';
  18473. t['\uFCD7'] = '\u0647\u062C';
  18474. t['\uFCD8'] = '\u0647\u0645';
  18475. t['\uFCD9'] = '\u0647\u0670';
  18476. t['\uFCDA'] = '\u064A\u062C';
  18477. t['\uFCDB'] = '\u064A\u062D';
  18478. t['\uFCDC'] = '\u064A\u062E';
  18479. t['\uFCDD'] = '\u064A\u0645';
  18480. t['\uFCDE'] = '\u064A\u0647';
  18481. t['\uFCDF'] = '\u0626\u0645';
  18482. t['\uFCE0'] = '\u0626\u0647';
  18483. t['\uFCE1'] = '\u0628\u0645';
  18484. t['\uFCE2'] = '\u0628\u0647';
  18485. t['\uFCE3'] = '\u062A\u0645';
  18486. t['\uFCE4'] = '\u062A\u0647';
  18487. t['\uFCE5'] = '\u062B\u0645';
  18488. t['\uFCE6'] = '\u062B\u0647';
  18489. t['\uFCE7'] = '\u0633\u0645';
  18490. t['\uFCE8'] = '\u0633\u0647';
  18491. t['\uFCE9'] = '\u0634\u0645';
  18492. t['\uFCEA'] = '\u0634\u0647';
  18493. t['\uFCEB'] = '\u0643\u0644';
  18494. t['\uFCEC'] = '\u0643\u0645';
  18495. t['\uFCED'] = '\u0644\u0645';
  18496. t['\uFCEE'] = '\u0646\u0645';
  18497. t['\uFCEF'] = '\u0646\u0647';
  18498. t['\uFCF0'] = '\u064A\u0645';
  18499. t['\uFCF1'] = '\u064A\u0647';
  18500. t['\uFCF2'] = '\u0640\u064E\u0651';
  18501. t['\uFCF3'] = '\u0640\u064F\u0651';
  18502. t['\uFCF4'] = '\u0640\u0650\u0651';
  18503. t['\uFCF5'] = '\u0637\u0649';
  18504. t['\uFCF6'] = '\u0637\u064A';
  18505. t['\uFCF7'] = '\u0639\u0649';
  18506. t['\uFCF8'] = '\u0639\u064A';
  18507. t['\uFCF9'] = '\u063A\u0649';
  18508. t['\uFCFA'] = '\u063A\u064A';
  18509. t['\uFCFB'] = '\u0633\u0649';
  18510. t['\uFCFC'] = '\u0633\u064A';
  18511. t['\uFCFD'] = '\u0634\u0649';
  18512. t['\uFCFE'] = '\u0634\u064A';
  18513. t['\uFCFF'] = '\u062D\u0649';
  18514. t['\uFD00'] = '\u062D\u064A';
  18515. t['\uFD01'] = '\u062C\u0649';
  18516. t['\uFD02'] = '\u062C\u064A';
  18517. t['\uFD03'] = '\u062E\u0649';
  18518. t['\uFD04'] = '\u062E\u064A';
  18519. t['\uFD05'] = '\u0635\u0649';
  18520. t['\uFD06'] = '\u0635\u064A';
  18521. t['\uFD07'] = '\u0636\u0649';
  18522. t['\uFD08'] = '\u0636\u064A';
  18523. t['\uFD09'] = '\u0634\u062C';
  18524. t['\uFD0A'] = '\u0634\u062D';
  18525. t['\uFD0B'] = '\u0634\u062E';
  18526. t['\uFD0C'] = '\u0634\u0645';
  18527. t['\uFD0D'] = '\u0634\u0631';
  18528. t['\uFD0E'] = '\u0633\u0631';
  18529. t['\uFD0F'] = '\u0635\u0631';
  18530. t['\uFD10'] = '\u0636\u0631';
  18531. t['\uFD11'] = '\u0637\u0649';
  18532. t['\uFD12'] = '\u0637\u064A';
  18533. t['\uFD13'] = '\u0639\u0649';
  18534. t['\uFD14'] = '\u0639\u064A';
  18535. t['\uFD15'] = '\u063A\u0649';
  18536. t['\uFD16'] = '\u063A\u064A';
  18537. t['\uFD17'] = '\u0633\u0649';
  18538. t['\uFD18'] = '\u0633\u064A';
  18539. t['\uFD19'] = '\u0634\u0649';
  18540. t['\uFD1A'] = '\u0634\u064A';
  18541. t['\uFD1B'] = '\u062D\u0649';
  18542. t['\uFD1C'] = '\u062D\u064A';
  18543. t['\uFD1D'] = '\u062C\u0649';
  18544. t['\uFD1E'] = '\u062C\u064A';
  18545. t['\uFD1F'] = '\u062E\u0649';
  18546. t['\uFD20'] = '\u062E\u064A';
  18547. t['\uFD21'] = '\u0635\u0649';
  18548. t['\uFD22'] = '\u0635\u064A';
  18549. t['\uFD23'] = '\u0636\u0649';
  18550. t['\uFD24'] = '\u0636\u064A';
  18551. t['\uFD25'] = '\u0634\u062C';
  18552. t['\uFD26'] = '\u0634\u062D';
  18553. t['\uFD27'] = '\u0634\u062E';
  18554. t['\uFD28'] = '\u0634\u0645';
  18555. t['\uFD29'] = '\u0634\u0631';
  18556. t['\uFD2A'] = '\u0633\u0631';
  18557. t['\uFD2B'] = '\u0635\u0631';
  18558. t['\uFD2C'] = '\u0636\u0631';
  18559. t['\uFD2D'] = '\u0634\u062C';
  18560. t['\uFD2E'] = '\u0634\u062D';
  18561. t['\uFD2F'] = '\u0634\u062E';
  18562. t['\uFD30'] = '\u0634\u0645';
  18563. t['\uFD31'] = '\u0633\u0647';
  18564. t['\uFD32'] = '\u0634\u0647';
  18565. t['\uFD33'] = '\u0637\u0645';
  18566. t['\uFD34'] = '\u0633\u062C';
  18567. t['\uFD35'] = '\u0633\u062D';
  18568. t['\uFD36'] = '\u0633\u062E';
  18569. t['\uFD37'] = '\u0634\u062C';
  18570. t['\uFD38'] = '\u0634\u062D';
  18571. t['\uFD39'] = '\u0634\u062E';
  18572. t['\uFD3A'] = '\u0637\u0645';
  18573. t['\uFD3B'] = '\u0638\u0645';
  18574. t['\uFD3C'] = '\u0627\u064B';
  18575. t['\uFD3D'] = '\u0627\u064B';
  18576. t['\uFD50'] = '\u062A\u062C\u0645';
  18577. t['\uFD51'] = '\u062A\u062D\u062C';
  18578. t['\uFD52'] = '\u062A\u062D\u062C';
  18579. t['\uFD53'] = '\u062A\u062D\u0645';
  18580. t['\uFD54'] = '\u062A\u062E\u0645';
  18581. t['\uFD55'] = '\u062A\u0645\u062C';
  18582. t['\uFD56'] = '\u062A\u0645\u062D';
  18583. t['\uFD57'] = '\u062A\u0645\u062E';
  18584. t['\uFD58'] = '\u062C\u0645\u062D';
  18585. t['\uFD59'] = '\u062C\u0645\u062D';
  18586. t['\uFD5A'] = '\u062D\u0645\u064A';
  18587. t['\uFD5B'] = '\u062D\u0645\u0649';
  18588. t['\uFD5C'] = '\u0633\u062D\u062C';
  18589. t['\uFD5D'] = '\u0633\u062C\u062D';
  18590. t['\uFD5E'] = '\u0633\u062C\u0649';
  18591. t['\uFD5F'] = '\u0633\u0645\u062D';
  18592. t['\uFD60'] = '\u0633\u0645\u062D';
  18593. t['\uFD61'] = '\u0633\u0645\u062C';
  18594. t['\uFD62'] = '\u0633\u0645\u0645';
  18595. t['\uFD63'] = '\u0633\u0645\u0645';
  18596. t['\uFD64'] = '\u0635\u062D\u062D';
  18597. t['\uFD65'] = '\u0635\u062D\u062D';
  18598. t['\uFD66'] = '\u0635\u0645\u0645';
  18599. t['\uFD67'] = '\u0634\u062D\u0645';
  18600. t['\uFD68'] = '\u0634\u062D\u0645';
  18601. t['\uFD69'] = '\u0634\u062C\u064A';
  18602. t['\uFD6A'] = '\u0634\u0645\u062E';
  18603. t['\uFD6B'] = '\u0634\u0645\u062E';
  18604. t['\uFD6C'] = '\u0634\u0645\u0645';
  18605. t['\uFD6D'] = '\u0634\u0645\u0645';
  18606. t['\uFD6E'] = '\u0636\u062D\u0649';
  18607. t['\uFD6F'] = '\u0636\u062E\u0645';
  18608. t['\uFD70'] = '\u0636\u062E\u0645';
  18609. t['\uFD71'] = '\u0637\u0645\u062D';
  18610. t['\uFD72'] = '\u0637\u0645\u062D';
  18611. t['\uFD73'] = '\u0637\u0645\u0645';
  18612. t['\uFD74'] = '\u0637\u0645\u064A';
  18613. t['\uFD75'] = '\u0639\u062C\u0645';
  18614. t['\uFD76'] = '\u0639\u0645\u0645';
  18615. t['\uFD77'] = '\u0639\u0645\u0645';
  18616. t['\uFD78'] = '\u0639\u0645\u0649';
  18617. t['\uFD79'] = '\u063A\u0645\u0645';
  18618. t['\uFD7A'] = '\u063A\u0645\u064A';
  18619. t['\uFD7B'] = '\u063A\u0645\u0649';
  18620. t['\uFD7C'] = '\u0641\u062E\u0645';
  18621. t['\uFD7D'] = '\u0641\u062E\u0645';
  18622. t['\uFD7E'] = '\u0642\u0645\u062D';
  18623. t['\uFD7F'] = '\u0642\u0645\u0645';
  18624. t['\uFD80'] = '\u0644\u062D\u0645';
  18625. t['\uFD81'] = '\u0644\u062D\u064A';
  18626. t['\uFD82'] = '\u0644\u062D\u0649';
  18627. t['\uFD83'] = '\u0644\u062C\u062C';
  18628. t['\uFD84'] = '\u0644\u062C\u062C';
  18629. t['\uFD85'] = '\u0644\u062E\u0645';
  18630. t['\uFD86'] = '\u0644\u062E\u0645';
  18631. t['\uFD87'] = '\u0644\u0645\u062D';
  18632. t['\uFD88'] = '\u0644\u0645\u062D';
  18633. t['\uFD89'] = '\u0645\u062D\u062C';
  18634. t['\uFD8A'] = '\u0645\u062D\u0645';
  18635. t['\uFD8B'] = '\u0645\u062D\u064A';
  18636. t['\uFD8C'] = '\u0645\u062C\u062D';
  18637. t['\uFD8D'] = '\u0645\u062C\u0645';
  18638. t['\uFD8E'] = '\u0645\u062E\u062C';
  18639. t['\uFD8F'] = '\u0645\u062E\u0645';
  18640. t['\uFD92'] = '\u0645\u062C\u062E';
  18641. t['\uFD93'] = '\u0647\u0645\u062C';
  18642. t['\uFD94'] = '\u0647\u0645\u0645';
  18643. t['\uFD95'] = '\u0646\u062D\u0645';
  18644. t['\uFD96'] = '\u0646\u062D\u0649';
  18645. t['\uFD97'] = '\u0646\u062C\u0645';
  18646. t['\uFD98'] = '\u0646\u062C\u0645';
  18647. t['\uFD99'] = '\u0646\u062C\u0649';
  18648. t['\uFD9A'] = '\u0646\u0645\u064A';
  18649. t['\uFD9B'] = '\u0646\u0645\u0649';
  18650. t['\uFD9C'] = '\u064A\u0645\u0645';
  18651. t['\uFD9D'] = '\u064A\u0645\u0645';
  18652. t['\uFD9E'] = '\u0628\u062E\u064A';
  18653. t['\uFD9F'] = '\u062A\u062C\u064A';
  18654. t['\uFDA0'] = '\u062A\u062C\u0649';
  18655. t['\uFDA1'] = '\u062A\u062E\u064A';
  18656. t['\uFDA2'] = '\u062A\u062E\u0649';
  18657. t['\uFDA3'] = '\u062A\u0645\u064A';
  18658. t['\uFDA4'] = '\u062A\u0645\u0649';
  18659. t['\uFDA5'] = '\u062C\u0645\u064A';
  18660. t['\uFDA6'] = '\u062C\u062D\u0649';
  18661. t['\uFDA7'] = '\u062C\u0645\u0649';
  18662. t['\uFDA8'] = '\u0633\u062E\u0649';
  18663. t['\uFDA9'] = '\u0635\u062D\u064A';
  18664. t['\uFDAA'] = '\u0634\u062D\u064A';
  18665. t['\uFDAB'] = '\u0636\u062D\u064A';
  18666. t['\uFDAC'] = '\u0644\u062C\u064A';
  18667. t['\uFDAD'] = '\u0644\u0645\u064A';
  18668. t['\uFDAE'] = '\u064A\u062D\u064A';
  18669. t['\uFDAF'] = '\u064A\u062C\u064A';
  18670. t['\uFDB0'] = '\u064A\u0645\u064A';
  18671. t['\uFDB1'] = '\u0645\u0645\u064A';
  18672. t['\uFDB2'] = '\u0642\u0645\u064A';
  18673. t['\uFDB3'] = '\u0646\u062D\u064A';
  18674. t['\uFDB4'] = '\u0642\u0645\u062D';
  18675. t['\uFDB5'] = '\u0644\u062D\u0645';
  18676. t['\uFDB6'] = '\u0639\u0645\u064A';
  18677. t['\uFDB7'] = '\u0643\u0645\u064A';
  18678. t['\uFDB8'] = '\u0646\u062C\u062D';
  18679. t['\uFDB9'] = '\u0645\u062E\u064A';
  18680. t['\uFDBA'] = '\u0644\u062C\u0645';
  18681. t['\uFDBB'] = '\u0643\u0645\u0645';
  18682. t['\uFDBC'] = '\u0644\u062C\u0645';
  18683. t['\uFDBD'] = '\u0646\u062C\u062D';
  18684. t['\uFDBE'] = '\u062C\u062D\u064A';
  18685. t['\uFDBF'] = '\u062D\u062C\u064A';
  18686. t['\uFDC0'] = '\u0645\u062C\u064A';
  18687. t['\uFDC1'] = '\u0641\u0645\u064A';
  18688. t['\uFDC2'] = '\u0628\u062D\u064A';
  18689. t['\uFDC3'] = '\u0643\u0645\u0645';
  18690. t['\uFDC4'] = '\u0639\u062C\u0645';
  18691. t['\uFDC5'] = '\u0635\u0645\u0645';
  18692. t['\uFDC6'] = '\u0633\u062E\u064A';
  18693. t['\uFDC7'] = '\u0646\u062C\u064A';
  18694. t['\uFE49'] = '\u203E';
  18695. t['\uFE4A'] = '\u203E';
  18696. t['\uFE4B'] = '\u203E';
  18697. t['\uFE4C'] = '\u203E';
  18698. t['\uFE4D'] = '\u005F';
  18699. t['\uFE4E'] = '\u005F';
  18700. t['\uFE4F'] = '\u005F';
  18701. t['\uFE80'] = '\u0621';
  18702. t['\uFE81'] = '\u0622';
  18703. t['\uFE82'] = '\u0622';
  18704. t['\uFE83'] = '\u0623';
  18705. t['\uFE84'] = '\u0623';
  18706. t['\uFE85'] = '\u0624';
  18707. t['\uFE86'] = '\u0624';
  18708. t['\uFE87'] = '\u0625';
  18709. t['\uFE88'] = '\u0625';
  18710. t['\uFE89'] = '\u0626';
  18711. t['\uFE8A'] = '\u0626';
  18712. t['\uFE8B'] = '\u0626';
  18713. t['\uFE8C'] = '\u0626';
  18714. t['\uFE8D'] = '\u0627';
  18715. t['\uFE8E'] = '\u0627';
  18716. t['\uFE8F'] = '\u0628';
  18717. t['\uFE90'] = '\u0628';
  18718. t['\uFE91'] = '\u0628';
  18719. t['\uFE92'] = '\u0628';
  18720. t['\uFE93'] = '\u0629';
  18721. t['\uFE94'] = '\u0629';
  18722. t['\uFE95'] = '\u062A';
  18723. t['\uFE96'] = '\u062A';
  18724. t['\uFE97'] = '\u062A';
  18725. t['\uFE98'] = '\u062A';
  18726. t['\uFE99'] = '\u062B';
  18727. t['\uFE9A'] = '\u062B';
  18728. t['\uFE9B'] = '\u062B';
  18729. t['\uFE9C'] = '\u062B';
  18730. t['\uFE9D'] = '\u062C';
  18731. t['\uFE9E'] = '\u062C';
  18732. t['\uFE9F'] = '\u062C';
  18733. t['\uFEA0'] = '\u062C';
  18734. t['\uFEA1'] = '\u062D';
  18735. t['\uFEA2'] = '\u062D';
  18736. t['\uFEA3'] = '\u062D';
  18737. t['\uFEA4'] = '\u062D';
  18738. t['\uFEA5'] = '\u062E';
  18739. t['\uFEA6'] = '\u062E';
  18740. t['\uFEA7'] = '\u062E';
  18741. t['\uFEA8'] = '\u062E';
  18742. t['\uFEA9'] = '\u062F';
  18743. t['\uFEAA'] = '\u062F';
  18744. t['\uFEAB'] = '\u0630';
  18745. t['\uFEAC'] = '\u0630';
  18746. t['\uFEAD'] = '\u0631';
  18747. t['\uFEAE'] = '\u0631';
  18748. t['\uFEAF'] = '\u0632';
  18749. t['\uFEB0'] = '\u0632';
  18750. t['\uFEB1'] = '\u0633';
  18751. t['\uFEB2'] = '\u0633';
  18752. t['\uFEB3'] = '\u0633';
  18753. t['\uFEB4'] = '\u0633';
  18754. t['\uFEB5'] = '\u0634';
  18755. t['\uFEB6'] = '\u0634';
  18756. t['\uFEB7'] = '\u0634';
  18757. t['\uFEB8'] = '\u0634';
  18758. t['\uFEB9'] = '\u0635';
  18759. t['\uFEBA'] = '\u0635';
  18760. t['\uFEBB'] = '\u0635';
  18761. t['\uFEBC'] = '\u0635';
  18762. t['\uFEBD'] = '\u0636';
  18763. t['\uFEBE'] = '\u0636';
  18764. t['\uFEBF'] = '\u0636';
  18765. t['\uFEC0'] = '\u0636';
  18766. t['\uFEC1'] = '\u0637';
  18767. t['\uFEC2'] = '\u0637';
  18768. t['\uFEC3'] = '\u0637';
  18769. t['\uFEC4'] = '\u0637';
  18770. t['\uFEC5'] = '\u0638';
  18771. t['\uFEC6'] = '\u0638';
  18772. t['\uFEC7'] = '\u0638';
  18773. t['\uFEC8'] = '\u0638';
  18774. t['\uFEC9'] = '\u0639';
  18775. t['\uFECA'] = '\u0639';
  18776. t['\uFECB'] = '\u0639';
  18777. t['\uFECC'] = '\u0639';
  18778. t['\uFECD'] = '\u063A';
  18779. t['\uFECE'] = '\u063A';
  18780. t['\uFECF'] = '\u063A';
  18781. t['\uFED0'] = '\u063A';
  18782. t['\uFED1'] = '\u0641';
  18783. t['\uFED2'] = '\u0641';
  18784. t['\uFED3'] = '\u0641';
  18785. t['\uFED4'] = '\u0641';
  18786. t['\uFED5'] = '\u0642';
  18787. t['\uFED6'] = '\u0642';
  18788. t['\uFED7'] = '\u0642';
  18789. t['\uFED8'] = '\u0642';
  18790. t['\uFED9'] = '\u0643';
  18791. t['\uFEDA'] = '\u0643';
  18792. t['\uFEDB'] = '\u0643';
  18793. t['\uFEDC'] = '\u0643';
  18794. t['\uFEDD'] = '\u0644';
  18795. t['\uFEDE'] = '\u0644';
  18796. t['\uFEDF'] = '\u0644';
  18797. t['\uFEE0'] = '\u0644';
  18798. t['\uFEE1'] = '\u0645';
  18799. t['\uFEE2'] = '\u0645';
  18800. t['\uFEE3'] = '\u0645';
  18801. t['\uFEE4'] = '\u0645';
  18802. t['\uFEE5'] = '\u0646';
  18803. t['\uFEE6'] = '\u0646';
  18804. t['\uFEE7'] = '\u0646';
  18805. t['\uFEE8'] = '\u0646';
  18806. t['\uFEE9'] = '\u0647';
  18807. t['\uFEEA'] = '\u0647';
  18808. t['\uFEEB'] = '\u0647';
  18809. t['\uFEEC'] = '\u0647';
  18810. t['\uFEED'] = '\u0648';
  18811. t['\uFEEE'] = '\u0648';
  18812. t['\uFEEF'] = '\u0649';
  18813. t['\uFEF0'] = '\u0649';
  18814. t['\uFEF1'] = '\u064A';
  18815. t['\uFEF2'] = '\u064A';
  18816. t['\uFEF3'] = '\u064A';
  18817. t['\uFEF4'] = '\u064A';
  18818. t['\uFEF5'] = '\u0644\u0622';
  18819. t['\uFEF6'] = '\u0644\u0622';
  18820. t['\uFEF7'] = '\u0644\u0623';
  18821. t['\uFEF8'] = '\u0644\u0623';
  18822. t['\uFEF9'] = '\u0644\u0625';
  18823. t['\uFEFA'] = '\u0644\u0625';
  18824. t['\uFEFB'] = '\u0644\u0627';
  18825. t['\uFEFC'] = '\u0644\u0627';
  18826. });
  18827. function reverseIfRtl(chars) {
  18828. var charsLength = chars.length;
  18829. //reverse an arabic ligature
  18830. if (charsLength <= 1 || !isRTLRangeFor(chars.charCodeAt(0))) {
  18831. return chars;
  18832. }
  18833. var s = '';
  18834. for (var ii = charsLength - 1; ii >= 0; ii--) {
  18835. s += chars[ii];
  18836. }
  18837. return s;
  18838. }
  18839. exports.mapSpecialUnicodeValues = mapSpecialUnicodeValues;
  18840. exports.reverseIfRtl = reverseIfRtl;
  18841. exports.getUnicodeRangeFor = getUnicodeRangeFor;
  18842. exports.getNormalizedUnicodes = getNormalizedUnicodes;
  18843. exports.getUnicodeForGlyph = getUnicodeForGlyph;
  18844. }));
  18845. (function (root, factory) {
  18846. {
  18847. factory((root.pdfjsDisplayGlobal = {}), root.pdfjsSharedUtil);
  18848. }
  18849. }(this, function (exports, sharedUtil) {
  18850. var globalScope = sharedUtil.globalScope;
  18851. var isWorker = (typeof window === 'undefined');
  18852. // The global PDFJS object exposes the API
  18853. // In production, it will be declared outside a global wrapper
  18854. // In development, it will be declared here
  18855. if (!globalScope.PDFJS) {
  18856. globalScope.PDFJS = {};
  18857. }
  18858. var PDFJS = globalScope.PDFJS;
  18859. if (typeof pdfjsVersion !== 'undefined') {
  18860. PDFJS.version = pdfjsVersion;
  18861. }
  18862. if (typeof pdfjsBuild !== 'undefined') {
  18863. PDFJS.build = pdfjsBuild;
  18864. }
  18865. PDFJS.pdfBug = false;
  18866. if (PDFJS.verbosity !== undefined) {
  18867. sharedUtil.setVerbosityLevel(PDFJS.verbosity);
  18868. }
  18869. delete PDFJS.verbosity;
  18870. Object.defineProperty(PDFJS, 'verbosity', {
  18871. get: function () { return sharedUtil.getVerbosityLevel(); },
  18872. set: function (level) { sharedUtil.setVerbosityLevel(level); },
  18873. enumerable: true,
  18874. configurable: true
  18875. });
  18876. PDFJS.VERBOSITY_LEVELS = sharedUtil.VERBOSITY_LEVELS;
  18877. PDFJS.OPS = sharedUtil.OPS;
  18878. PDFJS.UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  18879. PDFJS.isValidUrl = sharedUtil.isValidUrl;
  18880. PDFJS.shadow = sharedUtil.shadow;
  18881. PDFJS.createBlob = sharedUtil.createBlob;
  18882. PDFJS.createObjectURL = function PDFJS_createObjectURL(data, contentType) {
  18883. return sharedUtil.createObjectURL(data, contentType,
  18884. PDFJS.disableCreateObjectURL);
  18885. };
  18886. Object.defineProperty(PDFJS, 'isLittleEndian', {
  18887. configurable: true,
  18888. get: function PDFJS_isLittleEndian() {
  18889. var value = sharedUtil.isLittleEndian();
  18890. return sharedUtil.shadow(PDFJS, 'isLittleEndian', value);
  18891. }
  18892. });
  18893. PDFJS.removeNullCharacters = sharedUtil.removeNullCharacters;
  18894. PDFJS.PasswordResponses = sharedUtil.PasswordResponses;
  18895. PDFJS.PasswordException = sharedUtil.PasswordException;
  18896. PDFJS.UnknownErrorException = sharedUtil.UnknownErrorException;
  18897. PDFJS.InvalidPDFException = sharedUtil.InvalidPDFException;
  18898. PDFJS.MissingPDFException = sharedUtil.MissingPDFException;
  18899. PDFJS.UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  18900. PDFJS.Util = sharedUtil.Util;
  18901. PDFJS.PageViewport = sharedUtil.PageViewport;
  18902. PDFJS.createPromiseCapability = sharedUtil.createPromiseCapability;
  18903. exports.globalScope = globalScope;
  18904. exports.isWorker = isWorker;
  18905. exports.PDFJS = globalScope.PDFJS;
  18906. }));
  18907. (function (root, factory) {
  18908. {
  18909. factory((root.pdfjsCoreStream = {}), root.pdfjsSharedUtil,
  18910. root.pdfjsCorePrimitives, root.pdfjsCoreJbig2, root.pdfjsCoreJpg,
  18911. root.pdfjsCoreJpx);
  18912. }
  18913. }(this, function (exports, sharedUtil, corePrimitives, coreJbig2, coreJpg,
  18914. coreJpx) {
  18915. var Util = sharedUtil.Util;
  18916. var error = sharedUtil.error;
  18917. var info = sharedUtil.info;
  18918. var isArray = sharedUtil.isArray;
  18919. var createObjectURL = sharedUtil.createObjectURL;
  18920. var shadow = sharedUtil.shadow;
  18921. var warn = sharedUtil.warn;
  18922. var Dict = corePrimitives.Dict;
  18923. var Jbig2Image = coreJbig2.Jbig2Image;
  18924. var JpegImage = coreJpg.JpegImage;
  18925. var JpxImage = coreJpx.JpxImage;
  18926. var Stream = (function StreamClosure() {
  18927. function Stream(arrayBuffer, start, length, dict) {
  18928. this.bytes = (arrayBuffer instanceof Uint8Array ?
  18929. arrayBuffer : new Uint8Array(arrayBuffer));
  18930. this.start = start || 0;
  18931. this.pos = this.start;
  18932. this.end = (start + length) || this.bytes.length;
  18933. this.dict = dict;
  18934. }
  18935. // required methods for a stream. if a particular stream does not
  18936. // implement these, an error should be thrown
  18937. Stream.prototype = {
  18938. get length() {
  18939. return this.end - this.start;
  18940. },
  18941. get isEmpty() {
  18942. return this.length === 0;
  18943. },
  18944. getByte: function Stream_getByte() {
  18945. if (this.pos >= this.end) {
  18946. return -1;
  18947. }
  18948. return this.bytes[this.pos++];
  18949. },
  18950. getUint16: function Stream_getUint16() {
  18951. var b0 = this.getByte();
  18952. var b1 = this.getByte();
  18953. if (b0 === -1 || b1 === -1) {
  18954. return -1;
  18955. }
  18956. return (b0 << 8) + b1;
  18957. },
  18958. getInt32: function Stream_getInt32() {
  18959. var b0 = this.getByte();
  18960. var b1 = this.getByte();
  18961. var b2 = this.getByte();
  18962. var b3 = this.getByte();
  18963. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  18964. },
  18965. // returns subarray of original buffer
  18966. // should only be read
  18967. getBytes: function Stream_getBytes(length) {
  18968. var bytes = this.bytes;
  18969. var pos = this.pos;
  18970. var strEnd = this.end;
  18971. if (!length) {
  18972. return bytes.subarray(pos, strEnd);
  18973. }
  18974. var end = pos + length;
  18975. if (end > strEnd) {
  18976. end = strEnd;
  18977. }
  18978. this.pos = end;
  18979. return bytes.subarray(pos, end);
  18980. },
  18981. peekByte: function Stream_peekByte() {
  18982. var peekedByte = this.getByte();
  18983. this.pos--;
  18984. return peekedByte;
  18985. },
  18986. peekBytes: function Stream_peekBytes(length) {
  18987. var bytes = this.getBytes(length);
  18988. this.pos -= bytes.length;
  18989. return bytes;
  18990. },
  18991. skip: function Stream_skip(n) {
  18992. if (!n) {
  18993. n = 1;
  18994. }
  18995. this.pos += n;
  18996. },
  18997. reset: function Stream_reset() {
  18998. this.pos = this.start;
  18999. },
  19000. moveStart: function Stream_moveStart() {
  19001. this.start = this.pos;
  19002. },
  19003. makeSubStream: function Stream_makeSubStream(start, length, dict) {
  19004. return new Stream(this.bytes.buffer, start, length, dict);
  19005. },
  19006. isStream: true
  19007. };
  19008. return Stream;
  19009. })();
  19010. var StringStream = (function StringStreamClosure() {
  19011. function StringStream(str) {
  19012. var length = str.length;
  19013. var bytes = new Uint8Array(length);
  19014. for (var n = 0; n < length; ++n) {
  19015. bytes[n] = str.charCodeAt(n);
  19016. }
  19017. Stream.call(this, bytes);
  19018. }
  19019. StringStream.prototype = Stream.prototype;
  19020. return StringStream;
  19021. })();
  19022. // super class for the decoding streams
  19023. var DecodeStream = (function DecodeStreamClosure() {
  19024. // Lots of DecodeStreams are created whose buffers are never used. For these
  19025. // we share a single empty buffer. This is (a) space-efficient and (b) avoids
  19026. // having special cases that would be required if we used |null| for an empty
  19027. // buffer.
  19028. var emptyBuffer = new Uint8Array(0);
  19029. function DecodeStream(maybeMinBufferLength) {
  19030. this.pos = 0;
  19031. this.bufferLength = 0;
  19032. this.eof = false;
  19033. this.buffer = emptyBuffer;
  19034. this.minBufferLength = 512;
  19035. if (maybeMinBufferLength) {
  19036. // Compute the first power of two that is as big as maybeMinBufferLength.
  19037. while (this.minBufferLength < maybeMinBufferLength) {
  19038. this.minBufferLength *= 2;
  19039. }
  19040. }
  19041. }
  19042. DecodeStream.prototype = {
  19043. get isEmpty() {
  19044. while (!this.eof && this.bufferLength === 0) {
  19045. this.readBlock();
  19046. }
  19047. return this.bufferLength === 0;
  19048. },
  19049. ensureBuffer: function DecodeStream_ensureBuffer(requested) {
  19050. var buffer = this.buffer;
  19051. if (requested <= buffer.byteLength) {
  19052. return buffer;
  19053. }
  19054. var size = this.minBufferLength;
  19055. while (size < requested) {
  19056. size *= 2;
  19057. }
  19058. var buffer2 = new Uint8Array(size);
  19059. buffer2.set(buffer);
  19060. return (this.buffer = buffer2);
  19061. },
  19062. getByte: function DecodeStream_getByte() {
  19063. var pos = this.pos;
  19064. while (this.bufferLength <= pos) {
  19065. if (this.eof) {
  19066. return -1;
  19067. }
  19068. this.readBlock();
  19069. }
  19070. return this.buffer[this.pos++];
  19071. },
  19072. getUint16: function DecodeStream_getUint16() {
  19073. var b0 = this.getByte();
  19074. var b1 = this.getByte();
  19075. if (b0 === -1 || b1 === -1) {
  19076. return -1;
  19077. }
  19078. return (b0 << 8) + b1;
  19079. },
  19080. getInt32: function DecodeStream_getInt32() {
  19081. var b0 = this.getByte();
  19082. var b1 = this.getByte();
  19083. var b2 = this.getByte();
  19084. var b3 = this.getByte();
  19085. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  19086. },
  19087. getBytes: function DecodeStream_getBytes(length) {
  19088. var end, pos = this.pos;
  19089. if (length) {
  19090. this.ensureBuffer(pos + length);
  19091. end = pos + length;
  19092. while (!this.eof && this.bufferLength < end) {
  19093. this.readBlock();
  19094. }
  19095. var bufEnd = this.bufferLength;
  19096. if (end > bufEnd) {
  19097. end = bufEnd;
  19098. }
  19099. } else {
  19100. while (!this.eof) {
  19101. this.readBlock();
  19102. }
  19103. end = this.bufferLength;
  19104. }
  19105. this.pos = end;
  19106. return this.buffer.subarray(pos, end);
  19107. },
  19108. peekByte: function DecodeStream_peekByte() {
  19109. var peekedByte = this.getByte();
  19110. this.pos--;
  19111. return peekedByte;
  19112. },
  19113. peekBytes: function DecodeStream_peekBytes(length) {
  19114. var bytes = this.getBytes(length);
  19115. this.pos -= bytes.length;
  19116. return bytes;
  19117. },
  19118. makeSubStream: function DecodeStream_makeSubStream(start, length, dict) {
  19119. var end = start + length;
  19120. while (this.bufferLength <= end && !this.eof) {
  19121. this.readBlock();
  19122. }
  19123. return new Stream(this.buffer, start, length, dict);
  19124. },
  19125. skip: function DecodeStream_skip(n) {
  19126. if (!n) {
  19127. n = 1;
  19128. }
  19129. this.pos += n;
  19130. },
  19131. reset: function DecodeStream_reset() {
  19132. this.pos = 0;
  19133. },
  19134. getBaseStreams: function DecodeStream_getBaseStreams() {
  19135. if (this.str && this.str.getBaseStreams) {
  19136. return this.str.getBaseStreams();
  19137. }
  19138. return [];
  19139. }
  19140. };
  19141. return DecodeStream;
  19142. })();
  19143. var StreamsSequenceStream = (function StreamsSequenceStreamClosure() {
  19144. function StreamsSequenceStream(streams) {
  19145. this.streams = streams;
  19146. DecodeStream.call(this, /* maybeLength = */ null);
  19147. }
  19148. StreamsSequenceStream.prototype = Object.create(DecodeStream.prototype);
  19149. StreamsSequenceStream.prototype.readBlock =
  19150. function streamSequenceStreamReadBlock() {
  19151. var streams = this.streams;
  19152. if (streams.length === 0) {
  19153. this.eof = true;
  19154. return;
  19155. }
  19156. var stream = streams.shift();
  19157. var chunk = stream.getBytes();
  19158. var bufferLength = this.bufferLength;
  19159. var newLength = bufferLength + chunk.length;
  19160. var buffer = this.ensureBuffer(newLength);
  19161. buffer.set(chunk, bufferLength);
  19162. this.bufferLength = newLength;
  19163. };
  19164. StreamsSequenceStream.prototype.getBaseStreams =
  19165. function StreamsSequenceStream_getBaseStreams() {
  19166. var baseStreams = [];
  19167. for (var i = 0, ii = this.streams.length; i < ii; i++) {
  19168. var stream = this.streams[i];
  19169. if (stream.getBaseStreams) {
  19170. Util.appendToArray(baseStreams, stream.getBaseStreams());
  19171. }
  19172. }
  19173. return baseStreams;
  19174. };
  19175. return StreamsSequenceStream;
  19176. })();
  19177. var FlateStream = (function FlateStreamClosure() {
  19178. var codeLenCodeMap = new Int32Array([
  19179. 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
  19180. ]);
  19181. var lengthDecode = new Int32Array([
  19182. 0x00003, 0x00004, 0x00005, 0x00006, 0x00007, 0x00008, 0x00009, 0x0000a,
  19183. 0x1000b, 0x1000d, 0x1000f, 0x10011, 0x20013, 0x20017, 0x2001b, 0x2001f,
  19184. 0x30023, 0x3002b, 0x30033, 0x3003b, 0x40043, 0x40053, 0x40063, 0x40073,
  19185. 0x50083, 0x500a3, 0x500c3, 0x500e3, 0x00102, 0x00102, 0x00102
  19186. ]);
  19187. var distDecode = new Int32Array([
  19188. 0x00001, 0x00002, 0x00003, 0x00004, 0x10005, 0x10007, 0x20009, 0x2000d,
  19189. 0x30011, 0x30019, 0x40021, 0x40031, 0x50041, 0x50061, 0x60081, 0x600c1,
  19190. 0x70101, 0x70181, 0x80201, 0x80301, 0x90401, 0x90601, 0xa0801, 0xa0c01,
  19191. 0xb1001, 0xb1801, 0xc2001, 0xc3001, 0xd4001, 0xd6001
  19192. ]);
  19193. var fixedLitCodeTab = [new Int32Array([
  19194. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c0,
  19195. 0x70108, 0x80060, 0x80020, 0x900a0, 0x80000, 0x80080, 0x80040, 0x900e0,
  19196. 0x70104, 0x80058, 0x80018, 0x90090, 0x70114, 0x80078, 0x80038, 0x900d0,
  19197. 0x7010c, 0x80068, 0x80028, 0x900b0, 0x80008, 0x80088, 0x80048, 0x900f0,
  19198. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c8,
  19199. 0x7010a, 0x80064, 0x80024, 0x900a8, 0x80004, 0x80084, 0x80044, 0x900e8,
  19200. 0x70106, 0x8005c, 0x8001c, 0x90098, 0x70116, 0x8007c, 0x8003c, 0x900d8,
  19201. 0x7010e, 0x8006c, 0x8002c, 0x900b8, 0x8000c, 0x8008c, 0x8004c, 0x900f8,
  19202. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c4,
  19203. 0x70109, 0x80062, 0x80022, 0x900a4, 0x80002, 0x80082, 0x80042, 0x900e4,
  19204. 0x70105, 0x8005a, 0x8001a, 0x90094, 0x70115, 0x8007a, 0x8003a, 0x900d4,
  19205. 0x7010d, 0x8006a, 0x8002a, 0x900b4, 0x8000a, 0x8008a, 0x8004a, 0x900f4,
  19206. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cc,
  19207. 0x7010b, 0x80066, 0x80026, 0x900ac, 0x80006, 0x80086, 0x80046, 0x900ec,
  19208. 0x70107, 0x8005e, 0x8001e, 0x9009c, 0x70117, 0x8007e, 0x8003e, 0x900dc,
  19209. 0x7010f, 0x8006e, 0x8002e, 0x900bc, 0x8000e, 0x8008e, 0x8004e, 0x900fc,
  19210. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c2,
  19211. 0x70108, 0x80061, 0x80021, 0x900a2, 0x80001, 0x80081, 0x80041, 0x900e2,
  19212. 0x70104, 0x80059, 0x80019, 0x90092, 0x70114, 0x80079, 0x80039, 0x900d2,
  19213. 0x7010c, 0x80069, 0x80029, 0x900b2, 0x80009, 0x80089, 0x80049, 0x900f2,
  19214. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900ca,
  19215. 0x7010a, 0x80065, 0x80025, 0x900aa, 0x80005, 0x80085, 0x80045, 0x900ea,
  19216. 0x70106, 0x8005d, 0x8001d, 0x9009a, 0x70116, 0x8007d, 0x8003d, 0x900da,
  19217. 0x7010e, 0x8006d, 0x8002d, 0x900ba, 0x8000d, 0x8008d, 0x8004d, 0x900fa,
  19218. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c6,
  19219. 0x70109, 0x80063, 0x80023, 0x900a6, 0x80003, 0x80083, 0x80043, 0x900e6,
  19220. 0x70105, 0x8005b, 0x8001b, 0x90096, 0x70115, 0x8007b, 0x8003b, 0x900d6,
  19221. 0x7010d, 0x8006b, 0x8002b, 0x900b6, 0x8000b, 0x8008b, 0x8004b, 0x900f6,
  19222. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900ce,
  19223. 0x7010b, 0x80067, 0x80027, 0x900ae, 0x80007, 0x80087, 0x80047, 0x900ee,
  19224. 0x70107, 0x8005f, 0x8001f, 0x9009e, 0x70117, 0x8007f, 0x8003f, 0x900de,
  19225. 0x7010f, 0x8006f, 0x8002f, 0x900be, 0x8000f, 0x8008f, 0x8004f, 0x900fe,
  19226. 0x70100, 0x80050, 0x80010, 0x80118, 0x70110, 0x80070, 0x80030, 0x900c1,
  19227. 0x70108, 0x80060, 0x80020, 0x900a1, 0x80000, 0x80080, 0x80040, 0x900e1,
  19228. 0x70104, 0x80058, 0x80018, 0x90091, 0x70114, 0x80078, 0x80038, 0x900d1,
  19229. 0x7010c, 0x80068, 0x80028, 0x900b1, 0x80008, 0x80088, 0x80048, 0x900f1,
  19230. 0x70102, 0x80054, 0x80014, 0x8011c, 0x70112, 0x80074, 0x80034, 0x900c9,
  19231. 0x7010a, 0x80064, 0x80024, 0x900a9, 0x80004, 0x80084, 0x80044, 0x900e9,
  19232. 0x70106, 0x8005c, 0x8001c, 0x90099, 0x70116, 0x8007c, 0x8003c, 0x900d9,
  19233. 0x7010e, 0x8006c, 0x8002c, 0x900b9, 0x8000c, 0x8008c, 0x8004c, 0x900f9,
  19234. 0x70101, 0x80052, 0x80012, 0x8011a, 0x70111, 0x80072, 0x80032, 0x900c5,
  19235. 0x70109, 0x80062, 0x80022, 0x900a5, 0x80002, 0x80082, 0x80042, 0x900e5,
  19236. 0x70105, 0x8005a, 0x8001a, 0x90095, 0x70115, 0x8007a, 0x8003a, 0x900d5,
  19237. 0x7010d, 0x8006a, 0x8002a, 0x900b5, 0x8000a, 0x8008a, 0x8004a, 0x900f5,
  19238. 0x70103, 0x80056, 0x80016, 0x8011e, 0x70113, 0x80076, 0x80036, 0x900cd,
  19239. 0x7010b, 0x80066, 0x80026, 0x900ad, 0x80006, 0x80086, 0x80046, 0x900ed,
  19240. 0x70107, 0x8005e, 0x8001e, 0x9009d, 0x70117, 0x8007e, 0x8003e, 0x900dd,
  19241. 0x7010f, 0x8006e, 0x8002e, 0x900bd, 0x8000e, 0x8008e, 0x8004e, 0x900fd,
  19242. 0x70100, 0x80051, 0x80011, 0x80119, 0x70110, 0x80071, 0x80031, 0x900c3,
  19243. 0x70108, 0x80061, 0x80021, 0x900a3, 0x80001, 0x80081, 0x80041, 0x900e3,
  19244. 0x70104, 0x80059, 0x80019, 0x90093, 0x70114, 0x80079, 0x80039, 0x900d3,
  19245. 0x7010c, 0x80069, 0x80029, 0x900b3, 0x80009, 0x80089, 0x80049, 0x900f3,
  19246. 0x70102, 0x80055, 0x80015, 0x8011d, 0x70112, 0x80075, 0x80035, 0x900cb,
  19247. 0x7010a, 0x80065, 0x80025, 0x900ab, 0x80005, 0x80085, 0x80045, 0x900eb,
  19248. 0x70106, 0x8005d, 0x8001d, 0x9009b, 0x70116, 0x8007d, 0x8003d, 0x900db,
  19249. 0x7010e, 0x8006d, 0x8002d, 0x900bb, 0x8000d, 0x8008d, 0x8004d, 0x900fb,
  19250. 0x70101, 0x80053, 0x80013, 0x8011b, 0x70111, 0x80073, 0x80033, 0x900c7,
  19251. 0x70109, 0x80063, 0x80023, 0x900a7, 0x80003, 0x80083, 0x80043, 0x900e7,
  19252. 0x70105, 0x8005b, 0x8001b, 0x90097, 0x70115, 0x8007b, 0x8003b, 0x900d7,
  19253. 0x7010d, 0x8006b, 0x8002b, 0x900b7, 0x8000b, 0x8008b, 0x8004b, 0x900f7,
  19254. 0x70103, 0x80057, 0x80017, 0x8011f, 0x70113, 0x80077, 0x80037, 0x900cf,
  19255. 0x7010b, 0x80067, 0x80027, 0x900af, 0x80007, 0x80087, 0x80047, 0x900ef,
  19256. 0x70107, 0x8005f, 0x8001f, 0x9009f, 0x70117, 0x8007f, 0x8003f, 0x900df,
  19257. 0x7010f, 0x8006f, 0x8002f, 0x900bf, 0x8000f, 0x8008f, 0x8004f, 0x900ff
  19258. ]), 9];
  19259. var fixedDistCodeTab = [new Int32Array([
  19260. 0x50000, 0x50010, 0x50008, 0x50018, 0x50004, 0x50014, 0x5000c, 0x5001c,
  19261. 0x50002, 0x50012, 0x5000a, 0x5001a, 0x50006, 0x50016, 0x5000e, 0x00000,
  19262. 0x50001, 0x50011, 0x50009, 0x50019, 0x50005, 0x50015, 0x5000d, 0x5001d,
  19263. 0x50003, 0x50013, 0x5000b, 0x5001b, 0x50007, 0x50017, 0x5000f, 0x00000
  19264. ]), 5];
  19265. function FlateStream(str, maybeLength) {
  19266. this.str = str;
  19267. this.dict = str.dict;
  19268. var cmf = str.getByte();
  19269. var flg = str.getByte();
  19270. if (cmf === -1 || flg === -1) {
  19271. error('Invalid header in flate stream: ' + cmf + ', ' + flg);
  19272. }
  19273. if ((cmf & 0x0f) !== 0x08) {
  19274. error('Unknown compression method in flate stream: ' + cmf + ', ' + flg);
  19275. }
  19276. if ((((cmf << 8) + flg) % 31) !== 0) {
  19277. error('Bad FCHECK in flate stream: ' + cmf + ', ' + flg);
  19278. }
  19279. if (flg & 0x20) {
  19280. error('FDICT bit set in flate stream: ' + cmf + ', ' + flg);
  19281. }
  19282. this.codeSize = 0;
  19283. this.codeBuf = 0;
  19284. DecodeStream.call(this, maybeLength);
  19285. }
  19286. FlateStream.prototype = Object.create(DecodeStream.prototype);
  19287. FlateStream.prototype.getBits = function FlateStream_getBits(bits) {
  19288. var str = this.str;
  19289. var codeSize = this.codeSize;
  19290. var codeBuf = this.codeBuf;
  19291. var b;
  19292. while (codeSize < bits) {
  19293. if ((b = str.getByte()) === -1) {
  19294. error('Bad encoding in flate stream');
  19295. }
  19296. codeBuf |= b << codeSize;
  19297. codeSize += 8;
  19298. }
  19299. b = codeBuf & ((1 << bits) - 1);
  19300. this.codeBuf = codeBuf >> bits;
  19301. this.codeSize = codeSize -= bits;
  19302. return b;
  19303. };
  19304. FlateStream.prototype.getCode = function FlateStream_getCode(table) {
  19305. var str = this.str;
  19306. var codes = table[0];
  19307. var maxLen = table[1];
  19308. var codeSize = this.codeSize;
  19309. var codeBuf = this.codeBuf;
  19310. var b;
  19311. while (codeSize < maxLen) {
  19312. if ((b = str.getByte()) === -1) {
  19313. // premature end of stream. code might however still be valid.
  19314. // codeSize < codeLen check below guards against incomplete codeVal.
  19315. break;
  19316. }
  19317. codeBuf |= (b << codeSize);
  19318. codeSize += 8;
  19319. }
  19320. var code = codes[codeBuf & ((1 << maxLen) - 1)];
  19321. var codeLen = code >> 16;
  19322. var codeVal = code & 0xffff;
  19323. if (codeLen < 1 || codeSize < codeLen) {
  19324. error('Bad encoding in flate stream');
  19325. }
  19326. this.codeBuf = (codeBuf >> codeLen);
  19327. this.codeSize = (codeSize - codeLen);
  19328. return codeVal;
  19329. };
  19330. FlateStream.prototype.generateHuffmanTable =
  19331. function flateStreamGenerateHuffmanTable(lengths) {
  19332. var n = lengths.length;
  19333. // find max code length
  19334. var maxLen = 0;
  19335. var i;
  19336. for (i = 0; i < n; ++i) {
  19337. if (lengths[i] > maxLen) {
  19338. maxLen = lengths[i];
  19339. }
  19340. }
  19341. // build the table
  19342. var size = 1 << maxLen;
  19343. var codes = new Int32Array(size);
  19344. for (var len = 1, code = 0, skip = 2;
  19345. len <= maxLen;
  19346. ++len, code <<= 1, skip <<= 1) {
  19347. for (var val = 0; val < n; ++val) {
  19348. if (lengths[val] === len) {
  19349. // bit-reverse the code
  19350. var code2 = 0;
  19351. var t = code;
  19352. for (i = 0; i < len; ++i) {
  19353. code2 = (code2 << 1) | (t & 1);
  19354. t >>= 1;
  19355. }
  19356. // fill the table entries
  19357. for (i = code2; i < size; i += skip) {
  19358. codes[i] = (len << 16) | val;
  19359. }
  19360. ++code;
  19361. }
  19362. }
  19363. }
  19364. return [codes, maxLen];
  19365. };
  19366. FlateStream.prototype.readBlock = function FlateStream_readBlock() {
  19367. var buffer, len;
  19368. var str = this.str;
  19369. // read block header
  19370. var hdr = this.getBits(3);
  19371. if (hdr & 1) {
  19372. this.eof = true;
  19373. }
  19374. hdr >>= 1;
  19375. if (hdr === 0) { // uncompressed block
  19376. var b;
  19377. if ((b = str.getByte()) === -1) {
  19378. error('Bad block header in flate stream');
  19379. }
  19380. var blockLen = b;
  19381. if ((b = str.getByte()) === -1) {
  19382. error('Bad block header in flate stream');
  19383. }
  19384. blockLen |= (b << 8);
  19385. if ((b = str.getByte()) === -1) {
  19386. error('Bad block header in flate stream');
  19387. }
  19388. var check = b;
  19389. if ((b = str.getByte()) === -1) {
  19390. error('Bad block header in flate stream');
  19391. }
  19392. check |= (b << 8);
  19393. if (check !== (~blockLen & 0xffff) &&
  19394. (blockLen !== 0 || check !== 0)) {
  19395. // Ignoring error for bad "empty" block (see issue 1277)
  19396. error('Bad uncompressed block length in flate stream');
  19397. }
  19398. this.codeBuf = 0;
  19399. this.codeSize = 0;
  19400. var bufferLength = this.bufferLength;
  19401. buffer = this.ensureBuffer(bufferLength + blockLen);
  19402. var end = bufferLength + blockLen;
  19403. this.bufferLength = end;
  19404. if (blockLen === 0) {
  19405. if (str.peekByte() === -1) {
  19406. this.eof = true;
  19407. }
  19408. } else {
  19409. for (var n = bufferLength; n < end; ++n) {
  19410. if ((b = str.getByte()) === -1) {
  19411. this.eof = true;
  19412. break;
  19413. }
  19414. buffer[n] = b;
  19415. }
  19416. }
  19417. return;
  19418. }
  19419. var litCodeTable;
  19420. var distCodeTable;
  19421. if (hdr === 1) { // compressed block, fixed codes
  19422. litCodeTable = fixedLitCodeTab;
  19423. distCodeTable = fixedDistCodeTab;
  19424. } else if (hdr === 2) { // compressed block, dynamic codes
  19425. var numLitCodes = this.getBits(5) + 257;
  19426. var numDistCodes = this.getBits(5) + 1;
  19427. var numCodeLenCodes = this.getBits(4) + 4;
  19428. // build the code lengths code table
  19429. var codeLenCodeLengths = new Uint8Array(codeLenCodeMap.length);
  19430. var i;
  19431. for (i = 0; i < numCodeLenCodes; ++i) {
  19432. codeLenCodeLengths[codeLenCodeMap[i]] = this.getBits(3);
  19433. }
  19434. var codeLenCodeTab = this.generateHuffmanTable(codeLenCodeLengths);
  19435. // build the literal and distance code tables
  19436. len = 0;
  19437. i = 0;
  19438. var codes = numLitCodes + numDistCodes;
  19439. var codeLengths = new Uint8Array(codes);
  19440. var bitsLength, bitsOffset, what;
  19441. while (i < codes) {
  19442. var code = this.getCode(codeLenCodeTab);
  19443. if (code === 16) {
  19444. bitsLength = 2; bitsOffset = 3; what = len;
  19445. } else if (code === 17) {
  19446. bitsLength = 3; bitsOffset = 3; what = (len = 0);
  19447. } else if (code === 18) {
  19448. bitsLength = 7; bitsOffset = 11; what = (len = 0);
  19449. } else {
  19450. codeLengths[i++] = len = code;
  19451. continue;
  19452. }
  19453. var repeatLength = this.getBits(bitsLength) + bitsOffset;
  19454. while (repeatLength-- > 0) {
  19455. codeLengths[i++] = what;
  19456. }
  19457. }
  19458. litCodeTable =
  19459. this.generateHuffmanTable(codeLengths.subarray(0, numLitCodes));
  19460. distCodeTable =
  19461. this.generateHuffmanTable(codeLengths.subarray(numLitCodes, codes));
  19462. } else {
  19463. error('Unknown block type in flate stream');
  19464. }
  19465. buffer = this.buffer;
  19466. var limit = buffer ? buffer.length : 0;
  19467. var pos = this.bufferLength;
  19468. while (true) {
  19469. var code1 = this.getCode(litCodeTable);
  19470. if (code1 < 256) {
  19471. if (pos + 1 >= limit) {
  19472. buffer = this.ensureBuffer(pos + 1);
  19473. limit = buffer.length;
  19474. }
  19475. buffer[pos++] = code1;
  19476. continue;
  19477. }
  19478. if (code1 === 256) {
  19479. this.bufferLength = pos;
  19480. return;
  19481. }
  19482. code1 -= 257;
  19483. code1 = lengthDecode[code1];
  19484. var code2 = code1 >> 16;
  19485. if (code2 > 0) {
  19486. code2 = this.getBits(code2);
  19487. }
  19488. len = (code1 & 0xffff) + code2;
  19489. code1 = this.getCode(distCodeTable);
  19490. code1 = distDecode[code1];
  19491. code2 = code1 >> 16;
  19492. if (code2 > 0) {
  19493. code2 = this.getBits(code2);
  19494. }
  19495. var dist = (code1 & 0xffff) + code2;
  19496. if (pos + len >= limit) {
  19497. buffer = this.ensureBuffer(pos + len);
  19498. limit = buffer.length;
  19499. }
  19500. for (var k = 0; k < len; ++k, ++pos) {
  19501. buffer[pos] = buffer[pos - dist];
  19502. }
  19503. }
  19504. };
  19505. return FlateStream;
  19506. })();
  19507. var PredictorStream = (function PredictorStreamClosure() {
  19508. function PredictorStream(str, maybeLength, params) {
  19509. var predictor = this.predictor = params.get('Predictor') || 1;
  19510. if (predictor <= 1) {
  19511. return str; // no prediction
  19512. }
  19513. if (predictor !== 2 && (predictor < 10 || predictor > 15)) {
  19514. error('Unsupported predictor: ' + predictor);
  19515. }
  19516. if (predictor === 2) {
  19517. this.readBlock = this.readBlockTiff;
  19518. } else {
  19519. this.readBlock = this.readBlockPng;
  19520. }
  19521. this.str = str;
  19522. this.dict = str.dict;
  19523. var colors = this.colors = params.get('Colors') || 1;
  19524. var bits = this.bits = params.get('BitsPerComponent') || 8;
  19525. var columns = this.columns = params.get('Columns') || 1;
  19526. this.pixBytes = (colors * bits + 7) >> 3;
  19527. this.rowBytes = (columns * colors * bits + 7) >> 3;
  19528. DecodeStream.call(this, maybeLength);
  19529. return this;
  19530. }
  19531. PredictorStream.prototype = Object.create(DecodeStream.prototype);
  19532. PredictorStream.prototype.readBlockTiff =
  19533. function predictorStreamReadBlockTiff() {
  19534. var rowBytes = this.rowBytes;
  19535. var bufferLength = this.bufferLength;
  19536. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19537. var bits = this.bits;
  19538. var colors = this.colors;
  19539. var rawBytes = this.str.getBytes(rowBytes);
  19540. this.eof = !rawBytes.length;
  19541. if (this.eof) {
  19542. return;
  19543. }
  19544. var inbuf = 0, outbuf = 0;
  19545. var inbits = 0, outbits = 0;
  19546. var pos = bufferLength;
  19547. var i;
  19548. if (bits === 1) {
  19549. for (i = 0; i < rowBytes; ++i) {
  19550. var c = rawBytes[i];
  19551. inbuf = (inbuf << 8) | c;
  19552. // bitwise addition is exclusive or
  19553. // first shift inbuf and then add
  19554. buffer[pos++] = (c ^ (inbuf >> colors)) & 0xFF;
  19555. // truncate inbuf (assumes colors < 16)
  19556. inbuf &= 0xFFFF;
  19557. }
  19558. } else if (bits === 8) {
  19559. for (i = 0; i < colors; ++i) {
  19560. buffer[pos++] = rawBytes[i];
  19561. }
  19562. for (; i < rowBytes; ++i) {
  19563. buffer[pos] = buffer[pos - colors] + rawBytes[i];
  19564. pos++;
  19565. }
  19566. } else {
  19567. var compArray = new Uint8Array(colors + 1);
  19568. var bitMask = (1 << bits) - 1;
  19569. var j = 0, k = bufferLength;
  19570. var columns = this.columns;
  19571. for (i = 0; i < columns; ++i) {
  19572. for (var kk = 0; kk < colors; ++kk) {
  19573. if (inbits < bits) {
  19574. inbuf = (inbuf << 8) | (rawBytes[j++] & 0xFF);
  19575. inbits += 8;
  19576. }
  19577. compArray[kk] = (compArray[kk] +
  19578. (inbuf >> (inbits - bits))) & bitMask;
  19579. inbits -= bits;
  19580. outbuf = (outbuf << bits) | compArray[kk];
  19581. outbits += bits;
  19582. if (outbits >= 8) {
  19583. buffer[k++] = (outbuf >> (outbits - 8)) & 0xFF;
  19584. outbits -= 8;
  19585. }
  19586. }
  19587. }
  19588. if (outbits > 0) {
  19589. buffer[k++] = (outbuf << (8 - outbits)) +
  19590. (inbuf & ((1 << (8 - outbits)) - 1));
  19591. }
  19592. }
  19593. this.bufferLength += rowBytes;
  19594. };
  19595. PredictorStream.prototype.readBlockPng =
  19596. function predictorStreamReadBlockPng() {
  19597. var rowBytes = this.rowBytes;
  19598. var pixBytes = this.pixBytes;
  19599. var predictor = this.str.getByte();
  19600. var rawBytes = this.str.getBytes(rowBytes);
  19601. this.eof = !rawBytes.length;
  19602. if (this.eof) {
  19603. return;
  19604. }
  19605. var bufferLength = this.bufferLength;
  19606. var buffer = this.ensureBuffer(bufferLength + rowBytes);
  19607. var prevRow = buffer.subarray(bufferLength - rowBytes, bufferLength);
  19608. if (prevRow.length === 0) {
  19609. prevRow = new Uint8Array(rowBytes);
  19610. }
  19611. var i, j = bufferLength, up, c;
  19612. switch (predictor) {
  19613. case 0:
  19614. for (i = 0; i < rowBytes; ++i) {
  19615. buffer[j++] = rawBytes[i];
  19616. }
  19617. break;
  19618. case 1:
  19619. for (i = 0; i < pixBytes; ++i) {
  19620. buffer[j++] = rawBytes[i];
  19621. }
  19622. for (; i < rowBytes; ++i) {
  19623. buffer[j] = (buffer[j - pixBytes] + rawBytes[i]) & 0xFF;
  19624. j++;
  19625. }
  19626. break;
  19627. case 2:
  19628. for (i = 0; i < rowBytes; ++i) {
  19629. buffer[j++] = (prevRow[i] + rawBytes[i]) & 0xFF;
  19630. }
  19631. break;
  19632. case 3:
  19633. for (i = 0; i < pixBytes; ++i) {
  19634. buffer[j++] = (prevRow[i] >> 1) + rawBytes[i];
  19635. }
  19636. for (; i < rowBytes; ++i) {
  19637. buffer[j] = (((prevRow[i] + buffer[j - pixBytes]) >> 1) +
  19638. rawBytes[i]) & 0xFF;
  19639. j++;
  19640. }
  19641. break;
  19642. case 4:
  19643. // we need to save the up left pixels values. the simplest way
  19644. // is to create a new buffer
  19645. for (i = 0; i < pixBytes; ++i) {
  19646. up = prevRow[i];
  19647. c = rawBytes[i];
  19648. buffer[j++] = up + c;
  19649. }
  19650. for (; i < rowBytes; ++i) {
  19651. up = prevRow[i];
  19652. var upLeft = prevRow[i - pixBytes];
  19653. var left = buffer[j - pixBytes];
  19654. var p = left + up - upLeft;
  19655. var pa = p - left;
  19656. if (pa < 0) {
  19657. pa = -pa;
  19658. }
  19659. var pb = p - up;
  19660. if (pb < 0) {
  19661. pb = -pb;
  19662. }
  19663. var pc = p - upLeft;
  19664. if (pc < 0) {
  19665. pc = -pc;
  19666. }
  19667. c = rawBytes[i];
  19668. if (pa <= pb && pa <= pc) {
  19669. buffer[j++] = left + c;
  19670. } else if (pb <= pc) {
  19671. buffer[j++] = up + c;
  19672. } else {
  19673. buffer[j++] = upLeft + c;
  19674. }
  19675. }
  19676. break;
  19677. default:
  19678. error('Unsupported predictor: ' + predictor);
  19679. }
  19680. this.bufferLength += rowBytes;
  19681. };
  19682. return PredictorStream;
  19683. })();
  19684. /**
  19685. * Depending on the type of JPEG a JpegStream is handled in different ways. For
  19686. * JPEG's that are supported natively such as DeviceGray and DeviceRGB the image
  19687. * data is stored and then loaded by the browser. For unsupported JPEG's we use
  19688. * a library to decode these images and the stream behaves like all the other
  19689. * DecodeStreams.
  19690. */
  19691. var JpegStream = (function JpegStreamClosure() {
  19692. function JpegStream(stream, maybeLength, dict, xref) {
  19693. // Some images may contain 'junk' before the SOI (start-of-image) marker.
  19694. // Note: this seems to mainly affect inline images.
  19695. var ch;
  19696. while ((ch = stream.getByte()) !== -1) {
  19697. if (ch === 0xFF) { // Find the first byte of the SOI marker (0xFFD8).
  19698. stream.skip(-1); // Reset the stream position to the SOI.
  19699. break;
  19700. }
  19701. }
  19702. this.stream = stream;
  19703. this.maybeLength = maybeLength;
  19704. this.dict = dict;
  19705. DecodeStream.call(this, maybeLength);
  19706. }
  19707. JpegStream.prototype = Object.create(DecodeStream.prototype);
  19708. Object.defineProperty(JpegStream.prototype, 'bytes', {
  19709. get: function JpegStream_bytes() {
  19710. // If this.maybeLength is null, we'll get the entire stream.
  19711. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19712. },
  19713. configurable: true
  19714. });
  19715. JpegStream.prototype.ensureBuffer = function JpegStream_ensureBuffer(req) {
  19716. if (this.bufferLength) {
  19717. return;
  19718. }
  19719. try {
  19720. var jpegImage = new JpegImage();
  19721. // checking if values needs to be transformed before conversion
  19722. if (this.forceRGB && this.dict && isArray(this.dict.get('Decode'))) {
  19723. var decodeArr = this.dict.get('Decode');
  19724. var bitsPerComponent = this.dict.get('BitsPerComponent') || 8;
  19725. var decodeArrLength = decodeArr.length;
  19726. var transform = new Int32Array(decodeArrLength);
  19727. var transformNeeded = false;
  19728. var maxValue = (1 << bitsPerComponent) - 1;
  19729. for (var i = 0; i < decodeArrLength; i += 2) {
  19730. transform[i] = ((decodeArr[i + 1] - decodeArr[i]) * 256) | 0;
  19731. transform[i + 1] = (decodeArr[i] * maxValue) | 0;
  19732. if (transform[i] !== 256 || transform[i + 1] !== 0) {
  19733. transformNeeded = true;
  19734. }
  19735. }
  19736. if (transformNeeded) {
  19737. jpegImage.decodeTransform = transform;
  19738. }
  19739. }
  19740. jpegImage.parse(this.bytes);
  19741. var data = jpegImage.getData(this.drawWidth, this.drawHeight,
  19742. this.forceRGB);
  19743. this.buffer = data;
  19744. this.bufferLength = data.length;
  19745. this.eof = true;
  19746. } catch (e) {
  19747. error('JPEG error: ' + e);
  19748. }
  19749. };
  19750. JpegStream.prototype.getBytes = function JpegStream_getBytes(length) {
  19751. this.ensureBuffer();
  19752. return this.buffer;
  19753. };
  19754. JpegStream.prototype.getIR = function JpegStream_getIR(forceDataSchema) {
  19755. return createObjectURL(this.bytes, 'image/jpeg', forceDataSchema);
  19756. };
  19757. return JpegStream;
  19758. })();
  19759. /**
  19760. * For JPEG 2000's we use a library to decode these images and
  19761. * the stream behaves like all the other DecodeStreams.
  19762. */
  19763. var JpxStream = (function JpxStreamClosure() {
  19764. function JpxStream(stream, maybeLength, dict) {
  19765. this.stream = stream;
  19766. this.maybeLength = maybeLength;
  19767. this.dict = dict;
  19768. DecodeStream.call(this, maybeLength);
  19769. }
  19770. JpxStream.prototype = Object.create(DecodeStream.prototype);
  19771. Object.defineProperty(JpxStream.prototype, 'bytes', {
  19772. get: function JpxStream_bytes() {
  19773. // If this.maybeLength is null, we'll get the entire stream.
  19774. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19775. },
  19776. configurable: true
  19777. });
  19778. JpxStream.prototype.ensureBuffer = function JpxStream_ensureBuffer(req) {
  19779. if (this.bufferLength) {
  19780. return;
  19781. }
  19782. var jpxImage = new JpxImage();
  19783. jpxImage.parse(this.bytes);
  19784. var width = jpxImage.width;
  19785. var height = jpxImage.height;
  19786. var componentsCount = jpxImage.componentsCount;
  19787. var tileCount = jpxImage.tiles.length;
  19788. if (tileCount === 1) {
  19789. this.buffer = jpxImage.tiles[0].items;
  19790. } else {
  19791. var data = new Uint8Array(width * height * componentsCount);
  19792. for (var k = 0; k < tileCount; k++) {
  19793. var tileComponents = jpxImage.tiles[k];
  19794. var tileWidth = tileComponents.width;
  19795. var tileHeight = tileComponents.height;
  19796. var tileLeft = tileComponents.left;
  19797. var tileTop = tileComponents.top;
  19798. var src = tileComponents.items;
  19799. var srcPosition = 0;
  19800. var dataPosition = (width * tileTop + tileLeft) * componentsCount;
  19801. var imgRowSize = width * componentsCount;
  19802. var tileRowSize = tileWidth * componentsCount;
  19803. for (var j = 0; j < tileHeight; j++) {
  19804. var rowBytes = src.subarray(srcPosition, srcPosition + tileRowSize);
  19805. data.set(rowBytes, dataPosition);
  19806. srcPosition += tileRowSize;
  19807. dataPosition += imgRowSize;
  19808. }
  19809. }
  19810. this.buffer = data;
  19811. }
  19812. this.bufferLength = this.buffer.length;
  19813. this.eof = true;
  19814. };
  19815. return JpxStream;
  19816. })();
  19817. /**
  19818. * For JBIG2's we use a library to decode these images and
  19819. * the stream behaves like all the other DecodeStreams.
  19820. */
  19821. var Jbig2Stream = (function Jbig2StreamClosure() {
  19822. function Jbig2Stream(stream, maybeLength, dict) {
  19823. this.stream = stream;
  19824. this.maybeLength = maybeLength;
  19825. this.dict = dict;
  19826. DecodeStream.call(this, maybeLength);
  19827. }
  19828. Jbig2Stream.prototype = Object.create(DecodeStream.prototype);
  19829. Object.defineProperty(Jbig2Stream.prototype, 'bytes', {
  19830. get: function Jbig2Stream_bytes() {
  19831. // If this.maybeLength is null, we'll get the entire stream.
  19832. return shadow(this, 'bytes', this.stream.getBytes(this.maybeLength));
  19833. },
  19834. configurable: true
  19835. });
  19836. Jbig2Stream.prototype.ensureBuffer = function Jbig2Stream_ensureBuffer(req) {
  19837. if (this.bufferLength) {
  19838. return;
  19839. }
  19840. var jbig2Image = new Jbig2Image();
  19841. var chunks = [], xref = this.dict.xref;
  19842. var decodeParams = xref.fetchIfRef(this.dict.get('DecodeParms'));
  19843. // According to the PDF specification, DecodeParms can be either
  19844. // a dictionary, or an array whose elements are dictionaries.
  19845. if (isArray(decodeParams)) {
  19846. if (decodeParams.length > 1) {
  19847. warn('JBIG2 - \'DecodeParms\' array with multiple elements ' +
  19848. 'not supported.');
  19849. }
  19850. decodeParams = xref.fetchIfRef(decodeParams[0]);
  19851. }
  19852. if (decodeParams && decodeParams.has('JBIG2Globals')) {
  19853. var globalsStream = decodeParams.get('JBIG2Globals');
  19854. var globals = globalsStream.getBytes();
  19855. chunks.push({data: globals, start: 0, end: globals.length});
  19856. }
  19857. chunks.push({data: this.bytes, start: 0, end: this.bytes.length});
  19858. var data = jbig2Image.parseChunks(chunks);
  19859. var dataLength = data.length;
  19860. // JBIG2 had black as 1 and white as 0, inverting the colors
  19861. for (var i = 0; i < dataLength; i++) {
  19862. data[i] ^= 0xFF;
  19863. }
  19864. this.buffer = data;
  19865. this.bufferLength = dataLength;
  19866. this.eof = true;
  19867. };
  19868. return Jbig2Stream;
  19869. })();
  19870. var DecryptStream = (function DecryptStreamClosure() {
  19871. function DecryptStream(str, maybeLength, decrypt) {
  19872. this.str = str;
  19873. this.dict = str.dict;
  19874. this.decrypt = decrypt;
  19875. this.nextChunk = null;
  19876. this.initialized = false;
  19877. DecodeStream.call(this, maybeLength);
  19878. }
  19879. var chunkSize = 512;
  19880. DecryptStream.prototype = Object.create(DecodeStream.prototype);
  19881. DecryptStream.prototype.readBlock = function DecryptStream_readBlock() {
  19882. var chunk;
  19883. if (this.initialized) {
  19884. chunk = this.nextChunk;
  19885. } else {
  19886. chunk = this.str.getBytes(chunkSize);
  19887. this.initialized = true;
  19888. }
  19889. if (!chunk || chunk.length === 0) {
  19890. this.eof = true;
  19891. return;
  19892. }
  19893. this.nextChunk = this.str.getBytes(chunkSize);
  19894. var hasMoreData = this.nextChunk && this.nextChunk.length > 0;
  19895. var decrypt = this.decrypt;
  19896. chunk = decrypt(chunk, !hasMoreData);
  19897. var bufferLength = this.bufferLength;
  19898. var i, n = chunk.length;
  19899. var buffer = this.ensureBuffer(bufferLength + n);
  19900. for (i = 0; i < n; i++) {
  19901. buffer[bufferLength++] = chunk[i];
  19902. }
  19903. this.bufferLength = bufferLength;
  19904. };
  19905. return DecryptStream;
  19906. })();
  19907. var Ascii85Stream = (function Ascii85StreamClosure() {
  19908. // Checks if ch is one of the following characters: SPACE, TAB, CR or LF.
  19909. function isSpace(ch) {
  19910. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  19911. }
  19912. function Ascii85Stream(str, maybeLength) {
  19913. this.str = str;
  19914. this.dict = str.dict;
  19915. this.input = new Uint8Array(5);
  19916. // Most streams increase in size when decoded, but Ascii85 streams
  19917. // typically shrink by ~20%.
  19918. if (maybeLength) {
  19919. maybeLength = 0.8 * maybeLength;
  19920. }
  19921. DecodeStream.call(this, maybeLength);
  19922. }
  19923. Ascii85Stream.prototype = Object.create(DecodeStream.prototype);
  19924. Ascii85Stream.prototype.readBlock = function Ascii85Stream_readBlock() {
  19925. var TILDA_CHAR = 0x7E; // '~'
  19926. var Z_LOWER_CHAR = 0x7A; // 'z'
  19927. var EOF = -1;
  19928. var str = this.str;
  19929. var c = str.getByte();
  19930. while (isSpace(c)) {
  19931. c = str.getByte();
  19932. }
  19933. if (c === EOF || c === TILDA_CHAR) {
  19934. this.eof = true;
  19935. return;
  19936. }
  19937. var bufferLength = this.bufferLength, buffer;
  19938. var i;
  19939. // special code for z
  19940. if (c === Z_LOWER_CHAR) {
  19941. buffer = this.ensureBuffer(bufferLength + 4);
  19942. for (i = 0; i < 4; ++i) {
  19943. buffer[bufferLength + i] = 0;
  19944. }
  19945. this.bufferLength += 4;
  19946. } else {
  19947. var input = this.input;
  19948. input[0] = c;
  19949. for (i = 1; i < 5; ++i) {
  19950. c = str.getByte();
  19951. while (isSpace(c)) {
  19952. c = str.getByte();
  19953. }
  19954. input[i] = c;
  19955. if (c === EOF || c === TILDA_CHAR) {
  19956. break;
  19957. }
  19958. }
  19959. buffer = this.ensureBuffer(bufferLength + i - 1);
  19960. this.bufferLength += i - 1;
  19961. // partial ending;
  19962. if (i < 5) {
  19963. for (; i < 5; ++i) {
  19964. input[i] = 0x21 + 84;
  19965. }
  19966. this.eof = true;
  19967. }
  19968. var t = 0;
  19969. for (i = 0; i < 5; ++i) {
  19970. t = t * 85 + (input[i] - 0x21);
  19971. }
  19972. for (i = 3; i >= 0; --i) {
  19973. buffer[bufferLength + i] = t & 0xFF;
  19974. t >>= 8;
  19975. }
  19976. }
  19977. };
  19978. return Ascii85Stream;
  19979. })();
  19980. var AsciiHexStream = (function AsciiHexStreamClosure() {
  19981. function AsciiHexStream(str, maybeLength) {
  19982. this.str = str;
  19983. this.dict = str.dict;
  19984. this.firstDigit = -1;
  19985. // Most streams increase in size when decoded, but AsciiHex streams shrink
  19986. // by 50%.
  19987. if (maybeLength) {
  19988. maybeLength = 0.5 * maybeLength;
  19989. }
  19990. DecodeStream.call(this, maybeLength);
  19991. }
  19992. AsciiHexStream.prototype = Object.create(DecodeStream.prototype);
  19993. AsciiHexStream.prototype.readBlock = function AsciiHexStream_readBlock() {
  19994. var UPSTREAM_BLOCK_SIZE = 8000;
  19995. var bytes = this.str.getBytes(UPSTREAM_BLOCK_SIZE);
  19996. if (!bytes.length) {
  19997. this.eof = true;
  19998. return;
  19999. }
  20000. var maxDecodeLength = (bytes.length + 1) >> 1;
  20001. var buffer = this.ensureBuffer(this.bufferLength + maxDecodeLength);
  20002. var bufferLength = this.bufferLength;
  20003. var firstDigit = this.firstDigit;
  20004. for (var i = 0, ii = bytes.length; i < ii; i++) {
  20005. var ch = bytes[i], digit;
  20006. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  20007. digit = ch & 0x0F;
  20008. } else if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  20009. // 'A'-'Z', 'a'-'z'
  20010. digit = (ch & 0x0F) + 9;
  20011. } else if (ch === 0x3E) { // '>'
  20012. this.eof = true;
  20013. break;
  20014. } else { // probably whitespace
  20015. continue; // ignoring
  20016. }
  20017. if (firstDigit < 0) {
  20018. firstDigit = digit;
  20019. } else {
  20020. buffer[bufferLength++] = (firstDigit << 4) | digit;
  20021. firstDigit = -1;
  20022. }
  20023. }
  20024. if (firstDigit >= 0 && this.eof) {
  20025. // incomplete byte
  20026. buffer[bufferLength++] = (firstDigit << 4);
  20027. firstDigit = -1;
  20028. }
  20029. this.firstDigit = firstDigit;
  20030. this.bufferLength = bufferLength;
  20031. };
  20032. return AsciiHexStream;
  20033. })();
  20034. var RunLengthStream = (function RunLengthStreamClosure() {
  20035. function RunLengthStream(str, maybeLength) {
  20036. this.str = str;
  20037. this.dict = str.dict;
  20038. DecodeStream.call(this, maybeLength);
  20039. }
  20040. RunLengthStream.prototype = Object.create(DecodeStream.prototype);
  20041. RunLengthStream.prototype.readBlock = function RunLengthStream_readBlock() {
  20042. // The repeatHeader has following format. The first byte defines type of run
  20043. // and amount of bytes to repeat/copy: n = 0 through 127 - copy next n bytes
  20044. // (in addition to the second byte from the header), n = 129 through 255 -
  20045. // duplicate the second byte from the header (257 - n) times, n = 128 - end.
  20046. var repeatHeader = this.str.getBytes(2);
  20047. if (!repeatHeader || repeatHeader.length < 2 || repeatHeader[0] === 128) {
  20048. this.eof = true;
  20049. return;
  20050. }
  20051. var buffer;
  20052. var bufferLength = this.bufferLength;
  20053. var n = repeatHeader[0];
  20054. if (n < 128) {
  20055. // copy n bytes
  20056. buffer = this.ensureBuffer(bufferLength + n + 1);
  20057. buffer[bufferLength++] = repeatHeader[1];
  20058. if (n > 0) {
  20059. var source = this.str.getBytes(n);
  20060. buffer.set(source, bufferLength);
  20061. bufferLength += n;
  20062. }
  20063. } else {
  20064. n = 257 - n;
  20065. var b = repeatHeader[1];
  20066. buffer = this.ensureBuffer(bufferLength + n + 1);
  20067. for (var i = 0; i < n; i++) {
  20068. buffer[bufferLength++] = b;
  20069. }
  20070. }
  20071. this.bufferLength = bufferLength;
  20072. };
  20073. return RunLengthStream;
  20074. })();
  20075. var CCITTFaxStream = (function CCITTFaxStreamClosure() {
  20076. var ccittEOL = -2;
  20077. var ccittEOF = -1;
  20078. var twoDimPass = 0;
  20079. var twoDimHoriz = 1;
  20080. var twoDimVert0 = 2;
  20081. var twoDimVertR1 = 3;
  20082. var twoDimVertL1 = 4;
  20083. var twoDimVertR2 = 5;
  20084. var twoDimVertL2 = 6;
  20085. var twoDimVertR3 = 7;
  20086. var twoDimVertL3 = 8;
  20087. var twoDimTable = [
  20088. [-1, -1], [-1, -1], // 000000x
  20089. [7, twoDimVertL3], // 0000010
  20090. [7, twoDimVertR3], // 0000011
  20091. [6, twoDimVertL2], [6, twoDimVertL2], // 000010x
  20092. [6, twoDimVertR2], [6, twoDimVertR2], // 000011x
  20093. [4, twoDimPass], [4, twoDimPass], // 0001xxx
  20094. [4, twoDimPass], [4, twoDimPass],
  20095. [4, twoDimPass], [4, twoDimPass],
  20096. [4, twoDimPass], [4, twoDimPass],
  20097. [3, twoDimHoriz], [3, twoDimHoriz], // 001xxxx
  20098. [3, twoDimHoriz], [3, twoDimHoriz],
  20099. [3, twoDimHoriz], [3, twoDimHoriz],
  20100. [3, twoDimHoriz], [3, twoDimHoriz],
  20101. [3, twoDimHoriz], [3, twoDimHoriz],
  20102. [3, twoDimHoriz], [3, twoDimHoriz],
  20103. [3, twoDimHoriz], [3, twoDimHoriz],
  20104. [3, twoDimHoriz], [3, twoDimHoriz],
  20105. [3, twoDimVertL1], [3, twoDimVertL1], // 010xxxx
  20106. [3, twoDimVertL1], [3, twoDimVertL1],
  20107. [3, twoDimVertL1], [3, twoDimVertL1],
  20108. [3, twoDimVertL1], [3, twoDimVertL1],
  20109. [3, twoDimVertL1], [3, twoDimVertL1],
  20110. [3, twoDimVertL1], [3, twoDimVertL1],
  20111. [3, twoDimVertL1], [3, twoDimVertL1],
  20112. [3, twoDimVertL1], [3, twoDimVertL1],
  20113. [3, twoDimVertR1], [3, twoDimVertR1], // 011xxxx
  20114. [3, twoDimVertR1], [3, twoDimVertR1],
  20115. [3, twoDimVertR1], [3, twoDimVertR1],
  20116. [3, twoDimVertR1], [3, twoDimVertR1],
  20117. [3, twoDimVertR1], [3, twoDimVertR1],
  20118. [3, twoDimVertR1], [3, twoDimVertR1],
  20119. [3, twoDimVertR1], [3, twoDimVertR1],
  20120. [3, twoDimVertR1], [3, twoDimVertR1],
  20121. [1, twoDimVert0], [1, twoDimVert0], // 1xxxxxx
  20122. [1, twoDimVert0], [1, twoDimVert0],
  20123. [1, twoDimVert0], [1, twoDimVert0],
  20124. [1, twoDimVert0], [1, twoDimVert0],
  20125. [1, twoDimVert0], [1, twoDimVert0],
  20126. [1, twoDimVert0], [1, twoDimVert0],
  20127. [1, twoDimVert0], [1, twoDimVert0],
  20128. [1, twoDimVert0], [1, twoDimVert0],
  20129. [1, twoDimVert0], [1, twoDimVert0],
  20130. [1, twoDimVert0], [1, twoDimVert0],
  20131. [1, twoDimVert0], [1, twoDimVert0],
  20132. [1, twoDimVert0], [1, twoDimVert0],
  20133. [1, twoDimVert0], [1, twoDimVert0],
  20134. [1, twoDimVert0], [1, twoDimVert0],
  20135. [1, twoDimVert0], [1, twoDimVert0],
  20136. [1, twoDimVert0], [1, twoDimVert0],
  20137. [1, twoDimVert0], [1, twoDimVert0],
  20138. [1, twoDimVert0], [1, twoDimVert0],
  20139. [1, twoDimVert0], [1, twoDimVert0],
  20140. [1, twoDimVert0], [1, twoDimVert0],
  20141. [1, twoDimVert0], [1, twoDimVert0],
  20142. [1, twoDimVert0], [1, twoDimVert0],
  20143. [1, twoDimVert0], [1, twoDimVert0],
  20144. [1, twoDimVert0], [1, twoDimVert0],
  20145. [1, twoDimVert0], [1, twoDimVert0],
  20146. [1, twoDimVert0], [1, twoDimVert0],
  20147. [1, twoDimVert0], [1, twoDimVert0],
  20148. [1, twoDimVert0], [1, twoDimVert0],
  20149. [1, twoDimVert0], [1, twoDimVert0],
  20150. [1, twoDimVert0], [1, twoDimVert0],
  20151. [1, twoDimVert0], [1, twoDimVert0],
  20152. [1, twoDimVert0], [1, twoDimVert0]
  20153. ];
  20154. var whiteTable1 = [
  20155. [-1, -1], // 00000
  20156. [12, ccittEOL], // 00001
  20157. [-1, -1], [-1, -1], // 0001x
  20158. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 001xx
  20159. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 010xx
  20160. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 011xx
  20161. [11, 1792], [11, 1792], // 1000x
  20162. [12, 1984], // 10010
  20163. [12, 2048], // 10011
  20164. [12, 2112], // 10100
  20165. [12, 2176], // 10101
  20166. [12, 2240], // 10110
  20167. [12, 2304], // 10111
  20168. [11, 1856], [11, 1856], // 1100x
  20169. [11, 1920], [11, 1920], // 1101x
  20170. [12, 2368], // 11100
  20171. [12, 2432], // 11101
  20172. [12, 2496], // 11110
  20173. [12, 2560] // 11111
  20174. ];
  20175. var whiteTable2 = [
  20176. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000000xx
  20177. [8, 29], [8, 29], // 00000010x
  20178. [8, 30], [8, 30], // 00000011x
  20179. [8, 45], [8, 45], // 00000100x
  20180. [8, 46], [8, 46], // 00000101x
  20181. [7, 22], [7, 22], [7, 22], [7, 22], // 0000011xx
  20182. [7, 23], [7, 23], [7, 23], [7, 23], // 0000100xx
  20183. [8, 47], [8, 47], // 00001010x
  20184. [8, 48], [8, 48], // 00001011x
  20185. [6, 13], [6, 13], [6, 13], [6, 13], // 000011xxx
  20186. [6, 13], [6, 13], [6, 13], [6, 13],
  20187. [7, 20], [7, 20], [7, 20], [7, 20], // 0001000xx
  20188. [8, 33], [8, 33], // 00010010x
  20189. [8, 34], [8, 34], // 00010011x
  20190. [8, 35], [8, 35], // 00010100x
  20191. [8, 36], [8, 36], // 00010101x
  20192. [8, 37], [8, 37], // 00010110x
  20193. [8, 38], [8, 38], // 00010111x
  20194. [7, 19], [7, 19], [7, 19], [7, 19], // 0001100xx
  20195. [8, 31], [8, 31], // 00011010x
  20196. [8, 32], [8, 32], // 00011011x
  20197. [6, 1], [6, 1], [6, 1], [6, 1], // 000111xxx
  20198. [6, 1], [6, 1], [6, 1], [6, 1],
  20199. [6, 12], [6, 12], [6, 12], [6, 12], // 001000xxx
  20200. [6, 12], [6, 12], [6, 12], [6, 12],
  20201. [8, 53], [8, 53], // 00100100x
  20202. [8, 54], [8, 54], // 00100101x
  20203. [7, 26], [7, 26], [7, 26], [7, 26], // 0010011xx
  20204. [8, 39], [8, 39], // 00101000x
  20205. [8, 40], [8, 40], // 00101001x
  20206. [8, 41], [8, 41], // 00101010x
  20207. [8, 42], [8, 42], // 00101011x
  20208. [8, 43], [8, 43], // 00101100x
  20209. [8, 44], [8, 44], // 00101101x
  20210. [7, 21], [7, 21], [7, 21], [7, 21], // 0010111xx
  20211. [7, 28], [7, 28], [7, 28], [7, 28], // 0011000xx
  20212. [8, 61], [8, 61], // 00110010x
  20213. [8, 62], [8, 62], // 00110011x
  20214. [8, 63], [8, 63], // 00110100x
  20215. [8, 0], [8, 0], // 00110101x
  20216. [8, 320], [8, 320], // 00110110x
  20217. [8, 384], [8, 384], // 00110111x
  20218. [5, 10], [5, 10], [5, 10], [5, 10], // 00111xxxx
  20219. [5, 10], [5, 10], [5, 10], [5, 10],
  20220. [5, 10], [5, 10], [5, 10], [5, 10],
  20221. [5, 10], [5, 10], [5, 10], [5, 10],
  20222. [5, 11], [5, 11], [5, 11], [5, 11], // 01000xxxx
  20223. [5, 11], [5, 11], [5, 11], [5, 11],
  20224. [5, 11], [5, 11], [5, 11], [5, 11],
  20225. [5, 11], [5, 11], [5, 11], [5, 11],
  20226. [7, 27], [7, 27], [7, 27], [7, 27], // 0100100xx
  20227. [8, 59], [8, 59], // 01001010x
  20228. [8, 60], [8, 60], // 01001011x
  20229. [9, 1472], // 010011000
  20230. [9, 1536], // 010011001
  20231. [9, 1600], // 010011010
  20232. [9, 1728], // 010011011
  20233. [7, 18], [7, 18], [7, 18], [7, 18], // 0100111xx
  20234. [7, 24], [7, 24], [7, 24], [7, 24], // 0101000xx
  20235. [8, 49], [8, 49], // 01010010x
  20236. [8, 50], [8, 50], // 01010011x
  20237. [8, 51], [8, 51], // 01010100x
  20238. [8, 52], [8, 52], // 01010101x
  20239. [7, 25], [7, 25], [7, 25], [7, 25], // 0101011xx
  20240. [8, 55], [8, 55], // 01011000x
  20241. [8, 56], [8, 56], // 01011001x
  20242. [8, 57], [8, 57], // 01011010x
  20243. [8, 58], [8, 58], // 01011011x
  20244. [6, 192], [6, 192], [6, 192], [6, 192], // 010111xxx
  20245. [6, 192], [6, 192], [6, 192], [6, 192],
  20246. [6, 1664], [6, 1664], [6, 1664], [6, 1664], // 011000xxx
  20247. [6, 1664], [6, 1664], [6, 1664], [6, 1664],
  20248. [8, 448], [8, 448], // 01100100x
  20249. [8, 512], [8, 512], // 01100101x
  20250. [9, 704], // 011001100
  20251. [9, 768], // 011001101
  20252. [8, 640], [8, 640], // 01100111x
  20253. [8, 576], [8, 576], // 01101000x
  20254. [9, 832], // 011010010
  20255. [9, 896], // 011010011
  20256. [9, 960], // 011010100
  20257. [9, 1024], // 011010101
  20258. [9, 1088], // 011010110
  20259. [9, 1152], // 011010111
  20260. [9, 1216], // 011011000
  20261. [9, 1280], // 011011001
  20262. [9, 1344], // 011011010
  20263. [9, 1408], // 011011011
  20264. [7, 256], [7, 256], [7, 256], [7, 256], // 0110111xx
  20265. [4, 2], [4, 2], [4, 2], [4, 2], // 0111xxxxx
  20266. [4, 2], [4, 2], [4, 2], [4, 2],
  20267. [4, 2], [4, 2], [4, 2], [4, 2],
  20268. [4, 2], [4, 2], [4, 2], [4, 2],
  20269. [4, 2], [4, 2], [4, 2], [4, 2],
  20270. [4, 2], [4, 2], [4, 2], [4, 2],
  20271. [4, 2], [4, 2], [4, 2], [4, 2],
  20272. [4, 2], [4, 2], [4, 2], [4, 2],
  20273. [4, 3], [4, 3], [4, 3], [4, 3], // 1000xxxxx
  20274. [4, 3], [4, 3], [4, 3], [4, 3],
  20275. [4, 3], [4, 3], [4, 3], [4, 3],
  20276. [4, 3], [4, 3], [4, 3], [4, 3],
  20277. [4, 3], [4, 3], [4, 3], [4, 3],
  20278. [4, 3], [4, 3], [4, 3], [4, 3],
  20279. [4, 3], [4, 3], [4, 3], [4, 3],
  20280. [4, 3], [4, 3], [4, 3], [4, 3],
  20281. [5, 128], [5, 128], [5, 128], [5, 128], // 10010xxxx
  20282. [5, 128], [5, 128], [5, 128], [5, 128],
  20283. [5, 128], [5, 128], [5, 128], [5, 128],
  20284. [5, 128], [5, 128], [5, 128], [5, 128],
  20285. [5, 8], [5, 8], [5, 8], [5, 8], // 10011xxxx
  20286. [5, 8], [5, 8], [5, 8], [5, 8],
  20287. [5, 8], [5, 8], [5, 8], [5, 8],
  20288. [5, 8], [5, 8], [5, 8], [5, 8],
  20289. [5, 9], [5, 9], [5, 9], [5, 9], // 10100xxxx
  20290. [5, 9], [5, 9], [5, 9], [5, 9],
  20291. [5, 9], [5, 9], [5, 9], [5, 9],
  20292. [5, 9], [5, 9], [5, 9], [5, 9],
  20293. [6, 16], [6, 16], [6, 16], [6, 16], // 101010xxx
  20294. [6, 16], [6, 16], [6, 16], [6, 16],
  20295. [6, 17], [6, 17], [6, 17], [6, 17], // 101011xxx
  20296. [6, 17], [6, 17], [6, 17], [6, 17],
  20297. [4, 4], [4, 4], [4, 4], [4, 4], // 1011xxxxx
  20298. [4, 4], [4, 4], [4, 4], [4, 4],
  20299. [4, 4], [4, 4], [4, 4], [4, 4],
  20300. [4, 4], [4, 4], [4, 4], [4, 4],
  20301. [4, 4], [4, 4], [4, 4], [4, 4],
  20302. [4, 4], [4, 4], [4, 4], [4, 4],
  20303. [4, 4], [4, 4], [4, 4], [4, 4],
  20304. [4, 4], [4, 4], [4, 4], [4, 4],
  20305. [4, 5], [4, 5], [4, 5], [4, 5], // 1100xxxxx
  20306. [4, 5], [4, 5], [4, 5], [4, 5],
  20307. [4, 5], [4, 5], [4, 5], [4, 5],
  20308. [4, 5], [4, 5], [4, 5], [4, 5],
  20309. [4, 5], [4, 5], [4, 5], [4, 5],
  20310. [4, 5], [4, 5], [4, 5], [4, 5],
  20311. [4, 5], [4, 5], [4, 5], [4, 5],
  20312. [4, 5], [4, 5], [4, 5], [4, 5],
  20313. [6, 14], [6, 14], [6, 14], [6, 14], // 110100xxx
  20314. [6, 14], [6, 14], [6, 14], [6, 14],
  20315. [6, 15], [6, 15], [6, 15], [6, 15], // 110101xxx
  20316. [6, 15], [6, 15], [6, 15], [6, 15],
  20317. [5, 64], [5, 64], [5, 64], [5, 64], // 11011xxxx
  20318. [5, 64], [5, 64], [5, 64], [5, 64],
  20319. [5, 64], [5, 64], [5, 64], [5, 64],
  20320. [5, 64], [5, 64], [5, 64], [5, 64],
  20321. [4, 6], [4, 6], [4, 6], [4, 6], // 1110xxxxx
  20322. [4, 6], [4, 6], [4, 6], [4, 6],
  20323. [4, 6], [4, 6], [4, 6], [4, 6],
  20324. [4, 6], [4, 6], [4, 6], [4, 6],
  20325. [4, 6], [4, 6], [4, 6], [4, 6],
  20326. [4, 6], [4, 6], [4, 6], [4, 6],
  20327. [4, 6], [4, 6], [4, 6], [4, 6],
  20328. [4, 6], [4, 6], [4, 6], [4, 6],
  20329. [4, 7], [4, 7], [4, 7], [4, 7], // 1111xxxxx
  20330. [4, 7], [4, 7], [4, 7], [4, 7],
  20331. [4, 7], [4, 7], [4, 7], [4, 7],
  20332. [4, 7], [4, 7], [4, 7], [4, 7],
  20333. [4, 7], [4, 7], [4, 7], [4, 7],
  20334. [4, 7], [4, 7], [4, 7], [4, 7],
  20335. [4, 7], [4, 7], [4, 7], [4, 7],
  20336. [4, 7], [4, 7], [4, 7], [4, 7]
  20337. ];
  20338. var blackTable1 = [
  20339. [-1, -1], [-1, -1], // 000000000000x
  20340. [12, ccittEOL], [12, ccittEOL], // 000000000001x
  20341. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000001xx
  20342. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000010xx
  20343. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000011xx
  20344. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000100xx
  20345. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000101xx
  20346. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000110xx
  20347. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 00000000111xx
  20348. [11, 1792], [11, 1792], [11, 1792], [11, 1792], // 00000001000xx
  20349. [12, 1984], [12, 1984], // 000000010010x
  20350. [12, 2048], [12, 2048], // 000000010011x
  20351. [12, 2112], [12, 2112], // 000000010100x
  20352. [12, 2176], [12, 2176], // 000000010101x
  20353. [12, 2240], [12, 2240], // 000000010110x
  20354. [12, 2304], [12, 2304], // 000000010111x
  20355. [11, 1856], [11, 1856], [11, 1856], [11, 1856], // 00000001100xx
  20356. [11, 1920], [11, 1920], [11, 1920], [11, 1920], // 00000001101xx
  20357. [12, 2368], [12, 2368], // 000000011100x
  20358. [12, 2432], [12, 2432], // 000000011101x
  20359. [12, 2496], [12, 2496], // 000000011110x
  20360. [12, 2560], [12, 2560], // 000000011111x
  20361. [10, 18], [10, 18], [10, 18], [10, 18], // 0000001000xxx
  20362. [10, 18], [10, 18], [10, 18], [10, 18],
  20363. [12, 52], [12, 52], // 000000100100x
  20364. [13, 640], // 0000001001010
  20365. [13, 704], // 0000001001011
  20366. [13, 768], // 0000001001100
  20367. [13, 832], // 0000001001101
  20368. [12, 55], [12, 55], // 000000100111x
  20369. [12, 56], [12, 56], // 000000101000x
  20370. [13, 1280], // 0000001010010
  20371. [13, 1344], // 0000001010011
  20372. [13, 1408], // 0000001010100
  20373. [13, 1472], // 0000001010101
  20374. [12, 59], [12, 59], // 000000101011x
  20375. [12, 60], [12, 60], // 000000101100x
  20376. [13, 1536], // 0000001011010
  20377. [13, 1600], // 0000001011011
  20378. [11, 24], [11, 24], [11, 24], [11, 24], // 00000010111xx
  20379. [11, 25], [11, 25], [11, 25], [11, 25], // 00000011000xx
  20380. [13, 1664], // 0000001100100
  20381. [13, 1728], // 0000001100101
  20382. [12, 320], [12, 320], // 000000110011x
  20383. [12, 384], [12, 384], // 000000110100x
  20384. [12, 448], [12, 448], // 000000110101x
  20385. [13, 512], // 0000001101100
  20386. [13, 576], // 0000001101101
  20387. [12, 53], [12, 53], // 000000110111x
  20388. [12, 54], [12, 54], // 000000111000x
  20389. [13, 896], // 0000001110010
  20390. [13, 960], // 0000001110011
  20391. [13, 1024], // 0000001110100
  20392. [13, 1088], // 0000001110101
  20393. [13, 1152], // 0000001110110
  20394. [13, 1216], // 0000001110111
  20395. [10, 64], [10, 64], [10, 64], [10, 64], // 0000001111xxx
  20396. [10, 64], [10, 64], [10, 64], [10, 64]
  20397. ];
  20398. var blackTable2 = [
  20399. [8, 13], [8, 13], [8, 13], [8, 13], // 00000100xxxx
  20400. [8, 13], [8, 13], [8, 13], [8, 13],
  20401. [8, 13], [8, 13], [8, 13], [8, 13],
  20402. [8, 13], [8, 13], [8, 13], [8, 13],
  20403. [11, 23], [11, 23], // 00000101000x
  20404. [12, 50], // 000001010010
  20405. [12, 51], // 000001010011
  20406. [12, 44], // 000001010100
  20407. [12, 45], // 000001010101
  20408. [12, 46], // 000001010110
  20409. [12, 47], // 000001010111
  20410. [12, 57], // 000001011000
  20411. [12, 58], // 000001011001
  20412. [12, 61], // 000001011010
  20413. [12, 256], // 000001011011
  20414. [10, 16], [10, 16], [10, 16], [10, 16], // 0000010111xx
  20415. [10, 17], [10, 17], [10, 17], [10, 17], // 0000011000xx
  20416. [12, 48], // 000001100100
  20417. [12, 49], // 000001100101
  20418. [12, 62], // 000001100110
  20419. [12, 63], // 000001100111
  20420. [12, 30], // 000001101000
  20421. [12, 31], // 000001101001
  20422. [12, 32], // 000001101010
  20423. [12, 33], // 000001101011
  20424. [12, 40], // 000001101100
  20425. [12, 41], // 000001101101
  20426. [11, 22], [11, 22], // 00000110111x
  20427. [8, 14], [8, 14], [8, 14], [8, 14], // 00000111xxxx
  20428. [8, 14], [8, 14], [8, 14], [8, 14],
  20429. [8, 14], [8, 14], [8, 14], [8, 14],
  20430. [8, 14], [8, 14], [8, 14], [8, 14],
  20431. [7, 10], [7, 10], [7, 10], [7, 10], // 0000100xxxxx
  20432. [7, 10], [7, 10], [7, 10], [7, 10],
  20433. [7, 10], [7, 10], [7, 10], [7, 10],
  20434. [7, 10], [7, 10], [7, 10], [7, 10],
  20435. [7, 10], [7, 10], [7, 10], [7, 10],
  20436. [7, 10], [7, 10], [7, 10], [7, 10],
  20437. [7, 10], [7, 10], [7, 10], [7, 10],
  20438. [7, 10], [7, 10], [7, 10], [7, 10],
  20439. [7, 11], [7, 11], [7, 11], [7, 11], // 0000101xxxxx
  20440. [7, 11], [7, 11], [7, 11], [7, 11],
  20441. [7, 11], [7, 11], [7, 11], [7, 11],
  20442. [7, 11], [7, 11], [7, 11], [7, 11],
  20443. [7, 11], [7, 11], [7, 11], [7, 11],
  20444. [7, 11], [7, 11], [7, 11], [7, 11],
  20445. [7, 11], [7, 11], [7, 11], [7, 11],
  20446. [7, 11], [7, 11], [7, 11], [7, 11],
  20447. [9, 15], [9, 15], [9, 15], [9, 15], // 000011000xxx
  20448. [9, 15], [9, 15], [9, 15], [9, 15],
  20449. [12, 128], // 000011001000
  20450. [12, 192], // 000011001001
  20451. [12, 26], // 000011001010
  20452. [12, 27], // 000011001011
  20453. [12, 28], // 000011001100
  20454. [12, 29], // 000011001101
  20455. [11, 19], [11, 19], // 00001100111x
  20456. [11, 20], [11, 20], // 00001101000x
  20457. [12, 34], // 000011010010
  20458. [12, 35], // 000011010011
  20459. [12, 36], // 000011010100
  20460. [12, 37], // 000011010101
  20461. [12, 38], // 000011010110
  20462. [12, 39], // 000011010111
  20463. [11, 21], [11, 21], // 00001101100x
  20464. [12, 42], // 000011011010
  20465. [12, 43], // 000011011011
  20466. [10, 0], [10, 0], [10, 0], [10, 0], // 0000110111xx
  20467. [7, 12], [7, 12], [7, 12], [7, 12], // 0000111xxxxx
  20468. [7, 12], [7, 12], [7, 12], [7, 12],
  20469. [7, 12], [7, 12], [7, 12], [7, 12],
  20470. [7, 12], [7, 12], [7, 12], [7, 12],
  20471. [7, 12], [7, 12], [7, 12], [7, 12],
  20472. [7, 12], [7, 12], [7, 12], [7, 12],
  20473. [7, 12], [7, 12], [7, 12], [7, 12],
  20474. [7, 12], [7, 12], [7, 12], [7, 12]
  20475. ];
  20476. var blackTable3 = [
  20477. [-1, -1], [-1, -1], [-1, -1], [-1, -1], // 0000xx
  20478. [6, 9], // 000100
  20479. [6, 8], // 000101
  20480. [5, 7], [5, 7], // 00011x
  20481. [4, 6], [4, 6], [4, 6], [4, 6], // 0010xx
  20482. [4, 5], [4, 5], [4, 5], [4, 5], // 0011xx
  20483. [3, 1], [3, 1], [3, 1], [3, 1], // 010xxx
  20484. [3, 1], [3, 1], [3, 1], [3, 1],
  20485. [3, 4], [3, 4], [3, 4], [3, 4], // 011xxx
  20486. [3, 4], [3, 4], [3, 4], [3, 4],
  20487. [2, 3], [2, 3], [2, 3], [2, 3], // 10xxxx
  20488. [2, 3], [2, 3], [2, 3], [2, 3],
  20489. [2, 3], [2, 3], [2, 3], [2, 3],
  20490. [2, 3], [2, 3], [2, 3], [2, 3],
  20491. [2, 2], [2, 2], [2, 2], [2, 2], // 11xxxx
  20492. [2, 2], [2, 2], [2, 2], [2, 2],
  20493. [2, 2], [2, 2], [2, 2], [2, 2],
  20494. [2, 2], [2, 2], [2, 2], [2, 2]
  20495. ];
  20496. function CCITTFaxStream(str, maybeLength, params) {
  20497. this.str = str;
  20498. this.dict = str.dict;
  20499. params = params || Dict.empty;
  20500. this.encoding = params.get('K') || 0;
  20501. this.eoline = params.get('EndOfLine') || false;
  20502. this.byteAlign = params.get('EncodedByteAlign') || false;
  20503. this.columns = params.get('Columns') || 1728;
  20504. this.rows = params.get('Rows') || 0;
  20505. var eoblock = params.get('EndOfBlock');
  20506. if (eoblock === null || eoblock === undefined) {
  20507. eoblock = true;
  20508. }
  20509. this.eoblock = eoblock;
  20510. this.black = params.get('BlackIs1') || false;
  20511. this.codingLine = new Uint32Array(this.columns + 1);
  20512. this.refLine = new Uint32Array(this.columns + 2);
  20513. this.codingLine[0] = this.columns;
  20514. this.codingPos = 0;
  20515. this.row = 0;
  20516. this.nextLine2D = this.encoding < 0;
  20517. this.inputBits = 0;
  20518. this.inputBuf = 0;
  20519. this.outputBits = 0;
  20520. var code1;
  20521. while ((code1 = this.lookBits(12)) === 0) {
  20522. this.eatBits(1);
  20523. }
  20524. if (code1 === 1) {
  20525. this.eatBits(12);
  20526. }
  20527. if (this.encoding > 0) {
  20528. this.nextLine2D = !this.lookBits(1);
  20529. this.eatBits(1);
  20530. }
  20531. DecodeStream.call(this, maybeLength);
  20532. }
  20533. CCITTFaxStream.prototype = Object.create(DecodeStream.prototype);
  20534. CCITTFaxStream.prototype.readBlock = function CCITTFaxStream_readBlock() {
  20535. while (!this.eof) {
  20536. var c = this.lookChar();
  20537. this.ensureBuffer(this.bufferLength + 1);
  20538. this.buffer[this.bufferLength++] = c;
  20539. }
  20540. };
  20541. CCITTFaxStream.prototype.addPixels =
  20542. function ccittFaxStreamAddPixels(a1, blackPixels) {
  20543. var codingLine = this.codingLine;
  20544. var codingPos = this.codingPos;
  20545. if (a1 > codingLine[codingPos]) {
  20546. if (a1 > this.columns) {
  20547. info('row is wrong length');
  20548. this.err = true;
  20549. a1 = this.columns;
  20550. }
  20551. if ((codingPos & 1) ^ blackPixels) {
  20552. ++codingPos;
  20553. }
  20554. codingLine[codingPos] = a1;
  20555. }
  20556. this.codingPos = codingPos;
  20557. };
  20558. CCITTFaxStream.prototype.addPixelsNeg =
  20559. function ccittFaxStreamAddPixelsNeg(a1, blackPixels) {
  20560. var codingLine = this.codingLine;
  20561. var codingPos = this.codingPos;
  20562. if (a1 > codingLine[codingPos]) {
  20563. if (a1 > this.columns) {
  20564. info('row is wrong length');
  20565. this.err = true;
  20566. a1 = this.columns;
  20567. }
  20568. if ((codingPos & 1) ^ blackPixels) {
  20569. ++codingPos;
  20570. }
  20571. codingLine[codingPos] = a1;
  20572. } else if (a1 < codingLine[codingPos]) {
  20573. if (a1 < 0) {
  20574. info('invalid code');
  20575. this.err = true;
  20576. a1 = 0;
  20577. }
  20578. while (codingPos > 0 && a1 < codingLine[codingPos - 1]) {
  20579. --codingPos;
  20580. }
  20581. codingLine[codingPos] = a1;
  20582. }
  20583. this.codingPos = codingPos;
  20584. };
  20585. CCITTFaxStream.prototype.lookChar = function CCITTFaxStream_lookChar() {
  20586. var refLine = this.refLine;
  20587. var codingLine = this.codingLine;
  20588. var columns = this.columns;
  20589. var refPos, blackPixels, bits, i;
  20590. if (this.outputBits === 0) {
  20591. if (this.eof) {
  20592. return null;
  20593. }
  20594. this.err = false;
  20595. var code1, code2, code3;
  20596. if (this.nextLine2D) {
  20597. for (i = 0; codingLine[i] < columns; ++i) {
  20598. refLine[i] = codingLine[i];
  20599. }
  20600. refLine[i++] = columns;
  20601. refLine[i] = columns;
  20602. codingLine[0] = 0;
  20603. this.codingPos = 0;
  20604. refPos = 0;
  20605. blackPixels = 0;
  20606. while (codingLine[this.codingPos] < columns) {
  20607. code1 = this.getTwoDimCode();
  20608. switch (code1) {
  20609. case twoDimPass:
  20610. this.addPixels(refLine[refPos + 1], blackPixels);
  20611. if (refLine[refPos + 1] < columns) {
  20612. refPos += 2;
  20613. }
  20614. break;
  20615. case twoDimHoriz:
  20616. code1 = code2 = 0;
  20617. if (blackPixels) {
  20618. do {
  20619. code1 += (code3 = this.getBlackCode());
  20620. } while (code3 >= 64);
  20621. do {
  20622. code2 += (code3 = this.getWhiteCode());
  20623. } while (code3 >= 64);
  20624. } else {
  20625. do {
  20626. code1 += (code3 = this.getWhiteCode());
  20627. } while (code3 >= 64);
  20628. do {
  20629. code2 += (code3 = this.getBlackCode());
  20630. } while (code3 >= 64);
  20631. }
  20632. this.addPixels(codingLine[this.codingPos] +
  20633. code1, blackPixels);
  20634. if (codingLine[this.codingPos] < columns) {
  20635. this.addPixels(codingLine[this.codingPos] + code2,
  20636. blackPixels ^ 1);
  20637. }
  20638. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20639. refLine[refPos] < columns) {
  20640. refPos += 2;
  20641. }
  20642. break;
  20643. case twoDimVertR3:
  20644. this.addPixels(refLine[refPos] + 3, blackPixels);
  20645. blackPixels ^= 1;
  20646. if (codingLine[this.codingPos] < columns) {
  20647. ++refPos;
  20648. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20649. refLine[refPos] < columns) {
  20650. refPos += 2;
  20651. }
  20652. }
  20653. break;
  20654. case twoDimVertR2:
  20655. this.addPixels(refLine[refPos] + 2, blackPixels);
  20656. blackPixels ^= 1;
  20657. if (codingLine[this.codingPos] < columns) {
  20658. ++refPos;
  20659. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20660. refLine[refPos] < columns) {
  20661. refPos += 2;
  20662. }
  20663. }
  20664. break;
  20665. case twoDimVertR1:
  20666. this.addPixels(refLine[refPos] + 1, blackPixels);
  20667. blackPixels ^= 1;
  20668. if (codingLine[this.codingPos] < columns) {
  20669. ++refPos;
  20670. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20671. refLine[refPos] < columns) {
  20672. refPos += 2;
  20673. }
  20674. }
  20675. break;
  20676. case twoDimVert0:
  20677. this.addPixels(refLine[refPos], blackPixels);
  20678. blackPixels ^= 1;
  20679. if (codingLine[this.codingPos] < columns) {
  20680. ++refPos;
  20681. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20682. refLine[refPos] < columns) {
  20683. refPos += 2;
  20684. }
  20685. }
  20686. break;
  20687. case twoDimVertL3:
  20688. this.addPixelsNeg(refLine[refPos] - 3, blackPixels);
  20689. blackPixels ^= 1;
  20690. if (codingLine[this.codingPos] < columns) {
  20691. if (refPos > 0) {
  20692. --refPos;
  20693. } else {
  20694. ++refPos;
  20695. }
  20696. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20697. refLine[refPos] < columns) {
  20698. refPos += 2;
  20699. }
  20700. }
  20701. break;
  20702. case twoDimVertL2:
  20703. this.addPixelsNeg(refLine[refPos] - 2, blackPixels);
  20704. blackPixels ^= 1;
  20705. if (codingLine[this.codingPos] < columns) {
  20706. if (refPos > 0) {
  20707. --refPos;
  20708. } else {
  20709. ++refPos;
  20710. }
  20711. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20712. refLine[refPos] < columns) {
  20713. refPos += 2;
  20714. }
  20715. }
  20716. break;
  20717. case twoDimVertL1:
  20718. this.addPixelsNeg(refLine[refPos] - 1, blackPixels);
  20719. blackPixels ^= 1;
  20720. if (codingLine[this.codingPos] < columns) {
  20721. if (refPos > 0) {
  20722. --refPos;
  20723. } else {
  20724. ++refPos;
  20725. }
  20726. while (refLine[refPos] <= codingLine[this.codingPos] &&
  20727. refLine[refPos] < columns) {
  20728. refPos += 2;
  20729. }
  20730. }
  20731. break;
  20732. case ccittEOF:
  20733. this.addPixels(columns, 0);
  20734. this.eof = true;
  20735. break;
  20736. default:
  20737. info('bad 2d code');
  20738. this.addPixels(columns, 0);
  20739. this.err = true;
  20740. }
  20741. }
  20742. } else {
  20743. codingLine[0] = 0;
  20744. this.codingPos = 0;
  20745. blackPixels = 0;
  20746. while (codingLine[this.codingPos] < columns) {
  20747. code1 = 0;
  20748. if (blackPixels) {
  20749. do {
  20750. code1 += (code3 = this.getBlackCode());
  20751. } while (code3 >= 64);
  20752. } else {
  20753. do {
  20754. code1 += (code3 = this.getWhiteCode());
  20755. } while (code3 >= 64);
  20756. }
  20757. this.addPixels(codingLine[this.codingPos] + code1, blackPixels);
  20758. blackPixels ^= 1;
  20759. }
  20760. }
  20761. var gotEOL = false;
  20762. if (this.byteAlign) {
  20763. this.inputBits &= ~7;
  20764. }
  20765. if (!this.eoblock && this.row === this.rows - 1) {
  20766. this.eof = true;
  20767. } else {
  20768. code1 = this.lookBits(12);
  20769. if (this.eoline) {
  20770. while (code1 !== ccittEOF && code1 !== 1) {
  20771. this.eatBits(1);
  20772. code1 = this.lookBits(12);
  20773. }
  20774. } else {
  20775. while (code1 === 0) {
  20776. this.eatBits(1);
  20777. code1 = this.lookBits(12);
  20778. }
  20779. }
  20780. if (code1 === 1) {
  20781. this.eatBits(12);
  20782. gotEOL = true;
  20783. } else if (code1 === ccittEOF) {
  20784. this.eof = true;
  20785. }
  20786. }
  20787. if (!this.eof && this.encoding > 0) {
  20788. this.nextLine2D = !this.lookBits(1);
  20789. this.eatBits(1);
  20790. }
  20791. if (this.eoblock && gotEOL && this.byteAlign) {
  20792. code1 = this.lookBits(12);
  20793. if (code1 === 1) {
  20794. this.eatBits(12);
  20795. if (this.encoding > 0) {
  20796. this.lookBits(1);
  20797. this.eatBits(1);
  20798. }
  20799. if (this.encoding >= 0) {
  20800. for (i = 0; i < 4; ++i) {
  20801. code1 = this.lookBits(12);
  20802. if (code1 !== 1) {
  20803. info('bad rtc code: ' + code1);
  20804. }
  20805. this.eatBits(12);
  20806. if (this.encoding > 0) {
  20807. this.lookBits(1);
  20808. this.eatBits(1);
  20809. }
  20810. }
  20811. }
  20812. this.eof = true;
  20813. }
  20814. } else if (this.err && this.eoline) {
  20815. while (true) {
  20816. code1 = this.lookBits(13);
  20817. if (code1 === ccittEOF) {
  20818. this.eof = true;
  20819. return null;
  20820. }
  20821. if ((code1 >> 1) === 1) {
  20822. break;
  20823. }
  20824. this.eatBits(1);
  20825. }
  20826. this.eatBits(12);
  20827. if (this.encoding > 0) {
  20828. this.eatBits(1);
  20829. this.nextLine2D = !(code1 & 1);
  20830. }
  20831. }
  20832. if (codingLine[0] > 0) {
  20833. this.outputBits = codingLine[this.codingPos = 0];
  20834. } else {
  20835. this.outputBits = codingLine[this.codingPos = 1];
  20836. }
  20837. this.row++;
  20838. }
  20839. var c;
  20840. if (this.outputBits >= 8) {
  20841. c = (this.codingPos & 1) ? 0 : 0xFF;
  20842. this.outputBits -= 8;
  20843. if (this.outputBits === 0 && codingLine[this.codingPos] < columns) {
  20844. this.codingPos++;
  20845. this.outputBits = (codingLine[this.codingPos] -
  20846. codingLine[this.codingPos - 1]);
  20847. }
  20848. } else {
  20849. bits = 8;
  20850. c = 0;
  20851. do {
  20852. if (this.outputBits > bits) {
  20853. c <<= bits;
  20854. if (!(this.codingPos & 1)) {
  20855. c |= 0xFF >> (8 - bits);
  20856. }
  20857. this.outputBits -= bits;
  20858. bits = 0;
  20859. } else {
  20860. c <<= this.outputBits;
  20861. if (!(this.codingPos & 1)) {
  20862. c |= 0xFF >> (8 - this.outputBits);
  20863. }
  20864. bits -= this.outputBits;
  20865. this.outputBits = 0;
  20866. if (codingLine[this.codingPos] < columns) {
  20867. this.codingPos++;
  20868. this.outputBits = (codingLine[this.codingPos] -
  20869. codingLine[this.codingPos - 1]);
  20870. } else if (bits > 0) {
  20871. c <<= bits;
  20872. bits = 0;
  20873. }
  20874. }
  20875. } while (bits);
  20876. }
  20877. if (this.black) {
  20878. c ^= 0xFF;
  20879. }
  20880. return c;
  20881. };
  20882. // This functions returns the code found from the table.
  20883. // The start and end parameters set the boundaries for searching the table.
  20884. // The limit parameter is optional. Function returns an array with three
  20885. // values. The first array element indicates whether a valid code is being
  20886. // returned. The second array element is the actual code. The third array
  20887. // element indicates whether EOF was reached.
  20888. CCITTFaxStream.prototype.findTableCode =
  20889. function ccittFaxStreamFindTableCode(start, end, table, limit) {
  20890. var limitValue = limit || 0;
  20891. for (var i = start; i <= end; ++i) {
  20892. var code = this.lookBits(i);
  20893. if (code === ccittEOF) {
  20894. return [true, 1, false];
  20895. }
  20896. if (i < end) {
  20897. code <<= end - i;
  20898. }
  20899. if (!limitValue || code >= limitValue) {
  20900. var p = table[code - limitValue];
  20901. if (p[0] === i) {
  20902. this.eatBits(i);
  20903. return [true, p[1], true];
  20904. }
  20905. }
  20906. }
  20907. return [false, 0, false];
  20908. };
  20909. CCITTFaxStream.prototype.getTwoDimCode =
  20910. function ccittFaxStreamGetTwoDimCode() {
  20911. var code = 0;
  20912. var p;
  20913. if (this.eoblock) {
  20914. code = this.lookBits(7);
  20915. p = twoDimTable[code];
  20916. if (p && p[0] > 0) {
  20917. this.eatBits(p[0]);
  20918. return p[1];
  20919. }
  20920. } else {
  20921. var result = this.findTableCode(1, 7, twoDimTable);
  20922. if (result[0] && result[2]) {
  20923. return result[1];
  20924. }
  20925. }
  20926. info('Bad two dim code');
  20927. return ccittEOF;
  20928. };
  20929. CCITTFaxStream.prototype.getWhiteCode =
  20930. function ccittFaxStreamGetWhiteCode() {
  20931. var code = 0;
  20932. var p;
  20933. if (this.eoblock) {
  20934. code = this.lookBits(12);
  20935. if (code === ccittEOF) {
  20936. return 1;
  20937. }
  20938. if ((code >> 5) === 0) {
  20939. p = whiteTable1[code];
  20940. } else {
  20941. p = whiteTable2[code >> 3];
  20942. }
  20943. if (p[0] > 0) {
  20944. this.eatBits(p[0]);
  20945. return p[1];
  20946. }
  20947. } else {
  20948. var result = this.findTableCode(1, 9, whiteTable2);
  20949. if (result[0]) {
  20950. return result[1];
  20951. }
  20952. result = this.findTableCode(11, 12, whiteTable1);
  20953. if (result[0]) {
  20954. return result[1];
  20955. }
  20956. }
  20957. info('bad white code');
  20958. this.eatBits(1);
  20959. return 1;
  20960. };
  20961. CCITTFaxStream.prototype.getBlackCode =
  20962. function ccittFaxStreamGetBlackCode() {
  20963. var code, p;
  20964. if (this.eoblock) {
  20965. code = this.lookBits(13);
  20966. if (code === ccittEOF) {
  20967. return 1;
  20968. }
  20969. if ((code >> 7) === 0) {
  20970. p = blackTable1[code];
  20971. } else if ((code >> 9) === 0 && (code >> 7) !== 0) {
  20972. p = blackTable2[(code >> 1) - 64];
  20973. } else {
  20974. p = blackTable3[code >> 7];
  20975. }
  20976. if (p[0] > 0) {
  20977. this.eatBits(p[0]);
  20978. return p[1];
  20979. }
  20980. } else {
  20981. var result = this.findTableCode(2, 6, blackTable3);
  20982. if (result[0]) {
  20983. return result[1];
  20984. }
  20985. result = this.findTableCode(7, 12, blackTable2, 64);
  20986. if (result[0]) {
  20987. return result[1];
  20988. }
  20989. result = this.findTableCode(10, 13, blackTable1);
  20990. if (result[0]) {
  20991. return result[1];
  20992. }
  20993. }
  20994. info('bad black code');
  20995. this.eatBits(1);
  20996. return 1;
  20997. };
  20998. CCITTFaxStream.prototype.lookBits = function CCITTFaxStream_lookBits(n) {
  20999. var c;
  21000. while (this.inputBits < n) {
  21001. if ((c = this.str.getByte()) === -1) {
  21002. if (this.inputBits === 0) {
  21003. return ccittEOF;
  21004. }
  21005. return ((this.inputBuf << (n - this.inputBits)) &
  21006. (0xFFFF >> (16 - n)));
  21007. }
  21008. this.inputBuf = (this.inputBuf << 8) | c;
  21009. this.inputBits += 8;
  21010. }
  21011. return (this.inputBuf >> (this.inputBits - n)) & (0xFFFF >> (16 - n));
  21012. };
  21013. CCITTFaxStream.prototype.eatBits = function CCITTFaxStream_eatBits(n) {
  21014. if ((this.inputBits -= n) < 0) {
  21015. this.inputBits = 0;
  21016. }
  21017. };
  21018. return CCITTFaxStream;
  21019. })();
  21020. var LZWStream = (function LZWStreamClosure() {
  21021. function LZWStream(str, maybeLength, earlyChange) {
  21022. this.str = str;
  21023. this.dict = str.dict;
  21024. this.cachedData = 0;
  21025. this.bitsCached = 0;
  21026. var maxLzwDictionarySize = 4096;
  21027. var lzwState = {
  21028. earlyChange: earlyChange,
  21029. codeLength: 9,
  21030. nextCode: 258,
  21031. dictionaryValues: new Uint8Array(maxLzwDictionarySize),
  21032. dictionaryLengths: new Uint16Array(maxLzwDictionarySize),
  21033. dictionaryPrevCodes: new Uint16Array(maxLzwDictionarySize),
  21034. currentSequence: new Uint8Array(maxLzwDictionarySize),
  21035. currentSequenceLength: 0
  21036. };
  21037. for (var i = 0; i < 256; ++i) {
  21038. lzwState.dictionaryValues[i] = i;
  21039. lzwState.dictionaryLengths[i] = 1;
  21040. }
  21041. this.lzwState = lzwState;
  21042. DecodeStream.call(this, maybeLength);
  21043. }
  21044. LZWStream.prototype = Object.create(DecodeStream.prototype);
  21045. LZWStream.prototype.readBits = function LZWStream_readBits(n) {
  21046. var bitsCached = this.bitsCached;
  21047. var cachedData = this.cachedData;
  21048. while (bitsCached < n) {
  21049. var c = this.str.getByte();
  21050. if (c === -1) {
  21051. this.eof = true;
  21052. return null;
  21053. }
  21054. cachedData = (cachedData << 8) | c;
  21055. bitsCached += 8;
  21056. }
  21057. this.bitsCached = (bitsCached -= n);
  21058. this.cachedData = cachedData;
  21059. this.lastCode = null;
  21060. return (cachedData >>> bitsCached) & ((1 << n) - 1);
  21061. };
  21062. LZWStream.prototype.readBlock = function LZWStream_readBlock() {
  21063. var blockSize = 512;
  21064. var estimatedDecodedSize = blockSize * 2, decodedSizeDelta = blockSize;
  21065. var i, j, q;
  21066. var lzwState = this.lzwState;
  21067. if (!lzwState) {
  21068. return; // eof was found
  21069. }
  21070. var earlyChange = lzwState.earlyChange;
  21071. var nextCode = lzwState.nextCode;
  21072. var dictionaryValues = lzwState.dictionaryValues;
  21073. var dictionaryLengths = lzwState.dictionaryLengths;
  21074. var dictionaryPrevCodes = lzwState.dictionaryPrevCodes;
  21075. var codeLength = lzwState.codeLength;
  21076. var prevCode = lzwState.prevCode;
  21077. var currentSequence = lzwState.currentSequence;
  21078. var currentSequenceLength = lzwState.currentSequenceLength;
  21079. var decodedLength = 0;
  21080. var currentBufferLength = this.bufferLength;
  21081. var buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21082. for (i = 0; i < blockSize; i++) {
  21083. var code = this.readBits(codeLength);
  21084. var hasPrev = currentSequenceLength > 0;
  21085. if (code < 256) {
  21086. currentSequence[0] = code;
  21087. currentSequenceLength = 1;
  21088. } else if (code >= 258) {
  21089. if (code < nextCode) {
  21090. currentSequenceLength = dictionaryLengths[code];
  21091. for (j = currentSequenceLength - 1, q = code; j >= 0; j--) {
  21092. currentSequence[j] = dictionaryValues[q];
  21093. q = dictionaryPrevCodes[q];
  21094. }
  21095. } else {
  21096. currentSequence[currentSequenceLength++] = currentSequence[0];
  21097. }
  21098. } else if (code === 256) {
  21099. codeLength = 9;
  21100. nextCode = 258;
  21101. currentSequenceLength = 0;
  21102. continue;
  21103. } else {
  21104. this.eof = true;
  21105. delete this.lzwState;
  21106. break;
  21107. }
  21108. if (hasPrev) {
  21109. dictionaryPrevCodes[nextCode] = prevCode;
  21110. dictionaryLengths[nextCode] = dictionaryLengths[prevCode] + 1;
  21111. dictionaryValues[nextCode] = currentSequence[0];
  21112. nextCode++;
  21113. codeLength = (nextCode + earlyChange) & (nextCode + earlyChange - 1) ?
  21114. codeLength : Math.min(Math.log(nextCode + earlyChange) /
  21115. 0.6931471805599453 + 1, 12) | 0;
  21116. }
  21117. prevCode = code;
  21118. decodedLength += currentSequenceLength;
  21119. if (estimatedDecodedSize < decodedLength) {
  21120. do {
  21121. estimatedDecodedSize += decodedSizeDelta;
  21122. } while (estimatedDecodedSize < decodedLength);
  21123. buffer = this.ensureBuffer(this.bufferLength + estimatedDecodedSize);
  21124. }
  21125. for (j = 0; j < currentSequenceLength; j++) {
  21126. buffer[currentBufferLength++] = currentSequence[j];
  21127. }
  21128. }
  21129. lzwState.nextCode = nextCode;
  21130. lzwState.codeLength = codeLength;
  21131. lzwState.prevCode = prevCode;
  21132. lzwState.currentSequenceLength = currentSequenceLength;
  21133. this.bufferLength = currentBufferLength;
  21134. };
  21135. return LZWStream;
  21136. })();
  21137. var NullStream = (function NullStreamClosure() {
  21138. function NullStream() {
  21139. Stream.call(this, new Uint8Array(0));
  21140. }
  21141. NullStream.prototype = Stream.prototype;
  21142. return NullStream;
  21143. })();
  21144. exports.Ascii85Stream = Ascii85Stream;
  21145. exports.AsciiHexStream = AsciiHexStream;
  21146. exports.CCITTFaxStream = CCITTFaxStream;
  21147. exports.DecryptStream = DecryptStream;
  21148. exports.DecodeStream = DecodeStream;
  21149. exports.FlateStream = FlateStream;
  21150. exports.Jbig2Stream = Jbig2Stream;
  21151. exports.JpegStream = JpegStream;
  21152. exports.JpxStream = JpxStream;
  21153. exports.NullStream = NullStream;
  21154. exports.PredictorStream = PredictorStream;
  21155. exports.RunLengthStream = RunLengthStream;
  21156. exports.Stream = Stream;
  21157. exports.StreamsSequenceStream = StreamsSequenceStream;
  21158. exports.StringStream = StringStream;
  21159. exports.LZWStream = LZWStream;
  21160. }));
  21161. (function (root, factory) {
  21162. {
  21163. factory((root.pdfjsDisplayDOMUtils = {}), root.pdfjsSharedUtil,
  21164. root.pdfjsDisplayGlobal);
  21165. }
  21166. }(this, function (exports, sharedUtil, displayGlobal) {
  21167. var deprecated = sharedUtil.deprecated;
  21168. var removeNullCharacters = sharedUtil.removeNullCharacters;
  21169. var shadow = sharedUtil.shadow;
  21170. var warn = sharedUtil.warn;
  21171. var PDFJS = displayGlobal.PDFJS;
  21172. /**
  21173. * Optimised CSS custom property getter/setter.
  21174. * @class
  21175. */
  21176. var CustomStyle = (function CustomStyleClosure() {
  21177. // As noted on: http://www.zachstronaut.com/posts/2009/02/17/
  21178. // animate-css-transforms-firefox-webkit.html
  21179. // in some versions of IE9 it is critical that ms appear in this list
  21180. // before Moz
  21181. var prefixes = ['ms', 'Moz', 'Webkit', 'O'];
  21182. var _cache = Object.create(null);
  21183. function CustomStyle() {}
  21184. CustomStyle.getProp = function get(propName, element) {
  21185. // check cache only when no element is given
  21186. if (arguments.length === 1 && typeof _cache[propName] === 'string') {
  21187. return _cache[propName];
  21188. }
  21189. element = element || document.documentElement;
  21190. var style = element.style, prefixed, uPropName;
  21191. // test standard property first
  21192. if (typeof style[propName] === 'string') {
  21193. return (_cache[propName] = propName);
  21194. }
  21195. // capitalize
  21196. uPropName = propName.charAt(0).toUpperCase() + propName.slice(1);
  21197. // test vendor specific properties
  21198. for (var i = 0, l = prefixes.length; i < l; i++) {
  21199. prefixed = prefixes[i] + uPropName;
  21200. if (typeof style[prefixed] === 'string') {
  21201. return (_cache[propName] = prefixed);
  21202. }
  21203. }
  21204. //if all fails then set to undefined
  21205. return (_cache[propName] = 'undefined');
  21206. };
  21207. CustomStyle.setProp = function set(propName, element, str) {
  21208. var prop = this.getProp(propName);
  21209. if (prop !== 'undefined') {
  21210. element.style[prop] = str;
  21211. }
  21212. };
  21213. return CustomStyle;
  21214. })();
  21215. PDFJS.CustomStyle = CustomStyle;
  21216. // Lazy test if the userAgent support CanvasTypedArrays
  21217. function hasCanvasTypedArrays() {
  21218. var canvas = document.createElement('canvas');
  21219. canvas.width = canvas.height = 1;
  21220. var ctx = canvas.getContext('2d');
  21221. var imageData = ctx.createImageData(1, 1);
  21222. return (typeof imageData.data.buffer !== 'undefined');
  21223. }
  21224. Object.defineProperty(PDFJS, 'hasCanvasTypedArrays', {
  21225. configurable: true,
  21226. get: function PDFJS_hasCanvasTypedArrays() {
  21227. return shadow(PDFJS, 'hasCanvasTypedArrays', hasCanvasTypedArrays());
  21228. }
  21229. });
  21230. var LinkTarget = {
  21231. NONE: 0, // Default value.
  21232. SELF: 1,
  21233. BLANK: 2,
  21234. PARENT: 3,
  21235. TOP: 4,
  21236. };
  21237. PDFJS.LinkTarget = LinkTarget;
  21238. var LinkTargetStringMap = [
  21239. '',
  21240. '_self',
  21241. '_blank',
  21242. '_parent',
  21243. '_top'
  21244. ];
  21245. function isExternalLinkTargetSet() {
  21246. if (PDFJS.openExternalLinksInNewWindow) {
  21247. deprecated('PDFJS.openExternalLinksInNewWindow, please use ' +
  21248. '"PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK" instead.');
  21249. if (PDFJS.externalLinkTarget === LinkTarget.NONE) {
  21250. PDFJS.externalLinkTarget = LinkTarget.BLANK;
  21251. }
  21252. // Reset the deprecated parameter, to suppress further warnings.
  21253. PDFJS.openExternalLinksInNewWindow = false;
  21254. }
  21255. switch (PDFJS.externalLinkTarget) {
  21256. case LinkTarget.NONE:
  21257. return false;
  21258. case LinkTarget.SELF:
  21259. case LinkTarget.BLANK:
  21260. case LinkTarget.PARENT:
  21261. case LinkTarget.TOP:
  21262. return true;
  21263. }
  21264. warn('PDFJS.externalLinkTarget is invalid: ' + PDFJS.externalLinkTarget);
  21265. // Reset the external link target, to suppress further warnings.
  21266. PDFJS.externalLinkTarget = LinkTarget.NONE;
  21267. return false;
  21268. }
  21269. PDFJS.isExternalLinkTargetSet = isExternalLinkTargetSet;
  21270. /**
  21271. * Adds various attributes (href, title, target, rel) to hyperlinks.
  21272. * @param {HTMLLinkElement} link - The link element.
  21273. * @param {Object} params - An object with the properties:
  21274. * @param {string} params.url - An absolute URL.
  21275. */
  21276. function addLinkAttributes(link, params) {
  21277. var url = params && params.url;
  21278. link.href = link.title = (url ? removeNullCharacters(url) : '');
  21279. if (url) {
  21280. if (isExternalLinkTargetSet()) {
  21281. link.target = LinkTargetStringMap[PDFJS.externalLinkTarget];
  21282. }
  21283. // Strip referrer from the URL.
  21284. link.rel = PDFJS.externalLinkRel;
  21285. }
  21286. }
  21287. PDFJS.addLinkAttributes = addLinkAttributes;
  21288. // Gets the file name from a given URL.
  21289. function getFilenameFromUrl(url) {
  21290. var anchor = url.indexOf('#');
  21291. var query = url.indexOf('?');
  21292. var end = Math.min(
  21293. anchor > 0 ? anchor : url.length,
  21294. query > 0 ? query : url.length);
  21295. return url.substring(url.lastIndexOf('/', end) + 1, end);
  21296. }
  21297. PDFJS.getFilenameFromUrl = getFilenameFromUrl;
  21298. exports.CustomStyle = CustomStyle;
  21299. exports.addLinkAttributes = addLinkAttributes;
  21300. exports.isExternalLinkTargetSet = isExternalLinkTargetSet;
  21301. exports.getFilenameFromUrl = getFilenameFromUrl;
  21302. exports.LinkTarget = LinkTarget;
  21303. }));
  21304. (function (root, factory) {
  21305. {
  21306. factory((root.pdfjsDisplayFontLoader = {}), root.pdfjsSharedUtil,
  21307. root.pdfjsDisplayGlobal);
  21308. }
  21309. }(this, function (exports, sharedUtil, displayGlobal) {
  21310. var assert = sharedUtil.assert;
  21311. var bytesToString = sharedUtil.bytesToString;
  21312. var string32 = sharedUtil.string32;
  21313. var shadow = sharedUtil.shadow;
  21314. var warn = sharedUtil.warn;
  21315. var PDFJS = displayGlobal.PDFJS;
  21316. var globalScope = displayGlobal.globalScope;
  21317. var isWorker = displayGlobal.isWorker;
  21318. function FontLoader(docId) {
  21319. this.docId = docId;
  21320. this.styleElement = null;
  21321. this.nativeFontFaces = [];
  21322. this.loadTestFontId = 0;
  21323. this.loadingContext = {
  21324. requests: [],
  21325. nextRequestId: 0
  21326. };
  21327. }
  21328. FontLoader.prototype = {
  21329. insertRule: function fontLoaderInsertRule(rule) {
  21330. var styleElement = this.styleElement;
  21331. if (!styleElement) {
  21332. styleElement = this.styleElement = document.createElement('style');
  21333. styleElement.id = 'PDFJS_FONT_STYLE_TAG_' + this.docId;
  21334. document.documentElement.getElementsByTagName('head')[0].appendChild(
  21335. styleElement);
  21336. }
  21337. var styleSheet = styleElement.sheet;
  21338. styleSheet.insertRule(rule, styleSheet.cssRules.length);
  21339. },
  21340. clear: function fontLoaderClear() {
  21341. var styleElement = this.styleElement;
  21342. if (styleElement) {
  21343. styleElement.parentNode.removeChild(styleElement);
  21344. styleElement = this.styleElement = null;
  21345. }
  21346. this.nativeFontFaces.forEach(function(nativeFontFace) {
  21347. document.fonts.delete(nativeFontFace);
  21348. });
  21349. this.nativeFontFaces.length = 0;
  21350. },
  21351. get loadTestFont() {
  21352. // This is a CFF font with 1 glyph for '.' that fills its entire width and
  21353. // height.
  21354. return shadow(this, 'loadTestFont', atob(
  21355. 'T1RUTwALAIAAAwAwQ0ZGIDHtZg4AAAOYAAAAgUZGVE1lkzZwAAAEHAAAABxHREVGABQAFQ' +
  21356. 'AABDgAAAAeT1MvMlYNYwkAAAEgAAAAYGNtYXABDQLUAAACNAAAAUJoZWFk/xVFDQAAALwA' +
  21357. 'AAA2aGhlYQdkA+oAAAD0AAAAJGhtdHgD6AAAAAAEWAAAAAZtYXhwAAJQAAAAARgAAAAGbm' +
  21358. 'FtZVjmdH4AAAGAAAAAsXBvc3T/hgAzAAADeAAAACAAAQAAAAEAALZRFsRfDzz1AAsD6AAA' +
  21359. 'AADOBOTLAAAAAM4KHDwAAAAAA+gDIQAAAAgAAgAAAAAAAAABAAADIQAAAFoD6AAAAAAD6A' +
  21360. 'ABAAAAAAAAAAAAAAAAAAAAAQAAUAAAAgAAAAQD6AH0AAUAAAKKArwAAACMAooCvAAAAeAA' +
  21361. 'MQECAAACAAYJAAAAAAAAAAAAAQAAAAAAAAAAAAAAAFBmRWQAwAAuAC4DIP84AFoDIQAAAA' +
  21362. 'AAAQAAAAAAAAAAACAAIAABAAAADgCuAAEAAAAAAAAAAQAAAAEAAAAAAAEAAQAAAAEAAAAA' +
  21363. 'AAIAAQAAAAEAAAAAAAMAAQAAAAEAAAAAAAQAAQAAAAEAAAAAAAUAAQAAAAEAAAAAAAYAAQ' +
  21364. 'AAAAMAAQQJAAAAAgABAAMAAQQJAAEAAgABAAMAAQQJAAIAAgABAAMAAQQJAAMAAgABAAMA' +
  21365. 'AQQJAAQAAgABAAMAAQQJAAUAAgABAAMAAQQJAAYAAgABWABYAAAAAAAAAwAAAAMAAAAcAA' +
  21366. 'EAAAAAADwAAwABAAAAHAAEACAAAAAEAAQAAQAAAC7//wAAAC7////TAAEAAAAAAAABBgAA' +
  21367. 'AQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAA' +
  21368. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  21369. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  21370. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' +
  21371. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAAA' +
  21372. 'AAAAD/gwAyAAAAAQAAAAAAAAAAAAAAAAAAAAABAAQEAAEBAQJYAAEBASH4DwD4GwHEAvgc' +
  21373. 'A/gXBIwMAYuL+nz5tQXkD5j3CBLnEQACAQEBIVhYWFhYWFhYWFhYWFhYWFhYWFhYWFhYWF' +
  21374. 'hYWFhYWFhYAAABAQAADwACAQEEE/t3Dov6fAH6fAT+fPp8+nwHDosMCvm1Cvm1DAz6fBQA' +
  21375. 'AAAAAAABAAAAAMmJbzEAAAAAzgTjFQAAAADOBOQpAAEAAAAAAAAADAAUAAQAAAABAAAAAg' +
  21376. 'ABAAAAAAAAAAAD6AAAAAAAAA=='
  21377. ));
  21378. },
  21379. addNativeFontFace: function fontLoader_addNativeFontFace(nativeFontFace) {
  21380. this.nativeFontFaces.push(nativeFontFace);
  21381. document.fonts.add(nativeFontFace);
  21382. },
  21383. bind: function fontLoaderBind(fonts, callback) {
  21384. assert(!isWorker, 'bind() shall be called from main thread');
  21385. var rules = [];
  21386. var fontsToLoad = [];
  21387. var fontLoadPromises = [];
  21388. var getNativeFontPromise = function(nativeFontFace) {
  21389. // Return a promise that is always fulfilled, even when the font fails to
  21390. // load.
  21391. return nativeFontFace.loaded.catch(function(e) {
  21392. warn('Failed to load font "' + nativeFontFace.family + '": ' + e);
  21393. });
  21394. };
  21395. for (var i = 0, ii = fonts.length; i < ii; i++) {
  21396. var font = fonts[i];
  21397. // Add the font to the DOM only once or skip if the font
  21398. // is already loaded.
  21399. if (font.attached || font.loading === false) {
  21400. continue;
  21401. }
  21402. font.attached = true;
  21403. if (FontLoader.isFontLoadingAPISupported) {
  21404. var nativeFontFace = font.createNativeFontFace();
  21405. if (nativeFontFace) {
  21406. this.addNativeFontFace(nativeFontFace);
  21407. fontLoadPromises.push(getNativeFontPromise(nativeFontFace));
  21408. }
  21409. } else {
  21410. var rule = font.createFontFaceRule();
  21411. if (rule) {
  21412. this.insertRule(rule);
  21413. rules.push(rule);
  21414. fontsToLoad.push(font);
  21415. }
  21416. }
  21417. }
  21418. var request = this.queueLoadingCallback(callback);
  21419. if (FontLoader.isFontLoadingAPISupported) {
  21420. Promise.all(fontLoadPromises).then(function() {
  21421. request.complete();
  21422. });
  21423. } else if (rules.length > 0 && !FontLoader.isSyncFontLoadingSupported) {
  21424. this.prepareFontLoadEvent(rules, fontsToLoad, request);
  21425. } else {
  21426. request.complete();
  21427. }
  21428. },
  21429. queueLoadingCallback: function FontLoader_queueLoadingCallback(callback) {
  21430. function LoadLoader_completeRequest() {
  21431. assert(!request.end, 'completeRequest() cannot be called twice');
  21432. request.end = Date.now();
  21433. // sending all completed requests in order how they were queued
  21434. while (context.requests.length > 0 && context.requests[0].end) {
  21435. var otherRequest = context.requests.shift();
  21436. setTimeout(otherRequest.callback, 0);
  21437. }
  21438. }
  21439. var context = this.loadingContext;
  21440. var requestId = 'pdfjs-font-loading-' + (context.nextRequestId++);
  21441. var request = {
  21442. id: requestId,
  21443. complete: LoadLoader_completeRequest,
  21444. callback: callback,
  21445. started: Date.now()
  21446. };
  21447. context.requests.push(request);
  21448. return request;
  21449. },
  21450. prepareFontLoadEvent: function fontLoaderPrepareFontLoadEvent(rules,
  21451. fonts,
  21452. request) {
  21453. /** Hack begin */
  21454. // There's currently no event when a font has finished downloading so the
  21455. // following code is a dirty hack to 'guess' when a font is
  21456. // ready. It's assumed fonts are loaded in order, so add a known test
  21457. // font after the desired fonts and then test for the loading of that
  21458. // test font.
  21459. function int32(data, offset) {
  21460. return (data.charCodeAt(offset) << 24) |
  21461. (data.charCodeAt(offset + 1) << 16) |
  21462. (data.charCodeAt(offset + 2) << 8) |
  21463. (data.charCodeAt(offset + 3) & 0xff);
  21464. }
  21465. function spliceString(s, offset, remove, insert) {
  21466. var chunk1 = s.substr(0, offset);
  21467. var chunk2 = s.substr(offset + remove);
  21468. return chunk1 + insert + chunk2;
  21469. }
  21470. var i, ii;
  21471. var canvas = document.createElement('canvas');
  21472. canvas.width = 1;
  21473. canvas.height = 1;
  21474. var ctx = canvas.getContext('2d');
  21475. var called = 0;
  21476. function isFontReady(name, callback) {
  21477. called++;
  21478. // With setTimeout clamping this gives the font ~100ms to load.
  21479. if(called > 30) {
  21480. warn('Load test font never loaded.');
  21481. callback();
  21482. return;
  21483. }
  21484. ctx.font = '30px ' + name;
  21485. ctx.fillText('.', 0, 20);
  21486. var imageData = ctx.getImageData(0, 0, 1, 1);
  21487. if (imageData.data[3] > 0) {
  21488. callback();
  21489. return;
  21490. }
  21491. setTimeout(isFontReady.bind(null, name, callback));
  21492. }
  21493. var loadTestFontId = 'lt' + Date.now() + this.loadTestFontId++;
  21494. // Chromium seems to cache fonts based on a hash of the actual font data,
  21495. // so the font must be modified for each load test else it will appear to
  21496. // be loaded already.
  21497. // TODO: This could maybe be made faster by avoiding the btoa of the full
  21498. // font by splitting it in chunks before hand and padding the font id.
  21499. var data = this.loadTestFont;
  21500. var COMMENT_OFFSET = 976; // has to be on 4 byte boundary (for checksum)
  21501. data = spliceString(data, COMMENT_OFFSET, loadTestFontId.length,
  21502. loadTestFontId);
  21503. // CFF checksum is important for IE, adjusting it
  21504. var CFF_CHECKSUM_OFFSET = 16;
  21505. var XXXX_VALUE = 0x58585858; // the "comment" filled with 'X'
  21506. var checksum = int32(data, CFF_CHECKSUM_OFFSET);
  21507. for (i = 0, ii = loadTestFontId.length - 3; i < ii; i += 4) {
  21508. checksum = (checksum - XXXX_VALUE + int32(loadTestFontId, i)) | 0;
  21509. }
  21510. if (i < loadTestFontId.length) { // align to 4 bytes boundary
  21511. checksum = (checksum - XXXX_VALUE +
  21512. int32(loadTestFontId + 'XXX', i)) | 0;
  21513. }
  21514. data = spliceString(data, CFF_CHECKSUM_OFFSET, 4, string32(checksum));
  21515. var url = 'url(data:font/opentype;base64,' + btoa(data) + ');';
  21516. var rule = '@font-face { font-family:"' + loadTestFontId + '";src:' +
  21517. url + '}';
  21518. this.insertRule(rule);
  21519. var names = [];
  21520. for (i = 0, ii = fonts.length; i < ii; i++) {
  21521. names.push(fonts[i].loadedName);
  21522. }
  21523. names.push(loadTestFontId);
  21524. var div = document.createElement('div');
  21525. div.setAttribute('style',
  21526. 'visibility: hidden;' +
  21527. 'width: 10px; height: 10px;' +
  21528. 'position: absolute; top: 0px; left: 0px;');
  21529. for (i = 0, ii = names.length; i < ii; ++i) {
  21530. var span = document.createElement('span');
  21531. span.textContent = 'Hi';
  21532. span.style.fontFamily = names[i];
  21533. div.appendChild(span);
  21534. }
  21535. document.body.appendChild(div);
  21536. isFontReady(loadTestFontId, function() {
  21537. document.body.removeChild(div);
  21538. request.complete();
  21539. });
  21540. /** Hack end */
  21541. }
  21542. };
  21543. FontLoader.isFontLoadingAPISupported = (!isWorker &&
  21544. typeof document !== 'undefined' && !!document.fonts);
  21545. Object.defineProperty(FontLoader, 'isSyncFontLoadingSupported', {
  21546. get: function () {
  21547. var supported = false;
  21548. // User agent string sniffing is bad, but there is no reliable way to tell
  21549. // if font is fully loaded and ready to be used with canvas.
  21550. var userAgent = window.navigator.userAgent;
  21551. var m = /Mozilla\/5.0.*?rv:(\d+).*? Gecko/.exec(userAgent);
  21552. if (m && m[1] >= 14) {
  21553. supported = true;
  21554. }
  21555. // TODO other browsers
  21556. if (userAgent === 'node') {
  21557. supported = true;
  21558. }
  21559. return shadow(FontLoader, 'isSyncFontLoadingSupported', supported);
  21560. },
  21561. enumerable: true,
  21562. configurable: true
  21563. });
  21564. var FontFaceObject = (function FontFaceObjectClosure() {
  21565. function FontFaceObject(translatedData) {
  21566. this.compiledGlyphs = Object.create(null);
  21567. // importing translated data
  21568. for (var i in translatedData) {
  21569. this[i] = translatedData[i];
  21570. }
  21571. }
  21572. Object.defineProperty(FontFaceObject, 'isEvalSupported', {
  21573. get: function () {
  21574. var evalSupport = false;
  21575. if (PDFJS.isEvalSupported) {
  21576. try {
  21577. /* jshint evil: true */
  21578. new Function('');
  21579. evalSupport = true;
  21580. } catch (e) {}
  21581. }
  21582. return shadow(this, 'isEvalSupported', evalSupport);
  21583. },
  21584. enumerable: true,
  21585. configurable: true
  21586. });
  21587. FontFaceObject.prototype = {
  21588. createNativeFontFace: function FontFaceObject_createNativeFontFace() {
  21589. if (!this.data) {
  21590. return null;
  21591. }
  21592. if (PDFJS.disableFontFace) {
  21593. this.disableFontFace = true;
  21594. return null;
  21595. }
  21596. var nativeFontFace = new FontFace(this.loadedName, this.data, {});
  21597. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  21598. globalScope['FontInspector'].enabled) {
  21599. globalScope['FontInspector'].fontAdded(this);
  21600. }
  21601. return nativeFontFace;
  21602. },
  21603. createFontFaceRule: function FontFaceObject_createFontFaceRule() {
  21604. if (!this.data) {
  21605. return null;
  21606. }
  21607. if (PDFJS.disableFontFace) {
  21608. this.disableFontFace = true;
  21609. return null;
  21610. }
  21611. var data = bytesToString(new Uint8Array(this.data));
  21612. var fontName = this.loadedName;
  21613. // Add the font-face rule to the document
  21614. var url = ('url(data:' + this.mimetype + ';base64,' +
  21615. window.btoa(data) + ');');
  21616. var rule = '@font-face { font-family:"' + fontName + '";src:' + url + '}';
  21617. if (PDFJS.pdfBug && 'FontInspector' in globalScope &&
  21618. globalScope['FontInspector'].enabled) {
  21619. globalScope['FontInspector'].fontAdded(this, url);
  21620. }
  21621. return rule;
  21622. },
  21623. getPathGenerator:
  21624. function FontFaceObject_getPathGenerator(objs, character) {
  21625. if (!(character in this.compiledGlyphs)) {
  21626. var cmds = objs.get(this.loadedName + '_path_' + character);
  21627. var current, i, len;
  21628. // If we can, compile cmds into JS for MAXIMUM SPEED
  21629. if (FontFaceObject.isEvalSupported) {
  21630. var args, js = '';
  21631. for (i = 0, len = cmds.length; i < len; i++) {
  21632. current = cmds[i];
  21633. if (current.args !== undefined) {
  21634. args = current.args.join(',');
  21635. } else {
  21636. args = '';
  21637. }
  21638. js += 'c.' + current.cmd + '(' + args + ');\n';
  21639. }
  21640. /* jshint -W054 */
  21641. this.compiledGlyphs[character] = new Function('c', 'size', js);
  21642. } else {
  21643. // But fall back on using Function.prototype.apply() if we're
  21644. // blocked from using eval() for whatever reason (like CSP policies)
  21645. this.compiledGlyphs[character] = function(c, size) {
  21646. for (i = 0, len = cmds.length; i < len; i++) {
  21647. current = cmds[i];
  21648. if (current.cmd === 'scale') {
  21649. current.args = [size, -size];
  21650. }
  21651. c[current.cmd].apply(c, current.args);
  21652. }
  21653. };
  21654. }
  21655. }
  21656. return this.compiledGlyphs[character];
  21657. }
  21658. };
  21659. return FontFaceObject;
  21660. })();
  21661. exports.FontFaceObject = FontFaceObject;
  21662. exports.FontLoader = FontLoader;
  21663. }));
  21664. (function (root, factory) {
  21665. {
  21666. factory((root.pdfjsDisplayMetadata = {}), root.pdfjsSharedUtil,
  21667. root.pdfjsDisplayGlobal);
  21668. }
  21669. }(this, function (exports, sharedUtil, displayGlobal) {
  21670. var error = sharedUtil.error;
  21671. var PDFJS = displayGlobal.PDFJS;
  21672. var Metadata = PDFJS.Metadata = (function MetadataClosure() {
  21673. function fixMetadata(meta) {
  21674. return meta.replace(/>\\376\\377([^<]+)/g, function(all, codes) {
  21675. var bytes = codes.replace(/\\([0-3])([0-7])([0-7])/g,
  21676. function(code, d1, d2, d3) {
  21677. return String.fromCharCode(d1 * 64 + d2 * 8 + d3 * 1);
  21678. });
  21679. var chars = '';
  21680. for (var i = 0; i < bytes.length; i += 2) {
  21681. var code = bytes.charCodeAt(i) * 256 + bytes.charCodeAt(i + 1);
  21682. chars += code >= 32 && code < 127 && code !== 60 && code !== 62 &&
  21683. code !== 38 && false ? String.fromCharCode(code) :
  21684. '&#x' + (0x10000 + code).toString(16).substring(1) + ';';
  21685. }
  21686. return '>' + chars;
  21687. });
  21688. }
  21689. function Metadata(meta) {
  21690. if (typeof meta === 'string') {
  21691. // Ghostscript produces invalid metadata
  21692. meta = fixMetadata(meta);
  21693. var parser = new DOMParser();
  21694. meta = parser.parseFromString(meta, 'application/xml');
  21695. } else if (!(meta instanceof Document)) {
  21696. error('Metadata: Invalid metadata object');
  21697. }
  21698. this.metaDocument = meta;
  21699. this.metadata = Object.create(null);
  21700. this.parse();
  21701. }
  21702. Metadata.prototype = {
  21703. parse: function Metadata_parse() {
  21704. var doc = this.metaDocument;
  21705. var rdf = doc.documentElement;
  21706. if (rdf.nodeName.toLowerCase() !== 'rdf:rdf') { // Wrapped in <xmpmeta>
  21707. rdf = rdf.firstChild;
  21708. while (rdf && rdf.nodeName.toLowerCase() !== 'rdf:rdf') {
  21709. rdf = rdf.nextSibling;
  21710. }
  21711. }
  21712. var nodeName = (rdf) ? rdf.nodeName.toLowerCase() : null;
  21713. if (!rdf || nodeName !== 'rdf:rdf' || !rdf.hasChildNodes()) {
  21714. return;
  21715. }
  21716. var children = rdf.childNodes, desc, entry, name, i, ii, length, iLength;
  21717. for (i = 0, length = children.length; i < length; i++) {
  21718. desc = children[i];
  21719. if (desc.nodeName.toLowerCase() !== 'rdf:description') {
  21720. continue;
  21721. }
  21722. for (ii = 0, iLength = desc.childNodes.length; ii < iLength; ii++) {
  21723. if (desc.childNodes[ii].nodeName.toLowerCase() !== '#text') {
  21724. entry = desc.childNodes[ii];
  21725. name = entry.nodeName.toLowerCase();
  21726. this.metadata[name] = entry.textContent.trim();
  21727. }
  21728. }
  21729. }
  21730. },
  21731. get: function Metadata_get(name) {
  21732. return this.metadata[name] || null;
  21733. },
  21734. has: function Metadata_has(name) {
  21735. return typeof this.metadata[name] !== 'undefined';
  21736. }
  21737. };
  21738. return Metadata;
  21739. })();
  21740. exports.Metadata = Metadata;
  21741. }));
  21742. (function (root, factory) {
  21743. {
  21744. factory((root.pdfjsDisplaySVG = {}), root.pdfjsSharedUtil,
  21745. root.pdfjsDisplayGlobal);
  21746. }
  21747. }(this, function (exports, sharedUtil, displayGlobal) {
  21748. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  21749. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  21750. var ImageKind = sharedUtil.ImageKind;
  21751. var OPS = sharedUtil.OPS;
  21752. var Util = sharedUtil.Util;
  21753. var isNum = sharedUtil.isNum;
  21754. var isArray = sharedUtil.isArray;
  21755. var warn = sharedUtil.warn;
  21756. var PDFJS = displayGlobal.PDFJS;
  21757. var SVG_DEFAULTS = {
  21758. fontStyle: 'normal',
  21759. fontWeight: 'normal',
  21760. fillColor: '#000000'
  21761. };
  21762. var convertImgDataToPng = (function convertImgDataToPngClosure() {
  21763. var PNG_HEADER =
  21764. new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
  21765. var CHUNK_WRAPPER_SIZE = 12;
  21766. var crcTable = new Int32Array(256);
  21767. for (var i = 0; i < 256; i++) {
  21768. var c = i;
  21769. for (var h = 0; h < 8; h++) {
  21770. if (c & 1) {
  21771. c = 0xedB88320 ^ ((c >> 1) & 0x7fffffff);
  21772. } else {
  21773. c = (c >> 1) & 0x7fffffff;
  21774. }
  21775. }
  21776. crcTable[i] = c;
  21777. }
  21778. function crc32(data, start, end) {
  21779. var crc = -1;
  21780. for (var i = start; i < end; i++) {
  21781. var a = (crc ^ data[i]) & 0xff;
  21782. var b = crcTable[a];
  21783. crc = (crc >>> 8) ^ b;
  21784. }
  21785. return crc ^ -1;
  21786. }
  21787. function writePngChunk(type, body, data, offset) {
  21788. var p = offset;
  21789. var len = body.length;
  21790. data[p] = len >> 24 & 0xff;
  21791. data[p + 1] = len >> 16 & 0xff;
  21792. data[p + 2] = len >> 8 & 0xff;
  21793. data[p + 3] = len & 0xff;
  21794. p += 4;
  21795. data[p] = type.charCodeAt(0) & 0xff;
  21796. data[p + 1] = type.charCodeAt(1) & 0xff;
  21797. data[p + 2] = type.charCodeAt(2) & 0xff;
  21798. data[p + 3] = type.charCodeAt(3) & 0xff;
  21799. p += 4;
  21800. data.set(body, p);
  21801. p += body.length;
  21802. var crc = crc32(data, offset + 4, p);
  21803. data[p] = crc >> 24 & 0xff;
  21804. data[p + 1] = crc >> 16 & 0xff;
  21805. data[p + 2] = crc >> 8 & 0xff;
  21806. data[p + 3] = crc & 0xff;
  21807. }
  21808. function adler32(data, start, end) {
  21809. var a = 1;
  21810. var b = 0;
  21811. for (var i = start; i < end; ++i) {
  21812. a = (a + (data[i] & 0xff)) % 65521;
  21813. b = (b + a) % 65521;
  21814. }
  21815. return (b << 16) | a;
  21816. }
  21817. function encode(imgData, kind) {
  21818. var width = imgData.width;
  21819. var height = imgData.height;
  21820. var bitDepth, colorType, lineSize;
  21821. var bytes = imgData.data;
  21822. switch (kind) {
  21823. case ImageKind.GRAYSCALE_1BPP:
  21824. colorType = 0;
  21825. bitDepth = 1;
  21826. lineSize = (width + 7) >> 3;
  21827. break;
  21828. case ImageKind.RGB_24BPP:
  21829. colorType = 2;
  21830. bitDepth = 8;
  21831. lineSize = width * 3;
  21832. break;
  21833. case ImageKind.RGBA_32BPP:
  21834. colorType = 6;
  21835. bitDepth = 8;
  21836. lineSize = width * 4;
  21837. break;
  21838. default:
  21839. throw new Error('invalid format');
  21840. }
  21841. // prefix every row with predictor 0
  21842. var literals = new Uint8Array((1 + lineSize) * height);
  21843. var offsetLiterals = 0, offsetBytes = 0;
  21844. var y, i;
  21845. for (y = 0; y < height; ++y) {
  21846. literals[offsetLiterals++] = 0; // no prediction
  21847. literals.set(bytes.subarray(offsetBytes, offsetBytes + lineSize),
  21848. offsetLiterals);
  21849. offsetBytes += lineSize;
  21850. offsetLiterals += lineSize;
  21851. }
  21852. if (kind === ImageKind.GRAYSCALE_1BPP) {
  21853. // inverting for B/W
  21854. offsetLiterals = 0;
  21855. for (y = 0; y < height; y++) {
  21856. offsetLiterals++; // skipping predictor
  21857. for (i = 0; i < lineSize; i++) {
  21858. literals[offsetLiterals++] ^= 0xFF;
  21859. }
  21860. }
  21861. }
  21862. var ihdr = new Uint8Array([
  21863. width >> 24 & 0xff,
  21864. width >> 16 & 0xff,
  21865. width >> 8 & 0xff,
  21866. width & 0xff,
  21867. height >> 24 & 0xff,
  21868. height >> 16 & 0xff,
  21869. height >> 8 & 0xff,
  21870. height & 0xff,
  21871. bitDepth, // bit depth
  21872. colorType, // color type
  21873. 0x00, // compression method
  21874. 0x00, // filter method
  21875. 0x00 // interlace method
  21876. ]);
  21877. var len = literals.length;
  21878. var maxBlockLength = 0xFFFF;
  21879. var deflateBlocks = Math.ceil(len / maxBlockLength);
  21880. var idat = new Uint8Array(2 + len + deflateBlocks * 5 + 4);
  21881. var pi = 0;
  21882. idat[pi++] = 0x78; // compression method and flags
  21883. idat[pi++] = 0x9c; // flags
  21884. var pos = 0;
  21885. while (len > maxBlockLength) {
  21886. // writing non-final DEFLATE blocks type 0 and length of 65535
  21887. idat[pi++] = 0x00;
  21888. idat[pi++] = 0xff;
  21889. idat[pi++] = 0xff;
  21890. idat[pi++] = 0x00;
  21891. idat[pi++] = 0x00;
  21892. idat.set(literals.subarray(pos, pos + maxBlockLength), pi);
  21893. pi += maxBlockLength;
  21894. pos += maxBlockLength;
  21895. len -= maxBlockLength;
  21896. }
  21897. // writing non-final DEFLATE blocks type 0
  21898. idat[pi++] = 0x01;
  21899. idat[pi++] = len & 0xff;
  21900. idat[pi++] = len >> 8 & 0xff;
  21901. idat[pi++] = (~len & 0xffff) & 0xff;
  21902. idat[pi++] = (~len & 0xffff) >> 8 & 0xff;
  21903. idat.set(literals.subarray(pos), pi);
  21904. pi += literals.length - pos;
  21905. var adler = adler32(literals, 0, literals.length); // checksum
  21906. idat[pi++] = adler >> 24 & 0xff;
  21907. idat[pi++] = adler >> 16 & 0xff;
  21908. idat[pi++] = adler >> 8 & 0xff;
  21909. idat[pi++] = adler & 0xff;
  21910. // PNG will consists: header, IHDR+data, IDAT+data, and IEND.
  21911. var pngLength = PNG_HEADER.length + (CHUNK_WRAPPER_SIZE * 3) +
  21912. ihdr.length + idat.length;
  21913. var data = new Uint8Array(pngLength);
  21914. var offset = 0;
  21915. data.set(PNG_HEADER, offset);
  21916. offset += PNG_HEADER.length;
  21917. writePngChunk('IHDR', ihdr, data, offset);
  21918. offset += CHUNK_WRAPPER_SIZE + ihdr.length;
  21919. writePngChunk('IDATA', idat, data, offset);
  21920. offset += CHUNK_WRAPPER_SIZE + idat.length;
  21921. writePngChunk('IEND', new Uint8Array(0), data, offset);
  21922. return PDFJS.createObjectURL(data, 'image/png');
  21923. }
  21924. return function convertImgDataToPng(imgData) {
  21925. var kind = (imgData.kind === undefined ?
  21926. ImageKind.GRAYSCALE_1BPP : imgData.kind);
  21927. return encode(imgData, kind);
  21928. };
  21929. })();
  21930. var SVGExtraState = (function SVGExtraStateClosure() {
  21931. function SVGExtraState() {
  21932. this.fontSizeScale = 1;
  21933. this.fontWeight = SVG_DEFAULTS.fontWeight;
  21934. this.fontSize = 0;
  21935. this.textMatrix = IDENTITY_MATRIX;
  21936. this.fontMatrix = FONT_IDENTITY_MATRIX;
  21937. this.leading = 0;
  21938. // Current point (in user coordinates)
  21939. this.x = 0;
  21940. this.y = 0;
  21941. // Start of text line (in text coordinates)
  21942. this.lineX = 0;
  21943. this.lineY = 0;
  21944. // Character and word spacing
  21945. this.charSpacing = 0;
  21946. this.wordSpacing = 0;
  21947. this.textHScale = 1;
  21948. this.textRise = 0;
  21949. // Default foreground and background colors
  21950. this.fillColor = SVG_DEFAULTS.fillColor;
  21951. this.strokeColor = '#000000';
  21952. this.fillAlpha = 1;
  21953. this.strokeAlpha = 1;
  21954. this.lineWidth = 1;
  21955. this.lineJoin = '';
  21956. this.lineCap = '';
  21957. this.miterLimit = 0;
  21958. this.dashArray = [];
  21959. this.dashPhase = 0;
  21960. this.dependencies = [];
  21961. // Clipping
  21962. this.clipId = '';
  21963. this.pendingClip = false;
  21964. this.maskId = '';
  21965. }
  21966. SVGExtraState.prototype = {
  21967. clone: function SVGExtraState_clone() {
  21968. return Object.create(this);
  21969. },
  21970. setCurrentPoint: function SVGExtraState_setCurrentPoint(x, y) {
  21971. this.x = x;
  21972. this.y = y;
  21973. }
  21974. };
  21975. return SVGExtraState;
  21976. })();
  21977. var SVGGraphics = (function SVGGraphicsClosure() {
  21978. function createScratchSVG(width, height) {
  21979. var NS = 'http://www.w3.org/2000/svg';
  21980. var svg = document.createElementNS(NS, 'svg:svg');
  21981. svg.setAttributeNS(null, 'version', '1.1');
  21982. svg.setAttributeNS(null, 'width', width + 'px');
  21983. svg.setAttributeNS(null, 'height', height + 'px');
  21984. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  21985. return svg;
  21986. }
  21987. function opListToTree(opList) {
  21988. var opTree = [];
  21989. var tmp = [];
  21990. var opListLen = opList.length;
  21991. for (var x = 0; x < opListLen; x++) {
  21992. if (opList[x].fn === 'save') {
  21993. opTree.push({'fnId': 92, 'fn': 'group', 'items': []});
  21994. tmp.push(opTree);
  21995. opTree = opTree[opTree.length - 1].items;
  21996. continue;
  21997. }
  21998. if(opList[x].fn === 'restore') {
  21999. opTree = tmp.pop();
  22000. } else {
  22001. opTree.push(opList[x]);
  22002. }
  22003. }
  22004. return opTree;
  22005. }
  22006. /**
  22007. * Formats float number.
  22008. * @param value {number} number to format.
  22009. * @returns {string}
  22010. */
  22011. function pf(value) {
  22012. if (value === (value | 0)) { // integer number
  22013. return value.toString();
  22014. }
  22015. var s = value.toFixed(10);
  22016. var i = s.length - 1;
  22017. if (s[i] !== '0') {
  22018. return s;
  22019. }
  22020. // removing trailing zeros
  22021. do {
  22022. i--;
  22023. } while (s[i] === '0');
  22024. return s.substr(0, s[i] === '.' ? i : i + 1);
  22025. }
  22026. /**
  22027. * Formats transform matrix. The standard rotation, scale and translate
  22028. * matrices are replaced by their shorter forms, and for identity matrix
  22029. * returns empty string to save the memory.
  22030. * @param m {Array} matrix to format.
  22031. * @returns {string}
  22032. */
  22033. function pm(m) {
  22034. if (m[4] === 0 && m[5] === 0) {
  22035. if (m[1] === 0 && m[2] === 0) {
  22036. if (m[0] === 1 && m[3] === 1) {
  22037. return '';
  22038. }
  22039. return 'scale(' + pf(m[0]) + ' ' + pf(m[3]) + ')';
  22040. }
  22041. if (m[0] === m[3] && m[1] === -m[2]) {
  22042. var a = Math.acos(m[0]) * 180 / Math.PI;
  22043. return 'rotate(' + pf(a) + ')';
  22044. }
  22045. } else {
  22046. if (m[0] === 1 && m[1] === 0 && m[2] === 0 && m[3] === 1) {
  22047. return 'translate(' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  22048. }
  22049. }
  22050. return 'matrix(' + pf(m[0]) + ' ' + pf(m[1]) + ' ' + pf(m[2]) + ' ' +
  22051. pf(m[3]) + ' ' + pf(m[4]) + ' ' + pf(m[5]) + ')';
  22052. }
  22053. function SVGGraphics(commonObjs, objs) {
  22054. this.current = new SVGExtraState();
  22055. this.transformMatrix = IDENTITY_MATRIX; // Graphics state matrix
  22056. this.transformStack = [];
  22057. this.extraStack = [];
  22058. this.commonObjs = commonObjs;
  22059. this.objs = objs;
  22060. this.pendingEOFill = false;
  22061. this.embedFonts = false;
  22062. this.embeddedFonts = Object.create(null);
  22063. this.cssStyle = null;
  22064. }
  22065. var NS = 'http://www.w3.org/2000/svg';
  22066. var XML_NS = 'http://www.w3.org/XML/1998/namespace';
  22067. var XLINK_NS = 'http://www.w3.org/1999/xlink';
  22068. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  22069. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  22070. var clipCount = 0;
  22071. var maskCount = 0;
  22072. SVGGraphics.prototype = {
  22073. save: function SVGGraphics_save() {
  22074. this.transformStack.push(this.transformMatrix);
  22075. var old = this.current;
  22076. this.extraStack.push(old);
  22077. this.current = old.clone();
  22078. },
  22079. restore: function SVGGraphics_restore() {
  22080. this.transformMatrix = this.transformStack.pop();
  22081. this.current = this.extraStack.pop();
  22082. this.tgrp = document.createElementNS(NS, 'svg:g');
  22083. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  22084. this.pgrp.appendChild(this.tgrp);
  22085. },
  22086. group: function SVGGraphics_group(items) {
  22087. this.save();
  22088. this.executeOpTree(items);
  22089. this.restore();
  22090. },
  22091. loadDependencies: function SVGGraphics_loadDependencies(operatorList) {
  22092. var fnArray = operatorList.fnArray;
  22093. var fnArrayLen = fnArray.length;
  22094. var argsArray = operatorList.argsArray;
  22095. var self = this;
  22096. for (var i = 0; i < fnArrayLen; i++) {
  22097. if (OPS.dependency === fnArray[i]) {
  22098. var deps = argsArray[i];
  22099. for (var n = 0, nn = deps.length; n < nn; n++) {
  22100. var obj = deps[n];
  22101. var common = obj.substring(0, 2) === 'g_';
  22102. var promise;
  22103. if (common) {
  22104. promise = new Promise(function(resolve) {
  22105. self.commonObjs.get(obj, resolve);
  22106. });
  22107. } else {
  22108. promise = new Promise(function(resolve) {
  22109. self.objs.get(obj, resolve);
  22110. });
  22111. }
  22112. this.current.dependencies.push(promise);
  22113. }
  22114. }
  22115. }
  22116. return Promise.all(this.current.dependencies);
  22117. },
  22118. transform: function SVGGraphics_transform(a, b, c, d, e, f) {
  22119. var transformMatrix = [a, b, c, d, e, f];
  22120. this.transformMatrix = PDFJS.Util.transform(this.transformMatrix,
  22121. transformMatrix);
  22122. this.tgrp = document.createElementNS(NS, 'svg:g');
  22123. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  22124. },
  22125. getSVG: function SVGGraphics_getSVG(operatorList, viewport) {
  22126. this.svg = createScratchSVG(viewport.width, viewport.height);
  22127. this.viewport = viewport;
  22128. return this.loadDependencies(operatorList).then(function () {
  22129. this.transformMatrix = IDENTITY_MATRIX;
  22130. this.pgrp = document.createElementNS(NS, 'svg:g'); // Parent group
  22131. this.pgrp.setAttributeNS(null, 'transform', pm(viewport.transform));
  22132. this.tgrp = document.createElementNS(NS, 'svg:g'); // Transform group
  22133. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  22134. this.defs = document.createElementNS(NS, 'svg:defs');
  22135. this.pgrp.appendChild(this.defs);
  22136. this.pgrp.appendChild(this.tgrp);
  22137. this.svg.appendChild(this.pgrp);
  22138. var opTree = this.convertOpList(operatorList);
  22139. this.executeOpTree(opTree);
  22140. return this.svg;
  22141. }.bind(this));
  22142. },
  22143. convertOpList: function SVGGraphics_convertOpList(operatorList) {
  22144. var argsArray = operatorList.argsArray;
  22145. var fnArray = operatorList.fnArray;
  22146. var fnArrayLen = fnArray.length;
  22147. var REVOPS = [];
  22148. var opList = [];
  22149. for (var op in OPS) {
  22150. REVOPS[OPS[op]] = op;
  22151. }
  22152. for (var x = 0; x < fnArrayLen; x++) {
  22153. var fnId = fnArray[x];
  22154. opList.push({'fnId' : fnId, 'fn': REVOPS[fnId], 'args': argsArray[x]});
  22155. }
  22156. return opListToTree(opList);
  22157. },
  22158. executeOpTree: function SVGGraphics_executeOpTree(opTree) {
  22159. var opTreeLen = opTree.length;
  22160. for(var x = 0; x < opTreeLen; x++) {
  22161. var fn = opTree[x].fn;
  22162. var fnId = opTree[x].fnId;
  22163. var args = opTree[x].args;
  22164. switch (fnId | 0) {
  22165. case OPS.beginText:
  22166. this.beginText();
  22167. break;
  22168. case OPS.setLeading:
  22169. this.setLeading(args);
  22170. break;
  22171. case OPS.setLeadingMoveText:
  22172. this.setLeadingMoveText(args[0], args[1]);
  22173. break;
  22174. case OPS.setFont:
  22175. this.setFont(args);
  22176. break;
  22177. case OPS.showText:
  22178. this.showText(args[0]);
  22179. break;
  22180. case OPS.showSpacedText:
  22181. this.showText(args[0]);
  22182. break;
  22183. case OPS.endText:
  22184. this.endText();
  22185. break;
  22186. case OPS.moveText:
  22187. this.moveText(args[0], args[1]);
  22188. break;
  22189. case OPS.setCharSpacing:
  22190. this.setCharSpacing(args[0]);
  22191. break;
  22192. case OPS.setWordSpacing:
  22193. this.setWordSpacing(args[0]);
  22194. break;
  22195. case OPS.setHScale:
  22196. this.setHScale(args[0]);
  22197. break;
  22198. case OPS.setTextMatrix:
  22199. this.setTextMatrix(args[0], args[1], args[2],
  22200. args[3], args[4], args[5]);
  22201. break;
  22202. case OPS.setLineWidth:
  22203. this.setLineWidth(args[0]);
  22204. break;
  22205. case OPS.setLineJoin:
  22206. this.setLineJoin(args[0]);
  22207. break;
  22208. case OPS.setLineCap:
  22209. this.setLineCap(args[0]);
  22210. break;
  22211. case OPS.setMiterLimit:
  22212. this.setMiterLimit(args[0]);
  22213. break;
  22214. case OPS.setFillRGBColor:
  22215. this.setFillRGBColor(args[0], args[1], args[2]);
  22216. break;
  22217. case OPS.setStrokeRGBColor:
  22218. this.setStrokeRGBColor(args[0], args[1], args[2]);
  22219. break;
  22220. case OPS.setDash:
  22221. this.setDash(args[0], args[1]);
  22222. break;
  22223. case OPS.setGState:
  22224. this.setGState(args[0]);
  22225. break;
  22226. case OPS.fill:
  22227. this.fill();
  22228. break;
  22229. case OPS.eoFill:
  22230. this.eoFill();
  22231. break;
  22232. case OPS.stroke:
  22233. this.stroke();
  22234. break;
  22235. case OPS.fillStroke:
  22236. this.fillStroke();
  22237. break;
  22238. case OPS.eoFillStroke:
  22239. this.eoFillStroke();
  22240. break;
  22241. case OPS.clip:
  22242. this.clip('nonzero');
  22243. break;
  22244. case OPS.eoClip:
  22245. this.clip('evenodd');
  22246. break;
  22247. case OPS.paintSolidColorImageMask:
  22248. this.paintSolidColorImageMask();
  22249. break;
  22250. case OPS.paintJpegXObject:
  22251. this.paintJpegXObject(args[0], args[1], args[2]);
  22252. break;
  22253. case OPS.paintImageXObject:
  22254. this.paintImageXObject(args[0]);
  22255. break;
  22256. case OPS.paintInlineImageXObject:
  22257. this.paintInlineImageXObject(args[0]);
  22258. break;
  22259. case OPS.paintImageMaskXObject:
  22260. this.paintImageMaskXObject(args[0]);
  22261. break;
  22262. case OPS.paintFormXObjectBegin:
  22263. this.paintFormXObjectBegin(args[0], args[1]);
  22264. break;
  22265. case OPS.paintFormXObjectEnd:
  22266. this.paintFormXObjectEnd();
  22267. break;
  22268. case OPS.closePath:
  22269. this.closePath();
  22270. break;
  22271. case OPS.closeStroke:
  22272. this.closeStroke();
  22273. break;
  22274. case OPS.closeFillStroke:
  22275. this.closeFillStroke();
  22276. break;
  22277. case OPS.nextLine:
  22278. this.nextLine();
  22279. break;
  22280. case OPS.transform:
  22281. this.transform(args[0], args[1], args[2], args[3],
  22282. args[4], args[5]);
  22283. break;
  22284. case OPS.constructPath:
  22285. this.constructPath(args[0], args[1]);
  22286. break;
  22287. case OPS.endPath:
  22288. this.endPath();
  22289. break;
  22290. case 92:
  22291. this.group(opTree[x].items);
  22292. break;
  22293. default:
  22294. warn('Unimplemented method '+ fn);
  22295. break;
  22296. }
  22297. }
  22298. },
  22299. setWordSpacing: function SVGGraphics_setWordSpacing(wordSpacing) {
  22300. this.current.wordSpacing = wordSpacing;
  22301. },
  22302. setCharSpacing: function SVGGraphics_setCharSpacing(charSpacing) {
  22303. this.current.charSpacing = charSpacing;
  22304. },
  22305. nextLine: function SVGGraphics_nextLine() {
  22306. this.moveText(0, this.current.leading);
  22307. },
  22308. setTextMatrix: function SVGGraphics_setTextMatrix(a, b, c, d, e, f) {
  22309. var current = this.current;
  22310. this.current.textMatrix = this.current.lineMatrix = [a, b, c, d, e, f];
  22311. this.current.x = this.current.lineX = 0;
  22312. this.current.y = this.current.lineY = 0;
  22313. current.xcoords = [];
  22314. current.tspan = document.createElementNS(NS, 'svg:tspan');
  22315. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  22316. current.tspan.setAttributeNS(null, 'font-size',
  22317. pf(current.fontSize) + 'px');
  22318. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  22319. current.txtElement = document.createElementNS(NS, 'svg:text');
  22320. current.txtElement.appendChild(current.tspan);
  22321. },
  22322. beginText: function SVGGraphics_beginText() {
  22323. this.current.x = this.current.lineX = 0;
  22324. this.current.y = this.current.lineY = 0;
  22325. this.current.textMatrix = IDENTITY_MATRIX;
  22326. this.current.lineMatrix = IDENTITY_MATRIX;
  22327. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  22328. this.current.txtElement = document.createElementNS(NS, 'svg:text');
  22329. this.current.txtgrp = document.createElementNS(NS, 'svg:g');
  22330. this.current.xcoords = [];
  22331. },
  22332. moveText: function SVGGraphics_moveText(x, y) {
  22333. var current = this.current;
  22334. this.current.x = this.current.lineX += x;
  22335. this.current.y = this.current.lineY += y;
  22336. current.xcoords = [];
  22337. current.tspan = document.createElementNS(NS, 'svg:tspan');
  22338. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  22339. current.tspan.setAttributeNS(null, 'font-size',
  22340. pf(current.fontSize) + 'px');
  22341. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  22342. },
  22343. showText: function SVGGraphics_showText(glyphs) {
  22344. var current = this.current;
  22345. var font = current.font;
  22346. var fontSize = current.fontSize;
  22347. if (fontSize === 0) {
  22348. return;
  22349. }
  22350. var charSpacing = current.charSpacing;
  22351. var wordSpacing = current.wordSpacing;
  22352. var fontDirection = current.fontDirection;
  22353. var textHScale = current.textHScale * fontDirection;
  22354. var glyphsLength = glyphs.length;
  22355. var vertical = font.vertical;
  22356. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  22357. var x = 0, i;
  22358. for (i = 0; i < glyphsLength; ++i) {
  22359. var glyph = glyphs[i];
  22360. if (glyph === null) {
  22361. // word break
  22362. x += fontDirection * wordSpacing;
  22363. continue;
  22364. } else if (isNum(glyph)) {
  22365. x += -glyph * fontSize * 0.001;
  22366. continue;
  22367. }
  22368. current.xcoords.push(current.x + x * textHScale);
  22369. var width = glyph.width;
  22370. var character = glyph.fontChar;
  22371. var charWidth = width * widthAdvanceScale + charSpacing * fontDirection;
  22372. x += charWidth;
  22373. current.tspan.textContent += character;
  22374. }
  22375. if (vertical) {
  22376. current.y -= x * textHScale;
  22377. } else {
  22378. current.x += x * textHScale;
  22379. }
  22380. current.tspan.setAttributeNS(null, 'x',
  22381. current.xcoords.map(pf).join(' '));
  22382. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  22383. current.tspan.setAttributeNS(null, 'font-family', current.fontFamily);
  22384. current.tspan.setAttributeNS(null, 'font-size',
  22385. pf(current.fontSize) + 'px');
  22386. if (current.fontStyle !== SVG_DEFAULTS.fontStyle) {
  22387. current.tspan.setAttributeNS(null, 'font-style', current.fontStyle);
  22388. }
  22389. if (current.fontWeight !== SVG_DEFAULTS.fontWeight) {
  22390. current.tspan.setAttributeNS(null, 'font-weight', current.fontWeight);
  22391. }
  22392. if (current.fillColor !== SVG_DEFAULTS.fillColor) {
  22393. current.tspan.setAttributeNS(null, 'fill', current.fillColor);
  22394. }
  22395. current.txtElement.setAttributeNS(null, 'transform',
  22396. pm(current.textMatrix) +
  22397. ' scale(1, -1)' );
  22398. current.txtElement.setAttributeNS(XML_NS, 'xml:space', 'preserve');
  22399. current.txtElement.appendChild(current.tspan);
  22400. current.txtgrp.appendChild(current.txtElement);
  22401. this.tgrp.appendChild(current.txtElement);
  22402. },
  22403. setLeadingMoveText: function SVGGraphics_setLeadingMoveText(x, y) {
  22404. this.setLeading(-y);
  22405. this.moveText(x, y);
  22406. },
  22407. addFontStyle: function SVGGraphics_addFontStyle(fontObj) {
  22408. if (!this.cssStyle) {
  22409. this.cssStyle = document.createElementNS(NS, 'svg:style');
  22410. this.cssStyle.setAttributeNS(null, 'type', 'text/css');
  22411. this.defs.appendChild(this.cssStyle);
  22412. }
  22413. var url = PDFJS.createObjectURL(fontObj.data, fontObj.mimetype);
  22414. this.cssStyle.textContent +=
  22415. '@font-face { font-family: "' + fontObj.loadedName + '";' +
  22416. ' src: url(' + url + '); }\n';
  22417. },
  22418. setFont: function SVGGraphics_setFont(details) {
  22419. var current = this.current;
  22420. var fontObj = this.commonObjs.get(details[0]);
  22421. var size = details[1];
  22422. this.current.font = fontObj;
  22423. if (this.embedFonts && fontObj.data &&
  22424. !this.embeddedFonts[fontObj.loadedName]) {
  22425. this.addFontStyle(fontObj);
  22426. this.embeddedFonts[fontObj.loadedName] = fontObj;
  22427. }
  22428. current.fontMatrix = (fontObj.fontMatrix ?
  22429. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  22430. var bold = fontObj.black ? (fontObj.bold ? 'bolder' : 'bold') :
  22431. (fontObj.bold ? 'bold' : 'normal');
  22432. var italic = fontObj.italic ? 'italic' : 'normal';
  22433. if (size < 0) {
  22434. size = -size;
  22435. current.fontDirection = -1;
  22436. } else {
  22437. current.fontDirection = 1;
  22438. }
  22439. current.fontSize = size;
  22440. current.fontFamily = fontObj.loadedName;
  22441. current.fontWeight = bold;
  22442. current.fontStyle = italic;
  22443. current.tspan = document.createElementNS(NS, 'svg:tspan');
  22444. current.tspan.setAttributeNS(null, 'y', pf(-current.y));
  22445. current.xcoords = [];
  22446. },
  22447. endText: function SVGGraphics_endText() {
  22448. if (this.current.pendingClip) {
  22449. this.cgrp.appendChild(this.tgrp);
  22450. this.pgrp.appendChild(this.cgrp);
  22451. } else {
  22452. this.pgrp.appendChild(this.tgrp);
  22453. }
  22454. this.tgrp = document.createElementNS(NS, 'svg:g');
  22455. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  22456. },
  22457. // Path properties
  22458. setLineWidth: function SVGGraphics_setLineWidth(width) {
  22459. this.current.lineWidth = width;
  22460. },
  22461. setLineCap: function SVGGraphics_setLineCap(style) {
  22462. this.current.lineCap = LINE_CAP_STYLES[style];
  22463. },
  22464. setLineJoin: function SVGGraphics_setLineJoin(style) {
  22465. this.current.lineJoin = LINE_JOIN_STYLES[style];
  22466. },
  22467. setMiterLimit: function SVGGraphics_setMiterLimit(limit) {
  22468. this.current.miterLimit = limit;
  22469. },
  22470. setStrokeRGBColor: function SVGGraphics_setStrokeRGBColor(r, g, b) {
  22471. var color = Util.makeCssRgb(r, g, b);
  22472. this.current.strokeColor = color;
  22473. },
  22474. setFillRGBColor: function SVGGraphics_setFillRGBColor(r, g, b) {
  22475. var color = Util.makeCssRgb(r, g, b);
  22476. this.current.fillColor = color;
  22477. this.current.tspan = document.createElementNS(NS, 'svg:tspan');
  22478. this.current.xcoords = [];
  22479. },
  22480. setDash: function SVGGraphics_setDash(dashArray, dashPhase) {
  22481. this.current.dashArray = dashArray;
  22482. this.current.dashPhase = dashPhase;
  22483. },
  22484. constructPath: function SVGGraphics_constructPath(ops, args) {
  22485. var current = this.current;
  22486. var x = current.x, y = current.y;
  22487. current.path = document.createElementNS(NS, 'svg:path');
  22488. var d = [];
  22489. var opLength = ops.length;
  22490. for (var i = 0, j = 0; i < opLength; i++) {
  22491. switch (ops[i] | 0) {
  22492. case OPS.rectangle:
  22493. x = args[j++];
  22494. y = args[j++];
  22495. var width = args[j++];
  22496. var height = args[j++];
  22497. var xw = x + width;
  22498. var yh = y + height;
  22499. d.push('M', pf(x), pf(y), 'L', pf(xw) , pf(y), 'L', pf(xw), pf(yh),
  22500. 'L', pf(x), pf(yh), 'Z');
  22501. break;
  22502. case OPS.moveTo:
  22503. x = args[j++];
  22504. y = args[j++];
  22505. d.push('M', pf(x), pf(y));
  22506. break;
  22507. case OPS.lineTo:
  22508. x = args[j++];
  22509. y = args[j++];
  22510. d.push('L', pf(x) , pf(y));
  22511. break;
  22512. case OPS.curveTo:
  22513. x = args[j + 4];
  22514. y = args[j + 5];
  22515. d.push('C', pf(args[j]), pf(args[j + 1]), pf(args[j + 2]),
  22516. pf(args[j + 3]), pf(x), pf(y));
  22517. j += 6;
  22518. break;
  22519. case OPS.curveTo2:
  22520. x = args[j + 2];
  22521. y = args[j + 3];
  22522. d.push('C', pf(x), pf(y), pf(args[j]), pf(args[j + 1]),
  22523. pf(args[j + 2]), pf(args[j + 3]));
  22524. j += 4;
  22525. break;
  22526. case OPS.curveTo3:
  22527. x = args[j + 2];
  22528. y = args[j + 3];
  22529. d.push('C', pf(args[j]), pf(args[j + 1]), pf(x), pf(y),
  22530. pf(x), pf(y));
  22531. j += 4;
  22532. break;
  22533. case OPS.closePath:
  22534. d.push('Z');
  22535. break;
  22536. }
  22537. }
  22538. current.path.setAttributeNS(null, 'd', d.join(' '));
  22539. current.path.setAttributeNS(null, 'stroke-miterlimit',
  22540. pf(current.miterLimit));
  22541. current.path.setAttributeNS(null, 'stroke-linecap', current.lineCap);
  22542. current.path.setAttributeNS(null, 'stroke-linejoin', current.lineJoin);
  22543. current.path.setAttributeNS(null, 'stroke-width',
  22544. pf(current.lineWidth) + 'px');
  22545. current.path.setAttributeNS(null, 'stroke-dasharray',
  22546. current.dashArray.map(pf).join(' '));
  22547. current.path.setAttributeNS(null, 'stroke-dashoffset',
  22548. pf(current.dashPhase) + 'px');
  22549. current.path.setAttributeNS(null, 'fill', 'none');
  22550. this.tgrp.appendChild(current.path);
  22551. if (current.pendingClip) {
  22552. this.cgrp.appendChild(this.tgrp);
  22553. this.pgrp.appendChild(this.cgrp);
  22554. } else {
  22555. this.pgrp.appendChild(this.tgrp);
  22556. }
  22557. // Saving a reference in current.element so that it can be addressed
  22558. // in 'fill' and 'stroke'
  22559. current.element = current.path;
  22560. current.setCurrentPoint(x, y);
  22561. },
  22562. endPath: function SVGGraphics_endPath() {
  22563. var current = this.current;
  22564. if (current.pendingClip) {
  22565. this.cgrp.appendChild(this.tgrp);
  22566. this.pgrp.appendChild(this.cgrp);
  22567. } else {
  22568. this.pgrp.appendChild(this.tgrp);
  22569. }
  22570. this.tgrp = document.createElementNS(NS, 'svg:g');
  22571. this.tgrp.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  22572. },
  22573. clip: function SVGGraphics_clip(type) {
  22574. var current = this.current;
  22575. // Add current path to clipping path
  22576. current.clipId = 'clippath' + clipCount;
  22577. clipCount++;
  22578. this.clippath = document.createElementNS(NS, 'svg:clipPath');
  22579. this.clippath.setAttributeNS(null, 'id', current.clipId);
  22580. var clipElement = current.element.cloneNode();
  22581. if (type === 'evenodd') {
  22582. clipElement.setAttributeNS(null, 'clip-rule', 'evenodd');
  22583. } else {
  22584. clipElement.setAttributeNS(null, 'clip-rule', 'nonzero');
  22585. }
  22586. this.clippath.setAttributeNS(null, 'transform', pm(this.transformMatrix));
  22587. this.clippath.appendChild(clipElement);
  22588. this.defs.appendChild(this.clippath);
  22589. // Create a new group with that attribute
  22590. current.pendingClip = true;
  22591. this.cgrp = document.createElementNS(NS, 'svg:g');
  22592. this.cgrp.setAttributeNS(null, 'clip-path',
  22593. 'url(#' + current.clipId + ')');
  22594. this.pgrp.appendChild(this.cgrp);
  22595. },
  22596. closePath: function SVGGraphics_closePath() {
  22597. var current = this.current;
  22598. var d = current.path.getAttributeNS(null, 'd');
  22599. d += 'Z';
  22600. current.path.setAttributeNS(null, 'd', d);
  22601. },
  22602. setLeading: function SVGGraphics_setLeading(leading) {
  22603. this.current.leading = -leading;
  22604. },
  22605. setTextRise: function SVGGraphics_setTextRise(textRise) {
  22606. this.current.textRise = textRise;
  22607. },
  22608. setHScale: function SVGGraphics_setHScale(scale) {
  22609. this.current.textHScale = scale / 100;
  22610. },
  22611. setGState: function SVGGraphics_setGState(states) {
  22612. for (var i = 0, ii = states.length; i < ii; i++) {
  22613. var state = states[i];
  22614. var key = state[0];
  22615. var value = state[1];
  22616. switch (key) {
  22617. case 'LW':
  22618. this.setLineWidth(value);
  22619. break;
  22620. case 'LC':
  22621. this.setLineCap(value);
  22622. break;
  22623. case 'LJ':
  22624. this.setLineJoin(value);
  22625. break;
  22626. case 'ML':
  22627. this.setMiterLimit(value);
  22628. break;
  22629. case 'D':
  22630. this.setDash(value[0], value[1]);
  22631. break;
  22632. case 'RI':
  22633. break;
  22634. case 'FL':
  22635. break;
  22636. case 'Font':
  22637. this.setFont(value);
  22638. break;
  22639. case 'CA':
  22640. break;
  22641. case 'ca':
  22642. break;
  22643. case 'BM':
  22644. break;
  22645. case 'SMask':
  22646. break;
  22647. }
  22648. }
  22649. },
  22650. fill: function SVGGraphics_fill() {
  22651. var current = this.current;
  22652. current.element.setAttributeNS(null, 'fill', current.fillColor);
  22653. },
  22654. stroke: function SVGGraphics_stroke() {
  22655. var current = this.current;
  22656. current.element.setAttributeNS(null, 'stroke', current.strokeColor);
  22657. current.element.setAttributeNS(null, 'fill', 'none');
  22658. },
  22659. eoFill: function SVGGraphics_eoFill() {
  22660. var current = this.current;
  22661. current.element.setAttributeNS(null, 'fill', current.fillColor);
  22662. current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  22663. },
  22664. fillStroke: function SVGGraphics_fillStroke() {
  22665. // Order is important since stroke wants fill to be none.
  22666. // First stroke, then if fill needed, it will be overwritten.
  22667. this.stroke();
  22668. this.fill();
  22669. },
  22670. eoFillStroke: function SVGGraphics_eoFillStroke() {
  22671. this.current.element.setAttributeNS(null, 'fill-rule', 'evenodd');
  22672. this.fillStroke();
  22673. },
  22674. closeStroke: function SVGGraphics_closeStroke() {
  22675. this.closePath();
  22676. this.stroke();
  22677. },
  22678. closeFillStroke: function SVGGraphics_closeFillStroke() {
  22679. this.closePath();
  22680. this.fillStroke();
  22681. },
  22682. paintSolidColorImageMask:
  22683. function SVGGraphics_paintSolidColorImageMask() {
  22684. var current = this.current;
  22685. var rect = document.createElementNS(NS, 'svg:rect');
  22686. rect.setAttributeNS(null, 'x', '0');
  22687. rect.setAttributeNS(null, 'y', '0');
  22688. rect.setAttributeNS(null, 'width', '1px');
  22689. rect.setAttributeNS(null, 'height', '1px');
  22690. rect.setAttributeNS(null, 'fill', current.fillColor);
  22691. this.tgrp.appendChild(rect);
  22692. },
  22693. paintJpegXObject: function SVGGraphics_paintJpegXObject(objId, w, h) {
  22694. var current = this.current;
  22695. var imgObj = this.objs.get(objId);
  22696. var imgEl = document.createElementNS(NS, 'svg:image');
  22697. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgObj.src);
  22698. imgEl.setAttributeNS(null, 'width', imgObj.width + 'px');
  22699. imgEl.setAttributeNS(null, 'height', imgObj.height + 'px');
  22700. imgEl.setAttributeNS(null, 'x', '0');
  22701. imgEl.setAttributeNS(null, 'y', pf(-h));
  22702. imgEl.setAttributeNS(null, 'transform',
  22703. 'scale(' + pf(1 / w) + ' ' + pf(-1 / h) + ')');
  22704. this.tgrp.appendChild(imgEl);
  22705. if (current.pendingClip) {
  22706. this.cgrp.appendChild(this.tgrp);
  22707. this.pgrp.appendChild(this.cgrp);
  22708. } else {
  22709. this.pgrp.appendChild(this.tgrp);
  22710. }
  22711. },
  22712. paintImageXObject: function SVGGraphics_paintImageXObject(objId) {
  22713. var imgData = this.objs.get(objId);
  22714. if (!imgData) {
  22715. warn('Dependent image isn\'t ready yet');
  22716. return;
  22717. }
  22718. this.paintInlineImageXObject(imgData);
  22719. },
  22720. paintInlineImageXObject:
  22721. function SVGGraphics_paintInlineImageXObject(imgData, mask) {
  22722. var current = this.current;
  22723. var width = imgData.width;
  22724. var height = imgData.height;
  22725. var imgSrc = convertImgDataToPng(imgData);
  22726. var cliprect = document.createElementNS(NS, 'svg:rect');
  22727. cliprect.setAttributeNS(null, 'x', '0');
  22728. cliprect.setAttributeNS(null, 'y', '0');
  22729. cliprect.setAttributeNS(null, 'width', pf(width));
  22730. cliprect.setAttributeNS(null, 'height', pf(height));
  22731. current.element = cliprect;
  22732. this.clip('nonzero');
  22733. var imgEl = document.createElementNS(NS, 'svg:image');
  22734. imgEl.setAttributeNS(XLINK_NS, 'xlink:href', imgSrc);
  22735. imgEl.setAttributeNS(null, 'x', '0');
  22736. imgEl.setAttributeNS(null, 'y', pf(-height));
  22737. imgEl.setAttributeNS(null, 'width', pf(width) + 'px');
  22738. imgEl.setAttributeNS(null, 'height', pf(height) + 'px');
  22739. imgEl.setAttributeNS(null, 'transform',
  22740. 'scale(' + pf(1 / width) + ' ' +
  22741. pf(-1 / height) + ')');
  22742. if (mask) {
  22743. mask.appendChild(imgEl);
  22744. } else {
  22745. this.tgrp.appendChild(imgEl);
  22746. }
  22747. if (current.pendingClip) {
  22748. this.cgrp.appendChild(this.tgrp);
  22749. this.pgrp.appendChild(this.cgrp);
  22750. } else {
  22751. this.pgrp.appendChild(this.tgrp);
  22752. }
  22753. },
  22754. paintImageMaskXObject:
  22755. function SVGGraphics_paintImageMaskXObject(imgData) {
  22756. var current = this.current;
  22757. var width = imgData.width;
  22758. var height = imgData.height;
  22759. var fillColor = current.fillColor;
  22760. current.maskId = 'mask' + maskCount++;
  22761. var mask = document.createElementNS(NS, 'svg:mask');
  22762. mask.setAttributeNS(null, 'id', current.maskId);
  22763. var rect = document.createElementNS(NS, 'svg:rect');
  22764. rect.setAttributeNS(null, 'x', '0');
  22765. rect.setAttributeNS(null, 'y', '0');
  22766. rect.setAttributeNS(null, 'width', pf(width));
  22767. rect.setAttributeNS(null, 'height', pf(height));
  22768. rect.setAttributeNS(null, 'fill', fillColor);
  22769. rect.setAttributeNS(null, 'mask', 'url(#' + current.maskId +')');
  22770. this.defs.appendChild(mask);
  22771. this.tgrp.appendChild(rect);
  22772. this.paintInlineImageXObject(imgData, mask);
  22773. },
  22774. paintFormXObjectBegin:
  22775. function SVGGraphics_paintFormXObjectBegin(matrix, bbox) {
  22776. this.save();
  22777. if (isArray(matrix) && matrix.length === 6) {
  22778. this.transform(matrix[0], matrix[1], matrix[2],
  22779. matrix[3], matrix[4], matrix[5]);
  22780. }
  22781. if (isArray(bbox) && bbox.length === 4) {
  22782. var width = bbox[2] - bbox[0];
  22783. var height = bbox[3] - bbox[1];
  22784. var cliprect = document.createElementNS(NS, 'svg:rect');
  22785. cliprect.setAttributeNS(null, 'x', bbox[0]);
  22786. cliprect.setAttributeNS(null, 'y', bbox[1]);
  22787. cliprect.setAttributeNS(null, 'width', pf(width));
  22788. cliprect.setAttributeNS(null, 'height', pf(height));
  22789. this.current.element = cliprect;
  22790. this.clip('nonzero');
  22791. this.endPath();
  22792. }
  22793. },
  22794. paintFormXObjectEnd:
  22795. function SVGGraphics_paintFormXObjectEnd() {
  22796. this.restore();
  22797. }
  22798. };
  22799. return SVGGraphics;
  22800. })();
  22801. PDFJS.SVGGraphics = SVGGraphics;
  22802. exports.SVGGraphics = SVGGraphics;
  22803. }));
  22804. (function (root, factory) {
  22805. {
  22806. factory((root.pdfjsDisplayWebGL = {}), root.pdfjsSharedUtil,
  22807. root.pdfjsDisplayGlobal);
  22808. }
  22809. }(this, function (exports, sharedUtil, displayGlobal) {
  22810. var shadow = sharedUtil.shadow;
  22811. var PDFJS = displayGlobal.PDFJS;
  22812. var WebGLUtils = (function WebGLUtilsClosure() {
  22813. function loadShader(gl, code, shaderType) {
  22814. var shader = gl.createShader(shaderType);
  22815. gl.shaderSource(shader, code);
  22816. gl.compileShader(shader);
  22817. var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  22818. if (!compiled) {
  22819. var errorMsg = gl.getShaderInfoLog(shader);
  22820. throw new Error('Error during shader compilation: ' + errorMsg);
  22821. }
  22822. return shader;
  22823. }
  22824. function createVertexShader(gl, code) {
  22825. return loadShader(gl, code, gl.VERTEX_SHADER);
  22826. }
  22827. function createFragmentShader(gl, code) {
  22828. return loadShader(gl, code, gl.FRAGMENT_SHADER);
  22829. }
  22830. function createProgram(gl, shaders) {
  22831. var program = gl.createProgram();
  22832. for (var i = 0, ii = shaders.length; i < ii; ++i) {
  22833. gl.attachShader(program, shaders[i]);
  22834. }
  22835. gl.linkProgram(program);
  22836. var linked = gl.getProgramParameter(program, gl.LINK_STATUS);
  22837. if (!linked) {
  22838. var errorMsg = gl.getProgramInfoLog(program);
  22839. throw new Error('Error during program linking: ' + errorMsg);
  22840. }
  22841. return program;
  22842. }
  22843. function createTexture(gl, image, textureId) {
  22844. gl.activeTexture(textureId);
  22845. var texture = gl.createTexture();
  22846. gl.bindTexture(gl.TEXTURE_2D, texture);
  22847. // Set the parameters so we can render any size image.
  22848. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  22849. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  22850. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
  22851. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
  22852. // Upload the image into the texture.
  22853. gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image);
  22854. return texture;
  22855. }
  22856. var currentGL, currentCanvas;
  22857. function generateGL() {
  22858. if (currentGL) {
  22859. return;
  22860. }
  22861. currentCanvas = document.createElement('canvas');
  22862. currentGL = currentCanvas.getContext('webgl',
  22863. { premultipliedalpha: false });
  22864. }
  22865. var smaskVertexShaderCode = '\
  22866. attribute vec2 a_position; \
  22867. attribute vec2 a_texCoord; \
  22868. \
  22869. uniform vec2 u_resolution; \
  22870. \
  22871. varying vec2 v_texCoord; \
  22872. \
  22873. void main() { \
  22874. vec2 clipSpace = (a_position / u_resolution) * 2.0 - 1.0; \
  22875. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  22876. \
  22877. v_texCoord = a_texCoord; \
  22878. } ';
  22879. var smaskFragmentShaderCode = '\
  22880. precision mediump float; \
  22881. \
  22882. uniform vec4 u_backdrop; \
  22883. uniform int u_subtype; \
  22884. uniform sampler2D u_image; \
  22885. uniform sampler2D u_mask; \
  22886. \
  22887. varying vec2 v_texCoord; \
  22888. \
  22889. void main() { \
  22890. vec4 imageColor = texture2D(u_image, v_texCoord); \
  22891. vec4 maskColor = texture2D(u_mask, v_texCoord); \
  22892. if (u_backdrop.a > 0.0) { \
  22893. maskColor.rgb = maskColor.rgb * maskColor.a + \
  22894. u_backdrop.rgb * (1.0 - maskColor.a); \
  22895. } \
  22896. float lum; \
  22897. if (u_subtype == 0) { \
  22898. lum = maskColor.a; \
  22899. } else { \
  22900. lum = maskColor.r * 0.3 + maskColor.g * 0.59 + \
  22901. maskColor.b * 0.11; \
  22902. } \
  22903. imageColor.a *= lum; \
  22904. imageColor.rgb *= imageColor.a; \
  22905. gl_FragColor = imageColor; \
  22906. } ';
  22907. var smaskCache = null;
  22908. function initSmaskGL() {
  22909. var canvas, gl;
  22910. generateGL();
  22911. canvas = currentCanvas;
  22912. currentCanvas = null;
  22913. gl = currentGL;
  22914. currentGL = null;
  22915. // setup a GLSL program
  22916. var vertexShader = createVertexShader(gl, smaskVertexShaderCode);
  22917. var fragmentShader = createFragmentShader(gl, smaskFragmentShaderCode);
  22918. var program = createProgram(gl, [vertexShader, fragmentShader]);
  22919. gl.useProgram(program);
  22920. var cache = {};
  22921. cache.gl = gl;
  22922. cache.canvas = canvas;
  22923. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  22924. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  22925. cache.backdropLocation = gl.getUniformLocation(program, 'u_backdrop');
  22926. cache.subtypeLocation = gl.getUniformLocation(program, 'u_subtype');
  22927. var texCoordLocation = gl.getAttribLocation(program, 'a_texCoord');
  22928. var texLayerLocation = gl.getUniformLocation(program, 'u_image');
  22929. var texMaskLocation = gl.getUniformLocation(program, 'u_mask');
  22930. // provide texture coordinates for the rectangle.
  22931. var texCoordBuffer = gl.createBuffer();
  22932. gl.bindBuffer(gl.ARRAY_BUFFER, texCoordBuffer);
  22933. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  22934. 0.0, 0.0,
  22935. 1.0, 0.0,
  22936. 0.0, 1.0,
  22937. 0.0, 1.0,
  22938. 1.0, 0.0,
  22939. 1.0, 1.0]), gl.STATIC_DRAW);
  22940. gl.enableVertexAttribArray(texCoordLocation);
  22941. gl.vertexAttribPointer(texCoordLocation, 2, gl.FLOAT, false, 0, 0);
  22942. gl.uniform1i(texLayerLocation, 0);
  22943. gl.uniform1i(texMaskLocation, 1);
  22944. smaskCache = cache;
  22945. }
  22946. function composeSMask(layer, mask, properties) {
  22947. var width = layer.width, height = layer.height;
  22948. if (!smaskCache) {
  22949. initSmaskGL();
  22950. }
  22951. var cache = smaskCache,canvas = cache.canvas, gl = cache.gl;
  22952. canvas.width = width;
  22953. canvas.height = height;
  22954. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  22955. gl.uniform2f(cache.resolutionLocation, width, height);
  22956. if (properties.backdrop) {
  22957. gl.uniform4f(cache.resolutionLocation, properties.backdrop[0],
  22958. properties.backdrop[1], properties.backdrop[2], 1);
  22959. } else {
  22960. gl.uniform4f(cache.resolutionLocation, 0, 0, 0, 0);
  22961. }
  22962. gl.uniform1i(cache.subtypeLocation,
  22963. properties.subtype === 'Luminosity' ? 1 : 0);
  22964. // Create a textures
  22965. var texture = createTexture(gl, layer, gl.TEXTURE0);
  22966. var maskTexture = createTexture(gl, mask, gl.TEXTURE1);
  22967. // Create a buffer and put a single clipspace rectangle in
  22968. // it (2 triangles)
  22969. var buffer = gl.createBuffer();
  22970. gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
  22971. gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
  22972. 0, 0,
  22973. width, 0,
  22974. 0, height,
  22975. 0, height,
  22976. width, 0,
  22977. width, height]), gl.STATIC_DRAW);
  22978. gl.enableVertexAttribArray(cache.positionLocation);
  22979. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  22980. // draw
  22981. gl.clearColor(0, 0, 0, 0);
  22982. gl.enable(gl.BLEND);
  22983. gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);
  22984. gl.clear(gl.COLOR_BUFFER_BIT);
  22985. gl.drawArrays(gl.TRIANGLES, 0, 6);
  22986. gl.flush();
  22987. gl.deleteTexture(texture);
  22988. gl.deleteTexture(maskTexture);
  22989. gl.deleteBuffer(buffer);
  22990. return canvas;
  22991. }
  22992. var figuresVertexShaderCode = '\
  22993. attribute vec2 a_position; \
  22994. attribute vec3 a_color; \
  22995. \
  22996. uniform vec2 u_resolution; \
  22997. uniform vec2 u_scale; \
  22998. uniform vec2 u_offset; \
  22999. \
  23000. varying vec4 v_color; \
  23001. \
  23002. void main() { \
  23003. vec2 position = (a_position + u_offset) * u_scale; \
  23004. vec2 clipSpace = (position / u_resolution) * 2.0 - 1.0; \
  23005. gl_Position = vec4(clipSpace * vec2(1, -1), 0, 1); \
  23006. \
  23007. v_color = vec4(a_color / 255.0, 1.0); \
  23008. } ';
  23009. var figuresFragmentShaderCode = '\
  23010. precision mediump float; \
  23011. \
  23012. varying vec4 v_color; \
  23013. \
  23014. void main() { \
  23015. gl_FragColor = v_color; \
  23016. } ';
  23017. var figuresCache = null;
  23018. function initFiguresGL() {
  23019. var canvas, gl;
  23020. generateGL();
  23021. canvas = currentCanvas;
  23022. currentCanvas = null;
  23023. gl = currentGL;
  23024. currentGL = null;
  23025. // setup a GLSL program
  23026. var vertexShader = createVertexShader(gl, figuresVertexShaderCode);
  23027. var fragmentShader = createFragmentShader(gl, figuresFragmentShaderCode);
  23028. var program = createProgram(gl, [vertexShader, fragmentShader]);
  23029. gl.useProgram(program);
  23030. var cache = {};
  23031. cache.gl = gl;
  23032. cache.canvas = canvas;
  23033. cache.resolutionLocation = gl.getUniformLocation(program, 'u_resolution');
  23034. cache.scaleLocation = gl.getUniformLocation(program, 'u_scale');
  23035. cache.offsetLocation = gl.getUniformLocation(program, 'u_offset');
  23036. cache.positionLocation = gl.getAttribLocation(program, 'a_position');
  23037. cache.colorLocation = gl.getAttribLocation(program, 'a_color');
  23038. figuresCache = cache;
  23039. }
  23040. function drawFigures(width, height, backgroundColor, figures, context) {
  23041. if (!figuresCache) {
  23042. initFiguresGL();
  23043. }
  23044. var cache = figuresCache, canvas = cache.canvas, gl = cache.gl;
  23045. canvas.width = width;
  23046. canvas.height = height;
  23047. gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
  23048. gl.uniform2f(cache.resolutionLocation, width, height);
  23049. // count triangle points
  23050. var count = 0;
  23051. var i, ii, rows;
  23052. for (i = 0, ii = figures.length; i < ii; i++) {
  23053. switch (figures[i].type) {
  23054. case 'lattice':
  23055. rows = (figures[i].coords.length / figures[i].verticesPerRow) | 0;
  23056. count += (rows - 1) * (figures[i].verticesPerRow - 1) * 6;
  23057. break;
  23058. case 'triangles':
  23059. count += figures[i].coords.length;
  23060. break;
  23061. }
  23062. }
  23063. // transfer data
  23064. var coords = new Float32Array(count * 2);
  23065. var colors = new Uint8Array(count * 3);
  23066. var coordsMap = context.coords, colorsMap = context.colors;
  23067. var pIndex = 0, cIndex = 0;
  23068. for (i = 0, ii = figures.length; i < ii; i++) {
  23069. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  23070. switch (figure.type) {
  23071. case 'lattice':
  23072. var cols = figure.verticesPerRow;
  23073. rows = (ps.length / cols) | 0;
  23074. for (var row = 1; row < rows; row++) {
  23075. var offset = row * cols + 1;
  23076. for (var col = 1; col < cols; col++, offset++) {
  23077. coords[pIndex] = coordsMap[ps[offset - cols - 1]];
  23078. coords[pIndex + 1] = coordsMap[ps[offset - cols - 1] + 1];
  23079. coords[pIndex + 2] = coordsMap[ps[offset - cols]];
  23080. coords[pIndex + 3] = coordsMap[ps[offset - cols] + 1];
  23081. coords[pIndex + 4] = coordsMap[ps[offset - 1]];
  23082. coords[pIndex + 5] = coordsMap[ps[offset - 1] + 1];
  23083. colors[cIndex] = colorsMap[cs[offset - cols - 1]];
  23084. colors[cIndex + 1] = colorsMap[cs[offset - cols - 1] + 1];
  23085. colors[cIndex + 2] = colorsMap[cs[offset - cols - 1] + 2];
  23086. colors[cIndex + 3] = colorsMap[cs[offset - cols]];
  23087. colors[cIndex + 4] = colorsMap[cs[offset - cols] + 1];
  23088. colors[cIndex + 5] = colorsMap[cs[offset - cols] + 2];
  23089. colors[cIndex + 6] = colorsMap[cs[offset - 1]];
  23090. colors[cIndex + 7] = colorsMap[cs[offset - 1] + 1];
  23091. colors[cIndex + 8] = colorsMap[cs[offset - 1] + 2];
  23092. coords[pIndex + 6] = coords[pIndex + 2];
  23093. coords[pIndex + 7] = coords[pIndex + 3];
  23094. coords[pIndex + 8] = coords[pIndex + 4];
  23095. coords[pIndex + 9] = coords[pIndex + 5];
  23096. coords[pIndex + 10] = coordsMap[ps[offset]];
  23097. coords[pIndex + 11] = coordsMap[ps[offset] + 1];
  23098. colors[cIndex + 9] = colors[cIndex + 3];
  23099. colors[cIndex + 10] = colors[cIndex + 4];
  23100. colors[cIndex + 11] = colors[cIndex + 5];
  23101. colors[cIndex + 12] = colors[cIndex + 6];
  23102. colors[cIndex + 13] = colors[cIndex + 7];
  23103. colors[cIndex + 14] = colors[cIndex + 8];
  23104. colors[cIndex + 15] = colorsMap[cs[offset]];
  23105. colors[cIndex + 16] = colorsMap[cs[offset] + 1];
  23106. colors[cIndex + 17] = colorsMap[cs[offset] + 2];
  23107. pIndex += 12;
  23108. cIndex += 18;
  23109. }
  23110. }
  23111. break;
  23112. case 'triangles':
  23113. for (var j = 0, jj = ps.length; j < jj; j++) {
  23114. coords[pIndex] = coordsMap[ps[j]];
  23115. coords[pIndex + 1] = coordsMap[ps[j] + 1];
  23116. colors[cIndex] = colorsMap[cs[j]];
  23117. colors[cIndex + 1] = colorsMap[cs[j] + 1];
  23118. colors[cIndex + 2] = colorsMap[cs[j] + 2];
  23119. pIndex += 2;
  23120. cIndex += 3;
  23121. }
  23122. break;
  23123. }
  23124. }
  23125. // draw
  23126. if (backgroundColor) {
  23127. gl.clearColor(backgroundColor[0] / 255, backgroundColor[1] / 255,
  23128. backgroundColor[2] / 255, 1.0);
  23129. } else {
  23130. gl.clearColor(0, 0, 0, 0);
  23131. }
  23132. gl.clear(gl.COLOR_BUFFER_BIT);
  23133. var coordsBuffer = gl.createBuffer();
  23134. gl.bindBuffer(gl.ARRAY_BUFFER, coordsBuffer);
  23135. gl.bufferData(gl.ARRAY_BUFFER, coords, gl.STATIC_DRAW);
  23136. gl.enableVertexAttribArray(cache.positionLocation);
  23137. gl.vertexAttribPointer(cache.positionLocation, 2, gl.FLOAT, false, 0, 0);
  23138. var colorsBuffer = gl.createBuffer();
  23139. gl.bindBuffer(gl.ARRAY_BUFFER, colorsBuffer);
  23140. gl.bufferData(gl.ARRAY_BUFFER, colors, gl.STATIC_DRAW);
  23141. gl.enableVertexAttribArray(cache.colorLocation);
  23142. gl.vertexAttribPointer(cache.colorLocation, 3, gl.UNSIGNED_BYTE, false,
  23143. 0, 0);
  23144. gl.uniform2f(cache.scaleLocation, context.scaleX, context.scaleY);
  23145. gl.uniform2f(cache.offsetLocation, context.offsetX, context.offsetY);
  23146. gl.drawArrays(gl.TRIANGLES, 0, count);
  23147. gl.flush();
  23148. gl.deleteBuffer(coordsBuffer);
  23149. gl.deleteBuffer(colorsBuffer);
  23150. return canvas;
  23151. }
  23152. function cleanup() {
  23153. if (smaskCache && smaskCache.canvas) {
  23154. smaskCache.canvas.width = 0;
  23155. smaskCache.canvas.height = 0;
  23156. }
  23157. if (figuresCache && figuresCache.canvas) {
  23158. figuresCache.canvas.width = 0;
  23159. figuresCache.canvas.height = 0;
  23160. }
  23161. smaskCache = null;
  23162. figuresCache = null;
  23163. }
  23164. return {
  23165. get isEnabled() {
  23166. if (PDFJS.disableWebGL) {
  23167. return false;
  23168. }
  23169. var enabled = false;
  23170. try {
  23171. generateGL();
  23172. enabled = !!currentGL;
  23173. } catch (e) { }
  23174. return shadow(this, 'isEnabled', enabled);
  23175. },
  23176. composeSMask: composeSMask,
  23177. drawFigures: drawFigures,
  23178. clear: cleanup
  23179. };
  23180. })();
  23181. exports.WebGLUtils = WebGLUtils;
  23182. }));
  23183. (function (root, factory) {
  23184. {
  23185. factory((root.pdfjsCoreCrypto = {}), root.pdfjsSharedUtil,
  23186. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  23187. }
  23188. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  23189. var PasswordException = sharedUtil.PasswordException;
  23190. var PasswordResponses = sharedUtil.PasswordResponses;
  23191. var bytesToString = sharedUtil.bytesToString;
  23192. var error = sharedUtil.error;
  23193. var isInt = sharedUtil.isInt;
  23194. var stringToBytes = sharedUtil.stringToBytes;
  23195. var utf8StringToString = sharedUtil.utf8StringToString;
  23196. var warn = sharedUtil.warn;
  23197. var Name = corePrimitives.Name;
  23198. var isName = corePrimitives.isName;
  23199. var isDict = corePrimitives.isDict;
  23200. var DecryptStream = coreStream.DecryptStream;
  23201. var ARCFourCipher = (function ARCFourCipherClosure() {
  23202. function ARCFourCipher(key) {
  23203. this.a = 0;
  23204. this.b = 0;
  23205. var s = new Uint8Array(256);
  23206. var i, j = 0, tmp, keyLength = key.length;
  23207. for (i = 0; i < 256; ++i) {
  23208. s[i] = i;
  23209. }
  23210. for (i = 0; i < 256; ++i) {
  23211. tmp = s[i];
  23212. j = (j + tmp + key[i % keyLength]) & 0xFF;
  23213. s[i] = s[j];
  23214. s[j] = tmp;
  23215. }
  23216. this.s = s;
  23217. }
  23218. ARCFourCipher.prototype = {
  23219. encryptBlock: function ARCFourCipher_encryptBlock(data) {
  23220. var i, n = data.length, tmp, tmp2;
  23221. var a = this.a, b = this.b, s = this.s;
  23222. var output = new Uint8Array(n);
  23223. for (i = 0; i < n; ++i) {
  23224. a = (a + 1) & 0xFF;
  23225. tmp = s[a];
  23226. b = (b + tmp) & 0xFF;
  23227. tmp2 = s[b];
  23228. s[a] = tmp2;
  23229. s[b] = tmp;
  23230. output[i] = data[i] ^ s[(tmp + tmp2) & 0xFF];
  23231. }
  23232. this.a = a;
  23233. this.b = b;
  23234. return output;
  23235. }
  23236. };
  23237. ARCFourCipher.prototype.decryptBlock = ARCFourCipher.prototype.encryptBlock;
  23238. return ARCFourCipher;
  23239. })();
  23240. var calculateMD5 = (function calculateMD5Closure() {
  23241. var r = new Uint8Array([
  23242. 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
  23243. 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
  23244. 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
  23245. 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21]);
  23246. var k = new Int32Array([
  23247. -680876936, -389564586, 606105819, -1044525330, -176418897, 1200080426,
  23248. -1473231341, -45705983, 1770035416, -1958414417, -42063, -1990404162,
  23249. 1804603682, -40341101, -1502002290, 1236535329, -165796510, -1069501632,
  23250. 643717713, -373897302, -701558691, 38016083, -660478335, -405537848,
  23251. 568446438, -1019803690, -187363961, 1163531501, -1444681467, -51403784,
  23252. 1735328473, -1926607734, -378558, -2022574463, 1839030562, -35309556,
  23253. -1530992060, 1272893353, -155497632, -1094730640, 681279174, -358537222,
  23254. -722521979, 76029189, -640364487, -421815835, 530742520, -995338651,
  23255. -198630844, 1126891415, -1416354905, -57434055, 1700485571, -1894986606,
  23256. -1051523, -2054922799, 1873313359, -30611744, -1560198380, 1309151649,
  23257. -145523070, -1120210379, 718787259, -343485551]);
  23258. function hash(data, offset, length) {
  23259. var h0 = 1732584193, h1 = -271733879, h2 = -1732584194, h3 = 271733878;
  23260. // pre-processing
  23261. var paddedLength = (length + 72) & ~63; // data + 9 extra bytes
  23262. var padded = new Uint8Array(paddedLength);
  23263. var i, j, n;
  23264. for (i = 0; i < length; ++i) {
  23265. padded[i] = data[offset++];
  23266. }
  23267. padded[i++] = 0x80;
  23268. n = paddedLength - 8;
  23269. while (i < n) {
  23270. padded[i++] = 0;
  23271. }
  23272. padded[i++] = (length << 3) & 0xFF;
  23273. padded[i++] = (length >> 5) & 0xFF;
  23274. padded[i++] = (length >> 13) & 0xFF;
  23275. padded[i++] = (length >> 21) & 0xFF;
  23276. padded[i++] = (length >>> 29) & 0xFF;
  23277. padded[i++] = 0;
  23278. padded[i++] = 0;
  23279. padded[i++] = 0;
  23280. var w = new Int32Array(16);
  23281. for (i = 0; i < paddedLength;) {
  23282. for (j = 0; j < 16; ++j, i += 4) {
  23283. w[j] = (padded[i] | (padded[i + 1] << 8) |
  23284. (padded[i + 2] << 16) | (padded[i + 3] << 24));
  23285. }
  23286. var a = h0, b = h1, c = h2, d = h3, f, g;
  23287. for (j = 0; j < 64; ++j) {
  23288. if (j < 16) {
  23289. f = (b & c) | ((~b) & d);
  23290. g = j;
  23291. } else if (j < 32) {
  23292. f = (d & b) | ((~d) & c);
  23293. g = (5 * j + 1) & 15;
  23294. } else if (j < 48) {
  23295. f = b ^ c ^ d;
  23296. g = (3 * j + 5) & 15;
  23297. } else {
  23298. f = c ^ (b | (~d));
  23299. g = (7 * j) & 15;
  23300. }
  23301. var tmp = d, rotateArg = (a + f + k[j] + w[g]) | 0, rotate = r[j];
  23302. d = c;
  23303. c = b;
  23304. b = (b + ((rotateArg << rotate) | (rotateArg >>> (32 - rotate)))) | 0;
  23305. a = tmp;
  23306. }
  23307. h0 = (h0 + a) | 0;
  23308. h1 = (h1 + b) | 0;
  23309. h2 = (h2 + c) | 0;
  23310. h3 = (h3 + d) | 0;
  23311. }
  23312. return new Uint8Array([
  23313. h0 & 0xFF, (h0 >> 8) & 0xFF, (h0 >> 16) & 0xFF, (h0 >>> 24) & 0xFF,
  23314. h1 & 0xFF, (h1 >> 8) & 0xFF, (h1 >> 16) & 0xFF, (h1 >>> 24) & 0xFF,
  23315. h2 & 0xFF, (h2 >> 8) & 0xFF, (h2 >> 16) & 0xFF, (h2 >>> 24) & 0xFF,
  23316. h3 & 0xFF, (h3 >> 8) & 0xFF, (h3 >> 16) & 0xFF, (h3 >>> 24) & 0xFF
  23317. ]);
  23318. }
  23319. return hash;
  23320. })();
  23321. var Word64 = (function Word64Closure() {
  23322. function Word64(highInteger, lowInteger) {
  23323. this.high = highInteger | 0;
  23324. this.low = lowInteger | 0;
  23325. }
  23326. Word64.prototype = {
  23327. and: function Word64_and(word) {
  23328. this.high &= word.high;
  23329. this.low &= word.low;
  23330. },
  23331. xor: function Word64_xor(word) {
  23332. this.high ^= word.high;
  23333. this.low ^= word.low;
  23334. },
  23335. or: function Word64_or(word) {
  23336. this.high |= word.high;
  23337. this.low |= word.low;
  23338. },
  23339. shiftRight: function Word64_shiftRight(places) {
  23340. if (places >= 32) {
  23341. this.low = (this.high >>> (places - 32)) | 0;
  23342. this.high = 0;
  23343. } else {
  23344. this.low = (this.low >>> places) | (this.high << (32 - places));
  23345. this.high = (this.high >>> places) | 0;
  23346. }
  23347. },
  23348. shiftLeft: function Word64_shiftLeft(places) {
  23349. if (places >= 32) {
  23350. this.high = this.low << (places - 32);
  23351. this.low = 0;
  23352. } else {
  23353. this.high = (this.high << places) | (this.low >>> (32 - places));
  23354. this.low = this.low << places;
  23355. }
  23356. },
  23357. rotateRight: function Word64_rotateRight(places) {
  23358. var low, high;
  23359. if (places & 32) {
  23360. high = this.low;
  23361. low = this.high;
  23362. } else {
  23363. low = this.low;
  23364. high = this.high;
  23365. }
  23366. places &= 31;
  23367. this.low = (low >>> places) | (high << (32 - places));
  23368. this.high = (high >>> places) | (low << (32 - places));
  23369. },
  23370. not: function Word64_not() {
  23371. this.high = ~this.high;
  23372. this.low = ~this.low;
  23373. },
  23374. add: function Word64_add(word) {
  23375. var lowAdd = (this.low >>> 0) + (word.low >>> 0);
  23376. var highAdd = (this.high >>> 0) + (word.high >>> 0);
  23377. if (lowAdd > 0xFFFFFFFF) {
  23378. highAdd += 1;
  23379. }
  23380. this.low = lowAdd | 0;
  23381. this.high = highAdd | 0;
  23382. },
  23383. copyTo: function Word64_copyTo(bytes, offset) {
  23384. bytes[offset] = (this.high >>> 24) & 0xFF;
  23385. bytes[offset + 1] = (this.high >> 16) & 0xFF;
  23386. bytes[offset + 2] = (this.high >> 8) & 0xFF;
  23387. bytes[offset + 3] = this.high & 0xFF;
  23388. bytes[offset + 4] = (this.low >>> 24) & 0xFF;
  23389. bytes[offset + 5] = (this.low >> 16) & 0xFF;
  23390. bytes[offset + 6] = (this.low >> 8) & 0xFF;
  23391. bytes[offset + 7] = this.low & 0xFF;
  23392. },
  23393. assign: function Word64_assign(word) {
  23394. this.high = word.high;
  23395. this.low = word.low;
  23396. }
  23397. };
  23398. return Word64;
  23399. })();
  23400. var calculateSHA256 = (function calculateSHA256Closure() {
  23401. function rotr(x, n) {
  23402. return (x >>> n) | (x << 32 - n);
  23403. }
  23404. function ch(x, y, z) {
  23405. return (x & y) ^ (~x & z);
  23406. }
  23407. function maj(x, y, z) {
  23408. return (x & y) ^ (x & z) ^ (y & z);
  23409. }
  23410. function sigma(x) {
  23411. return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
  23412. }
  23413. function sigmaPrime(x) {
  23414. return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
  23415. }
  23416. function littleSigma(x) {
  23417. return rotr(x, 7) ^ rotr(x, 18) ^ x >>> 3;
  23418. }
  23419. function littleSigmaPrime(x) {
  23420. return rotr(x, 17) ^ rotr(x, 19) ^ x >>> 10;
  23421. }
  23422. var k = [0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5,
  23423. 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
  23424. 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3,
  23425. 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
  23426. 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc,
  23427. 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
  23428. 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7,
  23429. 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
  23430. 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13,
  23431. 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
  23432. 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3,
  23433. 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
  23434. 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5,
  23435. 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
  23436. 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208,
  23437. 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2];
  23438. function hash(data, offset, length) {
  23439. // initial hash values
  23440. var h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372,
  23441. h3 = 0xa54ff53a, h4 = 0x510e527f, h5 = 0x9b05688c,
  23442. h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
  23443. // pre-processing
  23444. var paddedLength = Math.ceil((length + 9) / 64) * 64;
  23445. var padded = new Uint8Array(paddedLength);
  23446. var i, j, n;
  23447. for (i = 0; i < length; ++i) {
  23448. padded[i] = data[offset++];
  23449. }
  23450. padded[i++] = 0x80;
  23451. n = paddedLength - 8;
  23452. while (i < n) {
  23453. padded[i++] = 0;
  23454. }
  23455. padded[i++] = 0;
  23456. padded[i++] = 0;
  23457. padded[i++] = 0;
  23458. padded[i++] = (length >>> 29) & 0xFF;
  23459. padded[i++] = (length >> 21) & 0xFF;
  23460. padded[i++] = (length >> 13) & 0xFF;
  23461. padded[i++] = (length >> 5) & 0xFF;
  23462. padded[i++] = (length << 3) & 0xFF;
  23463. var w = new Uint32Array(64);
  23464. // for each 512 bit block
  23465. for (i = 0; i < paddedLength;) {
  23466. for (j = 0; j < 16; ++j) {
  23467. w[j] = (padded[i] << 24 | (padded[i + 1] << 16) |
  23468. (padded[i + 2] << 8) | (padded[i + 3]));
  23469. i += 4;
  23470. }
  23471. for (j = 16; j < 64; ++j) {
  23472. w[j] = littleSigmaPrime(w[j - 2]) + w[j - 7] +
  23473. littleSigma(w[j - 15]) + w[j - 16] | 0;
  23474. }
  23475. var a = h0, b = h1, c = h2, d = h3, e = h4,
  23476. f = h5, g = h6, h = h7, t1, t2;
  23477. for (j = 0; j < 64; ++j) {
  23478. t1 = h + sigmaPrime(e) + ch(e, f, g) + k[j] + w[j];
  23479. t2 = sigma(a) + maj(a, b, c);
  23480. h = g;
  23481. g = f;
  23482. f = e;
  23483. e = (d + t1) | 0;
  23484. d = c;
  23485. c = b;
  23486. b = a;
  23487. a = (t1 + t2) | 0;
  23488. }
  23489. h0 = (h0 + a) | 0;
  23490. h1 = (h1 + b) | 0;
  23491. h2 = (h2 + c) | 0;
  23492. h3 = (h3 + d) | 0;
  23493. h4 = (h4 + e) | 0;
  23494. h5 = (h5 + f) | 0;
  23495. h6 = (h6 + g) | 0;
  23496. h7 = (h7 + h) | 0;
  23497. }
  23498. return new Uint8Array([
  23499. (h0 >> 24) & 0xFF, (h0 >> 16) & 0xFF, (h0 >> 8) & 0xFF, (h0) & 0xFF,
  23500. (h1 >> 24) & 0xFF, (h1 >> 16) & 0xFF, (h1 >> 8) & 0xFF, (h1) & 0xFF,
  23501. (h2 >> 24) & 0xFF, (h2 >> 16) & 0xFF, (h2 >> 8) & 0xFF, (h2) & 0xFF,
  23502. (h3 >> 24) & 0xFF, (h3 >> 16) & 0xFF, (h3 >> 8) & 0xFF, (h3) & 0xFF,
  23503. (h4 >> 24) & 0xFF, (h4 >> 16) & 0xFF, (h4 >> 8) & 0xFF, (h4) & 0xFF,
  23504. (h5 >> 24) & 0xFF, (h5 >> 16) & 0xFF, (h5 >> 8) & 0xFF, (h5) & 0xFF,
  23505. (h6 >> 24) & 0xFF, (h6 >> 16) & 0xFF, (h6 >> 8) & 0xFF, (h6) & 0xFF,
  23506. (h7 >> 24) & 0xFF, (h7 >> 16) & 0xFF, (h7 >> 8) & 0xFF, (h7) & 0xFF
  23507. ]);
  23508. }
  23509. return hash;
  23510. })();
  23511. var calculateSHA512 = (function calculateSHA512Closure() {
  23512. function ch(result, x, y, z, tmp) {
  23513. result.assign(x);
  23514. result.and(y);
  23515. tmp.assign(x);
  23516. tmp.not();
  23517. tmp.and(z);
  23518. result.xor(tmp);
  23519. }
  23520. function maj(result, x, y, z, tmp) {
  23521. result.assign(x);
  23522. result.and(y);
  23523. tmp.assign(x);
  23524. tmp.and(z);
  23525. result.xor(tmp);
  23526. tmp.assign(y);
  23527. tmp.and(z);
  23528. result.xor(tmp);
  23529. }
  23530. function sigma(result, x, tmp) {
  23531. result.assign(x);
  23532. result.rotateRight(28);
  23533. tmp.assign(x);
  23534. tmp.rotateRight(34);
  23535. result.xor(tmp);
  23536. tmp.assign(x);
  23537. tmp.rotateRight(39);
  23538. result.xor(tmp);
  23539. }
  23540. function sigmaPrime(result, x, tmp) {
  23541. result.assign(x);
  23542. result.rotateRight(14);
  23543. tmp.assign(x);
  23544. tmp.rotateRight(18);
  23545. result.xor(tmp);
  23546. tmp.assign(x);
  23547. tmp.rotateRight(41);
  23548. result.xor(tmp);
  23549. }
  23550. function littleSigma(result, x, tmp) {
  23551. result.assign(x);
  23552. result.rotateRight(1);
  23553. tmp.assign(x);
  23554. tmp.rotateRight(8);
  23555. result.xor(tmp);
  23556. tmp.assign(x);
  23557. tmp.shiftRight(7);
  23558. result.xor(tmp);
  23559. }
  23560. function littleSigmaPrime(result, x, tmp) {
  23561. result.assign(x);
  23562. result.rotateRight(19);
  23563. tmp.assign(x);
  23564. tmp.rotateRight(61);
  23565. result.xor(tmp);
  23566. tmp.assign(x);
  23567. tmp.shiftRight(6);
  23568. result.xor(tmp);
  23569. }
  23570. var k = [
  23571. new Word64(0x428a2f98, 0xd728ae22), new Word64(0x71374491, 0x23ef65cd),
  23572. new Word64(0xb5c0fbcf, 0xec4d3b2f), new Word64(0xe9b5dba5, 0x8189dbbc),
  23573. new Word64(0x3956c25b, 0xf348b538), new Word64(0x59f111f1, 0xb605d019),
  23574. new Word64(0x923f82a4, 0xaf194f9b), new Word64(0xab1c5ed5, 0xda6d8118),
  23575. new Word64(0xd807aa98, 0xa3030242), new Word64(0x12835b01, 0x45706fbe),
  23576. new Word64(0x243185be, 0x4ee4b28c), new Word64(0x550c7dc3, 0xd5ffb4e2),
  23577. new Word64(0x72be5d74, 0xf27b896f), new Word64(0x80deb1fe, 0x3b1696b1),
  23578. new Word64(0x9bdc06a7, 0x25c71235), new Word64(0xc19bf174, 0xcf692694),
  23579. new Word64(0xe49b69c1, 0x9ef14ad2), new Word64(0xefbe4786, 0x384f25e3),
  23580. new Word64(0x0fc19dc6, 0x8b8cd5b5), new Word64(0x240ca1cc, 0x77ac9c65),
  23581. new Word64(0x2de92c6f, 0x592b0275), new Word64(0x4a7484aa, 0x6ea6e483),
  23582. new Word64(0x5cb0a9dc, 0xbd41fbd4), new Word64(0x76f988da, 0x831153b5),
  23583. new Word64(0x983e5152, 0xee66dfab), new Word64(0xa831c66d, 0x2db43210),
  23584. new Word64(0xb00327c8, 0x98fb213f), new Word64(0xbf597fc7, 0xbeef0ee4),
  23585. new Word64(0xc6e00bf3, 0x3da88fc2), new Word64(0xd5a79147, 0x930aa725),
  23586. new Word64(0x06ca6351, 0xe003826f), new Word64(0x14292967, 0x0a0e6e70),
  23587. new Word64(0x27b70a85, 0x46d22ffc), new Word64(0x2e1b2138, 0x5c26c926),
  23588. new Word64(0x4d2c6dfc, 0x5ac42aed), new Word64(0x53380d13, 0x9d95b3df),
  23589. new Word64(0x650a7354, 0x8baf63de), new Word64(0x766a0abb, 0x3c77b2a8),
  23590. new Word64(0x81c2c92e, 0x47edaee6), new Word64(0x92722c85, 0x1482353b),
  23591. new Word64(0xa2bfe8a1, 0x4cf10364), new Word64(0xa81a664b, 0xbc423001),
  23592. new Word64(0xc24b8b70, 0xd0f89791), new Word64(0xc76c51a3, 0x0654be30),
  23593. new Word64(0xd192e819, 0xd6ef5218), new Word64(0xd6990624, 0x5565a910),
  23594. new Word64(0xf40e3585, 0x5771202a), new Word64(0x106aa070, 0x32bbd1b8),
  23595. new Word64(0x19a4c116, 0xb8d2d0c8), new Word64(0x1e376c08, 0x5141ab53),
  23596. new Word64(0x2748774c, 0xdf8eeb99), new Word64(0x34b0bcb5, 0xe19b48a8),
  23597. new Word64(0x391c0cb3, 0xc5c95a63), new Word64(0x4ed8aa4a, 0xe3418acb),
  23598. new Word64(0x5b9cca4f, 0x7763e373), new Word64(0x682e6ff3, 0xd6b2b8a3),
  23599. new Word64(0x748f82ee, 0x5defb2fc), new Word64(0x78a5636f, 0x43172f60),
  23600. new Word64(0x84c87814, 0xa1f0ab72), new Word64(0x8cc70208, 0x1a6439ec),
  23601. new Word64(0x90befffa, 0x23631e28), new Word64(0xa4506ceb, 0xde82bde9),
  23602. new Word64(0xbef9a3f7, 0xb2c67915), new Word64(0xc67178f2, 0xe372532b),
  23603. new Word64(0xca273ece, 0xea26619c), new Word64(0xd186b8c7, 0x21c0c207),
  23604. new Word64(0xeada7dd6, 0xcde0eb1e), new Word64(0xf57d4f7f, 0xee6ed178),
  23605. new Word64(0x06f067aa, 0x72176fba), new Word64(0x0a637dc5, 0xa2c898a6),
  23606. new Word64(0x113f9804, 0xbef90dae), new Word64(0x1b710b35, 0x131c471b),
  23607. new Word64(0x28db77f5, 0x23047d84), new Word64(0x32caab7b, 0x40c72493),
  23608. new Word64(0x3c9ebe0a, 0x15c9bebc), new Word64(0x431d67c4, 0x9c100d4c),
  23609. new Word64(0x4cc5d4be, 0xcb3e42b6), new Word64(0x597f299c, 0xfc657e2a),
  23610. new Word64(0x5fcb6fab, 0x3ad6faec), new Word64(0x6c44198c, 0x4a475817)];
  23611. function hash(data, offset, length, mode384) {
  23612. mode384 = !!mode384;
  23613. // initial hash values
  23614. var h0, h1, h2, h3, h4, h5, h6, h7;
  23615. if (!mode384) {
  23616. h0 = new Word64(0x6a09e667, 0xf3bcc908);
  23617. h1 = new Word64(0xbb67ae85, 0x84caa73b);
  23618. h2 = new Word64(0x3c6ef372, 0xfe94f82b);
  23619. h3 = new Word64(0xa54ff53a, 0x5f1d36f1);
  23620. h4 = new Word64(0x510e527f, 0xade682d1);
  23621. h5 = new Word64(0x9b05688c, 0x2b3e6c1f);
  23622. h6 = new Word64(0x1f83d9ab, 0xfb41bd6b);
  23623. h7 = new Word64(0x5be0cd19, 0x137e2179);
  23624. }
  23625. else {
  23626. // SHA384 is exactly the same
  23627. // except with different starting values and a trimmed result
  23628. h0 = new Word64(0xcbbb9d5d, 0xc1059ed8);
  23629. h1 = new Word64(0x629a292a, 0x367cd507);
  23630. h2 = new Word64(0x9159015a, 0x3070dd17);
  23631. h3 = new Word64(0x152fecd8, 0xf70e5939);
  23632. h4 = new Word64(0x67332667, 0xffc00b31);
  23633. h5 = new Word64(0x8eb44a87, 0x68581511);
  23634. h6 = new Word64(0xdb0c2e0d, 0x64f98fa7);
  23635. h7 = new Word64(0x47b5481d, 0xbefa4fa4);
  23636. }
  23637. // pre-processing
  23638. var paddedLength = Math.ceil((length + 17) / 128) * 128;
  23639. var padded = new Uint8Array(paddedLength);
  23640. var i, j, n;
  23641. for (i = 0; i < length; ++i) {
  23642. padded[i] = data[offset++];
  23643. }
  23644. padded[i++] = 0x80;
  23645. n = paddedLength - 16;
  23646. while (i < n) {
  23647. padded[i++] = 0;
  23648. }
  23649. padded[i++] = 0;
  23650. padded[i++] = 0;
  23651. padded[i++] = 0;
  23652. padded[i++] = 0;
  23653. padded[i++] = 0;
  23654. padded[i++] = 0;
  23655. padded[i++] = 0;
  23656. padded[i++] = 0;
  23657. padded[i++] = 0;
  23658. padded[i++] = 0;
  23659. padded[i++] = 0;
  23660. padded[i++] = (length >>> 29) & 0xFF;
  23661. padded[i++] = (length >> 21) & 0xFF;
  23662. padded[i++] = (length >> 13) & 0xFF;
  23663. padded[i++] = (length >> 5) & 0xFF;
  23664. padded[i++] = (length << 3) & 0xFF;
  23665. var w = new Array(80);
  23666. for (i = 0; i < 80; i++) {
  23667. w[i] = new Word64(0, 0);
  23668. }
  23669. var a = new Word64(0, 0), b = new Word64(0, 0), c = new Word64(0, 0);
  23670. var d = new Word64(0, 0), e = new Word64(0, 0), f = new Word64(0, 0);
  23671. var g = new Word64(0, 0), h = new Word64(0, 0);
  23672. var t1 = new Word64(0, 0), t2 = new Word64(0, 0);
  23673. var tmp1 = new Word64(0, 0), tmp2 = new Word64(0, 0), tmp3;
  23674. // for each 1024 bit block
  23675. for (i = 0; i < paddedLength;) {
  23676. for (j = 0; j < 16; ++j) {
  23677. w[j].high = (padded[i] << 24) | (padded[i + 1] << 16) |
  23678. (padded[i + 2] << 8) | (padded[i + 3]);
  23679. w[j].low = (padded[i + 4]) << 24 | (padded[i + 5]) << 16 |
  23680. (padded[i + 6]) << 8 | (padded[i + 7]);
  23681. i += 8;
  23682. }
  23683. for (j = 16; j < 80; ++j) {
  23684. tmp3 = w[j];
  23685. littleSigmaPrime(tmp3, w[j - 2], tmp2);
  23686. tmp3.add(w[j - 7]);
  23687. littleSigma(tmp1, w[j - 15], tmp2);
  23688. tmp3.add(tmp1);
  23689. tmp3.add(w[j - 16]);
  23690. }
  23691. a.assign(h0); b.assign(h1); c.assign(h2); d.assign(h3);
  23692. e.assign(h4); f.assign(h5); g.assign(h6); h.assign(h7);
  23693. for (j = 0; j < 80; ++j) {
  23694. t1.assign(h);
  23695. sigmaPrime(tmp1, e, tmp2);
  23696. t1.add(tmp1);
  23697. ch(tmp1, e, f, g, tmp2);
  23698. t1.add(tmp1);
  23699. t1.add(k[j]);
  23700. t1.add(w[j]);
  23701. sigma(t2, a, tmp2);
  23702. maj(tmp1, a, b, c, tmp2);
  23703. t2.add(tmp1);
  23704. tmp3 = h;
  23705. h = g;
  23706. g = f;
  23707. f = e;
  23708. d.add(t1);
  23709. e = d;
  23710. d = c;
  23711. c = b;
  23712. b = a;
  23713. tmp3.assign(t1);
  23714. tmp3.add(t2);
  23715. a = tmp3;
  23716. }
  23717. h0.add(a);
  23718. h1.add(b);
  23719. h2.add(c);
  23720. h3.add(d);
  23721. h4.add(e);
  23722. h5.add(f);
  23723. h6.add(g);
  23724. h7.add(h);
  23725. }
  23726. var result;
  23727. if (!mode384) {
  23728. result = new Uint8Array(64);
  23729. h0.copyTo(result,0);
  23730. h1.copyTo(result,8);
  23731. h2.copyTo(result,16);
  23732. h3.copyTo(result,24);
  23733. h4.copyTo(result,32);
  23734. h5.copyTo(result,40);
  23735. h6.copyTo(result,48);
  23736. h7.copyTo(result,56);
  23737. }
  23738. else {
  23739. result = new Uint8Array(48);
  23740. h0.copyTo(result,0);
  23741. h1.copyTo(result,8);
  23742. h2.copyTo(result,16);
  23743. h3.copyTo(result,24);
  23744. h4.copyTo(result,32);
  23745. h5.copyTo(result,40);
  23746. }
  23747. return result;
  23748. }
  23749. return hash;
  23750. })();
  23751. var calculateSHA384 = (function calculateSHA384Closure() {
  23752. function hash(data, offset, length) {
  23753. return calculateSHA512(data, offset, length, true);
  23754. }
  23755. return hash;
  23756. })();
  23757. var NullCipher = (function NullCipherClosure() {
  23758. function NullCipher() {
  23759. }
  23760. NullCipher.prototype = {
  23761. decryptBlock: function NullCipher_decryptBlock(data) {
  23762. return data;
  23763. }
  23764. };
  23765. return NullCipher;
  23766. })();
  23767. var AES128Cipher = (function AES128CipherClosure() {
  23768. var rcon = new Uint8Array([
  23769. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23770. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23771. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23772. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23773. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  23774. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  23775. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  23776. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  23777. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  23778. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  23779. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  23780. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  23781. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  23782. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  23783. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  23784. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  23785. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  23786. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  23787. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  23788. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  23789. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  23790. 0x74, 0xe8, 0xcb, 0x8d]);
  23791. var s = new Uint8Array([
  23792. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  23793. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  23794. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  23795. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  23796. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  23797. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  23798. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  23799. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  23800. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  23801. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  23802. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  23803. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  23804. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  23805. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  23806. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  23807. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  23808. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  23809. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  23810. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  23811. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  23812. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  23813. 0xb0, 0x54, 0xbb, 0x16]);
  23814. var inv_s = new Uint8Array([
  23815. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  23816. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  23817. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  23818. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  23819. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  23820. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  23821. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  23822. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  23823. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  23824. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  23825. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  23826. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  23827. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  23828. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  23829. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  23830. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  23831. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  23832. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  23833. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  23834. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  23835. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  23836. 0x55, 0x21, 0x0c, 0x7d]);
  23837. var mixCol = new Uint8Array(256);
  23838. for (var i = 0; i < 256; i++) {
  23839. if (i < 128) {
  23840. mixCol[i] = i << 1;
  23841. } else {
  23842. mixCol[i] = (i << 1) ^ 0x1b;
  23843. }
  23844. }
  23845. var mix = new Uint32Array([
  23846. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  23847. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  23848. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  23849. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  23850. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  23851. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  23852. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  23853. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  23854. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  23855. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  23856. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  23857. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  23858. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  23859. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  23860. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  23861. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  23862. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  23863. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  23864. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  23865. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  23866. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  23867. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  23868. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  23869. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  23870. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  23871. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  23872. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  23873. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  23874. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  23875. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  23876. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  23877. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  23878. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  23879. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  23880. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  23881. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  23882. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  23883. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  23884. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  23885. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  23886. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  23887. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  23888. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  23889. function expandKey128(cipherKey) {
  23890. var b = 176, result = new Uint8Array(b);
  23891. result.set(cipherKey);
  23892. for (var j = 16, i = 1; j < b; ++i) {
  23893. // RotWord
  23894. var t1 = result[j - 3], t2 = result[j - 2],
  23895. t3 = result[j - 1], t4 = result[j - 4];
  23896. // SubWord
  23897. t1 = s[t1];
  23898. t2 = s[t2];
  23899. t3 = s[t3];
  23900. t4 = s[t4];
  23901. // Rcon
  23902. t1 = t1 ^ rcon[i];
  23903. for (var n = 0; n < 4; ++n) {
  23904. result[j] = (t1 ^= result[j - 16]);
  23905. j++;
  23906. result[j] = (t2 ^= result[j - 16]);
  23907. j++;
  23908. result[j] = (t3 ^= result[j - 16]);
  23909. j++;
  23910. result[j] = (t4 ^= result[j - 16]);
  23911. j++;
  23912. }
  23913. }
  23914. return result;
  23915. }
  23916. function decrypt128(input, key) {
  23917. var state = new Uint8Array(16);
  23918. state.set(input);
  23919. var i, j, k;
  23920. var t, u, v;
  23921. // AddRoundKey
  23922. for (j = 0, k = 160; j < 16; ++j, ++k) {
  23923. state[j] ^= key[k];
  23924. }
  23925. for (i = 9; i >= 1; --i) {
  23926. // InvShiftRows
  23927. t = state[13];
  23928. state[13] = state[9];
  23929. state[9] = state[5];
  23930. state[5] = state[1];
  23931. state[1] = t;
  23932. t = state[14];
  23933. u = state[10];
  23934. state[14] = state[6];
  23935. state[10] = state[2];
  23936. state[6] = t;
  23937. state[2] = u;
  23938. t = state[15];
  23939. u = state[11];
  23940. v = state[7];
  23941. state[15] = state[3];
  23942. state[11] = t;
  23943. state[7] = u;
  23944. state[3] = v;
  23945. // InvSubBytes
  23946. for (j = 0; j < 16; ++j) {
  23947. state[j] = inv_s[state[j]];
  23948. }
  23949. // AddRoundKey
  23950. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  23951. state[j] ^= key[k];
  23952. }
  23953. // InvMixColumns
  23954. for (j = 0; j < 16; j += 4) {
  23955. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  23956. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  23957. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  23958. (s3 >>> 24) ^ (s3 << 8));
  23959. state[j] = (t >>> 24) & 0xFF;
  23960. state[j + 1] = (t >> 16) & 0xFF;
  23961. state[j + 2] = (t >> 8) & 0xFF;
  23962. state[j + 3] = t & 0xFF;
  23963. }
  23964. }
  23965. // InvShiftRows
  23966. t = state[13];
  23967. state[13] = state[9];
  23968. state[9] = state[5];
  23969. state[5] = state[1];
  23970. state[1] = t;
  23971. t = state[14];
  23972. u = state[10];
  23973. state[14] = state[6];
  23974. state[10] = state[2];
  23975. state[6] = t;
  23976. state[2] = u;
  23977. t = state[15];
  23978. u = state[11];
  23979. v = state[7];
  23980. state[15] = state[3];
  23981. state[11] = t;
  23982. state[7] = u;
  23983. state[3] = v;
  23984. for (j = 0; j < 16; ++j) {
  23985. // InvSubBytes
  23986. state[j] = inv_s[state[j]];
  23987. // AddRoundKey
  23988. state[j] ^= key[j];
  23989. }
  23990. return state;
  23991. }
  23992. function encrypt128(input, key) {
  23993. var t, u, v, k;
  23994. var state = new Uint8Array(16);
  23995. state.set(input);
  23996. for (j = 0; j < 16; ++j) {
  23997. // AddRoundKey
  23998. state[j] ^= key[j];
  23999. }
  24000. for (i = 1; i < 10; i++) {
  24001. //SubBytes
  24002. for (j = 0; j < 16; ++j) {
  24003. state[j] = s[state[j]];
  24004. }
  24005. //ShiftRows
  24006. v = state[1];
  24007. state[1] = state[5];
  24008. state[5] = state[9];
  24009. state[9] = state[13];
  24010. state[13] = v;
  24011. v = state[2];
  24012. u = state[6];
  24013. state[2] = state[10];
  24014. state[6] = state[14];
  24015. state[10] = v;
  24016. state[14] = u;
  24017. v = state[3];
  24018. u = state[7];
  24019. t = state[11];
  24020. state[3] = state[15];
  24021. state[7] = v;
  24022. state[11] = u;
  24023. state[15] = t;
  24024. //MixColumns
  24025. for (var j = 0; j < 16; j += 4) {
  24026. var s0 = state[j + 0], s1 = state[j + 1];
  24027. var s2 = state[j + 2], s3 = state[j + 3];
  24028. t = s0 ^ s1 ^ s2 ^ s3;
  24029. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24030. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24031. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24032. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24033. }
  24034. //AddRoundKey
  24035. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24036. state[j] ^= key[k];
  24037. }
  24038. }
  24039. //SubBytes
  24040. for (j = 0; j < 16; ++j) {
  24041. state[j] = s[state[j]];
  24042. }
  24043. //ShiftRows
  24044. v = state[1];
  24045. state[1] = state[5];
  24046. state[5] = state[9];
  24047. state[9] = state[13];
  24048. state[13] = v;
  24049. v = state[2];
  24050. u = state[6];
  24051. state[2] = state[10];
  24052. state[6] = state[14];
  24053. state[10] = v;
  24054. state[14] = u;
  24055. v = state[3];
  24056. u = state[7];
  24057. t = state[11];
  24058. state[3] = state[15];
  24059. state[7] = v;
  24060. state[11] = u;
  24061. state[15] = t;
  24062. //AddRoundKey
  24063. for (j = 0, k = 160; j < 16; ++j, ++k) {
  24064. state[j] ^= key[k];
  24065. }
  24066. return state;
  24067. }
  24068. function AES128Cipher(key) {
  24069. this.key = expandKey128(key);
  24070. this.buffer = new Uint8Array(16);
  24071. this.bufferPosition = 0;
  24072. }
  24073. function decryptBlock2(data, finalize) {
  24074. var i, j, ii, sourceLength = data.length,
  24075. buffer = this.buffer, bufferLength = this.bufferPosition,
  24076. result = [], iv = this.iv;
  24077. for (i = 0; i < sourceLength; ++i) {
  24078. buffer[bufferLength] = data[i];
  24079. ++bufferLength;
  24080. if (bufferLength < 16) {
  24081. continue;
  24082. }
  24083. // buffer is full, decrypting
  24084. var plain = decrypt128(buffer, this.key);
  24085. // xor-ing the IV vector to get plain text
  24086. for (j = 0; j < 16; ++j) {
  24087. plain[j] ^= iv[j];
  24088. }
  24089. iv = buffer;
  24090. result.push(plain);
  24091. buffer = new Uint8Array(16);
  24092. bufferLength = 0;
  24093. }
  24094. // saving incomplete buffer
  24095. this.buffer = buffer;
  24096. this.bufferLength = bufferLength;
  24097. this.iv = iv;
  24098. if (result.length === 0) {
  24099. return new Uint8Array([]);
  24100. }
  24101. // combining plain text blocks into one
  24102. var outputLength = 16 * result.length;
  24103. if (finalize) {
  24104. // undo a padding that is described in RFC 2898
  24105. var lastBlock = result[result.length - 1];
  24106. var psLen = lastBlock[15];
  24107. if (psLen <= 16) {
  24108. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24109. if (lastBlock[i] !== psLen) {
  24110. // Invalid padding, assume that the block has no padding.
  24111. psLen = 0;
  24112. break;
  24113. }
  24114. }
  24115. outputLength -= psLen;
  24116. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24117. }
  24118. }
  24119. var output = new Uint8Array(outputLength);
  24120. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24121. output.set(result[i], j);
  24122. }
  24123. return output;
  24124. }
  24125. AES128Cipher.prototype = {
  24126. decryptBlock: function AES128Cipher_decryptBlock(data, finalize) {
  24127. var i, sourceLength = data.length;
  24128. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24129. // waiting for IV values -- they are at the start of the stream
  24130. for (i = 0; bufferLength < 16 && i < sourceLength; ++i, ++bufferLength) {
  24131. buffer[bufferLength] = data[i];
  24132. }
  24133. if (bufferLength < 16) {
  24134. // need more data
  24135. this.bufferLength = bufferLength;
  24136. return new Uint8Array([]);
  24137. }
  24138. this.iv = buffer;
  24139. this.buffer = new Uint8Array(16);
  24140. this.bufferLength = 0;
  24141. // starting decryption
  24142. this.decryptBlock = decryptBlock2;
  24143. return this.decryptBlock(data.subarray(16), finalize);
  24144. },
  24145. encrypt: function AES128Cipher_encrypt(data, iv) {
  24146. var i, j, ii, sourceLength = data.length,
  24147. buffer = this.buffer, bufferLength = this.bufferPosition,
  24148. result = [];
  24149. if (!iv) {
  24150. iv = new Uint8Array(16);
  24151. }
  24152. for (i = 0; i < sourceLength; ++i) {
  24153. buffer[bufferLength] = data[i];
  24154. ++bufferLength;
  24155. if (bufferLength < 16) {
  24156. continue;
  24157. }
  24158. for (j = 0; j < 16; ++j) {
  24159. buffer[j] ^= iv[j];
  24160. }
  24161. // buffer is full, encrypting
  24162. var cipher = encrypt128(buffer, this.key);
  24163. iv = cipher;
  24164. result.push(cipher);
  24165. buffer = new Uint8Array(16);
  24166. bufferLength = 0;
  24167. }
  24168. // saving incomplete buffer
  24169. this.buffer = buffer;
  24170. this.bufferLength = bufferLength;
  24171. this.iv = iv;
  24172. if (result.length === 0) {
  24173. return new Uint8Array([]);
  24174. }
  24175. // combining plain text blocks into one
  24176. var outputLength = 16 * result.length;
  24177. var output = new Uint8Array(outputLength);
  24178. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24179. output.set(result[i], j);
  24180. }
  24181. return output;
  24182. }
  24183. };
  24184. return AES128Cipher;
  24185. })();
  24186. var AES256Cipher = (function AES256CipherClosure() {
  24187. var rcon = new Uint8Array([
  24188. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24189. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24190. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24191. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24192. 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
  24193. 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6,
  24194. 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72,
  24195. 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc,
  24196. 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10,
  24197. 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e,
  24198. 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5,
  24199. 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94,
  24200. 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb, 0x8d, 0x01, 0x02,
  24201. 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c, 0xd8, 0xab, 0x4d,
  24202. 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a, 0xd4, 0xb3, 0x7d,
  24203. 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd, 0x61, 0xc2, 0x9f,
  24204. 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a, 0x74, 0xe8, 0xcb,
  24205. 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36, 0x6c,
  24206. 0xd8, 0xab, 0x4d, 0x9a, 0x2f, 0x5e, 0xbc, 0x63, 0xc6, 0x97, 0x35, 0x6a,
  24207. 0xd4, 0xb3, 0x7d, 0xfa, 0xef, 0xc5, 0x91, 0x39, 0x72, 0xe4, 0xd3, 0xbd,
  24208. 0x61, 0xc2, 0x9f, 0x25, 0x4a, 0x94, 0x33, 0x66, 0xcc, 0x83, 0x1d, 0x3a,
  24209. 0x74, 0xe8, 0xcb, 0x8d]);
  24210. var s = new Uint8Array([
  24211. 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b,
  24212. 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0,
  24213. 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26,
  24214. 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15,
  24215. 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2,
  24216. 0xeb, 0x27, 0xb2, 0x75, 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0,
  24217. 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed,
  24218. 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf,
  24219. 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f,
  24220. 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5,
  24221. 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, 0x13, 0xec,
  24222. 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73,
  24223. 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14,
  24224. 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c,
  24225. 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d,
  24226. 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08,
  24227. 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f,
  24228. 0x4b, 0xbd, 0x8b, 0x8a, 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e,
  24229. 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11,
  24230. 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf,
  24231. 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f,
  24232. 0xb0, 0x54, 0xbb, 0x16]);
  24233. var inv_s = new Uint8Array([
  24234. 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e,
  24235. 0x81, 0xf3, 0xd7, 0xfb, 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87,
  24236. 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 0x54, 0x7b, 0x94, 0x32,
  24237. 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e,
  24238. 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49,
  24239. 0x6d, 0x8b, 0xd1, 0x25, 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16,
  24240. 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 0x6c, 0x70, 0x48, 0x50,
  24241. 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84,
  24242. 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05,
  24243. 0xb8, 0xb3, 0x45, 0x06, 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02,
  24244. 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 0x3a, 0x91, 0x11, 0x41,
  24245. 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73,
  24246. 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8,
  24247. 0x1c, 0x75, 0xdf, 0x6e, 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89,
  24248. 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 0xfc, 0x56, 0x3e, 0x4b,
  24249. 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4,
  24250. 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59,
  24251. 0x27, 0x80, 0xec, 0x5f, 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d,
  24252. 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 0xa0, 0xe0, 0x3b, 0x4d,
  24253. 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61,
  24254. 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63,
  24255. 0x55, 0x21, 0x0c, 0x7d]);
  24256. var mixCol = new Uint8Array(256);
  24257. for (var i = 0; i < 256; i++) {
  24258. if (i < 128) {
  24259. mixCol[i] = i << 1;
  24260. } else {
  24261. mixCol[i] = (i << 1) ^ 0x1b;
  24262. }
  24263. }
  24264. var mix = new Uint32Array([
  24265. 0x00000000, 0x0e090d0b, 0x1c121a16, 0x121b171d, 0x3824342c, 0x362d3927,
  24266. 0x24362e3a, 0x2a3f2331, 0x70486858, 0x7e416553, 0x6c5a724e, 0x62537f45,
  24267. 0x486c5c74, 0x4665517f, 0x547e4662, 0x5a774b69, 0xe090d0b0, 0xee99ddbb,
  24268. 0xfc82caa6, 0xf28bc7ad, 0xd8b4e49c, 0xd6bde997, 0xc4a6fe8a, 0xcaaff381,
  24269. 0x90d8b8e8, 0x9ed1b5e3, 0x8ccaa2fe, 0x82c3aff5, 0xa8fc8cc4, 0xa6f581cf,
  24270. 0xb4ee96d2, 0xbae79bd9, 0xdb3bbb7b, 0xd532b670, 0xc729a16d, 0xc920ac66,
  24271. 0xe31f8f57, 0xed16825c, 0xff0d9541, 0xf104984a, 0xab73d323, 0xa57ade28,
  24272. 0xb761c935, 0xb968c43e, 0x9357e70f, 0x9d5eea04, 0x8f45fd19, 0x814cf012,
  24273. 0x3bab6bcb, 0x35a266c0, 0x27b971dd, 0x29b07cd6, 0x038f5fe7, 0x0d8652ec,
  24274. 0x1f9d45f1, 0x119448fa, 0x4be30393, 0x45ea0e98, 0x57f11985, 0x59f8148e,
  24275. 0x73c737bf, 0x7dce3ab4, 0x6fd52da9, 0x61dc20a2, 0xad766df6, 0xa37f60fd,
  24276. 0xb16477e0, 0xbf6d7aeb, 0x955259da, 0x9b5b54d1, 0x894043cc, 0x87494ec7,
  24277. 0xdd3e05ae, 0xd33708a5, 0xc12c1fb8, 0xcf2512b3, 0xe51a3182, 0xeb133c89,
  24278. 0xf9082b94, 0xf701269f, 0x4de6bd46, 0x43efb04d, 0x51f4a750, 0x5ffdaa5b,
  24279. 0x75c2896a, 0x7bcb8461, 0x69d0937c, 0x67d99e77, 0x3daed51e, 0x33a7d815,
  24280. 0x21bccf08, 0x2fb5c203, 0x058ae132, 0x0b83ec39, 0x1998fb24, 0x1791f62f,
  24281. 0x764dd68d, 0x7844db86, 0x6a5fcc9b, 0x6456c190, 0x4e69e2a1, 0x4060efaa,
  24282. 0x527bf8b7, 0x5c72f5bc, 0x0605bed5, 0x080cb3de, 0x1a17a4c3, 0x141ea9c8,
  24283. 0x3e218af9, 0x302887f2, 0x223390ef, 0x2c3a9de4, 0x96dd063d, 0x98d40b36,
  24284. 0x8acf1c2b, 0x84c61120, 0xaef93211, 0xa0f03f1a, 0xb2eb2807, 0xbce2250c,
  24285. 0xe6956e65, 0xe89c636e, 0xfa877473, 0xf48e7978, 0xdeb15a49, 0xd0b85742,
  24286. 0xc2a3405f, 0xccaa4d54, 0x41ecdaf7, 0x4fe5d7fc, 0x5dfec0e1, 0x53f7cdea,
  24287. 0x79c8eedb, 0x77c1e3d0, 0x65daf4cd, 0x6bd3f9c6, 0x31a4b2af, 0x3fadbfa4,
  24288. 0x2db6a8b9, 0x23bfa5b2, 0x09808683, 0x07898b88, 0x15929c95, 0x1b9b919e,
  24289. 0xa17c0a47, 0xaf75074c, 0xbd6e1051, 0xb3671d5a, 0x99583e6b, 0x97513360,
  24290. 0x854a247d, 0x8b432976, 0xd134621f, 0xdf3d6f14, 0xcd267809, 0xc32f7502,
  24291. 0xe9105633, 0xe7195b38, 0xf5024c25, 0xfb0b412e, 0x9ad7618c, 0x94de6c87,
  24292. 0x86c57b9a, 0x88cc7691, 0xa2f355a0, 0xacfa58ab, 0xbee14fb6, 0xb0e842bd,
  24293. 0xea9f09d4, 0xe49604df, 0xf68d13c2, 0xf8841ec9, 0xd2bb3df8, 0xdcb230f3,
  24294. 0xcea927ee, 0xc0a02ae5, 0x7a47b13c, 0x744ebc37, 0x6655ab2a, 0x685ca621,
  24295. 0x42638510, 0x4c6a881b, 0x5e719f06, 0x5078920d, 0x0a0fd964, 0x0406d46f,
  24296. 0x161dc372, 0x1814ce79, 0x322bed48, 0x3c22e043, 0x2e39f75e, 0x2030fa55,
  24297. 0xec9ab701, 0xe293ba0a, 0xf088ad17, 0xfe81a01c, 0xd4be832d, 0xdab78e26,
  24298. 0xc8ac993b, 0xc6a59430, 0x9cd2df59, 0x92dbd252, 0x80c0c54f, 0x8ec9c844,
  24299. 0xa4f6eb75, 0xaaffe67e, 0xb8e4f163, 0xb6edfc68, 0x0c0a67b1, 0x02036aba,
  24300. 0x10187da7, 0x1e1170ac, 0x342e539d, 0x3a275e96, 0x283c498b, 0x26354480,
  24301. 0x7c420fe9, 0x724b02e2, 0x605015ff, 0x6e5918f4, 0x44663bc5, 0x4a6f36ce,
  24302. 0x587421d3, 0x567d2cd8, 0x37a10c7a, 0x39a80171, 0x2bb3166c, 0x25ba1b67,
  24303. 0x0f853856, 0x018c355d, 0x13972240, 0x1d9e2f4b, 0x47e96422, 0x49e06929,
  24304. 0x5bfb7e34, 0x55f2733f, 0x7fcd500e, 0x71c45d05, 0x63df4a18, 0x6dd64713,
  24305. 0xd731dcca, 0xd938d1c1, 0xcb23c6dc, 0xc52acbd7, 0xef15e8e6, 0xe11ce5ed,
  24306. 0xf307f2f0, 0xfd0efffb, 0xa779b492, 0xa970b999, 0xbb6bae84, 0xb562a38f,
  24307. 0x9f5d80be, 0x91548db5, 0x834f9aa8, 0x8d4697a3]);
  24308. function expandKey256(cipherKey) {
  24309. var b = 240, result = new Uint8Array(b);
  24310. var r = 1;
  24311. result.set(cipherKey);
  24312. for (var j = 32, i = 1; j < b; ++i) {
  24313. if (j % 32 === 16) {
  24314. t1 = s[t1];
  24315. t2 = s[t2];
  24316. t3 = s[t3];
  24317. t4 = s[t4];
  24318. } else if (j % 32 === 0) {
  24319. // RotWord
  24320. var t1 = result[j - 3], t2 = result[j - 2],
  24321. t3 = result[j - 1], t4 = result[j - 4];
  24322. // SubWord
  24323. t1 = s[t1];
  24324. t2 = s[t2];
  24325. t3 = s[t3];
  24326. t4 = s[t4];
  24327. // Rcon
  24328. t1 = t1 ^ r;
  24329. if ((r <<= 1) >= 256) {
  24330. r = (r ^ 0x1b) & 0xFF;
  24331. }
  24332. }
  24333. for (var n = 0; n < 4; ++n) {
  24334. result[j] = (t1 ^= result[j - 32]);
  24335. j++;
  24336. result[j] = (t2 ^= result[j - 32]);
  24337. j++;
  24338. result[j] = (t3 ^= result[j - 32]);
  24339. j++;
  24340. result[j] = (t4 ^= result[j - 32]);
  24341. j++;
  24342. }
  24343. }
  24344. return result;
  24345. }
  24346. function decrypt256(input, key) {
  24347. var state = new Uint8Array(16);
  24348. state.set(input);
  24349. var i, j, k;
  24350. var t, u, v;
  24351. // AddRoundKey
  24352. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24353. state[j] ^= key[k];
  24354. }
  24355. for (i = 13; i >= 1; --i) {
  24356. // InvShiftRows
  24357. t = state[13];
  24358. state[13] = state[9];
  24359. state[9] = state[5];
  24360. state[5] = state[1];
  24361. state[1] = t;
  24362. t = state[14];
  24363. u = state[10];
  24364. state[14] = state[6];
  24365. state[10] = state[2];
  24366. state[6] = t;
  24367. state[2] = u;
  24368. t = state[15];
  24369. u = state[11];
  24370. v = state[7];
  24371. state[15] = state[3];
  24372. state[11] = t;
  24373. state[7] = u;
  24374. state[3] = v;
  24375. // InvSubBytes
  24376. for (j = 0; j < 16; ++j) {
  24377. state[j] = inv_s[state[j]];
  24378. }
  24379. // AddRoundKey
  24380. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24381. state[j] ^= key[k];
  24382. }
  24383. // InvMixColumns
  24384. for (j = 0; j < 16; j += 4) {
  24385. var s0 = mix[state[j]], s1 = mix[state[j + 1]],
  24386. s2 = mix[state[j + 2]], s3 = mix[state[j + 3]];
  24387. t = (s0 ^ (s1 >>> 8) ^ (s1 << 24) ^ (s2 >>> 16) ^ (s2 << 16) ^
  24388. (s3 >>> 24) ^ (s3 << 8));
  24389. state[j] = (t >>> 24) & 0xFF;
  24390. state[j + 1] = (t >> 16) & 0xFF;
  24391. state[j + 2] = (t >> 8) & 0xFF;
  24392. state[j + 3] = t & 0xFF;
  24393. }
  24394. }
  24395. // InvShiftRows
  24396. t = state[13];
  24397. state[13] = state[9];
  24398. state[9] = state[5];
  24399. state[5] = state[1];
  24400. state[1] = t;
  24401. t = state[14];
  24402. u = state[10];
  24403. state[14] = state[6];
  24404. state[10] = state[2];
  24405. state[6] = t;
  24406. state[2] = u;
  24407. t = state[15];
  24408. u = state[11];
  24409. v = state[7];
  24410. state[15] = state[3];
  24411. state[11] = t;
  24412. state[7] = u;
  24413. state[3] = v;
  24414. for (j = 0; j < 16; ++j) {
  24415. // InvSubBytes
  24416. state[j] = inv_s[state[j]];
  24417. // AddRoundKey
  24418. state[j] ^= key[j];
  24419. }
  24420. return state;
  24421. }
  24422. function encrypt256(input, key) {
  24423. var t, u, v, k;
  24424. var state = new Uint8Array(16);
  24425. state.set(input);
  24426. for (j = 0; j < 16; ++j) {
  24427. // AddRoundKey
  24428. state[j] ^= key[j];
  24429. }
  24430. for (i = 1; i < 14; i++) {
  24431. //SubBytes
  24432. for (j = 0; j < 16; ++j) {
  24433. state[j] = s[state[j]];
  24434. }
  24435. //ShiftRows
  24436. v = state[1];
  24437. state[1] = state[5];
  24438. state[5] = state[9];
  24439. state[9] = state[13];
  24440. state[13] = v;
  24441. v = state[2];
  24442. u = state[6];
  24443. state[2] = state[10];
  24444. state[6] = state[14];
  24445. state[10] = v;
  24446. state[14] = u;
  24447. v = state[3];
  24448. u = state[7];
  24449. t = state[11];
  24450. state[3] = state[15];
  24451. state[7] = v;
  24452. state[11] = u;
  24453. state[15] = t;
  24454. //MixColumns
  24455. for (var j = 0; j < 16; j += 4) {
  24456. var s0 = state[j + 0], s1 = state[j + 1];
  24457. var s2 = state[j + 2], s3 = state[j + 3];
  24458. t = s0 ^ s1 ^ s2 ^ s3;
  24459. state[j + 0] ^= t ^ mixCol[s0 ^ s1];
  24460. state[j + 1] ^= t ^ mixCol[s1 ^ s2];
  24461. state[j + 2] ^= t ^ mixCol[s2 ^ s3];
  24462. state[j + 3] ^= t ^ mixCol[s3 ^ s0];
  24463. }
  24464. //AddRoundKey
  24465. for (j = 0, k = i * 16; j < 16; ++j, ++k) {
  24466. state[j] ^= key[k];
  24467. }
  24468. }
  24469. //SubBytes
  24470. for (j = 0; j < 16; ++j) {
  24471. state[j] = s[state[j]];
  24472. }
  24473. //ShiftRows
  24474. v = state[1];
  24475. state[1] = state[5];
  24476. state[5] = state[9];
  24477. state[9] = state[13];
  24478. state[13] = v;
  24479. v = state[2];
  24480. u = state[6];
  24481. state[2] = state[10];
  24482. state[6] = state[14];
  24483. state[10] = v;
  24484. state[14] = u;
  24485. v = state[3];
  24486. u = state[7];
  24487. t = state[11];
  24488. state[3] = state[15];
  24489. state[7] = v;
  24490. state[11] = u;
  24491. state[15] = t;
  24492. //AddRoundKey
  24493. for (j = 0, k = 224; j < 16; ++j, ++k) {
  24494. state[j] ^= key[k];
  24495. }
  24496. return state;
  24497. }
  24498. function AES256Cipher(key) {
  24499. this.key = expandKey256(key);
  24500. this.buffer = new Uint8Array(16);
  24501. this.bufferPosition = 0;
  24502. }
  24503. function decryptBlock2(data, finalize) {
  24504. var i, j, ii, sourceLength = data.length,
  24505. buffer = this.buffer, bufferLength = this.bufferPosition,
  24506. result = [], iv = this.iv;
  24507. for (i = 0; i < sourceLength; ++i) {
  24508. buffer[bufferLength] = data[i];
  24509. ++bufferLength;
  24510. if (bufferLength < 16) {
  24511. continue;
  24512. }
  24513. // buffer is full, decrypting
  24514. var plain = decrypt256(buffer, this.key);
  24515. // xor-ing the IV vector to get plain text
  24516. for (j = 0; j < 16; ++j) {
  24517. plain[j] ^= iv[j];
  24518. }
  24519. iv = buffer;
  24520. result.push(plain);
  24521. buffer = new Uint8Array(16);
  24522. bufferLength = 0;
  24523. }
  24524. // saving incomplete buffer
  24525. this.buffer = buffer;
  24526. this.bufferLength = bufferLength;
  24527. this.iv = iv;
  24528. if (result.length === 0) {
  24529. return new Uint8Array([]);
  24530. }
  24531. // combining plain text blocks into one
  24532. var outputLength = 16 * result.length;
  24533. if (finalize) {
  24534. // undo a padding that is described in RFC 2898
  24535. var lastBlock = result[result.length - 1];
  24536. var psLen = lastBlock[15];
  24537. if (psLen <= 16) {
  24538. for (i = 15, ii = 16 - psLen; i >= ii; --i) {
  24539. if (lastBlock[i] !== psLen) {
  24540. // Invalid padding, assume that the block has no padding.
  24541. psLen = 0;
  24542. break;
  24543. }
  24544. }
  24545. outputLength -= psLen;
  24546. result[result.length - 1] = lastBlock.subarray(0, 16 - psLen);
  24547. }
  24548. }
  24549. var output = new Uint8Array(outputLength);
  24550. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24551. output.set(result[i], j);
  24552. }
  24553. return output;
  24554. }
  24555. AES256Cipher.prototype = {
  24556. decryptBlock: function AES256Cipher_decryptBlock(data, finalize, iv) {
  24557. var i, sourceLength = data.length;
  24558. var buffer = this.buffer, bufferLength = this.bufferPosition;
  24559. // if not supplied an IV wait for IV values
  24560. // they are at the start of the stream
  24561. if (iv) {
  24562. this.iv = iv;
  24563. } else {
  24564. for (i = 0; bufferLength < 16 &&
  24565. i < sourceLength; ++i, ++bufferLength) {
  24566. buffer[bufferLength] = data[i];
  24567. }
  24568. if (bufferLength < 16) {
  24569. //need more data
  24570. this.bufferLength = bufferLength;
  24571. return new Uint8Array([]);
  24572. }
  24573. this.iv = buffer;
  24574. data = data.subarray(16);
  24575. }
  24576. this.buffer = new Uint8Array(16);
  24577. this.bufferLength = 0;
  24578. // starting decryption
  24579. this.decryptBlock = decryptBlock2;
  24580. return this.decryptBlock(data, finalize);
  24581. },
  24582. encrypt: function AES256Cipher_encrypt(data, iv) {
  24583. var i, j, ii, sourceLength = data.length,
  24584. buffer = this.buffer, bufferLength = this.bufferPosition,
  24585. result = [];
  24586. if (!iv) {
  24587. iv = new Uint8Array(16);
  24588. }
  24589. for (i = 0; i < sourceLength; ++i) {
  24590. buffer[bufferLength] = data[i];
  24591. ++bufferLength;
  24592. if (bufferLength < 16) {
  24593. continue;
  24594. }
  24595. for (j = 0; j < 16; ++j) {
  24596. buffer[j] ^= iv[j];
  24597. }
  24598. // buffer is full, encrypting
  24599. var cipher = encrypt256(buffer, this.key);
  24600. this.iv = cipher;
  24601. result.push(cipher);
  24602. buffer = new Uint8Array(16);
  24603. bufferLength = 0;
  24604. }
  24605. // saving incomplete buffer
  24606. this.buffer = buffer;
  24607. this.bufferLength = bufferLength;
  24608. this.iv = iv;
  24609. if (result.length === 0) {
  24610. return new Uint8Array([]);
  24611. }
  24612. // combining plain text blocks into one
  24613. var outputLength = 16 * result.length;
  24614. var output = new Uint8Array(outputLength);
  24615. for (i = 0, j = 0, ii = result.length; i < ii; ++i, j += 16) {
  24616. output.set(result[i], j);
  24617. }
  24618. return output;
  24619. }
  24620. };
  24621. return AES256Cipher;
  24622. })();
  24623. var PDF17 = (function PDF17Closure() {
  24624. function compareByteArrays(array1, array2) {
  24625. if (array1.length !== array2.length) {
  24626. return false;
  24627. }
  24628. for (var i = 0; i < array1.length; i++) {
  24629. if (array1[i] !== array2[i]) {
  24630. return false;
  24631. }
  24632. }
  24633. return true;
  24634. }
  24635. function PDF17() {
  24636. }
  24637. PDF17.prototype = {
  24638. checkOwnerPassword: function PDF17_checkOwnerPassword(password,
  24639. ownerValidationSalt,
  24640. userBytes,
  24641. ownerPassword) {
  24642. var hashData = new Uint8Array(password.length + 56);
  24643. hashData.set(password, 0);
  24644. hashData.set(ownerValidationSalt, password.length);
  24645. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24646. var result = calculateSHA256(hashData, 0, hashData.length);
  24647. return compareByteArrays(result, ownerPassword);
  24648. },
  24649. checkUserPassword: function PDF17_checkUserPassword(password,
  24650. userValidationSalt,
  24651. userPassword) {
  24652. var hashData = new Uint8Array(password.length + 8);
  24653. hashData.set(password, 0);
  24654. hashData.set(userValidationSalt, password.length);
  24655. var result = calculateSHA256(hashData, 0, hashData.length);
  24656. return compareByteArrays(result, userPassword);
  24657. },
  24658. getOwnerKey: function PDF17_getOwnerKey(password, ownerKeySalt, userBytes,
  24659. ownerEncryption) {
  24660. var hashData = new Uint8Array(password.length + 56);
  24661. hashData.set(password, 0);
  24662. hashData.set(ownerKeySalt, password.length);
  24663. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24664. var key = calculateSHA256(hashData, 0, hashData.length);
  24665. var cipher = new AES256Cipher(key);
  24666. return cipher.decryptBlock(ownerEncryption,
  24667. false,
  24668. new Uint8Array(16));
  24669. },
  24670. getUserKey: function PDF17_getUserKey(password, userKeySalt,
  24671. userEncryption) {
  24672. var hashData = new Uint8Array(password.length + 8);
  24673. hashData.set(password, 0);
  24674. hashData.set(userKeySalt, password.length);
  24675. //key is the decryption key for the UE string
  24676. var key = calculateSHA256(hashData, 0, hashData.length);
  24677. var cipher = new AES256Cipher(key);
  24678. return cipher.decryptBlock(userEncryption,
  24679. false,
  24680. new Uint8Array(16));
  24681. }
  24682. };
  24683. return PDF17;
  24684. })();
  24685. var PDF20 = (function PDF20Closure() {
  24686. function concatArrays(array1, array2) {
  24687. var t = new Uint8Array(array1.length + array2.length);
  24688. t.set(array1, 0);
  24689. t.set(array2, array1.length);
  24690. return t;
  24691. }
  24692. function calculatePDF20Hash(password, input, userBytes) {
  24693. //This refers to Algorithm 2.B as defined in ISO 32000-2
  24694. var k = calculateSHA256(input, 0, input.length).subarray(0, 32);
  24695. var e = [0];
  24696. var i = 0;
  24697. while (i < 64 || e[e.length - 1] > i - 32) {
  24698. var arrayLength = password.length + k.length + userBytes.length;
  24699. var k1 = new Uint8Array(arrayLength * 64);
  24700. var array = concatArrays(password, k);
  24701. array = concatArrays(array, userBytes);
  24702. for (var j = 0, pos = 0; j < 64; j++, pos += arrayLength) {
  24703. k1.set(array, pos);
  24704. }
  24705. //AES128 CBC NO PADDING with
  24706. //first 16 bytes of k as the key and the second 16 as the iv.
  24707. var cipher = new AES128Cipher(k.subarray(0, 16));
  24708. e = cipher.encrypt(k1, k.subarray(16, 32));
  24709. //Now we have to take the first 16 bytes of an unsigned
  24710. //big endian integer... and compute the remainder
  24711. //modulo 3.... That is a fairly large number and
  24712. //JavaScript isn't going to handle that well...
  24713. //So we're using a trick that allows us to perform
  24714. //modulo math byte by byte
  24715. var remainder = 0;
  24716. for (var z = 0; z < 16; z++) {
  24717. remainder *= (256 % 3);
  24718. remainder %= 3;
  24719. remainder += ((e[z] >>> 0) % 3);
  24720. remainder %= 3;
  24721. }
  24722. if (remainder === 0) {
  24723. k = calculateSHA256(e, 0, e.length);
  24724. }
  24725. else if (remainder === 1) {
  24726. k = calculateSHA384(e, 0, e.length);
  24727. }
  24728. else if (remainder === 2) {
  24729. k = calculateSHA512(e, 0, e.length);
  24730. }
  24731. i++;
  24732. }
  24733. return k.subarray(0, 32);
  24734. }
  24735. function PDF20() {
  24736. }
  24737. function compareByteArrays(array1, array2) {
  24738. if (array1.length !== array2.length) {
  24739. return false;
  24740. }
  24741. for (var i = 0; i < array1.length; i++) {
  24742. if (array1[i] !== array2[i]) {
  24743. return false;
  24744. }
  24745. }
  24746. return true;
  24747. }
  24748. PDF20.prototype = {
  24749. hash: function PDF20_hash(password, concatBytes, userBytes) {
  24750. return calculatePDF20Hash(password, concatBytes, userBytes);
  24751. },
  24752. checkOwnerPassword: function PDF20_checkOwnerPassword(password,
  24753. ownerValidationSalt,
  24754. userBytes,
  24755. ownerPassword) {
  24756. var hashData = new Uint8Array(password.length + 56);
  24757. hashData.set(password, 0);
  24758. hashData.set(ownerValidationSalt, password.length);
  24759. hashData.set(userBytes, password.length + ownerValidationSalt.length);
  24760. var result = calculatePDF20Hash(password, hashData, userBytes);
  24761. return compareByteArrays(result, ownerPassword);
  24762. },
  24763. checkUserPassword: function PDF20_checkUserPassword(password,
  24764. userValidationSalt,
  24765. userPassword) {
  24766. var hashData = new Uint8Array(password.length + 8);
  24767. hashData.set(password, 0);
  24768. hashData.set(userValidationSalt, password.length);
  24769. var result = calculatePDF20Hash(password, hashData, []);
  24770. return compareByteArrays(result, userPassword);
  24771. },
  24772. getOwnerKey: function PDF20_getOwnerKey(password, ownerKeySalt, userBytes,
  24773. ownerEncryption) {
  24774. var hashData = new Uint8Array(password.length + 56);
  24775. hashData.set(password, 0);
  24776. hashData.set(ownerKeySalt, password.length);
  24777. hashData.set(userBytes, password.length + ownerKeySalt.length);
  24778. var key = calculatePDF20Hash(password, hashData, userBytes);
  24779. var cipher = new AES256Cipher(key);
  24780. return cipher.decryptBlock(ownerEncryption,
  24781. false,
  24782. new Uint8Array(16));
  24783. },
  24784. getUserKey: function PDF20_getUserKey(password, userKeySalt,
  24785. userEncryption) {
  24786. var hashData = new Uint8Array(password.length + 8);
  24787. hashData.set(password, 0);
  24788. hashData.set(userKeySalt, password.length);
  24789. //key is the decryption key for the UE string
  24790. var key = calculatePDF20Hash(password, hashData, []);
  24791. var cipher = new AES256Cipher(key);
  24792. return cipher.decryptBlock(userEncryption,
  24793. false,
  24794. new Uint8Array(16));
  24795. }
  24796. };
  24797. return PDF20;
  24798. })();
  24799. var CipherTransform = (function CipherTransformClosure() {
  24800. function CipherTransform(stringCipherConstructor, streamCipherConstructor) {
  24801. this.stringCipherConstructor = stringCipherConstructor;
  24802. this.streamCipherConstructor = streamCipherConstructor;
  24803. }
  24804. CipherTransform.prototype = {
  24805. createStream: function CipherTransform_createStream(stream, length) {
  24806. var cipher = new this.streamCipherConstructor();
  24807. return new DecryptStream(stream, length,
  24808. function cipherTransformDecryptStream(data, finalize) {
  24809. return cipher.decryptBlock(data, finalize);
  24810. }
  24811. );
  24812. },
  24813. decryptString: function CipherTransform_decryptString(s) {
  24814. var cipher = new this.stringCipherConstructor();
  24815. var data = stringToBytes(s);
  24816. data = cipher.decryptBlock(data, true);
  24817. return bytesToString(data);
  24818. }
  24819. };
  24820. return CipherTransform;
  24821. })();
  24822. var CipherTransformFactory = (function CipherTransformFactoryClosure() {
  24823. var defaultPasswordBytes = new Uint8Array([
  24824. 0x28, 0xBF, 0x4E, 0x5E, 0x4E, 0x75, 0x8A, 0x41,
  24825. 0x64, 0x00, 0x4E, 0x56, 0xFF, 0xFA, 0x01, 0x08,
  24826. 0x2E, 0x2E, 0x00, 0xB6, 0xD0, 0x68, 0x3E, 0x80,
  24827. 0x2F, 0x0C, 0xA9, 0xFE, 0x64, 0x53, 0x69, 0x7A]);
  24828. function createEncryptionKey20(revision, password, ownerPassword,
  24829. ownerValidationSalt, ownerKeySalt, uBytes,
  24830. userPassword, userValidationSalt, userKeySalt,
  24831. ownerEncryption, userEncryption, perms) {
  24832. if (password) {
  24833. var passwordLength = Math.min(127, password.length);
  24834. password = password.subarray(0, passwordLength);
  24835. } else {
  24836. password = [];
  24837. }
  24838. var pdfAlgorithm;
  24839. if (revision === 6) {
  24840. pdfAlgorithm = new PDF20();
  24841. } else {
  24842. pdfAlgorithm = new PDF17();
  24843. }
  24844. if (pdfAlgorithm) {
  24845. if (pdfAlgorithm.checkUserPassword(password, userValidationSalt,
  24846. userPassword)) {
  24847. return pdfAlgorithm.getUserKey(password, userKeySalt, userEncryption);
  24848. } else if (password.length && pdfAlgorithm.checkOwnerPassword(password,
  24849. ownerValidationSalt,
  24850. uBytes,
  24851. ownerPassword)) {
  24852. return pdfAlgorithm.getOwnerKey(password, ownerKeySalt, uBytes,
  24853. ownerEncryption);
  24854. }
  24855. }
  24856. return null;
  24857. }
  24858. function prepareKeyData(fileId, password, ownerPassword, userPassword,
  24859. flags, revision, keyLength, encryptMetadata) {
  24860. var hashDataSize = 40 + ownerPassword.length + fileId.length;
  24861. var hashData = new Uint8Array(hashDataSize), i = 0, j, n;
  24862. if (password) {
  24863. n = Math.min(32, password.length);
  24864. for (; i < n; ++i) {
  24865. hashData[i] = password[i];
  24866. }
  24867. }
  24868. j = 0;
  24869. while (i < 32) {
  24870. hashData[i++] = defaultPasswordBytes[j++];
  24871. }
  24872. // as now the padded password in the hashData[0..i]
  24873. for (j = 0, n = ownerPassword.length; j < n; ++j) {
  24874. hashData[i++] = ownerPassword[j];
  24875. }
  24876. hashData[i++] = flags & 0xFF;
  24877. hashData[i++] = (flags >> 8) & 0xFF;
  24878. hashData[i++] = (flags >> 16) & 0xFF;
  24879. hashData[i++] = (flags >>> 24) & 0xFF;
  24880. for (j = 0, n = fileId.length; j < n; ++j) {
  24881. hashData[i++] = fileId[j];
  24882. }
  24883. if (revision >= 4 && !encryptMetadata) {
  24884. hashData[i++] = 0xFF;
  24885. hashData[i++] = 0xFF;
  24886. hashData[i++] = 0xFF;
  24887. hashData[i++] = 0xFF;
  24888. }
  24889. var hash = calculateMD5(hashData, 0, i);
  24890. var keyLengthInBytes = keyLength >> 3;
  24891. if (revision >= 3) {
  24892. for (j = 0; j < 50; ++j) {
  24893. hash = calculateMD5(hash, 0, keyLengthInBytes);
  24894. }
  24895. }
  24896. var encryptionKey = hash.subarray(0, keyLengthInBytes);
  24897. var cipher, checkData;
  24898. if (revision >= 3) {
  24899. for (i = 0; i < 32; ++i) {
  24900. hashData[i] = defaultPasswordBytes[i];
  24901. }
  24902. for (j = 0, n = fileId.length; j < n; ++j) {
  24903. hashData[i++] = fileId[j];
  24904. }
  24905. cipher = new ARCFourCipher(encryptionKey);
  24906. checkData = cipher.encryptBlock(calculateMD5(hashData, 0, i));
  24907. n = encryptionKey.length;
  24908. var derivedKey = new Uint8Array(n), k;
  24909. for (j = 1; j <= 19; ++j) {
  24910. for (k = 0; k < n; ++k) {
  24911. derivedKey[k] = encryptionKey[k] ^ j;
  24912. }
  24913. cipher = new ARCFourCipher(derivedKey);
  24914. checkData = cipher.encryptBlock(checkData);
  24915. }
  24916. for (j = 0, n = checkData.length; j < n; ++j) {
  24917. if (userPassword[j] !== checkData[j]) {
  24918. return null;
  24919. }
  24920. }
  24921. } else {
  24922. cipher = new ARCFourCipher(encryptionKey);
  24923. checkData = cipher.encryptBlock(defaultPasswordBytes);
  24924. for (j = 0, n = checkData.length; j < n; ++j) {
  24925. if (userPassword[j] !== checkData[j]) {
  24926. return null;
  24927. }
  24928. }
  24929. }
  24930. return encryptionKey;
  24931. }
  24932. function decodeUserPassword(password, ownerPassword, revision, keyLength) {
  24933. var hashData = new Uint8Array(32), i = 0, j, n;
  24934. n = Math.min(32, password.length);
  24935. for (; i < n; ++i) {
  24936. hashData[i] = password[i];
  24937. }
  24938. j = 0;
  24939. while (i < 32) {
  24940. hashData[i++] = defaultPasswordBytes[j++];
  24941. }
  24942. var hash = calculateMD5(hashData, 0, i);
  24943. var keyLengthInBytes = keyLength >> 3;
  24944. if (revision >= 3) {
  24945. for (j = 0; j < 50; ++j) {
  24946. hash = calculateMD5(hash, 0, hash.length);
  24947. }
  24948. }
  24949. var cipher, userPassword;
  24950. if (revision >= 3) {
  24951. userPassword = ownerPassword;
  24952. var derivedKey = new Uint8Array(keyLengthInBytes), k;
  24953. for (j = 19; j >= 0; j--) {
  24954. for (k = 0; k < keyLengthInBytes; ++k) {
  24955. derivedKey[k] = hash[k] ^ j;
  24956. }
  24957. cipher = new ARCFourCipher(derivedKey);
  24958. userPassword = cipher.encryptBlock(userPassword);
  24959. }
  24960. } else {
  24961. cipher = new ARCFourCipher(hash.subarray(0, keyLengthInBytes));
  24962. userPassword = cipher.encryptBlock(ownerPassword);
  24963. }
  24964. return userPassword;
  24965. }
  24966. var identityName = Name.get('Identity');
  24967. function CipherTransformFactory(dict, fileId, password) {
  24968. var filter = dict.get('Filter');
  24969. if (!isName(filter) || filter.name !== 'Standard') {
  24970. error('unknown encryption method');
  24971. }
  24972. this.dict = dict;
  24973. var algorithm = dict.get('V');
  24974. if (!isInt(algorithm) ||
  24975. (algorithm !== 1 && algorithm !== 2 && algorithm !== 4 &&
  24976. algorithm !== 5)) {
  24977. error('unsupported encryption algorithm');
  24978. }
  24979. this.algorithm = algorithm;
  24980. var keyLength = dict.get('Length');
  24981. if (!keyLength) {
  24982. // Spec asks to rely on encryption dictionary's Length entry, however
  24983. // some PDFs don't have it. Trying to recover.
  24984. if (algorithm <= 3) {
  24985. // For 1 and 2 it's fixed to 40-bit, for 3 40-bit is a minimal value.
  24986. keyLength = 40;
  24987. } else {
  24988. // Trying to find default handler -- it usually has Length.
  24989. var cfDict = dict.get('CF');
  24990. var streamCryptoName = dict.get('StmF');
  24991. if (isDict(cfDict) && isName(streamCryptoName)) {
  24992. var handlerDict = cfDict.get(streamCryptoName.name);
  24993. keyLength = (handlerDict && handlerDict.get('Length')) || 128;
  24994. if (keyLength < 40) {
  24995. // Sometimes it's incorrect value of bits, generators specify bytes.
  24996. keyLength <<= 3;
  24997. }
  24998. }
  24999. }
  25000. }
  25001. if (!isInt(keyLength) ||
  25002. keyLength < 40 || (keyLength % 8) !== 0) {
  25003. error('invalid key length');
  25004. }
  25005. // prepare keys
  25006. var ownerPassword = stringToBytes(dict.get('O')).subarray(0, 32);
  25007. var userPassword = stringToBytes(dict.get('U')).subarray(0, 32);
  25008. var flags = dict.get('P');
  25009. var revision = dict.get('R');
  25010. // meaningful when V is 4 or 5
  25011. var encryptMetadata = ((algorithm === 4 || algorithm === 5) &&
  25012. dict.get('EncryptMetadata') !== false);
  25013. this.encryptMetadata = encryptMetadata;
  25014. var fileIdBytes = stringToBytes(fileId);
  25015. var passwordBytes;
  25016. if (password) {
  25017. if (revision === 6) {
  25018. try {
  25019. password = utf8StringToString(password);
  25020. } catch (ex) {
  25021. warn('CipherTransformFactory: ' +
  25022. 'Unable to convert UTF8 encoded password.');
  25023. }
  25024. }
  25025. passwordBytes = stringToBytes(password);
  25026. }
  25027. var encryptionKey;
  25028. if (algorithm !== 5) {
  25029. encryptionKey = prepareKeyData(fileIdBytes, passwordBytes,
  25030. ownerPassword, userPassword, flags,
  25031. revision, keyLength, encryptMetadata);
  25032. }
  25033. else {
  25034. var ownerValidationSalt = stringToBytes(dict.get('O')).subarray(32, 40);
  25035. var ownerKeySalt = stringToBytes(dict.get('O')).subarray(40, 48);
  25036. var uBytes = stringToBytes(dict.get('U')).subarray(0, 48);
  25037. var userValidationSalt = stringToBytes(dict.get('U')).subarray(32, 40);
  25038. var userKeySalt = stringToBytes(dict.get('U')).subarray(40, 48);
  25039. var ownerEncryption = stringToBytes(dict.get('OE'));
  25040. var userEncryption = stringToBytes(dict.get('UE'));
  25041. var perms = stringToBytes(dict.get('Perms'));
  25042. encryptionKey =
  25043. createEncryptionKey20(revision, passwordBytes,
  25044. ownerPassword, ownerValidationSalt,
  25045. ownerKeySalt, uBytes,
  25046. userPassword, userValidationSalt,
  25047. userKeySalt, ownerEncryption,
  25048. userEncryption, perms);
  25049. }
  25050. if (!encryptionKey && !password) {
  25051. throw new PasswordException('No password given',
  25052. PasswordResponses.NEED_PASSWORD);
  25053. } else if (!encryptionKey && password) {
  25054. // Attempting use the password as an owner password
  25055. var decodedPassword = decodeUserPassword(passwordBytes, ownerPassword,
  25056. revision, keyLength);
  25057. encryptionKey = prepareKeyData(fileIdBytes, decodedPassword,
  25058. ownerPassword, userPassword, flags,
  25059. revision, keyLength, encryptMetadata);
  25060. }
  25061. if (!encryptionKey) {
  25062. throw new PasswordException('Incorrect Password',
  25063. PasswordResponses.INCORRECT_PASSWORD);
  25064. }
  25065. this.encryptionKey = encryptionKey;
  25066. if (algorithm >= 4) {
  25067. this.cf = dict.get('CF');
  25068. this.stmf = dict.get('StmF') || identityName;
  25069. this.strf = dict.get('StrF') || identityName;
  25070. this.eff = dict.get('EFF') || this.stmf;
  25071. }
  25072. }
  25073. function buildObjectKey(num, gen, encryptionKey, isAes) {
  25074. var key = new Uint8Array(encryptionKey.length + 9), i, n;
  25075. for (i = 0, n = encryptionKey.length; i < n; ++i) {
  25076. key[i] = encryptionKey[i];
  25077. }
  25078. key[i++] = num & 0xFF;
  25079. key[i++] = (num >> 8) & 0xFF;
  25080. key[i++] = (num >> 16) & 0xFF;
  25081. key[i++] = gen & 0xFF;
  25082. key[i++] = (gen >> 8) & 0xFF;
  25083. if (isAes) {
  25084. key[i++] = 0x73;
  25085. key[i++] = 0x41;
  25086. key[i++] = 0x6C;
  25087. key[i++] = 0x54;
  25088. }
  25089. var hash = calculateMD5(key, 0, i);
  25090. return hash.subarray(0, Math.min(encryptionKey.length + 5, 16));
  25091. }
  25092. function buildCipherConstructor(cf, name, num, gen, key) {
  25093. var cryptFilter = cf.get(name.name);
  25094. var cfm;
  25095. if (cryptFilter !== null && cryptFilter !== undefined) {
  25096. cfm = cryptFilter.get('CFM');
  25097. }
  25098. if (!cfm || cfm.name === 'None') {
  25099. return function cipherTransformFactoryBuildCipherConstructorNone() {
  25100. return new NullCipher();
  25101. };
  25102. }
  25103. if ('V2' === cfm.name) {
  25104. return function cipherTransformFactoryBuildCipherConstructorV2() {
  25105. return new ARCFourCipher(buildObjectKey(num, gen, key, false));
  25106. };
  25107. }
  25108. if ('AESV2' === cfm.name) {
  25109. return function cipherTransformFactoryBuildCipherConstructorAESV2() {
  25110. return new AES128Cipher(buildObjectKey(num, gen, key, true));
  25111. };
  25112. }
  25113. if ('AESV3' === cfm.name) {
  25114. return function cipherTransformFactoryBuildCipherConstructorAESV3() {
  25115. return new AES256Cipher(key);
  25116. };
  25117. }
  25118. error('Unknown crypto method');
  25119. }
  25120. CipherTransformFactory.prototype = {
  25121. createCipherTransform:
  25122. function CipherTransformFactory_createCipherTransform(num, gen) {
  25123. if (this.algorithm === 4 || this.algorithm === 5) {
  25124. return new CipherTransform(
  25125. buildCipherConstructor(this.cf, this.stmf,
  25126. num, gen, this.encryptionKey),
  25127. buildCipherConstructor(this.cf, this.strf,
  25128. num, gen, this.encryptionKey));
  25129. }
  25130. // algorithms 1 and 2
  25131. var key = buildObjectKey(num, gen, this.encryptionKey, false);
  25132. var cipherConstructor = function buildCipherCipherConstructor() {
  25133. return new ARCFourCipher(key);
  25134. };
  25135. return new CipherTransform(cipherConstructor, cipherConstructor);
  25136. }
  25137. };
  25138. return CipherTransformFactory;
  25139. })();
  25140. exports.AES128Cipher = AES128Cipher;
  25141. exports.AES256Cipher = AES256Cipher;
  25142. exports.ARCFourCipher = ARCFourCipher;
  25143. exports.CipherTransformFactory = CipherTransformFactory;
  25144. exports.PDF17 = PDF17;
  25145. exports.PDF20 = PDF20;
  25146. exports.calculateMD5 = calculateMD5;
  25147. exports.calculateSHA256 = calculateSHA256;
  25148. exports.calculateSHA384 = calculateSHA384;
  25149. exports.calculateSHA512 = calculateSHA512;
  25150. }));
  25151. (function (root, factory) {
  25152. {
  25153. factory((root.pdfjsCoreFontRenderer = {}), root.pdfjsSharedUtil,
  25154. root.pdfjsCoreStream, root.pdfjsCoreGlyphList, root.pdfjsCoreEncodings,
  25155. root.pdfjsCoreCFFParser);
  25156. }
  25157. }(this, function (exports, sharedUtil, coreStream, coreGlyphList,
  25158. coreEncodings, coreCFFParser) {
  25159. var Util = sharedUtil.Util;
  25160. var bytesToString = sharedUtil.bytesToString;
  25161. var error = sharedUtil.error;
  25162. var Stream = coreStream.Stream;
  25163. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  25164. var StandardEncoding = coreEncodings.StandardEncoding;
  25165. var CFFParser = coreCFFParser.CFFParser;
  25166. var FontRendererFactory = (function FontRendererFactoryClosure() {
  25167. function getLong(data, offset) {
  25168. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25169. (data[offset + 2] << 8) | data[offset + 3];
  25170. }
  25171. function getUshort(data, offset) {
  25172. return (data[offset] << 8) | data[offset + 1];
  25173. }
  25174. function parseCmap(data, start, end) {
  25175. var offset = (getUshort(data, start + 2) === 1 ?
  25176. getLong(data, start + 8) : getLong(data, start + 16));
  25177. var format = getUshort(data, start + offset);
  25178. var length, ranges, p, i;
  25179. if (format === 4) {
  25180. length = getUshort(data, start + offset + 2);
  25181. var segCount = getUshort(data, start + offset + 6) >> 1;
  25182. p = start + offset + 14;
  25183. ranges = [];
  25184. for (i = 0; i < segCount; i++, p += 2) {
  25185. ranges[i] = {end: getUshort(data, p)};
  25186. }
  25187. p += 2;
  25188. for (i = 0; i < segCount; i++, p += 2) {
  25189. ranges[i].start = getUshort(data, p);
  25190. }
  25191. for (i = 0; i < segCount; i++, p += 2) {
  25192. ranges[i].idDelta = getUshort(data, p);
  25193. }
  25194. for (i = 0; i < segCount; i++, p += 2) {
  25195. var idOffset = getUshort(data, p);
  25196. if (idOffset === 0) {
  25197. continue;
  25198. }
  25199. ranges[i].ids = [];
  25200. for (var j = 0, jj = ranges[i].end - ranges[i].start + 1; j < jj; j++) {
  25201. ranges[i].ids[j] = getUshort(data, p + idOffset);
  25202. idOffset += 2;
  25203. }
  25204. }
  25205. return ranges;
  25206. } else if (format === 12) {
  25207. length = getLong(data, start + offset + 4);
  25208. var groups = getLong(data, start + offset + 12);
  25209. p = start + offset + 16;
  25210. ranges = [];
  25211. for (i = 0; i < groups; i++) {
  25212. ranges.push({
  25213. start: getLong(data, p),
  25214. end: getLong(data, p + 4),
  25215. idDelta: getLong(data, p + 8) - getLong(data, p)
  25216. });
  25217. p += 12;
  25218. }
  25219. return ranges;
  25220. }
  25221. error('not supported cmap: ' + format);
  25222. }
  25223. function parseCff(data, start, end, seacAnalysisEnabled) {
  25224. var properties = {};
  25225. var parser = new CFFParser(new Stream(data, start, end - start),
  25226. properties, seacAnalysisEnabled);
  25227. var cff = parser.parse();
  25228. return {
  25229. glyphs: cff.charStrings.objects,
  25230. subrs: (cff.topDict.privateDict && cff.topDict.privateDict.subrsIndex &&
  25231. cff.topDict.privateDict.subrsIndex.objects),
  25232. gsubrs: cff.globalSubrIndex && cff.globalSubrIndex.objects
  25233. };
  25234. }
  25235. function parseGlyfTable(glyf, loca, isGlyphLocationsLong) {
  25236. var itemSize, itemDecode;
  25237. if (isGlyphLocationsLong) {
  25238. itemSize = 4;
  25239. itemDecode = function fontItemDecodeLong(data, offset) {
  25240. return (data[offset] << 24) | (data[offset + 1] << 16) |
  25241. (data[offset + 2] << 8) | data[offset + 3];
  25242. };
  25243. } else {
  25244. itemSize = 2;
  25245. itemDecode = function fontItemDecode(data, offset) {
  25246. return (data[offset] << 9) | (data[offset + 1] << 1);
  25247. };
  25248. }
  25249. var glyphs = [];
  25250. var startOffset = itemDecode(loca, 0);
  25251. for (var j = itemSize; j < loca.length; j += itemSize) {
  25252. var endOffset = itemDecode(loca, j);
  25253. glyphs.push(glyf.subarray(startOffset, endOffset));
  25254. startOffset = endOffset;
  25255. }
  25256. return glyphs;
  25257. }
  25258. function lookupCmap(ranges, unicode) {
  25259. var code = unicode.charCodeAt(0), gid = 0;
  25260. var l = 0, r = ranges.length - 1;
  25261. while (l < r) {
  25262. var c = (l + r + 1) >> 1;
  25263. if (code < ranges[c].start) {
  25264. r = c - 1;
  25265. } else {
  25266. l = c;
  25267. }
  25268. }
  25269. if (ranges[l].start <= code && code <= ranges[l].end) {
  25270. gid = (ranges[l].idDelta + (ranges[l].ids ?
  25271. ranges[l].ids[code - ranges[l].start] : code)) & 0xFFFF;
  25272. }
  25273. return {
  25274. charCode: code,
  25275. glyphId: gid,
  25276. };
  25277. }
  25278. function compileGlyf(code, cmds, font) {
  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 quadraticCurveTo(xa, ya, x, y) {
  25286. cmds.push({cmd: 'quadraticCurveTo', args: [xa, ya, x, y]});
  25287. }
  25288. var i = 0;
  25289. var numberOfContours = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25290. var flags;
  25291. var x = 0, y = 0;
  25292. i += 10;
  25293. if (numberOfContours < 0) {
  25294. // composite glyph
  25295. do {
  25296. flags = (code[i] << 8) | code[i + 1];
  25297. var glyphIndex = (code[i + 2] << 8) | code[i + 3];
  25298. i += 4;
  25299. var arg1, arg2;
  25300. if ((flags & 0x01)) {
  25301. arg1 = ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25302. arg2 = ((code[i + 2] << 24) | (code[i + 3] << 16)) >> 16;
  25303. i += 4;
  25304. } else {
  25305. arg1 = code[i++]; arg2 = code[i++];
  25306. }
  25307. if ((flags & 0x02)) {
  25308. x = arg1;
  25309. y = arg2;
  25310. } else {
  25311. x = 0; y = 0; // TODO "they are points" ?
  25312. }
  25313. var scaleX = 1, scaleY = 1, scale01 = 0, scale10 = 0;
  25314. if ((flags & 0x08)) {
  25315. scaleX =
  25316. scaleY = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25317. i += 2;
  25318. } else if ((flags & 0x40)) {
  25319. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25320. scaleY = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25321. i += 4;
  25322. } else if ((flags & 0x80)) {
  25323. scaleX = ((code[i] << 24) | (code[i + 1] << 16)) / 1073741824;
  25324. scale01 = ((code[i + 2] << 24) | (code[i + 3] << 16)) / 1073741824;
  25325. scale10 = ((code[i + 4] << 24) | (code[i + 5] << 16)) / 1073741824;
  25326. scaleY = ((code[i + 6] << 24) | (code[i + 7] << 16)) / 1073741824;
  25327. i += 8;
  25328. }
  25329. var subglyph = font.glyphs[glyphIndex];
  25330. if (subglyph) {
  25331. cmds.push({cmd: 'save'});
  25332. cmds.push({cmd: 'transform',
  25333. args: [scaleX, scale01, scale10, scaleY, x, y]});
  25334. compileGlyf(subglyph, cmds, font);
  25335. cmds.push({cmd: 'restore'});
  25336. }
  25337. } while ((flags & 0x20));
  25338. } else {
  25339. // simple glyph
  25340. var endPtsOfContours = [];
  25341. var j, jj;
  25342. for (j = 0; j < numberOfContours; j++) {
  25343. endPtsOfContours.push((code[i] << 8) | code[i + 1]);
  25344. i += 2;
  25345. }
  25346. var instructionLength = (code[i] << 8) | code[i + 1];
  25347. i += 2 + instructionLength; // skipping the instructions
  25348. var numberOfPoints = endPtsOfContours[endPtsOfContours.length - 1] + 1;
  25349. var points = [];
  25350. while (points.length < numberOfPoints) {
  25351. flags = code[i++];
  25352. var repeat = 1;
  25353. if ((flags & 0x08)) {
  25354. repeat += code[i++];
  25355. }
  25356. while (repeat-- > 0) {
  25357. points.push({flags: flags});
  25358. }
  25359. }
  25360. for (j = 0; j < numberOfPoints; j++) {
  25361. switch (points[j].flags & 0x12) {
  25362. case 0x00:
  25363. x += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25364. i += 2;
  25365. break;
  25366. case 0x02:
  25367. x -= code[i++];
  25368. break;
  25369. case 0x12:
  25370. x += code[i++];
  25371. break;
  25372. }
  25373. points[j].x = x;
  25374. }
  25375. for (j = 0; j < numberOfPoints; j++) {
  25376. switch (points[j].flags & 0x24) {
  25377. case 0x00:
  25378. y += ((code[i] << 24) | (code[i + 1] << 16)) >> 16;
  25379. i += 2;
  25380. break;
  25381. case 0x04:
  25382. y -= code[i++];
  25383. break;
  25384. case 0x24:
  25385. y += code[i++];
  25386. break;
  25387. }
  25388. points[j].y = y;
  25389. }
  25390. var startPoint = 0;
  25391. for (i = 0; i < numberOfContours; i++) {
  25392. var endPoint = endPtsOfContours[i];
  25393. // contours might have implicit points, which is located in the middle
  25394. // between two neighboring off-curve points
  25395. var contour = points.slice(startPoint, endPoint + 1);
  25396. if ((contour[0].flags & 1)) {
  25397. contour.push(contour[0]); // using start point at the contour end
  25398. } else if ((contour[contour.length - 1].flags & 1)) {
  25399. // first is off-curve point, trying to use one from the end
  25400. contour.unshift(contour[contour.length - 1]);
  25401. } else {
  25402. // start and end are off-curve points, creating implicit one
  25403. var p = {
  25404. flags: 1,
  25405. x: (contour[0].x + contour[contour.length - 1].x) / 2,
  25406. y: (contour[0].y + contour[contour.length - 1].y) / 2
  25407. };
  25408. contour.unshift(p);
  25409. contour.push(p);
  25410. }
  25411. moveTo(contour[0].x, contour[0].y);
  25412. for (j = 1, jj = contour.length; j < jj; j++) {
  25413. if ((contour[j].flags & 1)) {
  25414. lineTo(contour[j].x, contour[j].y);
  25415. } else if ((contour[j + 1].flags & 1)){
  25416. quadraticCurveTo(contour[j].x, contour[j].y,
  25417. contour[j + 1].x, contour[j + 1].y);
  25418. j++;
  25419. } else {
  25420. quadraticCurveTo(contour[j].x, contour[j].y,
  25421. (contour[j].x + contour[j + 1].x) / 2,
  25422. (contour[j].y + contour[j + 1].y) / 2);
  25423. }
  25424. }
  25425. startPoint = endPoint + 1;
  25426. }
  25427. }
  25428. }
  25429. function compileCharString(code, cmds, font) {
  25430. var stack = [];
  25431. var x = 0, y = 0;
  25432. var stems = 0;
  25433. function moveTo(x, y) {
  25434. cmds.push({cmd: 'moveTo', args: [x, y]});
  25435. }
  25436. function lineTo(x, y) {
  25437. cmds.push({cmd: 'lineTo', args: [x, y]});
  25438. }
  25439. function bezierCurveTo(x1, y1, x2, y2, x, y) {
  25440. cmds.push({cmd: 'bezierCurveTo', args: [x1, y1, x2, y2, x, y]});
  25441. }
  25442. function parse(code) {
  25443. var i = 0;
  25444. while (i < code.length) {
  25445. var stackClean = false;
  25446. var v = code[i++];
  25447. var xa, xb, ya, yb, y1, y2, y3, n, subrCode;
  25448. switch (v) {
  25449. case 1: // hstem
  25450. stems += stack.length >> 1;
  25451. stackClean = true;
  25452. break;
  25453. case 3: // vstem
  25454. stems += stack.length >> 1;
  25455. stackClean = true;
  25456. break;
  25457. case 4: // vmoveto
  25458. y += stack.pop();
  25459. moveTo(x, y);
  25460. stackClean = true;
  25461. break;
  25462. case 5: // rlineto
  25463. while (stack.length > 0) {
  25464. x += stack.shift();
  25465. y += stack.shift();
  25466. lineTo(x, y);
  25467. }
  25468. break;
  25469. case 6: // hlineto
  25470. while (stack.length > 0) {
  25471. x += stack.shift();
  25472. lineTo(x, y);
  25473. if (stack.length === 0) {
  25474. break;
  25475. }
  25476. y += stack.shift();
  25477. lineTo(x, y);
  25478. }
  25479. break;
  25480. case 7: // vlineto
  25481. while (stack.length > 0) {
  25482. y += stack.shift();
  25483. lineTo(x, y);
  25484. if (stack.length === 0) {
  25485. break;
  25486. }
  25487. x += stack.shift();
  25488. lineTo(x, y);
  25489. }
  25490. break;
  25491. case 8: // rrcurveto
  25492. while (stack.length > 0) {
  25493. xa = x + stack.shift(); ya = y + stack.shift();
  25494. xb = xa + stack.shift(); yb = ya + stack.shift();
  25495. x = xb + stack.shift(); y = yb + stack.shift();
  25496. bezierCurveTo(xa, ya, xb, yb, x, y);
  25497. }
  25498. break;
  25499. case 10: // callsubr
  25500. n = stack.pop() + font.subrsBias;
  25501. subrCode = font.subrs[n];
  25502. if (subrCode) {
  25503. parse(subrCode);
  25504. }
  25505. break;
  25506. case 11: // return
  25507. return;
  25508. case 12:
  25509. v = code[i++];
  25510. switch (v) {
  25511. case 34: // flex
  25512. xa = x + stack.shift();
  25513. xb = xa + stack.shift(); y1 = y + stack.shift();
  25514. x = xb + stack.shift();
  25515. bezierCurveTo(xa, y, xb, y1, x, y1);
  25516. xa = x + stack.shift();
  25517. xb = xa + stack.shift();
  25518. x = xb + stack.shift();
  25519. bezierCurveTo(xa, y1, xb, y, x, y);
  25520. break;
  25521. case 35: // flex
  25522. xa = x + stack.shift(); ya = y + stack.shift();
  25523. xb = xa + stack.shift(); yb = ya + stack.shift();
  25524. x = xb + stack.shift(); y = yb + stack.shift();
  25525. bezierCurveTo(xa, ya, xb, yb, x, y);
  25526. xa = x + stack.shift(); ya = y + stack.shift();
  25527. xb = xa + stack.shift(); yb = ya + stack.shift();
  25528. x = xb + stack.shift(); y = yb + stack.shift();
  25529. bezierCurveTo(xa, ya, xb, yb, x, y);
  25530. stack.pop(); // fd
  25531. break;
  25532. case 36: // hflex1
  25533. xa = x + stack.shift(); y1 = y + stack.shift();
  25534. xb = xa + stack.shift(); y2 = y1 + stack.shift();
  25535. x = xb + stack.shift();
  25536. bezierCurveTo(xa, y1, xb, y2, x, y2);
  25537. xa = x + stack.shift();
  25538. xb = xa + stack.shift(); y3 = y2 + stack.shift();
  25539. x = xb + stack.shift();
  25540. bezierCurveTo(xa, y2, xb, y3, x, y);
  25541. break;
  25542. case 37: // flex1
  25543. var x0 = x, y0 = y;
  25544. xa = x + stack.shift(); ya = y + stack.shift();
  25545. xb = xa + stack.shift(); yb = ya + stack.shift();
  25546. x = xb + stack.shift(); y = yb + stack.shift();
  25547. bezierCurveTo(xa, ya, xb, yb, x, y);
  25548. xa = x + stack.shift(); ya = y + stack.shift();
  25549. xb = xa + stack.shift(); yb = ya + stack.shift();
  25550. x = xb; y = yb;
  25551. if (Math.abs(x - x0) > Math.abs(y - y0)) {
  25552. x += stack.shift();
  25553. } else {
  25554. y += stack.shift();
  25555. }
  25556. bezierCurveTo(xa, ya, xb, yb, x, y);
  25557. break;
  25558. default:
  25559. error('unknown operator: 12 ' + v);
  25560. }
  25561. break;
  25562. case 14: // endchar
  25563. if (stack.length >= 4) {
  25564. var achar = stack.pop();
  25565. var bchar = stack.pop();
  25566. y = stack.pop();
  25567. x = stack.pop();
  25568. cmds.push({cmd: 'save'});
  25569. cmds.push({cmd: 'translate', args: [x, y]});
  25570. var cmap = lookupCmap(font.cmap, String.fromCharCode(
  25571. font.glyphNameMap[StandardEncoding[achar]]));
  25572. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  25573. cmds.push({cmd: 'restore'});
  25574. cmap = lookupCmap(font.cmap, String.fromCharCode(
  25575. font.glyphNameMap[StandardEncoding[bchar]]));
  25576. compileCharString(font.glyphs[cmap.glyphId], cmds, font);
  25577. }
  25578. return;
  25579. case 18: // hstemhm
  25580. stems += stack.length >> 1;
  25581. stackClean = true;
  25582. break;
  25583. case 19: // hintmask
  25584. stems += stack.length >> 1;
  25585. i += (stems + 7) >> 3;
  25586. stackClean = true;
  25587. break;
  25588. case 20: // cntrmask
  25589. stems += stack.length >> 1;
  25590. i += (stems + 7) >> 3;
  25591. stackClean = true;
  25592. break;
  25593. case 21: // rmoveto
  25594. y += stack.pop();
  25595. x += stack.pop();
  25596. moveTo(x, y);
  25597. stackClean = true;
  25598. break;
  25599. case 22: // hmoveto
  25600. x += stack.pop();
  25601. moveTo(x, y);
  25602. stackClean = true;
  25603. break;
  25604. case 23: // vstemhm
  25605. stems += stack.length >> 1;
  25606. stackClean = true;
  25607. break;
  25608. case 24: // rcurveline
  25609. while (stack.length > 2) {
  25610. xa = x + stack.shift(); ya = y + stack.shift();
  25611. xb = xa + stack.shift(); yb = ya + stack.shift();
  25612. x = xb + stack.shift(); y = yb + stack.shift();
  25613. bezierCurveTo(xa, ya, xb, yb, x, y);
  25614. }
  25615. x += stack.shift();
  25616. y += stack.shift();
  25617. lineTo(x, y);
  25618. break;
  25619. case 25: // rlinecurve
  25620. while (stack.length > 6) {
  25621. x += stack.shift();
  25622. y += stack.shift();
  25623. lineTo(x, y);
  25624. }
  25625. xa = x + stack.shift(); ya = y + stack.shift();
  25626. xb = xa + stack.shift(); yb = ya + stack.shift();
  25627. x = xb + stack.shift(); y = yb + stack.shift();
  25628. bezierCurveTo(xa, ya, xb, yb, x, y);
  25629. break;
  25630. case 26: // vvcurveto
  25631. if (stack.length % 2) {
  25632. x += stack.shift();
  25633. }
  25634. while (stack.length > 0) {
  25635. xa = x; ya = y + stack.shift();
  25636. xb = xa + stack.shift(); yb = ya + stack.shift();
  25637. x = xb; y = yb + stack.shift();
  25638. bezierCurveTo(xa, ya, xb, yb, x, y);
  25639. }
  25640. break;
  25641. case 27: // hhcurveto
  25642. if (stack.length % 2) {
  25643. y += stack.shift();
  25644. }
  25645. while (stack.length > 0) {
  25646. xa = x + stack.shift(); ya = y;
  25647. xb = xa + stack.shift(); yb = ya + stack.shift();
  25648. x = xb + stack.shift(); y = yb;
  25649. bezierCurveTo(xa, ya, xb, yb, x, y);
  25650. }
  25651. break;
  25652. case 28:
  25653. stack.push(((code[i] << 24) | (code[i + 1] << 16)) >> 16);
  25654. i += 2;
  25655. break;
  25656. case 29: // callgsubr
  25657. n = stack.pop() + font.gsubrsBias;
  25658. subrCode = font.gsubrs[n];
  25659. if (subrCode) {
  25660. parse(subrCode);
  25661. }
  25662. break;
  25663. case 30: // vhcurveto
  25664. while (stack.length > 0) {
  25665. xa = x; ya = y + stack.shift();
  25666. xb = xa + stack.shift(); yb = ya + stack.shift();
  25667. x = xb + stack.shift();
  25668. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25669. bezierCurveTo(xa, ya, xb, yb, x, y);
  25670. if (stack.length === 0) {
  25671. break;
  25672. }
  25673. xa = x + stack.shift(); ya = y;
  25674. xb = xa + stack.shift(); yb = ya + stack.shift();
  25675. y = yb + stack.shift();
  25676. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25677. bezierCurveTo(xa, ya, xb, yb, x, y);
  25678. }
  25679. break;
  25680. case 31: // hvcurveto
  25681. while (stack.length > 0) {
  25682. xa = x + stack.shift(); ya = y;
  25683. xb = xa + stack.shift(); yb = ya + stack.shift();
  25684. y = yb + stack.shift();
  25685. x = xb + (stack.length === 1 ? stack.shift() : 0);
  25686. bezierCurveTo(xa, ya, xb, yb, x, y);
  25687. if (stack.length === 0) {
  25688. break;
  25689. }
  25690. xa = x; ya = y + stack.shift();
  25691. xb = xa + stack.shift(); yb = ya + stack.shift();
  25692. x = xb + stack.shift();
  25693. y = yb + (stack.length === 1 ? stack.shift() : 0);
  25694. bezierCurveTo(xa, ya, xb, yb, x, y);
  25695. }
  25696. break;
  25697. default:
  25698. if (v < 32) {
  25699. error('unknown operator: ' + v);
  25700. }
  25701. if (v < 247) {
  25702. stack.push(v - 139);
  25703. } else if (v < 251) {
  25704. stack.push((v - 247) * 256 + code[i++] + 108);
  25705. } else if (v < 255) {
  25706. stack.push(-(v - 251) * 256 - code[i++] - 108);
  25707. } else {
  25708. stack.push(((code[i] << 24) | (code[i + 1] << 16) |
  25709. (code[i + 2] << 8) | code[i + 3]) / 65536);
  25710. i += 4;
  25711. }
  25712. break;
  25713. }
  25714. if (stackClean) {
  25715. stack.length = 0;
  25716. }
  25717. }
  25718. }
  25719. parse(code);
  25720. }
  25721. var noop = '';
  25722. function CompiledFont(fontMatrix) {
  25723. this.compiledGlyphs = Object.create(null);
  25724. this.compiledCharCodeToGlyphId = Object.create(null);
  25725. this.fontMatrix = fontMatrix;
  25726. }
  25727. CompiledFont.prototype = {
  25728. getPathJs: function (unicode) {
  25729. var cmap = lookupCmap(this.cmap, unicode);
  25730. var fn = this.compiledGlyphs[cmap.glyphId];
  25731. if (!fn) {
  25732. fn = this.compileGlyph(this.glyphs[cmap.glyphId]);
  25733. this.compiledGlyphs[cmap.glyphId] = fn;
  25734. }
  25735. if (this.compiledCharCodeToGlyphId[cmap.charCode] === undefined) {
  25736. this.compiledCharCodeToGlyphId[cmap.charCode] = cmap.glyphId;
  25737. }
  25738. return fn;
  25739. },
  25740. compileGlyph: function (code) {
  25741. if (!code || code.length === 0 || code[0] === 14) {
  25742. return noop;
  25743. }
  25744. var cmds = [];
  25745. cmds.push({cmd: 'save'});
  25746. cmds.push({cmd: 'transform', args: this.fontMatrix.slice()});
  25747. cmds.push({cmd: 'scale', args: ['size', '-size']});
  25748. this.compileGlyphImpl(code, cmds);
  25749. cmds.push({cmd: 'restore'});
  25750. return cmds;
  25751. },
  25752. compileGlyphImpl: function () {
  25753. error('Children classes should implement this.');
  25754. },
  25755. hasBuiltPath: function (unicode) {
  25756. var cmap = lookupCmap(this.cmap, unicode);
  25757. return (this.compiledGlyphs[cmap.glyphId] !== undefined &&
  25758. this.compiledCharCodeToGlyphId[cmap.charCode] !== undefined);
  25759. }
  25760. };
  25761. function TrueTypeCompiled(glyphs, cmap, fontMatrix) {
  25762. fontMatrix = fontMatrix || [0.000488, 0, 0, 0.000488, 0, 0];
  25763. CompiledFont.call(this, fontMatrix);
  25764. this.glyphs = glyphs;
  25765. this.cmap = cmap;
  25766. }
  25767. Util.inherit(TrueTypeCompiled, CompiledFont, {
  25768. compileGlyphImpl: function (code, cmds) {
  25769. compileGlyf(code, cmds, this);
  25770. }
  25771. });
  25772. function Type2Compiled(cffInfo, cmap, fontMatrix, glyphNameMap) {
  25773. fontMatrix = fontMatrix || [0.001, 0, 0, 0.001, 0, 0];
  25774. CompiledFont.call(this, fontMatrix);
  25775. this.glyphs = cffInfo.glyphs;
  25776. this.gsubrs = cffInfo.gsubrs || [];
  25777. this.subrs = cffInfo.subrs || [];
  25778. this.cmap = cmap;
  25779. this.glyphNameMap = glyphNameMap || getGlyphsUnicode();
  25780. this.gsubrsBias = (this.gsubrs.length < 1240 ?
  25781. 107 : (this.gsubrs.length < 33900 ? 1131 : 32768));
  25782. this.subrsBias = (this.subrs.length < 1240 ?
  25783. 107 : (this.subrs.length < 33900 ? 1131 : 32768));
  25784. }
  25785. Util.inherit(Type2Compiled, CompiledFont, {
  25786. compileGlyphImpl: function (code, cmds) {
  25787. compileCharString(code, cmds, this);
  25788. }
  25789. });
  25790. return {
  25791. create: function FontRendererFactory_create(font, seacAnalysisEnabled) {
  25792. var data = new Uint8Array(font.data);
  25793. var cmap, glyf, loca, cff, indexToLocFormat, unitsPerEm;
  25794. var numTables = getUshort(data, 4);
  25795. for (var i = 0, p = 12; i < numTables; i++, p += 16) {
  25796. var tag = bytesToString(data.subarray(p, p + 4));
  25797. var offset = getLong(data, p + 8);
  25798. var length = getLong(data, p + 12);
  25799. switch (tag) {
  25800. case 'cmap':
  25801. cmap = parseCmap(data, offset, offset + length);
  25802. break;
  25803. case 'glyf':
  25804. glyf = data.subarray(offset, offset + length);
  25805. break;
  25806. case 'loca':
  25807. loca = data.subarray(offset, offset + length);
  25808. break;
  25809. case 'head':
  25810. unitsPerEm = getUshort(data, offset + 18);
  25811. indexToLocFormat = getUshort(data, offset + 50);
  25812. break;
  25813. case 'CFF ':
  25814. cff = parseCff(data, offset, offset + length, seacAnalysisEnabled);
  25815. break;
  25816. }
  25817. }
  25818. if (glyf) {
  25819. var fontMatrix = (!unitsPerEm ? font.fontMatrix :
  25820. [1 / unitsPerEm, 0, 0, 1 / unitsPerEm, 0, 0]);
  25821. return new TrueTypeCompiled(
  25822. parseGlyfTable(glyf, loca, indexToLocFormat), cmap, fontMatrix);
  25823. } else {
  25824. return new Type2Compiled(cff, cmap, font.fontMatrix, font.glyphNameMap);
  25825. }
  25826. }
  25827. };
  25828. })();
  25829. exports.FontRendererFactory = FontRendererFactory;
  25830. }));
  25831. (function (root, factory) {
  25832. {
  25833. factory((root.pdfjsCoreParser = {}), root.pdfjsSharedUtil,
  25834. root.pdfjsCorePrimitives, root.pdfjsCoreStream);
  25835. }
  25836. }(this, function (exports, sharedUtil, corePrimitives, coreStream) {
  25837. var MissingDataException = sharedUtil.MissingDataException;
  25838. var StreamType = sharedUtil.StreamType;
  25839. var assert = sharedUtil.assert;
  25840. var error = sharedUtil.error;
  25841. var info = sharedUtil.info;
  25842. var isArray = sharedUtil.isArray;
  25843. var isInt = sharedUtil.isInt;
  25844. var isNum = sharedUtil.isNum;
  25845. var isString = sharedUtil.isString;
  25846. var warn = sharedUtil.warn;
  25847. var Cmd = corePrimitives.Cmd;
  25848. var Dict = corePrimitives.Dict;
  25849. var Name = corePrimitives.Name;
  25850. var Ref = corePrimitives.Ref;
  25851. var isCmd = corePrimitives.isCmd;
  25852. var isDict = corePrimitives.isDict;
  25853. var isName = corePrimitives.isName;
  25854. var Ascii85Stream = coreStream.Ascii85Stream;
  25855. var AsciiHexStream = coreStream.AsciiHexStream;
  25856. var CCITTFaxStream = coreStream.CCITTFaxStream;
  25857. var FlateStream = coreStream.FlateStream;
  25858. var Jbig2Stream = coreStream.Jbig2Stream;
  25859. var JpegStream = coreStream.JpegStream;
  25860. var JpxStream = coreStream.JpxStream;
  25861. var LZWStream = coreStream.LZWStream;
  25862. var NullStream = coreStream.NullStream;
  25863. var PredictorStream = coreStream.PredictorStream;
  25864. var RunLengthStream = coreStream.RunLengthStream;
  25865. var EOF = {};
  25866. function isEOF(v) {
  25867. return (v === EOF);
  25868. }
  25869. var MAX_LENGTH_TO_CACHE = 1000;
  25870. var Parser = (function ParserClosure() {
  25871. function Parser(lexer, allowStreams, xref) {
  25872. this.lexer = lexer;
  25873. this.allowStreams = allowStreams;
  25874. this.xref = xref;
  25875. this.imageCache = Object.create(null);
  25876. this.refill();
  25877. }
  25878. Parser.prototype = {
  25879. refill: function Parser_refill() {
  25880. this.buf1 = this.lexer.getObj();
  25881. this.buf2 = this.lexer.getObj();
  25882. },
  25883. shift: function Parser_shift() {
  25884. if (isCmd(this.buf2, 'ID')) {
  25885. this.buf1 = this.buf2;
  25886. this.buf2 = null;
  25887. } else {
  25888. this.buf1 = this.buf2;
  25889. this.buf2 = this.lexer.getObj();
  25890. }
  25891. },
  25892. tryShift: function Parser_tryShift() {
  25893. try {
  25894. this.shift();
  25895. return true;
  25896. } catch (e) {
  25897. if (e instanceof MissingDataException) {
  25898. throw e;
  25899. }
  25900. // Upon failure, the caller should reset this.lexer.pos to a known good
  25901. // state and call this.shift() twice to reset the buffers.
  25902. return false;
  25903. }
  25904. },
  25905. getObj: function Parser_getObj(cipherTransform) {
  25906. var buf1 = this.buf1;
  25907. this.shift();
  25908. if (buf1 instanceof Cmd) {
  25909. switch (buf1.cmd) {
  25910. case 'BI': // inline image
  25911. return this.makeInlineImage(cipherTransform);
  25912. case '[': // array
  25913. var array = [];
  25914. while (!isCmd(this.buf1, ']') && !isEOF(this.buf1)) {
  25915. array.push(this.getObj(cipherTransform));
  25916. }
  25917. if (isEOF(this.buf1)) {
  25918. error('End of file inside array');
  25919. }
  25920. this.shift();
  25921. return array;
  25922. case '<<': // dictionary or stream
  25923. var dict = new Dict(this.xref);
  25924. while (!isCmd(this.buf1, '>>') && !isEOF(this.buf1)) {
  25925. if (!isName(this.buf1)) {
  25926. info('Malformed dictionary: key must be a name object');
  25927. this.shift();
  25928. continue;
  25929. }
  25930. var key = this.buf1.name;
  25931. this.shift();
  25932. if (isEOF(this.buf1)) {
  25933. break;
  25934. }
  25935. dict.set(key, this.getObj(cipherTransform));
  25936. }
  25937. if (isEOF(this.buf1)) {
  25938. error('End of file inside dictionary');
  25939. }
  25940. // Stream objects are not allowed inside content streams or
  25941. // object streams.
  25942. if (isCmd(this.buf2, 'stream')) {
  25943. return (this.allowStreams ?
  25944. this.makeStream(dict, cipherTransform) : dict);
  25945. }
  25946. this.shift();
  25947. return dict;
  25948. default: // simple object
  25949. return buf1;
  25950. }
  25951. }
  25952. if (isInt(buf1)) { // indirect reference or integer
  25953. var num = buf1;
  25954. if (isInt(this.buf1) && isCmd(this.buf2, 'R')) {
  25955. var ref = new Ref(num, this.buf1);
  25956. this.shift();
  25957. this.shift();
  25958. return ref;
  25959. }
  25960. return num;
  25961. }
  25962. if (isString(buf1)) { // string
  25963. var str = buf1;
  25964. if (cipherTransform) {
  25965. str = cipherTransform.decryptString(str);
  25966. }
  25967. return str;
  25968. }
  25969. // simple object
  25970. return buf1;
  25971. },
  25972. /**
  25973. * Find the end of the stream by searching for the /EI\s/.
  25974. * @returns {number} The inline stream length.
  25975. */
  25976. findDefaultInlineStreamEnd:
  25977. function Parser_findDefaultInlineStreamEnd(stream) {
  25978. var E = 0x45, I = 0x49, SPACE = 0x20, LF = 0xA, CR = 0xD;
  25979. var startPos = stream.pos, state = 0, ch, i, n, followingBytes;
  25980. while ((ch = stream.getByte()) !== -1) {
  25981. if (state === 0) {
  25982. state = (ch === E) ? 1 : 0;
  25983. } else if (state === 1) {
  25984. state = (ch === I) ? 2 : 0;
  25985. } else {
  25986. assert(state === 2);
  25987. if (ch === SPACE || ch === LF || ch === CR) {
  25988. // Let's check the next five bytes are ASCII... just be sure.
  25989. n = 5;
  25990. followingBytes = stream.peekBytes(n);
  25991. for (i = 0; i < n; i++) {
  25992. ch = followingBytes[i];
  25993. if (ch !== LF && ch !== CR && (ch < SPACE || ch > 0x7F)) {
  25994. // Not a LF, CR, SPACE or any visible ASCII character, i.e.
  25995. // it's binary stuff. Resetting the state.
  25996. state = 0;
  25997. break;
  25998. }
  25999. }
  26000. if (state === 2) {
  26001. break; // Finished!
  26002. }
  26003. } else {
  26004. state = 0;
  26005. }
  26006. }
  26007. }
  26008. return ((stream.pos - 4) - startPos);
  26009. },
  26010. /**
  26011. * Find the EOI (end-of-image) marker 0xFFD9 of the stream.
  26012. * @returns {number} The inline stream length.
  26013. */
  26014. findDCTDecodeInlineStreamEnd:
  26015. function Parser_findDCTDecodeInlineStreamEnd(stream) {
  26016. var startPos = stream.pos, foundEOI = false, b, markerLength, length;
  26017. while ((b = stream.getByte()) !== -1) {
  26018. if (b !== 0xFF) { // Not a valid marker.
  26019. continue;
  26020. }
  26021. switch (stream.getByte()) {
  26022. case 0x00: // Byte stuffing.
  26023. // 0xFF00 appears to be a very common byte sequence in JPEG images.
  26024. break;
  26025. case 0xFF: // Fill byte.
  26026. // Avoid skipping a valid marker, resetting the stream position.
  26027. stream.skip(-1);
  26028. break;
  26029. case 0xD9: // EOI
  26030. foundEOI = true;
  26031. break;
  26032. case 0xC0: // SOF0
  26033. case 0xC1: // SOF1
  26034. case 0xC2: // SOF2
  26035. case 0xC3: // SOF3
  26036. case 0xC5: // SOF5
  26037. case 0xC6: // SOF6
  26038. case 0xC7: // SOF7
  26039. case 0xC9: // SOF9
  26040. case 0xCA: // SOF10
  26041. case 0xCB: // SOF11
  26042. case 0xCD: // SOF13
  26043. case 0xCE: // SOF14
  26044. case 0xCF: // SOF15
  26045. case 0xC4: // DHT
  26046. case 0xCC: // DAC
  26047. case 0xDA: // SOS
  26048. case 0xDB: // DQT
  26049. case 0xDC: // DNL
  26050. case 0xDD: // DRI
  26051. case 0xDE: // DHP
  26052. case 0xDF: // EXP
  26053. case 0xE0: // APP0
  26054. case 0xE1: // APP1
  26055. case 0xE2: // APP2
  26056. case 0xE3: // APP3
  26057. case 0xE4: // APP4
  26058. case 0xE5: // APP5
  26059. case 0xE6: // APP6
  26060. case 0xE7: // APP7
  26061. case 0xE8: // APP8
  26062. case 0xE9: // APP9
  26063. case 0xEA: // APP10
  26064. case 0xEB: // APP11
  26065. case 0xEC: // APP12
  26066. case 0xED: // APP13
  26067. case 0xEE: // APP14
  26068. case 0xEF: // APP15
  26069. case 0xFE: // COM
  26070. // The marker should be followed by the length of the segment.
  26071. markerLength = stream.getUint16();
  26072. if (markerLength > 2) {
  26073. // |markerLength| contains the byte length of the marker segment,
  26074. // including its own length (2 bytes) and excluding the marker.
  26075. stream.skip(markerLength - 2); // Jump to the next marker.
  26076. } else {
  26077. // The marker length is invalid, resetting the stream position.
  26078. stream.skip(-2);
  26079. }
  26080. break;
  26081. }
  26082. if (foundEOI) {
  26083. break;
  26084. }
  26085. }
  26086. length = stream.pos - startPos;
  26087. if (b === -1) {
  26088. warn('Inline DCTDecode image stream: ' +
  26089. 'EOI marker not found, searching for /EI/ instead.');
  26090. stream.skip(-length); // Reset the stream position.
  26091. return this.findDefaultInlineStreamEnd(stream);
  26092. }
  26093. this.inlineStreamSkipEI(stream);
  26094. return length;
  26095. },
  26096. /**
  26097. * Find the EOD (end-of-data) marker '~>' (i.e. TILDE + GT) of the stream.
  26098. * @returns {number} The inline stream length.
  26099. */
  26100. findASCII85DecodeInlineStreamEnd:
  26101. function Parser_findASCII85DecodeInlineStreamEnd(stream) {
  26102. var TILDE = 0x7E, GT = 0x3E;
  26103. var startPos = stream.pos, ch, length;
  26104. while ((ch = stream.getByte()) !== -1) {
  26105. if (ch === TILDE && stream.peekByte() === GT) {
  26106. stream.skip();
  26107. break;
  26108. }
  26109. }
  26110. length = stream.pos - startPos;
  26111. if (ch === -1) {
  26112. warn('Inline ASCII85Decode image stream: ' +
  26113. 'EOD marker not found, searching for /EI/ instead.');
  26114. stream.skip(-length); // Reset the stream position.
  26115. return this.findDefaultInlineStreamEnd(stream);
  26116. }
  26117. this.inlineStreamSkipEI(stream);
  26118. return length;
  26119. },
  26120. /**
  26121. * Find the EOD (end-of-data) marker '>' (i.e. GT) of the stream.
  26122. * @returns {number} The inline stream length.
  26123. */
  26124. findASCIIHexDecodeInlineStreamEnd:
  26125. function Parser_findASCIIHexDecodeInlineStreamEnd(stream) {
  26126. var GT = 0x3E;
  26127. var startPos = stream.pos, ch, length;
  26128. while ((ch = stream.getByte()) !== -1) {
  26129. if (ch === GT) {
  26130. break;
  26131. }
  26132. }
  26133. length = stream.pos - startPos;
  26134. if (ch === -1) {
  26135. warn('Inline ASCIIHexDecode image stream: ' +
  26136. 'EOD marker not found, searching for /EI/ instead.');
  26137. stream.skip(-length); // Reset the stream position.
  26138. return this.findDefaultInlineStreamEnd(stream);
  26139. }
  26140. this.inlineStreamSkipEI(stream);
  26141. return length;
  26142. },
  26143. /**
  26144. * Skip over the /EI/ for streams where we search for an EOD marker.
  26145. */
  26146. inlineStreamSkipEI: function Parser_inlineStreamSkipEI(stream) {
  26147. var E = 0x45, I = 0x49;
  26148. var state = 0, ch;
  26149. while ((ch = stream.getByte()) !== -1) {
  26150. if (state === 0) {
  26151. state = (ch === E) ? 1 : 0;
  26152. } else if (state === 1) {
  26153. state = (ch === I) ? 2 : 0;
  26154. } else if (state === 2) {
  26155. break;
  26156. }
  26157. }
  26158. },
  26159. makeInlineImage: function Parser_makeInlineImage(cipherTransform) {
  26160. var lexer = this.lexer;
  26161. var stream = lexer.stream;
  26162. // Parse dictionary.
  26163. var dict = new Dict(this.xref);
  26164. while (!isCmd(this.buf1, 'ID') && !isEOF(this.buf1)) {
  26165. if (!isName(this.buf1)) {
  26166. error('Dictionary key must be a name object');
  26167. }
  26168. var key = this.buf1.name;
  26169. this.shift();
  26170. if (isEOF(this.buf1)) {
  26171. break;
  26172. }
  26173. dict.set(key, this.getObj(cipherTransform));
  26174. }
  26175. // Extract the name of the first (i.e. the current) image filter.
  26176. var filter = dict.get('Filter', 'F'), filterName;
  26177. if (isName(filter)) {
  26178. filterName = filter.name;
  26179. } else if (isArray(filter) && isName(filter[0])) {
  26180. filterName = filter[0].name;
  26181. }
  26182. // Parse image stream.
  26183. var startPos = stream.pos, length, i, ii;
  26184. if (filterName === 'DCTDecode' || filterName === 'DCT') {
  26185. length = this.findDCTDecodeInlineStreamEnd(stream);
  26186. } else if (filterName === 'ASCII85Decide' || filterName === 'A85') {
  26187. length = this.findASCII85DecodeInlineStreamEnd(stream);
  26188. } else if (filterName === 'ASCIIHexDecode' || filterName === 'AHx') {
  26189. length = this.findASCIIHexDecodeInlineStreamEnd(stream);
  26190. } else {
  26191. length = this.findDefaultInlineStreamEnd(stream);
  26192. }
  26193. var imageStream = stream.makeSubStream(startPos, length, dict);
  26194. // Cache all images below the MAX_LENGTH_TO_CACHE threshold by their
  26195. // adler32 checksum.
  26196. var adler32;
  26197. if (length < MAX_LENGTH_TO_CACHE) {
  26198. var imageBytes = imageStream.getBytes();
  26199. imageStream.reset();
  26200. var a = 1;
  26201. var b = 0;
  26202. for (i = 0, ii = imageBytes.length; i < ii; ++i) {
  26203. // No modulo required in the loop if imageBytes.length < 5552.
  26204. a += imageBytes[i] & 0xff;
  26205. b += a;
  26206. }
  26207. adler32 = ((b % 65521) << 16) | (a % 65521);
  26208. if (this.imageCache.adler32 === adler32) {
  26209. this.buf2 = Cmd.get('EI');
  26210. this.shift();
  26211. this.imageCache[adler32].reset();
  26212. return this.imageCache[adler32];
  26213. }
  26214. }
  26215. if (cipherTransform) {
  26216. imageStream = cipherTransform.createStream(imageStream, length);
  26217. }
  26218. imageStream = this.filter(imageStream, dict, length);
  26219. imageStream.dict = dict;
  26220. if (adler32 !== undefined) {
  26221. imageStream.cacheKey = 'inline_' + length + '_' + adler32;
  26222. this.imageCache[adler32] = imageStream;
  26223. }
  26224. this.buf2 = Cmd.get('EI');
  26225. this.shift();
  26226. return imageStream;
  26227. },
  26228. makeStream: function Parser_makeStream(dict, cipherTransform) {
  26229. var lexer = this.lexer;
  26230. var stream = lexer.stream;
  26231. // get stream start position
  26232. lexer.skipToNextLine();
  26233. var pos = stream.pos - 1;
  26234. // get length
  26235. var length = dict.get('Length');
  26236. if (!isInt(length)) {
  26237. info('Bad ' + length + ' attribute in stream');
  26238. length = 0;
  26239. }
  26240. // skip over the stream data
  26241. stream.pos = pos + length;
  26242. lexer.nextChar();
  26243. // Shift '>>' and check whether the new object marks the end of the stream
  26244. if (this.tryShift() && isCmd(this.buf2, 'endstream')) {
  26245. this.shift(); // 'stream'
  26246. } else {
  26247. // bad stream length, scanning for endstream
  26248. stream.pos = pos;
  26249. var SCAN_BLOCK_SIZE = 2048;
  26250. var ENDSTREAM_SIGNATURE_LENGTH = 9;
  26251. var ENDSTREAM_SIGNATURE = [0x65, 0x6E, 0x64, 0x73, 0x74, 0x72, 0x65,
  26252. 0x61, 0x6D];
  26253. var skipped = 0, found = false, i, j;
  26254. while (stream.pos < stream.end) {
  26255. var scanBytes = stream.peekBytes(SCAN_BLOCK_SIZE);
  26256. var scanLength = scanBytes.length - ENDSTREAM_SIGNATURE_LENGTH;
  26257. if (scanLength <= 0) {
  26258. break;
  26259. }
  26260. found = false;
  26261. i = 0;
  26262. while (i < scanLength) {
  26263. j = 0;
  26264. while (j < ENDSTREAM_SIGNATURE_LENGTH &&
  26265. scanBytes[i + j] === ENDSTREAM_SIGNATURE[j]) {
  26266. j++;
  26267. }
  26268. if (j >= ENDSTREAM_SIGNATURE_LENGTH) {
  26269. found = true;
  26270. break;
  26271. }
  26272. i++;
  26273. }
  26274. if (found) {
  26275. skipped += i;
  26276. stream.pos += i;
  26277. break;
  26278. }
  26279. skipped += scanLength;
  26280. stream.pos += scanLength;
  26281. }
  26282. if (!found) {
  26283. error('Missing endstream');
  26284. }
  26285. length = skipped;
  26286. lexer.nextChar();
  26287. this.shift();
  26288. this.shift();
  26289. }
  26290. this.shift(); // 'endstream'
  26291. stream = stream.makeSubStream(pos, length, dict);
  26292. if (cipherTransform) {
  26293. stream = cipherTransform.createStream(stream, length);
  26294. }
  26295. stream = this.filter(stream, dict, length);
  26296. stream.dict = dict;
  26297. return stream;
  26298. },
  26299. filter: function Parser_filter(stream, dict, length) {
  26300. var filter = dict.get('Filter', 'F');
  26301. var params = dict.get('DecodeParms', 'DP');
  26302. if (isName(filter)) {
  26303. return this.makeFilter(stream, filter.name, length, params);
  26304. }
  26305. var maybeLength = length;
  26306. if (isArray(filter)) {
  26307. var filterArray = filter;
  26308. var paramsArray = params;
  26309. for (var i = 0, ii = filterArray.length; i < ii; ++i) {
  26310. filter = filterArray[i];
  26311. if (!isName(filter)) {
  26312. error('Bad filter name: ' + filter);
  26313. }
  26314. params = null;
  26315. if (isArray(paramsArray) && (i in paramsArray)) {
  26316. params = paramsArray[i];
  26317. }
  26318. stream = this.makeFilter(stream, filter.name, maybeLength, params);
  26319. // after the first stream the length variable is invalid
  26320. maybeLength = null;
  26321. }
  26322. }
  26323. return stream;
  26324. },
  26325. makeFilter: function Parser_makeFilter(stream, name, maybeLength, params) {
  26326. if (stream.dict.get('Length') === 0 && !maybeLength) {
  26327. warn('Empty "' + name + '" stream.');
  26328. return new NullStream(stream);
  26329. }
  26330. try {
  26331. if (params && this.xref) {
  26332. params = this.xref.fetchIfRef(params);
  26333. }
  26334. var xrefStreamStats = this.xref.stats.streamTypes;
  26335. if (name === 'FlateDecode' || name === 'Fl') {
  26336. xrefStreamStats[StreamType.FLATE] = true;
  26337. if (params) {
  26338. return new PredictorStream(new FlateStream(stream, maybeLength),
  26339. maybeLength, params);
  26340. }
  26341. return new FlateStream(stream, maybeLength);
  26342. }
  26343. if (name === 'LZWDecode' || name === 'LZW') {
  26344. xrefStreamStats[StreamType.LZW] = true;
  26345. var earlyChange = 1;
  26346. if (params) {
  26347. if (params.has('EarlyChange')) {
  26348. earlyChange = params.get('EarlyChange');
  26349. }
  26350. return new PredictorStream(
  26351. new LZWStream(stream, maybeLength, earlyChange),
  26352. maybeLength, params);
  26353. }
  26354. return new LZWStream(stream, maybeLength, earlyChange);
  26355. }
  26356. if (name === 'DCTDecode' || name === 'DCT') {
  26357. xrefStreamStats[StreamType.DCT] = true;
  26358. return new JpegStream(stream, maybeLength, stream.dict, this.xref);
  26359. }
  26360. if (name === 'JPXDecode' || name === 'JPX') {
  26361. xrefStreamStats[StreamType.JPX] = true;
  26362. return new JpxStream(stream, maybeLength, stream.dict);
  26363. }
  26364. if (name === 'ASCII85Decode' || name === 'A85') {
  26365. xrefStreamStats[StreamType.A85] = true;
  26366. return new Ascii85Stream(stream, maybeLength);
  26367. }
  26368. if (name === 'ASCIIHexDecode' || name === 'AHx') {
  26369. xrefStreamStats[StreamType.AHX] = true;
  26370. return new AsciiHexStream(stream, maybeLength);
  26371. }
  26372. if (name === 'CCITTFaxDecode' || name === 'CCF') {
  26373. xrefStreamStats[StreamType.CCF] = true;
  26374. return new CCITTFaxStream(stream, maybeLength, params);
  26375. }
  26376. if (name === 'RunLengthDecode' || name === 'RL') {
  26377. xrefStreamStats[StreamType.RL] = true;
  26378. return new RunLengthStream(stream, maybeLength);
  26379. }
  26380. if (name === 'JBIG2Decode') {
  26381. xrefStreamStats[StreamType.JBIG] = true;
  26382. return new Jbig2Stream(stream, maybeLength, stream.dict);
  26383. }
  26384. warn('filter "' + name + '" not supported yet');
  26385. return stream;
  26386. } catch (ex) {
  26387. if (ex instanceof MissingDataException) {
  26388. throw ex;
  26389. }
  26390. warn('Invalid stream: \"' + ex + '\"');
  26391. return new NullStream(stream);
  26392. }
  26393. }
  26394. };
  26395. return Parser;
  26396. })();
  26397. var Lexer = (function LexerClosure() {
  26398. function Lexer(stream, knownCommands) {
  26399. this.stream = stream;
  26400. this.nextChar();
  26401. // While lexing, we build up many strings one char at a time. Using += for
  26402. // this can result in lots of garbage strings. It's better to build an
  26403. // array of single-char strings and then join() them together at the end.
  26404. // And reusing a single array (i.e. |this.strBuf|) over and over for this
  26405. // purpose uses less memory than using a new array for each string.
  26406. this.strBuf = [];
  26407. // The PDFs might have "glued" commands with other commands, operands or
  26408. // literals, e.g. "q1". The knownCommands is a dictionary of the valid
  26409. // commands and their prefixes. The prefixes are built the following way:
  26410. // if there a command that is a prefix of the other valid command or
  26411. // literal (e.g. 'f' and 'false') the following prefixes must be included,
  26412. // 'fa', 'fal', 'fals'. The prefixes are not needed, if the command has no
  26413. // other commands or literals as a prefix. The knowCommands is optional.
  26414. this.knownCommands = knownCommands;
  26415. }
  26416. Lexer.isSpace = function Lexer_isSpace(ch) {
  26417. // Space is one of the following characters: SPACE, TAB, CR or LF.
  26418. return (ch === 0x20 || ch === 0x09 || ch === 0x0D || ch === 0x0A);
  26419. };
  26420. // A '1' in this array means the character is white space. A '1' or
  26421. // '2' means the character ends a name or command.
  26422. var specialChars = [
  26423. 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, // 0x
  26424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 1x
  26425. 1, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, // 2x
  26426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, // 3x
  26427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 4x
  26428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 5x
  26429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 6x
  26430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, // 7x
  26431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 8x
  26432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 9x
  26433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ax
  26434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // bx
  26435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // cx
  26436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // dx
  26437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // ex
  26438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // fx
  26439. ];
  26440. function toHexDigit(ch) {
  26441. if (ch >= 0x30 && ch <= 0x39) { // '0'-'9'
  26442. return ch & 0x0F;
  26443. }
  26444. if ((ch >= 0x41 && ch <= 0x46) || (ch >= 0x61 && ch <= 0x66)) {
  26445. // 'A'-'F', 'a'-'f'
  26446. return (ch & 0x0F) + 9;
  26447. }
  26448. return -1;
  26449. }
  26450. Lexer.prototype = {
  26451. nextChar: function Lexer_nextChar() {
  26452. return (this.currentChar = this.stream.getByte());
  26453. },
  26454. peekChar: function Lexer_peekChar() {
  26455. return this.stream.peekByte();
  26456. },
  26457. getNumber: function Lexer_getNumber() {
  26458. var ch = this.currentChar;
  26459. var eNotation = false;
  26460. var divideBy = 0; // different from 0 if it's a floating point value
  26461. var sign = 1;
  26462. if (ch === 0x2D) { // '-'
  26463. sign = -1;
  26464. ch = this.nextChar();
  26465. if (ch === 0x2D) { // '-'
  26466. // Ignore double negative (this is consistent with Adobe Reader).
  26467. ch = this.nextChar();
  26468. }
  26469. } else if (ch === 0x2B) { // '+'
  26470. ch = this.nextChar();
  26471. }
  26472. if (ch === 0x2E) { // '.'
  26473. divideBy = 10;
  26474. ch = this.nextChar();
  26475. }
  26476. if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26477. error('Invalid number: ' + String.fromCharCode(ch));
  26478. return 0;
  26479. }
  26480. var baseValue = ch - 0x30; // '0'
  26481. var powerValue = 0;
  26482. var powerValueSign = 1;
  26483. while ((ch = this.nextChar()) >= 0) {
  26484. if (0x30 <= ch && ch <= 0x39) { // '0' - '9'
  26485. var currentDigit = ch - 0x30; // '0'
  26486. if (eNotation) { // We are after an 'e' or 'E'
  26487. powerValue = powerValue * 10 + currentDigit;
  26488. } else {
  26489. if (divideBy !== 0) { // We are after a point
  26490. divideBy *= 10;
  26491. }
  26492. baseValue = baseValue * 10 + currentDigit;
  26493. }
  26494. } else if (ch === 0x2E) { // '.'
  26495. if (divideBy === 0) {
  26496. divideBy = 1;
  26497. } else {
  26498. // A number can have only one '.'
  26499. break;
  26500. }
  26501. } else if (ch === 0x2D) { // '-'
  26502. // ignore minus signs in the middle of numbers to match
  26503. // Adobe's behavior
  26504. warn('Badly formated number');
  26505. } else if (ch === 0x45 || ch === 0x65) { // 'E', 'e'
  26506. // 'E' can be either a scientific notation or the beginning of a new
  26507. // operator
  26508. ch = this.peekChar();
  26509. if (ch === 0x2B || ch === 0x2D) { // '+', '-'
  26510. powerValueSign = (ch === 0x2D) ? -1 : 1;
  26511. this.nextChar(); // Consume the sign character
  26512. } else if (ch < 0x30 || ch > 0x39) { // '0' - '9'
  26513. // The 'E' must be the beginning of a new operator
  26514. break;
  26515. }
  26516. eNotation = true;
  26517. } else {
  26518. // the last character doesn't belong to us
  26519. break;
  26520. }
  26521. }
  26522. if (divideBy !== 0) {
  26523. baseValue /= divideBy;
  26524. }
  26525. if (eNotation) {
  26526. baseValue *= Math.pow(10, powerValueSign * powerValue);
  26527. }
  26528. return sign * baseValue;
  26529. },
  26530. getString: function Lexer_getString() {
  26531. var numParen = 1;
  26532. var done = false;
  26533. var strBuf = this.strBuf;
  26534. strBuf.length = 0;
  26535. var ch = this.nextChar();
  26536. while (true) {
  26537. var charBuffered = false;
  26538. switch (ch | 0) {
  26539. case -1:
  26540. warn('Unterminated string');
  26541. done = true;
  26542. break;
  26543. case 0x28: // '('
  26544. ++numParen;
  26545. strBuf.push('(');
  26546. break;
  26547. case 0x29: // ')'
  26548. if (--numParen === 0) {
  26549. this.nextChar(); // consume strings ')'
  26550. done = true;
  26551. } else {
  26552. strBuf.push(')');
  26553. }
  26554. break;
  26555. case 0x5C: // '\\'
  26556. ch = this.nextChar();
  26557. switch (ch) {
  26558. case -1:
  26559. warn('Unterminated string');
  26560. done = true;
  26561. break;
  26562. case 0x6E: // 'n'
  26563. strBuf.push('\n');
  26564. break;
  26565. case 0x72: // 'r'
  26566. strBuf.push('\r');
  26567. break;
  26568. case 0x74: // 't'
  26569. strBuf.push('\t');
  26570. break;
  26571. case 0x62: // 'b'
  26572. strBuf.push('\b');
  26573. break;
  26574. case 0x66: // 'f'
  26575. strBuf.push('\f');
  26576. break;
  26577. case 0x5C: // '\'
  26578. case 0x28: // '('
  26579. case 0x29: // ')'
  26580. strBuf.push(String.fromCharCode(ch));
  26581. break;
  26582. case 0x30: case 0x31: case 0x32: case 0x33: // '0'-'3'
  26583. case 0x34: case 0x35: case 0x36: case 0x37: // '4'-'7'
  26584. var x = ch & 0x0F;
  26585. ch = this.nextChar();
  26586. charBuffered = true;
  26587. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26588. x = (x << 3) + (ch & 0x0F);
  26589. ch = this.nextChar();
  26590. if (ch >= 0x30 && ch <= 0x37) { // '0'-'7'
  26591. charBuffered = false;
  26592. x = (x << 3) + (ch & 0x0F);
  26593. }
  26594. }
  26595. strBuf.push(String.fromCharCode(x));
  26596. break;
  26597. case 0x0D: // CR
  26598. if (this.peekChar() === 0x0A) { // LF
  26599. this.nextChar();
  26600. }
  26601. break;
  26602. case 0x0A: // LF
  26603. break;
  26604. default:
  26605. strBuf.push(String.fromCharCode(ch));
  26606. break;
  26607. }
  26608. break;
  26609. default:
  26610. strBuf.push(String.fromCharCode(ch));
  26611. break;
  26612. }
  26613. if (done) {
  26614. break;
  26615. }
  26616. if (!charBuffered) {
  26617. ch = this.nextChar();
  26618. }
  26619. }
  26620. return strBuf.join('');
  26621. },
  26622. getName: function Lexer_getName() {
  26623. var ch, previousCh;
  26624. var strBuf = this.strBuf;
  26625. strBuf.length = 0;
  26626. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26627. if (ch === 0x23) { // '#'
  26628. ch = this.nextChar();
  26629. if (specialChars[ch]) {
  26630. warn('Lexer_getName: ' +
  26631. 'NUMBER SIGN (#) should be followed by a hexadecimal number.');
  26632. strBuf.push('#');
  26633. break;
  26634. }
  26635. var x = toHexDigit(ch);
  26636. if (x !== -1) {
  26637. previousCh = ch;
  26638. ch = this.nextChar();
  26639. var x2 = toHexDigit(ch);
  26640. if (x2 === -1) {
  26641. warn('Lexer_getName: Illegal digit (' +
  26642. String.fromCharCode(ch) +') in hexadecimal number.');
  26643. strBuf.push('#', String.fromCharCode(previousCh));
  26644. if (specialChars[ch]) {
  26645. break;
  26646. }
  26647. strBuf.push(String.fromCharCode(ch));
  26648. continue;
  26649. }
  26650. strBuf.push(String.fromCharCode((x << 4) | x2));
  26651. } else {
  26652. strBuf.push('#', String.fromCharCode(ch));
  26653. }
  26654. } else {
  26655. strBuf.push(String.fromCharCode(ch));
  26656. }
  26657. }
  26658. if (strBuf.length > 127) {
  26659. warn('name token is longer than allowed by the spec: ' + strBuf.length);
  26660. }
  26661. return Name.get(strBuf.join(''));
  26662. },
  26663. getHexString: function Lexer_getHexString() {
  26664. var strBuf = this.strBuf;
  26665. strBuf.length = 0;
  26666. var ch = this.currentChar;
  26667. var isFirstHex = true;
  26668. var firstDigit;
  26669. var secondDigit;
  26670. while (true) {
  26671. if (ch < 0) {
  26672. warn('Unterminated hex string');
  26673. break;
  26674. } else if (ch === 0x3E) { // '>'
  26675. this.nextChar();
  26676. break;
  26677. } else if (specialChars[ch] === 1) {
  26678. ch = this.nextChar();
  26679. continue;
  26680. } else {
  26681. if (isFirstHex) {
  26682. firstDigit = toHexDigit(ch);
  26683. if (firstDigit === -1) {
  26684. warn('Ignoring invalid character "' + ch + '" in hex string');
  26685. ch = this.nextChar();
  26686. continue;
  26687. }
  26688. } else {
  26689. secondDigit = toHexDigit(ch);
  26690. if (secondDigit === -1) {
  26691. warn('Ignoring invalid character "' + ch + '" in hex string');
  26692. ch = this.nextChar();
  26693. continue;
  26694. }
  26695. strBuf.push(String.fromCharCode((firstDigit << 4) | secondDigit));
  26696. }
  26697. isFirstHex = !isFirstHex;
  26698. ch = this.nextChar();
  26699. }
  26700. }
  26701. return strBuf.join('');
  26702. },
  26703. getObj: function Lexer_getObj() {
  26704. // skip whitespace and comments
  26705. var comment = false;
  26706. var ch = this.currentChar;
  26707. while (true) {
  26708. if (ch < 0) {
  26709. return EOF;
  26710. }
  26711. if (comment) {
  26712. if (ch === 0x0A || ch === 0x0D) { // LF, CR
  26713. comment = false;
  26714. }
  26715. } else if (ch === 0x25) { // '%'
  26716. comment = true;
  26717. } else if (specialChars[ch] !== 1) {
  26718. break;
  26719. }
  26720. ch = this.nextChar();
  26721. }
  26722. // start reading token
  26723. switch (ch | 0) {
  26724. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  26725. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  26726. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  26727. return this.getNumber();
  26728. case 0x28: // '('
  26729. return this.getString();
  26730. case 0x2F: // '/'
  26731. return this.getName();
  26732. // array punctuation
  26733. case 0x5B: // '['
  26734. this.nextChar();
  26735. return Cmd.get('[');
  26736. case 0x5D: // ']'
  26737. this.nextChar();
  26738. return Cmd.get(']');
  26739. // hex string or dict punctuation
  26740. case 0x3C: // '<'
  26741. ch = this.nextChar();
  26742. if (ch === 0x3C) {
  26743. // dict punctuation
  26744. this.nextChar();
  26745. return Cmd.get('<<');
  26746. }
  26747. return this.getHexString();
  26748. // dict punctuation
  26749. case 0x3E: // '>'
  26750. ch = this.nextChar();
  26751. if (ch === 0x3E) {
  26752. this.nextChar();
  26753. return Cmd.get('>>');
  26754. }
  26755. return Cmd.get('>');
  26756. case 0x7B: // '{'
  26757. this.nextChar();
  26758. return Cmd.get('{');
  26759. case 0x7D: // '}'
  26760. this.nextChar();
  26761. return Cmd.get('}');
  26762. case 0x29: // ')'
  26763. error('Illegal character: ' + ch);
  26764. break;
  26765. }
  26766. // command
  26767. var str = String.fromCharCode(ch);
  26768. var knownCommands = this.knownCommands;
  26769. var knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26770. while ((ch = this.nextChar()) >= 0 && !specialChars[ch]) {
  26771. // stop if known command is found and next character does not make
  26772. // the str a command
  26773. var possibleCommand = str + String.fromCharCode(ch);
  26774. if (knownCommandFound && knownCommands[possibleCommand] === undefined) {
  26775. break;
  26776. }
  26777. if (str.length === 128) {
  26778. error('Command token too long: ' + str.length);
  26779. }
  26780. str = possibleCommand;
  26781. knownCommandFound = knownCommands && knownCommands[str] !== undefined;
  26782. }
  26783. if (str === 'true') {
  26784. return true;
  26785. }
  26786. if (str === 'false') {
  26787. return false;
  26788. }
  26789. if (str === 'null') {
  26790. return null;
  26791. }
  26792. return Cmd.get(str);
  26793. },
  26794. skipToNextLine: function Lexer_skipToNextLine() {
  26795. var ch = this.currentChar;
  26796. while (ch >= 0) {
  26797. if (ch === 0x0D) { // CR
  26798. ch = this.nextChar();
  26799. if (ch === 0x0A) { // LF
  26800. this.nextChar();
  26801. }
  26802. break;
  26803. } else if (ch === 0x0A) { // LF
  26804. this.nextChar();
  26805. break;
  26806. }
  26807. ch = this.nextChar();
  26808. }
  26809. }
  26810. };
  26811. return Lexer;
  26812. })();
  26813. var Linearization = {
  26814. create: function LinearizationCreate(stream) {
  26815. function getInt(name, allowZeroValue) {
  26816. var obj = linDict.get(name);
  26817. if (isInt(obj) && (allowZeroValue ? obj >= 0 : obj > 0)) {
  26818. return obj;
  26819. }
  26820. throw new Error('The "' + name + '" parameter in the linearization ' +
  26821. 'dictionary is invalid.');
  26822. }
  26823. function getHints() {
  26824. var hints = linDict.get('H'), hintsLength, item;
  26825. if (isArray(hints) &&
  26826. ((hintsLength = hints.length) === 2 || hintsLength === 4)) {
  26827. for (var index = 0; index < hintsLength; index++) {
  26828. if (!(isInt(item = hints[index]) && item > 0)) {
  26829. throw new Error('Hint (' + index +
  26830. ') in the linearization dictionary is invalid.');
  26831. }
  26832. }
  26833. return hints;
  26834. }
  26835. throw new Error('Hint array in the linearization dictionary is invalid.');
  26836. }
  26837. var parser = new Parser(new Lexer(stream), false, null);
  26838. var obj1 = parser.getObj();
  26839. var obj2 = parser.getObj();
  26840. var obj3 = parser.getObj();
  26841. var linDict = parser.getObj();
  26842. var obj, length;
  26843. if (!(isInt(obj1) && isInt(obj2) && isCmd(obj3, 'obj') && isDict(linDict) &&
  26844. isNum(obj = linDict.get('Linearized')) && obj > 0)) {
  26845. return null; // No valid linearization dictionary found.
  26846. } else if ((length = getInt('L')) !== stream.length) {
  26847. throw new Error('The "L" parameter in the linearization dictionary ' +
  26848. 'does not equal the stream length.');
  26849. }
  26850. return {
  26851. length: length,
  26852. hints: getHints(),
  26853. objectNumberFirst: getInt('O'),
  26854. endFirst: getInt('E'),
  26855. numPages: getInt('N'),
  26856. mainXRefEntriesOffset: getInt('T'),
  26857. pageFirst: (linDict.has('P') ? getInt('P', true) : 0)
  26858. };
  26859. }
  26860. };
  26861. exports.EOF = EOF;
  26862. exports.Lexer = Lexer;
  26863. exports.Linearization = Linearization;
  26864. exports.Parser = Parser;
  26865. exports.isEOF = isEOF;
  26866. }));
  26867. (function (root, factory) {
  26868. {
  26869. factory((root.pdfjsDisplayAnnotationLayer = {}), root.pdfjsSharedUtil,
  26870. root.pdfjsDisplayDOMUtils);
  26871. }
  26872. }(this, function (exports, sharedUtil, displayDOMUtils) {
  26873. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  26874. var AnnotationType = sharedUtil.AnnotationType;
  26875. var Util = sharedUtil.Util;
  26876. var addLinkAttributes = displayDOMUtils.addLinkAttributes;
  26877. var getFilenameFromUrl = displayDOMUtils.getFilenameFromUrl;
  26878. var warn = sharedUtil.warn;
  26879. var CustomStyle = displayDOMUtils.CustomStyle;
  26880. /**
  26881. * @typedef {Object} AnnotationElementParameters
  26882. * @property {Object} data
  26883. * @property {HTMLDivElement} layer
  26884. * @property {PDFPage} page
  26885. * @property {PageViewport} viewport
  26886. * @property {IPDFLinkService} linkService
  26887. * @property {DownloadManager} downloadManager
  26888. */
  26889. /**
  26890. * @class
  26891. * @alias AnnotationElementFactory
  26892. */
  26893. function AnnotationElementFactory() {}
  26894. AnnotationElementFactory.prototype =
  26895. /** @lends AnnotationElementFactory.prototype */ {
  26896. /**
  26897. * @param {AnnotationElementParameters} parameters
  26898. * @returns {AnnotationElement}
  26899. */
  26900. create: function AnnotationElementFactory_create(parameters) {
  26901. var subtype = parameters.data.annotationType;
  26902. switch (subtype) {
  26903. case AnnotationType.LINK:
  26904. return new LinkAnnotationElement(parameters);
  26905. case AnnotationType.TEXT:
  26906. return new TextAnnotationElement(parameters);
  26907. case AnnotationType.WIDGET:
  26908. return new WidgetAnnotationElement(parameters);
  26909. case AnnotationType.POPUP:
  26910. return new PopupAnnotationElement(parameters);
  26911. case AnnotationType.HIGHLIGHT:
  26912. return new HighlightAnnotationElement(parameters);
  26913. case AnnotationType.UNDERLINE:
  26914. return new UnderlineAnnotationElement(parameters);
  26915. case AnnotationType.SQUIGGLY:
  26916. return new SquigglyAnnotationElement(parameters);
  26917. case AnnotationType.STRIKEOUT:
  26918. return new StrikeOutAnnotationElement(parameters);
  26919. case AnnotationType.FILEATTACHMENT:
  26920. return new FileAttachmentAnnotationElement(parameters);
  26921. default:
  26922. return new AnnotationElement(parameters);
  26923. }
  26924. }
  26925. };
  26926. /**
  26927. * @class
  26928. * @alias AnnotationElement
  26929. */
  26930. var AnnotationElement = (function AnnotationElementClosure() {
  26931. function AnnotationElement(parameters, isRenderable) {
  26932. this.isRenderable = isRenderable || false;
  26933. this.data = parameters.data;
  26934. this.layer = parameters.layer;
  26935. this.page = parameters.page;
  26936. this.viewport = parameters.viewport;
  26937. this.linkService = parameters.linkService;
  26938. this.downloadManager = parameters.downloadManager;
  26939. if (isRenderable) {
  26940. this.container = this._createContainer();
  26941. }
  26942. }
  26943. AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {
  26944. /**
  26945. * Create an empty container for the annotation's HTML element.
  26946. *
  26947. * @private
  26948. * @memberof AnnotationElement
  26949. * @returns {HTMLSectionElement}
  26950. */
  26951. _createContainer: function AnnotationElement_createContainer() {
  26952. var data = this.data, page = this.page, viewport = this.viewport;
  26953. var container = document.createElement('section');
  26954. var width = data.rect[2] - data.rect[0];
  26955. var height = data.rect[3] - data.rect[1];
  26956. container.setAttribute('data-annotation-id', data.id);
  26957. // Do *not* modify `data.rect`, since that will corrupt the annotation
  26958. // position on subsequent calls to `_createContainer` (see issue 6804).
  26959. var rect = Util.normalizeRect([
  26960. data.rect[0],
  26961. page.view[3] - data.rect[1] + page.view[1],
  26962. data.rect[2],
  26963. page.view[3] - data.rect[3] + page.view[1]
  26964. ]);
  26965. CustomStyle.setProp('transform', container,
  26966. 'matrix(' + viewport.transform.join(',') + ')');
  26967. CustomStyle.setProp('transformOrigin', container,
  26968. -rect[0] + 'px ' + -rect[1] + 'px');
  26969. if (data.borderStyle.width > 0) {
  26970. container.style.borderWidth = data.borderStyle.width + 'px';
  26971. if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {
  26972. // Underline styles only have a bottom border, so we do not need
  26973. // to adjust for all borders. This yields a similar result as
  26974. // Adobe Acrobat/Reader.
  26975. width = width - 2 * data.borderStyle.width;
  26976. height = height - 2 * data.borderStyle.width;
  26977. }
  26978. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  26979. var verticalRadius = data.borderStyle.verticalCornerRadius;
  26980. if (horizontalRadius > 0 || verticalRadius > 0) {
  26981. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  26982. CustomStyle.setProp('borderRadius', container, radius);
  26983. }
  26984. switch (data.borderStyle.style) {
  26985. case AnnotationBorderStyleType.SOLID:
  26986. container.style.borderStyle = 'solid';
  26987. break;
  26988. case AnnotationBorderStyleType.DASHED:
  26989. container.style.borderStyle = 'dashed';
  26990. break;
  26991. case AnnotationBorderStyleType.BEVELED:
  26992. warn('Unimplemented border style: beveled');
  26993. break;
  26994. case AnnotationBorderStyleType.INSET:
  26995. warn('Unimplemented border style: inset');
  26996. break;
  26997. case AnnotationBorderStyleType.UNDERLINE:
  26998. container.style.borderBottomStyle = 'solid';
  26999. break;
  27000. default:
  27001. break;
  27002. }
  27003. if (data.color) {
  27004. container.style.borderColor =
  27005. Util.makeCssRgb(data.color[0] | 0,
  27006. data.color[1] | 0,
  27007. data.color[2] | 0);
  27008. } else {
  27009. // Transparent (invisible) border, so do not draw it at all.
  27010. container.style.borderWidth = 0;
  27011. }
  27012. }
  27013. container.style.left = rect[0] + 'px';
  27014. container.style.top = rect[1] + 'px';
  27015. container.style.width = width + 'px';
  27016. container.style.height = height + 'px';
  27017. return container;
  27018. },
  27019. /**
  27020. * Create a popup for the annotation's HTML element. This is used for
  27021. * annotations that do not have a Popup entry in the dictionary, but
  27022. * are of a type that works with popups (such as Highlight annotations).
  27023. *
  27024. * @private
  27025. * @param {HTMLSectionElement} container
  27026. * @param {HTMLDivElement|HTMLImageElement|null} trigger
  27027. * @param {Object} data
  27028. * @memberof AnnotationElement
  27029. */
  27030. _createPopup:
  27031. function AnnotationElement_createPopup(container, trigger, data) {
  27032. // If no trigger element is specified, create it.
  27033. if (!trigger) {
  27034. trigger = document.createElement('div');
  27035. trigger.style.height = container.style.height;
  27036. trigger.style.width = container.style.width;
  27037. container.appendChild(trigger);
  27038. }
  27039. var popupElement = new PopupElement({
  27040. container: container,
  27041. trigger: trigger,
  27042. color: data.color,
  27043. title: data.title,
  27044. contents: data.contents,
  27045. hideWrapper: true
  27046. });
  27047. var popup = popupElement.render();
  27048. // Position the popup next to the annotation's container.
  27049. popup.style.left = container.style.width;
  27050. container.appendChild(popup);
  27051. },
  27052. /**
  27053. * Render the annotation's HTML element in the empty container.
  27054. *
  27055. * @public
  27056. * @memberof AnnotationElement
  27057. */
  27058. render: function AnnotationElement_render() {
  27059. throw new Error('Abstract method AnnotationElement.render called');
  27060. }
  27061. };
  27062. return AnnotationElement;
  27063. })();
  27064. /**
  27065. * @class
  27066. * @alias LinkAnnotationElement
  27067. */
  27068. var LinkAnnotationElement = (function LinkAnnotationElementClosure() {
  27069. function LinkAnnotationElement(parameters) {
  27070. AnnotationElement.call(this, parameters, true);
  27071. }
  27072. Util.inherit(LinkAnnotationElement, AnnotationElement, {
  27073. /**
  27074. * Render the link annotation's HTML element in the empty container.
  27075. *
  27076. * @public
  27077. * @memberof LinkAnnotationElement
  27078. * @returns {HTMLSectionElement}
  27079. */
  27080. render: function LinkAnnotationElement_render() {
  27081. this.container.className = 'linkAnnotation';
  27082. var link = document.createElement('a');
  27083. addLinkAttributes(link, { url: this.data.url });
  27084. if (!this.data.url) {
  27085. if (this.data.action) {
  27086. this._bindNamedAction(link, this.data.action);
  27087. } else {
  27088. this._bindLink(link, ('dest' in this.data) ? this.data.dest : null);
  27089. }
  27090. }
  27091. this.container.appendChild(link);
  27092. return this.container;
  27093. },
  27094. /**
  27095. * Bind internal links to the link element.
  27096. *
  27097. * @private
  27098. * @param {Object} link
  27099. * @param {Object} destination
  27100. * @memberof LinkAnnotationElement
  27101. */
  27102. _bindLink: function LinkAnnotationElement_bindLink(link, destination) {
  27103. var self = this;
  27104. link.href = this.linkService.getDestinationHash(destination);
  27105. link.onclick = function() {
  27106. if (destination) {
  27107. self.linkService.navigateTo(destination);
  27108. }
  27109. return false;
  27110. };
  27111. if (destination) {
  27112. link.className = 'internalLink';
  27113. }
  27114. },
  27115. /**
  27116. * Bind named actions to the link element.
  27117. *
  27118. * @private
  27119. * @param {Object} link
  27120. * @param {Object} action
  27121. * @memberof LinkAnnotationElement
  27122. */
  27123. _bindNamedAction:
  27124. function LinkAnnotationElement_bindNamedAction(link, action) {
  27125. var self = this;
  27126. link.href = this.linkService.getAnchorUrl('');
  27127. link.onclick = function() {
  27128. self.linkService.executeNamedAction(action);
  27129. return false;
  27130. };
  27131. link.className = 'internalLink';
  27132. }
  27133. });
  27134. return LinkAnnotationElement;
  27135. })();
  27136. /**
  27137. * @class
  27138. * @alias TextAnnotationElement
  27139. */
  27140. var TextAnnotationElement = (function TextAnnotationElementClosure() {
  27141. function TextAnnotationElement(parameters) {
  27142. var isRenderable = !!(parameters.data.hasPopup ||
  27143. parameters.data.title || parameters.data.contents);
  27144. AnnotationElement.call(this, parameters, isRenderable);
  27145. }
  27146. Util.inherit(TextAnnotationElement, AnnotationElement, {
  27147. /**
  27148. * Render the text annotation's HTML element in the empty container.
  27149. *
  27150. * @public
  27151. * @memberof TextAnnotationElement
  27152. * @returns {HTMLSectionElement}
  27153. */
  27154. render: function TextAnnotationElement_render() {
  27155. this.container.className = 'textAnnotation';
  27156. var image = document.createElement('img');
  27157. image.style.height = this.container.style.height;
  27158. image.style.width = this.container.style.width;
  27159. image.src = PDFJS.imageResourcesPath + 'annotation-' +
  27160. this.data.name.toLowerCase() + '.svg';
  27161. image.alt = '[{{type}} Annotation]';
  27162. image.dataset.l10nId = 'text_annotation_type';
  27163. image.dataset.l10nArgs = JSON.stringify({type: this.data.name});
  27164. if (!this.data.hasPopup) {
  27165. this._createPopup(this.container, image, this.data);
  27166. }
  27167. this.container.appendChild(image);
  27168. return this.container;
  27169. }
  27170. });
  27171. return TextAnnotationElement;
  27172. })();
  27173. /**
  27174. * @class
  27175. * @alias WidgetAnnotationElement
  27176. */
  27177. var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {
  27178. function WidgetAnnotationElement(parameters) {
  27179. var isRenderable = !parameters.data.hasAppearance &&
  27180. !!parameters.data.fieldValue;
  27181. AnnotationElement.call(this, parameters, isRenderable);
  27182. }
  27183. Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  27184. /**
  27185. * Render the widget annotation's HTML element in the empty container.
  27186. *
  27187. * @public
  27188. * @memberof WidgetAnnotationElement
  27189. * @returns {HTMLSectionElement}
  27190. */
  27191. render: function WidgetAnnotationElement_render() {
  27192. var content = document.createElement('div');
  27193. content.textContent = this.data.fieldValue;
  27194. var textAlignment = this.data.textAlignment;
  27195. content.style.textAlign = ['left', 'center', 'right'][textAlignment];
  27196. content.style.verticalAlign = 'middle';
  27197. content.style.display = 'table-cell';
  27198. var font = (this.data.fontRefName ?
  27199. this.page.commonObjs.getData(this.data.fontRefName) : null);
  27200. this._setTextStyle(content, font);
  27201. this.container.appendChild(content);
  27202. return this.container;
  27203. },
  27204. /**
  27205. * Apply text styles to the text in the element.
  27206. *
  27207. * @private
  27208. * @param {HTMLDivElement} element
  27209. * @param {Object} font
  27210. * @memberof WidgetAnnotationElement
  27211. */
  27212. _setTextStyle:
  27213. function WidgetAnnotationElement_setTextStyle(element, font) {
  27214. // TODO: This duplicates some of the logic in CanvasGraphics.setFont().
  27215. var style = element.style;
  27216. style.fontSize = this.data.fontSize + 'px';
  27217. style.direction = (this.data.fontDirection < 0 ? 'rtl': 'ltr');
  27218. if (!font) {
  27219. return;
  27220. }
  27221. style.fontWeight = (font.black ?
  27222. (font.bold ? '900' : 'bold') :
  27223. (font.bold ? 'bold' : 'normal'));
  27224. style.fontStyle = (font.italic ? 'italic' : 'normal');
  27225. // Use a reasonable default font if the font doesn't specify a fallback.
  27226. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  27227. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  27228. style.fontFamily = fontFamily + fallbackName;
  27229. }
  27230. });
  27231. return WidgetAnnotationElement;
  27232. })();
  27233. /**
  27234. * @class
  27235. * @alias PopupAnnotationElement
  27236. */
  27237. var PopupAnnotationElement = (function PopupAnnotationElementClosure() {
  27238. function PopupAnnotationElement(parameters) {
  27239. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  27240. AnnotationElement.call(this, parameters, isRenderable);
  27241. }
  27242. Util.inherit(PopupAnnotationElement, AnnotationElement, {
  27243. /**
  27244. * Render the popup annotation's HTML element in the empty container.
  27245. *
  27246. * @public
  27247. * @memberof PopupAnnotationElement
  27248. * @returns {HTMLSectionElement}
  27249. */
  27250. render: function PopupAnnotationElement_render() {
  27251. this.container.className = 'popupAnnotation';
  27252. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  27253. var parentElement = this.layer.querySelector(selector);
  27254. if (!parentElement) {
  27255. return this.container;
  27256. }
  27257. var popup = new PopupElement({
  27258. container: this.container,
  27259. trigger: parentElement,
  27260. color: this.data.color,
  27261. title: this.data.title,
  27262. contents: this.data.contents
  27263. });
  27264. // Position the popup next to the parent annotation's container.
  27265. // PDF viewers ignore a popup annotation's rectangle.
  27266. var parentLeft = parseFloat(parentElement.style.left);
  27267. var parentWidth = parseFloat(parentElement.style.width);
  27268. CustomStyle.setProp('transformOrigin', this.container,
  27269. -(parentLeft + parentWidth) + 'px -' +
  27270. parentElement.style.top);
  27271. this.container.style.left = (parentLeft + parentWidth) + 'px';
  27272. this.container.appendChild(popup.render());
  27273. return this.container;
  27274. }
  27275. });
  27276. return PopupAnnotationElement;
  27277. })();
  27278. /**
  27279. * @class
  27280. * @alias PopupElement
  27281. */
  27282. var PopupElement = (function PopupElementClosure() {
  27283. var BACKGROUND_ENLIGHT = 0.7;
  27284. function PopupElement(parameters) {
  27285. this.container = parameters.container;
  27286. this.trigger = parameters.trigger;
  27287. this.color = parameters.color;
  27288. this.title = parameters.title;
  27289. this.contents = parameters.contents;
  27290. this.hideWrapper = parameters.hideWrapper || false;
  27291. this.pinned = false;
  27292. }
  27293. PopupElement.prototype = /** @lends PopupElement.prototype */ {
  27294. /**
  27295. * Render the popup's HTML element.
  27296. *
  27297. * @public
  27298. * @memberof PopupElement
  27299. * @returns {HTMLSectionElement}
  27300. */
  27301. render: function PopupElement_render() {
  27302. var wrapper = document.createElement('div');
  27303. wrapper.className = 'popupWrapper';
  27304. // For Popup annotations we hide the entire section because it contains
  27305. // only the popup. However, for Text annotations without a separate Popup
  27306. // annotation, we cannot hide the entire container as the image would
  27307. // disappear too. In that special case, hiding the wrapper suffices.
  27308. this.hideElement = (this.hideWrapper ? wrapper : this.container);
  27309. this.hideElement.setAttribute('hidden', true);
  27310. var popup = document.createElement('div');
  27311. popup.className = 'popup';
  27312. var color = this.color;
  27313. if (color) {
  27314. // Enlighten the color.
  27315. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  27316. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  27317. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  27318. popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);
  27319. }
  27320. var contents = this._formatContents(this.contents);
  27321. var title = document.createElement('h1');
  27322. title.textContent = this.title;
  27323. // Attach the event listeners to the trigger element.
  27324. this.trigger.addEventListener('click', this._toggle.bind(this));
  27325. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  27326. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  27327. popup.addEventListener('click', this._hide.bind(this, true));
  27328. popup.appendChild(title);
  27329. popup.appendChild(contents);
  27330. wrapper.appendChild(popup);
  27331. return wrapper;
  27332. },
  27333. /**
  27334. * Format the contents of the popup by adding newlines where necessary.
  27335. *
  27336. * @private
  27337. * @param {string} contents
  27338. * @memberof PopupElement
  27339. * @returns {HTMLParagraphElement}
  27340. */
  27341. _formatContents: function PopupElement_formatContents(contents) {
  27342. var p = document.createElement('p');
  27343. var lines = contents.split(/(?:\r\n?|\n)/);
  27344. for (var i = 0, ii = lines.length; i < ii; ++i) {
  27345. var line = lines[i];
  27346. p.appendChild(document.createTextNode(line));
  27347. if (i < (ii - 1)) {
  27348. p.appendChild(document.createElement('br'));
  27349. }
  27350. }
  27351. return p;
  27352. },
  27353. /**
  27354. * Toggle the visibility of the popup.
  27355. *
  27356. * @private
  27357. * @memberof PopupElement
  27358. */
  27359. _toggle: function PopupElement_toggle() {
  27360. if (this.pinned) {
  27361. this._hide(true);
  27362. } else {
  27363. this._show(true);
  27364. }
  27365. },
  27366. /**
  27367. * Show the popup.
  27368. *
  27369. * @private
  27370. * @param {boolean} pin
  27371. * @memberof PopupElement
  27372. */
  27373. _show: function PopupElement_show(pin) {
  27374. if (pin) {
  27375. this.pinned = true;
  27376. }
  27377. if (this.hideElement.hasAttribute('hidden')) {
  27378. this.hideElement.removeAttribute('hidden');
  27379. this.container.style.zIndex += 1;
  27380. }
  27381. },
  27382. /**
  27383. * Hide the popup.
  27384. *
  27385. * @private
  27386. * @param {boolean} unpin
  27387. * @memberof PopupElement
  27388. */
  27389. _hide: function PopupElement_hide(unpin) {
  27390. if (unpin) {
  27391. this.pinned = false;
  27392. }
  27393. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  27394. this.hideElement.setAttribute('hidden', true);
  27395. this.container.style.zIndex -= 1;
  27396. }
  27397. }
  27398. };
  27399. return PopupElement;
  27400. })();
  27401. /**
  27402. * @class
  27403. * @alias HighlightAnnotationElement
  27404. */
  27405. var HighlightAnnotationElement = (
  27406. function HighlightAnnotationElementClosure() {
  27407. function HighlightAnnotationElement(parameters) {
  27408. var isRenderable = !!(parameters.data.hasPopup ||
  27409. parameters.data.title || parameters.data.contents);
  27410. AnnotationElement.call(this, parameters, isRenderable);
  27411. }
  27412. Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  27413. /**
  27414. * Render the highlight annotation's HTML element in the empty container.
  27415. *
  27416. * @public
  27417. * @memberof HighlightAnnotationElement
  27418. * @returns {HTMLSectionElement}
  27419. */
  27420. render: function HighlightAnnotationElement_render() {
  27421. this.container.className = 'highlightAnnotation';
  27422. if (!this.data.hasPopup) {
  27423. this._createPopup(this.container, null, this.data);
  27424. }
  27425. return this.container;
  27426. }
  27427. });
  27428. return HighlightAnnotationElement;
  27429. })();
  27430. /**
  27431. * @class
  27432. * @alias UnderlineAnnotationElement
  27433. */
  27434. var UnderlineAnnotationElement = (
  27435. function UnderlineAnnotationElementClosure() {
  27436. function UnderlineAnnotationElement(parameters) {
  27437. var isRenderable = !!(parameters.data.hasPopup ||
  27438. parameters.data.title || parameters.data.contents);
  27439. AnnotationElement.call(this, parameters, isRenderable);
  27440. }
  27441. Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  27442. /**
  27443. * Render the underline annotation's HTML element in the empty container.
  27444. *
  27445. * @public
  27446. * @memberof UnderlineAnnotationElement
  27447. * @returns {HTMLSectionElement}
  27448. */
  27449. render: function UnderlineAnnotationElement_render() {
  27450. this.container.className = 'underlineAnnotation';
  27451. if (!this.data.hasPopup) {
  27452. this._createPopup(this.container, null, this.data);
  27453. }
  27454. return this.container;
  27455. }
  27456. });
  27457. return UnderlineAnnotationElement;
  27458. })();
  27459. /**
  27460. * @class
  27461. * @alias SquigglyAnnotationElement
  27462. */
  27463. var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {
  27464. function SquigglyAnnotationElement(parameters) {
  27465. var isRenderable = !!(parameters.data.hasPopup ||
  27466. parameters.data.title || parameters.data.contents);
  27467. AnnotationElement.call(this, parameters, isRenderable);
  27468. }
  27469. Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  27470. /**
  27471. * Render the squiggly annotation's HTML element in the empty container.
  27472. *
  27473. * @public
  27474. * @memberof SquigglyAnnotationElement
  27475. * @returns {HTMLSectionElement}
  27476. */
  27477. render: function SquigglyAnnotationElement_render() {
  27478. this.container.className = 'squigglyAnnotation';
  27479. if (!this.data.hasPopup) {
  27480. this._createPopup(this.container, null, this.data);
  27481. }
  27482. return this.container;
  27483. }
  27484. });
  27485. return SquigglyAnnotationElement;
  27486. })();
  27487. /**
  27488. * @class
  27489. * @alias StrikeOutAnnotationElement
  27490. */
  27491. var StrikeOutAnnotationElement = (
  27492. function StrikeOutAnnotationElementClosure() {
  27493. function StrikeOutAnnotationElement(parameters) {
  27494. var isRenderable = !!(parameters.data.hasPopup ||
  27495. parameters.data.title || parameters.data.contents);
  27496. AnnotationElement.call(this, parameters, isRenderable);
  27497. }
  27498. Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  27499. /**
  27500. * Render the strikeout annotation's HTML element in the empty container.
  27501. *
  27502. * @public
  27503. * @memberof StrikeOutAnnotationElement
  27504. * @returns {HTMLSectionElement}
  27505. */
  27506. render: function StrikeOutAnnotationElement_render() {
  27507. this.container.className = 'strikeoutAnnotation';
  27508. if (!this.data.hasPopup) {
  27509. this._createPopup(this.container, null, this.data);
  27510. }
  27511. return this.container;
  27512. }
  27513. });
  27514. return StrikeOutAnnotationElement;
  27515. })();
  27516. /**
  27517. * @class
  27518. * @alias FileAttachmentAnnotationElement
  27519. */
  27520. var FileAttachmentAnnotationElement = (
  27521. function FileAttachmentAnnotationElementClosure() {
  27522. function FileAttachmentAnnotationElement(parameters) {
  27523. AnnotationElement.call(this, parameters, true);
  27524. this.filename = getFilenameFromUrl(parameters.data.file.filename);
  27525. this.content = parameters.data.file.content;
  27526. }
  27527. Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  27528. /**
  27529. * Render the file attachment annotation's HTML element in the empty
  27530. * container.
  27531. *
  27532. * @public
  27533. * @memberof FileAttachmentAnnotationElement
  27534. * @returns {HTMLSectionElement}
  27535. */
  27536. render: function FileAttachmentAnnotationElement_render() {
  27537. this.container.className = 'fileAttachmentAnnotation';
  27538. var trigger = document.createElement('div');
  27539. trigger.style.height = this.container.style.height;
  27540. trigger.style.width = this.container.style.width;
  27541. trigger.addEventListener('dblclick', this._download.bind(this));
  27542. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  27543. this._createPopup(this.container, trigger, this.data);
  27544. }
  27545. this.container.appendChild(trigger);
  27546. return this.container;
  27547. },
  27548. /**
  27549. * Download the file attachment associated with this annotation.
  27550. *
  27551. * @private
  27552. * @memberof FileAttachmentAnnotationElement
  27553. */
  27554. _download: function FileAttachmentAnnotationElement_download() {
  27555. if (!this.downloadManager) {
  27556. warn('Download cannot be started due to unavailable download manager');
  27557. return;
  27558. }
  27559. this.downloadManager.downloadData(this.content, this.filename, '');
  27560. }
  27561. });
  27562. return FileAttachmentAnnotationElement;
  27563. })();
  27564. /**
  27565. * @typedef {Object} AnnotationLayerParameters
  27566. * @property {PageViewport} viewport
  27567. * @property {HTMLDivElement} div
  27568. * @property {Array} annotations
  27569. * @property {PDFPage} page
  27570. * @property {IPDFLinkService} linkService
  27571. */
  27572. /**
  27573. * @class
  27574. * @alias AnnotationLayer
  27575. */
  27576. var AnnotationLayer = (function AnnotationLayerClosure() {
  27577. return {
  27578. /**
  27579. * Render a new annotation layer with all annotation elements.
  27580. *
  27581. * @public
  27582. * @param {AnnotationLayerParameters} parameters
  27583. * @memberof AnnotationLayer
  27584. */
  27585. render: function AnnotationLayer_render(parameters) {
  27586. var annotationElementFactory = new AnnotationElementFactory();
  27587. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  27588. var data = parameters.annotations[i];
  27589. if (!data) {
  27590. continue;
  27591. }
  27592. var properties = {
  27593. data: data,
  27594. layer: parameters.div,
  27595. page: parameters.page,
  27596. viewport: parameters.viewport,
  27597. linkService: parameters.linkService,
  27598. downloadManager: parameters.downloadManager
  27599. };
  27600. var element = annotationElementFactory.create(properties);
  27601. if (element.isRenderable) {
  27602. parameters.div.appendChild(element.render());
  27603. }
  27604. }
  27605. },
  27606. /**
  27607. * Update the annotation elements on existing annotation layer.
  27608. *
  27609. * @public
  27610. * @param {AnnotationLayerParameters} parameters
  27611. * @memberof AnnotationLayer
  27612. */
  27613. update: function AnnotationLayer_update(parameters) {
  27614. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  27615. var data = parameters.annotations[i];
  27616. var element = parameters.div.querySelector(
  27617. '[data-annotation-id="' + data.id + '"]');
  27618. if (element) {
  27619. CustomStyle.setProp('transform', element,
  27620. 'matrix(' + parameters.viewport.transform.join(',') + ')');
  27621. }
  27622. }
  27623. parameters.div.removeAttribute('hidden');
  27624. }
  27625. };
  27626. })();
  27627. PDFJS.AnnotationLayer = AnnotationLayer;
  27628. exports.AnnotationLayer = AnnotationLayer;
  27629. }));
  27630. (function (root, factory) {
  27631. {
  27632. factory((root.pdfjsDisplayPatternHelper = {}), root.pdfjsSharedUtil,
  27633. root.pdfjsDisplayWebGL);
  27634. }
  27635. }(this, function (exports, sharedUtil, displayWebGL) {
  27636. var Util = sharedUtil.Util;
  27637. var info = sharedUtil.info;
  27638. var isArray = sharedUtil.isArray;
  27639. var error = sharedUtil.error;
  27640. var WebGLUtils = displayWebGL.WebGLUtils;
  27641. var ShadingIRs = {};
  27642. ShadingIRs.RadialAxial = {
  27643. fromIR: function RadialAxial_fromIR(raw) {
  27644. var type = raw[1];
  27645. var colorStops = raw[2];
  27646. var p0 = raw[3];
  27647. var p1 = raw[4];
  27648. var r0 = raw[5];
  27649. var r1 = raw[6];
  27650. return {
  27651. type: 'Pattern',
  27652. getPattern: function RadialAxial_getPattern(ctx) {
  27653. var grad;
  27654. if (type === 'axial') {
  27655. grad = ctx.createLinearGradient(p0[0], p0[1], p1[0], p1[1]);
  27656. } else if (type === 'radial') {
  27657. grad = ctx.createRadialGradient(p0[0], p0[1], r0, p1[0], p1[1], r1);
  27658. }
  27659. for (var i = 0, ii = colorStops.length; i < ii; ++i) {
  27660. var c = colorStops[i];
  27661. grad.addColorStop(c[0], c[1]);
  27662. }
  27663. return grad;
  27664. }
  27665. };
  27666. }
  27667. };
  27668. var createMeshCanvas = (function createMeshCanvasClosure() {
  27669. function drawTriangle(data, context, p1, p2, p3, c1, c2, c3) {
  27670. // Very basic Gouraud-shaded triangle rasterization algorithm.
  27671. var coords = context.coords, colors = context.colors;
  27672. var bytes = data.data, rowSize = data.width * 4;
  27673. var tmp;
  27674. if (coords[p1 + 1] > coords[p2 + 1]) {
  27675. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  27676. }
  27677. if (coords[p2 + 1] > coords[p3 + 1]) {
  27678. tmp = p2; p2 = p3; p3 = tmp; tmp = c2; c2 = c3; c3 = tmp;
  27679. }
  27680. if (coords[p1 + 1] > coords[p2 + 1]) {
  27681. tmp = p1; p1 = p2; p2 = tmp; tmp = c1; c1 = c2; c2 = tmp;
  27682. }
  27683. var x1 = (coords[p1] + context.offsetX) * context.scaleX;
  27684. var y1 = (coords[p1 + 1] + context.offsetY) * context.scaleY;
  27685. var x2 = (coords[p2] + context.offsetX) * context.scaleX;
  27686. var y2 = (coords[p2 + 1] + context.offsetY) * context.scaleY;
  27687. var x3 = (coords[p3] + context.offsetX) * context.scaleX;
  27688. var y3 = (coords[p3 + 1] + context.offsetY) * context.scaleY;
  27689. if (y1 >= y3) {
  27690. return;
  27691. }
  27692. var c1r = colors[c1], c1g = colors[c1 + 1], c1b = colors[c1 + 2];
  27693. var c2r = colors[c2], c2g = colors[c2 + 1], c2b = colors[c2 + 2];
  27694. var c3r = colors[c3], c3g = colors[c3 + 1], c3b = colors[c3 + 2];
  27695. var minY = Math.round(y1), maxY = Math.round(y3);
  27696. var xa, car, cag, cab;
  27697. var xb, cbr, cbg, cbb;
  27698. var k;
  27699. for (var y = minY; y <= maxY; y++) {
  27700. if (y < y2) {
  27701. k = y < y1 ? 0 : y1 === y2 ? 1 : (y1 - y) / (y1 - y2);
  27702. xa = x1 - (x1 - x2) * k;
  27703. car = c1r - (c1r - c2r) * k;
  27704. cag = c1g - (c1g - c2g) * k;
  27705. cab = c1b - (c1b - c2b) * k;
  27706. } else {
  27707. k = y > y3 ? 1 : y2 === y3 ? 0 : (y2 - y) / (y2 - y3);
  27708. xa = x2 - (x2 - x3) * k;
  27709. car = c2r - (c2r - c3r) * k;
  27710. cag = c2g - (c2g - c3g) * k;
  27711. cab = c2b - (c2b - c3b) * k;
  27712. }
  27713. k = y < y1 ? 0 : y > y3 ? 1 : (y1 - y) / (y1 - y3);
  27714. xb = x1 - (x1 - x3) * k;
  27715. cbr = c1r - (c1r - c3r) * k;
  27716. cbg = c1g - (c1g - c3g) * k;
  27717. cbb = c1b - (c1b - c3b) * k;
  27718. var x1_ = Math.round(Math.min(xa, xb));
  27719. var x2_ = Math.round(Math.max(xa, xb));
  27720. var j = rowSize * y + x1_ * 4;
  27721. for (var x = x1_; x <= x2_; x++) {
  27722. k = (xa - x) / (xa - xb);
  27723. k = k < 0 ? 0 : k > 1 ? 1 : k;
  27724. bytes[j++] = (car - (car - cbr) * k) | 0;
  27725. bytes[j++] = (cag - (cag - cbg) * k) | 0;
  27726. bytes[j++] = (cab - (cab - cbb) * k) | 0;
  27727. bytes[j++] = 255;
  27728. }
  27729. }
  27730. }
  27731. function drawFigure(data, figure, context) {
  27732. var ps = figure.coords;
  27733. var cs = figure.colors;
  27734. var i, ii;
  27735. switch (figure.type) {
  27736. case 'lattice':
  27737. var verticesPerRow = figure.verticesPerRow;
  27738. var rows = Math.floor(ps.length / verticesPerRow) - 1;
  27739. var cols = verticesPerRow - 1;
  27740. for (i = 0; i < rows; i++) {
  27741. var q = i * verticesPerRow;
  27742. for (var j = 0; j < cols; j++, q++) {
  27743. drawTriangle(data, context,
  27744. ps[q], ps[q + 1], ps[q + verticesPerRow],
  27745. cs[q], cs[q + 1], cs[q + verticesPerRow]);
  27746. drawTriangle(data, context,
  27747. ps[q + verticesPerRow + 1], ps[q + 1], ps[q + verticesPerRow],
  27748. cs[q + verticesPerRow + 1], cs[q + 1], cs[q + verticesPerRow]);
  27749. }
  27750. }
  27751. break;
  27752. case 'triangles':
  27753. for (i = 0, ii = ps.length; i < ii; i += 3) {
  27754. drawTriangle(data, context,
  27755. ps[i], ps[i + 1], ps[i + 2],
  27756. cs[i], cs[i + 1], cs[i + 2]);
  27757. }
  27758. break;
  27759. default:
  27760. error('illigal figure');
  27761. break;
  27762. }
  27763. }
  27764. function createMeshCanvas(bounds, combinesScale, coords, colors, figures,
  27765. backgroundColor, cachedCanvases) {
  27766. // we will increase scale on some weird factor to let antialiasing take
  27767. // care of "rough" edges
  27768. var EXPECTED_SCALE = 1.1;
  27769. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  27770. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  27771. var offsetX = Math.floor(bounds[0]);
  27772. var offsetY = Math.floor(bounds[1]);
  27773. var boundsWidth = Math.ceil(bounds[2]) - offsetX;
  27774. var boundsHeight = Math.ceil(bounds[3]) - offsetY;
  27775. var width = Math.min(Math.ceil(Math.abs(boundsWidth * combinesScale[0] *
  27776. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  27777. var height = Math.min(Math.ceil(Math.abs(boundsHeight * combinesScale[1] *
  27778. EXPECTED_SCALE)), MAX_PATTERN_SIZE);
  27779. var scaleX = boundsWidth / width;
  27780. var scaleY = boundsHeight / height;
  27781. var context = {
  27782. coords: coords,
  27783. colors: colors,
  27784. offsetX: -offsetX,
  27785. offsetY: -offsetY,
  27786. scaleX: 1 / scaleX,
  27787. scaleY: 1 / scaleY
  27788. };
  27789. var canvas, tmpCanvas, i, ii;
  27790. if (WebGLUtils.isEnabled) {
  27791. canvas = WebGLUtils.drawFigures(width, height, backgroundColor,
  27792. figures, context);
  27793. // https://bugzilla.mozilla.org/show_bug.cgi?id=972126
  27794. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  27795. tmpCanvas.context.drawImage(canvas, 0, 0);
  27796. canvas = tmpCanvas.canvas;
  27797. } else {
  27798. tmpCanvas = cachedCanvases.getCanvas('mesh', width, height, false);
  27799. var tmpCtx = tmpCanvas.context;
  27800. var data = tmpCtx.createImageData(width, height);
  27801. if (backgroundColor) {
  27802. var bytes = data.data;
  27803. for (i = 0, ii = bytes.length; i < ii; i += 4) {
  27804. bytes[i] = backgroundColor[0];
  27805. bytes[i + 1] = backgroundColor[1];
  27806. bytes[i + 2] = backgroundColor[2];
  27807. bytes[i + 3] = 255;
  27808. }
  27809. }
  27810. for (i = 0; i < figures.length; i++) {
  27811. drawFigure(data, figures[i], context);
  27812. }
  27813. tmpCtx.putImageData(data, 0, 0);
  27814. canvas = tmpCanvas.canvas;
  27815. }
  27816. return {canvas: canvas, offsetX: offsetX, offsetY: offsetY,
  27817. scaleX: scaleX, scaleY: scaleY};
  27818. }
  27819. return createMeshCanvas;
  27820. })();
  27821. ShadingIRs.Mesh = {
  27822. fromIR: function Mesh_fromIR(raw) {
  27823. //var type = raw[1];
  27824. var coords = raw[2];
  27825. var colors = raw[3];
  27826. var figures = raw[4];
  27827. var bounds = raw[5];
  27828. var matrix = raw[6];
  27829. //var bbox = raw[7];
  27830. var background = raw[8];
  27831. return {
  27832. type: 'Pattern',
  27833. getPattern: function Mesh_getPattern(ctx, owner, shadingFill) {
  27834. var scale;
  27835. if (shadingFill) {
  27836. scale = Util.singularValueDecompose2dScale(ctx.mozCurrentTransform);
  27837. } else {
  27838. // Obtain scale from matrix and current transformation matrix.
  27839. scale = Util.singularValueDecompose2dScale(owner.baseTransform);
  27840. if (matrix) {
  27841. var matrixScale = Util.singularValueDecompose2dScale(matrix);
  27842. scale = [scale[0] * matrixScale[0],
  27843. scale[1] * matrixScale[1]];
  27844. }
  27845. }
  27846. // Rasterizing on the main thread since sending/queue large canvases
  27847. // might cause OOM.
  27848. var temporaryPatternCanvas = createMeshCanvas(bounds, scale, coords,
  27849. colors, figures, shadingFill ? null : background,
  27850. owner.cachedCanvases);
  27851. if (!shadingFill) {
  27852. ctx.setTransform.apply(ctx, owner.baseTransform);
  27853. if (matrix) {
  27854. ctx.transform.apply(ctx, matrix);
  27855. }
  27856. }
  27857. ctx.translate(temporaryPatternCanvas.offsetX,
  27858. temporaryPatternCanvas.offsetY);
  27859. ctx.scale(temporaryPatternCanvas.scaleX,
  27860. temporaryPatternCanvas.scaleY);
  27861. return ctx.createPattern(temporaryPatternCanvas.canvas, 'no-repeat');
  27862. }
  27863. };
  27864. }
  27865. };
  27866. ShadingIRs.Dummy = {
  27867. fromIR: function Dummy_fromIR() {
  27868. return {
  27869. type: 'Pattern',
  27870. getPattern: function Dummy_fromIR_getPattern() {
  27871. return 'hotpink';
  27872. }
  27873. };
  27874. }
  27875. };
  27876. function getShadingPatternFromIR(raw) {
  27877. var shadingIR = ShadingIRs[raw[0]];
  27878. if (!shadingIR) {
  27879. error('Unknown IR type: ' + raw[0]);
  27880. }
  27881. return shadingIR.fromIR(raw);
  27882. }
  27883. var TilingPattern = (function TilingPatternClosure() {
  27884. var PaintType = {
  27885. COLORED: 1,
  27886. UNCOLORED: 2
  27887. };
  27888. var MAX_PATTERN_SIZE = 3000; // 10in @ 300dpi shall be enough
  27889. function TilingPattern(IR, color, ctx, canvasGraphicsFactory, baseTransform) {
  27890. this.operatorList = IR[2];
  27891. this.matrix = IR[3] || [1, 0, 0, 1, 0, 0];
  27892. this.bbox = IR[4];
  27893. this.xstep = IR[5];
  27894. this.ystep = IR[6];
  27895. this.paintType = IR[7];
  27896. this.tilingType = IR[8];
  27897. this.color = color;
  27898. this.canvasGraphicsFactory = canvasGraphicsFactory;
  27899. this.baseTransform = baseTransform;
  27900. this.type = 'Pattern';
  27901. this.ctx = ctx;
  27902. }
  27903. TilingPattern.prototype = {
  27904. createPatternCanvas: function TilinPattern_createPatternCanvas(owner) {
  27905. var operatorList = this.operatorList;
  27906. var bbox = this.bbox;
  27907. var xstep = this.xstep;
  27908. var ystep = this.ystep;
  27909. var paintType = this.paintType;
  27910. var tilingType = this.tilingType;
  27911. var color = this.color;
  27912. var canvasGraphicsFactory = this.canvasGraphicsFactory;
  27913. info('TilingType: ' + tilingType);
  27914. var x0 = bbox[0], y0 = bbox[1], x1 = bbox[2], y1 = bbox[3];
  27915. var topLeft = [x0, y0];
  27916. // we want the canvas to be as large as the step size
  27917. var botRight = [x0 + xstep, y0 + ystep];
  27918. var width = botRight[0] - topLeft[0];
  27919. var height = botRight[1] - topLeft[1];
  27920. // Obtain scale from matrix and current transformation matrix.
  27921. var matrixScale = Util.singularValueDecompose2dScale(this.matrix);
  27922. var curMatrixScale = Util.singularValueDecompose2dScale(
  27923. this.baseTransform);
  27924. var combinedScale = [matrixScale[0] * curMatrixScale[0],
  27925. matrixScale[1] * curMatrixScale[1]];
  27926. // MAX_PATTERN_SIZE is used to avoid OOM situation.
  27927. // Use width and height values that are as close as possible to the end
  27928. // result when the pattern is used. Too low value makes the pattern look
  27929. // blurry. Too large value makes it look too crispy.
  27930. width = Math.min(Math.ceil(Math.abs(width * combinedScale[0])),
  27931. MAX_PATTERN_SIZE);
  27932. height = Math.min(Math.ceil(Math.abs(height * combinedScale[1])),
  27933. MAX_PATTERN_SIZE);
  27934. var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
  27935. width, height, true);
  27936. var tmpCtx = tmpCanvas.context;
  27937. var graphics = canvasGraphicsFactory.createCanvasGraphics(tmpCtx);
  27938. graphics.groupLevel = owner.groupLevel;
  27939. this.setFillAndStrokeStyleToContext(tmpCtx, paintType, color);
  27940. this.setScale(width, height, xstep, ystep);
  27941. this.transformToScale(graphics);
  27942. // transform coordinates to pattern space
  27943. var tmpTranslate = [1, 0, 0, 1, -topLeft[0], -topLeft[1]];
  27944. graphics.transform.apply(graphics, tmpTranslate);
  27945. this.clipBbox(graphics, bbox, x0, y0, x1, y1);
  27946. graphics.executeOperatorList(operatorList);
  27947. return tmpCanvas.canvas;
  27948. },
  27949. setScale: function TilingPattern_setScale(width, height, xstep, ystep) {
  27950. this.scale = [width / xstep, height / ystep];
  27951. },
  27952. transformToScale: function TilingPattern_transformToScale(graphics) {
  27953. var scale = this.scale;
  27954. var tmpScale = [scale[0], 0, 0, scale[1], 0, 0];
  27955. graphics.transform.apply(graphics, tmpScale);
  27956. },
  27957. scaleToContext: function TilingPattern_scaleToContext() {
  27958. var scale = this.scale;
  27959. this.ctx.scale(1 / scale[0], 1 / scale[1]);
  27960. },
  27961. clipBbox: function clipBbox(graphics, bbox, x0, y0, x1, y1) {
  27962. if (bbox && isArray(bbox) && bbox.length === 4) {
  27963. var bboxWidth = x1 - x0;
  27964. var bboxHeight = y1 - y0;
  27965. graphics.ctx.rect(x0, y0, bboxWidth, bboxHeight);
  27966. graphics.clip();
  27967. graphics.endPath();
  27968. }
  27969. },
  27970. setFillAndStrokeStyleToContext:
  27971. function setFillAndStrokeStyleToContext(context, paintType, color) {
  27972. switch (paintType) {
  27973. case PaintType.COLORED:
  27974. var ctx = this.ctx;
  27975. context.fillStyle = ctx.fillStyle;
  27976. context.strokeStyle = ctx.strokeStyle;
  27977. break;
  27978. case PaintType.UNCOLORED:
  27979. var cssColor = Util.makeCssRgb(color[0], color[1], color[2]);
  27980. context.fillStyle = cssColor;
  27981. context.strokeStyle = cssColor;
  27982. break;
  27983. default:
  27984. error('Unsupported paint type: ' + paintType);
  27985. }
  27986. },
  27987. getPattern: function TilingPattern_getPattern(ctx, owner) {
  27988. var temporaryPatternCanvas = this.createPatternCanvas(owner);
  27989. ctx = this.ctx;
  27990. ctx.setTransform.apply(ctx, this.baseTransform);
  27991. ctx.transform.apply(ctx, this.matrix);
  27992. this.scaleToContext();
  27993. return ctx.createPattern(temporaryPatternCanvas, 'repeat');
  27994. }
  27995. };
  27996. return TilingPattern;
  27997. })();
  27998. exports.getShadingPatternFromIR = getShadingPatternFromIR;
  27999. exports.TilingPattern = TilingPattern;
  28000. }));
  28001. (function (root, factory) {
  28002. {
  28003. factory((root.pdfjsDisplayTextLayer = {}), root.pdfjsSharedUtil,
  28004. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayGlobal);
  28005. }
  28006. }(this, function (exports, sharedUtil, displayDOMUtils, displayGlobal) {
  28007. var Util = sharedUtil.Util;
  28008. var createPromiseCapability = sharedUtil.createPromiseCapability;
  28009. var CustomStyle = displayDOMUtils.CustomStyle;
  28010. var PDFJS = displayGlobal.PDFJS;
  28011. /**
  28012. * Text layer render parameters.
  28013. *
  28014. * @typedef {Object} TextLayerRenderParameters
  28015. * @property {TextContent} textContent - Text content to render (the object is
  28016. * returned by the page's getTextContent() method).
  28017. * @property {HTMLElement} container - HTML element that will contain text runs.
  28018. * @property {PDFJS.PageViewport} viewport - The target viewport to properly
  28019. * layout the text runs.
  28020. * @property {Array} textDivs - (optional) HTML elements that are correspond
  28021. * the text items of the textContent input. This is output and shall be
  28022. * initially be set to empty array.
  28023. * @property {number} timeout - (optional) Delay in milliseconds before
  28024. * rendering of the text runs occurs.
  28025. */
  28026. var renderTextLayer = (function renderTextLayerClosure() {
  28027. var MAX_TEXT_DIVS_TO_RENDER = 100000;
  28028. var NonWhitespaceRegexp = /\S/;
  28029. function isAllWhitespace(str) {
  28030. return !NonWhitespaceRegexp.test(str);
  28031. }
  28032. function appendText(textDivs, viewport, geom, styles) {
  28033. var style = styles[geom.fontName];
  28034. var textDiv = document.createElement('div');
  28035. textDivs.push(textDiv);
  28036. if (isAllWhitespace(geom.str)) {
  28037. textDiv.dataset.isWhitespace = true;
  28038. return;
  28039. }
  28040. var tx = Util.transform(viewport.transform, geom.transform);
  28041. var angle = Math.atan2(tx[1], tx[0]);
  28042. if (style.vertical) {
  28043. angle += Math.PI / 2;
  28044. }
  28045. var fontHeight = Math.sqrt((tx[2] * tx[2]) + (tx[3] * tx[3]));
  28046. var fontAscent = fontHeight;
  28047. if (style.ascent) {
  28048. fontAscent = style.ascent * fontAscent;
  28049. } else if (style.descent) {
  28050. fontAscent = (1 + style.descent) * fontAscent;
  28051. }
  28052. var left;
  28053. var top;
  28054. if (angle === 0) {
  28055. left = tx[4];
  28056. top = tx[5] - fontAscent;
  28057. } else {
  28058. left = tx[4] + (fontAscent * Math.sin(angle));
  28059. top = tx[5] - (fontAscent * Math.cos(angle));
  28060. }
  28061. textDiv.style.left = left + 'px';
  28062. textDiv.style.top = top + 'px';
  28063. textDiv.style.fontSize = fontHeight + 'px';
  28064. textDiv.style.fontFamily = style.fontFamily;
  28065. textDiv.textContent = geom.str;
  28066. // |fontName| is only used by the Font Inspector. This test will succeed
  28067. // when e.g. the Font Inspector is off but the Stepper is on, but it's
  28068. // not worth the effort to do a more accurate test.
  28069. if (PDFJS.pdfBug) {
  28070. textDiv.dataset.fontName = geom.fontName;
  28071. }
  28072. // Storing into dataset will convert number into string.
  28073. if (angle !== 0) {
  28074. textDiv.dataset.angle = angle * (180 / Math.PI);
  28075. }
  28076. // We don't bother scaling single-char text divs, because it has very
  28077. // little effect on text highlighting. This makes scrolling on docs with
  28078. // lots of such divs a lot faster.
  28079. if (geom.str.length > 1) {
  28080. if (style.vertical) {
  28081. textDiv.dataset.canvasWidth = geom.height * viewport.scale;
  28082. } else {
  28083. textDiv.dataset.canvasWidth = geom.width * viewport.scale;
  28084. }
  28085. }
  28086. }
  28087. function render(task) {
  28088. if (task._canceled) {
  28089. return;
  28090. }
  28091. var textLayerFrag = task._container;
  28092. var textDivs = task._textDivs;
  28093. var capability = task._capability;
  28094. var textDivsLength = textDivs.length;
  28095. // No point in rendering many divs as it would make the browser
  28096. // unusable even after the divs are rendered.
  28097. if (textDivsLength > MAX_TEXT_DIVS_TO_RENDER) {
  28098. capability.resolve();
  28099. return;
  28100. }
  28101. var canvas = document.createElement('canvas');
  28102. var ctx = canvas.getContext('2d', {alpha: false});
  28103. var lastFontSize;
  28104. var lastFontFamily;
  28105. for (var i = 0; i < textDivsLength; i++) {
  28106. var textDiv = textDivs[i];
  28107. if (textDiv.dataset.isWhitespace !== undefined) {
  28108. continue;
  28109. }
  28110. var fontSize = textDiv.style.fontSize;
  28111. var fontFamily = textDiv.style.fontFamily;
  28112. // Only build font string and set to context if different from last.
  28113. if (fontSize !== lastFontSize || fontFamily !== lastFontFamily) {
  28114. ctx.font = fontSize + ' ' + fontFamily;
  28115. lastFontSize = fontSize;
  28116. lastFontFamily = fontFamily;
  28117. }
  28118. var width = ctx.measureText(textDiv.textContent).width;
  28119. if (width > 0) {
  28120. textLayerFrag.appendChild(textDiv);
  28121. var transform;
  28122. if (textDiv.dataset.canvasWidth !== undefined) {
  28123. // Dataset values come of type string.
  28124. var textScale = textDiv.dataset.canvasWidth / width;
  28125. transform = 'scaleX(' + textScale + ')';
  28126. } else {
  28127. transform = '';
  28128. }
  28129. var rotation = textDiv.dataset.angle;
  28130. if (rotation) {
  28131. transform = 'rotate(' + rotation + 'deg) ' + transform;
  28132. }
  28133. if (transform) {
  28134. CustomStyle.setProp('transform' , textDiv, transform);
  28135. }
  28136. }
  28137. }
  28138. capability.resolve();
  28139. }
  28140. /**
  28141. * Text layer rendering task.
  28142. *
  28143. * @param {TextContent} textContent
  28144. * @param {HTMLElement} container
  28145. * @param {PDFJS.PageViewport} viewport
  28146. * @param {Array} textDivs
  28147. * @private
  28148. */
  28149. function TextLayerRenderTask(textContent, container, viewport, textDivs) {
  28150. this._textContent = textContent;
  28151. this._container = container;
  28152. this._viewport = viewport;
  28153. textDivs = textDivs || [];
  28154. this._textDivs = textDivs;
  28155. this._canceled = false;
  28156. this._capability = createPromiseCapability();
  28157. this._renderTimer = null;
  28158. }
  28159. TextLayerRenderTask.prototype = {
  28160. get promise() {
  28161. return this._capability.promise;
  28162. },
  28163. cancel: function TextLayer_cancel() {
  28164. this._canceled = true;
  28165. if (this._renderTimer !== null) {
  28166. clearTimeout(this._renderTimer);
  28167. this._renderTimer = null;
  28168. }
  28169. this._capability.reject('canceled');
  28170. },
  28171. _render: function TextLayer_render(timeout) {
  28172. var textItems = this._textContent.items;
  28173. var styles = this._textContent.styles;
  28174. var textDivs = this._textDivs;
  28175. var viewport = this._viewport;
  28176. for (var i = 0, len = textItems.length; i < len; i++) {
  28177. appendText(textDivs, viewport, textItems[i], styles);
  28178. }
  28179. if (!timeout) { // Render right away
  28180. render(this);
  28181. } else { // Schedule
  28182. var self = this;
  28183. this._renderTimer = setTimeout(function() {
  28184. render(self);
  28185. self._renderTimer = null;
  28186. }, timeout);
  28187. }
  28188. }
  28189. };
  28190. /**
  28191. * Starts rendering of the text layer.
  28192. *
  28193. * @param {TextLayerRenderParameters} renderParameters
  28194. * @returns {TextLayerRenderTask}
  28195. */
  28196. function renderTextLayer(renderParameters) {
  28197. var task = new TextLayerRenderTask(renderParameters.textContent,
  28198. renderParameters.container,
  28199. renderParameters.viewport,
  28200. renderParameters.textDivs);
  28201. task._render(renderParameters.timeout);
  28202. return task;
  28203. }
  28204. return renderTextLayer;
  28205. })();
  28206. PDFJS.renderTextLayer = renderTextLayer;
  28207. exports.renderTextLayer = renderTextLayer;
  28208. }));
  28209. (function (root, factory) {
  28210. {
  28211. factory((root.pdfjsCoreCMap = {}), root.pdfjsSharedUtil,
  28212. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser);
  28213. }
  28214. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser) {
  28215. var Util = sharedUtil.Util;
  28216. var assert = sharedUtil.assert;
  28217. var error = sharedUtil.error;
  28218. var isInt = sharedUtil.isInt;
  28219. var isString = sharedUtil.isString;
  28220. var isName = corePrimitives.isName;
  28221. var isCmd = corePrimitives.isCmd;
  28222. var isStream = corePrimitives.isStream;
  28223. var StringStream = coreStream.StringStream;
  28224. var Lexer = coreParser.Lexer;
  28225. var isEOF = coreParser.isEOF;
  28226. var BUILT_IN_CMAPS = [
  28227. // << Start unicode maps.
  28228. 'Adobe-GB1-UCS2',
  28229. 'Adobe-CNS1-UCS2',
  28230. 'Adobe-Japan1-UCS2',
  28231. 'Adobe-Korea1-UCS2',
  28232. // >> End unicode maps.
  28233. '78-EUC-H',
  28234. '78-EUC-V',
  28235. '78-H',
  28236. '78-RKSJ-H',
  28237. '78-RKSJ-V',
  28238. '78-V',
  28239. '78ms-RKSJ-H',
  28240. '78ms-RKSJ-V',
  28241. '83pv-RKSJ-H',
  28242. '90ms-RKSJ-H',
  28243. '90ms-RKSJ-V',
  28244. '90msp-RKSJ-H',
  28245. '90msp-RKSJ-V',
  28246. '90pv-RKSJ-H',
  28247. '90pv-RKSJ-V',
  28248. 'Add-H',
  28249. 'Add-RKSJ-H',
  28250. 'Add-RKSJ-V',
  28251. 'Add-V',
  28252. 'Adobe-CNS1-0',
  28253. 'Adobe-CNS1-1',
  28254. 'Adobe-CNS1-2',
  28255. 'Adobe-CNS1-3',
  28256. 'Adobe-CNS1-4',
  28257. 'Adobe-CNS1-5',
  28258. 'Adobe-CNS1-6',
  28259. 'Adobe-GB1-0',
  28260. 'Adobe-GB1-1',
  28261. 'Adobe-GB1-2',
  28262. 'Adobe-GB1-3',
  28263. 'Adobe-GB1-4',
  28264. 'Adobe-GB1-5',
  28265. 'Adobe-Japan1-0',
  28266. 'Adobe-Japan1-1',
  28267. 'Adobe-Japan1-2',
  28268. 'Adobe-Japan1-3',
  28269. 'Adobe-Japan1-4',
  28270. 'Adobe-Japan1-5',
  28271. 'Adobe-Japan1-6',
  28272. 'Adobe-Korea1-0',
  28273. 'Adobe-Korea1-1',
  28274. 'Adobe-Korea1-2',
  28275. 'B5-H',
  28276. 'B5-V',
  28277. 'B5pc-H',
  28278. 'B5pc-V',
  28279. 'CNS-EUC-H',
  28280. 'CNS-EUC-V',
  28281. 'CNS1-H',
  28282. 'CNS1-V',
  28283. 'CNS2-H',
  28284. 'CNS2-V',
  28285. 'ETHK-B5-H',
  28286. 'ETHK-B5-V',
  28287. 'ETen-B5-H',
  28288. 'ETen-B5-V',
  28289. 'ETenms-B5-H',
  28290. 'ETenms-B5-V',
  28291. 'EUC-H',
  28292. 'EUC-V',
  28293. 'Ext-H',
  28294. 'Ext-RKSJ-H',
  28295. 'Ext-RKSJ-V',
  28296. 'Ext-V',
  28297. 'GB-EUC-H',
  28298. 'GB-EUC-V',
  28299. 'GB-H',
  28300. 'GB-V',
  28301. 'GBK-EUC-H',
  28302. 'GBK-EUC-V',
  28303. 'GBK2K-H',
  28304. 'GBK2K-V',
  28305. 'GBKp-EUC-H',
  28306. 'GBKp-EUC-V',
  28307. 'GBT-EUC-H',
  28308. 'GBT-EUC-V',
  28309. 'GBT-H',
  28310. 'GBT-V',
  28311. 'GBTpc-EUC-H',
  28312. 'GBTpc-EUC-V',
  28313. 'GBpc-EUC-H',
  28314. 'GBpc-EUC-V',
  28315. 'H',
  28316. 'HKdla-B5-H',
  28317. 'HKdla-B5-V',
  28318. 'HKdlb-B5-H',
  28319. 'HKdlb-B5-V',
  28320. 'HKgccs-B5-H',
  28321. 'HKgccs-B5-V',
  28322. 'HKm314-B5-H',
  28323. 'HKm314-B5-V',
  28324. 'HKm471-B5-H',
  28325. 'HKm471-B5-V',
  28326. 'HKscs-B5-H',
  28327. 'HKscs-B5-V',
  28328. 'Hankaku',
  28329. 'Hiragana',
  28330. 'KSC-EUC-H',
  28331. 'KSC-EUC-V',
  28332. 'KSC-H',
  28333. 'KSC-Johab-H',
  28334. 'KSC-Johab-V',
  28335. 'KSC-V',
  28336. 'KSCms-UHC-H',
  28337. 'KSCms-UHC-HW-H',
  28338. 'KSCms-UHC-HW-V',
  28339. 'KSCms-UHC-V',
  28340. 'KSCpc-EUC-H',
  28341. 'KSCpc-EUC-V',
  28342. 'Katakana',
  28343. 'NWP-H',
  28344. 'NWP-V',
  28345. 'RKSJ-H',
  28346. 'RKSJ-V',
  28347. 'Roman',
  28348. 'UniCNS-UCS2-H',
  28349. 'UniCNS-UCS2-V',
  28350. 'UniCNS-UTF16-H',
  28351. 'UniCNS-UTF16-V',
  28352. 'UniCNS-UTF32-H',
  28353. 'UniCNS-UTF32-V',
  28354. 'UniCNS-UTF8-H',
  28355. 'UniCNS-UTF8-V',
  28356. 'UniGB-UCS2-H',
  28357. 'UniGB-UCS2-V',
  28358. 'UniGB-UTF16-H',
  28359. 'UniGB-UTF16-V',
  28360. 'UniGB-UTF32-H',
  28361. 'UniGB-UTF32-V',
  28362. 'UniGB-UTF8-H',
  28363. 'UniGB-UTF8-V',
  28364. 'UniJIS-UCS2-H',
  28365. 'UniJIS-UCS2-HW-H',
  28366. 'UniJIS-UCS2-HW-V',
  28367. 'UniJIS-UCS2-V',
  28368. 'UniJIS-UTF16-H',
  28369. 'UniJIS-UTF16-V',
  28370. 'UniJIS-UTF32-H',
  28371. 'UniJIS-UTF32-V',
  28372. 'UniJIS-UTF8-H',
  28373. 'UniJIS-UTF8-V',
  28374. 'UniJIS2004-UTF16-H',
  28375. 'UniJIS2004-UTF16-V',
  28376. 'UniJIS2004-UTF32-H',
  28377. 'UniJIS2004-UTF32-V',
  28378. 'UniJIS2004-UTF8-H',
  28379. 'UniJIS2004-UTF8-V',
  28380. 'UniJISPro-UCS2-HW-V',
  28381. 'UniJISPro-UCS2-V',
  28382. 'UniJISPro-UTF8-V',
  28383. 'UniJISX0213-UTF32-H',
  28384. 'UniJISX0213-UTF32-V',
  28385. 'UniJISX02132004-UTF32-H',
  28386. 'UniJISX02132004-UTF32-V',
  28387. 'UniKS-UCS2-H',
  28388. 'UniKS-UCS2-V',
  28389. 'UniKS-UTF16-H',
  28390. 'UniKS-UTF16-V',
  28391. 'UniKS-UTF32-H',
  28392. 'UniKS-UTF32-V',
  28393. 'UniKS-UTF8-H',
  28394. 'UniKS-UTF8-V',
  28395. 'V',
  28396. 'WP-Symbol'];
  28397. // CMap, not to be confused with TrueType's cmap.
  28398. var CMap = (function CMapClosure() {
  28399. function CMap(builtInCMap) {
  28400. // Codespace ranges are stored as follows:
  28401. // [[1BytePairs], [2BytePairs], [3BytePairs], [4BytePairs]]
  28402. // where nBytePairs are ranges e.g. [low1, high1, low2, high2, ...]
  28403. this.codespaceRanges = [[], [], [], []];
  28404. this.numCodespaceRanges = 0;
  28405. // Map entries have one of two forms.
  28406. // - cid chars are 16-bit unsigned integers, stored as integers.
  28407. // - bf chars are variable-length byte sequences, stored as strings, with
  28408. // one byte per character.
  28409. this._map = [];
  28410. this.name = '';
  28411. this.vertical = false;
  28412. this.useCMap = null;
  28413. this.builtInCMap = builtInCMap;
  28414. }
  28415. CMap.prototype = {
  28416. addCodespaceRange: function(n, low, high) {
  28417. this.codespaceRanges[n - 1].push(low, high);
  28418. this.numCodespaceRanges++;
  28419. },
  28420. mapCidRange: function(low, high, dstLow) {
  28421. while (low <= high) {
  28422. this._map[low++] = dstLow++;
  28423. }
  28424. },
  28425. mapBfRange: function(low, high, dstLow) {
  28426. var lastByte = dstLow.length - 1;
  28427. while (low <= high) {
  28428. this._map[low++] = dstLow;
  28429. // Only the last byte has to be incremented.
  28430. dstLow = dstLow.substr(0, lastByte) +
  28431. String.fromCharCode(dstLow.charCodeAt(lastByte) + 1);
  28432. }
  28433. },
  28434. mapBfRangeToArray: function(low, high, array) {
  28435. var i = 0, ii = array.length;
  28436. while (low <= high && i < ii) {
  28437. this._map[low] = array[i++];
  28438. ++low;
  28439. }
  28440. },
  28441. // This is used for both bf and cid chars.
  28442. mapOne: function(src, dst) {
  28443. this._map[src] = dst;
  28444. },
  28445. lookup: function(code) {
  28446. return this._map[code];
  28447. },
  28448. contains: function(code) {
  28449. return this._map[code] !== undefined;
  28450. },
  28451. forEach: function(callback) {
  28452. // Most maps have fewer than 65536 entries, and for those we use normal
  28453. // array iteration. But really sparse tables are possible -- e.g. with
  28454. // indices in the *billions*. For such tables we use for..in, which isn't
  28455. // ideal because it stringifies the indices for all present elements, but
  28456. // it does avoid iterating over every undefined entry.
  28457. var map = this._map;
  28458. var length = map.length;
  28459. var i;
  28460. if (length <= 0x10000) {
  28461. for (i = 0; i < length; i++) {
  28462. if (map[i] !== undefined) {
  28463. callback(i, map[i]);
  28464. }
  28465. }
  28466. } else {
  28467. for (i in this._map) {
  28468. callback(i, map[i]);
  28469. }
  28470. }
  28471. },
  28472. charCodeOf: function(value) {
  28473. return this._map.indexOf(value);
  28474. },
  28475. getMap: function() {
  28476. return this._map;
  28477. },
  28478. readCharCode: function(str, offset, out) {
  28479. var c = 0;
  28480. var codespaceRanges = this.codespaceRanges;
  28481. var codespaceRangesLen = this.codespaceRanges.length;
  28482. // 9.7.6.2 CMap Mapping
  28483. // The code length is at most 4.
  28484. for (var n = 0; n < codespaceRangesLen; n++) {
  28485. c = ((c << 8) | str.charCodeAt(offset + n)) >>> 0;
  28486. // Check each codespace range to see if it falls within.
  28487. var codespaceRange = codespaceRanges[n];
  28488. for (var k = 0, kk = codespaceRange.length; k < kk;) {
  28489. var low = codespaceRange[k++];
  28490. var high = codespaceRange[k++];
  28491. if (c >= low && c <= high) {
  28492. out.charcode = c;
  28493. out.length = n + 1;
  28494. return;
  28495. }
  28496. }
  28497. }
  28498. out.charcode = 0;
  28499. out.length = 1;
  28500. },
  28501. get length() {
  28502. return this._map.length;
  28503. },
  28504. get isIdentityCMap() {
  28505. if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
  28506. return false;
  28507. }
  28508. if (this._map.length !== 0x10000) {
  28509. return false;
  28510. }
  28511. for (var i = 0; i < 0x10000; i++) {
  28512. if (this._map[i] !== i) {
  28513. return false;
  28514. }
  28515. }
  28516. return true;
  28517. }
  28518. };
  28519. return CMap;
  28520. })();
  28521. // A special case of CMap, where the _map array implicitly has a length of
  28522. // 65536 and each element is equal to its index.
  28523. var IdentityCMap = (function IdentityCMapClosure() {
  28524. function IdentityCMap(vertical, n) {
  28525. CMap.call(this);
  28526. this.vertical = vertical;
  28527. this.addCodespaceRange(n, 0, 0xffff);
  28528. }
  28529. Util.inherit(IdentityCMap, CMap, {});
  28530. IdentityCMap.prototype = {
  28531. addCodespaceRange: CMap.prototype.addCodespaceRange,
  28532. mapCidRange: function(low, high, dstLow) {
  28533. error('should not call mapCidRange');
  28534. },
  28535. mapBfRange: function(low, high, dstLow) {
  28536. error('should not call mapBfRange');
  28537. },
  28538. mapBfRangeToArray: function(low, high, array) {
  28539. error('should not call mapBfRangeToArray');
  28540. },
  28541. mapOne: function(src, dst) {
  28542. error('should not call mapCidOne');
  28543. },
  28544. lookup: function(code) {
  28545. return (isInt(code) && code <= 0xffff) ? code : undefined;
  28546. },
  28547. contains: function(code) {
  28548. return isInt(code) && code <= 0xffff;
  28549. },
  28550. forEach: function(callback) {
  28551. for (var i = 0; i <= 0xffff; i++) {
  28552. callback(i, i);
  28553. }
  28554. },
  28555. charCodeOf: function(value) {
  28556. return (isInt(value) && value <= 0xffff) ? value : -1;
  28557. },
  28558. getMap: function() {
  28559. // Sometimes identity maps must be instantiated, but it's rare.
  28560. var map = new Array(0x10000);
  28561. for (var i = 0; i <= 0xffff; i++) {
  28562. map[i] = i;
  28563. }
  28564. return map;
  28565. },
  28566. readCharCode: CMap.prototype.readCharCode,
  28567. get length() {
  28568. return 0x10000;
  28569. },
  28570. get isIdentityCMap() {
  28571. error('should not access .isIdentityCMap');
  28572. }
  28573. };
  28574. return IdentityCMap;
  28575. })();
  28576. var BinaryCMapReader = (function BinaryCMapReaderClosure() {
  28577. function fetchBinaryData(url) {
  28578. return new Promise(function (resolve, reject) {
  28579. var request = new XMLHttpRequest();
  28580. request.open('GET', url, true);
  28581. request.responseType = 'arraybuffer';
  28582. request.onreadystatechange = function () {
  28583. if (request.readyState === XMLHttpRequest.DONE) {
  28584. if (!request.response || request.status !== 200 &&
  28585. request.status !== 0) {
  28586. reject(new Error('Unable to get binary cMap at: ' + url));
  28587. } else {
  28588. resolve(new Uint8Array(request.response));
  28589. }
  28590. }
  28591. };
  28592. request.send(null);
  28593. });
  28594. }
  28595. function hexToInt(a, size) {
  28596. var n = 0;
  28597. for (var i = 0; i <= size; i++) {
  28598. n = (n << 8) | a[i];
  28599. }
  28600. return n >>> 0;
  28601. }
  28602. function hexToStr(a, size) {
  28603. // This code is hot. Special-case some common values to avoid creating an
  28604. // object with subarray().
  28605. if (size === 1) {
  28606. return String.fromCharCode(a[0], a[1]);
  28607. }
  28608. if (size === 3) {
  28609. return String.fromCharCode(a[0], a[1], a[2], a[3]);
  28610. }
  28611. return String.fromCharCode.apply(null, a.subarray(0, size + 1));
  28612. }
  28613. function addHex(a, b, size) {
  28614. var c = 0;
  28615. for (var i = size; i >= 0; i--) {
  28616. c += a[i] + b[i];
  28617. a[i] = c & 255;
  28618. c >>= 8;
  28619. }
  28620. }
  28621. function incHex(a, size) {
  28622. var c = 1;
  28623. for (var i = size; i >= 0 && c > 0; i--) {
  28624. c += a[i];
  28625. a[i] = c & 255;
  28626. c >>= 8;
  28627. }
  28628. }
  28629. var MAX_NUM_SIZE = 16;
  28630. var MAX_ENCODED_NUM_SIZE = 19; // ceil(MAX_NUM_SIZE * 7 / 8)
  28631. function BinaryCMapStream(data) {
  28632. this.buffer = data;
  28633. this.pos = 0;
  28634. this.end = data.length;
  28635. this.tmpBuf = new Uint8Array(MAX_ENCODED_NUM_SIZE);
  28636. }
  28637. BinaryCMapStream.prototype = {
  28638. readByte: function () {
  28639. if (this.pos >= this.end) {
  28640. return -1;
  28641. }
  28642. return this.buffer[this.pos++];
  28643. },
  28644. readNumber: function () {
  28645. var n = 0;
  28646. var last;
  28647. do {
  28648. var b = this.readByte();
  28649. if (b < 0) {
  28650. error('unexpected EOF in bcmap');
  28651. }
  28652. last = !(b & 0x80);
  28653. n = (n << 7) | (b & 0x7F);
  28654. } while (!last);
  28655. return n;
  28656. },
  28657. readSigned: function () {
  28658. var n = this.readNumber();
  28659. return (n & 1) ? ~(n >>> 1) : n >>> 1;
  28660. },
  28661. readHex: function (num, size) {
  28662. num.set(this.buffer.subarray(this.pos,
  28663. this.pos + size + 1));
  28664. this.pos += size + 1;
  28665. },
  28666. readHexNumber: function (num, size) {
  28667. var last;
  28668. var stack = this.tmpBuf, sp = 0;
  28669. do {
  28670. var b = this.readByte();
  28671. if (b < 0) {
  28672. error('unexpected EOF in bcmap');
  28673. }
  28674. last = !(b & 0x80);
  28675. stack[sp++] = b & 0x7F;
  28676. } while (!last);
  28677. var i = size, buffer = 0, bufferSize = 0;
  28678. while (i >= 0) {
  28679. while (bufferSize < 8 && stack.length > 0) {
  28680. buffer = (stack[--sp] << bufferSize) | buffer;
  28681. bufferSize += 7;
  28682. }
  28683. num[i] = buffer & 255;
  28684. i--;
  28685. buffer >>= 8;
  28686. bufferSize -= 8;
  28687. }
  28688. },
  28689. readHexSigned: function (num, size) {
  28690. this.readHexNumber(num, size);
  28691. var sign = num[size] & 1 ? 255 : 0;
  28692. var c = 0;
  28693. for (var i = 0; i <= size; i++) {
  28694. c = ((c & 1) << 8) | num[i];
  28695. num[i] = (c >> 1) ^ sign;
  28696. }
  28697. },
  28698. readString: function () {
  28699. var len = this.readNumber();
  28700. var s = '';
  28701. for (var i = 0; i < len; i++) {
  28702. s += String.fromCharCode(this.readNumber());
  28703. }
  28704. return s;
  28705. }
  28706. };
  28707. function processBinaryCMap(url, cMap, extend) {
  28708. return fetchBinaryData(url).then(function (data) {
  28709. var stream = new BinaryCMapStream(data);
  28710. var header = stream.readByte();
  28711. cMap.vertical = !!(header & 1);
  28712. var useCMap = null;
  28713. var start = new Uint8Array(MAX_NUM_SIZE);
  28714. var end = new Uint8Array(MAX_NUM_SIZE);
  28715. var char = new Uint8Array(MAX_NUM_SIZE);
  28716. var charCode = new Uint8Array(MAX_NUM_SIZE);
  28717. var tmp = new Uint8Array(MAX_NUM_SIZE);
  28718. var code;
  28719. var b;
  28720. while ((b = stream.readByte()) >= 0) {
  28721. var type = b >> 5;
  28722. if (type === 7) { // metadata, e.g. comment or usecmap
  28723. switch (b & 0x1F) {
  28724. case 0:
  28725. stream.readString(); // skipping comment
  28726. break;
  28727. case 1:
  28728. useCMap = stream.readString();
  28729. break;
  28730. }
  28731. continue;
  28732. }
  28733. var sequence = !!(b & 0x10);
  28734. var dataSize = b & 15;
  28735. assert(dataSize + 1 <= MAX_NUM_SIZE);
  28736. var ucs2DataSize = 1;
  28737. var subitemsCount = stream.readNumber();
  28738. var i;
  28739. switch (type) {
  28740. case 0: // codespacerange
  28741. stream.readHex(start, dataSize);
  28742. stream.readHexNumber(end, dataSize);
  28743. addHex(end, start, dataSize);
  28744. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  28745. hexToInt(end, dataSize));
  28746. for (i = 1; i < subitemsCount; i++) {
  28747. incHex(end, dataSize);
  28748. stream.readHexNumber(start, dataSize);
  28749. addHex(start, end, dataSize);
  28750. stream.readHexNumber(end, dataSize);
  28751. addHex(end, start, dataSize);
  28752. cMap.addCodespaceRange(dataSize + 1, hexToInt(start, dataSize),
  28753. hexToInt(end, dataSize));
  28754. }
  28755. break;
  28756. case 1: // notdefrange
  28757. stream.readHex(start, dataSize);
  28758. stream.readHexNumber(end, dataSize);
  28759. addHex(end, start, dataSize);
  28760. code = stream.readNumber();
  28761. // undefined range, skipping
  28762. for (i = 1; i < subitemsCount; i++) {
  28763. incHex(end, dataSize);
  28764. stream.readHexNumber(start, dataSize);
  28765. addHex(start, end, dataSize);
  28766. stream.readHexNumber(end, dataSize);
  28767. addHex(end, start, dataSize);
  28768. code = stream.readNumber();
  28769. // nop
  28770. }
  28771. break;
  28772. case 2: // cidchar
  28773. stream.readHex(char, dataSize);
  28774. code = stream.readNumber();
  28775. cMap.mapOne(hexToInt(char, dataSize), code);
  28776. for (i = 1; i < subitemsCount; i++) {
  28777. incHex(char, dataSize);
  28778. if (!sequence) {
  28779. stream.readHexNumber(tmp, dataSize);
  28780. addHex(char, tmp, dataSize);
  28781. }
  28782. code = stream.readSigned() + (code + 1);
  28783. cMap.mapOne(hexToInt(char, dataSize), code);
  28784. }
  28785. break;
  28786. case 3: // cidrange
  28787. stream.readHex(start, dataSize);
  28788. stream.readHexNumber(end, dataSize);
  28789. addHex(end, start, dataSize);
  28790. code = stream.readNumber();
  28791. cMap.mapCidRange(hexToInt(start, dataSize), hexToInt(end, dataSize),
  28792. code);
  28793. for (i = 1; i < subitemsCount; i++) {
  28794. incHex(end, dataSize);
  28795. if (!sequence) {
  28796. stream.readHexNumber(start, dataSize);
  28797. addHex(start, end, dataSize);
  28798. } else {
  28799. start.set(end);
  28800. }
  28801. stream.readHexNumber(end, dataSize);
  28802. addHex(end, start, dataSize);
  28803. code = stream.readNumber();
  28804. cMap.mapCidRange(hexToInt(start, dataSize),
  28805. hexToInt(end, dataSize), code);
  28806. }
  28807. break;
  28808. case 4: // bfchar
  28809. stream.readHex(char, ucs2DataSize);
  28810. stream.readHex(charCode, dataSize);
  28811. cMap.mapOne(hexToInt(char, ucs2DataSize),
  28812. hexToStr(charCode, dataSize));
  28813. for (i = 1; i < subitemsCount; i++) {
  28814. incHex(char, ucs2DataSize);
  28815. if (!sequence) {
  28816. stream.readHexNumber(tmp, ucs2DataSize);
  28817. addHex(char, tmp, ucs2DataSize);
  28818. }
  28819. incHex(charCode, dataSize);
  28820. stream.readHexSigned(tmp, dataSize);
  28821. addHex(charCode, tmp, dataSize);
  28822. cMap.mapOne(hexToInt(char, ucs2DataSize),
  28823. hexToStr(charCode, dataSize));
  28824. }
  28825. break;
  28826. case 5: // bfrange
  28827. stream.readHex(start, ucs2DataSize);
  28828. stream.readHexNumber(end, ucs2DataSize);
  28829. addHex(end, start, ucs2DataSize);
  28830. stream.readHex(charCode, dataSize);
  28831. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  28832. hexToInt(end, ucs2DataSize),
  28833. hexToStr(charCode, dataSize));
  28834. for (i = 1; i < subitemsCount; i++) {
  28835. incHex(end, ucs2DataSize);
  28836. if (!sequence) {
  28837. stream.readHexNumber(start, ucs2DataSize);
  28838. addHex(start, end, ucs2DataSize);
  28839. } else {
  28840. start.set(end);
  28841. }
  28842. stream.readHexNumber(end, ucs2DataSize);
  28843. addHex(end, start, ucs2DataSize);
  28844. stream.readHex(charCode, dataSize);
  28845. cMap.mapBfRange(hexToInt(start, ucs2DataSize),
  28846. hexToInt(end, ucs2DataSize),
  28847. hexToStr(charCode, dataSize));
  28848. }
  28849. break;
  28850. default:
  28851. error('Unknown type: ' + type);
  28852. break;
  28853. }
  28854. }
  28855. if (useCMap) {
  28856. return extend(useCMap);
  28857. }
  28858. return cMap;
  28859. });
  28860. }
  28861. function BinaryCMapReader() {}
  28862. BinaryCMapReader.prototype = {
  28863. read: processBinaryCMap
  28864. };
  28865. return BinaryCMapReader;
  28866. })();
  28867. var CMapFactory = (function CMapFactoryClosure() {
  28868. function strToInt(str) {
  28869. var a = 0;
  28870. for (var i = 0; i < str.length; i++) {
  28871. a = (a << 8) | str.charCodeAt(i);
  28872. }
  28873. return a >>> 0;
  28874. }
  28875. function expectString(obj) {
  28876. if (!isString(obj)) {
  28877. error('Malformed CMap: expected string.');
  28878. }
  28879. }
  28880. function expectInt(obj) {
  28881. if (!isInt(obj)) {
  28882. error('Malformed CMap: expected int.');
  28883. }
  28884. }
  28885. function parseBfChar(cMap, lexer) {
  28886. while (true) {
  28887. var obj = lexer.getObj();
  28888. if (isEOF(obj)) {
  28889. break;
  28890. }
  28891. if (isCmd(obj, 'endbfchar')) {
  28892. return;
  28893. }
  28894. expectString(obj);
  28895. var src = strToInt(obj);
  28896. obj = lexer.getObj();
  28897. // TODO are /dstName used?
  28898. expectString(obj);
  28899. var dst = obj;
  28900. cMap.mapOne(src, dst);
  28901. }
  28902. }
  28903. function parseBfRange(cMap, lexer) {
  28904. while (true) {
  28905. var obj = lexer.getObj();
  28906. if (isEOF(obj)) {
  28907. break;
  28908. }
  28909. if (isCmd(obj, 'endbfrange')) {
  28910. return;
  28911. }
  28912. expectString(obj);
  28913. var low = strToInt(obj);
  28914. obj = lexer.getObj();
  28915. expectString(obj);
  28916. var high = strToInt(obj);
  28917. obj = lexer.getObj();
  28918. if (isInt(obj) || isString(obj)) {
  28919. var dstLow = isInt(obj) ? String.fromCharCode(obj) : obj;
  28920. cMap.mapBfRange(low, high, dstLow);
  28921. } else if (isCmd(obj, '[')) {
  28922. obj = lexer.getObj();
  28923. var array = [];
  28924. while (!isCmd(obj, ']') && !isEOF(obj)) {
  28925. array.push(obj);
  28926. obj = lexer.getObj();
  28927. }
  28928. cMap.mapBfRangeToArray(low, high, array);
  28929. } else {
  28930. break;
  28931. }
  28932. }
  28933. error('Invalid bf range.');
  28934. }
  28935. function parseCidChar(cMap, lexer) {
  28936. while (true) {
  28937. var obj = lexer.getObj();
  28938. if (isEOF(obj)) {
  28939. break;
  28940. }
  28941. if (isCmd(obj, 'endcidchar')) {
  28942. return;
  28943. }
  28944. expectString(obj);
  28945. var src = strToInt(obj);
  28946. obj = lexer.getObj();
  28947. expectInt(obj);
  28948. var dst = obj;
  28949. cMap.mapOne(src, dst);
  28950. }
  28951. }
  28952. function parseCidRange(cMap, lexer) {
  28953. while (true) {
  28954. var obj = lexer.getObj();
  28955. if (isEOF(obj)) {
  28956. break;
  28957. }
  28958. if (isCmd(obj, 'endcidrange')) {
  28959. return;
  28960. }
  28961. expectString(obj);
  28962. var low = strToInt(obj);
  28963. obj = lexer.getObj();
  28964. expectString(obj);
  28965. var high = strToInt(obj);
  28966. obj = lexer.getObj();
  28967. expectInt(obj);
  28968. var dstLow = obj;
  28969. cMap.mapCidRange(low, high, dstLow);
  28970. }
  28971. }
  28972. function parseCodespaceRange(cMap, lexer) {
  28973. while (true) {
  28974. var obj = lexer.getObj();
  28975. if (isEOF(obj)) {
  28976. break;
  28977. }
  28978. if (isCmd(obj, 'endcodespacerange')) {
  28979. return;
  28980. }
  28981. if (!isString(obj)) {
  28982. break;
  28983. }
  28984. var low = strToInt(obj);
  28985. obj = lexer.getObj();
  28986. if (!isString(obj)) {
  28987. break;
  28988. }
  28989. var high = strToInt(obj);
  28990. cMap.addCodespaceRange(obj.length, low, high);
  28991. }
  28992. error('Invalid codespace range.');
  28993. }
  28994. function parseWMode(cMap, lexer) {
  28995. var obj = lexer.getObj();
  28996. if (isInt(obj)) {
  28997. cMap.vertical = !!obj;
  28998. }
  28999. }
  29000. function parseCMapName(cMap, lexer) {
  29001. var obj = lexer.getObj();
  29002. if (isName(obj) && isString(obj.name)) {
  29003. cMap.name = obj.name;
  29004. }
  29005. }
  29006. function parseCMap(cMap, lexer, builtInCMapParams, useCMap) {
  29007. var previous;
  29008. var embededUseCMap;
  29009. objLoop: while (true) {
  29010. var obj = lexer.getObj();
  29011. if (isEOF(obj)) {
  29012. break;
  29013. } else if (isName(obj)) {
  29014. if (obj.name === 'WMode') {
  29015. parseWMode(cMap, lexer);
  29016. } else if (obj.name === 'CMapName') {
  29017. parseCMapName(cMap, lexer);
  29018. }
  29019. previous = obj;
  29020. } else if (isCmd(obj)) {
  29021. switch (obj.cmd) {
  29022. case 'endcmap':
  29023. break objLoop;
  29024. case 'usecmap':
  29025. if (isName(previous)) {
  29026. embededUseCMap = previous.name;
  29027. }
  29028. break;
  29029. case 'begincodespacerange':
  29030. parseCodespaceRange(cMap, lexer);
  29031. break;
  29032. case 'beginbfchar':
  29033. parseBfChar(cMap, lexer);
  29034. break;
  29035. case 'begincidchar':
  29036. parseCidChar(cMap, lexer);
  29037. break;
  29038. case 'beginbfrange':
  29039. parseBfRange(cMap, lexer);
  29040. break;
  29041. case 'begincidrange':
  29042. parseCidRange(cMap, lexer);
  29043. break;
  29044. }
  29045. }
  29046. }
  29047. if (!useCMap && embededUseCMap) {
  29048. // Load the usecmap definition from the file only if there wasn't one
  29049. // specified.
  29050. useCMap = embededUseCMap;
  29051. }
  29052. if (useCMap) {
  29053. return extendCMap(cMap, builtInCMapParams, useCMap);
  29054. } else {
  29055. return Promise.resolve(cMap);
  29056. }
  29057. }
  29058. function extendCMap(cMap, builtInCMapParams, useCMap) {
  29059. return createBuiltInCMap(useCMap, builtInCMapParams).then(
  29060. function(newCMap) {
  29061. cMap.useCMap = newCMap;
  29062. // If there aren't any code space ranges defined clone all the parent ones
  29063. // into this cMap.
  29064. if (cMap.numCodespaceRanges === 0) {
  29065. var useCodespaceRanges = cMap.useCMap.codespaceRanges;
  29066. for (var i = 0; i < useCodespaceRanges.length; i++) {
  29067. cMap.codespaceRanges[i] = useCodespaceRanges[i].slice();
  29068. }
  29069. cMap.numCodespaceRanges = cMap.useCMap.numCodespaceRanges;
  29070. }
  29071. // Merge the map into the current one, making sure not to override
  29072. // any previously defined entries.
  29073. cMap.useCMap.forEach(function(key, value) {
  29074. if (!cMap.contains(key)) {
  29075. cMap.mapOne(key, cMap.useCMap.lookup(key));
  29076. }
  29077. });
  29078. return cMap;
  29079. });
  29080. }
  29081. function parseBinaryCMap(name, builtInCMapParams) {
  29082. var url = builtInCMapParams.url + name + '.bcmap';
  29083. var cMap = new CMap(true);
  29084. return new BinaryCMapReader().read(url, cMap, function (useCMap) {
  29085. return extendCMap(cMap, builtInCMapParams, useCMap);
  29086. });
  29087. }
  29088. function createBuiltInCMap(name, builtInCMapParams) {
  29089. if (name === 'Identity-H') {
  29090. return Promise.resolve(new IdentityCMap(false, 2));
  29091. } else if (name === 'Identity-V') {
  29092. return Promise.resolve(new IdentityCMap(true, 2));
  29093. }
  29094. if (BUILT_IN_CMAPS.indexOf(name) === -1) {
  29095. return Promise.reject(new Error('Unknown cMap name: ' + name));
  29096. }
  29097. assert(builtInCMapParams, 'built-in cMap parameters are not provided');
  29098. if (builtInCMapParams.packed) {
  29099. return parseBinaryCMap(name, builtInCMapParams);
  29100. }
  29101. return new Promise(function (resolve, reject) {
  29102. var url = builtInCMapParams.url + name;
  29103. var request = new XMLHttpRequest();
  29104. request.onreadystatechange = function () {
  29105. if (request.readyState === XMLHttpRequest.DONE) {
  29106. if (request.status === 200 || request.status === 0) {
  29107. var cMap = new CMap(true);
  29108. var lexer = new Lexer(new StringStream(request.responseText));
  29109. parseCMap(cMap, lexer, builtInCMapParams, null).then(
  29110. function (parsedCMap) {
  29111. resolve(parsedCMap);
  29112. }).catch(function (e) {
  29113. reject(new Error({ message: 'Invalid CMap data', error: e }));
  29114. });
  29115. } else {
  29116. reject(new Error('Unable to get cMap at: ' + url));
  29117. }
  29118. }
  29119. };
  29120. request.open('GET', url, true);
  29121. request.send(null);
  29122. });
  29123. }
  29124. return {
  29125. create: function (encoding, builtInCMapParams, useCMap) {
  29126. if (isName(encoding)) {
  29127. return createBuiltInCMap(encoding.name, builtInCMapParams);
  29128. } else if (isStream(encoding)) {
  29129. var cMap = new CMap();
  29130. var lexer = new Lexer(encoding);
  29131. return parseCMap(cMap, lexer, builtInCMapParams, useCMap).then(
  29132. function (parsedCMap) {
  29133. if (parsedCMap.isIdentityCMap) {
  29134. return createBuiltInCMap(parsedCMap.name, builtInCMapParams);
  29135. }
  29136. return parsedCMap;
  29137. });
  29138. }
  29139. return Promise.reject(new Error('Encoding required.'));
  29140. }
  29141. };
  29142. })();
  29143. exports.CMap = CMap;
  29144. exports.CMapFactory = CMapFactory;
  29145. exports.IdentityCMap = IdentityCMap;
  29146. }));
  29147. (function (root, factory) {
  29148. {
  29149. factory((root.pdfjsCorePsParser = {}), root.pdfjsSharedUtil,
  29150. root.pdfjsCoreParser);
  29151. }
  29152. }(this, function (exports, sharedUtil, coreParser) {
  29153. var error = sharedUtil.error;
  29154. var EOF = coreParser.EOF;
  29155. var Lexer = coreParser.Lexer;
  29156. var PostScriptParser = (function PostScriptParserClosure() {
  29157. function PostScriptParser(lexer) {
  29158. this.lexer = lexer;
  29159. this.operators = [];
  29160. this.token = null;
  29161. this.prev = null;
  29162. }
  29163. PostScriptParser.prototype = {
  29164. nextToken: function PostScriptParser_nextToken() {
  29165. this.prev = this.token;
  29166. this.token = this.lexer.getToken();
  29167. },
  29168. accept: function PostScriptParser_accept(type) {
  29169. if (this.token.type === type) {
  29170. this.nextToken();
  29171. return true;
  29172. }
  29173. return false;
  29174. },
  29175. expect: function PostScriptParser_expect(type) {
  29176. if (this.accept(type)) {
  29177. return true;
  29178. }
  29179. error('Unexpected symbol: found ' + this.token.type + ' expected ' +
  29180. type + '.');
  29181. },
  29182. parse: function PostScriptParser_parse() {
  29183. this.nextToken();
  29184. this.expect(PostScriptTokenTypes.LBRACE);
  29185. this.parseBlock();
  29186. this.expect(PostScriptTokenTypes.RBRACE);
  29187. return this.operators;
  29188. },
  29189. parseBlock: function PostScriptParser_parseBlock() {
  29190. while (true) {
  29191. if (this.accept(PostScriptTokenTypes.NUMBER)) {
  29192. this.operators.push(this.prev.value);
  29193. } else if (this.accept(PostScriptTokenTypes.OPERATOR)) {
  29194. this.operators.push(this.prev.value);
  29195. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29196. this.parseCondition();
  29197. } else {
  29198. return;
  29199. }
  29200. }
  29201. },
  29202. parseCondition: function PostScriptParser_parseCondition() {
  29203. // Add two place holders that will be updated later
  29204. var conditionLocation = this.operators.length;
  29205. this.operators.push(null, null);
  29206. this.parseBlock();
  29207. this.expect(PostScriptTokenTypes.RBRACE);
  29208. if (this.accept(PostScriptTokenTypes.IF)) {
  29209. // The true block is right after the 'if' so it just falls through on
  29210. // true else it jumps and skips the true block.
  29211. this.operators[conditionLocation] = this.operators.length;
  29212. this.operators[conditionLocation + 1] = 'jz';
  29213. } else if (this.accept(PostScriptTokenTypes.LBRACE)) {
  29214. var jumpLocation = this.operators.length;
  29215. this.operators.push(null, null);
  29216. var endOfTrue = this.operators.length;
  29217. this.parseBlock();
  29218. this.expect(PostScriptTokenTypes.RBRACE);
  29219. this.expect(PostScriptTokenTypes.IFELSE);
  29220. // The jump is added at the end of the true block to skip the false
  29221. // block.
  29222. this.operators[jumpLocation] = this.operators.length;
  29223. this.operators[jumpLocation + 1] = 'j';
  29224. this.operators[conditionLocation] = endOfTrue;
  29225. this.operators[conditionLocation + 1] = 'jz';
  29226. } else {
  29227. error('PS Function: error parsing conditional.');
  29228. }
  29229. }
  29230. };
  29231. return PostScriptParser;
  29232. })();
  29233. var PostScriptTokenTypes = {
  29234. LBRACE: 0,
  29235. RBRACE: 1,
  29236. NUMBER: 2,
  29237. OPERATOR: 3,
  29238. IF: 4,
  29239. IFELSE: 5
  29240. };
  29241. var PostScriptToken = (function PostScriptTokenClosure() {
  29242. function PostScriptToken(type, value) {
  29243. this.type = type;
  29244. this.value = value;
  29245. }
  29246. var opCache = Object.create(null);
  29247. PostScriptToken.getOperator = function PostScriptToken_getOperator(op) {
  29248. var opValue = opCache[op];
  29249. if (opValue) {
  29250. return opValue;
  29251. }
  29252. return opCache[op] = new PostScriptToken(PostScriptTokenTypes.OPERATOR, op);
  29253. };
  29254. PostScriptToken.LBRACE = new PostScriptToken(PostScriptTokenTypes.LBRACE,
  29255. '{');
  29256. PostScriptToken.RBRACE = new PostScriptToken(PostScriptTokenTypes.RBRACE,
  29257. '}');
  29258. PostScriptToken.IF = new PostScriptToken(PostScriptTokenTypes.IF, 'IF');
  29259. PostScriptToken.IFELSE = new PostScriptToken(PostScriptTokenTypes.IFELSE,
  29260. 'IFELSE');
  29261. return PostScriptToken;
  29262. })();
  29263. var PostScriptLexer = (function PostScriptLexerClosure() {
  29264. function PostScriptLexer(stream) {
  29265. this.stream = stream;
  29266. this.nextChar();
  29267. this.strBuf = [];
  29268. }
  29269. PostScriptLexer.prototype = {
  29270. nextChar: function PostScriptLexer_nextChar() {
  29271. return (this.currentChar = this.stream.getByte());
  29272. },
  29273. getToken: function PostScriptLexer_getToken() {
  29274. var comment = false;
  29275. var ch = this.currentChar;
  29276. // skip comments
  29277. while (true) {
  29278. if (ch < 0) {
  29279. return EOF;
  29280. }
  29281. if (comment) {
  29282. if (ch === 0x0A || ch === 0x0D) {
  29283. comment = false;
  29284. }
  29285. } else if (ch === 0x25) { // '%'
  29286. comment = true;
  29287. } else if (!Lexer.isSpace(ch)) {
  29288. break;
  29289. }
  29290. ch = this.nextChar();
  29291. }
  29292. switch (ch | 0) {
  29293. case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: // '0'-'4'
  29294. case 0x35: case 0x36: case 0x37: case 0x38: case 0x39: // '5'-'9'
  29295. case 0x2B: case 0x2D: case 0x2E: // '+', '-', '.'
  29296. return new PostScriptToken(PostScriptTokenTypes.NUMBER,
  29297. this.getNumber());
  29298. case 0x7B: // '{'
  29299. this.nextChar();
  29300. return PostScriptToken.LBRACE;
  29301. case 0x7D: // '}'
  29302. this.nextChar();
  29303. return PostScriptToken.RBRACE;
  29304. }
  29305. // operator
  29306. var strBuf = this.strBuf;
  29307. strBuf.length = 0;
  29308. strBuf[0] = String.fromCharCode(ch);
  29309. while ((ch = this.nextChar()) >= 0 && // and 'A'-'Z', 'a'-'z'
  29310. ((ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A))) {
  29311. strBuf.push(String.fromCharCode(ch));
  29312. }
  29313. var str = strBuf.join('');
  29314. switch (str.toLowerCase()) {
  29315. case 'if':
  29316. return PostScriptToken.IF;
  29317. case 'ifelse':
  29318. return PostScriptToken.IFELSE;
  29319. default:
  29320. return PostScriptToken.getOperator(str);
  29321. }
  29322. },
  29323. getNumber: function PostScriptLexer_getNumber() {
  29324. var ch = this.currentChar;
  29325. var strBuf = this.strBuf;
  29326. strBuf.length = 0;
  29327. strBuf[0] = String.fromCharCode(ch);
  29328. while ((ch = this.nextChar()) >= 0) {
  29329. if ((ch >= 0x30 && ch <= 0x39) || // '0'-'9'
  29330. ch === 0x2D || ch === 0x2E) { // '-', '.'
  29331. strBuf.push(String.fromCharCode(ch));
  29332. } else {
  29333. break;
  29334. }
  29335. }
  29336. var value = parseFloat(strBuf.join(''));
  29337. if (isNaN(value)) {
  29338. error('Invalid floating point number: ' + value);
  29339. }
  29340. return value;
  29341. }
  29342. };
  29343. return PostScriptLexer;
  29344. })();
  29345. exports.PostScriptLexer = PostScriptLexer;
  29346. exports.PostScriptParser = PostScriptParser;
  29347. }));
  29348. (function (root, factory) {
  29349. {
  29350. factory((root.pdfjsCoreType1Parser = {}), root.pdfjsSharedUtil,
  29351. root.pdfjsCoreStream, root.pdfjsCoreParser, root.pdfjsCoreEncodings);
  29352. }
  29353. }(this, function (exports, sharedUtil, coreStream, coreParser, coreEncodings) {
  29354. var warn = sharedUtil.warn;
  29355. var Stream = coreStream.Stream;
  29356. var Lexer = coreParser.Lexer;
  29357. var getEncoding = coreEncodings.getEncoding;
  29358. // Hinting is currently disabled due to unknown problems on windows
  29359. // in tracemonkey and various other pdfs with type1 fonts.
  29360. var HINTING_ENABLED = false;
  29361. /*
  29362. * CharStrings are encoded following the the CharString Encoding sequence
  29363. * describe in Chapter 6 of the "Adobe Type1 Font Format" specification.
  29364. * The value in a byte indicates a command, a number, or subsequent bytes
  29365. * that are to be interpreted in a special way.
  29366. *
  29367. * CharString Number Encoding:
  29368. * A CharString byte containing the values from 32 through 255 inclusive
  29369. * indicate an integer. These values are decoded in four ranges.
  29370. *
  29371. * 1. A CharString byte containing a value, v, between 32 and 246 inclusive,
  29372. * indicate the integer v - 139. Thus, the integer values from -107 through
  29373. * 107 inclusive may be encoded in single byte.
  29374. *
  29375. * 2. A CharString byte containing a value, v, between 247 and 250 inclusive,
  29376. * indicates an integer involving the next byte, w, according to the formula:
  29377. * [(v - 247) x 256] + w + 108
  29378. *
  29379. * 3. A CharString byte containing a value, v, between 251 and 254 inclusive,
  29380. * indicates an integer involving the next byte, w, according to the formula:
  29381. * -[(v - 251) * 256] - w - 108
  29382. *
  29383. * 4. A CharString containing the value 255 indicates that the next 4 bytes
  29384. * are a two complement signed integer. The first of these bytes contains the
  29385. * highest order bits, the second byte contains the next higher order bits
  29386. * and the fourth byte contain the lowest order bits.
  29387. *
  29388. *
  29389. * CharString Command Encoding:
  29390. * CharStrings commands are encoded in 1 or 2 bytes.
  29391. *
  29392. * Single byte commands are encoded in 1 byte that contains a value between
  29393. * 0 and 31 inclusive.
  29394. * If a command byte contains the value 12, then the value in the next byte
  29395. * indicates a command. This "escape" mechanism allows many extra commands
  29396. * to be encoded and this encoding technique helps to minimize the length of
  29397. * the charStrings.
  29398. */
  29399. var Type1CharString = (function Type1CharStringClosure() {
  29400. var COMMAND_MAP = {
  29401. 'hstem': [1],
  29402. 'vstem': [3],
  29403. 'vmoveto': [4],
  29404. 'rlineto': [5],
  29405. 'hlineto': [6],
  29406. 'vlineto': [7],
  29407. 'rrcurveto': [8],
  29408. 'callsubr': [10],
  29409. 'flex': [12, 35],
  29410. 'drop' : [12, 18],
  29411. 'endchar': [14],
  29412. 'rmoveto': [21],
  29413. 'hmoveto': [22],
  29414. 'vhcurveto': [30],
  29415. 'hvcurveto': [31]
  29416. };
  29417. function Type1CharString() {
  29418. this.width = 0;
  29419. this.lsb = 0;
  29420. this.flexing = false;
  29421. this.output = [];
  29422. this.stack = [];
  29423. }
  29424. Type1CharString.prototype = {
  29425. convert: function Type1CharString_convert(encoded, subrs,
  29426. seacAnalysisEnabled) {
  29427. var count = encoded.length;
  29428. var error = false;
  29429. var wx, sbx, subrNumber;
  29430. for (var i = 0; i < count; i++) {
  29431. var value = encoded[i];
  29432. if (value < 32) {
  29433. if (value === 12) {
  29434. value = (value << 8) + encoded[++i];
  29435. }
  29436. switch (value) {
  29437. case 1: // hstem
  29438. if (!HINTING_ENABLED) {
  29439. this.stack = [];
  29440. break;
  29441. }
  29442. error = this.executeCommand(2, COMMAND_MAP.hstem);
  29443. break;
  29444. case 3: // vstem
  29445. if (!HINTING_ENABLED) {
  29446. this.stack = [];
  29447. break;
  29448. }
  29449. error = this.executeCommand(2, COMMAND_MAP.vstem);
  29450. break;
  29451. case 4: // vmoveto
  29452. if (this.flexing) {
  29453. if (this.stack.length < 1) {
  29454. error = true;
  29455. break;
  29456. }
  29457. // Add the dx for flex and but also swap the values so they are
  29458. // the right order.
  29459. var dy = this.stack.pop();
  29460. this.stack.push(0, dy);
  29461. break;
  29462. }
  29463. error = this.executeCommand(1, COMMAND_MAP.vmoveto);
  29464. break;
  29465. case 5: // rlineto
  29466. error = this.executeCommand(2, COMMAND_MAP.rlineto);
  29467. break;
  29468. case 6: // hlineto
  29469. error = this.executeCommand(1, COMMAND_MAP.hlineto);
  29470. break;
  29471. case 7: // vlineto
  29472. error = this.executeCommand(1, COMMAND_MAP.vlineto);
  29473. break;
  29474. case 8: // rrcurveto
  29475. error = this.executeCommand(6, COMMAND_MAP.rrcurveto);
  29476. break;
  29477. case 9: // closepath
  29478. // closepath is a Type1 command that does not take argument and is
  29479. // useless in Type2 and it can simply be ignored.
  29480. this.stack = [];
  29481. break;
  29482. case 10: // callsubr
  29483. if (this.stack.length < 1) {
  29484. error = true;
  29485. break;
  29486. }
  29487. subrNumber = this.stack.pop();
  29488. error = this.convert(subrs[subrNumber], subrs,
  29489. seacAnalysisEnabled);
  29490. break;
  29491. case 11: // return
  29492. return error;
  29493. case 13: // hsbw
  29494. if (this.stack.length < 2) {
  29495. error = true;
  29496. break;
  29497. }
  29498. // To convert to type2 we have to move the width value to the
  29499. // first part of the charstring and then use hmoveto with lsb.
  29500. wx = this.stack.pop();
  29501. sbx = this.stack.pop();
  29502. this.lsb = sbx;
  29503. this.width = wx;
  29504. this.stack.push(wx, sbx);
  29505. error = this.executeCommand(2, COMMAND_MAP.hmoveto);
  29506. break;
  29507. case 14: // endchar
  29508. this.output.push(COMMAND_MAP.endchar[0]);
  29509. break;
  29510. case 21: // rmoveto
  29511. if (this.flexing) {
  29512. break;
  29513. }
  29514. error = this.executeCommand(2, COMMAND_MAP.rmoveto);
  29515. break;
  29516. case 22: // hmoveto
  29517. if (this.flexing) {
  29518. // Add the dy for flex.
  29519. this.stack.push(0);
  29520. break;
  29521. }
  29522. error = this.executeCommand(1, COMMAND_MAP.hmoveto);
  29523. break;
  29524. case 30: // vhcurveto
  29525. error = this.executeCommand(4, COMMAND_MAP.vhcurveto);
  29526. break;
  29527. case 31: // hvcurveto
  29528. error = this.executeCommand(4, COMMAND_MAP.hvcurveto);
  29529. break;
  29530. case (12 << 8) + 0: // dotsection
  29531. // dotsection is a Type1 command to specify some hinting feature
  29532. // for dots that do not take a parameter and it can safely be
  29533. // ignored for Type2.
  29534. this.stack = [];
  29535. break;
  29536. case (12 << 8) + 1: // vstem3
  29537. if (!HINTING_ENABLED) {
  29538. this.stack = [];
  29539. break;
  29540. }
  29541. // [vh]stem3 are Type1 only and Type2 supports [vh]stem with
  29542. // multiple parameters, so instead of returning [vh]stem3 take a
  29543. // shortcut and return [vhstem] instead.
  29544. error = this.executeCommand(2, COMMAND_MAP.vstem);
  29545. break;
  29546. case (12 << 8) + 2: // hstem3
  29547. if (!HINTING_ENABLED) {
  29548. this.stack = [];
  29549. break;
  29550. }
  29551. // See vstem3.
  29552. error = this.executeCommand(2, COMMAND_MAP.hstem);
  29553. break;
  29554. case (12 << 8) + 6: // seac
  29555. // seac is like type 2's special endchar but it doesn't use the
  29556. // first argument asb, so remove it.
  29557. if (seacAnalysisEnabled) {
  29558. this.seac = this.stack.splice(-4, 4);
  29559. error = this.executeCommand(0, COMMAND_MAP.endchar);
  29560. } else {
  29561. error = this.executeCommand(4, COMMAND_MAP.endchar);
  29562. }
  29563. break;
  29564. case (12 << 8) + 7: // sbw
  29565. if (this.stack.length < 4) {
  29566. error = true;
  29567. break;
  29568. }
  29569. // To convert to type2 we have to move the width value to the
  29570. // first part of the charstring and then use rmoveto with
  29571. // (dx, dy). The height argument will not be used for vmtx and
  29572. // vhea tables reconstruction -- ignoring it.
  29573. var wy = this.stack.pop();
  29574. wx = this.stack.pop();
  29575. var sby = this.stack.pop();
  29576. sbx = this.stack.pop();
  29577. this.lsb = sbx;
  29578. this.width = wx;
  29579. this.stack.push(wx, sbx, sby);
  29580. error = this.executeCommand(3, COMMAND_MAP.rmoveto);
  29581. break;
  29582. case (12 << 8) + 12: // div
  29583. if (this.stack.length < 2) {
  29584. error = true;
  29585. break;
  29586. }
  29587. var num2 = this.stack.pop();
  29588. var num1 = this.stack.pop();
  29589. this.stack.push(num1 / num2);
  29590. break;
  29591. case (12 << 8) + 16: // callothersubr
  29592. if (this.stack.length < 2) {
  29593. error = true;
  29594. break;
  29595. }
  29596. subrNumber = this.stack.pop();
  29597. var numArgs = this.stack.pop();
  29598. if (subrNumber === 0 && numArgs === 3) {
  29599. var flexArgs = this.stack.splice(this.stack.length - 17, 17);
  29600. this.stack.push(
  29601. flexArgs[2] + flexArgs[0], // bcp1x + rpx
  29602. flexArgs[3] + flexArgs[1], // bcp1y + rpy
  29603. flexArgs[4], // bcp2x
  29604. flexArgs[5], // bcp2y
  29605. flexArgs[6], // p2x
  29606. flexArgs[7], // p2y
  29607. flexArgs[8], // bcp3x
  29608. flexArgs[9], // bcp3y
  29609. flexArgs[10], // bcp4x
  29610. flexArgs[11], // bcp4y
  29611. flexArgs[12], // p3x
  29612. flexArgs[13], // p3y
  29613. flexArgs[14] // flexDepth
  29614. // 15 = finalx unused by flex
  29615. // 16 = finaly unused by flex
  29616. );
  29617. error = this.executeCommand(13, COMMAND_MAP.flex, true);
  29618. this.flexing = false;
  29619. this.stack.push(flexArgs[15], flexArgs[16]);
  29620. } else if (subrNumber === 1 && numArgs === 0) {
  29621. this.flexing = true;
  29622. }
  29623. break;
  29624. case (12 << 8) + 17: // pop
  29625. // Ignore this since it is only used with othersubr.
  29626. break;
  29627. case (12 << 8) + 33: // setcurrentpoint
  29628. // Ignore for now.
  29629. this.stack = [];
  29630. break;
  29631. default:
  29632. warn('Unknown type 1 charstring command of "' + value + '"');
  29633. break;
  29634. }
  29635. if (error) {
  29636. break;
  29637. }
  29638. continue;
  29639. } else if (value <= 246) {
  29640. value = value - 139;
  29641. } else if (value <= 250) {
  29642. value = ((value - 247) * 256) + encoded[++i] + 108;
  29643. } else if (value <= 254) {
  29644. value = -((value - 251) * 256) - encoded[++i] - 108;
  29645. } else {
  29646. value = (encoded[++i] & 0xff) << 24 | (encoded[++i] & 0xff) << 16 |
  29647. (encoded[++i] & 0xff) << 8 | (encoded[++i] & 0xff) << 0;
  29648. }
  29649. this.stack.push(value);
  29650. }
  29651. return error;
  29652. },
  29653. executeCommand: function(howManyArgs, command, keepStack) {
  29654. var stackLength = this.stack.length;
  29655. if (howManyArgs > stackLength) {
  29656. return true;
  29657. }
  29658. var start = stackLength - howManyArgs;
  29659. for (var i = start; i < stackLength; i++) {
  29660. var value = this.stack[i];
  29661. if (value === (value | 0)) { // int
  29662. this.output.push(28, (value >> 8) & 0xff, value & 0xff);
  29663. } else { // fixed point
  29664. value = (65536 * value) | 0;
  29665. this.output.push(255,
  29666. (value >> 24) & 0xFF,
  29667. (value >> 16) & 0xFF,
  29668. (value >> 8) & 0xFF,
  29669. value & 0xFF);
  29670. }
  29671. }
  29672. this.output.push.apply(this.output, command);
  29673. if (keepStack) {
  29674. this.stack.splice(start, howManyArgs);
  29675. } else {
  29676. this.stack.length = 0;
  29677. }
  29678. return false;
  29679. }
  29680. };
  29681. return Type1CharString;
  29682. })();
  29683. /*
  29684. * Type1Parser encapsulate the needed code for parsing a Type1 font
  29685. * program. Some of its logic depends on the Type2 charstrings
  29686. * structure.
  29687. * Note: this doesn't really parse the font since that would require evaluation
  29688. * of PostScript, but it is possible in most cases to extract what we need
  29689. * without a full parse.
  29690. */
  29691. var Type1Parser = (function Type1ParserClosure() {
  29692. /*
  29693. * Decrypt a Sequence of Ciphertext Bytes to Produce the Original Sequence
  29694. * of Plaintext Bytes. The function took a key as a parameter which can be
  29695. * for decrypting the eexec block of for decoding charStrings.
  29696. */
  29697. var EEXEC_ENCRYPT_KEY = 55665;
  29698. var CHAR_STRS_ENCRYPT_KEY = 4330;
  29699. function isHexDigit(code) {
  29700. return code >= 48 && code <= 57 || // '0'-'9'
  29701. code >= 65 && code <= 70 || // 'A'-'F'
  29702. code >= 97 && code <= 102; // 'a'-'f'
  29703. }
  29704. function decrypt(data, key, discardNumber) {
  29705. if (discardNumber >= data.length) {
  29706. return new Uint8Array(0);
  29707. }
  29708. var r = key | 0, c1 = 52845, c2 = 22719, i, j;
  29709. for (i = 0; i < discardNumber; i++) {
  29710. r = ((data[i] + r) * c1 + c2) & ((1 << 16) - 1);
  29711. }
  29712. var count = data.length - discardNumber;
  29713. var decrypted = new Uint8Array(count);
  29714. for (i = discardNumber, j = 0; j < count; i++, j++) {
  29715. var value = data[i];
  29716. decrypted[j] = value ^ (r >> 8);
  29717. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  29718. }
  29719. return decrypted;
  29720. }
  29721. function decryptAscii(data, key, discardNumber) {
  29722. var r = key | 0, c1 = 52845, c2 = 22719;
  29723. var count = data.length, maybeLength = count >>> 1;
  29724. var decrypted = new Uint8Array(maybeLength);
  29725. var i, j;
  29726. for (i = 0, j = 0; i < count; i++) {
  29727. var digit1 = data[i];
  29728. if (!isHexDigit(digit1)) {
  29729. continue;
  29730. }
  29731. i++;
  29732. var digit2;
  29733. while (i < count && !isHexDigit(digit2 = data[i])) {
  29734. i++;
  29735. }
  29736. if (i < count) {
  29737. var value = parseInt(String.fromCharCode(digit1, digit2), 16);
  29738. decrypted[j++] = value ^ (r >> 8);
  29739. r = ((value + r) * c1 + c2) & ((1 << 16) - 1);
  29740. }
  29741. }
  29742. return Array.prototype.slice.call(decrypted, discardNumber, j);
  29743. }
  29744. function isSpecial(c) {
  29745. return c === 0x2F || // '/'
  29746. c === 0x5B || c === 0x5D || // '[', ']'
  29747. c === 0x7B || c === 0x7D || // '{', '}'
  29748. c === 0x28 || c === 0x29; // '(', ')'
  29749. }
  29750. function Type1Parser(stream, encrypted, seacAnalysisEnabled) {
  29751. if (encrypted) {
  29752. var data = stream.getBytes();
  29753. var isBinary = !(isHexDigit(data[0]) && isHexDigit(data[1]) &&
  29754. isHexDigit(data[2]) && isHexDigit(data[3]));
  29755. stream = new Stream(isBinary ? decrypt(data, EEXEC_ENCRYPT_KEY, 4) :
  29756. decryptAscii(data, EEXEC_ENCRYPT_KEY, 4));
  29757. }
  29758. this.seacAnalysisEnabled = !!seacAnalysisEnabled;
  29759. this.stream = stream;
  29760. this.nextChar();
  29761. }
  29762. Type1Parser.prototype = {
  29763. readNumberArray: function Type1Parser_readNumberArray() {
  29764. this.getToken(); // read '[' or '{' (arrays can start with either)
  29765. var array = [];
  29766. while (true) {
  29767. var token = this.getToken();
  29768. if (token === null || token === ']' || token === '}') {
  29769. break;
  29770. }
  29771. array.push(parseFloat(token || 0));
  29772. }
  29773. return array;
  29774. },
  29775. readNumber: function Type1Parser_readNumber() {
  29776. var token = this.getToken();
  29777. return parseFloat(token || 0);
  29778. },
  29779. readInt: function Type1Parser_readInt() {
  29780. // Use '| 0' to prevent setting a double into length such as the double
  29781. // does not flow into the loop variable.
  29782. var token = this.getToken();
  29783. return parseInt(token || 0, 10) | 0;
  29784. },
  29785. readBoolean: function Type1Parser_readBoolean() {
  29786. var token = this.getToken();
  29787. // Use 1 and 0 since that's what type2 charstrings use.
  29788. return token === 'true' ? 1 : 0;
  29789. },
  29790. nextChar : function Type1_nextChar() {
  29791. return (this.currentChar = this.stream.getByte());
  29792. },
  29793. getToken: function Type1Parser_getToken() {
  29794. // Eat whitespace and comments.
  29795. var comment = false;
  29796. var ch = this.currentChar;
  29797. while (true) {
  29798. if (ch === -1) {
  29799. return null;
  29800. }
  29801. if (comment) {
  29802. if (ch === 0x0A || ch === 0x0D) {
  29803. comment = false;
  29804. }
  29805. } else if (ch === 0x25) { // '%'
  29806. comment = true;
  29807. } else if (!Lexer.isSpace(ch)) {
  29808. break;
  29809. }
  29810. ch = this.nextChar();
  29811. }
  29812. if (isSpecial(ch)) {
  29813. this.nextChar();
  29814. return String.fromCharCode(ch);
  29815. }
  29816. var token = '';
  29817. do {
  29818. token += String.fromCharCode(ch);
  29819. ch = this.nextChar();
  29820. } while (ch >= 0 && !Lexer.isSpace(ch) && !isSpecial(ch));
  29821. return token;
  29822. },
  29823. /*
  29824. * Returns an object containing a Subrs array and a CharStrings
  29825. * array extracted from and eexec encrypted block of data
  29826. */
  29827. extractFontProgram: function Type1Parser_extractFontProgram() {
  29828. var stream = this.stream;
  29829. var subrs = [], charstrings = [];
  29830. var privateData = Object.create(null);
  29831. privateData['lenIV'] = 4;
  29832. var program = {
  29833. subrs: [],
  29834. charstrings: [],
  29835. properties: {
  29836. 'privateData': privateData
  29837. }
  29838. };
  29839. var token, length, data, lenIV, encoded;
  29840. while ((token = this.getToken()) !== null) {
  29841. if (token !== '/') {
  29842. continue;
  29843. }
  29844. token = this.getToken();
  29845. switch (token) {
  29846. case 'CharStrings':
  29847. // The number immediately following CharStrings must be greater or
  29848. // equal to the number of CharStrings.
  29849. this.getToken();
  29850. this.getToken(); // read in 'dict'
  29851. this.getToken(); // read in 'dup'
  29852. this.getToken(); // read in 'begin'
  29853. while(true) {
  29854. token = this.getToken();
  29855. if (token === null || token === 'end') {
  29856. break;
  29857. }
  29858. if (token !== '/') {
  29859. continue;
  29860. }
  29861. var glyph = this.getToken();
  29862. length = this.readInt();
  29863. this.getToken(); // read in 'RD' or '-|'
  29864. data = stream.makeSubStream(stream.pos, length);
  29865. lenIV = program.properties.privateData['lenIV'];
  29866. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  29867. // Skip past the required space and binary data.
  29868. stream.skip(length);
  29869. this.nextChar();
  29870. token = this.getToken(); // read in 'ND' or '|-'
  29871. if (token === 'noaccess') {
  29872. this.getToken(); // read in 'def'
  29873. }
  29874. charstrings.push({
  29875. glyph: glyph,
  29876. encoded: encoded
  29877. });
  29878. }
  29879. break;
  29880. case 'Subrs':
  29881. var num = this.readInt();
  29882. this.getToken(); // read in 'array'
  29883. while ((token = this.getToken()) === 'dup') {
  29884. var index = this.readInt();
  29885. length = this.readInt();
  29886. this.getToken(); // read in 'RD' or '-|'
  29887. data = stream.makeSubStream(stream.pos, length);
  29888. lenIV = program.properties.privateData['lenIV'];
  29889. encoded = decrypt(data.getBytes(), CHAR_STRS_ENCRYPT_KEY, lenIV);
  29890. // Skip past the required space and binary data.
  29891. stream.skip(length);
  29892. this.nextChar();
  29893. token = this.getToken(); // read in 'NP' or '|'
  29894. if (token === 'noaccess') {
  29895. this.getToken(); // read in 'put'
  29896. }
  29897. subrs[index] = encoded;
  29898. }
  29899. break;
  29900. case 'BlueValues':
  29901. case 'OtherBlues':
  29902. case 'FamilyBlues':
  29903. case 'FamilyOtherBlues':
  29904. var blueArray = this.readNumberArray();
  29905. // *Blue* values may contain invalid data: disables reading of
  29906. // those values when hinting is disabled.
  29907. if (blueArray.length > 0 && (blueArray.length % 2) === 0 &&
  29908. HINTING_ENABLED) {
  29909. program.properties.privateData[token] = blueArray;
  29910. }
  29911. break;
  29912. case 'StemSnapH':
  29913. case 'StemSnapV':
  29914. program.properties.privateData[token] = this.readNumberArray();
  29915. break;
  29916. case 'StdHW':
  29917. case 'StdVW':
  29918. program.properties.privateData[token] =
  29919. this.readNumberArray()[0];
  29920. break;
  29921. case 'BlueShift':
  29922. case 'lenIV':
  29923. case 'BlueFuzz':
  29924. case 'BlueScale':
  29925. case 'LanguageGroup':
  29926. case 'ExpansionFactor':
  29927. program.properties.privateData[token] = this.readNumber();
  29928. break;
  29929. case 'ForceBold':
  29930. program.properties.privateData[token] = this.readBoolean();
  29931. break;
  29932. }
  29933. }
  29934. for (var i = 0; i < charstrings.length; i++) {
  29935. glyph = charstrings[i].glyph;
  29936. encoded = charstrings[i].encoded;
  29937. var charString = new Type1CharString();
  29938. var error = charString.convert(encoded, subrs,
  29939. this.seacAnalysisEnabled);
  29940. var output = charString.output;
  29941. if (error) {
  29942. // It seems when FreeType encounters an error while evaluating a glyph
  29943. // that it completely ignores the glyph so we'll mimic that behaviour
  29944. // here and put an endchar to make the validator happy.
  29945. output = [14];
  29946. }
  29947. program.charstrings.push({
  29948. glyphName: glyph,
  29949. charstring: output,
  29950. width: charString.width,
  29951. lsb: charString.lsb,
  29952. seac: charString.seac
  29953. });
  29954. }
  29955. return program;
  29956. },
  29957. extractFontHeader: function Type1Parser_extractFontHeader(properties) {
  29958. var token;
  29959. while ((token = this.getToken()) !== null) {
  29960. if (token !== '/') {
  29961. continue;
  29962. }
  29963. token = this.getToken();
  29964. switch (token) {
  29965. case 'FontMatrix':
  29966. var matrix = this.readNumberArray();
  29967. properties.fontMatrix = matrix;
  29968. break;
  29969. case 'Encoding':
  29970. var encodingArg = this.getToken();
  29971. var encoding;
  29972. if (!/^\d+$/.test(encodingArg)) {
  29973. // encoding name is specified
  29974. encoding = getEncoding(encodingArg);
  29975. } else {
  29976. encoding = [];
  29977. var size = parseInt(encodingArg, 10) | 0;
  29978. this.getToken(); // read in 'array'
  29979. for (var j = 0; j < size; j++) {
  29980. token = this.getToken();
  29981. // skipping till first dup or def (e.g. ignoring for statement)
  29982. while (token !== 'dup' && token !== 'def') {
  29983. token = this.getToken();
  29984. if (token === null) {
  29985. return; // invalid header
  29986. }
  29987. }
  29988. if (token === 'def') {
  29989. break; // read all array data
  29990. }
  29991. var index = this.readInt();
  29992. this.getToken(); // read in '/'
  29993. var glyph = this.getToken();
  29994. encoding[index] = glyph;
  29995. this.getToken(); // read the in 'put'
  29996. }
  29997. }
  29998. properties.builtInEncoding = encoding;
  29999. break;
  30000. case 'FontBBox':
  30001. var fontBBox = this.readNumberArray();
  30002. // adjusting ascent/descent
  30003. properties.ascent = fontBBox[3];
  30004. properties.descent = fontBBox[1];
  30005. properties.ascentScaled = true;
  30006. break;
  30007. }
  30008. }
  30009. }
  30010. };
  30011. return Type1Parser;
  30012. })();
  30013. exports.Type1Parser = Type1Parser;
  30014. }));
  30015. (function (root, factory) {
  30016. {
  30017. factory((root.pdfjsDisplayCanvas = {}), root.pdfjsSharedUtil,
  30018. root.pdfjsDisplayDOMUtils, root.pdfjsDisplayPatternHelper,
  30019. root.pdfjsDisplayWebGL);
  30020. }
  30021. }(this, function (exports, sharedUtil, displayDOMUtils, displayPatternHelper,
  30022. displayWebGL) {
  30023. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  30024. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  30025. var ImageKind = sharedUtil.ImageKind;
  30026. var OPS = sharedUtil.OPS;
  30027. var TextRenderingMode = sharedUtil.TextRenderingMode;
  30028. var Uint32ArrayView = sharedUtil.Uint32ArrayView;
  30029. var Util = sharedUtil.Util;
  30030. var assert = sharedUtil.assert;
  30031. var info = sharedUtil.info;
  30032. var isNum = sharedUtil.isNum;
  30033. var isArray = sharedUtil.isArray;
  30034. var error = sharedUtil.error;
  30035. var shadow = sharedUtil.shadow;
  30036. var warn = sharedUtil.warn;
  30037. var TilingPattern = displayPatternHelper.TilingPattern;
  30038. var getShadingPatternFromIR = displayPatternHelper.getShadingPatternFromIR;
  30039. var WebGLUtils = displayWebGL.WebGLUtils;
  30040. // <canvas> contexts store most of the state we need natively.
  30041. // However, PDF needs a bit more state, which we store here.
  30042. // Minimal font size that would be used during canvas fillText operations.
  30043. var MIN_FONT_SIZE = 16;
  30044. // Maximum font size that would be used during canvas fillText operations.
  30045. var MAX_FONT_SIZE = 100;
  30046. var MAX_GROUP_SIZE = 4096;
  30047. // Heuristic value used when enforcing minimum line widths.
  30048. var MIN_WIDTH_FACTOR = 0.65;
  30049. var COMPILE_TYPE3_GLYPHS = true;
  30050. var MAX_SIZE_TO_COMPILE = 1000;
  30051. var FULL_CHUNK_HEIGHT = 16;
  30052. function createScratchCanvas(width, height) {
  30053. var canvas = document.createElement('canvas');
  30054. canvas.width = width;
  30055. canvas.height = height;
  30056. return canvas;
  30057. }
  30058. function addContextCurrentTransform(ctx) {
  30059. // If the context doesn't expose a `mozCurrentTransform`, add a JS based one.
  30060. if (!ctx.mozCurrentTransform) {
  30061. ctx._originalSave = ctx.save;
  30062. ctx._originalRestore = ctx.restore;
  30063. ctx._originalRotate = ctx.rotate;
  30064. ctx._originalScale = ctx.scale;
  30065. ctx._originalTranslate = ctx.translate;
  30066. ctx._originalTransform = ctx.transform;
  30067. ctx._originalSetTransform = ctx.setTransform;
  30068. ctx._transformMatrix = ctx._transformMatrix || [1, 0, 0, 1, 0, 0];
  30069. ctx._transformStack = [];
  30070. Object.defineProperty(ctx, 'mozCurrentTransform', {
  30071. get: function getCurrentTransform() {
  30072. return this._transformMatrix;
  30073. }
  30074. });
  30075. Object.defineProperty(ctx, 'mozCurrentTransformInverse', {
  30076. get: function getCurrentTransformInverse() {
  30077. // Calculation done using WolframAlpha:
  30078. // http://www.wolframalpha.com/input/?
  30079. // i=Inverse+{{a%2C+c%2C+e}%2C+{b%2C+d%2C+f}%2C+{0%2C+0%2C+1}}
  30080. var m = this._transformMatrix;
  30081. var a = m[0], b = m[1], c = m[2], d = m[3], e = m[4], f = m[5];
  30082. var ad_bc = a * d - b * c;
  30083. var bc_ad = b * c - a * d;
  30084. return [
  30085. d / ad_bc,
  30086. b / bc_ad,
  30087. c / bc_ad,
  30088. a / ad_bc,
  30089. (d * e - c * f) / bc_ad,
  30090. (b * e - a * f) / ad_bc
  30091. ];
  30092. }
  30093. });
  30094. ctx.save = function ctxSave() {
  30095. var old = this._transformMatrix;
  30096. this._transformStack.push(old);
  30097. this._transformMatrix = old.slice(0, 6);
  30098. this._originalSave();
  30099. };
  30100. ctx.restore = function ctxRestore() {
  30101. var prev = this._transformStack.pop();
  30102. if (prev) {
  30103. this._transformMatrix = prev;
  30104. this._originalRestore();
  30105. }
  30106. };
  30107. ctx.translate = function ctxTranslate(x, y) {
  30108. var m = this._transformMatrix;
  30109. m[4] = m[0] * x + m[2] * y + m[4];
  30110. m[5] = m[1] * x + m[3] * y + m[5];
  30111. this._originalTranslate(x, y);
  30112. };
  30113. ctx.scale = function ctxScale(x, y) {
  30114. var m = this._transformMatrix;
  30115. m[0] = m[0] * x;
  30116. m[1] = m[1] * x;
  30117. m[2] = m[2] * y;
  30118. m[3] = m[3] * y;
  30119. this._originalScale(x, y);
  30120. };
  30121. ctx.transform = function ctxTransform(a, b, c, d, e, f) {
  30122. var m = this._transformMatrix;
  30123. this._transformMatrix = [
  30124. m[0] * a + m[2] * b,
  30125. m[1] * a + m[3] * b,
  30126. m[0] * c + m[2] * d,
  30127. m[1] * c + m[3] * d,
  30128. m[0] * e + m[2] * f + m[4],
  30129. m[1] * e + m[3] * f + m[5]
  30130. ];
  30131. ctx._originalTransform(a, b, c, d, e, f);
  30132. };
  30133. ctx.setTransform = function ctxSetTransform(a, b, c, d, e, f) {
  30134. this._transformMatrix = [a, b, c, d, e, f];
  30135. ctx._originalSetTransform(a, b, c, d, e, f);
  30136. };
  30137. ctx.rotate = function ctxRotate(angle) {
  30138. var cosValue = Math.cos(angle);
  30139. var sinValue = Math.sin(angle);
  30140. var m = this._transformMatrix;
  30141. this._transformMatrix = [
  30142. m[0] * cosValue + m[2] * sinValue,
  30143. m[1] * cosValue + m[3] * sinValue,
  30144. m[0] * (-sinValue) + m[2] * cosValue,
  30145. m[1] * (-sinValue) + m[3] * cosValue,
  30146. m[4],
  30147. m[5]
  30148. ];
  30149. this._originalRotate(angle);
  30150. };
  30151. }
  30152. }
  30153. var CachedCanvases = (function CachedCanvasesClosure() {
  30154. function CachedCanvases() {
  30155. this.cache = Object.create(null);
  30156. }
  30157. CachedCanvases.prototype = {
  30158. getCanvas: function CachedCanvases_getCanvas(id, width, height,
  30159. trackTransform) {
  30160. var canvasEntry;
  30161. if (this.cache[id] !== undefined) {
  30162. canvasEntry = this.cache[id];
  30163. canvasEntry.canvas.width = width;
  30164. canvasEntry.canvas.height = height;
  30165. // reset canvas transform for emulated mozCurrentTransform, if needed
  30166. canvasEntry.context.setTransform(1, 0, 0, 1, 0, 0);
  30167. } else {
  30168. var canvas = createScratchCanvas(width, height);
  30169. var ctx = canvas.getContext('2d');
  30170. if (trackTransform) {
  30171. addContextCurrentTransform(ctx);
  30172. }
  30173. this.cache[id] = canvasEntry = {canvas: canvas, context: ctx};
  30174. }
  30175. return canvasEntry;
  30176. },
  30177. clear: function () {
  30178. for (var id in this.cache) {
  30179. var canvasEntry = this.cache[id];
  30180. // Zeroing the width and height causes Firefox to release graphics
  30181. // resources immediately, which can greatly reduce memory consumption.
  30182. canvasEntry.canvas.width = 0;
  30183. canvasEntry.canvas.height = 0;
  30184. delete this.cache[id];
  30185. }
  30186. }
  30187. };
  30188. return CachedCanvases;
  30189. })();
  30190. function compileType3Glyph(imgData) {
  30191. var POINT_TO_PROCESS_LIMIT = 1000;
  30192. var width = imgData.width, height = imgData.height;
  30193. var i, j, j0, width1 = width + 1;
  30194. var points = new Uint8Array(width1 * (height + 1));
  30195. var POINT_TYPES =
  30196. new Uint8Array([0, 2, 4, 0, 1, 0, 5, 4, 8, 10, 0, 8, 0, 2, 1, 0]);
  30197. // decodes bit-packed mask data
  30198. var lineSize = (width + 7) & ~7, data0 = imgData.data;
  30199. var data = new Uint8Array(lineSize * height), pos = 0, ii;
  30200. for (i = 0, ii = data0.length; i < ii; i++) {
  30201. var mask = 128, elem = data0[i];
  30202. while (mask > 0) {
  30203. data[pos++] = (elem & mask) ? 0 : 255;
  30204. mask >>= 1;
  30205. }
  30206. }
  30207. // finding iteresting points: every point is located between mask pixels,
  30208. // so there will be points of the (width + 1)x(height + 1) grid. Every point
  30209. // will have flags assigned based on neighboring mask pixels:
  30210. // 4 | 8
  30211. // --P--
  30212. // 2 | 1
  30213. // We are interested only in points with the flags:
  30214. // - outside corners: 1, 2, 4, 8;
  30215. // - inside corners: 7, 11, 13, 14;
  30216. // - and, intersections: 5, 10.
  30217. var count = 0;
  30218. pos = 0;
  30219. if (data[pos] !== 0) {
  30220. points[0] = 1;
  30221. ++count;
  30222. }
  30223. for (j = 1; j < width; j++) {
  30224. if (data[pos] !== data[pos + 1]) {
  30225. points[j] = data[pos] ? 2 : 1;
  30226. ++count;
  30227. }
  30228. pos++;
  30229. }
  30230. if (data[pos] !== 0) {
  30231. points[j] = 2;
  30232. ++count;
  30233. }
  30234. for (i = 1; i < height; i++) {
  30235. pos = i * lineSize;
  30236. j0 = i * width1;
  30237. if (data[pos - lineSize] !== data[pos]) {
  30238. points[j0] = data[pos] ? 1 : 8;
  30239. ++count;
  30240. }
  30241. // 'sum' is the position of the current pixel configuration in the 'TYPES'
  30242. // array (in order 8-1-2-4, so we can use '>>2' to shift the column).
  30243. var sum = (data[pos] ? 4 : 0) + (data[pos - lineSize] ? 8 : 0);
  30244. for (j = 1; j < width; j++) {
  30245. sum = (sum >> 2) + (data[pos + 1] ? 4 : 0) +
  30246. (data[pos - lineSize + 1] ? 8 : 0);
  30247. if (POINT_TYPES[sum]) {
  30248. points[j0 + j] = POINT_TYPES[sum];
  30249. ++count;
  30250. }
  30251. pos++;
  30252. }
  30253. if (data[pos - lineSize] !== data[pos]) {
  30254. points[j0 + j] = data[pos] ? 2 : 4;
  30255. ++count;
  30256. }
  30257. if (count > POINT_TO_PROCESS_LIMIT) {
  30258. return null;
  30259. }
  30260. }
  30261. pos = lineSize * (height - 1);
  30262. j0 = i * width1;
  30263. if (data[pos] !== 0) {
  30264. points[j0] = 8;
  30265. ++count;
  30266. }
  30267. for (j = 1; j < width; j++) {
  30268. if (data[pos] !== data[pos + 1]) {
  30269. points[j0 + j] = data[pos] ? 4 : 8;
  30270. ++count;
  30271. }
  30272. pos++;
  30273. }
  30274. if (data[pos] !== 0) {
  30275. points[j0 + j] = 4;
  30276. ++count;
  30277. }
  30278. if (count > POINT_TO_PROCESS_LIMIT) {
  30279. return null;
  30280. }
  30281. // building outlines
  30282. var steps = new Int32Array([0, width1, -1, 0, -width1, 0, 0, 0, 1]);
  30283. var outlines = [];
  30284. for (i = 0; count && i <= height; i++) {
  30285. var p = i * width1;
  30286. var end = p + width;
  30287. while (p < end && !points[p]) {
  30288. p++;
  30289. }
  30290. if (p === end) {
  30291. continue;
  30292. }
  30293. var coords = [p % width1, i];
  30294. var type = points[p], p0 = p, pp;
  30295. do {
  30296. var step = steps[type];
  30297. do {
  30298. p += step;
  30299. } while (!points[p]);
  30300. pp = points[p];
  30301. if (pp !== 5 && pp !== 10) {
  30302. // set new direction
  30303. type = pp;
  30304. // delete mark
  30305. points[p] = 0;
  30306. } else { // type is 5 or 10, ie, a crossing
  30307. // set new direction
  30308. type = pp & ((0x33 * type) >> 4);
  30309. // set new type for "future hit"
  30310. points[p] &= (type >> 2 | type << 2);
  30311. }
  30312. coords.push(p % width1);
  30313. coords.push((p / width1) | 0);
  30314. --count;
  30315. } while (p0 !== p);
  30316. outlines.push(coords);
  30317. --i;
  30318. }
  30319. var drawOutline = function(c) {
  30320. c.save();
  30321. // the path shall be painted in [0..1]x[0..1] space
  30322. c.scale(1 / width, -1 / height);
  30323. c.translate(0, -height);
  30324. c.beginPath();
  30325. for (var i = 0, ii = outlines.length; i < ii; i++) {
  30326. var o = outlines[i];
  30327. c.moveTo(o[0], o[1]);
  30328. for (var j = 2, jj = o.length; j < jj; j += 2) {
  30329. c.lineTo(o[j], o[j+1]);
  30330. }
  30331. }
  30332. c.fill();
  30333. c.beginPath();
  30334. c.restore();
  30335. };
  30336. return drawOutline;
  30337. }
  30338. var CanvasExtraState = (function CanvasExtraStateClosure() {
  30339. function CanvasExtraState(old) {
  30340. // Are soft masks and alpha values shapes or opacities?
  30341. this.alphaIsShape = false;
  30342. this.fontSize = 0;
  30343. this.fontSizeScale = 1;
  30344. this.textMatrix = IDENTITY_MATRIX;
  30345. this.textMatrixScale = 1;
  30346. this.fontMatrix = FONT_IDENTITY_MATRIX;
  30347. this.leading = 0;
  30348. // Current point (in user coordinates)
  30349. this.x = 0;
  30350. this.y = 0;
  30351. // Start of text line (in text coordinates)
  30352. this.lineX = 0;
  30353. this.lineY = 0;
  30354. // Character and word spacing
  30355. this.charSpacing = 0;
  30356. this.wordSpacing = 0;
  30357. this.textHScale = 1;
  30358. this.textRenderingMode = TextRenderingMode.FILL;
  30359. this.textRise = 0;
  30360. // Default fore and background colors
  30361. this.fillColor = '#000000';
  30362. this.strokeColor = '#000000';
  30363. this.patternFill = false;
  30364. // Note: fill alpha applies to all non-stroking operations
  30365. this.fillAlpha = 1;
  30366. this.strokeAlpha = 1;
  30367. this.lineWidth = 1;
  30368. this.activeSMask = null; // nonclonable field (see the save method below)
  30369. this.old = old;
  30370. }
  30371. CanvasExtraState.prototype = {
  30372. clone: function CanvasExtraState_clone() {
  30373. return Object.create(this);
  30374. },
  30375. setCurrentPoint: function CanvasExtraState_setCurrentPoint(x, y) {
  30376. this.x = x;
  30377. this.y = y;
  30378. }
  30379. };
  30380. return CanvasExtraState;
  30381. })();
  30382. var CanvasGraphics = (function CanvasGraphicsClosure() {
  30383. // Defines the time the executeOperatorList is going to be executing
  30384. // before it stops and shedules a continue of execution.
  30385. var EXECUTION_TIME = 15;
  30386. // Defines the number of steps before checking the execution time
  30387. var EXECUTION_STEPS = 10;
  30388. function CanvasGraphics(canvasCtx, commonObjs, objs, imageLayer) {
  30389. this.ctx = canvasCtx;
  30390. this.current = new CanvasExtraState();
  30391. this.stateStack = [];
  30392. this.pendingClip = null;
  30393. this.pendingEOFill = false;
  30394. this.res = null;
  30395. this.xobjs = null;
  30396. this.commonObjs = commonObjs;
  30397. this.objs = objs;
  30398. this.imageLayer = imageLayer;
  30399. this.groupStack = [];
  30400. this.processingType3 = null;
  30401. // Patterns are painted relative to the initial page/form transform, see pdf
  30402. // spec 8.7.2 NOTE 1.
  30403. this.baseTransform = null;
  30404. this.baseTransformStack = [];
  30405. this.groupLevel = 0;
  30406. this.smaskStack = [];
  30407. this.smaskCounter = 0;
  30408. this.tempSMask = null;
  30409. this.cachedCanvases = new CachedCanvases();
  30410. if (canvasCtx) {
  30411. // NOTE: if mozCurrentTransform is polyfilled, then the current state of
  30412. // the transformation must already be set in canvasCtx._transformMatrix.
  30413. addContextCurrentTransform(canvasCtx);
  30414. }
  30415. this.cachedGetSinglePixelWidth = null;
  30416. }
  30417. function putBinaryImageData(ctx, imgData) {
  30418. if (typeof ImageData !== 'undefined' && imgData instanceof ImageData) {
  30419. ctx.putImageData(imgData, 0, 0);
  30420. return;
  30421. }
  30422. // Put the image data to the canvas in chunks, rather than putting the
  30423. // whole image at once. This saves JS memory, because the ImageData object
  30424. // is smaller. It also possibly saves C++ memory within the implementation
  30425. // of putImageData(). (E.g. in Firefox we make two short-lived copies of
  30426. // the data passed to putImageData()). |n| shouldn't be too small, however,
  30427. // because too many putImageData() calls will slow things down.
  30428. //
  30429. // Note: as written, if the last chunk is partial, the putImageData() call
  30430. // will (conceptually) put pixels past the bounds of the canvas. But
  30431. // that's ok; any such pixels are ignored.
  30432. var height = imgData.height, width = imgData.width;
  30433. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  30434. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  30435. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  30436. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  30437. var srcPos = 0, destPos;
  30438. var src = imgData.data;
  30439. var dest = chunkImgData.data;
  30440. var i, j, thisChunkHeight, elemsInThisChunk;
  30441. // There are multiple forms in which the pixel data can be passed, and
  30442. // imgData.kind tells us which one this is.
  30443. if (imgData.kind === ImageKind.GRAYSCALE_1BPP) {
  30444. // Grayscale, 1 bit per pixel (i.e. black-and-white).
  30445. var srcLength = src.byteLength;
  30446. var dest32 = PDFJS.hasCanvasTypedArrays ? new Uint32Array(dest.buffer) :
  30447. new Uint32ArrayView(dest);
  30448. var dest32DataLength = dest32.length;
  30449. var fullSrcDiff = (width + 7) >> 3;
  30450. var white = 0xFFFFFFFF;
  30451. var black = (PDFJS.isLittleEndian || !PDFJS.hasCanvasTypedArrays) ?
  30452. 0xFF000000 : 0x000000FF;
  30453. for (i = 0; i < totalChunks; i++) {
  30454. thisChunkHeight =
  30455. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  30456. destPos = 0;
  30457. for (j = 0; j < thisChunkHeight; j++) {
  30458. var srcDiff = srcLength - srcPos;
  30459. var k = 0;
  30460. var kEnd = (srcDiff > fullSrcDiff) ? width : srcDiff * 8 - 7;
  30461. var kEndUnrolled = kEnd & ~7;
  30462. var mask = 0;
  30463. var srcByte = 0;
  30464. for (; k < kEndUnrolled; k += 8) {
  30465. srcByte = src[srcPos++];
  30466. dest32[destPos++] = (srcByte & 128) ? white : black;
  30467. dest32[destPos++] = (srcByte & 64) ? white : black;
  30468. dest32[destPos++] = (srcByte & 32) ? white : black;
  30469. dest32[destPos++] = (srcByte & 16) ? white : black;
  30470. dest32[destPos++] = (srcByte & 8) ? white : black;
  30471. dest32[destPos++] = (srcByte & 4) ? white : black;
  30472. dest32[destPos++] = (srcByte & 2) ? white : black;
  30473. dest32[destPos++] = (srcByte & 1) ? white : black;
  30474. }
  30475. for (; k < kEnd; k++) {
  30476. if (mask === 0) {
  30477. srcByte = src[srcPos++];
  30478. mask = 128;
  30479. }
  30480. dest32[destPos++] = (srcByte & mask) ? white : black;
  30481. mask >>= 1;
  30482. }
  30483. }
  30484. // We ran out of input. Make all remaining pixels transparent.
  30485. while (destPos < dest32DataLength) {
  30486. dest32[destPos++] = 0;
  30487. }
  30488. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  30489. }
  30490. } else if (imgData.kind === ImageKind.RGBA_32BPP) {
  30491. // RGBA, 32-bits per pixel.
  30492. j = 0;
  30493. elemsInThisChunk = width * FULL_CHUNK_HEIGHT * 4;
  30494. for (i = 0; i < fullChunks; i++) {
  30495. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  30496. srcPos += elemsInThisChunk;
  30497. ctx.putImageData(chunkImgData, 0, j);
  30498. j += FULL_CHUNK_HEIGHT;
  30499. }
  30500. if (i < totalChunks) {
  30501. elemsInThisChunk = width * partialChunkHeight * 4;
  30502. dest.set(src.subarray(srcPos, srcPos + elemsInThisChunk));
  30503. ctx.putImageData(chunkImgData, 0, j);
  30504. }
  30505. } else if (imgData.kind === ImageKind.RGB_24BPP) {
  30506. // RGB, 24-bits per pixel.
  30507. thisChunkHeight = FULL_CHUNK_HEIGHT;
  30508. elemsInThisChunk = width * thisChunkHeight;
  30509. for (i = 0; i < totalChunks; i++) {
  30510. if (i >= fullChunks) {
  30511. thisChunkHeight = partialChunkHeight;
  30512. elemsInThisChunk = width * thisChunkHeight;
  30513. }
  30514. destPos = 0;
  30515. for (j = elemsInThisChunk; j--;) {
  30516. dest[destPos++] = src[srcPos++];
  30517. dest[destPos++] = src[srcPos++];
  30518. dest[destPos++] = src[srcPos++];
  30519. dest[destPos++] = 255;
  30520. }
  30521. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  30522. }
  30523. } else {
  30524. error('bad image kind: ' + imgData.kind);
  30525. }
  30526. }
  30527. function putBinaryImageMask(ctx, imgData) {
  30528. var height = imgData.height, width = imgData.width;
  30529. var partialChunkHeight = height % FULL_CHUNK_HEIGHT;
  30530. var fullChunks = (height - partialChunkHeight) / FULL_CHUNK_HEIGHT;
  30531. var totalChunks = partialChunkHeight === 0 ? fullChunks : fullChunks + 1;
  30532. var chunkImgData = ctx.createImageData(width, FULL_CHUNK_HEIGHT);
  30533. var srcPos = 0;
  30534. var src = imgData.data;
  30535. var dest = chunkImgData.data;
  30536. for (var i = 0; i < totalChunks; i++) {
  30537. var thisChunkHeight =
  30538. (i < fullChunks) ? FULL_CHUNK_HEIGHT : partialChunkHeight;
  30539. // Expand the mask so it can be used by the canvas. Any required
  30540. // inversion has already been handled.
  30541. var destPos = 3; // alpha component offset
  30542. for (var j = 0; j < thisChunkHeight; j++) {
  30543. var mask = 0;
  30544. for (var k = 0; k < width; k++) {
  30545. if (!mask) {
  30546. var elem = src[srcPos++];
  30547. mask = 128;
  30548. }
  30549. dest[destPos] = (elem & mask) ? 0 : 255;
  30550. destPos += 4;
  30551. mask >>= 1;
  30552. }
  30553. }
  30554. ctx.putImageData(chunkImgData, 0, i * FULL_CHUNK_HEIGHT);
  30555. }
  30556. }
  30557. function copyCtxState(sourceCtx, destCtx) {
  30558. var properties = ['strokeStyle', 'fillStyle', 'fillRule', 'globalAlpha',
  30559. 'lineWidth', 'lineCap', 'lineJoin', 'miterLimit',
  30560. 'globalCompositeOperation', 'font'];
  30561. for (var i = 0, ii = properties.length; i < ii; i++) {
  30562. var property = properties[i];
  30563. if (sourceCtx[property] !== undefined) {
  30564. destCtx[property] = sourceCtx[property];
  30565. }
  30566. }
  30567. if (sourceCtx.setLineDash !== undefined) {
  30568. destCtx.setLineDash(sourceCtx.getLineDash());
  30569. destCtx.lineDashOffset = sourceCtx.lineDashOffset;
  30570. } else if (sourceCtx.mozDashOffset !== undefined) {
  30571. destCtx.mozDash = sourceCtx.mozDash;
  30572. destCtx.mozDashOffset = sourceCtx.mozDashOffset;
  30573. }
  30574. }
  30575. function composeSMaskBackdrop(bytes, r0, g0, b0) {
  30576. var length = bytes.length;
  30577. for (var i = 3; i < length; i += 4) {
  30578. var alpha = bytes[i];
  30579. if (alpha === 0) {
  30580. bytes[i - 3] = r0;
  30581. bytes[i - 2] = g0;
  30582. bytes[i - 1] = b0;
  30583. } else if (alpha < 255) {
  30584. var alpha_ = 255 - alpha;
  30585. bytes[i - 3] = (bytes[i - 3] * alpha + r0 * alpha_) >> 8;
  30586. bytes[i - 2] = (bytes[i - 2] * alpha + g0 * alpha_) >> 8;
  30587. bytes[i - 1] = (bytes[i - 1] * alpha + b0 * alpha_) >> 8;
  30588. }
  30589. }
  30590. }
  30591. function composeSMaskAlpha(maskData, layerData, transferMap) {
  30592. var length = maskData.length;
  30593. var scale = 1 / 255;
  30594. for (var i = 3; i < length; i += 4) {
  30595. var alpha = transferMap ? transferMap[maskData[i]] : maskData[i];
  30596. layerData[i] = (layerData[i] * alpha * scale) | 0;
  30597. }
  30598. }
  30599. function composeSMaskLuminosity(maskData, layerData, transferMap) {
  30600. var length = maskData.length;
  30601. for (var i = 3; i < length; i += 4) {
  30602. var y = (maskData[i - 3] * 77) + // * 0.3 / 255 * 0x10000
  30603. (maskData[i - 2] * 152) + // * 0.59 ....
  30604. (maskData[i - 1] * 28); // * 0.11 ....
  30605. layerData[i] = transferMap ?
  30606. (layerData[i] * transferMap[y >> 8]) >> 8 :
  30607. (layerData[i] * y) >> 16;
  30608. }
  30609. }
  30610. function genericComposeSMask(maskCtx, layerCtx, width, height,
  30611. subtype, backdrop, transferMap) {
  30612. var hasBackdrop = !!backdrop;
  30613. var r0 = hasBackdrop ? backdrop[0] : 0;
  30614. var g0 = hasBackdrop ? backdrop[1] : 0;
  30615. var b0 = hasBackdrop ? backdrop[2] : 0;
  30616. var composeFn;
  30617. if (subtype === 'Luminosity') {
  30618. composeFn = composeSMaskLuminosity;
  30619. } else {
  30620. composeFn = composeSMaskAlpha;
  30621. }
  30622. // processing image in chunks to save memory
  30623. var PIXELS_TO_PROCESS = 1048576;
  30624. var chunkSize = Math.min(height, Math.ceil(PIXELS_TO_PROCESS / width));
  30625. for (var row = 0; row < height; row += chunkSize) {
  30626. var chunkHeight = Math.min(chunkSize, height - row);
  30627. var maskData = maskCtx.getImageData(0, row, width, chunkHeight);
  30628. var layerData = layerCtx.getImageData(0, row, width, chunkHeight);
  30629. if (hasBackdrop) {
  30630. composeSMaskBackdrop(maskData.data, r0, g0, b0);
  30631. }
  30632. composeFn(maskData.data, layerData.data, transferMap);
  30633. maskCtx.putImageData(layerData, 0, row);
  30634. }
  30635. }
  30636. function composeSMask(ctx, smask, layerCtx) {
  30637. var mask = smask.canvas;
  30638. var maskCtx = smask.context;
  30639. ctx.setTransform(smask.scaleX, 0, 0, smask.scaleY,
  30640. smask.offsetX, smask.offsetY);
  30641. var backdrop = smask.backdrop || null;
  30642. if (!smask.transferMap && WebGLUtils.isEnabled) {
  30643. var composed = WebGLUtils.composeSMask(layerCtx.canvas, mask,
  30644. {subtype: smask.subtype, backdrop: backdrop});
  30645. ctx.setTransform(1, 0, 0, 1, 0, 0);
  30646. ctx.drawImage(composed, smask.offsetX, smask.offsetY);
  30647. return;
  30648. }
  30649. genericComposeSMask(maskCtx, layerCtx, mask.width, mask.height,
  30650. smask.subtype, backdrop, smask.transferMap);
  30651. ctx.drawImage(mask, 0, 0);
  30652. }
  30653. var LINE_CAP_STYLES = ['butt', 'round', 'square'];
  30654. var LINE_JOIN_STYLES = ['miter', 'round', 'bevel'];
  30655. var NORMAL_CLIP = {};
  30656. var EO_CLIP = {};
  30657. CanvasGraphics.prototype = {
  30658. beginDrawing: function CanvasGraphics_beginDrawing(transform, viewport,
  30659. transparency) {
  30660. // For pdfs that use blend modes we have to clear the canvas else certain
  30661. // blend modes can look wrong since we'd be blending with a white
  30662. // backdrop. The problem with a transparent backdrop though is we then
  30663. // don't get sub pixel anti aliasing on text, creating temporary
  30664. // transparent canvas when we have blend modes.
  30665. var width = this.ctx.canvas.width;
  30666. var height = this.ctx.canvas.height;
  30667. this.ctx.save();
  30668. this.ctx.fillStyle = 'rgb(255, 255, 255)';
  30669. this.ctx.fillRect(0, 0, width, height);
  30670. this.ctx.restore();
  30671. if (transparency) {
  30672. var transparentCanvas = this.cachedCanvases.getCanvas(
  30673. 'transparent', width, height, true);
  30674. this.compositeCtx = this.ctx;
  30675. this.transparentCanvas = transparentCanvas.canvas;
  30676. this.ctx = transparentCanvas.context;
  30677. this.ctx.save();
  30678. // The transform can be applied before rendering, transferring it to
  30679. // the new canvas.
  30680. this.ctx.transform.apply(this.ctx,
  30681. this.compositeCtx.mozCurrentTransform);
  30682. }
  30683. this.ctx.save();
  30684. if (transform) {
  30685. this.ctx.transform.apply(this.ctx, transform);
  30686. }
  30687. this.ctx.transform.apply(this.ctx, viewport.transform);
  30688. this.baseTransform = this.ctx.mozCurrentTransform.slice();
  30689. if (this.imageLayer) {
  30690. this.imageLayer.beginLayout();
  30691. }
  30692. },
  30693. executeOperatorList: function CanvasGraphics_executeOperatorList(
  30694. operatorList,
  30695. executionStartIdx, continueCallback,
  30696. stepper) {
  30697. var argsArray = operatorList.argsArray;
  30698. var fnArray = operatorList.fnArray;
  30699. var i = executionStartIdx || 0;
  30700. var argsArrayLen = argsArray.length;
  30701. // Sometimes the OperatorList to execute is empty.
  30702. if (argsArrayLen === i) {
  30703. return i;
  30704. }
  30705. var chunkOperations = (argsArrayLen - i > EXECUTION_STEPS &&
  30706. typeof continueCallback === 'function');
  30707. var endTime = chunkOperations ? Date.now() + EXECUTION_TIME : 0;
  30708. var steps = 0;
  30709. var commonObjs = this.commonObjs;
  30710. var objs = this.objs;
  30711. var fnId;
  30712. while (true) {
  30713. if (stepper !== undefined && i === stepper.nextBreakPoint) {
  30714. stepper.breakIt(i, continueCallback);
  30715. return i;
  30716. }
  30717. fnId = fnArray[i];
  30718. if (fnId !== OPS.dependency) {
  30719. this[fnId].apply(this, argsArray[i]);
  30720. } else {
  30721. var deps = argsArray[i];
  30722. for (var n = 0, nn = deps.length; n < nn; n++) {
  30723. var depObjId = deps[n];
  30724. var common = depObjId[0] === 'g' && depObjId[1] === '_';
  30725. var objsPool = common ? commonObjs : objs;
  30726. // If the promise isn't resolved yet, add the continueCallback
  30727. // to the promise and bail out.
  30728. if (!objsPool.isResolved(depObjId)) {
  30729. objsPool.get(depObjId, continueCallback);
  30730. return i;
  30731. }
  30732. }
  30733. }
  30734. i++;
  30735. // If the entire operatorList was executed, stop as were done.
  30736. if (i === argsArrayLen) {
  30737. return i;
  30738. }
  30739. // If the execution took longer then a certain amount of time and
  30740. // `continueCallback` is specified, interrupt the execution.
  30741. if (chunkOperations && ++steps > EXECUTION_STEPS) {
  30742. if (Date.now() > endTime) {
  30743. continueCallback();
  30744. return i;
  30745. }
  30746. steps = 0;
  30747. }
  30748. // If the operatorList isn't executed completely yet OR the execution
  30749. // time was short enough, do another execution round.
  30750. }
  30751. },
  30752. endDrawing: function CanvasGraphics_endDrawing() {
  30753. this.ctx.restore();
  30754. if (this.transparentCanvas) {
  30755. this.ctx = this.compositeCtx;
  30756. this.ctx.save();
  30757. this.ctx.setTransform(1, 0, 0, 1, 0, 0); // Avoid apply transform twice
  30758. this.ctx.drawImage(this.transparentCanvas, 0, 0);
  30759. this.ctx.restore();
  30760. this.transparentCanvas = null;
  30761. }
  30762. this.cachedCanvases.clear();
  30763. WebGLUtils.clear();
  30764. if (this.imageLayer) {
  30765. this.imageLayer.endLayout();
  30766. }
  30767. },
  30768. // Graphics state
  30769. setLineWidth: function CanvasGraphics_setLineWidth(width) {
  30770. this.current.lineWidth = width;
  30771. this.ctx.lineWidth = width;
  30772. },
  30773. setLineCap: function CanvasGraphics_setLineCap(style) {
  30774. this.ctx.lineCap = LINE_CAP_STYLES[style];
  30775. },
  30776. setLineJoin: function CanvasGraphics_setLineJoin(style) {
  30777. this.ctx.lineJoin = LINE_JOIN_STYLES[style];
  30778. },
  30779. setMiterLimit: function CanvasGraphics_setMiterLimit(limit) {
  30780. this.ctx.miterLimit = limit;
  30781. },
  30782. setDash: function CanvasGraphics_setDash(dashArray, dashPhase) {
  30783. var ctx = this.ctx;
  30784. if (ctx.setLineDash !== undefined) {
  30785. ctx.setLineDash(dashArray);
  30786. ctx.lineDashOffset = dashPhase;
  30787. } else {
  30788. ctx.mozDash = dashArray;
  30789. ctx.mozDashOffset = dashPhase;
  30790. }
  30791. },
  30792. setRenderingIntent: function CanvasGraphics_setRenderingIntent(intent) {
  30793. // Maybe if we one day fully support color spaces this will be important
  30794. // for now we can ignore.
  30795. // TODO set rendering intent?
  30796. },
  30797. setFlatness: function CanvasGraphics_setFlatness(flatness) {
  30798. // There's no way to control this with canvas, but we can safely ignore.
  30799. // TODO set flatness?
  30800. },
  30801. setGState: function CanvasGraphics_setGState(states) {
  30802. for (var i = 0, ii = states.length; i < ii; i++) {
  30803. var state = states[i];
  30804. var key = state[0];
  30805. var value = state[1];
  30806. switch (key) {
  30807. case 'LW':
  30808. this.setLineWidth(value);
  30809. break;
  30810. case 'LC':
  30811. this.setLineCap(value);
  30812. break;
  30813. case 'LJ':
  30814. this.setLineJoin(value);
  30815. break;
  30816. case 'ML':
  30817. this.setMiterLimit(value);
  30818. break;
  30819. case 'D':
  30820. this.setDash(value[0], value[1]);
  30821. break;
  30822. case 'RI':
  30823. this.setRenderingIntent(value);
  30824. break;
  30825. case 'FL':
  30826. this.setFlatness(value);
  30827. break;
  30828. case 'Font':
  30829. this.setFont(value[0], value[1]);
  30830. break;
  30831. case 'CA':
  30832. this.current.strokeAlpha = state[1];
  30833. break;
  30834. case 'ca':
  30835. this.current.fillAlpha = state[1];
  30836. this.ctx.globalAlpha = state[1];
  30837. break;
  30838. case 'BM':
  30839. if (value && value.name && (value.name !== 'Normal')) {
  30840. var mode = value.name.replace(/([A-Z])/g,
  30841. function(c) {
  30842. return '-' + c.toLowerCase();
  30843. }
  30844. ).substring(1);
  30845. this.ctx.globalCompositeOperation = mode;
  30846. if (this.ctx.globalCompositeOperation !== mode) {
  30847. warn('globalCompositeOperation "' + mode +
  30848. '" is not supported');
  30849. }
  30850. } else {
  30851. this.ctx.globalCompositeOperation = 'source-over';
  30852. }
  30853. break;
  30854. case 'SMask':
  30855. if (this.current.activeSMask) {
  30856. this.endSMaskGroup();
  30857. }
  30858. this.current.activeSMask = value ? this.tempSMask : null;
  30859. if (this.current.activeSMask) {
  30860. this.beginSMaskGroup();
  30861. }
  30862. this.tempSMask = null;
  30863. break;
  30864. }
  30865. }
  30866. },
  30867. beginSMaskGroup: function CanvasGraphics_beginSMaskGroup() {
  30868. var activeSMask = this.current.activeSMask;
  30869. var drawnWidth = activeSMask.canvas.width;
  30870. var drawnHeight = activeSMask.canvas.height;
  30871. var cacheId = 'smaskGroupAt' + this.groupLevel;
  30872. var scratchCanvas = this.cachedCanvases.getCanvas(
  30873. cacheId, drawnWidth, drawnHeight, true);
  30874. var currentCtx = this.ctx;
  30875. var currentTransform = currentCtx.mozCurrentTransform;
  30876. this.ctx.save();
  30877. var groupCtx = scratchCanvas.context;
  30878. groupCtx.scale(1 / activeSMask.scaleX, 1 / activeSMask.scaleY);
  30879. groupCtx.translate(-activeSMask.offsetX, -activeSMask.offsetY);
  30880. groupCtx.transform.apply(groupCtx, currentTransform);
  30881. copyCtxState(currentCtx, groupCtx);
  30882. this.ctx = groupCtx;
  30883. this.setGState([
  30884. ['BM', 'Normal'],
  30885. ['ca', 1],
  30886. ['CA', 1]
  30887. ]);
  30888. this.groupStack.push(currentCtx);
  30889. this.groupLevel++;
  30890. },
  30891. endSMaskGroup: function CanvasGraphics_endSMaskGroup() {
  30892. var groupCtx = this.ctx;
  30893. this.groupLevel--;
  30894. this.ctx = this.groupStack.pop();
  30895. composeSMask(this.ctx, this.current.activeSMask, groupCtx);
  30896. this.ctx.restore();
  30897. copyCtxState(groupCtx, this.ctx);
  30898. },
  30899. save: function CanvasGraphics_save() {
  30900. this.ctx.save();
  30901. var old = this.current;
  30902. this.stateStack.push(old);
  30903. this.current = old.clone();
  30904. this.current.activeSMask = null;
  30905. },
  30906. restore: function CanvasGraphics_restore() {
  30907. if (this.stateStack.length !== 0) {
  30908. if (this.current.activeSMask !== null) {
  30909. this.endSMaskGroup();
  30910. }
  30911. this.current = this.stateStack.pop();
  30912. this.ctx.restore();
  30913. // Ensure that the clipping path is reset (fixes issue6413.pdf).
  30914. this.pendingClip = null;
  30915. this.cachedGetSinglePixelWidth = null;
  30916. }
  30917. },
  30918. transform: function CanvasGraphics_transform(a, b, c, d, e, f) {
  30919. this.ctx.transform(a, b, c, d, e, f);
  30920. this.cachedGetSinglePixelWidth = null;
  30921. },
  30922. // Path
  30923. constructPath: function CanvasGraphics_constructPath(ops, args) {
  30924. var ctx = this.ctx;
  30925. var current = this.current;
  30926. var x = current.x, y = current.y;
  30927. for (var i = 0, j = 0, ii = ops.length; i < ii; i++) {
  30928. switch (ops[i] | 0) {
  30929. case OPS.rectangle:
  30930. x = args[j++];
  30931. y = args[j++];
  30932. var width = args[j++];
  30933. var height = args[j++];
  30934. if (width === 0) {
  30935. width = this.getSinglePixelWidth();
  30936. }
  30937. if (height === 0) {
  30938. height = this.getSinglePixelWidth();
  30939. }
  30940. var xw = x + width;
  30941. var yh = y + height;
  30942. this.ctx.moveTo(x, y);
  30943. this.ctx.lineTo(xw, y);
  30944. this.ctx.lineTo(xw, yh);
  30945. this.ctx.lineTo(x, yh);
  30946. this.ctx.lineTo(x, y);
  30947. this.ctx.closePath();
  30948. break;
  30949. case OPS.moveTo:
  30950. x = args[j++];
  30951. y = args[j++];
  30952. ctx.moveTo(x, y);
  30953. break;
  30954. case OPS.lineTo:
  30955. x = args[j++];
  30956. y = args[j++];
  30957. ctx.lineTo(x, y);
  30958. break;
  30959. case OPS.curveTo:
  30960. x = args[j + 4];
  30961. y = args[j + 5];
  30962. ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3],
  30963. x, y);
  30964. j += 6;
  30965. break;
  30966. case OPS.curveTo2:
  30967. ctx.bezierCurveTo(x, y, args[j], args[j + 1],
  30968. args[j + 2], args[j + 3]);
  30969. x = args[j + 2];
  30970. y = args[j + 3];
  30971. j += 4;
  30972. break;
  30973. case OPS.curveTo3:
  30974. x = args[j + 2];
  30975. y = args[j + 3];
  30976. ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y);
  30977. j += 4;
  30978. break;
  30979. case OPS.closePath:
  30980. ctx.closePath();
  30981. break;
  30982. }
  30983. }
  30984. current.setCurrentPoint(x, y);
  30985. },
  30986. closePath: function CanvasGraphics_closePath() {
  30987. this.ctx.closePath();
  30988. },
  30989. stroke: function CanvasGraphics_stroke(consumePath) {
  30990. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  30991. var ctx = this.ctx;
  30992. var strokeColor = this.current.strokeColor;
  30993. // Prevent drawing too thin lines by enforcing a minimum line width.
  30994. ctx.lineWidth = Math.max(this.getSinglePixelWidth() * MIN_WIDTH_FACTOR,
  30995. this.current.lineWidth);
  30996. // For stroke we want to temporarily change the global alpha to the
  30997. // stroking alpha.
  30998. ctx.globalAlpha = this.current.strokeAlpha;
  30999. if (strokeColor && strokeColor.hasOwnProperty('type') &&
  31000. strokeColor.type === 'Pattern') {
  31001. // for patterns, we transform to pattern space, calculate
  31002. // the pattern, call stroke, and restore to user space
  31003. ctx.save();
  31004. ctx.strokeStyle = strokeColor.getPattern(ctx, this);
  31005. ctx.stroke();
  31006. ctx.restore();
  31007. } else {
  31008. ctx.stroke();
  31009. }
  31010. if (consumePath) {
  31011. this.consumePath();
  31012. }
  31013. // Restore the global alpha to the fill alpha
  31014. ctx.globalAlpha = this.current.fillAlpha;
  31015. },
  31016. closeStroke: function CanvasGraphics_closeStroke() {
  31017. this.closePath();
  31018. this.stroke();
  31019. },
  31020. fill: function CanvasGraphics_fill(consumePath) {
  31021. consumePath = typeof consumePath !== 'undefined' ? consumePath : true;
  31022. var ctx = this.ctx;
  31023. var fillColor = this.current.fillColor;
  31024. var isPatternFill = this.current.patternFill;
  31025. var needRestore = false;
  31026. if (isPatternFill) {
  31027. ctx.save();
  31028. if (this.baseTransform) {
  31029. ctx.setTransform.apply(ctx, this.baseTransform);
  31030. }
  31031. ctx.fillStyle = fillColor.getPattern(ctx, this);
  31032. needRestore = true;
  31033. }
  31034. if (this.pendingEOFill) {
  31035. if (ctx.mozFillRule !== undefined) {
  31036. ctx.mozFillRule = 'evenodd';
  31037. ctx.fill();
  31038. ctx.mozFillRule = 'nonzero';
  31039. } else {
  31040. ctx.fill('evenodd');
  31041. }
  31042. this.pendingEOFill = false;
  31043. } else {
  31044. ctx.fill();
  31045. }
  31046. if (needRestore) {
  31047. ctx.restore();
  31048. }
  31049. if (consumePath) {
  31050. this.consumePath();
  31051. }
  31052. },
  31053. eoFill: function CanvasGraphics_eoFill() {
  31054. this.pendingEOFill = true;
  31055. this.fill();
  31056. },
  31057. fillStroke: function CanvasGraphics_fillStroke() {
  31058. this.fill(false);
  31059. this.stroke(false);
  31060. this.consumePath();
  31061. },
  31062. eoFillStroke: function CanvasGraphics_eoFillStroke() {
  31063. this.pendingEOFill = true;
  31064. this.fillStroke();
  31065. },
  31066. closeFillStroke: function CanvasGraphics_closeFillStroke() {
  31067. this.closePath();
  31068. this.fillStroke();
  31069. },
  31070. closeEOFillStroke: function CanvasGraphics_closeEOFillStroke() {
  31071. this.pendingEOFill = true;
  31072. this.closePath();
  31073. this.fillStroke();
  31074. },
  31075. endPath: function CanvasGraphics_endPath() {
  31076. this.consumePath();
  31077. },
  31078. // Clipping
  31079. clip: function CanvasGraphics_clip() {
  31080. this.pendingClip = NORMAL_CLIP;
  31081. },
  31082. eoClip: function CanvasGraphics_eoClip() {
  31083. this.pendingClip = EO_CLIP;
  31084. },
  31085. // Text
  31086. beginText: function CanvasGraphics_beginText() {
  31087. this.current.textMatrix = IDENTITY_MATRIX;
  31088. this.current.textMatrixScale = 1;
  31089. this.current.x = this.current.lineX = 0;
  31090. this.current.y = this.current.lineY = 0;
  31091. },
  31092. endText: function CanvasGraphics_endText() {
  31093. var paths = this.pendingTextPaths;
  31094. var ctx = this.ctx;
  31095. if (paths === undefined) {
  31096. ctx.beginPath();
  31097. return;
  31098. }
  31099. ctx.save();
  31100. ctx.beginPath();
  31101. for (var i = 0; i < paths.length; i++) {
  31102. var path = paths[i];
  31103. ctx.setTransform.apply(ctx, path.transform);
  31104. ctx.translate(path.x, path.y);
  31105. path.addToPath(ctx, path.fontSize);
  31106. }
  31107. ctx.restore();
  31108. ctx.clip();
  31109. ctx.beginPath();
  31110. delete this.pendingTextPaths;
  31111. },
  31112. setCharSpacing: function CanvasGraphics_setCharSpacing(spacing) {
  31113. this.current.charSpacing = spacing;
  31114. },
  31115. setWordSpacing: function CanvasGraphics_setWordSpacing(spacing) {
  31116. this.current.wordSpacing = spacing;
  31117. },
  31118. setHScale: function CanvasGraphics_setHScale(scale) {
  31119. this.current.textHScale = scale / 100;
  31120. },
  31121. setLeading: function CanvasGraphics_setLeading(leading) {
  31122. this.current.leading = -leading;
  31123. },
  31124. setFont: function CanvasGraphics_setFont(fontRefName, size) {
  31125. var fontObj = this.commonObjs.get(fontRefName);
  31126. var current = this.current;
  31127. if (!fontObj) {
  31128. error('Can\'t find font for ' + fontRefName);
  31129. }
  31130. current.fontMatrix = (fontObj.fontMatrix ?
  31131. fontObj.fontMatrix : FONT_IDENTITY_MATRIX);
  31132. // A valid matrix needs all main diagonal elements to be non-zero
  31133. // This also ensures we bypass FF bugzilla bug #719844.
  31134. if (current.fontMatrix[0] === 0 ||
  31135. current.fontMatrix[3] === 0) {
  31136. warn('Invalid font matrix for font ' + fontRefName);
  31137. }
  31138. // The spec for Tf (setFont) says that 'size' specifies the font 'scale',
  31139. // and in some docs this can be negative (inverted x-y axes).
  31140. if (size < 0) {
  31141. size = -size;
  31142. current.fontDirection = -1;
  31143. } else {
  31144. current.fontDirection = 1;
  31145. }
  31146. this.current.font = fontObj;
  31147. this.current.fontSize = size;
  31148. if (fontObj.isType3Font) {
  31149. return; // we don't need ctx.font for Type3 fonts
  31150. }
  31151. var name = fontObj.loadedName || 'sans-serif';
  31152. var bold = fontObj.black ? (fontObj.bold ? '900' : 'bold') :
  31153. (fontObj.bold ? 'bold' : 'normal');
  31154. var italic = fontObj.italic ? 'italic' : 'normal';
  31155. var typeface = '"' + name + '", ' + fontObj.fallbackName;
  31156. // Some font backends cannot handle fonts below certain size.
  31157. // Keeping the font at minimal size and using the fontSizeScale to change
  31158. // the current transformation matrix before the fillText/strokeText.
  31159. // See https://bugzilla.mozilla.org/show_bug.cgi?id=726227
  31160. var browserFontSize = size < MIN_FONT_SIZE ? MIN_FONT_SIZE :
  31161. size > MAX_FONT_SIZE ? MAX_FONT_SIZE : size;
  31162. this.current.fontSizeScale = size / browserFontSize;
  31163. var rule = italic + ' ' + bold + ' ' + browserFontSize + 'px ' + typeface;
  31164. this.ctx.font = rule;
  31165. },
  31166. setTextRenderingMode: function CanvasGraphics_setTextRenderingMode(mode) {
  31167. this.current.textRenderingMode = mode;
  31168. },
  31169. setTextRise: function CanvasGraphics_setTextRise(rise) {
  31170. this.current.textRise = rise;
  31171. },
  31172. moveText: function CanvasGraphics_moveText(x, y) {
  31173. this.current.x = this.current.lineX += x;
  31174. this.current.y = this.current.lineY += y;
  31175. },
  31176. setLeadingMoveText: function CanvasGraphics_setLeadingMoveText(x, y) {
  31177. this.setLeading(-y);
  31178. this.moveText(x, y);
  31179. },
  31180. setTextMatrix: function CanvasGraphics_setTextMatrix(a, b, c, d, e, f) {
  31181. this.current.textMatrix = [a, b, c, d, e, f];
  31182. this.current.textMatrixScale = Math.sqrt(a * a + b * b);
  31183. this.current.x = this.current.lineX = 0;
  31184. this.current.y = this.current.lineY = 0;
  31185. },
  31186. nextLine: function CanvasGraphics_nextLine() {
  31187. this.moveText(0, this.current.leading);
  31188. },
  31189. paintChar: function CanvasGraphics_paintChar(character, x, y) {
  31190. var ctx = this.ctx;
  31191. var current = this.current;
  31192. var font = current.font;
  31193. var textRenderingMode = current.textRenderingMode;
  31194. var fontSize = current.fontSize / current.fontSizeScale;
  31195. var fillStrokeMode = textRenderingMode &
  31196. TextRenderingMode.FILL_STROKE_MASK;
  31197. var isAddToPathSet = !!(textRenderingMode &
  31198. TextRenderingMode.ADD_TO_PATH_FLAG);
  31199. var addToPath;
  31200. if (font.disableFontFace || isAddToPathSet) {
  31201. addToPath = font.getPathGenerator(this.commonObjs, character);
  31202. }
  31203. if (font.disableFontFace) {
  31204. ctx.save();
  31205. ctx.translate(x, y);
  31206. ctx.beginPath();
  31207. addToPath(ctx, fontSize);
  31208. if (fillStrokeMode === TextRenderingMode.FILL ||
  31209. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  31210. ctx.fill();
  31211. }
  31212. if (fillStrokeMode === TextRenderingMode.STROKE ||
  31213. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  31214. ctx.stroke();
  31215. }
  31216. ctx.restore();
  31217. } else {
  31218. if (fillStrokeMode === TextRenderingMode.FILL ||
  31219. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  31220. ctx.fillText(character, x, y);
  31221. }
  31222. if (fillStrokeMode === TextRenderingMode.STROKE ||
  31223. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  31224. ctx.strokeText(character, x, y);
  31225. }
  31226. }
  31227. if (isAddToPathSet) {
  31228. var paths = this.pendingTextPaths || (this.pendingTextPaths = []);
  31229. paths.push({
  31230. transform: ctx.mozCurrentTransform,
  31231. x: x,
  31232. y: y,
  31233. fontSize: fontSize,
  31234. addToPath: addToPath
  31235. });
  31236. }
  31237. },
  31238. get isFontSubpixelAAEnabled() {
  31239. // Checks if anti-aliasing is enabled when scaled text is painted.
  31240. // On Windows GDI scaled fonts looks bad.
  31241. var ctx = document.createElement('canvas').getContext('2d');
  31242. ctx.scale(1.5, 1);
  31243. ctx.fillText('I', 0, 10);
  31244. var data = ctx.getImageData(0, 0, 10, 10).data;
  31245. var enabled = false;
  31246. for (var i = 3; i < data.length; i += 4) {
  31247. if (data[i] > 0 && data[i] < 255) {
  31248. enabled = true;
  31249. break;
  31250. }
  31251. }
  31252. return shadow(this, 'isFontSubpixelAAEnabled', enabled);
  31253. },
  31254. showText: function CanvasGraphics_showText(glyphs) {
  31255. var current = this.current;
  31256. var font = current.font;
  31257. if (font.isType3Font) {
  31258. return this.showType3Text(glyphs);
  31259. }
  31260. var fontSize = current.fontSize;
  31261. if (fontSize === 0) {
  31262. return;
  31263. }
  31264. var ctx = this.ctx;
  31265. var fontSizeScale = current.fontSizeScale;
  31266. var charSpacing = current.charSpacing;
  31267. var wordSpacing = current.wordSpacing;
  31268. var fontDirection = current.fontDirection;
  31269. var textHScale = current.textHScale * fontDirection;
  31270. var glyphsLength = glyphs.length;
  31271. var vertical = font.vertical;
  31272. var spacingDir = vertical ? 1 : -1;
  31273. var defaultVMetrics = font.defaultVMetrics;
  31274. var widthAdvanceScale = fontSize * current.fontMatrix[0];
  31275. var simpleFillText =
  31276. current.textRenderingMode === TextRenderingMode.FILL &&
  31277. !font.disableFontFace;
  31278. ctx.save();
  31279. ctx.transform.apply(ctx, current.textMatrix);
  31280. ctx.translate(current.x, current.y + current.textRise);
  31281. if (current.patternFill) {
  31282. // TODO: Some shading patterns are not applied correctly to text,
  31283. // e.g. issues 3988 and 5432, and ShowText-ShadingPattern.pdf.
  31284. ctx.fillStyle = current.fillColor.getPattern(ctx, this);
  31285. }
  31286. if (fontDirection > 0) {
  31287. ctx.scale(textHScale, -1);
  31288. } else {
  31289. ctx.scale(textHScale, 1);
  31290. }
  31291. var lineWidth = current.lineWidth;
  31292. var scale = current.textMatrixScale;
  31293. if (scale === 0 || lineWidth === 0) {
  31294. var fillStrokeMode = current.textRenderingMode &
  31295. TextRenderingMode.FILL_STROKE_MASK;
  31296. if (fillStrokeMode === TextRenderingMode.STROKE ||
  31297. fillStrokeMode === TextRenderingMode.FILL_STROKE) {
  31298. this.cachedGetSinglePixelWidth = null;
  31299. lineWidth = this.getSinglePixelWidth() * MIN_WIDTH_FACTOR;
  31300. }
  31301. } else {
  31302. lineWidth /= scale;
  31303. }
  31304. if (fontSizeScale !== 1.0) {
  31305. ctx.scale(fontSizeScale, fontSizeScale);
  31306. lineWidth /= fontSizeScale;
  31307. }
  31308. ctx.lineWidth = lineWidth;
  31309. var x = 0, i;
  31310. for (i = 0; i < glyphsLength; ++i) {
  31311. var glyph = glyphs[i];
  31312. if (isNum(glyph)) {
  31313. x += spacingDir * glyph * fontSize / 1000;
  31314. continue;
  31315. }
  31316. var restoreNeeded = false;
  31317. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  31318. var character = glyph.fontChar;
  31319. var accent = glyph.accent;
  31320. var scaledX, scaledY, scaledAccentX, scaledAccentY;
  31321. var width = glyph.width;
  31322. if (vertical) {
  31323. var vmetric, vx, vy;
  31324. vmetric = glyph.vmetric || defaultVMetrics;
  31325. vx = glyph.vmetric ? vmetric[1] : width * 0.5;
  31326. vx = -vx * widthAdvanceScale;
  31327. vy = vmetric[2] * widthAdvanceScale;
  31328. width = vmetric ? -vmetric[0] : width;
  31329. scaledX = vx / fontSizeScale;
  31330. scaledY = (x + vy) / fontSizeScale;
  31331. } else {
  31332. scaledX = x / fontSizeScale;
  31333. scaledY = 0;
  31334. }
  31335. if (font.remeasure && width > 0) {
  31336. // Some standard fonts may not have the exact width: rescale per
  31337. // character if measured width is greater than expected glyph width
  31338. // and subpixel-aa is enabled, otherwise just center the glyph.
  31339. var measuredWidth = ctx.measureText(character).width * 1000 /
  31340. fontSize * fontSizeScale;
  31341. if (width < measuredWidth && this.isFontSubpixelAAEnabled) {
  31342. var characterScaleX = width / measuredWidth;
  31343. restoreNeeded = true;
  31344. ctx.save();
  31345. ctx.scale(characterScaleX, 1);
  31346. scaledX /= characterScaleX;
  31347. } else if (width !== measuredWidth) {
  31348. scaledX += (width - measuredWidth) / 2000 *
  31349. fontSize / fontSizeScale;
  31350. }
  31351. }
  31352. // Only attempt to draw the glyph if it is actually in the embedded font
  31353. // file or if there isn't a font file so the fallback font is shown.
  31354. if (glyph.isInFont || font.missingFile) {
  31355. if (simpleFillText && !accent) {
  31356. // common case
  31357. ctx.fillText(character, scaledX, scaledY);
  31358. } else {
  31359. this.paintChar(character, scaledX, scaledY);
  31360. if (accent) {
  31361. scaledAccentX = scaledX + accent.offset.x / fontSizeScale;
  31362. scaledAccentY = scaledY - accent.offset.y / fontSizeScale;
  31363. this.paintChar(accent.fontChar, scaledAccentX, scaledAccentY);
  31364. }
  31365. }
  31366. }
  31367. var charWidth = width * widthAdvanceScale + spacing * fontDirection;
  31368. x += charWidth;
  31369. if (restoreNeeded) {
  31370. ctx.restore();
  31371. }
  31372. }
  31373. if (vertical) {
  31374. current.y -= x * textHScale;
  31375. } else {
  31376. current.x += x * textHScale;
  31377. }
  31378. ctx.restore();
  31379. },
  31380. showType3Text: function CanvasGraphics_showType3Text(glyphs) {
  31381. // Type3 fonts - each glyph is a "mini-PDF"
  31382. var ctx = this.ctx;
  31383. var current = this.current;
  31384. var font = current.font;
  31385. var fontSize = current.fontSize;
  31386. var fontDirection = current.fontDirection;
  31387. var spacingDir = font.vertical ? 1 : -1;
  31388. var charSpacing = current.charSpacing;
  31389. var wordSpacing = current.wordSpacing;
  31390. var textHScale = current.textHScale * fontDirection;
  31391. var fontMatrix = current.fontMatrix || FONT_IDENTITY_MATRIX;
  31392. var glyphsLength = glyphs.length;
  31393. var isTextInvisible =
  31394. current.textRenderingMode === TextRenderingMode.INVISIBLE;
  31395. var i, glyph, width, spacingLength;
  31396. if (isTextInvisible || fontSize === 0) {
  31397. return;
  31398. }
  31399. this.cachedGetSinglePixelWidth = null;
  31400. ctx.save();
  31401. ctx.transform.apply(ctx, current.textMatrix);
  31402. ctx.translate(current.x, current.y);
  31403. ctx.scale(textHScale, fontDirection);
  31404. for (i = 0; i < glyphsLength; ++i) {
  31405. glyph = glyphs[i];
  31406. if (isNum(glyph)) {
  31407. spacingLength = spacingDir * glyph * fontSize / 1000;
  31408. this.ctx.translate(spacingLength, 0);
  31409. current.x += spacingLength * textHScale;
  31410. continue;
  31411. }
  31412. var spacing = (glyph.isSpace ? wordSpacing : 0) + charSpacing;
  31413. var operatorList = font.charProcOperatorList[glyph.operatorListId];
  31414. if (!operatorList) {
  31415. warn('Type3 character \"' + glyph.operatorListId +
  31416. '\" is not available');
  31417. continue;
  31418. }
  31419. this.processingType3 = glyph;
  31420. this.save();
  31421. ctx.scale(fontSize, fontSize);
  31422. ctx.transform.apply(ctx, fontMatrix);
  31423. this.executeOperatorList(operatorList);
  31424. this.restore();
  31425. var transformed = Util.applyTransform([glyph.width, 0], fontMatrix);
  31426. width = transformed[0] * fontSize + spacing;
  31427. ctx.translate(width, 0);
  31428. current.x += width * textHScale;
  31429. }
  31430. ctx.restore();
  31431. this.processingType3 = null;
  31432. },
  31433. // Type3 fonts
  31434. setCharWidth: function CanvasGraphics_setCharWidth(xWidth, yWidth) {
  31435. // We can safely ignore this since the width should be the same
  31436. // as the width in the Widths array.
  31437. },
  31438. setCharWidthAndBounds: function CanvasGraphics_setCharWidthAndBounds(xWidth,
  31439. yWidth,
  31440. llx,
  31441. lly,
  31442. urx,
  31443. ury) {
  31444. // TODO According to the spec we're also suppose to ignore any operators
  31445. // that set color or include images while processing this type3 font.
  31446. this.ctx.rect(llx, lly, urx - llx, ury - lly);
  31447. this.clip();
  31448. this.endPath();
  31449. },
  31450. // Color
  31451. getColorN_Pattern: function CanvasGraphics_getColorN_Pattern(IR) {
  31452. var pattern;
  31453. if (IR[0] === 'TilingPattern') {
  31454. var color = IR[1];
  31455. var baseTransform = this.baseTransform ||
  31456. this.ctx.mozCurrentTransform.slice();
  31457. var self = this;
  31458. var canvasGraphicsFactory = {
  31459. createCanvasGraphics: function (ctx) {
  31460. return new CanvasGraphics(ctx, self.commonObjs, self.objs);
  31461. }
  31462. };
  31463. pattern = new TilingPattern(IR, color, this.ctx, canvasGraphicsFactory,
  31464. baseTransform);
  31465. } else {
  31466. pattern = getShadingPatternFromIR(IR);
  31467. }
  31468. return pattern;
  31469. },
  31470. setStrokeColorN: function CanvasGraphics_setStrokeColorN(/*...*/) {
  31471. this.current.strokeColor = this.getColorN_Pattern(arguments);
  31472. },
  31473. setFillColorN: function CanvasGraphics_setFillColorN(/*...*/) {
  31474. this.current.fillColor = this.getColorN_Pattern(arguments);
  31475. this.current.patternFill = true;
  31476. },
  31477. setStrokeRGBColor: function CanvasGraphics_setStrokeRGBColor(r, g, b) {
  31478. var color = Util.makeCssRgb(r, g, b);
  31479. this.ctx.strokeStyle = color;
  31480. this.current.strokeColor = color;
  31481. },
  31482. setFillRGBColor: function CanvasGraphics_setFillRGBColor(r, g, b) {
  31483. var color = Util.makeCssRgb(r, g, b);
  31484. this.ctx.fillStyle = color;
  31485. this.current.fillColor = color;
  31486. this.current.patternFill = false;
  31487. },
  31488. shadingFill: function CanvasGraphics_shadingFill(patternIR) {
  31489. var ctx = this.ctx;
  31490. this.save();
  31491. var pattern = getShadingPatternFromIR(patternIR);
  31492. ctx.fillStyle = pattern.getPattern(ctx, this, true);
  31493. var inv = ctx.mozCurrentTransformInverse;
  31494. if (inv) {
  31495. var canvas = ctx.canvas;
  31496. var width = canvas.width;
  31497. var height = canvas.height;
  31498. var bl = Util.applyTransform([0, 0], inv);
  31499. var br = Util.applyTransform([0, height], inv);
  31500. var ul = Util.applyTransform([width, 0], inv);
  31501. var ur = Util.applyTransform([width, height], inv);
  31502. var x0 = Math.min(bl[0], br[0], ul[0], ur[0]);
  31503. var y0 = Math.min(bl[1], br[1], ul[1], ur[1]);
  31504. var x1 = Math.max(bl[0], br[0], ul[0], ur[0]);
  31505. var y1 = Math.max(bl[1], br[1], ul[1], ur[1]);
  31506. this.ctx.fillRect(x0, y0, x1 - x0, y1 - y0);
  31507. } else {
  31508. // HACK to draw the gradient onto an infinite rectangle.
  31509. // PDF gradients are drawn across the entire image while
  31510. // Canvas only allows gradients to be drawn in a rectangle
  31511. // The following bug should allow us to remove this.
  31512. // https://bugzilla.mozilla.org/show_bug.cgi?id=664884
  31513. this.ctx.fillRect(-1e10, -1e10, 2e10, 2e10);
  31514. }
  31515. this.restore();
  31516. },
  31517. // Images
  31518. beginInlineImage: function CanvasGraphics_beginInlineImage() {
  31519. error('Should not call beginInlineImage');
  31520. },
  31521. beginImageData: function CanvasGraphics_beginImageData() {
  31522. error('Should not call beginImageData');
  31523. },
  31524. paintFormXObjectBegin: function CanvasGraphics_paintFormXObjectBegin(matrix,
  31525. bbox) {
  31526. this.save();
  31527. this.baseTransformStack.push(this.baseTransform);
  31528. if (isArray(matrix) && 6 === matrix.length) {
  31529. this.transform.apply(this, matrix);
  31530. }
  31531. this.baseTransform = this.ctx.mozCurrentTransform;
  31532. if (isArray(bbox) && 4 === bbox.length) {
  31533. var width = bbox[2] - bbox[0];
  31534. var height = bbox[3] - bbox[1];
  31535. this.ctx.rect(bbox[0], bbox[1], width, height);
  31536. this.clip();
  31537. this.endPath();
  31538. }
  31539. },
  31540. paintFormXObjectEnd: function CanvasGraphics_paintFormXObjectEnd() {
  31541. this.restore();
  31542. this.baseTransform = this.baseTransformStack.pop();
  31543. },
  31544. beginGroup: function CanvasGraphics_beginGroup(group) {
  31545. this.save();
  31546. var currentCtx = this.ctx;
  31547. // TODO non-isolated groups - according to Rik at adobe non-isolated
  31548. // group results aren't usually that different and they even have tools
  31549. // that ignore this setting. Notes from Rik on implmenting:
  31550. // - When you encounter an transparency group, create a new canvas with
  31551. // the dimensions of the bbox
  31552. // - copy the content from the previous canvas to the new canvas
  31553. // - draw as usual
  31554. // - remove the backdrop alpha:
  31555. // alphaNew = 1 - (1 - alpha)/(1 - alphaBackdrop) with 'alpha' the alpha
  31556. // value of your transparency group and 'alphaBackdrop' the alpha of the
  31557. // backdrop
  31558. // - remove background color:
  31559. // colorNew = color - alphaNew *colorBackdrop /(1 - alphaNew)
  31560. if (!group.isolated) {
  31561. info('TODO: Support non-isolated groups.');
  31562. }
  31563. // TODO knockout - supposedly possible with the clever use of compositing
  31564. // modes.
  31565. if (group.knockout) {
  31566. warn('Knockout groups not supported.');
  31567. }
  31568. var currentTransform = currentCtx.mozCurrentTransform;
  31569. if (group.matrix) {
  31570. currentCtx.transform.apply(currentCtx, group.matrix);
  31571. }
  31572. assert(group.bbox, 'Bounding box is required.');
  31573. // Based on the current transform figure out how big the bounding box
  31574. // will actually be.
  31575. var bounds = Util.getAxialAlignedBoundingBox(
  31576. group.bbox,
  31577. currentCtx.mozCurrentTransform);
  31578. // Clip the bounding box to the current canvas.
  31579. var canvasBounds = [0,
  31580. 0,
  31581. currentCtx.canvas.width,
  31582. currentCtx.canvas.height];
  31583. bounds = Util.intersect(bounds, canvasBounds) || [0, 0, 0, 0];
  31584. // Use ceil in case we're between sizes so we don't create canvas that is
  31585. // too small and make the canvas at least 1x1 pixels.
  31586. var offsetX = Math.floor(bounds[0]);
  31587. var offsetY = Math.floor(bounds[1]);
  31588. var drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
  31589. var drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
  31590. var scaleX = 1, scaleY = 1;
  31591. if (drawnWidth > MAX_GROUP_SIZE) {
  31592. scaleX = drawnWidth / MAX_GROUP_SIZE;
  31593. drawnWidth = MAX_GROUP_SIZE;
  31594. }
  31595. if (drawnHeight > MAX_GROUP_SIZE) {
  31596. scaleY = drawnHeight / MAX_GROUP_SIZE;
  31597. drawnHeight = MAX_GROUP_SIZE;
  31598. }
  31599. var cacheId = 'groupAt' + this.groupLevel;
  31600. if (group.smask) {
  31601. // Using two cache entries is case if masks are used one after another.
  31602. cacheId += '_smask_' + ((this.smaskCounter++) % 2);
  31603. }
  31604. var scratchCanvas = this.cachedCanvases.getCanvas(
  31605. cacheId, drawnWidth, drawnHeight, true);
  31606. var groupCtx = scratchCanvas.context;
  31607. // Since we created a new canvas that is just the size of the bounding box
  31608. // we have to translate the group ctx.
  31609. groupCtx.scale(1 / scaleX, 1 / scaleY);
  31610. groupCtx.translate(-offsetX, -offsetY);
  31611. groupCtx.transform.apply(groupCtx, currentTransform);
  31612. if (group.smask) {
  31613. // Saving state and cached mask to be used in setGState.
  31614. this.smaskStack.push({
  31615. canvas: scratchCanvas.canvas,
  31616. context: groupCtx,
  31617. offsetX: offsetX,
  31618. offsetY: offsetY,
  31619. scaleX: scaleX,
  31620. scaleY: scaleY,
  31621. subtype: group.smask.subtype,
  31622. backdrop: group.smask.backdrop,
  31623. transferMap: group.smask.transferMap || null
  31624. });
  31625. } else {
  31626. // Setup the current ctx so when the group is popped we draw it at the
  31627. // right location.
  31628. currentCtx.setTransform(1, 0, 0, 1, 0, 0);
  31629. currentCtx.translate(offsetX, offsetY);
  31630. currentCtx.scale(scaleX, scaleY);
  31631. }
  31632. // The transparency group inherits all off the current graphics state
  31633. // except the blend mode, soft mask, and alpha constants.
  31634. copyCtxState(currentCtx, groupCtx);
  31635. this.ctx = groupCtx;
  31636. this.setGState([
  31637. ['BM', 'Normal'],
  31638. ['ca', 1],
  31639. ['CA', 1]
  31640. ]);
  31641. this.groupStack.push(currentCtx);
  31642. this.groupLevel++;
  31643. },
  31644. endGroup: function CanvasGraphics_endGroup(group) {
  31645. this.groupLevel--;
  31646. var groupCtx = this.ctx;
  31647. this.ctx = this.groupStack.pop();
  31648. // Turn off image smoothing to avoid sub pixel interpolation which can
  31649. // look kind of blurry for some pdfs.
  31650. if (this.ctx.imageSmoothingEnabled !== undefined) {
  31651. this.ctx.imageSmoothingEnabled = false;
  31652. } else {
  31653. this.ctx.mozImageSmoothingEnabled = false;
  31654. }
  31655. if (group.smask) {
  31656. this.tempSMask = this.smaskStack.pop();
  31657. } else {
  31658. this.ctx.drawImage(groupCtx.canvas, 0, 0);
  31659. }
  31660. this.restore();
  31661. },
  31662. beginAnnotations: function CanvasGraphics_beginAnnotations() {
  31663. this.save();
  31664. this.current = new CanvasExtraState();
  31665. if (this.baseTransform) {
  31666. this.ctx.setTransform.apply(this.ctx, this.baseTransform);
  31667. }
  31668. },
  31669. endAnnotations: function CanvasGraphics_endAnnotations() {
  31670. this.restore();
  31671. },
  31672. beginAnnotation: function CanvasGraphics_beginAnnotation(rect, transform,
  31673. matrix) {
  31674. this.save();
  31675. if (isArray(rect) && 4 === rect.length) {
  31676. var width = rect[2] - rect[0];
  31677. var height = rect[3] - rect[1];
  31678. this.ctx.rect(rect[0], rect[1], width, height);
  31679. this.clip();
  31680. this.endPath();
  31681. }
  31682. this.transform.apply(this, transform);
  31683. this.transform.apply(this, matrix);
  31684. },
  31685. endAnnotation: function CanvasGraphics_endAnnotation() {
  31686. this.restore();
  31687. },
  31688. paintJpegXObject: function CanvasGraphics_paintJpegXObject(objId, w, h) {
  31689. var domImage = this.objs.get(objId);
  31690. if (!domImage) {
  31691. warn('Dependent image isn\'t ready yet');
  31692. return;
  31693. }
  31694. this.save();
  31695. var ctx = this.ctx;
  31696. // scale the image to the unit square
  31697. ctx.scale(1 / w, -1 / h);
  31698. ctx.drawImage(domImage, 0, 0, domImage.width, domImage.height,
  31699. 0, -h, w, h);
  31700. if (this.imageLayer) {
  31701. var currentTransform = ctx.mozCurrentTransformInverse;
  31702. var position = this.getCanvasPosition(0, 0);
  31703. this.imageLayer.appendImage({
  31704. objId: objId,
  31705. left: position[0],
  31706. top: position[1],
  31707. width: w / currentTransform[0],
  31708. height: h / currentTransform[3]
  31709. });
  31710. }
  31711. this.restore();
  31712. },
  31713. paintImageMaskXObject: function CanvasGraphics_paintImageMaskXObject(img) {
  31714. var ctx = this.ctx;
  31715. var width = img.width, height = img.height;
  31716. var fillColor = this.current.fillColor;
  31717. var isPatternFill = this.current.patternFill;
  31718. var glyph = this.processingType3;
  31719. if (COMPILE_TYPE3_GLYPHS && glyph && glyph.compiled === undefined) {
  31720. if (width <= MAX_SIZE_TO_COMPILE && height <= MAX_SIZE_TO_COMPILE) {
  31721. glyph.compiled =
  31722. compileType3Glyph({data: img.data, width: width, height: height});
  31723. } else {
  31724. glyph.compiled = null;
  31725. }
  31726. }
  31727. if (glyph && glyph.compiled) {
  31728. glyph.compiled(ctx);
  31729. return;
  31730. }
  31731. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  31732. width, height);
  31733. var maskCtx = maskCanvas.context;
  31734. maskCtx.save();
  31735. putBinaryImageMask(maskCtx, img);
  31736. maskCtx.globalCompositeOperation = 'source-in';
  31737. maskCtx.fillStyle = isPatternFill ?
  31738. fillColor.getPattern(maskCtx, this) : fillColor;
  31739. maskCtx.fillRect(0, 0, width, height);
  31740. maskCtx.restore();
  31741. this.paintInlineImageXObject(maskCanvas.canvas);
  31742. },
  31743. paintImageMaskXObjectRepeat:
  31744. function CanvasGraphics_paintImageMaskXObjectRepeat(imgData, scaleX,
  31745. scaleY, positions) {
  31746. var width = imgData.width;
  31747. var height = imgData.height;
  31748. var fillColor = this.current.fillColor;
  31749. var isPatternFill = this.current.patternFill;
  31750. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  31751. width, height);
  31752. var maskCtx = maskCanvas.context;
  31753. maskCtx.save();
  31754. putBinaryImageMask(maskCtx, imgData);
  31755. maskCtx.globalCompositeOperation = 'source-in';
  31756. maskCtx.fillStyle = isPatternFill ?
  31757. fillColor.getPattern(maskCtx, this) : fillColor;
  31758. maskCtx.fillRect(0, 0, width, height);
  31759. maskCtx.restore();
  31760. var ctx = this.ctx;
  31761. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  31762. ctx.save();
  31763. ctx.transform(scaleX, 0, 0, scaleY, positions[i], positions[i + 1]);
  31764. ctx.scale(1, -1);
  31765. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  31766. 0, -1, 1, 1);
  31767. ctx.restore();
  31768. }
  31769. },
  31770. paintImageMaskXObjectGroup:
  31771. function CanvasGraphics_paintImageMaskXObjectGroup(images) {
  31772. var ctx = this.ctx;
  31773. var fillColor = this.current.fillColor;
  31774. var isPatternFill = this.current.patternFill;
  31775. for (var i = 0, ii = images.length; i < ii; i++) {
  31776. var image = images[i];
  31777. var width = image.width, height = image.height;
  31778. var maskCanvas = this.cachedCanvases.getCanvas('maskCanvas',
  31779. width, height);
  31780. var maskCtx = maskCanvas.context;
  31781. maskCtx.save();
  31782. putBinaryImageMask(maskCtx, image);
  31783. maskCtx.globalCompositeOperation = 'source-in';
  31784. maskCtx.fillStyle = isPatternFill ?
  31785. fillColor.getPattern(maskCtx, this) : fillColor;
  31786. maskCtx.fillRect(0, 0, width, height);
  31787. maskCtx.restore();
  31788. ctx.save();
  31789. ctx.transform.apply(ctx, image.transform);
  31790. ctx.scale(1, -1);
  31791. ctx.drawImage(maskCanvas.canvas, 0, 0, width, height,
  31792. 0, -1, 1, 1);
  31793. ctx.restore();
  31794. }
  31795. },
  31796. paintImageXObject: function CanvasGraphics_paintImageXObject(objId) {
  31797. var imgData = this.objs.get(objId);
  31798. if (!imgData) {
  31799. warn('Dependent image isn\'t ready yet');
  31800. return;
  31801. }
  31802. this.paintInlineImageXObject(imgData);
  31803. },
  31804. paintImageXObjectRepeat:
  31805. function CanvasGraphics_paintImageXObjectRepeat(objId, scaleX, scaleY,
  31806. positions) {
  31807. var imgData = this.objs.get(objId);
  31808. if (!imgData) {
  31809. warn('Dependent image isn\'t ready yet');
  31810. return;
  31811. }
  31812. var width = imgData.width;
  31813. var height = imgData.height;
  31814. var map = [];
  31815. for (var i = 0, ii = positions.length; i < ii; i += 2) {
  31816. map.push({transform: [scaleX, 0, 0, scaleY, positions[i],
  31817. positions[i + 1]], x: 0, y: 0, w: width, h: height});
  31818. }
  31819. this.paintInlineImageXObjectGroup(imgData, map);
  31820. },
  31821. paintInlineImageXObject:
  31822. function CanvasGraphics_paintInlineImageXObject(imgData) {
  31823. var width = imgData.width;
  31824. var height = imgData.height;
  31825. var ctx = this.ctx;
  31826. this.save();
  31827. // scale the image to the unit square
  31828. ctx.scale(1 / width, -1 / height);
  31829. var currentTransform = ctx.mozCurrentTransformInverse;
  31830. var a = currentTransform[0], b = currentTransform[1];
  31831. var widthScale = Math.max(Math.sqrt(a * a + b * b), 1);
  31832. var c = currentTransform[2], d = currentTransform[3];
  31833. var heightScale = Math.max(Math.sqrt(c * c + d * d), 1);
  31834. var imgToPaint, tmpCanvas;
  31835. // instanceof HTMLElement does not work in jsdom node.js module
  31836. if (imgData instanceof HTMLElement || !imgData.data) {
  31837. imgToPaint = imgData;
  31838. } else {
  31839. tmpCanvas = this.cachedCanvases.getCanvas('inlineImage',
  31840. width, height);
  31841. var tmpCtx = tmpCanvas.context;
  31842. putBinaryImageData(tmpCtx, imgData);
  31843. imgToPaint = tmpCanvas.canvas;
  31844. }
  31845. var paintWidth = width, paintHeight = height;
  31846. var tmpCanvasId = 'prescale1';
  31847. // Vertial or horizontal scaling shall not be more than 2 to not loose the
  31848. // pixels during drawImage operation, painting on the temporary canvas(es)
  31849. // that are twice smaller in size
  31850. while ((widthScale > 2 && paintWidth > 1) ||
  31851. (heightScale > 2 && paintHeight > 1)) {
  31852. var newWidth = paintWidth, newHeight = paintHeight;
  31853. if (widthScale > 2 && paintWidth > 1) {
  31854. newWidth = Math.ceil(paintWidth / 2);
  31855. widthScale /= paintWidth / newWidth;
  31856. }
  31857. if (heightScale > 2 && paintHeight > 1) {
  31858. newHeight = Math.ceil(paintHeight / 2);
  31859. heightScale /= paintHeight / newHeight;
  31860. }
  31861. tmpCanvas = this.cachedCanvases.getCanvas(tmpCanvasId,
  31862. newWidth, newHeight);
  31863. tmpCtx = tmpCanvas.context;
  31864. tmpCtx.clearRect(0, 0, newWidth, newHeight);
  31865. tmpCtx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  31866. 0, 0, newWidth, newHeight);
  31867. imgToPaint = tmpCanvas.canvas;
  31868. paintWidth = newWidth;
  31869. paintHeight = newHeight;
  31870. tmpCanvasId = tmpCanvasId === 'prescale1' ? 'prescale2' : 'prescale1';
  31871. }
  31872. ctx.drawImage(imgToPaint, 0, 0, paintWidth, paintHeight,
  31873. 0, -height, width, height);
  31874. if (this.imageLayer) {
  31875. var position = this.getCanvasPosition(0, -height);
  31876. this.imageLayer.appendImage({
  31877. imgData: imgData,
  31878. left: position[0],
  31879. top: position[1],
  31880. width: width / currentTransform[0],
  31881. height: height / currentTransform[3]
  31882. });
  31883. }
  31884. this.restore();
  31885. },
  31886. paintInlineImageXObjectGroup:
  31887. function CanvasGraphics_paintInlineImageXObjectGroup(imgData, map) {
  31888. var ctx = this.ctx;
  31889. var w = imgData.width;
  31890. var h = imgData.height;
  31891. var tmpCanvas = this.cachedCanvases.getCanvas('inlineImage', w, h);
  31892. var tmpCtx = tmpCanvas.context;
  31893. putBinaryImageData(tmpCtx, imgData);
  31894. for (var i = 0, ii = map.length; i < ii; i++) {
  31895. var entry = map[i];
  31896. ctx.save();
  31897. ctx.transform.apply(ctx, entry.transform);
  31898. ctx.scale(1, -1);
  31899. ctx.drawImage(tmpCanvas.canvas, entry.x, entry.y, entry.w, entry.h,
  31900. 0, -1, 1, 1);
  31901. if (this.imageLayer) {
  31902. var position = this.getCanvasPosition(entry.x, entry.y);
  31903. this.imageLayer.appendImage({
  31904. imgData: imgData,
  31905. left: position[0],
  31906. top: position[1],
  31907. width: w,
  31908. height: h
  31909. });
  31910. }
  31911. ctx.restore();
  31912. }
  31913. },
  31914. paintSolidColorImageMask:
  31915. function CanvasGraphics_paintSolidColorImageMask() {
  31916. this.ctx.fillRect(0, 0, 1, 1);
  31917. },
  31918. paintXObject: function CanvasGraphics_paintXObject() {
  31919. warn('Unsupported \'paintXObject\' command.');
  31920. },
  31921. // Marked content
  31922. markPoint: function CanvasGraphics_markPoint(tag) {
  31923. // TODO Marked content.
  31924. },
  31925. markPointProps: function CanvasGraphics_markPointProps(tag, properties) {
  31926. // TODO Marked content.
  31927. },
  31928. beginMarkedContent: function CanvasGraphics_beginMarkedContent(tag) {
  31929. // TODO Marked content.
  31930. },
  31931. beginMarkedContentProps: function CanvasGraphics_beginMarkedContentProps(
  31932. tag, properties) {
  31933. // TODO Marked content.
  31934. },
  31935. endMarkedContent: function CanvasGraphics_endMarkedContent() {
  31936. // TODO Marked content.
  31937. },
  31938. // Compatibility
  31939. beginCompat: function CanvasGraphics_beginCompat() {
  31940. // TODO ignore undefined operators (should we do that anyway?)
  31941. },
  31942. endCompat: function CanvasGraphics_endCompat() {
  31943. // TODO stop ignoring undefined operators
  31944. },
  31945. // Helper functions
  31946. consumePath: function CanvasGraphics_consumePath() {
  31947. var ctx = this.ctx;
  31948. if (this.pendingClip) {
  31949. if (this.pendingClip === EO_CLIP) {
  31950. if (ctx.mozFillRule !== undefined) {
  31951. ctx.mozFillRule = 'evenodd';
  31952. ctx.clip();
  31953. ctx.mozFillRule = 'nonzero';
  31954. } else {
  31955. ctx.clip('evenodd');
  31956. }
  31957. } else {
  31958. ctx.clip();
  31959. }
  31960. this.pendingClip = null;
  31961. }
  31962. ctx.beginPath();
  31963. },
  31964. getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) {
  31965. if (this.cachedGetSinglePixelWidth === null) {
  31966. var inverse = this.ctx.mozCurrentTransformInverse;
  31967. // max of the current horizontal and vertical scale
  31968. this.cachedGetSinglePixelWidth = Math.sqrt(Math.max(
  31969. (inverse[0] * inverse[0] + inverse[1] * inverse[1]),
  31970. (inverse[2] * inverse[2] + inverse[3] * inverse[3])));
  31971. }
  31972. return this.cachedGetSinglePixelWidth;
  31973. },
  31974. getCanvasPosition: function CanvasGraphics_getCanvasPosition(x, y) {
  31975. var transform = this.ctx.mozCurrentTransform;
  31976. return [
  31977. transform[0] * x + transform[2] * y + transform[4],
  31978. transform[1] * x + transform[3] * y + transform[5]
  31979. ];
  31980. }
  31981. };
  31982. for (var op in OPS) {
  31983. CanvasGraphics.prototype[OPS[op]] = CanvasGraphics.prototype[op];
  31984. }
  31985. return CanvasGraphics;
  31986. })();
  31987. exports.CanvasGraphics = CanvasGraphics;
  31988. exports.createScratchCanvas = createScratchCanvas;
  31989. }));
  31990. (function (root, factory) {
  31991. {
  31992. factory((root.pdfjsCoreFonts = {}), root.pdfjsSharedUtil,
  31993. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  31994. root.pdfjsCoreGlyphList, root.pdfjsCoreCharsets,
  31995. root.pdfjsCoreFontRenderer, root.pdfjsCoreEncodings,
  31996. root.pdfjsCoreStandardFonts, root.pdfjsCoreUnicode,
  31997. root.pdfjsCoreType1Parser, root.pdfjsCoreCFFParser);
  31998. }
  31999. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  32000. coreGlyphList, coreCharsets, coreFontRenderer,
  32001. coreEncodings, coreStandardFonts, coreUnicode,
  32002. coreType1Parser, coreCFFParser) {
  32003. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  32004. var FontType = sharedUtil.FontType;
  32005. var Util = sharedUtil.Util;
  32006. var assert = sharedUtil.assert;
  32007. var bytesToString = sharedUtil.bytesToString;
  32008. var error = sharedUtil.error;
  32009. var info = sharedUtil.info;
  32010. var isArray = sharedUtil.isArray;
  32011. var isInt = sharedUtil.isInt;
  32012. var isNum = sharedUtil.isNum;
  32013. var readUint32 = sharedUtil.readUint32;
  32014. var shadow = sharedUtil.shadow;
  32015. var stringToBytes = sharedUtil.stringToBytes;
  32016. var string32 = sharedUtil.string32;
  32017. var warn = sharedUtil.warn;
  32018. var MissingDataException = sharedUtil.MissingDataException;
  32019. var Stream = coreStream.Stream;
  32020. var Lexer = coreParser.Lexer;
  32021. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  32022. var getDingbatsGlyphsUnicode = coreGlyphList.getDingbatsGlyphsUnicode;
  32023. var ISOAdobeCharset = coreCharsets.ISOAdobeCharset;
  32024. var ExpertCharset = coreCharsets.ExpertCharset;
  32025. var ExpertSubsetCharset = coreCharsets.ExpertSubsetCharset;
  32026. var FontRendererFactory = coreFontRenderer.FontRendererFactory;
  32027. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  32028. var StandardEncoding = coreEncodings.StandardEncoding;
  32029. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  32030. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  32031. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  32032. var ExpertEncoding = coreEncodings.ExpertEncoding;
  32033. var getEncoding = coreEncodings.getEncoding;
  32034. var getStdFontMap = coreStandardFonts.getStdFontMap;
  32035. var getNonStdFontMap = coreStandardFonts.getNonStdFontMap;
  32036. var getGlyphMapForStandardFonts = coreStandardFonts.getGlyphMapForStandardFonts;
  32037. var getSupplementalGlyphMapForArialBlack =
  32038. coreStandardFonts.getSupplementalGlyphMapForArialBlack;
  32039. var getUnicodeRangeFor = coreUnicode.getUnicodeRangeFor;
  32040. var mapSpecialUnicodeValues = coreUnicode.mapSpecialUnicodeValues;
  32041. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  32042. var Type1Parser = coreType1Parser.Type1Parser;
  32043. var CFFStandardStrings = coreCFFParser.CFFStandardStrings;
  32044. var CFFParser = coreCFFParser.CFFParser;
  32045. var CFFCompiler = coreCFFParser.CFFCompiler;
  32046. var CFF = coreCFFParser.CFF;
  32047. var CFFHeader = coreCFFParser.CFFHeader;
  32048. var CFFTopDict = coreCFFParser.CFFTopDict;
  32049. var CFFPrivateDict = coreCFFParser.CFFPrivateDict;
  32050. var CFFStrings = coreCFFParser.CFFStrings;
  32051. var CFFIndex = coreCFFParser.CFFIndex;
  32052. var CFFCharset = coreCFFParser.CFFCharset;
  32053. // Unicode Private Use Area
  32054. var PRIVATE_USE_OFFSET_START = 0xE000;
  32055. var PRIVATE_USE_OFFSET_END = 0xF8FF;
  32056. var SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = false;
  32057. // PDF Glyph Space Units are one Thousandth of a TextSpace Unit
  32058. // except for Type 3 fonts
  32059. var PDF_GLYPH_SPACE_UNITS = 1000;
  32060. // Accented charactars are not displayed properly on Windows, using this flag
  32061. // to control analysis of seac charstrings.
  32062. var SEAC_ANALYSIS_ENABLED = false;
  32063. var FontFlags = {
  32064. FixedPitch: 1,
  32065. Serif: 2,
  32066. Symbolic: 4,
  32067. Script: 8,
  32068. Nonsymbolic: 32,
  32069. Italic: 64,
  32070. AllCap: 65536,
  32071. SmallCap: 131072,
  32072. ForceBold: 262144
  32073. };
  32074. var MacStandardGlyphOrdering = [
  32075. '.notdef', '.null', 'nonmarkingreturn', 'space', 'exclam', 'quotedbl',
  32076. 'numbersign', 'dollar', 'percent', 'ampersand', 'quotesingle', 'parenleft',
  32077. 'parenright', 'asterisk', 'plus', 'comma', 'hyphen', 'period', 'slash',
  32078. 'zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight',
  32079. 'nine', 'colon', 'semicolon', 'less', 'equal', 'greater', 'question', 'at',
  32080. 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
  32081. 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'bracketleft',
  32082. 'backslash', 'bracketright', 'asciicircum', 'underscore', 'grave', 'a', 'b',
  32083. 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
  32084. 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'braceleft', 'bar', 'braceright',
  32085. 'asciitilde', 'Adieresis', 'Aring', 'Ccedilla', 'Eacute', 'Ntilde',
  32086. 'Odieresis', 'Udieresis', 'aacute', 'agrave', 'acircumflex', 'adieresis',
  32087. 'atilde', 'aring', 'ccedilla', 'eacute', 'egrave', 'ecircumflex', 'edieresis',
  32088. 'iacute', 'igrave', 'icircumflex', 'idieresis', 'ntilde', 'oacute', 'ograve',
  32089. 'ocircumflex', 'odieresis', 'otilde', 'uacute', 'ugrave', 'ucircumflex',
  32090. 'udieresis', 'dagger', 'degree', 'cent', 'sterling', 'section', 'bullet',
  32091. 'paragraph', 'germandbls', 'registered', 'copyright', 'trademark', 'acute',
  32092. 'dieresis', 'notequal', 'AE', 'Oslash', 'infinity', 'plusminus', 'lessequal',
  32093. 'greaterequal', 'yen', 'mu', 'partialdiff', 'summation', 'product', 'pi',
  32094. 'integral', 'ordfeminine', 'ordmasculine', 'Omega', 'ae', 'oslash',
  32095. 'questiondown', 'exclamdown', 'logicalnot', 'radical', 'florin',
  32096. 'approxequal', 'Delta', 'guillemotleft', 'guillemotright', 'ellipsis',
  32097. 'nonbreakingspace', 'Agrave', 'Atilde', 'Otilde', 'OE', 'oe', 'endash',
  32098. 'emdash', 'quotedblleft', 'quotedblright', 'quoteleft', 'quoteright',
  32099. 'divide', 'lozenge', 'ydieresis', 'Ydieresis', 'fraction', 'currency',
  32100. 'guilsinglleft', 'guilsinglright', 'fi', 'fl', 'daggerdbl', 'periodcentered',
  32101. 'quotesinglbase', 'quotedblbase', 'perthousand', 'Acircumflex',
  32102. 'Ecircumflex', 'Aacute', 'Edieresis', 'Egrave', 'Iacute', 'Icircumflex',
  32103. 'Idieresis', 'Igrave', 'Oacute', 'Ocircumflex', 'apple', 'Ograve', 'Uacute',
  32104. 'Ucircumflex', 'Ugrave', 'dotlessi', 'circumflex', 'tilde', 'macron',
  32105. 'breve', 'dotaccent', 'ring', 'cedilla', 'hungarumlaut', 'ogonek', 'caron',
  32106. 'Lslash', 'lslash', 'Scaron', 'scaron', 'Zcaron', 'zcaron', 'brokenbar',
  32107. 'Eth', 'eth', 'Yacute', 'yacute', 'Thorn', 'thorn', 'minus', 'multiply',
  32108. 'onesuperior', 'twosuperior', 'threesuperior', 'onehalf', 'onequarter',
  32109. 'threequarters', 'franc', 'Gbreve', 'gbreve', 'Idotaccent', 'Scedilla',
  32110. 'scedilla', 'Cacute', 'cacute', 'Ccaron', 'ccaron', 'dcroat'];
  32111. function adjustWidths(properties) {
  32112. if (!properties.fontMatrix) {
  32113. return;
  32114. }
  32115. if (properties.fontMatrix[0] === FONT_IDENTITY_MATRIX[0]) {
  32116. return;
  32117. }
  32118. // adjusting width to fontMatrix scale
  32119. var scale = 0.001 / properties.fontMatrix[0];
  32120. var glyphsWidths = properties.widths;
  32121. for (var glyph in glyphsWidths) {
  32122. glyphsWidths[glyph] *= scale;
  32123. }
  32124. properties.defaultWidth *= scale;
  32125. }
  32126. function getFontType(type, subtype) {
  32127. switch (type) {
  32128. case 'Type1':
  32129. return subtype === 'Type1C' ? FontType.TYPE1C : FontType.TYPE1;
  32130. case 'CIDFontType0':
  32131. return subtype === 'CIDFontType0C' ? FontType.CIDFONTTYPE0C :
  32132. FontType.CIDFONTTYPE0;
  32133. case 'OpenType':
  32134. return FontType.OPENTYPE;
  32135. case 'TrueType':
  32136. return FontType.TRUETYPE;
  32137. case 'CIDFontType2':
  32138. return FontType.CIDFONTTYPE2;
  32139. case 'MMType1':
  32140. return FontType.MMTYPE1;
  32141. case 'Type0':
  32142. return FontType.TYPE0;
  32143. default:
  32144. return FontType.UNKNOWN;
  32145. }
  32146. }
  32147. var Glyph = (function GlyphClosure() {
  32148. function Glyph(fontChar, unicode, accent, width, vmetric, operatorListId,
  32149. isSpace, isInFont) {
  32150. this.fontChar = fontChar;
  32151. this.unicode = unicode;
  32152. this.accent = accent;
  32153. this.width = width;
  32154. this.vmetric = vmetric;
  32155. this.operatorListId = operatorListId;
  32156. this.isSpace = isSpace;
  32157. this.isInFont = isInFont;
  32158. }
  32159. Glyph.prototype.matchesForCache = function(fontChar, unicode, accent, width,
  32160. vmetric, operatorListId, isSpace,
  32161. isInFont) {
  32162. return this.fontChar === fontChar &&
  32163. this.unicode === unicode &&
  32164. this.accent === accent &&
  32165. this.width === width &&
  32166. this.vmetric === vmetric &&
  32167. this.operatorListId === operatorListId &&
  32168. this.isSpace === isSpace &&
  32169. this.isInFont === isInFont;
  32170. };
  32171. return Glyph;
  32172. })();
  32173. var ToUnicodeMap = (function ToUnicodeMapClosure() {
  32174. function ToUnicodeMap(cmap) {
  32175. // The elements of this._map can be integers or strings, depending on how
  32176. // |cmap| was created.
  32177. this._map = cmap;
  32178. }
  32179. ToUnicodeMap.prototype = {
  32180. get length() {
  32181. return this._map.length;
  32182. },
  32183. forEach: function(callback) {
  32184. for (var charCode in this._map) {
  32185. callback(charCode, this._map[charCode].charCodeAt(0));
  32186. }
  32187. },
  32188. has: function(i) {
  32189. return this._map[i] !== undefined;
  32190. },
  32191. get: function(i) {
  32192. return this._map[i];
  32193. },
  32194. charCodeOf: function(v) {
  32195. return this._map.indexOf(v);
  32196. }
  32197. };
  32198. return ToUnicodeMap;
  32199. })();
  32200. var IdentityToUnicodeMap = (function IdentityToUnicodeMapClosure() {
  32201. function IdentityToUnicodeMap(firstChar, lastChar) {
  32202. this.firstChar = firstChar;
  32203. this.lastChar = lastChar;
  32204. }
  32205. IdentityToUnicodeMap.prototype = {
  32206. get length() {
  32207. return (this.lastChar + 1) - this.firstChar;
  32208. },
  32209. forEach: function (callback) {
  32210. for (var i = this.firstChar, ii = this.lastChar; i <= ii; i++) {
  32211. callback(i, i);
  32212. }
  32213. },
  32214. has: function (i) {
  32215. return this.firstChar <= i && i <= this.lastChar;
  32216. },
  32217. get: function (i) {
  32218. if (this.firstChar <= i && i <= this.lastChar) {
  32219. return String.fromCharCode(i);
  32220. }
  32221. return undefined;
  32222. },
  32223. charCodeOf: function (v) {
  32224. return (isInt(v) && v >= this.firstChar && v <= this.lastChar) ? v : -1;
  32225. }
  32226. };
  32227. return IdentityToUnicodeMap;
  32228. })();
  32229. var OpenTypeFileBuilder = (function OpenTypeFileBuilderClosure() {
  32230. function writeInt16(dest, offset, num) {
  32231. dest[offset] = (num >> 8) & 0xFF;
  32232. dest[offset + 1] = num & 0xFF;
  32233. }
  32234. function writeInt32(dest, offset, num) {
  32235. dest[offset] = (num >> 24) & 0xFF;
  32236. dest[offset + 1] = (num >> 16) & 0xFF;
  32237. dest[offset + 2] = (num >> 8) & 0xFF;
  32238. dest[offset + 3] = num & 0xFF;
  32239. }
  32240. function writeData(dest, offset, data) {
  32241. var i, ii;
  32242. if (data instanceof Uint8Array) {
  32243. dest.set(data, offset);
  32244. } else if (typeof data === 'string') {
  32245. for (i = 0, ii = data.length; i < ii; i++) {
  32246. dest[offset++] = data.charCodeAt(i) & 0xFF;
  32247. }
  32248. } else {
  32249. // treating everything else as array
  32250. for (i = 0, ii = data.length; i < ii; i++) {
  32251. dest[offset++] = data[i] & 0xFF;
  32252. }
  32253. }
  32254. }
  32255. function OpenTypeFileBuilder(sfnt) {
  32256. this.sfnt = sfnt;
  32257. this.tables = Object.create(null);
  32258. }
  32259. OpenTypeFileBuilder.getSearchParams =
  32260. function OpenTypeFileBuilder_getSearchParams(entriesCount, entrySize) {
  32261. var maxPower2 = 1, log2 = 0;
  32262. while ((maxPower2 ^ entriesCount) > maxPower2) {
  32263. maxPower2 <<= 1;
  32264. log2++;
  32265. }
  32266. var searchRange = maxPower2 * entrySize;
  32267. return {
  32268. range: searchRange,
  32269. entry: log2,
  32270. rangeShift: entrySize * entriesCount - searchRange
  32271. };
  32272. };
  32273. var OTF_HEADER_SIZE = 12;
  32274. var OTF_TABLE_ENTRY_SIZE = 16;
  32275. OpenTypeFileBuilder.prototype = {
  32276. toArray: function OpenTypeFileBuilder_toArray() {
  32277. var sfnt = this.sfnt;
  32278. // Tables needs to be written by ascendant alphabetic order
  32279. var tables = this.tables;
  32280. var tablesNames = Object.keys(tables);
  32281. tablesNames.sort();
  32282. var numTables = tablesNames.length;
  32283. var i, j, jj, table, tableName;
  32284. // layout the tables data
  32285. var offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
  32286. var tableOffsets = [offset];
  32287. for (i = 0; i < numTables; i++) {
  32288. table = tables[tablesNames[i]];
  32289. var paddedLength = ((table.length + 3) & ~3) >>> 0;
  32290. offset += paddedLength;
  32291. tableOffsets.push(offset);
  32292. }
  32293. var file = new Uint8Array(offset);
  32294. // write the table data first (mostly for checksum)
  32295. for (i = 0; i < numTables; i++) {
  32296. table = tables[tablesNames[i]];
  32297. writeData(file, tableOffsets[i], table);
  32298. }
  32299. // sfnt version (4 bytes)
  32300. if (sfnt === 'true') {
  32301. // Windows hates the Mac TrueType sfnt version number
  32302. sfnt = string32(0x00010000);
  32303. }
  32304. file[0] = sfnt.charCodeAt(0) & 0xFF;
  32305. file[1] = sfnt.charCodeAt(1) & 0xFF;
  32306. file[2] = sfnt.charCodeAt(2) & 0xFF;
  32307. file[3] = sfnt.charCodeAt(3) & 0xFF;
  32308. // numTables (2 bytes)
  32309. writeInt16(file, 4, numTables);
  32310. var searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
  32311. // searchRange (2 bytes)
  32312. writeInt16(file, 6, searchParams.range);
  32313. // entrySelector (2 bytes)
  32314. writeInt16(file, 8, searchParams.entry);
  32315. // rangeShift (2 bytes)
  32316. writeInt16(file, 10, searchParams.rangeShift);
  32317. offset = OTF_HEADER_SIZE;
  32318. // writing table entries
  32319. for (i = 0; i < numTables; i++) {
  32320. tableName = tablesNames[i];
  32321. file[offset] = tableName.charCodeAt(0) & 0xFF;
  32322. file[offset + 1] = tableName.charCodeAt(1) & 0xFF;
  32323. file[offset + 2] = tableName.charCodeAt(2) & 0xFF;
  32324. file[offset + 3] = tableName.charCodeAt(3) & 0xFF;
  32325. // checksum
  32326. var checksum = 0;
  32327. for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
  32328. var quad = readUint32(file, j);
  32329. checksum = (checksum + quad) >>> 0;
  32330. }
  32331. writeInt32(file, offset + 4, checksum);
  32332. // offset
  32333. writeInt32(file, offset + 8, tableOffsets[i]);
  32334. // length
  32335. writeInt32(file, offset + 12, tables[tableName].length);
  32336. offset += OTF_TABLE_ENTRY_SIZE;
  32337. }
  32338. return file;
  32339. },
  32340. addTable: function OpenTypeFileBuilder_addTable(tag, data) {
  32341. if (tag in this.tables) {
  32342. throw new Error('Table ' + tag + ' already exists');
  32343. }
  32344. this.tables[tag] = data;
  32345. }
  32346. };
  32347. return OpenTypeFileBuilder;
  32348. })();
  32349. // Problematic Unicode characters in the fonts that needs to be moved to avoid
  32350. // issues when they are painted on the canvas, e.g. complex-script shaping or
  32351. // control/whitespace characters. The ranges are listed in pairs: the first item
  32352. // is a code of the first problematic code, the second one is the next
  32353. // non-problematic code. The ranges must be in sorted order.
  32354. var ProblematicCharRanges = new Int32Array([
  32355. // Control characters.
  32356. 0x0000, 0x0020,
  32357. 0x007F, 0x00A1,
  32358. 0x00AD, 0x00AE,
  32359. // Chars that is used in complex-script shaping.
  32360. 0x0600, 0x0780,
  32361. 0x08A0, 0x10A0,
  32362. 0x1780, 0x1800,
  32363. // General punctuation chars.
  32364. 0x2000, 0x2010,
  32365. 0x2011, 0x2012,
  32366. 0x2028, 0x2030,
  32367. 0x205F, 0x2070,
  32368. 0x25CC, 0x25CD,
  32369. // Chars that is used in complex-script shaping.
  32370. 0xAA60, 0xAA80,
  32371. // Specials Unicode block.
  32372. 0xFFF0, 0x10000
  32373. ]);
  32374. /**
  32375. * 'Font' is the class the outside world should use, it encapsulate all the font
  32376. * decoding logics whatever type it is (assuming the font type is supported).
  32377. *
  32378. * For example to read a Type1 font and to attach it to the document:
  32379. * var type1Font = new Font("MyFontName", binaryFile, propertiesObject);
  32380. * type1Font.bind();
  32381. */
  32382. var Font = (function FontClosure() {
  32383. function Font(name, file, properties) {
  32384. var charCode, glyphName, unicode;
  32385. this.name = name;
  32386. this.loadedName = properties.loadedName;
  32387. this.isType3Font = properties.isType3Font;
  32388. this.sizes = [];
  32389. this.missingFile = false;
  32390. this.glyphCache = Object.create(null);
  32391. var names = name.split('+');
  32392. names = names.length > 1 ? names[1] : names[0];
  32393. names = names.split(/[-,_]/g)[0];
  32394. this.isSerifFont = !!(properties.flags & FontFlags.Serif);
  32395. this.isSymbolicFont = !!(properties.flags & FontFlags.Symbolic);
  32396. this.isMonospace = !!(properties.flags & FontFlags.FixedPitch);
  32397. var type = properties.type;
  32398. var subtype = properties.subtype;
  32399. this.type = type;
  32400. this.fallbackName = (this.isMonospace ? 'monospace' :
  32401. (this.isSerifFont ? 'serif' : 'sans-serif'));
  32402. this.differences = properties.differences;
  32403. this.widths = properties.widths;
  32404. this.defaultWidth = properties.defaultWidth;
  32405. this.composite = properties.composite;
  32406. this.wideChars = properties.wideChars;
  32407. this.cMap = properties.cMap;
  32408. this.ascent = properties.ascent / PDF_GLYPH_SPACE_UNITS;
  32409. this.descent = properties.descent / PDF_GLYPH_SPACE_UNITS;
  32410. this.fontMatrix = properties.fontMatrix;
  32411. this.bbox = properties.bbox;
  32412. this.toUnicode = properties.toUnicode;
  32413. this.toFontChar = [];
  32414. if (properties.type === 'Type3') {
  32415. for (charCode = 0; charCode < 256; charCode++) {
  32416. this.toFontChar[charCode] = (this.differences[charCode] ||
  32417. properties.defaultEncoding[charCode]);
  32418. }
  32419. this.fontType = FontType.TYPE3;
  32420. return;
  32421. }
  32422. this.cidEncoding = properties.cidEncoding;
  32423. this.vertical = properties.vertical;
  32424. if (this.vertical) {
  32425. this.vmetrics = properties.vmetrics;
  32426. this.defaultVMetrics = properties.defaultVMetrics;
  32427. }
  32428. var glyphsUnicodeMap;
  32429. if (!file || file.isEmpty) {
  32430. if (file) {
  32431. // Some bad PDF generators will include empty font files,
  32432. // attempting to recover by assuming that no file exists.
  32433. warn('Font file is empty in "' + name + '" (' + this.loadedName + ')');
  32434. }
  32435. this.missingFile = true;
  32436. // The file data is not specified. Trying to fix the font name
  32437. // to be used with the canvas.font.
  32438. var fontName = name.replace(/[,_]/g, '-');
  32439. var stdFontMap = getStdFontMap(), nonStdFontMap = getNonStdFontMap();
  32440. var isStandardFont = !!stdFontMap[fontName] ||
  32441. !!(nonStdFontMap[fontName] && stdFontMap[nonStdFontMap[fontName]]);
  32442. fontName = stdFontMap[fontName] || nonStdFontMap[fontName] || fontName;
  32443. this.bold = (fontName.search(/bold/gi) !== -1);
  32444. this.italic = ((fontName.search(/oblique/gi) !== -1) ||
  32445. (fontName.search(/italic/gi) !== -1));
  32446. // Use 'name' instead of 'fontName' here because the original
  32447. // name ArialBlack for example will be replaced by Helvetica.
  32448. this.black = (name.search(/Black/g) !== -1);
  32449. // if at least one width is present, remeasure all chars when exists
  32450. this.remeasure = Object.keys(this.widths).length > 0;
  32451. if (isStandardFont && type === 'CIDFontType2' &&
  32452. properties.cidEncoding.indexOf('Identity-') === 0) {
  32453. var GlyphMapForStandardFonts = getGlyphMapForStandardFonts();
  32454. // Standard fonts might be embedded as CID font without glyph mapping.
  32455. // Building one based on GlyphMapForStandardFonts.
  32456. var map = [];
  32457. for (charCode in GlyphMapForStandardFonts) {
  32458. map[+charCode] = GlyphMapForStandardFonts[charCode];
  32459. }
  32460. if (/ArialBlack/i.test(name)) {
  32461. var SupplementalGlyphMapForArialBlack =
  32462. getSupplementalGlyphMapForArialBlack();
  32463. for (charCode in SupplementalGlyphMapForArialBlack) {
  32464. map[+charCode] = SupplementalGlyphMapForArialBlack[charCode];
  32465. }
  32466. }
  32467. var isIdentityUnicode = this.toUnicode instanceof IdentityToUnicodeMap;
  32468. if (!isIdentityUnicode) {
  32469. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32470. map[+charCode] = unicodeCharCode;
  32471. });
  32472. }
  32473. this.toFontChar = map;
  32474. this.toUnicode = new ToUnicodeMap(map);
  32475. } else if (/Symbol/i.test(fontName)) {
  32476. this.toFontChar = buildToFontChar(SymbolSetEncoding, getGlyphsUnicode(),
  32477. properties.differences);
  32478. } else if (/Dingbats/i.test(fontName)) {
  32479. if (/Wingdings/i.test(name)) {
  32480. warn('Non-embedded Wingdings font, falling back to ZapfDingbats.');
  32481. }
  32482. this.toFontChar = buildToFontChar(ZapfDingbatsEncoding,
  32483. getDingbatsGlyphsUnicode(),
  32484. properties.differences);
  32485. } else if (isStandardFont) {
  32486. this.toFontChar = buildToFontChar(properties.defaultEncoding,
  32487. getGlyphsUnicode(),
  32488. properties.differences);
  32489. } else {
  32490. glyphsUnicodeMap = getGlyphsUnicode();
  32491. this.toUnicode.forEach(function(charCode, unicodeCharCode) {
  32492. if (!this.composite) {
  32493. glyphName = (properties.differences[charCode] ||
  32494. properties.defaultEncoding[charCode]);
  32495. unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  32496. if (unicode !== -1) {
  32497. unicodeCharCode = unicode;
  32498. }
  32499. }
  32500. this.toFontChar[charCode] = unicodeCharCode;
  32501. }.bind(this));
  32502. }
  32503. this.loadedName = fontName.split('-')[0];
  32504. this.loading = false;
  32505. this.fontType = getFontType(type, subtype);
  32506. return;
  32507. }
  32508. // Some fonts might use wrong font types for Type1C or CIDFontType0C
  32509. if (subtype === 'Type1C' && (type !== 'Type1' && type !== 'MMType1')) {
  32510. // Some TrueType fonts by mistake claim Type1C
  32511. if (isTrueTypeFile(file)) {
  32512. subtype = 'TrueType';
  32513. } else {
  32514. type = 'Type1';
  32515. }
  32516. }
  32517. if (subtype === 'CIDFontType0C' && type !== 'CIDFontType0') {
  32518. type = 'CIDFontType0';
  32519. }
  32520. if (subtype === 'OpenType') {
  32521. type = 'OpenType';
  32522. }
  32523. // Some CIDFontType0C fonts by mistake claim CIDFontType0.
  32524. if (type === 'CIDFontType0') {
  32525. if (isType1File(file)) {
  32526. subtype = 'CIDFontType0';
  32527. } else if (isOpenTypeFile(file)) {
  32528. // Sometimes the type/subtype can be a complete lie (see issue6782.pdf).
  32529. type = subtype = 'OpenType';
  32530. } else {
  32531. subtype = 'CIDFontType0C';
  32532. }
  32533. }
  32534. var data;
  32535. switch (type) {
  32536. case 'MMType1':
  32537. info('MMType1 font (' + name + '), falling back to Type1.');
  32538. /* falls through */
  32539. case 'Type1':
  32540. case 'CIDFontType0':
  32541. this.mimetype = 'font/opentype';
  32542. var cff = (subtype === 'Type1C' || subtype === 'CIDFontType0C') ?
  32543. new CFFFont(file, properties) : new Type1Font(name, file, properties);
  32544. adjustWidths(properties);
  32545. // Wrap the CFF data inside an OTF font file
  32546. data = this.convert(name, cff, properties);
  32547. break;
  32548. case 'OpenType':
  32549. case 'TrueType':
  32550. case 'CIDFontType2':
  32551. this.mimetype = 'font/opentype';
  32552. // Repair the TrueType file. It is can be damaged in the point of
  32553. // view of the sanitizer
  32554. data = this.checkAndRepair(name, file, properties);
  32555. if (this.isOpenType) {
  32556. adjustWidths(properties);
  32557. type = 'OpenType';
  32558. }
  32559. break;
  32560. default:
  32561. error('Font ' + type + ' is not supported');
  32562. break;
  32563. }
  32564. this.data = data;
  32565. this.fontType = getFontType(type, subtype);
  32566. // Transfer some properties again that could change during font conversion
  32567. this.fontMatrix = properties.fontMatrix;
  32568. this.widths = properties.widths;
  32569. this.defaultWidth = properties.defaultWidth;
  32570. this.encoding = properties.baseEncoding;
  32571. this.seacMap = properties.seacMap;
  32572. this.loading = true;
  32573. }
  32574. Font.getFontID = (function () {
  32575. var ID = 1;
  32576. return function Font_getFontID() {
  32577. return String(ID++);
  32578. };
  32579. })();
  32580. function int16(b0, b1) {
  32581. return (b0 << 8) + b1;
  32582. }
  32583. function signedInt16(b0, b1) {
  32584. var value = (b0 << 8) + b1;
  32585. return value & (1 << 15) ? value - 0x10000 : value;
  32586. }
  32587. function int32(b0, b1, b2, b3) {
  32588. return (b0 << 24) + (b1 << 16) + (b2 << 8) + b3;
  32589. }
  32590. function string16(value) {
  32591. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32592. }
  32593. function safeString16(value) {
  32594. // clamp value to the 16-bit int range
  32595. value = (value > 0x7FFF ? 0x7FFF : (value < -0x8000 ? -0x8000 : value));
  32596. return String.fromCharCode((value >> 8) & 0xff, value & 0xff);
  32597. }
  32598. function isTrueTypeFile(file) {
  32599. var header = file.peekBytes(4);
  32600. return readUint32(header, 0) === 0x00010000;
  32601. }
  32602. function isOpenTypeFile(file) {
  32603. var header = file.peekBytes(4);
  32604. return bytesToString(header) === 'OTTO';
  32605. }
  32606. function isType1File(file) {
  32607. var header = file.peekBytes(2);
  32608. // All Type1 font programs must begin with the comment '%!' (0x25 + 0x21).
  32609. if (header[0] === 0x25 && header[1] === 0x21) {
  32610. return true;
  32611. }
  32612. // ... obviously some fonts violate that part of the specification,
  32613. // please refer to the comment in |Type1Font| below.
  32614. if (header[0] === 0x80 && header[1] === 0x01) { // pfb file header.
  32615. return true;
  32616. }
  32617. return false;
  32618. }
  32619. function buildToFontChar(encoding, glyphsUnicodeMap, differences) {
  32620. var toFontChar = [], unicode;
  32621. for (var i = 0, ii = encoding.length; i < ii; i++) {
  32622. unicode = getUnicodeForGlyph(encoding[i], glyphsUnicodeMap);
  32623. if (unicode !== -1) {
  32624. toFontChar[i] = unicode;
  32625. }
  32626. }
  32627. for (var charCode in differences) {
  32628. unicode = getUnicodeForGlyph(differences[charCode], glyphsUnicodeMap);
  32629. if (unicode !== -1) {
  32630. toFontChar[+charCode] = unicode;
  32631. }
  32632. }
  32633. return toFontChar;
  32634. }
  32635. /**
  32636. * Helper function for |adjustMapping|.
  32637. * @return {boolean}
  32638. */
  32639. function isProblematicUnicodeLocation(code) {
  32640. // Using binary search to find a range start.
  32641. var i = 0, j = ProblematicCharRanges.length - 1;
  32642. while (i < j) {
  32643. var c = (i + j + 1) >> 1;
  32644. if (code < ProblematicCharRanges[c]) {
  32645. j = c - 1;
  32646. } else {
  32647. i = c;
  32648. }
  32649. }
  32650. // Even index means code in problematic range.
  32651. return !(i & 1);
  32652. }
  32653. /**
  32654. * Rebuilds the char code to glyph ID map by trying to replace the char codes
  32655. * with their unicode value. It also moves char codes that are in known
  32656. * problematic locations.
  32657. * @return {Object} Two properties:
  32658. * 'toFontChar' - maps original char codes(the value that will be read
  32659. * from commands such as show text) to the char codes that will be used in the
  32660. * font that we build
  32661. * 'charCodeToGlyphId' - maps the new font char codes to glyph ids
  32662. */
  32663. function adjustMapping(charCodeToGlyphId, properties) {
  32664. var toUnicode = properties.toUnicode;
  32665. var isSymbolic = !!(properties.flags & FontFlags.Symbolic);
  32666. var isIdentityUnicode =
  32667. properties.toUnicode instanceof IdentityToUnicodeMap;
  32668. var newMap = Object.create(null);
  32669. var toFontChar = [];
  32670. var usedFontCharCodes = [];
  32671. var nextAvailableFontCharCode = PRIVATE_USE_OFFSET_START;
  32672. for (var originalCharCode in charCodeToGlyphId) {
  32673. originalCharCode |= 0;
  32674. var glyphId = charCodeToGlyphId[originalCharCode];
  32675. var fontCharCode = originalCharCode;
  32676. // First try to map the value to a unicode position if a non identity map
  32677. // was created.
  32678. if (!isIdentityUnicode && toUnicode.has(originalCharCode)) {
  32679. var unicode = toUnicode.get(fontCharCode);
  32680. // TODO: Try to map ligatures to the correct spot.
  32681. if (unicode.length === 1) {
  32682. fontCharCode = unicode.charCodeAt(0);
  32683. }
  32684. }
  32685. // Try to move control characters, special characters and already mapped
  32686. // characters to the private use area since they will not be drawn by
  32687. // canvas if left in their current position. Also, move characters if the
  32688. // font was symbolic and there is only an identity unicode map since the
  32689. // characters probably aren't in the correct position (fixes an issue
  32690. // with firefox and thuluthfont).
  32691. if ((usedFontCharCodes[fontCharCode] !== undefined ||
  32692. isProblematicUnicodeLocation(fontCharCode) ||
  32693. (isSymbolic && isIdentityUnicode)) &&
  32694. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END) { // Room left.
  32695. // Loop to try and find a free spot in the private use area.
  32696. do {
  32697. fontCharCode = nextAvailableFontCharCode++;
  32698. if (SKIP_PRIVATE_USE_RANGE_F000_TO_F01F && fontCharCode === 0xF000) {
  32699. fontCharCode = 0xF020;
  32700. nextAvailableFontCharCode = fontCharCode + 1;
  32701. }
  32702. } while (usedFontCharCodes[fontCharCode] !== undefined &&
  32703. nextAvailableFontCharCode <= PRIVATE_USE_OFFSET_END);
  32704. }
  32705. newMap[fontCharCode] = glyphId;
  32706. toFontChar[originalCharCode] = fontCharCode;
  32707. usedFontCharCodes[fontCharCode] = true;
  32708. }
  32709. return {
  32710. toFontChar: toFontChar,
  32711. charCodeToGlyphId: newMap,
  32712. nextAvailableFontCharCode: nextAvailableFontCharCode
  32713. };
  32714. }
  32715. function getRanges(glyphs, numGlyphs) {
  32716. // Array.sort() sorts by characters, not numerically, so convert to an
  32717. // array of characters.
  32718. var codes = [];
  32719. for (var charCode in glyphs) {
  32720. // Remove an invalid glyph ID mappings to make OTS happy.
  32721. if (glyphs[charCode] >= numGlyphs) {
  32722. continue;
  32723. }
  32724. codes.push({ fontCharCode: charCode | 0, glyphId: glyphs[charCode] });
  32725. }
  32726. codes.sort(function fontGetRangesSort(a, b) {
  32727. return a.fontCharCode - b.fontCharCode;
  32728. });
  32729. // Split the sorted codes into ranges.
  32730. var ranges = [];
  32731. var length = codes.length;
  32732. for (var n = 0; n < length; ) {
  32733. var start = codes[n].fontCharCode;
  32734. var codeIndices = [codes[n].glyphId];
  32735. ++n;
  32736. var end = start;
  32737. while (n < length && end + 1 === codes[n].fontCharCode) {
  32738. codeIndices.push(codes[n].glyphId);
  32739. ++end;
  32740. ++n;
  32741. if (end === 0xFFFF) {
  32742. break;
  32743. }
  32744. }
  32745. ranges.push([start, end, codeIndices]);
  32746. }
  32747. return ranges;
  32748. }
  32749. function createCmapTable(glyphs, numGlyphs) {
  32750. var ranges = getRanges(glyphs, numGlyphs);
  32751. var numTables = ranges[ranges.length - 1][1] > 0xFFFF ? 2 : 1;
  32752. var cmap = '\x00\x00' + // version
  32753. string16(numTables) + // numTables
  32754. '\x00\x03' + // platformID
  32755. '\x00\x01' + // encodingID
  32756. string32(4 + numTables * 8); // start of the table record
  32757. var i, ii, j, jj;
  32758. for (i = ranges.length - 1; i >= 0; --i) {
  32759. if (ranges[i][0] <= 0xFFFF) { break; }
  32760. }
  32761. var bmpLength = i + 1;
  32762. if (ranges[i][0] < 0xFFFF && ranges[i][1] === 0xFFFF) {
  32763. ranges[i][1] = 0xFFFE;
  32764. }
  32765. var trailingRangesCount = ranges[i][1] < 0xFFFF ? 1 : 0;
  32766. var segCount = bmpLength + trailingRangesCount;
  32767. var searchParams = OpenTypeFileBuilder.getSearchParams(segCount, 2);
  32768. // Fill up the 4 parallel arrays describing the segments.
  32769. var startCount = '';
  32770. var endCount = '';
  32771. var idDeltas = '';
  32772. var idRangeOffsets = '';
  32773. var glyphsIds = '';
  32774. var bias = 0;
  32775. var range, start, end, codes;
  32776. for (i = 0, ii = bmpLength; i < ii; i++) {
  32777. range = ranges[i];
  32778. start = range[0];
  32779. end = range[1];
  32780. startCount += string16(start);
  32781. endCount += string16(end);
  32782. codes = range[2];
  32783. var contiguous = true;
  32784. for (j = 1, jj = codes.length; j < jj; ++j) {
  32785. if (codes[j] !== codes[j - 1] + 1) {
  32786. contiguous = false;
  32787. break;
  32788. }
  32789. }
  32790. if (!contiguous) {
  32791. var offset = (segCount - i) * 2 + bias * 2;
  32792. bias += (end - start + 1);
  32793. idDeltas += string16(0);
  32794. idRangeOffsets += string16(offset);
  32795. for (j = 0, jj = codes.length; j < jj; ++j) {
  32796. glyphsIds += string16(codes[j]);
  32797. }
  32798. } else {
  32799. var startCode = codes[0];
  32800. idDeltas += string16((startCode - start) & 0xFFFF);
  32801. idRangeOffsets += string16(0);
  32802. }
  32803. }
  32804. if (trailingRangesCount > 0) {
  32805. endCount += '\xFF\xFF';
  32806. startCount += '\xFF\xFF';
  32807. idDeltas += '\x00\x01';
  32808. idRangeOffsets += '\x00\x00';
  32809. }
  32810. var format314 = '\x00\x00' + // language
  32811. string16(2 * segCount) +
  32812. string16(searchParams.range) +
  32813. string16(searchParams.entry) +
  32814. string16(searchParams.rangeShift) +
  32815. endCount + '\x00\x00' + startCount +
  32816. idDeltas + idRangeOffsets + glyphsIds;
  32817. var format31012 = '';
  32818. var header31012 = '';
  32819. if (numTables > 1) {
  32820. cmap += '\x00\x03' + // platformID
  32821. '\x00\x0A' + // encodingID
  32822. string32(4 + numTables * 8 +
  32823. 4 + format314.length); // start of the table record
  32824. format31012 = '';
  32825. for (i = 0, ii = ranges.length; i < ii; i++) {
  32826. range = ranges[i];
  32827. start = range[0];
  32828. codes = range[2];
  32829. var code = codes[0];
  32830. for (j = 1, jj = codes.length; j < jj; ++j) {
  32831. if (codes[j] !== codes[j - 1] + 1) {
  32832. end = range[0] + j - 1;
  32833. format31012 += string32(start) + // startCharCode
  32834. string32(end) + // endCharCode
  32835. string32(code); // startGlyphID
  32836. start = end + 1;
  32837. code = codes[j];
  32838. }
  32839. }
  32840. format31012 += string32(start) + // startCharCode
  32841. string32(range[1]) + // endCharCode
  32842. string32(code); // startGlyphID
  32843. }
  32844. header31012 = '\x00\x0C' + // format
  32845. '\x00\x00' + // reserved
  32846. string32(format31012.length + 16) + // length
  32847. '\x00\x00\x00\x00' + // language
  32848. string32(format31012.length / 12); // nGroups
  32849. }
  32850. return cmap + '\x00\x04' + // format
  32851. string16(format314.length + 4) + // length
  32852. format314 + header31012 + format31012;
  32853. }
  32854. function validateOS2Table(os2) {
  32855. var stream = new Stream(os2.data);
  32856. var version = stream.getUint16();
  32857. // TODO verify all OS/2 tables fields, but currently we validate only those
  32858. // that give us issues
  32859. stream.getBytes(60); // skipping type, misc sizes, panose, unicode ranges
  32860. var selection = stream.getUint16();
  32861. if (version < 4 && (selection & 0x0300)) {
  32862. return false;
  32863. }
  32864. var firstChar = stream.getUint16();
  32865. var lastChar = stream.getUint16();
  32866. if (firstChar > lastChar) {
  32867. return false;
  32868. }
  32869. stream.getBytes(6); // skipping sTypoAscender/Descender/LineGap
  32870. var usWinAscent = stream.getUint16();
  32871. if (usWinAscent === 0) { // makes font unreadable by windows
  32872. return false;
  32873. }
  32874. // OS/2 appears to be valid, resetting some fields
  32875. os2.data[8] = os2.data[9] = 0; // IE rejects fonts if fsType != 0
  32876. return true;
  32877. }
  32878. function createOS2Table(properties, charstrings, override) {
  32879. override = override || {
  32880. unitsPerEm: 0,
  32881. yMax: 0,
  32882. yMin: 0,
  32883. ascent: 0,
  32884. descent: 0
  32885. };
  32886. var ulUnicodeRange1 = 0;
  32887. var ulUnicodeRange2 = 0;
  32888. var ulUnicodeRange3 = 0;
  32889. var ulUnicodeRange4 = 0;
  32890. var firstCharIndex = null;
  32891. var lastCharIndex = 0;
  32892. if (charstrings) {
  32893. for (var code in charstrings) {
  32894. code |= 0;
  32895. if (firstCharIndex > code || !firstCharIndex) {
  32896. firstCharIndex = code;
  32897. }
  32898. if (lastCharIndex < code) {
  32899. lastCharIndex = code;
  32900. }
  32901. var position = getUnicodeRangeFor(code);
  32902. if (position < 32) {
  32903. ulUnicodeRange1 |= 1 << position;
  32904. } else if (position < 64) {
  32905. ulUnicodeRange2 |= 1 << position - 32;
  32906. } else if (position < 96) {
  32907. ulUnicodeRange3 |= 1 << position - 64;
  32908. } else if (position < 123) {
  32909. ulUnicodeRange4 |= 1 << position - 96;
  32910. } else {
  32911. error('Unicode ranges Bits > 123 are reserved for internal usage');
  32912. }
  32913. }
  32914. } else {
  32915. // TODO
  32916. firstCharIndex = 0;
  32917. lastCharIndex = 255;
  32918. }
  32919. var bbox = properties.bbox || [0, 0, 0, 0];
  32920. var unitsPerEm = (override.unitsPerEm ||
  32921. 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0]);
  32922. // if the font units differ to the PDF glyph space units
  32923. // then scale up the values
  32924. var scale = (properties.ascentScaled ? 1.0 :
  32925. unitsPerEm / PDF_GLYPH_SPACE_UNITS);
  32926. var typoAscent = (override.ascent ||
  32927. Math.round(scale * (properties.ascent || bbox[3])));
  32928. var typoDescent = (override.descent ||
  32929. Math.round(scale * (properties.descent || bbox[1])));
  32930. if (typoDescent > 0 && properties.descent > 0 && bbox[1] < 0) {
  32931. typoDescent = -typoDescent; // fixing incorrect descent
  32932. }
  32933. var winAscent = override.yMax || typoAscent;
  32934. var winDescent = -override.yMin || -typoDescent;
  32935. return '\x00\x03' + // version
  32936. '\x02\x24' + // xAvgCharWidth
  32937. '\x01\xF4' + // usWeightClass
  32938. '\x00\x05' + // usWidthClass
  32939. '\x00\x00' + // fstype (0 to let the font loads via font-face on IE)
  32940. '\x02\x8A' + // ySubscriptXSize
  32941. '\x02\xBB' + // ySubscriptYSize
  32942. '\x00\x00' + // ySubscriptXOffset
  32943. '\x00\x8C' + // ySubscriptYOffset
  32944. '\x02\x8A' + // ySuperScriptXSize
  32945. '\x02\xBB' + // ySuperScriptYSize
  32946. '\x00\x00' + // ySuperScriptXOffset
  32947. '\x01\xDF' + // ySuperScriptYOffset
  32948. '\x00\x31' + // yStrikeOutSize
  32949. '\x01\x02' + // yStrikeOutPosition
  32950. '\x00\x00' + // sFamilyClass
  32951. '\x00\x00\x06' +
  32952. String.fromCharCode(properties.fixedPitch ? 0x09 : 0x00) +
  32953. '\x00\x00\x00\x00\x00\x00' + // Panose
  32954. string32(ulUnicodeRange1) + // ulUnicodeRange1 (Bits 0-31)
  32955. string32(ulUnicodeRange2) + // ulUnicodeRange2 (Bits 32-63)
  32956. string32(ulUnicodeRange3) + // ulUnicodeRange3 (Bits 64-95)
  32957. string32(ulUnicodeRange4) + // ulUnicodeRange4 (Bits 96-127)
  32958. '\x2A\x32\x31\x2A' + // achVendID
  32959. string16(properties.italicAngle ? 1 : 0) + // fsSelection
  32960. string16(firstCharIndex ||
  32961. properties.firstChar) + // usFirstCharIndex
  32962. string16(lastCharIndex || properties.lastChar) + // usLastCharIndex
  32963. string16(typoAscent) + // sTypoAscender
  32964. string16(typoDescent) + // sTypoDescender
  32965. '\x00\x64' + // sTypoLineGap (7%-10% of the unitsPerEM value)
  32966. string16(winAscent) + // usWinAscent
  32967. string16(winDescent) + // usWinDescent
  32968. '\x00\x00\x00\x00' + // ulCodePageRange1 (Bits 0-31)
  32969. '\x00\x00\x00\x00' + // ulCodePageRange2 (Bits 32-63)
  32970. string16(properties.xHeight) + // sxHeight
  32971. string16(properties.capHeight) + // sCapHeight
  32972. string16(0) + // usDefaultChar
  32973. string16(firstCharIndex || properties.firstChar) + // usBreakChar
  32974. '\x00\x03'; // usMaxContext
  32975. }
  32976. function createPostTable(properties) {
  32977. var angle = Math.floor(properties.italicAngle * (Math.pow(2, 16)));
  32978. return ('\x00\x03\x00\x00' + // Version number
  32979. string32(angle) + // italicAngle
  32980. '\x00\x00' + // underlinePosition
  32981. '\x00\x00' + // underlineThickness
  32982. string32(properties.fixedPitch) + // isFixedPitch
  32983. '\x00\x00\x00\x00' + // minMemType42
  32984. '\x00\x00\x00\x00' + // maxMemType42
  32985. '\x00\x00\x00\x00' + // minMemType1
  32986. '\x00\x00\x00\x00'); // maxMemType1
  32987. }
  32988. function createNameTable(name, proto) {
  32989. if (!proto) {
  32990. proto = [[], []]; // no strings and unicode strings
  32991. }
  32992. var strings = [
  32993. proto[0][0] || 'Original licence', // 0.Copyright
  32994. proto[0][1] || name, // 1.Font family
  32995. proto[0][2] || 'Unknown', // 2.Font subfamily (font weight)
  32996. proto[0][3] || 'uniqueID', // 3.Unique ID
  32997. proto[0][4] || name, // 4.Full font name
  32998. proto[0][5] || 'Version 0.11', // 5.Version
  32999. proto[0][6] || '', // 6.Postscript name
  33000. proto[0][7] || 'Unknown', // 7.Trademark
  33001. proto[0][8] || 'Unknown', // 8.Manufacturer
  33002. proto[0][9] || 'Unknown' // 9.Designer
  33003. ];
  33004. // Mac want 1-byte per character strings while Windows want
  33005. // 2-bytes per character, so duplicate the names table
  33006. var stringsUnicode = [];
  33007. var i, ii, j, jj, str;
  33008. for (i = 0, ii = strings.length; i < ii; i++) {
  33009. str = proto[1][i] || strings[i];
  33010. var strBufUnicode = [];
  33011. for (j = 0, jj = str.length; j < jj; j++) {
  33012. strBufUnicode.push(string16(str.charCodeAt(j)));
  33013. }
  33014. stringsUnicode.push(strBufUnicode.join(''));
  33015. }
  33016. var names = [strings, stringsUnicode];
  33017. var platforms = ['\x00\x01', '\x00\x03'];
  33018. var encodings = ['\x00\x00', '\x00\x01'];
  33019. var languages = ['\x00\x00', '\x04\x09'];
  33020. var namesRecordCount = strings.length * platforms.length;
  33021. var nameTable =
  33022. '\x00\x00' + // format
  33023. string16(namesRecordCount) + // Number of names Record
  33024. string16(namesRecordCount * 12 + 6); // Storage
  33025. // Build the name records field
  33026. var strOffset = 0;
  33027. for (i = 0, ii = platforms.length; i < ii; i++) {
  33028. var strs = names[i];
  33029. for (j = 0, jj = strs.length; j < jj; j++) {
  33030. str = strs[j];
  33031. var nameRecord =
  33032. platforms[i] + // platform ID
  33033. encodings[i] + // encoding ID
  33034. languages[i] + // language ID
  33035. string16(j) + // name ID
  33036. string16(str.length) +
  33037. string16(strOffset);
  33038. nameTable += nameRecord;
  33039. strOffset += str.length;
  33040. }
  33041. }
  33042. nameTable += strings.join('') + stringsUnicode.join('');
  33043. return nameTable;
  33044. }
  33045. Font.prototype = {
  33046. name: null,
  33047. font: null,
  33048. mimetype: null,
  33049. encoding: null,
  33050. get renderer() {
  33051. var renderer = FontRendererFactory.create(this, SEAC_ANALYSIS_ENABLED);
  33052. return shadow(this, 'renderer', renderer);
  33053. },
  33054. exportData: function Font_exportData() {
  33055. // TODO remove enumerating of the properties, e.g. hardcode exact names.
  33056. var data = {};
  33057. for (var i in this) {
  33058. if (this.hasOwnProperty(i)) {
  33059. data[i] = this[i];
  33060. }
  33061. }
  33062. return data;
  33063. },
  33064. checkAndRepair: function Font_checkAndRepair(name, font, properties) {
  33065. function readTableEntry(file) {
  33066. var tag = bytesToString(file.getBytes(4));
  33067. var checksum = file.getInt32() >>> 0;
  33068. var offset = file.getInt32() >>> 0;
  33069. var length = file.getInt32() >>> 0;
  33070. // Read the table associated data
  33071. var previousPosition = file.pos;
  33072. file.pos = file.start ? file.start : 0;
  33073. file.skip(offset);
  33074. var data = file.getBytes(length);
  33075. file.pos = previousPosition;
  33076. if (tag === 'head') {
  33077. // clearing checksum adjustment
  33078. data[8] = data[9] = data[10] = data[11] = 0;
  33079. data[17] |= 0x20; //Set font optimized for cleartype flag
  33080. }
  33081. return {
  33082. tag: tag,
  33083. checksum: checksum,
  33084. length: length,
  33085. offset: offset,
  33086. data: data
  33087. };
  33088. }
  33089. function readOpenTypeHeader(ttf) {
  33090. return {
  33091. version: bytesToString(ttf.getBytes(4)),
  33092. numTables: ttf.getUint16(),
  33093. searchRange: ttf.getUint16(),
  33094. entrySelector: ttf.getUint16(),
  33095. rangeShift: ttf.getUint16()
  33096. };
  33097. }
  33098. /**
  33099. * Read the appropriate subtable from the cmap according to 9.6.6.4 from
  33100. * PDF spec
  33101. */
  33102. function readCmapTable(cmap, font, isSymbolicFont, hasEncoding) {
  33103. if (!cmap) {
  33104. warn('No cmap table available.');
  33105. return {
  33106. platformId: -1,
  33107. encodingId: -1,
  33108. mappings: [],
  33109. hasShortCmap: false
  33110. };
  33111. }
  33112. var segment;
  33113. var start = (font.start ? font.start : 0) + cmap.offset;
  33114. font.pos = start;
  33115. var version = font.getUint16();
  33116. var numTables = font.getUint16();
  33117. var potentialTable;
  33118. var canBreak = false;
  33119. // There's an order of preference in terms of which cmap subtable to
  33120. // use:
  33121. // - non-symbolic fonts the preference is a 3,1 table then a 1,0 table
  33122. // - symbolic fonts the preference is a 3,0 table then a 1,0 table
  33123. // The following takes advantage of the fact that the tables are sorted
  33124. // to work.
  33125. for (var i = 0; i < numTables; i++) {
  33126. var platformId = font.getUint16();
  33127. var encodingId = font.getUint16();
  33128. var offset = font.getInt32() >>> 0;
  33129. var useTable = false;
  33130. if (platformId === 0 && encodingId === 0) {
  33131. useTable = true;
  33132. // Continue the loop since there still may be a higher priority
  33133. // table.
  33134. } else if (platformId === 1 && encodingId === 0) {
  33135. useTable = true;
  33136. // Continue the loop since there still may be a higher priority
  33137. // table.
  33138. } else if (platformId === 3 && encodingId === 1 &&
  33139. ((!isSymbolicFont && hasEncoding) || !potentialTable)) {
  33140. useTable = true;
  33141. if (!isSymbolicFont) {
  33142. canBreak = true;
  33143. }
  33144. } else if (isSymbolicFont && platformId === 3 && encodingId === 0) {
  33145. useTable = true;
  33146. canBreak = true;
  33147. }
  33148. if (useTable) {
  33149. potentialTable = {
  33150. platformId: platformId,
  33151. encodingId: encodingId,
  33152. offset: offset
  33153. };
  33154. }
  33155. if (canBreak) {
  33156. break;
  33157. }
  33158. }
  33159. if (potentialTable) {
  33160. font.pos = start + potentialTable.offset;
  33161. }
  33162. if (!potentialTable || font.peekByte() === -1) {
  33163. warn('Could not find a preferred cmap table.');
  33164. return {
  33165. platformId: -1,
  33166. encodingId: -1,
  33167. mappings: [],
  33168. hasShortCmap: false
  33169. };
  33170. }
  33171. var format = font.getUint16();
  33172. var length = font.getUint16();
  33173. var language = font.getUint16();
  33174. var hasShortCmap = false;
  33175. var mappings = [];
  33176. var j, glyphId;
  33177. // TODO(mack): refactor this cmap subtable reading logic out
  33178. if (format === 0) {
  33179. for (j = 0; j < 256; j++) {
  33180. var index = font.getByte();
  33181. if (!index) {
  33182. continue;
  33183. }
  33184. mappings.push({
  33185. charCode: j,
  33186. glyphId: index
  33187. });
  33188. }
  33189. hasShortCmap = true;
  33190. } else if (format === 4) {
  33191. // re-creating the table in format 4 since the encoding
  33192. // might be changed
  33193. var segCount = (font.getUint16() >> 1);
  33194. font.getBytes(6); // skipping range fields
  33195. var segIndex, segments = [];
  33196. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33197. segments.push({ end: font.getUint16() });
  33198. }
  33199. font.getUint16();
  33200. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33201. segments[segIndex].start = font.getUint16();
  33202. }
  33203. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33204. segments[segIndex].delta = font.getUint16();
  33205. }
  33206. var offsetsCount = 0;
  33207. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33208. segment = segments[segIndex];
  33209. var rangeOffset = font.getUint16();
  33210. if (!rangeOffset) {
  33211. segment.offsetIndex = -1;
  33212. continue;
  33213. }
  33214. var offsetIndex = (rangeOffset >> 1) - (segCount - segIndex);
  33215. segment.offsetIndex = offsetIndex;
  33216. offsetsCount = Math.max(offsetsCount, offsetIndex +
  33217. segment.end - segment.start + 1);
  33218. }
  33219. var offsets = [];
  33220. for (j = 0; j < offsetsCount; j++) {
  33221. offsets.push(font.getUint16());
  33222. }
  33223. for (segIndex = 0; segIndex < segCount; segIndex++) {
  33224. segment = segments[segIndex];
  33225. start = segment.start;
  33226. var end = segment.end;
  33227. var delta = segment.delta;
  33228. offsetIndex = segment.offsetIndex;
  33229. for (j = start; j <= end; j++) {
  33230. if (j === 0xFFFF) {
  33231. continue;
  33232. }
  33233. glyphId = (offsetIndex < 0 ?
  33234. j : offsets[offsetIndex + j - start]);
  33235. glyphId = (glyphId + delta) & 0xFFFF;
  33236. if (glyphId === 0) {
  33237. continue;
  33238. }
  33239. mappings.push({
  33240. charCode: j,
  33241. glyphId: glyphId
  33242. });
  33243. }
  33244. }
  33245. } else if (format === 6) {
  33246. // Format 6 is a 2-bytes dense mapping, which means the font data
  33247. // lives glue together even if they are pretty far in the unicode
  33248. // table. (This looks weird, so I can have missed something), this
  33249. // works on Linux but seems to fails on Mac so let's rewrite the
  33250. // cmap table to a 3-1-4 style
  33251. var firstCode = font.getUint16();
  33252. var entryCount = font.getUint16();
  33253. for (j = 0; j < entryCount; j++) {
  33254. glyphId = font.getUint16();
  33255. var charCode = firstCode + j;
  33256. mappings.push({
  33257. charCode: charCode,
  33258. glyphId: glyphId
  33259. });
  33260. }
  33261. } else {
  33262. warn('cmap table has unsupported format: ' + format);
  33263. return {
  33264. platformId: -1,
  33265. encodingId: -1,
  33266. mappings: [],
  33267. hasShortCmap: false
  33268. };
  33269. }
  33270. // removing duplicate entries
  33271. mappings.sort(function (a, b) {
  33272. return a.charCode - b.charCode;
  33273. });
  33274. for (i = 1; i < mappings.length; i++) {
  33275. if (mappings[i - 1].charCode === mappings[i].charCode) {
  33276. mappings.splice(i, 1);
  33277. i--;
  33278. }
  33279. }
  33280. return {
  33281. platformId: potentialTable.platformId,
  33282. encodingId: potentialTable.encodingId,
  33283. mappings: mappings,
  33284. hasShortCmap: hasShortCmap
  33285. };
  33286. }
  33287. function sanitizeMetrics(font, header, metrics, numGlyphs) {
  33288. if (!header) {
  33289. if (metrics) {
  33290. metrics.data = null;
  33291. }
  33292. return;
  33293. }
  33294. font.pos = (font.start ? font.start : 0) + header.offset;
  33295. font.pos += header.length - 2;
  33296. var numOfMetrics = font.getUint16();
  33297. if (numOfMetrics > numGlyphs) {
  33298. info('The numOfMetrics (' + numOfMetrics + ') should not be ' +
  33299. 'greater than the numGlyphs (' + numGlyphs + ')');
  33300. // Reduce numOfMetrics if it is greater than numGlyphs
  33301. numOfMetrics = numGlyphs;
  33302. header.data[34] = (numOfMetrics & 0xff00) >> 8;
  33303. header.data[35] = numOfMetrics & 0x00ff;
  33304. }
  33305. var numOfSidebearings = numGlyphs - numOfMetrics;
  33306. var numMissing = numOfSidebearings -
  33307. ((metrics.length - numOfMetrics * 4) >> 1);
  33308. if (numMissing > 0) {
  33309. // For each missing glyph, we set both the width and lsb to 0 (zero).
  33310. // Since we need to add two properties for each glyph, this explains
  33311. // the use of |numMissing * 2| when initializing the typed array.
  33312. var entries = new Uint8Array(metrics.length + numMissing * 2);
  33313. entries.set(metrics.data);
  33314. metrics.data = entries;
  33315. }
  33316. }
  33317. function sanitizeGlyph(source, sourceStart, sourceEnd, dest, destStart,
  33318. hintsValid) {
  33319. if (sourceEnd - sourceStart <= 12) {
  33320. // glyph with data less than 12 is invalid one
  33321. return 0;
  33322. }
  33323. var glyf = source.subarray(sourceStart, sourceEnd);
  33324. var contoursCount = (glyf[0] << 8) | glyf[1];
  33325. if (contoursCount & 0x8000) {
  33326. // complex glyph, writing as is
  33327. dest.set(glyf, destStart);
  33328. return glyf.length;
  33329. }
  33330. var i, j = 10, flagsCount = 0;
  33331. for (i = 0; i < contoursCount; i++) {
  33332. var endPoint = (glyf[j] << 8) | glyf[j + 1];
  33333. flagsCount = endPoint + 1;
  33334. j += 2;
  33335. }
  33336. // skipping instructions
  33337. var instructionsStart = j;
  33338. var instructionsLength = (glyf[j] << 8) | glyf[j + 1];
  33339. j += 2 + instructionsLength;
  33340. var instructionsEnd = j;
  33341. // validating flags
  33342. var coordinatesLength = 0;
  33343. for (i = 0; i < flagsCount; i++) {
  33344. var flag = glyf[j++];
  33345. if (flag & 0xC0) {
  33346. // reserved flags must be zero, cleaning up
  33347. glyf[j - 1] = flag & 0x3F;
  33348. }
  33349. var xyLength = ((flag & 2) ? 1 : (flag & 16) ? 0 : 2) +
  33350. ((flag & 4) ? 1 : (flag & 32) ? 0 : 2);
  33351. coordinatesLength += xyLength;
  33352. if (flag & 8) {
  33353. var repeat = glyf[j++];
  33354. i += repeat;
  33355. coordinatesLength += repeat * xyLength;
  33356. }
  33357. }
  33358. // glyph without coordinates will be rejected
  33359. if (coordinatesLength === 0) {
  33360. return 0;
  33361. }
  33362. var glyphDataLength = j + coordinatesLength;
  33363. if (glyphDataLength > glyf.length) {
  33364. // not enough data for coordinates
  33365. return 0;
  33366. }
  33367. if (!hintsValid && instructionsLength > 0) {
  33368. dest.set(glyf.subarray(0, instructionsStart), destStart);
  33369. dest.set([0, 0], destStart + instructionsStart);
  33370. dest.set(glyf.subarray(instructionsEnd, glyphDataLength),
  33371. destStart + instructionsStart + 2);
  33372. glyphDataLength -= instructionsLength;
  33373. if (glyf.length - glyphDataLength > 3) {
  33374. glyphDataLength = (glyphDataLength + 3) & ~3;
  33375. }
  33376. return glyphDataLength;
  33377. }
  33378. if (glyf.length - glyphDataLength > 3) {
  33379. // truncating and aligning to 4 bytes the long glyph data
  33380. glyphDataLength = (glyphDataLength + 3) & ~3;
  33381. dest.set(glyf.subarray(0, glyphDataLength), destStart);
  33382. return glyphDataLength;
  33383. }
  33384. // glyph data is fine
  33385. dest.set(glyf, destStart);
  33386. return glyf.length;
  33387. }
  33388. function sanitizeHead(head, numGlyphs, locaLength) {
  33389. var data = head.data;
  33390. // Validate version:
  33391. // Should always be 0x00010000
  33392. var version = int32(data[0], data[1], data[2], data[3]);
  33393. if (version >> 16 !== 1) {
  33394. info('Attempting to fix invalid version in head table: ' + version);
  33395. data[0] = 0;
  33396. data[1] = 1;
  33397. data[2] = 0;
  33398. data[3] = 0;
  33399. }
  33400. var indexToLocFormat = int16(data[50], data[51]);
  33401. if (indexToLocFormat < 0 || indexToLocFormat > 1) {
  33402. info('Attempting to fix invalid indexToLocFormat in head table: ' +
  33403. indexToLocFormat);
  33404. // The value of indexToLocFormat should be 0 if the loca table
  33405. // consists of short offsets, and should be 1 if the loca table
  33406. // consists of long offsets.
  33407. //
  33408. // The number of entries in the loca table should be numGlyphs + 1.
  33409. //
  33410. // Using this information, we can work backwards to deduce if the
  33411. // size of each offset in the loca table, and thus figure out the
  33412. // appropriate value for indexToLocFormat.
  33413. var numGlyphsPlusOne = numGlyphs + 1;
  33414. if (locaLength === numGlyphsPlusOne << 1) {
  33415. // 0x0000 indicates the loca table consists of short offsets
  33416. data[50] = 0;
  33417. data[51] = 0;
  33418. } else if (locaLength === numGlyphsPlusOne << 2) {
  33419. // 0x0001 indicates the loca table consists of long offsets
  33420. data[50] = 0;
  33421. data[51] = 1;
  33422. } else {
  33423. warn('Could not fix indexToLocFormat: ' + indexToLocFormat);
  33424. }
  33425. }
  33426. }
  33427. function sanitizeGlyphLocations(loca, glyf, numGlyphs,
  33428. isGlyphLocationsLong, hintsValid,
  33429. dupFirstEntry) {
  33430. var itemSize, itemDecode, itemEncode;
  33431. if (isGlyphLocationsLong) {
  33432. itemSize = 4;
  33433. itemDecode = function fontItemDecodeLong(data, offset) {
  33434. return (data[offset] << 24) | (data[offset + 1] << 16) |
  33435. (data[offset + 2] << 8) | data[offset + 3];
  33436. };
  33437. itemEncode = function fontItemEncodeLong(data, offset, value) {
  33438. data[offset] = (value >>> 24) & 0xFF;
  33439. data[offset + 1] = (value >> 16) & 0xFF;
  33440. data[offset + 2] = (value >> 8) & 0xFF;
  33441. data[offset + 3] = value & 0xFF;
  33442. };
  33443. } else {
  33444. itemSize = 2;
  33445. itemDecode = function fontItemDecode(data, offset) {
  33446. return (data[offset] << 9) | (data[offset + 1] << 1);
  33447. };
  33448. itemEncode = function fontItemEncode(data, offset, value) {
  33449. data[offset] = (value >> 9) & 0xFF;
  33450. data[offset + 1] = (value >> 1) & 0xFF;
  33451. };
  33452. }
  33453. var locaData = loca.data;
  33454. var locaDataSize = itemSize * (1 + numGlyphs);
  33455. // is loca.data too short or long?
  33456. if (locaData.length !== locaDataSize) {
  33457. locaData = new Uint8Array(locaDataSize);
  33458. locaData.set(loca.data.subarray(0, locaDataSize));
  33459. loca.data = locaData;
  33460. }
  33461. // removing the invalid glyphs
  33462. var oldGlyfData = glyf.data;
  33463. var oldGlyfDataLength = oldGlyfData.length;
  33464. var newGlyfData = new Uint8Array(oldGlyfDataLength);
  33465. var startOffset = itemDecode(locaData, 0);
  33466. var writeOffset = 0;
  33467. var missingGlyphData = Object.create(null);
  33468. itemEncode(locaData, 0, writeOffset);
  33469. var i, j;
  33470. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33471. var endOffset = itemDecode(locaData, j);
  33472. if (endOffset > oldGlyfDataLength &&
  33473. ((oldGlyfDataLength + 3) & ~3) === endOffset) {
  33474. // Aspose breaks fonts by aligning the glyphs to the qword, but not
  33475. // the glyf table size, which makes last glyph out of range.
  33476. endOffset = oldGlyfDataLength;
  33477. }
  33478. if (endOffset > oldGlyfDataLength) {
  33479. // glyph end offset points outside glyf data, rejecting the glyph
  33480. itemEncode(locaData, j, writeOffset);
  33481. startOffset = endOffset;
  33482. continue;
  33483. }
  33484. if (startOffset === endOffset) {
  33485. missingGlyphData[i] = true;
  33486. }
  33487. var newLength = sanitizeGlyph(oldGlyfData, startOffset, endOffset,
  33488. newGlyfData, writeOffset, hintsValid);
  33489. writeOffset += newLength;
  33490. itemEncode(locaData, j, writeOffset);
  33491. startOffset = endOffset;
  33492. }
  33493. if (writeOffset === 0) {
  33494. // glyf table cannot be empty -- redoing the glyf and loca tables
  33495. // to have single glyph with one point
  33496. var simpleGlyph = new Uint8Array(
  33497. [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 49, 0]);
  33498. for (i = 0, j = itemSize; i < numGlyphs; i++, j += itemSize) {
  33499. itemEncode(locaData, j, simpleGlyph.length);
  33500. }
  33501. glyf.data = simpleGlyph;
  33502. return missingGlyphData;
  33503. }
  33504. if (dupFirstEntry) {
  33505. var firstEntryLength = itemDecode(locaData, itemSize);
  33506. if (newGlyfData.length > firstEntryLength + writeOffset) {
  33507. glyf.data = newGlyfData.subarray(0, firstEntryLength + writeOffset);
  33508. } else {
  33509. glyf.data = new Uint8Array(firstEntryLength + writeOffset);
  33510. glyf.data.set(newGlyfData.subarray(0, writeOffset));
  33511. }
  33512. glyf.data.set(newGlyfData.subarray(0, firstEntryLength), writeOffset);
  33513. itemEncode(loca.data, locaData.length - itemSize,
  33514. writeOffset + firstEntryLength);
  33515. } else {
  33516. glyf.data = newGlyfData.subarray(0, writeOffset);
  33517. }
  33518. return missingGlyphData;
  33519. }
  33520. function readPostScriptTable(post, properties, maxpNumGlyphs) {
  33521. var start = (font.start ? font.start : 0) + post.offset;
  33522. font.pos = start;
  33523. var length = post.length, end = start + length;
  33524. var version = font.getInt32();
  33525. // skip rest to the tables
  33526. font.getBytes(28);
  33527. var glyphNames;
  33528. var valid = true;
  33529. var i;
  33530. switch (version) {
  33531. case 0x00010000:
  33532. glyphNames = MacStandardGlyphOrdering;
  33533. break;
  33534. case 0x00020000:
  33535. var numGlyphs = font.getUint16();
  33536. if (numGlyphs !== maxpNumGlyphs) {
  33537. valid = false;
  33538. break;
  33539. }
  33540. var glyphNameIndexes = [];
  33541. for (i = 0; i < numGlyphs; ++i) {
  33542. var index = font.getUint16();
  33543. if (index >= 32768) {
  33544. valid = false;
  33545. break;
  33546. }
  33547. glyphNameIndexes.push(index);
  33548. }
  33549. if (!valid) {
  33550. break;
  33551. }
  33552. var customNames = [];
  33553. var strBuf = [];
  33554. while (font.pos < end) {
  33555. var stringLength = font.getByte();
  33556. strBuf.length = stringLength;
  33557. for (i = 0; i < stringLength; ++i) {
  33558. strBuf[i] = String.fromCharCode(font.getByte());
  33559. }
  33560. customNames.push(strBuf.join(''));
  33561. }
  33562. glyphNames = [];
  33563. for (i = 0; i < numGlyphs; ++i) {
  33564. var j = glyphNameIndexes[i];
  33565. if (j < 258) {
  33566. glyphNames.push(MacStandardGlyphOrdering[j]);
  33567. continue;
  33568. }
  33569. glyphNames.push(customNames[j - 258]);
  33570. }
  33571. break;
  33572. case 0x00030000:
  33573. break;
  33574. default:
  33575. warn('Unknown/unsupported post table version ' + version);
  33576. valid = false;
  33577. if (properties.defaultEncoding) {
  33578. glyphNames = properties.defaultEncoding;
  33579. }
  33580. break;
  33581. }
  33582. properties.glyphNames = glyphNames;
  33583. return valid;
  33584. }
  33585. function readNameTable(nameTable) {
  33586. var start = (font.start ? font.start : 0) + nameTable.offset;
  33587. font.pos = start;
  33588. var names = [[], []];
  33589. var length = nameTable.length, end = start + length;
  33590. var format = font.getUint16();
  33591. var FORMAT_0_HEADER_LENGTH = 6;
  33592. if (format !== 0 || length < FORMAT_0_HEADER_LENGTH) {
  33593. // unsupported name table format or table "too" small
  33594. return names;
  33595. }
  33596. var numRecords = font.getUint16();
  33597. var stringsStart = font.getUint16();
  33598. var records = [];
  33599. var NAME_RECORD_LENGTH = 12;
  33600. var i, ii;
  33601. for (i = 0; i < numRecords &&
  33602. font.pos + NAME_RECORD_LENGTH <= end; i++) {
  33603. var r = {
  33604. platform: font.getUint16(),
  33605. encoding: font.getUint16(),
  33606. language: font.getUint16(),
  33607. name: font.getUint16(),
  33608. length: font.getUint16(),
  33609. offset: font.getUint16()
  33610. };
  33611. // using only Macintosh and Windows platform/encoding names
  33612. if ((r.platform === 1 && r.encoding === 0 && r.language === 0) ||
  33613. (r.platform === 3 && r.encoding === 1 && r.language === 0x409)) {
  33614. records.push(r);
  33615. }
  33616. }
  33617. for (i = 0, ii = records.length; i < ii; i++) {
  33618. var record = records[i];
  33619. if (record.length <= 0) {
  33620. continue; // Nothing to process, ignoring.
  33621. }
  33622. var pos = start + stringsStart + record.offset;
  33623. if (pos + record.length > end) {
  33624. continue; // outside of name table, ignoring
  33625. }
  33626. font.pos = pos;
  33627. var nameIndex = record.name;
  33628. if (record.encoding) {
  33629. // unicode
  33630. var str = '';
  33631. for (var j = 0, jj = record.length; j < jj; j += 2) {
  33632. str += String.fromCharCode(font.getUint16());
  33633. }
  33634. names[1][nameIndex] = str;
  33635. } else {
  33636. names[0][nameIndex] = bytesToString(font.getBytes(record.length));
  33637. }
  33638. }
  33639. return names;
  33640. }
  33641. var TTOpsStackDeltas = [
  33642. 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -2, -2, 0, 0, -2, -5,
  33643. -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, -1, -1,
  33644. 1, -1, -999, 0, 1, 0, -1, -2, 0, -1, -2, -1, -1, 0, -1, -1,
  33645. 0, 0, -999, -999, -1, -1, -1, -1, -2, -999, -2, -2, -999, 0, -2, -2,
  33646. 0, 0, -2, 0, -2, 0, 0, 0, -2, -1, -1, 1, 1, 0, 0, -1,
  33647. -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, -1, -1, 0, -999, -1, -1,
  33648. -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  33649. -2, -999, -999, -999, -999, -999, -1, -1, -2, -2, 0, 0, 0, 0, -1, -1,
  33650. -999, -2, -2, 0, 0, -1, -2, -2, 0, 0, 0, -1, -1, -1, -2];
  33651. // 0xC0-DF == -1 and 0xE0-FF == -2
  33652. function sanitizeTTProgram(table, ttContext) {
  33653. var data = table.data;
  33654. var i = 0, j, n, b, funcId, pc, lastEndf = 0, lastDeff = 0;
  33655. var stack = [];
  33656. var callstack = [];
  33657. var functionsCalled = [];
  33658. var tooComplexToFollowFunctions =
  33659. ttContext.tooComplexToFollowFunctions;
  33660. var inFDEF = false, ifLevel = 0, inELSE = 0;
  33661. for (var ii = data.length; i < ii;) {
  33662. var op = data[i++];
  33663. // The TrueType instruction set docs can be found at
  33664. // https://developer.apple.com/fonts/TTRefMan/RM05/Chap5.html
  33665. if (op === 0x40) { // NPUSHB - pushes n bytes
  33666. n = data[i++];
  33667. if (inFDEF || inELSE) {
  33668. i += n;
  33669. } else {
  33670. for (j = 0; j < n; j++) {
  33671. stack.push(data[i++]);
  33672. }
  33673. }
  33674. } else if (op === 0x41) { // NPUSHW - pushes n words
  33675. n = data[i++];
  33676. if (inFDEF || inELSE) {
  33677. i += n * 2;
  33678. } else {
  33679. for (j = 0; j < n; j++) {
  33680. b = data[i++];
  33681. stack.push((b << 8) | data[i++]);
  33682. }
  33683. }
  33684. } else if ((op & 0xF8) === 0xB0) { // PUSHB - pushes bytes
  33685. n = op - 0xB0 + 1;
  33686. if (inFDEF || inELSE) {
  33687. i += n;
  33688. } else {
  33689. for (j = 0; j < n; j++) {
  33690. stack.push(data[i++]);
  33691. }
  33692. }
  33693. } else if ((op & 0xF8) === 0xB8) { // PUSHW - pushes words
  33694. n = op - 0xB8 + 1;
  33695. if (inFDEF || inELSE) {
  33696. i += n * 2;
  33697. } else {
  33698. for (j = 0; j < n; j++) {
  33699. b = data[i++];
  33700. stack.push((b << 8) | data[i++]);
  33701. }
  33702. }
  33703. } else if (op === 0x2B && !tooComplexToFollowFunctions) { // CALL
  33704. if (!inFDEF && !inELSE) {
  33705. // collecting inforamtion about which functions are used
  33706. funcId = stack[stack.length - 1];
  33707. ttContext.functionsUsed[funcId] = true;
  33708. if (funcId in ttContext.functionsStackDeltas) {
  33709. stack.length += ttContext.functionsStackDeltas[funcId];
  33710. } else if (funcId in ttContext.functionsDefined &&
  33711. functionsCalled.indexOf(funcId) < 0) {
  33712. callstack.push({data: data, i: i, stackTop: stack.length - 1});
  33713. functionsCalled.push(funcId);
  33714. pc = ttContext.functionsDefined[funcId];
  33715. if (!pc) {
  33716. warn('TT: CALL non-existent function');
  33717. ttContext.hintsValid = false;
  33718. return;
  33719. }
  33720. data = pc.data;
  33721. i = pc.i;
  33722. }
  33723. }
  33724. } else if (op === 0x2C && !tooComplexToFollowFunctions) { // FDEF
  33725. if (inFDEF || inELSE) {
  33726. warn('TT: nested FDEFs not allowed');
  33727. tooComplexToFollowFunctions = true;
  33728. }
  33729. inFDEF = true;
  33730. // collecting inforamtion about which functions are defined
  33731. lastDeff = i;
  33732. funcId = stack.pop();
  33733. ttContext.functionsDefined[funcId] = {data: data, i: i};
  33734. } else if (op === 0x2D) { // ENDF - end of function
  33735. if (inFDEF) {
  33736. inFDEF = false;
  33737. lastEndf = i;
  33738. } else {
  33739. pc = callstack.pop();
  33740. if (!pc) {
  33741. warn('TT: ENDF bad stack');
  33742. ttContext.hintsValid = false;
  33743. return;
  33744. }
  33745. funcId = functionsCalled.pop();
  33746. data = pc.data;
  33747. i = pc.i;
  33748. ttContext.functionsStackDeltas[funcId] =
  33749. stack.length - pc.stackTop;
  33750. }
  33751. } else if (op === 0x89) { // IDEF - instruction definition
  33752. if (inFDEF || inELSE) {
  33753. warn('TT: nested IDEFs not allowed');
  33754. tooComplexToFollowFunctions = true;
  33755. }
  33756. inFDEF = true;
  33757. // recording it as a function to track ENDF
  33758. lastDeff = i;
  33759. } else if (op === 0x58) { // IF
  33760. ++ifLevel;
  33761. } else if (op === 0x1B) { // ELSE
  33762. inELSE = ifLevel;
  33763. } else if (op === 0x59) { // EIF
  33764. if (inELSE === ifLevel) {
  33765. inELSE = 0;
  33766. }
  33767. --ifLevel;
  33768. } else if (op === 0x1C) { // JMPR
  33769. if (!inFDEF && !inELSE) {
  33770. var offset = stack[stack.length - 1];
  33771. // only jumping forward to prevent infinite loop
  33772. if (offset > 0) {
  33773. i += offset - 1;
  33774. }
  33775. }
  33776. }
  33777. // Adjusting stack not extactly, but just enough to get function id
  33778. if (!inFDEF && !inELSE) {
  33779. var stackDelta = op <= 0x8E ? TTOpsStackDeltas[op] :
  33780. op >= 0xC0 && op <= 0xDF ? -1 : op >= 0xE0 ? -2 : 0;
  33781. if (op >= 0x71 && op <= 0x75) {
  33782. n = stack.pop();
  33783. if (n === n) {
  33784. stackDelta = -n * 2;
  33785. }
  33786. }
  33787. while (stackDelta < 0 && stack.length > 0) {
  33788. stack.pop();
  33789. stackDelta++;
  33790. }
  33791. while (stackDelta > 0) {
  33792. stack.push(NaN); // pushing any number into stack
  33793. stackDelta--;
  33794. }
  33795. }
  33796. }
  33797. ttContext.tooComplexToFollowFunctions = tooComplexToFollowFunctions;
  33798. var content = [data];
  33799. if (i > data.length) {
  33800. content.push(new Uint8Array(i - data.length));
  33801. }
  33802. if (lastDeff > lastEndf) {
  33803. warn('TT: complementing a missing function tail');
  33804. // new function definition started, but not finished
  33805. // complete function by [CLEAR, ENDF]
  33806. content.push(new Uint8Array([0x22, 0x2D]));
  33807. }
  33808. foldTTTable(table, content);
  33809. }
  33810. function checkInvalidFunctions(ttContext, maxFunctionDefs) {
  33811. if (ttContext.tooComplexToFollowFunctions) {
  33812. return;
  33813. }
  33814. if (ttContext.functionsDefined.length > maxFunctionDefs) {
  33815. warn('TT: more functions defined than expected');
  33816. ttContext.hintsValid = false;
  33817. return;
  33818. }
  33819. for (var j = 0, jj = ttContext.functionsUsed.length; j < jj; j++) {
  33820. if (j > maxFunctionDefs) {
  33821. warn('TT: invalid function id: ' + j);
  33822. ttContext.hintsValid = false;
  33823. return;
  33824. }
  33825. if (ttContext.functionsUsed[j] && !ttContext.functionsDefined[j]) {
  33826. warn('TT: undefined function: ' + j);
  33827. ttContext.hintsValid = false;
  33828. return;
  33829. }
  33830. }
  33831. }
  33832. function foldTTTable(table, content) {
  33833. if (content.length > 1) {
  33834. // concatenating the content items
  33835. var newLength = 0;
  33836. var j, jj;
  33837. for (j = 0, jj = content.length; j < jj; j++) {
  33838. newLength += content[j].length;
  33839. }
  33840. newLength = (newLength + 3) & ~3;
  33841. var result = new Uint8Array(newLength);
  33842. var pos = 0;
  33843. for (j = 0, jj = content.length; j < jj; j++) {
  33844. result.set(content[j], pos);
  33845. pos += content[j].length;
  33846. }
  33847. table.data = result;
  33848. table.length = newLength;
  33849. }
  33850. }
  33851. function sanitizeTTPrograms(fpgm, prep, cvt) {
  33852. var ttContext = {
  33853. functionsDefined: [],
  33854. functionsUsed: [],
  33855. functionsStackDeltas: [],
  33856. tooComplexToFollowFunctions: false,
  33857. hintsValid: true
  33858. };
  33859. if (fpgm) {
  33860. sanitizeTTProgram(fpgm, ttContext);
  33861. }
  33862. if (prep) {
  33863. sanitizeTTProgram(prep, ttContext);
  33864. }
  33865. if (fpgm) {
  33866. checkInvalidFunctions(ttContext, maxFunctionDefs);
  33867. }
  33868. if (cvt && (cvt.length & 1)) {
  33869. var cvtData = new Uint8Array(cvt.length + 1);
  33870. cvtData.set(cvt.data);
  33871. cvt.data = cvtData;
  33872. }
  33873. return ttContext.hintsValid;
  33874. }
  33875. // The following steps modify the original font data, making copy
  33876. font = new Stream(new Uint8Array(font.getBytes()));
  33877. var VALID_TABLES = ['OS/2', 'cmap', 'head', 'hhea', 'hmtx', 'maxp',
  33878. 'name', 'post', 'loca', 'glyf', 'fpgm', 'prep', 'cvt ', 'CFF '];
  33879. var header = readOpenTypeHeader(font);
  33880. var numTables = header.numTables;
  33881. var cff, cffFile;
  33882. var tables = Object.create(null);
  33883. tables['OS/2'] = null;
  33884. tables['cmap'] = null;
  33885. tables['head'] = null;
  33886. tables['hhea'] = null;
  33887. tables['hmtx'] = null;
  33888. tables['maxp'] = null;
  33889. tables['name'] = null;
  33890. tables['post'] = null;
  33891. var table;
  33892. for (var i = 0; i < numTables; i++) {
  33893. table = readTableEntry(font);
  33894. if (VALID_TABLES.indexOf(table.tag) < 0) {
  33895. continue; // skipping table if it's not a required or optional table
  33896. }
  33897. if (table.length === 0) {
  33898. continue; // skipping empty tables
  33899. }
  33900. tables[table.tag] = table;
  33901. }
  33902. var isTrueType = !tables['CFF '];
  33903. if (!isTrueType) {
  33904. // OpenType font
  33905. if ((header.version === 'OTTO' && properties.type !== 'CIDFontType2') ||
  33906. !tables['head'] || !tables['hhea'] || !tables['maxp'] ||
  33907. !tables['post']) {
  33908. // no major tables: throwing everything at CFFFont
  33909. cffFile = new Stream(tables['CFF '].data);
  33910. cff = new CFFFont(cffFile, properties);
  33911. adjustWidths(properties);
  33912. return this.convert(name, cff, properties);
  33913. }
  33914. delete tables['glyf'];
  33915. delete tables['loca'];
  33916. delete tables['fpgm'];
  33917. delete tables['prep'];
  33918. delete tables['cvt '];
  33919. this.isOpenType = true;
  33920. } else {
  33921. if (!tables['loca']) {
  33922. error('Required "loca" table is not found');
  33923. }
  33924. if (!tables['glyf']) {
  33925. warn('Required "glyf" table is not found -- trying to recover.');
  33926. // Note: We use `sanitizeGlyphLocations` to add dummy glyf data below.
  33927. tables['glyf'] = {
  33928. tag: 'glyf',
  33929. data: new Uint8Array(0),
  33930. };
  33931. }
  33932. this.isOpenType = false;
  33933. }
  33934. if (!tables['maxp']) {
  33935. error('Required "maxp" table is not found');
  33936. }
  33937. font.pos = (font.start || 0) + tables['maxp'].offset;
  33938. var version = font.getInt32();
  33939. var numGlyphs = font.getUint16();
  33940. var maxFunctionDefs = 0;
  33941. if (version >= 0x00010000 && tables['maxp'].length >= 22) {
  33942. // maxZones can be invalid
  33943. font.pos += 8;
  33944. var maxZones = font.getUint16();
  33945. if (maxZones > 2) { // reset to 2 if font has invalid maxZones
  33946. tables['maxp'].data[14] = 0;
  33947. tables['maxp'].data[15] = 2;
  33948. }
  33949. font.pos += 4;
  33950. maxFunctionDefs = font.getUint16();
  33951. }
  33952. var dupFirstEntry = false;
  33953. if (properties.type === 'CIDFontType2' && properties.toUnicode &&
  33954. properties.toUnicode.get(0) > '\u0000') {
  33955. // oracle's defect (see 3427), duplicating first entry
  33956. dupFirstEntry = true;
  33957. numGlyphs++;
  33958. tables['maxp'].data[4] = numGlyphs >> 8;
  33959. tables['maxp'].data[5] = numGlyphs & 255;
  33960. }
  33961. var hintsValid = sanitizeTTPrograms(tables['fpgm'], tables['prep'],
  33962. tables['cvt '], maxFunctionDefs);
  33963. if (!hintsValid) {
  33964. delete tables['fpgm'];
  33965. delete tables['prep'];
  33966. delete tables['cvt '];
  33967. }
  33968. // Ensure the hmtx table contains the advance width and
  33969. // sidebearings information for numGlyphs in the maxp table
  33970. sanitizeMetrics(font, tables['hhea'], tables['hmtx'], numGlyphs);
  33971. if (!tables['head']) {
  33972. error('Required "head" table is not found');
  33973. }
  33974. sanitizeHead(tables['head'], numGlyphs,
  33975. isTrueType ? tables['loca'].length : 0);
  33976. var missingGlyphs = Object.create(null);
  33977. if (isTrueType) {
  33978. var isGlyphLocationsLong = int16(tables['head'].data[50],
  33979. tables['head'].data[51]);
  33980. missingGlyphs = sanitizeGlyphLocations(tables['loca'], tables['glyf'],
  33981. numGlyphs, isGlyphLocationsLong,
  33982. hintsValid, dupFirstEntry);
  33983. }
  33984. if (!tables['hhea']) {
  33985. error('Required "hhea" table is not found');
  33986. }
  33987. // Sanitizer reduces the glyph advanceWidth to the maxAdvanceWidth
  33988. // Sometimes it's 0. That needs to be fixed
  33989. if (tables['hhea'].data[10] === 0 && tables['hhea'].data[11] === 0) {
  33990. tables['hhea'].data[10] = 0xFF;
  33991. tables['hhea'].data[11] = 0xFF;
  33992. }
  33993. // Extract some more font properties from the OpenType head and
  33994. // hhea tables; yMin and descent value are always negative.
  33995. var metricsOverride = {
  33996. unitsPerEm: int16(tables['head'].data[18], tables['head'].data[19]),
  33997. yMax: int16(tables['head'].data[42], tables['head'].data[43]),
  33998. yMin: signedInt16(tables['head'].data[38], tables['head'].data[39]),
  33999. ascent: int16(tables['hhea'].data[4], tables['hhea'].data[5]),
  34000. descent: signedInt16(tables['hhea'].data[6], tables['hhea'].data[7])
  34001. };
  34002. // PDF FontDescriptor metrics lie -- using data from actual font.
  34003. this.ascent = metricsOverride.ascent / metricsOverride.unitsPerEm;
  34004. this.descent = metricsOverride.descent / metricsOverride.unitsPerEm;
  34005. // The 'post' table has glyphs names.
  34006. if (tables['post']) {
  34007. var valid = readPostScriptTable(tables['post'], properties, numGlyphs);
  34008. if (!valid) {
  34009. tables['post'] = null;
  34010. }
  34011. }
  34012. var charCodeToGlyphId = [], charCode;
  34013. var toUnicode = properties.toUnicode, widths = properties.widths;
  34014. var skipToUnicode = (toUnicode instanceof IdentityToUnicodeMap ||
  34015. toUnicode.length === 0x10000);
  34016. // Helper function to try to skip mapping of empty glyphs.
  34017. // Note: In some cases, just relying on the glyph data doesn't work,
  34018. // hence we also use a few heuristics to fix various PDF files.
  34019. function hasGlyph(glyphId, charCode, widthCode) {
  34020. if (!missingGlyphs[glyphId]) {
  34021. return true;
  34022. }
  34023. if (!skipToUnicode && charCode >= 0 && toUnicode.has(charCode)) {
  34024. return true;
  34025. }
  34026. if (widths && widthCode >= 0 && isNum(widths[widthCode])) {
  34027. return true;
  34028. }
  34029. return false;
  34030. }
  34031. // Some bad PDF generators, e.g. Scribus PDF, include glyph names
  34032. // in a 'uniXXXX' format -- attempting to recover proper ones.
  34033. function recoverGlyphName(name, glyphsUnicodeMap) {
  34034. if (glyphsUnicodeMap[name] !== undefined) {
  34035. return name;
  34036. }
  34037. // The glyph name is non-standard, trying to recover.
  34038. var unicode = getUnicodeForGlyph(name, glyphsUnicodeMap);
  34039. if (unicode !== -1) {
  34040. for (var key in glyphsUnicodeMap) {
  34041. if (glyphsUnicodeMap[key] === unicode) {
  34042. return key;
  34043. }
  34044. }
  34045. }
  34046. warn('Unable to recover a standard glyph name for: ' + name);
  34047. return name;
  34048. }
  34049. if (properties.type === 'CIDFontType2') {
  34050. var cidToGidMap = properties.cidToGidMap || [];
  34051. var isCidToGidMapEmpty = cidToGidMap.length === 0;
  34052. properties.cMap.forEach(function(charCode, cid) {
  34053. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  34054. var glyphId = -1;
  34055. if (isCidToGidMapEmpty) {
  34056. glyphId = cid;
  34057. } else if (cidToGidMap[cid] !== undefined) {
  34058. glyphId = cidToGidMap[cid];
  34059. }
  34060. if (glyphId >= 0 && glyphId < numGlyphs &&
  34061. hasGlyph(glyphId, charCode, cid)) {
  34062. charCodeToGlyphId[charCode] = glyphId;
  34063. }
  34064. });
  34065. if (dupFirstEntry) {
  34066. charCodeToGlyphId[0] = numGlyphs - 1;
  34067. }
  34068. } else {
  34069. // Most of the following logic in this code branch is based on the
  34070. // 9.6.6.4 of the PDF spec.
  34071. var hasEncoding =
  34072. properties.differences.length > 0 || !!properties.baseEncodingName;
  34073. var cmapTable =
  34074. readCmapTable(tables['cmap'], font, this.isSymbolicFont, hasEncoding);
  34075. var cmapPlatformId = cmapTable.platformId;
  34076. var cmapEncodingId = cmapTable.encodingId;
  34077. var cmapMappings = cmapTable.mappings;
  34078. var cmapMappingsLength = cmapMappings.length;
  34079. // The spec seems to imply that if the font is symbolic the encoding
  34080. // should be ignored, this doesn't appear to work for 'preistabelle.pdf'
  34081. // where the the font is symbolic and it has an encoding.
  34082. if (hasEncoding &&
  34083. (cmapPlatformId === 3 && cmapEncodingId === 1 ||
  34084. cmapPlatformId === 1 && cmapEncodingId === 0) ||
  34085. (cmapPlatformId === -1 && cmapEncodingId === -1 && // Temporary hack
  34086. !!getEncoding(properties.baseEncodingName))) { // Temporary hack
  34087. // When no preferred cmap table was found and |baseEncodingName| is
  34088. // one of the predefined encodings, we seem to obtain a better
  34089. // |charCodeToGlyphId| map from the code below (fixes bug 1057544).
  34090. // TODO: Note that this is a hack which should be removed as soon as
  34091. // we have proper support for more exotic cmap tables.
  34092. var baseEncoding = [];
  34093. if (properties.baseEncodingName === 'MacRomanEncoding' ||
  34094. properties.baseEncodingName === 'WinAnsiEncoding') {
  34095. baseEncoding = getEncoding(properties.baseEncodingName);
  34096. }
  34097. var glyphsUnicodeMap = getGlyphsUnicode();
  34098. for (charCode = 0; charCode < 256; charCode++) {
  34099. var glyphName, standardGlyphName;
  34100. if (this.differences && charCode in this.differences) {
  34101. glyphName = this.differences[charCode];
  34102. } else if (charCode in baseEncoding &&
  34103. baseEncoding[charCode] !== '') {
  34104. glyphName = baseEncoding[charCode];
  34105. } else {
  34106. glyphName = StandardEncoding[charCode];
  34107. }
  34108. if (!glyphName) {
  34109. continue;
  34110. }
  34111. // Ensure that non-standard glyph names are resolved to valid ones.
  34112. standardGlyphName = recoverGlyphName(glyphName, glyphsUnicodeMap);
  34113. var unicodeOrCharCode, isUnicode = false;
  34114. if (cmapPlatformId === 3 && cmapEncodingId === 1) {
  34115. unicodeOrCharCode = glyphsUnicodeMap[standardGlyphName];
  34116. isUnicode = true;
  34117. } else if (cmapPlatformId === 1 && cmapEncodingId === 0) {
  34118. // TODO: the encoding needs to be updated with mac os table.
  34119. unicodeOrCharCode = MacRomanEncoding.indexOf(standardGlyphName);
  34120. }
  34121. var found = false;
  34122. for (i = 0; i < cmapMappingsLength; ++i) {
  34123. if (cmapMappings[i].charCode !== unicodeOrCharCode) {
  34124. continue;
  34125. }
  34126. var code = isUnicode ? charCode : unicodeOrCharCode;
  34127. if (hasGlyph(cmapMappings[i].glyphId, code, -1)) {
  34128. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34129. found = true;
  34130. break;
  34131. }
  34132. }
  34133. if (!found && properties.glyphNames) {
  34134. // Try to map using the post table.
  34135. var glyphId = properties.glyphNames.indexOf(glyphName);
  34136. // The post table ought to use the same kind of glyph names as the
  34137. // `differences` array, but check the standard ones as a fallback.
  34138. if (glyphId === -1 && standardGlyphName !== glyphName) {
  34139. glyphId = properties.glyphNames.indexOf(standardGlyphName);
  34140. }
  34141. if (glyphId > 0 && hasGlyph(glyphId, -1, -1)) {
  34142. charCodeToGlyphId[charCode] = glyphId;
  34143. found = true;
  34144. }
  34145. }
  34146. if (!found) {
  34147. charCodeToGlyphId[charCode] = 0; // notdef
  34148. }
  34149. }
  34150. } else if (cmapPlatformId === 0 && cmapEncodingId === 0) {
  34151. // Default Unicode semantics, use the charcodes as is.
  34152. for (i = 0; i < cmapMappingsLength; ++i) {
  34153. charCodeToGlyphId[cmapMappings[i].charCode] =
  34154. cmapMappings[i].glyphId;
  34155. }
  34156. } else {
  34157. // For (3, 0) cmap tables:
  34158. // The charcode key being stored in charCodeToGlyphId is the lower
  34159. // byte of the two-byte charcodes of the cmap table since according to
  34160. // the spec: 'each byte from the string shall be prepended with the
  34161. // high byte of the range [of charcodes in the cmap table], to form
  34162. // a two-byte character, which shall be used to select the
  34163. // associated glyph description from the subtable'.
  34164. //
  34165. // For (1, 0) cmap tables:
  34166. // 'single bytes from the string shall be used to look up the
  34167. // associated glyph descriptions from the subtable'. This means
  34168. // charcodes in the cmap will be single bytes, so no-op since
  34169. // glyph.charCode & 0xFF === glyph.charCode
  34170. for (i = 0; i < cmapMappingsLength; ++i) {
  34171. charCode = cmapMappings[i].charCode & 0xFF;
  34172. charCodeToGlyphId[charCode] = cmapMappings[i].glyphId;
  34173. }
  34174. }
  34175. }
  34176. if (charCodeToGlyphId.length === 0) {
  34177. // defines at least one glyph
  34178. charCodeToGlyphId[0] = 0;
  34179. }
  34180. // Converting glyphs and ids into font's cmap table
  34181. var newMapping = adjustMapping(charCodeToGlyphId, properties);
  34182. this.toFontChar = newMapping.toFontChar;
  34183. tables['cmap'] = {
  34184. tag: 'cmap',
  34185. data: createCmapTable(newMapping.charCodeToGlyphId, numGlyphs)
  34186. };
  34187. if (!tables['OS/2'] || !validateOS2Table(tables['OS/2'])) {
  34188. tables['OS/2'] = {
  34189. tag: 'OS/2',
  34190. data: createOS2Table(properties, newMapping.charCodeToGlyphId,
  34191. metricsOverride)
  34192. };
  34193. }
  34194. // Rewrite the 'post' table if needed
  34195. if (!tables['post']) {
  34196. tables['post'] = {
  34197. tag: 'post',
  34198. data: createPostTable(properties)
  34199. };
  34200. }
  34201. if (!isTrueType) {
  34202. try {
  34203. // Trying to repair CFF file
  34204. cffFile = new Stream(tables['CFF '].data);
  34205. var parser = new CFFParser(cffFile, properties,
  34206. SEAC_ANALYSIS_ENABLED);
  34207. cff = parser.parse();
  34208. var compiler = new CFFCompiler(cff);
  34209. tables['CFF '].data = compiler.compile();
  34210. } catch (e) {
  34211. warn('Failed to compile font ' + properties.loadedName);
  34212. }
  34213. }
  34214. // Re-creating 'name' table
  34215. if (!tables['name']) {
  34216. tables['name'] = {
  34217. tag: 'name',
  34218. data: createNameTable(this.name)
  34219. };
  34220. } else {
  34221. // ... using existing 'name' table as prototype
  34222. var namePrototype = readNameTable(tables['name']);
  34223. tables['name'].data = createNameTable(name, namePrototype);
  34224. }
  34225. var builder = new OpenTypeFileBuilder(header.version);
  34226. for (var tableTag in tables) {
  34227. builder.addTable(tableTag, tables[tableTag].data);
  34228. }
  34229. return builder.toArray();
  34230. },
  34231. convert: function Font_convert(fontName, font, properties) {
  34232. // TODO: Check the charstring widths to determine this.
  34233. properties.fixedPitch = false;
  34234. var mapping = font.getGlyphMapping(properties);
  34235. var newMapping = adjustMapping(mapping, properties);
  34236. this.toFontChar = newMapping.toFontChar;
  34237. var numGlyphs = font.numGlyphs;
  34238. function getCharCodes(charCodeToGlyphId, glyphId) {
  34239. var charCodes = null;
  34240. for (var charCode in charCodeToGlyphId) {
  34241. if (glyphId === charCodeToGlyphId[charCode]) {
  34242. if (!charCodes) {
  34243. charCodes = [];
  34244. }
  34245. charCodes.push(charCode | 0);
  34246. }
  34247. }
  34248. return charCodes;
  34249. }
  34250. function createCharCode(charCodeToGlyphId, glyphId) {
  34251. for (var charCode in charCodeToGlyphId) {
  34252. if (glyphId === charCodeToGlyphId[charCode]) {
  34253. return charCode | 0;
  34254. }
  34255. }
  34256. newMapping.charCodeToGlyphId[newMapping.nextAvailableFontCharCode] =
  34257. glyphId;
  34258. return newMapping.nextAvailableFontCharCode++;
  34259. }
  34260. var seacs = font.seacs;
  34261. if (SEAC_ANALYSIS_ENABLED && seacs && seacs.length) {
  34262. var matrix = properties.fontMatrix || FONT_IDENTITY_MATRIX;
  34263. var charset = font.getCharset();
  34264. var seacMap = Object.create(null);
  34265. for (var glyphId in seacs) {
  34266. glyphId |= 0;
  34267. var seac = seacs[glyphId];
  34268. var baseGlyphName = StandardEncoding[seac[2]];
  34269. var accentGlyphName = StandardEncoding[seac[3]];
  34270. var baseGlyphId = charset.indexOf(baseGlyphName);
  34271. var accentGlyphId = charset.indexOf(accentGlyphName);
  34272. if (baseGlyphId < 0 || accentGlyphId < 0) {
  34273. continue;
  34274. }
  34275. var accentOffset = {
  34276. x: seac[0] * matrix[0] + seac[1] * matrix[2] + matrix[4],
  34277. y: seac[0] * matrix[1] + seac[1] * matrix[3] + matrix[5]
  34278. };
  34279. var charCodes = getCharCodes(mapping, glyphId);
  34280. if (!charCodes) {
  34281. // There's no point in mapping it if the char code was never mapped
  34282. // to begin with.
  34283. continue;
  34284. }
  34285. for (var i = 0, ii = charCodes.length; i < ii; i++) {
  34286. var charCode = charCodes[i];
  34287. // Find a fontCharCode that maps to the base and accent glyphs.
  34288. // If one doesn't exists, create it.
  34289. var charCodeToGlyphId = newMapping.charCodeToGlyphId;
  34290. var baseFontCharCode = createCharCode(charCodeToGlyphId,
  34291. baseGlyphId);
  34292. var accentFontCharCode = createCharCode(charCodeToGlyphId,
  34293. accentGlyphId);
  34294. seacMap[charCode] = {
  34295. baseFontCharCode: baseFontCharCode,
  34296. accentFontCharCode: accentFontCharCode,
  34297. accentOffset: accentOffset
  34298. };
  34299. }
  34300. }
  34301. properties.seacMap = seacMap;
  34302. }
  34303. var unitsPerEm = 1 / (properties.fontMatrix || FONT_IDENTITY_MATRIX)[0];
  34304. var builder = new OpenTypeFileBuilder('\x4F\x54\x54\x4F');
  34305. // PostScript Font Program
  34306. builder.addTable('CFF ', font.data);
  34307. // OS/2 and Windows Specific metrics
  34308. builder.addTable('OS/2', createOS2Table(properties,
  34309. newMapping.charCodeToGlyphId));
  34310. // Character to glyphs mapping
  34311. builder.addTable('cmap', createCmapTable(newMapping.charCodeToGlyphId,
  34312. numGlyphs));
  34313. // Font header
  34314. builder.addTable('head',
  34315. '\x00\x01\x00\x00' + // Version number
  34316. '\x00\x00\x10\x00' + // fontRevision
  34317. '\x00\x00\x00\x00' + // checksumAdjustement
  34318. '\x5F\x0F\x3C\xF5' + // magicNumber
  34319. '\x00\x00' + // Flags
  34320. safeString16(unitsPerEm) + // unitsPerEM
  34321. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // creation date
  34322. '\x00\x00\x00\x00\x9e\x0b\x7e\x27' + // modifification date
  34323. '\x00\x00' + // xMin
  34324. safeString16(properties.descent) + // yMin
  34325. '\x0F\xFF' + // xMax
  34326. safeString16(properties.ascent) + // yMax
  34327. string16(properties.italicAngle ? 2 : 0) + // macStyle
  34328. '\x00\x11' + // lowestRecPPEM
  34329. '\x00\x00' + // fontDirectionHint
  34330. '\x00\x00' + // indexToLocFormat
  34331. '\x00\x00'); // glyphDataFormat
  34332. // Horizontal header
  34333. builder.addTable('hhea',
  34334. '\x00\x01\x00\x00' + // Version number
  34335. safeString16(properties.ascent) + // Typographic Ascent
  34336. safeString16(properties.descent) + // Typographic Descent
  34337. '\x00\x00' + // Line Gap
  34338. '\xFF\xFF' + // advanceWidthMax
  34339. '\x00\x00' + // minLeftSidebearing
  34340. '\x00\x00' + // minRightSidebearing
  34341. '\x00\x00' + // xMaxExtent
  34342. safeString16(properties.capHeight) + // caretSlopeRise
  34343. safeString16(Math.tan(properties.italicAngle) *
  34344. properties.xHeight) + // caretSlopeRun
  34345. '\x00\x00' + // caretOffset
  34346. '\x00\x00' + // -reserved-
  34347. '\x00\x00' + // -reserved-
  34348. '\x00\x00' + // -reserved-
  34349. '\x00\x00' + // -reserved-
  34350. '\x00\x00' + // metricDataFormat
  34351. string16(numGlyphs)); // Number of HMetrics
  34352. // Horizontal metrics
  34353. builder.addTable('hmtx', (function fontFieldsHmtx() {
  34354. var charstrings = font.charstrings;
  34355. var cffWidths = font.cff ? font.cff.widths : null;
  34356. var hmtx = '\x00\x00\x00\x00'; // Fake .notdef
  34357. for (var i = 1, ii = numGlyphs; i < ii; i++) {
  34358. var width = 0;
  34359. if (charstrings) {
  34360. var charstring = charstrings[i - 1];
  34361. width = 'width' in charstring ? charstring.width : 0;
  34362. } else if (cffWidths) {
  34363. width = Math.ceil(cffWidths[i] || 0);
  34364. }
  34365. hmtx += string16(width) + string16(0);
  34366. }
  34367. return hmtx;
  34368. })());
  34369. // Maximum profile
  34370. builder.addTable('maxp',
  34371. '\x00\x00\x50\x00' + // Version number
  34372. string16(numGlyphs)); // Num of glyphs
  34373. // Naming tables
  34374. builder.addTable('name', createNameTable(fontName));
  34375. // PostScript informations
  34376. builder.addTable('post', createPostTable(properties));
  34377. return builder.toArray();
  34378. },
  34379. get spaceWidth() {
  34380. if ('_shadowWidth' in this) {
  34381. return this._shadowWidth;
  34382. }
  34383. // trying to estimate space character width
  34384. var possibleSpaceReplacements = ['space', 'minus', 'one', 'i'];
  34385. var width;
  34386. for (var i = 0, ii = possibleSpaceReplacements.length; i < ii; i++) {
  34387. var glyphName = possibleSpaceReplacements[i];
  34388. // if possible, getting width by glyph name
  34389. if (glyphName in this.widths) {
  34390. width = this.widths[glyphName];
  34391. break;
  34392. }
  34393. var glyphsUnicodeMap = getGlyphsUnicode();
  34394. var glyphUnicode = glyphsUnicodeMap[glyphName];
  34395. // finding the charcode via unicodeToCID map
  34396. var charcode = 0;
  34397. if (this.composite) {
  34398. if (this.cMap.contains(glyphUnicode)) {
  34399. charcode = this.cMap.lookup(glyphUnicode);
  34400. }
  34401. }
  34402. // ... via toUnicode map
  34403. if (!charcode && this.toUnicode) {
  34404. charcode = this.toUnicode.charCodeOf(glyphUnicode);
  34405. }
  34406. // setting it to unicode if negative or undefined
  34407. if (charcode <= 0) {
  34408. charcode = glyphUnicode;
  34409. }
  34410. // trying to get width via charcode
  34411. width = this.widths[charcode];
  34412. if (width) {
  34413. break; // the non-zero width found
  34414. }
  34415. }
  34416. width = width || this.defaultWidth;
  34417. // Do not shadow the property here. See discussion:
  34418. // https://github.com/mozilla/pdf.js/pull/2127#discussion_r1662280
  34419. this._shadowWidth = width;
  34420. return width;
  34421. },
  34422. charToGlyph: function Font_charToGlyph(charcode, isSpace) {
  34423. var fontCharCode, width, operatorListId;
  34424. var widthCode = charcode;
  34425. if (this.cMap && this.cMap.contains(charcode)) {
  34426. widthCode = this.cMap.lookup(charcode);
  34427. }
  34428. width = this.widths[widthCode];
  34429. width = isNum(width) ? width : this.defaultWidth;
  34430. var vmetric = this.vmetrics && this.vmetrics[widthCode];
  34431. var unicode = this.toUnicode.get(charcode) || charcode;
  34432. if (typeof unicode === 'number') {
  34433. unicode = String.fromCharCode(unicode);
  34434. }
  34435. var isInFont = charcode in this.toFontChar;
  34436. // First try the toFontChar map, if it's not there then try falling
  34437. // back to the char code.
  34438. fontCharCode = this.toFontChar[charcode] || charcode;
  34439. if (this.missingFile) {
  34440. fontCharCode = mapSpecialUnicodeValues(fontCharCode);
  34441. }
  34442. if (this.isType3Font) {
  34443. // Font char code in this case is actually a glyph name.
  34444. operatorListId = fontCharCode;
  34445. }
  34446. var accent = null;
  34447. if (this.seacMap && this.seacMap[charcode]) {
  34448. isInFont = true;
  34449. var seac = this.seacMap[charcode];
  34450. fontCharCode = seac.baseFontCharCode;
  34451. accent = {
  34452. fontChar: String.fromCharCode(seac.accentFontCharCode),
  34453. offset: seac.accentOffset
  34454. };
  34455. }
  34456. var fontChar = String.fromCharCode(fontCharCode);
  34457. var glyph = this.glyphCache[charcode];
  34458. if (!glyph ||
  34459. !glyph.matchesForCache(fontChar, unicode, accent, width, vmetric,
  34460. operatorListId, isSpace, isInFont)) {
  34461. glyph = new Glyph(fontChar, unicode, accent, width, vmetric,
  34462. operatorListId, isSpace, isInFont);
  34463. this.glyphCache[charcode] = glyph;
  34464. }
  34465. return glyph;
  34466. },
  34467. charsToGlyphs: function Font_charsToGlyphs(chars) {
  34468. var charsCache = this.charsCache;
  34469. var glyphs, glyph, charcode;
  34470. // if we translated this string before, just grab it from the cache
  34471. if (charsCache) {
  34472. glyphs = charsCache[chars];
  34473. if (glyphs) {
  34474. return glyphs;
  34475. }
  34476. }
  34477. // lazily create the translation cache
  34478. if (!charsCache) {
  34479. charsCache = this.charsCache = Object.create(null);
  34480. }
  34481. glyphs = [];
  34482. var charsCacheKey = chars;
  34483. var i = 0, ii;
  34484. if (this.cMap) {
  34485. // composite fonts have multi-byte strings convert the string from
  34486. // single-byte to multi-byte
  34487. var c = Object.create(null);
  34488. while (i < chars.length) {
  34489. this.cMap.readCharCode(chars, i, c);
  34490. charcode = c.charcode;
  34491. var length = c.length;
  34492. i += length;
  34493. // Space is char with code 0x20 and length 1 in multiple-byte codes.
  34494. var isSpace = length === 1 && chars.charCodeAt(i - 1) === 0x20;
  34495. glyph = this.charToGlyph(charcode, isSpace);
  34496. glyphs.push(glyph);
  34497. }
  34498. } else {
  34499. for (i = 0, ii = chars.length; i < ii; ++i) {
  34500. charcode = chars.charCodeAt(i);
  34501. glyph = this.charToGlyph(charcode, charcode === 0x20);
  34502. glyphs.push(glyph);
  34503. }
  34504. }
  34505. // Enter the translated string into the cache
  34506. return (charsCache[charsCacheKey] = glyphs);
  34507. }
  34508. };
  34509. return Font;
  34510. })();
  34511. var ErrorFont = (function ErrorFontClosure() {
  34512. function ErrorFont(error) {
  34513. this.error = error;
  34514. this.loadedName = 'g_font_error';
  34515. this.loading = false;
  34516. }
  34517. ErrorFont.prototype = {
  34518. charsToGlyphs: function ErrorFont_charsToGlyphs() {
  34519. return [];
  34520. },
  34521. exportData: function ErrorFont_exportData() {
  34522. return {error: this.error};
  34523. }
  34524. };
  34525. return ErrorFont;
  34526. })();
  34527. /**
  34528. * Shared logic for building a char code to glyph id mapping for Type1 and
  34529. * simple CFF fonts. See section 9.6.6.2 of the spec.
  34530. * @param {Object} properties Font properties object.
  34531. * @param {Object} builtInEncoding The encoding contained within the actual font
  34532. * data.
  34533. * @param {Array} Array of glyph names where the index is the glyph ID.
  34534. * @returns {Object} A char code to glyph ID map.
  34535. */
  34536. function type1FontGlyphMapping(properties, builtInEncoding, glyphNames) {
  34537. var charCodeToGlyphId = Object.create(null);
  34538. var glyphId, charCode, baseEncoding;
  34539. if (properties.baseEncodingName) {
  34540. // If a valid base encoding name was used, the mapping is initialized with
  34541. // that.
  34542. baseEncoding = getEncoding(properties.baseEncodingName);
  34543. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34544. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34545. if (glyphId >= 0) {
  34546. charCodeToGlyphId[charCode] = glyphId;
  34547. } else {
  34548. charCodeToGlyphId[charCode] = 0; // notdef
  34549. }
  34550. }
  34551. } else if (!!(properties.flags & FontFlags.Symbolic)) {
  34552. // For a symbolic font the encoding should be the fonts built-in
  34553. // encoding.
  34554. for (charCode in builtInEncoding) {
  34555. charCodeToGlyphId[charCode] = builtInEncoding[charCode];
  34556. }
  34557. } else {
  34558. // For non-symbolic fonts that don't have a base encoding the standard
  34559. // encoding should be used.
  34560. baseEncoding = StandardEncoding;
  34561. for (charCode = 0; charCode < baseEncoding.length; charCode++) {
  34562. glyphId = glyphNames.indexOf(baseEncoding[charCode]);
  34563. if (glyphId >= 0) {
  34564. charCodeToGlyphId[charCode] = glyphId;
  34565. } else {
  34566. charCodeToGlyphId[charCode] = 0; // notdef
  34567. }
  34568. }
  34569. }
  34570. // Lastly, merge in the differences.
  34571. var differences = properties.differences;
  34572. if (differences) {
  34573. for (charCode in differences) {
  34574. var glyphName = differences[charCode];
  34575. glyphId = glyphNames.indexOf(glyphName);
  34576. if (glyphId >= 0) {
  34577. charCodeToGlyphId[charCode] = glyphId;
  34578. } else {
  34579. charCodeToGlyphId[charCode] = 0; // notdef
  34580. }
  34581. }
  34582. }
  34583. return charCodeToGlyphId;
  34584. }
  34585. // Type1Font is also a CIDFontType0.
  34586. var Type1Font = (function Type1FontClosure() {
  34587. function findBlock(streamBytes, signature, startIndex) {
  34588. var streamBytesLength = streamBytes.length;
  34589. var signatureLength = signature.length;
  34590. var scanLength = streamBytesLength - signatureLength;
  34591. var i = startIndex, j, found = false;
  34592. while (i < scanLength) {
  34593. j = 0;
  34594. while (j < signatureLength && streamBytes[i + j] === signature[j]) {
  34595. j++;
  34596. }
  34597. if (j >= signatureLength) { // `signature` found, skip over whitespace.
  34598. i += j;
  34599. while (i < streamBytesLength && Lexer.isSpace(streamBytes[i])) {
  34600. i++;
  34601. }
  34602. found = true;
  34603. break;
  34604. }
  34605. i++;
  34606. }
  34607. return {
  34608. found: found,
  34609. length: i,
  34610. };
  34611. }
  34612. function getHeaderBlock(stream, suggestedLength) {
  34613. var EEXEC_SIGNATURE = [0x65, 0x65, 0x78, 0x65, 0x63];
  34614. var streamStartPos = stream.pos; // Save the initial stream position.
  34615. var headerBytes, headerBytesLength, block;
  34616. try {
  34617. headerBytes = stream.getBytes(suggestedLength);
  34618. headerBytesLength = headerBytes.length;
  34619. } catch (ex) {
  34620. if (ex instanceof MissingDataException) {
  34621. throw ex;
  34622. }
  34623. // Ignore errors if the `suggestedLength` is huge enough that a Uint8Array
  34624. // cannot hold the result of `getBytes`, and fallback to simply checking
  34625. // the entire stream (fixes issue3928.pdf).
  34626. }
  34627. if (headerBytesLength === suggestedLength) {
  34628. // Most of the time `suggestedLength` is correct, so to speed things up we
  34629. // initially only check the last few bytes to see if the header was found.
  34630. // Otherwise we (potentially) check the entire stream to prevent errors in
  34631. // `Type1Parser` (fixes issue5686.pdf).
  34632. block = findBlock(headerBytes, EEXEC_SIGNATURE,
  34633. suggestedLength - 2 * EEXEC_SIGNATURE.length);
  34634. if (block.found && block.length === suggestedLength) {
  34635. return {
  34636. stream: new Stream(headerBytes),
  34637. length: suggestedLength,
  34638. };
  34639. }
  34640. }
  34641. warn('Invalid "Length1" property in Type1 font -- trying to recover.');
  34642. stream.pos = streamStartPos; // Reset the stream position.
  34643. var SCAN_BLOCK_LENGTH = 2048;
  34644. var actualLength;
  34645. while (true) {
  34646. var scanBytes = stream.peekBytes(SCAN_BLOCK_LENGTH);
  34647. block = findBlock(scanBytes, EEXEC_SIGNATURE, 0);
  34648. if (block.length === 0) {
  34649. break;
  34650. }
  34651. stream.pos += block.length; // Update the stream position.
  34652. if (block.found) {
  34653. actualLength = stream.pos - streamStartPos;
  34654. break;
  34655. }
  34656. }
  34657. stream.pos = streamStartPos; // Reset the stream position.
  34658. if (actualLength) {
  34659. return {
  34660. stream: new Stream(stream.getBytes(actualLength)),
  34661. length: actualLength,
  34662. };
  34663. }
  34664. warn('Unable to recover "Length1" property in Type1 font -- using as is.');
  34665. return {
  34666. stream: new Stream(stream.getBytes(suggestedLength)),
  34667. length: suggestedLength,
  34668. };
  34669. }
  34670. function getEexecBlock(stream, suggestedLength) {
  34671. // We should ideally parse the eexec block to ensure that `suggestedLength`
  34672. // is correct, so we don't truncate the block data if it's too small.
  34673. // However, this would also require checking if the fixed-content portion
  34674. // exists (using the 'Length3' property), and ensuring that it's valid.
  34675. //
  34676. // Given that `suggestedLength` almost always is correct, all the validation
  34677. // would require a great deal of unnecessary parsing for most fonts.
  34678. // To save time, we always fetch the entire stream instead, which also avoid
  34679. // issues if `suggestedLength` is huge (see comment in `getHeaderBlock`).
  34680. //
  34681. // NOTE: This means that the function can include the fixed-content portion
  34682. // in the returned eexec block. In practice this does *not* seem to matter,
  34683. // since `Type1Parser_extractFontProgram` will skip over any non-commands.
  34684. var eexecBytes = stream.getBytes();
  34685. return {
  34686. stream: new Stream(eexecBytes),
  34687. length: eexecBytes.length,
  34688. };
  34689. }
  34690. function Type1Font(name, file, properties) {
  34691. // Some bad generators embed pfb file as is, we have to strip 6-byte header.
  34692. // Also, length1 and length2 might be off by 6 bytes as well.
  34693. // http://www.math.ubc.ca/~cass/piscript/type1.pdf
  34694. var PFB_HEADER_SIZE = 6;
  34695. var headerBlockLength = properties.length1;
  34696. var eexecBlockLength = properties.length2;
  34697. var pfbHeader = file.peekBytes(PFB_HEADER_SIZE);
  34698. var pfbHeaderPresent = pfbHeader[0] === 0x80 && pfbHeader[1] === 0x01;
  34699. if (pfbHeaderPresent) {
  34700. file.skip(PFB_HEADER_SIZE);
  34701. headerBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  34702. (pfbHeader[3] << 8) | pfbHeader[2];
  34703. }
  34704. // Get the data block containing glyphs and subrs informations
  34705. var headerBlock = getHeaderBlock(file, headerBlockLength);
  34706. headerBlockLength = headerBlock.length;
  34707. var headerBlockParser = new Type1Parser(headerBlock.stream, false,
  34708. SEAC_ANALYSIS_ENABLED);
  34709. headerBlockParser.extractFontHeader(properties);
  34710. if (pfbHeaderPresent) {
  34711. pfbHeader = file.getBytes(PFB_HEADER_SIZE);
  34712. eexecBlockLength = (pfbHeader[5] << 24) | (pfbHeader[4] << 16) |
  34713. (pfbHeader[3] << 8) | pfbHeader[2];
  34714. }
  34715. // Decrypt the data blocks and retrieve it's content
  34716. var eexecBlock = getEexecBlock(file, eexecBlockLength);
  34717. eexecBlockLength = eexecBlock.length;
  34718. var eexecBlockParser = new Type1Parser(eexecBlock.stream, true,
  34719. SEAC_ANALYSIS_ENABLED);
  34720. var data = eexecBlockParser.extractFontProgram();
  34721. for (var info in data.properties) {
  34722. properties[info] = data.properties[info];
  34723. }
  34724. var charstrings = data.charstrings;
  34725. var type2Charstrings = this.getType2Charstrings(charstrings);
  34726. var subrs = this.getType2Subrs(data.subrs);
  34727. this.charstrings = charstrings;
  34728. this.data = this.wrap(name, type2Charstrings, this.charstrings,
  34729. subrs, properties);
  34730. this.seacs = this.getSeacs(data.charstrings);
  34731. }
  34732. Type1Font.prototype = {
  34733. get numGlyphs() {
  34734. return this.charstrings.length + 1;
  34735. },
  34736. getCharset: function Type1Font_getCharset() {
  34737. var charset = ['.notdef'];
  34738. var charstrings = this.charstrings;
  34739. for (var glyphId = 0; glyphId < charstrings.length; glyphId++) {
  34740. charset.push(charstrings[glyphId].glyphName);
  34741. }
  34742. return charset;
  34743. },
  34744. getGlyphMapping: function Type1Font_getGlyphMapping(properties) {
  34745. var charstrings = this.charstrings;
  34746. var glyphNames = ['.notdef'], glyphId;
  34747. for (glyphId = 0; glyphId < charstrings.length; glyphId++) {
  34748. glyphNames.push(charstrings[glyphId].glyphName);
  34749. }
  34750. var encoding = properties.builtInEncoding;
  34751. if (encoding) {
  34752. var builtInEncoding = Object.create(null);
  34753. for (var charCode in encoding) {
  34754. glyphId = glyphNames.indexOf(encoding[charCode]);
  34755. if (glyphId >= 0) {
  34756. builtInEncoding[charCode] = glyphId;
  34757. }
  34758. }
  34759. }
  34760. return type1FontGlyphMapping(properties, builtInEncoding, glyphNames);
  34761. },
  34762. getSeacs: function Type1Font_getSeacs(charstrings) {
  34763. var i, ii;
  34764. var seacMap = [];
  34765. for (i = 0, ii = charstrings.length; i < ii; i++) {
  34766. var charstring = charstrings[i];
  34767. if (charstring.seac) {
  34768. // Offset by 1 for .notdef
  34769. seacMap[i + 1] = charstring.seac;
  34770. }
  34771. }
  34772. return seacMap;
  34773. },
  34774. getType2Charstrings: function Type1Font_getType2Charstrings(
  34775. type1Charstrings) {
  34776. var type2Charstrings = [];
  34777. for (var i = 0, ii = type1Charstrings.length; i < ii; i++) {
  34778. type2Charstrings.push(type1Charstrings[i].charstring);
  34779. }
  34780. return type2Charstrings;
  34781. },
  34782. getType2Subrs: function Type1Font_getType2Subrs(type1Subrs) {
  34783. var bias = 0;
  34784. var count = type1Subrs.length;
  34785. if (count < 1133) {
  34786. bias = 107;
  34787. } else if (count < 33769) {
  34788. bias = 1131;
  34789. } else {
  34790. bias = 32768;
  34791. }
  34792. // Add a bunch of empty subrs to deal with the Type2 bias
  34793. var type2Subrs = [];
  34794. var i;
  34795. for (i = 0; i < bias; i++) {
  34796. type2Subrs.push([0x0B]);
  34797. }
  34798. for (i = 0; i < count; i++) {
  34799. type2Subrs.push(type1Subrs[i]);
  34800. }
  34801. return type2Subrs;
  34802. },
  34803. wrap: function Type1Font_wrap(name, glyphs, charstrings, subrs,
  34804. properties) {
  34805. var cff = new CFF();
  34806. cff.header = new CFFHeader(1, 0, 4, 4);
  34807. cff.names = [name];
  34808. var topDict = new CFFTopDict();
  34809. // CFF strings IDs 0...390 are predefined names, so refering
  34810. // to entries in our own String INDEX starts at SID 391.
  34811. topDict.setByName('version', 391);
  34812. topDict.setByName('Notice', 392);
  34813. topDict.setByName('FullName', 393);
  34814. topDict.setByName('FamilyName', 394);
  34815. topDict.setByName('Weight', 395);
  34816. topDict.setByName('Encoding', null); // placeholder
  34817. topDict.setByName('FontMatrix', properties.fontMatrix);
  34818. topDict.setByName('FontBBox', properties.bbox);
  34819. topDict.setByName('charset', null); // placeholder
  34820. topDict.setByName('CharStrings', null); // placeholder
  34821. topDict.setByName('Private', null); // placeholder
  34822. cff.topDict = topDict;
  34823. var strings = new CFFStrings();
  34824. strings.add('Version 0.11'); // Version
  34825. strings.add('See original notice'); // Notice
  34826. strings.add(name); // FullName
  34827. strings.add(name); // FamilyName
  34828. strings.add('Medium'); // Weight
  34829. cff.strings = strings;
  34830. cff.globalSubrIndex = new CFFIndex();
  34831. var count = glyphs.length;
  34832. var charsetArray = [0];
  34833. var i, ii;
  34834. for (i = 0; i < count; i++) {
  34835. var index = CFFStandardStrings.indexOf(charstrings[i].glyphName);
  34836. // TODO: Insert the string and correctly map it. Previously it was
  34837. // thought mapping names that aren't in the standard strings to .notdef
  34838. // was fine, however in issue818 when mapping them all to .notdef the
  34839. // adieresis glyph no longer worked.
  34840. if (index === -1) {
  34841. index = 0;
  34842. }
  34843. charsetArray.push((index >> 8) & 0xff, index & 0xff);
  34844. }
  34845. cff.charset = new CFFCharset(false, 0, [], charsetArray);
  34846. var charStringsIndex = new CFFIndex();
  34847. charStringsIndex.add([0x8B, 0x0E]); // .notdef
  34848. for (i = 0; i < count; i++) {
  34849. charStringsIndex.add(glyphs[i]);
  34850. }
  34851. cff.charStrings = charStringsIndex;
  34852. var privateDict = new CFFPrivateDict();
  34853. privateDict.setByName('Subrs', null); // placeholder
  34854. var fields = [
  34855. 'BlueValues',
  34856. 'OtherBlues',
  34857. 'FamilyBlues',
  34858. 'FamilyOtherBlues',
  34859. 'StemSnapH',
  34860. 'StemSnapV',
  34861. 'BlueShift',
  34862. 'BlueFuzz',
  34863. 'BlueScale',
  34864. 'LanguageGroup',
  34865. 'ExpansionFactor',
  34866. 'ForceBold',
  34867. 'StdHW',
  34868. 'StdVW'
  34869. ];
  34870. for (i = 0, ii = fields.length; i < ii; i++) {
  34871. var field = fields[i];
  34872. if (!(field in properties.privateData)) {
  34873. continue;
  34874. }
  34875. var value = properties.privateData[field];
  34876. if (isArray(value)) {
  34877. // All of the private dictionary array data in CFF must be stored as
  34878. // "delta-encoded" numbers.
  34879. for (var j = value.length - 1; j > 0; j--) {
  34880. value[j] -= value[j - 1]; // ... difference from previous value
  34881. }
  34882. }
  34883. privateDict.setByName(field, value);
  34884. }
  34885. cff.topDict.privateDict = privateDict;
  34886. var subrIndex = new CFFIndex();
  34887. for (i = 0, ii = subrs.length; i < ii; i++) {
  34888. subrIndex.add(subrs[i]);
  34889. }
  34890. privateDict.subrsIndex = subrIndex;
  34891. var compiler = new CFFCompiler(cff);
  34892. return compiler.compile();
  34893. }
  34894. };
  34895. return Type1Font;
  34896. })();
  34897. var CFFFont = (function CFFFontClosure() {
  34898. function CFFFont(file, properties) {
  34899. this.properties = properties;
  34900. var parser = new CFFParser(file, properties, SEAC_ANALYSIS_ENABLED);
  34901. this.cff = parser.parse();
  34902. var compiler = new CFFCompiler(this.cff);
  34903. this.seacs = this.cff.seacs;
  34904. try {
  34905. this.data = compiler.compile();
  34906. } catch (e) {
  34907. warn('Failed to compile font ' + properties.loadedName);
  34908. // There may have just been an issue with the compiler, set the data
  34909. // anyway and hope the font loaded.
  34910. this.data = file;
  34911. }
  34912. }
  34913. CFFFont.prototype = {
  34914. get numGlyphs() {
  34915. return this.cff.charStrings.count;
  34916. },
  34917. getCharset: function CFFFont_getCharset() {
  34918. return this.cff.charset.charset;
  34919. },
  34920. getGlyphMapping: function CFFFont_getGlyphMapping() {
  34921. var cff = this.cff;
  34922. var properties = this.properties;
  34923. var charsets = cff.charset.charset;
  34924. var charCodeToGlyphId;
  34925. var glyphId;
  34926. if (properties.composite) {
  34927. charCodeToGlyphId = Object.create(null);
  34928. if (cff.isCIDFont) {
  34929. // If the font is actually a CID font then we should use the charset
  34930. // to map CIDs to GIDs.
  34931. for (glyphId = 0; glyphId < charsets.length; glyphId++) {
  34932. var cid = charsets[glyphId];
  34933. var charCode = properties.cMap.charCodeOf(cid);
  34934. charCodeToGlyphId[charCode] = glyphId;
  34935. }
  34936. } else {
  34937. // If it is NOT actually a CID font then CIDs should be mapped
  34938. // directly to GIDs.
  34939. for (glyphId = 0; glyphId < cff.charStrings.count; glyphId++) {
  34940. charCodeToGlyphId[glyphId] = glyphId;
  34941. }
  34942. }
  34943. return charCodeToGlyphId;
  34944. }
  34945. var encoding = cff.encoding ? cff.encoding.encoding : null;
  34946. charCodeToGlyphId = type1FontGlyphMapping(properties, encoding, charsets);
  34947. return charCodeToGlyphId;
  34948. }
  34949. };
  34950. return CFFFont;
  34951. })();
  34952. // Workaround for seac on Windows.
  34953. (function checkSeacSupport() {
  34954. if (typeof navigator !== 'undefined' && /Windows/.test(navigator.userAgent)) {
  34955. SEAC_ANALYSIS_ENABLED = true;
  34956. }
  34957. })();
  34958. // Workaround for Private Use Area characters in Chrome on Windows
  34959. // http://code.google.com/p/chromium/issues/detail?id=122465
  34960. // https://github.com/mozilla/pdf.js/issues/1689
  34961. (function checkChromeWindows() {
  34962. if (typeof navigator !== 'undefined' &&
  34963. /Windows.*Chrome/.test(navigator.userAgent)) {
  34964. SKIP_PRIVATE_USE_RANGE_F000_TO_F01F = true;
  34965. }
  34966. })();
  34967. exports.SEAC_ANALYSIS_ENABLED = SEAC_ANALYSIS_ENABLED;
  34968. exports.ErrorFont = ErrorFont;
  34969. exports.Font = Font;
  34970. exports.FontFlags = FontFlags;
  34971. exports.IdentityToUnicodeMap = IdentityToUnicodeMap;
  34972. exports.ToUnicodeMap = ToUnicodeMap;
  34973. exports.getFontType = getFontType;
  34974. }));
  34975. (function (root, factory) {
  34976. {
  34977. factory((root.pdfjsCoreFunction = {}), root.pdfjsSharedUtil,
  34978. root.pdfjsCorePrimitives, root.pdfjsCorePsParser);
  34979. }
  34980. }(this, function (exports, sharedUtil, corePrimitives, corePsParser) {
  34981. var error = sharedUtil.error;
  34982. var info = sharedUtil.info;
  34983. var isArray = sharedUtil.isArray;
  34984. var isBool = sharedUtil.isBool;
  34985. var isDict = corePrimitives.isDict;
  34986. var isStream = corePrimitives.isStream;
  34987. var PostScriptLexer = corePsParser.PostScriptLexer;
  34988. var PostScriptParser = corePsParser.PostScriptParser;
  34989. var PDFFunction = (function PDFFunctionClosure() {
  34990. var CONSTRUCT_SAMPLED = 0;
  34991. var CONSTRUCT_INTERPOLATED = 2;
  34992. var CONSTRUCT_STICHED = 3;
  34993. var CONSTRUCT_POSTSCRIPT = 4;
  34994. return {
  34995. getSampleArray: function PDFFunction_getSampleArray(size, outputSize, bps,
  34996. str) {
  34997. var i, ii;
  34998. var length = 1;
  34999. for (i = 0, ii = size.length; i < ii; i++) {
  35000. length *= size[i];
  35001. }
  35002. length *= outputSize;
  35003. var array = new Array(length);
  35004. var codeSize = 0;
  35005. var codeBuf = 0;
  35006. // 32 is a valid bps so shifting won't work
  35007. var sampleMul = 1.0 / (Math.pow(2.0, bps) - 1);
  35008. var strBytes = str.getBytes((length * bps + 7) / 8);
  35009. var strIdx = 0;
  35010. for (i = 0; i < length; i++) {
  35011. while (codeSize < bps) {
  35012. codeBuf <<= 8;
  35013. codeBuf |= strBytes[strIdx++];
  35014. codeSize += 8;
  35015. }
  35016. codeSize -= bps;
  35017. array[i] = (codeBuf >> codeSize) * sampleMul;
  35018. codeBuf &= (1 << codeSize) - 1;
  35019. }
  35020. return array;
  35021. },
  35022. getIR: function PDFFunction_getIR(xref, fn) {
  35023. var dict = fn.dict;
  35024. if (!dict) {
  35025. dict = fn;
  35026. }
  35027. var types = [this.constructSampled,
  35028. null,
  35029. this.constructInterpolated,
  35030. this.constructStiched,
  35031. this.constructPostScript];
  35032. var typeNum = dict.get('FunctionType');
  35033. var typeFn = types[typeNum];
  35034. if (!typeFn) {
  35035. error('Unknown type of function');
  35036. }
  35037. return typeFn.call(this, fn, dict, xref);
  35038. },
  35039. fromIR: function PDFFunction_fromIR(IR) {
  35040. var type = IR[0];
  35041. switch (type) {
  35042. case CONSTRUCT_SAMPLED:
  35043. return this.constructSampledFromIR(IR);
  35044. case CONSTRUCT_INTERPOLATED:
  35045. return this.constructInterpolatedFromIR(IR);
  35046. case CONSTRUCT_STICHED:
  35047. return this.constructStichedFromIR(IR);
  35048. //case CONSTRUCT_POSTSCRIPT:
  35049. default:
  35050. return this.constructPostScriptFromIR(IR);
  35051. }
  35052. },
  35053. parse: function PDFFunction_parse(xref, fn) {
  35054. var IR = this.getIR(xref, fn);
  35055. return this.fromIR(IR);
  35056. },
  35057. parseArray: function PDFFunction_parseArray(xref, fnObj) {
  35058. if (!isArray(fnObj)) {
  35059. // not an array -- parsing as regular function
  35060. return this.parse(xref, fnObj);
  35061. }
  35062. var fnArray = [];
  35063. for (var j = 0, jj = fnObj.length; j < jj; j++) {
  35064. var obj = xref.fetchIfRef(fnObj[j]);
  35065. fnArray.push(PDFFunction.parse(xref, obj));
  35066. }
  35067. return function (src, srcOffset, dest, destOffset) {
  35068. for (var i = 0, ii = fnArray.length; i < ii; i++) {
  35069. fnArray[i](src, srcOffset, dest, destOffset + i);
  35070. }
  35071. };
  35072. },
  35073. constructSampled: function PDFFunction_constructSampled(str, dict) {
  35074. function toMultiArray(arr) {
  35075. var inputLength = arr.length;
  35076. var out = [];
  35077. var index = 0;
  35078. for (var i = 0; i < inputLength; i += 2) {
  35079. out[index] = [arr[i], arr[i + 1]];
  35080. ++index;
  35081. }
  35082. return out;
  35083. }
  35084. var domain = dict.get('Domain');
  35085. var range = dict.get('Range');
  35086. if (!domain || !range) {
  35087. error('No domain or range');
  35088. }
  35089. var inputSize = domain.length / 2;
  35090. var outputSize = range.length / 2;
  35091. domain = toMultiArray(domain);
  35092. range = toMultiArray(range);
  35093. var size = dict.get('Size');
  35094. var bps = dict.get('BitsPerSample');
  35095. var order = dict.get('Order') || 1;
  35096. if (order !== 1) {
  35097. // No description how cubic spline interpolation works in PDF32000:2008
  35098. // As in poppler, ignoring order, linear interpolation may work as good
  35099. info('No support for cubic spline interpolation: ' + order);
  35100. }
  35101. var encode = dict.get('Encode');
  35102. if (!encode) {
  35103. encode = [];
  35104. for (var i = 0; i < inputSize; ++i) {
  35105. encode.push(0);
  35106. encode.push(size[i] - 1);
  35107. }
  35108. }
  35109. encode = toMultiArray(encode);
  35110. var decode = dict.get('Decode');
  35111. if (!decode) {
  35112. decode = range;
  35113. } else {
  35114. decode = toMultiArray(decode);
  35115. }
  35116. var samples = this.getSampleArray(size, outputSize, bps, str);
  35117. return [
  35118. CONSTRUCT_SAMPLED, inputSize, domain, encode, decode, samples, size,
  35119. outputSize, Math.pow(2, bps) - 1, range
  35120. ];
  35121. },
  35122. constructSampledFromIR: function PDFFunction_constructSampledFromIR(IR) {
  35123. // See chapter 3, page 109 of the PDF reference
  35124. function interpolate(x, xmin, xmax, ymin, ymax) {
  35125. return ymin + ((x - xmin) * ((ymax - ymin) / (xmax - xmin)));
  35126. }
  35127. return function constructSampledFromIRResult(src, srcOffset,
  35128. dest, destOffset) {
  35129. // See chapter 3, page 110 of the PDF reference.
  35130. var m = IR[1];
  35131. var domain = IR[2];
  35132. var encode = IR[3];
  35133. var decode = IR[4];
  35134. var samples = IR[5];
  35135. var size = IR[6];
  35136. var n = IR[7];
  35137. //var mask = IR[8];
  35138. var range = IR[9];
  35139. // Building the cube vertices: its part and sample index
  35140. // http://rjwagner49.com/Mathematics/Interpolation.pdf
  35141. var cubeVertices = 1 << m;
  35142. var cubeN = new Float64Array(cubeVertices);
  35143. var cubeVertex = new Uint32Array(cubeVertices);
  35144. var i, j;
  35145. for (j = 0; j < cubeVertices; j++) {
  35146. cubeN[j] = 1;
  35147. }
  35148. var k = n, pos = 1;
  35149. // Map x_i to y_j for 0 <= i < m using the sampled function.
  35150. for (i = 0; i < m; ++i) {
  35151. // x_i' = min(max(x_i, Domain_2i), Domain_2i+1)
  35152. var domain_2i = domain[i][0];
  35153. var domain_2i_1 = domain[i][1];
  35154. var xi = Math.min(Math.max(src[srcOffset +i], domain_2i),
  35155. domain_2i_1);
  35156. // e_i = Interpolate(x_i', Domain_2i, Domain_2i+1,
  35157. // Encode_2i, Encode_2i+1)
  35158. var e = interpolate(xi, domain_2i, domain_2i_1,
  35159. encode[i][0], encode[i][1]);
  35160. // e_i' = min(max(e_i, 0), Size_i - 1)
  35161. var size_i = size[i];
  35162. e = Math.min(Math.max(e, 0), size_i - 1);
  35163. // Adjusting the cube: N and vertex sample index
  35164. var e0 = e < size_i - 1 ? Math.floor(e) : e - 1; // e1 = e0 + 1;
  35165. var n0 = e0 + 1 - e; // (e1 - e) / (e1 - e0);
  35166. var n1 = e - e0; // (e - e0) / (e1 - e0);
  35167. var offset0 = e0 * k;
  35168. var offset1 = offset0 + k; // e1 * k
  35169. for (j = 0; j < cubeVertices; j++) {
  35170. if (j & pos) {
  35171. cubeN[j] *= n1;
  35172. cubeVertex[j] += offset1;
  35173. } else {
  35174. cubeN[j] *= n0;
  35175. cubeVertex[j] += offset0;
  35176. }
  35177. }
  35178. k *= size_i;
  35179. pos <<= 1;
  35180. }
  35181. for (j = 0; j < n; ++j) {
  35182. // Sum all cube vertices' samples portions
  35183. var rj = 0;
  35184. for (i = 0; i < cubeVertices; i++) {
  35185. rj += samples[cubeVertex[i] + j] * cubeN[i];
  35186. }
  35187. // r_j' = Interpolate(r_j, 0, 2^BitsPerSample - 1,
  35188. // Decode_2j, Decode_2j+1)
  35189. rj = interpolate(rj, 0, 1, decode[j][0], decode[j][1]);
  35190. // y_j = min(max(r_j, range_2j), range_2j+1)
  35191. dest[destOffset + j] = Math.min(Math.max(rj, range[j][0]),
  35192. range[j][1]);
  35193. }
  35194. };
  35195. },
  35196. constructInterpolated: function PDFFunction_constructInterpolated(str,
  35197. dict) {
  35198. var c0 = dict.get('C0') || [0];
  35199. var c1 = dict.get('C1') || [1];
  35200. var n = dict.get('N');
  35201. if (!isArray(c0) || !isArray(c1)) {
  35202. error('Illegal dictionary for interpolated function');
  35203. }
  35204. var length = c0.length;
  35205. var diff = [];
  35206. for (var i = 0; i < length; ++i) {
  35207. diff.push(c1[i] - c0[i]);
  35208. }
  35209. return [CONSTRUCT_INTERPOLATED, c0, diff, n];
  35210. },
  35211. constructInterpolatedFromIR:
  35212. function PDFFunction_constructInterpolatedFromIR(IR) {
  35213. var c0 = IR[1];
  35214. var diff = IR[2];
  35215. var n = IR[3];
  35216. var length = diff.length;
  35217. return function constructInterpolatedFromIRResult(src, srcOffset,
  35218. dest, destOffset) {
  35219. var x = n === 1 ? src[srcOffset] : Math.pow(src[srcOffset], n);
  35220. for (var j = 0; j < length; ++j) {
  35221. dest[destOffset + j] = c0[j] + (x * diff[j]);
  35222. }
  35223. };
  35224. },
  35225. constructStiched: function PDFFunction_constructStiched(fn, dict, xref) {
  35226. var domain = dict.get('Domain');
  35227. if (!domain) {
  35228. error('No domain');
  35229. }
  35230. var inputSize = domain.length / 2;
  35231. if (inputSize !== 1) {
  35232. error('Bad domain for stiched function');
  35233. }
  35234. var fnRefs = dict.get('Functions');
  35235. var fns = [];
  35236. for (var i = 0, ii = fnRefs.length; i < ii; ++i) {
  35237. fns.push(PDFFunction.getIR(xref, xref.fetchIfRef(fnRefs[i])));
  35238. }
  35239. var bounds = dict.get('Bounds');
  35240. var encode = dict.get('Encode');
  35241. return [CONSTRUCT_STICHED, domain, bounds, encode, fns];
  35242. },
  35243. constructStichedFromIR: function PDFFunction_constructStichedFromIR(IR) {
  35244. var domain = IR[1];
  35245. var bounds = IR[2];
  35246. var encode = IR[3];
  35247. var fnsIR = IR[4];
  35248. var fns = [];
  35249. var tmpBuf = new Float32Array(1);
  35250. for (var i = 0, ii = fnsIR.length; i < ii; i++) {
  35251. fns.push(PDFFunction.fromIR(fnsIR[i]));
  35252. }
  35253. return function constructStichedFromIRResult(src, srcOffset,
  35254. dest, destOffset) {
  35255. var clip = function constructStichedFromIRClip(v, min, max) {
  35256. if (v > max) {
  35257. v = max;
  35258. } else if (v < min) {
  35259. v = min;
  35260. }
  35261. return v;
  35262. };
  35263. // clip to domain
  35264. var v = clip(src[srcOffset], domain[0], domain[1]);
  35265. // calulate which bound the value is in
  35266. for (var i = 0, ii = bounds.length; i < ii; ++i) {
  35267. if (v < bounds[i]) {
  35268. break;
  35269. }
  35270. }
  35271. // encode value into domain of function
  35272. var dmin = domain[0];
  35273. if (i > 0) {
  35274. dmin = bounds[i - 1];
  35275. }
  35276. var dmax = domain[1];
  35277. if (i < bounds.length) {
  35278. dmax = bounds[i];
  35279. }
  35280. var rmin = encode[2 * i];
  35281. var rmax = encode[2 * i + 1];
  35282. // Prevent the value from becoming NaN as a result
  35283. // of division by zero (fixes issue6113.pdf).
  35284. tmpBuf[0] = dmin === dmax ? rmin :
  35285. rmin + (v - dmin) * (rmax - rmin) / (dmax - dmin);
  35286. // call the appropriate function
  35287. fns[i](tmpBuf, 0, dest, destOffset);
  35288. };
  35289. },
  35290. constructPostScript: function PDFFunction_constructPostScript(fn, dict,
  35291. xref) {
  35292. var domain = dict.get('Domain');
  35293. var range = dict.get('Range');
  35294. if (!domain) {
  35295. error('No domain.');
  35296. }
  35297. if (!range) {
  35298. error('No range.');
  35299. }
  35300. var lexer = new PostScriptLexer(fn);
  35301. var parser = new PostScriptParser(lexer);
  35302. var code = parser.parse();
  35303. return [CONSTRUCT_POSTSCRIPT, domain, range, code];
  35304. },
  35305. constructPostScriptFromIR: function PDFFunction_constructPostScriptFromIR(
  35306. IR) {
  35307. var domain = IR[1];
  35308. var range = IR[2];
  35309. var code = IR[3];
  35310. var compiled = (new PostScriptCompiler()).compile(code, domain, range);
  35311. if (compiled) {
  35312. // Compiled function consists of simple expressions such as addition,
  35313. // subtraction, Math.max, and also contains 'var' and 'return'
  35314. // statements. See the generation in the PostScriptCompiler below.
  35315. /*jshint -W054 */
  35316. return new Function('src', 'srcOffset', 'dest', 'destOffset', compiled);
  35317. }
  35318. info('Unable to compile PS function');
  35319. var numOutputs = range.length >> 1;
  35320. var numInputs = domain.length >> 1;
  35321. var evaluator = new PostScriptEvaluator(code);
  35322. // Cache the values for a big speed up, the cache size is limited though
  35323. // since the number of possible values can be huge from a PS function.
  35324. var cache = Object.create(null);
  35325. // The MAX_CACHE_SIZE is set to ~4x the maximum number of distinct values
  35326. // seen in our tests.
  35327. var MAX_CACHE_SIZE = 2048 * 4;
  35328. var cache_available = MAX_CACHE_SIZE;
  35329. var tmpBuf = new Float32Array(numInputs);
  35330. return function constructPostScriptFromIRResult(src, srcOffset,
  35331. dest, destOffset) {
  35332. var i, value;
  35333. var key = '';
  35334. var input = tmpBuf;
  35335. for (i = 0; i < numInputs; i++) {
  35336. value = src[srcOffset + i];
  35337. input[i] = value;
  35338. key += value + '_';
  35339. }
  35340. var cachedValue = cache[key];
  35341. if (cachedValue !== undefined) {
  35342. dest.set(cachedValue, destOffset);
  35343. return;
  35344. }
  35345. var output = new Float32Array(numOutputs);
  35346. var stack = evaluator.execute(input);
  35347. var stackIndex = stack.length - numOutputs;
  35348. for (i = 0; i < numOutputs; i++) {
  35349. value = stack[stackIndex + i];
  35350. var bound = range[i * 2];
  35351. if (value < bound) {
  35352. value = bound;
  35353. } else {
  35354. bound = range[i * 2 +1];
  35355. if (value > bound) {
  35356. value = bound;
  35357. }
  35358. }
  35359. output[i] = value;
  35360. }
  35361. if (cache_available > 0) {
  35362. cache_available--;
  35363. cache[key] = output;
  35364. }
  35365. dest.set(output, destOffset);
  35366. };
  35367. }
  35368. };
  35369. })();
  35370. function isPDFFunction(v) {
  35371. var fnDict;
  35372. if (typeof v !== 'object') {
  35373. return false;
  35374. } else if (isDict(v)) {
  35375. fnDict = v;
  35376. } else if (isStream(v)) {
  35377. fnDict = v.dict;
  35378. } else {
  35379. return false;
  35380. }
  35381. return fnDict.has('FunctionType');
  35382. }
  35383. var PostScriptStack = (function PostScriptStackClosure() {
  35384. var MAX_STACK_SIZE = 100;
  35385. function PostScriptStack(initialStack) {
  35386. this.stack = !initialStack ? [] :
  35387. Array.prototype.slice.call(initialStack, 0);
  35388. }
  35389. PostScriptStack.prototype = {
  35390. push: function PostScriptStack_push(value) {
  35391. if (this.stack.length >= MAX_STACK_SIZE) {
  35392. error('PostScript function stack overflow.');
  35393. }
  35394. this.stack.push(value);
  35395. },
  35396. pop: function PostScriptStack_pop() {
  35397. if (this.stack.length <= 0) {
  35398. error('PostScript function stack underflow.');
  35399. }
  35400. return this.stack.pop();
  35401. },
  35402. copy: function PostScriptStack_copy(n) {
  35403. if (this.stack.length + n >= MAX_STACK_SIZE) {
  35404. error('PostScript function stack overflow.');
  35405. }
  35406. var stack = this.stack;
  35407. for (var i = stack.length - n, j = n - 1; j >= 0; j--, i++) {
  35408. stack.push(stack[i]);
  35409. }
  35410. },
  35411. index: function PostScriptStack_index(n) {
  35412. this.push(this.stack[this.stack.length - n - 1]);
  35413. },
  35414. // rotate the last n stack elements p times
  35415. roll: function PostScriptStack_roll(n, p) {
  35416. var stack = this.stack;
  35417. var l = stack.length - n;
  35418. var r = stack.length - 1, c = l + (p - Math.floor(p / n) * n), i, j, t;
  35419. for (i = l, j = r; i < j; i++, j--) {
  35420. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35421. }
  35422. for (i = l, j = c - 1; i < j; i++, j--) {
  35423. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35424. }
  35425. for (i = c, j = r; i < j; i++, j--) {
  35426. t = stack[i]; stack[i] = stack[j]; stack[j] = t;
  35427. }
  35428. }
  35429. };
  35430. return PostScriptStack;
  35431. })();
  35432. var PostScriptEvaluator = (function PostScriptEvaluatorClosure() {
  35433. function PostScriptEvaluator(operators) {
  35434. this.operators = operators;
  35435. }
  35436. PostScriptEvaluator.prototype = {
  35437. execute: function PostScriptEvaluator_execute(initialStack) {
  35438. var stack = new PostScriptStack(initialStack);
  35439. var counter = 0;
  35440. var operators = this.operators;
  35441. var length = operators.length;
  35442. var operator, a, b;
  35443. while (counter < length) {
  35444. operator = operators[counter++];
  35445. if (typeof operator === 'number') {
  35446. // Operator is really an operand and should be pushed to the stack.
  35447. stack.push(operator);
  35448. continue;
  35449. }
  35450. switch (operator) {
  35451. // non standard ps operators
  35452. case 'jz': // jump if false
  35453. b = stack.pop();
  35454. a = stack.pop();
  35455. if (!a) {
  35456. counter = b;
  35457. }
  35458. break;
  35459. case 'j': // jump
  35460. a = stack.pop();
  35461. counter = a;
  35462. break;
  35463. // all ps operators in alphabetical order (excluding if/ifelse)
  35464. case 'abs':
  35465. a = stack.pop();
  35466. stack.push(Math.abs(a));
  35467. break;
  35468. case 'add':
  35469. b = stack.pop();
  35470. a = stack.pop();
  35471. stack.push(a + b);
  35472. break;
  35473. case 'and':
  35474. b = stack.pop();
  35475. a = stack.pop();
  35476. if (isBool(a) && isBool(b)) {
  35477. stack.push(a && b);
  35478. } else {
  35479. stack.push(a & b);
  35480. }
  35481. break;
  35482. case 'atan':
  35483. a = stack.pop();
  35484. stack.push(Math.atan(a));
  35485. break;
  35486. case 'bitshift':
  35487. b = stack.pop();
  35488. a = stack.pop();
  35489. if (a > 0) {
  35490. stack.push(a << b);
  35491. } else {
  35492. stack.push(a >> b);
  35493. }
  35494. break;
  35495. case 'ceiling':
  35496. a = stack.pop();
  35497. stack.push(Math.ceil(a));
  35498. break;
  35499. case 'copy':
  35500. a = stack.pop();
  35501. stack.copy(a);
  35502. break;
  35503. case 'cos':
  35504. a = stack.pop();
  35505. stack.push(Math.cos(a));
  35506. break;
  35507. case 'cvi':
  35508. a = stack.pop() | 0;
  35509. stack.push(a);
  35510. break;
  35511. case 'cvr':
  35512. // noop
  35513. break;
  35514. case 'div':
  35515. b = stack.pop();
  35516. a = stack.pop();
  35517. stack.push(a / b);
  35518. break;
  35519. case 'dup':
  35520. stack.copy(1);
  35521. break;
  35522. case 'eq':
  35523. b = stack.pop();
  35524. a = stack.pop();
  35525. stack.push(a === b);
  35526. break;
  35527. case 'exch':
  35528. stack.roll(2, 1);
  35529. break;
  35530. case 'exp':
  35531. b = stack.pop();
  35532. a = stack.pop();
  35533. stack.push(Math.pow(a, b));
  35534. break;
  35535. case 'false':
  35536. stack.push(false);
  35537. break;
  35538. case 'floor':
  35539. a = stack.pop();
  35540. stack.push(Math.floor(a));
  35541. break;
  35542. case 'ge':
  35543. b = stack.pop();
  35544. a = stack.pop();
  35545. stack.push(a >= b);
  35546. break;
  35547. case 'gt':
  35548. b = stack.pop();
  35549. a = stack.pop();
  35550. stack.push(a > b);
  35551. break;
  35552. case 'idiv':
  35553. b = stack.pop();
  35554. a = stack.pop();
  35555. stack.push((a / b) | 0);
  35556. break;
  35557. case 'index':
  35558. a = stack.pop();
  35559. stack.index(a);
  35560. break;
  35561. case 'le':
  35562. b = stack.pop();
  35563. a = stack.pop();
  35564. stack.push(a <= b);
  35565. break;
  35566. case 'ln':
  35567. a = stack.pop();
  35568. stack.push(Math.log(a));
  35569. break;
  35570. case 'log':
  35571. a = stack.pop();
  35572. stack.push(Math.log(a) / Math.LN10);
  35573. break;
  35574. case 'lt':
  35575. b = stack.pop();
  35576. a = stack.pop();
  35577. stack.push(a < b);
  35578. break;
  35579. case 'mod':
  35580. b = stack.pop();
  35581. a = stack.pop();
  35582. stack.push(a % b);
  35583. break;
  35584. case 'mul':
  35585. b = stack.pop();
  35586. a = stack.pop();
  35587. stack.push(a * b);
  35588. break;
  35589. case 'ne':
  35590. b = stack.pop();
  35591. a = stack.pop();
  35592. stack.push(a !== b);
  35593. break;
  35594. case 'neg':
  35595. a = stack.pop();
  35596. stack.push(-a);
  35597. break;
  35598. case 'not':
  35599. a = stack.pop();
  35600. if (isBool(a)) {
  35601. stack.push(!a);
  35602. } else {
  35603. stack.push(~a);
  35604. }
  35605. break;
  35606. case 'or':
  35607. b = stack.pop();
  35608. a = stack.pop();
  35609. if (isBool(a) && isBool(b)) {
  35610. stack.push(a || b);
  35611. } else {
  35612. stack.push(a | b);
  35613. }
  35614. break;
  35615. case 'pop':
  35616. stack.pop();
  35617. break;
  35618. case 'roll':
  35619. b = stack.pop();
  35620. a = stack.pop();
  35621. stack.roll(a, b);
  35622. break;
  35623. case 'round':
  35624. a = stack.pop();
  35625. stack.push(Math.round(a));
  35626. break;
  35627. case 'sin':
  35628. a = stack.pop();
  35629. stack.push(Math.sin(a));
  35630. break;
  35631. case 'sqrt':
  35632. a = stack.pop();
  35633. stack.push(Math.sqrt(a));
  35634. break;
  35635. case 'sub':
  35636. b = stack.pop();
  35637. a = stack.pop();
  35638. stack.push(a - b);
  35639. break;
  35640. case 'true':
  35641. stack.push(true);
  35642. break;
  35643. case 'truncate':
  35644. a = stack.pop();
  35645. a = a < 0 ? Math.ceil(a) : Math.floor(a);
  35646. stack.push(a);
  35647. break;
  35648. case 'xor':
  35649. b = stack.pop();
  35650. a = stack.pop();
  35651. if (isBool(a) && isBool(b)) {
  35652. stack.push(a !== b);
  35653. } else {
  35654. stack.push(a ^ b);
  35655. }
  35656. break;
  35657. default:
  35658. error('Unknown operator ' + operator);
  35659. break;
  35660. }
  35661. }
  35662. return stack.stack;
  35663. }
  35664. };
  35665. return PostScriptEvaluator;
  35666. })();
  35667. // Most of the PDFs functions consist of simple operations such as:
  35668. // roll, exch, sub, cvr, pop, index, dup, mul, if, gt, add.
  35669. //
  35670. // We can compile most of such programs, and at the same moment, we can
  35671. // optimize some expressions using basic math properties. Keeping track of
  35672. // min/max values will allow us to avoid extra Math.min/Math.max calls.
  35673. var PostScriptCompiler = (function PostScriptCompilerClosure() {
  35674. function AstNode(type) {
  35675. this.type = type;
  35676. }
  35677. AstNode.prototype.visit = function (visitor) {
  35678. throw new Error('abstract method');
  35679. };
  35680. function AstArgument(index, min, max) {
  35681. AstNode.call(this, 'args');
  35682. this.index = index;
  35683. this.min = min;
  35684. this.max = max;
  35685. }
  35686. AstArgument.prototype = Object.create(AstNode.prototype);
  35687. AstArgument.prototype.visit = function (visitor) {
  35688. visitor.visitArgument(this);
  35689. };
  35690. function AstLiteral(number) {
  35691. AstNode.call(this, 'literal');
  35692. this.number = number;
  35693. this.min = number;
  35694. this.max = number;
  35695. }
  35696. AstLiteral.prototype = Object.create(AstNode.prototype);
  35697. AstLiteral.prototype.visit = function (visitor) {
  35698. visitor.visitLiteral(this);
  35699. };
  35700. function AstBinaryOperation(op, arg1, arg2, min, max) {
  35701. AstNode.call(this, 'binary');
  35702. this.op = op;
  35703. this.arg1 = arg1;
  35704. this.arg2 = arg2;
  35705. this.min = min;
  35706. this.max = max;
  35707. }
  35708. AstBinaryOperation.prototype = Object.create(AstNode.prototype);
  35709. AstBinaryOperation.prototype.visit = function (visitor) {
  35710. visitor.visitBinaryOperation(this);
  35711. };
  35712. function AstMin(arg, max) {
  35713. AstNode.call(this, 'max');
  35714. this.arg = arg;
  35715. this.min = arg.min;
  35716. this.max = max;
  35717. }
  35718. AstMin.prototype = Object.create(AstNode.prototype);
  35719. AstMin.prototype.visit = function (visitor) {
  35720. visitor.visitMin(this);
  35721. };
  35722. function AstVariable(index, min, max) {
  35723. AstNode.call(this, 'var');
  35724. this.index = index;
  35725. this.min = min;
  35726. this.max = max;
  35727. }
  35728. AstVariable.prototype = Object.create(AstNode.prototype);
  35729. AstVariable.prototype.visit = function (visitor) {
  35730. visitor.visitVariable(this);
  35731. };
  35732. function AstVariableDefinition(variable, arg) {
  35733. AstNode.call(this, 'definition');
  35734. this.variable = variable;
  35735. this.arg = arg;
  35736. }
  35737. AstVariableDefinition.prototype = Object.create(AstNode.prototype);
  35738. AstVariableDefinition.prototype.visit = function (visitor) {
  35739. visitor.visitVariableDefinition(this);
  35740. };
  35741. function ExpressionBuilderVisitor() {
  35742. this.parts = [];
  35743. }
  35744. ExpressionBuilderVisitor.prototype = {
  35745. visitArgument: function (arg) {
  35746. this.parts.push('Math.max(', arg.min, ', Math.min(',
  35747. arg.max, ', src[srcOffset + ', arg.index, ']))');
  35748. },
  35749. visitVariable: function (variable) {
  35750. this.parts.push('v', variable.index);
  35751. },
  35752. visitLiteral: function (literal) {
  35753. this.parts.push(literal.number);
  35754. },
  35755. visitBinaryOperation: function (operation) {
  35756. this.parts.push('(');
  35757. operation.arg1.visit(this);
  35758. this.parts.push(' ', operation.op, ' ');
  35759. operation.arg2.visit(this);
  35760. this.parts.push(')');
  35761. },
  35762. visitVariableDefinition: function (definition) {
  35763. this.parts.push('var ');
  35764. definition.variable.visit(this);
  35765. this.parts.push(' = ');
  35766. definition.arg.visit(this);
  35767. this.parts.push(';');
  35768. },
  35769. visitMin: function (max) {
  35770. this.parts.push('Math.min(');
  35771. max.arg.visit(this);
  35772. this.parts.push(', ', max.max, ')');
  35773. },
  35774. toString: function () {
  35775. return this.parts.join('');
  35776. }
  35777. };
  35778. function buildAddOperation(num1, num2) {
  35779. if (num2.type === 'literal' && num2.number === 0) {
  35780. // optimization: second operand is 0
  35781. return num1;
  35782. }
  35783. if (num1.type === 'literal' && num1.number === 0) {
  35784. // optimization: first operand is 0
  35785. return num2;
  35786. }
  35787. if (num2.type === 'literal' && num1.type === 'literal') {
  35788. // optimization: operands operand are literals
  35789. return new AstLiteral(num1.number + num2.number);
  35790. }
  35791. return new AstBinaryOperation('+', num1, num2,
  35792. num1.min + num2.min, num1.max + num2.max);
  35793. }
  35794. function buildMulOperation(num1, num2) {
  35795. if (num2.type === 'literal') {
  35796. // optimization: second operands is a literal...
  35797. if (num2.number === 0) {
  35798. return new AstLiteral(0); // and it's 0
  35799. } else if (num2.number === 1) {
  35800. return num1; // and it's 1
  35801. } else if (num1.type === 'literal') {
  35802. // ... and first operands is a literal too
  35803. return new AstLiteral(num1.number * num2.number);
  35804. }
  35805. }
  35806. if (num1.type === 'literal') {
  35807. // optimization: first operands is a literal...
  35808. if (num1.number === 0) {
  35809. return new AstLiteral(0); // and it's 0
  35810. } else if (num1.number === 1) {
  35811. return num2; // and it's 1
  35812. }
  35813. }
  35814. var min = Math.min(num1.min * num2.min, num1.min * num2.max,
  35815. num1.max * num2.min, num1.max * num2.max);
  35816. var max = Math.max(num1.min * num2.min, num1.min * num2.max,
  35817. num1.max * num2.min, num1.max * num2.max);
  35818. return new AstBinaryOperation('*', num1, num2, min, max);
  35819. }
  35820. function buildSubOperation(num1, num2) {
  35821. if (num2.type === 'literal') {
  35822. // optimization: second operands is a literal...
  35823. if (num2.number === 0) {
  35824. return num1; // ... and it's 0
  35825. } else if (num1.type === 'literal') {
  35826. // ... and first operands is a literal too
  35827. return new AstLiteral(num1.number - num2.number);
  35828. }
  35829. }
  35830. if (num2.type === 'binary' && num2.op === '-' &&
  35831. num1.type === 'literal' && num1.number === 1 &&
  35832. num2.arg1.type === 'literal' && num2.arg1.number === 1) {
  35833. // optimization for case: 1 - (1 - x)
  35834. return num2.arg2;
  35835. }
  35836. return new AstBinaryOperation('-', num1, num2,
  35837. num1.min - num2.max, num1.max - num2.min);
  35838. }
  35839. function buildMinOperation(num1, max) {
  35840. if (num1.min >= max) {
  35841. // optimization: num1 min value is not less than required max
  35842. return new AstLiteral(max); // just returning max
  35843. } else if (num1.max <= max) {
  35844. // optimization: num1 max value is not greater than required max
  35845. return num1; // just returning an argument
  35846. }
  35847. return new AstMin(num1, max);
  35848. }
  35849. function PostScriptCompiler() {}
  35850. PostScriptCompiler.prototype = {
  35851. compile: function PostScriptCompiler_compile(code, domain, range) {
  35852. var stack = [];
  35853. var i, ii;
  35854. var instructions = [];
  35855. var inputSize = domain.length >> 1, outputSize = range.length >> 1;
  35856. var lastRegister = 0;
  35857. var n, j;
  35858. var num1, num2, ast1, ast2, tmpVar, item;
  35859. for (i = 0; i < inputSize; i++) {
  35860. stack.push(new AstArgument(i, domain[i * 2], domain[i * 2 + 1]));
  35861. }
  35862. for (i = 0, ii = code.length; i < ii; i++) {
  35863. item = code[i];
  35864. if (typeof item === 'number') {
  35865. stack.push(new AstLiteral(item));
  35866. continue;
  35867. }
  35868. switch (item) {
  35869. case 'add':
  35870. if (stack.length < 2) {
  35871. return null;
  35872. }
  35873. num2 = stack.pop();
  35874. num1 = stack.pop();
  35875. stack.push(buildAddOperation(num1, num2));
  35876. break;
  35877. case 'cvr':
  35878. if (stack.length < 1) {
  35879. return null;
  35880. }
  35881. break;
  35882. case 'mul':
  35883. if (stack.length < 2) {
  35884. return null;
  35885. }
  35886. num2 = stack.pop();
  35887. num1 = stack.pop();
  35888. stack.push(buildMulOperation(num1, num2));
  35889. break;
  35890. case 'sub':
  35891. if (stack.length < 2) {
  35892. return null;
  35893. }
  35894. num2 = stack.pop();
  35895. num1 = stack.pop();
  35896. stack.push(buildSubOperation(num1, num2));
  35897. break;
  35898. case 'exch':
  35899. if (stack.length < 2) {
  35900. return null;
  35901. }
  35902. ast1 = stack.pop(); ast2 = stack.pop();
  35903. stack.push(ast1, ast2);
  35904. break;
  35905. case 'pop':
  35906. if (stack.length < 1) {
  35907. return null;
  35908. }
  35909. stack.pop();
  35910. break;
  35911. case 'index':
  35912. if (stack.length < 1) {
  35913. return null;
  35914. }
  35915. num1 = stack.pop();
  35916. if (num1.type !== 'literal') {
  35917. return null;
  35918. }
  35919. n = num1.number;
  35920. if (n < 0 || (n|0) !== n || stack.length < n) {
  35921. return null;
  35922. }
  35923. ast1 = stack[stack.length - n - 1];
  35924. if (ast1.type === 'literal' || ast1.type === 'var') {
  35925. stack.push(ast1);
  35926. break;
  35927. }
  35928. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  35929. stack[stack.length - n - 1] = tmpVar;
  35930. stack.push(tmpVar);
  35931. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  35932. break;
  35933. case 'dup':
  35934. if (stack.length < 1) {
  35935. return null;
  35936. }
  35937. if (typeof code[i + 1] === 'number' && code[i + 2] === 'gt' &&
  35938. code[i + 3] === i + 7 && code[i + 4] === 'jz' &&
  35939. code[i + 5] === 'pop' && code[i + 6] === code[i + 1]) {
  35940. // special case of the commands sequence for the min operation
  35941. num1 = stack.pop();
  35942. stack.push(buildMinOperation(num1, code[i + 1]));
  35943. i += 6;
  35944. break;
  35945. }
  35946. ast1 = stack[stack.length - 1];
  35947. if (ast1.type === 'literal' || ast1.type === 'var') {
  35948. // we don't have to save into intermediate variable a literal or
  35949. // variable.
  35950. stack.push(ast1);
  35951. break;
  35952. }
  35953. tmpVar = new AstVariable(lastRegister++, ast1.min, ast1.max);
  35954. stack[stack.length - 1] = tmpVar;
  35955. stack.push(tmpVar);
  35956. instructions.push(new AstVariableDefinition(tmpVar, ast1));
  35957. break;
  35958. case 'roll':
  35959. if (stack.length < 2) {
  35960. return null;
  35961. }
  35962. num2 = stack.pop();
  35963. num1 = stack.pop();
  35964. if (num2.type !== 'literal' || num1.type !== 'literal') {
  35965. // both roll operands must be numbers
  35966. return null;
  35967. }
  35968. j = num2.number;
  35969. n = num1.number;
  35970. if (n <= 0 || (n|0) !== n || (j|0) !== j || stack.length < n) {
  35971. // ... and integers
  35972. return null;
  35973. }
  35974. j = ((j % n) + n) % n;
  35975. if (j === 0) {
  35976. break; // just skipping -- there are nothing to rotate
  35977. }
  35978. Array.prototype.push.apply(stack,
  35979. stack.splice(stack.length - n, n - j));
  35980. break;
  35981. default:
  35982. return null; // unsupported operator
  35983. }
  35984. }
  35985. if (stack.length !== outputSize) {
  35986. return null;
  35987. }
  35988. var result = [];
  35989. instructions.forEach(function (instruction) {
  35990. var statementBuilder = new ExpressionBuilderVisitor();
  35991. instruction.visit(statementBuilder);
  35992. result.push(statementBuilder.toString());
  35993. });
  35994. stack.forEach(function (expr, i) {
  35995. var statementBuilder = new ExpressionBuilderVisitor();
  35996. expr.visit(statementBuilder);
  35997. var min = range[i * 2], max = range[i * 2 + 1];
  35998. var out = [statementBuilder.toString()];
  35999. if (min > expr.min) {
  36000. out.unshift('Math.max(', min, ', ');
  36001. out.push(')');
  36002. }
  36003. if (max < expr.max) {
  36004. out.unshift('Math.min(', max, ', ');
  36005. out.push(')');
  36006. }
  36007. out.unshift('dest[destOffset + ', i, '] = ');
  36008. out.push(';');
  36009. result.push(out.join(''));
  36010. });
  36011. return result.join('\n');
  36012. }
  36013. };
  36014. return PostScriptCompiler;
  36015. })();
  36016. exports.isPDFFunction = isPDFFunction;
  36017. exports.PDFFunction = PDFFunction;
  36018. exports.PostScriptEvaluator = PostScriptEvaluator;
  36019. exports.PostScriptCompiler = PostScriptCompiler;
  36020. }));
  36021. (function (root, factory) {
  36022. {
  36023. factory((root.pdfjsDisplayAPI = {}), root.pdfjsSharedUtil,
  36024. root.pdfjsDisplayFontLoader, root.pdfjsDisplayCanvas,
  36025. root.pdfjsDisplayMetadata, root.pdfjsDisplayDOMUtils,
  36026. root.pdfjsDisplayGlobal);
  36027. }
  36028. }(this, function (exports, sharedUtil, displayFontLoader, displayCanvas,
  36029. displayMetadata, displayDOMUtils, displayGlobal, amdRequire) {
  36030. var InvalidPDFException = sharedUtil.InvalidPDFException;
  36031. var MessageHandler = sharedUtil.MessageHandler;
  36032. var MissingPDFException = sharedUtil.MissingPDFException;
  36033. var PasswordResponses = sharedUtil.PasswordResponses;
  36034. var PasswordException = sharedUtil.PasswordException;
  36035. var StatTimer = sharedUtil.StatTimer;
  36036. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  36037. var UnknownErrorException = sharedUtil.UnknownErrorException;
  36038. var Util = sharedUtil.Util;
  36039. var createPromiseCapability = sharedUtil.createPromiseCapability;
  36040. var combineUrl = sharedUtil.combineUrl;
  36041. var error = sharedUtil.error;
  36042. var deprecated = sharedUtil.deprecated;
  36043. var getVerbosityLevel = sharedUtil.getVerbosityLevel;
  36044. var info = sharedUtil.info;
  36045. var isArrayBuffer = sharedUtil.isArrayBuffer;
  36046. var isSameOrigin = sharedUtil.isSameOrigin;
  36047. var loadJpegStream = sharedUtil.loadJpegStream;
  36048. var stringToBytes = sharedUtil.stringToBytes;
  36049. var warn = sharedUtil.warn;
  36050. var FontFaceObject = displayFontLoader.FontFaceObject;
  36051. var FontLoader = displayFontLoader.FontLoader;
  36052. var CanvasGraphics = displayCanvas.CanvasGraphics;
  36053. var createScratchCanvas = displayCanvas.createScratchCanvas;
  36054. var Metadata = displayMetadata.Metadata;
  36055. var PDFJS = displayGlobal.PDFJS;
  36056. var globalScope = displayGlobal.globalScope;
  36057. var DEFAULT_RANGE_CHUNK_SIZE = 65536; // 2^16 = 65536
  36058. /**
  36059. * The maximum allowed image size in total pixels e.g. width * height. Images
  36060. * above this value will not be drawn. Use -1 for no limit.
  36061. * @var {number}
  36062. */
  36063. PDFJS.maxImageSize = (PDFJS.maxImageSize === undefined ?
  36064. -1 : PDFJS.maxImageSize);
  36065. /**
  36066. * The url of where the predefined Adobe CMaps are located. Include trailing
  36067. * slash.
  36068. * @var {string}
  36069. */
  36070. PDFJS.cMapUrl = (PDFJS.cMapUrl === undefined ? null : PDFJS.cMapUrl);
  36071. /**
  36072. * Specifies if CMaps are binary packed.
  36073. * @var {boolean}
  36074. */
  36075. PDFJS.cMapPacked = PDFJS.cMapPacked === undefined ? false : PDFJS.cMapPacked;
  36076. /**
  36077. * By default fonts are converted to OpenType fonts and loaded via font face
  36078. * rules. If disabled, the font will be rendered using a built in font renderer
  36079. * that constructs the glyphs with primitive path commands.
  36080. * @var {boolean}
  36081. */
  36082. PDFJS.disableFontFace = (PDFJS.disableFontFace === undefined ?
  36083. false : PDFJS.disableFontFace);
  36084. /**
  36085. * Path for image resources, mainly for annotation icons. Include trailing
  36086. * slash.
  36087. * @var {string}
  36088. */
  36089. PDFJS.imageResourcesPath = (PDFJS.imageResourcesPath === undefined ?
  36090. '' : PDFJS.imageResourcesPath);
  36091. /**
  36092. * Disable the web worker and run all code on the main thread. This will happen
  36093. * automatically if the browser doesn't support workers or sending typed arrays
  36094. * to workers.
  36095. * @var {boolean}
  36096. */
  36097. PDFJS.disableWorker = (PDFJS.disableWorker === undefined ?
  36098. false : PDFJS.disableWorker);
  36099. /**
  36100. * Path and filename of the worker file. Required when the worker is enabled in
  36101. * development mode. If unspecified in the production build, the worker will be
  36102. * loaded based on the location of the pdf.js file. It is recommended that
  36103. * the workerSrc is set in a custom application to prevent issues caused by
  36104. * third-party frameworks and libraries.
  36105. * @var {string}
  36106. */
  36107. PDFJS.workerSrc = (PDFJS.workerSrc === undefined ? null : PDFJS.workerSrc);
  36108. /**
  36109. * Disable range request loading of PDF files. When enabled and if the server
  36110. * supports partial content requests then the PDF will be fetched in chunks.
  36111. * Enabled (false) by default.
  36112. * @var {boolean}
  36113. */
  36114. PDFJS.disableRange = (PDFJS.disableRange === undefined ?
  36115. false : PDFJS.disableRange);
  36116. /**
  36117. * Disable streaming of PDF file data. By default PDF.js attempts to load PDF
  36118. * in chunks. This default behavior can be disabled.
  36119. * @var {boolean}
  36120. */
  36121. PDFJS.disableStream = (PDFJS.disableStream === undefined ?
  36122. false : PDFJS.disableStream);
  36123. /**
  36124. * Disable pre-fetching of PDF file data. When range requests are enabled PDF.js
  36125. * will automatically keep fetching more data even if it isn't needed to display
  36126. * the current page. This default behavior can be disabled.
  36127. *
  36128. * NOTE: It is also necessary to disable streaming, see above,
  36129. * in order for disabling of pre-fetching to work correctly.
  36130. * @var {boolean}
  36131. */
  36132. PDFJS.disableAutoFetch = (PDFJS.disableAutoFetch === undefined ?
  36133. false : PDFJS.disableAutoFetch);
  36134. /**
  36135. * Enables special hooks for debugging PDF.js.
  36136. * @var {boolean}
  36137. */
  36138. PDFJS.pdfBug = (PDFJS.pdfBug === undefined ? false : PDFJS.pdfBug);
  36139. /**
  36140. * Enables transfer usage in postMessage for ArrayBuffers.
  36141. * @var {boolean}
  36142. */
  36143. PDFJS.postMessageTransfers = (PDFJS.postMessageTransfers === undefined ?
  36144. true : PDFJS.postMessageTransfers);
  36145. /**
  36146. * Disables URL.createObjectURL usage.
  36147. * @var {boolean}
  36148. */
  36149. PDFJS.disableCreateObjectURL = (PDFJS.disableCreateObjectURL === undefined ?
  36150. false : PDFJS.disableCreateObjectURL);
  36151. /**
  36152. * Disables WebGL usage.
  36153. * @var {boolean}
  36154. */
  36155. PDFJS.disableWebGL = (PDFJS.disableWebGL === undefined ?
  36156. true : PDFJS.disableWebGL);
  36157. /**
  36158. * Disables fullscreen support, and by extension Presentation Mode,
  36159. * in browsers which support the fullscreen API.
  36160. * @var {boolean}
  36161. */
  36162. PDFJS.disableFullscreen = (PDFJS.disableFullscreen === undefined ?
  36163. false : PDFJS.disableFullscreen);
  36164. /**
  36165. * Enables CSS only zooming.
  36166. * @var {boolean}
  36167. */
  36168. PDFJS.useOnlyCssZoom = (PDFJS.useOnlyCssZoom === undefined ?
  36169. false : PDFJS.useOnlyCssZoom);
  36170. /**
  36171. * The maximum supported canvas size in total pixels e.g. width * height.
  36172. * The default value is 4096 * 4096. Use -1 for no limit.
  36173. * @var {number}
  36174. */
  36175. PDFJS.maxCanvasPixels = (PDFJS.maxCanvasPixels === undefined ?
  36176. 16777216 : PDFJS.maxCanvasPixels);
  36177. /**
  36178. * (Deprecated) Opens external links in a new window if enabled.
  36179. * The default behavior opens external links in the PDF.js window.
  36180. *
  36181. * NOTE: This property has been deprecated, please use
  36182. * `PDFJS.externalLinkTarget = PDFJS.LinkTarget.BLANK` instead.
  36183. * @var {boolean}
  36184. */
  36185. PDFJS.openExternalLinksInNewWindow = (
  36186. PDFJS.openExternalLinksInNewWindow === undefined ?
  36187. false : PDFJS.openExternalLinksInNewWindow);
  36188. /**
  36189. * Specifies the |target| attribute for external links.
  36190. * The constants from PDFJS.LinkTarget should be used:
  36191. * - NONE [default]
  36192. * - SELF
  36193. * - BLANK
  36194. * - PARENT
  36195. * - TOP
  36196. * @var {number}
  36197. */
  36198. PDFJS.externalLinkTarget = (PDFJS.externalLinkTarget === undefined ?
  36199. PDFJS.LinkTarget.NONE : PDFJS.externalLinkTarget);
  36200. /**
  36201. * Specifies the |rel| attribute for external links. Defaults to stripping
  36202. * the referrer.
  36203. * @var {string}
  36204. */
  36205. PDFJS.externalLinkRel = (PDFJS.externalLinkRel === undefined ?
  36206. 'noreferrer' : PDFJS.externalLinkRel);
  36207. /**
  36208. * Determines if we can eval strings as JS. Primarily used to improve
  36209. * performance for font rendering.
  36210. * @var {boolean}
  36211. */
  36212. PDFJS.isEvalSupported = (PDFJS.isEvalSupported === undefined ?
  36213. true : PDFJS.isEvalSupported);
  36214. /**
  36215. * Document initialization / loading parameters object.
  36216. *
  36217. * @typedef {Object} DocumentInitParameters
  36218. * @property {string} url - The URL of the PDF.
  36219. * @property {TypedArray|Array|string} data - Binary PDF data. Use typed arrays
  36220. * (Uint8Array) to improve the memory usage. If PDF data is BASE64-encoded,
  36221. * use atob() to convert it to a binary string first.
  36222. * @property {Object} httpHeaders - Basic authentication headers.
  36223. * @property {boolean} withCredentials - Indicates whether or not cross-site
  36224. * Access-Control requests should be made using credentials such as cookies
  36225. * or authorization headers. The default is false.
  36226. * @property {string} password - For decrypting password-protected PDFs.
  36227. * @property {TypedArray} initialData - A typed array with the first portion or
  36228. * all of the pdf data. Used by the extension since some data is already
  36229. * loaded before the switch to range requests.
  36230. * @property {number} length - The PDF file length. It's used for progress
  36231. * reports and range requests operations.
  36232. * @property {PDFDataRangeTransport} range
  36233. * @property {number} rangeChunkSize - Optional parameter to specify
  36234. * maximum number of bytes fetched per range request. The default value is
  36235. * 2^16 = 65536.
  36236. * @property {PDFWorker} worker - The worker that will be used for the loading
  36237. * and parsing of the PDF data.
  36238. */
  36239. /**
  36240. * @typedef {Object} PDFDocumentStats
  36241. * @property {Array} streamTypes - Used stream types in the document (an item
  36242. * is set to true if specific stream ID was used in the document).
  36243. * @property {Array} fontTypes - Used font type in the document (an item is set
  36244. * to true if specific font ID was used in the document).
  36245. */
  36246. /**
  36247. * This is the main entry point for loading a PDF and interacting with it.
  36248. * NOTE: If a URL is used to fetch the PDF data a standard XMLHttpRequest(XHR)
  36249. * is used, which means it must follow the same origin rules that any XHR does
  36250. * e.g. No cross domain requests without CORS.
  36251. *
  36252. * @param {string|TypedArray|DocumentInitParameters|PDFDataRangeTransport} src
  36253. * Can be a url to where a PDF is located, a typed array (Uint8Array)
  36254. * already populated with data or parameter object.
  36255. *
  36256. * @param {PDFDataRangeTransport} pdfDataRangeTransport (deprecated) It is used
  36257. * if you want to manually serve range requests for data in the PDF.
  36258. *
  36259. * @param {function} passwordCallback (deprecated) It is used to request a
  36260. * password if wrong or no password was provided. The callback receives two
  36261. * parameters: function that needs to be called with new password and reason
  36262. * (see {PasswordResponses}).
  36263. *
  36264. * @param {function} progressCallback (deprecated) It is used to be able to
  36265. * monitor the loading progress of the PDF file (necessary to implement e.g.
  36266. * a loading bar). The callback receives an {Object} with the properties:
  36267. * {number} loaded and {number} total.
  36268. *
  36269. * @return {PDFDocumentLoadingTask}
  36270. */
  36271. PDFJS.getDocument = function getDocument(src,
  36272. pdfDataRangeTransport,
  36273. passwordCallback,
  36274. progressCallback) {
  36275. var task = new PDFDocumentLoadingTask();
  36276. // Support of the obsolete arguments (for compatibility with API v1.0)
  36277. if (arguments.length > 1) {
  36278. deprecated('getDocument is called with pdfDataRangeTransport, ' +
  36279. 'passwordCallback or progressCallback argument');
  36280. }
  36281. if (pdfDataRangeTransport) {
  36282. if (!(pdfDataRangeTransport instanceof PDFDataRangeTransport)) {
  36283. // Not a PDFDataRangeTransport instance, trying to add missing properties.
  36284. pdfDataRangeTransport = Object.create(pdfDataRangeTransport);
  36285. pdfDataRangeTransport.length = src.length;
  36286. pdfDataRangeTransport.initialData = src.initialData;
  36287. if (!pdfDataRangeTransport.abort) {
  36288. pdfDataRangeTransport.abort = function () {};
  36289. }
  36290. }
  36291. src = Object.create(src);
  36292. src.range = pdfDataRangeTransport;
  36293. }
  36294. task.onPassword = passwordCallback || null;
  36295. task.onProgress = progressCallback || null;
  36296. var source;
  36297. if (typeof src === 'string') {
  36298. source = { url: src };
  36299. } else if (isArrayBuffer(src)) {
  36300. source = { data: src };
  36301. } else if (src instanceof PDFDataRangeTransport) {
  36302. source = { range: src };
  36303. } else {
  36304. if (typeof src !== 'object') {
  36305. error('Invalid parameter in getDocument, need either Uint8Array, ' +
  36306. 'string or a parameter object');
  36307. }
  36308. if (!src.url && !src.data && !src.range) {
  36309. error('Invalid parameter object: need either .data, .range or .url');
  36310. }
  36311. source = src;
  36312. }
  36313. var params = {};
  36314. var rangeTransport = null;
  36315. var worker = null;
  36316. for (var key in source) {
  36317. if (key === 'url' && typeof window !== 'undefined') {
  36318. // The full path is required in the 'url' field.
  36319. params[key] = combineUrl(window.location.href, source[key]);
  36320. continue;
  36321. } else if (key === 'range') {
  36322. rangeTransport = source[key];
  36323. continue;
  36324. } else if (key === 'worker') {
  36325. worker = source[key];
  36326. continue;
  36327. } else if (key === 'data' && !(source[key] instanceof Uint8Array)) {
  36328. // Converting string or array-like data to Uint8Array.
  36329. var pdfBytes = source[key];
  36330. if (typeof pdfBytes === 'string') {
  36331. params[key] = stringToBytes(pdfBytes);
  36332. } else if (typeof pdfBytes === 'object' && pdfBytes !== null &&
  36333. !isNaN(pdfBytes.length)) {
  36334. params[key] = new Uint8Array(pdfBytes);
  36335. } else if (isArrayBuffer(pdfBytes)) {
  36336. params[key] = new Uint8Array(pdfBytes);
  36337. } else {
  36338. error('Invalid PDF binary data: either typed array, string or ' +
  36339. 'array-like object is expected in the data property.');
  36340. }
  36341. continue;
  36342. }
  36343. params[key] = source[key];
  36344. }
  36345. params.rangeChunkSize = params.rangeChunkSize || DEFAULT_RANGE_CHUNK_SIZE;
  36346. if (!worker) {
  36347. // Worker was not provided -- creating and owning our own.
  36348. worker = new PDFWorker();
  36349. task._worker = worker;
  36350. }
  36351. var docId = task.docId;
  36352. worker.promise.then(function () {
  36353. if (task.destroyed) {
  36354. throw new Error('Loading aborted');
  36355. }
  36356. return _fetchDocument(worker, params, rangeTransport, docId).then(
  36357. function (workerId) {
  36358. if (task.destroyed) {
  36359. throw new Error('Loading aborted');
  36360. }
  36361. var messageHandler = new MessageHandler(docId, workerId, worker.port);
  36362. var transport = new WorkerTransport(messageHandler, task, rangeTransport);
  36363. task._transport = transport;
  36364. messageHandler.send('Ready', null);
  36365. });
  36366. }).catch(task._capability.reject);
  36367. return task;
  36368. };
  36369. /**
  36370. * Starts fetching of specified PDF document/data.
  36371. * @param {PDFWorker} worker
  36372. * @param {Object} source
  36373. * @param {PDFDataRangeTransport} pdfDataRangeTransport
  36374. * @param {string} docId Unique document id, used as MessageHandler id.
  36375. * @returns {Promise} The promise, which is resolved when worker id of
  36376. * MessageHandler is known.
  36377. * @private
  36378. */
  36379. function _fetchDocument(worker, source, pdfDataRangeTransport, docId) {
  36380. if (worker.destroyed) {
  36381. return Promise.reject(new Error('Worker was destroyed'));
  36382. }
  36383. source.disableAutoFetch = PDFJS.disableAutoFetch;
  36384. source.disableStream = PDFJS.disableStream;
  36385. source.chunkedViewerLoading = !!pdfDataRangeTransport;
  36386. if (pdfDataRangeTransport) {
  36387. source.length = pdfDataRangeTransport.length;
  36388. source.initialData = pdfDataRangeTransport.initialData;
  36389. }
  36390. return worker.messageHandler.sendWithPromise('GetDocRequest', {
  36391. docId: docId,
  36392. source: source,
  36393. disableRange: PDFJS.disableRange,
  36394. maxImageSize: PDFJS.maxImageSize,
  36395. cMapUrl: PDFJS.cMapUrl,
  36396. cMapPacked: PDFJS.cMapPacked,
  36397. disableFontFace: PDFJS.disableFontFace,
  36398. disableCreateObjectURL: PDFJS.disableCreateObjectURL,
  36399. postMessageTransfers: PDFJS.postMessageTransfers,
  36400. }).then(function (workerId) {
  36401. if (worker.destroyed) {
  36402. throw new Error('Worker was destroyed');
  36403. }
  36404. return workerId;
  36405. });
  36406. }
  36407. /**
  36408. * PDF document loading operation.
  36409. * @class
  36410. * @alias PDFDocumentLoadingTask
  36411. */
  36412. var PDFDocumentLoadingTask = (function PDFDocumentLoadingTaskClosure() {
  36413. var nextDocumentId = 0;
  36414. /** @constructs PDFDocumentLoadingTask */
  36415. function PDFDocumentLoadingTask() {
  36416. this._capability = createPromiseCapability();
  36417. this._transport = null;
  36418. this._worker = null;
  36419. /**
  36420. * Unique document loading task id -- used in MessageHandlers.
  36421. * @type {string}
  36422. */
  36423. this.docId = 'd' + (nextDocumentId++);
  36424. /**
  36425. * Shows if loading task is destroyed.
  36426. * @type {boolean}
  36427. */
  36428. this.destroyed = false;
  36429. /**
  36430. * Callback to request a password if wrong or no password was provided.
  36431. * The callback receives two parameters: function that needs to be called
  36432. * with new password and reason (see {PasswordResponses}).
  36433. */
  36434. this.onPassword = null;
  36435. /**
  36436. * Callback to be able to monitor the loading progress of the PDF file
  36437. * (necessary to implement e.g. a loading bar). The callback receives
  36438. * an {Object} with the properties: {number} loaded and {number} total.
  36439. */
  36440. this.onProgress = null;
  36441. /**
  36442. * Callback to when unsupported feature is used. The callback receives
  36443. * an {PDFJS.UNSUPPORTED_FEATURES} argument.
  36444. */
  36445. this.onUnsupportedFeature = null;
  36446. }
  36447. PDFDocumentLoadingTask.prototype =
  36448. /** @lends PDFDocumentLoadingTask.prototype */ {
  36449. /**
  36450. * @return {Promise}
  36451. */
  36452. get promise() {
  36453. return this._capability.promise;
  36454. },
  36455. /**
  36456. * Aborts all network requests and destroys worker.
  36457. * @return {Promise} A promise that is resolved after destruction activity
  36458. * is completed.
  36459. */
  36460. destroy: function () {
  36461. this.destroyed = true;
  36462. var transportDestroyed = !this._transport ? Promise.resolve() :
  36463. this._transport.destroy();
  36464. return transportDestroyed.then(function () {
  36465. this._transport = null;
  36466. if (this._worker) {
  36467. this._worker.destroy();
  36468. this._worker = null;
  36469. }
  36470. }.bind(this));
  36471. },
  36472. /**
  36473. * Registers callbacks to indicate the document loading completion.
  36474. *
  36475. * @param {function} onFulfilled The callback for the loading completion.
  36476. * @param {function} onRejected The callback for the loading failure.
  36477. * @return {Promise} A promise that is resolved after the onFulfilled or
  36478. * onRejected callback.
  36479. */
  36480. then: function PDFDocumentLoadingTask_then(onFulfilled, onRejected) {
  36481. return this.promise.then.apply(this.promise, arguments);
  36482. }
  36483. };
  36484. return PDFDocumentLoadingTask;
  36485. })();
  36486. /**
  36487. * Abstract class to support range requests file loading.
  36488. * @class
  36489. * @alias PDFJS.PDFDataRangeTransport
  36490. * @param {number} length
  36491. * @param {Uint8Array} initialData
  36492. */
  36493. var PDFDataRangeTransport = (function pdfDataRangeTransportClosure() {
  36494. function PDFDataRangeTransport(length, initialData) {
  36495. this.length = length;
  36496. this.initialData = initialData;
  36497. this._rangeListeners = [];
  36498. this._progressListeners = [];
  36499. this._progressiveReadListeners = [];
  36500. this._readyCapability = createPromiseCapability();
  36501. }
  36502. PDFDataRangeTransport.prototype =
  36503. /** @lends PDFDataRangeTransport.prototype */ {
  36504. addRangeListener:
  36505. function PDFDataRangeTransport_addRangeListener(listener) {
  36506. this._rangeListeners.push(listener);
  36507. },
  36508. addProgressListener:
  36509. function PDFDataRangeTransport_addProgressListener(listener) {
  36510. this._progressListeners.push(listener);
  36511. },
  36512. addProgressiveReadListener:
  36513. function PDFDataRangeTransport_addProgressiveReadListener(listener) {
  36514. this._progressiveReadListeners.push(listener);
  36515. },
  36516. onDataRange: function PDFDataRangeTransport_onDataRange(begin, chunk) {
  36517. var listeners = this._rangeListeners;
  36518. for (var i = 0, n = listeners.length; i < n; ++i) {
  36519. listeners[i](begin, chunk);
  36520. }
  36521. },
  36522. onDataProgress: function PDFDataRangeTransport_onDataProgress(loaded) {
  36523. this._readyCapability.promise.then(function () {
  36524. var listeners = this._progressListeners;
  36525. for (var i = 0, n = listeners.length; i < n; ++i) {
  36526. listeners[i](loaded);
  36527. }
  36528. }.bind(this));
  36529. },
  36530. onDataProgressiveRead:
  36531. function PDFDataRangeTransport_onDataProgress(chunk) {
  36532. this._readyCapability.promise.then(function () {
  36533. var listeners = this._progressiveReadListeners;
  36534. for (var i = 0, n = listeners.length; i < n; ++i) {
  36535. listeners[i](chunk);
  36536. }
  36537. }.bind(this));
  36538. },
  36539. transportReady: function PDFDataRangeTransport_transportReady() {
  36540. this._readyCapability.resolve();
  36541. },
  36542. requestDataRange:
  36543. function PDFDataRangeTransport_requestDataRange(begin, end) {
  36544. throw new Error('Abstract method PDFDataRangeTransport.requestDataRange');
  36545. },
  36546. abort: function PDFDataRangeTransport_abort() {
  36547. }
  36548. };
  36549. return PDFDataRangeTransport;
  36550. })();
  36551. PDFJS.PDFDataRangeTransport = PDFDataRangeTransport;
  36552. /**
  36553. * Proxy to a PDFDocument in the worker thread. Also, contains commonly used
  36554. * properties that can be read synchronously.
  36555. * @class
  36556. * @alias PDFDocumentProxy
  36557. */
  36558. var PDFDocumentProxy = (function PDFDocumentProxyClosure() {
  36559. function PDFDocumentProxy(pdfInfo, transport, loadingTask) {
  36560. this.pdfInfo = pdfInfo;
  36561. this.transport = transport;
  36562. this.loadingTask = loadingTask;
  36563. }
  36564. PDFDocumentProxy.prototype = /** @lends PDFDocumentProxy.prototype */ {
  36565. /**
  36566. * @return {number} Total number of pages the PDF contains.
  36567. */
  36568. get numPages() {
  36569. return this.pdfInfo.numPages;
  36570. },
  36571. /**
  36572. * @return {string} A unique ID to identify a PDF. Not guaranteed to be
  36573. * unique.
  36574. */
  36575. get fingerprint() {
  36576. return this.pdfInfo.fingerprint;
  36577. },
  36578. /**
  36579. * @param {number} pageNumber The page number to get. The first page is 1.
  36580. * @return {Promise} A promise that is resolved with a {@link PDFPageProxy}
  36581. * object.
  36582. */
  36583. getPage: function PDFDocumentProxy_getPage(pageNumber) {
  36584. return this.transport.getPage(pageNumber);
  36585. },
  36586. /**
  36587. * @param {{num: number, gen: number}} ref The page reference. Must have
  36588. * the 'num' and 'gen' properties.
  36589. * @return {Promise} A promise that is resolved with the page index that is
  36590. * associated with the reference.
  36591. */
  36592. getPageIndex: function PDFDocumentProxy_getPageIndex(ref) {
  36593. return this.transport.getPageIndex(ref);
  36594. },
  36595. /**
  36596. * @return {Promise} A promise that is resolved with a lookup table for
  36597. * mapping named destinations to reference numbers.
  36598. *
  36599. * This can be slow for large documents: use getDestination instead
  36600. */
  36601. getDestinations: function PDFDocumentProxy_getDestinations() {
  36602. return this.transport.getDestinations();
  36603. },
  36604. /**
  36605. * @param {string} id The named destination to get.
  36606. * @return {Promise} A promise that is resolved with all information
  36607. * of the given named destination.
  36608. */
  36609. getDestination: function PDFDocumentProxy_getDestination(id) {
  36610. return this.transport.getDestination(id);
  36611. },
  36612. /**
  36613. * @return {Promise} A promise that is resolved with:
  36614. * an Array containing the pageLabels that correspond to the pageIndexes,
  36615. * or `null` when no pageLabels are present in the PDF file.
  36616. */
  36617. getPageLabels: function PDFDocumentProxy_getPageLabels() {
  36618. return this.transport.getPageLabels();
  36619. },
  36620. /**
  36621. * @return {Promise} A promise that is resolved with a lookup table for
  36622. * mapping named attachments to their content.
  36623. */
  36624. getAttachments: function PDFDocumentProxy_getAttachments() {
  36625. return this.transport.getAttachments();
  36626. },
  36627. /**
  36628. * @return {Promise} A promise that is resolved with an array of all the
  36629. * JavaScript strings in the name tree.
  36630. */
  36631. getJavaScript: function PDFDocumentProxy_getJavaScript() {
  36632. return this.transport.getJavaScript();
  36633. },
  36634. /**
  36635. * @return {Promise} A promise that is resolved with an {Array} that is a
  36636. * tree outline (if it has one) of the PDF. The tree is in the format of:
  36637. * [
  36638. * {
  36639. * title: string,
  36640. * bold: boolean,
  36641. * italic: boolean,
  36642. * color: rgb Uint8Array,
  36643. * dest: dest obj,
  36644. * url: string,
  36645. * items: array of more items like this
  36646. * },
  36647. * ...
  36648. * ].
  36649. */
  36650. getOutline: function PDFDocumentProxy_getOutline() {
  36651. return this.transport.getOutline();
  36652. },
  36653. /**
  36654. * @return {Promise} A promise that is resolved with an {Object} that has
  36655. * info and metadata properties. Info is an {Object} filled with anything
  36656. * available in the information dictionary and similarly metadata is a
  36657. * {Metadata} object with information from the metadata section of the PDF.
  36658. */
  36659. getMetadata: function PDFDocumentProxy_getMetadata() {
  36660. return this.transport.getMetadata();
  36661. },
  36662. /**
  36663. * @return {Promise} A promise that is resolved with a TypedArray that has
  36664. * the raw data from the PDF.
  36665. */
  36666. getData: function PDFDocumentProxy_getData() {
  36667. return this.transport.getData();
  36668. },
  36669. /**
  36670. * @return {Promise} A promise that is resolved when the document's data
  36671. * is loaded. It is resolved with an {Object} that contains the length
  36672. * property that indicates size of the PDF data in bytes.
  36673. */
  36674. getDownloadInfo: function PDFDocumentProxy_getDownloadInfo() {
  36675. return this.transport.downloadInfoCapability.promise;
  36676. },
  36677. /**
  36678. * @return {Promise} A promise this is resolved with current stats about
  36679. * document structures (see {@link PDFDocumentStats}).
  36680. */
  36681. getStats: function PDFDocumentProxy_getStats() {
  36682. return this.transport.getStats();
  36683. },
  36684. /**
  36685. * Cleans up resources allocated by the document, e.g. created @font-face.
  36686. */
  36687. cleanup: function PDFDocumentProxy_cleanup() {
  36688. this.transport.startCleanup();
  36689. },
  36690. /**
  36691. * Destroys current document instance and terminates worker.
  36692. */
  36693. destroy: function PDFDocumentProxy_destroy() {
  36694. return this.loadingTask.destroy();
  36695. }
  36696. };
  36697. return PDFDocumentProxy;
  36698. })();
  36699. /**
  36700. * Page getTextContent parameters.
  36701. *
  36702. * @typedef {Object} getTextContentParameters
  36703. * @param {boolean} normalizeWhitespace - replaces all occurrences of
  36704. * whitespace with standard spaces (0x20). The default value is `false`.
  36705. */
  36706. /**
  36707. * Page text content.
  36708. *
  36709. * @typedef {Object} TextContent
  36710. * @property {array} items - array of {@link TextItem}
  36711. * @property {Object} styles - {@link TextStyles} objects, indexed by font
  36712. * name.
  36713. */
  36714. /**
  36715. * Page text content part.
  36716. *
  36717. * @typedef {Object} TextItem
  36718. * @property {string} str - text content.
  36719. * @property {string} dir - text direction: 'ttb', 'ltr' or 'rtl'.
  36720. * @property {array} transform - transformation matrix.
  36721. * @property {number} width - width in device space.
  36722. * @property {number} height - height in device space.
  36723. * @property {string} fontName - font name used by pdf.js for converted font.
  36724. */
  36725. /**
  36726. * Text style.
  36727. *
  36728. * @typedef {Object} TextStyle
  36729. * @property {number} ascent - font ascent.
  36730. * @property {number} descent - font descent.
  36731. * @property {boolean} vertical - text is in vertical mode.
  36732. * @property {string} fontFamily - possible font family
  36733. */
  36734. /**
  36735. * Page annotation parameters.
  36736. *
  36737. * @typedef {Object} GetAnnotationsParameters
  36738. * @param {string} intent - Determines the annotations that will be fetched,
  36739. * can be either 'display' (viewable annotations) or 'print'
  36740. * (printable annotations).
  36741. * If the parameter is omitted, all annotations are fetched.
  36742. */
  36743. /**
  36744. * Page render parameters.
  36745. *
  36746. * @typedef {Object} RenderParameters
  36747. * @property {Object} canvasContext - A 2D context of a DOM Canvas object.
  36748. * @property {PDFJS.PageViewport} viewport - Rendering viewport obtained by
  36749. * calling of PDFPage.getViewport method.
  36750. * @property {string} intent - Rendering intent, can be 'display' or 'print'
  36751. * (default value is 'display').
  36752. * @property {Array} transform - (optional) Additional transform, applied
  36753. * just before viewport transform.
  36754. * @property {Object} imageLayer - (optional) An object that has beginLayout,
  36755. * endLayout and appendImage functions.
  36756. * @property {function} continueCallback - (deprecated) A function that will be
  36757. * called each time the rendering is paused. To continue
  36758. * rendering call the function that is the first argument
  36759. * to the callback.
  36760. */
  36761. /**
  36762. * PDF page operator list.
  36763. *
  36764. * @typedef {Object} PDFOperatorList
  36765. * @property {Array} fnArray - Array containing the operator functions.
  36766. * @property {Array} argsArray - Array containing the arguments of the
  36767. * functions.
  36768. */
  36769. /**
  36770. * Proxy to a PDFPage in the worker thread.
  36771. * @class
  36772. * @alias PDFPageProxy
  36773. */
  36774. var PDFPageProxy = (function PDFPageProxyClosure() {
  36775. function PDFPageProxy(pageIndex, pageInfo, transport) {
  36776. this.pageIndex = pageIndex;
  36777. this.pageInfo = pageInfo;
  36778. this.transport = transport;
  36779. this.stats = new StatTimer();
  36780. this.stats.enabled = !!globalScope.PDFJS.enableStats;
  36781. this.commonObjs = transport.commonObjs;
  36782. this.objs = new PDFObjects();
  36783. this.cleanupAfterRender = false;
  36784. this.pendingCleanup = false;
  36785. this.intentStates = Object.create(null);
  36786. this.destroyed = false;
  36787. }
  36788. PDFPageProxy.prototype = /** @lends PDFPageProxy.prototype */ {
  36789. /**
  36790. * @return {number} Page number of the page. First page is 1.
  36791. */
  36792. get pageNumber() {
  36793. return this.pageIndex + 1;
  36794. },
  36795. /**
  36796. * @return {number} The number of degrees the page is rotated clockwise.
  36797. */
  36798. get rotate() {
  36799. return this.pageInfo.rotate;
  36800. },
  36801. /**
  36802. * @return {Object} The reference that points to this page. It has 'num' and
  36803. * 'gen' properties.
  36804. */
  36805. get ref() {
  36806. return this.pageInfo.ref;
  36807. },
  36808. /**
  36809. * @return {Array} An array of the visible portion of the PDF page in the
  36810. * user space units - [x1, y1, x2, y2].
  36811. */
  36812. get view() {
  36813. return this.pageInfo.view;
  36814. },
  36815. /**
  36816. * @param {number} scale The desired scale of the viewport.
  36817. * @param {number} rotate Degrees to rotate the viewport. If omitted this
  36818. * defaults to the page rotation.
  36819. * @return {PDFJS.PageViewport} Contains 'width' and 'height' properties
  36820. * along with transforms required for rendering.
  36821. */
  36822. getViewport: function PDFPageProxy_getViewport(scale, rotate) {
  36823. if (arguments.length < 2) {
  36824. rotate = this.rotate;
  36825. }
  36826. return new PDFJS.PageViewport(this.view, scale, rotate, 0, 0);
  36827. },
  36828. /**
  36829. * @param {GetAnnotationsParameters} params - Annotation parameters.
  36830. * @return {Promise} A promise that is resolved with an {Array} of the
  36831. * annotation objects.
  36832. */
  36833. getAnnotations: function PDFPageProxy_getAnnotations(params) {
  36834. var intent = (params && params.intent) || null;
  36835. if (!this.annotationsPromise || this.annotationsIntent !== intent) {
  36836. this.annotationsPromise = this.transport.getAnnotations(this.pageIndex,
  36837. intent);
  36838. this.annotationsIntent = intent;
  36839. }
  36840. return this.annotationsPromise;
  36841. },
  36842. /**
  36843. * Begins the process of rendering a page to the desired context.
  36844. * @param {RenderParameters} params Page render parameters.
  36845. * @return {RenderTask} An object that contains the promise, which
  36846. * is resolved when the page finishes rendering.
  36847. */
  36848. render: function PDFPageProxy_render(params) {
  36849. var stats = this.stats;
  36850. stats.time('Overall');
  36851. // If there was a pending destroy cancel it so no cleanup happens during
  36852. // this call to render.
  36853. this.pendingCleanup = false;
  36854. var renderingIntent = (params.intent === 'print' ? 'print' : 'display');
  36855. if (!this.intentStates[renderingIntent]) {
  36856. this.intentStates[renderingIntent] = Object.create(null);
  36857. }
  36858. var intentState = this.intentStates[renderingIntent];
  36859. // If there's no displayReadyCapability yet, then the operatorList
  36860. // was never requested before. Make the request and create the promise.
  36861. if (!intentState.displayReadyCapability) {
  36862. intentState.receivingOperatorList = true;
  36863. intentState.displayReadyCapability = createPromiseCapability();
  36864. intentState.operatorList = {
  36865. fnArray: [],
  36866. argsArray: [],
  36867. lastChunk: false
  36868. };
  36869. this.stats.time('Page Request');
  36870. this.transport.messageHandler.send('RenderPageRequest', {
  36871. pageIndex: this.pageNumber - 1,
  36872. intent: renderingIntent
  36873. });
  36874. }
  36875. var internalRenderTask = new InternalRenderTask(complete, params,
  36876. this.objs,
  36877. this.commonObjs,
  36878. intentState.operatorList,
  36879. this.pageNumber);
  36880. internalRenderTask.useRequestAnimationFrame = renderingIntent !== 'print';
  36881. if (!intentState.renderTasks) {
  36882. intentState.renderTasks = [];
  36883. }
  36884. intentState.renderTasks.push(internalRenderTask);
  36885. var renderTask = internalRenderTask.task;
  36886. // Obsolete parameter support
  36887. if (params.continueCallback) {
  36888. deprecated('render is used with continueCallback parameter');
  36889. renderTask.onContinue = params.continueCallback;
  36890. }
  36891. var self = this;
  36892. intentState.displayReadyCapability.promise.then(
  36893. function pageDisplayReadyPromise(transparency) {
  36894. if (self.pendingCleanup) {
  36895. complete();
  36896. return;
  36897. }
  36898. stats.time('Rendering');
  36899. internalRenderTask.initalizeGraphics(transparency);
  36900. internalRenderTask.operatorListChanged();
  36901. },
  36902. function pageDisplayReadPromiseError(reason) {
  36903. complete(reason);
  36904. }
  36905. );
  36906. function complete(error) {
  36907. var i = intentState.renderTasks.indexOf(internalRenderTask);
  36908. if (i >= 0) {
  36909. intentState.renderTasks.splice(i, 1);
  36910. }
  36911. if (self.cleanupAfterRender) {
  36912. self.pendingCleanup = true;
  36913. }
  36914. self._tryCleanup();
  36915. if (error) {
  36916. internalRenderTask.capability.reject(error);
  36917. } else {
  36918. internalRenderTask.capability.resolve();
  36919. }
  36920. stats.timeEnd('Rendering');
  36921. stats.timeEnd('Overall');
  36922. }
  36923. return renderTask;
  36924. },
  36925. /**
  36926. * @return {Promise} A promise resolved with an {@link PDFOperatorList}
  36927. * object that represents page's operator list.
  36928. */
  36929. getOperatorList: function PDFPageProxy_getOperatorList() {
  36930. function operatorListChanged() {
  36931. if (intentState.operatorList.lastChunk) {
  36932. intentState.opListReadCapability.resolve(intentState.operatorList);
  36933. var i = intentState.renderTasks.indexOf(opListTask);
  36934. if (i >= 0) {
  36935. intentState.renderTasks.splice(i, 1);
  36936. }
  36937. }
  36938. }
  36939. var renderingIntent = 'oplist';
  36940. if (!this.intentStates[renderingIntent]) {
  36941. this.intentStates[renderingIntent] = Object.create(null);
  36942. }
  36943. var intentState = this.intentStates[renderingIntent];
  36944. var opListTask;
  36945. if (!intentState.opListReadCapability) {
  36946. opListTask = {};
  36947. opListTask.operatorListChanged = operatorListChanged;
  36948. intentState.receivingOperatorList = true;
  36949. intentState.opListReadCapability = createPromiseCapability();
  36950. intentState.renderTasks = [];
  36951. intentState.renderTasks.push(opListTask);
  36952. intentState.operatorList = {
  36953. fnArray: [],
  36954. argsArray: [],
  36955. lastChunk: false
  36956. };
  36957. this.transport.messageHandler.send('RenderPageRequest', {
  36958. pageIndex: this.pageIndex,
  36959. intent: renderingIntent
  36960. });
  36961. }
  36962. return intentState.opListReadCapability.promise;
  36963. },
  36964. /**
  36965. * @param {getTextContentParameters} params - getTextContent parameters.
  36966. * @return {Promise} That is resolved a {@link TextContent}
  36967. * object that represent the page text content.
  36968. */
  36969. getTextContent: function PDFPageProxy_getTextContent(params) {
  36970. var normalizeWhitespace = (params && params.normalizeWhitespace) || false;
  36971. return this.transport.messageHandler.sendWithPromise('GetTextContent', {
  36972. pageIndex: this.pageNumber - 1,
  36973. normalizeWhitespace: normalizeWhitespace,
  36974. });
  36975. },
  36976. /**
  36977. * Destroys page object.
  36978. */
  36979. _destroy: function PDFPageProxy_destroy() {
  36980. this.destroyed = true;
  36981. this.transport.pageCache[this.pageIndex] = null;
  36982. var waitOn = [];
  36983. Object.keys(this.intentStates).forEach(function(intent) {
  36984. if (intent === 'oplist') {
  36985. // Avoid errors below, since the renderTasks are just stubs.
  36986. return;
  36987. }
  36988. var intentState = this.intentStates[intent];
  36989. intentState.renderTasks.forEach(function(renderTask) {
  36990. var renderCompleted = renderTask.capability.promise.
  36991. catch(function () {}); // ignoring failures
  36992. waitOn.push(renderCompleted);
  36993. renderTask.cancel();
  36994. });
  36995. }, this);
  36996. this.objs.clear();
  36997. this.annotationsPromise = null;
  36998. this.pendingCleanup = false;
  36999. return Promise.all(waitOn);
  37000. },
  37001. /**
  37002. * Cleans up resources allocated by the page. (deprecated)
  37003. */
  37004. destroy: function() {
  37005. deprecated('page destroy method, use cleanup() instead');
  37006. this.cleanup();
  37007. },
  37008. /**
  37009. * Cleans up resources allocated by the page.
  37010. */
  37011. cleanup: function PDFPageProxy_cleanup() {
  37012. this.pendingCleanup = true;
  37013. this._tryCleanup();
  37014. },
  37015. /**
  37016. * For internal use only. Attempts to clean up if rendering is in a state
  37017. * where that's possible.
  37018. * @ignore
  37019. */
  37020. _tryCleanup: function PDFPageProxy_tryCleanup() {
  37021. if (!this.pendingCleanup ||
  37022. Object.keys(this.intentStates).some(function(intent) {
  37023. var intentState = this.intentStates[intent];
  37024. return (intentState.renderTasks.length !== 0 ||
  37025. intentState.receivingOperatorList);
  37026. }, this)) {
  37027. return;
  37028. }
  37029. Object.keys(this.intentStates).forEach(function(intent) {
  37030. delete this.intentStates[intent];
  37031. }, this);
  37032. this.objs.clear();
  37033. this.annotationsPromise = null;
  37034. this.pendingCleanup = false;
  37035. },
  37036. /**
  37037. * For internal use only.
  37038. * @ignore
  37039. */
  37040. _startRenderPage: function PDFPageProxy_startRenderPage(transparency,
  37041. intent) {
  37042. var intentState = this.intentStates[intent];
  37043. // TODO Refactor RenderPageRequest to separate rendering
  37044. // and operator list logic
  37045. if (intentState.displayReadyCapability) {
  37046. intentState.displayReadyCapability.resolve(transparency);
  37047. }
  37048. },
  37049. /**
  37050. * For internal use only.
  37051. * @ignore
  37052. */
  37053. _renderPageChunk: function PDFPageProxy_renderPageChunk(operatorListChunk,
  37054. intent) {
  37055. var intentState = this.intentStates[intent];
  37056. var i, ii;
  37057. // Add the new chunk to the current operator list.
  37058. for (i = 0, ii = operatorListChunk.length; i < ii; i++) {
  37059. intentState.operatorList.fnArray.push(operatorListChunk.fnArray[i]);
  37060. intentState.operatorList.argsArray.push(
  37061. operatorListChunk.argsArray[i]);
  37062. }
  37063. intentState.operatorList.lastChunk = operatorListChunk.lastChunk;
  37064. // Notify all the rendering tasks there are more operators to be consumed.
  37065. for (i = 0; i < intentState.renderTasks.length; i++) {
  37066. intentState.renderTasks[i].operatorListChanged();
  37067. }
  37068. if (operatorListChunk.lastChunk) {
  37069. intentState.receivingOperatorList = false;
  37070. this._tryCleanup();
  37071. }
  37072. }
  37073. };
  37074. return PDFPageProxy;
  37075. })();
  37076. /**
  37077. * PDF.js web worker abstraction, it controls instantiation of PDF documents and
  37078. * WorkerTransport for them. If creation of a web worker is not possible,
  37079. * a "fake" worker will be used instead.
  37080. * @class
  37081. */
  37082. var PDFWorker = (function PDFWorkerClosure() {
  37083. var nextFakeWorkerId = 0;
  37084. function getWorkerSrc() {
  37085. if (PDFJS.workerSrc) {
  37086. return PDFJS.workerSrc;
  37087. }
  37088. if (pdfjsFilePath) {
  37089. return pdfjsFilePath.replace(/\.js$/i, '.worker.js');
  37090. }
  37091. error('No PDFJS.workerSrc specified');
  37092. }
  37093. var fakeWorkerFilesLoadedCapability;
  37094. // Loads worker code into main thread.
  37095. function setupFakeWorkerGlobal() {
  37096. var WorkerMessageHandler;
  37097. if (!fakeWorkerFilesLoadedCapability) {
  37098. fakeWorkerFilesLoadedCapability = createPromiseCapability();
  37099. // In the developer build load worker_loader which in turn loads all the
  37100. // other files and resolves the promise. In production only the
  37101. // pdf.worker.js file is needed.
  37102. WorkerMessageHandler = pdfjsLibs.pdfjsCoreWorker.WorkerMessageHandler;
  37103. fakeWorkerFilesLoadedCapability.resolve(WorkerMessageHandler);
  37104. }
  37105. return fakeWorkerFilesLoadedCapability.promise;
  37106. }
  37107. function createCDNWrapper(url) {
  37108. // We will rely on blob URL's property to specify origin.
  37109. // We want this function to fail in case if createObjectURL or Blob do not
  37110. // exist or fail for some reason -- our Worker creation will fail anyway.
  37111. var wrapper = 'importScripts(\'' + url + '\');';
  37112. return URL.createObjectURL(new Blob([wrapper]));
  37113. }
  37114. function PDFWorker(name) {
  37115. this.name = name;
  37116. this.destroyed = false;
  37117. this._readyCapability = createPromiseCapability();
  37118. this._port = null;
  37119. this._webWorker = null;
  37120. this._messageHandler = null;
  37121. this._initialize();
  37122. }
  37123. PDFWorker.prototype = /** @lends PDFWorker.prototype */ {
  37124. get promise() {
  37125. return this._readyCapability.promise;
  37126. },
  37127. get port() {
  37128. return this._port;
  37129. },
  37130. get messageHandler() {
  37131. return this._messageHandler;
  37132. },
  37133. _initialize: function PDFWorker_initialize() {
  37134. // If worker support isn't disabled explicit and the browser has worker
  37135. // support, create a new web worker and test if it/the browser fulfills
  37136. // all requirements to run parts of pdf.js in a web worker.
  37137. // Right now, the requirement is, that an Uint8Array is still an
  37138. // Uint8Array as it arrives on the worker. (Chrome added this with v.15.)
  37139. // Either workers are disabled, not supported or have thrown an exception.
  37140. // Thus, we fallback to a faked worker.
  37141. this._setupFakeWorker();
  37142. },
  37143. _setupFakeWorker: function PDFWorker_setupFakeWorker() {
  37144. if (!globalScope.PDFJS.disableWorker) {
  37145. warn('Setting up fake worker.');
  37146. globalScope.PDFJS.disableWorker = true;
  37147. }
  37148. setupFakeWorkerGlobal().then(function (WorkerMessageHandler) {
  37149. if (this.destroyed) {
  37150. this._readyCapability.reject(new Error('Worker was destroyed'));
  37151. return;
  37152. }
  37153. // If we don't use a worker, just post/sendMessage to the main thread.
  37154. var port = {
  37155. _listeners: [],
  37156. postMessage: function (obj) {
  37157. var e = {data: obj};
  37158. this._listeners.forEach(function (listener) {
  37159. listener.call(this, e);
  37160. }, this);
  37161. },
  37162. addEventListener: function (name, listener) {
  37163. this._listeners.push(listener);
  37164. },
  37165. removeEventListener: function (name, listener) {
  37166. var i = this._listeners.indexOf(listener);
  37167. this._listeners.splice(i, 1);
  37168. },
  37169. terminate: function () {}
  37170. };
  37171. this._port = port;
  37172. // All fake workers use the same port, making id unique.
  37173. var id = 'fake' + (nextFakeWorkerId++);
  37174. // If the main thread is our worker, setup the handling for the
  37175. // messages -- the main thread sends to it self.
  37176. var workerHandler = new MessageHandler(id + '_worker', id, port);
  37177. WorkerMessageHandler.setup(workerHandler, port);
  37178. var messageHandler = new MessageHandler(id, id + '_worker', port);
  37179. this._messageHandler = messageHandler;
  37180. this._readyCapability.resolve();
  37181. }.bind(this));
  37182. },
  37183. /**
  37184. * Destroys the worker instance.
  37185. */
  37186. destroy: function PDFWorker_destroy() {
  37187. this.destroyed = true;
  37188. if (this._webWorker) {
  37189. // We need to terminate only web worker created resource.
  37190. this._webWorker.terminate();
  37191. this._webWorker = null;
  37192. }
  37193. this._port = null;
  37194. if (this._messageHandler) {
  37195. this._messageHandler.destroy();
  37196. this._messageHandler = null;
  37197. }
  37198. }
  37199. };
  37200. return PDFWorker;
  37201. })();
  37202. PDFJS.PDFWorker = PDFWorker;
  37203. /**
  37204. * For internal use only.
  37205. * @ignore
  37206. */
  37207. var WorkerTransport = (function WorkerTransportClosure() {
  37208. function WorkerTransport(messageHandler, loadingTask, pdfDataRangeTransport) {
  37209. this.messageHandler = messageHandler;
  37210. this.loadingTask = loadingTask;
  37211. this.pdfDataRangeTransport = pdfDataRangeTransport;
  37212. this.commonObjs = new PDFObjects();
  37213. this.fontLoader = new FontLoader(loadingTask.docId);
  37214. this.destroyed = false;
  37215. this.destroyCapability = null;
  37216. this.pageCache = [];
  37217. this.pagePromises = [];
  37218. this.downloadInfoCapability = createPromiseCapability();
  37219. this.setupMessageHandler();
  37220. }
  37221. WorkerTransport.prototype = {
  37222. destroy: function WorkerTransport_destroy() {
  37223. if (this.destroyCapability) {
  37224. return this.destroyCapability.promise;
  37225. }
  37226. this.destroyed = true;
  37227. this.destroyCapability = createPromiseCapability();
  37228. var waitOn = [];
  37229. // We need to wait for all renderings to be completed, e.g.
  37230. // timeout/rAF can take a long time.
  37231. this.pageCache.forEach(function (page) {
  37232. if (page) {
  37233. waitOn.push(page._destroy());
  37234. }
  37235. });
  37236. this.pageCache = [];
  37237. this.pagePromises = [];
  37238. var self = this;
  37239. // We also need to wait for the worker to finish its long running tasks.
  37240. var terminated = this.messageHandler.sendWithPromise('Terminate', null);
  37241. waitOn.push(terminated);
  37242. Promise.all(waitOn).then(function () {
  37243. self.fontLoader.clear();
  37244. if (self.pdfDataRangeTransport) {
  37245. self.pdfDataRangeTransport.abort();
  37246. self.pdfDataRangeTransport = null;
  37247. }
  37248. if (self.messageHandler) {
  37249. self.messageHandler.destroy();
  37250. self.messageHandler = null;
  37251. }
  37252. self.destroyCapability.resolve();
  37253. }, this.destroyCapability.reject);
  37254. return this.destroyCapability.promise;
  37255. },
  37256. setupMessageHandler:
  37257. function WorkerTransport_setupMessageHandler() {
  37258. var messageHandler = this.messageHandler;
  37259. function updatePassword(password) {
  37260. messageHandler.send('UpdatePassword', password);
  37261. }
  37262. var pdfDataRangeTransport = this.pdfDataRangeTransport;
  37263. if (pdfDataRangeTransport) {
  37264. pdfDataRangeTransport.addRangeListener(function(begin, chunk) {
  37265. messageHandler.send('OnDataRange', {
  37266. begin: begin,
  37267. chunk: chunk
  37268. });
  37269. });
  37270. pdfDataRangeTransport.addProgressListener(function(loaded) {
  37271. messageHandler.send('OnDataProgress', {
  37272. loaded: loaded
  37273. });
  37274. });
  37275. pdfDataRangeTransport.addProgressiveReadListener(function(chunk) {
  37276. messageHandler.send('OnDataRange', {
  37277. chunk: chunk
  37278. });
  37279. });
  37280. messageHandler.on('RequestDataRange',
  37281. function transportDataRange(data) {
  37282. pdfDataRangeTransport.requestDataRange(data.begin, data.end);
  37283. }, this);
  37284. }
  37285. messageHandler.on('GetDoc', function transportDoc(data) {
  37286. var pdfInfo = data.pdfInfo;
  37287. this.numPages = data.pdfInfo.numPages;
  37288. var loadingTask = this.loadingTask;
  37289. var pdfDocument = new PDFDocumentProxy(pdfInfo, this, loadingTask);
  37290. this.pdfDocument = pdfDocument;
  37291. loadingTask._capability.resolve(pdfDocument);
  37292. }, this);
  37293. messageHandler.on('NeedPassword',
  37294. function transportNeedPassword(exception) {
  37295. var loadingTask = this.loadingTask;
  37296. if (loadingTask.onPassword) {
  37297. return loadingTask.onPassword(updatePassword,
  37298. PasswordResponses.NEED_PASSWORD);
  37299. }
  37300. loadingTask._capability.reject(
  37301. new PasswordException(exception.message, exception.code));
  37302. }, this);
  37303. messageHandler.on('IncorrectPassword',
  37304. function transportIncorrectPassword(exception) {
  37305. var loadingTask = this.loadingTask;
  37306. if (loadingTask.onPassword) {
  37307. return loadingTask.onPassword(updatePassword,
  37308. PasswordResponses.INCORRECT_PASSWORD);
  37309. }
  37310. loadingTask._capability.reject(
  37311. new PasswordException(exception.message, exception.code));
  37312. }, this);
  37313. messageHandler.on('InvalidPDF', function transportInvalidPDF(exception) {
  37314. this.loadingTask._capability.reject(
  37315. new InvalidPDFException(exception.message));
  37316. }, this);
  37317. messageHandler.on('MissingPDF', function transportMissingPDF(exception) {
  37318. this.loadingTask._capability.reject(
  37319. new MissingPDFException(exception.message));
  37320. }, this);
  37321. messageHandler.on('UnexpectedResponse',
  37322. function transportUnexpectedResponse(exception) {
  37323. this.loadingTask._capability.reject(
  37324. new UnexpectedResponseException(exception.message, exception.status));
  37325. }, this);
  37326. messageHandler.on('UnknownError',
  37327. function transportUnknownError(exception) {
  37328. this.loadingTask._capability.reject(
  37329. new UnknownErrorException(exception.message, exception.details));
  37330. }, this);
  37331. messageHandler.on('DataLoaded', function transportPage(data) {
  37332. this.downloadInfoCapability.resolve(data);
  37333. }, this);
  37334. messageHandler.on('PDFManagerReady', function transportPage(data) {
  37335. if (this.pdfDataRangeTransport) {
  37336. this.pdfDataRangeTransport.transportReady();
  37337. }
  37338. }, this);
  37339. messageHandler.on('StartRenderPage', function transportRender(data) {
  37340. if (this.destroyed) {
  37341. return; // Ignore any pending requests if the worker was terminated.
  37342. }
  37343. var page = this.pageCache[data.pageIndex];
  37344. page.stats.timeEnd('Page Request');
  37345. page._startRenderPage(data.transparency, data.intent);
  37346. }, this);
  37347. messageHandler.on('RenderPageChunk', function transportRender(data) {
  37348. if (this.destroyed) {
  37349. return; // Ignore any pending requests if the worker was terminated.
  37350. }
  37351. var page = this.pageCache[data.pageIndex];
  37352. page._renderPageChunk(data.operatorList, data.intent);
  37353. }, this);
  37354. messageHandler.on('commonobj', function transportObj(data) {
  37355. if (this.destroyed) {
  37356. return; // Ignore any pending requests if the worker was terminated.
  37357. }
  37358. var id = data[0];
  37359. var type = data[1];
  37360. if (this.commonObjs.hasData(id)) {
  37361. return;
  37362. }
  37363. switch (type) {
  37364. case 'Font':
  37365. var exportedData = data[2];
  37366. var font;
  37367. if ('error' in exportedData) {
  37368. var error = exportedData.error;
  37369. warn('Error during font loading: ' + error);
  37370. this.commonObjs.resolve(id, error);
  37371. break;
  37372. } else {
  37373. font = new FontFaceObject(exportedData);
  37374. }
  37375. this.fontLoader.bind(
  37376. [font],
  37377. function fontReady(fontObjs) {
  37378. this.commonObjs.resolve(id, font);
  37379. }.bind(this)
  37380. );
  37381. break;
  37382. case 'FontPath':
  37383. this.commonObjs.resolve(id, data[2]);
  37384. break;
  37385. default:
  37386. error('Got unknown common object type ' + type);
  37387. }
  37388. }, this);
  37389. messageHandler.on('obj', function transportObj(data) {
  37390. if (this.destroyed) {
  37391. return; // Ignore any pending requests if the worker was terminated.
  37392. }
  37393. var id = data[0];
  37394. var pageIndex = data[1];
  37395. var type = data[2];
  37396. var pageProxy = this.pageCache[pageIndex];
  37397. var imageData;
  37398. if (pageProxy.objs.hasData(id)) {
  37399. return;
  37400. }
  37401. switch (type) {
  37402. case 'JpegStream':
  37403. imageData = data[3];
  37404. loadJpegStream(id, imageData, pageProxy.objs);
  37405. break;
  37406. case 'Image':
  37407. imageData = data[3];
  37408. pageProxy.objs.resolve(id, imageData);
  37409. // heuristics that will allow not to store large data
  37410. var MAX_IMAGE_SIZE_TO_STORE = 8000000;
  37411. if (imageData && 'data' in imageData &&
  37412. imageData.data.length > MAX_IMAGE_SIZE_TO_STORE) {
  37413. pageProxy.cleanupAfterRender = true;
  37414. }
  37415. break;
  37416. default:
  37417. error('Got unknown object type ' + type);
  37418. }
  37419. }, this);
  37420. messageHandler.on('DocProgress', function transportDocProgress(data) {
  37421. if (this.destroyed) {
  37422. return; // Ignore any pending requests if the worker was terminated.
  37423. }
  37424. var loadingTask = this.loadingTask;
  37425. if (loadingTask.onProgress) {
  37426. loadingTask.onProgress({
  37427. loaded: data.loaded,
  37428. total: data.total
  37429. });
  37430. }
  37431. }, this);
  37432. messageHandler.on('PageError', function transportError(data) {
  37433. if (this.destroyed) {
  37434. return; // Ignore any pending requests if the worker was terminated.
  37435. }
  37436. var page = this.pageCache[data.pageNum - 1];
  37437. var intentState = page.intentStates[data.intent];
  37438. if (intentState.displayReadyCapability) {
  37439. intentState.displayReadyCapability.reject(data.error);
  37440. } else {
  37441. error(data.error);
  37442. }
  37443. if (intentState.operatorList) {
  37444. // Mark operator list as complete.
  37445. intentState.operatorList.lastChunk = true;
  37446. for (var i = 0; i < intentState.renderTasks.length; i++) {
  37447. intentState.renderTasks[i].operatorListChanged();
  37448. }
  37449. }
  37450. }, this);
  37451. messageHandler.on('UnsupportedFeature',
  37452. function transportUnsupportedFeature(data) {
  37453. if (this.destroyed) {
  37454. return; // Ignore any pending requests if the worker was terminated.
  37455. }
  37456. var featureId = data.featureId;
  37457. var loadingTask = this.loadingTask;
  37458. if (loadingTask.onUnsupportedFeature) {
  37459. loadingTask.onUnsupportedFeature(featureId);
  37460. }
  37461. PDFJS.UnsupportedManager.notify(featureId);
  37462. }, this);
  37463. messageHandler.on('JpegDecode', function(data) {
  37464. if (this.destroyed) {
  37465. return Promise.reject('Worker was terminated');
  37466. }
  37467. var imageUrl = data[0];
  37468. var components = data[1];
  37469. if (components !== 3 && components !== 1) {
  37470. return Promise.reject(
  37471. new Error('Only 3 components or 1 component can be returned'));
  37472. }
  37473. return new Promise(function (resolve, reject) {
  37474. var img = new Image();
  37475. img.onload = function () {
  37476. var width = img.width;
  37477. var height = img.height;
  37478. var size = width * height;
  37479. var rgbaLength = size * 4;
  37480. var buf = new Uint8Array(size * components);
  37481. var tmpCanvas = createScratchCanvas(width, height);
  37482. var tmpCtx = tmpCanvas.getContext('2d');
  37483. tmpCtx.drawImage(img, 0, 0);
  37484. var data = tmpCtx.getImageData(0, 0, width, height).data;
  37485. var i, j;
  37486. if (components === 3) {
  37487. for (i = 0, j = 0; i < rgbaLength; i += 4, j += 3) {
  37488. buf[j] = data[i];
  37489. buf[j + 1] = data[i + 1];
  37490. buf[j + 2] = data[i + 2];
  37491. }
  37492. } else if (components === 1) {
  37493. for (i = 0, j = 0; i < rgbaLength; i += 4, j++) {
  37494. buf[j] = data[i];
  37495. }
  37496. }
  37497. resolve({ data: buf, width: width, height: height});
  37498. };
  37499. img.onerror = function () {
  37500. reject(new Error('JpegDecode failed to load image'));
  37501. };
  37502. img.src = imageUrl;
  37503. });
  37504. }, this);
  37505. },
  37506. getData: function WorkerTransport_getData() {
  37507. return this.messageHandler.sendWithPromise('GetData', null);
  37508. },
  37509. getPage: function WorkerTransport_getPage(pageNumber, capability) {
  37510. if (pageNumber <= 0 || pageNumber > this.numPages ||
  37511. (pageNumber|0) !== pageNumber) {
  37512. return Promise.reject(new Error('Invalid page request'));
  37513. }
  37514. var pageIndex = pageNumber - 1;
  37515. if (pageIndex in this.pagePromises) {
  37516. return this.pagePromises[pageIndex];
  37517. }
  37518. var promise = this.messageHandler.sendWithPromise('GetPage', {
  37519. pageIndex: pageIndex
  37520. }).then(function (pageInfo) {
  37521. if (this.destroyed) {
  37522. throw new Error('Transport destroyed');
  37523. }
  37524. var page = new PDFPageProxy(pageIndex, pageInfo, this);
  37525. this.pageCache[pageIndex] = page;
  37526. return page;
  37527. }.bind(this));
  37528. this.pagePromises[pageIndex] = promise;
  37529. return promise;
  37530. },
  37531. getPageIndex: function WorkerTransport_getPageIndexByRef(ref) {
  37532. return this.messageHandler.sendWithPromise('GetPageIndex', { ref: ref });
  37533. },
  37534. getAnnotations: function WorkerTransport_getAnnotations(pageIndex, intent) {
  37535. return this.messageHandler.sendWithPromise('GetAnnotations', {
  37536. pageIndex: pageIndex,
  37537. intent: intent,
  37538. });
  37539. },
  37540. getDestinations: function WorkerTransport_getDestinations() {
  37541. return this.messageHandler.sendWithPromise('GetDestinations', null);
  37542. },
  37543. getDestination: function WorkerTransport_getDestination(id) {
  37544. return this.messageHandler.sendWithPromise('GetDestination', { id: id });
  37545. },
  37546. getPageLabels: function WorkerTransport_getPageLabels() {
  37547. return this.messageHandler.sendWithPromise('GetPageLabels', null);
  37548. },
  37549. getAttachments: function WorkerTransport_getAttachments() {
  37550. return this.messageHandler.sendWithPromise('GetAttachments', null);
  37551. },
  37552. getJavaScript: function WorkerTransport_getJavaScript() {
  37553. return this.messageHandler.sendWithPromise('GetJavaScript', null);
  37554. },
  37555. getOutline: function WorkerTransport_getOutline() {
  37556. return this.messageHandler.sendWithPromise('GetOutline', null);
  37557. },
  37558. getMetadata: function WorkerTransport_getMetadata() {
  37559. return this.messageHandler.sendWithPromise('GetMetadata', null).
  37560. then(function transportMetadata(results) {
  37561. return {
  37562. info: results[0],
  37563. metadata: (results[1] ? new Metadata(results[1]) : null)
  37564. };
  37565. });
  37566. },
  37567. getStats: function WorkerTransport_getStats() {
  37568. return this.messageHandler.sendWithPromise('GetStats', null);
  37569. },
  37570. startCleanup: function WorkerTransport_startCleanup() {
  37571. this.messageHandler.sendWithPromise('Cleanup', null).
  37572. then(function endCleanup() {
  37573. for (var i = 0, ii = this.pageCache.length; i < ii; i++) {
  37574. var page = this.pageCache[i];
  37575. if (page) {
  37576. page.cleanup();
  37577. }
  37578. }
  37579. this.commonObjs.clear();
  37580. this.fontLoader.clear();
  37581. }.bind(this));
  37582. }
  37583. };
  37584. return WorkerTransport;
  37585. })();
  37586. /**
  37587. * A PDF document and page is built of many objects. E.g. there are objects
  37588. * for fonts, images, rendering code and such. These objects might get processed
  37589. * inside of a worker. The `PDFObjects` implements some basic functions to
  37590. * manage these objects.
  37591. * @ignore
  37592. */
  37593. var PDFObjects = (function PDFObjectsClosure() {
  37594. function PDFObjects() {
  37595. this.objs = Object.create(null);
  37596. }
  37597. PDFObjects.prototype = {
  37598. /**
  37599. * Internal function.
  37600. * Ensures there is an object defined for `objId`.
  37601. */
  37602. ensureObj: function PDFObjects_ensureObj(objId) {
  37603. if (this.objs[objId]) {
  37604. return this.objs[objId];
  37605. }
  37606. var obj = {
  37607. capability: createPromiseCapability(),
  37608. data: null,
  37609. resolved: false
  37610. };
  37611. this.objs[objId] = obj;
  37612. return obj;
  37613. },
  37614. /**
  37615. * If called *without* callback, this returns the data of `objId` but the
  37616. * object needs to be resolved. If it isn't, this function throws.
  37617. *
  37618. * If called *with* a callback, the callback is called with the data of the
  37619. * object once the object is resolved. That means, if you call this
  37620. * function and the object is already resolved, the callback gets called
  37621. * right away.
  37622. */
  37623. get: function PDFObjects_get(objId, callback) {
  37624. // If there is a callback, then the get can be async and the object is
  37625. // not required to be resolved right now
  37626. if (callback) {
  37627. this.ensureObj(objId).capability.promise.then(callback);
  37628. return null;
  37629. }
  37630. // If there isn't a callback, the user expects to get the resolved data
  37631. // directly.
  37632. var obj = this.objs[objId];
  37633. // If there isn't an object yet or the object isn't resolved, then the
  37634. // data isn't ready yet!
  37635. if (!obj || !obj.resolved) {
  37636. error('Requesting object that isn\'t resolved yet ' + objId);
  37637. }
  37638. return obj.data;
  37639. },
  37640. /**
  37641. * Resolves the object `objId` with optional `data`.
  37642. */
  37643. resolve: function PDFObjects_resolve(objId, data) {
  37644. var obj = this.ensureObj(objId);
  37645. obj.resolved = true;
  37646. obj.data = data;
  37647. obj.capability.resolve(data);
  37648. },
  37649. isResolved: function PDFObjects_isResolved(objId) {
  37650. var objs = this.objs;
  37651. if (!objs[objId]) {
  37652. return false;
  37653. } else {
  37654. return objs[objId].resolved;
  37655. }
  37656. },
  37657. hasData: function PDFObjects_hasData(objId) {
  37658. return this.isResolved(objId);
  37659. },
  37660. /**
  37661. * Returns the data of `objId` if object exists, null otherwise.
  37662. */
  37663. getData: function PDFObjects_getData(objId) {
  37664. var objs = this.objs;
  37665. if (!objs[objId] || !objs[objId].resolved) {
  37666. return null;
  37667. } else {
  37668. return objs[objId].data;
  37669. }
  37670. },
  37671. clear: function PDFObjects_clear() {
  37672. this.objs = Object.create(null);
  37673. }
  37674. };
  37675. return PDFObjects;
  37676. })();
  37677. /**
  37678. * Allows controlling of the rendering tasks.
  37679. * @class
  37680. * @alias RenderTask
  37681. */
  37682. var RenderTask = (function RenderTaskClosure() {
  37683. function RenderTask(internalRenderTask) {
  37684. this._internalRenderTask = internalRenderTask;
  37685. /**
  37686. * Callback for incremental rendering -- a function that will be called
  37687. * each time the rendering is paused. To continue rendering call the
  37688. * function that is the first argument to the callback.
  37689. * @type {function}
  37690. */
  37691. this.onContinue = null;
  37692. }
  37693. RenderTask.prototype = /** @lends RenderTask.prototype */ {
  37694. /**
  37695. * Promise for rendering task completion.
  37696. * @return {Promise}
  37697. */
  37698. get promise() {
  37699. return this._internalRenderTask.capability.promise;
  37700. },
  37701. /**
  37702. * Cancels the rendering task. If the task is currently rendering it will
  37703. * not be cancelled until graphics pauses with a timeout. The promise that
  37704. * this object extends will resolved when cancelled.
  37705. */
  37706. cancel: function RenderTask_cancel() {
  37707. this._internalRenderTask.cancel();
  37708. },
  37709. /**
  37710. * Registers callbacks to indicate the rendering task completion.
  37711. *
  37712. * @param {function} onFulfilled The callback for the rendering completion.
  37713. * @param {function} onRejected The callback for the rendering failure.
  37714. * @return {Promise} A promise that is resolved after the onFulfilled or
  37715. * onRejected callback.
  37716. */
  37717. then: function RenderTask_then(onFulfilled, onRejected) {
  37718. return this.promise.then.apply(this.promise, arguments);
  37719. }
  37720. };
  37721. return RenderTask;
  37722. })();
  37723. /**
  37724. * For internal use only.
  37725. * @ignore
  37726. */
  37727. var InternalRenderTask = (function InternalRenderTaskClosure() {
  37728. function InternalRenderTask(callback, params, objs, commonObjs, operatorList,
  37729. pageNumber) {
  37730. this.callback = callback;
  37731. this.params = params;
  37732. this.objs = objs;
  37733. this.commonObjs = commonObjs;
  37734. this.operatorListIdx = null;
  37735. this.operatorList = operatorList;
  37736. this.pageNumber = pageNumber;
  37737. this.running = false;
  37738. this.graphicsReadyCallback = null;
  37739. this.graphicsReady = false;
  37740. this.useRequestAnimationFrame = false;
  37741. this.cancelled = false;
  37742. this.capability = createPromiseCapability();
  37743. this.task = new RenderTask(this);
  37744. // caching this-bound methods
  37745. this._continueBound = this._continue.bind(this);
  37746. this._scheduleNextBound = this._scheduleNext.bind(this);
  37747. this._nextBound = this._next.bind(this);
  37748. }
  37749. InternalRenderTask.prototype = {
  37750. initalizeGraphics:
  37751. function InternalRenderTask_initalizeGraphics(transparency) {
  37752. if (this.cancelled) {
  37753. return;
  37754. }
  37755. if (PDFJS.pdfBug && 'StepperManager' in globalScope &&
  37756. globalScope.StepperManager.enabled) {
  37757. this.stepper = globalScope.StepperManager.create(this.pageNumber - 1);
  37758. this.stepper.init(this.operatorList);
  37759. this.stepper.nextBreakPoint = this.stepper.getNextBreakPoint();
  37760. }
  37761. var params = this.params;
  37762. this.gfx = new CanvasGraphics(params.canvasContext, this.commonObjs,
  37763. this.objs, params.imageLayer);
  37764. this.gfx.beginDrawing(params.transform, params.viewport, transparency);
  37765. this.operatorListIdx = 0;
  37766. this.graphicsReady = true;
  37767. if (this.graphicsReadyCallback) {
  37768. this.graphicsReadyCallback();
  37769. }
  37770. },
  37771. cancel: function InternalRenderTask_cancel() {
  37772. this.running = false;
  37773. this.cancelled = true;
  37774. this.callback('cancelled');
  37775. },
  37776. operatorListChanged: function InternalRenderTask_operatorListChanged() {
  37777. if (!this.graphicsReady) {
  37778. if (!this.graphicsReadyCallback) {
  37779. this.graphicsReadyCallback = this._continueBound;
  37780. }
  37781. return;
  37782. }
  37783. if (this.stepper) {
  37784. this.stepper.updateOperatorList(this.operatorList);
  37785. }
  37786. if (this.running) {
  37787. return;
  37788. }
  37789. this._continue();
  37790. },
  37791. _continue: function InternalRenderTask__continue() {
  37792. this.running = true;
  37793. if (this.cancelled) {
  37794. return;
  37795. }
  37796. if (this.task.onContinue) {
  37797. this.task.onContinue.call(this.task, this._scheduleNextBound);
  37798. } else {
  37799. this._scheduleNext();
  37800. }
  37801. },
  37802. _scheduleNext: function InternalRenderTask__scheduleNext() {
  37803. if (this.useRequestAnimationFrame) {
  37804. window.requestAnimationFrame(this._nextBound);
  37805. } else {
  37806. Promise.resolve(undefined).then(this._nextBound);
  37807. }
  37808. },
  37809. _next: function InternalRenderTask__next() {
  37810. if (this.cancelled) {
  37811. return;
  37812. }
  37813. this.operatorListIdx = this.gfx.executeOperatorList(this.operatorList,
  37814. this.operatorListIdx,
  37815. this._continueBound,
  37816. this.stepper);
  37817. if (this.operatorListIdx === this.operatorList.argsArray.length) {
  37818. this.running = false;
  37819. if (this.operatorList.lastChunk) {
  37820. this.gfx.endDrawing();
  37821. this.callback();
  37822. }
  37823. }
  37824. }
  37825. };
  37826. return InternalRenderTask;
  37827. })();
  37828. /**
  37829. * (Deprecated) Global observer of unsupported feature usages. Use
  37830. * onUnsupportedFeature callback of the {PDFDocumentLoadingTask} instance.
  37831. */
  37832. PDFJS.UnsupportedManager = (function UnsupportedManagerClosure() {
  37833. var listeners = [];
  37834. return {
  37835. listen: function (cb) {
  37836. deprecated('Global UnsupportedManager.listen is used: ' +
  37837. ' use PDFDocumentLoadingTask.onUnsupportedFeature instead');
  37838. listeners.push(cb);
  37839. },
  37840. notify: function (featureId) {
  37841. for (var i = 0, ii = listeners.length; i < ii; i++) {
  37842. listeners[i](featureId);
  37843. }
  37844. }
  37845. };
  37846. })();
  37847. exports.getDocument = PDFJS.getDocument;
  37848. exports.PDFDataRangeTransport = PDFDataRangeTransport;
  37849. exports.PDFDocumentProxy = PDFDocumentProxy;
  37850. exports.PDFPageProxy = PDFPageProxy;
  37851. }));
  37852. (function (root, factory) {
  37853. {
  37854. factory((root.pdfjsCoreColorSpace = {}), root.pdfjsSharedUtil,
  37855. root.pdfjsCorePrimitives, root.pdfjsCoreFunction);
  37856. }
  37857. }(this, function (exports, sharedUtil, corePrimitives, coreFunction) {
  37858. var error = sharedUtil.error;
  37859. var info = sharedUtil.info;
  37860. var isArray = sharedUtil.isArray;
  37861. var isString = sharedUtil.isString;
  37862. var shadow = sharedUtil.shadow;
  37863. var warn = sharedUtil.warn;
  37864. var isDict = corePrimitives.isDict;
  37865. var isName = corePrimitives.isName;
  37866. var isStream = corePrimitives.isStream;
  37867. var PDFFunction = coreFunction.PDFFunction;
  37868. var coreImage; // see _setCoreImage below
  37869. var PDFImage; // = coreImage.PDFImage;
  37870. var ColorSpace = (function ColorSpaceClosure() {
  37871. // Constructor should define this.numComps, this.defaultColor, this.name
  37872. function ColorSpace() {
  37873. error('should not call ColorSpace constructor');
  37874. }
  37875. ColorSpace.prototype = {
  37876. /**
  37877. * Converts the color value to the RGB color. The color components are
  37878. * located in the src array starting from the srcOffset. Returns the array
  37879. * of the rgb components, each value ranging from [0,255].
  37880. */
  37881. getRgb: function ColorSpace_getRgb(src, srcOffset) {
  37882. var rgb = new Uint8Array(3);
  37883. this.getRgbItem(src, srcOffset, rgb, 0);
  37884. return rgb;
  37885. },
  37886. /**
  37887. * Converts the color value to the RGB color, similar to the getRgb method.
  37888. * The result placed into the dest array starting from the destOffset.
  37889. */
  37890. getRgbItem: function ColorSpace_getRgbItem(src, srcOffset,
  37891. dest, destOffset) {
  37892. error('Should not call ColorSpace.getRgbItem');
  37893. },
  37894. /**
  37895. * Converts the specified number of the color values to the RGB colors.
  37896. * The colors are located in the src array starting from the srcOffset.
  37897. * The result is placed into the dest array starting from the destOffset.
  37898. * The src array items shall be in [0,2^bits) range, the dest array items
  37899. * will be in [0,255] range. alpha01 indicates how many alpha components
  37900. * there are in the dest array; it will be either 0 (RGB array) or 1 (RGBA
  37901. * array).
  37902. */
  37903. getRgbBuffer: function ColorSpace_getRgbBuffer(src, srcOffset, count,
  37904. dest, destOffset, bits,
  37905. alpha01) {
  37906. error('Should not call ColorSpace.getRgbBuffer');
  37907. },
  37908. /**
  37909. * Determines the number of bytes required to store the result of the
  37910. * conversion done by the getRgbBuffer method. As in getRgbBuffer,
  37911. * |alpha01| is either 0 (RGB output) or 1 (RGBA output).
  37912. */
  37913. getOutputLength: function ColorSpace_getOutputLength(inputLength,
  37914. alpha01) {
  37915. error('Should not call ColorSpace.getOutputLength');
  37916. },
  37917. /**
  37918. * Returns true if source data will be equal the result/output data.
  37919. */
  37920. isPassthrough: function ColorSpace_isPassthrough(bits) {
  37921. return false;
  37922. },
  37923. /**
  37924. * Fills in the RGB colors in the destination buffer. alpha01 indicates
  37925. * how many alpha components there are in the dest array; it will be either
  37926. * 0 (RGB array) or 1 (RGBA array).
  37927. */
  37928. fillRgb: function ColorSpace_fillRgb(dest, originalWidth,
  37929. originalHeight, width, height,
  37930. actualHeight, bpc, comps, alpha01) {
  37931. var count = originalWidth * originalHeight;
  37932. var rgbBuf = null;
  37933. var numComponentColors = 1 << bpc;
  37934. var needsResizing = originalHeight !== height || originalWidth !== width;
  37935. var i, ii;
  37936. if (this.isPassthrough(bpc)) {
  37937. rgbBuf = comps;
  37938. } else if (this.numComps === 1 && count > numComponentColors &&
  37939. this.name !== 'DeviceGray' && this.name !== 'DeviceRGB') {
  37940. // Optimization: create a color map when there is just one component and
  37941. // we are converting more colors than the size of the color map. We
  37942. // don't build the map if the colorspace is gray or rgb since those
  37943. // methods are faster than building a map. This mainly offers big speed
  37944. // ups for indexed and alternate colorspaces.
  37945. //
  37946. // TODO it may be worth while to cache the color map. While running
  37947. // testing I never hit a cache so I will leave that out for now (perhaps
  37948. // we are reparsing colorspaces too much?).
  37949. var allColors = bpc <= 8 ? new Uint8Array(numComponentColors) :
  37950. new Uint16Array(numComponentColors);
  37951. var key;
  37952. for (i = 0; i < numComponentColors; i++) {
  37953. allColors[i] = i;
  37954. }
  37955. var colorMap = new Uint8Array(numComponentColors * 3);
  37956. this.getRgbBuffer(allColors, 0, numComponentColors, colorMap, 0, bpc,
  37957. /* alpha01 = */ 0);
  37958. var destPos, rgbPos;
  37959. if (!needsResizing) {
  37960. // Fill in the RGB values directly into |dest|.
  37961. destPos = 0;
  37962. for (i = 0; i < count; ++i) {
  37963. key = comps[i] * 3;
  37964. dest[destPos++] = colorMap[key];
  37965. dest[destPos++] = colorMap[key + 1];
  37966. dest[destPos++] = colorMap[key + 2];
  37967. destPos += alpha01;
  37968. }
  37969. } else {
  37970. rgbBuf = new Uint8Array(count * 3);
  37971. rgbPos = 0;
  37972. for (i = 0; i < count; ++i) {
  37973. key = comps[i] * 3;
  37974. rgbBuf[rgbPos++] = colorMap[key];
  37975. rgbBuf[rgbPos++] = colorMap[key + 1];
  37976. rgbBuf[rgbPos++] = colorMap[key + 2];
  37977. }
  37978. }
  37979. } else {
  37980. if (!needsResizing) {
  37981. // Fill in the RGB values directly into |dest|.
  37982. this.getRgbBuffer(comps, 0, width * actualHeight, dest, 0, bpc,
  37983. alpha01);
  37984. } else {
  37985. rgbBuf = new Uint8Array(count * 3);
  37986. this.getRgbBuffer(comps, 0, count, rgbBuf, 0, bpc,
  37987. /* alpha01 = */ 0);
  37988. }
  37989. }
  37990. if (rgbBuf) {
  37991. if (needsResizing) {
  37992. PDFImage.resize(rgbBuf, bpc, 3, originalWidth, originalHeight, width,
  37993. height, dest, alpha01);
  37994. } else {
  37995. rgbPos = 0;
  37996. destPos = 0;
  37997. for (i = 0, ii = width * actualHeight; i < ii; i++) {
  37998. dest[destPos++] = rgbBuf[rgbPos++];
  37999. dest[destPos++] = rgbBuf[rgbPos++];
  38000. dest[destPos++] = rgbBuf[rgbPos++];
  38001. destPos += alpha01;
  38002. }
  38003. }
  38004. }
  38005. },
  38006. /**
  38007. * True if the colorspace has components in the default range of [0, 1].
  38008. * This should be true for all colorspaces except for lab color spaces
  38009. * which are [0,100], [-128, 127], [-128, 127].
  38010. */
  38011. usesZeroToOneRange: true
  38012. };
  38013. ColorSpace.parse = function ColorSpace_parse(cs, xref, res) {
  38014. var IR = ColorSpace.parseToIR(cs, xref, res);
  38015. if (IR instanceof AlternateCS) {
  38016. return IR;
  38017. }
  38018. return ColorSpace.fromIR(IR);
  38019. };
  38020. ColorSpace.fromIR = function ColorSpace_fromIR(IR) {
  38021. var name = isArray(IR) ? IR[0] : IR;
  38022. var whitePoint, blackPoint, gamma;
  38023. switch (name) {
  38024. case 'DeviceGrayCS':
  38025. return this.singletons.gray;
  38026. case 'DeviceRgbCS':
  38027. return this.singletons.rgb;
  38028. case 'DeviceCmykCS':
  38029. return this.singletons.cmyk;
  38030. case 'CalGrayCS':
  38031. whitePoint = IR[1];
  38032. blackPoint = IR[2];
  38033. gamma = IR[3];
  38034. return new CalGrayCS(whitePoint, blackPoint, gamma);
  38035. case 'CalRGBCS':
  38036. whitePoint = IR[1];
  38037. blackPoint = IR[2];
  38038. gamma = IR[3];
  38039. var matrix = IR[4];
  38040. return new CalRGBCS(whitePoint, blackPoint, gamma, matrix);
  38041. case 'PatternCS':
  38042. var basePatternCS = IR[1];
  38043. if (basePatternCS) {
  38044. basePatternCS = ColorSpace.fromIR(basePatternCS);
  38045. }
  38046. return new PatternCS(basePatternCS);
  38047. case 'IndexedCS':
  38048. var baseIndexedCS = IR[1];
  38049. var hiVal = IR[2];
  38050. var lookup = IR[3];
  38051. return new IndexedCS(ColorSpace.fromIR(baseIndexedCS), hiVal, lookup);
  38052. case 'AlternateCS':
  38053. var numComps = IR[1];
  38054. var alt = IR[2];
  38055. var tintFnIR = IR[3];
  38056. return new AlternateCS(numComps, ColorSpace.fromIR(alt),
  38057. PDFFunction.fromIR(tintFnIR));
  38058. case 'LabCS':
  38059. whitePoint = IR[1];
  38060. blackPoint = IR[2];
  38061. var range = IR[3];
  38062. return new LabCS(whitePoint, blackPoint, range);
  38063. default:
  38064. error('Unknown name ' + name);
  38065. }
  38066. return null;
  38067. };
  38068. ColorSpace.parseToIR = function ColorSpace_parseToIR(cs, xref, res) {
  38069. if (isName(cs)) {
  38070. var colorSpaces = res.get('ColorSpace');
  38071. if (isDict(colorSpaces)) {
  38072. var refcs = colorSpaces.get(cs.name);
  38073. if (refcs) {
  38074. cs = refcs;
  38075. }
  38076. }
  38077. }
  38078. cs = xref.fetchIfRef(cs);
  38079. var mode;
  38080. if (isName(cs)) {
  38081. mode = cs.name;
  38082. this.mode = mode;
  38083. switch (mode) {
  38084. case 'DeviceGray':
  38085. case 'G':
  38086. return 'DeviceGrayCS';
  38087. case 'DeviceRGB':
  38088. case 'RGB':
  38089. return 'DeviceRgbCS';
  38090. case 'DeviceCMYK':
  38091. case 'CMYK':
  38092. return 'DeviceCmykCS';
  38093. case 'Pattern':
  38094. return ['PatternCS', null];
  38095. default:
  38096. error('unrecognized colorspace ' + mode);
  38097. }
  38098. } else if (isArray(cs)) {
  38099. mode = xref.fetchIfRef(cs[0]).name;
  38100. this.mode = mode;
  38101. var numComps, params, alt, whitePoint, blackPoint, gamma;
  38102. switch (mode) {
  38103. case 'DeviceGray':
  38104. case 'G':
  38105. return 'DeviceGrayCS';
  38106. case 'DeviceRGB':
  38107. case 'RGB':
  38108. return 'DeviceRgbCS';
  38109. case 'DeviceCMYK':
  38110. case 'CMYK':
  38111. return 'DeviceCmykCS';
  38112. case 'CalGray':
  38113. params = xref.fetchIfRef(cs[1]);
  38114. whitePoint = params.get('WhitePoint');
  38115. blackPoint = params.get('BlackPoint');
  38116. gamma = params.get('Gamma');
  38117. return ['CalGrayCS', whitePoint, blackPoint, gamma];
  38118. case 'CalRGB':
  38119. params = xref.fetchIfRef(cs[1]);
  38120. whitePoint = params.get('WhitePoint');
  38121. blackPoint = params.get('BlackPoint');
  38122. gamma = params.get('Gamma');
  38123. var matrix = params.get('Matrix');
  38124. return ['CalRGBCS', whitePoint, blackPoint, gamma, matrix];
  38125. case 'ICCBased':
  38126. var stream = xref.fetchIfRef(cs[1]);
  38127. var dict = stream.dict;
  38128. numComps = dict.get('N');
  38129. alt = dict.get('Alternate');
  38130. if (alt) {
  38131. var altIR = ColorSpace.parseToIR(alt, xref, res);
  38132. // Parse the /Alternate CS to ensure that the number of components
  38133. // are correct, and also (indirectly) that it is not a PatternCS.
  38134. var altCS = ColorSpace.fromIR(altIR);
  38135. if (altCS.numComps === numComps) {
  38136. return altIR;
  38137. }
  38138. warn('ICCBased color space: Ignoring incorrect /Alternate entry.');
  38139. }
  38140. if (numComps === 1) {
  38141. return 'DeviceGrayCS';
  38142. } else if (numComps === 3) {
  38143. return 'DeviceRgbCS';
  38144. } else if (numComps === 4) {
  38145. return 'DeviceCmykCS';
  38146. }
  38147. break;
  38148. case 'Pattern':
  38149. var basePatternCS = cs[1] || null;
  38150. if (basePatternCS) {
  38151. basePatternCS = ColorSpace.parseToIR(basePatternCS, xref, res);
  38152. }
  38153. return ['PatternCS', basePatternCS];
  38154. case 'Indexed':
  38155. case 'I':
  38156. var baseIndexedCS = ColorSpace.parseToIR(cs[1], xref, res);
  38157. var hiVal = xref.fetchIfRef(cs[2]) + 1;
  38158. var lookup = xref.fetchIfRef(cs[3]);
  38159. if (isStream(lookup)) {
  38160. lookup = lookup.getBytes();
  38161. }
  38162. return ['IndexedCS', baseIndexedCS, hiVal, lookup];
  38163. case 'Separation':
  38164. case 'DeviceN':
  38165. var name = xref.fetchIfRef(cs[1]);
  38166. numComps = 1;
  38167. if (isName(name)) {
  38168. numComps = 1;
  38169. } else if (isArray(name)) {
  38170. numComps = name.length;
  38171. }
  38172. alt = ColorSpace.parseToIR(cs[2], xref, res);
  38173. var tintFnIR = PDFFunction.getIR(xref, xref.fetchIfRef(cs[3]));
  38174. return ['AlternateCS', numComps, alt, tintFnIR];
  38175. case 'Lab':
  38176. params = xref.fetchIfRef(cs[1]);
  38177. whitePoint = params.get('WhitePoint');
  38178. blackPoint = params.get('BlackPoint');
  38179. var range = params.get('Range');
  38180. return ['LabCS', whitePoint, blackPoint, range];
  38181. default:
  38182. error('unimplemented color space object "' + mode + '"');
  38183. }
  38184. } else {
  38185. error('unrecognized color space object: "' + cs + '"');
  38186. }
  38187. return null;
  38188. };
  38189. /**
  38190. * Checks if a decode map matches the default decode map for a color space.
  38191. * This handles the general decode maps where there are two values per
  38192. * component. e.g. [0, 1, 0, 1, 0, 1] for a RGB color.
  38193. * This does not handle Lab, Indexed, or Pattern decode maps since they are
  38194. * slightly different.
  38195. * @param {Array} decode Decode map (usually from an image).
  38196. * @param {Number} n Number of components the color space has.
  38197. */
  38198. ColorSpace.isDefaultDecode = function ColorSpace_isDefaultDecode(decode, n) {
  38199. if (!isArray(decode)) {
  38200. return true;
  38201. }
  38202. if (n * 2 !== decode.length) {
  38203. warn('The decode map is not the correct length');
  38204. return true;
  38205. }
  38206. for (var i = 0, ii = decode.length; i < ii; i += 2) {
  38207. if (decode[i] !== 0 || decode[i + 1] !== 1) {
  38208. return false;
  38209. }
  38210. }
  38211. return true;
  38212. };
  38213. ColorSpace.singletons = {
  38214. get gray() {
  38215. return shadow(this, 'gray', new DeviceGrayCS());
  38216. },
  38217. get rgb() {
  38218. return shadow(this, 'rgb', new DeviceRgbCS());
  38219. },
  38220. get cmyk() {
  38221. return shadow(this, 'cmyk', new DeviceCmykCS());
  38222. }
  38223. };
  38224. return ColorSpace;
  38225. })();
  38226. /**
  38227. * Alternate color space handles both Separation and DeviceN color spaces. A
  38228. * Separation color space is actually just a DeviceN with one color component.
  38229. * Both color spaces use a tinting function to convert colors to a base color
  38230. * space.
  38231. */
  38232. var AlternateCS = (function AlternateCSClosure() {
  38233. function AlternateCS(numComps, base, tintFn) {
  38234. this.name = 'Alternate';
  38235. this.numComps = numComps;
  38236. this.defaultColor = new Float32Array(numComps);
  38237. for (var i = 0; i < numComps; ++i) {
  38238. this.defaultColor[i] = 1;
  38239. }
  38240. this.base = base;
  38241. this.tintFn = tintFn;
  38242. this.tmpBuf = new Float32Array(base.numComps);
  38243. }
  38244. AlternateCS.prototype = {
  38245. getRgb: ColorSpace.prototype.getRgb,
  38246. getRgbItem: function AlternateCS_getRgbItem(src, srcOffset,
  38247. dest, destOffset) {
  38248. var tmpBuf = this.tmpBuf;
  38249. this.tintFn(src, srcOffset, tmpBuf, 0);
  38250. this.base.getRgbItem(tmpBuf, 0, dest, destOffset);
  38251. },
  38252. getRgbBuffer: function AlternateCS_getRgbBuffer(src, srcOffset, count,
  38253. dest, destOffset, bits,
  38254. alpha01) {
  38255. var tintFn = this.tintFn;
  38256. var base = this.base;
  38257. var scale = 1 / ((1 << bits) - 1);
  38258. var baseNumComps = base.numComps;
  38259. var usesZeroToOneRange = base.usesZeroToOneRange;
  38260. var isPassthrough = (base.isPassthrough(8) || !usesZeroToOneRange) &&
  38261. alpha01 === 0;
  38262. var pos = isPassthrough ? destOffset : 0;
  38263. var baseBuf = isPassthrough ? dest : new Uint8Array(baseNumComps * count);
  38264. var numComps = this.numComps;
  38265. var scaled = new Float32Array(numComps);
  38266. var tinted = new Float32Array(baseNumComps);
  38267. var i, j;
  38268. if (usesZeroToOneRange) {
  38269. for (i = 0; i < count; i++) {
  38270. for (j = 0; j < numComps; j++) {
  38271. scaled[j] = src[srcOffset++] * scale;
  38272. }
  38273. tintFn(scaled, 0, tinted, 0);
  38274. for (j = 0; j < baseNumComps; j++) {
  38275. baseBuf[pos++] = tinted[j] * 255;
  38276. }
  38277. }
  38278. } else {
  38279. for (i = 0; i < count; i++) {
  38280. for (j = 0; j < numComps; j++) {
  38281. scaled[j] = src[srcOffset++] * scale;
  38282. }
  38283. tintFn(scaled, 0, tinted, 0);
  38284. base.getRgbItem(tinted, 0, baseBuf, pos);
  38285. pos += baseNumComps;
  38286. }
  38287. }
  38288. if (!isPassthrough) {
  38289. base.getRgbBuffer(baseBuf, 0, count, dest, destOffset, 8, alpha01);
  38290. }
  38291. },
  38292. getOutputLength: function AlternateCS_getOutputLength(inputLength,
  38293. alpha01) {
  38294. return this.base.getOutputLength(inputLength *
  38295. this.base.numComps / this.numComps,
  38296. alpha01);
  38297. },
  38298. isPassthrough: ColorSpace.prototype.isPassthrough,
  38299. fillRgb: ColorSpace.prototype.fillRgb,
  38300. isDefaultDecode: function AlternateCS_isDefaultDecode(decodeMap) {
  38301. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38302. },
  38303. usesZeroToOneRange: true
  38304. };
  38305. return AlternateCS;
  38306. })();
  38307. var PatternCS = (function PatternCSClosure() {
  38308. function PatternCS(baseCS) {
  38309. this.name = 'Pattern';
  38310. this.base = baseCS;
  38311. }
  38312. PatternCS.prototype = {};
  38313. return PatternCS;
  38314. })();
  38315. var IndexedCS = (function IndexedCSClosure() {
  38316. function IndexedCS(base, highVal, lookup) {
  38317. this.name = 'Indexed';
  38318. this.numComps = 1;
  38319. this.defaultColor = new Uint8Array([0]);
  38320. this.base = base;
  38321. this.highVal = highVal;
  38322. var baseNumComps = base.numComps;
  38323. var length = baseNumComps * highVal;
  38324. var lookupArray;
  38325. if (isStream(lookup)) {
  38326. lookupArray = new Uint8Array(length);
  38327. var bytes = lookup.getBytes(length);
  38328. lookupArray.set(bytes);
  38329. } else if (isString(lookup)) {
  38330. lookupArray = new Uint8Array(length);
  38331. for (var i = 0; i < length; ++i) {
  38332. lookupArray[i] = lookup.charCodeAt(i);
  38333. }
  38334. } else if (lookup instanceof Uint8Array || lookup instanceof Array) {
  38335. lookupArray = lookup;
  38336. } else {
  38337. error('Unrecognized lookup table: ' + lookup);
  38338. }
  38339. this.lookup = lookupArray;
  38340. }
  38341. IndexedCS.prototype = {
  38342. getRgb: ColorSpace.prototype.getRgb,
  38343. getRgbItem: function IndexedCS_getRgbItem(src, srcOffset,
  38344. dest, destOffset) {
  38345. var numComps = this.base.numComps;
  38346. var start = src[srcOffset] * numComps;
  38347. this.base.getRgbItem(this.lookup, start, dest, destOffset);
  38348. },
  38349. getRgbBuffer: function IndexedCS_getRgbBuffer(src, srcOffset, count,
  38350. dest, destOffset, bits,
  38351. alpha01) {
  38352. var base = this.base;
  38353. var numComps = base.numComps;
  38354. var outputDelta = base.getOutputLength(numComps, alpha01);
  38355. var lookup = this.lookup;
  38356. for (var i = 0; i < count; ++i) {
  38357. var lookupPos = src[srcOffset++] * numComps;
  38358. base.getRgbBuffer(lookup, lookupPos, 1, dest, destOffset, 8, alpha01);
  38359. destOffset += outputDelta;
  38360. }
  38361. },
  38362. getOutputLength: function IndexedCS_getOutputLength(inputLength, alpha01) {
  38363. return this.base.getOutputLength(inputLength * this.base.numComps,
  38364. alpha01);
  38365. },
  38366. isPassthrough: ColorSpace.prototype.isPassthrough,
  38367. fillRgb: ColorSpace.prototype.fillRgb,
  38368. isDefaultDecode: function IndexedCS_isDefaultDecode(decodeMap) {
  38369. // indexed color maps shouldn't be changed
  38370. return true;
  38371. },
  38372. usesZeroToOneRange: true
  38373. };
  38374. return IndexedCS;
  38375. })();
  38376. var DeviceGrayCS = (function DeviceGrayCSClosure() {
  38377. function DeviceGrayCS() {
  38378. this.name = 'DeviceGray';
  38379. this.numComps = 1;
  38380. this.defaultColor = new Float32Array([0]);
  38381. }
  38382. DeviceGrayCS.prototype = {
  38383. getRgb: ColorSpace.prototype.getRgb,
  38384. getRgbItem: function DeviceGrayCS_getRgbItem(src, srcOffset,
  38385. dest, destOffset) {
  38386. var c = (src[srcOffset] * 255) | 0;
  38387. c = c < 0 ? 0 : c > 255 ? 255 : c;
  38388. dest[destOffset] = dest[destOffset + 1] = dest[destOffset + 2] = c;
  38389. },
  38390. getRgbBuffer: function DeviceGrayCS_getRgbBuffer(src, srcOffset, count,
  38391. dest, destOffset, bits,
  38392. alpha01) {
  38393. var scale = 255 / ((1 << bits) - 1);
  38394. var j = srcOffset, q = destOffset;
  38395. for (var i = 0; i < count; ++i) {
  38396. var c = (scale * src[j++]) | 0;
  38397. dest[q++] = c;
  38398. dest[q++] = c;
  38399. dest[q++] = c;
  38400. q += alpha01;
  38401. }
  38402. },
  38403. getOutputLength: function DeviceGrayCS_getOutputLength(inputLength,
  38404. alpha01) {
  38405. return inputLength * (3 + alpha01);
  38406. },
  38407. isPassthrough: ColorSpace.prototype.isPassthrough,
  38408. fillRgb: ColorSpace.prototype.fillRgb,
  38409. isDefaultDecode: function DeviceGrayCS_isDefaultDecode(decodeMap) {
  38410. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38411. },
  38412. usesZeroToOneRange: true
  38413. };
  38414. return DeviceGrayCS;
  38415. })();
  38416. var DeviceRgbCS = (function DeviceRgbCSClosure() {
  38417. function DeviceRgbCS() {
  38418. this.name = 'DeviceRGB';
  38419. this.numComps = 3;
  38420. this.defaultColor = new Float32Array([0, 0, 0]);
  38421. }
  38422. DeviceRgbCS.prototype = {
  38423. getRgb: ColorSpace.prototype.getRgb,
  38424. getRgbItem: function DeviceRgbCS_getRgbItem(src, srcOffset,
  38425. dest, destOffset) {
  38426. var r = (src[srcOffset] * 255) | 0;
  38427. var g = (src[srcOffset + 1] * 255) | 0;
  38428. var b = (src[srcOffset + 2] * 255) | 0;
  38429. dest[destOffset] = r < 0 ? 0 : r > 255 ? 255 : r;
  38430. dest[destOffset + 1] = g < 0 ? 0 : g > 255 ? 255 : g;
  38431. dest[destOffset + 2] = b < 0 ? 0 : b > 255 ? 255 : b;
  38432. },
  38433. getRgbBuffer: function DeviceRgbCS_getRgbBuffer(src, srcOffset, count,
  38434. dest, destOffset, bits,
  38435. alpha01) {
  38436. if (bits === 8 && alpha01 === 0) {
  38437. dest.set(src.subarray(srcOffset, srcOffset + count * 3), destOffset);
  38438. return;
  38439. }
  38440. var scale = 255 / ((1 << bits) - 1);
  38441. var j = srcOffset, q = destOffset;
  38442. for (var i = 0; i < count; ++i) {
  38443. dest[q++] = (scale * src[j++]) | 0;
  38444. dest[q++] = (scale * src[j++]) | 0;
  38445. dest[q++] = (scale * src[j++]) | 0;
  38446. q += alpha01;
  38447. }
  38448. },
  38449. getOutputLength: function DeviceRgbCS_getOutputLength(inputLength,
  38450. alpha01) {
  38451. return (inputLength * (3 + alpha01) / 3) | 0;
  38452. },
  38453. isPassthrough: function DeviceRgbCS_isPassthrough(bits) {
  38454. return bits === 8;
  38455. },
  38456. fillRgb: ColorSpace.prototype.fillRgb,
  38457. isDefaultDecode: function DeviceRgbCS_isDefaultDecode(decodeMap) {
  38458. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38459. },
  38460. usesZeroToOneRange: true
  38461. };
  38462. return DeviceRgbCS;
  38463. })();
  38464. var DeviceCmykCS = (function DeviceCmykCSClosure() {
  38465. // The coefficients below was found using numerical analysis: the method of
  38466. // steepest descent for the sum((f_i - color_value_i)^2) for r/g/b colors,
  38467. // where color_value is the tabular value from the table of sampled RGB colors
  38468. // from CMYK US Web Coated (SWOP) colorspace, and f_i is the corresponding
  38469. // CMYK color conversion using the estimation below:
  38470. // f(A, B,.. N) = Acc+Bcm+Ccy+Dck+c+Fmm+Gmy+Hmk+Im+Jyy+Kyk+Ly+Mkk+Nk+255
  38471. function convertToRgb(src, srcOffset, srcScale, dest, destOffset) {
  38472. var c = src[srcOffset + 0] * srcScale;
  38473. var m = src[srcOffset + 1] * srcScale;
  38474. var y = src[srcOffset + 2] * srcScale;
  38475. var k = src[srcOffset + 3] * srcScale;
  38476. var r =
  38477. (c * (-4.387332384609988 * c + 54.48615194189176 * m +
  38478. 18.82290502165302 * y + 212.25662451639585 * k +
  38479. -285.2331026137004) +
  38480. m * (1.7149763477362134 * m - 5.6096736904047315 * y +
  38481. -17.873870861415444 * k - 5.497006427196366) +
  38482. y * (-2.5217340131683033 * y - 21.248923337353073 * k +
  38483. 17.5119270841813) +
  38484. k * (-21.86122147463605 * k - 189.48180835922747) + 255) | 0;
  38485. var g =
  38486. (c * (8.841041422036149 * c + 60.118027045597366 * m +
  38487. 6.871425592049007 * y + 31.159100130055922 * k +
  38488. -79.2970844816548) +
  38489. m * (-15.310361306967817 * m + 17.575251261109482 * y +
  38490. 131.35250912493976 * k - 190.9453302588951) +
  38491. y * (4.444339102852739 * y + 9.8632861493405 * k - 24.86741582555878) +
  38492. k * (-20.737325471181034 * k - 187.80453709719578) + 255) | 0;
  38493. var b =
  38494. (c * (0.8842522430003296 * c + 8.078677503112928 * m +
  38495. 30.89978309703729 * y - 0.23883238689178934 * k +
  38496. -14.183576799673286) +
  38497. m * (10.49593273432072 * m + 63.02378494754052 * y +
  38498. 50.606957656360734 * k - 112.23884253719248) +
  38499. y * (0.03296041114873217 * y + 115.60384449646641 * k +
  38500. -193.58209356861505) +
  38501. k * (-22.33816807309886 * k - 180.12613974708367) + 255) | 0;
  38502. dest[destOffset] = r > 255 ? 255 : r < 0 ? 0 : r;
  38503. dest[destOffset + 1] = g > 255 ? 255 : g < 0 ? 0 : g;
  38504. dest[destOffset + 2] = b > 255 ? 255 : b < 0 ? 0 : b;
  38505. }
  38506. function DeviceCmykCS() {
  38507. this.name = 'DeviceCMYK';
  38508. this.numComps = 4;
  38509. this.defaultColor = new Float32Array([0, 0, 0, 1]);
  38510. }
  38511. DeviceCmykCS.prototype = {
  38512. getRgb: ColorSpace.prototype.getRgb,
  38513. getRgbItem: function DeviceCmykCS_getRgbItem(src, srcOffset,
  38514. dest, destOffset) {
  38515. convertToRgb(src, srcOffset, 1, dest, destOffset);
  38516. },
  38517. getRgbBuffer: function DeviceCmykCS_getRgbBuffer(src, srcOffset, count,
  38518. dest, destOffset, bits,
  38519. alpha01) {
  38520. var scale = 1 / ((1 << bits) - 1);
  38521. for (var i = 0; i < count; i++) {
  38522. convertToRgb(src, srcOffset, scale, dest, destOffset);
  38523. srcOffset += 4;
  38524. destOffset += 3 + alpha01;
  38525. }
  38526. },
  38527. getOutputLength: function DeviceCmykCS_getOutputLength(inputLength,
  38528. alpha01) {
  38529. return (inputLength / 4 * (3 + alpha01)) | 0;
  38530. },
  38531. isPassthrough: ColorSpace.prototype.isPassthrough,
  38532. fillRgb: ColorSpace.prototype.fillRgb,
  38533. isDefaultDecode: function DeviceCmykCS_isDefaultDecode(decodeMap) {
  38534. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38535. },
  38536. usesZeroToOneRange: true
  38537. };
  38538. return DeviceCmykCS;
  38539. })();
  38540. //
  38541. // CalGrayCS: Based on "PDF Reference, Sixth Ed", p.245
  38542. //
  38543. var CalGrayCS = (function CalGrayCSClosure() {
  38544. function CalGrayCS(whitePoint, blackPoint, gamma) {
  38545. this.name = 'CalGray';
  38546. this.numComps = 1;
  38547. this.defaultColor = new Float32Array([0]);
  38548. if (!whitePoint) {
  38549. error('WhitePoint missing - required for color space CalGray');
  38550. }
  38551. blackPoint = blackPoint || [0, 0, 0];
  38552. gamma = gamma || 1;
  38553. // Translate arguments to spec variables.
  38554. this.XW = whitePoint[0];
  38555. this.YW = whitePoint[1];
  38556. this.ZW = whitePoint[2];
  38557. this.XB = blackPoint[0];
  38558. this.YB = blackPoint[1];
  38559. this.ZB = blackPoint[2];
  38560. this.G = gamma;
  38561. // Validate variables as per spec.
  38562. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38563. error('Invalid WhitePoint components for ' + this.name +
  38564. ', no fallback available');
  38565. }
  38566. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38567. info('Invalid BlackPoint for ' + this.name + ', falling back to default');
  38568. this.XB = this.YB = this.ZB = 0;
  38569. }
  38570. if (this.XB !== 0 || this.YB !== 0 || this.ZB !== 0) {
  38571. warn(this.name + ', BlackPoint: XB: ' + this.XB + ', YB: ' + this.YB +
  38572. ', ZB: ' + this.ZB + ', only default values are supported.');
  38573. }
  38574. if (this.G < 1) {
  38575. info('Invalid Gamma: ' + this.G + ' for ' + this.name +
  38576. ', falling back to default');
  38577. this.G = 1;
  38578. }
  38579. }
  38580. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38581. // A represents a gray component of a calibrated gray space.
  38582. // A <---> AG in the spec
  38583. var A = src[srcOffset] * scale;
  38584. var AG = Math.pow(A, cs.G);
  38585. // Computes L as per spec. ( = cs.YW * AG )
  38586. // Except if other than default BlackPoint values are used.
  38587. var L = cs.YW * AG;
  38588. // http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html, Ch 4.
  38589. // Convert values to rgb range [0, 255].
  38590. var val = Math.max(295.8 * Math.pow(L, 0.333333333333333333) - 40.8, 0) | 0;
  38591. dest[destOffset] = val;
  38592. dest[destOffset + 1] = val;
  38593. dest[destOffset + 2] = val;
  38594. }
  38595. CalGrayCS.prototype = {
  38596. getRgb: ColorSpace.prototype.getRgb,
  38597. getRgbItem: function CalGrayCS_getRgbItem(src, srcOffset,
  38598. dest, destOffset) {
  38599. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38600. },
  38601. getRgbBuffer: function CalGrayCS_getRgbBuffer(src, srcOffset, count,
  38602. dest, destOffset, bits,
  38603. alpha01) {
  38604. var scale = 1 / ((1 << bits) - 1);
  38605. for (var i = 0; i < count; ++i) {
  38606. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38607. srcOffset += 1;
  38608. destOffset += 3 + alpha01;
  38609. }
  38610. },
  38611. getOutputLength: function CalGrayCS_getOutputLength(inputLength, alpha01) {
  38612. return inputLength * (3 + alpha01);
  38613. },
  38614. isPassthrough: ColorSpace.prototype.isPassthrough,
  38615. fillRgb: ColorSpace.prototype.fillRgb,
  38616. isDefaultDecode: function CalGrayCS_isDefaultDecode(decodeMap) {
  38617. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38618. },
  38619. usesZeroToOneRange: true
  38620. };
  38621. return CalGrayCS;
  38622. })();
  38623. //
  38624. // CalRGBCS: Based on "PDF Reference, Sixth Ed", p.247
  38625. //
  38626. var CalRGBCS = (function CalRGBCSClosure() {
  38627. // See http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html for these
  38628. // matrices.
  38629. var BRADFORD_SCALE_MATRIX = new Float32Array([
  38630. 0.8951, 0.2664, -0.1614,
  38631. -0.7502, 1.7135, 0.0367,
  38632. 0.0389, -0.0685, 1.0296]);
  38633. var BRADFORD_SCALE_INVERSE_MATRIX = new Float32Array([
  38634. 0.9869929, -0.1470543, 0.1599627,
  38635. 0.4323053, 0.5183603, 0.0492912,
  38636. -0.0085287, 0.0400428, 0.9684867]);
  38637. // See http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html.
  38638. var SRGB_D65_XYZ_TO_RGB_MATRIX = new Float32Array([
  38639. 3.2404542, -1.5371385, -0.4985314,
  38640. -0.9692660, 1.8760108, 0.0415560,
  38641. 0.0556434, -0.2040259, 1.0572252]);
  38642. var FLAT_WHITEPOINT_MATRIX = new Float32Array([1, 1, 1]);
  38643. var tempNormalizeMatrix = new Float32Array(3);
  38644. var tempConvertMatrix1 = new Float32Array(3);
  38645. var tempConvertMatrix2 = new Float32Array(3);
  38646. var DECODE_L_CONSTANT = Math.pow(((8 + 16) / 116), 3) / 8.0;
  38647. function CalRGBCS(whitePoint, blackPoint, gamma, matrix) {
  38648. this.name = 'CalRGB';
  38649. this.numComps = 3;
  38650. this.defaultColor = new Float32Array(3);
  38651. if (!whitePoint) {
  38652. error('WhitePoint missing - required for color space CalRGB');
  38653. }
  38654. blackPoint = blackPoint || new Float32Array(3);
  38655. gamma = gamma || new Float32Array([1, 1, 1]);
  38656. matrix = matrix || new Float32Array([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  38657. // Translate arguments to spec variables.
  38658. var XW = whitePoint[0];
  38659. var YW = whitePoint[1];
  38660. var ZW = whitePoint[2];
  38661. this.whitePoint = whitePoint;
  38662. var XB = blackPoint[0];
  38663. var YB = blackPoint[1];
  38664. var ZB = blackPoint[2];
  38665. this.blackPoint = blackPoint;
  38666. this.GR = gamma[0];
  38667. this.GG = gamma[1];
  38668. this.GB = gamma[2];
  38669. this.MXA = matrix[0];
  38670. this.MYA = matrix[1];
  38671. this.MZA = matrix[2];
  38672. this.MXB = matrix[3];
  38673. this.MYB = matrix[4];
  38674. this.MZB = matrix[5];
  38675. this.MXC = matrix[6];
  38676. this.MYC = matrix[7];
  38677. this.MZC = matrix[8];
  38678. // Validate variables as per spec.
  38679. if (XW < 0 || ZW < 0 || YW !== 1) {
  38680. error('Invalid WhitePoint components for ' + this.name +
  38681. ', no fallback available');
  38682. }
  38683. if (XB < 0 || YB < 0 || ZB < 0) {
  38684. info('Invalid BlackPoint for ' + this.name + ' [' + XB + ', ' + YB +
  38685. ', ' + ZB + '], falling back to default');
  38686. this.blackPoint = new Float32Array(3);
  38687. }
  38688. if (this.GR < 0 || this.GG < 0 || this.GB < 0) {
  38689. info('Invalid Gamma [' + this.GR + ', ' + this.GG + ', ' + this.GB +
  38690. '] for ' + this.name + ', falling back to default');
  38691. this.GR = this.GG = this.GB = 1;
  38692. }
  38693. if (this.MXA < 0 || this.MYA < 0 || this.MZA < 0 ||
  38694. this.MXB < 0 || this.MYB < 0 || this.MZB < 0 ||
  38695. this.MXC < 0 || this.MYC < 0 || this.MZC < 0) {
  38696. info('Invalid Matrix for ' + this.name + ' [' +
  38697. this.MXA + ', ' + this.MYA + ', ' + this.MZA +
  38698. this.MXB + ', ' + this.MYB + ', ' + this.MZB +
  38699. this.MXC + ', ' + this.MYC + ', ' + this.MZC +
  38700. '], falling back to default');
  38701. this.MXA = this.MYB = this.MZC = 1;
  38702. this.MXB = this.MYA = this.MZA = this.MXC = this.MYC = this.MZB = 0;
  38703. }
  38704. }
  38705. function matrixProduct(a, b, result) {
  38706. result[0] = a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  38707. result[1] = a[3] * b[0] + a[4] * b[1] + a[5] * b[2];
  38708. result[2] = a[6] * b[0] + a[7] * b[1] + a[8] * b[2];
  38709. }
  38710. function convertToFlat(sourceWhitePoint, LMS, result) {
  38711. result[0] = LMS[0] * 1 / sourceWhitePoint[0];
  38712. result[1] = LMS[1] * 1 / sourceWhitePoint[1];
  38713. result[2] = LMS[2] * 1 / sourceWhitePoint[2];
  38714. }
  38715. function convertToD65(sourceWhitePoint, LMS, result) {
  38716. var D65X = 0.95047;
  38717. var D65Y = 1;
  38718. var D65Z = 1.08883;
  38719. result[0] = LMS[0] * D65X / sourceWhitePoint[0];
  38720. result[1] = LMS[1] * D65Y / sourceWhitePoint[1];
  38721. result[2] = LMS[2] * D65Z / sourceWhitePoint[2];
  38722. }
  38723. function sRGBTransferFunction(color) {
  38724. // See http://en.wikipedia.org/wiki/SRGB.
  38725. if (color <= 0.0031308){
  38726. return adjustToRange(0, 1, 12.92 * color);
  38727. }
  38728. return adjustToRange(0, 1, (1 + 0.055) * Math.pow(color, 1 / 2.4) - 0.055);
  38729. }
  38730. function adjustToRange(min, max, value) {
  38731. return Math.max(min, Math.min(max, value));
  38732. }
  38733. function decodeL(L) {
  38734. if (L < 0) {
  38735. return -decodeL(-L);
  38736. }
  38737. if (L > 8.0) {
  38738. return Math.pow(((L + 16) / 116), 3);
  38739. }
  38740. return L * DECODE_L_CONSTANT;
  38741. }
  38742. function compensateBlackPoint(sourceBlackPoint, XYZ_Flat, result) {
  38743. // In case the blackPoint is already the default blackPoint then there is
  38744. // no need to do compensation.
  38745. if (sourceBlackPoint[0] === 0 &&
  38746. sourceBlackPoint[1] === 0 &&
  38747. sourceBlackPoint[2] === 0) {
  38748. result[0] = XYZ_Flat[0];
  38749. result[1] = XYZ_Flat[1];
  38750. result[2] = XYZ_Flat[2];
  38751. return;
  38752. }
  38753. // For the blackPoint calculation details, please see
  38754. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38755. // AdobeBPC.pdf.
  38756. // The destination blackPoint is the default blackPoint [0, 0, 0].
  38757. var zeroDecodeL = decodeL(0);
  38758. var X_DST = zeroDecodeL;
  38759. var X_SRC = decodeL(sourceBlackPoint[0]);
  38760. var Y_DST = zeroDecodeL;
  38761. var Y_SRC = decodeL(sourceBlackPoint[1]);
  38762. var Z_DST = zeroDecodeL;
  38763. var Z_SRC = decodeL(sourceBlackPoint[2]);
  38764. var X_Scale = (1 - X_DST) / (1 - X_SRC);
  38765. var X_Offset = 1 - X_Scale;
  38766. var Y_Scale = (1 - Y_DST) / (1 - Y_SRC);
  38767. var Y_Offset = 1 - Y_Scale;
  38768. var Z_Scale = (1 - Z_DST) / (1 - Z_SRC);
  38769. var Z_Offset = 1 - Z_Scale;
  38770. result[0] = XYZ_Flat[0] * X_Scale + X_Offset;
  38771. result[1] = XYZ_Flat[1] * Y_Scale + Y_Offset;
  38772. result[2] = XYZ_Flat[2] * Z_Scale + Z_Offset;
  38773. }
  38774. function normalizeWhitePointToFlat(sourceWhitePoint, XYZ_In, result) {
  38775. // In case the whitePoint is already flat then there is no need to do
  38776. // normalization.
  38777. if (sourceWhitePoint[0] === 1 && sourceWhitePoint[2] === 1) {
  38778. result[0] = XYZ_In[0];
  38779. result[1] = XYZ_In[1];
  38780. result[2] = XYZ_In[2];
  38781. return;
  38782. }
  38783. var LMS = result;
  38784. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38785. var LMS_Flat = tempNormalizeMatrix;
  38786. convertToFlat(sourceWhitePoint, LMS, LMS_Flat);
  38787. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_Flat, result);
  38788. }
  38789. function normalizeWhitePointToD65(sourceWhitePoint, XYZ_In, result) {
  38790. var LMS = result;
  38791. matrixProduct(BRADFORD_SCALE_MATRIX, XYZ_In, LMS);
  38792. var LMS_D65 = tempNormalizeMatrix;
  38793. convertToD65(sourceWhitePoint, LMS, LMS_D65);
  38794. matrixProduct(BRADFORD_SCALE_INVERSE_MATRIX, LMS_D65, result);
  38795. }
  38796. function convertToRgb(cs, src, srcOffset, dest, destOffset, scale) {
  38797. // A, B and C represent a red, green and blue components of a calibrated
  38798. // rgb space.
  38799. var A = adjustToRange(0, 1, src[srcOffset] * scale);
  38800. var B = adjustToRange(0, 1, src[srcOffset + 1] * scale);
  38801. var C = adjustToRange(0, 1, src[srcOffset + 2] * scale);
  38802. // A <---> AGR in the spec
  38803. // B <---> BGG in the spec
  38804. // C <---> CGB in the spec
  38805. var AGR = Math.pow(A, cs.GR);
  38806. var BGG = Math.pow(B, cs.GG);
  38807. var CGB = Math.pow(C, cs.GB);
  38808. // Computes intermediate variables L, M, N as per spec.
  38809. // To decode X, Y, Z values map L, M, N directly to them.
  38810. var X = cs.MXA * AGR + cs.MXB * BGG + cs.MXC * CGB;
  38811. var Y = cs.MYA * AGR + cs.MYB * BGG + cs.MYC * CGB;
  38812. var Z = cs.MZA * AGR + cs.MZB * BGG + cs.MZC * CGB;
  38813. // The following calculations are based on this document:
  38814. // http://www.adobe.com/content/dam/Adobe/en/devnet/photoshop/sdk/
  38815. // AdobeBPC.pdf.
  38816. var XYZ = tempConvertMatrix1;
  38817. XYZ[0] = X;
  38818. XYZ[1] = Y;
  38819. XYZ[2] = Z;
  38820. var XYZ_Flat = tempConvertMatrix2;
  38821. normalizeWhitePointToFlat(cs.whitePoint, XYZ, XYZ_Flat);
  38822. var XYZ_Black = tempConvertMatrix1;
  38823. compensateBlackPoint(cs.blackPoint, XYZ_Flat, XYZ_Black);
  38824. var XYZ_D65 = tempConvertMatrix2;
  38825. normalizeWhitePointToD65(FLAT_WHITEPOINT_MATRIX, XYZ_Black, XYZ_D65);
  38826. var SRGB = tempConvertMatrix1;
  38827. matrixProduct(SRGB_D65_XYZ_TO_RGB_MATRIX, XYZ_D65, SRGB);
  38828. var sR = sRGBTransferFunction(SRGB[0]);
  38829. var sG = sRGBTransferFunction(SRGB[1]);
  38830. var sB = sRGBTransferFunction(SRGB[2]);
  38831. // Convert the values to rgb range [0, 255].
  38832. dest[destOffset] = Math.round(sR * 255);
  38833. dest[destOffset + 1] = Math.round(sG * 255);
  38834. dest[destOffset + 2] = Math.round(sB * 255);
  38835. }
  38836. CalRGBCS.prototype = {
  38837. getRgb: function CalRGBCS_getRgb(src, srcOffset) {
  38838. var rgb = new Uint8Array(3);
  38839. this.getRgbItem(src, srcOffset, rgb, 0);
  38840. return rgb;
  38841. },
  38842. getRgbItem: function CalRGBCS_getRgbItem(src, srcOffset,
  38843. dest, destOffset) {
  38844. convertToRgb(this, src, srcOffset, dest, destOffset, 1);
  38845. },
  38846. getRgbBuffer: function CalRGBCS_getRgbBuffer(src, srcOffset, count,
  38847. dest, destOffset, bits,
  38848. alpha01) {
  38849. var scale = 1 / ((1 << bits) - 1);
  38850. for (var i = 0; i < count; ++i) {
  38851. convertToRgb(this, src, srcOffset, dest, destOffset, scale);
  38852. srcOffset += 3;
  38853. destOffset += 3 + alpha01;
  38854. }
  38855. },
  38856. getOutputLength: function CalRGBCS_getOutputLength(inputLength, alpha01) {
  38857. return (inputLength * (3 + alpha01) / 3) | 0;
  38858. },
  38859. isPassthrough: ColorSpace.prototype.isPassthrough,
  38860. fillRgb: ColorSpace.prototype.fillRgb,
  38861. isDefaultDecode: function CalRGBCS_isDefaultDecode(decodeMap) {
  38862. return ColorSpace.isDefaultDecode(decodeMap, this.numComps);
  38863. },
  38864. usesZeroToOneRange: true
  38865. };
  38866. return CalRGBCS;
  38867. })();
  38868. //
  38869. // LabCS: Based on "PDF Reference, Sixth Ed", p.250
  38870. //
  38871. var LabCS = (function LabCSClosure() {
  38872. function LabCS(whitePoint, blackPoint, range) {
  38873. this.name = 'Lab';
  38874. this.numComps = 3;
  38875. this.defaultColor = new Float32Array([0, 0, 0]);
  38876. if (!whitePoint) {
  38877. error('WhitePoint missing - required for color space Lab');
  38878. }
  38879. blackPoint = blackPoint || [0, 0, 0];
  38880. range = range || [-100, 100, -100, 100];
  38881. // Translate args to spec variables
  38882. this.XW = whitePoint[0];
  38883. this.YW = whitePoint[1];
  38884. this.ZW = whitePoint[2];
  38885. this.amin = range[0];
  38886. this.amax = range[1];
  38887. this.bmin = range[2];
  38888. this.bmax = range[3];
  38889. // These are here just for completeness - the spec doesn't offer any
  38890. // formulas that use BlackPoint in Lab
  38891. this.XB = blackPoint[0];
  38892. this.YB = blackPoint[1];
  38893. this.ZB = blackPoint[2];
  38894. // Validate vars as per spec
  38895. if (this.XW < 0 || this.ZW < 0 || this.YW !== 1) {
  38896. error('Invalid WhitePoint components, no fallback available');
  38897. }
  38898. if (this.XB < 0 || this.YB < 0 || this.ZB < 0) {
  38899. info('Invalid BlackPoint, falling back to default');
  38900. this.XB = this.YB = this.ZB = 0;
  38901. }
  38902. if (this.amin > this.amax || this.bmin > this.bmax) {
  38903. info('Invalid Range, falling back to defaults');
  38904. this.amin = -100;
  38905. this.amax = 100;
  38906. this.bmin = -100;
  38907. this.bmax = 100;
  38908. }
  38909. }
  38910. // Function g(x) from spec
  38911. function fn_g(x) {
  38912. if (x >= 6 / 29) {
  38913. return x * x * x;
  38914. } else {
  38915. return (108 / 841) * (x - 4 / 29);
  38916. }
  38917. }
  38918. function decode(value, high1, low2, high2) {
  38919. return low2 + (value) * (high2 - low2) / (high1);
  38920. }
  38921. // If decoding is needed maxVal should be 2^bits per component - 1.
  38922. function convertToRgb(cs, src, srcOffset, maxVal, dest, destOffset) {
  38923. // XXX: Lab input is in the range of [0, 100], [amin, amax], [bmin, bmax]
  38924. // not the usual [0, 1]. If a command like setFillColor is used the src
  38925. // values will already be within the correct range. However, if we are
  38926. // converting an image we have to map the values to the correct range given
  38927. // above.
  38928. // Ls,as,bs <---> L*,a*,b* in the spec
  38929. var Ls = src[srcOffset];
  38930. var as = src[srcOffset + 1];
  38931. var bs = src[srcOffset + 2];
  38932. if (maxVal !== false) {
  38933. Ls = decode(Ls, maxVal, 0, 100);
  38934. as = decode(as, maxVal, cs.amin, cs.amax);
  38935. bs = decode(bs, maxVal, cs.bmin, cs.bmax);
  38936. }
  38937. // Adjust limits of 'as' and 'bs'
  38938. as = as > cs.amax ? cs.amax : as < cs.amin ? cs.amin : as;
  38939. bs = bs > cs.bmax ? cs.bmax : bs < cs.bmin ? cs.bmin : bs;
  38940. // Computes intermediate variables X,Y,Z as per spec
  38941. var M = (Ls + 16) / 116;
  38942. var L = M + (as / 500);
  38943. var N = M - (bs / 200);
  38944. var X = cs.XW * fn_g(L);
  38945. var Y = cs.YW * fn_g(M);
  38946. var Z = cs.ZW * fn_g(N);
  38947. var r, g, b;
  38948. // Using different conversions for D50 and D65 white points,
  38949. // per http://www.color.org/srgb.pdf
  38950. if (cs.ZW < 1) {
  38951. // Assuming D50 (X=0.9642, Y=1.00, Z=0.8249)
  38952. r = X * 3.1339 + Y * -1.6170 + Z * -0.4906;
  38953. g = X * -0.9785 + Y * 1.9160 + Z * 0.0333;
  38954. b = X * 0.0720 + Y * -0.2290 + Z * 1.4057;
  38955. } else {
  38956. // Assuming D65 (X=0.9505, Y=1.00, Z=1.0888)
  38957. r = X * 3.2406 + Y * -1.5372 + Z * -0.4986;
  38958. g = X * -0.9689 + Y * 1.8758 + Z * 0.0415;
  38959. b = X * 0.0557 + Y * -0.2040 + Z * 1.0570;
  38960. }
  38961. // clamp color values to [0,1] range then convert to [0,255] range.
  38962. dest[destOffset] = r <= 0 ? 0 : r >= 1 ? 255 : Math.sqrt(r) * 255 | 0;
  38963. dest[destOffset + 1] = g <= 0 ? 0 : g >= 1 ? 255 : Math.sqrt(g) * 255 | 0;
  38964. dest[destOffset + 2] = b <= 0 ? 0 : b >= 1 ? 255 : Math.sqrt(b) * 255 | 0;
  38965. }
  38966. LabCS.prototype = {
  38967. getRgb: ColorSpace.prototype.getRgb,
  38968. getRgbItem: function LabCS_getRgbItem(src, srcOffset, dest, destOffset) {
  38969. convertToRgb(this, src, srcOffset, false, dest, destOffset);
  38970. },
  38971. getRgbBuffer: function LabCS_getRgbBuffer(src, srcOffset, count,
  38972. dest, destOffset, bits,
  38973. alpha01) {
  38974. var maxVal = (1 << bits) - 1;
  38975. for (var i = 0; i < count; i++) {
  38976. convertToRgb(this, src, srcOffset, maxVal, dest, destOffset);
  38977. srcOffset += 3;
  38978. destOffset += 3 + alpha01;
  38979. }
  38980. },
  38981. getOutputLength: function LabCS_getOutputLength(inputLength, alpha01) {
  38982. return (inputLength * (3 + alpha01) / 3) | 0;
  38983. },
  38984. isPassthrough: ColorSpace.prototype.isPassthrough,
  38985. fillRgb: ColorSpace.prototype.fillRgb,
  38986. isDefaultDecode: function LabCS_isDefaultDecode(decodeMap) {
  38987. // XXX: Decoding is handled with the lab conversion because of the strange
  38988. // ranges that are used.
  38989. return true;
  38990. },
  38991. usesZeroToOneRange: false
  38992. };
  38993. return LabCS;
  38994. })();
  38995. // TODO refactor to remove dependency on image.js
  38996. function _setCoreImage(coreImage_) {
  38997. coreImage = coreImage_;
  38998. PDFImage = coreImage_.PDFImage;
  38999. }
  39000. exports._setCoreImage = _setCoreImage;
  39001. exports.ColorSpace = ColorSpace;
  39002. }));
  39003. (function (root, factory) {
  39004. {
  39005. factory((root.pdfjsCoreImage = {}), root.pdfjsSharedUtil,
  39006. root.pdfjsCorePrimitives, root.pdfjsCoreColorSpace, root.pdfjsCoreStream,
  39007. root.pdfjsCoreJpx);
  39008. }
  39009. }(this, function (exports, sharedUtil, corePrimitives, coreColorSpace,
  39010. coreStream, coreJpx) {
  39011. var ImageKind = sharedUtil.ImageKind;
  39012. var assert = sharedUtil.assert;
  39013. var error = sharedUtil.error;
  39014. var info = sharedUtil.info;
  39015. var isArray = sharedUtil.isArray;
  39016. var warn = sharedUtil.warn;
  39017. var Name = corePrimitives.Name;
  39018. var isStream = corePrimitives.isStream;
  39019. var ColorSpace = coreColorSpace.ColorSpace;
  39020. var DecodeStream = coreStream.DecodeStream;
  39021. var JpegStream = coreStream.JpegStream;
  39022. var JpxImage = coreJpx.JpxImage;
  39023. var PDFImage = (function PDFImageClosure() {
  39024. /**
  39025. * Decodes the image using native decoder if possible. Resolves the promise
  39026. * when the image data is ready.
  39027. */
  39028. function handleImageData(image, nativeDecoder) {
  39029. if (nativeDecoder && nativeDecoder.canDecode(image)) {
  39030. return nativeDecoder.decode(image);
  39031. } else {
  39032. return Promise.resolve(image);
  39033. }
  39034. }
  39035. /**
  39036. * Decode and clamp a value. The formula is different from the spec because we
  39037. * don't decode to float range [0,1], we decode it in the [0,max] range.
  39038. */
  39039. function decodeAndClamp(value, addend, coefficient, max) {
  39040. value = addend + value * coefficient;
  39041. // Clamp the value to the range
  39042. return (value < 0 ? 0 : (value > max ? max : value));
  39043. }
  39044. function PDFImage(xref, res, image, inline, smask, mask, isMask) {
  39045. this.image = image;
  39046. var dict = image.dict;
  39047. if (dict.has('Filter')) {
  39048. var filter = dict.get('Filter').name;
  39049. if (filter === 'JPXDecode') {
  39050. var jpxImage = new JpxImage();
  39051. jpxImage.parseImageProperties(image.stream);
  39052. image.stream.reset();
  39053. image.bitsPerComponent = jpxImage.bitsPerComponent;
  39054. image.numComps = jpxImage.componentsCount;
  39055. } else if (filter === 'JBIG2Decode') {
  39056. image.bitsPerComponent = 1;
  39057. image.numComps = 1;
  39058. }
  39059. }
  39060. // TODO cache rendered images?
  39061. this.width = dict.get('Width', 'W');
  39062. this.height = dict.get('Height', 'H');
  39063. if (this.width < 1 || this.height < 1) {
  39064. error('Invalid image width: ' + this.width + ' or height: ' +
  39065. this.height);
  39066. }
  39067. this.interpolate = dict.get('Interpolate', 'I') || false;
  39068. this.imageMask = dict.get('ImageMask', 'IM') || false;
  39069. this.matte = dict.get('Matte') || false;
  39070. var bitsPerComponent = image.bitsPerComponent;
  39071. if (!bitsPerComponent) {
  39072. bitsPerComponent = dict.get('BitsPerComponent', 'BPC');
  39073. if (!bitsPerComponent) {
  39074. if (this.imageMask) {
  39075. bitsPerComponent = 1;
  39076. } else {
  39077. error('Bits per component missing in image: ' + this.imageMask);
  39078. }
  39079. }
  39080. }
  39081. this.bpc = bitsPerComponent;
  39082. if (!this.imageMask) {
  39083. var colorSpace = dict.get('ColorSpace', 'CS');
  39084. if (!colorSpace) {
  39085. info('JPX images (which do not require color spaces)');
  39086. switch (image.numComps) {
  39087. case 1:
  39088. colorSpace = Name.get('DeviceGray');
  39089. break;
  39090. case 3:
  39091. colorSpace = Name.get('DeviceRGB');
  39092. break;
  39093. case 4:
  39094. colorSpace = Name.get('DeviceCMYK');
  39095. break;
  39096. default:
  39097. error('JPX images with ' + this.numComps +
  39098. ' color components not supported.');
  39099. }
  39100. }
  39101. this.colorSpace = ColorSpace.parse(colorSpace, xref, res);
  39102. this.numComps = this.colorSpace.numComps;
  39103. }
  39104. this.decode = dict.get('Decode', 'D');
  39105. this.needsDecode = false;
  39106. if (this.decode &&
  39107. ((this.colorSpace && !this.colorSpace.isDefaultDecode(this.decode)) ||
  39108. (isMask && !ColorSpace.isDefaultDecode(this.decode, 1)))) {
  39109. this.needsDecode = true;
  39110. // Do some preprocessing to avoid more math.
  39111. var max = (1 << bitsPerComponent) - 1;
  39112. this.decodeCoefficients = [];
  39113. this.decodeAddends = [];
  39114. for (var i = 0, j = 0; i < this.decode.length; i += 2, ++j) {
  39115. var dmin = this.decode[i];
  39116. var dmax = this.decode[i + 1];
  39117. this.decodeCoefficients[j] = dmax - dmin;
  39118. this.decodeAddends[j] = max * dmin;
  39119. }
  39120. }
  39121. if (smask) {
  39122. this.smask = new PDFImage(xref, res, smask, false);
  39123. } else if (mask) {
  39124. if (isStream(mask)) {
  39125. var maskDict = mask.dict, imageMask = maskDict.get('ImageMask', 'IM');
  39126. if (!imageMask) {
  39127. warn('Ignoring /Mask in image without /ImageMask.');
  39128. } else {
  39129. this.mask = new PDFImage(xref, res, mask, false, null, null, true);
  39130. }
  39131. } else {
  39132. // Color key mask (just an array).
  39133. this.mask = mask;
  39134. }
  39135. }
  39136. }
  39137. /**
  39138. * Handles processing of image data and returns the Promise that is resolved
  39139. * with a PDFImage when the image is ready to be used.
  39140. */
  39141. PDFImage.buildImage = function PDFImage_buildImage(handler, xref,
  39142. res, image, inline,
  39143. nativeDecoder) {
  39144. var imagePromise = handleImageData(image, nativeDecoder);
  39145. var smaskPromise;
  39146. var maskPromise;
  39147. var smask = image.dict.get('SMask');
  39148. var mask = image.dict.get('Mask');
  39149. if (smask) {
  39150. smaskPromise = handleImageData(smask, nativeDecoder);
  39151. maskPromise = Promise.resolve(null);
  39152. } else {
  39153. smaskPromise = Promise.resolve(null);
  39154. if (mask) {
  39155. if (isStream(mask)) {
  39156. maskPromise = handleImageData(mask, nativeDecoder);
  39157. } else if (isArray(mask)) {
  39158. maskPromise = Promise.resolve(mask);
  39159. } else {
  39160. warn('Unsupported mask format.');
  39161. maskPromise = Promise.resolve(null);
  39162. }
  39163. } else {
  39164. maskPromise = Promise.resolve(null);
  39165. }
  39166. }
  39167. return Promise.all([imagePromise, smaskPromise, maskPromise]).then(
  39168. function(results) {
  39169. var imageData = results[0];
  39170. var smaskData = results[1];
  39171. var maskData = results[2];
  39172. return new PDFImage(xref, res, imageData, inline, smaskData, maskData);
  39173. });
  39174. };
  39175. /**
  39176. * Resize an image using the nearest neighbor algorithm. Currently only
  39177. * supports one and three component images.
  39178. * @param {TypedArray} pixels The original image with one component.
  39179. * @param {Number} bpc Number of bits per component.
  39180. * @param {Number} components Number of color components, 1 or 3 is supported.
  39181. * @param {Number} w1 Original width.
  39182. * @param {Number} h1 Original height.
  39183. * @param {Number} w2 New width.
  39184. * @param {Number} h2 New height.
  39185. * @param {TypedArray} dest (Optional) The destination buffer.
  39186. * @param {Number} alpha01 (Optional) Size reserved for the alpha channel.
  39187. * @return {TypedArray} Resized image data.
  39188. */
  39189. PDFImage.resize = function PDFImage_resize(pixels, bpc, components,
  39190. w1, h1, w2, h2, dest, alpha01) {
  39191. if (components !== 1 && components !== 3) {
  39192. error('Unsupported component count for resizing.');
  39193. }
  39194. var length = w2 * h2 * components;
  39195. var temp = dest ? dest : (bpc <= 8 ? new Uint8Array(length) :
  39196. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39197. var xRatio = w1 / w2;
  39198. var yRatio = h1 / h2;
  39199. var i, j, py, newIndex = 0, oldIndex;
  39200. var xScaled = new Uint16Array(w2);
  39201. var w1Scanline = w1 * components;
  39202. if (alpha01 !== 1) {
  39203. alpha01 = 0;
  39204. }
  39205. for (j = 0; j < w2; j++) {
  39206. xScaled[j] = Math.floor(j * xRatio) * components;
  39207. }
  39208. if (components === 1) {
  39209. for (i = 0; i < h2; i++) {
  39210. py = Math.floor(i * yRatio) * w1Scanline;
  39211. for (j = 0; j < w2; j++) {
  39212. oldIndex = py + xScaled[j];
  39213. temp[newIndex++] = pixels[oldIndex];
  39214. }
  39215. }
  39216. } else if (components === 3) {
  39217. for (i = 0; i < h2; i++) {
  39218. py = Math.floor(i * yRatio) * w1Scanline;
  39219. for (j = 0; j < w2; j++) {
  39220. oldIndex = py + xScaled[j];
  39221. temp[newIndex++] = pixels[oldIndex++];
  39222. temp[newIndex++] = pixels[oldIndex++];
  39223. temp[newIndex++] = pixels[oldIndex++];
  39224. newIndex += alpha01;
  39225. }
  39226. }
  39227. }
  39228. return temp;
  39229. };
  39230. PDFImage.createMask =
  39231. function PDFImage_createMask(imgArray, width, height,
  39232. imageIsFromDecodeStream, inverseDecode) {
  39233. // |imgArray| might not contain full data for every pixel of the mask, so
  39234. // we need to distinguish between |computedLength| and |actualLength|.
  39235. // In particular, if inverseDecode is true, then the array we return must
  39236. // have a length of |computedLength|.
  39237. var computedLength = ((width + 7) >> 3) * height;
  39238. var actualLength = imgArray.byteLength;
  39239. var haveFullData = computedLength === actualLength;
  39240. var data, i;
  39241. if (imageIsFromDecodeStream && (!inverseDecode || haveFullData)) {
  39242. // imgArray came from a DecodeStream and its data is in an appropriate
  39243. // form, so we can just transfer it.
  39244. data = imgArray;
  39245. } else if (!inverseDecode) {
  39246. data = new Uint8Array(actualLength);
  39247. data.set(imgArray);
  39248. } else {
  39249. data = new Uint8Array(computedLength);
  39250. data.set(imgArray);
  39251. for (i = actualLength; i < computedLength; i++) {
  39252. data[i] = 0xff;
  39253. }
  39254. }
  39255. // If necessary, invert the original mask data (but not any extra we might
  39256. // have added above). It's safe to modify the array -- whether it's the
  39257. // original or a copy, we're about to transfer it anyway, so nothing else
  39258. // in this thread can be relying on its contents.
  39259. if (inverseDecode) {
  39260. for (i = 0; i < actualLength; i++) {
  39261. data[i] = ~data[i];
  39262. }
  39263. }
  39264. return {data: data, width: width, height: height};
  39265. };
  39266. PDFImage.prototype = {
  39267. get drawWidth() {
  39268. return Math.max(this.width,
  39269. this.smask && this.smask.width || 0,
  39270. this.mask && this.mask.width || 0);
  39271. },
  39272. get drawHeight() {
  39273. return Math.max(this.height,
  39274. this.smask && this.smask.height || 0,
  39275. this.mask && this.mask.height || 0);
  39276. },
  39277. decodeBuffer: function PDFImage_decodeBuffer(buffer) {
  39278. var bpc = this.bpc;
  39279. var numComps = this.numComps;
  39280. var decodeAddends = this.decodeAddends;
  39281. var decodeCoefficients = this.decodeCoefficients;
  39282. var max = (1 << bpc) - 1;
  39283. var i, ii;
  39284. if (bpc === 1) {
  39285. // If the buffer needed decode that means it just needs to be inverted.
  39286. for (i = 0, ii = buffer.length; i < ii; i++) {
  39287. buffer[i] = +!(buffer[i]);
  39288. }
  39289. return;
  39290. }
  39291. var index = 0;
  39292. for (i = 0, ii = this.width * this.height; i < ii; i++) {
  39293. for (var j = 0; j < numComps; j++) {
  39294. buffer[index] = decodeAndClamp(buffer[index], decodeAddends[j],
  39295. decodeCoefficients[j], max);
  39296. index++;
  39297. }
  39298. }
  39299. },
  39300. getComponents: function PDFImage_getComponents(buffer) {
  39301. var bpc = this.bpc;
  39302. // This image doesn't require any extra work.
  39303. if (bpc === 8) {
  39304. return buffer;
  39305. }
  39306. var width = this.width;
  39307. var height = this.height;
  39308. var numComps = this.numComps;
  39309. var length = width * height * numComps;
  39310. var bufferPos = 0;
  39311. var output = (bpc <= 8 ? new Uint8Array(length) :
  39312. (bpc <= 16 ? new Uint16Array(length) : new Uint32Array(length)));
  39313. var rowComps = width * numComps;
  39314. var max = (1 << bpc) - 1;
  39315. var i = 0, ii, buf;
  39316. if (bpc === 1) {
  39317. // Optimization for reading 1 bpc images.
  39318. var mask, loop1End, loop2End;
  39319. for (var j = 0; j < height; j++) {
  39320. loop1End = i + (rowComps & ~7);
  39321. loop2End = i + rowComps;
  39322. // unroll loop for all full bytes
  39323. while (i < loop1End) {
  39324. buf = buffer[bufferPos++];
  39325. output[i] = (buf >> 7) & 1;
  39326. output[i + 1] = (buf >> 6) & 1;
  39327. output[i + 2] = (buf >> 5) & 1;
  39328. output[i + 3] = (buf >> 4) & 1;
  39329. output[i + 4] = (buf >> 3) & 1;
  39330. output[i + 5] = (buf >> 2) & 1;
  39331. output[i + 6] = (buf >> 1) & 1;
  39332. output[i + 7] = buf & 1;
  39333. i += 8;
  39334. }
  39335. // handle remaing bits
  39336. if (i < loop2End) {
  39337. buf = buffer[bufferPos++];
  39338. mask = 128;
  39339. while (i < loop2End) {
  39340. output[i++] = +!!(buf & mask);
  39341. mask >>= 1;
  39342. }
  39343. }
  39344. }
  39345. } else {
  39346. // The general case that handles all other bpc values.
  39347. var bits = 0;
  39348. buf = 0;
  39349. for (i = 0, ii = length; i < ii; ++i) {
  39350. if (i % rowComps === 0) {
  39351. buf = 0;
  39352. bits = 0;
  39353. }
  39354. while (bits < bpc) {
  39355. buf = (buf << 8) | buffer[bufferPos++];
  39356. bits += 8;
  39357. }
  39358. var remainingBits = bits - bpc;
  39359. var value = buf >> remainingBits;
  39360. output[i] = (value < 0 ? 0 : (value > max ? max : value));
  39361. buf = buf & ((1 << remainingBits) - 1);
  39362. bits = remainingBits;
  39363. }
  39364. }
  39365. return output;
  39366. },
  39367. fillOpacity: function PDFImage_fillOpacity(rgbaBuf, width, height,
  39368. actualHeight, image) {
  39369. var smask = this.smask;
  39370. var mask = this.mask;
  39371. var alphaBuf, sw, sh, i, ii, j;
  39372. if (smask) {
  39373. sw = smask.width;
  39374. sh = smask.height;
  39375. alphaBuf = new Uint8Array(sw * sh);
  39376. smask.fillGrayBuffer(alphaBuf);
  39377. if (sw !== width || sh !== height) {
  39378. alphaBuf = PDFImage.resize(alphaBuf, smask.bpc, 1, sw, sh, width,
  39379. height);
  39380. }
  39381. } else if (mask) {
  39382. if (mask instanceof PDFImage) {
  39383. sw = mask.width;
  39384. sh = mask.height;
  39385. alphaBuf = new Uint8Array(sw * sh);
  39386. mask.numComps = 1;
  39387. mask.fillGrayBuffer(alphaBuf);
  39388. // Need to invert values in rgbaBuf
  39389. for (i = 0, ii = sw * sh; i < ii; ++i) {
  39390. alphaBuf[i] = 255 - alphaBuf[i];
  39391. }
  39392. if (sw !== width || sh !== height) {
  39393. alphaBuf = PDFImage.resize(alphaBuf, mask.bpc, 1, sw, sh, width,
  39394. height);
  39395. }
  39396. } else if (isArray(mask)) {
  39397. // Color key mask: if any of the compontents are outside the range
  39398. // then they should be painted.
  39399. alphaBuf = new Uint8Array(width * height);
  39400. var numComps = this.numComps;
  39401. for (i = 0, ii = width * height; i < ii; ++i) {
  39402. var opacity = 0;
  39403. var imageOffset = i * numComps;
  39404. for (j = 0; j < numComps; ++j) {
  39405. var color = image[imageOffset + j];
  39406. var maskOffset = j * 2;
  39407. if (color < mask[maskOffset] || color > mask[maskOffset + 1]) {
  39408. opacity = 255;
  39409. break;
  39410. }
  39411. }
  39412. alphaBuf[i] = opacity;
  39413. }
  39414. } else {
  39415. error('Unknown mask format.');
  39416. }
  39417. }
  39418. if (alphaBuf) {
  39419. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39420. rgbaBuf[j] = alphaBuf[i];
  39421. }
  39422. } else {
  39423. // No mask.
  39424. for (i = 0, j = 3, ii = width * actualHeight; i < ii; ++i, j += 4) {
  39425. rgbaBuf[j] = 255;
  39426. }
  39427. }
  39428. },
  39429. undoPreblend: function PDFImage_undoPreblend(buffer, width, height) {
  39430. var matte = this.smask && this.smask.matte;
  39431. if (!matte) {
  39432. return;
  39433. }
  39434. var matteRgb = this.colorSpace.getRgb(matte, 0);
  39435. var matteR = matteRgb[0];
  39436. var matteG = matteRgb[1];
  39437. var matteB = matteRgb[2];
  39438. var length = width * height * 4;
  39439. var r, g, b;
  39440. for (var i = 0; i < length; i += 4) {
  39441. var alpha = buffer[i + 3];
  39442. if (alpha === 0) {
  39443. // according formula we have to get Infinity in all components
  39444. // making it white (typical paper color) should be okay
  39445. buffer[i] = 255;
  39446. buffer[i + 1] = 255;
  39447. buffer[i + 2] = 255;
  39448. continue;
  39449. }
  39450. var k = 255 / alpha;
  39451. r = (buffer[i] - matteR) * k + matteR;
  39452. g = (buffer[i + 1] - matteG) * k + matteG;
  39453. b = (buffer[i + 2] - matteB) * k + matteB;
  39454. buffer[i] = r <= 0 ? 0 : r >= 255 ? 255 : r | 0;
  39455. buffer[i + 1] = g <= 0 ? 0 : g >= 255 ? 255 : g | 0;
  39456. buffer[i + 2] = b <= 0 ? 0 : b >= 255 ? 255 : b | 0;
  39457. }
  39458. },
  39459. createImageData: function PDFImage_createImageData(forceRGBA) {
  39460. var drawWidth = this.drawWidth;
  39461. var drawHeight = this.drawHeight;
  39462. var imgData = { // other fields are filled in below
  39463. width: drawWidth,
  39464. height: drawHeight
  39465. };
  39466. var numComps = this.numComps;
  39467. var originalWidth = this.width;
  39468. var originalHeight = this.height;
  39469. var bpc = this.bpc;
  39470. // Rows start at byte boundary.
  39471. var rowBytes = (originalWidth * numComps * bpc + 7) >> 3;
  39472. var imgArray;
  39473. if (!forceRGBA) {
  39474. // If it is a 1-bit-per-pixel grayscale (i.e. black-and-white) image
  39475. // without any complications, we pass a same-sized copy to the main
  39476. // thread rather than expanding by 32x to RGBA form. This saves *lots*
  39477. // of memory for many scanned documents. It's also much faster.
  39478. //
  39479. // Similarly, if it is a 24-bit-per pixel RGB image without any
  39480. // complications, we avoid expanding by 1.333x to RGBA form.
  39481. var kind;
  39482. if (this.colorSpace.name === 'DeviceGray' && bpc === 1) {
  39483. kind = ImageKind.GRAYSCALE_1BPP;
  39484. } else if (this.colorSpace.name === 'DeviceRGB' && bpc === 8 &&
  39485. !this.needsDecode) {
  39486. kind = ImageKind.RGB_24BPP;
  39487. }
  39488. if (kind && !this.smask && !this.mask &&
  39489. drawWidth === originalWidth && drawHeight === originalHeight) {
  39490. imgData.kind = kind;
  39491. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39492. // If imgArray came from a DecodeStream, we're safe to transfer it
  39493. // (and thus detach its underlying buffer) because it will constitute
  39494. // the entire DecodeStream's data. But if it came from a Stream, we
  39495. // need to copy it because it'll only be a portion of the Stream's
  39496. // data, and the rest will be read later on.
  39497. if (this.image instanceof DecodeStream) {
  39498. imgData.data = imgArray;
  39499. } else {
  39500. var newArray = new Uint8Array(imgArray.length);
  39501. newArray.set(imgArray);
  39502. imgData.data = newArray;
  39503. }
  39504. if (this.needsDecode) {
  39505. // Invert the buffer (which must be grayscale if we reached here).
  39506. assert(kind === ImageKind.GRAYSCALE_1BPP);
  39507. var buffer = imgData.data;
  39508. for (var i = 0, ii = buffer.length; i < ii; i++) {
  39509. buffer[i] ^= 0xff;
  39510. }
  39511. }
  39512. return imgData;
  39513. }
  39514. if (this.image instanceof JpegStream && !this.smask && !this.mask &&
  39515. (this.colorSpace.name === 'DeviceGray' ||
  39516. this.colorSpace.name === 'DeviceRGB' ||
  39517. this.colorSpace.name === 'DeviceCMYK')) {
  39518. imgData.kind = ImageKind.RGB_24BPP;
  39519. imgData.data = this.getImageBytes(originalHeight * rowBytes,
  39520. drawWidth, drawHeight, true);
  39521. return imgData;
  39522. }
  39523. }
  39524. imgArray = this.getImageBytes(originalHeight * rowBytes);
  39525. // imgArray can be incomplete (e.g. after CCITT fax encoding).
  39526. var actualHeight = 0 | (imgArray.length / rowBytes *
  39527. drawHeight / originalHeight);
  39528. var comps = this.getComponents(imgArray);
  39529. // If opacity data is present, use RGBA_32BPP form. Otherwise, use the
  39530. // more compact RGB_24BPP form if allowable.
  39531. var alpha01, maybeUndoPreblend;
  39532. if (!forceRGBA && !this.smask && !this.mask) {
  39533. imgData.kind = ImageKind.RGB_24BPP;
  39534. imgData.data = new Uint8Array(drawWidth * drawHeight * 3);
  39535. alpha01 = 0;
  39536. maybeUndoPreblend = false;
  39537. } else {
  39538. imgData.kind = ImageKind.RGBA_32BPP;
  39539. imgData.data = new Uint8Array(drawWidth * drawHeight * 4);
  39540. alpha01 = 1;
  39541. maybeUndoPreblend = true;
  39542. // Color key masking (opacity) must be performed before decoding.
  39543. this.fillOpacity(imgData.data, drawWidth, drawHeight, actualHeight,
  39544. comps);
  39545. }
  39546. if (this.needsDecode) {
  39547. this.decodeBuffer(comps);
  39548. }
  39549. this.colorSpace.fillRgb(imgData.data, originalWidth, originalHeight,
  39550. drawWidth, drawHeight, actualHeight, bpc, comps,
  39551. alpha01);
  39552. if (maybeUndoPreblend) {
  39553. this.undoPreblend(imgData.data, drawWidth, actualHeight);
  39554. }
  39555. return imgData;
  39556. },
  39557. fillGrayBuffer: function PDFImage_fillGrayBuffer(buffer) {
  39558. var numComps = this.numComps;
  39559. if (numComps !== 1) {
  39560. error('Reading gray scale from a color image: ' + numComps);
  39561. }
  39562. var width = this.width;
  39563. var height = this.height;
  39564. var bpc = this.bpc;
  39565. // rows start at byte boundary
  39566. var rowBytes = (width * numComps * bpc + 7) >> 3;
  39567. var imgArray = this.getImageBytes(height * rowBytes);
  39568. var comps = this.getComponents(imgArray);
  39569. var i, length;
  39570. if (bpc === 1) {
  39571. // inline decoding (= inversion) for 1 bpc images
  39572. length = width * height;
  39573. if (this.needsDecode) {
  39574. // invert and scale to {0, 255}
  39575. for (i = 0; i < length; ++i) {
  39576. buffer[i] = (comps[i] - 1) & 255;
  39577. }
  39578. } else {
  39579. // scale to {0, 255}
  39580. for (i = 0; i < length; ++i) {
  39581. buffer[i] = (-comps[i]) & 255;
  39582. }
  39583. }
  39584. return;
  39585. }
  39586. if (this.needsDecode) {
  39587. this.decodeBuffer(comps);
  39588. }
  39589. length = width * height;
  39590. // we aren't using a colorspace so we need to scale the value
  39591. var scale = 255 / ((1 << bpc) - 1);
  39592. for (i = 0; i < length; ++i) {
  39593. buffer[i] = (scale * comps[i]) | 0;
  39594. }
  39595. },
  39596. getImageBytes: function PDFImage_getImageBytes(length,
  39597. drawWidth, drawHeight,
  39598. forceRGB) {
  39599. this.image.reset();
  39600. this.image.drawWidth = drawWidth || this.width;
  39601. this.image.drawHeight = drawHeight || this.height;
  39602. this.image.forceRGB = !!forceRGB;
  39603. return this.image.getBytes(length);
  39604. }
  39605. };
  39606. return PDFImage;
  39607. })();
  39608. exports.PDFImage = PDFImage;
  39609. // TODO refactor to remove dependency on colorspace.js
  39610. coreColorSpace._setCoreImage(exports);
  39611. }));
  39612. (function (root, factory) {
  39613. {
  39614. factory((root.pdfjsCoreObj = {}), root.pdfjsSharedUtil,
  39615. root.pdfjsCorePrimitives, root.pdfjsCoreCrypto, root.pdfjsCoreParser,
  39616. root.pdfjsCoreChunkedStream, root.pdfjsCoreColorSpace);
  39617. }
  39618. }(this, function (exports, sharedUtil, corePrimitives, coreCrypto, coreParser,
  39619. coreChunkedStream, coreColorSpace) {
  39620. var InvalidPDFException = sharedUtil.InvalidPDFException;
  39621. var MissingDataException = sharedUtil.MissingDataException;
  39622. var XRefParseException = sharedUtil.XRefParseException;
  39623. var assert = sharedUtil.assert;
  39624. var bytesToString = sharedUtil.bytesToString;
  39625. var createPromiseCapability = sharedUtil.createPromiseCapability;
  39626. var error = sharedUtil.error;
  39627. var info = sharedUtil.info;
  39628. var isArray = sharedUtil.isArray;
  39629. var isInt = sharedUtil.isInt;
  39630. var isString = sharedUtil.isString;
  39631. var shadow = sharedUtil.shadow;
  39632. var stringToPDFString = sharedUtil.stringToPDFString;
  39633. var stringToUTF8String = sharedUtil.stringToUTF8String;
  39634. var warn = sharedUtil.warn;
  39635. var isValidUrl = sharedUtil.isValidUrl;
  39636. var Util = sharedUtil.Util;
  39637. var Ref = corePrimitives.Ref;
  39638. var RefSet = corePrimitives.RefSet;
  39639. var RefSetCache = corePrimitives.RefSetCache;
  39640. var isName = corePrimitives.isName;
  39641. var isCmd = corePrimitives.isCmd;
  39642. var isDict = corePrimitives.isDict;
  39643. var isRef = corePrimitives.isRef;
  39644. var isStream = corePrimitives.isStream;
  39645. var CipherTransformFactory = coreCrypto.CipherTransformFactory;
  39646. var Lexer = coreParser.Lexer;
  39647. var Parser = coreParser.Parser;
  39648. var ChunkedStream = coreChunkedStream.ChunkedStream;
  39649. var ColorSpace = coreColorSpace.ColorSpace;
  39650. var Catalog = (function CatalogClosure() {
  39651. function Catalog(pdfManager, xref, pageFactory) {
  39652. this.pdfManager = pdfManager;
  39653. this.xref = xref;
  39654. this.catDict = xref.getCatalogObj();
  39655. this.fontCache = new RefSetCache();
  39656. assert(isDict(this.catDict),
  39657. 'catalog object is not a dictionary');
  39658. // TODO refactor to move getPage() to the PDFDocument.
  39659. this.pageFactory = pageFactory;
  39660. this.pagePromises = [];
  39661. }
  39662. Catalog.prototype = {
  39663. get metadata() {
  39664. var streamRef = this.catDict.getRaw('Metadata');
  39665. if (!isRef(streamRef)) {
  39666. return shadow(this, 'metadata', null);
  39667. }
  39668. var encryptMetadata = (!this.xref.encrypt ? false :
  39669. this.xref.encrypt.encryptMetadata);
  39670. var stream = this.xref.fetch(streamRef, !encryptMetadata);
  39671. var metadata;
  39672. if (stream && isDict(stream.dict)) {
  39673. var type = stream.dict.get('Type');
  39674. var subtype = stream.dict.get('Subtype');
  39675. if (isName(type) && isName(subtype) &&
  39676. type.name === 'Metadata' && subtype.name === 'XML') {
  39677. // XXX: This should examine the charset the XML document defines,
  39678. // however since there are currently no real means to decode
  39679. // arbitrary charsets, let's just hope that the author of the PDF
  39680. // was reasonable enough to stick with the XML default charset,
  39681. // which is UTF-8.
  39682. try {
  39683. metadata = stringToUTF8String(bytesToString(stream.getBytes()));
  39684. } catch (e) {
  39685. info('Skipping invalid metadata.');
  39686. }
  39687. }
  39688. }
  39689. return shadow(this, 'metadata', metadata);
  39690. },
  39691. get toplevelPagesDict() {
  39692. var pagesObj = this.catDict.get('Pages');
  39693. assert(isDict(pagesObj), 'invalid top-level pages dictionary');
  39694. // shadow the prototype getter
  39695. return shadow(this, 'toplevelPagesDict', pagesObj);
  39696. },
  39697. get documentOutline() {
  39698. var obj = null;
  39699. try {
  39700. obj = this.readDocumentOutline();
  39701. } catch (ex) {
  39702. if (ex instanceof MissingDataException) {
  39703. throw ex;
  39704. }
  39705. warn('Unable to read document outline');
  39706. }
  39707. return shadow(this, 'documentOutline', obj);
  39708. },
  39709. readDocumentOutline: function Catalog_readDocumentOutline() {
  39710. var obj = this.catDict.get('Outlines');
  39711. if (!isDict(obj)) {
  39712. return null;
  39713. }
  39714. obj = obj.getRaw('First');
  39715. if (!isRef(obj)) {
  39716. return null;
  39717. }
  39718. var root = { items: [] };
  39719. var queue = [{obj: obj, parent: root}];
  39720. // To avoid recursion, keep track of the already processed items.
  39721. var processed = new RefSet();
  39722. processed.put(obj);
  39723. var xref = this.xref, blackColor = new Uint8Array(3);
  39724. while (queue.length > 0) {
  39725. var i = queue.shift();
  39726. var outlineDict = xref.fetchIfRef(i.obj);
  39727. if (outlineDict === null) {
  39728. continue;
  39729. }
  39730. assert(outlineDict.has('Title'), 'Invalid outline item');
  39731. var actionDict = outlineDict.get('A'), dest = null, url = null;
  39732. if (actionDict) {
  39733. var destEntry = actionDict.get('D');
  39734. if (destEntry) {
  39735. dest = destEntry;
  39736. } else {
  39737. var uriEntry = actionDict.get('URI');
  39738. if (isString(uriEntry) && isValidUrl(uriEntry, false)) {
  39739. url = uriEntry;
  39740. }
  39741. }
  39742. } else if (outlineDict.has('Dest')) {
  39743. dest = outlineDict.getRaw('Dest');
  39744. if (isName(dest)) {
  39745. dest = dest.name;
  39746. }
  39747. }
  39748. var title = outlineDict.get('Title');
  39749. var flags = outlineDict.get('F') || 0;
  39750. var color = outlineDict.get('C'), rgbColor = blackColor;
  39751. // We only need to parse the color when it's valid, and non-default.
  39752. if (isArray(color) && color.length === 3 &&
  39753. (color[0] !== 0 || color[1] !== 0 || color[2] !== 0)) {
  39754. rgbColor = ColorSpace.singletons.rgb.getRgb(color, 0);
  39755. }
  39756. var outlineItem = {
  39757. dest: dest,
  39758. url: url,
  39759. title: stringToPDFString(title),
  39760. color: rgbColor,
  39761. count: outlineDict.get('Count'),
  39762. bold: !!(flags & 2),
  39763. italic: !!(flags & 1),
  39764. items: []
  39765. };
  39766. i.parent.items.push(outlineItem);
  39767. obj = outlineDict.getRaw('First');
  39768. if (isRef(obj) && !processed.has(obj)) {
  39769. queue.push({obj: obj, parent: outlineItem});
  39770. processed.put(obj);
  39771. }
  39772. obj = outlineDict.getRaw('Next');
  39773. if (isRef(obj) && !processed.has(obj)) {
  39774. queue.push({obj: obj, parent: i.parent});
  39775. processed.put(obj);
  39776. }
  39777. }
  39778. return (root.items.length > 0 ? root.items : null);
  39779. },
  39780. get numPages() {
  39781. var obj = this.toplevelPagesDict.get('Count');
  39782. assert(
  39783. isInt(obj),
  39784. 'page count in top level pages object is not an integer'
  39785. );
  39786. // shadow the prototype getter
  39787. return shadow(this, 'num', obj);
  39788. },
  39789. get destinations() {
  39790. function fetchDestination(dest) {
  39791. return isDict(dest) ? dest.get('D') : dest;
  39792. }
  39793. var xref = this.xref;
  39794. var dests = {}, nameTreeRef, nameDictionaryRef;
  39795. var obj = this.catDict.get('Names');
  39796. if (obj && obj.has('Dests')) {
  39797. nameTreeRef = obj.getRaw('Dests');
  39798. } else if (this.catDict.has('Dests')) {
  39799. nameDictionaryRef = this.catDict.get('Dests');
  39800. }
  39801. if (nameDictionaryRef) {
  39802. // reading simple destination dictionary
  39803. obj = nameDictionaryRef;
  39804. obj.forEach(function catalogForEach(key, value) {
  39805. if (!value) {
  39806. return;
  39807. }
  39808. dests[key] = fetchDestination(value);
  39809. });
  39810. }
  39811. if (nameTreeRef) {
  39812. var nameTree = new NameTree(nameTreeRef, xref);
  39813. var names = nameTree.getAll();
  39814. for (var name in names) {
  39815. dests[name] = fetchDestination(names[name]);
  39816. }
  39817. }
  39818. return shadow(this, 'destinations', dests);
  39819. },
  39820. getDestination: function Catalog_getDestination(destinationId) {
  39821. function fetchDestination(dest) {
  39822. return isDict(dest) ? dest.get('D') : dest;
  39823. }
  39824. var xref = this.xref;
  39825. var dest = null, nameTreeRef, nameDictionaryRef;
  39826. var obj = this.catDict.get('Names');
  39827. if (obj && obj.has('Dests')) {
  39828. nameTreeRef = obj.getRaw('Dests');
  39829. } else if (this.catDict.has('Dests')) {
  39830. nameDictionaryRef = this.catDict.get('Dests');
  39831. }
  39832. if (nameDictionaryRef) { // Simple destination dictionary.
  39833. var value = nameDictionaryRef.get(destinationId);
  39834. if (value) {
  39835. dest = fetchDestination(value);
  39836. }
  39837. }
  39838. if (nameTreeRef) {
  39839. var nameTree = new NameTree(nameTreeRef, xref);
  39840. dest = fetchDestination(nameTree.get(destinationId));
  39841. }
  39842. return dest;
  39843. },
  39844. get pageLabels() {
  39845. var obj = null;
  39846. try {
  39847. obj = this.readPageLabels();
  39848. } catch (ex) {
  39849. if (ex instanceof MissingDataException) {
  39850. throw ex;
  39851. }
  39852. warn('Unable to read page labels.');
  39853. }
  39854. return shadow(this, 'pageLabels', obj);
  39855. },
  39856. readPageLabels: function Catalog_readPageLabels() {
  39857. var obj = this.catDict.getRaw('PageLabels');
  39858. if (!obj) {
  39859. return null;
  39860. }
  39861. var pageLabels = new Array(this.numPages);
  39862. var style = null;
  39863. var prefix = '';
  39864. var start = 1;
  39865. var numberTree = new NumberTree(obj, this.xref);
  39866. var nums = numberTree.getAll();
  39867. var currentLabel = '', currentIndex = 1;
  39868. for (var i = 0, ii = this.numPages; i < ii; i++) {
  39869. if (i in nums) {
  39870. var labelDict = nums[i];
  39871. assert(isDict(labelDict), 'The PageLabel is not a dictionary.');
  39872. var type = labelDict.get('Type');
  39873. assert(!type || (isName(type) && type.name === 'PageLabel'),
  39874. 'Invalid type in PageLabel dictionary.');
  39875. var s = labelDict.get('S');
  39876. assert(!s || isName(s), 'Invalid style in PageLabel dictionary.');
  39877. style = (s ? s.name : null);
  39878. prefix = labelDict.get('P') || '';
  39879. assert(isString(prefix), 'Invalid prefix in PageLabel dictionary.');
  39880. start = labelDict.get('St') || 1;
  39881. assert(isInt(start), 'Invalid start in PageLabel dictionary.');
  39882. currentIndex = start;
  39883. }
  39884. switch (style) {
  39885. case 'D':
  39886. currentLabel = currentIndex;
  39887. break;
  39888. case 'R':
  39889. case 'r':
  39890. currentLabel = Util.toRoman(currentIndex, style === 'r');
  39891. break;
  39892. case 'A':
  39893. case 'a':
  39894. var LIMIT = 26; // Use only the characters A--Z, or a--z.
  39895. var A_UPPER_CASE = 0x41, A_LOWER_CASE = 0x61;
  39896. var baseCharCode = (style === 'a' ? A_LOWER_CASE : A_UPPER_CASE);
  39897. var letterIndex = currentIndex - 1;
  39898. var character = String.fromCharCode(baseCharCode +
  39899. (letterIndex % LIMIT));
  39900. var charBuf = [];
  39901. for (var j = 0, jj = (letterIndex / LIMIT) | 0; j <= jj; j++) {
  39902. charBuf.push(character);
  39903. }
  39904. currentLabel = charBuf.join('');
  39905. break;
  39906. default:
  39907. assert(!style,
  39908. 'Invalid style "' + style + '" in PageLabel dictionary.');
  39909. }
  39910. pageLabels[i] = prefix + currentLabel;
  39911. currentLabel = '';
  39912. currentIndex++;
  39913. }
  39914. return pageLabels;
  39915. },
  39916. get attachments() {
  39917. var xref = this.xref;
  39918. var attachments = null, nameTreeRef;
  39919. var obj = this.catDict.get('Names');
  39920. if (obj) {
  39921. nameTreeRef = obj.getRaw('EmbeddedFiles');
  39922. }
  39923. if (nameTreeRef) {
  39924. var nameTree = new NameTree(nameTreeRef, xref);
  39925. var names = nameTree.getAll();
  39926. for (var name in names) {
  39927. var fs = new FileSpec(names[name], xref);
  39928. if (!attachments) {
  39929. attachments = Object.create(null);
  39930. }
  39931. attachments[stringToPDFString(name)] = fs.serializable;
  39932. }
  39933. }
  39934. return shadow(this, 'attachments', attachments);
  39935. },
  39936. get javaScript() {
  39937. var xref = this.xref;
  39938. var obj = this.catDict.get('Names');
  39939. var javaScript = [];
  39940. function appendIfJavaScriptDict(jsDict) {
  39941. var type = jsDict.get('S');
  39942. if (!isName(type) || type.name !== 'JavaScript') {
  39943. return;
  39944. }
  39945. var js = jsDict.get('JS');
  39946. if (isStream(js)) {
  39947. js = bytesToString(js.getBytes());
  39948. } else if (!isString(js)) {
  39949. return;
  39950. }
  39951. javaScript.push(stringToPDFString(js));
  39952. }
  39953. if (obj && obj.has('JavaScript')) {
  39954. var nameTree = new NameTree(obj.getRaw('JavaScript'), xref);
  39955. var names = nameTree.getAll();
  39956. for (var name in names) {
  39957. // We don't really use the JavaScript right now. This code is
  39958. // defensive so we don't cause errors on document load.
  39959. var jsDict = names[name];
  39960. if (isDict(jsDict)) {
  39961. appendIfJavaScriptDict(jsDict);
  39962. }
  39963. }
  39964. }
  39965. // Append OpenAction actions to javaScript array
  39966. var openactionDict = this.catDict.get('OpenAction');
  39967. if (isDict(openactionDict, 'Action')) {
  39968. var actionType = openactionDict.get('S');
  39969. if (isName(actionType) && actionType.name === 'Named') {
  39970. // The named Print action is not a part of the PDF 1.7 specification,
  39971. // but is supported by many PDF readers/writers (including Adobe's).
  39972. var action = openactionDict.get('N');
  39973. if (isName(action) && action.name === 'Print') {
  39974. javaScript.push('print({});');
  39975. }
  39976. } else {
  39977. appendIfJavaScriptDict(openactionDict);
  39978. }
  39979. }
  39980. return shadow(this, 'javaScript', javaScript);
  39981. },
  39982. cleanup: function Catalog_cleanup() {
  39983. var promises = [];
  39984. this.fontCache.forEach(function (promise) {
  39985. promises.push(promise);
  39986. });
  39987. return Promise.all(promises).then(function (translatedFonts) {
  39988. for (var i = 0, ii = translatedFonts.length; i < ii; i++) {
  39989. var font = translatedFonts[i].dict;
  39990. delete font.translated;
  39991. }
  39992. this.fontCache.clear();
  39993. }.bind(this));
  39994. },
  39995. getPage: function Catalog_getPage(pageIndex) {
  39996. if (!(pageIndex in this.pagePromises)) {
  39997. this.pagePromises[pageIndex] = this.getPageDict(pageIndex).then(
  39998. function (a) {
  39999. var dict = a[0];
  40000. var ref = a[1];
  40001. return this.pageFactory.createPage(pageIndex, dict, ref,
  40002. this.fontCache);
  40003. }.bind(this)
  40004. );
  40005. }
  40006. return this.pagePromises[pageIndex];
  40007. },
  40008. getPageDict: function Catalog_getPageDict(pageIndex) {
  40009. var capability = createPromiseCapability();
  40010. var nodesToVisit = [this.catDict.getRaw('Pages')];
  40011. var currentPageIndex = 0;
  40012. var xref = this.xref;
  40013. var checkAllKids = false;
  40014. function next() {
  40015. while (nodesToVisit.length) {
  40016. var currentNode = nodesToVisit.pop();
  40017. if (isRef(currentNode)) {
  40018. xref.fetchAsync(currentNode).then(function (obj) {
  40019. if (isDict(obj, 'Page') || (isDict(obj) && !obj.has('Kids'))) {
  40020. if (pageIndex === currentPageIndex) {
  40021. capability.resolve([obj, currentNode]);
  40022. } else {
  40023. currentPageIndex++;
  40024. next();
  40025. }
  40026. return;
  40027. }
  40028. nodesToVisit.push(obj);
  40029. next();
  40030. }, capability.reject);
  40031. return;
  40032. }
  40033. // Must be a child page dictionary.
  40034. assert(
  40035. isDict(currentNode),
  40036. 'page dictionary kid reference points to wrong type of object'
  40037. );
  40038. var count = currentNode.get('Count');
  40039. // If the current node doesn't have any children, avoid getting stuck
  40040. // in an empty node further down in the tree (see issue5644.pdf).
  40041. if (count === 0) {
  40042. checkAllKids = true;
  40043. }
  40044. // Skip nodes where the page can't be.
  40045. if (currentPageIndex + count <= pageIndex) {
  40046. currentPageIndex += count;
  40047. continue;
  40048. }
  40049. var kids = currentNode.get('Kids');
  40050. assert(isArray(kids), 'page dictionary kids object is not an array');
  40051. if (!checkAllKids && count === kids.length) {
  40052. // Nodes that don't have the page have been skipped and this is the
  40053. // bottom of the tree which means the page requested must be a
  40054. // descendant of this pages node. Ideally we would just resolve the
  40055. // promise with the page ref here, but there is the case where more
  40056. // pages nodes could link to single a page (see issue 3666 pdf). To
  40057. // handle this push it back on the queue so if it is a pages node it
  40058. // will be descended into.
  40059. nodesToVisit = [kids[pageIndex - currentPageIndex]];
  40060. currentPageIndex = pageIndex;
  40061. continue;
  40062. } else {
  40063. for (var last = kids.length - 1; last >= 0; last--) {
  40064. nodesToVisit.push(kids[last]);
  40065. }
  40066. }
  40067. }
  40068. capability.reject('Page index ' + pageIndex + ' not found.');
  40069. }
  40070. next();
  40071. return capability.promise;
  40072. },
  40073. getPageIndex: function Catalog_getPageIndex(ref) {
  40074. // The page tree nodes have the count of all the leaves below them. To get
  40075. // how many pages are before we just have to walk up the tree and keep
  40076. // adding the count of siblings to the left of the node.
  40077. var xref = this.xref;
  40078. function pagesBeforeRef(kidRef) {
  40079. var total = 0;
  40080. var parentRef;
  40081. return xref.fetchAsync(kidRef).then(function (node) {
  40082. if (!node) {
  40083. return null;
  40084. }
  40085. parentRef = node.getRaw('Parent');
  40086. return node.getAsync('Parent');
  40087. }).then(function (parent) {
  40088. if (!parent) {
  40089. return null;
  40090. }
  40091. return parent.getAsync('Kids');
  40092. }).then(function (kids) {
  40093. if (!kids) {
  40094. return null;
  40095. }
  40096. var kidPromises = [];
  40097. var found = false;
  40098. for (var i = 0; i < kids.length; i++) {
  40099. var kid = kids[i];
  40100. assert(isRef(kid), 'kids must be a ref');
  40101. if (kid.num === kidRef.num) {
  40102. found = true;
  40103. break;
  40104. }
  40105. kidPromises.push(xref.fetchAsync(kid).then(function (kid) {
  40106. if (kid.has('Count')) {
  40107. var count = kid.get('Count');
  40108. total += count;
  40109. } else { // page leaf node
  40110. total++;
  40111. }
  40112. }));
  40113. }
  40114. if (!found) {
  40115. error('kid ref not found in parents kids');
  40116. }
  40117. return Promise.all(kidPromises).then(function () {
  40118. return [total, parentRef];
  40119. });
  40120. });
  40121. }
  40122. var total = 0;
  40123. function next(ref) {
  40124. return pagesBeforeRef(ref).then(function (args) {
  40125. if (!args) {
  40126. return total;
  40127. }
  40128. var count = args[0];
  40129. var parentRef = args[1];
  40130. total += count;
  40131. return next(parentRef);
  40132. });
  40133. }
  40134. return next(ref);
  40135. }
  40136. };
  40137. return Catalog;
  40138. })();
  40139. var XRef = (function XRefClosure() {
  40140. function XRef(stream, password) {
  40141. this.stream = stream;
  40142. this.entries = [];
  40143. this.xrefstms = Object.create(null);
  40144. // prepare the XRef cache
  40145. this.cache = [];
  40146. this.password = password;
  40147. this.stats = {
  40148. streamTypes: [],
  40149. fontTypes: []
  40150. };
  40151. }
  40152. XRef.prototype = {
  40153. setStartXRef: function XRef_setStartXRef(startXRef) {
  40154. // Store the starting positions of xref tables as we process them
  40155. // so we can recover from missing data errors
  40156. this.startXRefQueue = [startXRef];
  40157. },
  40158. parse: function XRef_parse(recoveryMode) {
  40159. var trailerDict;
  40160. if (!recoveryMode) {
  40161. trailerDict = this.readXRef();
  40162. } else {
  40163. warn('Indexing all PDF objects');
  40164. trailerDict = this.indexObjects();
  40165. }
  40166. trailerDict.assignXref(this);
  40167. this.trailer = trailerDict;
  40168. var encrypt = trailerDict.get('Encrypt');
  40169. if (encrypt) {
  40170. var ids = trailerDict.get('ID');
  40171. var fileId = (ids && ids.length) ? ids[0] : '';
  40172. this.encrypt = new CipherTransformFactory(encrypt, fileId,
  40173. this.password);
  40174. }
  40175. // get the root dictionary (catalog) object
  40176. if (!(this.root = trailerDict.get('Root'))) {
  40177. error('Invalid root reference');
  40178. }
  40179. },
  40180. processXRefTable: function XRef_processXRefTable(parser) {
  40181. if (!('tableState' in this)) {
  40182. // Stores state of the table as we process it so we can resume
  40183. // from middle of table in case of missing data error
  40184. this.tableState = {
  40185. entryNum: 0,
  40186. streamPos: parser.lexer.stream.pos,
  40187. parserBuf1: parser.buf1,
  40188. parserBuf2: parser.buf2
  40189. };
  40190. }
  40191. var obj = this.readXRefTable(parser);
  40192. // Sanity check
  40193. if (!isCmd(obj, 'trailer')) {
  40194. error('Invalid XRef table: could not find trailer dictionary');
  40195. }
  40196. // Read trailer dictionary, e.g.
  40197. // trailer
  40198. // << /Size 22
  40199. // /Root 20R
  40200. // /Info 10R
  40201. // /ID [ <81b14aafa313db63dbd6f981e49f94f4> ]
  40202. // >>
  40203. // The parser goes through the entire stream << ... >> and provides
  40204. // a getter interface for the key-value table
  40205. var dict = parser.getObj();
  40206. // The pdflib PDF generator can generate a nested trailer dictionary
  40207. if (!isDict(dict) && dict.dict) {
  40208. dict = dict.dict;
  40209. }
  40210. if (!isDict(dict)) {
  40211. error('Invalid XRef table: could not parse trailer dictionary');
  40212. }
  40213. delete this.tableState;
  40214. return dict;
  40215. },
  40216. readXRefTable: function XRef_readXRefTable(parser) {
  40217. // Example of cross-reference table:
  40218. // xref
  40219. // 0 1 <-- subsection header (first obj #, obj count)
  40220. // 0000000000 65535 f <-- actual object (offset, generation #, f/n)
  40221. // 23 2 <-- subsection header ... and so on ...
  40222. // 0000025518 00002 n
  40223. // 0000025635 00000 n
  40224. // trailer
  40225. // ...
  40226. var stream = parser.lexer.stream;
  40227. var tableState = this.tableState;
  40228. stream.pos = tableState.streamPos;
  40229. parser.buf1 = tableState.parserBuf1;
  40230. parser.buf2 = tableState.parserBuf2;
  40231. // Outer loop is over subsection headers
  40232. var obj;
  40233. while (true) {
  40234. if (!('firstEntryNum' in tableState) || !('entryCount' in tableState)) {
  40235. if (isCmd(obj = parser.getObj(), 'trailer')) {
  40236. break;
  40237. }
  40238. tableState.firstEntryNum = obj;
  40239. tableState.entryCount = parser.getObj();
  40240. }
  40241. var first = tableState.firstEntryNum;
  40242. var count = tableState.entryCount;
  40243. if (!isInt(first) || !isInt(count)) {
  40244. error('Invalid XRef table: wrong types in subsection header');
  40245. }
  40246. // Inner loop is over objects themselves
  40247. for (var i = tableState.entryNum; i < count; i++) {
  40248. tableState.streamPos = stream.pos;
  40249. tableState.entryNum = i;
  40250. tableState.parserBuf1 = parser.buf1;
  40251. tableState.parserBuf2 = parser.buf2;
  40252. var entry = {};
  40253. entry.offset = parser.getObj();
  40254. entry.gen = parser.getObj();
  40255. var type = parser.getObj();
  40256. if (isCmd(type, 'f')) {
  40257. entry.free = true;
  40258. } else if (isCmd(type, 'n')) {
  40259. entry.uncompressed = true;
  40260. }
  40261. // Validate entry obj
  40262. if (!isInt(entry.offset) || !isInt(entry.gen) ||
  40263. !(entry.free || entry.uncompressed)) {
  40264. error('Invalid entry in XRef subsection: ' + first + ', ' + count);
  40265. }
  40266. if (!this.entries[i + first]) {
  40267. this.entries[i + first] = entry;
  40268. }
  40269. }
  40270. tableState.entryNum = 0;
  40271. tableState.streamPos = stream.pos;
  40272. tableState.parserBuf1 = parser.buf1;
  40273. tableState.parserBuf2 = parser.buf2;
  40274. delete tableState.firstEntryNum;
  40275. delete tableState.entryCount;
  40276. }
  40277. // Per issue 3248: hp scanners generate bad XRef
  40278. if (first === 1 && this.entries[1] && this.entries[1].free) {
  40279. // shifting the entries
  40280. this.entries.shift();
  40281. }
  40282. // Sanity check: as per spec, first object must be free
  40283. if (this.entries[0] && !this.entries[0].free) {
  40284. error('Invalid XRef table: unexpected first object');
  40285. }
  40286. return obj;
  40287. },
  40288. processXRefStream: function XRef_processXRefStream(stream) {
  40289. if (!('streamState' in this)) {
  40290. // Stores state of the stream as we process it so we can resume
  40291. // from middle of stream in case of missing data error
  40292. var streamParameters = stream.dict;
  40293. var byteWidths = streamParameters.get('W');
  40294. var range = streamParameters.get('Index');
  40295. if (!range) {
  40296. range = [0, streamParameters.get('Size')];
  40297. }
  40298. this.streamState = {
  40299. entryRanges: range,
  40300. byteWidths: byteWidths,
  40301. entryNum: 0,
  40302. streamPos: stream.pos
  40303. };
  40304. }
  40305. this.readXRefStream(stream);
  40306. delete this.streamState;
  40307. return stream.dict;
  40308. },
  40309. readXRefStream: function XRef_readXRefStream(stream) {
  40310. var i, j;
  40311. var streamState = this.streamState;
  40312. stream.pos = streamState.streamPos;
  40313. var byteWidths = streamState.byteWidths;
  40314. var typeFieldWidth = byteWidths[0];
  40315. var offsetFieldWidth = byteWidths[1];
  40316. var generationFieldWidth = byteWidths[2];
  40317. var entryRanges = streamState.entryRanges;
  40318. while (entryRanges.length > 0) {
  40319. var first = entryRanges[0];
  40320. var n = entryRanges[1];
  40321. if (!isInt(first) || !isInt(n)) {
  40322. error('Invalid XRef range fields: ' + first + ', ' + n);
  40323. }
  40324. if (!isInt(typeFieldWidth) || !isInt(offsetFieldWidth) ||
  40325. !isInt(generationFieldWidth)) {
  40326. error('Invalid XRef entry fields length: ' + first + ', ' + n);
  40327. }
  40328. for (i = streamState.entryNum; i < n; ++i) {
  40329. streamState.entryNum = i;
  40330. streamState.streamPos = stream.pos;
  40331. var type = 0, offset = 0, generation = 0;
  40332. for (j = 0; j < typeFieldWidth; ++j) {
  40333. type = (type << 8) | stream.getByte();
  40334. }
  40335. // if type field is absent, its default value is 1
  40336. if (typeFieldWidth === 0) {
  40337. type = 1;
  40338. }
  40339. for (j = 0; j < offsetFieldWidth; ++j) {
  40340. offset = (offset << 8) | stream.getByte();
  40341. }
  40342. for (j = 0; j < generationFieldWidth; ++j) {
  40343. generation = (generation << 8) | stream.getByte();
  40344. }
  40345. var entry = {};
  40346. entry.offset = offset;
  40347. entry.gen = generation;
  40348. switch (type) {
  40349. case 0:
  40350. entry.free = true;
  40351. break;
  40352. case 1:
  40353. entry.uncompressed = true;
  40354. break;
  40355. case 2:
  40356. break;
  40357. default:
  40358. error('Invalid XRef entry type: ' + type);
  40359. }
  40360. if (!this.entries[first + i]) {
  40361. this.entries[first + i] = entry;
  40362. }
  40363. }
  40364. streamState.entryNum = 0;
  40365. streamState.streamPos = stream.pos;
  40366. entryRanges.splice(0, 2);
  40367. }
  40368. },
  40369. indexObjects: function XRef_indexObjects() {
  40370. // Simple scan through the PDF content to find objects,
  40371. // trailers and XRef streams.
  40372. var TAB = 0x9, LF = 0xA, CR = 0xD, SPACE = 0x20;
  40373. var PERCENT = 0x25, LT = 0x3C;
  40374. function readToken(data, offset) {
  40375. var token = '', ch = data[offset];
  40376. while (ch !== LF && ch !== CR && ch !== LT) {
  40377. if (++offset >= data.length) {
  40378. break;
  40379. }
  40380. token += String.fromCharCode(ch);
  40381. ch = data[offset];
  40382. }
  40383. return token;
  40384. }
  40385. function skipUntil(data, offset, what) {
  40386. var length = what.length, dataLength = data.length;
  40387. var skipped = 0;
  40388. // finding byte sequence
  40389. while (offset < dataLength) {
  40390. var i = 0;
  40391. while (i < length && data[offset + i] === what[i]) {
  40392. ++i;
  40393. }
  40394. if (i >= length) {
  40395. break; // sequence found
  40396. }
  40397. offset++;
  40398. skipped++;
  40399. }
  40400. return skipped;
  40401. }
  40402. var objRegExp = /^(\d+)\s+(\d+)\s+obj\b/;
  40403. var trailerBytes = new Uint8Array([116, 114, 97, 105, 108, 101, 114]);
  40404. var startxrefBytes = new Uint8Array([115, 116, 97, 114, 116, 120, 114,
  40405. 101, 102]);
  40406. var endobjBytes = new Uint8Array([101, 110, 100, 111, 98, 106]);
  40407. var xrefBytes = new Uint8Array([47, 88, 82, 101, 102]);
  40408. // Clear out any existing entries, since they may be bogus.
  40409. this.entries.length = 0;
  40410. var stream = this.stream;
  40411. stream.pos = 0;
  40412. var buffer = stream.getBytes();
  40413. var position = stream.start, length = buffer.length;
  40414. var trailers = [], xrefStms = [];
  40415. while (position < length) {
  40416. var ch = buffer[position];
  40417. if (ch === TAB || ch === LF || ch === CR || ch === SPACE) {
  40418. ++position;
  40419. continue;
  40420. }
  40421. if (ch === PERCENT) { // %-comment
  40422. do {
  40423. ++position;
  40424. if (position >= length) {
  40425. break;
  40426. }
  40427. ch = buffer[position];
  40428. } while (ch !== LF && ch !== CR);
  40429. continue;
  40430. }
  40431. var token = readToken(buffer, position);
  40432. var m;
  40433. if (token.indexOf('xref') === 0 &&
  40434. (token.length === 4 || /\s/.test(token[4]))) {
  40435. position += skipUntil(buffer, position, trailerBytes);
  40436. trailers.push(position);
  40437. position += skipUntil(buffer, position, startxrefBytes);
  40438. } else if ((m = objRegExp.exec(token))) {
  40439. if (typeof this.entries[m[1]] === 'undefined') {
  40440. this.entries[m[1]] = {
  40441. offset: position - stream.start,
  40442. gen: m[2] | 0,
  40443. uncompressed: true
  40444. };
  40445. }
  40446. var contentLength = skipUntil(buffer, position, endobjBytes) + 7;
  40447. var content = buffer.subarray(position, position + contentLength);
  40448. // checking XRef stream suspect
  40449. // (it shall have '/XRef' and next char is not a letter)
  40450. var xrefTagOffset = skipUntil(content, 0, xrefBytes);
  40451. if (xrefTagOffset < contentLength &&
  40452. content[xrefTagOffset + 5] < 64) {
  40453. xrefStms.push(position - stream.start);
  40454. this.xrefstms[position - stream.start] = 1; // Avoid recursion
  40455. }
  40456. position += contentLength;
  40457. } else if (token.indexOf('trailer') === 0 &&
  40458. (token.length === 7 || /\s/.test(token[7]))) {
  40459. trailers.push(position);
  40460. position += skipUntil(buffer, position, startxrefBytes);
  40461. } else {
  40462. position += token.length + 1;
  40463. }
  40464. }
  40465. // reading XRef streams
  40466. var i, ii;
  40467. for (i = 0, ii = xrefStms.length; i < ii; ++i) {
  40468. this.startXRefQueue.push(xrefStms[i]);
  40469. this.readXRef(/* recoveryMode */ true);
  40470. }
  40471. // finding main trailer
  40472. var dict;
  40473. for (i = 0, ii = trailers.length; i < ii; ++i) {
  40474. stream.pos = trailers[i];
  40475. var parser = new Parser(new Lexer(stream), true, this);
  40476. var obj = parser.getObj();
  40477. if (!isCmd(obj, 'trailer')) {
  40478. continue;
  40479. }
  40480. // read the trailer dictionary
  40481. if (!isDict(dict = parser.getObj())) {
  40482. continue;
  40483. }
  40484. // taking the first one with 'ID'
  40485. if (dict.has('ID')) {
  40486. return dict;
  40487. }
  40488. }
  40489. // no tailer with 'ID', taking last one (if exists)
  40490. if (dict) {
  40491. return dict;
  40492. }
  40493. // nothing helps
  40494. // calling error() would reject worker with an UnknownErrorException.
  40495. throw new InvalidPDFException('Invalid PDF structure');
  40496. },
  40497. readXRef: function XRef_readXRef(recoveryMode) {
  40498. var stream = this.stream;
  40499. try {
  40500. while (this.startXRefQueue.length) {
  40501. var startXRef = this.startXRefQueue[0];
  40502. stream.pos = startXRef + stream.start;
  40503. var parser = new Parser(new Lexer(stream), true, this);
  40504. var obj = parser.getObj();
  40505. var dict;
  40506. // Get dictionary
  40507. if (isCmd(obj, 'xref')) {
  40508. // Parse end-of-file XRef
  40509. dict = this.processXRefTable(parser);
  40510. if (!this.topDict) {
  40511. this.topDict = dict;
  40512. }
  40513. // Recursively get other XRefs 'XRefStm', if any
  40514. obj = dict.get('XRefStm');
  40515. if (isInt(obj)) {
  40516. var pos = obj;
  40517. // ignore previously loaded xref streams
  40518. // (possible infinite recursion)
  40519. if (!(pos in this.xrefstms)) {
  40520. this.xrefstms[pos] = 1;
  40521. this.startXRefQueue.push(pos);
  40522. }
  40523. }
  40524. } else if (isInt(obj)) {
  40525. // Parse in-stream XRef
  40526. if (!isInt(parser.getObj()) ||
  40527. !isCmd(parser.getObj(), 'obj') ||
  40528. !isStream(obj = parser.getObj())) {
  40529. error('Invalid XRef stream');
  40530. }
  40531. dict = this.processXRefStream(obj);
  40532. if (!this.topDict) {
  40533. this.topDict = dict;
  40534. }
  40535. if (!dict) {
  40536. error('Failed to read XRef stream');
  40537. }
  40538. } else {
  40539. error('Invalid XRef stream header');
  40540. }
  40541. // Recursively get previous dictionary, if any
  40542. obj = dict.get('Prev');
  40543. if (isInt(obj)) {
  40544. this.startXRefQueue.push(obj);
  40545. } else if (isRef(obj)) {
  40546. // The spec says Prev must not be a reference, i.e. "/Prev NNN"
  40547. // This is a fallback for non-compliant PDFs, i.e. "/Prev NNN 0 R"
  40548. this.startXRefQueue.push(obj.num);
  40549. }
  40550. this.startXRefQueue.shift();
  40551. }
  40552. return this.topDict;
  40553. } catch (e) {
  40554. if (e instanceof MissingDataException) {
  40555. throw e;
  40556. }
  40557. info('(while reading XRef): ' + e);
  40558. }
  40559. if (recoveryMode) {
  40560. return;
  40561. }
  40562. throw new XRefParseException();
  40563. },
  40564. getEntry: function XRef_getEntry(i) {
  40565. var xrefEntry = this.entries[i];
  40566. if (xrefEntry && !xrefEntry.free && xrefEntry.offset) {
  40567. return xrefEntry;
  40568. }
  40569. return null;
  40570. },
  40571. fetchIfRef: function XRef_fetchIfRef(obj) {
  40572. if (!isRef(obj)) {
  40573. return obj;
  40574. }
  40575. return this.fetch(obj);
  40576. },
  40577. fetch: function XRef_fetch(ref, suppressEncryption) {
  40578. assert(isRef(ref), 'ref object is not a reference');
  40579. var num = ref.num;
  40580. if (num in this.cache) {
  40581. var cacheEntry = this.cache[num];
  40582. return cacheEntry;
  40583. }
  40584. var xrefEntry = this.getEntry(num);
  40585. // the referenced entry can be free
  40586. if (xrefEntry === null) {
  40587. return (this.cache[num] = null);
  40588. }
  40589. if (xrefEntry.uncompressed) {
  40590. xrefEntry = this.fetchUncompressed(ref, xrefEntry, suppressEncryption);
  40591. } else {
  40592. xrefEntry = this.fetchCompressed(xrefEntry, suppressEncryption);
  40593. }
  40594. if (isDict(xrefEntry)){
  40595. xrefEntry.objId = ref.toString();
  40596. } else if (isStream(xrefEntry)) {
  40597. xrefEntry.dict.objId = ref.toString();
  40598. }
  40599. return xrefEntry;
  40600. },
  40601. fetchUncompressed: function XRef_fetchUncompressed(ref, xrefEntry,
  40602. suppressEncryption) {
  40603. var gen = ref.gen;
  40604. var num = ref.num;
  40605. if (xrefEntry.gen !== gen) {
  40606. error('inconsistent generation in XRef');
  40607. }
  40608. var stream = this.stream.makeSubStream(xrefEntry.offset +
  40609. this.stream.start);
  40610. var parser = new Parser(new Lexer(stream), true, this);
  40611. var obj1 = parser.getObj();
  40612. var obj2 = parser.getObj();
  40613. var obj3 = parser.getObj();
  40614. if (!isInt(obj1) || parseInt(obj1, 10) !== num ||
  40615. !isInt(obj2) || parseInt(obj2, 10) !== gen ||
  40616. !isCmd(obj3)) {
  40617. error('bad XRef entry');
  40618. }
  40619. if (!isCmd(obj3, 'obj')) {
  40620. // some bad PDFs use "obj1234" and really mean 1234
  40621. if (obj3.cmd.indexOf('obj') === 0) {
  40622. num = parseInt(obj3.cmd.substring(3), 10);
  40623. if (!isNaN(num)) {
  40624. return num;
  40625. }
  40626. }
  40627. error('bad XRef entry');
  40628. }
  40629. if (this.encrypt && !suppressEncryption) {
  40630. xrefEntry = parser.getObj(this.encrypt.createCipherTransform(num, gen));
  40631. } else {
  40632. xrefEntry = parser.getObj();
  40633. }
  40634. if (!isStream(xrefEntry)) {
  40635. this.cache[num] = xrefEntry;
  40636. }
  40637. return xrefEntry;
  40638. },
  40639. fetchCompressed: function XRef_fetchCompressed(xrefEntry,
  40640. suppressEncryption) {
  40641. var tableOffset = xrefEntry.offset;
  40642. var stream = this.fetch(new Ref(tableOffset, 0));
  40643. if (!isStream(stream)) {
  40644. error('bad ObjStm stream');
  40645. }
  40646. var first = stream.dict.get('First');
  40647. var n = stream.dict.get('N');
  40648. if (!isInt(first) || !isInt(n)) {
  40649. error('invalid first and n parameters for ObjStm stream');
  40650. }
  40651. var parser = new Parser(new Lexer(stream), false, this);
  40652. parser.allowStreams = true;
  40653. var i, entries = [], num, nums = [];
  40654. // read the object numbers to populate cache
  40655. for (i = 0; i < n; ++i) {
  40656. num = parser.getObj();
  40657. if (!isInt(num)) {
  40658. error('invalid object number in the ObjStm stream: ' + num);
  40659. }
  40660. nums.push(num);
  40661. var offset = parser.getObj();
  40662. if (!isInt(offset)) {
  40663. error('invalid object offset in the ObjStm stream: ' + offset);
  40664. }
  40665. }
  40666. // read stream objects for cache
  40667. for (i = 0; i < n; ++i) {
  40668. entries.push(parser.getObj());
  40669. num = nums[i];
  40670. var entry = this.entries[num];
  40671. if (entry && entry.offset === tableOffset && entry.gen === i) {
  40672. this.cache[num] = entries[i];
  40673. }
  40674. }
  40675. xrefEntry = entries[xrefEntry.gen];
  40676. if (xrefEntry === undefined) {
  40677. error('bad XRef entry for compressed object');
  40678. }
  40679. return xrefEntry;
  40680. },
  40681. fetchIfRefAsync: function XRef_fetchIfRefAsync(obj) {
  40682. if (!isRef(obj)) {
  40683. return Promise.resolve(obj);
  40684. }
  40685. return this.fetchAsync(obj);
  40686. },
  40687. fetchAsync: function XRef_fetchAsync(ref, suppressEncryption) {
  40688. var streamManager = this.stream.manager;
  40689. var xref = this;
  40690. return new Promise(function tryFetch(resolve, reject) {
  40691. try {
  40692. resolve(xref.fetch(ref, suppressEncryption));
  40693. } catch (e) {
  40694. if (e instanceof MissingDataException) {
  40695. streamManager.requestRange(e.begin, e.end).then(function () {
  40696. tryFetch(resolve, reject);
  40697. }, reject);
  40698. return;
  40699. }
  40700. reject(e);
  40701. }
  40702. });
  40703. },
  40704. getCatalogObj: function XRef_getCatalogObj() {
  40705. return this.root;
  40706. }
  40707. };
  40708. return XRef;
  40709. })();
  40710. /**
  40711. * A NameTree/NumberTree is like a Dict but has some advantageous properties,
  40712. * see the specification (7.9.6 and 7.9.7) for additional details.
  40713. * TODO: implement all the Dict functions and make this more efficient.
  40714. */
  40715. var NameOrNumberTree = (function NameOrNumberTreeClosure() {
  40716. function NameOrNumberTree(root, xref) {
  40717. throw new Error('Cannot initialize NameOrNumberTree.');
  40718. }
  40719. NameOrNumberTree.prototype = {
  40720. getAll: function NameOrNumberTree_getAll() {
  40721. var dict = Object.create(null);
  40722. if (!this.root) {
  40723. return dict;
  40724. }
  40725. var xref = this.xref;
  40726. // Reading Name/Number tree.
  40727. var processed = new RefSet();
  40728. processed.put(this.root);
  40729. var queue = [this.root];
  40730. while (queue.length > 0) {
  40731. var i, n;
  40732. var obj = xref.fetchIfRef(queue.shift());
  40733. if (!isDict(obj)) {
  40734. continue;
  40735. }
  40736. if (obj.has('Kids')) {
  40737. var kids = obj.get('Kids');
  40738. for (i = 0, n = kids.length; i < n; i++) {
  40739. var kid = kids[i];
  40740. assert(!processed.has(kid),
  40741. 'Duplicate entry in "' + this._type + '" tree.');
  40742. queue.push(kid);
  40743. processed.put(kid);
  40744. }
  40745. continue;
  40746. }
  40747. var entries = obj.get(this._type);
  40748. if (isArray(entries)) {
  40749. for (i = 0, n = entries.length; i < n; i += 2) {
  40750. dict[xref.fetchIfRef(entries[i])] = xref.fetchIfRef(entries[i + 1]);
  40751. }
  40752. }
  40753. }
  40754. return dict;
  40755. },
  40756. get: function NameOrNumberTree_get(key) {
  40757. if (!this.root) {
  40758. return null;
  40759. }
  40760. var xref = this.xref;
  40761. var kidsOrEntries = xref.fetchIfRef(this.root);
  40762. var loopCount = 0;
  40763. var MAX_LEVELS = 10;
  40764. var l, r, m;
  40765. // Perform a binary search to quickly find the entry that
  40766. // contains the key we are looking for.
  40767. while (kidsOrEntries.has('Kids')) {
  40768. if (++loopCount > MAX_LEVELS) {
  40769. warn('Search depth limit reached for "' + this._type + '" tree.');
  40770. return null;
  40771. }
  40772. var kids = kidsOrEntries.get('Kids');
  40773. if (!isArray(kids)) {
  40774. return null;
  40775. }
  40776. l = 0;
  40777. r = kids.length - 1;
  40778. while (l <= r) {
  40779. m = (l + r) >> 1;
  40780. var kid = xref.fetchIfRef(kids[m]);
  40781. var limits = kid.get('Limits');
  40782. if (key < xref.fetchIfRef(limits[0])) {
  40783. r = m - 1;
  40784. } else if (key > xref.fetchIfRef(limits[1])) {
  40785. l = m + 1;
  40786. } else {
  40787. kidsOrEntries = xref.fetchIfRef(kids[m]);
  40788. break;
  40789. }
  40790. }
  40791. if (l > r) {
  40792. return null;
  40793. }
  40794. }
  40795. // If we get here, then we have found the right entry. Now go through the
  40796. // entries in the dictionary until we find the key we're looking for.
  40797. var entries = kidsOrEntries.get(this._type);
  40798. if (isArray(entries)) {
  40799. // Perform a binary search to reduce the lookup time.
  40800. l = 0;
  40801. r = entries.length - 2;
  40802. while (l <= r) {
  40803. // Check only even indices (0, 2, 4, ...) because the
  40804. // odd indices contain the actual data.
  40805. m = (l + r) & ~1;
  40806. var currentKey = xref.fetchIfRef(entries[m]);
  40807. if (key < currentKey) {
  40808. r = m - 2;
  40809. } else if (key > currentKey) {
  40810. l = m + 2;
  40811. } else {
  40812. return xref.fetchIfRef(entries[m + 1]);
  40813. }
  40814. }
  40815. }
  40816. return null;
  40817. }
  40818. };
  40819. return NameOrNumberTree;
  40820. })();
  40821. var NameTree = (function NameTreeClosure() {
  40822. function NameTree(root, xref) {
  40823. this.root = root;
  40824. this.xref = xref;
  40825. this._type = 'Names';
  40826. }
  40827. Util.inherit(NameTree, NameOrNumberTree, {});
  40828. return NameTree;
  40829. })();
  40830. var NumberTree = (function NumberTreeClosure() {
  40831. function NumberTree(root, xref) {
  40832. this.root = root;
  40833. this.xref = xref;
  40834. this._type = 'Nums';
  40835. }
  40836. Util.inherit(NumberTree, NameOrNumberTree, {});
  40837. return NumberTree;
  40838. })();
  40839. /**
  40840. * "A PDF file can refer to the contents of another file by using a File
  40841. * Specification (PDF 1.1)", see the spec (7.11) for more details.
  40842. * NOTE: Only embedded files are supported (as part of the attachments support)
  40843. * TODO: support the 'URL' file system (with caching if !/V), portable
  40844. * collections attributes and related files (/RF)
  40845. */
  40846. var FileSpec = (function FileSpecClosure() {
  40847. function FileSpec(root, xref) {
  40848. if (!root || !isDict(root)) {
  40849. return;
  40850. }
  40851. this.xref = xref;
  40852. this.root = root;
  40853. if (root.has('FS')) {
  40854. this.fs = root.get('FS');
  40855. }
  40856. this.description = root.has('Desc') ?
  40857. stringToPDFString(root.get('Desc')) :
  40858. '';
  40859. if (root.has('RF')) {
  40860. warn('Related file specifications are not supported');
  40861. }
  40862. this.contentAvailable = true;
  40863. if (!root.has('EF')) {
  40864. this.contentAvailable = false;
  40865. warn('Non-embedded file specifications are not supported');
  40866. }
  40867. }
  40868. function pickPlatformItem(dict) {
  40869. // Look for the filename in this order:
  40870. // UF, F, Unix, Mac, DOS
  40871. if (dict.has('UF')) {
  40872. return dict.get('UF');
  40873. } else if (dict.has('F')) {
  40874. return dict.get('F');
  40875. } else if (dict.has('Unix')) {
  40876. return dict.get('Unix');
  40877. } else if (dict.has('Mac')) {
  40878. return dict.get('Mac');
  40879. } else if (dict.has('DOS')) {
  40880. return dict.get('DOS');
  40881. } else {
  40882. return null;
  40883. }
  40884. }
  40885. FileSpec.prototype = {
  40886. get filename() {
  40887. if (!this._filename && this.root) {
  40888. var filename = pickPlatformItem(this.root) || 'unnamed';
  40889. this._filename = stringToPDFString(filename).
  40890. replace(/\\\\/g, '\\').
  40891. replace(/\\\//g, '/').
  40892. replace(/\\/g, '/');
  40893. }
  40894. return this._filename;
  40895. },
  40896. get content() {
  40897. if (!this.contentAvailable) {
  40898. return null;
  40899. }
  40900. if (!this.contentRef && this.root) {
  40901. this.contentRef = pickPlatformItem(this.root.get('EF'));
  40902. }
  40903. var content = null;
  40904. if (this.contentRef) {
  40905. var xref = this.xref;
  40906. var fileObj = xref.fetchIfRef(this.contentRef);
  40907. if (fileObj && isStream(fileObj)) {
  40908. content = fileObj.getBytes();
  40909. } else {
  40910. warn('Embedded file specification points to non-existing/invalid ' +
  40911. 'content');
  40912. }
  40913. } else {
  40914. warn('Embedded file specification does not have a content');
  40915. }
  40916. return content;
  40917. },
  40918. get serializable() {
  40919. return {
  40920. filename: this.filename,
  40921. content: this.content
  40922. };
  40923. }
  40924. };
  40925. return FileSpec;
  40926. })();
  40927. /**
  40928. * A helper for loading missing data in object graphs. It traverses the graph
  40929. * depth first and queues up any objects that have missing data. Once it has
  40930. * has traversed as many objects that are available it attempts to bundle the
  40931. * missing data requests and then resume from the nodes that weren't ready.
  40932. *
  40933. * NOTE: It provides protection from circular references by keeping track of
  40934. * of loaded references. However, you must be careful not to load any graphs
  40935. * that have references to the catalog or other pages since that will cause the
  40936. * entire PDF document object graph to be traversed.
  40937. */
  40938. var ObjectLoader = (function() {
  40939. function mayHaveChildren(value) {
  40940. return isRef(value) || isDict(value) || isArray(value) || isStream(value);
  40941. }
  40942. function addChildren(node, nodesToVisit) {
  40943. var value;
  40944. if (isDict(node) || isStream(node)) {
  40945. var map;
  40946. if (isDict(node)) {
  40947. map = node.map;
  40948. } else {
  40949. map = node.dict.map;
  40950. }
  40951. for (var key in map) {
  40952. value = map[key];
  40953. if (mayHaveChildren(value)) {
  40954. nodesToVisit.push(value);
  40955. }
  40956. }
  40957. } else if (isArray(node)) {
  40958. for (var i = 0, ii = node.length; i < ii; i++) {
  40959. value = node[i];
  40960. if (mayHaveChildren(value)) {
  40961. nodesToVisit.push(value);
  40962. }
  40963. }
  40964. }
  40965. }
  40966. function ObjectLoader(obj, keys, xref) {
  40967. this.obj = obj;
  40968. this.keys = keys;
  40969. this.xref = xref;
  40970. this.refSet = null;
  40971. this.capability = null;
  40972. }
  40973. ObjectLoader.prototype = {
  40974. load: function ObjectLoader_load() {
  40975. var keys = this.keys;
  40976. this.capability = createPromiseCapability();
  40977. // Don't walk the graph if all the data is already loaded.
  40978. if (!(this.xref.stream instanceof ChunkedStream) ||
  40979. this.xref.stream.getMissingChunks().length === 0) {
  40980. this.capability.resolve();
  40981. return this.capability.promise;
  40982. }
  40983. this.refSet = new RefSet();
  40984. // Setup the initial nodes to visit.
  40985. var nodesToVisit = [];
  40986. for (var i = 0; i < keys.length; i++) {
  40987. nodesToVisit.push(this.obj[keys[i]]);
  40988. }
  40989. this._walk(nodesToVisit);
  40990. return this.capability.promise;
  40991. },
  40992. _walk: function ObjectLoader_walk(nodesToVisit) {
  40993. var nodesToRevisit = [];
  40994. var pendingRequests = [];
  40995. // DFS walk of the object graph.
  40996. while (nodesToVisit.length) {
  40997. var currentNode = nodesToVisit.pop();
  40998. // Only references or chunked streams can cause missing data exceptions.
  40999. if (isRef(currentNode)) {
  41000. // Skip nodes that have already been visited.
  41001. if (this.refSet.has(currentNode)) {
  41002. continue;
  41003. }
  41004. try {
  41005. var ref = currentNode;
  41006. this.refSet.put(ref);
  41007. currentNode = this.xref.fetch(currentNode);
  41008. } catch (e) {
  41009. if (!(e instanceof MissingDataException)) {
  41010. throw e;
  41011. }
  41012. nodesToRevisit.push(currentNode);
  41013. pendingRequests.push({ begin: e.begin, end: e.end });
  41014. }
  41015. }
  41016. if (currentNode && currentNode.getBaseStreams) {
  41017. var baseStreams = currentNode.getBaseStreams();
  41018. var foundMissingData = false;
  41019. for (var i = 0; i < baseStreams.length; i++) {
  41020. var stream = baseStreams[i];
  41021. if (stream.getMissingChunks && stream.getMissingChunks().length) {
  41022. foundMissingData = true;
  41023. pendingRequests.push({
  41024. begin: stream.start,
  41025. end: stream.end
  41026. });
  41027. }
  41028. }
  41029. if (foundMissingData) {
  41030. nodesToRevisit.push(currentNode);
  41031. }
  41032. }
  41033. addChildren(currentNode, nodesToVisit);
  41034. }
  41035. if (pendingRequests.length) {
  41036. this.xref.stream.manager.requestRanges(pendingRequests).then(
  41037. function pendingRequestCallback() {
  41038. nodesToVisit = nodesToRevisit;
  41039. for (var i = 0; i < nodesToRevisit.length; i++) {
  41040. var node = nodesToRevisit[i];
  41041. // Remove any reference nodes from the currrent refset so they
  41042. // aren't skipped when we revist them.
  41043. if (isRef(node)) {
  41044. this.refSet.remove(node);
  41045. }
  41046. }
  41047. this._walk(nodesToVisit);
  41048. }.bind(this), this.capability.reject);
  41049. return;
  41050. }
  41051. // Everything is loaded.
  41052. this.refSet = null;
  41053. this.capability.resolve();
  41054. }
  41055. };
  41056. return ObjectLoader;
  41057. })();
  41058. exports.Catalog = Catalog;
  41059. exports.ObjectLoader = ObjectLoader;
  41060. exports.XRef = XRef;
  41061. exports.FileSpec = FileSpec;
  41062. }));
  41063. (function (root, factory) {
  41064. {
  41065. factory((root.pdfjsCorePattern = {}), root.pdfjsSharedUtil,
  41066. root.pdfjsCorePrimitives, root.pdfjsCoreFunction,
  41067. root.pdfjsCoreColorSpace);
  41068. }
  41069. }(this, function (exports, sharedUtil, corePrimitives, coreFunction,
  41070. coreColorSpace) {
  41071. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41072. var MissingDataException = sharedUtil.MissingDataException;
  41073. var Util = sharedUtil.Util;
  41074. var assert = sharedUtil.assert;
  41075. var error = sharedUtil.error;
  41076. var info = sharedUtil.info;
  41077. var warn = sharedUtil.warn;
  41078. var isStream = corePrimitives.isStream;
  41079. var PDFFunction = coreFunction.PDFFunction;
  41080. var ColorSpace = coreColorSpace.ColorSpace;
  41081. var ShadingType = {
  41082. FUNCTION_BASED: 1,
  41083. AXIAL: 2,
  41084. RADIAL: 3,
  41085. FREE_FORM_MESH: 4,
  41086. LATTICE_FORM_MESH: 5,
  41087. COONS_PATCH_MESH: 6,
  41088. TENSOR_PATCH_MESH: 7
  41089. };
  41090. var Pattern = (function PatternClosure() {
  41091. // Constructor should define this.getPattern
  41092. function Pattern() {
  41093. error('should not call Pattern constructor');
  41094. }
  41095. Pattern.prototype = {
  41096. // Input: current Canvas context
  41097. // Output: the appropriate fillStyle or strokeStyle
  41098. getPattern: function Pattern_getPattern(ctx) {
  41099. error('Should not call Pattern.getStyle: ' + ctx);
  41100. }
  41101. };
  41102. Pattern.parseShading = function Pattern_parseShading(shading, matrix, xref,
  41103. res, handler) {
  41104. var dict = isStream(shading) ? shading.dict : shading;
  41105. var type = dict.get('ShadingType');
  41106. try {
  41107. switch (type) {
  41108. case ShadingType.AXIAL:
  41109. case ShadingType.RADIAL:
  41110. // Both radial and axial shadings are handled by RadialAxial shading.
  41111. return new Shadings.RadialAxial(dict, matrix, xref, res);
  41112. case ShadingType.FREE_FORM_MESH:
  41113. case ShadingType.LATTICE_FORM_MESH:
  41114. case ShadingType.COONS_PATCH_MESH:
  41115. case ShadingType.TENSOR_PATCH_MESH:
  41116. return new Shadings.Mesh(shading, matrix, xref, res);
  41117. default:
  41118. throw new Error('Unsupported ShadingType: ' + type);
  41119. }
  41120. } catch (ex) {
  41121. if (ex instanceof MissingDataException) {
  41122. throw ex;
  41123. }
  41124. handler.send('UnsupportedFeature',
  41125. {featureId: UNSUPPORTED_FEATURES.shadingPattern});
  41126. warn(ex);
  41127. return new Shadings.Dummy();
  41128. }
  41129. };
  41130. return Pattern;
  41131. })();
  41132. var Shadings = {};
  41133. // A small number to offset the first/last color stops so we can insert ones to
  41134. // support extend. Number.MIN_VALUE is too small and breaks the extend.
  41135. Shadings.SMALL_NUMBER = 1e-6;
  41136. // Radial and axial shading have very similar implementations
  41137. // If needed, the implementations can be broken into two classes
  41138. Shadings.RadialAxial = (function RadialAxialClosure() {
  41139. function RadialAxial(dict, matrix, xref, res) {
  41140. this.matrix = matrix;
  41141. this.coordsArr = dict.get('Coords');
  41142. this.shadingType = dict.get('ShadingType');
  41143. this.type = 'Pattern';
  41144. var cs = dict.get('ColorSpace', 'CS');
  41145. cs = ColorSpace.parse(cs, xref, res);
  41146. this.cs = cs;
  41147. var t0 = 0.0, t1 = 1.0;
  41148. if (dict.has('Domain')) {
  41149. var domainArr = dict.get('Domain');
  41150. t0 = domainArr[0];
  41151. t1 = domainArr[1];
  41152. }
  41153. var extendStart = false, extendEnd = false;
  41154. if (dict.has('Extend')) {
  41155. var extendArr = dict.get('Extend');
  41156. extendStart = extendArr[0];
  41157. extendEnd = extendArr[1];
  41158. }
  41159. if (this.shadingType === ShadingType.RADIAL &&
  41160. (!extendStart || !extendEnd)) {
  41161. // Radial gradient only currently works if either circle is fully within
  41162. // the other circle.
  41163. var x1 = this.coordsArr[0];
  41164. var y1 = this.coordsArr[1];
  41165. var r1 = this.coordsArr[2];
  41166. var x2 = this.coordsArr[3];
  41167. var y2 = this.coordsArr[4];
  41168. var r2 = this.coordsArr[5];
  41169. var distance = Math.sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
  41170. if (r1 <= r2 + distance &&
  41171. r2 <= r1 + distance) {
  41172. warn('Unsupported radial gradient.');
  41173. }
  41174. }
  41175. this.extendStart = extendStart;
  41176. this.extendEnd = extendEnd;
  41177. var fnObj = dict.get('Function');
  41178. var fn = PDFFunction.parseArray(xref, fnObj);
  41179. // 10 samples seems good enough for now, but probably won't work
  41180. // if there are sharp color changes. Ideally, we would implement
  41181. // the spec faithfully and add lossless optimizations.
  41182. var diff = t1 - t0;
  41183. var step = diff / 10;
  41184. var colorStops = this.colorStops = [];
  41185. // Protect against bad domains so we don't end up in an infinte loop below.
  41186. if (t0 >= t1 || step <= 0) {
  41187. // Acrobat doesn't seem to handle these cases so we'll ignore for
  41188. // now.
  41189. info('Bad shading domain.');
  41190. return;
  41191. }
  41192. var color = new Float32Array(cs.numComps), ratio = new Float32Array(1);
  41193. var rgbColor;
  41194. for (var i = t0; i <= t1; i += step) {
  41195. ratio[0] = i;
  41196. fn(ratio, 0, color, 0);
  41197. rgbColor = cs.getRgb(color, 0);
  41198. var cssColor = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41199. colorStops.push([(i - t0) / diff, cssColor]);
  41200. }
  41201. var background = 'transparent';
  41202. if (dict.has('Background')) {
  41203. rgbColor = cs.getRgb(dict.get('Background'), 0);
  41204. background = Util.makeCssRgb(rgbColor[0], rgbColor[1], rgbColor[2]);
  41205. }
  41206. if (!extendStart) {
  41207. // Insert a color stop at the front and offset the first real color stop
  41208. // so it doesn't conflict with the one we insert.
  41209. colorStops.unshift([0, background]);
  41210. colorStops[1][0] += Shadings.SMALL_NUMBER;
  41211. }
  41212. if (!extendEnd) {
  41213. // Same idea as above in extendStart but for the end.
  41214. colorStops[colorStops.length - 1][0] -= Shadings.SMALL_NUMBER;
  41215. colorStops.push([1, background]);
  41216. }
  41217. this.colorStops = colorStops;
  41218. }
  41219. RadialAxial.prototype = {
  41220. getIR: function RadialAxial_getIR() {
  41221. var coordsArr = this.coordsArr;
  41222. var shadingType = this.shadingType;
  41223. var type, p0, p1, r0, r1;
  41224. if (shadingType === ShadingType.AXIAL) {
  41225. p0 = [coordsArr[0], coordsArr[1]];
  41226. p1 = [coordsArr[2], coordsArr[3]];
  41227. r0 = null;
  41228. r1 = null;
  41229. type = 'axial';
  41230. } else if (shadingType === ShadingType.RADIAL) {
  41231. p0 = [coordsArr[0], coordsArr[1]];
  41232. p1 = [coordsArr[3], coordsArr[4]];
  41233. r0 = coordsArr[2];
  41234. r1 = coordsArr[5];
  41235. type = 'radial';
  41236. } else {
  41237. error('getPattern type unknown: ' + shadingType);
  41238. }
  41239. var matrix = this.matrix;
  41240. if (matrix) {
  41241. p0 = Util.applyTransform(p0, matrix);
  41242. p1 = Util.applyTransform(p1, matrix);
  41243. if (shadingType === ShadingType.RADIAL) {
  41244. var scale = Util.singularValueDecompose2dScale(matrix);
  41245. r0 *= scale[0];
  41246. r1 *= scale[1];
  41247. }
  41248. }
  41249. return ['RadialAxial', type, this.colorStops, p0, p1, r0, r1];
  41250. }
  41251. };
  41252. return RadialAxial;
  41253. })();
  41254. // All mesh shading. For now, they will be presented as set of the triangles
  41255. // to be drawn on the canvas and rgb color for each vertex.
  41256. Shadings.Mesh = (function MeshClosure() {
  41257. function MeshStreamReader(stream, context) {
  41258. this.stream = stream;
  41259. this.context = context;
  41260. this.buffer = 0;
  41261. this.bufferLength = 0;
  41262. var numComps = context.numComps;
  41263. this.tmpCompsBuf = new Float32Array(numComps);
  41264. var csNumComps = context.colorSpace.numComps;
  41265. this.tmpCsCompsBuf = context.colorFn ? new Float32Array(csNumComps) :
  41266. this.tmpCompsBuf;
  41267. }
  41268. MeshStreamReader.prototype = {
  41269. get hasData() {
  41270. if (this.stream.end) {
  41271. return this.stream.pos < this.stream.end;
  41272. }
  41273. if (this.bufferLength > 0) {
  41274. return true;
  41275. }
  41276. var nextByte = this.stream.getByte();
  41277. if (nextByte < 0) {
  41278. return false;
  41279. }
  41280. this.buffer = nextByte;
  41281. this.bufferLength = 8;
  41282. return true;
  41283. },
  41284. readBits: function MeshStreamReader_readBits(n) {
  41285. var buffer = this.buffer;
  41286. var bufferLength = this.bufferLength;
  41287. if (n === 32) {
  41288. if (bufferLength === 0) {
  41289. return ((this.stream.getByte() << 24) |
  41290. (this.stream.getByte() << 16) | (this.stream.getByte() << 8) |
  41291. this.stream.getByte()) >>> 0;
  41292. }
  41293. buffer = (buffer << 24) | (this.stream.getByte() << 16) |
  41294. (this.stream.getByte() << 8) | this.stream.getByte();
  41295. var nextByte = this.stream.getByte();
  41296. this.buffer = nextByte & ((1 << bufferLength) - 1);
  41297. return ((buffer << (8 - bufferLength)) |
  41298. ((nextByte & 0xFF) >> bufferLength)) >>> 0;
  41299. }
  41300. if (n === 8 && bufferLength === 0) {
  41301. return this.stream.getByte();
  41302. }
  41303. while (bufferLength < n) {
  41304. buffer = (buffer << 8) | this.stream.getByte();
  41305. bufferLength += 8;
  41306. }
  41307. bufferLength -= n;
  41308. this.bufferLength = bufferLength;
  41309. this.buffer = buffer & ((1 << bufferLength) - 1);
  41310. return buffer >> bufferLength;
  41311. },
  41312. align: function MeshStreamReader_align() {
  41313. this.buffer = 0;
  41314. this.bufferLength = 0;
  41315. },
  41316. readFlag: function MeshStreamReader_readFlag() {
  41317. return this.readBits(this.context.bitsPerFlag);
  41318. },
  41319. readCoordinate: function MeshStreamReader_readCoordinate() {
  41320. var bitsPerCoordinate = this.context.bitsPerCoordinate;
  41321. var xi = this.readBits(bitsPerCoordinate);
  41322. var yi = this.readBits(bitsPerCoordinate);
  41323. var decode = this.context.decode;
  41324. var scale = bitsPerCoordinate < 32 ? 1 / ((1 << bitsPerCoordinate) - 1) :
  41325. 2.3283064365386963e-10; // 2 ^ -32
  41326. return [
  41327. xi * scale * (decode[1] - decode[0]) + decode[0],
  41328. yi * scale * (decode[3] - decode[2]) + decode[2]
  41329. ];
  41330. },
  41331. readComponents: function MeshStreamReader_readComponents() {
  41332. var numComps = this.context.numComps;
  41333. var bitsPerComponent = this.context.bitsPerComponent;
  41334. var scale = bitsPerComponent < 32 ? 1 / ((1 << bitsPerComponent) - 1) :
  41335. 2.3283064365386963e-10; // 2 ^ -32
  41336. var decode = this.context.decode;
  41337. var components = this.tmpCompsBuf;
  41338. for (var i = 0, j = 4; i < numComps; i++, j += 2) {
  41339. var ci = this.readBits(bitsPerComponent);
  41340. components[i] = ci * scale * (decode[j + 1] - decode[j]) + decode[j];
  41341. }
  41342. var color = this.tmpCsCompsBuf;
  41343. if (this.context.colorFn) {
  41344. this.context.colorFn(components, 0, color, 0);
  41345. }
  41346. return this.context.colorSpace.getRgb(color, 0);
  41347. }
  41348. };
  41349. function decodeType4Shading(mesh, reader) {
  41350. var coords = mesh.coords;
  41351. var colors = mesh.colors;
  41352. var operators = [];
  41353. var ps = []; // not maintaining cs since that will match ps
  41354. var verticesLeft = 0; // assuming we have all data to start a new triangle
  41355. while (reader.hasData) {
  41356. var f = reader.readFlag();
  41357. var coord = reader.readCoordinate();
  41358. var color = reader.readComponents();
  41359. if (verticesLeft === 0) { // ignoring flags if we started a triangle
  41360. assert(0 <= f && f <= 2, 'Unknown type4 flag');
  41361. switch (f) {
  41362. case 0:
  41363. verticesLeft = 3;
  41364. break;
  41365. case 1:
  41366. ps.push(ps[ps.length - 2], ps[ps.length - 1]);
  41367. verticesLeft = 1;
  41368. break;
  41369. case 2:
  41370. ps.push(ps[ps.length - 3], ps[ps.length - 1]);
  41371. verticesLeft = 1;
  41372. break;
  41373. }
  41374. operators.push(f);
  41375. }
  41376. ps.push(coords.length);
  41377. coords.push(coord);
  41378. colors.push(color);
  41379. verticesLeft--;
  41380. reader.align();
  41381. }
  41382. mesh.figures.push({
  41383. type: 'triangles',
  41384. coords: new Int32Array(ps),
  41385. colors: new Int32Array(ps),
  41386. });
  41387. }
  41388. function decodeType5Shading(mesh, reader, verticesPerRow) {
  41389. var coords = mesh.coords;
  41390. var colors = mesh.colors;
  41391. var ps = []; // not maintaining cs since that will match ps
  41392. while (reader.hasData) {
  41393. var coord = reader.readCoordinate();
  41394. var color = reader.readComponents();
  41395. ps.push(coords.length);
  41396. coords.push(coord);
  41397. colors.push(color);
  41398. }
  41399. mesh.figures.push({
  41400. type: 'lattice',
  41401. coords: new Int32Array(ps),
  41402. colors: new Int32Array(ps),
  41403. verticesPerRow: verticesPerRow
  41404. });
  41405. }
  41406. var MIN_SPLIT_PATCH_CHUNKS_AMOUNT = 3;
  41407. var MAX_SPLIT_PATCH_CHUNKS_AMOUNT = 20;
  41408. var TRIANGLE_DENSITY = 20; // count of triangles per entire mesh bounds
  41409. var getB = (function getBClosure() {
  41410. function buildB(count) {
  41411. var lut = [];
  41412. for (var i = 0; i <= count; i++) {
  41413. var t = i / count, t_ = 1 - t;
  41414. lut.push(new Float32Array([t_ * t_ * t_, 3 * t * t_ * t_,
  41415. 3 * t * t * t_, t * t * t]));
  41416. }
  41417. return lut;
  41418. }
  41419. var cache = [];
  41420. return function getB(count) {
  41421. if (!cache[count]) {
  41422. cache[count] = buildB(count);
  41423. }
  41424. return cache[count];
  41425. };
  41426. })();
  41427. function buildFigureFromPatch(mesh, index) {
  41428. var figure = mesh.figures[index];
  41429. assert(figure.type === 'patch', 'Unexpected patch mesh figure');
  41430. var coords = mesh.coords, colors = mesh.colors;
  41431. var pi = figure.coords;
  41432. var ci = figure.colors;
  41433. var figureMinX = Math.min(coords[pi[0]][0], coords[pi[3]][0],
  41434. coords[pi[12]][0], coords[pi[15]][0]);
  41435. var figureMinY = Math.min(coords[pi[0]][1], coords[pi[3]][1],
  41436. coords[pi[12]][1], coords[pi[15]][1]);
  41437. var figureMaxX = Math.max(coords[pi[0]][0], coords[pi[3]][0],
  41438. coords[pi[12]][0], coords[pi[15]][0]);
  41439. var figureMaxY = Math.max(coords[pi[0]][1], coords[pi[3]][1],
  41440. coords[pi[12]][1], coords[pi[15]][1]);
  41441. var splitXBy = Math.ceil((figureMaxX - figureMinX) * TRIANGLE_DENSITY /
  41442. (mesh.bounds[2] - mesh.bounds[0]));
  41443. splitXBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41444. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy));
  41445. var splitYBy = Math.ceil((figureMaxY - figureMinY) * TRIANGLE_DENSITY /
  41446. (mesh.bounds[3] - mesh.bounds[1]));
  41447. splitYBy = Math.max(MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
  41448. Math.min(MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy));
  41449. var verticesPerRow = splitXBy + 1;
  41450. var figureCoords = new Int32Array((splitYBy + 1) * verticesPerRow);
  41451. var figureColors = new Int32Array((splitYBy + 1) * verticesPerRow);
  41452. var k = 0;
  41453. var cl = new Uint8Array(3), cr = new Uint8Array(3);
  41454. var c0 = colors[ci[0]], c1 = colors[ci[1]],
  41455. c2 = colors[ci[2]], c3 = colors[ci[3]];
  41456. var bRow = getB(splitYBy), bCol = getB(splitXBy);
  41457. for (var row = 0; row <= splitYBy; row++) {
  41458. cl[0] = ((c0[0] * (splitYBy - row) + c2[0] * row) / splitYBy) | 0;
  41459. cl[1] = ((c0[1] * (splitYBy - row) + c2[1] * row) / splitYBy) | 0;
  41460. cl[2] = ((c0[2] * (splitYBy - row) + c2[2] * row) / splitYBy) | 0;
  41461. cr[0] = ((c1[0] * (splitYBy - row) + c3[0] * row) / splitYBy) | 0;
  41462. cr[1] = ((c1[1] * (splitYBy - row) + c3[1] * row) / splitYBy) | 0;
  41463. cr[2] = ((c1[2] * (splitYBy - row) + c3[2] * row) / splitYBy) | 0;
  41464. for (var col = 0; col <= splitXBy; col++, k++) {
  41465. if ((row === 0 || row === splitYBy) &&
  41466. (col === 0 || col === splitXBy)) {
  41467. continue;
  41468. }
  41469. var x = 0, y = 0;
  41470. var q = 0;
  41471. for (var i = 0; i <= 3; i++) {
  41472. for (var j = 0; j <= 3; j++, q++) {
  41473. var m = bRow[row][i] * bCol[col][j];
  41474. x += coords[pi[q]][0] * m;
  41475. y += coords[pi[q]][1] * m;
  41476. }
  41477. }
  41478. figureCoords[k] = coords.length;
  41479. coords.push([x, y]);
  41480. figureColors[k] = colors.length;
  41481. var newColor = new Uint8Array(3);
  41482. newColor[0] = ((cl[0] * (splitXBy - col) + cr[0] * col) / splitXBy) | 0;
  41483. newColor[1] = ((cl[1] * (splitXBy - col) + cr[1] * col) / splitXBy) | 0;
  41484. newColor[2] = ((cl[2] * (splitXBy - col) + cr[2] * col) / splitXBy) | 0;
  41485. colors.push(newColor);
  41486. }
  41487. }
  41488. figureCoords[0] = pi[0];
  41489. figureColors[0] = ci[0];
  41490. figureCoords[splitXBy] = pi[3];
  41491. figureColors[splitXBy] = ci[1];
  41492. figureCoords[verticesPerRow * splitYBy] = pi[12];
  41493. figureColors[verticesPerRow * splitYBy] = ci[2];
  41494. figureCoords[verticesPerRow * splitYBy + splitXBy] = pi[15];
  41495. figureColors[verticesPerRow * splitYBy + splitXBy] = ci[3];
  41496. mesh.figures[index] = {
  41497. type: 'lattice',
  41498. coords: figureCoords,
  41499. colors: figureColors,
  41500. verticesPerRow: verticesPerRow
  41501. };
  41502. }
  41503. function decodeType6Shading(mesh, reader) {
  41504. // A special case of Type 7. The p11, p12, p21, p22 automatically filled
  41505. var coords = mesh.coords;
  41506. var colors = mesh.colors;
  41507. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41508. var cs = new Int32Array(4); // c00, c30, c03, c33
  41509. while (reader.hasData) {
  41510. var f = reader.readFlag();
  41511. assert(0 <= f && f <= 3, 'Unknown type6 flag');
  41512. var i, ii;
  41513. var pi = coords.length;
  41514. for (i = 0, ii = (f !== 0 ? 8 : 12); i < ii; i++) {
  41515. coords.push(reader.readCoordinate());
  41516. }
  41517. var ci = colors.length;
  41518. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41519. colors.push(reader.readComponents());
  41520. }
  41521. var tmp1, tmp2, tmp3, tmp4;
  41522. switch (f) {
  41523. case 0:
  41524. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41525. ps[ 8] = pi + 2; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 7;
  41526. ps[ 4] = pi + 1; /* calculated below */ ps[ 7] = pi + 8;
  41527. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41528. cs[2] = ci + 1; cs[3] = ci + 2;
  41529. cs[0] = ci; cs[1] = ci + 3;
  41530. break;
  41531. case 1:
  41532. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41533. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41534. ps[ 8] = tmp3; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41535. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41536. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41537. tmp1 = cs[2]; tmp2 = cs[3];
  41538. cs[2] = tmp2; cs[3] = ci;
  41539. cs[0] = tmp1; cs[1] = ci + 1;
  41540. break;
  41541. case 2:
  41542. tmp1 = ps[15];
  41543. tmp2 = ps[11];
  41544. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41545. ps[ 8] = ps[7]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41546. ps[ 4] = tmp2; /* calculated below */ ps[ 7] = pi + 4;
  41547. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41548. tmp1 = cs[3];
  41549. cs[2] = cs[1]; cs[3] = ci;
  41550. cs[0] = tmp1; cs[1] = ci + 1;
  41551. break;
  41552. case 3:
  41553. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41554. ps[ 8] = ps[1]; /* values for 5, 6, 9, 10 are */ ps[11] = pi + 3;
  41555. ps[ 4] = ps[2]; /* calculated below */ ps[ 7] = pi + 4;
  41556. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41557. cs[2] = cs[0]; cs[3] = ci;
  41558. cs[0] = cs[1]; cs[1] = ci + 1;
  41559. break;
  41560. }
  41561. // set p11, p12, p21, p22
  41562. ps[5] = coords.length;
  41563. coords.push([
  41564. (-4 * coords[ps[0]][0] - coords[ps[15]][0] +
  41565. 6 * (coords[ps[4]][0] + coords[ps[1]][0]) -
  41566. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41567. 3 * (coords[ps[13]][0] + coords[ps[7]][0])) / 9,
  41568. (-4 * coords[ps[0]][1] - coords[ps[15]][1] +
  41569. 6 * (coords[ps[4]][1] + coords[ps[1]][1]) -
  41570. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41571. 3 * (coords[ps[13]][1] + coords[ps[7]][1])) / 9
  41572. ]);
  41573. ps[6] = coords.length;
  41574. coords.push([
  41575. (-4 * coords[ps[3]][0] - coords[ps[12]][0] +
  41576. 6 * (coords[ps[2]][0] + coords[ps[7]][0]) -
  41577. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41578. 3 * (coords[ps[4]][0] + coords[ps[14]][0])) / 9,
  41579. (-4 * coords[ps[3]][1] - coords[ps[12]][1] +
  41580. 6 * (coords[ps[2]][1] + coords[ps[7]][1]) -
  41581. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41582. 3 * (coords[ps[4]][1] + coords[ps[14]][1])) / 9
  41583. ]);
  41584. ps[9] = coords.length;
  41585. coords.push([
  41586. (-4 * coords[ps[12]][0] - coords[ps[3]][0] +
  41587. 6 * (coords[ps[8]][0] + coords[ps[13]][0]) -
  41588. 2 * (coords[ps[0]][0] + coords[ps[15]][0]) +
  41589. 3 * (coords[ps[11]][0] + coords[ps[1]][0])) / 9,
  41590. (-4 * coords[ps[12]][1] - coords[ps[3]][1] +
  41591. 6 * (coords[ps[8]][1] + coords[ps[13]][1]) -
  41592. 2 * (coords[ps[0]][1] + coords[ps[15]][1]) +
  41593. 3 * (coords[ps[11]][1] + coords[ps[1]][1])) / 9
  41594. ]);
  41595. ps[10] = coords.length;
  41596. coords.push([
  41597. (-4 * coords[ps[15]][0] - coords[ps[0]][0] +
  41598. 6 * (coords[ps[11]][0] + coords[ps[14]][0]) -
  41599. 2 * (coords[ps[12]][0] + coords[ps[3]][0]) +
  41600. 3 * (coords[ps[2]][0] + coords[ps[8]][0])) / 9,
  41601. (-4 * coords[ps[15]][1] - coords[ps[0]][1] +
  41602. 6 * (coords[ps[11]][1] + coords[ps[14]][1]) -
  41603. 2 * (coords[ps[12]][1] + coords[ps[3]][1]) +
  41604. 3 * (coords[ps[2]][1] + coords[ps[8]][1])) / 9
  41605. ]);
  41606. mesh.figures.push({
  41607. type: 'patch',
  41608. coords: new Int32Array(ps), // making copies of ps and cs
  41609. colors: new Int32Array(cs)
  41610. });
  41611. }
  41612. }
  41613. function decodeType7Shading(mesh, reader) {
  41614. var coords = mesh.coords;
  41615. var colors = mesh.colors;
  41616. var ps = new Int32Array(16); // p00, p10, ..., p30, p01, ..., p33
  41617. var cs = new Int32Array(4); // c00, c30, c03, c33
  41618. while (reader.hasData) {
  41619. var f = reader.readFlag();
  41620. assert(0 <= f && f <= 3, 'Unknown type7 flag');
  41621. var i, ii;
  41622. var pi = coords.length;
  41623. for (i = 0, ii = (f !== 0 ? 12 : 16); i < ii; i++) {
  41624. coords.push(reader.readCoordinate());
  41625. }
  41626. var ci = colors.length;
  41627. for (i = 0, ii = (f !== 0 ? 2 : 4); i < ii; i++) {
  41628. colors.push(reader.readComponents());
  41629. }
  41630. var tmp1, tmp2, tmp3, tmp4;
  41631. switch (f) {
  41632. case 0:
  41633. ps[12] = pi + 3; ps[13] = pi + 4; ps[14] = pi + 5; ps[15] = pi + 6;
  41634. ps[ 8] = pi + 2; ps[ 9] = pi + 13; ps[10] = pi + 14; ps[11] = pi + 7;
  41635. ps[ 4] = pi + 1; ps[ 5] = pi + 12; ps[ 6] = pi + 15; ps[ 7] = pi + 8;
  41636. ps[ 0] = pi; ps[ 1] = pi + 11; ps[ 2] = pi + 10; ps[ 3] = pi + 9;
  41637. cs[2] = ci + 1; cs[3] = ci + 2;
  41638. cs[0] = ci; cs[1] = ci + 3;
  41639. break;
  41640. case 1:
  41641. tmp1 = ps[12]; tmp2 = ps[13]; tmp3 = ps[14]; tmp4 = ps[15];
  41642. ps[12] = tmp4; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41643. ps[ 8] = tmp3; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41644. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41645. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41646. tmp1 = cs[2]; tmp2 = cs[3];
  41647. cs[2] = tmp2; cs[3] = ci;
  41648. cs[0] = tmp1; cs[1] = ci + 1;
  41649. break;
  41650. case 2:
  41651. tmp1 = ps[15];
  41652. tmp2 = ps[11];
  41653. ps[12] = ps[3]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41654. ps[ 8] = ps[7]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41655. ps[ 4] = tmp2; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41656. ps[ 0] = tmp1; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41657. tmp1 = cs[3];
  41658. cs[2] = cs[1]; cs[3] = ci;
  41659. cs[0] = tmp1; cs[1] = ci + 1;
  41660. break;
  41661. case 3:
  41662. ps[12] = ps[0]; ps[13] = pi + 0; ps[14] = pi + 1; ps[15] = pi + 2;
  41663. ps[ 8] = ps[1]; ps[ 9] = pi + 9; ps[10] = pi + 10; ps[11] = pi + 3;
  41664. ps[ 4] = ps[2]; ps[ 5] = pi + 8; ps[ 6] = pi + 11; ps[ 7] = pi + 4;
  41665. ps[ 0] = ps[3]; ps[ 1] = pi + 7; ps[ 2] = pi + 6; ps[ 3] = pi + 5;
  41666. cs[2] = cs[0]; cs[3] = ci;
  41667. cs[0] = cs[1]; cs[1] = ci + 1;
  41668. break;
  41669. }
  41670. mesh.figures.push({
  41671. type: 'patch',
  41672. coords: new Int32Array(ps), // making copies of ps and cs
  41673. colors: new Int32Array(cs)
  41674. });
  41675. }
  41676. }
  41677. function updateBounds(mesh) {
  41678. var minX = mesh.coords[0][0], minY = mesh.coords[0][1],
  41679. maxX = minX, maxY = minY;
  41680. for (var i = 1, ii = mesh.coords.length; i < ii; i++) {
  41681. var x = mesh.coords[i][0], y = mesh.coords[i][1];
  41682. minX = minX > x ? x : minX;
  41683. minY = minY > y ? y : minY;
  41684. maxX = maxX < x ? x : maxX;
  41685. maxY = maxY < y ? y : maxY;
  41686. }
  41687. mesh.bounds = [minX, minY, maxX, maxY];
  41688. }
  41689. function packData(mesh) {
  41690. var i, ii, j, jj;
  41691. var coords = mesh.coords;
  41692. var coordsPacked = new Float32Array(coords.length * 2);
  41693. for (i = 0, j = 0, ii = coords.length; i < ii; i++) {
  41694. var xy = coords[i];
  41695. coordsPacked[j++] = xy[0];
  41696. coordsPacked[j++] = xy[1];
  41697. }
  41698. mesh.coords = coordsPacked;
  41699. var colors = mesh.colors;
  41700. var colorsPacked = new Uint8Array(colors.length * 3);
  41701. for (i = 0, j = 0, ii = colors.length; i < ii; i++) {
  41702. var c = colors[i];
  41703. colorsPacked[j++] = c[0];
  41704. colorsPacked[j++] = c[1];
  41705. colorsPacked[j++] = c[2];
  41706. }
  41707. mesh.colors = colorsPacked;
  41708. var figures = mesh.figures;
  41709. for (i = 0, ii = figures.length; i < ii; i++) {
  41710. var figure = figures[i], ps = figure.coords, cs = figure.colors;
  41711. for (j = 0, jj = ps.length; j < jj; j++) {
  41712. ps[j] *= 2;
  41713. cs[j] *= 3;
  41714. }
  41715. }
  41716. }
  41717. function Mesh(stream, matrix, xref, res) {
  41718. assert(isStream(stream), 'Mesh data is not a stream');
  41719. var dict = stream.dict;
  41720. this.matrix = matrix;
  41721. this.shadingType = dict.get('ShadingType');
  41722. this.type = 'Pattern';
  41723. this.bbox = dict.get('BBox');
  41724. var cs = dict.get('ColorSpace', 'CS');
  41725. cs = ColorSpace.parse(cs, xref, res);
  41726. this.cs = cs;
  41727. this.background = dict.has('Background') ?
  41728. cs.getRgb(dict.get('Background'), 0) : null;
  41729. var fnObj = dict.get('Function');
  41730. var fn = fnObj ? PDFFunction.parseArray(xref, fnObj) : null;
  41731. this.coords = [];
  41732. this.colors = [];
  41733. this.figures = [];
  41734. var decodeContext = {
  41735. bitsPerCoordinate: dict.get('BitsPerCoordinate'),
  41736. bitsPerComponent: dict.get('BitsPerComponent'),
  41737. bitsPerFlag: dict.get('BitsPerFlag'),
  41738. decode: dict.get('Decode'),
  41739. colorFn: fn,
  41740. colorSpace: cs,
  41741. numComps: fn ? 1 : cs.numComps
  41742. };
  41743. var reader = new MeshStreamReader(stream, decodeContext);
  41744. var patchMesh = false;
  41745. switch (this.shadingType) {
  41746. case ShadingType.FREE_FORM_MESH:
  41747. decodeType4Shading(this, reader);
  41748. break;
  41749. case ShadingType.LATTICE_FORM_MESH:
  41750. var verticesPerRow = dict.get('VerticesPerRow') | 0;
  41751. assert(verticesPerRow >= 2, 'Invalid VerticesPerRow');
  41752. decodeType5Shading(this, reader, verticesPerRow);
  41753. break;
  41754. case ShadingType.COONS_PATCH_MESH:
  41755. decodeType6Shading(this, reader);
  41756. patchMesh = true;
  41757. break;
  41758. case ShadingType.TENSOR_PATCH_MESH:
  41759. decodeType7Shading(this, reader);
  41760. patchMesh = true;
  41761. break;
  41762. default:
  41763. error('Unsupported mesh type.');
  41764. break;
  41765. }
  41766. if (patchMesh) {
  41767. // dirty bounds calculation for determining, how dense shall be triangles
  41768. updateBounds(this);
  41769. for (var i = 0, ii = this.figures.length; i < ii; i++) {
  41770. buildFigureFromPatch(this, i);
  41771. }
  41772. }
  41773. // calculate bounds
  41774. updateBounds(this);
  41775. packData(this);
  41776. }
  41777. Mesh.prototype = {
  41778. getIR: function Mesh_getIR() {
  41779. return ['Mesh', this.shadingType, this.coords, this.colors, this.figures,
  41780. this.bounds, this.matrix, this.bbox, this.background];
  41781. }
  41782. };
  41783. return Mesh;
  41784. })();
  41785. Shadings.Dummy = (function DummyClosure() {
  41786. function Dummy() {
  41787. this.type = 'Pattern';
  41788. }
  41789. Dummy.prototype = {
  41790. getIR: function Dummy_getIR() {
  41791. return ['Dummy'];
  41792. }
  41793. };
  41794. return Dummy;
  41795. })();
  41796. function getTilingPatternIR(operatorList, dict, args) {
  41797. var matrix = dict.get('Matrix');
  41798. var bbox = dict.get('BBox');
  41799. var xstep = dict.get('XStep');
  41800. var ystep = dict.get('YStep');
  41801. var paintType = dict.get('PaintType');
  41802. var tilingType = dict.get('TilingType');
  41803. return [
  41804. 'TilingPattern', args, operatorList, matrix, bbox, xstep, ystep,
  41805. paintType, tilingType
  41806. ];
  41807. }
  41808. exports.Pattern = Pattern;
  41809. exports.getTilingPatternIR = getTilingPatternIR;
  41810. }));
  41811. (function (root, factory) {
  41812. {
  41813. factory((root.pdfjsCoreEvaluator = {}), root.pdfjsSharedUtil,
  41814. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreParser,
  41815. root.pdfjsCoreImage, root.pdfjsCoreColorSpace, root.pdfjsCoreMurmurHash3,
  41816. root.pdfjsCoreFonts, root.pdfjsCoreFunction, root.pdfjsCorePattern,
  41817. root.pdfjsCoreCMap, root.pdfjsCoreMetrics, root.pdfjsCoreBidi,
  41818. root.pdfjsCoreEncodings, root.pdfjsCoreStandardFonts,
  41819. root.pdfjsCoreUnicode, root.pdfjsCoreGlyphList);
  41820. }
  41821. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreParser,
  41822. coreImage, coreColorSpace, coreMurmurHash3, coreFonts,
  41823. coreFunction, corePattern, coreCMap, coreMetrics, coreBidi,
  41824. coreEncodings, coreStandardFonts, coreUnicode,
  41825. coreGlyphList) {
  41826. var FONT_IDENTITY_MATRIX = sharedUtil.FONT_IDENTITY_MATRIX;
  41827. var IDENTITY_MATRIX = sharedUtil.IDENTITY_MATRIX;
  41828. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  41829. var ImageKind = sharedUtil.ImageKind;
  41830. var OPS = sharedUtil.OPS;
  41831. var TextRenderingMode = sharedUtil.TextRenderingMode;
  41832. var Util = sharedUtil.Util;
  41833. var assert = sharedUtil.assert;
  41834. var createPromiseCapability = sharedUtil.createPromiseCapability;
  41835. var error = sharedUtil.error;
  41836. var info = sharedUtil.info;
  41837. var isArray = sharedUtil.isArray;
  41838. var isNum = sharedUtil.isNum;
  41839. var isString = sharedUtil.isString;
  41840. var getLookupTableFactory = sharedUtil.getLookupTableFactory;
  41841. var warn = sharedUtil.warn;
  41842. var Dict = corePrimitives.Dict;
  41843. var Name = corePrimitives.Name;
  41844. var isCmd = corePrimitives.isCmd;
  41845. var isDict = corePrimitives.isDict;
  41846. var isName = corePrimitives.isName;
  41847. var isRef = corePrimitives.isRef;
  41848. var isStream = corePrimitives.isStream;
  41849. var DecodeStream = coreStream.DecodeStream;
  41850. var JpegStream = coreStream.JpegStream;
  41851. var Stream = coreStream.Stream;
  41852. var Lexer = coreParser.Lexer;
  41853. var Parser = coreParser.Parser;
  41854. var isEOF = coreParser.isEOF;
  41855. var PDFImage = coreImage.PDFImage;
  41856. var ColorSpace = coreColorSpace.ColorSpace;
  41857. var MurmurHash3_64 = coreMurmurHash3.MurmurHash3_64;
  41858. var ErrorFont = coreFonts.ErrorFont;
  41859. var FontFlags = coreFonts.FontFlags;
  41860. var Font = coreFonts.Font;
  41861. var IdentityToUnicodeMap = coreFonts.IdentityToUnicodeMap;
  41862. var ToUnicodeMap = coreFonts.ToUnicodeMap;
  41863. var getFontType = coreFonts.getFontType;
  41864. var isPDFFunction = coreFunction.isPDFFunction;
  41865. var PDFFunction = coreFunction.PDFFunction;
  41866. var Pattern = corePattern.Pattern;
  41867. var getTilingPatternIR = corePattern.getTilingPatternIR;
  41868. var CMapFactory = coreCMap.CMapFactory;
  41869. var IdentityCMap = coreCMap.IdentityCMap;
  41870. var getMetrics = coreMetrics.getMetrics;
  41871. var bidi = coreBidi.bidi;
  41872. var WinAnsiEncoding = coreEncodings.WinAnsiEncoding;
  41873. var StandardEncoding = coreEncodings.StandardEncoding;
  41874. var MacRomanEncoding = coreEncodings.MacRomanEncoding;
  41875. var SymbolSetEncoding = coreEncodings.SymbolSetEncoding;
  41876. var ZapfDingbatsEncoding = coreEncodings.ZapfDingbatsEncoding;
  41877. var getEncoding = coreEncodings.getEncoding;
  41878. var getStdFontMap = coreStandardFonts.getStdFontMap;
  41879. var getSerifFonts = coreStandardFonts.getSerifFonts;
  41880. var getSymbolsFonts = coreStandardFonts.getSymbolsFonts;
  41881. var getNormalizedUnicodes = coreUnicode.getNormalizedUnicodes;
  41882. var reverseIfRtl = coreUnicode.reverseIfRtl;
  41883. var getUnicodeForGlyph = coreUnicode.getUnicodeForGlyph;
  41884. var getGlyphsUnicode = coreGlyphList.getGlyphsUnicode;
  41885. var PartialEvaluator = (function PartialEvaluatorClosure() {
  41886. var DefaultPartialEvaluatorOptions = {
  41887. forceDataSchema: false,
  41888. maxImageSize: -1,
  41889. disableFontFace: false,
  41890. cMapOptions: { url: null, packed: false }
  41891. };
  41892. function NativeImageDecoder(xref, resources, handler, forceDataSchema) {
  41893. this.xref = xref;
  41894. this.resources = resources;
  41895. this.handler = handler;
  41896. this.forceDataSchema = forceDataSchema;
  41897. }
  41898. NativeImageDecoder.prototype = {
  41899. canDecode: function (image) {
  41900. return image instanceof JpegStream &&
  41901. NativeImageDecoder.isDecodable(image, this.xref, this.resources);
  41902. },
  41903. decode: function (image) {
  41904. // For natively supported JPEGs send them to the main thread for decoding.
  41905. var dict = image.dict;
  41906. var colorSpace = dict.get('ColorSpace', 'CS');
  41907. colorSpace = ColorSpace.parse(colorSpace, this.xref, this.resources);
  41908. var numComps = colorSpace.numComps;
  41909. var decodePromise = this.handler.sendWithPromise('JpegDecode',
  41910. [image.getIR(this.forceDataSchema), numComps]);
  41911. return decodePromise.then(function (message) {
  41912. var data = message.data;
  41913. return new Stream(data, 0, data.length, image.dict);
  41914. });
  41915. }
  41916. };
  41917. /**
  41918. * Checks if the image can be decoded and displayed by the browser without any
  41919. * further processing such as color space conversions.
  41920. */
  41921. NativeImageDecoder.isSupported =
  41922. function NativeImageDecoder_isSupported(image, xref, res) {
  41923. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  41924. return (cs.name === 'DeviceGray' || cs.name === 'DeviceRGB') &&
  41925. cs.isDefaultDecode(image.dict.get('Decode', 'D'));
  41926. };
  41927. /**
  41928. * Checks if the image can be decoded by the browser.
  41929. */
  41930. NativeImageDecoder.isDecodable =
  41931. function NativeImageDecoder_isDecodable(image, xref, res) {
  41932. var cs = ColorSpace.parse(image.dict.get('ColorSpace', 'CS'), xref, res);
  41933. return (cs.numComps === 1 || cs.numComps === 3) &&
  41934. cs.isDefaultDecode(image.dict.get('Decode', 'D'));
  41935. };
  41936. function PartialEvaluator(pdfManager, xref, handler, pageIndex,
  41937. uniquePrefix, idCounters, fontCache, options) {
  41938. this.pdfManager = pdfManager;
  41939. this.xref = xref;
  41940. this.handler = handler;
  41941. this.pageIndex = pageIndex;
  41942. this.uniquePrefix = uniquePrefix;
  41943. this.idCounters = idCounters;
  41944. this.fontCache = fontCache;
  41945. this.options = options || DefaultPartialEvaluatorOptions;
  41946. }
  41947. // Trying to minimize Date.now() usage and check every 100 time
  41948. var TIME_SLOT_DURATION_MS = 20;
  41949. var CHECK_TIME_EVERY = 100;
  41950. function TimeSlotManager() {
  41951. this.reset();
  41952. }
  41953. TimeSlotManager.prototype = {
  41954. check: function TimeSlotManager_check() {
  41955. if (++this.checked < CHECK_TIME_EVERY) {
  41956. return false;
  41957. }
  41958. this.checked = 0;
  41959. return this.endTime <= Date.now();
  41960. },
  41961. reset: function TimeSlotManager_reset() {
  41962. this.endTime = Date.now() + TIME_SLOT_DURATION_MS;
  41963. this.checked = 0;
  41964. }
  41965. };
  41966. var deferred = Promise.resolve();
  41967. var TILING_PATTERN = 1, SHADING_PATTERN = 2;
  41968. PartialEvaluator.prototype = {
  41969. hasBlendModes: function PartialEvaluator_hasBlendModes(resources) {
  41970. if (!isDict(resources)) {
  41971. return false;
  41972. }
  41973. var processed = Object.create(null);
  41974. if (resources.objId) {
  41975. processed[resources.objId] = true;
  41976. }
  41977. var nodes = [resources], xref = this.xref;
  41978. while (nodes.length) {
  41979. var key, i, ii;
  41980. var node = nodes.shift();
  41981. // First check the current resources for blend modes.
  41982. var graphicStates = node.get('ExtGState');
  41983. if (isDict(graphicStates)) {
  41984. var graphicStatesKeys = graphicStates.getKeys();
  41985. for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
  41986. key = graphicStatesKeys[i];
  41987. var graphicState = graphicStates.get(key);
  41988. var bm = graphicState.get('BM');
  41989. if (isName(bm) && bm.name !== 'Normal') {
  41990. return true;
  41991. }
  41992. }
  41993. }
  41994. // Descend into the XObjects to look for more resources and blend modes.
  41995. var xObjects = node.get('XObject');
  41996. if (!isDict(xObjects)) {
  41997. continue;
  41998. }
  41999. var xObjectsKeys = xObjects.getKeys();
  42000. for (i = 0, ii = xObjectsKeys.length; i < ii; i++) {
  42001. key = xObjectsKeys[i];
  42002. var xObject = xObjects.getRaw(key);
  42003. if (isRef(xObject)) {
  42004. if (processed[xObject.toString()]) {
  42005. // The XObject has already been processed, and by avoiding a
  42006. // redundant `xref.fetch` we can *significantly* reduce the load
  42007. // time for badly generated PDF files (fixes issue6961.pdf).
  42008. continue;
  42009. }
  42010. xObject = xref.fetch(xObject);
  42011. }
  42012. if (!isStream(xObject)) {
  42013. continue;
  42014. }
  42015. if (xObject.dict.objId) {
  42016. if (processed[xObject.dict.objId]) {
  42017. // stream has objId and is processed already
  42018. continue;
  42019. }
  42020. processed[xObject.dict.objId] = true;
  42021. }
  42022. var xResources = xObject.dict.get('Resources');
  42023. // Checking objId to detect an infinite loop.
  42024. if (isDict(xResources) &&
  42025. (!xResources.objId || !processed[xResources.objId])) {
  42026. nodes.push(xResources);
  42027. if (xResources.objId) {
  42028. processed[xResources.objId] = true;
  42029. }
  42030. }
  42031. }
  42032. }
  42033. return false;
  42034. },
  42035. buildFormXObject: function PartialEvaluator_buildFormXObject(resources,
  42036. xobj, smask,
  42037. operatorList,
  42038. task,
  42039. initialState) {
  42040. var matrix = xobj.dict.getArray('Matrix');
  42041. var bbox = xobj.dict.getArray('BBox');
  42042. var group = xobj.dict.get('Group');
  42043. if (group) {
  42044. var groupOptions = {
  42045. matrix: matrix,
  42046. bbox: bbox,
  42047. smask: smask,
  42048. isolated: false,
  42049. knockout: false
  42050. };
  42051. var groupSubtype = group.get('S');
  42052. var colorSpace;
  42053. if (isName(groupSubtype) && groupSubtype.name === 'Transparency') {
  42054. groupOptions.isolated = (group.get('I') || false);
  42055. groupOptions.knockout = (group.get('K') || false);
  42056. colorSpace = (group.has('CS') ?
  42057. ColorSpace.parse(group.get('CS'), this.xref, resources) : null);
  42058. }
  42059. if (smask && smask.backdrop) {
  42060. colorSpace = colorSpace || ColorSpace.singletons.rgb;
  42061. smask.backdrop = colorSpace.getRgb(smask.backdrop, 0);
  42062. }
  42063. operatorList.addOp(OPS.beginGroup, [groupOptions]);
  42064. }
  42065. operatorList.addOp(OPS.paintFormXObjectBegin, [matrix, bbox]);
  42066. return this.getOperatorList(xobj, task,
  42067. (xobj.dict.get('Resources') || resources), operatorList, initialState).
  42068. then(function () {
  42069. operatorList.addOp(OPS.paintFormXObjectEnd, []);
  42070. if (group) {
  42071. operatorList.addOp(OPS.endGroup, [groupOptions]);
  42072. }
  42073. });
  42074. },
  42075. buildPaintImageXObject:
  42076. function PartialEvaluator_buildPaintImageXObject(resources, image,
  42077. inline, operatorList,
  42078. cacheKey, imageCache) {
  42079. var self = this;
  42080. var dict = image.dict;
  42081. var w = dict.get('Width', 'W');
  42082. var h = dict.get('Height', 'H');
  42083. if (!(w && isNum(w)) || !(h && isNum(h))) {
  42084. warn('Image dimensions are missing, or not numbers.');
  42085. return;
  42086. }
  42087. var maxImageSize = this.options.maxImageSize;
  42088. if (maxImageSize !== -1 && w * h > maxImageSize) {
  42089. warn('Image exceeded maximum allowed size and was removed.');
  42090. return;
  42091. }
  42092. var imageMask = (dict.get('ImageMask', 'IM') || false);
  42093. var imgData, args;
  42094. if (imageMask) {
  42095. // This depends on a tmpCanvas being filled with the
  42096. // current fillStyle, such that processing the pixel
  42097. // data can't be done here. Instead of creating a
  42098. // complete PDFImage, only read the information needed
  42099. // for later.
  42100. var width = dict.get('Width', 'W');
  42101. var height = dict.get('Height', 'H');
  42102. var bitStrideLength = (width + 7) >> 3;
  42103. var imgArray = image.getBytes(bitStrideLength * height);
  42104. var decode = dict.get('Decode', 'D');
  42105. var inverseDecode = (!!decode && decode[0] > 0);
  42106. imgData = PDFImage.createMask(imgArray, width, height,
  42107. image instanceof DecodeStream,
  42108. inverseDecode);
  42109. imgData.cached = true;
  42110. args = [imgData];
  42111. operatorList.addOp(OPS.paintImageMaskXObject, args);
  42112. if (cacheKey) {
  42113. imageCache[cacheKey] = {
  42114. fn: OPS.paintImageMaskXObject,
  42115. args: args
  42116. };
  42117. }
  42118. return;
  42119. }
  42120. var softMask = (dict.get('SMask', 'SM') || false);
  42121. var mask = (dict.get('Mask') || false);
  42122. var SMALL_IMAGE_DIMENSIONS = 200;
  42123. // Inlining small images into the queue as RGB data
  42124. if (inline && !softMask && !mask && !(image instanceof JpegStream) &&
  42125. (w + h) < SMALL_IMAGE_DIMENSIONS) {
  42126. var imageObj = new PDFImage(this.xref, resources, image,
  42127. inline, null, null);
  42128. // We force the use of RGBA_32BPP images here, because we can't handle
  42129. // any other kind.
  42130. imgData = imageObj.createImageData(/* forceRGBA = */ true);
  42131. operatorList.addOp(OPS.paintInlineImageXObject, [imgData]);
  42132. return;
  42133. }
  42134. // If there is no imageMask, create the PDFImage and a lot
  42135. // of image processing can be done here.
  42136. var uniquePrefix = (this.uniquePrefix || '');
  42137. var objId = 'img_' + uniquePrefix + (++this.idCounters.obj);
  42138. operatorList.addDependency(objId);
  42139. args = [objId, w, h];
  42140. if (!softMask && !mask && image instanceof JpegStream &&
  42141. NativeImageDecoder.isSupported(image, this.xref, resources)) {
  42142. // These JPEGs don't need any more processing so we can just send it.
  42143. operatorList.addOp(OPS.paintJpegXObject, args);
  42144. this.handler.send('obj',
  42145. [objId, this.pageIndex, 'JpegStream',
  42146. image.getIR(this.options.forceDataSchema)]);
  42147. return;
  42148. }
  42149. // Creates native image decoder only if a JPEG image or mask is present.
  42150. var nativeImageDecoder = null;
  42151. if (image instanceof JpegStream || mask instanceof JpegStream ||
  42152. softMask instanceof JpegStream) {
  42153. nativeImageDecoder = new NativeImageDecoder(self.xref, resources,
  42154. self.handler, self.options.forceDataSchema);
  42155. }
  42156. PDFImage.buildImage(self.handler, self.xref, resources, image, inline,
  42157. nativeImageDecoder).
  42158. then(function(imageObj) {
  42159. var imgData = imageObj.createImageData(/* forceRGBA = */ false);
  42160. self.handler.send('obj', [objId, self.pageIndex, 'Image', imgData],
  42161. [imgData.data.buffer]);
  42162. }).then(undefined, function (reason) {
  42163. warn('Unable to decode image: ' + reason);
  42164. self.handler.send('obj', [objId, self.pageIndex, 'Image', null]);
  42165. });
  42166. operatorList.addOp(OPS.paintImageXObject, args);
  42167. if (cacheKey) {
  42168. imageCache[cacheKey] = {
  42169. fn: OPS.paintImageXObject,
  42170. args: args
  42171. };
  42172. }
  42173. },
  42174. handleSMask: function PartialEvaluator_handleSmask(smask, resources,
  42175. operatorList, task,
  42176. stateManager) {
  42177. var smaskContent = smask.get('G');
  42178. var smaskOptions = {
  42179. subtype: smask.get('S').name,
  42180. backdrop: smask.get('BC')
  42181. };
  42182. // The SMask might have a alpha/luminosity value transfer function --
  42183. // we will build a map of integer values in range 0..255 to be fast.
  42184. var transferObj = smask.get('TR');
  42185. if (isPDFFunction(transferObj)) {
  42186. var transferFn = PDFFunction.parse(this.xref, transferObj);
  42187. var transferMap = new Uint8Array(256);
  42188. var tmp = new Float32Array(1);
  42189. for (var i = 0; i < 256; i++) {
  42190. tmp[0] = i / 255;
  42191. transferFn(tmp, 0, tmp, 0);
  42192. transferMap[i] = (tmp[0] * 255) | 0;
  42193. }
  42194. smaskOptions.transferMap = transferMap;
  42195. }
  42196. return this.buildFormXObject(resources, smaskContent, smaskOptions,
  42197. operatorList, task, stateManager.state.clone());
  42198. },
  42199. handleTilingType:
  42200. function PartialEvaluator_handleTilingType(fn, args, resources,
  42201. pattern, patternDict,
  42202. operatorList, task) {
  42203. // Create an IR of the pattern code.
  42204. var tilingOpList = new OperatorList();
  42205. // Merge the available resources, to prevent issues when the patternDict
  42206. // is missing some /Resources entries (fixes issue6541.pdf).
  42207. var resourcesArray = [patternDict.get('Resources'), resources];
  42208. var patternResources = Dict.merge(this.xref, resourcesArray);
  42209. return this.getOperatorList(pattern, task, patternResources,
  42210. tilingOpList).then(function () {
  42211. // Add the dependencies to the parent operator list so they are
  42212. // resolved before sub operator list is executed synchronously.
  42213. operatorList.addDependencies(tilingOpList.dependencies);
  42214. operatorList.addOp(fn, getTilingPatternIR({
  42215. fnArray: tilingOpList.fnArray,
  42216. argsArray: tilingOpList.argsArray
  42217. }, patternDict, args));
  42218. });
  42219. },
  42220. handleSetFont:
  42221. function PartialEvaluator_handleSetFont(resources, fontArgs, fontRef,
  42222. operatorList, task, state) {
  42223. // TODO(mack): Not needed?
  42224. var fontName;
  42225. if (fontArgs) {
  42226. fontArgs = fontArgs.slice();
  42227. fontName = fontArgs[0].name;
  42228. }
  42229. var self = this;
  42230. return this.loadFont(fontName, fontRef, this.xref, resources).then(
  42231. function (translated) {
  42232. if (!translated.font.isType3Font) {
  42233. return translated;
  42234. }
  42235. return translated.loadType3Data(self, resources, operatorList, task).
  42236. then(function () {
  42237. return translated;
  42238. }, function (reason) {
  42239. // Error in the font data -- sending unsupported feature notification.
  42240. self.handler.send('UnsupportedFeature',
  42241. {featureId: UNSUPPORTED_FEATURES.font});
  42242. return new TranslatedFont('g_font_error',
  42243. new ErrorFont('Type3 font load error: ' + reason), translated.font);
  42244. });
  42245. }).then(function (translated) {
  42246. state.font = translated.font;
  42247. translated.send(self.handler);
  42248. return translated.loadedName;
  42249. });
  42250. },
  42251. handleText: function PartialEvaluator_handleText(chars, state) {
  42252. var font = state.font;
  42253. var glyphs = font.charsToGlyphs(chars);
  42254. var isAddToPathSet = !!(state.textRenderingMode &
  42255. TextRenderingMode.ADD_TO_PATH_FLAG);
  42256. if (font.data && (isAddToPathSet || this.options.disableFontFace)) {
  42257. var buildPath = function (fontChar) {
  42258. if (!font.renderer.hasBuiltPath(fontChar)) {
  42259. var path = font.renderer.getPathJs(fontChar);
  42260. this.handler.send('commonobj', [
  42261. font.loadedName + '_path_' + fontChar,
  42262. 'FontPath',
  42263. path
  42264. ]);
  42265. }
  42266. }.bind(this);
  42267. for (var i = 0, ii = glyphs.length; i < ii; i++) {
  42268. var glyph = glyphs[i];
  42269. buildPath(glyph.fontChar);
  42270. // If the glyph has an accent we need to build a path for its
  42271. // fontChar too, otherwise CanvasGraphics_paintChar will fail.
  42272. var accent = glyph.accent;
  42273. if (accent && accent.fontChar) {
  42274. buildPath(accent.fontChar);
  42275. }
  42276. }
  42277. }
  42278. return glyphs;
  42279. },
  42280. setGState: function PartialEvaluator_setGState(resources, gState,
  42281. operatorList, task,
  42282. xref, stateManager) {
  42283. // This array holds the converted/processed state data.
  42284. var gStateObj = [];
  42285. var gStateKeys = gState.getKeys();
  42286. var self = this;
  42287. var promise = Promise.resolve();
  42288. for (var i = 0, ii = gStateKeys.length; i < ii; i++) {
  42289. var key = gStateKeys[i];
  42290. var value = gState.get(key);
  42291. switch (key) {
  42292. case 'Type':
  42293. break;
  42294. case 'LW':
  42295. case 'LC':
  42296. case 'LJ':
  42297. case 'ML':
  42298. case 'D':
  42299. case 'RI':
  42300. case 'FL':
  42301. case 'CA':
  42302. case 'ca':
  42303. gStateObj.push([key, value]);
  42304. break;
  42305. case 'Font':
  42306. promise = promise.then(function () {
  42307. return self.handleSetFont(resources, null, value[0], operatorList,
  42308. task, stateManager.state).
  42309. then(function (loadedName) {
  42310. operatorList.addDependency(loadedName);
  42311. gStateObj.push([key, [loadedName, value[1]]]);
  42312. });
  42313. });
  42314. break;
  42315. case 'BM':
  42316. gStateObj.push([key, value]);
  42317. break;
  42318. case 'SMask':
  42319. if (isName(value) && value.name === 'None') {
  42320. gStateObj.push([key, false]);
  42321. break;
  42322. }
  42323. if (isDict(value)) {
  42324. promise = promise.then(function (dict) {
  42325. return self.handleSMask(dict, resources, operatorList,
  42326. task, stateManager);
  42327. }.bind(this, value));
  42328. gStateObj.push([key, true]);
  42329. } else {
  42330. warn('Unsupported SMask type');
  42331. }
  42332. break;
  42333. // Only generate info log messages for the following since
  42334. // they are unlikely to have a big impact on the rendering.
  42335. case 'OP':
  42336. case 'op':
  42337. case 'OPM':
  42338. case 'BG':
  42339. case 'BG2':
  42340. case 'UCR':
  42341. case 'UCR2':
  42342. case 'TR':
  42343. case 'TR2':
  42344. case 'HT':
  42345. case 'SM':
  42346. case 'SA':
  42347. case 'AIS':
  42348. case 'TK':
  42349. // TODO implement these operators.
  42350. info('graphic state operator ' + key);
  42351. break;
  42352. default:
  42353. info('Unknown graphic state operator ' + key);
  42354. break;
  42355. }
  42356. }
  42357. return promise.then(function () {
  42358. if (gStateObj.length > 0) {
  42359. operatorList.addOp(OPS.setGState, [gStateObj]);
  42360. }
  42361. });
  42362. },
  42363. loadFont: function PartialEvaluator_loadFont(fontName, font, xref,
  42364. resources) {
  42365. function errorFont() {
  42366. return Promise.resolve(new TranslatedFont('g_font_error',
  42367. new ErrorFont('Font ' + fontName + ' is not available'), font));
  42368. }
  42369. var fontRef;
  42370. if (font) { // Loading by ref.
  42371. assert(isRef(font));
  42372. fontRef = font;
  42373. } else { // Loading by name.
  42374. var fontRes = resources.get('Font');
  42375. if (fontRes) {
  42376. fontRef = fontRes.getRaw(fontName);
  42377. } else {
  42378. warn('fontRes not available');
  42379. return errorFont();
  42380. }
  42381. }
  42382. if (!fontRef) {
  42383. warn('fontRef not available');
  42384. return errorFont();
  42385. }
  42386. if (this.fontCache.has(fontRef)) {
  42387. return this.fontCache.get(fontRef);
  42388. }
  42389. font = xref.fetchIfRef(fontRef);
  42390. if (!isDict(font)) {
  42391. return errorFont();
  42392. }
  42393. // We are holding font.translated references just for fontRef that are not
  42394. // dictionaries (Dict). See explanation below.
  42395. if (font.translated) {
  42396. return font.translated;
  42397. }
  42398. var fontCapability = createPromiseCapability();
  42399. var preEvaluatedFont = this.preEvaluateFont(font, xref);
  42400. var descriptor = preEvaluatedFont.descriptor;
  42401. var fontID = fontRef.num + '_' + fontRef.gen;
  42402. if (isDict(descriptor)) {
  42403. if (!descriptor.fontAliases) {
  42404. descriptor.fontAliases = Object.create(null);
  42405. }
  42406. var fontAliases = descriptor.fontAliases;
  42407. var hash = preEvaluatedFont.hash;
  42408. if (fontAliases[hash]) {
  42409. var aliasFontRef = fontAliases[hash].aliasRef;
  42410. if (aliasFontRef && this.fontCache.has(aliasFontRef)) {
  42411. this.fontCache.putAlias(fontRef, aliasFontRef);
  42412. return this.fontCache.get(fontRef);
  42413. }
  42414. }
  42415. if (!fontAliases[hash]) {
  42416. fontAliases[hash] = {
  42417. fontID: Font.getFontID()
  42418. };
  42419. }
  42420. fontAliases[hash].aliasRef = fontRef;
  42421. fontID = fontAliases[hash].fontID;
  42422. }
  42423. // Workaround for bad PDF generators that don't reference fonts
  42424. // properly, i.e. by not using an object identifier.
  42425. // Check if the fontRef is a Dict (as opposed to a standard object),
  42426. // in which case we don't cache the font and instead reference it by
  42427. // fontName in font.loadedName below.
  42428. var fontRefIsDict = isDict(fontRef);
  42429. if (!fontRefIsDict) {
  42430. this.fontCache.put(fontRef, fontCapability.promise);
  42431. }
  42432. // Keep track of each font we translated so the caller can
  42433. // load them asynchronously before calling display on a page.
  42434. font.loadedName = 'g_' + this.pdfManager.docId + '_f' + (fontRefIsDict ?
  42435. fontName.replace(/\W/g, '') : fontID);
  42436. font.translated = fontCapability.promise;
  42437. // TODO move promises into translate font
  42438. var translatedPromise;
  42439. try {
  42440. translatedPromise = this.translateFont(preEvaluatedFont, xref);
  42441. } catch (e) {
  42442. translatedPromise = Promise.reject(e);
  42443. }
  42444. var self = this;
  42445. translatedPromise.then(function (translatedFont) {
  42446. if (translatedFont.fontType !== undefined) {
  42447. var xrefFontStats = xref.stats.fontTypes;
  42448. xrefFontStats[translatedFont.fontType] = true;
  42449. }
  42450. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42451. translatedFont, font));
  42452. }, function (reason) {
  42453. // TODO fontCapability.reject?
  42454. // Error in the font data -- sending unsupported feature notification.
  42455. self.handler.send('UnsupportedFeature',
  42456. {featureId: UNSUPPORTED_FEATURES.font});
  42457. try {
  42458. // error, but it's still nice to have font type reported
  42459. var descriptor = preEvaluatedFont.descriptor;
  42460. var fontFile3 = descriptor && descriptor.get('FontFile3');
  42461. var subtype = fontFile3 && fontFile3.get('Subtype');
  42462. var fontType = getFontType(preEvaluatedFont.type,
  42463. subtype && subtype.name);
  42464. var xrefFontStats = xref.stats.fontTypes;
  42465. xrefFontStats[fontType] = true;
  42466. } catch (ex) { }
  42467. fontCapability.resolve(new TranslatedFont(font.loadedName,
  42468. new ErrorFont(reason instanceof Error ? reason.message : reason),
  42469. font));
  42470. });
  42471. return fontCapability.promise;
  42472. },
  42473. buildPath: function PartialEvaluator_buildPath(operatorList, fn, args) {
  42474. var lastIndex = operatorList.length - 1;
  42475. if (!args) {
  42476. args = [];
  42477. }
  42478. if (lastIndex < 0 ||
  42479. operatorList.fnArray[lastIndex] !== OPS.constructPath) {
  42480. operatorList.addOp(OPS.constructPath, [[fn], args]);
  42481. } else {
  42482. var opArgs = operatorList.argsArray[lastIndex];
  42483. opArgs[0].push(fn);
  42484. Array.prototype.push.apply(opArgs[1], args);
  42485. }
  42486. },
  42487. handleColorN: function PartialEvaluator_handleColorN(operatorList, fn, args,
  42488. cs, patterns, resources, task, xref) {
  42489. // compile tiling patterns
  42490. var patternName = args[args.length - 1];
  42491. // SCN/scn applies patterns along with normal colors
  42492. var pattern;
  42493. if (isName(patternName) &&
  42494. (pattern = patterns.get(patternName.name))) {
  42495. var dict = (isStream(pattern) ? pattern.dict : pattern);
  42496. var typeNum = dict.get('PatternType');
  42497. if (typeNum === TILING_PATTERN) {
  42498. var color = cs.base ? cs.base.getRgb(args, 0) : null;
  42499. return this.handleTilingType(fn, color, resources, pattern,
  42500. dict, operatorList, task);
  42501. } else if (typeNum === SHADING_PATTERN) {
  42502. var shading = dict.get('Shading');
  42503. var matrix = dict.get('Matrix');
  42504. pattern = Pattern.parseShading(shading, matrix, xref, resources,
  42505. this.handler);
  42506. operatorList.addOp(fn, pattern.getIR());
  42507. return Promise.resolve();
  42508. } else {
  42509. return Promise.reject('Unknown PatternType: ' + typeNum);
  42510. }
  42511. }
  42512. // TODO shall we fail here?
  42513. operatorList.addOp(fn, args);
  42514. return Promise.resolve();
  42515. },
  42516. getOperatorList: function PartialEvaluator_getOperatorList(stream,
  42517. task,
  42518. resources,
  42519. operatorList,
  42520. initialState) {
  42521. var self = this;
  42522. var xref = this.xref;
  42523. var imageCache = Object.create(null);
  42524. assert(operatorList);
  42525. resources = (resources || Dict.empty);
  42526. var xobjs = (resources.get('XObject') || Dict.empty);
  42527. var patterns = (resources.get('Pattern') || Dict.empty);
  42528. var stateManager = new StateManager(initialState || new EvalState());
  42529. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42530. var timeSlotManager = new TimeSlotManager();
  42531. return new Promise(function promiseBody(resolve, reject) {
  42532. var next = function (promise) {
  42533. promise.then(function () {
  42534. try {
  42535. promiseBody(resolve, reject);
  42536. } catch (ex) {
  42537. reject(ex);
  42538. }
  42539. }, reject);
  42540. };
  42541. task.ensureNotTerminated();
  42542. timeSlotManager.reset();
  42543. var stop, operation = {}, i, ii, cs;
  42544. while (!(stop = timeSlotManager.check())) {
  42545. // The arguments parsed by read() are used beyond this loop, so we
  42546. // cannot reuse the same array on each iteration. Therefore we pass
  42547. // in |null| as the initial value (see the comment on
  42548. // EvaluatorPreprocessor_read() for why).
  42549. operation.args = null;
  42550. if (!(preprocessor.read(operation))) {
  42551. break;
  42552. }
  42553. var args = operation.args;
  42554. var fn = operation.fn;
  42555. switch (fn | 0) {
  42556. case OPS.paintXObject:
  42557. if (args[0].code) {
  42558. break;
  42559. }
  42560. // eagerly compile XForm objects
  42561. var name = args[0].name;
  42562. if (!name) {
  42563. warn('XObject must be referred to by name.');
  42564. continue;
  42565. }
  42566. if (imageCache[name] !== undefined) {
  42567. operatorList.addOp(imageCache[name].fn, imageCache[name].args);
  42568. args = null;
  42569. continue;
  42570. }
  42571. var xobj = xobjs.get(name);
  42572. if (xobj) {
  42573. assert(isStream(xobj), 'XObject should be a stream');
  42574. var type = xobj.dict.get('Subtype');
  42575. assert(isName(type),
  42576. 'XObject should have a Name subtype');
  42577. if (type.name === 'Form') {
  42578. stateManager.save();
  42579. next(self.buildFormXObject(resources, xobj, null,
  42580. operatorList, task,
  42581. stateManager.state.clone()).
  42582. then(function () {
  42583. stateManager.restore();
  42584. }));
  42585. return;
  42586. } else if (type.name === 'Image') {
  42587. self.buildPaintImageXObject(resources, xobj, false,
  42588. operatorList, name, imageCache);
  42589. args = null;
  42590. continue;
  42591. } else if (type.name === 'PS') {
  42592. // PostScript XObjects are unused when viewing documents.
  42593. // See section 4.7.1 of Adobe's PDF reference.
  42594. info('Ignored XObject subtype PS');
  42595. continue;
  42596. } else {
  42597. error('Unhandled XObject subtype ' + type.name);
  42598. }
  42599. }
  42600. break;
  42601. case OPS.setFont:
  42602. var fontSize = args[1];
  42603. // eagerly collect all fonts
  42604. next(self.handleSetFont(resources, args, null, operatorList,
  42605. task, stateManager.state).
  42606. then(function (loadedName) {
  42607. operatorList.addDependency(loadedName);
  42608. operatorList.addOp(OPS.setFont, [loadedName, fontSize]);
  42609. }));
  42610. return;
  42611. case OPS.endInlineImage:
  42612. var cacheKey = args[0].cacheKey;
  42613. if (cacheKey) {
  42614. var cacheEntry = imageCache[cacheKey];
  42615. if (cacheEntry !== undefined) {
  42616. operatorList.addOp(cacheEntry.fn, cacheEntry.args);
  42617. args = null;
  42618. continue;
  42619. }
  42620. }
  42621. self.buildPaintImageXObject(resources, args[0], true,
  42622. operatorList, cacheKey, imageCache);
  42623. args = null;
  42624. continue;
  42625. case OPS.showText:
  42626. args[0] = self.handleText(args[0], stateManager.state);
  42627. break;
  42628. case OPS.showSpacedText:
  42629. var arr = args[0];
  42630. var combinedGlyphs = [];
  42631. var arrLength = arr.length;
  42632. var state = stateManager.state;
  42633. for (i = 0; i < arrLength; ++i) {
  42634. var arrItem = arr[i];
  42635. if (isString(arrItem)) {
  42636. Array.prototype.push.apply(combinedGlyphs,
  42637. self.handleText(arrItem, state));
  42638. } else if (isNum(arrItem)) {
  42639. combinedGlyphs.push(arrItem);
  42640. }
  42641. }
  42642. args[0] = combinedGlyphs;
  42643. fn = OPS.showText;
  42644. break;
  42645. case OPS.nextLineShowText:
  42646. operatorList.addOp(OPS.nextLine);
  42647. args[0] = self.handleText(args[0], stateManager.state);
  42648. fn = OPS.showText;
  42649. break;
  42650. case OPS.nextLineSetSpacingShowText:
  42651. operatorList.addOp(OPS.nextLine);
  42652. operatorList.addOp(OPS.setWordSpacing, [args.shift()]);
  42653. operatorList.addOp(OPS.setCharSpacing, [args.shift()]);
  42654. args[0] = self.handleText(args[0], stateManager.state);
  42655. fn = OPS.showText;
  42656. break;
  42657. case OPS.setTextRenderingMode:
  42658. stateManager.state.textRenderingMode = args[0];
  42659. break;
  42660. case OPS.setFillColorSpace:
  42661. stateManager.state.fillColorSpace =
  42662. ColorSpace.parse(args[0], xref, resources);
  42663. continue;
  42664. case OPS.setStrokeColorSpace:
  42665. stateManager.state.strokeColorSpace =
  42666. ColorSpace.parse(args[0], xref, resources);
  42667. continue;
  42668. case OPS.setFillColor:
  42669. cs = stateManager.state.fillColorSpace;
  42670. args = cs.getRgb(args, 0);
  42671. fn = OPS.setFillRGBColor;
  42672. break;
  42673. case OPS.setStrokeColor:
  42674. cs = stateManager.state.strokeColorSpace;
  42675. args = cs.getRgb(args, 0);
  42676. fn = OPS.setStrokeRGBColor;
  42677. break;
  42678. case OPS.setFillGray:
  42679. stateManager.state.fillColorSpace = ColorSpace.singletons.gray;
  42680. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42681. fn = OPS.setFillRGBColor;
  42682. break;
  42683. case OPS.setStrokeGray:
  42684. stateManager.state.strokeColorSpace = ColorSpace.singletons.gray;
  42685. args = ColorSpace.singletons.gray.getRgb(args, 0);
  42686. fn = OPS.setStrokeRGBColor;
  42687. break;
  42688. case OPS.setFillCMYKColor:
  42689. stateManager.state.fillColorSpace = ColorSpace.singletons.cmyk;
  42690. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42691. fn = OPS.setFillRGBColor;
  42692. break;
  42693. case OPS.setStrokeCMYKColor:
  42694. stateManager.state.strokeColorSpace = ColorSpace.singletons.cmyk;
  42695. args = ColorSpace.singletons.cmyk.getRgb(args, 0);
  42696. fn = OPS.setStrokeRGBColor;
  42697. break;
  42698. case OPS.setFillRGBColor:
  42699. stateManager.state.fillColorSpace = ColorSpace.singletons.rgb;
  42700. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42701. break;
  42702. case OPS.setStrokeRGBColor:
  42703. stateManager.state.strokeColorSpace = ColorSpace.singletons.rgb;
  42704. args = ColorSpace.singletons.rgb.getRgb(args, 0);
  42705. break;
  42706. case OPS.setFillColorN:
  42707. cs = stateManager.state.fillColorSpace;
  42708. if (cs.name === 'Pattern') {
  42709. next(self.handleColorN(operatorList, OPS.setFillColorN, args,
  42710. cs, patterns, resources, task, xref));
  42711. return;
  42712. }
  42713. args = cs.getRgb(args, 0);
  42714. fn = OPS.setFillRGBColor;
  42715. break;
  42716. case OPS.setStrokeColorN:
  42717. cs = stateManager.state.strokeColorSpace;
  42718. if (cs.name === 'Pattern') {
  42719. next(self.handleColorN(operatorList, OPS.setStrokeColorN, args,
  42720. cs, patterns, resources, task, xref));
  42721. return;
  42722. }
  42723. args = cs.getRgb(args, 0);
  42724. fn = OPS.setStrokeRGBColor;
  42725. break;
  42726. case OPS.shadingFill:
  42727. var shadingRes = resources.get('Shading');
  42728. if (!shadingRes) {
  42729. error('No shading resource found');
  42730. }
  42731. var shading = shadingRes.get(args[0].name);
  42732. if (!shading) {
  42733. error('No shading object found');
  42734. }
  42735. var shadingFill = Pattern.parseShading(shading, null, xref,
  42736. resources, self.handler);
  42737. var patternIR = shadingFill.getIR();
  42738. args = [patternIR];
  42739. fn = OPS.shadingFill;
  42740. break;
  42741. case OPS.setGState:
  42742. var dictName = args[0];
  42743. var extGState = resources.get('ExtGState');
  42744. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  42745. break;
  42746. }
  42747. var gState = extGState.get(dictName.name);
  42748. next(self.setGState(resources, gState, operatorList, task, xref,
  42749. stateManager));
  42750. return;
  42751. case OPS.moveTo:
  42752. case OPS.lineTo:
  42753. case OPS.curveTo:
  42754. case OPS.curveTo2:
  42755. case OPS.curveTo3:
  42756. case OPS.closePath:
  42757. self.buildPath(operatorList, fn, args);
  42758. continue;
  42759. case OPS.rectangle:
  42760. self.buildPath(operatorList, fn, args);
  42761. continue;
  42762. case OPS.markPoint:
  42763. case OPS.markPointProps:
  42764. case OPS.beginMarkedContent:
  42765. case OPS.beginMarkedContentProps:
  42766. case OPS.endMarkedContent:
  42767. case OPS.beginCompat:
  42768. case OPS.endCompat:
  42769. // Ignore operators where the corresponding handlers are known to
  42770. // be no-op in CanvasGraphics (display/canvas.js). This prevents
  42771. // serialization errors and is also a bit more efficient.
  42772. // We could also try to serialize all objects in a general way,
  42773. // e.g. as done in https://github.com/mozilla/pdf.js/pull/6266,
  42774. // but doing so is meaningless without knowing the semantics.
  42775. continue;
  42776. default:
  42777. // Note: Ignore the operator if it has `Dict` arguments, since
  42778. // those are non-serializable, otherwise postMessage will throw
  42779. // "An object could not be cloned.".
  42780. if (args !== null) {
  42781. for (i = 0, ii = args.length; i < ii; i++) {
  42782. if (args[i] instanceof Dict) {
  42783. break;
  42784. }
  42785. }
  42786. if (i < ii) {
  42787. warn('getOperatorList - ignoring operator: ' + fn);
  42788. continue;
  42789. }
  42790. }
  42791. }
  42792. operatorList.addOp(fn, args);
  42793. }
  42794. if (stop) {
  42795. next(deferred);
  42796. return;
  42797. }
  42798. // Some PDFs don't close all restores inside object/form.
  42799. // Closing those for them.
  42800. for (i = 0, ii = preprocessor.savedStatesDepth; i < ii; i++) {
  42801. operatorList.addOp(OPS.restore, []);
  42802. }
  42803. resolve();
  42804. });
  42805. },
  42806. getTextContent:
  42807. function PartialEvaluator_getTextContent(stream, task, resources,
  42808. stateManager,
  42809. normalizeWhitespace) {
  42810. stateManager = (stateManager || new StateManager(new TextState()));
  42811. var WhitespaceRegexp = /\s/g;
  42812. var textContent = {
  42813. items: [],
  42814. styles: Object.create(null)
  42815. };
  42816. var textContentItem = {
  42817. initialized: false,
  42818. str: [],
  42819. width: 0,
  42820. height: 0,
  42821. vertical: false,
  42822. lastAdvanceWidth: 0,
  42823. lastAdvanceHeight: 0,
  42824. textAdvanceScale: 0,
  42825. spaceWidth: 0,
  42826. fakeSpaceMin: Infinity,
  42827. fakeMultiSpaceMin: Infinity,
  42828. fakeMultiSpaceMax: -0,
  42829. textRunBreakAllowed: false,
  42830. transform: null,
  42831. fontName: null
  42832. };
  42833. var SPACE_FACTOR = 0.3;
  42834. var MULTI_SPACE_FACTOR = 1.5;
  42835. var MULTI_SPACE_FACTOR_MAX = 4;
  42836. var self = this;
  42837. var xref = this.xref;
  42838. resources = (xref.fetchIfRef(resources) || Dict.empty);
  42839. // The xobj is parsed iff it's needed, e.g. if there is a `DO` cmd.
  42840. var xobjs = null;
  42841. var xobjsCache = Object.create(null);
  42842. var preprocessor = new EvaluatorPreprocessor(stream, xref, stateManager);
  42843. var textState;
  42844. function ensureTextContentItem() {
  42845. if (textContentItem.initialized) {
  42846. return textContentItem;
  42847. }
  42848. var font = textState.font;
  42849. if (!(font.loadedName in textContent.styles)) {
  42850. textContent.styles[font.loadedName] = {
  42851. fontFamily: font.fallbackName,
  42852. ascent: font.ascent,
  42853. descent: font.descent,
  42854. vertical: font.vertical
  42855. };
  42856. }
  42857. textContentItem.fontName = font.loadedName;
  42858. // 9.4.4 Text Space Details
  42859. var tsm = [textState.fontSize * textState.textHScale, 0,
  42860. 0, textState.fontSize,
  42861. 0, textState.textRise];
  42862. if (font.isType3Font &&
  42863. textState.fontMatrix !== FONT_IDENTITY_MATRIX &&
  42864. textState.fontSize === 1) {
  42865. var glyphHeight = font.bbox[3] - font.bbox[1];
  42866. if (glyphHeight > 0) {
  42867. glyphHeight = glyphHeight * textState.fontMatrix[3];
  42868. tsm[3] *= glyphHeight;
  42869. }
  42870. }
  42871. var trm = Util.transform(textState.ctm,
  42872. Util.transform(textState.textMatrix, tsm));
  42873. textContentItem.transform = trm;
  42874. if (!font.vertical) {
  42875. textContentItem.width = 0;
  42876. textContentItem.height = Math.sqrt(trm[2] * trm[2] + trm[3] * trm[3]);
  42877. textContentItem.vertical = false;
  42878. } else {
  42879. textContentItem.width = Math.sqrt(trm[0] * trm[0] + trm[1] * trm[1]);
  42880. textContentItem.height = 0;
  42881. textContentItem.vertical = true;
  42882. }
  42883. var a = textState.textLineMatrix[0];
  42884. var b = textState.textLineMatrix[1];
  42885. var scaleLineX = Math.sqrt(a * a + b * b);
  42886. a = textState.ctm[0];
  42887. b = textState.ctm[1];
  42888. var scaleCtmX = Math.sqrt(a * a + b * b);
  42889. textContentItem.textAdvanceScale = scaleCtmX * scaleLineX;
  42890. textContentItem.lastAdvanceWidth = 0;
  42891. textContentItem.lastAdvanceHeight = 0;
  42892. var spaceWidth = font.spaceWidth / 1000 * textState.fontSize;
  42893. if (spaceWidth) {
  42894. textContentItem.spaceWidth = spaceWidth;
  42895. textContentItem.fakeSpaceMin = spaceWidth * SPACE_FACTOR;
  42896. textContentItem.fakeMultiSpaceMin = spaceWidth * MULTI_SPACE_FACTOR;
  42897. textContentItem.fakeMultiSpaceMax =
  42898. spaceWidth * MULTI_SPACE_FACTOR_MAX;
  42899. // It's okay for monospace fonts to fake as much space as needed.
  42900. textContentItem.textRunBreakAllowed = !font.isMonospace;
  42901. } else {
  42902. textContentItem.spaceWidth = 0;
  42903. textContentItem.fakeSpaceMin = Infinity;
  42904. textContentItem.fakeMultiSpaceMin = Infinity;
  42905. textContentItem.fakeMultiSpaceMax = 0;
  42906. textContentItem.textRunBreakAllowed = false;
  42907. }
  42908. textContentItem.initialized = true;
  42909. return textContentItem;
  42910. }
  42911. function replaceWhitespace(str) {
  42912. // Replaces all whitespaces with standard spaces (0x20), to avoid
  42913. // alignment issues between the textLayer and the canvas if the text
  42914. // contains e.g. tabs (fixes issue6612.pdf).
  42915. var i = 0, ii = str.length, code;
  42916. while (i < ii && (code = str.charCodeAt(i)) >= 0x20 && code <= 0x7F) {
  42917. i++;
  42918. }
  42919. return (i < ii ? str.replace(WhitespaceRegexp, ' ') : str);
  42920. }
  42921. function runBidiTransform(textChunk) {
  42922. var str = textChunk.str.join('');
  42923. var bidiResult = bidi(str, -1, textChunk.vertical);
  42924. return {
  42925. str: (normalizeWhitespace ? replaceWhitespace(bidiResult.str) :
  42926. bidiResult.str),
  42927. dir: bidiResult.dir,
  42928. width: textChunk.width,
  42929. height: textChunk.height,
  42930. transform: textChunk.transform,
  42931. fontName: textChunk.fontName
  42932. };
  42933. }
  42934. function handleSetFont(fontName, fontRef) {
  42935. return self.loadFont(fontName, fontRef, xref, resources).
  42936. then(function (translated) {
  42937. textState.font = translated.font;
  42938. textState.fontMatrix = translated.font.fontMatrix ||
  42939. FONT_IDENTITY_MATRIX;
  42940. });
  42941. }
  42942. function buildTextContentItem(chars) {
  42943. var font = textState.font;
  42944. var textChunk = ensureTextContentItem();
  42945. var width = 0;
  42946. var height = 0;
  42947. var glyphs = font.charsToGlyphs(chars);
  42948. var defaultVMetrics = font.defaultVMetrics;
  42949. for (var i = 0; i < glyphs.length; i++) {
  42950. var glyph = glyphs[i];
  42951. var vMetricX = null;
  42952. var vMetricY = null;
  42953. var glyphWidth = null;
  42954. if (font.vertical) {
  42955. if (glyph.vmetric) {
  42956. glyphWidth = glyph.vmetric[0];
  42957. vMetricX = glyph.vmetric[1];
  42958. vMetricY = glyph.vmetric[2];
  42959. } else {
  42960. glyphWidth = glyph.width;
  42961. vMetricX = glyph.width * 0.5;
  42962. vMetricY = defaultVMetrics[2];
  42963. }
  42964. } else {
  42965. glyphWidth = glyph.width;
  42966. }
  42967. var glyphUnicode = glyph.unicode;
  42968. var NormalizedUnicodes = getNormalizedUnicodes();
  42969. if (NormalizedUnicodes[glyphUnicode] !== undefined) {
  42970. glyphUnicode = NormalizedUnicodes[glyphUnicode];
  42971. }
  42972. glyphUnicode = reverseIfRtl(glyphUnicode);
  42973. // The following will calculate the x and y of the individual glyphs.
  42974. // if (font.vertical) {
  42975. // tsm[4] -= vMetricX * Math.abs(textState.fontSize) *
  42976. // textState.fontMatrix[0];
  42977. // tsm[5] -= vMetricY * textState.fontSize *
  42978. // textState.fontMatrix[0];
  42979. // }
  42980. // var trm = Util.transform(textState.textMatrix, tsm);
  42981. // var pt = Util.applyTransform([trm[4], trm[5]], textState.ctm);
  42982. // var x = pt[0];
  42983. // var y = pt[1];
  42984. var charSpacing = textState.charSpacing;
  42985. if (glyph.isSpace) {
  42986. var wordSpacing = textState.wordSpacing;
  42987. charSpacing += wordSpacing;
  42988. if (wordSpacing > 0) {
  42989. addFakeSpaces(wordSpacing, textChunk.str);
  42990. }
  42991. }
  42992. var tx = 0;
  42993. var ty = 0;
  42994. if (!font.vertical) {
  42995. var w0 = glyphWidth * textState.fontMatrix[0];
  42996. tx = (w0 * textState.fontSize + charSpacing) *
  42997. textState.textHScale;
  42998. width += tx;
  42999. } else {
  43000. var w1 = glyphWidth * textState.fontMatrix[0];
  43001. ty = w1 * textState.fontSize + charSpacing;
  43002. height += ty;
  43003. }
  43004. textState.translateTextMatrix(tx, ty);
  43005. textChunk.str.push(glyphUnicode);
  43006. }
  43007. if (!font.vertical) {
  43008. textChunk.lastAdvanceWidth = width;
  43009. textChunk.width += width * textChunk.textAdvanceScale;
  43010. } else {
  43011. textChunk.lastAdvanceHeight = height;
  43012. textChunk.height += Math.abs(height * textChunk.textAdvanceScale);
  43013. }
  43014. return textChunk;
  43015. }
  43016. function addFakeSpaces(width, strBuf) {
  43017. if (width < textContentItem.fakeSpaceMin) {
  43018. return;
  43019. }
  43020. if (width < textContentItem.fakeMultiSpaceMin) {
  43021. strBuf.push(' ');
  43022. return;
  43023. }
  43024. var fakeSpaces = Math.round(width / textContentItem.spaceWidth);
  43025. while (fakeSpaces-- > 0) {
  43026. strBuf.push(' ');
  43027. }
  43028. }
  43029. function flushTextContentItem() {
  43030. if (!textContentItem.initialized) {
  43031. return;
  43032. }
  43033. textContent.items.push(runBidiTransform(textContentItem));
  43034. textContentItem.initialized = false;
  43035. textContentItem.str.length = 0;
  43036. }
  43037. var timeSlotManager = new TimeSlotManager();
  43038. return new Promise(function promiseBody(resolve, reject) {
  43039. var next = function (promise) {
  43040. promise.then(function () {
  43041. try {
  43042. promiseBody(resolve, reject);
  43043. } catch (ex) {
  43044. reject(ex);
  43045. }
  43046. }, reject);
  43047. };
  43048. task.ensureNotTerminated();
  43049. timeSlotManager.reset();
  43050. var stop, operation = {}, args = [];
  43051. while (!(stop = timeSlotManager.check())) {
  43052. // The arguments parsed by read() are not used beyond this loop, so
  43053. // we can reuse the same array on every iteration, thus avoiding
  43054. // unnecessary allocations.
  43055. args.length = 0;
  43056. operation.args = args;
  43057. if (!(preprocessor.read(operation))) {
  43058. break;
  43059. }
  43060. textState = stateManager.state;
  43061. var fn = operation.fn;
  43062. args = operation.args;
  43063. var advance;
  43064. switch (fn | 0) {
  43065. case OPS.setFont:
  43066. flushTextContentItem();
  43067. textState.fontSize = args[1];
  43068. next(handleSetFont(args[0].name));
  43069. return;
  43070. case OPS.setTextRise:
  43071. flushTextContentItem();
  43072. textState.textRise = args[0];
  43073. break;
  43074. case OPS.setHScale:
  43075. flushTextContentItem();
  43076. textState.textHScale = args[0] / 100;
  43077. break;
  43078. case OPS.setLeading:
  43079. flushTextContentItem();
  43080. textState.leading = args[0];
  43081. break;
  43082. case OPS.moveText:
  43083. // Optimization to treat same line movement as advance
  43084. var isSameTextLine = !textState.font ? false :
  43085. ((textState.font.vertical ? args[0] : args[1]) === 0);
  43086. advance = args[0] - args[1];
  43087. if (isSameTextLine && textContentItem.initialized &&
  43088. advance > 0 &&
  43089. advance <= textContentItem.fakeMultiSpaceMax) {
  43090. textState.translateTextLineMatrix(args[0], args[1]);
  43091. textContentItem.width +=
  43092. (args[0] - textContentItem.lastAdvanceWidth);
  43093. textContentItem.height +=
  43094. (args[1] - textContentItem.lastAdvanceHeight);
  43095. var diff = (args[0] - textContentItem.lastAdvanceWidth) -
  43096. (args[1] - textContentItem.lastAdvanceHeight);
  43097. addFakeSpaces(diff, textContentItem.str);
  43098. break;
  43099. }
  43100. flushTextContentItem();
  43101. textState.translateTextLineMatrix(args[0], args[1]);
  43102. textState.textMatrix = textState.textLineMatrix.slice();
  43103. break;
  43104. case OPS.setLeadingMoveText:
  43105. flushTextContentItem();
  43106. textState.leading = -args[1];
  43107. textState.translateTextLineMatrix(args[0], args[1]);
  43108. textState.textMatrix = textState.textLineMatrix.slice();
  43109. break;
  43110. case OPS.nextLine:
  43111. flushTextContentItem();
  43112. textState.carriageReturn();
  43113. break;
  43114. case OPS.setTextMatrix:
  43115. flushTextContentItem();
  43116. textState.setTextMatrix(args[0], args[1], args[2], args[3],
  43117. args[4], args[5]);
  43118. textState.setTextLineMatrix(args[0], args[1], args[2], args[3],
  43119. args[4], args[5]);
  43120. break;
  43121. case OPS.setCharSpacing:
  43122. textState.charSpacing = args[0];
  43123. break;
  43124. case OPS.setWordSpacing:
  43125. textState.wordSpacing = args[0];
  43126. break;
  43127. case OPS.beginText:
  43128. flushTextContentItem();
  43129. textState.textMatrix = IDENTITY_MATRIX.slice();
  43130. textState.textLineMatrix = IDENTITY_MATRIX.slice();
  43131. break;
  43132. case OPS.showSpacedText:
  43133. var items = args[0];
  43134. var offset;
  43135. for (var j = 0, jj = items.length; j < jj; j++) {
  43136. if (typeof items[j] === 'string') {
  43137. buildTextContentItem(items[j]);
  43138. } else {
  43139. ensureTextContentItem();
  43140. // PDF Specification 5.3.2 states:
  43141. // The number is expressed in thousandths of a unit of text
  43142. // space.
  43143. // This amount is subtracted from the current horizontal or
  43144. // vertical coordinate, depending on the writing mode.
  43145. // In the default coordinate system, a positive adjustment
  43146. // has the effect of moving the next glyph painted either to
  43147. // the left or down by the given amount.
  43148. advance = items[j] * textState.fontSize / 1000;
  43149. var breakTextRun = false;
  43150. if (textState.font.vertical) {
  43151. offset = advance *
  43152. (textState.textHScale * textState.textMatrix[2] +
  43153. textState.textMatrix[3]);
  43154. textState.translateTextMatrix(0, advance);
  43155. breakTextRun = textContentItem.textRunBreakAllowed &&
  43156. advance > textContentItem.fakeMultiSpaceMax;
  43157. if (!breakTextRun) {
  43158. // Value needs to be added to height to paint down.
  43159. textContentItem.height += offset;
  43160. }
  43161. } else {
  43162. advance = -advance;
  43163. offset = advance * (
  43164. textState.textHScale * textState.textMatrix[0] +
  43165. textState.textMatrix[1]);
  43166. textState.translateTextMatrix(advance, 0);
  43167. breakTextRun = textContentItem.textRunBreakAllowed &&
  43168. advance > textContentItem.fakeMultiSpaceMax;
  43169. if (!breakTextRun) {
  43170. // Value needs to be subtracted from width to paint left.
  43171. textContentItem.width += offset;
  43172. }
  43173. }
  43174. if (breakTextRun) {
  43175. flushTextContentItem();
  43176. } else if (advance > 0) {
  43177. addFakeSpaces(advance, textContentItem.str);
  43178. }
  43179. }
  43180. }
  43181. break;
  43182. case OPS.showText:
  43183. buildTextContentItem(args[0]);
  43184. break;
  43185. case OPS.nextLineShowText:
  43186. flushTextContentItem();
  43187. textState.carriageReturn();
  43188. buildTextContentItem(args[0]);
  43189. break;
  43190. case OPS.nextLineSetSpacingShowText:
  43191. flushTextContentItem();
  43192. textState.wordSpacing = args[0];
  43193. textState.charSpacing = args[1];
  43194. textState.carriageReturn();
  43195. buildTextContentItem(args[2]);
  43196. break;
  43197. case OPS.paintXObject:
  43198. flushTextContentItem();
  43199. if (args[0].code) {
  43200. break;
  43201. }
  43202. if (!xobjs) {
  43203. xobjs = (resources.get('XObject') || Dict.empty);
  43204. }
  43205. var name = args[0].name;
  43206. if (xobjsCache.key === name) {
  43207. if (xobjsCache.texts) {
  43208. Util.appendToArray(textContent.items, xobjsCache.texts.items);
  43209. Util.extendObj(textContent.styles, xobjsCache.texts.styles);
  43210. }
  43211. break;
  43212. }
  43213. var xobj = xobjs.get(name);
  43214. if (!xobj) {
  43215. break;
  43216. }
  43217. assert(isStream(xobj), 'XObject should be a stream');
  43218. var type = xobj.dict.get('Subtype');
  43219. assert(isName(type),
  43220. 'XObject should have a Name subtype');
  43221. if ('Form' !== type.name) {
  43222. xobjsCache.key = name;
  43223. xobjsCache.texts = null;
  43224. break;
  43225. }
  43226. stateManager.save();
  43227. var matrix = xobj.dict.get('Matrix');
  43228. if (isArray(matrix) && matrix.length === 6) {
  43229. stateManager.transform(matrix);
  43230. }
  43231. next(self.getTextContent(xobj, task,
  43232. xobj.dict.get('Resources') || resources, stateManager,
  43233. normalizeWhitespace).then(function (formTextContent) {
  43234. Util.appendToArray(textContent.items, formTextContent.items);
  43235. Util.extendObj(textContent.styles, formTextContent.styles);
  43236. stateManager.restore();
  43237. xobjsCache.key = name;
  43238. xobjsCache.texts = formTextContent;
  43239. }));
  43240. return;
  43241. case OPS.setGState:
  43242. flushTextContentItem();
  43243. var dictName = args[0];
  43244. var extGState = resources.get('ExtGState');
  43245. if (!isDict(extGState) || !extGState.has(dictName.name)) {
  43246. break;
  43247. }
  43248. var gsStateMap = extGState.get(dictName.name);
  43249. var gsStateFont = null;
  43250. for (var key in gsStateMap) {
  43251. if (key === 'Font') {
  43252. assert(!gsStateFont);
  43253. gsStateFont = gsStateMap[key];
  43254. }
  43255. }
  43256. if (gsStateFont) {
  43257. textState.fontSize = gsStateFont[1];
  43258. next(handleSetFont(gsStateFont[0]));
  43259. return;
  43260. }
  43261. break;
  43262. } // switch
  43263. } // while
  43264. if (stop) {
  43265. next(deferred);
  43266. return;
  43267. }
  43268. flushTextContentItem();
  43269. resolve(textContent);
  43270. });
  43271. },
  43272. extractDataStructures: function
  43273. partialEvaluatorExtractDataStructures(dict, baseDict,
  43274. xref, properties) {
  43275. // 9.10.2
  43276. var toUnicode = (dict.get('ToUnicode') || baseDict.get('ToUnicode'));
  43277. var toUnicodePromise = toUnicode ?
  43278. this.readToUnicode(toUnicode) : Promise.resolve(undefined);
  43279. if (properties.composite) {
  43280. // CIDSystemInfo helps to match CID to glyphs
  43281. var cidSystemInfo = dict.get('CIDSystemInfo');
  43282. if (isDict(cidSystemInfo)) {
  43283. properties.cidSystemInfo = {
  43284. registry: cidSystemInfo.get('Registry'),
  43285. ordering: cidSystemInfo.get('Ordering'),
  43286. supplement: cidSystemInfo.get('Supplement')
  43287. };
  43288. }
  43289. var cidToGidMap = dict.get('CIDToGIDMap');
  43290. if (isStream(cidToGidMap)) {
  43291. properties.cidToGidMap = this.readCidToGidMap(cidToGidMap);
  43292. }
  43293. }
  43294. // Based on 9.6.6 of the spec the encoding can come from multiple places
  43295. // and depends on the font type. The base encoding and differences are
  43296. // read here, but the encoding that is actually used is chosen during
  43297. // glyph mapping in the font.
  43298. // TODO: Loading the built in encoding in the font would allow the
  43299. // differences to be merged in here not require us to hold on to it.
  43300. var differences = [];
  43301. var baseEncodingName = null;
  43302. var encoding;
  43303. if (dict.has('Encoding')) {
  43304. encoding = dict.get('Encoding');
  43305. if (isDict(encoding)) {
  43306. baseEncodingName = encoding.get('BaseEncoding');
  43307. baseEncodingName = (isName(baseEncodingName) ?
  43308. baseEncodingName.name : null);
  43309. // Load the differences between the base and original
  43310. if (encoding.has('Differences')) {
  43311. var diffEncoding = encoding.get('Differences');
  43312. var index = 0;
  43313. for (var j = 0, jj = diffEncoding.length; j < jj; j++) {
  43314. var data = xref.fetchIfRef(diffEncoding[j]);
  43315. if (isNum(data)) {
  43316. index = data;
  43317. } else if (isName(data)) {
  43318. differences[index++] = data.name;
  43319. } else {
  43320. error('Invalid entry in \'Differences\' array: ' + data);
  43321. }
  43322. }
  43323. }
  43324. } else if (isName(encoding)) {
  43325. baseEncodingName = encoding.name;
  43326. } else {
  43327. error('Encoding is not a Name nor a Dict');
  43328. }
  43329. // According to table 114 if the encoding is a named encoding it must be
  43330. // one of these predefined encodings.
  43331. if ((baseEncodingName !== 'MacRomanEncoding' &&
  43332. baseEncodingName !== 'MacExpertEncoding' &&
  43333. baseEncodingName !== 'WinAnsiEncoding')) {
  43334. baseEncodingName = null;
  43335. }
  43336. }
  43337. if (baseEncodingName) {
  43338. properties.defaultEncoding = getEncoding(baseEncodingName).slice();
  43339. } else {
  43340. encoding = (properties.type === 'TrueType' ?
  43341. WinAnsiEncoding : StandardEncoding);
  43342. // The Symbolic attribute can be misused for regular fonts
  43343. // Heuristic: we have to check if the font is a standard one also
  43344. if (!!(properties.flags & FontFlags.Symbolic)) {
  43345. encoding = MacRomanEncoding;
  43346. if (!properties.file) {
  43347. if (/Symbol/i.test(properties.name)) {
  43348. encoding = SymbolSetEncoding;
  43349. } else if (/Dingbats/i.test(properties.name)) {
  43350. encoding = ZapfDingbatsEncoding;
  43351. }
  43352. }
  43353. }
  43354. properties.defaultEncoding = encoding;
  43355. }
  43356. properties.differences = differences;
  43357. properties.baseEncodingName = baseEncodingName;
  43358. properties.dict = dict;
  43359. return toUnicodePromise.then(function(toUnicode) {
  43360. properties.toUnicode = toUnicode;
  43361. return this.buildToUnicode(properties);
  43362. }.bind(this)).then(function (toUnicode) {
  43363. properties.toUnicode = toUnicode;
  43364. return properties;
  43365. });
  43366. },
  43367. /**
  43368. * Builds a char code to unicode map based on section 9.10 of the spec.
  43369. * @param {Object} properties Font properties object.
  43370. * @return {Promise} A Promise resolving to ToUnicodeMap object.
  43371. */
  43372. buildToUnicode: function partialEvaluator_buildToUnicode(properties) {
  43373. // Section 9.10.2 Mapping Character Codes to Unicode Values
  43374. if (properties.toUnicode && properties.toUnicode.length !== 0) {
  43375. return Promise.resolve(properties.toUnicode);
  43376. }
  43377. // According to the spec if the font is a simple font we should only map
  43378. // to unicode if the base encoding is MacRoman, MacExpert, or WinAnsi or
  43379. // the differences array only contains adobe standard or symbol set names,
  43380. // in pratice it seems better to always try to create a toUnicode
  43381. // map based of the default encoding.
  43382. var toUnicode, charcode;
  43383. if (!properties.composite /* is simple font */) {
  43384. toUnicode = [];
  43385. var encoding = properties.defaultEncoding.slice();
  43386. var baseEncodingName = properties.baseEncodingName;
  43387. // Merge in the differences array.
  43388. var differences = properties.differences;
  43389. for (charcode in differences) {
  43390. encoding[charcode] = differences[charcode];
  43391. }
  43392. var glyphsUnicodeMap = getGlyphsUnicode();
  43393. for (charcode in encoding) {
  43394. // a) Map the character code to a character name.
  43395. var glyphName = encoding[charcode];
  43396. // b) Look up the character name in the Adobe Glyph List (see the
  43397. // Bibliography) to obtain the corresponding Unicode value.
  43398. if (glyphName === '') {
  43399. continue;
  43400. } else if (glyphsUnicodeMap[glyphName] === undefined) {
  43401. // (undocumented) c) Few heuristics to recognize unknown glyphs
  43402. // NOTE: Adobe Reader does not do this step, but OSX Preview does
  43403. var code = 0;
  43404. switch (glyphName[0]) {
  43405. case 'G': // Gxx glyph
  43406. if (glyphName.length === 3) {
  43407. code = parseInt(glyphName.substr(1), 16);
  43408. }
  43409. break;
  43410. case 'g': // g00xx glyph
  43411. if (glyphName.length === 5) {
  43412. code = parseInt(glyphName.substr(1), 16);
  43413. }
  43414. break;
  43415. case 'C': // Cddd glyph
  43416. case 'c': // cddd glyph
  43417. if (glyphName.length >= 3) {
  43418. code = +glyphName.substr(1);
  43419. }
  43420. break;
  43421. default:
  43422. // 'uniXXXX'/'uXXXX{XX}' glyphs
  43423. var unicode = getUnicodeForGlyph(glyphName, glyphsUnicodeMap);
  43424. if (unicode !== -1) {
  43425. code = unicode;
  43426. }
  43427. }
  43428. if (code) {
  43429. // If |baseEncodingName| is one the predefined encodings,
  43430. // and |code| equals |charcode|, using the glyph defined in the
  43431. // baseEncoding seems to yield a better |toUnicode| mapping
  43432. // (fixes issue 5070).
  43433. if (baseEncodingName && code === +charcode) {
  43434. var baseEncoding = getEncoding(baseEncodingName);
  43435. if (baseEncoding && (glyphName = baseEncoding[charcode])) {
  43436. toUnicode[charcode] =
  43437. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  43438. continue;
  43439. }
  43440. }
  43441. toUnicode[charcode] = String.fromCharCode(code);
  43442. }
  43443. continue;
  43444. }
  43445. toUnicode[charcode] =
  43446. String.fromCharCode(glyphsUnicodeMap[glyphName]);
  43447. }
  43448. return Promise.resolve(new ToUnicodeMap(toUnicode));
  43449. }
  43450. // If the font is a composite font that uses one of the predefined CMaps
  43451. // listed in Table 118 (except Identity–H and Identity–V) or whose
  43452. // descendant CIDFont uses the Adobe-GB1, Adobe-CNS1, Adobe-Japan1, or
  43453. // Adobe-Korea1 character collection:
  43454. if (properties.composite && (
  43455. (properties.cMap.builtInCMap &&
  43456. !(properties.cMap instanceof IdentityCMap)) ||
  43457. (properties.cidSystemInfo.registry === 'Adobe' &&
  43458. (properties.cidSystemInfo.ordering === 'GB1' ||
  43459. properties.cidSystemInfo.ordering === 'CNS1' ||
  43460. properties.cidSystemInfo.ordering === 'Japan1' ||
  43461. properties.cidSystemInfo.ordering === 'Korea1')))) {
  43462. // Then:
  43463. // a) Map the character code to a character identifier (CID) according
  43464. // to the font’s CMap.
  43465. // b) Obtain the registry and ordering of the character collection used
  43466. // by the font’s CMap (for example, Adobe and Japan1) from its
  43467. // CIDSystemInfo dictionary.
  43468. var registry = properties.cidSystemInfo.registry;
  43469. var ordering = properties.cidSystemInfo.ordering;
  43470. // c) Construct a second CMap name by concatenating the registry and
  43471. // ordering obtained in step (b) in the format registry–ordering–UCS2
  43472. // (for example, Adobe–Japan1–UCS2).
  43473. var ucs2CMapName = new Name(registry + '-' + ordering + '-UCS2');
  43474. // d) Obtain the CMap with the name constructed in step (c) (available
  43475. // from the ASN Web site; see the Bibliography).
  43476. return CMapFactory.create(ucs2CMapName, this.options.cMapOptions,
  43477. null).then(
  43478. function (ucs2CMap) {
  43479. var cMap = properties.cMap;
  43480. toUnicode = [];
  43481. cMap.forEach(function(charcode, cid) {
  43482. assert(cid <= 0xffff, 'Max size of CID is 65,535');
  43483. // e) Map the CID obtained in step (a) according to the CMap
  43484. // obtained in step (d), producing a Unicode value.
  43485. var ucs2 = ucs2CMap.lookup(cid);
  43486. if (ucs2) {
  43487. toUnicode[charcode] =
  43488. String.fromCharCode((ucs2.charCodeAt(0) << 8) +
  43489. ucs2.charCodeAt(1));
  43490. }
  43491. });
  43492. return new ToUnicodeMap(toUnicode);
  43493. });
  43494. }
  43495. // The viewer's choice, just use an identity map.
  43496. return Promise.resolve(new IdentityToUnicodeMap(properties.firstChar,
  43497. properties.lastChar));
  43498. },
  43499. readToUnicode: function PartialEvaluator_readToUnicode(toUnicode) {
  43500. var cmapObj = toUnicode;
  43501. if (isName(cmapObj)) {
  43502. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  43503. function (cmap) {
  43504. if (cmap instanceof IdentityCMap) {
  43505. return new IdentityToUnicodeMap(0, 0xFFFF);
  43506. }
  43507. return new ToUnicodeMap(cmap.getMap());
  43508. });
  43509. } else if (isStream(cmapObj)) {
  43510. return CMapFactory.create(cmapObj, this.options.cMapOptions, null).then(
  43511. function (cmap) {
  43512. if (cmap instanceof IdentityCMap) {
  43513. return new IdentityToUnicodeMap(0, 0xFFFF);
  43514. }
  43515. var map = new Array(cmap.length);
  43516. // Convert UTF-16BE
  43517. // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
  43518. // to iterate over all keys.
  43519. cmap.forEach(function(charCode, token) {
  43520. var str = [];
  43521. for (var k = 0; k < token.length; k += 2) {
  43522. var w1 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43523. if ((w1 & 0xF800) !== 0xD800) { // w1 < 0xD800 || w1 > 0xDFFF
  43524. str.push(w1);
  43525. continue;
  43526. }
  43527. k += 2;
  43528. var w2 = (token.charCodeAt(k) << 8) | token.charCodeAt(k + 1);
  43529. str.push(((w1 & 0x3ff) << 10) + (w2 & 0x3ff) + 0x10000);
  43530. }
  43531. map[charCode] = String.fromCharCode.apply(String, str);
  43532. });
  43533. return new ToUnicodeMap(map);
  43534. });
  43535. }
  43536. return Promise.resolve(null);
  43537. },
  43538. readCidToGidMap: function PartialEvaluator_readCidToGidMap(cidToGidStream) {
  43539. // Extract the encoding from the CIDToGIDMap
  43540. var glyphsData = cidToGidStream.getBytes();
  43541. // Set encoding 0 to later verify the font has an encoding
  43542. var result = [];
  43543. for (var j = 0, jj = glyphsData.length; j < jj; j++) {
  43544. var glyphID = (glyphsData[j++] << 8) | glyphsData[j];
  43545. if (glyphID === 0) {
  43546. continue;
  43547. }
  43548. var code = j >> 1;
  43549. result[code] = glyphID;
  43550. }
  43551. return result;
  43552. },
  43553. extractWidths: function PartialEvaluator_extractWidths(dict, xref,
  43554. descriptor,
  43555. properties) {
  43556. var glyphsWidths = [];
  43557. var defaultWidth = 0;
  43558. var glyphsVMetrics = [];
  43559. var defaultVMetrics;
  43560. var i, ii, j, jj, start, code, widths;
  43561. if (properties.composite) {
  43562. defaultWidth = dict.get('DW') || 1000;
  43563. widths = dict.get('W');
  43564. if (widths) {
  43565. for (i = 0, ii = widths.length; i < ii; i++) {
  43566. start = widths[i++];
  43567. code = xref.fetchIfRef(widths[i]);
  43568. if (isArray(code)) {
  43569. for (j = 0, jj = code.length; j < jj; j++) {
  43570. glyphsWidths[start++] = code[j];
  43571. }
  43572. } else {
  43573. var width = widths[++i];
  43574. for (j = start; j <= code; j++) {
  43575. glyphsWidths[j] = width;
  43576. }
  43577. }
  43578. }
  43579. }
  43580. if (properties.vertical) {
  43581. var vmetrics = (dict.get('DW2') || [880, -1000]);
  43582. defaultVMetrics = [vmetrics[1], defaultWidth * 0.5, vmetrics[0]];
  43583. vmetrics = dict.get('W2');
  43584. if (vmetrics) {
  43585. for (i = 0, ii = vmetrics.length; i < ii; i++) {
  43586. start = vmetrics[i++];
  43587. code = xref.fetchIfRef(vmetrics[i]);
  43588. if (isArray(code)) {
  43589. for (j = 0, jj = code.length; j < jj; j++) {
  43590. glyphsVMetrics[start++] = [code[j++], code[j++], code[j]];
  43591. }
  43592. } else {
  43593. var vmetric = [vmetrics[++i], vmetrics[++i], vmetrics[++i]];
  43594. for (j = start; j <= code; j++) {
  43595. glyphsVMetrics[j] = vmetric;
  43596. }
  43597. }
  43598. }
  43599. }
  43600. }
  43601. } else {
  43602. var firstChar = properties.firstChar;
  43603. widths = dict.get('Widths');
  43604. if (widths) {
  43605. j = firstChar;
  43606. for (i = 0, ii = widths.length; i < ii; i++) {
  43607. glyphsWidths[j++] = widths[i];
  43608. }
  43609. defaultWidth = (parseFloat(descriptor.get('MissingWidth')) || 0);
  43610. } else {
  43611. // Trying get the BaseFont metrics (see comment above).
  43612. var baseFontName = dict.get('BaseFont');
  43613. if (isName(baseFontName)) {
  43614. var metrics = this.getBaseFontMetrics(baseFontName.name);
  43615. glyphsWidths = this.buildCharCodeToWidth(metrics.widths,
  43616. properties);
  43617. defaultWidth = metrics.defaultWidth;
  43618. }
  43619. }
  43620. }
  43621. // Heuristic: detection of monospace font by checking all non-zero widths
  43622. var isMonospace = true;
  43623. var firstWidth = defaultWidth;
  43624. for (var glyph in glyphsWidths) {
  43625. var glyphWidth = glyphsWidths[glyph];
  43626. if (!glyphWidth) {
  43627. continue;
  43628. }
  43629. if (!firstWidth) {
  43630. firstWidth = glyphWidth;
  43631. continue;
  43632. }
  43633. if (firstWidth !== glyphWidth) {
  43634. isMonospace = false;
  43635. break;
  43636. }
  43637. }
  43638. if (isMonospace) {
  43639. properties.flags |= FontFlags.FixedPitch;
  43640. }
  43641. properties.defaultWidth = defaultWidth;
  43642. properties.widths = glyphsWidths;
  43643. properties.defaultVMetrics = defaultVMetrics;
  43644. properties.vmetrics = glyphsVMetrics;
  43645. },
  43646. isSerifFont: function PartialEvaluator_isSerifFont(baseFontName) {
  43647. // Simulating descriptor flags attribute
  43648. var fontNameWoStyle = baseFontName.split('-')[0];
  43649. return (fontNameWoStyle in getSerifFonts()) ||
  43650. (fontNameWoStyle.search(/serif/gi) !== -1);
  43651. },
  43652. getBaseFontMetrics: function PartialEvaluator_getBaseFontMetrics(name) {
  43653. var defaultWidth = 0;
  43654. var widths = [];
  43655. var monospace = false;
  43656. var stdFontMap = getStdFontMap();
  43657. var lookupName = (stdFontMap[name] || name);
  43658. var Metrics = getMetrics();
  43659. if (!(lookupName in Metrics)) {
  43660. // Use default fonts for looking up font metrics if the passed
  43661. // font is not a base font
  43662. if (this.isSerifFont(name)) {
  43663. lookupName = 'Times-Roman';
  43664. } else {
  43665. lookupName = 'Helvetica';
  43666. }
  43667. }
  43668. var glyphWidths = Metrics[lookupName];
  43669. if (isNum(glyphWidths)) {
  43670. defaultWidth = glyphWidths;
  43671. monospace = true;
  43672. } else {
  43673. widths = glyphWidths(); // expand lazy widths array
  43674. }
  43675. return {
  43676. defaultWidth: defaultWidth,
  43677. monospace: monospace,
  43678. widths: widths
  43679. };
  43680. },
  43681. buildCharCodeToWidth:
  43682. function PartialEvaluator_bulildCharCodeToWidth(widthsByGlyphName,
  43683. properties) {
  43684. var widths = Object.create(null);
  43685. var differences = properties.differences;
  43686. var encoding = properties.defaultEncoding;
  43687. for (var charCode = 0; charCode < 256; charCode++) {
  43688. if (charCode in differences &&
  43689. widthsByGlyphName[differences[charCode]]) {
  43690. widths[charCode] = widthsByGlyphName[differences[charCode]];
  43691. continue;
  43692. }
  43693. if (charCode in encoding && widthsByGlyphName[encoding[charCode]]) {
  43694. widths[charCode] = widthsByGlyphName[encoding[charCode]];
  43695. continue;
  43696. }
  43697. }
  43698. return widths;
  43699. },
  43700. preEvaluateFont: function PartialEvaluator_preEvaluateFont(dict, xref) {
  43701. var baseDict = dict;
  43702. var type = dict.get('Subtype');
  43703. assert(isName(type), 'invalid font Subtype');
  43704. var composite = false;
  43705. var uint8array;
  43706. if (type.name === 'Type0') {
  43707. // If font is a composite
  43708. // - get the descendant font
  43709. // - set the type according to the descendant font
  43710. // - get the FontDescriptor from the descendant font
  43711. var df = dict.get('DescendantFonts');
  43712. if (!df) {
  43713. error('Descendant fonts are not specified');
  43714. }
  43715. dict = (isArray(df) ? xref.fetchIfRef(df[0]) : df);
  43716. type = dict.get('Subtype');
  43717. assert(isName(type), 'invalid font Subtype');
  43718. composite = true;
  43719. }
  43720. var descriptor = dict.get('FontDescriptor');
  43721. if (descriptor) {
  43722. var hash = new MurmurHash3_64();
  43723. var encoding = baseDict.getRaw('Encoding');
  43724. if (isName(encoding)) {
  43725. hash.update(encoding.name);
  43726. } else if (isRef(encoding)) {
  43727. hash.update(encoding.num + '_' + encoding.gen);
  43728. } else if (isDict(encoding)) {
  43729. var keys = encoding.getKeys();
  43730. for (var i = 0, ii = keys.length; i < ii; i++) {
  43731. var entry = encoding.getRaw(keys[i]);
  43732. if (isName(entry)) {
  43733. hash.update(entry.name);
  43734. } else if (isRef(entry)) {
  43735. hash.update(entry.num + '_' + entry.gen);
  43736. } else if (isArray(entry)) { // 'Differences' entry.
  43737. // Ideally we should check the contents of the array, but to avoid
  43738. // parsing it here and then again in |extractDataStructures|,
  43739. // we only use the array length for now (fixes bug1157493.pdf).
  43740. hash.update(entry.length.toString());
  43741. }
  43742. }
  43743. }
  43744. var toUnicode = dict.get('ToUnicode') || baseDict.get('ToUnicode');
  43745. if (isStream(toUnicode)) {
  43746. var stream = toUnicode.str || toUnicode;
  43747. uint8array = stream.buffer ?
  43748. new Uint8Array(stream.buffer.buffer, 0, stream.bufferLength) :
  43749. new Uint8Array(stream.bytes.buffer,
  43750. stream.start, stream.end - stream.start);
  43751. hash.update(uint8array);
  43752. } else if (isName(toUnicode)) {
  43753. hash.update(toUnicode.name);
  43754. }
  43755. var widths = dict.get('Widths') || baseDict.get('Widths');
  43756. if (widths) {
  43757. uint8array = new Uint8Array(new Uint32Array(widths).buffer);
  43758. hash.update(uint8array);
  43759. }
  43760. }
  43761. return {
  43762. descriptor: descriptor,
  43763. dict: dict,
  43764. baseDict: baseDict,
  43765. composite: composite,
  43766. type: type.name,
  43767. hash: hash ? hash.hexdigest() : ''
  43768. };
  43769. },
  43770. translateFont: function PartialEvaluator_translateFont(preEvaluatedFont,
  43771. xref) {
  43772. var baseDict = preEvaluatedFont.baseDict;
  43773. var dict = preEvaluatedFont.dict;
  43774. var composite = preEvaluatedFont.composite;
  43775. var descriptor = preEvaluatedFont.descriptor;
  43776. var type = preEvaluatedFont.type;
  43777. var maxCharIndex = (composite ? 0xFFFF : 0xFF);
  43778. var cMapOptions = this.options.cMapOptions;
  43779. var properties;
  43780. if (!descriptor) {
  43781. if (type === 'Type3') {
  43782. // FontDescriptor is only required for Type3 fonts when the document
  43783. // is a tagged pdf. Create a barbebones one to get by.
  43784. descriptor = new Dict(null);
  43785. descriptor.set('FontName', Name.get(type));
  43786. descriptor.set('FontBBox', dict.get('FontBBox'));
  43787. } else {
  43788. // Before PDF 1.5 if the font was one of the base 14 fonts, having a
  43789. // FontDescriptor was not required.
  43790. // This case is here for compatibility.
  43791. var baseFontName = dict.get('BaseFont');
  43792. if (!isName(baseFontName)) {
  43793. error('Base font is not specified');
  43794. }
  43795. // Using base font name as a font name.
  43796. baseFontName = baseFontName.name.replace(/[,_]/g, '-');
  43797. var metrics = this.getBaseFontMetrics(baseFontName);
  43798. // Simulating descriptor flags attribute
  43799. var fontNameWoStyle = baseFontName.split('-')[0];
  43800. var flags =
  43801. (this.isSerifFont(fontNameWoStyle) ? FontFlags.Serif : 0) |
  43802. (metrics.monospace ? FontFlags.FixedPitch : 0) |
  43803. (getSymbolsFonts()[fontNameWoStyle] ? FontFlags.Symbolic :
  43804. FontFlags.Nonsymbolic);
  43805. properties = {
  43806. type: type,
  43807. name: baseFontName,
  43808. widths: metrics.widths,
  43809. defaultWidth: metrics.defaultWidth,
  43810. flags: flags,
  43811. firstChar: 0,
  43812. lastChar: maxCharIndex
  43813. };
  43814. return this.extractDataStructures(dict, dict, xref, properties).then(
  43815. function (properties) {
  43816. properties.widths = this.buildCharCodeToWidth(metrics.widths,
  43817. properties);
  43818. return new Font(baseFontName, null, properties);
  43819. }.bind(this));
  43820. }
  43821. }
  43822. // According to the spec if 'FontDescriptor' is declared, 'FirstChar',
  43823. // 'LastChar' and 'Widths' should exist too, but some PDF encoders seem
  43824. // to ignore this rule when a variant of a standart font is used.
  43825. // TODO Fill the width array depending on which of the base font this is
  43826. // a variant.
  43827. var firstChar = (dict.get('FirstChar') || 0);
  43828. var lastChar = (dict.get('LastChar') || maxCharIndex);
  43829. var fontName = descriptor.get('FontName');
  43830. var baseFont = dict.get('BaseFont');
  43831. // Some bad PDFs have a string as the font name.
  43832. if (isString(fontName)) {
  43833. fontName = Name.get(fontName);
  43834. }
  43835. if (isString(baseFont)) {
  43836. baseFont = Name.get(baseFont);
  43837. }
  43838. if (type !== 'Type3') {
  43839. var fontNameStr = fontName && fontName.name;
  43840. var baseFontStr = baseFont && baseFont.name;
  43841. if (fontNameStr !== baseFontStr) {
  43842. info('The FontDescriptor\'s FontName is "' + fontNameStr +
  43843. '" but should be the same as the Font\'s BaseFont "' +
  43844. baseFontStr + '"');
  43845. // Workaround for cases where e.g. fontNameStr = 'Arial' and
  43846. // baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
  43847. if (fontNameStr && baseFontStr &&
  43848. baseFontStr.indexOf(fontNameStr) === 0) {
  43849. fontName = baseFont;
  43850. }
  43851. }
  43852. }
  43853. fontName = (fontName || baseFont);
  43854. assert(isName(fontName), 'invalid font name');
  43855. var fontFile = descriptor.get('FontFile', 'FontFile2', 'FontFile3');
  43856. if (fontFile) {
  43857. if (fontFile.dict) {
  43858. var subtype = fontFile.dict.get('Subtype');
  43859. if (subtype) {
  43860. subtype = subtype.name;
  43861. }
  43862. var length1 = fontFile.dict.get('Length1');
  43863. var length2 = fontFile.dict.get('Length2');
  43864. var length3 = fontFile.dict.get('Length3');
  43865. }
  43866. }
  43867. properties = {
  43868. type: type,
  43869. name: fontName.name,
  43870. subtype: subtype,
  43871. file: fontFile,
  43872. length1: length1,
  43873. length2: length2,
  43874. length3: length3,
  43875. loadedName: baseDict.loadedName,
  43876. composite: composite,
  43877. wideChars: composite,
  43878. fixedPitch: false,
  43879. fontMatrix: (dict.get('FontMatrix') || FONT_IDENTITY_MATRIX),
  43880. firstChar: firstChar || 0,
  43881. lastChar: (lastChar || maxCharIndex),
  43882. bbox: descriptor.get('FontBBox'),
  43883. ascent: descriptor.get('Ascent'),
  43884. descent: descriptor.get('Descent'),
  43885. xHeight: descriptor.get('XHeight'),
  43886. capHeight: descriptor.get('CapHeight'),
  43887. flags: descriptor.get('Flags'),
  43888. italicAngle: descriptor.get('ItalicAngle'),
  43889. coded: false
  43890. };
  43891. var cMapPromise;
  43892. if (composite) {
  43893. var cidEncoding = baseDict.get('Encoding');
  43894. if (isName(cidEncoding)) {
  43895. properties.cidEncoding = cidEncoding.name;
  43896. }
  43897. cMapPromise = CMapFactory.create(cidEncoding, cMapOptions, null).then(
  43898. function (cMap) {
  43899. properties.cMap = cMap;
  43900. properties.vertical = properties.cMap.vertical;
  43901. });
  43902. } else {
  43903. cMapPromise = Promise.resolve(undefined);
  43904. }
  43905. return cMapPromise.then(function () {
  43906. return this.extractDataStructures(dict, baseDict, xref, properties);
  43907. }.bind(this)).then(function (properties) {
  43908. this.extractWidths(dict, xref, descriptor, properties);
  43909. if (type === 'Type3') {
  43910. properties.isType3Font = true;
  43911. }
  43912. return new Font(fontName.name, fontFile, properties);
  43913. }.bind(this));
  43914. }
  43915. };
  43916. return PartialEvaluator;
  43917. })();
  43918. var TranslatedFont = (function TranslatedFontClosure() {
  43919. function TranslatedFont(loadedName, font, dict) {
  43920. this.loadedName = loadedName;
  43921. this.font = font;
  43922. this.dict = dict;
  43923. this.type3Loaded = null;
  43924. this.sent = false;
  43925. }
  43926. TranslatedFont.prototype = {
  43927. send: function (handler) {
  43928. if (this.sent) {
  43929. return;
  43930. }
  43931. var fontData = this.font.exportData();
  43932. handler.send('commonobj', [
  43933. this.loadedName,
  43934. 'Font',
  43935. fontData
  43936. ]);
  43937. this.sent = true;
  43938. },
  43939. loadType3Data: function (evaluator, resources, parentOperatorList, task) {
  43940. assert(this.font.isType3Font);
  43941. if (this.type3Loaded) {
  43942. return this.type3Loaded;
  43943. }
  43944. var translatedFont = this.font;
  43945. var loadCharProcsPromise = Promise.resolve();
  43946. var charProcs = this.dict.get('CharProcs');
  43947. var fontResources = this.dict.get('Resources') || resources;
  43948. var charProcKeys = charProcs.getKeys();
  43949. var charProcOperatorList = Object.create(null);
  43950. for (var i = 0, n = charProcKeys.length; i < n; ++i) {
  43951. loadCharProcsPromise = loadCharProcsPromise.then(function (key) {
  43952. var glyphStream = charProcs.get(key);
  43953. var operatorList = new OperatorList();
  43954. return evaluator.getOperatorList(glyphStream, task, fontResources,
  43955. operatorList).then(function () {
  43956. charProcOperatorList[key] = operatorList.getIR();
  43957. // Add the dependencies to the parent operator list so they are
  43958. // resolved before sub operator list is executed synchronously.
  43959. parentOperatorList.addDependencies(operatorList.dependencies);
  43960. }, function (reason) {
  43961. warn('Type3 font resource \"' + key + '\" is not available');
  43962. var operatorList = new OperatorList();
  43963. charProcOperatorList[key] = operatorList.getIR();
  43964. });
  43965. }.bind(this, charProcKeys[i]));
  43966. }
  43967. this.type3Loaded = loadCharProcsPromise.then(function () {
  43968. translatedFont.charProcOperatorList = charProcOperatorList;
  43969. });
  43970. return this.type3Loaded;
  43971. }
  43972. };
  43973. return TranslatedFont;
  43974. })();
  43975. var OperatorList = (function OperatorListClosure() {
  43976. var CHUNK_SIZE = 1000;
  43977. var CHUNK_SIZE_ABOUT = CHUNK_SIZE - 5; // close to chunk size
  43978. function getTransfers(queue) {
  43979. var transfers = [];
  43980. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  43981. for (var i = 0, ii = queue.length; i < ii; i++) {
  43982. switch (fnArray[i]) {
  43983. case OPS.paintInlineImageXObject:
  43984. case OPS.paintInlineImageXObjectGroup:
  43985. case OPS.paintImageMaskXObject:
  43986. var arg = argsArray[i][0]; // first param in imgData
  43987. if (!arg.cached) {
  43988. transfers.push(arg.data.buffer);
  43989. }
  43990. break;
  43991. }
  43992. }
  43993. return transfers;
  43994. }
  43995. function OperatorList(intent, messageHandler, pageIndex) {
  43996. this.messageHandler = messageHandler;
  43997. this.fnArray = [];
  43998. this.argsArray = [];
  43999. this.dependencies = Object.create(null);
  44000. this._totalLength = 0;
  44001. this.pageIndex = pageIndex;
  44002. this.intent = intent;
  44003. }
  44004. OperatorList.prototype = {
  44005. get length() {
  44006. return this.argsArray.length;
  44007. },
  44008. /**
  44009. * @returns {number} The total length of the entire operator list,
  44010. * since `this.length === 0` after flushing.
  44011. */
  44012. get totalLength() {
  44013. return (this._totalLength + this.length);
  44014. },
  44015. addOp: function(fn, args) {
  44016. this.fnArray.push(fn);
  44017. this.argsArray.push(args);
  44018. if (this.messageHandler) {
  44019. if (this.fnArray.length >= CHUNK_SIZE) {
  44020. this.flush();
  44021. } else if (this.fnArray.length >= CHUNK_SIZE_ABOUT &&
  44022. (fn === OPS.restore || fn === OPS.endText)) {
  44023. // heuristic to flush on boundary of restore or endText
  44024. this.flush();
  44025. }
  44026. }
  44027. },
  44028. addDependency: function(dependency) {
  44029. if (dependency in this.dependencies) {
  44030. return;
  44031. }
  44032. this.dependencies[dependency] = true;
  44033. this.addOp(OPS.dependency, [dependency]);
  44034. },
  44035. addDependencies: function(dependencies) {
  44036. for (var key in dependencies) {
  44037. this.addDependency(key);
  44038. }
  44039. },
  44040. addOpList: function(opList) {
  44041. Util.extendObj(this.dependencies, opList.dependencies);
  44042. for (var i = 0, ii = opList.length; i < ii; i++) {
  44043. this.addOp(opList.fnArray[i], opList.argsArray[i]);
  44044. }
  44045. },
  44046. getIR: function() {
  44047. return {
  44048. fnArray: this.fnArray,
  44049. argsArray: this.argsArray,
  44050. length: this.length
  44051. };
  44052. },
  44053. flush: function(lastChunk) {
  44054. if (this.intent !== 'oplist') {
  44055. new QueueOptimizer().optimize(this);
  44056. }
  44057. var transfers = getTransfers(this);
  44058. var length = this.length;
  44059. this._totalLength += length;
  44060. this.messageHandler.send('RenderPageChunk', {
  44061. operatorList: {
  44062. fnArray: this.fnArray,
  44063. argsArray: this.argsArray,
  44064. lastChunk: lastChunk,
  44065. length: length
  44066. },
  44067. pageIndex: this.pageIndex,
  44068. intent: this.intent
  44069. }, transfers);
  44070. this.dependencies = Object.create(null);
  44071. this.fnArray.length = 0;
  44072. this.argsArray.length = 0;
  44073. }
  44074. };
  44075. return OperatorList;
  44076. })();
  44077. var StateManager = (function StateManagerClosure() {
  44078. function StateManager(initialState) {
  44079. this.state = initialState;
  44080. this.stateStack = [];
  44081. }
  44082. StateManager.prototype = {
  44083. save: function () {
  44084. var old = this.state;
  44085. this.stateStack.push(this.state);
  44086. this.state = old.clone();
  44087. },
  44088. restore: function () {
  44089. var prev = this.stateStack.pop();
  44090. if (prev) {
  44091. this.state = prev;
  44092. }
  44093. },
  44094. transform: function (args) {
  44095. this.state.ctm = Util.transform(this.state.ctm, args);
  44096. }
  44097. };
  44098. return StateManager;
  44099. })();
  44100. var TextState = (function TextStateClosure() {
  44101. function TextState() {
  44102. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44103. this.fontSize = 0;
  44104. this.font = null;
  44105. this.fontMatrix = FONT_IDENTITY_MATRIX;
  44106. this.textMatrix = IDENTITY_MATRIX.slice();
  44107. this.textLineMatrix = IDENTITY_MATRIX.slice();
  44108. this.charSpacing = 0;
  44109. this.wordSpacing = 0;
  44110. this.leading = 0;
  44111. this.textHScale = 1;
  44112. this.textRise = 0;
  44113. }
  44114. TextState.prototype = {
  44115. setTextMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  44116. var m = this.textMatrix;
  44117. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  44118. },
  44119. setTextLineMatrix: function TextState_setTextMatrix(a, b, c, d, e, f) {
  44120. var m = this.textLineMatrix;
  44121. m[0] = a; m[1] = b; m[2] = c; m[3] = d; m[4] = e; m[5] = f;
  44122. },
  44123. translateTextMatrix: function TextState_translateTextMatrix(x, y) {
  44124. var m = this.textMatrix;
  44125. m[4] = m[0] * x + m[2] * y + m[4];
  44126. m[5] = m[1] * x + m[3] * y + m[5];
  44127. },
  44128. translateTextLineMatrix: function TextState_translateTextMatrix(x, y) {
  44129. var m = this.textLineMatrix;
  44130. m[4] = m[0] * x + m[2] * y + m[4];
  44131. m[5] = m[1] * x + m[3] * y + m[5];
  44132. },
  44133. calcRenderMatrix: function TextState_calcRendeMatrix(ctm) {
  44134. // 9.4.4 Text Space Details
  44135. var tsm = [this.fontSize * this.textHScale, 0,
  44136. 0, this.fontSize,
  44137. 0, this.textRise];
  44138. return Util.transform(ctm, Util.transform(this.textMatrix, tsm));
  44139. },
  44140. carriageReturn: function TextState_carriageReturn() {
  44141. this.translateTextLineMatrix(0, -this.leading);
  44142. this.textMatrix = this.textLineMatrix.slice();
  44143. },
  44144. clone: function TextState_clone() {
  44145. var clone = Object.create(this);
  44146. clone.textMatrix = this.textMatrix.slice();
  44147. clone.textLineMatrix = this.textLineMatrix.slice();
  44148. clone.fontMatrix = this.fontMatrix.slice();
  44149. return clone;
  44150. }
  44151. };
  44152. return TextState;
  44153. })();
  44154. var EvalState = (function EvalStateClosure() {
  44155. function EvalState() {
  44156. this.ctm = new Float32Array(IDENTITY_MATRIX);
  44157. this.font = null;
  44158. this.textRenderingMode = TextRenderingMode.FILL;
  44159. this.fillColorSpace = ColorSpace.singletons.gray;
  44160. this.strokeColorSpace = ColorSpace.singletons.gray;
  44161. }
  44162. EvalState.prototype = {
  44163. clone: function CanvasExtraState_clone() {
  44164. return Object.create(this);
  44165. },
  44166. };
  44167. return EvalState;
  44168. })();
  44169. var EvaluatorPreprocessor = (function EvaluatorPreprocessorClosure() {
  44170. // Specifies properties for each command
  44171. //
  44172. // If variableArgs === true: [0, `numArgs`] expected
  44173. // If variableArgs === false: exactly `numArgs` expected
  44174. var getOPMap = getLookupTableFactory(function (t) {
  44175. // Graphic state
  44176. t['w'] = { id: OPS.setLineWidth, numArgs: 1, variableArgs: false };
  44177. t['J'] = { id: OPS.setLineCap, numArgs: 1, variableArgs: false };
  44178. t['j'] = { id: OPS.setLineJoin, numArgs: 1, variableArgs: false };
  44179. t['M'] = { id: OPS.setMiterLimit, numArgs: 1, variableArgs: false };
  44180. t['d'] = { id: OPS.setDash, numArgs: 2, variableArgs: false };
  44181. t['ri'] = { id: OPS.setRenderingIntent, numArgs: 1, variableArgs: false };
  44182. t['i'] = { id: OPS.setFlatness, numArgs: 1, variableArgs: false };
  44183. t['gs'] = { id: OPS.setGState, numArgs: 1, variableArgs: false };
  44184. t['q'] = { id: OPS.save, numArgs: 0, variableArgs: false };
  44185. t['Q'] = { id: OPS.restore, numArgs: 0, variableArgs: false };
  44186. t['cm'] = { id: OPS.transform, numArgs: 6, variableArgs: false };
  44187. // Path
  44188. t['m'] = { id: OPS.moveTo, numArgs: 2, variableArgs: false };
  44189. t['l'] = { id: OPS.lineTo, numArgs: 2, variableArgs: false };
  44190. t['c'] = { id: OPS.curveTo, numArgs: 6, variableArgs: false };
  44191. t['v'] = { id: OPS.curveTo2, numArgs: 4, variableArgs: false };
  44192. t['y'] = { id: OPS.curveTo3, numArgs: 4, variableArgs: false };
  44193. t['h'] = { id: OPS.closePath, numArgs: 0, variableArgs: false };
  44194. t['re'] = { id: OPS.rectangle, numArgs: 4, variableArgs: false };
  44195. t['S'] = { id: OPS.stroke, numArgs: 0, variableArgs: false };
  44196. t['s'] = { id: OPS.closeStroke, numArgs: 0, variableArgs: false };
  44197. t['f'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  44198. t['F'] = { id: OPS.fill, numArgs: 0, variableArgs: false };
  44199. t['f*'] = { id: OPS.eoFill, numArgs: 0, variableArgs: false };
  44200. t['B'] = { id: OPS.fillStroke, numArgs: 0, variableArgs: false };
  44201. t['B*'] = { id: OPS.eoFillStroke, numArgs: 0, variableArgs: false };
  44202. t['b'] = { id: OPS.closeFillStroke, numArgs: 0, variableArgs: false };
  44203. t['b*'] = { id: OPS.closeEOFillStroke, numArgs: 0, variableArgs: false };
  44204. t['n'] = { id: OPS.endPath, numArgs: 0, variableArgs: false };
  44205. // Clipping
  44206. t['W'] = { id: OPS.clip, numArgs: 0, variableArgs: false };
  44207. t['W*'] = { id: OPS.eoClip, numArgs: 0, variableArgs: false };
  44208. // Text
  44209. t['BT'] = { id: OPS.beginText, numArgs: 0, variableArgs: false };
  44210. t['ET'] = { id: OPS.endText, numArgs: 0, variableArgs: false };
  44211. t['Tc'] = { id: OPS.setCharSpacing, numArgs: 1, variableArgs: false };
  44212. t['Tw'] = { id: OPS.setWordSpacing, numArgs: 1, variableArgs: false };
  44213. t['Tz'] = { id: OPS.setHScale, numArgs: 1, variableArgs: false };
  44214. t['TL'] = { id: OPS.setLeading, numArgs: 1, variableArgs: false };
  44215. t['Tf'] = { id: OPS.setFont, numArgs: 2, variableArgs: false };
  44216. t['Tr'] = { id: OPS.setTextRenderingMode, numArgs: 1, variableArgs: false };
  44217. t['Ts'] = { id: OPS.setTextRise, numArgs: 1, variableArgs: false };
  44218. t['Td'] = { id: OPS.moveText, numArgs: 2, variableArgs: false };
  44219. t['TD'] = { id: OPS.setLeadingMoveText, numArgs: 2, variableArgs: false };
  44220. t['Tm'] = { id: OPS.setTextMatrix, numArgs: 6, variableArgs: false };
  44221. t['T*'] = { id: OPS.nextLine, numArgs: 0, variableArgs: false };
  44222. t['Tj'] = { id: OPS.showText, numArgs: 1, variableArgs: false };
  44223. t['TJ'] = { id: OPS.showSpacedText, numArgs: 1, variableArgs: false };
  44224. t['\''] = { id: OPS.nextLineShowText, numArgs: 1, variableArgs: false };
  44225. t['"'] = { id: OPS.nextLineSetSpacingShowText, numArgs: 3,
  44226. variableArgs: false };
  44227. // Type3 fonts
  44228. t['d0'] = { id: OPS.setCharWidth, numArgs: 2, variableArgs: false };
  44229. t['d1'] = { id: OPS.setCharWidthAndBounds, numArgs: 6,
  44230. variableArgs: false };
  44231. // Color
  44232. t['CS'] = { id: OPS.setStrokeColorSpace, numArgs: 1, variableArgs: false };
  44233. t['cs'] = { id: OPS.setFillColorSpace, numArgs: 1, variableArgs: false };
  44234. t['SC'] = { id: OPS.setStrokeColor, numArgs: 4, variableArgs: true };
  44235. t['SCN'] = { id: OPS.setStrokeColorN, numArgs: 33, variableArgs: true };
  44236. t['sc'] = { id: OPS.setFillColor, numArgs: 4, variableArgs: true };
  44237. t['scn'] = { id: OPS.setFillColorN, numArgs: 33, variableArgs: true };
  44238. t['G'] = { id: OPS.setStrokeGray, numArgs: 1, variableArgs: false };
  44239. t['g'] = { id: OPS.setFillGray, numArgs: 1, variableArgs: false };
  44240. t['RG'] = { id: OPS.setStrokeRGBColor, numArgs: 3, variableArgs: false };
  44241. t['rg'] = { id: OPS.setFillRGBColor, numArgs: 3, variableArgs: false };
  44242. t['K'] = { id: OPS.setStrokeCMYKColor, numArgs: 4, variableArgs: false };
  44243. t['k'] = { id: OPS.setFillCMYKColor, numArgs: 4, variableArgs: false };
  44244. // Shading
  44245. t['sh'] = { id: OPS.shadingFill, numArgs: 1, variableArgs: false };
  44246. // Images
  44247. t['BI'] = { id: OPS.beginInlineImage, numArgs: 0, variableArgs: false };
  44248. t['ID'] = { id: OPS.beginImageData, numArgs: 0, variableArgs: false };
  44249. t['EI'] = { id: OPS.endInlineImage, numArgs: 1, variableArgs: false };
  44250. // XObjects
  44251. t['Do'] = { id: OPS.paintXObject, numArgs: 1, variableArgs: false };
  44252. t['MP'] = { id: OPS.markPoint, numArgs: 1, variableArgs: false };
  44253. t['DP'] = { id: OPS.markPointProps, numArgs: 2, variableArgs: false };
  44254. t['BMC'] = { id: OPS.beginMarkedContent, numArgs: 1, variableArgs: false };
  44255. t['BDC'] = { id: OPS.beginMarkedContentProps, numArgs: 2,
  44256. variableArgs: false };
  44257. t['EMC'] = { id: OPS.endMarkedContent, numArgs: 0, variableArgs: false };
  44258. // Compatibility
  44259. t['BX'] = { id: OPS.beginCompat, numArgs: 0, variableArgs: false };
  44260. t['EX'] = { id: OPS.endCompat, numArgs: 0, variableArgs: false };
  44261. // (reserved partial commands for the lexer)
  44262. t['BM'] = null;
  44263. t['BD'] = null;
  44264. t['true'] = null;
  44265. t['fa'] = null;
  44266. t['fal'] = null;
  44267. t['fals'] = null;
  44268. t['false'] = null;
  44269. t['nu'] = null;
  44270. t['nul'] = null;
  44271. t['null'] = null;
  44272. });
  44273. function EvaluatorPreprocessor(stream, xref, stateManager) {
  44274. this.opMap = getOPMap();
  44275. // TODO(mduan): pass array of knownCommands rather than this.opMap
  44276. // dictionary
  44277. this.parser = new Parser(new Lexer(stream, this.opMap), false, xref);
  44278. this.stateManager = stateManager;
  44279. this.nonProcessedArgs = [];
  44280. }
  44281. EvaluatorPreprocessor.prototype = {
  44282. get savedStatesDepth() {
  44283. return this.stateManager.stateStack.length;
  44284. },
  44285. // |operation| is an object with two fields:
  44286. //
  44287. // - |fn| is an out param.
  44288. //
  44289. // - |args| is an inout param. On entry, it should have one of two values.
  44290. //
  44291. // - An empty array. This indicates that the caller is providing the
  44292. // array in which the args will be stored in. The caller should use
  44293. // this value if it can reuse a single array for each call to read().
  44294. //
  44295. // - |null|. This indicates that the caller needs this function to create
  44296. // the array in which any args are stored in. If there are zero args,
  44297. // this function will leave |operation.args| as |null| (thus avoiding
  44298. // allocations that would occur if we used an empty array to represent
  44299. // zero arguments). Otherwise, it will replace |null| with a new array
  44300. // containing the arguments. The caller should use this value if it
  44301. // cannot reuse an array for each call to read().
  44302. //
  44303. // These two modes are present because this function is very hot and so
  44304. // avoiding allocations where possible is worthwhile.
  44305. //
  44306. read: function EvaluatorPreprocessor_read(operation) {
  44307. var args = operation.args;
  44308. while (true) {
  44309. var obj = this.parser.getObj();
  44310. if (isCmd(obj)) {
  44311. var cmd = obj.cmd;
  44312. // Check that the command is valid
  44313. var opSpec = this.opMap[cmd];
  44314. if (!opSpec) {
  44315. warn('Unknown command "' + cmd + '"');
  44316. continue;
  44317. }
  44318. var fn = opSpec.id;
  44319. var numArgs = opSpec.numArgs;
  44320. var argsLength = args !== null ? args.length : 0;
  44321. if (!opSpec.variableArgs) {
  44322. // Postscript commands can be nested, e.g. /F2 /GS2 gs 5.711 Tf
  44323. if (argsLength !== numArgs) {
  44324. var nonProcessedArgs = this.nonProcessedArgs;
  44325. while (argsLength > numArgs) {
  44326. nonProcessedArgs.push(args.shift());
  44327. argsLength--;
  44328. }
  44329. while (argsLength < numArgs && nonProcessedArgs.length !== 0) {
  44330. if (!args) {
  44331. args = [];
  44332. }
  44333. args.unshift(nonProcessedArgs.pop());
  44334. argsLength++;
  44335. }
  44336. }
  44337. if (argsLength < numArgs) {
  44338. // If we receive too few args, it's not possible to possible
  44339. // to execute the command, so skip the command
  44340. info('Command ' + fn + ': because expected ' +
  44341. numArgs + ' args, but received ' + argsLength +
  44342. ' args; skipping');
  44343. args = null;
  44344. continue;
  44345. }
  44346. } else if (argsLength > numArgs) {
  44347. info('Command ' + fn + ': expected [0,' + numArgs +
  44348. '] args, but received ' + argsLength + ' args');
  44349. }
  44350. // TODO figure out how to type-check vararg functions
  44351. this.preprocessCommand(fn, args);
  44352. operation.fn = fn;
  44353. operation.args = args;
  44354. return true;
  44355. } else {
  44356. if (isEOF(obj)) {
  44357. return false; // no more commands
  44358. }
  44359. // argument
  44360. if (obj !== null) {
  44361. if (!args) {
  44362. args = [];
  44363. }
  44364. args.push(obj);
  44365. assert(args.length <= 33, 'Too many arguments');
  44366. }
  44367. }
  44368. }
  44369. },
  44370. preprocessCommand:
  44371. function EvaluatorPreprocessor_preprocessCommand(fn, args) {
  44372. switch (fn | 0) {
  44373. case OPS.save:
  44374. this.stateManager.save();
  44375. break;
  44376. case OPS.restore:
  44377. this.stateManager.restore();
  44378. break;
  44379. case OPS.transform:
  44380. this.stateManager.transform(args);
  44381. break;
  44382. }
  44383. }
  44384. };
  44385. return EvaluatorPreprocessor;
  44386. })();
  44387. var QueueOptimizer = (function QueueOptimizerClosure() {
  44388. function addState(parentState, pattern, fn) {
  44389. var state = parentState;
  44390. for (var i = 0, ii = pattern.length - 1; i < ii; i++) {
  44391. var item = pattern[i];
  44392. state = (state[item] || (state[item] = []));
  44393. }
  44394. state[pattern[pattern.length - 1]] = fn;
  44395. }
  44396. function handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44397. argsArray) {
  44398. // Handles special case of mainly LaTeX documents which use image masks to
  44399. // draw lines with the current fill style.
  44400. // 'count' groups of (save, transform, paintImageMaskXObject, restore)+
  44401. // have been found at iFirstSave.
  44402. var iFirstPIMXO = iFirstSave + 2;
  44403. for (var i = 0; i < count; i++) {
  44404. var arg = argsArray[iFirstPIMXO + 4 * i];
  44405. var imageMask = arg.length === 1 && arg[0];
  44406. if (imageMask && imageMask.width === 1 && imageMask.height === 1 &&
  44407. (!imageMask.data.length ||
  44408. (imageMask.data.length === 1 && imageMask.data[0] === 0))) {
  44409. fnArray[iFirstPIMXO + 4 * i] = OPS.paintSolidColorImageMask;
  44410. continue;
  44411. }
  44412. break;
  44413. }
  44414. return count - i;
  44415. }
  44416. var InitialState = [];
  44417. // This replaces (save, transform, paintInlineImageXObject, restore)+
  44418. // sequences with one |paintInlineImageXObjectGroup| operation.
  44419. addState(InitialState,
  44420. [OPS.save, OPS.transform, OPS.paintInlineImageXObject, OPS.restore],
  44421. function foundInlineImageGroup(context) {
  44422. var MIN_IMAGES_IN_INLINE_IMAGES_BLOCK = 10;
  44423. var MAX_IMAGES_IN_INLINE_IMAGES_BLOCK = 200;
  44424. var MAX_WIDTH = 1000;
  44425. var IMAGE_PADDING = 1;
  44426. var fnArray = context.fnArray, argsArray = context.argsArray;
  44427. var curr = context.iCurr;
  44428. var iFirstSave = curr - 3;
  44429. var iFirstTransform = curr - 2;
  44430. var iFirstPIIXO = curr - 1;
  44431. // Look for the quartets.
  44432. var i = iFirstSave + 4;
  44433. var ii = fnArray.length;
  44434. while (i + 3 < ii) {
  44435. if (fnArray[i] !== OPS.save ||
  44436. fnArray[i + 1] !== OPS.transform ||
  44437. fnArray[i + 2] !== OPS.paintInlineImageXObject ||
  44438. fnArray[i + 3] !== OPS.restore) {
  44439. break; // ops don't match
  44440. }
  44441. i += 4;
  44442. }
  44443. // At this point, i is the index of the first op past the last valid
  44444. // quartet.
  44445. var count = Math.min((i - iFirstSave) / 4,
  44446. MAX_IMAGES_IN_INLINE_IMAGES_BLOCK);
  44447. if (count < MIN_IMAGES_IN_INLINE_IMAGES_BLOCK) {
  44448. return i;
  44449. }
  44450. // assuming that heights of those image is too small (~1 pixel)
  44451. // packing as much as possible by lines
  44452. var maxX = 0;
  44453. var map = [], maxLineHeight = 0;
  44454. var currentX = IMAGE_PADDING, currentY = IMAGE_PADDING;
  44455. var q;
  44456. for (q = 0; q < count; q++) {
  44457. var transform = argsArray[iFirstTransform + (q << 2)];
  44458. var img = argsArray[iFirstPIIXO + (q << 2)][0];
  44459. if (currentX + img.width > MAX_WIDTH) {
  44460. // starting new line
  44461. maxX = Math.max(maxX, currentX);
  44462. currentY += maxLineHeight + 2 * IMAGE_PADDING;
  44463. currentX = 0;
  44464. maxLineHeight = 0;
  44465. }
  44466. map.push({
  44467. transform: transform,
  44468. x: currentX, y: currentY,
  44469. w: img.width, h: img.height
  44470. });
  44471. currentX += img.width + 2 * IMAGE_PADDING;
  44472. maxLineHeight = Math.max(maxLineHeight, img.height);
  44473. }
  44474. var imgWidth = Math.max(maxX, currentX) + IMAGE_PADDING;
  44475. var imgHeight = currentY + maxLineHeight + IMAGE_PADDING;
  44476. var imgData = new Uint8Array(imgWidth * imgHeight * 4);
  44477. var imgRowSize = imgWidth << 2;
  44478. for (q = 0; q < count; q++) {
  44479. var data = argsArray[iFirstPIIXO + (q << 2)][0].data;
  44480. // Copy image by lines and extends pixels into padding.
  44481. var rowSize = map[q].w << 2;
  44482. var dataOffset = 0;
  44483. var offset = (map[q].x + map[q].y * imgWidth) << 2;
  44484. imgData.set(data.subarray(0, rowSize), offset - imgRowSize);
  44485. for (var k = 0, kk = map[q].h; k < kk; k++) {
  44486. imgData.set(data.subarray(dataOffset, dataOffset + rowSize), offset);
  44487. dataOffset += rowSize;
  44488. offset += imgRowSize;
  44489. }
  44490. imgData.set(data.subarray(dataOffset - rowSize, dataOffset), offset);
  44491. while (offset >= 0) {
  44492. data[offset - 4] = data[offset];
  44493. data[offset - 3] = data[offset + 1];
  44494. data[offset - 2] = data[offset + 2];
  44495. data[offset - 1] = data[offset + 3];
  44496. data[offset + rowSize] = data[offset + rowSize - 4];
  44497. data[offset + rowSize + 1] = data[offset + rowSize - 3];
  44498. data[offset + rowSize + 2] = data[offset + rowSize - 2];
  44499. data[offset + rowSize + 3] = data[offset + rowSize - 1];
  44500. offset -= imgRowSize;
  44501. }
  44502. }
  44503. // Replace queue items.
  44504. fnArray.splice(iFirstSave, count * 4, OPS.paintInlineImageXObjectGroup);
  44505. argsArray.splice(iFirstSave, count * 4,
  44506. [{ width: imgWidth, height: imgHeight, kind: ImageKind.RGBA_32BPP,
  44507. data: imgData }, map]);
  44508. return iFirstSave + 1;
  44509. });
  44510. // This replaces (save, transform, paintImageMaskXObject, restore)+
  44511. // sequences with one |paintImageMaskXObjectGroup| or one
  44512. // |paintImageMaskXObjectRepeat| operation.
  44513. addState(InitialState,
  44514. [OPS.save, OPS.transform, OPS.paintImageMaskXObject, OPS.restore],
  44515. function foundImageMaskGroup(context) {
  44516. var MIN_IMAGES_IN_MASKS_BLOCK = 10;
  44517. var MAX_IMAGES_IN_MASKS_BLOCK = 100;
  44518. var MAX_SAME_IMAGES_IN_MASKS_BLOCK = 1000;
  44519. var fnArray = context.fnArray, argsArray = context.argsArray;
  44520. var curr = context.iCurr;
  44521. var iFirstSave = curr - 3;
  44522. var iFirstTransform = curr - 2;
  44523. var iFirstPIMXO = curr - 1;
  44524. // Look for the quartets.
  44525. var i = iFirstSave + 4;
  44526. var ii = fnArray.length;
  44527. while (i + 3 < ii) {
  44528. if (fnArray[i] !== OPS.save ||
  44529. fnArray[i + 1] !== OPS.transform ||
  44530. fnArray[i + 2] !== OPS.paintImageMaskXObject ||
  44531. fnArray[i + 3] !== OPS.restore) {
  44532. break; // ops don't match
  44533. }
  44534. i += 4;
  44535. }
  44536. // At this point, i is the index of the first op past the last valid
  44537. // quartet.
  44538. var count = (i - iFirstSave) / 4;
  44539. count = handlePaintSolidColorImageMask(iFirstSave, count, fnArray,
  44540. argsArray);
  44541. if (count < MIN_IMAGES_IN_MASKS_BLOCK) {
  44542. return i;
  44543. }
  44544. var q;
  44545. var isSameImage = false;
  44546. var iTransform, transformArgs;
  44547. var firstPIMXOArg0 = argsArray[iFirstPIMXO][0];
  44548. if (argsArray[iFirstTransform][1] === 0 &&
  44549. argsArray[iFirstTransform][2] === 0) {
  44550. isSameImage = true;
  44551. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44552. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44553. iTransform = iFirstTransform + 4;
  44554. var iPIMXO = iFirstPIMXO + 4;
  44555. for (q = 1; q < count; q++, iTransform += 4, iPIMXO += 4) {
  44556. transformArgs = argsArray[iTransform];
  44557. if (argsArray[iPIMXO][0] !== firstPIMXOArg0 ||
  44558. transformArgs[0] !== firstTransformArg0 ||
  44559. transformArgs[1] !== 0 ||
  44560. transformArgs[2] !== 0 ||
  44561. transformArgs[3] !== firstTransformArg3) {
  44562. if (q < MIN_IMAGES_IN_MASKS_BLOCK) {
  44563. isSameImage = false;
  44564. } else {
  44565. count = q;
  44566. }
  44567. break; // different image or transform
  44568. }
  44569. }
  44570. }
  44571. if (isSameImage) {
  44572. count = Math.min(count, MAX_SAME_IMAGES_IN_MASKS_BLOCK);
  44573. var positions = new Float32Array(count * 2);
  44574. iTransform = iFirstTransform;
  44575. for (q = 0; q < count; q++, iTransform += 4) {
  44576. transformArgs = argsArray[iTransform];
  44577. positions[(q << 1)] = transformArgs[4];
  44578. positions[(q << 1) + 1] = transformArgs[5];
  44579. }
  44580. // Replace queue items.
  44581. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectRepeat);
  44582. argsArray.splice(iFirstSave, count * 4,
  44583. [firstPIMXOArg0, firstTransformArg0, firstTransformArg3, positions]);
  44584. } else {
  44585. count = Math.min(count, MAX_IMAGES_IN_MASKS_BLOCK);
  44586. var images = [];
  44587. for (q = 0; q < count; q++) {
  44588. transformArgs = argsArray[iFirstTransform + (q << 2)];
  44589. var maskParams = argsArray[iFirstPIMXO + (q << 2)][0];
  44590. images.push({ data: maskParams.data, width: maskParams.width,
  44591. height: maskParams.height,
  44592. transform: transformArgs });
  44593. }
  44594. // Replace queue items.
  44595. fnArray.splice(iFirstSave, count * 4, OPS.paintImageMaskXObjectGroup);
  44596. argsArray.splice(iFirstSave, count * 4, [images]);
  44597. }
  44598. return iFirstSave + 1;
  44599. });
  44600. // This replaces (save, transform, paintImageXObject, restore)+ sequences
  44601. // with one paintImageXObjectRepeat operation, if the |transform| and
  44602. // |paintImageXObjectRepeat| ops are appropriate.
  44603. addState(InitialState,
  44604. [OPS.save, OPS.transform, OPS.paintImageXObject, OPS.restore],
  44605. function (context) {
  44606. var MIN_IMAGES_IN_BLOCK = 3;
  44607. var MAX_IMAGES_IN_BLOCK = 1000;
  44608. var fnArray = context.fnArray, argsArray = context.argsArray;
  44609. var curr = context.iCurr;
  44610. var iFirstSave = curr - 3;
  44611. var iFirstTransform = curr - 2;
  44612. var iFirstPIXO = curr - 1;
  44613. var iFirstRestore = curr;
  44614. if (argsArray[iFirstTransform][1] !== 0 ||
  44615. argsArray[iFirstTransform][2] !== 0) {
  44616. return iFirstRestore + 1; // transform has the wrong form
  44617. }
  44618. // Look for the quartets.
  44619. var firstPIXOArg0 = argsArray[iFirstPIXO][0];
  44620. var firstTransformArg0 = argsArray[iFirstTransform][0];
  44621. var firstTransformArg3 = argsArray[iFirstTransform][3];
  44622. var i = iFirstSave + 4;
  44623. var ii = fnArray.length;
  44624. while (i + 3 < ii) {
  44625. if (fnArray[i] !== OPS.save ||
  44626. fnArray[i + 1] !== OPS.transform ||
  44627. fnArray[i + 2] !== OPS.paintImageXObject ||
  44628. fnArray[i + 3] !== OPS.restore) {
  44629. break; // ops don't match
  44630. }
  44631. if (argsArray[i + 1][0] !== firstTransformArg0 ||
  44632. argsArray[i + 1][1] !== 0 ||
  44633. argsArray[i + 1][2] !== 0 ||
  44634. argsArray[i + 1][3] !== firstTransformArg3) {
  44635. break; // transforms don't match
  44636. }
  44637. if (argsArray[i + 2][0] !== firstPIXOArg0) {
  44638. break; // images don't match
  44639. }
  44640. i += 4;
  44641. }
  44642. // At this point, i is the index of the first op past the last valid
  44643. // quartet.
  44644. var count = Math.min((i - iFirstSave) / 4, MAX_IMAGES_IN_BLOCK);
  44645. if (count < MIN_IMAGES_IN_BLOCK) {
  44646. return i;
  44647. }
  44648. // Extract the (x,y) positions from all of the matching transforms.
  44649. var positions = new Float32Array(count * 2);
  44650. var iTransform = iFirstTransform;
  44651. for (var q = 0; q < count; q++, iTransform += 4) {
  44652. var transformArgs = argsArray[iTransform];
  44653. positions[(q << 1)] = transformArgs[4];
  44654. positions[(q << 1) + 1] = transformArgs[5];
  44655. }
  44656. // Replace queue items.
  44657. var args = [firstPIXOArg0, firstTransformArg0, firstTransformArg3,
  44658. positions];
  44659. fnArray.splice(iFirstSave, count * 4, OPS.paintImageXObjectRepeat);
  44660. argsArray.splice(iFirstSave, count * 4, args);
  44661. return iFirstSave + 1;
  44662. });
  44663. // This replaces (beginText, setFont, setTextMatrix, showText, endText)+
  44664. // sequences with (beginText, setFont, (setTextMatrix, showText)+, endText)+
  44665. // sequences, if the font for each one is the same.
  44666. addState(InitialState,
  44667. [OPS.beginText, OPS.setFont, OPS.setTextMatrix, OPS.showText, OPS.endText],
  44668. function (context) {
  44669. var MIN_CHARS_IN_BLOCK = 3;
  44670. var MAX_CHARS_IN_BLOCK = 1000;
  44671. var fnArray = context.fnArray, argsArray = context.argsArray;
  44672. var curr = context.iCurr;
  44673. var iFirstBeginText = curr - 4;
  44674. var iFirstSetFont = curr - 3;
  44675. var iFirstSetTextMatrix = curr - 2;
  44676. var iFirstShowText = curr - 1;
  44677. var iFirstEndText = curr;
  44678. // Look for the quintets.
  44679. var firstSetFontArg0 = argsArray[iFirstSetFont][0];
  44680. var firstSetFontArg1 = argsArray[iFirstSetFont][1];
  44681. var i = iFirstBeginText + 5;
  44682. var ii = fnArray.length;
  44683. while (i + 4 < ii) {
  44684. if (fnArray[i] !== OPS.beginText ||
  44685. fnArray[i + 1] !== OPS.setFont ||
  44686. fnArray[i + 2] !== OPS.setTextMatrix ||
  44687. fnArray[i + 3] !== OPS.showText ||
  44688. fnArray[i + 4] !== OPS.endText) {
  44689. break; // ops don't match
  44690. }
  44691. if (argsArray[i + 1][0] !== firstSetFontArg0 ||
  44692. argsArray[i + 1][1] !== firstSetFontArg1) {
  44693. break; // fonts don't match
  44694. }
  44695. i += 5;
  44696. }
  44697. // At this point, i is the index of the first op past the last valid
  44698. // quintet.
  44699. var count = Math.min(((i - iFirstBeginText) / 5), MAX_CHARS_IN_BLOCK);
  44700. if (count < MIN_CHARS_IN_BLOCK) {
  44701. return i;
  44702. }
  44703. // If the preceding quintet is (<something>, setFont, setTextMatrix,
  44704. // showText, endText), include that as well. (E.g. <something> might be
  44705. // |dependency|.)
  44706. var iFirst = iFirstBeginText;
  44707. if (iFirstBeginText >= 4 &&
  44708. fnArray[iFirstBeginText - 4] === fnArray[iFirstSetFont] &&
  44709. fnArray[iFirstBeginText - 3] === fnArray[iFirstSetTextMatrix] &&
  44710. fnArray[iFirstBeginText - 2] === fnArray[iFirstShowText] &&
  44711. fnArray[iFirstBeginText - 1] === fnArray[iFirstEndText] &&
  44712. argsArray[iFirstBeginText - 4][0] === firstSetFontArg0 &&
  44713. argsArray[iFirstBeginText - 4][1] === firstSetFontArg1) {
  44714. count++;
  44715. iFirst -= 5;
  44716. }
  44717. // Remove (endText, beginText, setFont) trios.
  44718. var iEndText = iFirst + 4;
  44719. for (var q = 1; q < count; q++) {
  44720. fnArray.splice(iEndText, 3);
  44721. argsArray.splice(iEndText, 3);
  44722. iEndText += 2;
  44723. }
  44724. return iEndText + 1;
  44725. });
  44726. function QueueOptimizer() {}
  44727. QueueOptimizer.prototype = {
  44728. optimize: function QueueOptimizer_optimize(queue) {
  44729. var fnArray = queue.fnArray, argsArray = queue.argsArray;
  44730. var context = {
  44731. iCurr: 0,
  44732. fnArray: fnArray,
  44733. argsArray: argsArray
  44734. };
  44735. var state;
  44736. var i = 0, ii = fnArray.length;
  44737. while (i < ii) {
  44738. state = (state || InitialState)[fnArray[i]];
  44739. if (typeof state === 'function') { // we found some handler
  44740. context.iCurr = i;
  44741. // state() returns the index of the first non-matching op (if we
  44742. // didn't match) or the first op past the modified ops (if we did
  44743. // match and replace).
  44744. i = state(context);
  44745. state = undefined; // reset the state machine
  44746. ii = context.fnArray.length;
  44747. } else {
  44748. i++;
  44749. }
  44750. }
  44751. }
  44752. };
  44753. return QueueOptimizer;
  44754. })();
  44755. exports.OperatorList = OperatorList;
  44756. exports.PartialEvaluator = PartialEvaluator;
  44757. }));
  44758. (function (root, factory) {
  44759. {
  44760. factory((root.pdfjsCoreAnnotation = {}), root.pdfjsSharedUtil,
  44761. root.pdfjsCorePrimitives, root.pdfjsCoreStream, root.pdfjsCoreColorSpace,
  44762. root.pdfjsCoreObj, root.pdfjsCoreEvaluator);
  44763. }
  44764. }(this, function (exports, sharedUtil, corePrimitives, coreStream,
  44765. coreColorSpace, coreObj, coreEvaluator) {
  44766. var AnnotationBorderStyleType = sharedUtil.AnnotationBorderStyleType;
  44767. var AnnotationFlag = sharedUtil.AnnotationFlag;
  44768. var AnnotationType = sharedUtil.AnnotationType;
  44769. var OPS = sharedUtil.OPS;
  44770. var Util = sharedUtil.Util;
  44771. var isArray = sharedUtil.isArray;
  44772. var isInt = sharedUtil.isInt;
  44773. var isValidUrl = sharedUtil.isValidUrl;
  44774. var stringToBytes = sharedUtil.stringToBytes;
  44775. var stringToPDFString = sharedUtil.stringToPDFString;
  44776. var stringToUTF8String = sharedUtil.stringToUTF8String;
  44777. var warn = sharedUtil.warn;
  44778. var Dict = corePrimitives.Dict;
  44779. var isDict = corePrimitives.isDict;
  44780. var isName = corePrimitives.isName;
  44781. var Stream = coreStream.Stream;
  44782. var ColorSpace = coreColorSpace.ColorSpace;
  44783. var ObjectLoader = coreObj.ObjectLoader;
  44784. var FileSpec = coreObj.FileSpec;
  44785. var OperatorList = coreEvaluator.OperatorList;
  44786. /**
  44787. * @class
  44788. * @alias AnnotationFactory
  44789. */
  44790. function AnnotationFactory() {}
  44791. AnnotationFactory.prototype = /** @lends AnnotationFactory.prototype */ {
  44792. /**
  44793. * @param {XRef} xref
  44794. * @param {Object} ref
  44795. * @returns {Annotation}
  44796. */
  44797. create: function AnnotationFactory_create(xref, ref) {
  44798. var dict = xref.fetchIfRef(ref);
  44799. if (!isDict(dict)) {
  44800. return;
  44801. }
  44802. // Determine the annotation's subtype.
  44803. var subtype = dict.get('Subtype');
  44804. subtype = isName(subtype) ? subtype.name : '';
  44805. // Return the right annotation object based on the subtype and field type.
  44806. var parameters = {
  44807. xref: xref,
  44808. dict: dict,
  44809. ref: ref
  44810. };
  44811. switch (subtype) {
  44812. case 'Link':
  44813. return new LinkAnnotation(parameters);
  44814. case 'Text':
  44815. return new TextAnnotation(parameters);
  44816. case 'Widget':
  44817. var fieldType = Util.getInheritableProperty(dict, 'FT');
  44818. if (isName(fieldType) && fieldType.name === 'Tx') {
  44819. return new TextWidgetAnnotation(parameters);
  44820. }
  44821. return new WidgetAnnotation(parameters);
  44822. case 'Popup':
  44823. return new PopupAnnotation(parameters);
  44824. case 'Highlight':
  44825. return new HighlightAnnotation(parameters);
  44826. case 'Underline':
  44827. return new UnderlineAnnotation(parameters);
  44828. case 'Squiggly':
  44829. return new SquigglyAnnotation(parameters);
  44830. case 'StrikeOut':
  44831. return new StrikeOutAnnotation(parameters);
  44832. case 'FileAttachment':
  44833. return new FileAttachmentAnnotation(parameters);
  44834. default:
  44835. warn('Unimplemented annotation type "' + subtype + '", ' +
  44836. 'falling back to base annotation');
  44837. return new Annotation(parameters);
  44838. }
  44839. }
  44840. };
  44841. var Annotation = (function AnnotationClosure() {
  44842. // 12.5.5: Algorithm: Appearance streams
  44843. function getTransformMatrix(rect, bbox, matrix) {
  44844. var bounds = Util.getAxialAlignedBoundingBox(bbox, matrix);
  44845. var minX = bounds[0];
  44846. var minY = bounds[1];
  44847. var maxX = bounds[2];
  44848. var maxY = bounds[3];
  44849. if (minX === maxX || minY === maxY) {
  44850. // From real-life file, bbox was [0, 0, 0, 0]. In this case,
  44851. // just apply the transform for rect
  44852. return [1, 0, 0, 1, rect[0], rect[1]];
  44853. }
  44854. var xRatio = (rect[2] - rect[0]) / (maxX - minX);
  44855. var yRatio = (rect[3] - rect[1]) / (maxY - minY);
  44856. return [
  44857. xRatio,
  44858. 0,
  44859. 0,
  44860. yRatio,
  44861. rect[0] - minX * xRatio,
  44862. rect[1] - minY * yRatio
  44863. ];
  44864. }
  44865. function getDefaultAppearance(dict) {
  44866. var appearanceState = dict.get('AP');
  44867. if (!isDict(appearanceState)) {
  44868. return;
  44869. }
  44870. var appearance;
  44871. var appearances = appearanceState.get('N');
  44872. if (isDict(appearances)) {
  44873. var as = dict.get('AS');
  44874. if (as && appearances.has(as.name)) {
  44875. appearance = appearances.get(as.name);
  44876. }
  44877. } else {
  44878. appearance = appearances;
  44879. }
  44880. return appearance;
  44881. }
  44882. function Annotation(params) {
  44883. var dict = params.dict;
  44884. this.setFlags(dict.get('F'));
  44885. this.setRectangle(dict.getArray('Rect'));
  44886. this.setColor(dict.get('C'));
  44887. this.setBorderStyle(dict);
  44888. this.appearance = getDefaultAppearance(dict);
  44889. // Expose public properties using a data object.
  44890. this.data = {};
  44891. this.data.id = params.ref.toString();
  44892. this.data.subtype = dict.get('Subtype').name;
  44893. this.data.annotationFlags = this.flags;
  44894. this.data.rect = this.rectangle;
  44895. this.data.color = this.color;
  44896. this.data.borderStyle = this.borderStyle;
  44897. this.data.hasAppearance = !!this.appearance;
  44898. }
  44899. Annotation.prototype = {
  44900. /**
  44901. * @return {boolean}
  44902. */
  44903. get viewable() {
  44904. if (this.flags) {
  44905. return !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44906. !this.hasFlag(AnnotationFlag.HIDDEN) &&
  44907. !this.hasFlag(AnnotationFlag.NOVIEW);
  44908. }
  44909. return true;
  44910. },
  44911. /**
  44912. * @return {boolean}
  44913. */
  44914. get printable() {
  44915. if (this.flags) {
  44916. return this.hasFlag(AnnotationFlag.PRINT) &&
  44917. !this.hasFlag(AnnotationFlag.INVISIBLE) &&
  44918. !this.hasFlag(AnnotationFlag.HIDDEN);
  44919. }
  44920. return false;
  44921. },
  44922. /**
  44923. * Set the flags.
  44924. *
  44925. * @public
  44926. * @memberof Annotation
  44927. * @param {number} flags - Unsigned 32-bit integer specifying annotation
  44928. * characteristics
  44929. * @see {@link shared/util.js}
  44930. */
  44931. setFlags: function Annotation_setFlags(flags) {
  44932. if (isInt(flags)) {
  44933. this.flags = flags;
  44934. } else {
  44935. this.flags = 0;
  44936. }
  44937. },
  44938. /**
  44939. * Check if a provided flag is set.
  44940. *
  44941. * @public
  44942. * @memberof Annotation
  44943. * @param {number} flag - Hexadecimal representation for an annotation
  44944. * characteristic
  44945. * @return {boolean}
  44946. * @see {@link shared/util.js}
  44947. */
  44948. hasFlag: function Annotation_hasFlag(flag) {
  44949. if (this.flags) {
  44950. return (this.flags & flag) > 0;
  44951. }
  44952. return false;
  44953. },
  44954. /**
  44955. * Set the rectangle.
  44956. *
  44957. * @public
  44958. * @memberof Annotation
  44959. * @param {Array} rectangle - The rectangle array with exactly four entries
  44960. */
  44961. setRectangle: function Annotation_setRectangle(rectangle) {
  44962. if (isArray(rectangle) && rectangle.length === 4) {
  44963. this.rectangle = Util.normalizeRect(rectangle);
  44964. } else {
  44965. this.rectangle = [0, 0, 0, 0];
  44966. }
  44967. },
  44968. /**
  44969. * Set the color and take care of color space conversion.
  44970. *
  44971. * @public
  44972. * @memberof Annotation
  44973. * @param {Array} color - The color array containing either 0
  44974. * (transparent), 1 (grayscale), 3 (RGB) or
  44975. * 4 (CMYK) elements
  44976. */
  44977. setColor: function Annotation_setColor(color) {
  44978. var rgbColor = new Uint8Array(3); // Black in RGB color space (default)
  44979. if (!isArray(color)) {
  44980. this.color = rgbColor;
  44981. return;
  44982. }
  44983. switch (color.length) {
  44984. case 0: // Transparent, which we indicate with a null value
  44985. this.color = null;
  44986. break;
  44987. case 1: // Convert grayscale to RGB
  44988. ColorSpace.singletons.gray.getRgbItem(color, 0, rgbColor, 0);
  44989. this.color = rgbColor;
  44990. break;
  44991. case 3: // Convert RGB percentages to RGB
  44992. ColorSpace.singletons.rgb.getRgbItem(color, 0, rgbColor, 0);
  44993. this.color = rgbColor;
  44994. break;
  44995. case 4: // Convert CMYK to RGB
  44996. ColorSpace.singletons.cmyk.getRgbItem(color, 0, rgbColor, 0);
  44997. this.color = rgbColor;
  44998. break;
  44999. default:
  45000. this.color = rgbColor;
  45001. break;
  45002. }
  45003. },
  45004. /**
  45005. * Set the border style (as AnnotationBorderStyle object).
  45006. *
  45007. * @public
  45008. * @memberof Annotation
  45009. * @param {Dict} borderStyle - The border style dictionary
  45010. */
  45011. setBorderStyle: function Annotation_setBorderStyle(borderStyle) {
  45012. this.borderStyle = new AnnotationBorderStyle();
  45013. if (!isDict(borderStyle)) {
  45014. return;
  45015. }
  45016. if (borderStyle.has('BS')) {
  45017. var dict = borderStyle.get('BS');
  45018. var dictType;
  45019. if (!dict.has('Type') || (isName(dictType = dict.get('Type')) &&
  45020. dictType.name === 'Border')) {
  45021. this.borderStyle.setWidth(dict.get('W'));
  45022. this.borderStyle.setStyle(dict.get('S'));
  45023. this.borderStyle.setDashArray(dict.get('D'));
  45024. }
  45025. } else if (borderStyle.has('Border')) {
  45026. var array = borderStyle.get('Border');
  45027. if (isArray(array) && array.length >= 3) {
  45028. this.borderStyle.setHorizontalCornerRadius(array[0]);
  45029. this.borderStyle.setVerticalCornerRadius(array[1]);
  45030. this.borderStyle.setWidth(array[2]);
  45031. if (array.length === 4) { // Dash array available
  45032. this.borderStyle.setDashArray(array[3]);
  45033. }
  45034. }
  45035. } else {
  45036. // There are no border entries in the dictionary. According to the
  45037. // specification, we should draw a solid border of width 1 in that
  45038. // case, but Adobe Reader did not implement that part of the
  45039. // specification and instead draws no border at all, so we do the same.
  45040. // See also https://github.com/mozilla/pdf.js/issues/6179.
  45041. this.borderStyle.setWidth(0);
  45042. }
  45043. },
  45044. /**
  45045. * Prepare the annotation for working with a popup in the display layer.
  45046. *
  45047. * @private
  45048. * @memberof Annotation
  45049. * @param {Dict} dict - The annotation's data dictionary
  45050. */
  45051. _preparePopup: function Annotation_preparePopup(dict) {
  45052. if (!dict.has('C')) {
  45053. // Fall back to the default background color.
  45054. this.data.color = null;
  45055. }
  45056. this.data.hasPopup = dict.has('Popup');
  45057. this.data.title = stringToPDFString(dict.get('T') || '');
  45058. this.data.contents = stringToPDFString(dict.get('Contents') || '');
  45059. },
  45060. loadResources: function Annotation_loadResources(keys) {
  45061. return new Promise(function (resolve, reject) {
  45062. this.appearance.dict.getAsync('Resources').then(function (resources) {
  45063. if (!resources) {
  45064. resolve();
  45065. return;
  45066. }
  45067. var objectLoader = new ObjectLoader(resources.map,
  45068. keys,
  45069. resources.xref);
  45070. objectLoader.load().then(function() {
  45071. resolve(resources);
  45072. }, reject);
  45073. }, reject);
  45074. }.bind(this));
  45075. },
  45076. getOperatorList: function Annotation_getOperatorList(evaluator, task) {
  45077. if (!this.appearance) {
  45078. return Promise.resolve(new OperatorList());
  45079. }
  45080. var data = this.data;
  45081. var appearanceDict = this.appearance.dict;
  45082. var resourcesPromise = this.loadResources([
  45083. 'ExtGState',
  45084. 'ColorSpace',
  45085. 'Pattern',
  45086. 'Shading',
  45087. 'XObject',
  45088. 'Font'
  45089. // ProcSet
  45090. // Properties
  45091. ]);
  45092. var bbox = appearanceDict.get('BBox') || [0, 0, 1, 1];
  45093. var matrix = appearanceDict.get('Matrix') || [1, 0, 0, 1, 0 ,0];
  45094. var transform = getTransformMatrix(data.rect, bbox, matrix);
  45095. var self = this;
  45096. return resourcesPromise.then(function(resources) {
  45097. var opList = new OperatorList();
  45098. opList.addOp(OPS.beginAnnotation, [data.rect, transform, matrix]);
  45099. return evaluator.getOperatorList(self.appearance, task,
  45100. resources, opList).
  45101. then(function () {
  45102. opList.addOp(OPS.endAnnotation, []);
  45103. self.appearance.reset();
  45104. return opList;
  45105. });
  45106. });
  45107. }
  45108. };
  45109. Annotation.appendToOperatorList = function Annotation_appendToOperatorList(
  45110. annotations, opList, partialEvaluator, task, intent) {
  45111. var annotationPromises = [];
  45112. for (var i = 0, n = annotations.length; i < n; ++i) {
  45113. if ((intent === 'display' && annotations[i].viewable) ||
  45114. (intent === 'print' && annotations[i].printable)) {
  45115. annotationPromises.push(
  45116. annotations[i].getOperatorList(partialEvaluator, task));
  45117. }
  45118. }
  45119. return Promise.all(annotationPromises).then(function(operatorLists) {
  45120. opList.addOp(OPS.beginAnnotations, []);
  45121. for (var i = 0, n = operatorLists.length; i < n; ++i) {
  45122. opList.addOpList(operatorLists[i]);
  45123. }
  45124. opList.addOp(OPS.endAnnotations, []);
  45125. });
  45126. };
  45127. return Annotation;
  45128. })();
  45129. /**
  45130. * Contains all data regarding an annotation's border style.
  45131. *
  45132. * @class
  45133. */
  45134. var AnnotationBorderStyle = (function AnnotationBorderStyleClosure() {
  45135. /**
  45136. * @constructor
  45137. * @private
  45138. */
  45139. function AnnotationBorderStyle() {
  45140. this.width = 1;
  45141. this.style = AnnotationBorderStyleType.SOLID;
  45142. this.dashArray = [3];
  45143. this.horizontalCornerRadius = 0;
  45144. this.verticalCornerRadius = 0;
  45145. }
  45146. AnnotationBorderStyle.prototype = {
  45147. /**
  45148. * Set the width.
  45149. *
  45150. * @public
  45151. * @memberof AnnotationBorderStyle
  45152. * @param {integer} width - The width
  45153. */
  45154. setWidth: function AnnotationBorderStyle_setWidth(width) {
  45155. if (width === (width | 0)) {
  45156. this.width = width;
  45157. }
  45158. },
  45159. /**
  45160. * Set the style.
  45161. *
  45162. * @public
  45163. * @memberof AnnotationBorderStyle
  45164. * @param {Object} style - The style object
  45165. * @see {@link shared/util.js}
  45166. */
  45167. setStyle: function AnnotationBorderStyle_setStyle(style) {
  45168. if (!style) {
  45169. return;
  45170. }
  45171. switch (style.name) {
  45172. case 'S':
  45173. this.style = AnnotationBorderStyleType.SOLID;
  45174. break;
  45175. case 'D':
  45176. this.style = AnnotationBorderStyleType.DASHED;
  45177. break;
  45178. case 'B':
  45179. this.style = AnnotationBorderStyleType.BEVELED;
  45180. break;
  45181. case 'I':
  45182. this.style = AnnotationBorderStyleType.INSET;
  45183. break;
  45184. case 'U':
  45185. this.style = AnnotationBorderStyleType.UNDERLINE;
  45186. break;
  45187. default:
  45188. break;
  45189. }
  45190. },
  45191. /**
  45192. * Set the dash array.
  45193. *
  45194. * @public
  45195. * @memberof AnnotationBorderStyle
  45196. * @param {Array} dashArray - The dash array with at least one element
  45197. */
  45198. setDashArray: function AnnotationBorderStyle_setDashArray(dashArray) {
  45199. // We validate the dash array, but we do not use it because CSS does not
  45200. // allow us to change spacing of dashes. For more information, visit
  45201. // http://www.w3.org/TR/css3-background/#the-border-style.
  45202. if (isArray(dashArray) && dashArray.length > 0) {
  45203. // According to the PDF specification: the elements in a dashArray
  45204. // shall be numbers that are nonnegative and not all equal to zero.
  45205. var isValid = true;
  45206. var allZeros = true;
  45207. for (var i = 0, len = dashArray.length; i < len; i++) {
  45208. var element = dashArray[i];
  45209. var validNumber = (+element >= 0);
  45210. if (!validNumber) {
  45211. isValid = false;
  45212. break;
  45213. } else if (element > 0) {
  45214. allZeros = false;
  45215. }
  45216. }
  45217. if (isValid && !allZeros) {
  45218. this.dashArray = dashArray;
  45219. } else {
  45220. this.width = 0; // Adobe behavior when the array is invalid.
  45221. }
  45222. } else if (dashArray) {
  45223. this.width = 0; // Adobe behavior when the array is invalid.
  45224. }
  45225. },
  45226. /**
  45227. * Set the horizontal corner radius (from a Border dictionary).
  45228. *
  45229. * @public
  45230. * @memberof AnnotationBorderStyle
  45231. * @param {integer} radius - The horizontal corner radius
  45232. */
  45233. setHorizontalCornerRadius:
  45234. function AnnotationBorderStyle_setHorizontalCornerRadius(radius) {
  45235. if (radius === (radius | 0)) {
  45236. this.horizontalCornerRadius = radius;
  45237. }
  45238. },
  45239. /**
  45240. * Set the vertical corner radius (from a Border dictionary).
  45241. *
  45242. * @public
  45243. * @memberof AnnotationBorderStyle
  45244. * @param {integer} radius - The vertical corner radius
  45245. */
  45246. setVerticalCornerRadius:
  45247. function AnnotationBorderStyle_setVerticalCornerRadius(radius) {
  45248. if (radius === (radius | 0)) {
  45249. this.verticalCornerRadius = radius;
  45250. }
  45251. }
  45252. };
  45253. return AnnotationBorderStyle;
  45254. })();
  45255. var WidgetAnnotation = (function WidgetAnnotationClosure() {
  45256. function WidgetAnnotation(params) {
  45257. Annotation.call(this, params);
  45258. var dict = params.dict;
  45259. var data = this.data;
  45260. data.annotationType = AnnotationType.WIDGET;
  45261. data.fieldValue = stringToPDFString(
  45262. Util.getInheritableProperty(dict, 'V') || '');
  45263. data.alternativeText = stringToPDFString(dict.get('TU') || '');
  45264. data.defaultAppearance = Util.getInheritableProperty(dict, 'DA') || '';
  45265. var fieldType = Util.getInheritableProperty(dict, 'FT');
  45266. data.fieldType = isName(fieldType) ? fieldType.name : '';
  45267. data.fieldFlags = Util.getInheritableProperty(dict, 'Ff') || 0;
  45268. this.fieldResources = Util.getInheritableProperty(dict, 'DR') || Dict.empty;
  45269. // Hide unsupported Widget signatures.
  45270. if (data.fieldType === 'Sig') {
  45271. warn('unimplemented annotation type: Widget signature');
  45272. this.setFlags(AnnotationFlag.HIDDEN);
  45273. }
  45274. // Building the full field name by collecting the field and
  45275. // its ancestors 'T' data and joining them using '.'.
  45276. var fieldName = [];
  45277. var namedItem = dict;
  45278. var ref = params.ref;
  45279. while (namedItem) {
  45280. var parent = namedItem.get('Parent');
  45281. var parentRef = namedItem.getRaw('Parent');
  45282. var name = namedItem.get('T');
  45283. if (name) {
  45284. fieldName.unshift(stringToPDFString(name));
  45285. } else if (parent && ref) {
  45286. // The field name is absent, that means more than one field
  45287. // with the same name may exist. Replacing the empty name
  45288. // with the '`' plus index in the parent's 'Kids' array.
  45289. // This is not in the PDF spec but necessary to id the
  45290. // the input controls.
  45291. var kids = parent.get('Kids');
  45292. var j, jj;
  45293. for (j = 0, jj = kids.length; j < jj; j++) {
  45294. var kidRef = kids[j];
  45295. if (kidRef.num === ref.num && kidRef.gen === ref.gen) {
  45296. break;
  45297. }
  45298. }
  45299. fieldName.unshift('`' + j);
  45300. }
  45301. namedItem = parent;
  45302. ref = parentRef;
  45303. }
  45304. data.fullName = fieldName.join('.');
  45305. }
  45306. Util.inherit(WidgetAnnotation, Annotation, {});
  45307. return WidgetAnnotation;
  45308. })();
  45309. var TextWidgetAnnotation = (function TextWidgetAnnotationClosure() {
  45310. function TextWidgetAnnotation(params) {
  45311. WidgetAnnotation.call(this, params);
  45312. this.data.textAlignment = Util.getInheritableProperty(params.dict, 'Q');
  45313. }
  45314. Util.inherit(TextWidgetAnnotation, WidgetAnnotation, {
  45315. getOperatorList: function TextWidgetAnnotation_getOperatorList(evaluator,
  45316. task) {
  45317. if (this.appearance) {
  45318. return Annotation.prototype.getOperatorList.call(this, evaluator, task);
  45319. }
  45320. var opList = new OperatorList();
  45321. var data = this.data;
  45322. // Even if there is an appearance stream, ignore it. This is the
  45323. // behaviour used by Adobe Reader.
  45324. if (!data.defaultAppearance) {
  45325. return Promise.resolve(opList);
  45326. }
  45327. var stream = new Stream(stringToBytes(data.defaultAppearance));
  45328. return evaluator.getOperatorList(stream, task,
  45329. this.fieldResources, opList).
  45330. then(function () {
  45331. return opList;
  45332. });
  45333. }
  45334. });
  45335. return TextWidgetAnnotation;
  45336. })();
  45337. var TextAnnotation = (function TextAnnotationClosure() {
  45338. var DEFAULT_ICON_SIZE = 22; // px
  45339. function TextAnnotation(parameters) {
  45340. Annotation.call(this, parameters);
  45341. this.data.annotationType = AnnotationType.TEXT;
  45342. if (this.data.hasAppearance) {
  45343. this.data.name = 'NoIcon';
  45344. } else {
  45345. this.data.rect[1] = this.data.rect[3] - DEFAULT_ICON_SIZE;
  45346. this.data.rect[2] = this.data.rect[0] + DEFAULT_ICON_SIZE;
  45347. this.data.name = parameters.dict.has('Name') ?
  45348. parameters.dict.get('Name').name : 'Note';
  45349. }
  45350. this._preparePopup(parameters.dict);
  45351. }
  45352. Util.inherit(TextAnnotation, Annotation, {});
  45353. return TextAnnotation;
  45354. })();
  45355. var LinkAnnotation = (function LinkAnnotationClosure() {
  45356. function LinkAnnotation(params) {
  45357. Annotation.call(this, params);
  45358. var dict = params.dict;
  45359. var data = this.data;
  45360. data.annotationType = AnnotationType.LINK;
  45361. var action = dict.get('A');
  45362. if (action && isDict(action)) {
  45363. var linkType = action.get('S').name;
  45364. if (linkType === 'URI') {
  45365. var url = action.get('URI');
  45366. if (isName(url)) {
  45367. // Some bad PDFs do not put parentheses around relative URLs.
  45368. url = '/' + url.name;
  45369. } else if (url) {
  45370. url = addDefaultProtocolToUrl(url);
  45371. }
  45372. // TODO: pdf spec mentions urls can be relative to a Base
  45373. // entry in the dictionary.
  45374. if (!isValidUrl(url, false)) {
  45375. url = '';
  45376. }
  45377. // According to ISO 32000-1:2008, section 12.6.4.7,
  45378. // URI should to be encoded in 7-bit ASCII.
  45379. // Some bad PDFs may have URIs in UTF-8 encoding, see Bugzilla 1122280.
  45380. try {
  45381. data.url = stringToUTF8String(url);
  45382. } catch (e) {
  45383. // Fall back to a simple copy.
  45384. data.url = url;
  45385. }
  45386. } else if (linkType === 'GoTo') {
  45387. data.dest = action.get('D');
  45388. } else if (linkType === 'GoToR') {
  45389. var urlDict = action.get('F');
  45390. if (isDict(urlDict)) {
  45391. // We assume that the 'url' is a Filspec dictionary
  45392. // and fetch the url without checking any further
  45393. url = urlDict.get('F') || '';
  45394. }
  45395. // TODO: pdf reference says that GoToR
  45396. // can also have 'NewWindow' attribute
  45397. if (!isValidUrl(url, false)) {
  45398. url = '';
  45399. }
  45400. data.url = url;
  45401. data.dest = action.get('D');
  45402. } else if (linkType === 'Named') {
  45403. data.action = action.get('N').name;
  45404. } else {
  45405. warn('unrecognized link type: ' + linkType);
  45406. }
  45407. } else if (dict.has('Dest')) {
  45408. // simple destination link
  45409. var dest = dict.get('Dest');
  45410. data.dest = isName(dest) ? dest.name : dest;
  45411. }
  45412. }
  45413. // Lets URLs beginning with 'www.' default to using the 'http://' protocol.
  45414. function addDefaultProtocolToUrl(url) {
  45415. if (url && url.indexOf('www.') === 0) {
  45416. return ('http://' + url);
  45417. }
  45418. return url;
  45419. }
  45420. Util.inherit(LinkAnnotation, Annotation, {});
  45421. return LinkAnnotation;
  45422. })();
  45423. var PopupAnnotation = (function PopupAnnotationClosure() {
  45424. function PopupAnnotation(parameters) {
  45425. Annotation.call(this, parameters);
  45426. this.data.annotationType = AnnotationType.POPUP;
  45427. var dict = parameters.dict;
  45428. var parentItem = dict.get('Parent');
  45429. if (!parentItem) {
  45430. warn('Popup annotation has a missing or invalid parent annotation.');
  45431. return;
  45432. }
  45433. this.data.parentId = dict.getRaw('Parent').toString();
  45434. this.data.title = stringToPDFString(parentItem.get('T') || '');
  45435. this.data.contents = stringToPDFString(parentItem.get('Contents') || '');
  45436. if (!parentItem.has('C')) {
  45437. // Fall back to the default background color.
  45438. this.data.color = null;
  45439. } else {
  45440. this.setColor(parentItem.get('C'));
  45441. this.data.color = this.color;
  45442. }
  45443. }
  45444. Util.inherit(PopupAnnotation, Annotation, {});
  45445. return PopupAnnotation;
  45446. })();
  45447. var HighlightAnnotation = (function HighlightAnnotationClosure() {
  45448. function HighlightAnnotation(parameters) {
  45449. Annotation.call(this, parameters);
  45450. this.data.annotationType = AnnotationType.HIGHLIGHT;
  45451. this._preparePopup(parameters.dict);
  45452. // PDF viewers completely ignore any border styles.
  45453. this.data.borderStyle.setWidth(0);
  45454. }
  45455. Util.inherit(HighlightAnnotation, Annotation, {});
  45456. return HighlightAnnotation;
  45457. })();
  45458. var UnderlineAnnotation = (function UnderlineAnnotationClosure() {
  45459. function UnderlineAnnotation(parameters) {
  45460. Annotation.call(this, parameters);
  45461. this.data.annotationType = AnnotationType.UNDERLINE;
  45462. this._preparePopup(parameters.dict);
  45463. // PDF viewers completely ignore any border styles.
  45464. this.data.borderStyle.setWidth(0);
  45465. }
  45466. Util.inherit(UnderlineAnnotation, Annotation, {});
  45467. return UnderlineAnnotation;
  45468. })();
  45469. var SquigglyAnnotation = (function SquigglyAnnotationClosure() {
  45470. function SquigglyAnnotation(parameters) {
  45471. Annotation.call(this, parameters);
  45472. this.data.annotationType = AnnotationType.SQUIGGLY;
  45473. this._preparePopup(parameters.dict);
  45474. // PDF viewers completely ignore any border styles.
  45475. this.data.borderStyle.setWidth(0);
  45476. }
  45477. Util.inherit(SquigglyAnnotation, Annotation, {});
  45478. return SquigglyAnnotation;
  45479. })();
  45480. var StrikeOutAnnotation = (function StrikeOutAnnotationClosure() {
  45481. function StrikeOutAnnotation(parameters) {
  45482. Annotation.call(this, parameters);
  45483. this.data.annotationType = AnnotationType.STRIKEOUT;
  45484. this._preparePopup(parameters.dict);
  45485. // PDF viewers completely ignore any border styles.
  45486. this.data.borderStyle.setWidth(0);
  45487. }
  45488. Util.inherit(StrikeOutAnnotation, Annotation, {});
  45489. return StrikeOutAnnotation;
  45490. })();
  45491. var FileAttachmentAnnotation = (function FileAttachmentAnnotationClosure() {
  45492. function FileAttachmentAnnotation(parameters) {
  45493. Annotation.call(this, parameters);
  45494. var file = new FileSpec(parameters.dict.get('FS'), parameters.xref);
  45495. this.data.annotationType = AnnotationType.FILEATTACHMENT;
  45496. this.data.file = file.serializable;
  45497. this._preparePopup(parameters.dict);
  45498. }
  45499. Util.inherit(FileAttachmentAnnotation, Annotation, {});
  45500. return FileAttachmentAnnotation;
  45501. })();
  45502. exports.Annotation = Annotation;
  45503. exports.AnnotationBorderStyle = AnnotationBorderStyle;
  45504. exports.AnnotationFactory = AnnotationFactory;
  45505. }));
  45506. (function (root, factory) {
  45507. {
  45508. factory((root.pdfjsCoreDocument = {}), root.pdfjsSharedUtil,
  45509. root.pdfjsCorePrimitives, root.pdfjsCoreStream,
  45510. root.pdfjsCoreObj, root.pdfjsCoreParser, root.pdfjsCoreCrypto,
  45511. root.pdfjsCoreEvaluator, root.pdfjsCoreAnnotation);
  45512. }
  45513. }(this, function (exports, sharedUtil, corePrimitives, coreStream, coreObj,
  45514. coreParser, coreCrypto, coreEvaluator, coreAnnotation) {
  45515. var MissingDataException = sharedUtil.MissingDataException;
  45516. var Util = sharedUtil.Util;
  45517. var assert = sharedUtil.assert;
  45518. var error = sharedUtil.error;
  45519. var info = sharedUtil.info;
  45520. var isArray = sharedUtil.isArray;
  45521. var isArrayBuffer = sharedUtil.isArrayBuffer;
  45522. var isString = sharedUtil.isString;
  45523. var shadow = sharedUtil.shadow;
  45524. var stringToBytes = sharedUtil.stringToBytes;
  45525. var stringToPDFString = sharedUtil.stringToPDFString;
  45526. var warn = sharedUtil.warn;
  45527. var Dict = corePrimitives.Dict;
  45528. var isDict = corePrimitives.isDict;
  45529. var isName = corePrimitives.isName;
  45530. var isStream = corePrimitives.isStream;
  45531. var NullStream = coreStream.NullStream;
  45532. var Stream = coreStream.Stream;
  45533. var StreamsSequenceStream = coreStream.StreamsSequenceStream;
  45534. var Catalog = coreObj.Catalog;
  45535. var ObjectLoader = coreObj.ObjectLoader;
  45536. var XRef = coreObj.XRef;
  45537. var Lexer = coreParser.Lexer;
  45538. var Linearization = coreParser.Linearization;
  45539. var calculateMD5 = coreCrypto.calculateMD5;
  45540. var OperatorList = coreEvaluator.OperatorList;
  45541. var PartialEvaluator = coreEvaluator.PartialEvaluator;
  45542. var Annotation = coreAnnotation.Annotation;
  45543. var AnnotationFactory = coreAnnotation.AnnotationFactory;
  45544. var Page = (function PageClosure() {
  45545. var LETTER_SIZE_MEDIABOX = [0, 0, 612, 792];
  45546. function Page(pdfManager, xref, pageIndex, pageDict, ref, fontCache) {
  45547. this.pdfManager = pdfManager;
  45548. this.pageIndex = pageIndex;
  45549. this.pageDict = pageDict;
  45550. this.xref = xref;
  45551. this.ref = ref;
  45552. this.fontCache = fontCache;
  45553. this.idCounters = {
  45554. obj: 0
  45555. };
  45556. this.evaluatorOptions = pdfManager.evaluatorOptions;
  45557. this.resourcesPromise = null;
  45558. }
  45559. Page.prototype = {
  45560. getPageProp: function Page_getPageProp(key) {
  45561. return this.pageDict.get(key);
  45562. },
  45563. getInheritedPageProp: function Page_getInheritedPageProp(key) {
  45564. var dict = this.pageDict, valueArray = null, loopCount = 0;
  45565. var MAX_LOOP_COUNT = 100;
  45566. // Always walk up the entire parent chain, to be able to find
  45567. // e.g. \Resources placed on multiple levels of the tree.
  45568. while (dict) {
  45569. var value = dict.get(key);
  45570. if (value) {
  45571. if (!valueArray) {
  45572. valueArray = [];
  45573. }
  45574. valueArray.push(value);
  45575. }
  45576. if (++loopCount > MAX_LOOP_COUNT) {
  45577. warn('Page_getInheritedPageProp: maximum loop count exceeded.');
  45578. break;
  45579. }
  45580. dict = dict.get('Parent');
  45581. }
  45582. if (!valueArray) {
  45583. return Dict.empty;
  45584. }
  45585. if (valueArray.length === 1 || !isDict(valueArray[0]) ||
  45586. loopCount > MAX_LOOP_COUNT) {
  45587. return valueArray[0];
  45588. }
  45589. return Dict.merge(this.xref, valueArray);
  45590. },
  45591. get content() {
  45592. return this.getPageProp('Contents');
  45593. },
  45594. get resources() {
  45595. // For robustness: The spec states that a \Resources entry has to be
  45596. // present, but can be empty. Some document omit it still, in this case
  45597. // we return an empty dictionary.
  45598. return shadow(this, 'resources', this.getInheritedPageProp('Resources'));
  45599. },
  45600. get mediaBox() {
  45601. var obj = this.getInheritedPageProp('MediaBox');
  45602. // Reset invalid media box to letter size.
  45603. if (!isArray(obj) || obj.length !== 4) {
  45604. obj = LETTER_SIZE_MEDIABOX;
  45605. }
  45606. return shadow(this, 'mediaBox', obj);
  45607. },
  45608. get view() {
  45609. var mediaBox = this.mediaBox;
  45610. var cropBox = this.getInheritedPageProp('CropBox');
  45611. if (!isArray(cropBox) || cropBox.length !== 4) {
  45612. return shadow(this, 'view', mediaBox);
  45613. }
  45614. // From the spec, 6th ed., p.963:
  45615. // "The crop, bleed, trim, and art boxes should not ordinarily
  45616. // extend beyond the boundaries of the media box. If they do, they are
  45617. // effectively reduced to their intersection with the media box."
  45618. cropBox = Util.intersect(cropBox, mediaBox);
  45619. if (!cropBox) {
  45620. return shadow(this, 'view', mediaBox);
  45621. }
  45622. return shadow(this, 'view', cropBox);
  45623. },
  45624. get rotate() {
  45625. var rotate = this.getInheritedPageProp('Rotate') || 0;
  45626. // Normalize rotation so it's a multiple of 90 and between 0 and 270
  45627. if (rotate % 90 !== 0) {
  45628. rotate = 0;
  45629. } else if (rotate >= 360) {
  45630. rotate = rotate % 360;
  45631. } else if (rotate < 0) {
  45632. // The spec doesn't cover negatives, assume its counterclockwise
  45633. // rotation. The following is the other implementation of modulo.
  45634. rotate = ((rotate % 360) + 360) % 360;
  45635. }
  45636. return shadow(this, 'rotate', rotate);
  45637. },
  45638. getContentStream: function Page_getContentStream() {
  45639. var content = this.content;
  45640. var stream;
  45641. if (isArray(content)) {
  45642. // fetching items
  45643. var xref = this.xref;
  45644. var i, n = content.length;
  45645. var streams = [];
  45646. for (i = 0; i < n; ++i) {
  45647. streams.push(xref.fetchIfRef(content[i]));
  45648. }
  45649. stream = new StreamsSequenceStream(streams);
  45650. } else if (isStream(content)) {
  45651. stream = content;
  45652. } else {
  45653. // replacing non-existent page content with empty one
  45654. stream = new NullStream();
  45655. }
  45656. return stream;
  45657. },
  45658. loadResources: function Page_loadResources(keys) {
  45659. if (!this.resourcesPromise) {
  45660. // TODO: add async getInheritedPageProp and remove this.
  45661. this.resourcesPromise = this.pdfManager.ensure(this, 'resources');
  45662. }
  45663. return this.resourcesPromise.then(function resourceSuccess() {
  45664. var objectLoader = new ObjectLoader(this.resources.map,
  45665. keys,
  45666. this.xref);
  45667. return objectLoader.load();
  45668. }.bind(this));
  45669. },
  45670. getOperatorList: function Page_getOperatorList(handler, task, intent) {
  45671. var self = this;
  45672. var pdfManager = this.pdfManager;
  45673. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45674. []);
  45675. var resourcesPromise = this.loadResources([
  45676. 'ExtGState',
  45677. 'ColorSpace',
  45678. 'Pattern',
  45679. 'Shading',
  45680. 'XObject',
  45681. 'Font'
  45682. // ProcSet
  45683. // Properties
  45684. ]);
  45685. var partialEvaluator = new PartialEvaluator(pdfManager, this.xref,
  45686. handler, this.pageIndex,
  45687. 'p' + this.pageIndex + '_',
  45688. this.idCounters,
  45689. this.fontCache,
  45690. this.evaluatorOptions);
  45691. var dataPromises = Promise.all([contentStreamPromise, resourcesPromise]);
  45692. var pageListPromise = dataPromises.then(function(data) {
  45693. var contentStream = data[0];
  45694. var opList = new OperatorList(intent, handler, self.pageIndex);
  45695. handler.send('StartRenderPage', {
  45696. transparency: partialEvaluator.hasBlendModes(self.resources),
  45697. pageIndex: self.pageIndex,
  45698. intent: intent
  45699. });
  45700. return partialEvaluator.getOperatorList(contentStream, task,
  45701. self.resources, opList).then(function () {
  45702. return opList;
  45703. });
  45704. });
  45705. var annotationsPromise = pdfManager.ensure(this, 'annotations');
  45706. return Promise.all([pageListPromise, annotationsPromise]).then(
  45707. function(datas) {
  45708. var pageOpList = datas[0];
  45709. var annotations = datas[1];
  45710. if (annotations.length === 0) {
  45711. pageOpList.flush(true);
  45712. return pageOpList;
  45713. }
  45714. var annotationsReadyPromise = Annotation.appendToOperatorList(
  45715. annotations, pageOpList, partialEvaluator, task, intent);
  45716. return annotationsReadyPromise.then(function () {
  45717. pageOpList.flush(true);
  45718. return pageOpList;
  45719. });
  45720. });
  45721. },
  45722. extractTextContent: function Page_extractTextContent(task,
  45723. normalizeWhitespace) {
  45724. var handler = {
  45725. on: function nullHandlerOn() {},
  45726. send: function nullHandlerSend() {}
  45727. };
  45728. var self = this;
  45729. var pdfManager = this.pdfManager;
  45730. var contentStreamPromise = pdfManager.ensure(this, 'getContentStream',
  45731. []);
  45732. var resourcesPromise = this.loadResources([
  45733. 'ExtGState',
  45734. 'XObject',
  45735. 'Font'
  45736. ]);
  45737. var dataPromises = Promise.all([contentStreamPromise,
  45738. resourcesPromise]);
  45739. return dataPromises.then(function(data) {
  45740. var contentStream = data[0];
  45741. var partialEvaluator = new PartialEvaluator(pdfManager, self.xref,
  45742. handler, self.pageIndex,
  45743. 'p' + self.pageIndex + '_',
  45744. self.idCounters,
  45745. self.fontCache,
  45746. self.evaluatorOptions);
  45747. return partialEvaluator.getTextContent(contentStream,
  45748. task,
  45749. self.resources,
  45750. /* stateManager = */ null,
  45751. normalizeWhitespace);
  45752. });
  45753. },
  45754. getAnnotationsData: function Page_getAnnotationsData(intent) {
  45755. var annotations = this.annotations;
  45756. var annotationsData = [];
  45757. for (var i = 0, n = annotations.length; i < n; ++i) {
  45758. if (intent) {
  45759. if (!(intent === 'display' && annotations[i].viewable) &&
  45760. !(intent === 'print' && annotations[i].printable)) {
  45761. continue;
  45762. }
  45763. }
  45764. annotationsData.push(annotations[i].data);
  45765. }
  45766. return annotationsData;
  45767. },
  45768. get annotations() {
  45769. var annotations = [];
  45770. var annotationRefs = this.getInheritedPageProp('Annots') || [];
  45771. var annotationFactory = new AnnotationFactory();
  45772. for (var i = 0, n = annotationRefs.length; i < n; ++i) {
  45773. var annotationRef = annotationRefs[i];
  45774. var annotation = annotationFactory.create(this.xref, annotationRef);
  45775. if (annotation) {
  45776. annotations.push(annotation);
  45777. }
  45778. }
  45779. return shadow(this, 'annotations', annotations);
  45780. }
  45781. };
  45782. return Page;
  45783. })();
  45784. /**
  45785. * The `PDFDocument` holds all the data of the PDF file. Compared to the
  45786. * `PDFDoc`, this one doesn't have any job management code.
  45787. * Right now there exists one PDFDocument on the main thread + one object
  45788. * for each worker. If there is no worker support enabled, there are two
  45789. * `PDFDocument` objects on the main thread created.
  45790. */
  45791. var PDFDocument = (function PDFDocumentClosure() {
  45792. var FINGERPRINT_FIRST_BYTES = 1024;
  45793. var EMPTY_FINGERPRINT = '\x00\x00\x00\x00\x00\x00\x00' +
  45794. '\x00\x00\x00\x00\x00\x00\x00\x00\x00';
  45795. function PDFDocument(pdfManager, arg, password) {
  45796. if (isStream(arg)) {
  45797. init.call(this, pdfManager, arg, password);
  45798. } else if (isArrayBuffer(arg)) {
  45799. init.call(this, pdfManager, new Stream(arg), password);
  45800. } else {
  45801. error('PDFDocument: Unknown argument type');
  45802. }
  45803. }
  45804. function init(pdfManager, stream, password) {
  45805. assert(stream.length > 0, 'stream must have data');
  45806. this.pdfManager = pdfManager;
  45807. this.stream = stream;
  45808. var xref = new XRef(this.stream, password, pdfManager);
  45809. this.xref = xref;
  45810. }
  45811. function find(stream, needle, limit, backwards) {
  45812. var pos = stream.pos;
  45813. var end = stream.end;
  45814. var strBuf = [];
  45815. if (pos + limit > end) {
  45816. limit = end - pos;
  45817. }
  45818. for (var n = 0; n < limit; ++n) {
  45819. strBuf.push(String.fromCharCode(stream.getByte()));
  45820. }
  45821. var str = strBuf.join('');
  45822. stream.pos = pos;
  45823. var index = backwards ? str.lastIndexOf(needle) : str.indexOf(needle);
  45824. if (index === -1) {
  45825. return false; /* not found */
  45826. }
  45827. stream.pos += index;
  45828. return true; /* found */
  45829. }
  45830. var DocumentInfoValidators = {
  45831. get entries() {
  45832. // Lazily build this since all the validation functions below are not
  45833. // defined until after this file loads.
  45834. return shadow(this, 'entries', {
  45835. Title: isString,
  45836. Author: isString,
  45837. Subject: isString,
  45838. Keywords: isString,
  45839. Creator: isString,
  45840. Producer: isString,
  45841. CreationDate: isString,
  45842. ModDate: isString,
  45843. Trapped: isName
  45844. });
  45845. }
  45846. };
  45847. PDFDocument.prototype = {
  45848. parse: function PDFDocument_parse(recoveryMode) {
  45849. this.setup(recoveryMode);
  45850. var version = this.catalog.catDict.get('Version');
  45851. if (isName(version)) {
  45852. this.pdfFormatVersion = version.name;
  45853. }
  45854. try {
  45855. // checking if AcroForm is present
  45856. this.acroForm = this.catalog.catDict.get('AcroForm');
  45857. if (this.acroForm) {
  45858. this.xfa = this.acroForm.get('XFA');
  45859. var fields = this.acroForm.get('Fields');
  45860. if ((!fields || !isArray(fields) || fields.length === 0) &&
  45861. !this.xfa) {
  45862. // no fields and no XFA -- not a form (?)
  45863. this.acroForm = null;
  45864. }
  45865. }
  45866. } catch (ex) {
  45867. info('Something wrong with AcroForm entry');
  45868. this.acroForm = null;
  45869. }
  45870. },
  45871. get linearization() {
  45872. var linearization = null;
  45873. if (this.stream.length) {
  45874. try {
  45875. linearization = Linearization.create(this.stream);
  45876. } catch (err) {
  45877. if (err instanceof MissingDataException) {
  45878. throw err;
  45879. }
  45880. info(err);
  45881. }
  45882. }
  45883. // shadow the prototype getter with a data property
  45884. return shadow(this, 'linearization', linearization);
  45885. },
  45886. get startXRef() {
  45887. var stream = this.stream;
  45888. var startXRef = 0;
  45889. var linearization = this.linearization;
  45890. if (linearization) {
  45891. // Find end of first obj.
  45892. stream.reset();
  45893. if (find(stream, 'endobj', 1024)) {
  45894. startXRef = stream.pos + 6;
  45895. }
  45896. } else {
  45897. // Find startxref by jumping backward from the end of the file.
  45898. var step = 1024;
  45899. var found = false, pos = stream.end;
  45900. while (!found && pos > 0) {
  45901. pos -= step - 'startxref'.length;
  45902. if (pos < 0) {
  45903. pos = 0;
  45904. }
  45905. stream.pos = pos;
  45906. found = find(stream, 'startxref', step, true);
  45907. }
  45908. if (found) {
  45909. stream.skip(9);
  45910. var ch;
  45911. do {
  45912. ch = stream.getByte();
  45913. } while (Lexer.isSpace(ch));
  45914. var str = '';
  45915. while (ch >= 0x20 && ch <= 0x39) { // < '9'
  45916. str += String.fromCharCode(ch);
  45917. ch = stream.getByte();
  45918. }
  45919. startXRef = parseInt(str, 10);
  45920. if (isNaN(startXRef)) {
  45921. startXRef = 0;
  45922. }
  45923. }
  45924. }
  45925. // shadow the prototype getter with a data property
  45926. return shadow(this, 'startXRef', startXRef);
  45927. },
  45928. get mainXRefEntriesOffset() {
  45929. var mainXRefEntriesOffset = 0;
  45930. var linearization = this.linearization;
  45931. if (linearization) {
  45932. mainXRefEntriesOffset = linearization.mainXRefEntriesOffset;
  45933. }
  45934. // shadow the prototype getter with a data property
  45935. return shadow(this, 'mainXRefEntriesOffset', mainXRefEntriesOffset);
  45936. },
  45937. // Find the header, remove leading garbage and setup the stream
  45938. // starting from the header.
  45939. checkHeader: function PDFDocument_checkHeader() {
  45940. var stream = this.stream;
  45941. stream.reset();
  45942. if (find(stream, '%PDF-', 1024)) {
  45943. // Found the header, trim off any garbage before it.
  45944. stream.moveStart();
  45945. // Reading file format version
  45946. var MAX_VERSION_LENGTH = 12;
  45947. var version = '', ch;
  45948. while ((ch = stream.getByte()) > 0x20) { // SPACE
  45949. if (version.length >= MAX_VERSION_LENGTH) {
  45950. break;
  45951. }
  45952. version += String.fromCharCode(ch);
  45953. }
  45954. if (!this.pdfFormatVersion) {
  45955. // removing "%PDF-"-prefix
  45956. this.pdfFormatVersion = version.substring(5);
  45957. }
  45958. return;
  45959. }
  45960. // May not be a PDF file, continue anyway.
  45961. },
  45962. parseStartXRef: function PDFDocument_parseStartXRef() {
  45963. var startXRef = this.startXRef;
  45964. this.xref.setStartXRef(startXRef);
  45965. },
  45966. setup: function PDFDocument_setup(recoveryMode) {
  45967. this.xref.parse(recoveryMode);
  45968. var self = this;
  45969. var pageFactory = {
  45970. createPage: function (pageIndex, dict, ref, fontCache) {
  45971. return new Page(self.pdfManager, self.xref, pageIndex, dict, ref,
  45972. fontCache);
  45973. }
  45974. };
  45975. this.catalog = new Catalog(this.pdfManager, this.xref, pageFactory);
  45976. },
  45977. get numPages() {
  45978. var linearization = this.linearization;
  45979. var num = linearization ? linearization.numPages : this.catalog.numPages;
  45980. // shadow the prototype getter
  45981. return shadow(this, 'numPages', num);
  45982. },
  45983. get documentInfo() {
  45984. var docInfo = {
  45985. PDFFormatVersion: this.pdfFormatVersion,
  45986. IsAcroFormPresent: !!this.acroForm,
  45987. IsXFAPresent: !!this.xfa
  45988. };
  45989. var infoDict;
  45990. try {
  45991. infoDict = this.xref.trailer.get('Info');
  45992. } catch (err) {
  45993. info('The document information dictionary is invalid.');
  45994. }
  45995. if (infoDict) {
  45996. var validEntries = DocumentInfoValidators.entries;
  45997. // Only fill the document info with valid entries from the spec.
  45998. for (var key in validEntries) {
  45999. if (infoDict.has(key)) {
  46000. var value = infoDict.get(key);
  46001. // Make sure the value conforms to the spec.
  46002. if (validEntries[key](value)) {
  46003. docInfo[key] = (typeof value !== 'string' ?
  46004. value : stringToPDFString(value));
  46005. } else {
  46006. info('Bad value in document info for "' + key + '"');
  46007. }
  46008. }
  46009. }
  46010. }
  46011. return shadow(this, 'documentInfo', docInfo);
  46012. },
  46013. get fingerprint() {
  46014. var xref = this.xref, hash, fileID = '';
  46015. var idArray = xref.trailer.get('ID');
  46016. if (idArray && isArray(idArray) && idArray[0] && isString(idArray[0]) &&
  46017. idArray[0] !== EMPTY_FINGERPRINT) {
  46018. hash = stringToBytes(idArray[0]);
  46019. } else {
  46020. if (this.stream.ensureRange) {
  46021. this.stream.ensureRange(0,
  46022. Math.min(FINGERPRINT_FIRST_BYTES, this.stream.end));
  46023. }
  46024. hash = calculateMD5(this.stream.bytes.subarray(0,
  46025. FINGERPRINT_FIRST_BYTES), 0, FINGERPRINT_FIRST_BYTES);
  46026. }
  46027. for (var i = 0, n = hash.length; i < n; i++) {
  46028. var hex = hash[i].toString(16);
  46029. fileID += hex.length === 1 ? '0' + hex : hex;
  46030. }
  46031. return shadow(this, 'fingerprint', fileID);
  46032. },
  46033. getPage: function PDFDocument_getPage(pageIndex) {
  46034. return this.catalog.getPage(pageIndex);
  46035. },
  46036. cleanup: function PDFDocument_cleanup() {
  46037. return this.catalog.cleanup();
  46038. }
  46039. };
  46040. return PDFDocument;
  46041. })();
  46042. exports.Page = Page;
  46043. exports.PDFDocument = PDFDocument;
  46044. }));
  46045. (function (root, factory) {
  46046. {
  46047. factory((root.pdfjsCorePdfManager = {}), root.pdfjsSharedUtil,
  46048. root.pdfjsCoreStream, root.pdfjsCoreChunkedStream,
  46049. root.pdfjsCoreDocument);
  46050. }
  46051. }(this, function (exports, sharedUtil, coreStream, coreChunkedStream,
  46052. coreDocument) {
  46053. var NotImplementedException = sharedUtil.NotImplementedException;
  46054. var MissingDataException = sharedUtil.MissingDataException;
  46055. var createPromiseCapability = sharedUtil.createPromiseCapability;
  46056. var Util = sharedUtil.Util;
  46057. var Stream = coreStream.Stream;
  46058. var ChunkedStreamManager = coreChunkedStream.ChunkedStreamManager;
  46059. var PDFDocument = coreDocument.PDFDocument;
  46060. var BasePdfManager = (function BasePdfManagerClosure() {
  46061. function BasePdfManager() {
  46062. throw new Error('Cannot initialize BaseManagerManager');
  46063. }
  46064. BasePdfManager.prototype = {
  46065. get docId() {
  46066. return this._docId;
  46067. },
  46068. onLoadedStream: function BasePdfManager_onLoadedStream() {
  46069. throw new NotImplementedException();
  46070. },
  46071. ensureDoc: function BasePdfManager_ensureDoc(prop, args) {
  46072. return this.ensure(this.pdfDocument, prop, args);
  46073. },
  46074. ensureXRef: function BasePdfManager_ensureXRef(prop, args) {
  46075. return this.ensure(this.pdfDocument.xref, prop, args);
  46076. },
  46077. ensureCatalog: function BasePdfManager_ensureCatalog(prop, args) {
  46078. return this.ensure(this.pdfDocument.catalog, prop, args);
  46079. },
  46080. getPage: function BasePdfManager_getPage(pageIndex) {
  46081. return this.pdfDocument.getPage(pageIndex);
  46082. },
  46083. cleanup: function BasePdfManager_cleanup() {
  46084. return this.pdfDocument.cleanup();
  46085. },
  46086. ensure: function BasePdfManager_ensure(obj, prop, args) {
  46087. return new NotImplementedException();
  46088. },
  46089. requestRange: function BasePdfManager_requestRange(begin, end) {
  46090. return new NotImplementedException();
  46091. },
  46092. requestLoadedStream: function BasePdfManager_requestLoadedStream() {
  46093. return new NotImplementedException();
  46094. },
  46095. sendProgressiveData: function BasePdfManager_sendProgressiveData(chunk) {
  46096. return new NotImplementedException();
  46097. },
  46098. updatePassword: function BasePdfManager_updatePassword(password) {
  46099. this.pdfDocument.xref.password = this.password = password;
  46100. if (this._passwordChangedCapability) {
  46101. this._passwordChangedCapability.resolve();
  46102. }
  46103. },
  46104. passwordChanged: function BasePdfManager_passwordChanged() {
  46105. this._passwordChangedCapability = createPromiseCapability();
  46106. return this._passwordChangedCapability.promise;
  46107. },
  46108. terminate: function BasePdfManager_terminate() {
  46109. return new NotImplementedException();
  46110. }
  46111. };
  46112. return BasePdfManager;
  46113. })();
  46114. var LocalPdfManager = (function LocalPdfManagerClosure() {
  46115. function LocalPdfManager(docId, data, password, evaluatorOptions) {
  46116. this._docId = docId;
  46117. this.evaluatorOptions = evaluatorOptions;
  46118. var stream = new Stream(data);
  46119. this.pdfDocument = new PDFDocument(this, stream, password);
  46120. this._loadedStreamCapability = createPromiseCapability();
  46121. this._loadedStreamCapability.resolve(stream);
  46122. }
  46123. Util.inherit(LocalPdfManager, BasePdfManager, {
  46124. ensure: function LocalPdfManager_ensure(obj, prop, args) {
  46125. return new Promise(function (resolve, reject) {
  46126. try {
  46127. var value = obj[prop];
  46128. var result;
  46129. if (typeof value === 'function') {
  46130. result = value.apply(obj, args);
  46131. } else {
  46132. result = value;
  46133. }
  46134. resolve(result);
  46135. } catch (e) {
  46136. reject(e);
  46137. }
  46138. });
  46139. },
  46140. requestRange: function LocalPdfManager_requestRange(begin, end) {
  46141. return Promise.resolve();
  46142. },
  46143. requestLoadedStream: function LocalPdfManager_requestLoadedStream() {
  46144. return;
  46145. },
  46146. onLoadedStream: function LocalPdfManager_onLoadedStream() {
  46147. return this._loadedStreamCapability.promise;
  46148. },
  46149. terminate: function LocalPdfManager_terminate() {
  46150. return;
  46151. }
  46152. });
  46153. return LocalPdfManager;
  46154. })();
  46155. var NetworkPdfManager = (function NetworkPdfManagerClosure() {
  46156. function NetworkPdfManager(docId, pdfNetworkStream, args, evaluatorOptions) {
  46157. this._docId = docId;
  46158. this.msgHandler = args.msgHandler;
  46159. this.evaluatorOptions = evaluatorOptions;
  46160. var params = {
  46161. msgHandler: args.msgHandler,
  46162. url: args.url,
  46163. length: args.length,
  46164. disableAutoFetch: args.disableAutoFetch,
  46165. rangeChunkSize: args.rangeChunkSize
  46166. };
  46167. this.streamManager = new ChunkedStreamManager(pdfNetworkStream, params);
  46168. this.pdfDocument = new PDFDocument(this, this.streamManager.getStream(),
  46169. args.password);
  46170. }
  46171. Util.inherit(NetworkPdfManager, BasePdfManager, {
  46172. ensure: function NetworkPdfManager_ensure(obj, prop, args) {
  46173. var pdfManager = this;
  46174. return new Promise(function (resolve, reject) {
  46175. function ensureHelper() {
  46176. try {
  46177. var result;
  46178. var value = obj[prop];
  46179. if (typeof value === 'function') {
  46180. result = value.apply(obj, args);
  46181. } else {
  46182. result = value;
  46183. }
  46184. resolve(result);
  46185. } catch(e) {
  46186. if (!(e instanceof MissingDataException)) {
  46187. reject(e);
  46188. return;
  46189. }
  46190. pdfManager.streamManager.requestRange(e.begin, e.end).
  46191. then(ensureHelper, reject);
  46192. }
  46193. }
  46194. ensureHelper();
  46195. });
  46196. },
  46197. requestRange: function NetworkPdfManager_requestRange(begin, end) {
  46198. return this.streamManager.requestRange(begin, end);
  46199. },
  46200. requestLoadedStream: function NetworkPdfManager_requestLoadedStream() {
  46201. this.streamManager.requestAllChunks();
  46202. },
  46203. sendProgressiveData:
  46204. function NetworkPdfManager_sendProgressiveData(chunk) {
  46205. this.streamManager.onReceiveData({ chunk: chunk });
  46206. },
  46207. onLoadedStream: function NetworkPdfManager_onLoadedStream() {
  46208. return this.streamManager.onLoadedStream();
  46209. },
  46210. terminate: function NetworkPdfManager_terminate() {
  46211. this.streamManager.abort();
  46212. }
  46213. });
  46214. return NetworkPdfManager;
  46215. })();
  46216. exports.LocalPdfManager = LocalPdfManager;
  46217. exports.NetworkPdfManager = NetworkPdfManager;
  46218. }));
  46219. (function (root, factory) {
  46220. {
  46221. factory((root.pdfjsCoreWorker = {}), root.pdfjsSharedUtil,
  46222. root.pdfjsCorePrimitives, root.pdfjsCorePdfManager);
  46223. }
  46224. }(this, function (exports, sharedUtil, corePrimitives, corePdfManager) {
  46225. var UNSUPPORTED_FEATURES = sharedUtil.UNSUPPORTED_FEATURES;
  46226. var InvalidPDFException = sharedUtil.InvalidPDFException;
  46227. var MessageHandler = sharedUtil.MessageHandler;
  46228. var MissingPDFException = sharedUtil.MissingPDFException;
  46229. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  46230. var PasswordException = sharedUtil.PasswordException;
  46231. var PasswordResponses = sharedUtil.PasswordResponses;
  46232. var UnknownErrorException = sharedUtil.UnknownErrorException;
  46233. var XRefParseException = sharedUtil.XRefParseException;
  46234. var arrayByteLength = sharedUtil.arrayByteLength;
  46235. var arraysToBytes = sharedUtil.arraysToBytes;
  46236. var assert = sharedUtil.assert;
  46237. var createPromiseCapability = sharedUtil.createPromiseCapability;
  46238. var error = sharedUtil.error;
  46239. var info = sharedUtil.info;
  46240. var warn = sharedUtil.warn;
  46241. var setVerbosityLevel = sharedUtil.setVerbosityLevel;
  46242. var Ref = corePrimitives.Ref;
  46243. var LocalPdfManager = corePdfManager.LocalPdfManager;
  46244. var NetworkPdfManager = corePdfManager.NetworkPdfManager;
  46245. var globalScope = sharedUtil.globalScope;
  46246. var WorkerTask = (function WorkerTaskClosure() {
  46247. function WorkerTask(name) {
  46248. this.name = name;
  46249. this.terminated = false;
  46250. this._capability = createPromiseCapability();
  46251. }
  46252. WorkerTask.prototype = {
  46253. get finished() {
  46254. return this._capability.promise;
  46255. },
  46256. finish: function () {
  46257. this._capability.resolve();
  46258. },
  46259. terminate: function () {
  46260. this.terminated = true;
  46261. },
  46262. ensureNotTerminated: function () {
  46263. if (this.terminated) {
  46264. throw new Error('Worker task was terminated');
  46265. }
  46266. }
  46267. };
  46268. return WorkerTask;
  46269. })();
  46270. /** @implements {IPDFStream} */
  46271. var PDFWorkerStream = (function PDFWorkerStreamClosure() {
  46272. function PDFWorkerStream(params, msgHandler) {
  46273. this._queuedChunks = [];
  46274. var initialData = params.initialData;
  46275. if (initialData && initialData.length > 0) {
  46276. this._queuedChunks.push(initialData);
  46277. }
  46278. this._msgHandler = msgHandler;
  46279. this._isRangeSupported = !(params.disableRange);
  46280. this._isStreamingSupported = !(params.disableStream);
  46281. this._contentLength = params.length;
  46282. this._fullRequestReader = null;
  46283. this._rangeReaders = [];
  46284. msgHandler.on('OnDataRange', this._onReceiveData.bind(this));
  46285. msgHandler.on('OnDataProgress', this._onProgress.bind(this));
  46286. }
  46287. PDFWorkerStream.prototype = {
  46288. _onReceiveData: function PDFWorkerStream_onReceiveData(args) {
  46289. if (args.begin === undefined) {
  46290. if (this._fullRequestReader) {
  46291. this._fullRequestReader._enqueue(args.chunk);
  46292. } else {
  46293. this._queuedChunks.push(args.chunk);
  46294. }
  46295. } else {
  46296. var found = this._rangeReaders.some(function (rangeReader) {
  46297. if (rangeReader._begin !== args.begin) {
  46298. return false;
  46299. }
  46300. rangeReader._enqueue(args.chunk);
  46301. return true;
  46302. });
  46303. assert(found);
  46304. }
  46305. },
  46306. _onProgress: function PDFWorkerStream_onProgress(evt) {
  46307. if (this._rangeReaders.length > 0) {
  46308. // Reporting to first range reader.
  46309. var firstReader = this._rangeReaders[0];
  46310. if (firstReader.onProgress) {
  46311. firstReader.onProgress({loaded: evt.loaded});
  46312. }
  46313. }
  46314. },
  46315. _removeRangeReader: function PDFWorkerStream_removeRangeReader(reader) {
  46316. var i = this._rangeReaders.indexOf(reader);
  46317. if (i >= 0) {
  46318. this._rangeReaders.splice(i, 1);
  46319. }
  46320. },
  46321. getFullReader: function PDFWorkerStream_getFullReader() {
  46322. assert(!this._fullRequestReader);
  46323. var queuedChunks = this._queuedChunks;
  46324. this._queuedChunks = null;
  46325. return new PDFWorkerStreamReader(this, queuedChunks);
  46326. },
  46327. getRangeReader: function PDFWorkerStream_getRangeReader(begin, end) {
  46328. var reader = new PDFWorkerStreamRangeReader(this, begin, end);
  46329. this._msgHandler.send('RequestDataRange', { begin: begin, end: end });
  46330. this._rangeReaders.push(reader);
  46331. return reader;
  46332. },
  46333. cancelAllRequests: function PDFWorkerStream_cancelAllRequests(reason) {
  46334. if (this._fullRequestReader) {
  46335. this._fullRequestReader.cancel(reason);
  46336. }
  46337. var readers = this._rangeReaders.slice(0);
  46338. readers.forEach(function (rangeReader) {
  46339. rangeReader.cancel(reason);
  46340. });
  46341. }
  46342. };
  46343. /** @implements {IPDFStreamReader} */
  46344. function PDFWorkerStreamReader(stream, queuedChunks) {
  46345. this._stream = stream;
  46346. this._done = false;
  46347. this._queuedChunks = queuedChunks || [];
  46348. this._requests = [];
  46349. this._headersReady = Promise.resolve();
  46350. stream._fullRequestReader = this;
  46351. this.onProgress = null; // not used
  46352. }
  46353. PDFWorkerStreamReader.prototype = {
  46354. _enqueue: function PDFWorkerStreamReader_enqueue(chunk) {
  46355. if (this._done) {
  46356. return; // ignore new data
  46357. }
  46358. if (this._requests.length > 0) {
  46359. var requestCapability = this._requests.shift();
  46360. requestCapability.resolve({value: chunk, done: false});
  46361. return;
  46362. }
  46363. this._queuedChunks.push(chunk);
  46364. },
  46365. get headersReady() {
  46366. return this._headersReady;
  46367. },
  46368. get isRangeSupported() {
  46369. return this._stream._isRangeSupported;
  46370. },
  46371. get isStreamingSupported() {
  46372. return this._stream._isStreamingSupported;
  46373. },
  46374. get contentLength() {
  46375. return this._stream._contentLength;
  46376. },
  46377. read: function PDFWorkerStreamReader_read() {
  46378. if (this._queuedChunks.length > 0) {
  46379. var chunk = this._queuedChunks.shift();
  46380. return Promise.resolve({value: chunk, done: false});
  46381. }
  46382. if (this._done) {
  46383. return Promise.resolve({value: undefined, done: true});
  46384. }
  46385. var requestCapability = createPromiseCapability();
  46386. this._requests.push(requestCapability);
  46387. return requestCapability.promise;
  46388. },
  46389. cancel: function PDFWorkerStreamReader_cancel(reason) {
  46390. this._done = true;
  46391. this._requests.forEach(function (requestCapability) {
  46392. requestCapability.resolve({value: undefined, done: true});
  46393. });
  46394. this._requests = [];
  46395. }
  46396. };
  46397. /** @implements {IPDFStreamRangeReader} */
  46398. function PDFWorkerStreamRangeReader(stream, begin, end) {
  46399. this._stream = stream;
  46400. this._begin = begin;
  46401. this._end = end;
  46402. this._queuedChunk = null;
  46403. this._requests = [];
  46404. this._done = false;
  46405. this.onProgress = null;
  46406. }
  46407. PDFWorkerStreamRangeReader.prototype = {
  46408. _enqueue: function PDFWorkerStreamRangeReader_enqueue(chunk) {
  46409. if (this._done) {
  46410. return; // ignore new data
  46411. }
  46412. if (this._requests.length === 0) {
  46413. this._queuedChunk = chunk;
  46414. } else {
  46415. var requestsCapability = this._requests.shift();
  46416. requestsCapability.resolve({value: chunk, done: false});
  46417. this._requests.forEach(function (requestCapability) {
  46418. requestCapability.resolve({value: undefined, done: true});
  46419. });
  46420. this._requests = [];
  46421. }
  46422. this._done = true;
  46423. this._stream._removeRangeReader(this);
  46424. },
  46425. get isStreamingSupported() {
  46426. return false;
  46427. },
  46428. read: function PDFWorkerStreamRangeReader_read() {
  46429. if (this._queuedChunk) {
  46430. return Promise.resolve({value: this._queuedChunk, done: false});
  46431. }
  46432. if (this._done) {
  46433. return Promise.resolve({value: undefined, done: true});
  46434. }
  46435. var requestCapability = createPromiseCapability();
  46436. this._requests.push(requestCapability);
  46437. return requestCapability.promise;
  46438. },
  46439. cancel: function PDFWorkerStreamRangeReader_cancel(reason) {
  46440. this._done = true;
  46441. this._requests.forEach(function (requestCapability) {
  46442. requestCapability.resolve({value: undefined, done: true});
  46443. });
  46444. this._requests = [];
  46445. this._stream._removeRangeReader(this);
  46446. }
  46447. };
  46448. return PDFWorkerStream;
  46449. })();
  46450. /** @type IPDFStream */
  46451. var PDFNetworkStream;
  46452. /**
  46453. * Sets PDFNetworkStream class to be used as alternative PDF data transport.
  46454. * @param {IPDFStream} cls - the PDF data transport.
  46455. */
  46456. function setPDFNetworkStreamClass(cls) {
  46457. PDFNetworkStream = cls;
  46458. }
  46459. var WorkerMessageHandler = {
  46460. setup: function wphSetup(handler, port) {
  46461. var testMessageProcessed = false;
  46462. handler.on('test', function wphSetupTest(data) {
  46463. if (testMessageProcessed) {
  46464. return; // we already processed 'test' message once
  46465. }
  46466. testMessageProcessed = true;
  46467. // check if Uint8Array can be sent to worker
  46468. if (!(data instanceof Uint8Array)) {
  46469. handler.send('test', 'main', false);
  46470. return;
  46471. }
  46472. // making sure postMessage transfers are working
  46473. var supportTransfers = data[0] === 255;
  46474. handler.postMessageTransfers = supportTransfers;
  46475. // check if the response property is supported by xhr
  46476. var xhr = new XMLHttpRequest();
  46477. var responseExists = 'response' in xhr;
  46478. // check if the property is actually implemented
  46479. try {
  46480. var dummy = xhr.responseType;
  46481. } catch (e) {
  46482. responseExists = false;
  46483. }
  46484. if (!responseExists) {
  46485. handler.send('test', false);
  46486. return;
  46487. }
  46488. handler.send('test', {
  46489. supportTypedArray: true,
  46490. supportTransfers: supportTransfers
  46491. });
  46492. });
  46493. handler.on('configure', function wphConfigure(data) {
  46494. setVerbosityLevel(data.verbosity);
  46495. });
  46496. handler.on('GetDocRequest', function wphSetupDoc(data) {
  46497. return WorkerMessageHandler.createDocumentHandler(data, port);
  46498. });
  46499. },
  46500. createDocumentHandler: function wphCreateDocumentHandler(docParams, port) {
  46501. // This context is actually holds references on pdfManager and handler,
  46502. // until the latter is destroyed.
  46503. var pdfManager;
  46504. var terminated = false;
  46505. var cancelXHRs = null;
  46506. var WorkerTasks = [];
  46507. var docId = docParams.docId;
  46508. var workerHandlerName = docParams.docId + '_worker';
  46509. var handler = new MessageHandler(workerHandlerName, docId, port);
  46510. // Ensure that postMessage transfers are correctly enabled/disabled,
  46511. // to prevent "DataCloneError" in older versions of IE (see issue 6957).
  46512. handler.postMessageTransfers = docParams.postMessageTransfers;
  46513. function ensureNotTerminated() {
  46514. if (terminated) {
  46515. throw new Error('Worker was terminated');
  46516. }
  46517. }
  46518. function startWorkerTask(task) {
  46519. WorkerTasks.push(task);
  46520. }
  46521. function finishWorkerTask(task) {
  46522. task.finish();
  46523. var i = WorkerTasks.indexOf(task);
  46524. WorkerTasks.splice(i, 1);
  46525. }
  46526. function loadDocument(recoveryMode) {
  46527. var loadDocumentCapability = createPromiseCapability();
  46528. var parseSuccess = function parseSuccess() {
  46529. var numPagesPromise = pdfManager.ensureDoc('numPages');
  46530. var fingerprintPromise = pdfManager.ensureDoc('fingerprint');
  46531. var encryptedPromise = pdfManager.ensureXRef('encrypt');
  46532. Promise.all([numPagesPromise, fingerprintPromise,
  46533. encryptedPromise]).then(function onDocReady(results) {
  46534. var doc = {
  46535. numPages: results[0],
  46536. fingerprint: results[1],
  46537. encrypted: !!results[2],
  46538. };
  46539. loadDocumentCapability.resolve(doc);
  46540. },
  46541. parseFailure);
  46542. };
  46543. var parseFailure = function parseFailure(e) {
  46544. loadDocumentCapability.reject(e);
  46545. };
  46546. pdfManager.ensureDoc('checkHeader', []).then(function() {
  46547. pdfManager.ensureDoc('parseStartXRef', []).then(function() {
  46548. pdfManager.ensureDoc('parse', [recoveryMode]).then(
  46549. parseSuccess, parseFailure);
  46550. }, parseFailure);
  46551. }, parseFailure);
  46552. return loadDocumentCapability.promise;
  46553. }
  46554. function getPdfManager(data, evaluatorOptions) {
  46555. var pdfManagerCapability = createPromiseCapability();
  46556. var pdfManager;
  46557. var source = data.source;
  46558. if (source.data) {
  46559. try {
  46560. pdfManager = new LocalPdfManager(docId, source.data, source.password,
  46561. evaluatorOptions);
  46562. pdfManagerCapability.resolve(pdfManager);
  46563. } catch (ex) {
  46564. pdfManagerCapability.reject(ex);
  46565. }
  46566. return pdfManagerCapability.promise;
  46567. }
  46568. var pdfStream;
  46569. try {
  46570. if (source.chunkedViewerLoading) {
  46571. pdfStream = new PDFWorkerStream(source, handler);
  46572. } else {
  46573. assert(PDFNetworkStream, 'pdfjs/core/network module is not loaded');
  46574. pdfStream = new PDFNetworkStream(data);
  46575. }
  46576. } catch (ex) {
  46577. pdfManagerCapability.reject(ex);
  46578. return pdfManagerCapability.promise;
  46579. }
  46580. var fullRequest = pdfStream.getFullReader();
  46581. fullRequest.headersReady.then(function () {
  46582. if (!fullRequest.isStreamingSupported ||
  46583. !fullRequest.isRangeSupported) {
  46584. // If stream or range are disabled, it's our only way to report
  46585. // loading progress.
  46586. fullRequest.onProgress = function (evt) {
  46587. handler.send('DocProgress', {
  46588. loaded: evt.loaded,
  46589. total: evt.total
  46590. });
  46591. };
  46592. }
  46593. if (!fullRequest.isRangeSupported) {
  46594. return;
  46595. }
  46596. // We don't need auto-fetch when streaming is enabled.
  46597. var disableAutoFetch = source.disableAutoFetch ||
  46598. fullRequest.isStreamingSupported;
  46599. pdfManager = new NetworkPdfManager(docId, pdfStream, {
  46600. msgHandler: handler,
  46601. url: source.url,
  46602. password: source.password,
  46603. length: fullRequest.contentLength,
  46604. disableAutoFetch: disableAutoFetch,
  46605. rangeChunkSize: source.rangeChunkSize
  46606. }, evaluatorOptions);
  46607. pdfManagerCapability.resolve(pdfManager);
  46608. cancelXHRs = null;
  46609. }).catch(function (reason) {
  46610. pdfManagerCapability.reject(reason);
  46611. cancelXHRs = null;
  46612. });
  46613. var cachedChunks = [], loaded = 0;
  46614. var flushChunks = function () {
  46615. var pdfFile = arraysToBytes(cachedChunks);
  46616. if (source.length && pdfFile.length !== source.length) {
  46617. warn('reported HTTP length is different from actual');
  46618. }
  46619. // the data is array, instantiating directly from it
  46620. try {
  46621. pdfManager = new LocalPdfManager(docId, pdfFile, source.password,
  46622. evaluatorOptions);
  46623. pdfManagerCapability.resolve(pdfManager);
  46624. } catch (ex) {
  46625. pdfManagerCapability.reject(ex);
  46626. }
  46627. cachedChunks = [];
  46628. };
  46629. var readPromise = new Promise(function (resolve, reject) {
  46630. var readChunk = function (chunk) {
  46631. try {
  46632. ensureNotTerminated();
  46633. if (chunk.done) {
  46634. if (!pdfManager) {
  46635. flushChunks();
  46636. }
  46637. cancelXHRs = null;
  46638. return;
  46639. }
  46640. var data = chunk.value;
  46641. loaded += arrayByteLength(data);
  46642. if (!fullRequest.isStreamingSupported) {
  46643. handler.send('DocProgress', {
  46644. loaded: loaded,
  46645. total: Math.max(loaded, fullRequest.contentLength || 0)
  46646. });
  46647. }
  46648. if (pdfManager) {
  46649. pdfManager.sendProgressiveData(data);
  46650. } else {
  46651. cachedChunks.push(data);
  46652. }
  46653. fullRequest.read().then(readChunk, reject);
  46654. } catch (e) {
  46655. reject(e);
  46656. }
  46657. };
  46658. fullRequest.read().then(readChunk, reject);
  46659. });
  46660. readPromise.catch(function (e) {
  46661. pdfManagerCapability.reject(e);
  46662. cancelXHRs = null;
  46663. });
  46664. cancelXHRs = function () {
  46665. pdfStream.cancelAllRequests('abort');
  46666. };
  46667. return pdfManagerCapability.promise;
  46668. }
  46669. var setupDoc = function(data) {
  46670. var onSuccess = function(doc) {
  46671. ensureNotTerminated();
  46672. handler.send('GetDoc', { pdfInfo: doc });
  46673. };
  46674. var onFailure = function(e) {
  46675. if (e instanceof PasswordException) {
  46676. if (e.code === PasswordResponses.NEED_PASSWORD) {
  46677. handler.send('NeedPassword', e);
  46678. } else if (e.code === PasswordResponses.INCORRECT_PASSWORD) {
  46679. handler.send('IncorrectPassword', e);
  46680. }
  46681. } else if (e instanceof InvalidPDFException) {
  46682. handler.send('InvalidPDF', e);
  46683. } else if (e instanceof MissingPDFException) {
  46684. handler.send('MissingPDF', e);
  46685. } else if (e instanceof UnexpectedResponseException) {
  46686. handler.send('UnexpectedResponse', e);
  46687. } else {
  46688. handler.send('UnknownError',
  46689. new UnknownErrorException(e.message, e.toString()));
  46690. }
  46691. };
  46692. ensureNotTerminated();
  46693. var cMapOptions = {
  46694. url: data.cMapUrl === undefined ? null : data.cMapUrl,
  46695. packed: data.cMapPacked === true
  46696. };
  46697. var evaluatorOptions = {
  46698. forceDataSchema: data.disableCreateObjectURL,
  46699. maxImageSize: data.maxImageSize === undefined ? -1 : data.maxImageSize,
  46700. disableFontFace: data.disableFontFace,
  46701. cMapOptions: cMapOptions
  46702. };
  46703. getPdfManager(data, evaluatorOptions).then(function (newPdfManager) {
  46704. if (terminated) {
  46705. // We were in a process of setting up the manager, but it got
  46706. // terminated in the middle.
  46707. newPdfManager.terminate();
  46708. throw new Error('Worker was terminated');
  46709. }
  46710. pdfManager = newPdfManager;
  46711. handler.send('PDFManagerReady', null);
  46712. pdfManager.onLoadedStream().then(function(stream) {
  46713. handler.send('DataLoaded', { length: stream.bytes.byteLength });
  46714. });
  46715. }).then(function pdfManagerReady() {
  46716. ensureNotTerminated();
  46717. loadDocument(false).then(onSuccess, function loadFailure(ex) {
  46718. ensureNotTerminated();
  46719. // Try again with recoveryMode == true
  46720. if (!(ex instanceof XRefParseException)) {
  46721. if (ex instanceof PasswordException) {
  46722. // after password exception prepare to receive a new password
  46723. // to repeat loading
  46724. pdfManager.passwordChanged().then(pdfManagerReady);
  46725. }
  46726. onFailure(ex);
  46727. return;
  46728. }
  46729. pdfManager.requestLoadedStream();
  46730. pdfManager.onLoadedStream().then(function() {
  46731. ensureNotTerminated();
  46732. loadDocument(true).then(onSuccess, onFailure);
  46733. });
  46734. }, onFailure);
  46735. }, onFailure);
  46736. };
  46737. handler.on('GetPage', function wphSetupGetPage(data) {
  46738. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46739. var rotatePromise = pdfManager.ensure(page, 'rotate');
  46740. var refPromise = pdfManager.ensure(page, 'ref');
  46741. var viewPromise = pdfManager.ensure(page, 'view');
  46742. return Promise.all([rotatePromise, refPromise, viewPromise]).then(
  46743. function(results) {
  46744. return {
  46745. rotate: results[0],
  46746. ref: results[1],
  46747. view: results[2]
  46748. };
  46749. });
  46750. });
  46751. });
  46752. handler.on('GetPageIndex', function wphSetupGetPageIndex(data) {
  46753. var ref = new Ref(data.ref.num, data.ref.gen);
  46754. var catalog = pdfManager.pdfDocument.catalog;
  46755. return catalog.getPageIndex(ref);
  46756. });
  46757. handler.on('GetDestinations',
  46758. function wphSetupGetDestinations(data) {
  46759. return pdfManager.ensureCatalog('destinations');
  46760. }
  46761. );
  46762. handler.on('GetDestination',
  46763. function wphSetupGetDestination(data) {
  46764. return pdfManager.ensureCatalog('getDestination', [data.id]);
  46765. }
  46766. );
  46767. handler.on('GetPageLabels',
  46768. function wphSetupGetPageLabels(data) {
  46769. return pdfManager.ensureCatalog('pageLabels');
  46770. }
  46771. );
  46772. handler.on('GetAttachments',
  46773. function wphSetupGetAttachments(data) {
  46774. return pdfManager.ensureCatalog('attachments');
  46775. }
  46776. );
  46777. handler.on('GetJavaScript',
  46778. function wphSetupGetJavaScript(data) {
  46779. return pdfManager.ensureCatalog('javaScript');
  46780. }
  46781. );
  46782. handler.on('GetOutline',
  46783. function wphSetupGetOutline(data) {
  46784. return pdfManager.ensureCatalog('documentOutline');
  46785. }
  46786. );
  46787. handler.on('GetMetadata',
  46788. function wphSetupGetMetadata(data) {
  46789. return Promise.all([pdfManager.ensureDoc('documentInfo'),
  46790. pdfManager.ensureCatalog('metadata')]);
  46791. }
  46792. );
  46793. handler.on('GetData', function wphSetupGetData(data) {
  46794. pdfManager.requestLoadedStream();
  46795. return pdfManager.onLoadedStream().then(function(stream) {
  46796. return stream.bytes;
  46797. });
  46798. });
  46799. handler.on('GetStats',
  46800. function wphSetupGetStats(data) {
  46801. return pdfManager.pdfDocument.xref.stats;
  46802. }
  46803. );
  46804. handler.on('UpdatePassword', function wphSetupUpdatePassword(data) {
  46805. pdfManager.updatePassword(data);
  46806. });
  46807. handler.on('GetAnnotations', function wphSetupGetAnnotations(data) {
  46808. return pdfManager.getPage(data.pageIndex).then(function(page) {
  46809. return pdfManager.ensure(page, 'getAnnotationsData', [data.intent]);
  46810. });
  46811. });
  46812. handler.on('RenderPageRequest', function wphSetupRenderPage(data) {
  46813. var pageIndex = data.pageIndex;
  46814. pdfManager.getPage(pageIndex).then(function(page) {
  46815. var task = new WorkerTask('RenderPageRequest: page ' + pageIndex);
  46816. startWorkerTask(task);
  46817. var pageNum = pageIndex + 1;
  46818. var start = Date.now();
  46819. // Pre compile the pdf page and fetch the fonts/images.
  46820. page.getOperatorList(handler, task, data.intent).then(
  46821. function(operatorList) {
  46822. finishWorkerTask(task);
  46823. info('page=' + pageNum + ' - getOperatorList: time=' +
  46824. (Date.now() - start) + 'ms, len=' + operatorList.totalLength);
  46825. }, function(e) {
  46826. finishWorkerTask(task);
  46827. if (task.terminated) {
  46828. return; // ignoring errors from the terminated thread
  46829. }
  46830. // For compatibility with older behavior, generating unknown
  46831. // unsupported feature notification on errors.
  46832. handler.send('UnsupportedFeature',
  46833. {featureId: UNSUPPORTED_FEATURES.unknown});
  46834. var minimumStackMessage =
  46835. 'worker.js: while trying to getPage() and getOperatorList()';
  46836. var wrappedException;
  46837. // Turn the error into an obj that can be serialized
  46838. if (typeof e === 'string') {
  46839. wrappedException = {
  46840. message: e,
  46841. stack: minimumStackMessage
  46842. };
  46843. } else if (typeof e === 'object') {
  46844. wrappedException = {
  46845. message: e.message || e.toString(),
  46846. stack: e.stack || minimumStackMessage
  46847. };
  46848. } else {
  46849. wrappedException = {
  46850. message: 'Unknown exception type: ' + (typeof e),
  46851. stack: minimumStackMessage
  46852. };
  46853. }
  46854. handler.send('PageError', {
  46855. pageNum: pageNum,
  46856. error: wrappedException,
  46857. intent: data.intent
  46858. });
  46859. });
  46860. });
  46861. }, this);
  46862. handler.on('GetTextContent', function wphExtractText(data) {
  46863. var pageIndex = data.pageIndex;
  46864. var normalizeWhitespace = data.normalizeWhitespace;
  46865. return pdfManager.getPage(pageIndex).then(function(page) {
  46866. var task = new WorkerTask('GetTextContent: page ' + pageIndex);
  46867. startWorkerTask(task);
  46868. var pageNum = pageIndex + 1;
  46869. var start = Date.now();
  46870. return page.extractTextContent(task, normalizeWhitespace).then(
  46871. function(textContent) {
  46872. finishWorkerTask(task);
  46873. info('text indexing: page=' + pageNum + ' - time=' +
  46874. (Date.now() - start) + 'ms');
  46875. return textContent;
  46876. }, function (reason) {
  46877. finishWorkerTask(task);
  46878. if (task.terminated) {
  46879. return; // ignoring errors from the terminated thread
  46880. }
  46881. throw reason;
  46882. });
  46883. });
  46884. });
  46885. handler.on('Cleanup', function wphCleanup(data) {
  46886. return pdfManager.cleanup();
  46887. });
  46888. handler.on('Terminate', function wphTerminate(data) {
  46889. terminated = true;
  46890. if (pdfManager) {
  46891. pdfManager.terminate();
  46892. pdfManager = null;
  46893. }
  46894. if (cancelXHRs) {
  46895. cancelXHRs();
  46896. }
  46897. var waitOn = [];
  46898. WorkerTasks.forEach(function (task) {
  46899. waitOn.push(task.finished);
  46900. task.terminate();
  46901. });
  46902. return Promise.all(waitOn).then(function () {
  46903. // Notice that even if we destroying handler, resolved response promise
  46904. // must be sent back.
  46905. handler.destroy();
  46906. handler = null;
  46907. });
  46908. });
  46909. handler.on('Ready', function wphReady(data) {
  46910. setupDoc(docParams);
  46911. docParams = null; // we don't need docParams anymore -- saving memory.
  46912. });
  46913. return workerHandlerName;
  46914. }
  46915. };
  46916. function initializeWorker() {
  46917. if (!('console' in globalScope)) {
  46918. var consoleTimer = {};
  46919. var workerConsole = {
  46920. log: function log() {
  46921. var args = Array.prototype.slice.call(arguments);
  46922. globalScope.postMessage({
  46923. targetName: 'main',
  46924. action: 'console_log',
  46925. data: args
  46926. });
  46927. },
  46928. error: function error() {
  46929. var args = Array.prototype.slice.call(arguments);
  46930. globalScope.postMessage({
  46931. targetName: 'main',
  46932. action: 'console_error',
  46933. data: args
  46934. });
  46935. throw 'pdf.js execution error';
  46936. },
  46937. time: function time(name) {
  46938. consoleTimer[name] = Date.now();
  46939. },
  46940. timeEnd: function timeEnd(name) {
  46941. var time = consoleTimer[name];
  46942. if (!time) {
  46943. error('Unknown timer name ' + name);
  46944. }
  46945. this.log('Timer:', name, Date.now() - time);
  46946. }
  46947. };
  46948. globalScope.console = workerConsole;
  46949. }
  46950. var handler = new MessageHandler('worker', 'main', self);
  46951. WorkerMessageHandler.setup(handler, self);
  46952. handler.send('ready', null);
  46953. }
  46954. // Worker thread (and not node.js)?
  46955. if (typeof window === 'undefined' &&
  46956. !(typeof module !== 'undefined' && module.require)) {
  46957. initializeWorker();
  46958. }
  46959. exports.setPDFNetworkStreamClass = setPDFNetworkStreamClass;
  46960. exports.WorkerTask = WorkerTask;
  46961. exports.WorkerMessageHandler = WorkerMessageHandler;
  46962. }));
  46963. var NetworkManager = (function NetworkManagerClosure() {
  46964. var OK_RESPONSE = 200;
  46965. var PARTIAL_CONTENT_RESPONSE = 206;
  46966. function NetworkManager(url, args) {
  46967. this.url = url;
  46968. args = args || {};
  46969. this.isHttp = /^https?:/i.test(url);
  46970. this.httpHeaders = (this.isHttp && args.httpHeaders) || {};
  46971. this.withCredentials = args.withCredentials || false;
  46972. this.getXhr = args.getXhr ||
  46973. function NetworkManager_getXhr() {
  46974. return new XMLHttpRequest();
  46975. };
  46976. this.currXhrId = 0;
  46977. this.pendingRequests = Object.create(null);
  46978. this.loadedRequests = Object.create(null);
  46979. }
  46980. function getArrayBuffer(xhr) {
  46981. var data = xhr.response;
  46982. if (typeof data !== 'string') {
  46983. return data;
  46984. }
  46985. var length = data.length;
  46986. var array = new Uint8Array(length);
  46987. for (var i = 0; i < length; i++) {
  46988. array[i] = data.charCodeAt(i) & 0xFF;
  46989. }
  46990. return array.buffer;
  46991. }
  46992. var supportsMozChunked = (function supportsMozChunkedClosure() {
  46993. try {
  46994. var x = new XMLHttpRequest();
  46995. // Firefox 37- required .open() to be called before setting responseType.
  46996. // https://bugzilla.mozilla.org/show_bug.cgi?id=707484
  46997. // Even though the URL is not visited, .open() could fail if the URL is
  46998. // blocked, e.g. via the connect-src CSP directive or the NoScript addon.
  46999. // When this error occurs, this feature detection method will mistakenly
  47000. // report that moz-chunked-arraybuffer is not supported in Firefox 37-.
  47001. x.open('GET', 'https://example.com');
  47002. x.responseType = 'moz-chunked-arraybuffer';
  47003. return x.responseType === 'moz-chunked-arraybuffer';
  47004. } catch (e) {
  47005. return false;
  47006. }
  47007. })();
  47008. NetworkManager.prototype = {
  47009. requestRange: function NetworkManager_requestRange(begin, end, listeners) {
  47010. var args = {
  47011. begin: begin,
  47012. end: end
  47013. };
  47014. for (var prop in listeners) {
  47015. args[prop] = listeners[prop];
  47016. }
  47017. return this.request(args);
  47018. },
  47019. requestFull: function NetworkManager_requestFull(listeners) {
  47020. return this.request(listeners);
  47021. },
  47022. request: function NetworkManager_request(args) {
  47023. var xhr = this.getXhr();
  47024. var xhrId = this.currXhrId++;
  47025. var pendingRequest = this.pendingRequests[xhrId] = {
  47026. xhr: xhr
  47027. };
  47028. xhr.open('GET', this.url);
  47029. xhr.withCredentials = this.withCredentials;
  47030. for (var property in this.httpHeaders) {
  47031. var value = this.httpHeaders[property];
  47032. if (typeof value === 'undefined') {
  47033. continue;
  47034. }
  47035. xhr.setRequestHeader(property, value);
  47036. }
  47037. if (this.isHttp && 'begin' in args && 'end' in args) {
  47038. var rangeStr = args.begin + '-' + (args.end - 1);
  47039. xhr.setRequestHeader('Range', 'bytes=' + rangeStr);
  47040. pendingRequest.expectedStatus = 206;
  47041. } else {
  47042. pendingRequest.expectedStatus = 200;
  47043. }
  47044. var useMozChunkedLoading = supportsMozChunked && !!args.onProgressiveData;
  47045. if (useMozChunkedLoading) {
  47046. xhr.responseType = 'moz-chunked-arraybuffer';
  47047. pendingRequest.onProgressiveData = args.onProgressiveData;
  47048. pendingRequest.mozChunked = true;
  47049. } else {
  47050. xhr.responseType = 'arraybuffer';
  47051. }
  47052. if (args.onError) {
  47053. xhr.onerror = function(evt) {
  47054. args.onError(xhr.status);
  47055. };
  47056. }
  47057. xhr.onreadystatechange = this.onStateChange.bind(this, xhrId);
  47058. xhr.onprogress = this.onProgress.bind(this, xhrId);
  47059. pendingRequest.onHeadersReceived = args.onHeadersReceived;
  47060. pendingRequest.onDone = args.onDone;
  47061. pendingRequest.onError = args.onError;
  47062. pendingRequest.onProgress = args.onProgress;
  47063. xhr.send(null);
  47064. return xhrId;
  47065. },
  47066. onProgress: function NetworkManager_onProgress(xhrId, evt) {
  47067. var pendingRequest = this.pendingRequests[xhrId];
  47068. if (!pendingRequest) {
  47069. // Maybe abortRequest was called...
  47070. return;
  47071. }
  47072. if (pendingRequest.mozChunked) {
  47073. var chunk = getArrayBuffer(pendingRequest.xhr);
  47074. pendingRequest.onProgressiveData(chunk);
  47075. }
  47076. var onProgress = pendingRequest.onProgress;
  47077. if (onProgress) {
  47078. onProgress(evt);
  47079. }
  47080. },
  47081. onStateChange: function NetworkManager_onStateChange(xhrId, evt) {
  47082. var pendingRequest = this.pendingRequests[xhrId];
  47083. if (!pendingRequest) {
  47084. // Maybe abortRequest was called...
  47085. return;
  47086. }
  47087. var xhr = pendingRequest.xhr;
  47088. if (xhr.readyState >= 2 && pendingRequest.onHeadersReceived) {
  47089. pendingRequest.onHeadersReceived();
  47090. delete pendingRequest.onHeadersReceived;
  47091. }
  47092. if (xhr.readyState !== 4) {
  47093. return;
  47094. }
  47095. if (!(xhrId in this.pendingRequests)) {
  47096. // The XHR request might have been aborted in onHeadersReceived()
  47097. // callback, in which case we should abort request
  47098. return;
  47099. }
  47100. delete this.pendingRequests[xhrId];
  47101. // success status == 0 can be on ftp, file and other protocols
  47102. if (xhr.status === 0 && this.isHttp) {
  47103. if (pendingRequest.onError) {
  47104. pendingRequest.onError(xhr.status);
  47105. }
  47106. return;
  47107. }
  47108. var xhrStatus = xhr.status || OK_RESPONSE;
  47109. // From http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35.2:
  47110. // "A server MAY ignore the Range header". This means it's possible to
  47111. // get a 200 rather than a 206 response from a range request.
  47112. var ok_response_on_range_request =
  47113. xhrStatus === OK_RESPONSE &&
  47114. pendingRequest.expectedStatus === PARTIAL_CONTENT_RESPONSE;
  47115. if (!ok_response_on_range_request &&
  47116. xhrStatus !== pendingRequest.expectedStatus) {
  47117. if (pendingRequest.onError) {
  47118. pendingRequest.onError(xhr.status);
  47119. }
  47120. return;
  47121. }
  47122. this.loadedRequests[xhrId] = true;
  47123. var chunk = getArrayBuffer(xhr);
  47124. if (xhrStatus === PARTIAL_CONTENT_RESPONSE) {
  47125. var rangeHeader = xhr.getResponseHeader('Content-Range');
  47126. var matches = /bytes (\d+)-(\d+)\/(\d+)/.exec(rangeHeader);
  47127. var begin = parseInt(matches[1], 10);
  47128. pendingRequest.onDone({
  47129. begin: begin,
  47130. chunk: chunk
  47131. });
  47132. } else if (pendingRequest.onProgressiveData) {
  47133. pendingRequest.onDone(null);
  47134. } else if (chunk) {
  47135. pendingRequest.onDone({
  47136. begin: 0,
  47137. chunk: chunk
  47138. });
  47139. } else if (pendingRequest.onError) {
  47140. pendingRequest.onError(xhr.status);
  47141. }
  47142. },
  47143. hasPendingRequests: function NetworkManager_hasPendingRequests() {
  47144. for (var xhrId in this.pendingRequests) {
  47145. return true;
  47146. }
  47147. return false;
  47148. },
  47149. getRequestXhr: function NetworkManager_getXhr(xhrId) {
  47150. return this.pendingRequests[xhrId].xhr;
  47151. },
  47152. isStreamingRequest: function NetworkManager_isStreamingRequest(xhrId) {
  47153. return !!(this.pendingRequests[xhrId].onProgressiveData);
  47154. },
  47155. isPendingRequest: function NetworkManager_isPendingRequest(xhrId) {
  47156. return xhrId in this.pendingRequests;
  47157. },
  47158. isLoadedRequest: function NetworkManager_isLoadedRequest(xhrId) {
  47159. return xhrId in this.loadedRequests;
  47160. },
  47161. abortAllRequests: function NetworkManager_abortAllRequests() {
  47162. for (var xhrId in this.pendingRequests) {
  47163. this.abortRequest(xhrId | 0);
  47164. }
  47165. },
  47166. abortRequest: function NetworkManager_abortRequest(xhrId) {
  47167. var xhr = this.pendingRequests[xhrId].xhr;
  47168. delete this.pendingRequests[xhrId];
  47169. xhr.abort();
  47170. }
  47171. };
  47172. return NetworkManager;
  47173. })();
  47174. (function (root, factory) {
  47175. {
  47176. factory((root.pdfjsCoreNetwork = {}), root.pdfjsSharedUtil,
  47177. root.pdfjsCoreWorker);
  47178. }
  47179. }(this, function (exports, sharedUtil, coreWorker) {
  47180. var assert = sharedUtil.assert;
  47181. var createPromiseCapability = sharedUtil.createPromiseCapability;
  47182. var isInt = sharedUtil.isInt;
  47183. var MissingPDFException = sharedUtil.MissingPDFException;
  47184. var UnexpectedResponseException = sharedUtil.UnexpectedResponseException;
  47185. /** @implements {IPDFStream} */
  47186. function PDFNetworkStream(options) {
  47187. this._options = options;
  47188. var source = options.source;
  47189. this._manager = new NetworkManager(source.url, {
  47190. httpHeaders: source.httpHeaders,
  47191. withCredentials: source.withCredentials
  47192. });
  47193. this._rangeChunkSize = source.rangeChunkSize;
  47194. this._fullRequestReader = null;
  47195. this._rangeRequestReaders = [];
  47196. }
  47197. PDFNetworkStream.prototype = {
  47198. _onRangeRequestReaderClosed:
  47199. function PDFNetworkStream_onRangeRequestReaderClosed(reader) {
  47200. var i = this._rangeRequestReaders.indexOf(reader);
  47201. if (i >= 0) {
  47202. this._rangeRequestReaders.splice(i, 1);
  47203. }
  47204. },
  47205. getFullReader: function PDFNetworkStream_getFullReader() {
  47206. assert(!this._fullRequestReader);
  47207. this._fullRequestReader =
  47208. new PDFNetworkStreamFullRequestReader(this._manager, this._options);
  47209. return this._fullRequestReader;
  47210. },
  47211. getRangeReader: function PDFNetworkStream_getRangeReader(begin, end) {
  47212. var reader = new PDFNetworkStreamRangeRequestReader(this._manager,
  47213. begin, end);
  47214. reader.onClosed = this._onRangeRequestReaderClosed.bind(this);
  47215. this._rangeRequestReaders.push(reader);
  47216. return reader;
  47217. },
  47218. cancelAllRequests: function PDFNetworkStream_cancelAllRequests(reason) {
  47219. if (this._fullRequestReader) {
  47220. this._fullRequestReader.cancel(reason);
  47221. }
  47222. var readers = this._rangeRequestReaders.slice(0);
  47223. readers.forEach(function (reader) {
  47224. reader.cancel(reason);
  47225. });
  47226. }
  47227. };
  47228. /** @implements {IPDFStreamReader} */
  47229. function PDFNetworkStreamFullRequestReader(manager, options) {
  47230. this._manager = manager;
  47231. var source = options.source;
  47232. var args = {
  47233. onHeadersReceived: this._onHeadersReceived.bind(this),
  47234. onProgressiveData: source.disableStream ? null :
  47235. this._onProgressiveData.bind(this),
  47236. onDone: this._onDone.bind(this),
  47237. onError: this._onError.bind(this),
  47238. onProgress: this._onProgress.bind(this)
  47239. };
  47240. this._url = source.url;
  47241. this._fullRequestId = manager.requestFull(args);
  47242. this._headersReceivedCapability = createPromiseCapability();
  47243. this._disableRange = options.disableRange || false;
  47244. this._contentLength = source.length; // optional
  47245. this._rangeChunkSize = source.rangeChunkSize;
  47246. if (!this._rangeChunkSize && !this._disableRange) {
  47247. this._disableRange = true;
  47248. }
  47249. this._isStreamingSupported = false;
  47250. this._isRangeSupported = false;
  47251. this._cachedChunks = [];
  47252. this._requests = [];
  47253. this._done = false;
  47254. this._storedError = undefined;
  47255. this.onProgress = null;
  47256. }
  47257. PDFNetworkStreamFullRequestReader.prototype = {
  47258. _validateRangeRequestCapabilities: function
  47259. PDFNetworkStreamFullRequestReader_validateRangeRequestCapabilities() {
  47260. if (this._disableRange) {
  47261. return false;
  47262. }
  47263. var networkManager = this._manager;
  47264. var fullRequestXhrId = this._fullRequestId;
  47265. var fullRequestXhr = networkManager.getRequestXhr(fullRequestXhrId);
  47266. if (fullRequestXhr.getResponseHeader('Accept-Ranges') !== 'bytes') {
  47267. return false;
  47268. }
  47269. var contentEncoding =
  47270. fullRequestXhr.getResponseHeader('Content-Encoding') || 'identity';
  47271. if (contentEncoding !== 'identity') {
  47272. return false;
  47273. }
  47274. var length = fullRequestXhr.getResponseHeader('Content-Length');
  47275. length = parseInt(length, 10);
  47276. if (!isInt(length)) {
  47277. return false;
  47278. }
  47279. this._contentLength = length; // setting right content length
  47280. if (length <= 2 * this._rangeChunkSize) {
  47281. // The file size is smaller than the size of two chunks, so it does
  47282. // not make any sense to abort the request and retry with a range
  47283. // request.
  47284. return false;
  47285. }
  47286. return true;
  47287. },
  47288. _onHeadersReceived:
  47289. function PDFNetworkStreamFullRequestReader_onHeadersReceived() {
  47290. if (this._validateRangeRequestCapabilities()) {
  47291. this._isRangeSupported = true;
  47292. }
  47293. var networkManager = this._manager;
  47294. var fullRequestXhrId = this._fullRequestId;
  47295. if (networkManager.isStreamingRequest(fullRequestXhrId)) {
  47296. // We can continue fetching when progressive loading is enabled,
  47297. // and we don't need the autoFetch feature.
  47298. this._isStreamingSupported = true;
  47299. } else if (this._isRangeSupported) {
  47300. // NOTE: by cancelling the full request, and then issuing range
  47301. // requests, there will be an issue for sites where you can only
  47302. // request the pdf once. However, if this is the case, then the
  47303. // server should not be returning that it can support range
  47304. // requests.
  47305. networkManager.abortRequest(fullRequestXhrId);
  47306. }
  47307. this._headersReceivedCapability.resolve();
  47308. },
  47309. _onProgressiveData:
  47310. function PDFNetworkStreamFullRequestReader_onProgressiveData(chunk) {
  47311. if (this._requests.length > 0) {
  47312. var requestCapability = this._requests.shift();
  47313. requestCapability.resolve({value: chunk, done: false});
  47314. } else {
  47315. this._cachedChunks.push(chunk);
  47316. }
  47317. },
  47318. _onDone: function PDFNetworkStreamFullRequestReader_onDone(args) {
  47319. if (args) {
  47320. this._onProgressiveData(args.chunk);
  47321. }
  47322. this._done = true;
  47323. if (this._cachedChunks.length > 0) {
  47324. return;
  47325. }
  47326. this._requests.forEach(function (requestCapability) {
  47327. requestCapability.resolve({value: undefined, done: true});
  47328. });
  47329. this._requests = [];
  47330. },
  47331. _onError: function PDFNetworkStreamFullRequestReader_onError(status) {
  47332. var url = this._url;
  47333. var exception;
  47334. if (status === 404 || status === 0 && /^file:/.test(url)) {
  47335. exception = new MissingPDFException('Missing PDF "' + url + '".');
  47336. } else {
  47337. exception = new UnexpectedResponseException(
  47338. 'Unexpected server response (' + status +
  47339. ') while retrieving PDF "' + url + '".', status);
  47340. }
  47341. this._storedError = exception;
  47342. this._headersReceivedCapability.reject(exception);
  47343. this._requests.forEach(function (requestCapability) {
  47344. requestCapability.reject(exception);
  47345. });
  47346. this._requests = [];
  47347. this._cachedChunks = [];
  47348. },
  47349. _onProgress: function PDFNetworkStreamFullRequestReader_onProgress(data) {
  47350. if (this.onProgress) {
  47351. this.onProgress({
  47352. loaded: data.loaded,
  47353. total: data.lengthComputable ? data.total : this._contentLength
  47354. });
  47355. }
  47356. },
  47357. get isRangeSupported() {
  47358. return this._isRangeSupported;
  47359. },
  47360. get isStreamingSupported() {
  47361. return this._isStreamingSupported;
  47362. },
  47363. get contentLength() {
  47364. return this._contentLength;
  47365. },
  47366. get headersReady() {
  47367. return this._headersReceivedCapability.promise;
  47368. },
  47369. read: function PDFNetworkStreamFullRequestReader_read() {
  47370. if (this._storedError) {
  47371. return Promise.reject(this._storedError);
  47372. }
  47373. if (this._cachedChunks.length > 0) {
  47374. var chunk = this._cachedChunks.shift();
  47375. return Promise.resolve(chunk);
  47376. }
  47377. if (this._done) {
  47378. return Promise.resolve({value: undefined, done: true});
  47379. }
  47380. var requestCapability = createPromiseCapability();
  47381. this._requests.push(requestCapability);
  47382. return requestCapability.promise;
  47383. },
  47384. cancel: function PDFNetworkStreamFullRequestReader_cancel(reason) {
  47385. this._done = true;
  47386. this._headersReceivedCapability.reject(reason);
  47387. this._requests.forEach(function (requestCapability) {
  47388. requestCapability.resolve({value: undefined, done: true});
  47389. });
  47390. this._requests = [];
  47391. if (this._manager.isPendingRequest(this._fullRequestId)) {
  47392. this._manager.abortRequest(this._fullRequestId);
  47393. }
  47394. this._fullRequestReader = null;
  47395. }
  47396. };
  47397. /** @implements {IPDFStreamRangeReader} */
  47398. function PDFNetworkStreamRangeRequestReader(manager, begin, end) {
  47399. this._manager = manager;
  47400. var args = {
  47401. onDone: this._onDone.bind(this),
  47402. onProgress: this._onProgress.bind(this)
  47403. };
  47404. this._requestId = manager.requestRange(begin, end, args);
  47405. this._requests = [];
  47406. this._queuedChunk = null;
  47407. this._done = false;
  47408. this.onProgress = null;
  47409. this.onClosed = null;
  47410. }
  47411. PDFNetworkStreamRangeRequestReader.prototype = {
  47412. _close: function PDFNetworkStreamRangeRequestReader_close() {
  47413. if (this.onClosed) {
  47414. this.onClosed(this);
  47415. }
  47416. },
  47417. _onDone: function PDFNetworkStreamRangeRequestReader_onDone(data) {
  47418. var chunk = data.chunk;
  47419. if (this._requests.length > 0) {
  47420. var requestCapability = this._requests.shift();
  47421. requestCapability.resolve({value: chunk, done: false});
  47422. } else {
  47423. this._queuedChunk = chunk;
  47424. }
  47425. this._done = true;
  47426. this._requests.forEach(function (requestCapability) {
  47427. requestCapability.resolve({value: undefined, done: true});
  47428. });
  47429. this._requests = [];
  47430. this._close();
  47431. },
  47432. _onProgress: function PDFNetworkStreamRangeRequestReader_onProgress(evt) {
  47433. if (!this.isStreamingSupported && this.onProgress) {
  47434. this.onProgress({
  47435. loaded: evt.loaded
  47436. });
  47437. }
  47438. },
  47439. get isStreamingSupported() {
  47440. return false; // TODO allow progressive range bytes loading
  47441. },
  47442. read: function PDFNetworkStreamRangeRequestReader_read() {
  47443. if (this._queuedChunk !== null) {
  47444. var chunk = this._queuedChunk;
  47445. this._queuedChunk = null;
  47446. return Promise.resolve({value: chunk, done: false});
  47447. }
  47448. if (this._done) {
  47449. return Promise.resolve({value: undefined, done: true});
  47450. }
  47451. var requestCapability = createPromiseCapability();
  47452. this._requests.push(requestCapability);
  47453. return requestCapability.promise;
  47454. },
  47455. cancel: function PDFNetworkStreamRangeRequestReader_cancel(reason) {
  47456. this._done = true;
  47457. this._requests.forEach(function (requestCapability) {
  47458. requestCapability.resolve({value: undefined, done: true});
  47459. });
  47460. this._requests = [];
  47461. if (this._manager.isPendingRequest(this._requestId)) {
  47462. this._manager.abortRequest(this._requestId);
  47463. }
  47464. this._close();
  47465. }
  47466. };
  47467. coreWorker.setPDFNetworkStreamClass(PDFNetworkStream);
  47468. exports.PDFNetworkStream = PDFNetworkStream;
  47469. exports.NetworkManager = NetworkManager;
  47470. }));
  47471. }).call(pdfjsLibs);
  47472. exports.PDFJS = pdfjsLibs.pdfjsDisplayGlobal.PDFJS;
  47473. exports.getDocument = pdfjsLibs.pdfjsDisplayAPI.getDocument;
  47474. exports.PDFDataRangeTransport =
  47475. pdfjsLibs.pdfjsDisplayAPI.PDFDataRangeTransport;
  47476. exports.renderTextLayer = pdfjsLibs.pdfjsDisplayTextLayer.renderTextLayer;
  47477. exports.AnnotationLayer =
  47478. pdfjsLibs.pdfjsDisplayAnnotationLayer.AnnotationLayer;
  47479. exports.CustomStyle = pdfjsLibs.pdfjsDisplayDOMUtils.CustomStyle;
  47480. exports.PasswordResponses = pdfjsLibs.pdfjsSharedUtil.PasswordResponses;
  47481. exports.InvalidPDFException = pdfjsLibs.pdfjsSharedUtil.InvalidPDFException;
  47482. exports.MissingPDFException = pdfjsLibs.pdfjsSharedUtil.MissingPDFException;
  47483. exports.UnexpectedResponseException =
  47484. pdfjsLibs.pdfjsSharedUtil.UnexpectedResponseException;
  47485. }));